-
Notifications
You must be signed in to change notification settings - Fork 0
/
auths.php
115 lines (102 loc) · 4.56 KB
/
auths.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
<?php
// 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/>.
/**
* OBU Forms - List all authorisations requested (excluding CSA) or just those for a given authoriser (including CSA)
*
* @package local_obu_forms
* @author Peter Welham
* @copyright 2019, Oxford Brookes University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*
*/
require_once('../../config.php');
require_once('./locallib.php');
$forms_course = local_obu_forms_get_forms_course();
require_login($forms_course);
$home = new moodle_url('/');
if (!local_obu_forms_is_manager()) {
redirect($home);
}
$dir = $home . 'local/obu_forms/';
$back = $home . 'course/view.php?id=' . $forms_course;
$authoriser_username = optional_param('authoriser', '', PARAM_TEXT);
if ($authoriser_username) {
$authoriser = get_complete_user_data('username', $authoriser_username);
$url = $dir . 'auths.php?authoriser=' . $authoriser_username;
if ($authoriser->username == 'csa') {
$heading = get_string('sc_auths', 'local_obu_forms');
$authoriser_id = $authoriser->id;
} else if ($authoriser->username == 'tpt') {
$heading = get_string('tpt_auths', 'local_obu_forms');
$authoriser_id = 0;
} else {
$heading = get_string('auths', 'local_obu_forms') . ': ' . $authoriser->firstname . ' ' . $authoriser->lastname;
$authoriser_id = $authoriser->id;
}
} else {
$authoriser = get_complete_user_data('username', 'csa'); // So that we can exclude them later
$authoriser_id = 0;
$url = $dir . 'auths.php';
$heading = get_string('auths_title', 'local_obu_forms');
}
$title = get_string('forms_management', 'local_obu_forms');
$PAGE->set_url($url);
$PAGE->set_pagelayout('standard');
$PAGE->set_title($title);
$PAGE->set_heading($title);
$PAGE->navbar->add($heading);
// The page contents
echo $OUTPUT->header();
echo $OUTPUT->heading($heading);
$process = $dir . 'process.php';
$redirect = $dir . 'redirect.php';
$auths = local_obu_forms_get_form_auths($authoriser_id); // Get outstanding authorisation requests
foreach ($auths as $auth) {
if (($authoriser_id != 0) || ($auth->authoriser != $authoriser->id)) {
local_obu_forms_read_form_data($auth->data_id, $data);
$template = local_obu_forms_read_form_template_by_id($data->template_id);
$form = local_obu_forms_read_form_settings($template->form_id);
// Check that the form type is correct for this report
if (($form->formref == 'M3') || ($form->formref == 'M200') || ($form->formref == 'M201') || ($form->formref == 'M201L') || ($form->formref == 'M300')) {
$tpt_form = true; // The responsibility of the Taught Programmes Team
} else {
$tpt_form = false;
}
if ((($authoriser->username == 'tpt') && !$tpt_form) || (($authoriser->username != 'tpt') && $tpt_form)) {
continue;
}
// Check that the user is a manager of this type of form and that it hasn't already been finally approved or rejected
if (local_obu_forms_is_manager($form) && ($data->authorisation_state == 0)) {
local_obu_forms_get_form_status($USER->id, $form, $data, $text, $button); // Get the authorisation trail and the next action (from the user's perspective)
// If a staff form, extract any given student number
$student_number = '';
if (!$form->student) {
local_obu_forms_load_form_fields($data, $fields);
if (array_key_exists('student_number', $fields)) {
$student_number = ' [' . $fields['student_number'] . ']';
}
} else if ($form->modular) {
$author = get_complete_user_data('id', $data->author);
$student_number = ' [' . $author->username . ']';
}
echo '<h4><a href="' . $process . '?source=' . urlencode('auths.php?authoriser=' . $authoriser_username) . '&id=' . $data->id . '">' . $form->formref . ': ' . $form->name . $student_number . '</a></h4>';
echo $text . '<' . $form->formref . '>';
if ($data->notes) {
echo '<h6>' . $data->notes . '</h6>';
}
if (has_capability('local/obu_forms:update', context_system::instance()) && ($authoriser_username != 'csa')) { // They can't redirect away from themselves
echo '<p><a href="' . $redirect . '?id=' . $data->id . '">' . get_string('redirect_form', 'local_obu_forms') . '</a></p>';
}
}
}
}
echo $OUTPUT->footer();