-
Notifications
You must be signed in to change notification settings - Fork 3
/
ajax_setstate.php
82 lines (64 loc) · 2.49 KB
/
ajax_setstate.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
<?php
// This file is part of block_semester_sortierung for Moodle - http://moodle.org/
//
// 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/>.
/**
* This file updates the user_preference for the block boxes' status
*
* @package block_semester_sortierung
* @author Andreas Hruska ([email protected])
* @author Katarzyna Potocka ([email protected])
* @author Simeon Naydenov ([email protected])
* @copyright 2014 Academic Moodle Cooperation {@link http://www.academic-moodle-cooperation.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define('AJAX_SCRIPT', true);
require_once(__DIR__ . '/../../config.php');
require_once(__DIR__ . '/locallib.php');
$boxid = required_param('id', PARAM_ALPHANUM);
$state = required_param('state', PARAM_INT);
$courseajax = optional_param('ajax', 0, PARAM_INT);
$boxtype = required_param('boxtype', PARAM_ALPHA);
require_login();
if ($boxtype == 's') {
$prefname = 'semester_sortierung_semesters';
} else {
$prefname = 'semester_sortierung_courses';
}
if ($expanded = get_user_preferences($prefname, '')) {
$expanded = explode(',', $expanded);
$expanded = array_flip($expanded);
} else {
$expanded = array();
}
if ($state) {
$expanded[$boxid] = 1;
} else {
if (isset($expanded[$boxid])) {
unset($expanded[$boxid]);
}
}
$expanded = implode(',', array_keys($expanded));
set_user_preference($prefname, $expanded);
if ($boxtype == 'c' && $courseajax) {
$cid = $boxid;
$courses = $DB->get_records('course', array('id' => $cid));
if (count($courses) > 0) {
$PAGE->set_context(\context_course::instance($cid));
$output = $PAGE->get_renderer('block_semester_sortierung');
$expandedevents = block_semester_sortierung_get_courses_events($courses, $output);
echo $output->header();
echo $output->render_course_info($cid, $expandedevents);
}
}