allnotes_ajax.php
1.14 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
<?php
define('AJAX_SCRIPT', true);
define('NO_DEBUG_DISPLAY', true);
require_once('../../config.php');
require_once($CFG->dirroot . '/blocks/mynotes/lib.php');
require_login ();
$context = context_system::instance ();
$PAGE->set_context ( $context );
$action = optional_param('action', '', PARAM_ALPHA);
$PAGE->requires->js_call_amd('block_mynotes/script', 'init');
$PAGE->set_url('/blocks/mynotes/allnotes_ajax.php');
switch ($action){
case 'edit':
$noteid = required_param('noteid', PARAM_INT);
$notes = required_param('newnotes', PARAM_TEXT);
$manager = new block_mynotes_manager();
if ($manager->edit($noteid,$notes)) {
echo json_encode(array('result' => "successfully updated"));
}else{
echo json_encode(array('error' => 'Unable to update edited note'));
}
die();
break;
case 'delete':
$noteid = required_param('noteid', PARAM_INT);
$manager = new block_mynotes_manager();
// $noteid=547;
if ($manager->delete($noteid)) {
echo json_encode(array('noteid' => $noteid, 'result' => "deleted"));
}
else {
echo json_encode(array('error' => 'Unable to delete note'));
}
die();
break;
}
die();