forked from Syxton/moodle-tool_coursearchiver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstep4.php
140 lines (122 loc) · 6.62 KB
/
step4.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
<?php
// This file is part of
//
// 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/>.
/**
* Step 4(Confirmation and Action).
*
* @package tool_coursearchiver
* @copyright 2015 Matthew Davidson
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define('NO_OUTPUT_BUFFERING', true);
require(__DIR__ . '/../../../config.php');
require_once($CFG->libdir . '/adminlib.php');
require_login();
admin_externalpage_setup('toolcoursearchiver');
$formdata = optional_param('formdata', false, PARAM_RAW);
$error = optional_param('error', false, PARAM_RAW);
$submitted = optional_param('submit_button', false, PARAM_RAW);
$mode = optional_param('mode', false, PARAM_INT);
$folder = optional_param('folder', false, PARAM_TEXT);
if (!empty($submitted) && !empty($formdata) && !empty($mode)) { // FORM 3 SUBMITTED.
if ($submitted == get_string('back', 'tool_coursearchiver')) { // Button to start over has been pressed.
$returnurl = new moodle_url('/admin/tool/coursearchiver/index.php');
redirect($returnurl);
}
if (!empty($error)) {
echo $OUTPUT->container($error, 'coursearchiver_myformerror');
}
if ($submitted == get_string('confirm', 'tool_coursearchiver')) {
if (!isset($mode) || !in_array($mode, array(tool_coursearchiver_processor::MODE_HIDE,
tool_coursearchiver_processor::MODE_ARCHIVE,
tool_coursearchiver_processor::MODE_HIDEEMAIL,
tool_coursearchiver_processor::MODE_ARCHIVEEMAIL))) {
throw new coding_exception('Unknown process mode');
}
switch($mode){
case tool_coursearchiver_processor::MODE_HIDEEMAIL:
case tool_coursearchiver_processor::MODE_ARCHIVEEMAIL:
header('X-Accel-Buffering: no');
echo $OUTPUT->header();
echo $OUTPUT->heading_with_help(get_string('coursearchiver', 'tool_coursearchiver'),
'coursearchiver',
'tool_coursearchiver');
$selected = unserialize($formdata);
$owners = array();
foreach ($selected as $s) {
$t = explode("_", $s);
if (count($t) == 2) { // Both a course and an owner are needed.
if (array_key_exists($t[1], $owners)) {
$temp = $owners[$t[1]]['courses'];
$owners[$t[1]]['courses'] = array_merge($temp, array($t[0] => get_course($t[0])));
} else {
$owners[$t[1]]['courses'] = array($t[0] => get_course($t[0]));
$owners[$t[1]]['user'] = $DB->get_record("user", array("id" => $t[1]));
}
}
}
if (!is_array($owners) || empty($owners)) { // If 0 courses are selected, show message and form again.
$returnurl = new moodle_url('/admin/tool/coursearchiver/step3.php',
array("formdata" => $formdata,
"error" => get_string('nousersselected', 'tool_coursearchiver')));
redirect($returnurl);
}
$processor = new tool_coursearchiver_processor(array("mode" => $mode, "data" => $owners));
$processor->execute(tool_coursearchiver_tracker::OUTPUT_HTML);
echo $OUTPUT->footer();
break;
case tool_coursearchiver_processor::MODE_HIDE:
case tool_coursearchiver_processor::MODE_ARCHIVE:
header('X-Accel-Buffering: no');
echo $OUTPUT->header();
echo $OUTPUT->heading_with_help(get_string('coursearchiver', 'tool_coursearchiver'),
'coursearchiver',
'tool_coursearchiver');
$courses = unserialize($formdata);
if (!is_array($courses) || empty($courses)) { // If 0 courses are selected, show message and form again.
$returnurl = new moodle_url('/admin/tool/coursearchiver/step2.php',
array("formdata" => $formdata,
"error" => get_string('nocoursesselected', 'tool_coursearchiver')));
redirect($returnurl);
}
$processor = new tool_coursearchiver_processor(array("mode" => $mode, "data" => $courses));
if (!empty($folder)) {
$processor->folder = $folder;
}
$processor->execute(tool_coursearchiver_tracker::OUTPUT_HTML, null);
echo $OUTPUT->footer();
break;
default:
$returnurl = new moodle_url('/admin/tool/coursearchiver/index.php',
array("error" => get_string('unknownerror', 'tool_coursearchiver')));
redirect($returnurl);
}
}
} else if (!empty($formdata) && !empty($mode)) { // FORM 3 SUBMITTED, SHOW FORM 4.
header('X-Accel-Buffering: no');
echo $OUTPUT->header();
echo $OUTPUT->heading_with_help(get_string('coursearchiver', 'tool_coursearchiver'), 'coursearchiver', 'tool_coursearchiver');
if (!empty($error)) {
echo $OUTPUT->container($error, 'coursearchiver_myformerror');
}
$param = array("mode" => $mode, "formdata" => $formdata);
$mform = new tool_coursearchiver_step4_form(null, array("processor_data" => $param));
$mform->display();
echo $OUTPUT->footer();
} else { // IN THE EVENT OF A FAILURE, JUST GO BACK TO THE BEGINNING.
$returnurl = new moodle_url('/admin/tool/coursearchiver/index.php',
array("error" => get_string('unknownerror', 'tool_coursearchiver')));
redirect($returnurl);
}