187fdbc6bSMichael Große<?php 287fdbc6bSMichael Große/** 387fdbc6bSMichael Große * DokuWiki Plugin struct (Admin Component) 487fdbc6bSMichael Große * 587fdbc6bSMichael Große * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 687fdbc6bSMichael Große * @author Andreas Gohr, Michael Große <dokuwiki@cosmocode.de> 787fdbc6bSMichael Große */ 887fdbc6bSMichael Große 987fdbc6bSMichael Große// must be run within Dokuwiki 101a8d1235SAndreas Gohruse plugin\struct\meta\Assignments; 1187fdbc6bSMichael Große 1287fdbc6bSMichael Großeif(!defined('DOKU_INC')) die(); 1387fdbc6bSMichael Große 1487fdbc6bSMichael Großeclass admin_plugin_struct_assignments extends DokuWiki_Admin_Plugin { 1587fdbc6bSMichael Große 1687fdbc6bSMichael Große /** 1787fdbc6bSMichael Große * @return int sort number in admin menu 1887fdbc6bSMichael Große */ 1987fdbc6bSMichael Große public function getMenuSort() { 2087fdbc6bSMichael Große return 501; 2187fdbc6bSMichael Große } 2287fdbc6bSMichael Große 2340b81cabSAndreas Gohr /** 2440b81cabSAndreas Gohr * Return the text that is displayed at the main admin menu 2540b81cabSAndreas Gohr * 2640b81cabSAndreas Gohr * @param string $language language code 2740b81cabSAndreas Gohr * @return string menu string 2840b81cabSAndreas Gohr */ 2940b81cabSAndreas Gohr public function getMenuText($language) { 3040b81cabSAndreas Gohr return $this->getLang('menu_assignments'); 3187fdbc6bSMichael Große } 3287fdbc6bSMichael Große 3387fdbc6bSMichael Große /** 3487fdbc6bSMichael Große * @return bool true if only access for superuser, false is for superusers and moderators 3587fdbc6bSMichael Große */ 3687fdbc6bSMichael Große public function forAdminOnly() { 3787fdbc6bSMichael Große return true; 3887fdbc6bSMichael Große } 3987fdbc6bSMichael Große 4087fdbc6bSMichael Große /** 4187fdbc6bSMichael Große * Should carry out any processing required by the plugin. 4287fdbc6bSMichael Große */ 4387fdbc6bSMichael Große public function handle() { 4487fdbc6bSMichael Große global $INPUT; 4528e05468SAndreas Gohr global $ID; 4687fdbc6bSMichael Große 471a8d1235SAndreas Gohr $assignments = new Assignments(); 4887fdbc6bSMichael Große if($INPUT->str('action') && $INPUT->arr('assignment') && checkSecurityToken()) { 4987fdbc6bSMichael Große $assignment = $INPUT->arr('assignment'); 5028e05468SAndreas Gohr $ok = true; 5128e05468SAndreas Gohr if(!blank($assignment['assign']) && !blank($assignment['tbl'])) { 5287fdbc6bSMichael Große if($INPUT->str('action') === 'delete') { 5333d7be6aSAndreas Gohr $ok = $assignments->removePattern($assignment['assign'], $assignment['tbl']); 541a8d1235SAndreas Gohr } else if($INPUT->str('action') === 'add') { 5533d7be6aSAndreas Gohr $ok = $assignments->addPattern($assignment['assign'], $assignment['tbl']); 5687fdbc6bSMichael Große } 5728e05468SAndreas Gohr } 5828e05468SAndreas Gohr 5928e05468SAndreas Gohr if(!$ok) { 6087fdbc6bSMichael Große msg('something went wrong while saving', -1); 6187fdbc6bSMichael Große } 6228e05468SAndreas Gohr 6328e05468SAndreas Gohr send_redirect(wl($ID, array('do' => 'admin', 'page' => 'struct_assignments'), true, '&')); 6487fdbc6bSMichael Große } 6587fdbc6bSMichael Große } 6687fdbc6bSMichael Große 6787fdbc6bSMichael Große /** 6887fdbc6bSMichael Große * Render HTML output, e.g. helpful text and a form 6987fdbc6bSMichael Große */ 7087fdbc6bSMichael Große public function html() { 71a3d1e459SAndreas Gohr global $ID; 72a3d1e459SAndreas Gohr 7387fdbc6bSMichael Große echo $this->locale_xhtml('assignments_intro'); 7487fdbc6bSMichael Große 755f803f49SAndreas Gohr //fixme listing schema tables should be moved to one of the meta classes 765f803f49SAndreas Gohr /** @var helper_plugin_struct_db $helper */ 775f803f49SAndreas Gohr $helper = plugin_load('helper', 'struct_db'); 785f803f49SAndreas Gohr $sqlite = $helper->getDB(); 795f803f49SAndreas Gohr $res = $sqlite->query('SELECT tbl FROM schemas GROUP BY tbl'); 805f803f49SAndreas Gohr $schemas = $sqlite->res2arr($res); 815f803f49SAndreas Gohr $sqlite->res_close($res); 8287fdbc6bSMichael Große 831a8d1235SAndreas Gohr $ass = new Assignments(); 8433d7be6aSAndreas Gohr $assignments = $ass->getAllPatterns(); 8587fdbc6bSMichael Große 8628e05468SAndreas Gohr echo '<form action="' . wl($ID) . '" action="post">'; 87a3d1e459SAndreas Gohr echo '<input type="hidden" name="do" value="admin" />'; 88a3d1e459SAndreas Gohr echo '<input type="hidden" name="page" value="struct_assignments" />'; 89a3d1e459SAndreas Gohr echo '<input type="hidden" name="sectok" value="' . getSecurityToken() . '" />'; 90a3d1e459SAndreas Gohr echo '<table class="inline">'; 91a3d1e459SAndreas Gohr 92a3d1e459SAndreas Gohr // header 93a3d1e459SAndreas Gohr echo '<tr>'; 94ececd523SAndreas Gohr echo '<th>'.$this->getLang('assign_assign').'</th>'; 95ececd523SAndreas Gohr echo '<th>'.$this->getLang('assign_tbl').'</th>'; 96a3d1e459SAndreas Gohr echo '<th></th>'; 97a3d1e459SAndreas Gohr echo '</tr>'; 98a3d1e459SAndreas Gohr 99a3d1e459SAndreas Gohr // existing assignments 10087fdbc6bSMichael Große foreach($assignments as $assignment) { 10187fdbc6bSMichael Große $schema = $assignment['tbl']; 102*f8d8a899SAndreas Gohr $assignee = $assignment['pattern']; 103a3d1e459SAndreas Gohr 10428e05468SAndreas Gohr $link = wl( 10528e05468SAndreas Gohr $ID, array( 106a3d1e459SAndreas Gohr 'do' => 'admin', 107a3d1e459SAndreas Gohr 'page' => 'struct_assignments', 108a3d1e459SAndreas Gohr 'action' => 'delete', 109a3d1e459SAndreas Gohr 'sectok' => getSecurityToken(), 110a3d1e459SAndreas Gohr 'assignment[tbl]' => $schema, 111a3d1e459SAndreas Gohr 'assignment[assign]' => $assignee, 11228e05468SAndreas Gohr ) 11328e05468SAndreas Gohr ); 114a3d1e459SAndreas Gohr 115a3d1e459SAndreas Gohr echo '<tr>'; 116a3d1e459SAndreas Gohr echo '<td>' . hsc($assignee) . '</td>'; 117a3d1e459SAndreas Gohr echo '<td>' . hsc($schema) . '</td>'; 118ececd523SAndreas Gohr echo '<td><a href="' . $link . '">'.$this->getLang('assign_del').'</a></td>'; 119a3d1e459SAndreas Gohr echo '</tr>'; 12087fdbc6bSMichael Große } 121a3d1e459SAndreas Gohr 122a3d1e459SAndreas Gohr // new assignment form 123a3d1e459SAndreas Gohr echo '<tr>'; 124a3d1e459SAndreas Gohr echo '<td><input type="text" name="assignment[assign]" /></td>'; 125a3d1e459SAndreas Gohr echo '<td>'; 126a3d1e459SAndreas Gohr echo '<select name="assignment[tbl]">'; 12787fdbc6bSMichael Große foreach($schemas as $schema) { 128a3d1e459SAndreas Gohr echo '<option value="' . hsc($schema['tbl']) . '">' . hsc($schema['tbl']) . '</option>'; 12987fdbc6bSMichael Große } 130a3d1e459SAndreas Gohr echo '</select>'; 131a3d1e459SAndreas Gohr echo '</td>'; 132ececd523SAndreas Gohr echo '<td><button type="submit" name="action" value="add">'.$this->getLang('assign_add').'</button></td>'; 133a3d1e459SAndreas Gohr echo '</tr>'; 134a3d1e459SAndreas Gohr 135a3d1e459SAndreas Gohr echo '</table>'; 13687fdbc6bSMichael Große } 137dbffe06eSAndreas Gohr 138dbffe06eSAndreas Gohr /** 139dbffe06eSAndreas Gohr * Copies the TOC from the Schema Editor 140dbffe06eSAndreas Gohr * 141dbffe06eSAndreas Gohr * @return array 142dbffe06eSAndreas Gohr */ 143dbffe06eSAndreas Gohr public function getTOC() { 144dbffe06eSAndreas Gohr /** @var admin_plugin_struct_schemas $plugin */ 145dbffe06eSAndreas Gohr $plugin = plugin_load('admin', 'struct_schemas'); 146dbffe06eSAndreas Gohr return $plugin->getTOC(); 14787fdbc6bSMichael Große } 14887fdbc6bSMichael Große 14987fdbc6bSMichael Große} 15087fdbc6bSMichael Große 15187fdbc6bSMichael Große// vim:ts=4:sw=4:et: 152