Exemple #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_RAW);
     $mform->addRule('username', get_string('missingusername'), 'required', null, 'client');
     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', core_user::get_property_type('password'));
     $mform->addRule('password', get_string('missingpassword'), 'required', null, 'client');
     $mform->addElement('header', 'supplyinfo', get_string('supplyinfo'), '');
     $mform->addElement('text', 'email', get_string('email'), 'maxlength="100" size="25"');
     $mform->setType('email', core_user::get_property_type('email'));
     $mform->addRule('email', get_string('missingemail'), 'required', null, 'client');
     $mform->setForceLtr('email');
     $mform->addElement('text', 'email2', get_string('emailagain'), 'maxlength="100" size="25"');
     $mform->setType('email2', core_user::get_property_type('email'));
     $mform->addRule('email2', get_string('missingemail'), 'required', null, 'client');
     $mform->setForceLtr('email2');
     $namefields = useredit_get_required_name_fields();
     foreach ($namefields as $field) {
         $mform->addElement('text', $field, get_string($field), 'maxlength="100" size="30"');
         $mform->setType($field, core_user::get_property_type('firstname'));
         $stringid = 'missing' . $field;
         if (!get_string_manager()->string_exists($stringid, 'moodle')) {
             $stringid = 'required';
         }
         $mform->addRule($field, get_string($stringid), 'required', null, 'client');
     }
     $mform->addElement('text', 'city', get_string('city'), 'maxlength="120" size="20"');
     $mform->setType('city', core_user::get_property_type('city'));
     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', '');
     }
     profile_signup_fields($mform);
     if (signup_captcha_enabled()) {
         $mform->addElement('recaptcha', 'recaptcha_element', get_string('security_question', 'auth'), array('https' => $CFG->loginhttps));
         $mform->addHelpButton('recaptcha_element', 'recaptcha', 'auth');
         $mform->closeHeaderBefore('recaptcha_element');
     }
     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, 'client');
     }
     // buttons
     $this->add_action_buttons(true, get_string('createaccount'));
 }
