-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.php
149 lines (118 loc) · 5.41 KB
/
index.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
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle 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 3 of the License, or
// (at your option) any later version.
//
// Moodle 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.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Requests page in local_extension. Providing a filter and search for requests.
*
* @package local_extension
* @author Nicholas Hoobin <[email protected]>
* @copyright Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use local_extension\access\capability_checker;
use local_extension\form\preferences_form;
use local_extension\preferences;
require_once(__DIR__ . '/../../config.php');
if ($CFG->branch < 35) {
require_once($CFG->libdir . '/coursecatlib.php');
}
$defaultcategoryid = get_config('local_extension', 'defaultcategory');
$categoryid = optional_param('catid', $defaultcategoryid, PARAM_INT);
$courseid = optional_param('id', 0, PARAM_INT);
$stateid = optional_param('state', 0, PARAM_INT);
$search = optional_param('search', '', PARAM_RAW); // Make sure it is processed with p() or s() when sending to output!
$faculty = optional_param('faculty', '', PARAM_RAW); // Make sure it is processed with p() or s() when sending to output!
$download = optional_param('download', '', PARAM_ALPHA);
require_login(null, false);
$PAGE->set_url('/local/extension/index.php', []);
if ($courseid) {
$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
$context = context_course::instance($course->id, MUST_EXIST);
} else {
$courseid = SITEID;
$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
$context = context_user::instance($USER->id, MUST_EXIST);
}
$checkcontext = $categoryid ? context_coursecat::instance($categoryid) : null;
$viewallrequests = capability_checker::can_view_all_requests($checkcontext);
if (!$viewallrequests) {
// The user cannot view all requests or select the categories.
$categoryid = 0;
}
$systemcontext = context_system::instance();
$isfrontpage = ($course->id == SITEID);
$frontpagectx = context_course::instance(SITEID);
$PAGE->set_context($systemcontext);
$PAGE->set_pagelayout('standard');
$PAGE->set_title(get_string('pluginname', 'local_extension'));
$PAGE->set_heading(get_string('page_heading_index', 'local_extension'));
$PAGE->requires->css('/local/extension/styles.css');
$PAGE->add_body_class('local_extension');
$PAGE->navbar->ignore_active();
$PAGE->navbar->add(get_string('breadcrumb_nav_index', 'local_extension'), new moodle_url('/local/extension/index.php'));
/* @var \local_extension_renderer $renderer IDE hinting */
$renderer = $PAGE->get_renderer('local_extension');
// Should use this variable so that we don't break stuff every time a variable is added or changed.
$baseurl = new moodle_url('/local/extension/index.php', array(
'id' => $courseid,
'catid' => $categoryid,
'state' => $stateid,
'search' => s($search),
'faculty' => s($faculty),
));
// If the user can view all requests, display the administrator table.
if ($viewallrequests) {
$table = new \local_extension\local\table\requests\administrator($baseurl, null, (bool)$download);
} else {
$table = new \local_extension\local\table\requests\student($baseurl, null, (bool)$download);
}
$table->generate_query($categoryid, $courseid, $stateid, $search, $faculty);
$table->is_downloading($download, 'AES_export', 'AES_export');
if (!$table->is_downloading()) {
echo $OUTPUT->header();
// New filter functionality, searching and listing of requests.
echo $renderer->render_index_search_controls($context, $categoryid, $courseid, $stateid, $baseurl, $search, $faculty);
// Query database here to see whether to display the download csv button.
// We perform two queries rather than override the out() function in the administrator and student classes.
$table->setup();
$table->query_db(30, false);
// Only display export csv button if there is data.
if (((new preferences)->get(preferences::EXPORT_CSV)) == '1' && count($table->rawdata) > 0) {
$url = clone $baseurl;
$url->param('download', 'csv');
echo html_writer::div(
$OUTPUT->single_button($url, get_string('export_csv', 'local_extension')),
'local_extension_option_buttons'
);
}
echo html_writer::div(
$OUTPUT->single_button(
'/local/extension/preferences.php',
get_string('preferences', 'local_extension')
),
'local_extension_option_buttons'
);
echo html_writer::tag('h2', get_string('page_h2_summary', 'local_extension'));
}
$table->out(30, false);
if (!$table->is_downloading()) {
echo html_writer::empty_tag('br');
if ($courseid == SITEID) {
$courseid = 0;
}
$url = new moodle_url("/local/extension/request.php", ['course' => $courseid]);
echo $OUTPUT->single_button($url, get_string('button_request_extension', 'local_extension'));
echo $OUTPUT->footer();
}