Merge branch 'MDL-62144-master' of git://github.com/damyon/moodle
[moodle.git] / course / pending.php
blob710ca555eb551a093be5ebbf35445efddcf553c5
1 <?php
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 ///////////////////////////////////////////////////////////////////////////
26 /**
27 * Allow the administrator to look through a list of course requests and approve or reject them.
29 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
30 * @package course
33 require_once(__DIR__ . '/../config.php');
34 require_once($CFG->libdir . '/adminlib.php');
35 require_once($CFG->dirroot . '/course/lib.php');
36 require_once($CFG->dirroot . '/course/request_form.php');
38 $approve = optional_param('approve', 0, PARAM_INT);
39 $reject = optional_param('reject', 0, PARAM_INT);
41 $baseurl = $CFG->wwwroot . '/course/pending.php';
42 admin_externalpage_setup('coursespending');
44 /// Process approval of a course.
45 if (!empty($approve) and confirm_sesskey()) {
46 /// Load the request.
47 $course = new course_request($approve);
48 $courseid = $course->approve();
50 if ($courseid !== false) {
51 redirect(new moodle_url('/course/edit.php', ['id' => $courseid, 'returnto' => 'pending']));
52 } else {
53 print_error('courseapprovedfailed');
57 /// Process rejection of a course.
58 if (!empty($reject)) {
59 // Load the request.
60 $course = new course_request($reject);
62 // Prepare the form.
63 $rejectform = new reject_request_form($baseurl);
64 $default = new stdClass();
65 $default->reject = $course->id;
66 $rejectform->set_data($default);
68 /// Standard form processing if statement.
69 if ($rejectform->is_cancelled()){
70 redirect($baseurl);
72 } else if ($data = $rejectform->get_data()) {
74 /// Reject the request
75 $course->reject($data->rejectnotice);
77 /// Redirect back to the course listing.
78 redirect($baseurl, get_string('courserejected'));
81 /// Display the form for giving a reason for rejecting the request.
82 echo $OUTPUT->header($rejectform->focus());
83 $rejectform->display();
84 echo $OUTPUT->footer();
85 exit;
88 /// Print a list of all the pending requests.
89 echo $OUTPUT->header();
91 $pending = $DB->get_records('course_request');
92 if (empty($pending)) {
93 echo $OUTPUT->heading(get_string('nopendingcourses'));
94 } else {
95 echo $OUTPUT->heading(get_string('coursespending'));
96 $role = $DB->get_record('role', array('id' => $CFG->creatornewroleid), '*', MUST_EXIST);
97 echo $OUTPUT->notification(get_string('courserequestwarning', 'core', role_get_name($role)), 'notifyproblem');
99 /// Build a table of all the requests.
100 $table = new html_table();
101 $table->attributes['class'] = 'pendingcourserequests generaltable';
102 $table->align = array('center', 'center', 'center', 'center', 'center', 'center');
103 $table->head = array(get_string('shortnamecourse'), get_string('fullnamecourse'), get_string('requestedby'),
104 get_string('summary'), get_string('category'), get_string('requestreason'), get_string('action'));
106 foreach ($pending as $course) {
107 $course = new course_request($course);
109 // Check here for shortname collisions and warn about them.
110 $course->check_shortname_collision();
112 $category = $course->get_category();
114 $row = array();
115 $row[] = format_string($course->shortname);
116 $row[] = format_string($course->fullname);
117 $row[] = fullname($course->get_requester());
118 $row[] = format_text($course->summary, $course->summaryformat);
119 $row[] = $category->get_formatted_name();
120 $row[] = format_string($course->reason);
121 $row[] = $OUTPUT->single_button(new moodle_url($baseurl, array('approve' => $course->id, 'sesskey' => sesskey())), get_string('approve'), 'get') .
122 $OUTPUT->single_button(new moodle_url($baseurl, array('reject' => $course->id)), get_string('rejectdots'), 'get');
124 /// Add the row to the table.
125 $table->data[] = $row;
128 /// Display the table.
129 echo html_writer::table($table);
131 /// Message about name collisions, if necessary.
132 if (!empty($collision)) {
133 print_string('shortnamecollisionwarning');
137 /// Finish off the page.
138 echo $OUTPUT->single_button($CFG->wwwroot . '/course/index.php', get_string('backtocourselisting'));
139 echo $OUTPUT->footer();