1a1a3b679SAndreas Boehler<?php 2a1a3b679SAndreas Boehler 3a1a3b679SAndreas Boehlerif(!defined('DOKU_INC')) die(); 4a1a3b679SAndreas Boehler 5a1a3b679SAndreas Boehlerclass action_plugin_davcal_ajax extends DokuWiki_Action_Plugin { 6a1a3b679SAndreas Boehler 7a1a3b679SAndreas Boehler /** 8a1a3b679SAndreas Boehler * @var helper_plugin_publish 9a1a3b679SAndreas Boehler */ 10a1a3b679SAndreas Boehler private $hlp = null; 11a1a3b679SAndreas Boehler 12a1a3b679SAndreas Boehler function __construct() { 13a1a3b679SAndreas Boehler $this->hlp =& plugin_load('helper','davcal'); 14a1a3b679SAndreas Boehler } 15a1a3b679SAndreas Boehler 16a1a3b679SAndreas Boehler function register(Doku_Event_Handler $controller) { 17a1a3b679SAndreas Boehler $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'handle_ajax_call_unknown'); 18a1a3b679SAndreas Boehler } 19a1a3b679SAndreas Boehler 20a1a3b679SAndreas Boehler function handle_ajax_call_unknown(&$event, $param) { 21a1a3b679SAndreas Boehler if($event->data != 'plugin_davcal') return; 22a1a3b679SAndreas Boehler 23a1a3b679SAndreas Boehler $event->preventDefault(); 24a1a3b679SAndreas Boehler $event->stopPropagation(); 25a1a3b679SAndreas Boehler global $INPUT; 26a1a3b679SAndreas Boehler 27a1a3b679SAndreas Boehler $action = trim($INPUT->post->str('action')); 28a1a3b679SAndreas Boehler $id = trim($INPUT->post->str('id')); 29a1a3b679SAndreas Boehler $params = $INPUT->post->arr('params'); 30a1a3b679SAndreas Boehler $user = $_SERVER['REMOTE_USER']; 31a1a3b679SAndreas Boehler $write = false; 32a1a3b679SAndreas Boehler 33a1a3b679SAndreas Boehler $data = array(); 34a1a3b679SAndreas Boehler 35a1a3b679SAndreas Boehler $data['result'] = false; 36a1a3b679SAndreas Boehler $data['html'] = $this->getLang('unknown_error'); 37a1a3b679SAndreas Boehler 38a1a3b679SAndreas Boehler $acl = auth_quickaclcheck($id); 39a1a3b679SAndreas Boehler if($acl > AUTH_READ) 40a1a3b679SAndreas Boehler { 41a1a3b679SAndreas Boehler $write = true; 42a1a3b679SAndreas Boehler } 43a1a3b679SAndreas Boehler 44a1a3b679SAndreas Boehler switch($action) 45a1a3b679SAndreas Boehler { 46a1a3b679SAndreas Boehler case 'newEvent': 47a1a3b679SAndreas Boehler if($write) 48a1a3b679SAndreas Boehler { 49a1a3b679SAndreas Boehler $data['result'] = true; 50a1a3b679SAndreas Boehler $data['html'] = $this->getLang('event_added'); 51a1a3b679SAndreas Boehler $this->hlp->addCalendarEntryToCalendarForPage($id, $user, $params); 52a1a3b679SAndreas Boehler } 53a1a3b679SAndreas Boehler else 54a1a3b679SAndreas Boehler { 55a1a3b679SAndreas Boehler $data['result'] = false; 56a1a3b679SAndreas Boehler $data['html'] = $this->getLang('no_permission'); 57a1a3b679SAndreas Boehler } 58a1a3b679SAndreas Boehler break; 59a1a3b679SAndreas Boehler case 'getEvents': 60a1a3b679SAndreas Boehler $startDate = $INPUT->post->str('start'); 61a1a3b679SAndreas Boehler $endDate = $INPUT->post->str('end'); 62a1a3b679SAndreas Boehler $data = $this->hlp->getEventsWithinDateRange($id, $user, $startDate, $endDate); 63a1a3b679SAndreas Boehler 64a1a3b679SAndreas Boehler break; 65a1a3b679SAndreas Boehler case 'editEvent': 66a1a3b679SAndreas Boehler if($write) 67a1a3b679SAndreas Boehler { 68a1a3b679SAndreas Boehler $data['result'] = true; 69a1a3b679SAndreas Boehler $data['html'] = $this->getLang('event_edited'); 70a1a3b679SAndreas Boehler $this->hlp->editCalendarEntryForPage($id, $user, $params); 71a1a3b679SAndreas Boehler } 72a1a3b679SAndreas Boehler else 73a1a3b679SAndreas Boehler { 74a1a3b679SAndreas Boehler $data['result'] = false; 75a1a3b679SAndreas Boehler $data['html'] = $this->getLang('no_permission'); 76a1a3b679SAndreas Boehler } 77a1a3b679SAndreas Boehler break; 78a1a3b679SAndreas Boehler case 'deleteEvent': 79a1a3b679SAndreas Boehler if($write) 80a1a3b679SAndreas Boehler { 81a1a3b679SAndreas Boehler $data['result'] = true; 82a1a3b679SAndreas Boehler $data['html'] = $this->getLang('event_deleted'); 83a1a3b679SAndreas Boehler $this->hlp->deleteCalendarEntryForPage($id, $params); 84a1a3b679SAndreas Boehler } 85a1a3b679SAndreas Boehler else 86a1a3b679SAndreas Boehler { 87a1a3b679SAndreas Boehler $data['result'] = false; 88a1a3b679SAndreas Boehler $data['html'] = $this->getLang('no_permission'); 89a1a3b679SAndreas Boehler } 90a1a3b679SAndreas Boehler break; 91*a495d34cSAndreas Boehler case 'getSettings': 92*a495d34cSAndreas Boehler $data['result'] = true; 93*a495d34cSAndreas Boehler $data['settings'] = $this->hlp->getPersonalSettings($user); 94*a495d34cSAndreas Boehler break; 95*a495d34cSAndreas Boehler case 'saveSettings': 96*a495d34cSAndreas Boehler $settings = array(); 97*a495d34cSAndreas Boehler $settings['weeknumbers'] = $params['weeknumbers']; 98*a495d34cSAndreas Boehler $settings['timezone'] = $params['timezone']; 99*a495d34cSAndreas Boehler $settings['workweek'] = $params['workweek']; 100*a495d34cSAndreas Boehler if($this->hlp->savePersonalSettings($settings, $user)) 101*a495d34cSAndreas Boehler { 102*a495d34cSAndreas Boehler $data['result'] = true; 103*a495d34cSAndreas Boehler $data['html'] = $this->getLang('settings_saved'); 104*a495d34cSAndreas Boehler } 105*a495d34cSAndreas Boehler else 106*a495d34cSAndreas Boehler { 107*a495d34cSAndreas Boehler $data['result'] = false; 108*a495d34cSAndreas Boehler $data['html'] = $this->getLang('error_saving'); 109*a495d34cSAndreas Boehler } 110*a495d34cSAndreas Boehler break; 111a1a3b679SAndreas Boehler } 112a1a3b679SAndreas Boehler 113a1a3b679SAndreas Boehler 114a1a3b679SAndreas Boehler 115a1a3b679SAndreas Boehler 116a1a3b679SAndreas Boehler // If we are still here, JSON output is requested 117a1a3b679SAndreas Boehler 118a1a3b679SAndreas Boehler //json library of DokuWiki 119a1a3b679SAndreas Boehler require_once DOKU_INC . 'inc/JSON.php'; 120a1a3b679SAndreas Boehler $json = new JSON(); 121a1a3b679SAndreas Boehler 122a1a3b679SAndreas Boehler //set content type 123a1a3b679SAndreas Boehler header('Content-Type: application/json'); 124a1a3b679SAndreas Boehler echo $json->encode($data); 125a1a3b679SAndreas Boehler } 126a1a3b679SAndreas Boehler 127a1a3b679SAndreas Boehler}