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