[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
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 page lets users to manage rules for a given course. 19 * 20 * @package tool_monitor 21 * @copyright 2014 onwards Ankit Agarwal <ankit.agrr@gmail.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 28 $courseid = optional_param('courseid', 0, PARAM_INT); 29 $ruleid = optional_param('ruleid', 0, PARAM_INT); 30 $action = optional_param('action', '', PARAM_ALPHA); 31 $confirm = optional_param('confirm', false, PARAM_BOOL); 32 $status = optional_param('status', 0, PARAM_BOOL); 33 34 // Validate course id. 35 if (empty($courseid)) { 36 require_login(); 37 $context = context_system::instance(); 38 $coursename = format_string($SITE->fullname, true, array('context' => $context)); 39 $PAGE->set_context($context); 40 } else { 41 $course = get_course($courseid); 42 require_login($course); 43 $context = context_course::instance($course->id); 44 $coursename = format_string($course->fullname, true, array('context' => $context)); 45 } 46 47 // Check for caps. 48 require_capability('tool/monitor:managerules', $context); 49 50 // Set up the page. 51 $manageurl = new moodle_url("/admin/tool/monitor/managerules.php", array('courseid' => $courseid)); 52 $PAGE->set_url($manageurl); 53 $PAGE->set_pagelayout('report'); 54 $PAGE->set_title($coursename); 55 $PAGE->set_heading($coursename); 56 57 // Site level report. 58 if (empty($courseid)) { 59 admin_externalpage_setup('toolmonitorrules', '', null, '', array('pagelayout' => 'report')); 60 } 61 62 if (!empty($action) && $action == 'changestatus') { 63 require_sesskey(); 64 require_capability('tool/monitor:managetool', context_system::instance()); 65 // Toggle status of the plugin. 66 set_config('enablemonitor', $status, 'tool_monitor'); 67 redirect(new moodle_url('/admin/tool/monitor/managerules.php', array('courseid' => 0))); 68 } 69 70 // Copy/delete rule if needed. 71 if (!empty($action) && $ruleid) { 72 require_sesskey(); 73 74 // If the rule does not exist, then redirect back as the rule must have already been deleted. 75 if (!$rule = $DB->get_record('tool_monitor_rules', array('id' => $ruleid), '*', IGNORE_MISSING)) { 76 redirect(new moodle_url('/admin/tool/monitor/managerules.php', array('courseid' => $courseid))); 77 } 78 79 echo $OUTPUT->header(); 80 $rule = \tool_monitor\rule_manager::get_rule($rule); 81 switch ($action) { 82 case 'copy': 83 // No need to check for capability here as it is done at the start of the page. 84 $rule->duplicate_rule($courseid); 85 echo $OUTPUT->notification(get_string('rulecopysuccess', 'tool_monitor'), 'notifysuccess'); 86 break; 87 case 'delete': 88 if ($rule->can_manage_rule()) { 89 $confirmurl = new moodle_url($CFG->wwwroot. '/admin/tool/monitor/managerules.php', 90 array('ruleid' => $ruleid, 'courseid' => $courseid, 'action' => 'delete', 91 'confirm' => true, 'sesskey' => sesskey())); 92 $cancelurl = new moodle_url($CFG->wwwroot. '/admin/tool/monitor/managerules.php', 93 array('courseid' => $courseid)); 94 if ($confirm) { 95 $rule->delete_rule(); 96 echo $OUTPUT->notification(get_string('ruledeletesuccess', 'tool_monitor'), 'notifysuccess'); 97 } else { 98 $strconfirm = get_string('ruleareyousure', 'tool_monitor', $rule->get_name($context)); 99 if ($numberofsubs = $DB->count_records('tool_monitor_subscriptions', array('ruleid' => $ruleid))) { 100 $strconfirm .= '<br />'; 101 $strconfirm .= get_string('ruleareyousureextra', 'tool_monitor', $numberofsubs); 102 } 103 echo $OUTPUT->confirm($strconfirm, $confirmurl, $cancelurl); 104 echo $OUTPUT->footer(); 105 exit(); 106 } 107 } else { 108 // User doesn't have permissions. Should never happen for real users. 109 throw new moodle_exception('rulenopermissions', 'tool_monitor', $manageurl, $action); 110 } 111 break; 112 default: 113 } 114 } else { 115 echo $OUTPUT->header(); 116 } 117 118 echo $OUTPUT->heading(get_string('managerules', 'tool_monitor')); 119 $status = get_config('tool_monitor', 'enablemonitor'); 120 $help = new help_icon('enablehelp', 'tool_monitor'); 121 122 // Display option to enable/disable the plugin. 123 if ($status) { 124 if (has_capability('tool/monitor:managetool', context_system::instance())) { 125 // We don't need to show enabled status to everyone. 126 echo get_string('monitorenabled', 'tool_monitor'); 127 $disableurl = new moodle_url("/admin/tool/monitor/managerules.php", 128 array('courseid' => $courseid, 'action' => 'changestatus', 'status' => 0, 'sesskey' => sesskey())); 129 echo ' ' . html_writer::link($disableurl, get_string('disable')); 130 echo $OUTPUT->render($help); 131 } 132 } else { 133 echo get_string('monitordisabled', 'tool_monitor'); 134 if (has_capability('tool/monitor:managetool', context_system::instance())) { 135 $enableurl = new moodle_url("/admin/tool/monitor/managerules.php", 136 array('courseid' => $courseid, 'action' => 'changestatus', 'status' => 1, 'sesskey' => sesskey())); 137 echo ' ' . html_writer::link($enableurl, get_string('enable')); 138 echo $OUTPUT->render($help); 139 } else { 140 echo ' ' . get_string('contactadmin', 'tool_monitor'); 141 } 142 echo $OUTPUT->footer(); // Do not render anything else. 143 exit(); 144 } 145 146 // Render the rule list. 147 $renderable = new \tool_monitor\output\managerules\renderable('toolmonitorrules', $manageurl, $courseid); 148 $renderer = $PAGE->get_renderer('tool_monitor', 'managerules'); 149 echo $renderer->render($renderable); 150 if (has_capability('tool/monitor:subscribe', $context)) { 151 $manageurl = new moodle_url("/admin/tool/monitor/index.php", array('courseid' => $courseid)); 152 echo $renderer->render_subscriptions_link($manageurl); 153 } 154 echo $OUTPUT->footer();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |