source: moodle/trunk/fuentes/admin/tool/monitor/edit.php @ 136

Last change on this file since 136 was 136, checked in by mabarracus, 4 years ago

Ported code to xenial

File size: 4.2 KB
Line 
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 * This file gives an overview of the monitors present in site.
19 *
20 * @package    tool_monitor
21 * @copyright  2014 onwards Simey Lameze <simey@moodle.com>
22 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24require(__DIR__ . '/../../../config.php');
25require_once($CFG->libdir.'/adminlib.php');
26
27$ruleid = optional_param('ruleid', 0, PARAM_INT);
28$courseid = optional_param('courseid', 0, PARAM_INT);
29
30// Validate course id.
31if (empty($courseid)) {
32    require_login();
33    $context = context_system::instance();
34    $coursename = format_string($SITE->fullname, true, array('context' => $context));
35    $PAGE->set_context($context);
36} else {
37    $course = get_course($courseid);
38    require_login($course);
39    $context = context_course::instance($course->id);
40    $coursename = format_string($course->fullname, true, array('context' => $context));
41}
42
43// Check for caps.
44require_capability('tool/monitor:managerules', $context);
45
46// Set up the page.
47$url = new moodle_url("/admin/tool/monitor/edit.php", array('courseid' => $courseid, 'ruleid' => $ruleid));
48$manageurl = new moodle_url("/admin/tool/monitor/managerules.php", array('courseid' => $courseid));
49$PAGE->set_url($url);
50$PAGE->set_pagelayout('report');
51$PAGE->set_title($coursename);
52$PAGE->set_heading($coursename);
53
54// Get data ready for mform.
55$eventlist = tool_monitor\eventlist::get_all_eventlist(true);
56$pluginlist = tool_monitor\eventlist::get_plugin_list();
57$eventlist = array_merge(array('' => get_string('choosedots')), $eventlist);
58$pluginlist = array_merge(array('' => get_string('choosedots')), $pluginlist);
59
60// Set up the yui module.
61$PAGE->requires->yui_module('moodle-tool_monitor-dropdown', 'Y.M.tool_monitor.DropDown.init',
62        array(array('eventlist' => $eventlist)));
63
64// Site level report.
65if (empty($courseid)) {
66    admin_externalpage_setup('toolmonitorrules', '', null, '', array('pagelayout' => 'report'));
67} else {
68    // Course level report.
69    $PAGE->navigation->override_active_url($manageurl);
70}
71
72// Mform setup.
73if (!empty($ruleid)) {
74    $rule = \tool_monitor\rule_manager::get_rule($ruleid)->get_mform_set_data();
75    $rule->minutes = $rule->timewindow / MINSECS;
76    $subscriptioncount = \tool_monitor\subscription_manager::count_rule_subscriptions($ruleid);
77} else {
78    $rule = new stdClass();
79    $subscriptioncount = 0;
80}
81
82$mform = new tool_monitor\rule_form(null, array('eventlist' => $eventlist, 'pluginlist' => $pluginlist, 'rule' => $rule,
83        'courseid' => $courseid, 'subscriptioncount' => $subscriptioncount));
84
85if ($mform->is_cancelled()) {
86    redirect(new moodle_url('/admin/tool/monitor/managerules.php', array('courseid' => $courseid)));
87    exit();
88}
89
90if ($mformdata = $mform->get_data()) {
91    $rule = \tool_monitor\rule_manager::clean_ruledata_form($mformdata);
92
93    if (empty($rule->id)) {
94        \tool_monitor\rule_manager::add_rule($rule);
95    } else {
96        \tool_monitor\rule_manager::update_rule($rule);
97    }
98
99    redirect($manageurl);
100} else {
101    echo $OUTPUT->header();
102    $mform->set_data($rule);
103    // If there's any subscription for this rule, display an information message.
104    if ($subscriptioncount > 0) {
105        echo $OUTPUT->notification(get_string('disablefieldswarning', 'tool_monitor'), 'notifyproblem');
106    }
107    $mform->display();
108    echo $OUTPUT->footer();
109    exit;
110}
111
112echo $OUTPUT->header();
113if (!empty($ruleid)) {
114    echo $OUTPUT->heading(get_string('editrule', 'tool_monitor'));
115} else {
116    echo $OUTPUT->heading(get_string('addrule', 'tool_monitor'));
117}
118$mform->set_data($rule);
119$mform->display();
120echo $OUTPUT->footer();
Note: See TracBrowser for help on using the repository browser.