-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdlquizzesnoq.php
More file actions
196 lines (151 loc) · 9.26 KB
/
dlquizzesnoq.php
File metadata and controls
196 lines (151 loc) · 9.26 KB
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<?php // $Id:,v 2.0 2012/05/20 16:10:00 Serafim Panov
require_once('../../config.php');
require_once('lib.php');
require_once($CFG->libdir.'/tablelib.php');
require_once($CFG->libdir.'/xmlize.php');
require_once($CFG->dirroot.'/course/moodleform_mod.php');
$id = required_param('id', PARAM_INT);
$quiz = optional_param_array('quiz', NULL, PARAM_INT);
$installall = optional_param_array('installall', NULL, PARAM_INT);
$password = optional_param('password', NULL, PARAM_CLEAN);
$second = optional_param('second', NULL, PARAM_CLEAN);
$step = optional_param('step', NULL, PARAM_CLEAN);
if (!$cm = get_coursemodule_from_id('reader', $id)) {
print_error('invalidcoursemodule');
}
if (!$course = $DB->get_record('course', array('id' => $cm->course))) {
print_error("coursemisconf");
}
if (!$reader = $DB->get_record('reader', array('id' => $cm->instance))) {
print_error('invalidcoursemodule');
}
if (!is_dir($CFG->dirroot.'/question/type/ordering')){
print_error('Ordering question type is missign. Please install it the first.');
}
require_login($course, true, $cm);
add_to_log($course->id, "reader", "Download Quizzes", "dlquizzesnoq.php?id=$id", "$cm->instance");
$readercfg = get_config('reader');
// Initialize $PAGE, compute blocks
$PAGE->set_url('/mod/reader/dlquizzesnoq.php', array('id' => $cm->id));
$title = $course->shortname . ': ' . format_string($reader->name);
$PAGE->set_title($title);
$PAGE->set_heading($course->fullname);
$PAGE->requires->js('/mod/reader/js/hide.js', true);
$PAGE->requires->js('/mod/reader/js/jquery-1.4.2.min.js', true);
$PAGE->requires->js('/mod/reader/js/dlquizzes.js');
$PAGE->requires->css('/mod/reader/css/main.css');
echo $OUTPUT->header();
if (!function_exists('file')) {
error("FILE function unavailable. ");
}
$listofpublishers = reader_curlfile("{$readercfg->reader_serverlink}/index-noq.php?a=publishers&login={$readercfg->reader_serverlogin}&password={$readercfg->reader_serverpassword}");
$listofpublishers = xmlize(reader_makexml($listofpublishers));
foreach ($listofpublishers['myxml']['#']['item'] as $listofpublisher) {
$quizzes[$listofpublisher['@']['publisher']][$listofpublisher['@']['level']][$listofpublisher['@']['id']] = $listofpublisher['#'];
$needpassword[$listofpublisher['@']['publisher']][$listofpublisher['@']['level']] = $listofpublisher['@']['needpass'];
}
$allquestionscount = 0;
$printerrormessage = false;
foreach ($quizzes as $key =>$value) {
foreach ($value as $key2 => $value2) {
foreach ($value2 as $key3 => $value3) {
$allquestionscount++;
$checkboxdatapublishersreal[$key][] = $key3;
$checkboxdatalevelsreal[$key][$key2][] = $key3;
$checkboxdatapublishers[$key][] = $allquestionscount;
$checkboxdatalevels[$key][$key2][] = $allquestionscount;
$quizzescountid[$key3] = $allquestionscount;
/* FOR LOGIN AND PASS CHECKING */
if (strstr($value3, "You should be student")) {
$printerrormessage = true;
}
}
}
}
require_once ('tabs_dl.php');
$context = get_context_instance(CONTEXT_COURSE, $course->id);
$contextmodule = get_context_instance(CONTEXT_MODULE, $cm->id);
if (!has_capability('mod/reader:manage', $contextmodule)) {
error("You should be \"Edit\" Teacher");
}
if ($installall) {
foreach ((array)$installall as $installall_) {
$installalldata = explode (",", $installall_);
foreach ($installalldata as $installalldata_) {
if (!empty($installalldata_)) {
$quiz[] = $installalldata_;
}
}
}
$quiz = array_unique($quiz);
}
echo $OUTPUT->box_start('generalbox');
/* FOR LOGIN AND PASS CHECKING */
if ($printerrormessage) {
echo "{$readercfg->reader_serverlink}/index-noq.php?a=publishers&login={$readercfg->reader_serverlogin}&password={$readercfg->reader_serverpassword} <br />";
error(" In order to download quizzes, you need to be registered on the \"Moodle Reader Users\" course on MoodleReader.org ( <a href=\"http://moodlereader.org/moodle/course/view.php?id=15\">http://moodlereader.org/moodle/course/view.php?id=15</a> ), Please contact the system administrator ( admin@moodlereader.org ) to register yourself, providing information on your school, your position, the grade level of your students and the approximate number of students who will be using the system.");
echo $OUTPUT->box_end();
die();
}
echo $OUTPUT->box_start('generalbox');
$o = "";
$o .= html_writer::start_tag('form', array('action'=>new moodle_url('/mod/reader/dlquizzes_proccess-noq.php', array('id'=>$id)), 'method'=>'post', 'id'=>'mform1'));
$o .= html_writer::start_tag('div', array('class'=>'w-600'));
$o .= html_writer::link('#', 'Show All', array('onclick'=>'myexpandall();return false;'));
$o .= ' / ';
$o .= html_writer::link('#', 'Hide All', array('onclick'=>'mycollapseall();return false;'));
$o .= html_writer::empty_tag('br');
$cp = 0;
if ($quizzes) {
foreach ($quizzes as $publiher => $datas) {
$cp++;
$o .= html_writer::empty_tag('br');
$o .= html_writer::start_tag('a', array('href'=>'#','onclick'=>'mytoggle(\'comments_'.$cp.'\');return false'));
$o .= html_writer::start_tag('span', array('id'=>'comments_'.$cp.'indicator'));
$o .= html_writer::empty_tag('img', array('src'=>$reader_images['open'], 'alt'=>'Opened folder'));
$o .= html_writer::end_tag('span');
$o .= html_writer::end_tag('a');
$o .= html_writer::tag('b', $publiher, array('class'=>'dl-title'));
$o .= html_writer::start_tag('span', array('id'=>'comments_'.$cp));
$o .= html_writer::empty_tag('input', array('type'=>'checkbox', 'name'=>'installall['.$cp.']', 'onclick'=>'setChecked(this,'.$checkboxdatapublishers[$publiher][0].','.end($checkboxdatapublishers[$publiher]).')', 'value'=>''));
$o .= html_writer::tag('span', 'Install All', array('id'=>'seltext_'.$cp, 'class'=>'ml-10'));
foreach ($datas as $level => $quizzesdata) {
$cp++;
$o .= html_writer::start_tag('div', array('class'=>'dl-page-box1'));
$o .= html_writer::start_tag('a', array('href'=>'#', 'onclick'=>'mytoggle(\'comments_'.$cp.'\');return false'));
$o .= html_writer::start_tag('span', array('id'=>'comments_'.$cp.'indicator'));
$o .= html_writer::empty_tag('img', array('src'=>$reader_images['open'], 'alt'=>'Opened folder'));
$o .= html_writer::end_tag('span');
$o .= html_writer::end_tag('a');
if ($needpassword[$publiher][$level] == "true") {
$o .= html_writer::empty_tag('img', array('src'=>$reader_images['pw'], 'width'=>'23', 'height'=>'15', 'alt'=>'Need password'));
}
$o .= html_writer::tag('b', $level, array('class'=>'dl-title'));
$o .= html_writer::start_tag('span', array('id'=>'comments_'.$cp));
$o .= html_writer::empty_tag('input', array('type'=>'checkbox', 'name'=>'installall['.$cp.']', 'onclick'=>'setChecked(this,'.$checkboxdatalevels[$publiher][$level][0].','.end($checkboxdatalevels[$publiher][$level]).')', 'value'=>''));
$o .= html_writer::tag('span', 'Install All', array('id'=>'seltext_'.$cp, 'class'=>'ml-10'));
$o .= html_writer::tag('div', '', array('class'=>'mt-10'));
foreach ($quizzesdata as $quizid => $quiztitle) {
$o .= html_writer::start_tag('div', array('class'=>'pl-20'));
$o .= html_writer::empty_tag('input', array('type'=>'checkbox', 'name'=>'quiz[]', 'id'=>'quiz_'.$quizzescountid[$quizid], 'value'=>$quizid));
$o .= html_writer::tag('span', $quiztitle, array('class'=>'ml-10'));
$o .= html_writer::end_tag('div');
}
$o .= html_writer::end_tag('span');
$o .= html_writer::end_tag('div');
}
$o .= html_writer::end_tag('span');
}
$o .= html_writer::start_tag('div', array('class'=>'dl-page-install'));
$o .= html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'downloadquizzes', 'value'=>'Install Quizzes'));
$o .= html_writer::end_tag('div');
}
$o .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'step', 'value'=>'1'));
$o .= html_writer::end_tag('div');
$o .= html_writer::end_tag('form');
echo $o;
echo $OUTPUT->box_end();
echo $OUTPUT->box_end();
if (isset($cp))
echo html_writer::script('var vh_numspans = '.$cp.';mycollapseall(vh_numspans);');
echo $OUTPUT->footer();