Exemple #2
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'));
}
Exemple #3
0
 /**
  * Define the form.
  */
 public function definition()
 {
     global $USER, $CFG, $COURSE;
     $mform = $this->_form;
     $editoroptions = null;
     $filemanageroptions = null;
     if (!is_array($this->_customdata)) {
         throw new coding_exception('invalid custom data for user_edit_form');
     }
     $editoroptions = $this->_customdata['editoroptions'];
     $filemanageroptions = $this->_customdata['filemanageroptions'];
     $user = $this->_customdata['user'];
     $userid = $user->id;
     // Accessibility: "Required" is bad legend text.
     $strgeneral = get_string('general');
     $strrequired = get_string('required');
     // Add some extra hidden fields.
     $mform->addElement('hidden', 'id');
     $mform->setType('id', core_user::get_property_type('id'));
     $mform->addElement('hidden', 'course', $COURSE->id);
     $mform->setType('course', PARAM_INT);
     // Print the required moodle fields first.
     $mform->addElement('header', 'moodle', $strgeneral);
     $auths = core_component::get_plugin_list('auth');
     $enabled = get_string('pluginenabled', 'core_plugin');
     $disabled = get_string('plugindisabled', 'core_plugin');
     $authoptions = array($enabled => array(), $disabled => array());
     $cannotchangepass = array();
     $cannotchangeusername = array();
     foreach ($auths as $auth => $unused) {
         $authinst = get_auth_plugin($auth);
         if (!$authinst->is_internal()) {
             $cannotchangeusername[] = $auth;
         }
         $passwordurl = $authinst->change_password_url();
         if (!($authinst->can_change_password() && empty($passwordurl))) {
             if ($userid < 1 and $authinst->is_internal()) {
                 // This is unlikely but we can not create account without password
                 // when plugin uses passwords, we need to set it initially at least.
             } else {
                 $cannotchangepass[] = $auth;
             }
         }
         if (is_enabled_auth($auth)) {
             $authoptions[$enabled][$auth] = get_string('pluginname', "auth_{$auth}");
         } else {
             $authoptions[$disabled][$auth] = get_string('pluginname', "auth_{$auth}");
         }
     }
     $mform->addElement('text', 'username', get_string('username'), 'size="20"');
     $mform->addHelpButton('username', 'username', 'auth');
     $mform->setType('username', core_user::get_property_type('username'));
     if ($userid !== -1) {
         $mform->disabledIf('username', 'auth', 'in', $cannotchangeusername);
     }
     $mform->addElement('selectgroups', 'auth', get_string('chooseauthmethod', 'auth'), $authoptions);
     $mform->addHelpButton('auth', 'chooseauthmethod', 'auth');
     $mform->addElement('advcheckbox', 'suspended', get_string('suspended', 'auth'));
     $mform->addHelpButton('suspended', 'suspended', 'auth');
     $mform->addElement('checkbox', 'createpassword', get_string('createpassword', 'auth'));
     $mform->disabledIf('createpassword', 'auth', 'in', $cannotchangepass);
     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', core_user::get_property_type('password'));
     $mform->disabledIf('newpassword', 'createpassword', 'checked');
     $mform->disabledIf('newpassword', 'auth', 'in', $cannotchangepass);
     $mform->addElement('advcheckbox', 'preference_auth_forcepasswordchange', get_string('forcepasswordchange'));
     $mform->addHelpButton('preference_auth_forcepasswordchange', 'forcepasswordchange');
     $mform->disabledIf('preference_auth_forcepasswordchange', 'createpassword', 'checked');
     // Shared fields.
     useredit_shared_definition($mform, $editoroptions, $filemanageroptions, $user);
     // Next the customisable profile fields.
     profile_definition($mform, $userid);
     if ($userid == -1) {
         $btnstring = get_string('createuser');
     } else {
         $btnstring = get_string('updatemyprofile');
     }
     $this->add_action_buttons(false, $btnstring);
     $this->set_data($user);
 }
Exemple #4
0
 /**
  * Test get_property_type() method.
  */
 public function test_get_property_type()
 {
     // Fetch valid properties and verify if the type is correct.
     $type = core_user::get_property_type('username');
     $this->assertEquals(PARAM_USERNAME, $type);
     $type = core_user::get_property_type('email');
     $this->assertEquals(PARAM_RAW_TRIMMED, $type);
     $type = core_user::get_property_type('timezone');
     $this->assertEquals(PARAM_TIMEZONE, $type);
     // Try to fetch type of a non-existent properties.
     $nonexistingproperty = 'userfullname';
     $this->expectException('coding_exception');
     $this->expectExceptionMessage('Invalid property requested: ' . $nonexistingproperty);
     core_user::get_property_type($nonexistingproperty);
     $nonexistingproperty = 'mobilenumber';
     $this->expectExceptionMessage('Invalid property requested: ' . $nonexistingproperty);
     core_user::get_property_type($nonexistingproperty);
 }
