Beispiel #1
0
 function definition()
 {
     global $USER, $CFG;
     $mform = $this->_form;
     $mform->addElement('header', 'createuserandpass', get_string('createuserandpass'), '');
     $mform->addElement('text', 'username', get_string('username'), 'maxlength="100" size="12"');
     $mform->setType('username', PARAM_NOTAGS);
     $mform->addRule('username', get_string('missingusername'), 'required', null, 'server');
     if (!empty($CFG->passwordpolicy)) {
         $mform->addElement('static', 'passwordpolicyinfo', '', print_password_policy());
     }
     $mform->addElement('passwordunmask', 'password', get_string('password'), 'maxlength="32" size="12"');
     $mform->setType('password', PARAM_RAW);
     $mform->addRule('password', get_string('missingpassword'), 'required', null, 'server');
     $mform->addElement('header', 'supplyinfo', get_string('supplyinfo'), '');
     $mform->addElement('text', 'email', get_string('email'), 'maxlength="100" size="25"');
     $mform->setType('email', PARAM_RAW_TRIMMED);
     $mform->addRule('email', get_string('missingemail'), 'required', null, 'server');
     $mform->addElement('text', 'email2', get_string('emailagain'), 'maxlength="100" size="25"');
     $mform->setType('email2', PARAM_RAW_TRIMMED);
     $mform->addRule('email2', get_string('missingemail'), 'required', null, 'server');
     $namefields = useredit_get_required_name_fields();
     foreach ($namefields as $field) {
         $mform->addElement('text', $field, get_string($field), 'maxlength="100" size="30"');
         $mform->setType($field, PARAM_TEXT);
         $stringid = 'missing' . $field;
         if (!get_string_manager()->string_exists($stringid, 'moodle')) {
             $stringid = 'required';
         }
         $mform->addRule($field, get_string($stringid), 'required', null, 'server');
     }
     $mform->addElement('text', 'city', get_string('city'), 'maxlength="120" size="20"');
     $mform->setType('city', PARAM_TEXT);
     if (!empty($CFG->defaultcity)) {
         $mform->setDefault('city', $CFG->defaultcity);
     }
     $country = get_string_manager()->get_list_of_countries();
     $default_country[''] = get_string('selectacountry');
     $country = array_merge($default_country, $country);
     $mform->addElement('select', 'country', get_string('country'), $country);
     if (!empty($CFG->country)) {
         $mform->setDefault('country', $CFG->country);
     } else {
         $mform->setDefault('country', '');
     }
     if ($this->signup_captcha_enabled()) {
         $mform->addElement('recaptcha', 'recaptcha_element', get_string('security_question', 'auth'), array('https' => $CFG->loginhttps));
         $mform->addHelpButton('recaptcha_element', 'recaptcha', 'auth');
     }
     profile_signup_fields($mform);
     if (!empty($CFG->sitepolicy)) {
         $mform->addElement('header', 'policyagreement', get_string('policyagreement'), '');
         $mform->setExpanded('policyagreement');
         $mform->addElement('static', 'policylink', '', '<a href="' . $CFG->sitepolicy . '" onclick="this.target=\'_blank\'">' . get_String('policyagreementclick') . '</a>');
         $mform->addElement('checkbox', 'policyagreed', get_string('policyaccept'));
         $mform->addRule('policyagreed', get_string('policyagree'), 'required', null, 'server');
     }
     // buttons
     $this->add_action_buttons(true, get_string('createaccount'));
 }
 /**
  * Test that the required fields are returned in the correct order.
  */
 function test_useredit_get_required_name_fields()
 {
     global $CFG;
     // Back up config settings for restore later.
     $originalcfg = new stdClass();
     $originalcfg->fullnamedisplay = $CFG->fullnamedisplay;
     $CFG->fullnamedisplay = 'language';
     $expectedresult = array(5 => 'firstname', 21 => 'lastname');
     $this->assertEquals(useredit_get_required_name_fields(), $expectedresult);
     $CFG->fullnamedisplay = 'firstname';
     $expectedresult = array(5 => 'firstname', 21 => 'lastname');
     $this->assertEquals(useredit_get_required_name_fields(), $expectedresult);
     $CFG->fullnamedisplay = 'lastname firstname';
     $expectedresult = array('lastname', 9 => 'firstname');
     $this->assertEquals(useredit_get_required_name_fields(), $expectedresult);
     $CFG->fullnamedisplay = 'firstnamephonetic lastnamephonetic';
     $expectedresult = array(5 => 'firstname', 21 => 'lastname');
     $this->assertEquals(useredit_get_required_name_fields(), $expectedresult);
     // Tidy up after we finish testing.
     $CFG->fullnamedisplay = $originalcfg->fullnamedisplay;
 }
 /**
  * Get the signup required settings and profile fields.
  *
  * @return array settings and possible warnings
  * @since Moodle 3.2
  * @throws moodle_exception
  */
 public static function get_signup_settings()
 {
     global $CFG, $PAGE;
     $context = context_system::instance();
     // We need this to make work the format text functions.
     $PAGE->set_context($context);
     self::check_signup_enabled();
     $result = array();
     $result['namefields'] = useredit_get_required_name_fields();
     if (!empty($CFG->passwordpolicy)) {
         $result['passwordpolicy'] = print_password_policy();
     }
     if (!empty($CFG->sitepolicy)) {
         $result['sitepolicy'] = $CFG->sitepolicy;
     }
     if (!empty($CFG->defaultcity)) {
         $result['defaultcity'] = $CFG->defaultcity;
     }
     if (!empty($CFG->country)) {
         $result['country'] = $CFG->country;
     }
     if ($fields = profile_get_signup_fields()) {
         $result['profilefields'] = array();
         foreach ($fields as $field) {
             $fielddata = $field->object->get_field_config_for_external();
             $fielddata['categoryname'] = external_format_string($field->categoryname, $context->id);
             $fielddata['name'] = external_format_string($fielddata['name'], $context->id);
             list($fielddata['defaultdata'], $fielddata['defaultdataformat']) = external_format_text($fielddata['defaultdata'], $fielddata['defaultdataformat'], $context->id);
             $result['profilefields'][] = $fielddata;
         }
     }
     if (signup_captcha_enabled()) {
         require_once $CFG->libdir . '/recaptchalib.php';
         // We return the public key, maybe we want to use the javascript api to get the image.
         $result['recaptchapublickey'] = $CFG->recaptchapublickey;
         list($result['recaptchachallengehash'], $result['recaptchachallengeimage'], $result['recaptchachallengejs']) = recaptcha_get_challenge_hash_and_urls(RECAPTCHA_API_SECURE_SERVER, $CFG->recaptchapublickey);
     }
     $result['warnings'] = array();
     return $result;
 }
