From d3a9ac153d6d13142174d4ac614bd8fea102cd7d Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Fri, 1 Dec 2017 14:55:31 +0400 Subject: Added classes that describe the form of the plugin --- classes/standard_forms.php | 153 +++++++++++++++++++++++++++++++++++++++++++++ editor.php | 2 +- 2 files changed, 154 insertions(+), 1 deletion(-) create mode 100644 classes/standard_forms.php diff --git a/classes/standard_forms.php b/classes/standard_forms.php new file mode 100644 index 0000000..ab0cd18 --- /dev/null +++ b/classes/standard_forms.php @@ -0,0 +1,153 @@ +. + +/** + * Defines the displayed forms. + * + * @package tool_managertokens + * @copyright 2017 "Valentin Popov" + * @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" + * @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->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" + * @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")); + } +} \ No newline at end of file diff --git a/editor.php b/editor.php index 1b27453..b098646 100644 --- a/editor.php +++ b/editor.php @@ -23,7 +23,7 @@ */ require_once(__DIR__ . "/../../../config.php"); -require_once(__DIR__ . "/classes/editor_form.php"); +require_once(__DIR__ . "/classes/standard_forms.php"); require_once(__DIR__ . "/lib.php"); require_once($CFG->libdir . "/adminlib.php"); -- cgit v1.2.3