*/ // must be run within Dokuwiki use dokuwiki\Form\Form; use plugin\struct\meta\Schema; use plugin\struct\meta\SchemaEditor; if(!defined('DOKU_INC')) die(); class admin_plugin_struct_schemas extends DokuWiki_Admin_Plugin { /** * @return int sort number in admin menu */ public function getMenuSort() { return 500; } /** * @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; $table = Schema::cleanTableName($INPUT->str('table')); if($table && $INPUT->bool('save') && checkSecurityToken()) { $builder = new \plugin\struct\meta\SchemaBuilder($table, $INPUT->arr('schema')); if(!$builder->build()) { msg('something went wrong while saving', -1); } } } /** * Render HTML output, e.g. helpful text and a form */ public function html() { global $INPUT; $table = Schema::cleanTableName($INPUT->str('table')); if($table) { echo $this->locale_xhtml('editor_edit'); echo '
'.$this->getLang('createhint').'
'); // FIXME is that true? we probably could $form->addFieldsetClose(); echo $form->toHTML(); } /** * Adds all available schemas to the Table of Contents * * @return array */ public function getTOC() { global $ID; /** @var helper_plugin_struct_db $helper */ $helper = plugin_load('helper', 'struct_db'); $db = $helper->getDB(); if(!$db) return parent::getTOC(); $res = $db->query("SELECT DISTINCT tbl FROM schemas ORDER BY tbl"); $tables = $db->res2arr($res); $db->res_close($res); $toc = array(); $link = wl($ID, array( 'do' => 'admin', 'page' => 'struct_assignments' )); $toc[] = html_mktocitem($link, $this->getLang('menu_assignments'), 0, ''); $link = wl($ID, array( 'do' => 'admin', 'page' => 'struct_schemas' )); $toc[] = html_mktocitem($link, $this->getLang('menu'), 0, ''); foreach($tables as $row) { $link = wl($ID, array( 'do' => 'admin', 'page' => 'struct_schemas', 'table' => $row['tbl'] )); $toc[] = html_mktocitem($link, hsc($row['tbl']), 1, ''); } return $toc; } } // vim:ts=4:sw=4:et: