*/ // must be run within Dokuwiki use plugin\struct\meta\Assignments; if(!defined('DOKU_INC')) die(); class admin_plugin_struct_assignments extends DokuWiki_Admin_Plugin { /** * @return int sort number in admin menu */ public function getMenuSort() { return 501; } /** * Return the text that is displayed at the main admin menu * * @param string $language language code * @return string menu string */ public function getMenuText($language) { return $this->getLang('menu_assignments'); } /** * @return bool true if only access for superuser, false is for superusers and moderators */ public function forAdminOnly() { return true; } /** * Should carry out any processing required by the plugin. */ public function handle() { global $INPUT; global $ID; $assignments = new Assignments(); if($INPUT->str('action') && $INPUT->arr('assignment') && checkSecurityToken()) { $assignment = $INPUT->arr('assignment'); $ok = true; if(!blank($assignment['assign']) && !blank($assignment['tbl'])) { if($INPUT->str('action') === 'delete') { $ok = $assignments->removePattern($assignment['assign'], $assignment['tbl']); } else if($INPUT->str('action') === 'add') { $ok = $assignments->addPattern($assignment['assign'], $assignment['tbl']); } } if(!$ok) { msg('something went wrong while saving', -1); } send_redirect(wl($ID, array('do' => 'admin', 'page' => 'struct_assignments'), true, '&')); } } /** * Render HTML output, e.g. helpful text and a form */ public function html() { global $ID; echo $this->locale_xhtml('assignments_intro'); //fixme listing schema tables should be moved to one of the meta classes /** @var helper_plugin_struct_db $helper */ $helper = plugin_load('helper', 'struct_db'); $sqlite = $helper->getDB(); $res = $sqlite->query('SELECT tbl FROM schemas GROUP BY tbl'); $schemas = $sqlite->res2arr($res); $sqlite->res_close($res); $ass = new Assignments(); $assignments = $ass->getAllPatterns(); echo '
'; echo ''; echo ''; echo ''; echo ''; // header echo ''; echo ''; echo ''; echo ''; echo ''; // existing assignments foreach($assignments as $assignment) { $schema = $assignment['tbl']; $assignee = $assignment['pattern']; $link = wl( $ID, array( 'do' => 'admin', 'page' => 'struct_assignments', 'action' => 'delete', 'sectok' => getSecurityToken(), 'assignment[tbl]' => $schema, 'assignment[assign]' => $assignee, ) ); echo ''; echo ''; echo ''; echo ''; echo ''; } // new assignment form echo ''; echo ''; echo ''; echo ''; echo ''; echo '
'.$this->getLang('assign_assign').''.$this->getLang('assign_tbl').'
' . hsc($assignee) . '' . hsc($schema) . ''.$this->getLang('assign_del').'
'; echo ''; echo '
'; } /** * Copies the TOC from the Schema Editor * * @return array */ public function getTOC() { /** @var admin_plugin_struct_schemas $plugin */ $plugin = plugin_load('admin', 'struct_schemas'); return $plugin->getTOC(); } } // vim:ts=4:sw=4:et: