forked from Syxton/moodle-tool_coursearchiver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
step2.php
146 lines (127 loc) · 5.75 KB
/
step2.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
<?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 2(Search Results).
*
* @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');
header('X-Accel-Buffering: no');
require_login();
admin_externalpage_setup('toolcoursearchiver');
global $SESSION;
$formdata = isset($SESSION->formdata) ? $SESSION->formdata : optional_param('formdata', false, PARAM_RAW);
$error = isset($SESSION->error) ? $SESSION->error : optional_param('error', false, PARAM_RAW);
$resume = isset($SESSION->resume) ? $SESSION->resume : optional_param('resume', false, PARAM_RAW);
$title = optional_param('save_title', false, PARAM_TEXT);
$selected = optional_param_array('course_selected', [], PARAM_INT);
$submitted = optional_param('submit_button', false, PARAM_RAW);
unset($SESSION->formdata);
unset($SESSION->error);
unset($SESSION->resume);
tool_coursearchiver_processor::select_deselect_javascript();
if (!empty($submitted)) { // FORM 2 SUBMITTED.
if ($submitted == get_string('save', 'tool_coursearchiver')) { // Save has been pressed.
tool_coursearchiver_processor::save_state(2, $title, $selected);
$SESSION->resume = true;
$SESSION->formdata = serialize($selected);
$SESSION->error = get_string('saved', 'tool_coursearchiver');
$returnurl = new moodle_url('/admin/tool/coursearchiver/step2.php');
redirect($returnurl);
}
// Clean selected course array.
$courses = [];
foreach ($selected as $c) {
if ($c > 0) {
$courses[] = $c;
}
}
if (empty($courses)) { // If 0 courses are selected, show message and form again.
$SESSION->formdata = $formdata;
$SESSION->error = get_string('nocoursesselected', 'tool_coursearchiver');
$returnurl = new moodle_url('/admin/tool/coursearchiver/step2.php');
redirect($returnurl);
}
switch($submitted){
case get_string('email', 'tool_coursearchiver'):
$SESSION->formdata = serialize($courses);
$returnurl = new moodle_url('/admin/tool/coursearchiver/step3.php');
redirect($returnurl);
break;
case get_string('hide', 'tool_coursearchiver'):
$SESSION->mode = tool_coursearchiver_processor::MODE_HIDE;
$SESSION->formdata = serialize($courses);
$returnurl = new moodle_url('/admin/tool/coursearchiver/step4.php');
redirect($returnurl);
break;
case get_string('backup', 'tool_coursearchiver'):
$SESSION->mode = tool_coursearchiver_processor::MODE_BACKUP;
$SESSION->formdata = serialize($courses);
$returnurl = new moodle_url('/admin/tool/coursearchiver/step4.php');
redirect($returnurl);
break;
case get_string('archive', 'tool_coursearchiver'):
$SESSION->mode = tool_coursearchiver_processor::MODE_ARCHIVE;
$SESSION->formdata = serialize($courses);
$returnurl = new moodle_url('/admin/tool/coursearchiver/step4.php');
redirect($returnurl);
break;
case get_string('delete', 'tool_coursearchiver'):
$SESSION->mode = tool_coursearchiver_processor::MODE_DELETE;
$SESSION->formdata = serialize($courses);
$returnurl = new moodle_url('/admin/tool/coursearchiver/step4.php');
redirect($returnurl);
break;
case get_string('optout', 'tool_coursearchiver'):
$SESSION->mode = tool_coursearchiver_processor::MODE_OPTOUT;
$SESSION->formdata = serialize($courses);
$returnurl = new moodle_url('/admin/tool/coursearchiver/step4.php');
redirect($returnurl);
break;
default:
$SESSION->error = get_string('unknownerror', 'tool_coursearchiver');
$returnurl = new moodle_url('/admin/tool/coursearchiver/index.php');
redirect($returnurl);
}
} else if (!empty($formdata)) { // FORM 1 SUBMITTED, SHOW FORM 2.
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');
}
$data = unserialize($formdata);
if (!empty($resume)) { // Resume from save point.
$searches = $data;
$searches["resume"] = true;
} else {
$searches = [];
foreach ($data as $key => $value) {
$searches["$key"] = $value;
}
}
$param = ["mode" => tool_coursearchiver_processor::MODE_COURSELIST, "searches" => $searches];
$mform = new tool_coursearchiver_step2_form(null, ["processor_data" => $param]);
$mform->display();
echo $OUTPUT->footer();
} else { // IN THE EVENT OF A FAILURE, JUST GO BACK TO THE BEGINNING.
$SESSION->error = get_string('unknownerror', 'tool_coursearchiver');
$returnurl = new moodle_url('/admin/tool/coursearchiver/index.php');
redirect($returnurl);
}