course/approval.php MDL-25589 Table misaligned
[moodle.git] / course / pending.php
CommitLineData
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
8bdc9cac
SH
33require_once(dirname(__FILE__) . '/../config.php');
34require_once($CFG->libdir . '/adminlib.php');
35require_once($CFG->dirroot . '/course/lib.php');
36require_once($CFG->dirroot . '/course/request_form.php');
0705ff84 37
8bdc9cac
SH
38require_login();
39require_capability('moodle/site:approvecourse', get_context_instance(CONTEXT_SYSTEM));
0705ff84 40
8bdc9cac
SH
41$approve = optional_param('approve', 0, PARAM_INT);
42$reject = optional_param('reject', 0, PARAM_INT);
0705ff84 43
8bdc9cac
SH
44$baseurl = $CFG->wwwroot . '/course/pending.php';
45admin_externalpage_setup('coursespending');
77eddcd5 46
47/// Process approval of a course.
8bdc9cac 48if (!empty($approve) and confirm_sesskey()) {
77eddcd5 49 /// Load the request.
8bdc9cac
SH
50 $course = new course_request($approve);
51 $courseid = $course->approve();
77eddcd5 52
8bdc9cac
SH
53 if ($courseid !== false) {
54 redirect($CFG->wwwroot.'/course/edit.php?id=' . $courseid);
55 } else {
56 print_error('courseapprovedfailed');
0705ff84 57 }
8bdc9cac 58}
0be6f678 59
77eddcd5 60/// Process rejection of a course.
8bdc9cac
SH
61if (!empty($reject)) {
62 // Load the request.
63 $course = new course_request($reject);
0705ff84 64
8bdc9cac
SH
65 // Prepare the form.
66 $rejectform = new reject_request_form($baseurl);
67 $default = new stdClass();
68 $default->reject = $course->id;
69 $rejectform->set_data($default);
0be6f678 70
8bdc9cac
SH
71/// Standard form processing if statement.
72 if ($rejectform->is_cancelled()){
73 redirect($baseurl);
77eddcd5 74
8bdc9cac 75 } else if ($data = $rejectform->get_data()) {
77eddcd5 76
8bdc9cac
SH
77 /// Reject the request
78 $course->reject($data->rejectnotice);
79
80 /// Redirect back to the course listing.
81 redirect($baseurl, get_string('courserejected'));
77eddcd5 82 }
83
8bdc9cac 84/// Display the form for giving a reason for rejecting the request.
61ef8f9f 85 echo $OUTPUT->header($rejectform->focus());
8bdc9cac
SH
86 $rejectform->display();
87 echo $OUTPUT->footer();
88 exit;
89}
77eddcd5 90
8bdc9cac 91/// Print a list of all the pending requests.
61ef8f9f 92echo $OUTPUT->header();
8bdc9cac
SH
93
94$pending = $DB->get_records('course_request');
95if (empty($pending)) {
96 echo $OUTPUT->heading(get_string('nopendingcourses'));
97} else {
98 echo $OUTPUT->heading(get_string('coursespending'));
99
100/// Build a table of all the requests.
101 $table = new html_table();
16be8974 102 $table->attributes['class'] = 'pendingcourserequests generaltable';
8bdc9cac 103 $table->align = array('center', 'center', 'center', 'center', 'center', 'center', 'center');
b5a49647 104 $table->head = array(get_string('shortname'), get_string('fullname'),
8bdc9cac 105 get_string('requestedby'), get_string('summary'), get_string('requestreason'), get_string('action'));
aa6c1ced 106
8bdc9cac
SH
107 foreach ($pending as $course) {
108 $course = new course_request($course);
aa6c1ced 109
8bdc9cac
SH
110 // Check here for shortname collisions and warn about them.
111 $course->check_shortname_collision();
112
113 $row = array();
8bdc9cac
SH
114 $row[] = format_string($course->shortname);
115 $row[] = format_string($course->fullname);
116 $row[] = fullname($course->get_requester());
117 $row[] = $course->summary;
118 $row[] = format_string($course->reason);
5c2ed7e2
PS
119 $row[] = $OUTPUT->single_button(new moodle_url($baseurl, array('approve' => $course->id, 'sesskey' => sesskey())), get_string('approve'), 'get') .
120 $OUTPUT->single_button(new moodle_url($baseurl, array('reject' => $course->id)), get_string('rejectdots'), 'get');
8bdc9cac
SH
121
122 /// Add the row to the table.
123 $table->data[] = $row;
124 }
77eddcd5 125
8bdc9cac 126/// Display the table.
16be8974 127 echo html_writer::table($table);
77eddcd5 128
8bdc9cac
SH
129/// Message about name collisions, if necessary.
130 if (!empty($collision)) {
131 print_string('shortnamecollisionwarning');
0705ff84 132 }
8bdc9cac 133}
0705ff84 134
77eddcd5 135/// Finish off the page.
5c2ed7e2 136echo $OUTPUT->single_button($CFG->wwwroot . '/course/index.php', get_string('backtocourselisting'));
16be8974 137echo $OUTPUT->footer();