[ Index ]

PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008]

title

Body

[close]

/user/ -> editlib.php (source)

   1  <?php  //$Id: editlib.php,v 1.11.2.10 2008/07/05 22:46:58 skodak Exp $
   2  
   3  function cancel_email_update($userid) {
   4      unset_user_preference('newemail', $userid);
   5      unset_user_preference('newemailkey', $userid);
   6      unset_user_preference('newemailattemptsleft', $userid);
   7  }
   8  
   9  function useredit_load_preferences(&$user, $reload=true) {
  10      global $USER;
  11  
  12      if (!empty($user->id)) {
  13          if ($reload and $USER->id == $user->id) {
  14              // reload preferences in case it was changed in other session
  15              unset($USER->preference);
  16          }
  17          
  18          if ($preferences = get_user_preferences(null, null, $user->id)) {
  19              foreach($preferences as $name=>$value) {
  20                  $user->{'preference_'.$name} = $value;
  21              }
  22          }
  23      }
  24  }
  25  
  26  function useredit_update_user_preference($usernew) {
  27      $ua = (array)$usernew;
  28      foreach($ua as $key=>$value) {
  29          if (strpos($key, 'preference_') === 0) {
  30              $name = substr($key, strlen('preference_'));
  31              set_user_preference($name, $value, $usernew->id);
  32          }
  33      }
  34  }
  35  
  36  function useredit_update_picture(&$usernew, &$userform) {
  37      global $CFG;
  38  
  39      if (isset($usernew->deletepicture) and $usernew->deletepicture) {
  40          $location = make_user_directory($usernew->id, true);
  41          @remove_dir($location);
  42          set_field('user', 'picture', 0, 'id', $usernew->id);
  43      } else if ($usernew->picture = save_profile_image($usernew->id, $userform->get_um(), 'user')) {
  44          set_field('user', 'picture', 1, 'id', $usernew->id);
  45      }
  46  }
  47  
  48  function useredit_update_bounces($user, $usernew) {
  49      if (!isset($usernew->email)) {
  50          //locked field
  51          return;
  52      }
  53      if (!isset($user->email) || $user->email !== $usernew->email) {
  54          set_bounce_count($usernew,true);
  55          set_send_count($usernew,true);
  56      }
  57  }
  58  
  59  function useredit_update_trackforums($user, $usernew) {
  60      global $CFG;
  61      if (!isset($usernew->trackforums)) {
  62          //locked field
  63          return;
  64      }
  65      if ((!isset($user->trackforums) || ($usernew->trackforums != $user->trackforums)) and !$usernew->trackforums) {
  66          require_once($CFG->dirroot.'/mod/forum/lib.php');
  67          forum_tp_delete_read_records($usernew->id);
  68      }
  69  }
  70  
  71  function useredit_update_interests($user, $csv_tag_names) {
  72      tag_set('user', $user->id, explode(',', $csv_tag_names));
  73  }
  74  
  75  function useredit_shared_definition(&$mform) {
  76      global $CFG, $USER;
  77  
  78      $user = get_record('user', 'id', $USER->id);
  79      useredit_load_preferences($user, false);
  80  
  81      $strrequired = get_string('required');
  82  
  83      $nameordercheck = new object();
  84      $nameordercheck->firstname = 'a';
  85      $nameordercheck->lastname  = 'b';
  86      if (fullname($nameordercheck) == 'b a' ) {  // See MDL-4325
  87          $mform->addElement('text', 'lastname',  get_string('lastname'),  'maxlength="100" size="30"');
  88          $mform->addElement('text', 'firstname', get_string('firstname'), 'maxlength="100" size="30"');
  89      } else {
  90          $mform->addElement('text', 'firstname', get_string('firstname'), 'maxlength="100" size="30"');
  91          $mform->addElement('text', 'lastname',  get_string('lastname'),  'maxlength="100" size="30"');
  92      }
  93  
  94      $mform->addRule('firstname', $strrequired, 'required', null, 'client');
  95      $mform->setType('firstname', PARAM_NOTAGS);
  96  
  97      $mform->addRule('lastname', $strrequired, 'required', null, 'client');
  98      $mform->setType('lastname', PARAM_NOTAGS);
  99  
 100      // Do not show email field if change confirmation is pending
 101      if ($CFG->emailchangeconfirmation && !empty($user->preference_newemail)) {
 102          $notice = get_string('auth_emailchangepending', 'auth', $user);
 103          $notice .= '<br /><a href="edit.php?cancelemailchange=1&amp;id='.$user->id.'">'
 104                  . get_string('auth_emailchangecancel', 'auth') . '</a>';
 105          $mform->addElement('static', 'emailpending', get_string('email'), $notice);
 106      } else {
 107          $mform->addElement('text', 'email', get_string('email'), 'maxlength="100" size="30"');
 108          $mform->addRule('email', $strrequired, 'required', null, 'client');
 109      }
 110  
 111      $choices = array();
 112      $choices['0'] = get_string('emaildisplayno');
 113      $choices['1'] = get_string('emaildisplayyes');
 114      $choices['2'] = get_string('emaildisplaycourse');
 115      $mform->addElement('select', 'maildisplay', get_string('emaildisplay'), $choices);
 116      $mform->setDefault('maildisplay', 2);
 117  
 118      $choices = array();
 119      $choices['0'] = get_string('emailenable');
 120      $choices['1'] = get_string('emaildisable');
 121      $mform->addElement('select', 'emailstop', get_string('emailactive'), $choices);
 122      $mform->setDefault('emailenable', 1);
 123  
 124      $choices = array();
 125      $choices['0'] = get_string('textformat');
 126      $choices['1'] = get_string('htmlformat');
 127      $mform->addElement('select', 'mailformat', get_string('emailformat'), $choices);
 128      $mform->setDefault('mailformat', 1);
 129      $mform->setAdvanced('mailformat');
 130  
 131      if (!empty($CFG->allowusermailcharset)) {
 132          $choices = array();
 133          $charsets = get_list_of_charsets();
 134          if (!empty($CFG->sitemailcharset)) {
 135              $choices['0'] = get_string('site').' ('.$CFG->sitemailcharset.')';
 136          } else {
 137              $choices['0'] = get_string('site').' (UTF-8)';
 138          }
 139          $choices = array_merge($choices, $charsets);
 140          $mform->addElement('select', 'preference_mailcharset', get_string('emailcharset'), $choices);
 141          $mform->setAdvanced('preference_mailcharset');
 142      }
 143  
 144      $choices = array();
 145      $choices['0'] = get_string('emaildigestoff');
 146      $choices['1'] = get_string('emaildigestcomplete');
 147      $choices['2'] = get_string('emaildigestsubjects');
 148      $mform->addElement('select', 'maildigest', get_string('emaildigest'), $choices);
 149      $mform->setDefault('maildigest', 0);
 150      $mform->setAdvanced('maildigest');
 151  
 152      $choices = array();
 153      $choices['1'] = get_string('autosubscribeyes');
 154      $choices['0'] = get_string('autosubscribeno');
 155      $mform->addElement('select', 'autosubscribe', get_string('autosubscribe'), $choices);
 156      $mform->setDefault('autosubscribe', 1);
 157      $mform->setAdvanced('autosubscribe');
 158  
 159      if (!empty($CFG->forum_trackreadposts)) {
 160          $choices = array();
 161          $choices['0'] = get_string('trackforumsno');
 162          $choices['1'] = get_string('trackforumsyes');
 163          $mform->addElement('select', 'trackforums', get_string('trackforums'), $choices);
 164          $mform->setDefault('trackforums', 0);
 165          $mform->setAdvanced('trackforums');
 166      }
 167  
 168      if ($CFG->htmleditor) {
 169          $choices = array();
 170          $choices['0'] = get_string('texteditor');
 171          $choices['1'] = get_string('htmleditor');
 172          $mform->addElement('select', 'htmleditor', get_string('textediting'), $choices);
 173          $mform->setDefault('htmleditor', 1);
 174          $mform->setAdvanced('htmleditor');
 175      }
 176  
 177      if (empty($CFG->enableajax)) {
 178          $mform->addElement('static', 'ajaxdisabled', get_string('ajaxuse'), get_string('ajaxno'));
 179          $mform->setAdvanced('ajaxdisabled');
 180      } else {
 181          $choices = array();
 182          $choices['0'] = get_string('ajaxno');
 183          $choices['1'] = get_string('ajaxyes');
 184          $mform->addElement('select', 'ajax', get_string('ajaxuse'), $choices);
 185          $mform->setDefault('ajax', 0);
 186          $mform->setAdvanced('ajax');
 187      }
 188  
 189      $choices = array();
 190      $choices['0'] = get_string('screenreaderno');
 191      $choices['1'] = get_string('screenreaderyes');
 192      $mform->addElement('select', 'screenreader', get_string('screenreaderuse'), $choices);
 193      $mform->setDefault('screenreader', 0);
 194      $mform->setAdvanced('screenreader');
 195  
 196      $mform->addElement('text', 'city', get_string('city'), 'maxlength="20" size="21"');
 197      $mform->setType('city', PARAM_MULTILANG);
 198      $mform->addRule('city', $strrequired, 'required', null, 'client');
 199  
 200  
 201      $choices = get_list_of_countries();
 202      $choices= array(''=>get_string('selectacountry').'...') + $choices;
 203      $mform->addElement('select', 'country', get_string('selectacountry'), $choices);
 204      $mform->addRule('country', $strrequired, 'required', null, 'client');
 205      if (!empty($CFG->country)) {
 206          $mform->setDefault('country', $CFG->country);
 207      }
 208  
 209      $choices = get_list_of_timezones();
 210      $choices['99'] = get_string('serverlocaltime');
 211      if ($CFG->forcetimezone != 99) {
 212          $mform->addElement('static', 'forcedtimezone', get_string('timezone'), $choices[$CFG->forcetimezone]);
 213      } else {
 214          $mform->addElement('select', 'timezone', get_string('timezone'), $choices);
 215          $mform->setDefault('timezone', '99');
 216      }
 217  
 218      $mform->addElement('select', 'lang', get_string('preferredlanguage'), get_list_of_languages());
 219      $mform->setDefault('lang', $CFG->lang);
 220  
 221      if (!empty($CFG->allowuserthemes)) {
 222          $choices = array();
 223          $choices[''] = get_string('default');
 224          $choices += get_list_of_themes();
 225          $mform->addElement('select', 'theme', get_string('preferredtheme'), $choices);
 226          $mform->setAdvanced('theme');
 227      }
 228  
 229      $mform->addElement('htmleditor', 'description', get_string('userdescription'));
 230      $mform->setType('description', PARAM_CLEAN);
 231      $mform->setHelpButton('description', array('text', get_string('helptext')));
 232  
 233      if (!empty($CFG->gdversion)) {
 234          $mform->addElement('header', 'moodle_picture', get_string('pictureof'));//TODO: Accessibility fix fieldset legend
 235  
 236          $mform->addElement('static', 'currentpicture', get_string('currentpicture'));
 237  
 238          $mform->addElement('checkbox', 'deletepicture', get_string('delete'));
 239          $mform->setDefault('deletepicture',false);
 240  
 241          $mform->addElement('file', 'imagefile', get_string('newpicture'));
 242          $mform->setHelpButton('imagefile', array('picture', get_string('helppicture')));
 243  
 244          $mform->addElement('text', 'imagealt', get_string('imagealt'), 'maxlength="100" size="30"');
 245          $mform->setType('imagealt', PARAM_MULTILANG);
 246  
 247      }
 248  
 249      if( !empty($CFG->usetags)) {
 250          $mform->addElement('header', 'moodle_interests', get_string('interests'));
 251          $mform->addElement('textarea', 'interests', get_string('interestslist'), 'cols="45" rows="3"');
 252          $mform->setHelpButton('interests', array('interestslist', get_string('helpinterestslist'),
 253                            false, true, false));
 254      }
 255  
 256      /// Moodle optional fields
 257      $mform->addElement('header', 'moodle_optional', get_string('optional', 'form'));
 258      $mform->setAdvanced('moodle_optional');
 259  
 260      $mform->addElement('text', 'url', get_string('webpage'), 'maxlength="255" size="50"');
 261      $mform->setType('url', PARAM_URL);
 262  
 263      $mform->addElement('text', 'icq', get_string('icqnumber'), 'maxlength="15" size="25"');
 264      $mform->setType('icq', PARAM_CLEAN);
 265  
 266      $mform->addElement('text', 'skype', get_string('skypeid'), 'maxlength="50" size="25"');
 267      $mform->setType('skype', PARAM_CLEAN);
 268  
 269      $mform->addElement('text', 'aim', get_string('aimid'), 'maxlength="50" size="25"');
 270      $mform->setType('aim', PARAM_CLEAN);
 271  
 272      $mform->addElement('text', 'yahoo', get_string('yahooid'), 'maxlength="50" size="25"');
 273      $mform->setType('yahoo', PARAM_CLEAN);
 274  
 275      $mform->addElement('text', 'msn', get_string('msnid'), 'maxlength="50" size="25"');
 276      $mform->setType('msn', PARAM_CLEAN);
 277  
 278      $mform->addElement('text', 'idnumber', get_string('idnumber'), 'maxlength="255" size="25"');
 279      $mform->setType('idnumber', PARAM_CLEAN);
 280  
 281      $mform->addElement('text', 'institution', get_string('institution'), 'maxlength="40" size="25"');
 282      $mform->setType('institution', PARAM_MULTILANG);
 283  
 284      $mform->addElement('text', 'department', get_string('department'), 'maxlength="30" size="25"');
 285      $mform->setType('department', PARAM_MULTILANG);
 286  
 287      $mform->addElement('text', 'phone1', get_string('phone'), 'maxlength="20" size="25"');
 288      $mform->setType('phone1', PARAM_CLEAN);
 289  
 290      $mform->addElement('text', 'phone2', get_string('phone2'), 'maxlength="20" size="25"');
 291      $mform->setType('phone2', PARAM_CLEAN);
 292  
 293      $mform->addElement('text', 'address', get_string('address'), 'maxlength="70" size="25"');
 294      $mform->setType('address', PARAM_MULTILANG);
 295  
 296  
 297  }
 298  
 299  ?>


Generated: Wed Jan 14 11:33:29 2009 Cross-referenced by PHPXref 0.7