Beispiel #4
0
 /**
  * Server side validation.
  */
 function validation($data, $files)
 {
     $errors = parent::validation($data, $files);
     $columns = $this->_customdata['columns'];
     $optype = $data['uutype'];
     // detect if password column needed in file
     if (!in_array('password', $columns)) {
         switch ($optype) {
             case UU_USER_UPDATE:
                 if (!empty($data['uupasswordold'])) {
                     $errors['uupasswordold'] = get_string('missingfield', 'error', 'password');
                 }
                 break;
             case UU_USER_ADD_UPDATE:
                 if (empty($data['uupasswordnew'])) {
                     $errors['uupasswordnew'] = get_string('missingfield', 'error', 'password');
                 }
                 if (!empty($data['uupasswordold'])) {
                     $errors['uupasswordold'] = get_string('missingfield', 'error', 'password');
                 }
                 break;
             case UU_USER_ADDNEW:
                 if (empty($data['uupasswordnew'])) {
                     $errors['uupasswordnew'] = get_string('missingfield', 'error', 'password');
                 }
                 break;
             case UU_USER_ADDINC:
                 if (empty($data['uupasswordnew'])) {
                     $errors['uupasswordnew'] = get_string('missingfield', 'error', 'password');
                 }
                 break;
         }
     }
     // look for other required data
     if ($optype != UU_USER_UPDATE) {
         $requiredusernames = useredit_get_required_name_fields();
         $missing = array();
         foreach ($requiredusernames as $requiredusername) {
             if (!in_array($requiredusername, $columns)) {
                 $missing[] = get_string('missingfield', 'error', $requiredusername);
             }
         }
         if ($missing) {
             $errors['uutype'] = implode('<br />', $missing);
         }
         if (!in_array('email', $columns) and empty($data['email'])) {
             $errors['email'] = get_string('requiredtemplate', 'tool_uploaduser');
         }
     }
     return $errors;
 }
Beispiel #5
0
/**
 * Powerful function that is used by edit and editadvanced to add common form elements/rules/etc.
 *
 * @param moodleform $mform
 * @param array $editoroptions
 * @param array $filemanageroptions
 * @param stdClass $user
 */
