~ubuntu-branches/ubuntu/jaunty/moodle/jaunty

« back to all changes in this revision

Viewing changes to group/group_form.php

  • Committer: Bazaar Package Importer
  • Author(s): Jordan Mantha, Matt Oquist
  • Date: 2009-02-25 15:16:22 UTC
  • mfrom: (1.1.11 upstream)
  • Revision ID: james.westby@ubuntu.com-20090225151622-0ekt1liwhv2obfza
Tags: 1.9.4.dfsg-0ubuntu1
* Merge with Debian git (Closes LP: #322961, #239481, #334611):
  - use Ubuntu's smarty lib directory for linking
  - use internal yui library 
  - add update-notifier support back in

[Matt Oquist]
  * renamed prerm script
  * significantly rewrote postinst and other maintainer scripts to improve
    user experience and package maintainability
    (Closes LP: #225662, #325450, #327843, #303078, #234609)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php //$Id: group_form.php,v 1.3.2.4 2008/12/29 21:32:36 skodak Exp $
 
2
 
 
3
require_once($CFG->dirroot.'/lib/formslib.php');
 
4
 
 
5
/// get url variables
 
6
class group_form extends moodleform {
 
7
 
 
8
    // Define the form
 
9
    function definition () {
 
10
        global $USER, $CFG, $COURSE;
 
11
 
 
12
        $mform =& $this->_form;
 
13
 
 
14
        $mform->addElement('text','name', get_string('groupname', 'group'),'maxlength="254" size="50"');
 
15
        $mform->addRule('name', get_string('required'), 'required', null, 'client');
 
16
        $mform->setType('name', PARAM_MULTILANG);
 
17
 
 
18
        $mform->addElement('htmleditor', 'description', get_string('groupdescription', 'group'), array('rows'=> '15', 'course' => $COURSE->id, 'cols'=>'45'));
 
19
        $mform->setType('description', PARAM_RAW);
 
20
 
 
21
        $mform->addElement('passwordunmask', 'enrolmentkey', get_string('enrolmentkey', 'group'), 'maxlength="254" size="24"', get_string('enrolmentkey'));
 
22
        $mform->setHelpButton('enrolmentkey', array('groupenrolmentkey', get_string('enrolmentkey', 'group')), true);
 
23
        $mform->setType('enrolmentkey', PARAM_RAW);
 
24
 
 
25
        $maxbytes = get_max_upload_file_size($CFG->maxbytes, $COURSE->maxbytes);
 
26
 
 
27
        if (!empty($CFG->gdversion) and $maxbytes) {
 
28
            $options = array(get_string('no'), get_string('yes'));
 
29
            $mform->addElement('select', 'hidepicture', get_string('hidepicture'), $options);
 
30
 
 
31
            $this->set_upload_manager(new upload_manager('imagefile', false, false, null, false, 0, true, true, false));
 
32
            $mform->addElement('file', 'imagefile', get_string('newpicture', 'group'));
 
33
            $mform->setHelpButton('imagefile', array ('picture', get_string('helppicture')), true);
 
34
        }
 
35
 
 
36
        $mform->addElement('hidden','id');
 
37
        $mform->setType('id', PARAM_INT);
 
38
 
 
39
        $mform->addElement('hidden','courseid');
 
40
        $mform->setType('courseid', PARAM_INT);
 
41
 
 
42
        $this->add_action_buttons();
 
43
    }
 
44
 
 
45
    function validation($data, $files) {
 
46
        global $COURSE, $CFG;
 
47
 
 
48
        $errors = parent::validation($data, $files);
 
49
 
 
50
        $textlib = textlib_get_instance();
 
51
 
 
52
        $name = trim(stripslashes($data['name']));
 
53
        if ($data['id'] and $group = get_record('groups', 'id', $data['id'])) {
 
54
            if ($textlib->strtolower($group->name) != $textlib->strtolower($name)) {
 
55
                if (groups_get_group_by_name($COURSE->id,  $name)) {
 
56
                    $errors['name'] = get_string('groupnameexists', 'group', $name);
 
57
                }
 
58
            }
 
59
 
 
60
            if (!empty($CFG->enrol_manual_usepasswordpolicy) and $data['enrolmentkey'] != '' and $group->enrolmentkey !== $data['enrolmentkey']) {
 
61
                // enforce password policy only if changing password
 
62
                $errmsg = '';
 
63
                if (!check_password_policy($data['enrolmentkey'], $errmsg)) {
 
64
                    $errors['enrolmentkey'] = $errmsg;
 
65
                }
 
66
            }
 
67
 
 
68
        } else if (groups_get_group_by_name($COURSE->id, $name)) {
 
69
            $errors['name'] = get_string('groupnameexists', 'group', $name);
 
70
        }
 
71
 
 
72
        return $errors;
 
73
    }
 
74
 
 
75
    function get_um() {
 
76
        return $this->_upload_manager;
 
77
    }
 
78
}
 
79
 
 
80
?>