Esempio n. 1
0
     $manual = NULL;
 }
 // clear bulk selection
 if ($bulk) {
     $SESSION->bulk_users = array();
 }
 // init csv import helper
 $cir->init();
 $linenum = 1;
 //column header is first line
 // init upload progress tracker
 $upt = new uu_progress_tracker();
 $upt->start();
 // start table
 while ($line = $cir->next()) {
     $upt->flush();
     $linenum++;
     $upt->track('line', $linenum);
     $user = new stdClass();
     // add fields to user object
     foreach ($line as $keynum => $value) {
         if (!isset($filecolumns[$keynum])) {
             // this should not happen
             continue;
         }
         $key = $filecolumns[$keynum];
         if (strpos($key, 'profile_field_') === 0) {
             //NOTE: bloody mega hack alert!!
             if (isset($USER->{$key}) and is_array($USER->{$key})) {
                 // this must be some hacky field that is abusing arrays to store content and format
                 $user->{$key} = array();
Esempio n. 2
0
function bulk_batch_enroll_existingstudents($cir, $data){
    
    
    global $CFG,$DB,$USER;
    require_once ($CFG->dirroot . '/group/lib.php');
    $returnurl = new moodle_url('/local/batches/bulk_enroll.php');
    $STD_FIELDS = array('userid', 'serviceid');

    $PRF_FIELDS = array();
   
    $result = '';
    
    $roleid = $data->roleassign;
    $useridfield = $data->firstcolumn;

    $enrollablecount = 0;
    $createdgroupscount = 0;
    $createdgroupingscount = 0;
    $createdgroups = '';
    $createdgroupings = '';
    
    $filecolumns = uu_validate_admission_upload_columns($cir, $STD_FIELDS, $PRF_FIELDS, $returnurl);
    $upt = new uu_progress_tracker();
    $plugin = enrol_get_plugin('manual');
    // init csv import helper
    $cir->init();

    $linenum = 1;
    loop:
    while ($line = $cir->next()) {
    $result=''; $existsmail=0;
    
    $upt->flush();
    $linenum++;
    $existuser = new stdClass();
    // add fields to admission object
    foreach ($line as $keynum => $value) {
        if (!isset($filecolumns[$keynum])) {
            // this should not happen
            continue;
        }
        $key = $filecolumns[$keynum];
	
        $existuser->$key = $value;
    }
     $existuser->linenum = $linenum;
        $batchid= $data->batchid;
        

	if(empty($batchid)){	    
	    echo '<div class="alert alert-error">'.get_string('batchempty', 'local_batches'). '</div>';
            continue;	
	}
	
	if(empty($existuser->serviceid)){
	     echo '<div class="alert alert-error">'.get_string('provideserviceid', 'local_batches'). '</div>';
            continue;	 
	    
	}
	
	if(empty($existuser->userid)){
	     echo '<div class="alert alert-error">'.get_string('provideuserid', 'local_batches'). '</div>';
            continue;	 	    
	}
        
	if($existuser->userid){
	    if(!$DB->record_exists('local_userdata',array('userid'=>$existuser->userid))){
	    echo '<div class="alert alert-error">'.get_string('provideuserid', 'local_batches'). '</div>';
            continue;
		
	    }
	    
	    
	}
	
	
            
        if($DB->record_exists('cohort_members',array('userid'=>$existuser->userid, 'cohortid'=>$batchid))) {
        echo '<div class="alert alert-error">'.get_string('im:already_in', 'local_mass_enroll', fullname($user)). '</div>';

        } else {
               cohort_add_member($batchid, $existuser->userid);
	}    
    
    }// end of while   
} // end of function