1<?php 2if(!defined('DOKU_INC')) die(); 3 4class action_plugin_kanban extends DokuWiki_Action_Plugin { 5 public function register(Doku_Event_Handler $controller) { 6 $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'handle_ajax'); 7 } 8 9 10 public function handle_started(Doku_Event $event, $param) { 11 global $JSINFO; 12 global $INPUT; 13 14 // Get the logged-in username from the REMOTE_USER environment variable 15 $user = $INPUT->server->str('REMOTE_USER'); 16 echo json_encode(['user' => $user]); 17 if($user) { 18 $JSINFO['user'] = $user; 19 } 20 } 21 22 23public function handle_ajax(Doku_Event $event, $param) { 24 if ($event->data !== 'kanban_save') return; // Must match call in JS 25 $event->preventDefault(); 26 $event->stopPropagation(); 27 28 global $INPUT, $conf; 29 $board = $INPUT->str('board'); 30 $cardId = $INPUT->str('card_id'); 31 32 // Dynamically build the path in data/kanban/ 33 $kanbanDir = '../' . '.' .$conf['savedir'] . '/kanban/' . $board . '/'; // added '../' . '.' . in the beginning path otherwise it writes to ./exe/data directory....annoying 34 if (!is_dir($kanbanDir)) io_makeFileDir($kanbanDir . 'placeholder.txt'); 35 36 echo $kanbanDir; //debugging line 37 38 $file = $kanbanDir . $cardId . '.json'; 39 40 $data = file_exists($file) ? json_decode(io_readFile($file), true) : ['id' => $cardId]; 41 42 43 //$newNote = $currNote . ' | ' . $data['note']; 44 // Update fields sent by AJAX 45 if ($INPUT->has('column')) $data['column'] = $INPUT->str('column'); 46 if ($INPUT->has('name')) $data['name'] = $INPUT->str('name'); 47 if ($INPUT->has('importance')) $data['importance'] = $INPUT->str('importance'); 48 if ($INPUT->has('desc')) $data['desc'] = $INPUT->str('desc'); 49 if ($INPUT->has('checked')) $data['checked'] = $INPUT->str('checked'); 50 if ($INPUT->has('note')) $data['note'] = $INPUT->str('note'); 51 52 io_saveFile($file, json_encode($data)); 53 echo json_encode(['status' => 'success']); 54} 55 56}