1<?php 2 3use dokuwiki\Form\Form; 4 5/** 6 * DokuWiki Plugin acknowledge (Admin Component) 7 * 8 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 9 * @author Andreas Gohr, Anna Dabrowska <dokuwiki@cosmocode.de> 10 */ 11class admin_plugin_acknowledge_assign extends \dokuwiki\Extension\AdminPlugin 12{ 13 /** @inheritDoc */ 14 public function getMenuText($language) 15 { 16 return $this->getLang('menu_assign'); 17 } 18 19 20 /** @inheritDoc */ 21 public function handle() 22 { 23 global $INPUT; 24 25 /** @var helper_plugin_acknowledge $helper */ 26 $helper = plugin_load('helper', 'acknowledge'); 27 28 $pattern = $INPUT->arr('pattern'); 29 $assignees = $INPUT->arr('assignees'); 30 $patterns = array_combine($pattern, $assignees); 31 32 if ($patterns && checkSecurityToken()) { 33 $helper->saveAssignmentPatterns($patterns); 34 } 35 36 } 37 38 /** @inheritDoc */ 39 public function html() 40 { 41 echo $this->locale_xhtml('assign'); 42 43 /** @var helper_plugin_acknowledge $helper */ 44 $helper = plugin_load('helper', 'acknowledge'); 45 46 $assignments = $helper->getAssignmentPatterns(); 47 48 $form = new Form(['method' => 'post']); 49 $form->setHiddenField('do', 'admin'); 50 $form->setHiddenField('page', 'acknowledge_assign'); 51 $form->addTagOpen('table'); 52 $form->addTagOpen('tr'); 53 $form->addTagOpen('th'); 54 $form->addHTML($this->getLang('pattern')); 55 $form->addTagClose('th'); 56 $form->addTagOpen('th'); 57 $form->addHTML($this->getLang('assignees')); 58 $form->addTagClose('th'); 59 $form->addTagClose('tr'); 60 foreach ($assignments as $pattern => $assignees) { 61 $this->addRow($form, $pattern, $assignees); 62 } 63 $this->addRow($form, '', ''); 64 $form->addTagClose('table'); 65 66 $form->addButton('save', $this->getLang('save')); 67 echo $form->toHTML(); 68 } 69 70 /** 71 * @param Form $form 72 * @param string $pattern 73 * @param string $assignee 74 * @return void 75 */ 76 public function addRow($form, $pattern, $assignee) 77 { 78 static $row = 0; 79 80 $form->addTagOpen('tr'); 81 $form->addTagOpen('td'); 82 $form->addTextInput("pattern[$row]")->val($pattern); 83 $form->addTagClose('td'); 84 $form->addTagOpen('td'); 85 $form->addTextInput("assignees[$row]")->val($assignee); 86 $form->addTagClose('td'); 87 $form->addTagClose('tr'); 88 $row++; 89 } 90 91 /** @inheritDoc */ 92 public function getTOC() 93 { 94 return (new admin_plugin_acknowledge_report())->getTOC(); 95 } 96 97 98} 99 100