Commit | Line | Data |
---|---|---|
8bdc9cac | 1 | <?php |
0705ff84 | 2 | |
77eddcd5 | 3 | /////////////////////////////////////////////////////////////////////////// |
4 | // // | |
5 | // NOTICE OF COPYRIGHT // | |
6 | // // | |
7 | // Moodle - Modular Object-Oriented Dynamic Learning Environment // | |
8 | // http://moodle.org // | |
9 | // // | |
10 | // Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com // | |
11 | // // | |
12 | // This program is free software; you can redistribute it and/or modify // | |
13 | // it under the terms of the GNU General Public License as published by // | |
14 | // the Free Software Foundation; either version 2 of the License, or // | |
15 | // (at your option) any later version. // | |
16 | // // | |
17 | // This program is distributed in the hope that it will be useful, // | |
18 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // | |
19 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // | |
20 | // GNU General Public License for more details: // | |
21 | // // | |
22 | // http://www.gnu.org/copyleft/gpl.html // | |
23 | // // | |
24 | /////////////////////////////////////////////////////////////////////////// | |
0705ff84 | 25 | |
77eddcd5 | 26 | /** |
27 | * Allow the administrator to look through a list of course requests and approve or reject them. | |
28 | * | |
29 | * @license http://www.gnu.org/copyleft/gpl.html GNU Public License | |
30 | * @package course | |
8bdc9cac | 31 | */ |
77eddcd5 | 32 | |
1fcf0ca8 | 33 | require_once(__DIR__ . '/../config.php'); |
8bdc9cac SH |
34 | require_once($CFG->libdir . '/adminlib.php'); |
35 | require_once($CFG->dirroot . '/course/lib.php'); | |
36 | require_once($CFG->dirroot . '/course/request_form.php'); | |
0705ff84 | 37 | |
8bdc9cac SH |
38 | $approve = optional_param('approve', 0, PARAM_INT); |
39 | $reject = optional_param('reject', 0, PARAM_INT); | |
0705ff84 | 40 | |
8bdc9cac | 41 | $baseurl = $CFG->wwwroot . '/course/pending.php'; |
3e15abe5 MG |
42 | $context = context_system::instance(); |
43 | if (has_capability('moodle/site:approvecourse', $context)) { | |
44 | // Similar to course management capabilities, if user has approve capability in system context | |
45 | // we add the link to the admin menu. Otherwise we check if user has capability anywhere. | |
46 | admin_externalpage_setup('coursespending'); | |
47 | } else { | |
48 | require_login(null, false); | |
49 | $categories = core_course_category::make_categories_list('moodle/site:approvecourse'); | |
50 | if (!$categories) { | |
51 | require_capability('moodle/site:approvecourse', $context); | |
52 | } | |
53 | $PAGE->set_context($context); | |
54 | $PAGE->set_url(new moodle_url('/course/pending.php')); | |
55 | } | |
77eddcd5 | 56 | |
57 | /// Process approval of a course. | |
8bdc9cac | 58 | if (!empty($approve) and confirm_sesskey()) { |
77eddcd5 | 59 | /// Load the request. |
8bdc9cac SH |
60 | $course = new course_request($approve); |
61 | $courseid = $course->approve(); | |
77eddcd5 | 62 | |
8bdc9cac | 63 | if ($courseid !== false) { |
3e15abe5 MG |
64 | if (has_capability('moodle/course:update', context_course::instance($courseid))) { |
65 | redirect(new moodle_url('/course/edit.php', ['id' => $courseid, 'returnto' => 'pending'])); | |
66 | } else { | |
67 | redirect(new moodle_url('/course/view.php', ['id' => $courseid])); | |
68 | } | |
8bdc9cac SH |
69 | } else { |
70 | print_error('courseapprovedfailed'); | |
0705ff84 | 71 | } |
8bdc9cac | 72 | } |
0be6f678 | 73 | |
77eddcd5 | 74 | /// Process rejection of a course. |
8bdc9cac SH |
75 | if (!empty($reject)) { |
76 | // Load the request. | |
77 | $course = new course_request($reject); | |
0705ff84 | 78 | |
8bdc9cac SH |
79 | // Prepare the form. |
80 | $rejectform = new reject_request_form($baseurl); | |
81 | $default = new stdClass(); | |
82 | $default->reject = $course->id; | |
83 | $rejectform->set_data($default); | |
0be6f678 | 84 | |
8bdc9cac SH |
85 | /// Standard form processing if statement. |
86 | if ($rejectform->is_cancelled()){ | |
87 | redirect($baseurl); | |
77eddcd5 | 88 | |
8bdc9cac | 89 | } else if ($data = $rejectform->get_data()) { |
77eddcd5 | 90 | |
8bdc9cac SH |
91 | /// Reject the request |
92 | $course->reject($data->rejectnotice); | |
93 | ||
94 | /// Redirect back to the course listing. | |
95 | redirect($baseurl, get_string('courserejected')); | |
77eddcd5 | 96 | } |
97 | ||
8bdc9cac | 98 | /// Display the form for giving a reason for rejecting the request. |
61ef8f9f | 99 | echo $OUTPUT->header($rejectform->focus()); |
8bdc9cac SH |
100 | $rejectform->display(); |
101 | echo $OUTPUT->footer(); | |
102 | exit; | |
103 | } | |
77eddcd5 | 104 | |
8bdc9cac | 105 | /// Print a list of all the pending requests. |
61ef8f9f | 106 | echo $OUTPUT->header(); |
8bdc9cac SH |
107 | |
108 | $pending = $DB->get_records('course_request'); | |
109 | if (empty($pending)) { | |
110 | echo $OUTPUT->heading(get_string('nopendingcourses')); | |
111 | } else { | |
112 | echo $OUTPUT->heading(get_string('coursespending')); | |
82356399 SL |
113 | $role = $DB->get_record('role', array('id' => $CFG->creatornewroleid), '*', MUST_EXIST); |
114 | echo $OUTPUT->notification(get_string('courserequestwarning', 'core', role_get_name($role)), 'notifyproblem'); | |
8bdc9cac SH |
115 | |
116 | /// Build a table of all the requests. | |
117 | $table = new html_table(); | |
16be8974 | 118 | $table->attributes['class'] = 'pendingcourserequests generaltable'; |
89881a34 | 119 | $table->align = array('center', 'center', 'center', 'center', 'center', 'center'); |
59b9a140 FM |
120 | $table->head = array(get_string('shortnamecourse'), get_string('fullnamecourse'), get_string('requestedby'), |
121 | get_string('summary'), get_string('category'), get_string('requestreason'), get_string('action')); | |
aa6c1ced | 122 | |
8bdc9cac SH |
123 | foreach ($pending as $course) { |
124 | $course = new course_request($course); | |
aa6c1ced | 125 | |
8bdc9cac SH |
126 | // Check here for shortname collisions and warn about them. |
127 | $course->check_shortname_collision(); | |
128 | ||
3e15abe5 MG |
129 | if (!$course->can_approve()) { |
130 | continue; | |
131 | } | |
2d8a275b | 132 | $category = $course->get_category(); |
59b9a140 | 133 | |
8bdc9cac | 134 | $row = array(); |
8bdc9cac SH |
135 | $row[] = format_string($course->shortname); |
136 | $row[] = format_string($course->fullname); | |
137 | $row[] = fullname($course->get_requester()); | |
52ecd1de | 138 | $row[] = format_text($course->summary, $course->summaryformat); |
2d8a275b | 139 | $row[] = $category->get_formatted_name(); |
8bdc9cac | 140 | $row[] = format_string($course->reason); |
5c2ed7e2 PS |
141 | $row[] = $OUTPUT->single_button(new moodle_url($baseurl, array('approve' => $course->id, 'sesskey' => sesskey())), get_string('approve'), 'get') . |
142 | $OUTPUT->single_button(new moodle_url($baseurl, array('reject' => $course->id)), get_string('rejectdots'), 'get'); | |
8bdc9cac SH |
143 | |
144 | /// Add the row to the table. | |
145 | $table->data[] = $row; | |
146 | } | |
77eddcd5 | 147 | |
8bdc9cac | 148 | /// Display the table. |
16be8974 | 149 | echo html_writer::table($table); |
77eddcd5 | 150 | |
8bdc9cac SH |
151 | /// Message about name collisions, if necessary. |
152 | if (!empty($collision)) { | |
153 | print_string('shortnamecollisionwarning'); | |
0705ff84 | 154 | } |
8bdc9cac | 155 | } |
0705ff84 | 156 | |
77eddcd5 | 157 | /// Finish off the page. |
5c2ed7e2 | 158 | echo $OUTPUT->single_button($CFG->wwwroot . '/course/index.php', get_string('backtocourselisting')); |
16be8974 | 159 | echo $OUTPUT->footer(); |