function useredit_shared_definition(&$mform, $editoroptions, $filemanageroptions, $user)
{
    global $CFG, $USER, $DB;
    if ($user->id > 0) {
        useredit_load_preferences($user, false);
    }
    $strrequired = get_string('required');
    $stringman = get_string_manager();
    // Add the necessary names.
    foreach (useredit_get_required_name_fields() as $fullname) {
        $mform->addElement('text', $fullname, get_string($fullname), 'maxlength="100" size="30"');
        if ($stringman->string_exists('missing' . $fullname, 'core')) {
            $strmissingfield = get_string('missing' . $fullname, 'core');
        } else {
            $strmissingfield = $strrequired;
        }
        $mform->addRule($fullname, $strmissingfield, 'required', null, 'client');
        $mform->setType($fullname, PARAM_NOTAGS);
    }
    $enabledusernamefields = useredit_get_enabled_name_fields();
    // Add the enabled additional name fields.
    foreach ($enabledusernamefields as $addname) {
        $mform->addElement('text', $addname, get_string($addname), 'maxlength="100" size="30"');
        $mform->setType($addname, PARAM_NOTAGS);
    }
    // Do not show email field if change confirmation is pending.
    if ($user->id > 0 and !empty($CFG->emailchangeconfirmation) and !empty($user->preference_newemail)) {
        $notice = get_string('emailchangepending', 'auth', $user);
        $notice .= '<br /><a href="edit.php?cancelemailchange=1&amp;id=' . $user->id . '">' . get_string('emailchangecancel', 'auth') . '</a>';
        $mform->addElement('static', 'emailpending', get_string('email'), $notice);
    } else {
        $mform->addElement('text', 'email', get_string('email'), 'maxlength="100" size="30"');
        $mform->addRule('email', $strrequired, 'required', null, 'client');
        $mform->setType('email', PARAM_RAW_TRIMMED);
    }
    $choices = array();
    $choices['0'] = get_string('emaildisplayno');
    $choices['1'] = get_string('emaildisplayyes');
    $choices['2'] = get_string('emaildisplaycourse');
    $mform->addElement('select', 'maildisplay', get_string('emaildisplay'), $choices);
    $mform->setDefault('maildisplay', core_user::get_property_default('maildisplay'));
    $mform->addElement('text', 'city', get_string('city'), 'maxlength="120" size="21"');
    $mform->setType('city', PARAM_TEXT);
    if (!empty($CFG->defaultcity)) {
        $mform->setDefault('city', $CFG->defaultcity);
    }
    $choices = get_string_manager()->get_list_of_countries();
    $choices = array('' => get_string('selectacountry') . '...') + $choices;
    $mform->addElement('select', 'country', get_string('selectacountry'), $choices);
    if (!empty($CFG->country)) {
        $mform->setDefault('country', core_user::get_property_default('country'));
    }
    if (isset($CFG->forcetimezone) and $CFG->forcetimezone != 99) {
        $choices = core_date::get_list_of_timezones($CFG->forcetimezone);
        $mform->addElement('static', 'forcedtimezone', get_string('timezone'), $choices[$CFG->forcetimezone]);
        $mform->addElement('hidden', 'timezone');
        $mform->setType('timezone', core_user::get_property_type('timezone'));
    } else {
        $choices = core_date::get_list_of_timezones($user->timezone, true);
        $mform->addElement('select', 'timezone', get_string('timezone'), $choices);
    }
    if (!empty($CFG->allowuserthemes)) {
        $choices = array();
        $choices[''] = get_string('default');
        $themes = get_list_of_themes();
        foreach ($themes as $key => $theme) {
            if (empty($theme->hidefromselector)) {
                $choices[$key] = get_string('pluginname', 'theme_' . $theme->name);
            }
        }
        $mform->addElement('select', 'theme', get_string('preferredtheme'), $choices);
    }
    $mform->addElement('editor', 'description_editor', get_string('userdescription'), null, $editoroptions);
    $mform->setType('description_editor', PARAM_CLEANHTML);
    $mform->addHelpButton('description_editor', 'userdescription');
    if (empty($USER->newadminuser)) {
        $mform->addElement('header', 'moodle_picture', get_string('pictureofuser'));
        $mform->setExpanded('moodle_picture', true);
        if (!empty($CFG->enablegravatar)) {
            $mform->addElement('html', html_writer::tag('p', get_string('gravatarenabled')));
        }
        $mform->addElement('static', 'currentpicture', get_string('currentpicture'));
        $mform->addElement('checkbox', 'deletepicture', get_string('delete'));
        $mform->setDefault('deletepicture', 0);
        $mform->addElement('filemanager', 'imagefile', get_string('newpicture'), '', $filemanageroptions);
        $mform->addHelpButton('imagefile', 'newpicture');
        $mform->addElement('text', 'imagealt', get_string('imagealt'), 'maxlength="100" size="30"');
        $mform->setType('imagealt', PARAM_TEXT);
    }
    // Display user name fields that are not currenlty enabled here if there are any.
    $disabledusernamefields = useredit_get_disabled_name_fields($enabledusernamefields);
    if (count($disabledusernamefields) > 0) {
        $mform->addElement('header', 'moodle_additional_names', get_string('additionalnames'));
        foreach ($disabledusernamefields as $allname) {
            $mform->addElement('text', $allname, get_string($allname), 'maxlength="100" size="30"');
            $mform->setType($allname, PARAM_NOTAGS);
        }
    }
    if (core_tag_tag::is_enabled('core', 'user') and empty($USER->newadminuser)) {
        $mform->addElement('header', 'moodle_interests', get_string('interests'));
        $mform->addElement('tags', 'interests', get_string('interestslist'), array('itemtype' => 'user', 'component' => 'core'));
        $mform->addHelpButton('interests', 'interestslist');
    }
    // Moodle optional fields.
    $mform->addElement('header', 'moodle_optional', get_string('optional', 'form'));
    $mform->addElement('text', 'url', get_string('webpage'), 'maxlength="255" size="50"');
    $mform->setType('url', core_user::get_property_type('url'));
    $mform->addElement('text', 'icq', get_string('icqnumber'), 'maxlength="15" size="25"');
    $mform->setType('icq', core_user::get_property_type('icq'));
    $mform->setForceLtr('icq');
    $mform->addElement('text', 'skype', get_string('skypeid'), 'maxlength="50" size="25"');
    $mform->setType('skype', core_user::get_property_type('skype'));
    $mform->setForceLtr('skype');
    $mform->addElement('text', 'aim', get_string('aimid'), 'maxlength="50" size="25"');
    $mform->setType('aim', core_user::get_property_type('aim'));
    $mform->setForceLtr('aim');
    $mform->addElement('text', 'yahoo', get_string('yahooid'), 'maxlength="50" size="25"');
    $mform->setType('yahoo', core_user::get_property_type('yahoo'));
    $mform->setForceLtr('yahoo');
    $mform->addElement('text', 'msn', get_string('msnid'), 'maxlength="50" size="25"');
    $mform->setType('msn', core_user::get_property_type('msn'));
    $mform->setForceLtr('msn');
    $mform->addElement('text', 'idnumber', get_string('idnumber'), 'maxlength="255" size="25"');
    $mform->setType('idnumber', core_user::get_property_type('idnumber'));
    $mform->addElement('text', 'institution', get_string('institution'), 'maxlength="255" size="25"');
    $mform->setType('institution', core_user::get_property_type('institution'));
    $mform->addElement('text', 'department', get_string('department'), 'maxlength="255" size="25"');
    $mform->setType('department', core_user::get_property_type('department'));
    $mform->addElement('text', 'phone1', get_string('phone1'), 'maxlength="20" size="25"');
    $mform->setType('phone1', core_user::get_property_type('phone1'));
    $mform->setForceLtr('phone1');
    $mform->addElement('text', 'phone2', get_string('phone2'), 'maxlength="20" size="25"');
    $mform->setType('phone2', core_user::get_property_type('phone2'));
    $mform->setForceLtr('phone2');
    $mform->addElement('text', 'address', get_string('address'), 'maxlength="255" size="25"');
    $mform->setType('address', core_user::get_property_type('address'));
}
Beispiel #6
0
function useredit_shared_definition(&$mform, $editoroptions = null, $filemanageroptions = null)
{
    global $CFG, $USER, $DB;
    $user = $DB->get_record('user', array('id' => $USER->id));
    useredit_load_preferences($user, false);
    $strrequired = get_string('required');
    // Add the necessary names.
    foreach (useredit_get_required_name_fields() as $fullname) {
        $mform->addElement('text', $fullname, get_string($fullname), 'maxlength="100" size="30"');
        $mform->addRule($fullname, $strrequired, 'required', null, 'client');
        $mform->setType($fullname, PARAM_NOTAGS);
    }
    $enabledusernamefields = useredit_get_enabled_name_fields();
    // Add the enabled additional name fields.
    foreach ($enabledusernamefields as $addname) {
        $mform->addElement('text', $addname, get_string($addname), 'maxlength="100" size="30"');
        $mform->setType($addname, PARAM_NOTAGS);
    }
    // Do not show email field if change confirmation is pending
    if (!empty($CFG->emailchangeconfirmation) and !empty($user->preference_newemail)) {
        $notice = get_string('emailchangepending', 'auth', $user);
        $notice .= '<br /><a href="edit.php?cancelemailchange=1&amp;id=' . $user->id . '">' . get_string('emailchangecancel', 'auth') . '</a>';
        $mform->addElement('static', 'emailpending', get_string('email'), $notice);
    } else {
        $mform->addElement('text', 'email', get_string('email'), 'maxlength="100" size="30"');
        $mform->addRule('email', $strrequired, 'required', null, 'client');
        $mform->setType('email', PARAM_EMAIL);
    }
    $choices = array();
    $choices['0'] = get_string('emaildisplayno');
    $choices['1'] = get_string('emaildisplayyes');
    $choices['2'] = get_string('emaildisplaycourse');
    $mform->addElement('select', 'maildisplay', get_string('emaildisplay'), $choices);
    $mform->setDefault('maildisplay', 2);
    $choices = array();
    $choices['0'] = get_string('textformat');
    $choices['1'] = get_string('htmlformat');
    $mform->addElement('select', 'mailformat', get_string('emailformat'), $choices);
    $mform->setDefault('mailformat', 1);
    if (!empty($CFG->allowusermailcharset)) {
        $choices = array();
        $charsets = get_list_of_charsets();
        if (!empty($CFG->sitemailcharset)) {
            $choices['0'] = get_string('site') . ' (' . $CFG->sitemailcharset . ')';
        } else {
            $choices['0'] = get_string('site') . ' (UTF-8)';
        }
        $choices = array_merge($choices, $charsets);
        $mform->addElement('select', 'preference_mailcharset', get_string('emailcharset'), $choices);
    }
    $choices = array();
    $choices['0'] = get_string('emaildigestoff');
    $choices['1'] = get_string('emaildigestcomplete');
    $choices['2'] = get_string('emaildigestsubjects');
    $mform->addElement('select', 'maildigest', get_string('emaildigest'), $choices);
    $mform->setDefault('maildigest', 0);
    $mform->addHelpButton('maildigest', 'emaildigest');
    $choices = array();
    $choices['1'] = get_string('autosubscribeyes');
    $choices['0'] = get_string('autosubscribeno');
    $mform->addElement('select', 'autosubscribe', get_string('autosubscribe'), $choices);
    $mform->setDefault('autosubscribe', 1);
    if (!empty($CFG->forum_trackreadposts)) {
        $choices = array();
        $choices['0'] = get_string('trackforumsno');
        $choices['1'] = get_string('trackforumsyes');
        $mform->addElement('select', 'trackforums', get_string('trackforums'), $choices);
        $mform->setDefault('trackforums', 0);
    }
    $editors = editors_get_enabled();
    if (count($editors) > 1) {
        $choices = array('' => get_string('defaulteditor'));
        $firsteditor = '';
        foreach (array_keys($editors) as $editor) {
            if (!$firsteditor) {
                $firsteditor = $editor;
            }
            $choices[$editor] = get_string('pluginname', 'editor_' . $editor);
        }
        $mform->addElement('select', 'preference_htmleditor', get_string('textediting'), $choices);
        $mform->setDefault('preference_htmleditor', '');
    } else {
        // Empty string means use the first chosen text editor.
        $mform->addElement('hidden', 'preference_htmleditor');
        $mform->setDefault('preference_htmleditor', '');
        $mform->setType('preference_htmleditor', PARAM_PLUGIN);
    }
    $mform->addElement('text', 'city', get_string('city'), 'maxlength="120" size="21"');
    $mform->setType('city', PARAM_TEXT);
    if (!empty($CFG->defaultcity)) {
        $mform->setDefault('city', $CFG->defaultcity);
    }
    $choices = get_string_manager()->get_list_of_countries();
    $choices = array('' => get_string('selectacountry') . '...') + $choices;
    $mform->addElement('select', 'country', get_string('selectacountry'), $choices);
    if (!empty($CFG->country)) {
        $mform->setDefault('country', $CFG->country);
    }
    $choices = get_list_of_timezones();
    $choices['99'] = get_string('serverlocaltime');
    if ($CFG->forcetimezone != 99) {
        $mform->addElement('static', 'forcedtimezone', get_string('timezone'), $choices[$CFG->forcetimezone]);
    } else {
        $mform->addElement('select', 'timezone', get_string('timezone'), $choices);
        $mform->setDefault('timezone', '99');
    }
    $mform->addElement('select', 'lang', get_string('preferredlanguage'), get_string_manager()->get_list_of_translations());
    $mform->setDefault('lang', $CFG->lang);
    // Multi-Calendar Support - see MDL-18375.
    $calendartypes = \core_calendar\type_factory::get_list_of_calendar_types();
    // We do not want to show this option unless there is more than one calendar type to display.
    if (count($calendartypes) > 1) {
        $mform->addElement('select', 'calendartype', get_string('preferredcalendar', 'calendar'), $calendartypes);
    }
    if (!empty($CFG->allowuserthemes)) {
        $choices = array();
        $choices[''] = get_string('default');
        $themes = get_list_of_themes();
        foreach ($themes as $key => $theme) {
            if (empty($theme->hidefromselector)) {
                $choices[$key] = get_string('pluginname', 'theme_' . $theme->name);
            }
        }
        $mform->addElement('select', 'theme', get_string('preferredtheme'), $choices);
    }
    $mform->addElement('editor', 'description_editor', get_string('userdescription'), null, $editoroptions);
    $mform->setType('description_editor', PARAM_CLEANHTML);
    $mform->addHelpButton('description_editor', 'userdescription');
    if (empty($USER->newadminuser)) {
        $mform->addElement('header', 'moodle_picture', get_string('pictureofuser'));
        if (!empty($CFG->enablegravatar)) {
            $mform->addElement('html', html_writer::tag('p', get_string('gravatarenabled')));
        }
        $mform->addElement('static', 'currentpicture', get_string('currentpicture'));
        $mform->addElement('checkbox', 'deletepicture', get_string('delete'));
        $mform->setDefault('deletepicture', 0);
        $mform->addElement('filemanager', 'imagefile', get_string('newpicture'), '', $filemanageroptions);
        $mform->addHelpButton('imagefile', 'newpicture');
        $mform->addElement('text', 'imagealt', get_string('imagealt'), 'maxlength="100" size="30"');
        $mform->setType('imagealt', PARAM_TEXT);
    }
    // Display user name fields that are not currenlty enabled here if there are any.
    $disabledusernamefields = useredit_get_disabled_name_fields($enabledusernamefields);
    if (count($disabledusernamefields) > 0) {
        $mform->addElement('header', 'moodle_additional_names', get_string('additionalnames'));
        foreach ($disabledusernamefields as $allname) {
            $mform->addElement('text', $allname, get_string($allname), 'maxlength="100" size="30"');
            $mform->setType($allname, PARAM_NOTAGS);
        }
    }
    if (!empty($CFG->usetags) and empty($USER->newadminuser)) {
        $mform->addElement('header', 'moodle_interests', get_string('interests'));
        $mform->addElement('tags', 'interests', get_string('interestslist'), array('display' => 'noofficial'));
        $mform->addHelpButton('interests', 'interestslist');
    }
    /// Moodle optional fields
    $mform->addElement('header', 'moodle_optional', get_string('optional', 'form'));
    $mform->addElement('text', 'url', get_string('webpage'), 'maxlength="255" size="50"');
    $mform->setType('url', PARAM_URL);
    $mform->addElement('text', 'icq', get_string('icqnumber'), 'maxlength="15" size="25"');
    $mform->setType('icq', PARAM_NOTAGS);
    $mform->addElement('text', 'skype', get_string('skypeid'), 'maxlength="50" size="25"');
    $mform->setType('skype', PARAM_NOTAGS);
    $mform->addElement('text', 'aim', get_string('aimid'), 'maxlength="50" size="25"');
    $mform->setType('aim', PARAM_NOTAGS);
    $mform->addElement('text', 'yahoo', get_string('yahooid'), 'maxlength="50" size="25"');
    $mform->setType('yahoo', PARAM_NOTAGS);
    $mform->addElement('text', 'msn', get_string('msnid'), 'maxlength="50" size="25"');
    $mform->setType('msn', PARAM_NOTAGS);
    $mform->addElement('text', 'idnumber', get_string('idnumber'), 'maxlength="255" size="25"');
    $mform->setType('idnumber', PARAM_NOTAGS);
    $mform->addElement('text', 'institution', get_string('institution'), 'maxlength="255" size="25"');
    $mform->setType('institution', PARAM_TEXT);
    $mform->addElement('text', 'department', get_string('department'), 'maxlength="255" size="25"');
    $mform->setType('department', PARAM_TEXT);
    $mform->addElement('text', 'phone1', get_string('phone'), 'maxlength="20" size="25"');
    $mform->setType('phone1', PARAM_NOTAGS);
    $mform->addElement('text', 'phone2', get_string('phone2'), 'maxlength="20" size="25"');
    $mform->setType('phone2', PARAM_NOTAGS);
    $mform->addElement('text', 'address', get_string('address'), 'maxlength="255" size="25"');
    $mform->setType('address', PARAM_TEXT);
}
Beispiel #7
0
 function definition_after_data()
 {
     $mform = $this->_form;
     $mform->applyFilter('username', 'trim');
     // Trim required name fields.
     foreach (useredit_get_required_name_fields() as $field) {
         $mform->applyFilter($field, 'trim');
     }
 }
