Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/user/editlib.php
Go to the documentation of this file.
00001 <?php
00002 
00003 function cancel_email_update($userid) {
00004     unset_user_preference('newemail', $userid);
00005     unset_user_preference('newemailkey', $userid);
00006     unset_user_preference('newemailattemptsleft', $userid);
00007 }
00008 
00009 function useredit_load_preferences(&$user, $reload=true) {
00010     global $USER;
00011 
00012     if (!empty($user->id)) {
00013         if ($reload and $USER->id == $user->id) {
00014             // reload preferences in case it was changed in other session
00015             unset($USER->preference);
00016         }
00017 
00018         if ($preferences = get_user_preferences(null, null, $user->id)) {
00019             foreach($preferences as $name=>$value) {
00020                 $user->{'preference_'.$name} = $value;
00021             }
00022         }
00023     }
00024 }
00025 
00026 function useredit_update_user_preference($usernew) {
00027     $ua = (array)$usernew;
00028     foreach($ua as $key=>$value) {
00029         if (strpos($key, 'preference_') === 0) {
00030             $name = substr($key, strlen('preference_'));
00031             set_user_preference($name, $value, $usernew->id);
00032         }
00033     }
00034 }
00035 
00045 function useredit_update_picture(stdClass $usernew, moodleform $userform) {
00046     global $CFG, $DB;
00047     require_once("$CFG->libdir/gdlib.php");
00048 
00049     $context = get_context_instance(CONTEXT_USER, $usernew->id, MUST_EXIST);
00050     // This will hold the value to set to the user's picture field at the end of
00051     // this function
00052     $picturetouse = null;
00053     if (!empty($usernew->deletepicture)) {
00054         // The user has chosen to delete the selected users picture
00055         $fs = get_file_storage();
00056         $fs->delete_area_files($context->id, 'user', 'icon'); // drop all areas
00057         $picturetouse = 0;
00058     } else if ($iconfile = $userform->save_temp_file('imagefile')) {
00059         // There is a new image that has been uploaded
00060         // Process the new image and set the user to make use of it.
00061         // NOTE: This may be overridden by Gravatar
00062         if (process_new_icon($context, 'user', 'icon', 0, $iconfile)) {
00063             $picturetouse = 1;
00064         }
00065         // Delete the file that has now been processed
00066         @unlink($iconfile);
00067     }
00068 
00069     // If we have a picture to set we can now do so. Note this will still be NULL
00070     // unless the user has changed their picture or caused a change by selecting
00071     // to delete their picture or use gravatar
00072     if (!is_null($picturetouse)) {
00073         $DB->set_field('user', 'picture', $picturetouse, array('id' => $usernew->id));
00074         return true;
00075     }
00076 
00077     return false;
00078 }
00079 
00080 function useredit_update_bounces($user, $usernew) {
00081     if (!isset($usernew->email)) {
00082         //locked field
00083         return;
00084     }
00085     if (!isset($user->email) || $user->email !== $usernew->email) {
00086         set_bounce_count($usernew,true);
00087         set_send_count($usernew,true);
00088     }
00089 }
00090 
00091 function useredit_update_trackforums($user, $usernew) {
00092     global $CFG;
00093     if (!isset($usernew->trackforums)) {
00094         //locked field
00095         return;
00096     }
00097     if ((!isset($user->trackforums) || ($usernew->trackforums != $user->trackforums)) and !$usernew->trackforums) {
00098         require_once($CFG->dirroot.'/mod/forum/lib.php');
00099         forum_tp_delete_read_records($usernew->id);
00100     }
00101 }
00102 
00103 function useredit_update_interests($user, $interests) {
00104     tag_set('user', $user->id, $interests);
00105 }
00106 
00107 function useredit_shared_definition(&$mform, $editoroptions = null) {
00108     global $CFG, $USER, $DB;
00109 
00110     $user = $DB->get_record('user', array('id' => $USER->id));
00111     useredit_load_preferences($user, false);
00112 
00113     $strrequired = get_string('required');
00114 
00115     $nameordercheck = new stdClass();
00116     $nameordercheck->firstname = 'a';
00117     $nameordercheck->lastname  = 'b';
00118     if (fullname($nameordercheck) == 'b a' ) {  // See MDL-4325
00119         $mform->addElement('text', 'lastname',  get_string('lastname'),  'maxlength="100" size="30"');
00120         $mform->addElement('text', 'firstname', get_string('firstname'), 'maxlength="100" size="30"');
00121     } else {
00122         $mform->addElement('text', 'firstname', get_string('firstname'), 'maxlength="100" size="30"');
00123         $mform->addElement('text', 'lastname',  get_string('lastname'),  'maxlength="100" size="30"');
00124     }
00125 
00126     $mform->addRule('firstname', $strrequired, 'required', null, 'client');
00127     $mform->setType('firstname', PARAM_NOTAGS);
00128 
00129     $mform->addRule('lastname', $strrequired, 'required', null, 'client');
00130     $mform->setType('lastname', PARAM_NOTAGS);
00131 
00132     // Do not show email field if change confirmation is pending
00133     if (!empty($CFG->emailchangeconfirmation) and !empty($user->preference_newemail)) {
00134         $notice = get_string('emailchangepending', 'auth', $user);
00135         $notice .= '<br /><a href="edit.php?cancelemailchange=1&amp;id='.$user->id.'">'
00136                 . get_string('emailchangecancel', 'auth') . '</a>';
00137         $mform->addElement('static', 'emailpending', get_string('email'), $notice);
00138     } else {
00139         $mform->addElement('text', 'email', get_string('email'), 'maxlength="100" size="30"');
00140         $mform->addRule('email', $strrequired, 'required', null, 'client');
00141     }
00142 
00143     $choices = array();
00144     $choices['0'] = get_string('emaildisplayno');
00145     $choices['1'] = get_string('emaildisplayyes');
00146     $choices['2'] = get_string('emaildisplaycourse');
00147     $mform->addElement('select', 'maildisplay', get_string('emaildisplay'), $choices);
00148     $mform->setDefault('maildisplay', 2);
00149 
00150     $choices = array();
00151     $choices['0'] = get_string('textformat');
00152     $choices['1'] = get_string('htmlformat');
00153     $mform->addElement('select', 'mailformat', get_string('emailformat'), $choices);
00154     $mform->setDefault('mailformat', 1);
00155 
00156     if (!empty($CFG->allowusermailcharset)) {
00157         $choices = array();
00158         $charsets = get_list_of_charsets();
00159         if (!empty($CFG->sitemailcharset)) {
00160             $choices['0'] = get_string('site').' ('.$CFG->sitemailcharset.')';
00161         } else {
00162             $choices['0'] = get_string('site').' (UTF-8)';
00163         }
00164         $choices = array_merge($choices, $charsets);
00165         $mform->addElement('select', 'preference_mailcharset', get_string('emailcharset'), $choices);
00166     }
00167 
00168     $choices = array();
00169     $choices['0'] = get_string('emaildigestoff');
00170     $choices['1'] = get_string('emaildigestcomplete');
00171     $choices['2'] = get_string('emaildigestsubjects');
00172     $mform->addElement('select', 'maildigest', get_string('emaildigest'), $choices);
00173     $mform->setDefault('maildigest', 0);
00174 
00175     $choices = array();
00176     $choices['1'] = get_string('autosubscribeyes');
00177     $choices['0'] = get_string('autosubscribeno');
00178     $mform->addElement('select', 'autosubscribe', get_string('autosubscribe'), $choices);
00179     $mform->setDefault('autosubscribe', 1);
00180 
00181     if (!empty($CFG->forum_trackreadposts)) {
00182         $choices = array();
00183         $choices['0'] = get_string('trackforumsno');
00184         $choices['1'] = get_string('trackforumsyes');
00185         $mform->addElement('select', 'trackforums', get_string('trackforums'), $choices);
00186         $mform->setDefault('trackforums', 0);
00187     }
00188 
00189     $editors = editors_get_enabled();
00190     if (count($editors) > 1) {
00191         $choices = array();
00192         $choices['0'] = get_string('texteditor');
00193         $choices['1'] = get_string('htmleditor');
00194         $mform->addElement('select', 'htmleditor', get_string('textediting'), $choices);
00195         $mform->setDefault('htmleditor', 1);
00196     } else {
00197         $mform->addElement('hidden', 'htmleditor');
00198         $mform->setDefault('htmleditor', 1);
00199         $mform->setType('htmleditor', PARAM_INT);
00200     }
00201 
00202     if (empty($CFG->enableajax)) {
00203         $mform->addElement('static', 'ajaxdisabled', get_string('ajaxuse'), get_string('ajaxno'));
00204     } else {
00205         $choices = array();
00206         $choices['0'] = get_string('ajaxno');
00207         $choices['1'] = get_string('ajaxyes');
00208         $mform->addElement('select', 'ajax', get_string('ajaxuse'), $choices);
00209         $mform->setDefault('ajax', 0);
00210     }
00211 
00212     $choices = array();
00213     $choices['0'] = get_string('screenreaderno');
00214     $choices['1'] = get_string('screenreaderyes');
00215     $mform->addElement('select', 'screenreader', get_string('screenreaderuse'), $choices);
00216     $mform->setDefault('screenreader', 0);
00217     $mform->addHelpButton('screenreader', 'screenreaderuse');
00218 
00219     $mform->addElement('text', 'city', get_string('city'), 'maxlength="120" size="21"');
00220     $mform->setType('city', PARAM_MULTILANG);
00221     $mform->addRule('city', $strrequired, 'required', null, 'client');
00222     if (!empty($CFG->defaultcity)) {
00223         $mform->setDefault('city', $CFG->defaultcity);
00224     }
00225 
00226     $choices = get_string_manager()->get_list_of_countries();
00227     $choices= array(''=>get_string('selectacountry').'...') + $choices;
00228     $mform->addElement('select', 'country', get_string('selectacountry'), $choices);
00229     $mform->addRule('country', $strrequired, 'required', null, 'client');
00230     if (!empty($CFG->country)) {
00231         $mform->setDefault('country', $CFG->country);
00232     }
00233 
00234     $choices = get_list_of_timezones();
00235     $choices['99'] = get_string('serverlocaltime');
00236     if ($CFG->forcetimezone != 99) {
00237         $mform->addElement('static', 'forcedtimezone', get_string('timezone'), $choices[$CFG->forcetimezone]);
00238     } else {
00239         $mform->addElement('select', 'timezone', get_string('timezone'), $choices);
00240         $mform->setDefault('timezone', '99');
00241     }
00242 
00243     $mform->addElement('select', 'lang', get_string('preferredlanguage'), get_string_manager()->get_list_of_translations());
00244     $mform->setDefault('lang', $CFG->lang);
00245 
00246     if (!empty($CFG->allowuserthemes)) {
00247         $choices = array();
00248         $choices[''] = get_string('default');
00249         $themes = get_list_of_themes();
00250         foreach ($themes as $key=>$theme) {
00251             if (empty($theme->hidefromselector)) {
00252                 $choices[$key] = get_string('pluginname', 'theme_'.$theme->name);
00253             }
00254         }
00255         $mform->addElement('select', 'theme', get_string('preferredtheme'), $choices);
00256     }
00257 
00258     $mform->addElement('editor', 'description_editor', get_string('userdescription'), null, $editoroptions);
00259     $mform->setType('description_editor', PARAM_CLEANHTML);
00260     $mform->addHelpButton('description_editor', 'userdescription');
00261 
00262     if (!empty($CFG->gdversion) and empty($USER->newadminuser)) {
00263         $mform->addElement('header', 'moodle_picture', get_string('pictureofuser'));
00264 
00265         if (!empty($CFG->enablegravatar)) {
00266             $mform->addElement('html', html_writer::tag('p', get_string('gravatarenabled')));
00267         }
00268 
00269         $mform->addElement('static', 'currentpicture', get_string('currentpicture'));
00270 
00271         $mform->addElement('checkbox', 'deletepicture', get_string('delete'));
00272         $mform->setDefault('deletepicture', 0);
00273 
00274         $mform->addElement('filepicker', 'imagefile', get_string('newpicture'), '', array('maxbytes'=>get_max_upload_file_size($CFG->maxbytes)));
00275         $mform->addHelpButton('imagefile', 'newpicture');
00276 
00277         $mform->addElement('text', 'imagealt', get_string('imagealt'), 'maxlength="100" size="30"');
00278         $mform->setType('imagealt', PARAM_MULTILANG);
00279 
00280     }
00281 
00282     if (!empty($CFG->usetags) and empty($USER->newadminuser)) {
00283         $mform->addElement('header', 'moodle_interests', get_string('interests'));
00284         $mform->addElement('tags', 'interests', get_string('interestslist'), array('display' => 'noofficial'));
00285         $mform->addHelpButton('interests', 'interestslist');
00286     }
00287 
00289     $mform->addElement('header', 'moodle_optional', get_string('optional', 'form'));
00290 
00291     $mform->addElement('text', 'url', get_string('webpage'), 'maxlength="255" size="50"');
00292     $mform->setType('url', PARAM_URL);
00293 
00294     $mform->addElement('text', 'icq', get_string('icqnumber'), 'maxlength="15" size="25"');
00295     $mform->setType('icq', PARAM_NOTAGS);
00296 
00297     $mform->addElement('text', 'skype', get_string('skypeid'), 'maxlength="50" size="25"');
00298     $mform->setType('skype', PARAM_NOTAGS);
00299 
00300     $mform->addElement('text', 'aim', get_string('aimid'), 'maxlength="50" size="25"');
00301     $mform->setType('aim', PARAM_NOTAGS);
00302 
00303     $mform->addElement('text', 'yahoo', get_string('yahooid'), 'maxlength="50" size="25"');
00304     $mform->setType('yahoo', PARAM_NOTAGS);
00305 
00306     $mform->addElement('text', 'msn', get_string('msnid'), 'maxlength="50" size="25"');
00307     $mform->setType('msn', PARAM_NOTAGS);
00308 
00309     $mform->addElement('text', 'idnumber', get_string('idnumber'), 'maxlength="255" size="25"');
00310     $mform->setType('idnumber', PARAM_NOTAGS);
00311 
00312     $mform->addElement('text', 'institution', get_string('institution'), 'maxlength="40" size="25"');
00313     $mform->setType('institution', PARAM_MULTILANG);
00314 
00315     $mform->addElement('text', 'department', get_string('department'), 'maxlength="30" size="25"');
00316     $mform->setType('department', PARAM_MULTILANG);
00317 
00318     $mform->addElement('text', 'phone1', get_string('phone'), 'maxlength="20" size="25"');
00319     $mform->setType('phone1', PARAM_NOTAGS);
00320 
00321     $mform->addElement('text', 'phone2', get_string('phone2'), 'maxlength="20" size="25"');
00322     $mform->setType('phone2', PARAM_NOTAGS);
00323 
00324     $mform->addElement('text', 'address', get_string('address'), 'maxlength="70" size="25"');
00325     $mform->setType('address', PARAM_MULTILANG);
00326 
00327 
00328 }
00329 
00330 
 All Data Structures Namespaces Files Functions Variables Enumerations