} $potentialuserselector->invalidate_selected_users(); $existinguserselector->invalidate_selected_users(); } } // Process removing user assignments from session. if (optional_param('remove', false, PARAM_BOOL) && confirm_sesskey()) { require_capability('mod/facetoface:removeattendees', $context); $userstoremove = $existinguserselector->get_selected_users(); if (!empty($userstoremove)) { foreach ($userstoremove as $removeuser) { if (!($removeuser = clean_param($removeuser->id, PARAM_INT))) { continue; // Invalid userid. } if (facetoface_user_cancel($session, $removeuser, true, $cancelerr)) { // Notify the user of the cancellation if the session hasn't started yet. $timenow = time(); if (!$suppressemail and !facetoface_has_session_started($session, $timenow)) { facetoface_send_cancellation_notice($facetoface, $session, $removeuser); } } else { $errors[] = $cancelerr; $usernamefields = get_all_user_name_fields(true); $erruser = $DB->get_record('user', array('id' => $removeuser), "id, {$usernamefields}"); $errors[] = get_string('error:removeattendee', 'facetoface', fullname($erruser)); } } $potentialuserselector->invalidate_selected_users(); $existinguserselector->invalidate_selected_users(); // Update attendees.
/** * Kohl's KW - WP06A - Google calendar integration * * If the unassigned user belongs to a course with an upcoming * face-to-face session and they are signed-up to attend, cancel * the sign-up (and trigger notification). */ function facetoface_eventhandler_role_unassigned_bulk($event) { global $CFG, $USER, $DB; $now = time(); $tmptable = $event['tmptable']; $hascontextid = $event['hascontextid']; $hasuserid = $event['hasuserid']; $hasroleid = $event['hasroleid']; $enrol = $event['enrol']; // Nothing to do if there are no contexts or userids if (!$hascontextid || !$hasuserid) { return true; } $sql = "SELECT DISTINCT cx.id, cx.* from {context} cx inner join {{$tmptable}} t on cx.id=t.contextid where cx.contextlevel="; $ctxlist = $DB->get_records_sql($sql, array(CONTEXT_COURSE)); if (!$ctxlist) { return true; } foreach ($ctxlist as $ctx) { // get all face-to-face activites in the course $activities = $DB->get_records('facetoface', array('course' => $ctx->instanceid)); if ($activities) { foreach ($activities as $facetoface) { // get all upcoming sessions for each face-to-face $sql = "SELECT s.id, s.facetoface, s.datetimeknown, s.capacity, s.duration, d.timestart, d.timefinish FROM {facetoface_sessions} s JOIN {facetoface_sessions_dates} d ON s.id = d.sessionid WHERE s.facetoface = ? AND d.sessionid = s.id AND (s.datetimeknown = 0 OR d.timestart > ?) ORDER BY s.datetimeknown, d.timestart "; if ($sessions = get_records_sql($sql, array($facetoface->id, $now))) { $cancelreason = "Unenrolled from course"; foreach ($sessions as $session) { $session = facetoface_get_session($session->id); // load dates etc. // remove trainer session assignments for user (if any exist) if ($trainers = facetoface_get_trainers($session->id)) { foreach ($trainers as $role_id => $users) { foreach ($users as $user_id => $trainer) { if ( record_exists($t, 'userid', $trainer->id, 'contextid', $ctx->id) ) { $form = $trainers; unset($form[$role_id][$user_id]); // remove trainer facetoface_update_trainers($session->id, $form); break; } } } } $signups = $DB->get_records_sql("SELECT DISTINCT t.userid FROM {{$tmptable}} t INNER JOIN {facetoface_signups} fs ON t.userid=fs.userid WHERE fs.sessionid=?", array($session->id)); if (!$signups) { $signups = array(); } foreach ($signups as $signup) { // cancel learner signup for user (if any exist) $errorstr = ''; if (facetoface_user_cancel($session, $signup->userid, true, $errorstr, $cancelreason)) { facetoface_send_cancellation_notice($facetoface, $session, $signup->userid); } } } } } } } return true; }
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; }
/** * Delete entry from the facetoface_sessions table along with all * related details in other tables * * @param object $session Record from facetoface_sessions */ function facetoface_delete_session($session) { global $CFG, $DB; $facetoface = $DB->get_record('facetoface', array('id' => $session->facetoface)); // Cancel user signups (and notify users). $signedupusers = $DB->get_records_sql("\n SELECT DISTINCT\n userid\n FROM\n {facetoface_signups} s\n LEFT JOIN\n {facetoface_signups_status} ss\n ON ss.signupid = s.id\n WHERE\n s.sessionid = ?\n AND ss.superceded = 0\n AND ss.statuscode >= ?\n ", array($session->id, MDL_F2F_STATUS_REQUESTED)); if ($signedupusers and count($signedupusers) > 0) { foreach ($signedupusers as $user) { if (facetoface_user_cancel($session, $user->userid, true)) { facetoface_send_cancellation_notice($facetoface, $session, $user->userid); } else { return false; // Cannot rollback since we notified users already. } } } $transaction = $DB->start_delegated_transaction(); // Remove entries from the teacher calendars. $DB->delete_records_select('event', "modulename = 'facetoface' AND\n eventtype = 'facetofacesession' AND\n instance = ? AND description LIKE ?", array($facetoface->id, "%attendees.php?s={$session->id}%")); if ($facetoface->showoncalendar == F2F_CAL_COURSE) { // Remove entry from course calendar. facetoface_remove_session_from_calendar($session, $facetoface->course); } else { if ($facetoface->showoncalendar == F2F_CAL_SITE) { // Remove entry from site-wide calendar. facetoface_remove_session_from_calendar($session, SITEID); } } // Delete session details. $DB->delete_records('facetoface_sessions', array('id' => $session->id)); $DB->delete_records('facetoface_sessions_dates', array('sessionid' => $session->id)); $DB->delete_records_select('facetoface_signups_status', "signupid IN\n (\n SELECT\n id\n FROM\n {facetoface_signups}\n WHERE\n sessionid = {$session->id}\n )\n "); $DB->delete_records('facetoface_signups', array('sessionid' => $session->id)); $transaction->allow_commit(); return true; }
if ($fromform = $mform->get_data()) { // Form submitted if (empty($fromform->submitbutton)) { print_error('error:unknownbuttonclicked', 'facetoface', $returnurl); } $forcecancel = false; $timenow = time(); $bookedsession = facetoface_get_user_submissions($facetoface->id, $USER->id, MDL_F2F_STATUS_WAITLISTED, MDL_F2F_STATUS_WAITLISTED, $session->id); if (!empty($bookedsession) && facetoface_has_session_started($session, $timenow)) { $forcecancel = true; } $errorstr = ''; if (facetoface_user_cancel($session, false, $forcecancel, $errorstr, $fromform->cancelreason)) { add_to_log($course->id, 'facetoface', 'cancel booking', "cancelsignup.php?s=$session->id", $facetoface->id, $cm->id); $message = get_string('bookingcancelled', 'facetoface'); if ($session->datetimeknown) { print_object($factoface); $error = facetoface_send_cancellation_notice($facetoface, $session, $USER->id); if (empty($error)) { if ($session->datetimeknown && isset($facetoface->cancellationinstrmngr) && !empty($facetoface->cancellationstrmngr)) { $message .= html_writer::empty_tag('br') . html_writer::empty_tag('br') . get_string('cancellationsentmgr', 'facetoface'); } else { $message .= html_writer::empty_tag('br') . html_writer::empty_tag('br') . get_string('cancellationsent', 'facetoface'); } } else {
$result['result'] = get_string('addedsuccessfully', 'facetoface'); $added[] = $result; } } } // Removing old attendees. // Check if we need to remove anyone. $attendeestoremove = array_diff_key($original, $attendees); if (!empty($attendeestoremove) && has_capability('mod/facetoface:removeattendees', $context)) { foreach ($attendeestoremove as $attendee) { $result = array(); $result['id'] = $attendee->id; $result['name'] = fullname($attendee); if (facetoface_user_cancel($session, $attendee->id, true, $cancelerr)) { // Notify the user of the cancellation if the session hasn't started yet $timenow = time(); if (!$suppressemail and !facetoface_has_session_started($session, $timenow)) { facetoface_send_cancellation_notice($facetoface, $session, $attendee->id); } $result['result'] = get_string('removedsuccessfully', 'facetoface'); $added[] = $result; } else { $result['result'] = $cancelerr; $errors[] = $result; } } } $_SESSION['f2f-bulk-results'][$session->id] = array($added, $errors);
$yesurl=new moodle_url('/mod/facetoface/confirm_session_cancel.php',array('id'=>$confirm)); $nourl=new moodle_url('/mod/facetoface/view_sessions.php'); echo $OUTPUT->confirm($message, $yesurl, $nourl); }elseif($confirm>0){ $assigned_session=$DB->get_record_sql("SELECT * FROM {facetoface_sessions} WHERE id=$confirm"); //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");