-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathajax.php
103 lines (97 loc) · 4.16 KB
/
ajax.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
<?php
// This file is part of 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/>.
/**
* Process ajax requests.
*
* @package mod_icontent
* @copyright 2016 Leo Renis Santos
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once("../../config.php");
require_once('lib.php');
if (!defined('AJAX_SCRIPT')) {
define('AJAX_SCRIPT', true);
}
$id = required_param('id', PARAM_INT);
$action = optional_param('action', '', PARAM_ALPHA);
$sesskey = optional_param('sesskey', false, PARAM_TEXT);
if ($id) {
$cm = get_coursemodule_from_id('icontent', $id, 0, false, MUST_EXIST);
$course = $DB->get_record('course', ['id' => $cm->course], '*', MUST_EXIST);
$icontent = $DB->get_record('icontent', ['id' => $cm->instance], '*', MUST_EXIST);
} else if ($n) {
$icontent = $DB->get_record('icontent', ['id' => $n], '*', MUST_EXIST);
$course = $DB->get_record('course', ['id' => $icontent->course], '*', MUST_EXIST);
$cm = get_coursemodule_from_instance('icontent', $icontent->id, $course->id, false, MUST_EXIST);
} else {
throw new moodle_exception(get_string('incorrectmodule', 'icontent'));
}
require_sesskey();
$context = context_module::instance($cm->id);
require_login($course, true, $cm);
// Check actions.
$return = false;
switch ($action) {
case 'loadpage':
require_capability('mod/icontent:view', $context);
$pagenum = required_param('pagenum', PARAM_INT);
$return = icontent_ajax_getpage($pagenum, $icontent, $context);
break;
// Save and return records table {pages_notes}.
case 'savereturnpagenotes':
require_capability('mod/icontent:viewnotes', $context);
$pageid = required_param('pageid', PARAM_INT);
$note = new stdClass;
$note->comment = required_param('comment', PARAM_CLEANHTML);
$note->cmid = required_param('id', PARAM_INT);
$note->featured = required_param('featured', PARAM_INT);
$note->private = required_param('private', PARAM_INT);
$note->doubttutor = required_param('doubttutor', PARAM_INT);
$note->tab = required_param('tab', PARAM_ALPHANUMEXT);
// Prepare return.
$return = icontent_ajax_savereturnnotes($pageid, $note, $icontent);
break;
case 'likenote':
require_capability('mod/icontent:likenotes', $context);
$notelike = new stdClass;
$notelike->pagenoteid = required_param('pagenoteid', PARAM_INT);
$notelike->cmid = required_param('id', PARAM_INT);
$return = icontent_ajax_likenote($notelike, $icontent);
break;
case 'editnote':
require_capability('mod/icontent:editnotes', $context);
$pagenote = new stdClass;
$pagenote->id = required_param('pagenoteid', PARAM_INT);
$pagenote->cmid = required_param('id', PARAM_INT);
$pagenote->comment = required_param('comment', PARAM_CLEANHTML);
$return = icontent_ajax_editnote($pagenote, $icontent);
break;
case 'replynote':
require_capability('mod/icontent:replynotes', $context);
$pagenote = new stdClass;
$pagenote->parent = required_param('parent', PARAM_INT);
$pagenote->cmid = required_param('id', PARAM_INT);
$pagenote->comment = required_param('comment', PARAM_CLEANHTML);
$return = icontent_ajax_replynote($pagenote, $icontent);
break;
case 'saveattempt':
require_capability('mod/icontent:view', $context);
$formdata = required_param('formdata', PARAM_RAW);
$return = icontent_ajax_saveattempt($formdata, $cm, $icontent);
break;
}
echo json_encode($return);
die;