allnotes_ajax.php 1.14 KB
<?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();