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 1087fdbc6bSMichael Großeuse dokuwiki\Form\Form; 11*1a8d1235SAndreas Gohruse plugin\struct\meta\Assignments; 1287fdbc6bSMichael Großeuse plugin\struct\meta\Schema; 1387fdbc6bSMichael Großeuse plugin\struct\meta\SchemaEditor; 1487fdbc6bSMichael Große 1587fdbc6bSMichael Großeif(!defined('DOKU_INC')) die(); 1687fdbc6bSMichael Große 1787fdbc6bSMichael Großeclass admin_plugin_struct_assignments extends DokuWiki_Admin_Plugin { 1887fdbc6bSMichael Große 1987fdbc6bSMichael Große /** @var helper_plugin_sqlite */ 2087fdbc6bSMichael Große protected $sqlite; 2187fdbc6bSMichael Große 2287fdbc6bSMichael Große /** 2387fdbc6bSMichael Große * @return int sort number in admin menu 2487fdbc6bSMichael Große */ 2587fdbc6bSMichael Große public function getMenuSort() { 2687fdbc6bSMichael Große return 501; 2787fdbc6bSMichael Große } 2887fdbc6bSMichael Große 2940b81cabSAndreas Gohr /** 3040b81cabSAndreas Gohr * Return the text that is displayed at the main admin menu 3140b81cabSAndreas Gohr * 3240b81cabSAndreas Gohr * @param string $language language code 3340b81cabSAndreas Gohr * @return string menu string 3440b81cabSAndreas Gohr */ 3540b81cabSAndreas Gohr public function getMenuText($language) { 3640b81cabSAndreas Gohr return $this->getLang('menu_assignments'); 3787fdbc6bSMichael Große } 3887fdbc6bSMichael Große 3987fdbc6bSMichael Große /** 4087fdbc6bSMichael Große * @return bool true if only access for superuser, false is for superusers and moderators 4187fdbc6bSMichael Große */ 4287fdbc6bSMichael Große public function forAdminOnly() { 4387fdbc6bSMichael Große return true; 4487fdbc6bSMichael Große } 4587fdbc6bSMichael Große 4687fdbc6bSMichael Große /** 4787fdbc6bSMichael Große * Should carry out any processing required by the plugin. 4887fdbc6bSMichael Große */ 4987fdbc6bSMichael Große public function handle() { 5087fdbc6bSMichael Große global $INPUT; 5187fdbc6bSMichael Große 52*1a8d1235SAndreas Gohr $assignments = new Assignments(); 5387fdbc6bSMichael Große if($INPUT->str('action') && $INPUT->arr('assignment') && checkSecurityToken()) { 5487fdbc6bSMichael Große $assignment = $INPUT->arr('assignment'); 55*1a8d1235SAndreas Gohr $ok = false; 5687fdbc6bSMichael Große if ($INPUT->str('action') === 'delete') { 57*1a8d1235SAndreas Gohr $ok = $assignments->remove($assignment['assign'], $assignment['tbl']); 58*1a8d1235SAndreas Gohr } else if($INPUT->str('action') === 'add') { 59*1a8d1235SAndreas Gohr $ok = $assignments->add($assignment['assign'], $assignment['tbl']); 6087fdbc6bSMichael Große } 61*1a8d1235SAndreas Gohr if(empty($sql) || empty($assignment['assign']) || empty($assignment['tbl']) || !$ok) { 6287fdbc6bSMichael Große msg('something went wrong while saving', -1); 6387fdbc6bSMichael Große } 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() { 7187fdbc6bSMichael Große global $INPUT; 7287fdbc6bSMichael Große 7387fdbc6bSMichael Große echo $this->locale_xhtml('assignments_intro'); 7487fdbc6bSMichael Große 7587fdbc6bSMichael Große $res = $this->sqlite->query('SELECT tbl FROM schemas GROUP BY tbl'); 7687fdbc6bSMichael Große $schemas = $this->sqlite->res2arr($res); 7787fdbc6bSMichael Große $this->sqlite->res_close($res); 7887fdbc6bSMichael Große 79*1a8d1235SAndreas Gohr $ass = new Assignments(); 80*1a8d1235SAndreas Gohr $assignments = $ass->getAll(); 8187fdbc6bSMichael Große 8287fdbc6bSMichael Große echo '<ul>'; 8387fdbc6bSMichael Große foreach ($assignments as $assignment) { 8487fdbc6bSMichael Große $schema = $assignment['tbl']; 8587fdbc6bSMichael Große $assignee = $assignment['assign']; 8687fdbc6bSMichael Große $form = new Form(); 8787fdbc6bSMichael Große $form->setHiddenField("assignment[assign]", $assignee); 8887fdbc6bSMichael Große $form->setHiddenField("assignment[tbl]", $schema); 8987fdbc6bSMichael Große $form->addHTML("<button type=\"submit\" name=\"action\" value=\"delete\">Delete</button>"); 9087fdbc6bSMichael Große $html = "<li class=\"level1\"><div class=\"li\">$assignee - $schema "; 9187fdbc6bSMichael Große $html .= $form->toHTML(); 9287fdbc6bSMichael Große $html .= "</div></li>"; 9387fdbc6bSMichael Große echo $html; 9487fdbc6bSMichael Große } 9587fdbc6bSMichael Große $form = new Form(); 9687fdbc6bSMichael Große $form->addTextInput("assignment[assign]",'Page or Namespace: '); 9787fdbc6bSMichael Große $form->addLabel('Schema','schemaSelect'); 9887fdbc6bSMichael Große $form->addHTML('<select id="schemaSelect" name="assignment[tbl]">'); 9987fdbc6bSMichael Große foreach ($schemas as $schema){ 10087fdbc6bSMichael Große $form->addHTML('<option value="'. $schema['tbl'] .'">'. $schema['tbl'] . '</option>'); 10187fdbc6bSMichael Große } 10287fdbc6bSMichael Große $form->addHTML('</select>'); 10387fdbc6bSMichael Große $form->addHTML("<button type=\"submit\" name=\"action\" value=\"add\">Add</button>"); 10487fdbc6bSMichael Große $html = "<li class=\"level1\"><div class=\"li\">"; 10587fdbc6bSMichael Große $html .= $form->toHTML(); 10687fdbc6bSMichael Große $html .= "</div></li>"; 10787fdbc6bSMichael Große echo $html; 10887fdbc6bSMichael Große echo '</ul>'; 10987fdbc6bSMichael Große 11087fdbc6bSMichael Große 11187fdbc6bSMichael Große $table = Schema::cleanTableName($INPUT->str('table')); 11287fdbc6bSMichael Große if($table) { 11387fdbc6bSMichael Große echo '<h2>'.sprintf($this->getLang('edithl'), hsc($table)).'</h2>'; 11487fdbc6bSMichael Große 11587fdbc6bSMichael Große $editor = new SchemaEditor(new Schema($table)); 11687fdbc6bSMichael Große echo $editor->getEditor(); 11787fdbc6bSMichael Große } else { 11887fdbc6bSMichael Große $this->html_newschema(); 11987fdbc6bSMichael Große } 12087fdbc6bSMichael Große } 12187fdbc6bSMichael Große 12287fdbc6bSMichael Große} 12387fdbc6bSMichael Große 12487fdbc6bSMichael Große// vim:ts=4:sw=4:et: 125