/** * Render the import entry request for country fields */ public static function render_import_entry_request($entry_content) { $countries = getoptions_country(); return isset($countries[$entry_content['title']]) ? $countries[$entry_content['title']] : ''; }
/** * Checks that all the required fields are set, and handles setting them if required. * * Checks whether the current user needs to change their password, and handles * the password changing if it's required. */ function auth_check_required_fields() { global $USER, $SESSION; if (defined('NOCHECKREQUIREDFIELDS')) { return; } $changepassword = true; $elements = array(); if (!$USER->get('passwordchange') || $USER->get('parentuser') && $USER->get('loginanyway') || defined('NOCHECKPASSWORDCHANGE')) { $changepassword = false; } // Check if the user wants to log in anyway if ($USER->get('passwordchange') && $USER->get('parentuser') && isset($_GET['loginanyway'])) { $USER->loginanyway = true; $changepassword = false; } // Do not force password change on JSON request. if (defined('JSON') && JSON == true) { $changepassword = false; } if ($changepassword) { $authobj = AuthFactory::create($USER->authinstance); if ($authobj->changepasswordurl) { redirect($authobj->changepasswordurl); exit; } if (method_exists($authobj, 'change_password')) { if ($SESSION->get('resetusername')) { $elements['username'] = array('type' => 'text', 'defaultvalue' => $USER->get('username'), 'title' => get_string('changeusername', 'account'), 'description' => get_string('changeusernamedesc', 'account', hsc(get_config('sitename')))); } $elements['password1'] = array('type' => 'password', 'title' => get_string('newpassword') . ':', 'description' => get_string('yournewpassword'), 'rules' => array('required' => true)); $elements['password2'] = array('type' => 'password', 'title' => get_string('confirmpassword') . ':', 'description' => get_string('yournewpasswordagain'), 'rules' => array('required' => true)); $elements['country'] = array('type' => 'select', 'title' => "Country", 'options' => array("ca" => "Canada", "us" => "United States"), 'defaultvalue' => "us", 'description' => "Country", 'rules' => array('required' => true)); $elements['state'] = array('type' => 'select', 'title' => "State", 'options' => array('AL' => "Alabama", 'AK' => "Alaska", 'AZ' => "Arizona", 'AR' => "Arkansas", 'CA' => "California", 'CO' => "Colorado", 'CT' => "Connecticut", 'DE' => "Delaware", 'DC' => "District of Columbia", 'FL' => "Florida", 'GA' => "Georgia", 'HI' => "Hawaii", 'ID' => "Idaho", 'IL' => "Illinois", 'IN' => "Indiana", 'IA' => "Iowa", 'KS' => "Kansas", 'KY' => "Kentucky", 'LA' => "Louisiana", 'ME' => "Maine", 'MD' => "Maryland", 'MA' => "Massachusetts", 'MI' => "Michigan", 'MN' => "Minnesota", 'MS' => "Mississippi", 'MO' => "Missouri", 'MT' => "Montana", 'NE' => "Nebraska", 'NV' => "Nevada", 'NH' => "New Hampshire", 'NJ' => "New Jersey", 'NM' => "New Mexico", 'NY' => "New York", 'NC' => "North Carolina", 'ND' => "North Dakota", 'OH' => "Ohio", 'OK' => "Oklahoma", 'OR' => "Oregon", 'PA' => "Pennsylvania", 'RI' => "Rhode Island", 'SC' => "South Carolina", 'SD' => "South Dakota", 'TN' => "Tennessee", 'TX' => "Texas", 'UT' => "Utah", 'VT' => "Vermont", 'VA' => "Virginia", 'WA' => "Washington", 'WV' => "West Virginia", 'WI' => "Wisconsin", 'WY' => "Wyoming", 'AB' => "Alberta", 'BC' => "British Columbia", 'MB' => "Manitoba", 'NB' => "New Brunswick", 'NL' => "Newfoundland and Labrador", 'NT' => "Northwest Territories", 'NS' => "Nova Scotia", 'NU' => "Nunavut", 'ON' => "Ontario", 'PE' => "Prince Edward Island", 'QC' => "Quebec", 'SK' => "Saskatchewan", 'YT' => "Yukon"), 'description' => "State", 'rules' => array('required' => true)); $elements['email'] = array('type' => 'text', 'title' => get_string('principalemailaddress', 'artefact.internal'), 'ignore' => trim($USER->get('email')) != '' && !preg_match('/@example\\.org$/', $USER->get('email')), 'rules' => array('required' => true, 'email' => true)); } } else { if (defined('JSON')) { // Don't need to check this for json requests return; } } safe_require('artefact', 'internal'); require_once 'pieforms/pieform.php'; $alwaysmandatoryfields = array_keys(ArtefactTypeProfile::get_always_mandatory_fields()); foreach (ArtefactTypeProfile::get_mandatory_fields() as $field => $type) { // Always mandatory fields are stored in the usr table, so are part of // the user session object. We can save a query by grabbing them from // the session. if (in_array($field, $alwaysmandatoryfields) && $USER->get($field) != null) { continue; } // Not cached? Get value the standard way. if (get_profile_field($USER->get('id'), $field) != null) { continue; } if ($field == 'email') { if (isset($elements['email'])) { continue; } // Use a text field for their first e-mail address, not the // emaillist element $type = 'text'; } $elements[$field] = array('type' => $type, 'title' => get_string($field, 'artefact.internal'), 'rules' => array('required' => true)); if ($field == 'socialprofile') { $elements[$field] = ArtefactTypeSocialprofile::get_new_profile_elements(); // add an element to flag that socialprofile is in the list of fields. $elements['socialprofile_hidden'] = array('type' => 'hidden', 'value' => 1); } // @todo ruthlessly stolen from artefact/internal/index.php, could be merged if ($type == 'wysiwyg') { $elements[$field]['rows'] = 10; $elements[$field]['cols'] = 60; } if ($type == 'textarea') { $elements[$field]['rows'] = 4; $elements[$field]['cols'] = 60; } if ($field == 'country') { $elements[$field]['options'] = getoptions_country(); $elements[$field]['defaultvalue'] = get_config('country'); } if ($field == 'email') { // Check if a validation email has been sent if (record_exists('artefact_internal_profile_email', 'owner', $USER->get('id'))) { $elements['email']['type'] = 'html'; $elements['email']['value'] = get_string('validationprimaryemailsent', 'auth'); $elements['email']['disabled'] = true; $elements['email']['rules'] = array('required' => false); } else { $elements[$field]['rules']['email'] = true; $elements[$field]['description'] = get_string('primaryemaildescription', 'auth'); } } } if (empty($elements)) { // No mandatory fields that aren't set return; } if (count($elements) == 1 && isset($elements['email']) && $elements['email']['type'] == 'html') { // Display a message if there is only 1 required field and this field is email whose validation has been sent $elements['submit'] = array('type' => 'submit', 'value' => get_string('continue', 'admin')); $form = pieform(array('name' => 'requiredfields', 'method' => 'post', 'action' => get_config('wwwroot') . '?logout', 'elements' => $elements)); } else { $elements['submit'] = array('type' => 'submit', 'value' => get_string('submit')); $form = pieform(array('name' => 'requiredfields', 'method' => 'post', 'action' => '', 'elements' => $elements)); } $smarty = smarty(); if ($USER->get('parentuser')) { $smarty->assign('loginasoverridepasswordchange', get_string('loginasoverridepasswordchange', 'admin', '<a class="btn" href="' . get_config('wwwroot') . '?loginanyway">', '</a>')); } $smarty->assign('changepassword', $changepassword); $smarty->assign('changeusername', $SESSION->get('resetusername')); $smarty->assign('form', $form); $smarty->display('requiredfields.tpl'); exit; }
/** * Checks that all the required fields are set, and handles setting them if required. * * Checks whether the current user needs to change their password, and handles * the password changing if it's required. */ function auth_check_required_fields() { global $USER, $SESSION; if (defined('NOCHECKREQUIREDFIELDS')) { return; } $changepassword = true; $elements = array(); if (!$USER->get('passwordchange') || $USER->get('parentuser') && $USER->get('loginanyway') || defined('NOCHECKPASSWORDCHANGE')) { $changepassword = false; } // Check if the user wants to log in anyway if ($USER->get('passwordchange') && $USER->get('parentuser') && isset($_GET['loginanyway'])) { $USER->loginanyway = true; $changepassword = false; } // Do not force password change on JSON request. if (defined('JSON') && JSON == true) { $changepassword = false; } if ($changepassword) { $authobj = AuthFactory::create($USER->authinstance); if ($authobj->changepasswordurl) { redirect($authobj->changepasswordurl); exit; } if (method_exists($authobj, 'change_password')) { if ($SESSION->get('resetusername')) { $elements['username'] = array('type' => 'text', 'defaultvalue' => $USER->get('username'), 'title' => get_string('changeusername', 'account'), 'description' => get_string('changeusernamedesc', 'account', hsc(get_config('sitename')))); } $elements['password1'] = array('type' => 'password', 'title' => get_string('newpassword') . ':', 'description' => get_string('yournewpassword'), 'rules' => array('required' => true)); $elements['password2'] = array('type' => 'password', 'title' => get_string('confirmpassword') . ':', 'description' => get_string('yournewpasswordagain'), 'rules' => array('required' => true)); $elements['email'] = array('type' => 'text', 'title' => get_string('principalemailaddress', 'artefact.internal'), 'ignore' => trim($USER->get('email')) != '' && !preg_match('/@example\\.org$/', $USER->get('email')), 'rules' => array('required' => true, 'email' => true)); } } else { if (defined('JSON')) { // Don't need to check this for json requests return; } } safe_require('artefact', 'internal'); require_once 'pieforms/pieform.php'; $alwaysmandatoryfields = array_keys(ArtefactTypeProfile::get_always_mandatory_fields()); foreach (ArtefactTypeProfile::get_mandatory_fields() as $field => $type) { // Always mandatory fields are stored in the usr table, so are part of // the user session object. We can save a query by grabbing them from // the session. if (in_array($field, $alwaysmandatoryfields) && $USER->get($field) != null) { continue; } // Not cached? Get value the standard way. if (get_profile_field($USER->get('id'), $field) != null) { continue; } if ($field == 'email') { if (isset($elements['email'])) { continue; } // Use a text field for their first e-mail address, not the // emaillist element $type = 'text'; } $elements[$field] = array('type' => $type, 'title' => get_string($field, 'artefact.internal'), 'rules' => array('required' => true)); if ($field == 'socialprofile') { $elements[$field] = ArtefactTypeSocialprofile::get_new_profile_elements(); // add an element to flag that socialprofile is in the list of fields. $elements['socialprofile_hidden'] = array('type' => 'hidden', 'value' => 1); } // @todo ruthlessly stolen from artefact/internal/index.php, could be merged if ($type == 'wysiwyg') { $elements[$field]['rows'] = 10; $elements[$field]['cols'] = 60; } if ($type == 'textarea') { $elements[$field]['rows'] = 4; $elements[$field]['cols'] = 60; } if ($field == 'country') { $elements[$field]['options'] = getoptions_country(); $elements[$field]['defaultvalue'] = get_config('country'); } if ($field == 'email') { // Check if a validation email has been sent if (record_exists('artefact_internal_profile_email', 'owner', $USER->get('id'))) { $elements['email']['type'] = 'html'; $elements['email']['value'] = get_string('validationprimaryemailsent', 'auth'); $elements['email']['disabled'] = true; $elements['email']['rules'] = array('required' => false); } else { $elements[$field]['rules']['email'] = true; $elements[$field]['description'] = get_string('primaryemaildescription', 'auth'); } } } if (empty($elements)) { // No mandatory fields that aren't set return; } if (count($elements) == 1 && isset($elements['email']) && $elements['email']['type'] == 'html') { // Display a message if there is only 1 required field and this field is email whose validation has been sent $elements['submit'] = array('type' => 'submit', 'value' => get_string('continue', 'admin')); $form = pieform(array('name' => 'requiredfields', 'method' => 'post', 'action' => get_config('wwwroot') . '?logout', 'elements' => $elements)); } else { $elements['submit'] = array('type' => 'submit', 'class' => 'btn-success', 'value' => get_string('submit')); $form = pieform(array('name' => 'requiredfields', 'method' => 'post', 'action' => '', 'elements' => $elements, 'dieaftersubmit' => FALSE, 'backoutaftersubmit' => TRUE)); } // Has the form been successfully submitted? Back out and let the requested URL continue. if ($form === FALSE) { return; } $smarty = smarty(); if ($USER->get('parentuser')) { $smarty->assign('loginasoverridepasswordchange', get_string('loginasoverridepasswordchange', 'admin', '<a class="" href="' . get_config('wwwroot') . '?loginanyway">', '</a>')); } $smarty->assign('changepassword', $changepassword); $smarty->assign('changeusername', $SESSION->get('resetusername')); $smarty->assign('form', $form); $smarty->display('requiredfields.tpl'); exit; }
/** * Given a user and their remote user record, attempt to populate some of * the user's profile fields and account settings from the remote data. * * This does not change the first name, last name or e-mail fields, as these are * dealt with differently depending on whether we are creating the user * record or updating it. * * This method attempts to set: * * * City * * Country * * Language * * Introduction * * WYSIWYG editor setting * * @param User $user * @param stdClass $remoteuser */ private function import_user_settings($user, $remoteuser) { $imported = array(); // City if (!empty($remoteuser->city)) { if (get_profile_field($user->id, 'town') != $remoteuser->city) { set_profile_field($user->id, 'town', $remoteuser->city); } $imported[] = 'town'; } // Country if (!empty($remoteuser->country)) { $validcountries = array_keys(getoptions_country()); $newcountry = strtolower($remoteuser->country); if (in_array($newcountry, $validcountries)) { set_profile_field($user->id, 'country', $newcountry); } $imported[] = 'country'; } // Language if (!empty($remoteuser->lang)) { $validlanguages = array_keys(get_languages()); $newlanguage = str_replace('_utf8', '', strtolower($remoteuser->lang)) . '.utf8'; if (in_array($newlanguage, $validlanguages)) { set_account_preference($user->id, 'lang', $newlanguage); $user->set_account_preference('lang', $newlanguage); } } // Description if (isset($remoteuser->description)) { if (get_profile_field($user->id, 'introduction') != $remoteuser->description) { set_profile_field($user->id, 'introduction', $remoteuser->description); } $imported[] = 'introduction'; } // HTML Editor setting if (isset($remoteuser->htmleditor)) { $htmleditor = $remoteuser->htmleditor ? 1 : 0; if ($htmleditor != get_account_preference($user->id, 'wysiwyg')) { set_account_preference($user->id, 'wysiwyg', $htmleditor); $user->set_account_preference('wysiwyg', $htmleditor); } } return $imported; }
$items[$element]['rules'] = $element_data[$element]['rules']; } if ($type == 'wysiwyg') { $items[$element]['rows'] = 10; $items[$element]['cols'] = 50; $items[$element]['rules'] = array('maxlength' => 65536); } if ($type == 'textarea') { $items[$element]['rows'] = 4; $items[$element]['cols'] = 50; } if ($type == 'text') { $items[$element]['size'] = 30; } if ($element == 'country') { $countries = getoptions_country(); $items[$element]['options'] = array('' => get_string('nocountryselected')) + $countries; $items[$element]['defaultvalue'] = get_config('country'); } if ($element == 'socialprofile') { $items[$element] = ArtefactTypeSocialprofile::render_profile_element(); } if (get_helpfile_location('artefact', 'internal', 'profileform', $element)) { $items[$element]['help'] = true; } if (isset($profilefields[$element])) { $items[$element]['defaultvalue'] = $profilefields[$element]; } if (isset($element_required[$element])) { $items[$element]['rules']['required'] = true; }
public function render_self($options) { $countries = getoptions_country(); return array('html' => $countries[$this->title], 'javascript' => null); }
/** * Checks that all the required fields are set, and handles setting them if required. */ function auth_check_required_fields() { global $USER; if (defined('JSON')) { // Don't need to check this for json requests return; } safe_require('artefact', 'internal'); require_once 'pieforms/pieform.php'; $elements = array(); $alwaysmandatoryfields = array_keys(ArtefactTypeProfile::get_always_mandatory_fields()); foreach (ArtefactTypeProfile::get_mandatory_fields() as $field => $type) { // Always mandatory fields are stored in the usr table, so are part of // the user session object. We can save a query by grabbing them from // the session. if (in_array($field, $alwaysmandatoryfields) && $USER->get($field) != null) { continue; } // Not cached? Get value the standard way. if (get_profile_field($USER->get('id'), $field) != null) { continue; } if ($field == 'email') { // Use a text field for their first e-mail address, not the // emaillist element $type = 'text'; } $elements[$field] = array('type' => $type, 'title' => get_string($field, 'artefact.internal'), 'rules' => array('required' => true)); // @todo ruthlessly stolen from artefact/internal/index.php, could be merged if ($type == 'wysiwyg') { $elements[$field]['rows'] = 10; $elements[$field]['cols'] = 60; } if ($type == 'textarea') { $elements[$field]['rows'] = 4; $elements[$field]['cols'] = 60; } if ($field == 'country') { $elements[$field]['options'] = getoptions_country(); $elements[$field]['defaultvalue'] = 'nz'; } if ($field == 'email') { $elements[$field]['rules']['email'] = true; } } if (empty($elements)) { // No mandatory fields that aren't set return; } $elements['submit'] = array('type' => 'submit', 'value' => get_string('submit')); $form = pieform(array('name' => 'requiredfields', 'method' => 'post', 'action' => '', 'elements' => $elements)); $smarty = smarty(); $smarty->assign('form', $form); $smarty->display('requiredfields.tpl'); exit; }
} } } $items = array(); foreach ($element_list as $element => $type) { $items[$element] = array('type' => $type, 'title' => get_string($element, 'artefact.internal')); if ($type == 'wysiwyg') { $items[$element]['rows'] = 10; $items[$element]['cols'] = 60; } if ($type == 'textarea') { $items[$element]['rows'] = 4; $items[$element]['cols'] = 60; } if ($element == 'country') { $items[$element]['options'] = getoptions_country(); // @todo configure default country somehow... $items[$element]['defaultvalue'] = 'nz'; } if (get_helpfile_location('artefact', 'internal', 'profileform', $element)) { $items[$element]['help'] = true; } if (isset($profilefields[$element])) { $items[$element]['defaultvalue'] = $profilefields[$element]; } if (isset($element_required[$element])) { $items[$element]['rules']['required'] = true; } if (isset($lockedfields[$element]) && !$USER->get('admin')) { $items[$element]['disabled'] = true; }
/** * Checks that all the required fields are set, and handles setting them if required. * * Checks whether the current user needs to change their password, and handles * the password changing if it's required. */ function auth_check_required_fields() { global $USER, $SESSION; $changepassword = true; $elements = array(); if (!$USER->get('passwordchange') || $USER->get('parentuser') && $USER->get('loginanyway') || defined('NOCHECKPASSWORDCHANGE')) { $changepassword = false; } // Check if the user wants to log in anyway if ($USER->get('passwordchange') && $USER->get('parentuser') && isset($_GET['loginanyway'])) { $USER->loginanyway = true; $changepassword = false; } if ($changepassword) { $authobj = AuthFactory::create($USER->authinstance); if ($authobj->changepasswordurl) { redirect($authobj->changepasswordurl); exit; } if (method_exists($authobj, 'change_password')) { if ($SESSION->get('resetusername')) { $elements['username'] = array('type' => 'text', 'defaultvalue' => $USER->get('username'), 'title' => get_string('changeusername', 'account'), 'description' => get_string('changeusernamedesc', 'account', hsc(get_config('sitename')))); } $elements['password1'] = array('type' => 'password', 'title' => get_string('newpassword') . ':', 'description' => get_string('yournewpassword'), 'rules' => array('required' => true)); $elements['password2'] = array('type' => 'password', 'title' => get_string('confirmpassword') . ':', 'description' => get_string('yournewpasswordagain'), 'rules' => array('required' => true)); $elements['email'] = array('type' => 'text', 'title' => get_string('principalemailaddress', 'artefact.internal'), 'ignore' => trim($USER->get('email')) != '' && !preg_match('/@example\\.org$/', $USER->get('email')), 'rules' => array('required' => true, 'email' => true)); } } else { if (defined('JSON')) { // Don't need to check this for json requests return; } } safe_require('artefact', 'internal'); require_once 'pieforms/pieform.php'; $alwaysmandatoryfields = array_keys(ArtefactTypeProfile::get_always_mandatory_fields()); foreach (ArtefactTypeProfile::get_mandatory_fields() as $field => $type) { // Always mandatory fields are stored in the usr table, so are part of // the user session object. We can save a query by grabbing them from // the session. if (in_array($field, $alwaysmandatoryfields) && $USER->get($field) != null) { continue; } // Not cached? Get value the standard way. if (get_profile_field($USER->get('id'), $field) != null) { continue; } if ($field == 'email') { if (isset($elements['email'])) { continue; } // Use a text field for their first e-mail address, not the // emaillist element $type = 'text'; } $elements[$field] = array('type' => $type, 'title' => get_string($field, 'artefact.internal'), 'rules' => array('required' => true)); // @todo ruthlessly stolen from artefact/internal/index.php, could be merged if ($type == 'wysiwyg') { $elements[$field]['rows'] = 10; $elements[$field]['cols'] = 60; } if ($type == 'textarea') { $elements[$field]['rows'] = 4; $elements[$field]['cols'] = 60; } if ($field == 'country') { $elements[$field]['options'] = getoptions_country(); $elements[$field]['defaultvalue'] = get_config('country'); } if ($field == 'email') { $elements[$field]['rules']['email'] = true; } } if (empty($elements)) { // No mandatory fields that aren't set return; } $elements['submit'] = array('type' => 'submit', 'value' => get_string('submit')); $form = pieform(array('name' => 'requiredfields', 'method' => 'post', 'action' => '', 'elements' => $elements)); $smarty = smarty(); if ($USER->get('parentuser')) { $smarty->assign('loginasoverridepasswordchange', get_string('loginasoverridepasswordchange', 'admin', '<a href="' . get_config('wwwroot') . '?loginanyway">', '</a>')); } $smarty->assign('changepassword', $changepassword); $smarty->assign('changeusername', $SESSION->get('resetusername')); $smarty->assign('form', $form); $smarty->display('requiredfields.tpl'); exit; }