예제 #1
0
                print_error('csvemptyfile', 'error', $returnurl);
            }
        }
        // test if columns ok
        $filecolumns = uu_validate_user_upload_columns($cir, $STD_FIELDS, $PRF_FIELDS, $returnurl);
        // continue to form2
    } else {
        echo $OUTPUT->header();
        echo $OUTPUT->heading_with_help(get_string('uploadusers', 'admin'), 'uploadusers', 'admin');
        $mform1->display();
        echo $OUTPUT->footer();
        die;
    }
} else {
    $cir = new csv_import_reader($iid, 'uploaduser');
    $filecolumns = uu_validate_user_upload_columns($cir, $STD_FIELDS, $PRF_FIELDS, $returnurl);
}
$mform2 = new admin_uploaduser_form2(null, array('columns' => $filecolumns, 'data' => array('iid' => $iid, 'previewrows' => $previewrows)));
// If a file has been uploaded, then process it
if ($formdata = $mform2->is_cancelled()) {
    $cir->cleanup(true);
    redirect($returnurl);
} else {
    if ($formdata = $mform2->get_data()) {
        // Print the header
        echo $OUTPUT->header();
        echo $OUTPUT->heading(get_string('uploadusersresult', 'admin'));
        $optype = $formdata->uutype;
        $updatetype = isset($formdata->uuupdatetype) ? $formdata->uuupdatetype : 0;
        $createpasswords = (!empty($formdata->uupasswordnew) and $optype != UU_USER_UPDATE);
        $updatepasswords = (!empty($formdata->uupasswordold) and $optype != UU_USER_ADDNEW and $optype != UU_USER_ADDINC and ($updatetype == UU_UPDATE_FILEOVERRIDE or $updatetype == UU_UPDATE_ALLOVERRIDE));
 /**
  * Constructor
  *
  * @param csv_import_reader $cir import reader object
  * @param array $options options of the process
  */
 public function __construct(csv_import_reader $cir, array $options)
 {
     global $DB, $UUC_STD_FIELDS, $UUC_PRF_FIELDS;
     // Extra sanity checks
     if (!isset($options['mode']) || !in_array($options['mode'], array(self::MODE_CREATE_NEW, self::MODE_CREATE_ALL, self::MODE_CREATE_OR_UPDATE, self::MODE_UPDATE_ONLY))) {
         throw new coding_exception('Unknown process mode');
     }
     // Force int to make sure === comparison work as expected.
     $this->mode = (int) $options['mode'];
     // Default update mode
     $this->updatemode = self::UPDATE_NOTHING;
     if (isset($options['updatemode'])) {
         $this->updatemode = (int) $options['updatemode'];
     }
     if (isset($options['allowrenames'])) {
         $this->allowrenames = $options['allowrenames'];
     }
     if (isset($options['allowdeletes'])) {
         $this->allowdeletes = $options['allowdeletes'];
     }
     if (isset($options['standardise'])) {
         $this->standardise = $options['standardise'];
     }
     if (isset($options['updatepassword'])) {
         $this->updatepassword = $options['updatepassword'];
     }
     if (isset($options['passwordmode'])) {
         $this->passwordmode = $options['passwordmode'];
     }
     if (isset($options['allowsuspends'])) {
         $this->allowsuspends = $options['allowsuspends'];
     }
     if (isset($options['noemailduplicates'])) {
         $this->noemailduplicates = $options['noemailduplicates'];
     }
     $this->forcepasswordchange = self::FORCE_PASSWORD_CHANGE_WEAK;
     if (isset($options['forcepasswordchange'])) {
         $this->forcepasswordchange = $options['forcepasswordchange'];
     }
     $this->cir = $cir;
     $phonyurl = new moodle_url('/admin/tool/uploaduser/index.php');
     $this->columns = uu_validate_user_upload_columns($this->cir, $UUC_STD_FIELDS, $UUC_PRF_FIELDS, $phonyurl);
     $this->reset();
 }