| [ Index ] |
PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008] |
[Summary view] [Print] [Text view]
1 <?php // $Id: signup_form.php,v 1.35.2.6 2008/07/23 05:21:21 nicolasconnault Exp $ 2 3 require_once($CFG->libdir.'/formslib.php'); 4 require_once($CFG->dirroot.'/user/profile/lib.php'); 5 6 class login_signup_form extends moodleform { 7 function definition() { 8 global $USER, $CFG; 9 10 $mform =& $this->_form; 11 12 $mform->addElement('header', '', get_string('createuserandpass'), ''); 13 14 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'); 18 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'); 22 23 $mform->addElement('header', '', get_string('supplyinfo'),''); 24 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'); 28 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'); 32 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"'); 42 } 43 44 $mform->setType('firstname', PARAM_TEXT); 45 $mform->addRule('firstname', get_string('missingfirstname'), 'required', null, 'server'); 46 47 $mform->setType('lastname', PARAM_TEXT); 48 $mform->addRule('lastname', get_string('missinglastname'), 'required', null, 'server'); 49 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'); 53 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'); 59 60 if( !empty($CFG->country) ){ 61 $mform->setDefault('country', $CFG->country); 62 }else{ 63 $mform->setDefault('country', ''); 64 } 65 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'))); 69 } 70 71 profile_signup_fields($mform); 72 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'); 78 } 79 80 // buttons 81 $this->add_action_buttons(true, get_string('createaccount')); 82 83 } 84 85 function definition_after_data(){ 86 $mform =& $this->_form; 87 88 $mform->applyFilter('username', 'moodle_strtolower'); 89 $mform->applyFilter('username', 'trim'); 90 } 91 92 function validation($data, $files) { 93 global $CFG; 94 $errors = parent::validation($data, $files); 95 96 $authplugin = get_auth_plugin($CFG->registerauth); 97 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'); 105 } 106 } 107 } 108 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'); 113 } 114 115 116 if (! validate_email($data['email'])) { 117 $errors['email'] = get_string('invalidemail'); 118 119 } else if (record_exists('user', 'email', $data['email'])) { 120 $errors['email'] = get_string('emailexists').' <a href="forgot_password.php">'.get_string('newpassword').'?</a>'; 121 } 122 if (empty($data['email2'])) { 123 $errors['email2'] = get_string('missingemail'); 124 125 } else if ($data['email2'] != $data['email']) { 126 $errors['email2'] = get_string('invalidemail'); 127 } 128 if (!isset($errors['email'])) { 129 if ($err = email_is_not_allowed($data['email'])) { 130 $errors['email'] = $err; 131 } 132 133 } 134 135 $errmsg = ''; 136 if (!check_password_policy($data['password'], $errmsg)) { 137 $errors['password'] = $errmsg; 138 } 139 140 if (signup_captcha_enabled()) { 141 $recaptcha_element = $this->_form->getElement('recaptcha_element'); 142 if (!empty($this->_form->_submitValues['recaptcha_challenge_field'])) { 143 $challenge_field = $this->_form->_submitValues['recaptcha_challenge_field']; 144 $response_field = $this->_form->_submitValues['recaptcha_response_field']; 145 if (true !== ($result = $recaptcha_element->verify($challenge_field, $response_field))) { 146 $errors['recaptcha'] = $result; 147 } 148 } else { 149 $errors['recaptcha'] = get_string('missingrecaptchachallengefield'); 150 } 151 } 152 153 return $errors; 154 155 156 } 157 } 158 159 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Jan 14 11:33:29 2009 | Cross-referenced by PHPXref 0.7 |