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\Assignments; 12use plugin\struct\meta\Schema; 13use plugin\struct\meta\SchemaEditor; 14 15if(!defined('DOKU_INC')) die(); 16 17class admin_plugin_struct_assignments extends DokuWiki_Admin_Plugin { 18 19 /** @var helper_plugin_sqlite */ 20 protected $sqlite; 21 22 /** 23 * @return int sort number in admin menu 24 */ 25 public function getMenuSort() { 26 return 501; 27 } 28 29 /** 30 * Return the text that is displayed at the main admin menu 31 * 32 * @param string $language language code 33 * @return string menu string 34 */ 35 public function getMenuText($language) { 36 return $this->getLang('menu_assignments'); 37 } 38 39 /** 40 * @return bool true if only access for superuser, false is for superusers and moderators 41 */ 42 public function forAdminOnly() { 43 return true; 44 } 45 46 /** 47 * Should carry out any processing required by the plugin. 48 */ 49 public function handle() { 50 global $INPUT; 51 52 $assignments = new Assignments(); 53 if($INPUT->str('action') && $INPUT->arr('assignment') && checkSecurityToken()) { 54 $assignment = $INPUT->arr('assignment'); 55 $ok = false; 56 if ($INPUT->str('action') === 'delete') { 57 $ok = $assignments->remove($assignment['assign'], $assignment['tbl']); 58 } else if($INPUT->str('action') === 'add') { 59 $ok = $assignments->add($assignment['assign'], $assignment['tbl']); 60 } 61 if(empty($sql) || empty($assignment['assign']) || empty($assignment['tbl']) || !$ok) { 62 msg('something went wrong while saving', -1); 63 } 64 } 65 } 66 67 /** 68 * Render HTML output, e.g. helpful text and a form 69 */ 70 public function html() { 71 global $INPUT; 72 73 echo $this->locale_xhtml('assignments_intro'); 74 75 $res = $this->sqlite->query('SELECT tbl FROM schemas GROUP BY tbl'); 76 $schemas = $this->sqlite->res2arr($res); 77 $this->sqlite->res_close($res); 78 79 $ass = new Assignments(); 80 $assignments = $ass->getAll(); 81 82 echo '<ul>'; 83 foreach ($assignments as $assignment) { 84 $schema = $assignment['tbl']; 85 $assignee = $assignment['assign']; 86 $form = new Form(); 87 $form->setHiddenField("assignment[assign]", $assignee); 88 $form->setHiddenField("assignment[tbl]", $schema); 89 $form->addHTML("<button type=\"submit\" name=\"action\" value=\"delete\">Delete</button>"); 90 $html = "<li class=\"level1\"><div class=\"li\">$assignee - $schema "; 91 $html .= $form->toHTML(); 92 $html .= "</div></li>"; 93 echo $html; 94 } 95 $form = new Form(); 96 $form->addTextInput("assignment[assign]",'Page or Namespace: '); 97 $form->addLabel('Schema','schemaSelect'); 98 $form->addHTML('<select id="schemaSelect" name="assignment[tbl]">'); 99 foreach ($schemas as $schema){ 100 $form->addHTML('<option value="'. $schema['tbl'] .'">'. $schema['tbl'] . '</option>'); 101 } 102 $form->addHTML('</select>'); 103 $form->addHTML("<button type=\"submit\" name=\"action\" value=\"add\">Add</button>"); 104 $html = "<li class=\"level1\"><div class=\"li\">"; 105 $html .= $form->toHTML(); 106 $html .= "</div></li>"; 107 echo $html; 108 echo '</ul>'; 109 110 111 $table = Schema::cleanTableName($INPUT->str('table')); 112 if($table) { 113 echo '<h2>'.sprintf($this->getLang('edithl'), hsc($table)).'</h2>'; 114 115 $editor = new SchemaEditor(new Schema($table)); 116 echo $editor->getEditor(); 117 } else { 118 $this->html_newschema(); 119 } 120 } 121 122} 123 124// vim:ts=4:sw=4:et: 125