MDL-22388 Added some checks to kill these scripts dead with an unequivocal notice...
[moodle.git] / group / grouping_form.php
CommitLineData
4ca6cfbf 1<?php
8bdc9cac
SH
2/**
3 * Create/Edit grouping form.
4 *
5 * @copyright &copy; 2006 The Open University
6 * @author N.D.Freear AT open.ac.uk
7 * @author J.White AT open.ac.uk
8 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
9 * @package groups
10 */
ddff2fa8 11
bfebaf64
MD
12if (!defined('MOODLE_INTERNAL')) {
13 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
14}
15
ddff2fa8 16require_once($CFG->dirroot.'/lib/formslib.php');
17
18/// get url variables
19class grouping_form extends moodleform {
20
21 // Define the form
22 function definition () {
23 global $USER, $CFG, $COURSE;
24
25 $mform =& $this->_form;
8bdc9cac 26 $editoroptions = $this->_customdata['editoroptions'];
ddff2fa8 27
28 $mform->addElement('text','name', get_string('groupingname', 'group'),'maxlength="254" size="50"');
29 $mform->addRule('name', get_string('required'), 'required', null, 'server');
30 $mform->setType('name', PARAM_MULTILANG);
31
8bdc9cac
SH
32 $mform->addElement('editor', 'description_editor', get_string('groupingdescription', 'group'), null, $editoroptions);
33 $mform->setType('description_editor', PARAM_RAW);
ddff2fa8 34
35 $mform->addElement('hidden','id');
36 $mform->setType('id', PARAM_INT);
37
38 $mform->addElement('hidden', 'courseid');
39 $mform->setType('courseid', PARAM_INT);
40
41 $this->add_action_buttons();
42 }
43
a78890d5 44 function validation($data, $files) {
dfdaabd6 45 global $COURSE, $DB;
ddff2fa8 46
a78890d5 47 $errors = parent::validation($data, $files);
ddff2fa8 48
9e1bb310 49 $textlib = textlib_get_instance();
50
32648682 51 $name = trim($data['name']);
dfdaabd6 52 if ($data['id'] and $grouping = $DB->get_record('groupings', array('id'=>$data['id']))) {
9e1bb310 53 if ($textlib->strtolower($grouping->name) != $textlib->strtolower($name)) {
ddff2fa8 54 if (groups_get_grouping_by_name($COURSE->id, $name)) {
55 $errors['name'] = get_string('groupingnameexists', 'group', $name);
56 }
57 }
58
59 } else if (groups_get_grouping_by_name($COURSE->id, $name)) {
60 $errors['name'] = get_string('groupingnameexists', 'group', $name);
61 }
62
a78890d5 63 return $errors;
ddff2fa8 64 }
65
66}