[ Index ]

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

title

Body

[close]

/admin/ -> uploaduser_form.php (source)

   1  <?php // $Id: uploaduser_form.php,v 1.4.2.7 2008/03/26 02:46:48 dongsheng Exp $
   2  require_once $CFG->libdir.'/formslib.php';
   3  
   4  class admin_uploaduser_form1 extends moodleform {
   5      function definition (){
   6          global $CFG, $USER;
   7  
   8          $mform =& $this->_form;
   9  
  10          $this->set_upload_manager(new upload_manager('userfile', false, false, null, false, 0, true, true, false));
  11  
  12          $mform->addElement('header', 'settingsheader', get_string('upload'));
  13  
  14          $mform->addElement('file', 'userfile', get_string('file'), 'size="40"');
  15          $mform->addRule('userfile', null, 'required');
  16  
  17          $choices = csv_import_reader::get_delimiter_list();
  18          $mform->addElement('select', 'delimiter_name', get_string('csvdelimiter', 'admin'), $choices);
  19          if (array_key_exists('cfg', $choices)) {
  20              $mform->setDefault('delimiter_name', 'cfg');
  21          } else if (get_string('listsep') == ';') {
  22              $mform->setDefault('delimiter_name', 'semicolon');
  23          } else {
  24              $mform->setDefault('delimiter_name', 'comma');
  25          }
  26  
  27          $textlib = textlib_get_instance();
  28          $choices = $textlib->get_encodings();
  29          $mform->addElement('select', 'encoding', get_string('encoding', 'admin'), $choices);
  30          $mform->setDefault('encoding', 'UTF-8');
  31  
  32          $choices = array('10'=>10, '20'=>20, '100'=>100, '1000'=>1000, '100000'=>100000);
  33          $mform->addElement('select', 'previewrows', get_string('rowpreviewnum', 'admin'), $choices);
  34          $mform->setType('previewrows', PARAM_INT);
  35  
  36          $this->add_action_buttons(false, get_string('uploadusers'));
  37      }
  38  }
  39  
  40  class admin_uploaduser_form2 extends moodleform {
  41      function definition (){
  42          global $CFG, $USER;
  43  
  44          //no editors here - we need proper empty fields
  45          $CFG->htmleditor = null;
  46  
  47          $mform   =& $this->_form;
  48          $columns =& $this->_customdata;
  49  
  50          // I am the template user, why should it be the administrator? we have roles now, other ppl may use this script ;-)
  51          $templateuser = $USER;
  52  
  53  // upload settings and file
  54          $mform->addElement('header', 'settingsheader', get_string('settings'));
  55  
  56          $choices = array(UU_ADDNEW    => get_string('uuoptype_addnew', 'admin'),
  57                           UU_ADDINC    => get_string('uuoptype_addinc', 'admin'),
  58                           UU_ADD_UPDATE => get_string('uuoptype_addupdate', 'admin'),
  59                           UU_UPDATE     => get_string('uuoptype_update', 'admin'));
  60          $mform->addElement('select', 'uutype', get_string('uuoptype', 'admin'), $choices);
  61  
  62          $choices = array(0 => get_string('infilefield', 'auth'), 1 => get_string('createpasswordifneeded', 'auth'));
  63          $mform->addElement('select', 'uupasswordnew', get_string('uupasswordnew', 'admin'), $choices);
  64          $mform->setDefault('uupasswordnew', 0);
  65          $mform->disabledIf('uupasswordnew', 'uutype', 'eq', UU_UPDATE);
  66  
  67          $choices = array(0 => get_string('nochanges', 'admin'),
  68                           1 => get_string('uuupdatefromfile', 'admin'),
  69                           2 => get_string('uuupdateall', 'admin'),
  70                           3 => get_string('uuupdatemissing', 'admin'));
  71          $mform->addElement('select', 'uuupdatetype', get_string('uuupdatetype', 'admin'), $choices);
  72          $mform->setDefault('uuupdatetype', 0);
  73          $mform->disabledIf('uuupdatetype', 'uutype', 'eq', UU_ADDNEW);
  74          $mform->disabledIf('uuupdatetype', 'uutype', 'eq', UU_ADDINC);
  75  
  76          $choices = array(0 => get_string('nochanges', 'admin'), 1 => get_string('update'));
  77          $mform->addElement('select', 'uupasswordold', get_string('uupasswordold', 'admin'), $choices);
  78          $mform->setDefault('uupasswordold', 0);
  79          $mform->disabledIf('uupasswordold', 'uutype', 'eq', UU_ADDNEW);
  80          $mform->disabledIf('uupasswordold', 'uutype', 'eq', UU_ADDINC);
  81          $mform->disabledIf('uupasswordold', 'uuupdatetype', 'eq', 0);
  82          $mform->disabledIf('uupasswordold', 'uuupdatetype', 'eq', 3);
  83  
  84          $mform->addElement('selectyesno', 'uuallowrenames', get_string('allowrenames', 'admin'));
  85          $mform->setDefault('uuallowrenames', 0);
  86          $mform->disabledIf('uuallowrenames', 'uutype', 'eq', UU_ADDNEW);
  87          $mform->disabledIf('uuallowrenames', 'uutype', 'eq', UU_ADDINC);
  88  
  89          $mform->addElement('selectyesno', 'uuallowdeletes', get_string('allowdeletes', 'admin'));
  90          $mform->setDefault('uuallowdeletes', 0);
  91          $mform->disabledIf('uuallowdeletes', 'uutype', 'eq', UU_ADDNEW);
  92          $mform->disabledIf('uuallowdeletes', 'uutype', 'eq', UU_ADDINC);
  93  
  94          $mform->addElement('selectyesno', 'uunoemailduplicates', get_string('uunoemailduplicates', 'admin'));
  95          $mform->setDefault('uunoemailduplicates', 0);
  96  
  97          $choices = array(0 => get_string('no'),
  98                           1 => get_string('uubulknew', 'admin'),
  99                           2 => get_string('uubulkupdated', 'admin'),
 100                           3 => get_string('uubulkall', 'admin'));
 101          $mform->addElement('select', 'uubulk', get_string('uubulk', 'admin'), $choices);
 102          $mform->setDefault('uubulk', 0);
 103  
 104  // roles selection
 105          $showroles = false;
 106          foreach ($columns as $column) {
 107              if (preg_match('/^type\d+$/', $column)) {
 108                  $showroles = true;
 109                  break;
 110              }
 111          }
 112          if ($showroles) {
 113              $mform->addElement('header', 'rolesheader', get_string('roles'));
 114  
 115              $choices = uu_allowed_roles(true);
 116  
 117              $choices[0] = get_string('uucoursedefaultrole', 'admin');
 118              $mform->addElement('select', 'uulegacy1', get_string('uulegacy1role', 'admin'), $choices);
 119              $mform->setDefault('uulegacy1', 0);
 120              unset($choices[0]);
 121  
 122              $mform->addElement('select', 'uulegacy2', get_string('uulegacy2role', 'admin'), $choices);
 123              if ($editteacherroles = get_roles_with_capability('moodle/legacy:editingteacher', CAP_ALLOW)) {
 124                  $editteacherrole = array_shift($editteacherroles);   /// Take the first one
 125                  $mform->setDefault('uulegacy2', $editteacherrole->id);
 126                  unset($editteacherroles);
 127              } else {
 128                  $mform->setDefault('uulegacy2', $CFG->defaultcourseroleid);
 129              }
 130  
 131              $mform->addElement('select', 'uulegacy3', get_string('uulegacy3role', 'admin'), $choices);
 132              if ($teacherroles = get_roles_with_capability('moodle/legacy:teacher', CAP_ALLOW)) {
 133                  $teacherrole = array_shift($teacherroles);   /// Take the first one
 134                  $mform->setDefault('uulegacy3', $teacherrole->id);
 135                  unset($teacherroles);
 136              } else {
 137                  $mform->setDefault('uulegacy3', $CFG->defaultcourseroleid);
 138              }
 139          }
 140  
 141  // default values
 142          $mform->addElement('header', 'defaultheader', get_string('defaultvalues', 'admin'));
 143  
 144          $mform->addElement('text', 'username', get_string('username'), 'size="20"');
 145          $mform->addRule('username', get_string('requiredtemplate', 'admin'), 'required', null, 'client');
 146  
 147          // only enabled and known to work plugins
 148          $choices = uu_allowed_auths();
 149          $mform->addElement('select', 'auth', get_string('chooseauthmethod','auth'), $choices);
 150          $mform->setDefault('auth', 'manual'); // manual is a sensible backwards compatible default
 151          $mform->setHelpButton('auth', array('authchange', get_string('chooseauthmethod','auth')));
 152          $mform->setAdvanced('auth');
 153  
 154          $mform->addElement('text', 'email', get_string('email'), 'maxlength="100" size="30"');
 155  
 156          $choices = array(0 => get_string('emaildisplayno'), 1 => get_string('emaildisplayyes'), 2 => get_string('emaildisplaycourse'));
 157          $mform->addElement('select', 'maildisplay', get_string('emaildisplay'), $choices);
 158          $mform->setDefault('maildisplay', 2);
 159  
 160          $choices = array(0 => get_string('emailenable'), 1 => get_string('emaildisable'));
 161          $mform->addElement('select', 'emailstop', get_string('emailactive'), $choices);
 162  
 163          $choices = array(0 => get_string('textformat'), 1 => get_string('htmlformat'));
 164          $mform->addElement('select', 'mailformat', get_string('emailformat'), $choices);
 165          $mform->setDefault('mailformat', 1);
 166          $mform->setAdvanced('mailformat');
 167  
 168          $choices = array(0 => get_string('emaildigestoff'), 1 => get_string('emaildigestcomplete'), 2 => get_string('emaildigestsubjects'));
 169          $mform->addElement('select', 'maildigest', get_string('emaildigest'), $choices);
 170          $mform->setDefault('maildigest', 0);
 171          $mform->setAdvanced('maildigest');
 172  
 173          $choices = array(0 => get_string('autosubscribeyes'), 1 => get_string('autosubscribeno'));
 174          $mform->addElement('select', 'autosubscribe', get_string('autosubscribe'), $choices);
 175          $mform->setDefault('autosubscribe', 1);
 176  
 177          if ($CFG->htmleditor) {
 178              $choices = array(0 => get_string('texteditor'), 1 => get_string('htmleditor'));
 179              $mform->addElement('select', 'htmleditor', get_string('textediting'), $choices);
 180              $mform->setDefault('htmleditor', 1);
 181          } else {
 182              $mform->addElement('static', 'htmleditor', get_string('textediting'), get_string('texteditor'));
 183          }
 184          $mform->setAdvanced('htmleditor');
 185  
 186          if (empty($CFG->enableajax)) {
 187              $mform->addElement('static', 'ajax', get_string('ajaxuse'), get_string('ajaxno'));
 188          } else {
 189              $choices = array( 0 => get_string('ajaxno'), 1 => get_string('ajaxyes'));
 190              $mform->addElement('select', 'ajax', get_string('ajaxuse'), $choices);
 191              $mform->setDefault('ajax', 1);
 192          }
 193          $mform->setAdvanced('ajax');
 194  
 195          $mform->addElement('text', 'city', get_string('city'), 'maxlength="100" size="25"');
 196          $mform->setType('city', PARAM_MULTILANG);
 197          $mform->setDefault('city', $templateuser->city);
 198  
 199          $mform->addElement('select', 'country', get_string('selectacountry'), get_list_of_countries());
 200          $mform->setDefault('country', $templateuser->country);
 201          $mform->setAdvanced('country');
 202  
 203          $choices = get_list_of_timezones();
 204          $choices['99'] = get_string('serverlocaltime');
 205          $mform->addElement('select', 'timezone', get_string('timezone'), $choices);
 206          $mform->setDefault('timezone', $templateuser->timezone);
 207          $mform->setAdvanced('timezone');
 208  
 209          $mform->addElement('select', 'lang', get_string('preferredlanguage'), get_list_of_languages());
 210          $mform->setDefault('lang', $templateuser->lang);
 211          $mform->setAdvanced('lang');
 212  
 213          $mform->addElement('htmleditor', 'description', get_string('userdescription'));
 214          $mform->setType('description', PARAM_CLEAN);
 215          $mform->setHelpButton('description', array('text', get_string('helptext')));
 216          $mform->setAdvanced('description');
 217  
 218          $mform->addElement('text', 'url', get_string('webpage'), 'maxlength="255" size="50"');
 219          $mform->setAdvanced('url');
 220  
 221          $mform->addElement('text', 'idnumber', get_string('idnumber'), 'maxlength="64" size="25"');
 222          $mform->setType('idnumber', PARAM_CLEAN);
 223  
 224          $mform->addElement('text', 'institution', get_string('institution'), 'maxlength="40" size="25"');
 225          $mform->setType('institution', PARAM_MULTILANG);
 226          $mform->setDefault('institution', $templateuser->institution);
 227  
 228          $mform->addElement('text', 'department', get_string('department'), 'maxlength="30" size="25"');
 229          $mform->setType('department', PARAM_MULTILANG);
 230          $mform->setDefault('department', $templateuser->department);
 231  
 232          $mform->addElement('text', 'phone1', get_string('phone'), 'maxlength="20" size="25"');
 233          $mform->setType('phone1', PARAM_CLEAN);
 234          $mform->setAdvanced('phone1');
 235  
 236          $mform->addElement('text', 'phone2', get_string('phone2'), 'maxlength="20" size="25"');
 237          $mform->setType('phone2', PARAM_CLEAN);
 238          $mform->setAdvanced('phone2');
 239  
 240          $mform->addElement('text', 'address', get_string('address'), 'maxlength="70" size="25"');
 241          $mform->setType('address', PARAM_MULTILANG);
 242          $mform->setAdvanced('address');
 243  
 244          /// Next the profile defaults
 245          profile_definition($mform);
 246  
 247  // hidden fields
 248          $mform->addElement('hidden', 'iid');
 249          $mform->setType('iid', PARAM_INT);
 250  
 251          $mform->addElement('hidden', 'previewrows');
 252          $mform->setType('previewrows', PARAM_INT);
 253  
 254          $mform->addElement('hidden', 'readcount');
 255          $mform->setType('readcount', PARAM_INT);
 256  
 257          $this->add_action_buttons(true, get_string('uploadusers'));
 258      }
 259  
 260      /**
 261       * Form tweaks that depend on current data.
 262       */
 263      function definition_after_data() {
 264          $mform   =& $this->_form;
 265          $columns =& $this->_customdata;
 266  
 267          foreach ($columns as $column) {
 268              if ($mform->elementExists($column)) {
 269                  $mform->removeElement($column);
 270              }
 271          }
 272      }
 273  
 274      /**
 275       * Server side validation.
 276       */
 277      function validation($data, $files) {
 278          $errors = parent::validation($data, $files);
 279          $columns =& $this->_customdata;
 280          $optype  = $data['uutype'];
 281  
 282          // detect if password column needed in file
 283          if (!in_array('password', $columns)) {
 284              switch ($optype) {
 285                  case UU_UPDATE:
 286                      if (!empty($data['uupasswordold'])) {
 287                          $errors['uupasswordold'] = get_string('missingfield', 'error', 'password');
 288                      }
 289                      break;
 290  
 291                  case UU_ADD_UPDATE:
 292                      if (empty($data['uupasswordnew'])) {
 293                          $errors['uupasswordnew'] = get_string('missingfield', 'error', 'password');
 294                      }
 295                      if  (!empty($data['uupasswordold'])) {
 296                          $errors['uupasswordold'] = get_string('missingfield', 'error', 'password');
 297                      }
 298                      break;
 299  
 300                  case UU_ADDNEW:
 301                  case UU_ADDINC:
 302                      if (empty($data['uupasswordnew'])) {
 303                          $errors['uupasswordnew'] = get_string('missingfield', 'error', 'password');
 304                      }
 305                      break;
 306               }
 307          }
 308  
 309          // look for other required data
 310          if ($optype != UU_UPDATE) {
 311              if (!in_array('firstname', $columns)) {
 312                  $errors['uutype'] = get_string('missingfield', 'error', 'firstname');
 313              }
 314  
 315              if (!in_array('lastname', $columns)) {
 316                  if (isset($errors['uutype'])) {
 317                      $errors['uutype'] = '';
 318                  } else {
 319                      $errors['uutype'] = ' ';
 320                  }
 321                  $errors['uutype'] .= get_string('missingfield', 'error', 'lastname');
 322              }
 323  
 324              if (!in_array('email', $columns) and empty($data['email'])) {
 325                  $errors['email'] = get_string('requiredtemplate', 'admin');
 326              }
 327  
 328              if (!in_array('city', $columns) and empty($data['city'])) {
 329                  $errors['city'] = get_string('required');
 330              }
 331          }
 332  
 333          return $errors;
 334      }
 335  }
 336  ?>


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