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; 111a8d1235SAndreas 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 521a8d1235SAndreas Gohr $assignments = new Assignments(); 5387fdbc6bSMichael Große if($INPUT->str('action') && $INPUT->arr('assignment') && checkSecurityToken()) { 5487fdbc6bSMichael Große $assignment = $INPUT->arr('assignment'); 551a8d1235SAndreas Gohr $ok = false; 5687fdbc6bSMichael Große if ($INPUT->str('action') === 'delete') { 571a8d1235SAndreas Gohr $ok = $assignments->remove($assignment['assign'], $assignment['tbl']); 581a8d1235SAndreas Gohr } else if($INPUT->str('action') === 'add') { 591a8d1235SAndreas Gohr $ok = $assignments->add($assignment['assign'], $assignment['tbl']); 6087fdbc6bSMichael Große } 611a8d1235SAndreas 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 echo $this->locale_xhtml('assignments_intro'); 7287fdbc6bSMichael Große 7387fdbc6bSMichael Große $res = $this->sqlite->query('SELECT tbl FROM schemas GROUP BY tbl'); 7487fdbc6bSMichael Große $schemas = $this->sqlite->res2arr($res); 7587fdbc6bSMichael Große $this->sqlite->res_close($res); 7687fdbc6bSMichael Große 771a8d1235SAndreas Gohr $ass = new Assignments(); 781a8d1235SAndreas Gohr $assignments = $ass->getAll(); 7987fdbc6bSMichael Große 8087fdbc6bSMichael Große echo '<ul>'; 8187fdbc6bSMichael Große foreach ($assignments as $assignment) { 8287fdbc6bSMichael Große $schema = $assignment['tbl']; 8387fdbc6bSMichael Große $assignee = $assignment['assign']; 8487fdbc6bSMichael Große $form = new Form(); 8587fdbc6bSMichael Große $form->setHiddenField("assignment[assign]", $assignee); 8687fdbc6bSMichael Große $form->setHiddenField("assignment[tbl]", $schema); 8787fdbc6bSMichael Große $form->addHTML("<button type=\"submit\" name=\"action\" value=\"delete\">Delete</button>"); 8887fdbc6bSMichael Große $html = "<li class=\"level1\"><div class=\"li\">$assignee - $schema "; 8987fdbc6bSMichael Große $html .= $form->toHTML(); 9087fdbc6bSMichael Große $html .= "</div></li>"; 9187fdbc6bSMichael Große echo $html; 9287fdbc6bSMichael Große } 9387fdbc6bSMichael Große $form = new Form(); 9487fdbc6bSMichael Große $form->addTextInput("assignment[assign]",'Page or Namespace: '); 9587fdbc6bSMichael Große $form->addLabel('Schema','schemaSelect'); 9687fdbc6bSMichael Große $form->addHTML('<select id="schemaSelect" name="assignment[tbl]">'); 9787fdbc6bSMichael Große foreach ($schemas as $schema){ 9887fdbc6bSMichael Große $form->addHTML('<option value="'. $schema['tbl'] .'">'. $schema['tbl'] . '</option>'); 9987fdbc6bSMichael Große } 10087fdbc6bSMichael Große $form->addHTML('</select>'); 10187fdbc6bSMichael Große $form->addHTML("<button type=\"submit\" name=\"action\" value=\"add\">Add</button>"); 10287fdbc6bSMichael Große $html = "<li class=\"level1\"><div class=\"li\">"; 10387fdbc6bSMichael Große $html .= $form->toHTML(); 10487fdbc6bSMichael Große $html .= "</div></li>"; 10587fdbc6bSMichael Große echo $html; 10687fdbc6bSMichael Große echo '</ul>'; 10787fdbc6bSMichael Große } 108*dbffe06eSAndreas Gohr 109*dbffe06eSAndreas Gohr /** 110*dbffe06eSAndreas Gohr * Copies the TOC from the Schema Editor 111*dbffe06eSAndreas Gohr * 112*dbffe06eSAndreas Gohr * @return array 113*dbffe06eSAndreas Gohr */ 114*dbffe06eSAndreas Gohr public function getTOC() { 115*dbffe06eSAndreas Gohr /** @var admin_plugin_struct_schemas $plugin */ 116*dbffe06eSAndreas Gohr $plugin = plugin_load('admin', 'struct_schemas'); 117*dbffe06eSAndreas Gohr return $plugin->getTOC(); 11887fdbc6bSMichael Große } 11987fdbc6bSMichael Große 12087fdbc6bSMichael Große} 12187fdbc6bSMichael Große 12287fdbc6bSMichael Große// vim:ts=4:sw=4:et: 123