Exemple #5
0
 /**
  * Create user return value description.
  *
  * @param array $additionalfields some additional field
  * @return single_structure_description
  */
 public static function user_description($additionalfields = array())
 {
     $userfields = array('id' => new external_value(core_user::get_property_type('id'), 'ID of the user'), 'username' => new external_value(core_user::get_property_type('username'), 'The username', VALUE_OPTIONAL), 'firstname' => new external_value(core_user::get_property_type('firstname'), 'The first name(s) of the user', VALUE_OPTIONAL), 'lastname' => new external_value(core_user::get_property_type('lastname'), 'The family name of the user', VALUE_OPTIONAL), 'fullname' => new external_value(core_user::get_property_type('firstname'), 'The fullname of the user'), 'email' => new external_value(core_user::get_property_type('email'), 'An email address - allow email as root@localhost', VALUE_OPTIONAL), 'address' => new external_value(core_user::get_property_type('address'), 'Postal address', VALUE_OPTIONAL), 'phone1' => new external_value(core_user::get_property_type('phone1'), 'Phone 1', VALUE_OPTIONAL), 'phone2' => new external_value(core_user::get_property_type('phone2'), 'Phone 2', VALUE_OPTIONAL), 'icq' => new external_value(core_user::get_property_type('icq'), 'icq number', VALUE_OPTIONAL), 'skype' => new external_value(core_user::get_property_type('skype'), 'skype id', VALUE_OPTIONAL), 'yahoo' => new external_value(core_user::get_property_type('yahoo'), 'yahoo id', VALUE_OPTIONAL), 'aim' => new external_value(core_user::get_property_type('aim'), 'aim id', VALUE_OPTIONAL), 'msn' => new external_value(core_user::get_property_type('msn'), 'msn number', VALUE_OPTIONAL), 'department' => new external_value(core_user::get_property_type('department'), 'department', VALUE_OPTIONAL), 'institution' => new external_value(core_user::get_property_type('institution'), 'institution', VALUE_OPTIONAL), 'idnumber' => new external_value(core_user::get_property_type('idnumber'), 'An arbitrary ID code number perhaps from the institution', VALUE_OPTIONAL), 'interests' => new external_value(PARAM_TEXT, 'user interests (separated by commas)', VALUE_OPTIONAL), 'firstaccess' => new external_value(core_user::get_property_type('firstaccess'), 'first access to the site (0 if never)', VALUE_OPTIONAL), 'lastaccess' => new external_value(core_user::get_property_type('lastaccess'), 'last access to the site (0 if never)', VALUE_OPTIONAL), 'auth' => new external_value(core_user::get_property_type('auth'), 'Auth plugins include manual, ldap, imap, etc', VALUE_OPTIONAL), 'confirmed' => new external_value(core_user::get_property_type('confirmed'), 'Active user: 1 if confirmed, 0 otherwise', VALUE_OPTIONAL), 'lang' => new external_value(core_user::get_property_type('lang'), 'Language code such as "en", must exist on server', VALUE_OPTIONAL), 'calendartype' => new external_value(core_user::get_property_type('calendartype'), 'Calendar type such as "gregorian", must exist on server', VALUE_OPTIONAL), 'theme' => new external_value(core_user::get_property_type('theme'), 'Theme name such as "standard", must exist on server', VALUE_OPTIONAL), 'timezone' => new external_value(core_user::get_property_type('timezone'), 'Timezone code such as Australia/Perth, or 99 for default', VALUE_OPTIONAL), 'mailformat' => new external_value(core_user::get_property_type('mailformat'), 'Mail format code is 0 for plain text, 1 for HTML etc', VALUE_OPTIONAL), 'description' => new external_value(core_user::get_property_type('description'), 'User profile description', VALUE_OPTIONAL), 'descriptionformat' => new external_format_value(core_user::get_property_type('descriptionformat'), VALUE_OPTIONAL), 'city' => new external_value(core_user::get_property_type('city'), 'Home city of the user', VALUE_OPTIONAL), 'url' => new external_value(core_user::get_property_type('url'), 'URL of the user', VALUE_OPTIONAL), 'country' => new external_value(core_user::get_property_type('country'), 'Home country code of the user, such as AU or CZ', VALUE_OPTIONAL), 'profileimageurlsmall' => new external_value(PARAM_URL, 'User image profile URL - small version'), 'profileimageurl' => new external_value(PARAM_URL, 'User image profile URL - big version'), 'customfields' => new external_multiple_structure(new external_single_structure(array('type' => new external_value(PARAM_ALPHANUMEXT, 'The type of the custom field - text field, checkbox...'), 'value' => new external_value(PARAM_RAW, 'The value of the custom field'), 'name' => new external_value(PARAM_RAW, 'The name of the custom field'), 'shortname' => new external_value(PARAM_RAW, 'The shortname of the custom field - to be able to build the field class in the code'))), 'User custom fields (also known as user profile fields)', VALUE_OPTIONAL), 'preferences' => new external_multiple_structure(new external_single_structure(array('name' => new external_value(PARAM_ALPHANUMEXT, 'The name of the preferences'), 'value' => new external_value(PARAM_RAW, 'The value of the custom field'))), 'Users preferences', VALUE_OPTIONAL));
     if (!empty($additionalfields)) {
         $userfields = array_merge($userfields, $additionalfields);
     }
     return new external_single_structure($userfields);
 }
 /**
  * Test for the type of the user-related properties in mod_assign_external::list_participants_returns().
  */
 public function test_list_participants_returns_user_property_types()
 {
     // Get user properties.
     $userdesc = core_user_external::user_description();
     $this->assertTrue(isset($userdesc->keys));
     $userproperties = array_keys($userdesc->keys);
     // Get returns description for mod_assign_external::list_participants_returns().
     $listreturns = mod_assign_external::list_participants_returns();
     $this->assertTrue(isset($listreturns->content));
     $listreturnsdesc = $listreturns->content->keys;
     // Iterate over list returns description's keys.
     foreach ($listreturnsdesc as $key => $desc) {
         // Check if key exists in user properties and the description has a type attribute.
         if (in_array($key, $userproperties) && isset($desc->type)) {
             try {
                 // The core_user::get_property_type() method might throw a coding_exception since
                 // core_user_external::user_description() might contain properties that are not yet included in
                 // core_user's $propertiescache.
                 $propertytype = core_user::get_property_type($key);
                 // Assert that user-related property types match those of the defined in core_user.
                 $this->assertEquals($propertytype, $desc->type);
             } catch (coding_exception $e) {
                 // All good.
             }
         }
     }
 }
