1<?php
2
3/**
4 * Admin Plugin: View and Delete Submissions in Admin Area
5 *
6 * @license GPL 3 (http://www.gnu.org/licenses/gpl.html)
7 * @author  Masoud Sadrnezhaad <masoud@sadrnezhaad.ir>
8 */
9class admin_plugin_judge extends DokuWiki_Admin_Plugin
10{
11
12    /**
13     * handle user request
14     */
15    function handle()
16    {
17
18        if (!isset($_REQUEST['cmd'])) {
19            return;   // first time - nothing to do
20        }
21        if (!checkSecurityToken()) {
22            return;
23        }
24        if (!is_array($_REQUEST['cmd'])) {
25            return;
26        }
27
28        $crud = plugin_load('helper', 'judge_crud', true);
29
30        // verify valid values
31        switch (key($_REQUEST['cmd'])) {
32            case 'get' :
33                $this->output = '<div class="table sectionedit1">
34                                    <table class="inline">';
35                $table = $crud->tableRender(array('problem_name' => $_REQUEST['problem_name'], 'type' => $_REQUEST['type'], 'user' => $_REQUEST['user']), "html", 1, "timestamp");
36                if ($table["count"] == 0) {
37                    $this->output .= '<p>' . $this->getLang("empty_result") . '</p>';
38                    break;
39                } else {
40                    $this->output .= $table["submissions_table"];
41                }
42                $this->output .= "</table></div>";
43                break;
44            case 'delete' :
45                $this->output = $crud->delSubmissions(array('problem_name' => $_REQUEST['problem_name'], 'type' => $_REQUEST['type'], 'user' => $_REQUEST['user']));
46                break;
47        }
48    }
49
50    /**
51     * output appropriate html
52     */
53    function html()
54    {
55        global $ID, $auth;
56
57        $filter['grps'] = "user";
58        if ($auth->canDo('getUsers')) {  // is this feature available?
59            $users = $auth->retrieveUsers(0, 0);
60        }
61
62        $html = '<p>' . $this->getLang("intro_message") . '</p>
63            <form class="admin-form" action="' . wl($ID) . '" method="post">
64            <label class="block">' . $this->getLang("question_name") . ': <input name="problem_name" type="text" /></label>
65            <label class="block">' . $this->getLang("sender") . ':
66            <select name="user">
67            <option value="">' . $this->getLang("all_users") . '</option>';
68        while ($user = current($users)) {
69            $html .= '<option value="' . key($users) . '">' . $user["name"] . '</option>';
70            next($users);
71        }
72
73        $html .= '
74            </select>
75            </label>
76            <label class="block">
77            <input type="radio" name="type" value="test-case"> ' . $this->getLang('programming_questions') . '<br />
78            <input type="radio" name="type" value="output-only"> ' . $this->getLang('outputonly_questions') . '
79            </label>';
80
81        // output hidden values to ensure dokuwiki will return back to this plugin
82        $html .= '<input type="hidden" name="do"   value="admin" />'
83            . '<input type="hidden" name="page" value="' . $this->getPluginName() . '" />';
84
85        ptln($html);
86        formSecurityToken();
87
88        $html = '
89        <input type="submit" name="cmd[get]"  value="' . $this->getLang('btn_get_submissions') . '" />
90        <input type="submit" name="cmd[delete]"  value="' . $this->getLang('btn_delete_submissions') . '" />
91        </form><h1 class="sectionedit1"></h1>
92        ';
93        $html .= $this->output;
94        ptln($html);
95    }
96
97}