function calendar_schedule_appointment_confirm_form_validate
Search API
7.x calendar.module | calendar_schedule_appointment_confirm_form_validate($form, &$form_state) |
6.x calendar.module | calendar_schedule_appointment_confirm_form_validate($form, &$form_state) |
This is our last chance to validate the form before saving.
- Make sure the CWID goes to a real student
- Make sure the time slot is still available! It might have gotten booked while we've been doing this.
File
- modules/
calendar/ calendar.module, line 1958
Code
function calendar_schedule_appointment_confirm_form_validate($form, &$form_state) {
$faculty_user_id = intval($form_state ['values']['faculty_user_id']);
$faculty_user = fp_load_user($faculty_user_id);
$faculty_cwid = $faculty_user->cwid;
$faculty_name = $faculty_user->f_name . " " . $faculty_user->l_name;
$schedule_date = $form_state ['values']['schedule_date'];
$schedule_begin_hm = $form_state ['values']['schedule_begin_hm'];
$schedule_time_ts = strtotime($schedule_date . " " . $schedule_begin_hm);
$utc_schedule_time_ts = $form_state ['values']['utc_schedule_time_ts'];
$month = date('n', $schedule_time_ts);
$year = date('Y', $schedule_time_ts);
$day = date('j', $schedule_time_ts);
$event_type_cid = intval($form_state ['values']['event_type_cid']);
$event_type_content = content_load($event_type_cid);
$event_duration_minutes = intval($event_type_content->field__event_duration_minutes ['value']);
// Confirm that the faculty_cwid matches this event type's faculty member.
if ($faculty_cwid != $event_type_content->field__faculty_id ['value']) {
form_error('', t("Sorry, but there was an issue attempting to save this appointment. Please try again."));
return;
}
$db = get_global_database_handler();
$student_name = trim($form_state ['values']['name']);
$student_cwid = trim($form_state ['values']['cwid']);
// Make sure this cwid actually exists.
$x = $db->get_student_name($student_cwid);
if (!$x) {
$x = $db->get_faculty_name($student_cwid);
if (!$x) {
form_error('cwid', t("Sorry, but the CWID entered does not match any records. Please make sure you typed it correctly and try again."));
return;
}
}
$student_email = trim($form_state ['values']['email']);
$student_phone = trim($form_state ['values']['phone']);
$student_comments = trim($form_state ['values']['comments']);
$bool_found_it = FALSE;
$available_slots = calendar_get_available_faculty_schedule($faculty_cwid, $event_type_cid, $month, $year);
$avail_times = calendar_get_available_times_on_date($available_slots, $faculty_user_id, $year, $month, $day, $event_type_cid);
foreach ($avail_times as $disp_hm => $details) {
if ($disp_hm == $schedule_begin_hm) {
$bool_found_it = TRUE;
break;
}
}
// make sure this event time is still available!
// NOTE: Comment out for dev, but remove comments for production! Otherwise users can hit "back" and save again to enter more than one meeting at the same time.
$available_slots = calendar_get_available_faculty_schedule($faculty_cwid, $event_type_cid, $month, $year);
if (!isset($available_slots [$year][$month][$day][$schedule_time_ts])) {
form_error('', t("Sorry, but the time you selected for your appointment is no longer available. Please select a new time."));
return;
}
if (!$bool_found_it) {
form_error('', t("Sorry, but the time you selected for your appointment is no longer available. Please select a new time."));
return;
}
////////////////////////////////////
// We have made it this far with no errors. If this is a video meeting, let's attempt to create that meeting.
// If this is a Zoom meeting, then attempt to create the zoom meeting and save it in form_state['values']['field__video_data'] so it
// gets saved with the content.
if (module_enabled("zoomapi") && @$event_type_content->field__video_meeting ['value'] == 'zoom') {
//gmt_date_time must look like yyyy-MM-ddTHH:mm:ssZ. For example: 2020-03-31T22:02:00Z. The Z tells it that we are using GMT/UTC time.
$gmt_date_time = date("Y-m-d\TH:i:s\Z", $utc_schedule_time_ts);
$response = zoomapi_create_zoom_meeting($faculty_user_id, $gmt_date_time, $event_duration_minutes, "Video meeting - $faculty_name / $student_name");
if (!$response) {
form_error("", t("Sorry, but there was an issue creating the Zoom meeting for this appointment. Your appointment has not been saved.
Please try another method, or contact the IT administrator to let them know of this issue."));
return;
}
$form_state ['values']['video_data'] = $response;
$form_state ['values']['video_type'] = "zoom";
$form_state ['values']['video_account_owner_user_id'] = $faculty_user_id;
}
//form_error("title", 'hey');
//return;
// Okay, if we made it here, then we are good to proceed and save!
}