function cancelbatch($id){ global $DB; $batchid=$id; $newbatch=new stdClass(); $newbatch->id=$id; $newbatch->active=2; //updating the sbatch status $DB->update_record('facetoface', $newbatch); //used for unenrolling the users from course $batch_courses=$DB->record_exists_sql("SELECT * FROM {local_batch_courses} WHERE batchid=$id AND courseid!=0"); $assigned_course=$DB->get_record_sql("SELECT * FROM {local_batch_courses} WHERE batchid=$id AND courseid!=0"); $email_log=simple_template_for_batches($id,1); if($email_log){ if($batch_courses==1){ $batch_users=$DB->record_exists_sql("SELECT * FROM {local_batch_users} WHERE f2fid=$id"); if($batch_users==1){ $assigned_users=$DB->get_records_sql("SELECT * FROM {local_batch_users} WHERE f2fid=$id"); foreach($assigned_users as $assigned_user){ $manual = enrol_get_plugin('manual'); $studentrole = $DB->get_record('role', array('shortname'=>'student')); $instance = $DB->get_record('enrol', array('courseid'=>$assigned_course->courseid, 'enrol'=>'manual'), '*', MUST_EXIST); if($instance){ $timeend=''; if(!$DB->record_exists_sql("SELECT * FROM {course_completions} WHERE course=$assigned_course->courseid AND userid=$assigned_user->userid and timecompleted!=''")){ $local_batch_courses=$DB->get_records_sql("SELECT lbu.* FROM {local_batch_users} lbu JOIN {facetoface} fa ON fa.id=lbu.f2fid and fa.active in (0,1,8,3) where lbu.courseid=$assigned_course->courseid and lbu.userid=$assigned_user->userid and fa.id!=$id"); if(count($local_batch_courses)==0){ $manual->unenrol_user($instance,$assigned_user->userid, $studentrole->id,time(),$timeend); } } //$manual->unenrol_user($instance,$assigned_user->userid, $studentrole->id,time(),$timeend); } if($assigned_course->groupid!=0) groups_remove_member($assigned_course->groupid, $assigned_user->userid); } } $assigned_sessions=$DB->get_records_sql("SELECT * FROM {facetoface_sessions} WHERE facetoface=$id"); if($assigned_sessions){ foreach($assigned_sessions as $assigned_session){ $facetoface = $DB->get_record('facetoface', array('id' =>$id)); $signedupusers = $DB->get_records_sql("SELECT * FROM {local_batch_users} WHERE f2fid= $id"); if ($signedupusers and count($signedupusers) > 0) { foreach ($signedupusers as $user) { if (facetoface_user_cancel($assigned_session, $user->userid, true)) { //facetoface_send_cancellation_notice($facetoface, $assigned_session, $user->userid); } else { return false; // Cannot rollback since we notified users already } } } if($facetoface->actualsessions){ $actual_sessions=$facetoface->actualsessions-1; $DB->execute('update {facetoface} SET actualsessions='.$actual_sessions.' WHERE id='.$id.''); } } } } return $email_log; } // unenrolling the users from course ends //==========================Rajut // Cancel user signups (and notify users)==========================// $facetoface = $DB->get_record('facetoface', array('id' =>$id)); $assigned_sessions=$DB->get_records_sql("SELECT * FROM {facetoface_sessions} WHERE facetoface=$id"); //print_object($assigned_sessions); foreach($assigned_sessions as $assigned_session){ // Cancel user signups (and notify users) $signedupusers = $DB->get_records_sql("SELECT * FROM {local_batch_users} WHERE f2fid=$id"); if ($signedupusers and count($signedupusers) > 0) { foreach ($signedupusers as $user) { if (facetoface_user_cancel($assigned_session, $user->userid, true)) { //facetoface_send_cancellation_notice($facetoface, $assigned_session, $user->userid); } else { return false; // Cannot rollback since we notified users already } } } } //return $id; }
//print_object($assigned_session);exit; $facetoface = $DB->get_record('facetoface', array('id' => $assigned_session->facetoface)); //print_object($facetoface);exit; // Cancel user signups (and notify users) $signedupusers = $DB->get_records_sql("SELECT * FROM {local_batch_users} WHERE f2fid= $assigned_session->facetoface"); if ($signedupusers and count($signedupusers) > 0) { foreach ($signedupusers as $user) { if (facetoface_user_cancel($assigned_session, $user->userid, true)) { //facetoface_send_cancellation_notice($facetoface, $assigned_session, $user->userid); } else { return false; // Cannot rollback since we notified users already } } $email_log=simple_template_for_batches($assigned_session->facetoface,2); } if($facetoface->actualsessions){ $actual_sessions=$facetoface->actualsessions-1; $DB->execute('update {facetoface} SET actualsessions='.$actual_sessions.' WHERE id='.$assigned_session->facetoface.''); } //$batch_id=$assigned_session->facetoface; //getting session cancel count //$batch_cancel_sessions_count=$DB->get_record_sql("SELECT count(id) as countid FROM `mdl_facetoface_signups_status` where signupid in (select id from `mdl_facetoface_signups` where `f2fid`=$batch_id) and `statuscode` = 10"); //print_object($batch_cancel_sessions_count); exit; //$cancel_sessions_count=$DB->get_record_sql("SELECT count(id) as countid FROM mdl_facetoface_signups_status WHERE `id`=$sessionid and =0"); //getting session attendence not takens //$total_abcent_count=$DB->get_record_sql("SELECT count(id) as countid FROM `mdl_facetoface_signups` where sessionid in (select id from `mdl_facetoface_sessions` where `facetoface`=$batch_id) and (status=0 OR status=2)"); //if cancelled and not taken count is equal