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 $ID; 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 83 84 echo '<form action="'.wl($ID).'">'; 85 echo '<input type="hidden" name="do" value="admin" />'; 86 echo '<input type="hidden" name="page" value="struct_assignments" />'; 87 echo '<input type="hidden" name="sectok" value="'.getSecurityToken().'" />'; 88 echo '<table class="inline">'; 89 90 // header 91 echo '<tr>'; 92 echo '<th>Page/Namespace</th>'; // FIXME localize 93 echo '<th>Schema</th>'; // FIXME localize 94 echo '<th></th>'; 95 echo '</tr>'; 96 97 // existing assignments 98 foreach ($assignments as $assignment) { 99 $schema = $assignment['tbl']; 100 $assignee = $assignment['assign']; 101 102 $link = wl($ID, array( 103 'do' => 'admin', 104 'page' => 'struct_assignments', 105 'action' => 'delete', 106 'sectok' => getSecurityToken(), 107 'assignment[tbl]' => $schema, 108 'assignment[assign]' => $assignee, 109 )); 110 111 echo '<tr>'; 112 echo '<td>'.hsc($assignee).'</td>'; 113 echo '<td>'.hsc($schema).'</td>'; 114 echo '<td><a href="'.$link.'">Delete</a></td>'; //FIXME localize 115 echo '</tr>'; 116 } 117 118 // new assignment form 119 echo '<tr>'; 120 echo '<td><input type="text" name="assignment[assign]" /></td>'; 121 echo '<td>'; 122 echo '<select name="assignment[tbl]">'; 123 foreach ($schemas as $schema){ 124 echo '<option value="'. hsc($schema['tbl']) .'">'. hsc($schema['tbl']) . '</option>'; 125 } 126 echo '</select>'; 127 echo '</td>'; 128 echo '<td><button type="submit" name="action" value="add">Add</button></td>'; // FIXME localize 129 echo '</tr>'; 130 131 echo '</table>'; 132 } 133 134 /** 135 * Copies the TOC from the Schema Editor 136 * 137 * @return array 138 */ 139 public function getTOC() { 140 /** @var admin_plugin_struct_schemas $plugin */ 141 $plugin = plugin_load('admin', 'struct_schemas'); 142 return $plugin->getTOC(); 143 } 144 145} 146 147// vim:ts=4:sw=4:et: 148