Exemple #7
0
 /**
  * Clean a specific user field.
  *
  * @param string $data the user field data to be cleaned.
  * @param string $field the user field name on the property definition cache.
  * @return string the cleaned user data.
  */
 public static function clean_field($data, $field)
 {
     if (empty($data) || empty($field)) {
         return $data;
     }
     try {
         $type = core_user::get_property_type($field);
         if (isset(self::$propertiescache[$field]['choices'])) {
             if (!array_key_exists($data, self::$propertiescache[$field]['choices'])) {
                 if (isset(self::$propertiescache[$field]['default'])) {
                     $data = self::$propertiescache[$field]['default'];
                 } else {
                     $data = '';
                 }
             } else {
                 return $data;
             }
         } else {
             $data = clean_param($data, $type);
         }
     } catch (coding_exception $e) {
         debugging("The property '{$field}' could not be cleaned.", DEBUG_DEVELOPER);
     }
     return $data;
 }
Exemple #8
0
 /**
  * Describes the parameters for confirm_user.
  *
  * @return external_external_function_parameters
  * @since Moodle 3.2
  */
 public static function confirm_user_parameters()
 {
     return new external_function_parameters(array('username' => new external_value(core_user::get_property_type('username'), 'User name'), 'secret' => new external_value(core_user::get_property_type('secret'), 'Confirmation secret')));
 }
 /**
  * Describes the parameters for signup_user.
  *
  * @return external_external_function_parameters
  * @since Moodle 3.2
  */
 public static function signup_user_parameters()
 {
     return new external_function_parameters(array('username' => new external_value(core_user::get_property_type('username'), 'Username'), 'password' => new external_value(core_user::get_property_type('password'), 'Plain text password'), 'firstname' => new external_value(core_user::get_property_type('firstname'), 'The first name(s) of the user'), 'lastname' => new external_value(core_user::get_property_type('lastname'), 'The family name of the user'), 'email' => new external_value(core_user::get_property_type('email'), 'A valid and unique email address'), 'city' => new external_value(core_user::get_property_type('city'), 'Home city of the user', VALUE_DEFAULT, ''), 'country' => new external_value(core_user::get_property_type('country'), 'Home country code', VALUE_DEFAULT, ''), 'recaptchachallengehash' => new external_value(PARAM_RAW, 'Recaptcha challenge hash', VALUE_DEFAULT, ''), 'recaptcharesponse' => new external_value(PARAM_NOTAGS, 'Recaptcha response', VALUE_DEFAULT, ''), 'customprofilefields' => new external_multiple_structure(new external_single_structure(array('type' => new external_value(PARAM_ALPHANUMEXT, 'The type of the custom field'), 'name' => new external_value(PARAM_ALPHANUMEXT, 'The name of the custom field'), 'value' => new external_value(PARAM_RAW, 'Custom field value, can be an encoded json if required'))), 'User custom fields (also known as user profile fields)', VALUE_DEFAULT, array()), 'redirect' => new external_value(PARAM_LOCALURL, 'Redirect the user to this site url after confirmation.', VALUE_DEFAULT, '')));
 }
