Ejemplo n.º 1
0
/**
 * 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;
}
Ejemplo n.º 2
0
}
// 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.
        facetoface_update_attendees($session);
    }
}
// Main page.
Ejemplo n.º 3
0
    $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 {
                print_error($error, 'facetoface');
            }
        }

       // set_notification($message, $returnurl, array('class' => 'notifysuccess'));
    }
    else {
Ejemplo n.º 4
0
/**
 * Mark users' booking requests as declined or approved
 *
 * @param array $data array containing the sessionid under the 's' key
 *                    and an array of request approval/denies
 */
function facetoface_approve_requests($data)
{
    global $USER, $DB;
    // Check request data.
    if (empty($data->requests) || !is_array($data->requests)) {
        error_log('F2F: No request data supplied');
        return false;
    }
    $sessionid = $data->s;
    // Load session.
    if (!($session = facetoface_get_session($sessionid))) {
        error_log('F2F: Could not load facetoface session');
        return false;
    }
    // Load facetoface.
    if (!($facetoface = $DB->get_record('facetoface', array('id' => $session->facetoface)))) {
        error_log('F2F: Could not load facetoface instance');
        return false;
    }
    // Load course.
    if (!($course = $DB->get_record('course', array('id' => $facetoface->course)))) {
        error_log('F2F: Could not load course');
        return false;
    }
    // Loop through requests.
    foreach ($data->requests as $key => $value) {
        // Check key/value.
        if (!is_numeric($key) || !is_numeric($value)) {
            continue;
        }
        // Load user submission.
        if (!($attendee = facetoface_get_attendee($sessionid, $key))) {
            error_log('F2F: User ' . $key . ' not an attendee of this session');
            continue;
        }
        // Update status.
        switch ($value) {
            // Decline.
            case 1:
                facetoface_update_signup_status($attendee->submissionid, MDL_F2F_STATUS_DECLINED, $USER->id);
                // Send a cancellation notice to the user.
                facetoface_send_cancellation_notice($facetoface, $session, $attendee->id);
                break;
                // Approve.
            // Approve.
            case 2:
                facetoface_update_signup_status($attendee->submissionid, MDL_F2F_STATUS_APPROVED, $USER->id);
                if (!($cm = get_coursemodule_from_instance('facetoface', $facetoface->id, $course->id))) {
                    print_error('error:incorrectcoursemodule', 'facetoface');
                }
                $contextmodule = context_module::instance($cm->id);
                // Check if there is capacity.
                if (facetoface_session_has_capacity($session, $contextmodule)) {
                    $status = MDL_F2F_STATUS_BOOKED;
                } else {
                    if ($session->allowoverbook) {
                        $status = MDL_F2F_STATUS_WAITLISTED;
                    }
                }
                // Signup user.
                if (!facetoface_user_signup($session, $facetoface, $course, $attendee->discountcode, $attendee->notificationtype, $status, $attendee->id)) {
                    continue;
                }
                break;
            case 0:
            default:
                // Change nothing.
                continue;
        }
    }
    return true;
}
Ejemplo n.º 5
0
    }

    // 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);

    $result_message = facetoface_generate_bulk_result_notice(array($added, $errors), 'addedit');
    $numattendees = facetoface_get_num_attendees($session->id);
    $overbooked = ($numattendees > $session->capacity);