2012-12-07 09:34:46 +00:00
|
|
|
<?php
|
2021-11-24 07:29:43 +00:00
|
|
|
// This file is part of the htmlcert module for Moodle - http://moodle.org/
|
2012-12-07 09:34:46 +00:00
|
|
|
//
|
|
|
|
// 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
|
2013-07-22 05:06:18 +00:00
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
2012-12-07 09:34:46 +00:00
|
|
|
|
2017-02-16 12:12:19 +00:00
|
|
|
/**
|
2021-11-24 07:29:43 +00:00
|
|
|
* This file contains the form for handling the layout of the htmlcert instance.
|
2017-02-16 12:12:19 +00:00
|
|
|
*
|
2021-11-24 07:29:43 +00:00
|
|
|
* @package mod_htmlcert
|
|
|
|
* @copyright 2013 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@kumi.systems>
|
2017-02-16 12:12:19 +00:00
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
|
|
|
|
2021-11-24 07:29:43 +00:00
|
|
|
namespace mod_htmlcert;
|
2016-02-16 09:03:34 +00:00
|
|
|
|
2013-04-10 09:17:19 +00:00
|
|
|
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
2012-12-07 09:34:46 +00:00
|
|
|
|
2013-02-24 15:41:33 +00:00
|
|
|
require_once($CFG->dirroot . '/course/moodleform_mod.php');
|
2012-12-07 09:34:46 +00:00
|
|
|
|
|
|
|
/**
|
2021-11-24 07:29:43 +00:00
|
|
|
* The form for handling the layout of the htmlcert instance.
|
2012-12-07 09:34:46 +00:00
|
|
|
*
|
2021-11-24 07:29:43 +00:00
|
|
|
* @package mod_htmlcert
|
|
|
|
* @copyright 2013 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@kumi.systems>
|
2012-12-07 09:34:46 +00:00
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
2016-02-16 09:03:34 +00:00
|
|
|
class edit_form extends \moodleform {
|
2012-12-07 09:34:46 +00:00
|
|
|
|
|
|
|
/**
|
2017-02-16 12:12:19 +00:00
|
|
|
* @var int The id of the template being used.
|
2012-12-07 09:34:46 +00:00
|
|
|
*/
|
2016-02-16 09:03:34 +00:00
|
|
|
protected $tid = null;
|
2012-12-07 09:34:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Form definition.
|
|
|
|
*/
|
2013-07-23 06:44:11 +00:00
|
|
|
public function definition() {
|
2017-08-07 08:59:45 +00:00
|
|
|
global $DB, $OUTPUT;
|
2012-12-07 09:34:46 +00:00
|
|
|
|
|
|
|
$mform =& $this->_form;
|
|
|
|
|
2021-11-24 07:29:43 +00:00
|
|
|
$mform->addElement('text', 'name', get_string('name', 'htmlcert'), 'maxlength="255"');
|
2016-02-16 09:03:34 +00:00
|
|
|
$mform->setType('name', PARAM_TEXT);
|
|
|
|
$mform->addRule('name', null, 'required');
|
|
|
|
|
2021-11-24 08:20:10 +00:00
|
|
|
$mform->addElement('textarea', 'html', get_string('html', 'htmlcert'));
|
2021-11-24 08:03:55 +00:00
|
|
|
$mform->setType('html', PARAM_RAW);
|
2013-05-16 09:12:51 +00:00
|
|
|
|
2013-05-03 10:51:41 +00:00
|
|
|
// Add the submit buttons.
|
|
|
|
$group = array();
|
2013-05-16 09:12:51 +00:00
|
|
|
$group[] = $mform->createElement('submit', 'submitbtn', get_string('savechanges'));
|
2021-11-24 07:29:43 +00:00
|
|
|
$group[] = $mform->createElement('submit', 'previewbtn', get_string('savechangespreview', 'htmlcert'), array(), false);
|
2013-05-16 09:12:51 +00:00
|
|
|
$mform->addElement('group', 'submitbtngroup', '', $group, '', false);
|
2012-12-07 09:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-24 07:29:43 +00:00
|
|
|
* Fill in the current page data for this htmlcert.
|
2012-12-07 09:34:46 +00:00
|
|
|
*/
|
2013-07-23 06:44:11 +00:00
|
|
|
public function definition_after_data() {
|
2012-12-07 09:34:46 +00:00
|
|
|
global $DB;
|
|
|
|
$mform = $this->_form;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Some basic validation.
|
|
|
|
*
|
2017-02-16 12:12:19 +00:00
|
|
|
* @param array $data
|
|
|
|
* @param array $files
|
2012-12-07 09:34:46 +00:00
|
|
|
* @return array the errors that were found
|
|
|
|
*/
|
|
|
|
public function validation($data, $files) {
|
|
|
|
$errors = parent::validation($data, $files);
|
|
|
|
|
2017-01-31 09:15:49 +00:00
|
|
|
if (\core_text::strlen($data['name']) > 255) {
|
2021-11-24 07:29:43 +00:00
|
|
|
$errors['name'] = get_string('nametoolong', 'htmlcert');
|
2012-12-07 09:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $errors;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds the page elements to the form.
|
|
|
|
*
|
2021-11-24 07:29:43 +00:00
|
|
|
* @param \stdClass $page the htmlcert page
|
2013-07-25 10:36:43 +00:00
|
|
|
*/
|
2021-11-24 07:29:43 +00:00
|
|
|
protected function add_htmlcert_page_elements($page) {
|
2013-06-06 10:59:08 +00:00
|
|
|
global $DB, $OUTPUT;
|
2012-12-07 09:34:46 +00:00
|
|
|
|
|
|
|
// Create the form object.
|
|
|
|
$mform =& $this->_form;
|
|
|
|
|
2021-11-24 07:29:43 +00:00
|
|
|
$editlink = '/mod/htmlcert/edit.php';
|
2017-09-02 06:01:13 +00:00
|
|
|
$editlinkparams = array('tid' => $this->tid, 'sesskey' => sesskey());
|
2013-02-20 12:21:57 +00:00
|
|
|
|
2021-11-24 07:29:43 +00:00
|
|
|
$mform->addElement('text', 'pagewidth', get_string('width', 'htmlcert'));
|
|
|
|
$mform->setType('pagewidth', PARAM_INT);
|
|
|
|
$mform->setDefault('pagewidth', '210');
|
|
|
|
$mform->addRule('pagewidth', null, 'required', null, 'client');
|
|
|
|
$mform->addHelpButton('pagewidth', 'width', 'htmlcert');
|
2015-12-08 09:41:38 +00:00
|
|
|
|
2021-11-24 07:29:43 +00:00
|
|
|
$mform->addElement('text', 'pageheight', get_string('height', 'htmlcert'));
|
|
|
|
$mform->setType('pageheight', PARAM_INT);
|
|
|
|
$mform->setDefault('pageheight', '297');
|
|
|
|
$mform->addRule('pageheight', null, 'required', null, 'client');
|
|
|
|
$mform->addHelpButton('pageheight', 'height', 'htmlcert');
|
2015-07-29 01:29:16 +00:00
|
|
|
|
2012-12-07 09:34:46 +00:00
|
|
|
}
|
|
|
|
}
|