Exemple #10
0
 /**
  * Add elements to the edit instance form.
  *
  * @param stdClass $instance
  * @param MoodleQuickForm $mform
  * @param context $context
  * @return bool
  */
 public function edit_instance_form($instance, MoodleQuickForm $mform, $context)
 {
     global $DB;
     $nameattribs = array('size' => '20', 'maxlength' => '255');
     $mform->addElement('text', 'name', get_string('custominstancename', 'enrol'), $nameattribs);
     $mform->setType('name', PARAM_TEXT);
     $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'server');
     $tools = array();
     $tools[$context->id] = get_string('course');
     $modinfo = get_fast_modinfo($instance->courseid);
     $mods = $modinfo->get_cms();
     foreach ($mods as $mod) {
         $tools[$mod->context->id] = format_string($mod->name);
     }
     $mform->addElement('select', 'contextid', get_string('tooltobeprovided', 'enrol_lti'), $tools);
     $mform->setDefault('contextid', $context->id);
     $mform->addElement('duration', 'enrolperiod', get_string('enrolperiod', 'enrol_lti'), array('optional' => true, 'defaultunit' => DAYSECS));
     $mform->setDefault('enrolperiod', 0);
     $mform->addHelpButton('enrolperiod', 'enrolperiod', 'enrol_lti');
     $mform->addElement('date_time_selector', 'enrolstartdate', get_string('enrolstartdate', 'enrol_lti'), array('optional' => true));
     $mform->setDefault('enrolstartdate', 0);
     $mform->addHelpButton('enrolstartdate', 'enrolstartdate', 'enrol_lti');
     $mform->addElement('date_time_selector', 'enrolenddate', get_string('enrolenddate', 'enrol_lti'), array('optional' => true));
     $mform->setDefault('enrolenddate', 0);
     $mform->addHelpButton('enrolenddate', 'enrolenddate', 'enrol_lti');
     $mform->addElement('text', 'maxenrolled', get_string('maxenrolled', 'enrol_lti'));
     $mform->setDefault('maxenrolled', 0);
     $mform->addHelpButton('maxenrolled', 'maxenrolled', 'enrol_lti');
     $mform->setType('maxenrolled', PARAM_INT);
     $assignableroles = get_assignable_roles($context);
     $mform->addElement('select', 'roleinstructor', get_string('roleinstructor', 'enrol_lti'), $assignableroles);
     $mform->setDefault('roleinstructor', '3');
     $mform->addHelpButton('roleinstructor', 'roleinstructor', 'enrol_lti');
     $mform->addElement('select', 'rolelearner', get_string('rolelearner', 'enrol_lti'), $assignableroles);
     $mform->setDefault('rolelearner', '5');
     $mform->addHelpButton('rolelearner', 'rolelearner', 'enrol_lti');
     $mform->addElement('header', 'remotesystem', get_string('remotesystem', 'enrol_lti'));
     $mform->addElement('text', 'secret', get_string('secret', 'enrol_lti'), 'maxlength="64" size="25"');
     $mform->setType('secret', PARAM_ALPHANUM);
     $mform->setDefault('secret', random_string(32));
     $mform->addHelpButton('secret', 'secret', 'enrol_lti');
     $mform->addRule('secret', get_string('required'), 'required');
     $mform->addElement('selectyesno', 'gradesync', get_string('gradesync', 'enrol_lti'));
     $mform->setDefault('gradesync', 1);
     $mform->addHelpButton('gradesync', 'gradesync', 'enrol_lti');
     $mform->addElement('selectyesno', 'gradesynccompletion', get_string('requirecompletion', 'enrol_lti'));
     $mform->setDefault('gradesynccompletion', 0);
     $mform->disabledIf('gradesynccompletion', 'gradesync', 0);
     $mform->addElement('selectyesno', 'membersync', get_string('membersync', 'enrol_lti'));
     $mform->setDefault('membersync', 1);
     $mform->addHelpButton('membersync', 'membersync', 'enrol_lti');
     $options = array();
     $options[\enrol_lti\helper::MEMBER_SYNC_ENROL_AND_UNENROL] = get_string('membersyncmodeenrolandunenrol', 'enrol_lti');
     $options[\enrol_lti\helper::MEMBER_SYNC_ENROL_NEW] = get_string('membersyncmodeenrolnew', 'enrol_lti');
     $options[\enrol_lti\helper::MEMBER_SYNC_UNENROL_MISSING] = get_string('membersyncmodeunenrolmissing', 'enrol_lti');
     $mform->addElement('select', 'membersyncmode', get_string('membersyncmode', 'enrol_lti'), $options);
     $mform->setDefault('membersyncmode', \enrol_lti\helper::MEMBER_SYNC_ENROL_AND_UNENROL);
     $mform->addHelpButton('membersyncmode', 'membersyncmode', 'enrol_lti');
     $mform->disabledIf('membersyncmode', 'membersync', 0);
     $mform->addElement('header', 'defaultheader', get_string('userdefaultvalues', 'enrol_lti'));
     $emaildisplay = get_config('enrol_lti', 'emaildisplay');
     $choices = array(0 => get_string('emaildisplayno'), 1 => get_string('emaildisplayyes'), 2 => get_string('emaildisplaycourse'));
     $mform->addElement('select', 'maildisplay', get_string('emaildisplay'), $choices);
     $mform->setDefault('maildisplay', $emaildisplay);
     $city = get_config('enrol_lti', 'city');
     $mform->addElement('text', 'city', get_string('city'), 'maxlength="100" size="25"');
     $mform->setType('city', PARAM_TEXT);
     $mform->setDefault('city', $city);
     $country = get_config('enrol_lti', 'country');
     $countries = array('' => get_string('selectacountry') . '...') + get_string_manager()->get_list_of_countries();
     $mform->addElement('select', 'country', get_string('selectacountry'), $countries);
     $mform->setDefault('country', $country);
     $mform->setAdvanced('country');
     $timezone = get_config('enrol_lti', 'timezone');
     $choices = core_date::get_list_of_timezones(null, true);
     $mform->addElement('select', 'timezone', get_string('timezone'), $choices);
     $mform->setDefault('timezone', $timezone);
     $mform->setAdvanced('timezone');
     $lang = get_config('enrol_lti', 'lang');
     $mform->addElement('select', 'lang', get_string('preferredlanguage'), get_string_manager()->get_list_of_translations());
     $mform->setDefault('lang', $lang);
     $mform->setAdvanced('lang');
     $institution = get_config('enrol_lti', 'institution');
     $mform->addElement('text', 'institution', get_string('institution'), 'maxlength="40" size="25"');
     $mform->setType('institution', core_user::get_property_type('institution'));
     $mform->setDefault('institution', $institution);
     $mform->setAdvanced('institution');
     // Check if we are editing an instance.
     if (!empty($instance->id)) {
         // Get the details from the enrol_lti_tools table.
         $ltitool = $DB->get_record('enrol_lti_tools', array('enrolid' => $instance->id), '*', MUST_EXIST);
         $mform->addElement('hidden', 'toolid');
         $mform->setType('toolid', PARAM_INT);
         $mform->setConstant('toolid', $ltitool->id);
         $mform->setDefaults((array) $ltitool);
     }
 }
