Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.
   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * Handles AJAX processing (convert date to timestamp using current calendar).
  19   *
  20   * @package availability_date
  21   * @copyright 2014 The Open University
  22   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  define('AJAX_SCRIPT', true);
  26  require(__DIR__ . '/../../../config.php');
  27  
  28  // Action verb.
  29  $action = required_param('action', PARAM_ALPHA);
  30  
  31  switch ($action) {
  32      case 'totime':
  33          // Converts from time fields to timestamp using current user's calendar and time zone.
  34          echo \availability_date\frontend::get_time_from_fields(
  35                  required_param('year', PARAM_INT),
  36                  required_param('month', PARAM_INT),
  37                  required_param('day', PARAM_INT),
  38                  required_param('hour', PARAM_INT),
  39                  required_param('minute', PARAM_INT));
  40          exit;
  41  
  42      case 'fromtime' :
  43          // Converts from timestamp to time fields.
  44          echo json_encode(\availability_date\frontend::get_fields_from_time(
  45                  required_param('time', PARAM_INT)));
  46          exit;
  47  }
  48  
  49  // Unexpected actions throw coding_exception (this error should not occur
  50  // unless there is a code bug).
  51  throw new coding_exception('Unexpected action parameter');