Beispiel #8
0
$PAGE->set_url('/login/signup.php');
$PAGE->set_context(context_system::instance());
$mform_signup = $authplugin->signup_form();
if ($mform_signup->is_cancelled()) {
    redirect(get_login_url());
} else {
    if ($user = $mform_signup->get_data()) {
        $user->confirmed = 0;
        $user->lang = current_language();
        $user->firstaccess = time();
        $user->timecreated = time();
        $user->mnethostid = $CFG->mnet_localhost_id;
        $user->secret = random_string(15);
        $user->auth = $CFG->registerauth;
        // Initialize alternate name fields to empty strings.
        $namefields = array_diff(get_all_user_name_fields(), useredit_get_required_name_fields());
        foreach ($namefields as $namefield) {
            $user->{$namefield} = '';
        }
        $authplugin->user_signup($user, true);
        // prints notice and link to login/index.php
        exit;
        //never reached
    }
}
// make sure we really are on the https page when https login required
$PAGE->verify_https_required();
$newaccount = get_string('newaccount');
$login = get_string('login');
$PAGE->navbar->add($login);
$PAGE->navbar->add($newaccount);
Beispiel #9
0
 /**
  * Extend the form definition after data has been parsed.
  */
 public function definition_after_data()
 {
     global $USER, $CFG, $DB, $OUTPUT;
     $mform = $this->_form;
     // Trim required name fields.
     foreach (useredit_get_required_name_fields() as $field) {
         $mform->applyFilter($field, 'trim');
     }
     if ($userid = $mform->getElementValue('id')) {
         $user = $DB->get_record('user', array('id' => $userid));
     } else {
         $user = false;
     }
     // User can not change own auth method.
     if ($userid == $USER->id) {
         $mform->hardFreeze('auth');
         $mform->hardFreeze('preference_auth_forcepasswordchange');
     }
     // Admin must choose some password and supply correct email.
     if (!empty($USER->newadminuser)) {
         $mform->addRule('newpassword', get_string('required'), 'required', null, 'client');
         if ($mform->elementExists('suspended')) {
             $mform->removeElement('suspended');
         }
     }
     // Require password for new users.
     if ($userid > 0) {
         if ($mform->elementExists('createpassword')) {
             $mform->removeElement('createpassword');
         }
     }
     if ($user and is_mnet_remote_user($user)) {
         // Only local accounts can be suspended.
         if ($mform->elementExists('suspended')) {
             $mform->removeElement('suspended');
         }
     }
     if ($user and ($user->id == $USER->id or is_siteadmin($user))) {
         // Prevent self and admin mess ups.
         if ($mform->elementExists('suspended')) {
             $mform->hardFreeze('suspended');
         }
     }
     // Print picture.
     if (empty($USER->newadminuser)) {
         if ($user) {
             $context = context_user::instance($user->id, MUST_EXIST);
             $fs = get_file_storage();
             $hasuploadedpicture = $fs->file_exists($context->id, 'user', 'icon', 0, '/', 'f2.png') || $fs->file_exists($context->id, 'user', 'icon', 0, '/', 'f2.jpg');
             if (!empty($user->picture) && $hasuploadedpicture) {
                 $imagevalue = $OUTPUT->user_picture($user, array('courseid' => SITEID, 'size' => 64));
             } else {
                 $imagevalue = get_string('none');
             }
         } else {
             $imagevalue = get_string('none');
         }
         $imageelement = $mform->getElement('currentpicture');
         $imageelement->setValue($imagevalue);
         if ($user && $mform->elementExists('deletepicture') && !$hasuploadedpicture) {
             $mform->removeElement('deletepicture');
         }
     }
     // Next the customisable profile fields.
     profile_definition_after_data($mform, $userid);
 }
 public function definition()
 {
     global $CFG, $DB;
     $mform =& $this->_form;
     // Then show the fields about where this block appears.
     $mform->addElement('header', 'header', get_string('companyuser', 'block_iomad_company_admin'));
     $mform->addElement('hidden', 'companyid', $this->selectedcompany);
     $mform->setType('companyid', PARAM_INT);
     // Code added by sumit
     $mform->addElement('hidden', 'returnurl', $this->returnurl);
     $mform->setType('returnurl', PARAM_LOCALURL);
     // end of code
     /* copied from /user/editlib.php */
     $strrequired = get_string('required');
     $mform->addElement('hidden', 'id', $this->userid);
     $mform->setType('id', PARAM_INT);
     // Deal with the name order sorting and required fields.
     $necessarynames = useredit_get_required_name_fields();
     foreach ($necessarynames as $necessaryname) {
         $mform->addElement('text', $necessaryname, get_string($necessaryname), 'maxlength="100" size="30"');
         $mform->addRule($necessaryname, $strrequired, 'required', null, 'client');
         $mform->setType($necessaryname, PARAM_NOTAGS);
     }
     // Do not show email field if change confirmation is pending.
     if (!empty($CFG->emailchangeconfirmation) and !empty($user->preference_newemail)) {
         $notice = get_string('auth_emailchangepending', 'auth_email', $user);
         $notice .= '<br /><a href="edit.php?cancelemailchange=1&amp;id=' . $user->id . '">' . get_string('auth_emailchangecancel', 'auth_email') . '</a>';
         $mform->addElement('static', 'emailpending', get_string('email'), $notice);
     } else {
         $mform->addElement('text', 'email', get_string('email'), 'maxlength="100" size="30"');
         $mform->addRule('email', $strrequired, 'required', null, 'client');
         $mform->setType('email', PARAM_EMAIL);
     }
     /* GWL : Add Field for Username while edit the user */
     $mform->addElement('text', 'username', get_string('phone'), 'size="20"');
     // GWL : Change get_string('username') to 'phone'
     $mform->addRule('username', $strrequired, 'required', null, 'client');
     $mform->setType('username', PARAM_RAW);
     /* GWL : Add Field for Username while edit the user  */
     /* /copied from /user/editlib.php */
     $mform->addElement('static', 'blankline', '', '');
     if (!empty($CFG->passwordpolicy)) {
         $mform->addElement('static', 'passwordpolicyinfo', '', print_password_policy());
     }
     $mform->addElement('passwordunmask', 'newpassword', get_string('newpassword'), 'size="20"');
     $mform->addHelpButton('newpassword', 'newpassword');
     $mform->setType('newpassword', PARAM_RAW);
     $mform->addElement('static', 'generatepassword', '', get_string('leavepasswordemptytogenerate', 'block_iomad_company_admin'));
     $mform->addElement('advcheckbox', 'preference_auth_forcepasswordchange', get_string('forcepasswordchange'));
     $mform->addHelpButton('preference_auth_forcepasswordchange', 'forcepasswordchange');
     // $mform->setDefault('preference_auth_forcepasswordchange', 1);
     $mform->addElement('selectyesno', 'sendnewpasswordemails', get_string('sendnewpasswordemails', 'block_iomad_company_admin'));
     $mform->setDefault('sendnewpasswordemails', 1);
     $mform->disabledIf('sendnewpasswordemails', 'newpassword', 'eq', '');
     // Deal with company optional fields.
     $mform->addElement('header', 'category_id', format_string(get_string('companyprofilefields', 'block_iomad_company_admin')));
     // Department drop down.
     // $mform->addElement('select', 'userdepartment', get_string('department', 'block_iomad_company_admin'), $this->subhierarchieslist, $this->userdepartment);
     // Add in company/department manager checkboxes.
     $departmentlist = company_department::get_department_list($this->selectedcompany);
     $titlelist = company_title::get_title_list($this->selectedcompany);
     if ($departmentlist) {
         $mform->addElement('select', 'userdepartment', get_string('department', 'block_iomad_company_admin'), $departmentlist);
     }
     if ($titlelist) {
         $mform->addElement('select', 'usertitle', get_string('title', 'local_manage_company_dept_title'), $titlelist);
     }
     $managerarray = array();
     if (iomad::has_capability('block/iomad_company_admin:assign_department_manager', context_system::instance())) {
         $managerarray['0'] = get_string('user', 'block_iomad_company_admin');
         $managerarray['2'] = get_string('regionlocationmanager', 'block_iomad_company_admin');
     }
     if (iomad::has_capability('block/iomad_company_admin:assign_company_manager', context_system::instance())) {
         if (empty($managearray)) {
             $managerarray['0'] = get_string('user', 'block_iomad_company_admin');
         }
         $managerarray['1'] = get_string('companymanager', 'block_iomad_company_admin');
         $managerarray['3'] = get_string('companyinstructor', 'block_iomad_company_admin');
         //GWL : Add Instructor
     }
     if (!empty($managerarray)) {
         $mform->addElement('select', 'managertype', get_string('managertype', 'block_iomad_company_admin'), $managerarray, 0);
         $mform->addHelpButton('managertype', 'managertype', 'block_iomad_company_admin');
     } else {
         $mform->addElement('hidden', 'managertype', 0);
     }
     // get region list
     $regionslistobj = company::get_all_regions($this->selectedcompany);
     $regionlist = array('' => get_string('regionnotselect', 'block_iomad_company_admin'));
     foreach ($regionslistobj as $region) {
         $regionlist[$region->id] = $region->name;
     }
     // Code added by sumit display region and location drop downs list
     $locationlist = array('' => get_string('choose'));
     if (!empty($this->regionid)) {
         $locationlistarr = company::get_all_locations($this->regionid);
         foreach ($locationlistarr as $location) {
             $locationlist[$location->id] = $location->name;
         }
     }
     $mform->addElement('select', 'userregion', get_string('region', 'block_iomad_company_admin'), $regionlist, array('class' => 'companyregion'));
     $mform->addElement('select', 'userlocation', get_string('location', 'block_iomad_company_admin'), $locationlist, array('id' => 'id_locationid'));
     $mform->disabledIf('userregion', 'managertype', 'eq', 1);
     $mform->disabledIf('userlocation', 'managertype', 'eq', 1);
     $mform->disabledIf('userregion', 'managertype', 'eq', 3);
     //GWL : Add Instructor
     $mform->disabledIf('userlocation', 'managertype', 'eq', 3);
     //GWL : Add Instructor
     // End of Code
     // Get global fields.
     // Get company category.
     if ($companyinfo = $DB->get_record('company', array('id' => $this->selectedcompany))) {
         // Get fields from company category.
         if ($fields = $DB->get_records('user_info_field', array('categoryid' => $companyinfo->profileid))) {
             // Display the header and the fields.
             foreach ($fields as $field) {
                 require_once $CFG->dirroot . '/user/profile/field/' . $field->datatype . '/field.class.php';
                 $newfield = 'profile_field_' . $field->datatype;
                 $formfield = new $newfield($field->id);
                 $formfield->edit_field($mform);
                 $mform->setDefault($formfield->inputname, $formfield->field->defaultdata);
             }
         }
     }
     /*
      $mform->addElement('header', 'courses', get_string('courses', 'block_iomad_company_admin'));
      $mform->addElement('html', "<div class='fitem'><div class='fitemtitle'>" .
      get_string('selectenrolmentcourse', 'block_iomad_company_admin') .
      "</div><div class='felement'>");
      $mform->addElement('html', $this->currentcourses->display(true));
      $mform->addElement('html', "</div></div>");
     */
     // add action buttons
     $buttonarray = array();
     //$buttonarray[] = &$mform->createElement('submit', 'submitbutton', get_string('createuseragain', 'block_iomad_company_admin'));
     $buttonarray[] =& $mform->createElement('submit', 'submitandback', get_string('createuserandback', 'block_iomad_company_admin'));
     $buttonarray[] =& $mform->createElement('cancel');
     $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
     $mform->closeHeaderBefore('buttonar');
 }
