function calendar_display_schedule_appointment_page

6.x calendar.module calendar_display_schedule_appointment_page($faculty_user_id)

This is the page which lets students schedule an appointment with the faculty member supplied in the user_id.

Notice this is USER_ID and not CWID! This is so that the cwid is kept secret, since it might be private information.

1 string reference to 'calendar_display_schedule_appointment_page'
calendar_menu in modules/calendar/calendar.module
implements hook_menu

File

modules/calendar/calendar.module, line 2260

Code

function calendar_display_schedule_appointment_page($faculty_user_id) {

  fp_add_css(fp_get_module_path('calendar') . '/css/style.css');

  $faculty_user = fp_load_user($faculty_user_id);

  if (!$faculty_user || $faculty_user->is_faculty != TRUE) {
    return "<p>" . t("We're sorry! The link you followed is either invalid, or the selected user ID is not listed as a faculty/staff member at your
            insititution.") . "</p>";
  }

  $rtn = "";

  $faculty_id = $faculty_user->cwid;
  $faculty_name = fp_get_faculty_name($faculty_id);

  fp_set_title(t("Schedule Appointment with @name", array("@name" => $faculty_name)));


  $image_url = @$faculty_user->settings ['image_url'];
  $image_html = "";
  if ($image_url) {
    $image_html .= "<span class='small-circle-profile-image'>
                  <img src='$image_url'> 
                </span>";
  }


  $stage = trim($_REQUEST ['stage']);


  if ($stage == '' || $stage == '1') {

    $event_types = content_get_content_for_faculty_id('schedule_event_type', $faculty_id);
    $rtn .= $image_html;
    $rtn .= "<p class='select-directions'>" . t("Begin by selecting which type of appointment you wish to schedule.") . "</p>
              
              <div class='select-from-event-types'>";

    foreach ($event_types as $cid => $content) {

      if ($content->field__enabled ['value'] != 'enabled') {
        continue;
      }

      $title = $content->title;
      $description = trim($content->field__description ['display_value']);

      $url = fp_url("schedule-appointment/$faculty_user_id", "stage=2&event_type_cid=$cid");

      $rtn .= "<a class='event-type' href='$url'>
                <div class='event-type-title'>$title <i class='fa fa-arrow-circle-right'></i></div>
                <div class='event-type-description'>$description</div>
              </a>";

    }

    $rtn .= '</div>';


    //$rtn .= "<br><br><div class='tzexplain'><i class='tzglobe fa fa-clock-o'></i> " . t("The time you select will be shown in your timezone of %tz.", array("%tz" => fp_get_user_timezone())) . "</div>";



  } // stage 1


  // Having selected the month, get a list of *unavailble* dates and times for this faculty member, for the selected month.
  if ($stage == '2') {


    $event_type_cid = intval($_REQUEST ['event_type_cid']);
    $content = content_load($event_type_cid);


    $month_year = trim(@$_REQUEST ['month_year']);
    if (!$month_year) {
      // Not set, so use today's month and year.
      $month = date('n');
      $year = date('Y');
      $month_year = $month . "_" . $year;
    }

    $temp = explode("_", $month_year);
    $month = intval($temp [0]);
    $year = intval($temp [1]);


    $url = fp_url("schedule-appointment/$faculty_user_id");
    $link_back = "<a href='$url' title='Back'><i class='fa fa-arrow-circle-left'></i></a>&nbsp; &nbsp;";


    $rtn .= "<h3>$link_back$faculty_name has time available on the following days:</h3>";

    $title = $content->title;
    $description = trim($content->field__description ['display_value']);

    $rtn .= "<div class='event-type-box'>
                <div class='event-type-title'>$title</div>
                <div class='event-type-description'>$description</div>
              </div>";



    // Get array of unavailable dates/times for the faculty user, for the selected month and year.
    $available_slots = calendar_get_available_faculty_schedule($faculty_id, $event_type_cid, $month, $year);

    // Draw a mini calendar, and make clickable any days which are at least partially available.    
    $rtn .= calendar_render_mini_calendar($month, $year, $faculty_user_id, $event_type_cid, $available_slots);


    $crumbs = array();
    $crumbs [] = array(
      'text' => t('Schedule Appointment with @name', array("@name" => $faculty_name)),
      'path' => "schedule-appointment/$faculty_user_id",
    );


    fp_set_breadcrumbs($crumbs);




  } // stage = 2


  // The user has selected a day, display the available times.
  if ($stage == '3') {

    $event_type_cid = intval($_REQUEST ['event_type_cid']);
    $content = content_load($event_type_cid);

    $month_year = trim(@$_REQUEST ['month_year']);
    if (!$month_year) {
      // Not set, so use today's month and year.
      $month = date('n');
      $year = date('Y');
      $month_year = $month . "_" . $year;
    }

    $temp = explode("_", $month_year);
    $month = intval($temp [0]);
    $year = intval($temp [1]);

    $day = intval($_REQUEST ['day']);

    $url = fp_url("schedule-appointment/$faculty_user_id", "stage=2&event_type_cid=$event_type_cid");
    $link_back = "<a href='$url' title='Back'><i class='fa fa-arrow-circle-left'></i></a>&nbsp; &nbsp;";

    $rtn .= "<h3>$link_back" . t("Select a time for") . " " . format_date(strtotime("$year-$month-$day"), '', 'l, F jS Y') . "</h3>";




    $title = $content->title;
    $description = trim($content->field__description ['display_value']);

    $rtn .= "<div class='event-type-box'>
                <div class='event-type-title'>$title</div>
                <div class='event-type-description'>$description</div>
              </div>";




    $rtn .= "<div class='event-select-time'>";
    $rtn .= "<div class='tzexplain'><i class='tzglobe fa fa-globe'></i> " . t("Times are shown in your timezone of <br>%tz", array("%tz" => friendly_timezone(fp_get_user_timezone()))) . "</div>";

    // Get array of unavailable dates/times for the faculty user, for the selected month and year.
    $available_slots = calendar_get_available_faculty_schedule($faculty_id, $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) {
      $rtn .= $details ['html'];
    }


    $rtn .= "</div>";


    $crumbs = array();
    $crumbs [] = array(
      'text' => t('Schedule Appointment with @name', array("@name" => $faculty_name)),
      'path' => "schedule-appointment/$faculty_user_id",
    );
    $crumbs [] = array(
      'text' => $content->title,
      'path' => "schedule-appointment/$faculty_user_id",
      'query' => "stage=2&event_type_cid=$content->cid",
    );


    fp_set_breadcrumbs($crumbs);



  } // stage 3




  return $rtn;

}