MDL-31006 revert partially @ get_config()
[moodle.git] / group / grouping_form.php
blob5842602788dcd43fe48b8d5356f525eaabaa2341
1 <?php
2 /**
3 * Create/Edit grouping form.
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
12 if (!defined('MOODLE_INTERNAL')) {
13 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
16 require_once($CFG->dirroot.'/lib/formslib.php');
18 /// get url variables
19 class grouping_form extends moodleform {
21 // Define the form
22 function definition () {
23 global $USER, $CFG, $COURSE;
25 $mform =& $this->_form;
26 $editoroptions = $this->_customdata['editoroptions'];
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);
32 $mform->addElement('editor', 'description_editor', get_string('groupingdescription', 'group'), null, $editoroptions);
33 $mform->setType('description_editor', PARAM_RAW);
35 $mform->addElement('hidden','id');
36 $mform->setType('id', PARAM_INT);
38 $mform->addElement('hidden', 'courseid');
39 $mform->setType('courseid', PARAM_INT);
41 $this->add_action_buttons();
44 function validation($data, $files) {
45 global $COURSE, $DB;
47 $errors = parent::validation($data, $files);
49 $textlib = textlib_get_instance();
51 $name = trim($data['name']);
52 if ($data['id'] and $grouping = $DB->get_record('groupings', array('id'=>$data['id']))) {
53 if ($textlib->strtolower($grouping->name) != $textlib->strtolower($name)) {
54 if (groups_get_grouping_by_name($COURSE->id, $name)) {
55 $errors['name'] = get_string('groupingnameexists', 'group', $name);
59 } else if (groups_get_grouping_by_name($COURSE->id, $name)) {
60 $errors['name'] = get_string('groupingnameexists', 'group', $name);
63 return $errors;