forked from Syxton/moodle-tool_coursearchiver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstep3.php
124 lines (105 loc) · 4.92 KB
/
step3.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
<?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 3(Selected users).
*
* @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);
$mode = optional_param('mode', false, PARAM_INT);
$error = optional_param('error', false, PARAM_RAW);
$selected = optional_param_array('user_selected', array(), PARAM_RAW);
$submitted = optional_param('submit_button', false, PARAM_RAW);
if (!empty($submitted)) { // 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);
}
// Clean selected course array.
$users = array();
foreach ($selected as $c) {
if (!empty($c)) {
$users[] = $c;
}
}
// Fully develope array.
$owners = array();
foreach ($users 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 (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);
}
switch($submitted){
case get_string('hideemail', 'tool_coursearchiver'):
$mode = tool_coursearchiver_processor::MODE_HIDEEMAIL;
$returnurl = new moodle_url('/admin/tool/coursearchiver/step4.php',
array("mode" => $mode, "formdata" => serialize($users)));
redirect($returnurl);
break;
case get_string('archiveemail', 'tool_coursearchiver'):
$mode = tool_coursearchiver_processor::MODE_ARCHIVEEMAIL;
$returnurl = new moodle_url('/admin/tool/coursearchiver/step4.php',
array("mode" => $mode, "formdata" => serialize($users)));
redirect($returnurl);
break;
default:
$returnurl = new moodle_url('/admin/tool/coursearchiver/index.php',
array("error" => get_string('unknownerror', 'tool_coursearchiver')));
redirect($returnurl);
}
} else if (!empty($formdata)) { // FORM 2 SUBMITTED, SHOW FORM 3.
$courses = unserialize($formdata);
// Check again to make sure courses are coming across correctly.
if (!is_array($courses) || empty($courses)) {
$returnurl = new moodle_url('/admin/tool/coursearchiver/step1.php',
array("error" => get_string('nocoursesselected', 'tool_coursearchiver')));
redirect($returnurl);
}
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" => tool_coursearchiver_processor::MODE_GETEMAILS, "courses" => $courses);
$mform = new tool_coursearchiver_step3_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);
}