Added LinuxChix theme
[moodle-linuxchix.git] / login / signup_form.php
blob0886bd7c0cccb0d1f31ed4812c951873e44e365b
1 <?php // $Id$
3 require_once($CFG->libdir.'/formslib.php');
4 require_once($CFG->dirroot.'/user/profile/lib.php');
6 class login_signup_form extends moodleform {
7 function definition() {
8 global $USER, $CFG;
10 $mform =& $this->_form;
12 $mform->addElement('header', '', get_string('createuserandpass'), '');
15 $mform->addElement('text', 'username', get_string('username'), 'maxlength="100" size="12"');
16 $mform->setType('username', PARAM_NOTAGS);
17 $mform->addRule('username', get_string('missingusername'), 'required', null, 'server');
19 $mform->addElement('passwordunmask', 'password', get_string('password'), 'maxlength="32" size="12"');
20 $mform->setType('password', PARAM_RAW);
21 $mform->addRule('password', get_string('missingpassword'), 'required', null, 'server');
23 $mform->addElement('header', '', get_string('supplyinfo'),'');
25 $mform->addElement('text', 'email', get_string('email'), 'maxlength="100" size="25"');
26 $mform->setType('email', PARAM_NOTAGS);
27 $mform->addRule('email', get_string('missingemail'), 'required', null, 'server');
29 $mform->addElement('text', 'email2', get_string('emailagain'), 'maxlength="100" size="25"');
30 $mform->setType('email2', PARAM_NOTAGS);
31 $mform->addRule('email2', get_string('missingemail'), 'required', null, 'server');
33 $nameordercheck = new object();
34 $nameordercheck->firstname = 'a';
35 $nameordercheck->lastname = 'b';
36 if (fullname($nameordercheck) == 'b a' ) { // See MDL-4325
37 $mform->addElement('text', 'lastname', get_string('lastname'), 'maxlength="100" size="30"');
38 $mform->addElement('text', 'firstname', get_string('firstname'), 'maxlength="100" size="30"');
39 } else {
40 $mform->addElement('text', 'firstname', get_string('firstname'), 'maxlength="100" size="30"');
41 $mform->addElement('text', 'lastname', get_string('lastname'), 'maxlength="100" size="30"');
44 $mform->setType('firstname', PARAM_TEXT);
45 $mform->addRule('firstname', get_string('missingfirstname'), 'required', null, 'server');
47 $mform->setType('lastname', PARAM_TEXT);
48 $mform->addRule('lastname', get_string('missinglastname'), 'required', null, 'server');
50 $mform->addElement('text', 'city', get_string('city'), 'maxlength="20" size="20"');
51 $mform->setType('city', PARAM_TEXT);
52 $mform->addRule('city', get_string('missingcity'), 'required', null, 'server');
54 $country = get_list_of_countries();
55 $default_country[''] = get_string('selectacountry');
56 $country = array_merge($default_country, $country);
57 $mform->addElement('select', 'country', get_string('country'), $country);
58 $mform->addRule('country', get_string('missingcountry'), 'required', null, 'server');
60 if( !empty($CFG->country) ){
61 $mform->setDefault('country', $CFG->country);
62 }else{
63 $mform->setDefault('country', '');
66 if (signup_captcha_enabled()) {
67 $mform->addElement('recaptcha', 'recaptcha_element', get_string('recaptcha', 'auth'), array('https' => $CFG->loginhttps));
68 $mform->setHelpButton('recaptcha_element', array('recaptcha', get_string('recaptcha', 'auth')));
71 profile_signup_fields($mform);
73 if (!empty($CFG->sitepolicy)) {
74 $mform->addElement('header', '', get_string('policyagreement'), '');
75 $mform->addElement('static', 'policylink', '', '<a href="'.$CFG->sitepolicy.'" onclick="this.target=\'_blank\'">'.get_String('policyagreementclick').'</a>');
76 $mform->addElement('checkbox', 'policyagreed', get_string('policyaccept'));
77 $mform->addRule('policyagreed', get_string('policyagree'), 'required', null, 'server');
80 // buttons
81 $this->add_action_buttons(true, get_string('createaccount'));
85 function definition_after_data(){
86 $mform =& $this->_form;
88 $mform->applyFilter('username', 'moodle_strtolower');
89 $mform->applyFilter('username', 'trim');
92 function validation($data, $files) {
93 global $CFG;
94 $errors = parent::validation($data, $files);
96 $authplugin = get_auth_plugin($CFG->registerauth);
98 if (record_exists('user', 'username', $data['username'], 'mnethostid', $CFG->mnet_localhost_id)) {
99 $errors['username'] = get_string('usernameexists');
100 } else {
101 if (empty($CFG->extendedusernamechars)) {
102 $string = eregi_replace("[^(-\.[:alnum:])]", '', $data['username']);
103 if (strcmp($data['username'], $string)) {
104 $errors['username'] = get_string('alphanumerical');
109 //check if user exists in external db
110 //TODO: maybe we should check all enabled plugins instead
111 if ($authplugin->user_exists($data['username'])) {
112 $errors['username'] = get_string('usernameexists');
116 if (! validate_email($data['email'])) {
117 $errors['email'] = get_string('invalidemail');
119 } else if (record_exists('user', 'email', $data['email'])) {
120 $errors['email'] = get_string('emailexists').' <a href="forgot_password.php">'.get_string('newpassword').'?</a>';
122 if (empty($data['email2'])) {
123 $errors['email2'] = get_string('missingemail');
125 } else if ($data['email2'] != $data['email']) {
126 $errors['email2'] = get_string('invalidemail');
128 if (!isset($errors['email'])) {
129 if ($err = email_is_not_allowed($data['email'])) {
130 $errors['email'] = $err;
135 $errmsg = '';
136 if (!check_password_policy($data['password'], $errmsg)) {
137 $errors['password'] = $errmsg;
140 if (signup_captcha_enabled()) {
141 $recaptcha_element = $this->_form->getElement('recaptcha_element');
142 $challenge_field = $this->_form->_submitValues['recaptcha_challenge_field'];
143 $response_field = $this->_form->_submitValues['recaptcha_response_field'];
144 if (true !== ($result = $recaptcha_element->verify($challenge_field, $response_field))) {
145 $errors['recaptcha'] = $result;
149 return $errors;