Example #1
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 webinar_approve_requests($data)
{
    global $USER, $DB;
    // Check request data
    if (empty($data->requests) || !is_array($data->requests)) {
        error_log('WEBINAR: No request data supplied');
        return false;
    }
    $sessionid = $data->s;
    // Load session
    if (!($session = webinar_get_session($sessionid))) {
        error_log('WEBINAR: Could not load webinar session');
        return false;
    }
    // Load webinar
    if (!($webinar = $DB->get_record('webinar', array('id' => $session->webinar)))) {
        error_log('WEBINAR: Could not load webinar instance');
        return false;
    }
    // Load course
    if (!($course = $DB->get_record('course', array('id' => $webinar->course)))) {
        error_log('WEBINAR: Could nto 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 = webinar_get_attendee($sessionid, $key))) {
            error_log('WEBINAR: User ' . $key . ' not an attendee of this session');
            continue;
        }
        // Update status
        switch ($value) {
            // Decline
            case 1:
                webinar_update_signup_status($attendee->submissionid, WEBINAR_STATUS_DECLINED, $USER->id);
                // Send a cancellation notice to the user
                webinar_send_cancellation_notice($webinar, $session, $attendee->id);
                break;
                // Approve
            // Approve
            case 2:
                webinar_update_signup_status($attendee->submissionid, WEBINAR_STATUS_APPROVED, $USER->id);
                // Check if there is capacity
                if (webinar_session_has_capacity($session)) {
                    $status = WEBINAR_STATUS_BOOKED;
                } else {
                    $status = WEBINAR_STATUS_WAITLISTED;
                }
                // Signup user
                if (!webinar_user_signup($session, $webinar, $course, $attendee->discountcode, $attendee->notificationtype, $status, $attendee->id)) {
                    continue;
                }
                break;
            case 0:
            default:
                // Change nothing
                continue;
        }
    }
    return true;
}
Example #2
0
             send_email_signup($webinar, $session, $cm, $user);
         }
     }
 } else {
     if ($remove and !empty($frm->removeselect) and confirm_sesskey()) {
         require_capability('mod/webinar:removeattendees', $context);
         foreach ($frm->removeselect as $removeuser) {
             if (!($removeuser = clean_param($removeuser, PARAM_INT))) {
                 continue;
                 // invalid userid
             }
             if (webinar_user_cancel($session, $removeuser, true, $cancelerr)) {
                 // Notify the user of the cancellation if the session hasn't started yet
                 $timenow = time();
                 if (!$suppressemail and !webinar_has_session_started($session, $timenow)) {
                     webinar_send_cancellation_notice($webinar, $session, $removeuser);
                 }
             } else {
                 $errors[] = $cancelerr;
                 $erruser = $DB->get_record('user', array('id' => $removeuser), 'id, firstname, lastname');
                 $errors[] = get_string('error:removeattendee', 'webinar', fullname($erruser));
             }
         }
         // Update attendees
         webinar_update_attendees($session);
         $user = $DB->get_record('user', array('id' => $removeuser));
         //Unregister this user from this webinar through Adobe Connect API call
         cancelsignup_meeting($webinar, $session, $user);
         //Send cancel registration email to user
         send_email_cancelsignup($webinar, $session, $cm, $user);
     } elseif ($showall) {