forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpending.php
213 lines (184 loc) · 9.53 KB
/
pending.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<?php // $Id$
///////////////////////////////////////////////////////////////////////////
// //
// NOTICE OF COPYRIGHT //
// //
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// http://moodle.org //
// //
// Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation; either version 2 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details: //
// //
// http://www.gnu.org/copyleft/gpl.html //
// //
///////////////////////////////////////////////////////////////////////////
/**
* Allow the administrator to look through a list of course requests and approve or reject them.
*
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package course
*//** */
require_once(dirname(__FILE__) . '/../config.php');
require_once($CFG->libdir . '/adminlib.php');
require_once($CFG->dirroot . '/course/lib.php');
require_once($CFG->dirroot . '/course/request_form.php');
require_login();
require_capability('moodle/site:approvecourse', get_context_instance(CONTEXT_SYSTEM));
$approve = optional_param('approve', 0, PARAM_INT);
$reject = optional_param('reject', 0, PARAM_INT);
$baseurl = $CFG->wwwroot . '/course/pending.php';
admin_externalpage_setup('coursespending');
/// Process approval of a course.
if (!empty($approve) and confirm_sesskey()) {
/// Load the request.
if (!$course = $DB->get_record('course_request', array('id' => $approve))) {
print_error('unknowncourserequest');
}
/// Get the category courses are added to.
$category = get_course_category($CFG->defaultrequestcategory);
/// Build up a course record based on the request.
$course->category = $category->id;
$course->sortorder = $category->sortorder; // place as the first in category
$course->requested = 1;
unset($course->reason);
unset($course->id);
$teacherid = $course->requester;
unset($course->requester);
if (!empty($CFG->restrictmodulesfor) && $CFG->restrictmodulesfor != 'none' && !empty($CFG->restrictbydefault)) {
$course->restrictmodules = 1;
}
/// Insert the record.
if ($courseid = $DB->insert_record('course', $course)) {
$course = $DB->get_record('course', array('id' => $courseid));
blocks_add_default_course_blocks($course);
$context = get_context_instance(CONTEXT_COURSE, $courseid);
role_assign($CFG->creatornewroleid, $teacherid, 0, $context->id); // assing teacher role
if (!empty($CFG->restrictmodulesfor) && $CFG->restrictmodulesfor != 'none' && !empty($CFG->restrictbydefault)) {
// if we're all or requested we're ok.
$allowedmods = explode(',',$CFG->defaultallowedmodules);
update_restricted_mods($course,$allowedmods);
}
$DB->delete_records('course_request', array('id'=>$approve));
$success = 1;
fix_course_sortorder();
}
if (!empty($success)) {
$user = $DB->get_record('user', array('id' => $teacherid));
$a->name = $course->fullname;
$a->url = $CFG->wwwroot.'/course/view.php?id=' . $courseid;
$eventdata = new object();
$eventdata->modulename = 'moodle';
$eventdata->component = 'course';
$eventdata->name = 'courserequestapproved';
$eventdata->userfrom = $USER;
$eventdata->userto = $user;
$eventdata->subject = get_string('courseapprovedsubject');
$eventdata->fullmessage = get_string('courseapprovedemail2', 'moodle', $a);
$eventdata->fullmessageformat = FORMAT_PLAIN;
$eventdata->fullmessagehtml = '';
$eventdata->smallmessage = '';
events_trigger('message_send', $eventdata);
redirect($CFG->wwwroot.'/course/edit.php?id=' . $courseid);
} else {
print_error('courseapprovedfailed');
}
}
/// Process rejection of a course.
if (!empty($reject)) {
/// Load the request.
if (!$course = $DB->get_record('course_request', array('id' => $reject))) {
print_error('unknowncourserequest');
}
/// Prepare the form.
$rejectform = new reject_request_form($baseurl);
$default = new stdClass();
$default->reject = $reject;
$rejectform->set_data($default);
/// Standard form processing if statement.
if ($rejectform->is_cancelled()){
redirect($baseurl);
} else if ($data = $rejectform->get_data()) {
/// Send an email to the requester.
$user = $DB->get_record('user', array('id' => $course->requester));
$eventdata = new object();
$eventdata->modulename = 'moodle';
$eventdata->component = 'course';
$eventdata->name = 'courserequestrejected';
$eventdata->userfrom = $USER;
$eventdata->userto = $user;
$eventdata->subject = get_string('courserejectsubject');
$eventdata->fullmessage = get_string('courserejectemail', 'moodle', $data->rejectnotice);
$eventdata->fullmessageformat = FORMAT_PLAIN;
$eventdata->fullmessagehtml = '';
$eventdata->smallmessage = '';
events_trigger('message_send', $eventdata);
/// Delete the request
$DB->delete_records('course_request', array('id' => $course->id));
/// Redirect back to the course listing.
redirect($baseurl, get_string('courserejected'));
}
/// Display the form for giving a reason for rejecting the request.
admin_externalpage_print_header($rejectform->focus());
$rejectform->display();
admin_externalpage_print_footer();
exit;
}
/// Print a list of all the pending requests.
admin_externalpage_print_header();
$pending = $DB->get_records('course_request');
if (empty($pending)) {
print_heading(get_string('nopendingcourses'));
} else {
print_heading(get_string('coursespending'));
/// Build a table of all the requests.
$table->class = 'pendingcourserequests generaltable';
$table->align = array('center', 'center', 'center', 'center', 'center', 'center', 'center');
$table->head = array(' ', get_string('shortname'), get_string('fullname'),
get_string('requestedby'), get_string('summary'), get_string('requestreason'), get_string('action'));
$strrequireskey = get_string('requireskey');
/// Loop over requested courses.
foreach ($pending as $course) {
$requester = $DB->get_record('user', array('id'=>$course->requester));
$row = array();
/// Check here for shortname collisions and warn about them.
if ($DB->record_exists('course', array('shortname' => $course->shortname))) {
$course->shortname .= ' [*]';
$collision = 1;
}
/// Show an enrolment key icon in the first column if applicable.
if (!empty($course->password)) {
$row[] = '<img hspace="1" alt="'.$strrequireskey.'" class="icon" src="'.$OUTPUT->old_icon_url('i/key') . '" />';
} else {
$row[] = '';
}
/// Info in the other columns.
$row[] = format_string($course->shortname);
$row[] = format_string($course->fullname);
$row[] = fullname($requester);
$row[] = format_string($course->summary);
$row[] = format_string($course->reason);
$row[] = print_single_button($baseurl, array('approve' => $course->id, 'sesskey' => sesskey()), get_string('approve'), 'get', '', true) .
print_single_button($baseurl, array('reject' => $course->id), get_string('rejectdots'), 'get', '', true);
/// Add the row to the table.
$table->data[] = $row;
}
/// Display the table.
print_table($table);
/// Message about name collisions, if necessary.
if (!empty($collision)) {
print_string('shortnamecollisionwarning');
}
}
/// Finish off the page.
print_single_button($CFG->wwwroot . '/course/index.php', array(), get_string('backtocourselisting'));
admin_externalpage_print_footer();
?>