[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/admin/tool/task/ -> scheduledtasks.php (source)

   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   * Scheduled task admin pages.
  19   *
  20   * @package    tool_task
  21   * @copyright  2013 Damyon Wiese <damyon@moodle.com>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  require_once(__DIR__ . '/../../../config.php');
  26  require_once($CFG->libdir.'/adminlib.php');
  27  require_once($CFG->libdir.'/tablelib.php');
  28  
  29  $PAGE->set_url('/admin/tool/task/scheduledtasks.php');
  30  $PAGE->set_context(context_system::instance());
  31  $PAGE->set_pagelayout('admin');
  32  $strheading = get_string('scheduledtasks', 'tool_task');
  33  $PAGE->set_title($strheading);
  34  $PAGE->set_heading($strheading);
  35  
  36  require_login();
  37  
  38  require_capability('moodle/site:config', context_system::instance());
  39  
  40  $renderer = $PAGE->get_renderer('tool_task');
  41  
  42  $action = optional_param('action', '', PARAM_ALPHAEXT);
  43  $taskname = optional_param('task', '', PARAM_RAW);
  44  $task = null;
  45  $mform = null;
  46  
  47  if ($taskname) {
  48      $task = \core\task\manager::get_scheduled_task($taskname);
  49      if (!$task) {
  50          print_error('invaliddata');
  51      }
  52  }
  53  
  54  if ($action == 'edit') {
  55      $PAGE->navbar->add(get_string('edittaskschedule', 'tool_task', $task->get_name()));
  56  }
  57  
  58  if ($task) {
  59      $mform = new tool_task_edit_scheduled_task_form(null, $task);
  60  }
  61  
  62  if ($mform && ($mform->is_cancelled() || !empty($CFG->preventscheduledtaskchanges))) {
  63      redirect(new moodle_url('/admin/tool/task/scheduledtasks.php'));
  64  } else if ($action == 'edit' && empty($CFG->preventscheduledtaskchanges)) {
  65  
  66      if ($data = $mform->get_data()) {
  67  
  68  
  69          if ($data->resettodefaults) {
  70              $defaulttask = \core\task\manager::get_default_scheduled_task($taskname);
  71              $task->set_minute($defaulttask->get_minute());
  72              $task->set_hour($defaulttask->get_hour());
  73              $task->set_month($defaulttask->get_month());
  74              $task->set_day_of_week($defaulttask->get_day_of_week());
  75              $task->set_day($defaulttask->get_day());
  76              $task->set_disabled($defaulttask->get_disabled());
  77              $task->set_customised(false);
  78          } else {
  79              $task->set_minute($data->minute);
  80              $task->set_hour($data->hour);
  81              $task->set_month($data->month);
  82              $task->set_day_of_week($data->dayofweek);
  83              $task->set_day($data->day);
  84              $task->set_disabled($data->disabled);
  85              $task->set_customised(true);
  86          }
  87  
  88          try {
  89              \core\task\manager::configure_scheduled_task($task);
  90              redirect($PAGE->url, get_string('changessaved'), null, \core\output\notification::NOTIFY_SUCCESS);
  91          } catch (Exception $e) {
  92              redirect($PAGE->url, $e->getMessage(), null, \core\output\notification::NOTIFY_ERROR);
  93          }
  94      } else {
  95          echo $OUTPUT->header();
  96          echo $OUTPUT->heading(get_string('edittaskschedule', 'tool_task', $task->get_name()));
  97          $mform->display();
  98          echo $OUTPUT->footer();
  99      }
 100  
 101  } else {
 102      echo $OUTPUT->header();
 103      $tasks = core\task\manager::get_all_scheduled_tasks();
 104      echo $renderer->scheduled_tasks_table($tasks);
 105      echo $OUTPUT->footer();
 106  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1