Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / login / signup_form.php
blobdf2f0a1e96d657b481bb57de16c82bb1bb77f7fc
1 <?php // $Id$
3 require_once($CFG->libdir.'/formslib.php');
5 class login_signup_form extends moodleform {
6 function definition() {
7 global $USER, $CFG;
9 $mform =& $this->_form;
11 $mform->addElement('header', '', get_string('createuserandpass'), '');
14 $mform->addElement('text', 'username', get_string('username'), 'maxlength="100" size="12"');
15 $mform->setType('username', PARAM_NOTAGS);
16 $mform->addRule('username', get_string('missingusername'), 'required', null, 'server');
18 $mform->addElement('passwordunmask', 'password', get_string('password'), 'maxlength="32" size="12"');
19 $mform->setType('password', PARAM_RAW);
20 $mform->addRule('password', get_string('missingpassword'), 'required', null, 'server');
22 $mform->addElement('header', '', get_string('supplyinfo'),'');
24 $mform->addElement('text', 'email', get_string('email'), 'maxlength="100" size="25"');
25 $mform->setType('email', PARAM_NOTAGS);
26 $mform->addRule('email', get_string('missingemail'), 'required', null, 'server');
28 $mform->addElement('text', 'email2', get_string('emailagain'), 'maxlength="100" size="25"');
29 $mform->setType('email2', PARAM_NOTAGS);
30 $mform->addRule('email2', get_string('missingemail'), 'required', null, 'server');
32 $nameordercheck = new object();
33 $nameordercheck->firstname = 'a';
34 $nameordercheck->lastname = 'b';
35 if (fullname($nameordercheck) == 'b a' ) { // See MDL-4325
36 $mform->addElement('text', 'lastname', get_string('lastname'), 'maxlength="100" size="30"');
37 $mform->addElement('text', 'firstname', get_string('firstname'), 'maxlength="100" size="30"');
38 } else {
39 $mform->addElement('text', 'firstname', get_string('firstname'), 'maxlength="100" size="30"');
40 $mform->addElement('text', 'lastname', get_string('lastname'), 'maxlength="100" size="30"');
43 $mform->setType('firstname', PARAM_TEXT);
44 $mform->addRule('firstname', get_string('missingfirstname'), 'required', null, 'server');
46 $mform->setType('lastname', PARAM_TEXT);
47 $mform->addRule('lastname', get_string('missinglastname'), 'required', null, 'server');
49 $mform->addElement('text', 'city', get_string('city'), 'maxlength="20" size="20"');
50 $mform->setType('city', PARAM_TEXT);
51 $mform->addRule('city', get_string('missingcity'), 'required', null, 'server');
53 $country = get_list_of_countries();
54 $default_country[''] = get_string('selectacountry');
55 $country = array_merge($default_country, $country);
56 $mform->addElement('select', 'country', get_string('country'), $country);
57 $mform->addRule('country', get_string('missingcountry'), 'required', null, 'server');
58 $mform->setDefault('country', '');
60 if (!empty($CFG->sitepolicy)) {
61 $mform->addElement('header', '', get_string('policyagreement'), '');
62 $mform->addElement('static', 'policylink', '', '<a href="'.$CFG->sitepolicy.'" onclick="this.target=\'_blank\'">'.get_String('policyagreementclick').'</a>');
63 $mform->addElement('checkbox', 'policyagreed', get_string('policyaccept'));
64 $mform->addRule('policyagreed', get_string('policyagree'), 'required', null, 'server');
67 // buttons
68 $this->add_action_buttons(true, get_string('createaccount'));
72 function definition_after_data(){
73 $mform =& $this->_form;
75 $mform->applyFilter('username', 'moodle_strtolower');
76 $mform->applyFilter('username', 'trim');
79 function validation($data) {
80 global $CFG;
81 $errors = array();
83 $authplugin = get_auth_plugin($CFG->registerauth);
85 if (record_exists('user', 'username', $data['username'], 'mnethostid', $CFG->mnet_localhost_id)) {
86 $errors['username'] = get_string('usernameexists');
87 } else {
88 if (empty($CFG->extendedusernamechars)) {
89 $string = eregi_replace("[^(-\.[:alnum:])]", '', $data['username']);
90 if (strcmp($data['username'], $string)) {
91 $errors['username'] = get_string('alphanumerical');
96 //check if user exists in external db
97 //TODO: maybe we should check all enabled plugins instead
98 if ($authplugin->user_exists($data['username'])) {
99 $errors['username'] = get_string('usernameexists');
103 if (! validate_email($data['email'])) {
104 $errors['email'] = get_string('invalidemail');
106 } else if (record_exists('user', 'email', $data['email'])) {
107 $errors['email'] = get_string('emailexists').' <a href="forgot_password.php">'.get_string('newpassword').'?</a>';
109 if (empty($data['email2'])) {
110 $errors['email2'] = get_string('missingemail');
112 } else if ($data['email2'] != $data['email']) {
113 $errors['email2'] = get_string('invalidemail');
115 if (!isset($errors['email'])) {
116 if ($err = email_is_not_allowed($data['email'])) {
117 $errors['email'] = $err;
122 if (!check_password_policy($data['password'], $errmsg)) {
123 $errors['password'] = $errmsg;
126 if (0 == count($errors)){
127 return true;
128 } else {
129 return $errors;