Beispiel #11
0
 /**
  * Extend the form definition after the data has been parsed.
  */
 public function definition_after_data()
 {
     global $CFG, $DB, $OUTPUT;
     $mform = $this->_form;
     $userid = $mform->getElementValue('id');
     // Trim required name fields.
     foreach (useredit_get_required_name_fields() as $field) {
         $mform->applyFilter($field, 'trim');
     }
     if ($user = $DB->get_record('user', array('id' => $userid))) {
         // Remove description.
         if (empty($user->description) && !empty($CFG->profilesforenrolledusersonly) && !$DB->record_exists('role_assignments', array('userid' => $userid))) {
             $mform->removeElement('description_editor');
         }
         // Print picture.
         $context = context_user::instance($user->id, MUST_EXIST);
         $fs = get_file_storage();
         $hasuploadedpicture = $fs->file_exists($context->id, 'user', 'icon', 0, '/', 'f2.png') || $fs->file_exists($context->id, 'user', 'icon', 0, '/', 'f2.jpg');
         if (!empty($user->picture) && $hasuploadedpicture) {
             $imagevalue = $OUTPUT->user_picture($user, array('courseid' => SITEID, 'size' => 64));
         } else {
             $imagevalue = get_string('none');
         }
         $imageelement = $mform->getElement('currentpicture');
         $imageelement->setValue($imagevalue);
         if ($mform->elementExists('deletepicture') && !$hasuploadedpicture) {
             $mform->removeElement('deletepicture');
         }
         // Disable fields that are locked by auth plugins.
         $fields = get_user_fieldnames();
         $authplugin = get_auth_plugin($user->auth);
         $customfields = $authplugin->get_custom_user_profile_fields();
         $customfieldsdata = profile_user_record($userid, false);
         $fields = array_merge($fields, $customfields);
         foreach ($fields as $field) {
             if ($field === 'description') {
                 // Hard coded hack for description field. See MDL-37704 for details.
                 $formfield = 'description_editor';
             } else {
                 $formfield = $field;
             }
             if (!$mform->elementExists($formfield)) {
                 continue;
             }
             // Get the original value for the field.
             if (in_array($field, $customfields)) {
                 $key = str_replace('profile_field_', '', $field);
                 $value = isset($customfieldsdata->{$key}) ? $customfieldsdata->{$key} : '';
             } else {
                 $value = $user->{$field};
             }
             $configvariable = 'field_lock_' . $field;
             if (isset($authplugin->config->{$configvariable})) {
                 if ($authplugin->config->{$configvariable} === 'locked') {
                     $mform->hardFreeze($formfield);
                     $mform->setConstant($formfield, $value);
                 } else {
                     if ($authplugin->config->{$configvariable} === 'unlockedifempty' and $value != '') {
                         $mform->hardFreeze($formfield);
                         $mform->setConstant($formfield, $value);
                     }
                 }
             }
         }
         // Next the customisable profile fields.
         profile_definition_after_data($mform, $user->id);
     } else {
         profile_definition_after_data($mform, 0);
     }
 }
