1<?php 2/** 3 * DokuWiki Plugin struct (Admin Component) 4 * 5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6 * @author Andreas Gohr, Michael Große <dokuwiki@cosmocode.de> 7 */ 8 9// must be run within Dokuwiki 10use dokuwiki\Form\Form; 11use plugin\struct\meta\Schema; 12use plugin\struct\meta\SchemaEditor; 13 14if(!defined('DOKU_INC')) die(); 15 16class admin_plugin_struct_schemas extends DokuWiki_Admin_Plugin { 17 18 /** 19 * @return int sort number in admin menu 20 */ 21 public function getMenuSort() { 22 return 500; 23 } 24 25 /** 26 * @return bool true if only access for superuser, false is for superusers and moderators 27 */ 28 public function forAdminOnly() { 29 return false; 30 } 31 32 /** 33 * Should carry out any processing required by the plugin. 34 */ 35 public function handle() { 36 global $INPUT; 37 38 $table = Schema::cleanTableName($INPUT->str('table')); 39 if($table && $INPUT->bool('save') && checkSecurityToken()) { 40 $builder = new \plugin\struct\meta\SchemaBuilder($table, $INPUT->arr('schema')); 41 if(!$builder->build()) { 42 msg('something went wrong while saving', -1); 43 } 44 } 45 46 } 47 48 /** 49 * Render HTML output, e.g. helpful text and a form 50 */ 51 public function html() { 52 global $INPUT; 53 54 55 56 $table = Schema::cleanTableName($INPUT->str('table')); 57 if($table) { 58 echo $this->locale_xhtml('editor_edit'); 59 60 echo '<h2>'.sprintf($this->getLang('edithl'), hsc($table)).'</h2>'; 61 $editor = new SchemaEditor(new Schema($table)); 62 echo $editor->getEditor(); 63 } else { 64 echo $this->locale_xhtml('editor_intro'); 65 $this->html_newschema(); 66 } 67 } 68 69 /** 70 * Form to add a new schema 71 */ 72 protected function html_newschema() { 73 $form = new Form(); 74 $form->addFieldsetOpen($this->getLang('create')); 75 $form->setHiddenField('do', 'admin'); 76 $form->setHiddenField('page', 'struct_schemas'); 77 $form->addTextInput('table', $this->getLang('schemaname')); 78 $form->addButton('', $this->getLang('save')); 79 $form->addHTML('<p>'.$this->getLang('createhint').'</p>'); // FIXME is that true? we probably could 80 $form->addFieldsetClose(); 81 echo $form->toHTML(); 82 } 83 84 /** 85 * Adds all available schemas to the Table of Contents 86 * 87 * @return array 88 */ 89 public function getTOC() { 90 global $ID; 91 92 $toc = array(); 93 $link = wl($ID, array( 94 'do' => 'admin', 95 'page' => 'struct_assignments' 96 )); 97 $toc[] = html_mktocitem($link, $this->getLang('menu_assignments'), 0, ''); 98 $link = wl($ID, array( 99 'do' => 'admin', 100 'page' => 'struct_schemas' 101 )); 102 $toc[] = html_mktocitem($link, $this->getLang('menu'), 0, ''); 103 104 $tables = Schema::getAll(); 105 foreach($tables as $table) { 106 $link = wl($ID, array( 107 'do' => 'admin', 108 'page' => 'struct_schemas', 109 'table' => $table 110 )); 111 112 $toc[] = html_mktocitem($link, hsc($table), 1, ''); 113 } 114 return $toc; 115 } 116 117} 118 119// vim:ts=4:sw=4:et: 120