aboutsummaryrefslogtreecommitdiff
path: root/classes/standard_forms.php
blob: cb985bf5baf8440eefef6a0c45d5a365fc9fa212 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.

/**
 * Defines the displayed forms.
 *
 * @package   tool_managertokens
 * @copyright 2017 "Valentin Popov" <info@valentineus.link>
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */

defined("MOODLE_INTERNAL") || die();

require_once($CFG->libdir . "/formslib.php");

/**
 * Defines the form of the token editor.
 *
 * @copyright 2017 "Valentin Popov" <info@valentineus.link>
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
class token_editor_form extends moodleform {
    /**
     * Constructor.
     *
     * @param string $baseurl
     */
    public function __construct($baseurl) {
        parent::__construct($baseurl);
    }

    /**
     * Defines the basic elements of the form.
     */
    protected function definition() {
        $mform =& $this->_form;

        /* Defines roles */
        $targettypetypes = array(
            "user" => new lang_string("user", "moodle")
        );

        /* Defines additional actions */
        $extendedactiontypes = array(
            "null" => new lang_string("none", "moodle"),
            "redirect" => new lang_string("redirect", "moodle")
        );

        /* The header of the main parameters */
        $mform->addElement("header", "general", new lang_string("general", "moodle"));

        /* Entry element of the token */
        $mform->addElement("text", "token", new lang_string("password", "moodle"));
        $mform->addRule("token", null, "required");
        $mform->setDefault("token", generate_password(12));
        $mform->setType("token", PARAM_NOTAGS);

        /* State switching element */
        $mform->addElement("advcheckbox", "enabled", new lang_string("enable", "moodle"));
        $mform->setAdvanced("enabled");
        $mform->setDefault("enabled", 1);
        $mform->setType("enabled", PARAM_BOOL);

        /* The role selection element */
        $mform->addElement("select", "targettype", new lang_string("role", "moodle"), $targettypetypes);
        $mform->addRule("targettype", null, "required");
        $mform->setDefault("targettype", "user");
        $mform->setType("targettype", PARAM_TAG);

        /* The identifier element */
        $mform->addElement("text", "targetid", new lang_string("idnumbermod", "moodle"));
        $mform->addRule("targetid", null, "required");
        $mform->setType("targetid", PARAM_INT);

        /* The header of constraints */
        $mform->addElement("header", "statsuserlogins", new lang_string("statsuserlogins", "moodle"));

        /* Element for restricting input attempts */
        $mform->addElement("text", "limited", new lang_string("statsuniquelogins", "moodle"));
        $mform->setDefault("limited", 0);
        $mform->setType("limited", PARAM_INT);

        /* Element for limiting time */
        $mform->addElement("duration", "timelimited", new lang_string("maxtimelimit", "admin"));
        $mform->setDefault("timelimited", 0);
        $mform->setType("timelimited", PARAM_INT);

        /* The header for additional actions */
        $mform->addElement("header", "advancedsettings", new lang_string("advancedsettings", "moodle"));

        /* Element for selecting an additional action */
        $mform->addElement("select", "extendedaction", new lang_string("action", "moodle"), $extendedactiontypes);
        $mform->setDefault("extendedaction", "null");
        $mform->setType("extendedaction", PARAM_TAG);

        /* Element of setting additional action */
        $mform->addElement("text", "extendedoptions", new lang_string("configuration", "moodle"));
        $mform->setDefault("extendedoptions", null);
        $mform->setType("extendedoptions", PARAM_RAW_TRIMMED);

        /* Control buttons */
        $this->add_action_buttons(true);
    }
}

/**
 * Defines the form of the recovery page.
 *
 * @copyright 2017 "Valentin Popov" <info@valentineus.link>
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
class tokens_backup_form extends moodleform {
    /**
     * Constructor.
     *
     * @param string $baseurl
     */
    public function __construct($baseurl) {
        parent::__construct($baseurl);
    }

    /**
     * Defines the basic elements of the form.
     */
    protected function definition() {
        $mform =& $this->_form;

        /* The header of the page */
        $mform->addElement("header", "restore", new lang_string("restore", "moodle"));

        /* Element for download file */
        $mform->addElement("filepicker", "backupfile", new lang_string("file", "moodle"));
        $mform->addRule("backupfile", null, "required");

        /* Element for checking the action */
        $mform->addElement("hidden", "sesskey", sesskey());

        /* Control buttons */
        $this->add_action_buttons(true, new lang_string("restore", "moodle"));
    }
}