Beispiel #12
0
/**
 * Add the missing fields to a user that is going to be created
 *
 * @param  stdClass $user the new user object
 * @return stdClass the user filled
 * @since Moodle 3.2
 */
function signup_setup_new_user($user)
{
    global $CFG;
    $user->confirmed = 0;
    $user->lang = current_language();
    $user->firstaccess = 0;
    $user->timecreated = time();
    $user->mnethostid = $CFG->mnet_localhost_id;
    $user->secret = random_string(15);
    $user->auth = $CFG->registerauth;
    // Initialize alternate name fields to empty strings.
    $namefields = array_diff(get_all_user_name_fields(), useredit_get_required_name_fields());
    foreach ($namefields as $namefield) {
        $user->{$namefield} = '';
    }
    return $user;
}
Beispiel #13
0
 function signup_user($user)
 {
     global $CFG;
     $authplugin = get_auth_plugin($CFG->registerauth);
     $namefields = array_diff(get_all_user_name_fields(), useredit_get_required_name_fields());
     foreach ($namefields as $namefield) {
         $user->{$namefield} = '';
     }
     try {
         $authplugin->user_signup($user, false);
         $this->update_users_data($user);
         echo "User {$user->username} has been imported";
         echo "<br>-------------------------------------------------------<br>";
     } catch (Exception $e) {
         echo 'Error occured: ', $e->getMessage(), "\n";
     }
 }