Exemple #11
0
 /**
  * The get profile return structure.
  *
  * @return external_single_structure
  * @since 3.2
  */
 public static function data_for_messagearea_get_profile_returns()
 {
     return new external_single_structure(array('userid' => new external_value(PARAM_INT, 'The id of the user whose profile we are viewing'), 'email' => new external_value(core_user::get_property_type('email'), 'An email address'), 'country' => new external_value(PARAM_TEXT, 'Home country of the user'), 'city' => new external_value(core_user::get_property_type('city'), 'Home city of the user'), 'fullname' => new external_value(PARAM_NOTAGS, 'The user\'s name'), 'profileimageurl' => new external_value(PARAM_URL, 'User picture URL'), 'profileimageurlsmall' => new external_value(PARAM_URL, 'Small user picture URL'), 'isonline' => new external_value(PARAM_BOOL, 'The user\'s online status'), 'isblocked' => new external_value(PARAM_BOOL, 'Is the user blocked?'), 'iscontact' => new external_value(PARAM_BOOL, 'Is the user a contact?')));
 }
 /**
  * The form definition.
  */
 public function definition()
 {
     global $CFG;
     $mform = $this->_form;
     $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
     // Note: these values are intentionally PARAM_RAW - we want users to test any rubbish as parameters.
     $data = $this->_customdata;
     if ($data['authmethod'] == 'simple') {
         $mform->addElement('text', 'wsusername', 'wsusername');
         $mform->setType('wsusername', core_user::get_property_type('username'));
         $mform->addElement('text', 'wspassword', 'wspassword');
         $mform->setType('wspassword', core_user::get_property_type('password'));
     } else {
         if ($data['authmethod'] == 'token') {
             $mform->addElement('text', 'token', 'token');
             $mform->setType('token', PARAM_RAW_TRIMMED);
         }
     }
     $mform->addElement('hidden', 'authmethod', $data['authmethod']);
     $mform->setType('authmethod', core_user::get_property_type('auth'));
     $mform->addElement('text', 'id[0]', 'id[0]');
     $mform->addElement('text', 'name[0]', 'name[0]');
     $mform->addElement('text', 'parent[0]', 'parent[0]');
     $mform->addElement('text', 'idnumber[0]', 'idnumber[0]');
     $mform->addElement('text', 'description[0]', 'description[0]');
     $mform->addElement('text', 'id[1]', 'id[1]');
     $mform->addElement('text', 'name[1]', 'name[1]');
     $mform->addElement('text', 'parent[1]', 'parent[1]');
     $mform->addElement('text', 'idnumber[1]', 'idnumber[1]');
     $mform->addElement('text', 'description[1]', 'description[1]');
     $mform->setType('id', core_user::get_property_type('id'));
     $mform->setType('name', core_user::get_property_type('firstname'));
     $mform->setType('parent', PARAM_INT);
     $mform->setType('idnumber', core_user::get_property_type('idnumber'));
     $mform->setType('description', core_user::get_property_type('description'));
     $mform->addElement('hidden', 'function');
     $mform->setType('function', PARAM_PLUGIN);
     $mform->addElement('hidden', 'protocol');
     $mform->setType('protocol', PARAM_ALPHA);
     $this->add_action_buttons(true, get_string('execute', 'webservice'));
 }
 public static function define_properties()
 {
     return array('id' => array('type' => \core_user::get_property_type('id')), 'email' => array('type' => \core_user::get_property_type('email'), 'default' => ''), 'idnumber' => array('type' => \core_user::get_property_type('idnumber'), 'default' => ''), 'phone1' => array('type' => \core_user::get_property_type('phone1'), 'default' => ''), 'phone2' => array('type' => \core_user::get_property_type('phone2'), 'default' => ''), 'department' => array('type' => \core_user::get_property_type('department'), 'default' => ''), 'institution' => array('type' => \core_user::get_property_type('institution'), 'default' => ''));
 }