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