*/ use dokuwiki\Extension\ActionPlugin; use dokuwiki\Extension\EventHandler; use dokuwiki\Extension\Event; use dokuwiki\plugin\struct\meta\AccessTable; use dokuwiki\plugin\struct\meta\AccessTableGlobal; use dokuwiki\plugin\struct\meta\AggregationEditorTable; use dokuwiki\plugin\struct\meta\Column; use dokuwiki\plugin\struct\meta\Schema; use dokuwiki\plugin\struct\meta\SearchConfig; use dokuwiki\plugin\struct\meta\StructException; use dokuwiki\plugin\struct\meta\Value; /** * Class action_plugin_struct_lookup * * Handle global and serial data table editing */ class action_plugin_struct_aggregationeditor extends ActionPlugin { /** @var Column */ protected $column; /** @var string */ protected $pid = ''; /** @var int */ protected $rid = 0; /** * Registers a callback function for a given event * * @param EventHandler $controller DokuWiki's event controller object * @return void */ public function register(EventHandler $controller) { $controller->register_hook('DOKUWIKI_STARTED', 'AFTER', $this, 'addJsinfo'); $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'handleAjax'); } /** * Add user's permissions to JSINFO * * @param Event $event */ public function addJsinfo(Event $event) { global $ID; global $JSINFO; $JSINFO['plugins']['struct']['isPageEditor'] = auth_quickaclcheck($ID) >= AUTH_EDIT; } /** * @param Event $event */ public function handleAjax(Event $event) { $len = strlen('plugin_struct_aggregationeditor_'); if (substr($event->data, 0, $len) != 'plugin_struct_aggregationeditor_') { return; } $event->preventDefault(); $event->stopPropagation(); try { if (substr($event->data, $len) == 'new') { $this->newRowEditor(); } if (substr($event->data, $len) == 'save') { $this->saveRow(); } if (substr($event->data, $len) == 'delete') { $this->deleteRow(); } } catch (StructException $e) { http_status(500); header('Content-Type: text/plain'); echo $e->getMessage(); } } /** * Deletes a row */ protected function deleteRow() { global $INPUT; $tablename = $INPUT->str('schema'); if (!$tablename) { throw new StructException('No schema given'); } $this->rid = $INPUT->int('rid'); $this->validate(); action_plugin_struct_inline::checkCSRF(); $access = $this->getAccess($tablename); if (!$access->getSchema()->isEditable()) { throw new StructException('lookup delete error: no permission for schema'); } $access->clearData(); } /** * Save one new row */ protected function saveRow() { global $INPUT; $tablename = $INPUT->str('schema'); $data = $INPUT->arr('entry'); $this->pid = $INPUT->str('pid'); action_plugin_struct_inline::checkCSRF(); // create a new row based on the original aggregation config $access = $this->getAccess($tablename); /** @var helper_plugin_struct $helper */ $helper = plugin_load('helper', 'struct'); $helper->saveLookupData($access, $data); $config = json_decode($INPUT->str('searchconf'), true, 512, JSON_THROW_ON_ERROR); // update row id $this->rid = $access->getRid(); $config = $this->addTypeFilter($config); $editorTable = new AggregationEditorTable( $this->pid, 'xhtml', new Doku_Renderer_xhtml(), new SearchConfig($config) ); echo $editorTable->getFirstRow(); } /** * Create the Editor for a new row */ protected function newRowEditor() { global $INPUT; global $lang; $searchconf = $INPUT->arr('searchconf'); $tablename = $searchconf['schemas'][0][0]; $schema = new Schema($tablename); if (!$schema->isEditable()) { return; } // no permissions, no editor // separate check for serial data in JS echo '