function system_display_dashboard_page

7.x system.module system_display_dashboard_page()
6.x system.module system_display_dashboard_page()

This is the "dashboard" page for FlightPath, which replaces the "main" page from FP 5.

File

modules/system/system.module, line 3806

Code

function system_display_dashboard_page() {
  global $user;
  $rtn = "";

  fp_set_title('');

  $render = array();
  $render ['#id'] = 'system_display_dashboard_page';


  // If we are not logged in, then we need to re-direct the user to 
  // the login page!
  if ($_SESSION ["fp_logged_in"] != TRUE) {
    $query = "";
    if (isset($_REQUEST ["logout"])) {
      $query = "logout=" . $_REQUEST ["logout"];
    }
    // Since we are not logged in, and are headed to the login page, also clear out any advising variables we might have.
    foreach ($_REQUEST as $key => $val) {
      unset($_REQUEST [$key]);
      unset($_GET [$key]);
      unset($_POST [$key]);
    }

    global $current_student_id;
    $current_student_id = ""; // clear this so the fp_goto doesn't try to add it.

    @session_destroy(); // In a rare occasion, the session hasn't had time to initialize yet, so this destroy triggers a warning.  The @ suppresses it.
    session_commit();
    fp_goto("login", $query);
    return;
  }

  fp_add_css(fp_get_module_path("system") . "/css/style.css");

  // It's a cheap hack, but when we don't have anything to show, the boxes get too small.  We're going to force some spaces
  // in that case, and we can tell it to display:none if we don't need it anymore in CSS.
  $force_spaces = "<span class='force-spaces'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
                      &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
                      &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
                      &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
                      &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
                      &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
                      </span>";


  //////////////////////////////////////////////////////////
  // To cut down on how long it takes to load huge groups
  // like Free Electives, we will the course inventory from cache here.
  if (@$_SESSION ["fp_cached_inventory_flag_one"] != TRUE) 
   {
    system_reload_and_cache_course_inventory();
  }


  $today = date("D, F jS, Y", convert_time(time()));
  $dname = $user->name;
  if ($user->f_name != "" || $user->l_name != "") {
    $dname = trim($user->f_name . " " . $user->l_name) . " ($user->name)";
  }



  $render ['inner_wrapper_start'] = array(
    'value' => "<div class='dashboard-inner-wrapper'>",
    'weight' => 10,
  );

  //$rtn .= "<div class='dashboard-inner-wrapper'>";  

  $render ["welcome_block"] = array('value' => "<div class='dash-welcome-block'>
                                <div class='welcome-section'>
                                  " . t("<h1>Welcome @dname!</h1>
                                  <h2>Today is @today</h2>", array("@dname" => $dname, "@today" => $today)) . "
                                </div>
                             </div>",
    'weight' => 20);

  /*
  $rtn .= "<div class='dash-welcome-block'>
              <div class='welcome-section'>
                <h1>Welcome $dname!</h1>
                <h2>Today is $today</h2>
              </div>
           </div>";
  */


  // Load announcements as HTML
  $announcements = "";

  $announcements .= "
               <div class='announcements-feed-block dash-feed-block'>
                  " . fp_render_section_title(t("Announcements")) . "
                 <div class='contents'>";


  $res = db_query("SELECT DISTINCT(a.cid) FROM content__announcement a, content n
                   WHERE a.vid = n.vid
                   AND a.cid = n.cid
                   AND n.delete_flag = 0
                   AND n.published = 1                                    
                   ORDER BY field__activity_datetime DESC, a.vid DESC
                   LIMIT 7");
  $bool_is_empty = TRUE;
  while ($cur = db_fetch_object($res)) {
    $cid = $cur->cid;
    $content = content_load($cid);

    // is this "faculty" visibility?  If so, do we have access to view?
    if ($content->field__visibility ['value'] == 'faculty' && !user_has_permission('can_view_faculty_engagements')) {
      continue;
    }


    $disp_date = date("m/d/Y g:ia", convert_time(strtotime($content->field__activity_datetime ['value'])));
    $bool_is_empty = FALSE;
    $announcements .= "<div class='feed-item'>
                <div class='feed-item-title'>$content->title</div>
                <div class='feed-item-desc'>{$content->field__msg ['display_value']}</div>
                <div class='feed-item-datetime'>$disp_date</div>
             </div>";

  } // while

  if ($bool_is_empty) {
    $announcements .= "<div class='empty'>                
                <p>" . t("Sorry, there are no announcements available at this time.") . "</p>                
             </div>";
  }



  $announcements .= "$force_spaces</div>  <!-- contents -->
               </div> <!-- feed block --> ";



  // Build up the "appoinments" HTML
  $appointments = "";
  $appointments .= "<div class='appointments-feed-block dash-feed-block'>
                    " . fp_render_section_title(t("Upcoming Appointments")) . "
                   <div class='contents'>";

  $upcoming = calendar_get_upcoming_appointments_for_cwid($user->cwid);
  $bool_is_empty = TRUE;
  foreach ($upcoming as $details) {

    $thedate = format_date(convert_time($details ['utc_start_ts']), 'long_no_year');
    $use_name = $details ['faculty_name'];
    if ($user->is_faculty) {
      $use_name = $details ['student_name'];
    }

    $bool_is_empty = FALSE;

    $msg = t("You have an appointment with @fn on @td.", array("@fn" => $use_name, "@td" => $thedate));


    $appointments .= "<div class='feed-item'>
                      <div class='feed-item-icon'><i class='fa fa-calendar'></i></div>
                      <div class='feed-item-title'>$use_name</div>
                      <div class='feed-item-desc'>$msg</div>
               </div>";

  }


  if ($bool_is_empty) {
    $appointments .= "<div class='empty'>
                      <p>" . t("You have no upcoming appointments within the next 5 days.") . "</p> 
               </div>
               $force_spaces";

  }




  $appointments .= "
                   </div> <!-- contents -->
                 </div> <!-- feed-block -->                                                
                ";




  $render ['#user_is_faculty'] = $user->is_faculty;

  if ($user->is_faculty) {


    $render ['dash_left_wrapper'] = array('value' => "<div class='dash-box dash-left'>", 'weight' => 30);

    //$rtn .= "<div class='dash-box dash-left'>";
    $render ["appointments"] = array('value' => $appointments, 'weight' => 40);
    //$rtn .= $appointments;

    if (user_has_permission('can_view_advisee_activity_records')) {

      $render ["activity_feed_block_top"] = array('value' => "<div class='activity-feed-block dash-feed-block'>
                                                " . fp_render_section_title("Advisee Activity Feed") . "
                                             <div class='contents'>",
        'weight' => 50);
      /*          
        $rtn .= "<div class='activity-feed-block dash-feed-block'>
                    " . fp_render_section_title("Advisee Activity Feed") . "
                 <div class='contents'>";
    */


      $activity = "";

      // Needs to only be within my advisees list....
      $adv_array = student_search_display_my_advisees(TRUE);
      $student_ids = array_keys($adv_array);
      $students_line = "'" . join("','", $student_ids) . "'";

      $icons = array(
        'alert' => 'fa-bell-o',
        'mail' => 'fa-envelope-o',
        'comment' => 'fa-comment-o',
        'calendar' => 'fa-calendar-o',
      );

      $res = db_query("SELECT DISTINCT(a.cid) FROM content__activity_record a, content n
                         WHERE a.vid = n.vid
                         AND a.cid = n.cid
                         AND n.delete_flag = 0
                         AND n.published = 1
                         AND field__student_id IN ($students_line)                                    
                         ORDER BY updated DESC, a.vid DESC
                         LIMIT 10");
      $bool_is_empty = TRUE;
      while ($cur = db_fetch_object($res)) {
        $cid = $cur->cid;
        $content = content_load($cid);

        $student_name = fp_get_student_name($content->field__student_id ['value'], TRUE);

        $disp_date = date("m/d/Y g:ia", convert_time($content->updated));

        $icon = $icons [$content->field__activity_type ['value']];
        $bool_is_empty = FALSE;
        $activity .= "<div class='feed-item'>
                      <div class='feed-item-icon'><i class='fa $icon'></i></div>
                      <div class='feed-item-title'>$student_name</div>
                      <div class='feed-item-desc'>$content->title</div>
                      <div class='feed-item-datetime'>$disp_date</div>
                   </div>";

      } // while

      if (!$bool_is_empty) {
        $activity .= "<div class='activity-view-all'>" . l(t("View All"), "advisee-activities", '', array('class' => 'button')) . "</div>";
      }
      else {
        $activity .= "<div class='empty'>
                        <p>" . t("There is no student activity to report at this time.") . "</p> 
                 </div>$force_spaces";
      }


      $render ['close_activity_feed_block'] = array('value' => "$activity</div>", 'weight' => 60);


      $render ['close_activities_feed_block'] = array('value' => "</div> <!-- feed-block -->          ", 'weight' => 70);
      $render ['close_left_dash_wrapper'] = array('value' => "</div> <!-- dash-box -->  ", 'weight' => 80);

    } // if user has permission can_view_advisee_activity_records




    $render ['dash_right_wrapper'] = array('value' => "<div class='dash-box dash-right'>", 'weight' => 90);
    //$rtn .= "<div class='dash-box dash-right'>";



    $advising_term_id = variable_get("advising_term_id", "");
    $advising_term_desc = get_term_description($advising_term_id, FALSE, $user->school_id);

    $url = fp_url("render-advising-snapshot-for-iframe", "window_mode=popup&fp_messages=none");

    // Show slightly different if we have the schools module enabled
    if (module_enabled("schools")) {
      $advising_term_desc = "Current Terms";

      // Get all the school ids this user is allowed to search.
      $school_ids = student_search_get_school_ids_user_is_allowed_to_search();
      $school_id_list = join(",", $school_ids);

      $url = fp_url("render-advising-snapshot-for-iframe", "window_mode=popup&fp_messages=none&school_id_list=$school_id_list");

    }

    $render ['advising_snapshot'] = array('value' => "<div class='snapshot-feed-block dash-feed-block'>
                                      " . fp_render_section_title(t("Advising Snapshot for ") . $advising_term_desc) . "
                                     <div class='contents'>
                                      <iframe src='$url' frameborder=0 width=100% height=85></iframe>
                                     </div>
                                   </div>",
      'weight' => 100);



    /// Do announcements under.

    $render ['announcements'] = array('value' => $announcements, 'weight' => 110);
    $render ['close_right_dash_wrapper'] = array('value' => "</div>", 'weight' => 120);

  } // if is_faculty
  else if ($user->is_student) {


    $render ['dash_left_wrapper'] = array('value' => "<div class='dash-box dash-left'>", 'weight' => 30);
    $render ["appointments"] = array('value' => $appointments, 'weight' => 40);


    //$rtn .= "<div class='dash-box dash-left'>";
    //$rtn .= $appointments;

    fp_add_js(fp_get_module_path('advise') . '/js/advise.js');
    $render ['recent_advising_history_top'] = array('value' => "<div class='advising-history-feed-block dash-feed-block'>
                                            " . fp_render_section_title(t("Recent Advising History")) . "
                                           <div class='contents'>", 'weight' => 50);


    // TODO: For the student advisings, we want to group together terms that were advised at the same time.



    $res = db_query("SELECT * FROM advising_sessions
                WHERE student_id = ?
                AND is_draft = 0
                AND is_empty = 0
                AND delete_flag = 0
                ORDER BY `posted` DESC, `term_id` DESC 
                LIMIT 5", $user->cwid);
    $c = 0;
    while ($cur = db_fetch_array($res)) {

      $dt = date("n/j/y g:ia", $cur ['posted']);
      $fac_name = fp_get_faculty_name($cur ['faculty_id'], FALSE);
      $html = "";

      $turl = fp_url("advise/popup-display-summary", "advising_session_id=" . $cur ['advising_session_id']);
      $advising_session_id_array [] = $cur ['advising_session_id'];
      $term = get_term_description($cur ['term_id'], FALSE, $user->student_id);
      $link = "popupLargeIframeDialog(\"" . $turl . "\",\"" . t("Advising Session @term - @date", array("@term" => $term, "@date" => $dt)) . "\",\"\");";
      $html .= "<div class='feed-item'>
                  <div class='feed-item-icon'><i class='fa fa-graduation-cap'></i></div>
                  <div class='feed-item-title'>Advised by $fac_name</div>
                  <a href='javascript:$link'>
                    <div class='feed-item-desc'>$term</div>                    
                  </a>                  
                  <div class='feed-item-datetime'>$dt</div>
                </div>";


      $render ['recent_advising_history_row_' . $cur ['advising_session_id']] = array('value' => $html, 'weight' => (200 + $c++));
    }



    $render ['close_advising_history_contents'] = array('value' => "</div> <!-- contents -->", 'weight' => 300);
    $render ['close_advising_sessions_feed_block'] = array('value' => "</div> <!-- feed-block -->          ", 'weight' => 310);
    $render ['close_left_dash_wrapper'] = array('value' => "</div> <!-- dash-box -->  ", 'weight' => 320);



    $render ['dash_box_right_wrapper'] = array('value' => "<div class='dash-box dash-right'>", 'weight' => 330);
    $render ['announcements'] = array('value' => $announcements, 'weight' => 340);
    $render ['close_right_dash_box'] = array('value' => "</div>", 'weight' => 350);


  } // if is_student

  watchdog("display_dashboard", "", array());


  $rtn = fp_render_content($render);

  return $rtn;
}