function advise_display_history

6.x advise.history.inc advise_display_history()
4.x advise.history.inc advise_display_history()
5.x advise.history.inc advise_display_history()

Displays the history tab on screen.

File

modules/advise/advise.history.inc, line 11

Code

function advise_display_history() {
  global $current_student_id, $user;

  $student_id = $current_student_id;
  $db = get_global_database_handler();
  $school_id = db_get_school_id_for_student_id($student_id);
  fp_set_title('');

  $extra_style = $ast = "";
  $rtn = "";

  fp_add_css(fp_get_module_path("advise") . "/css/advise.css");
  fp_add_js(fp_get_module_path("advise") . "/js/advise.js");


  $rtn .= "<table class='fp-semester-table'>";


  // If coming here from a save, display info here.
  if (@$_REQUEST ["adv_id_array_serialized"] != "") {
    $acount = 0;
    $click_links = "";
    $advising_session_id_array = unserialize($_REQUEST ["adv_id_array_serialized"]);

    foreach ($advising_session_id_array as $term_id => $value) {
      $term_id = (string) $term_id; // Make sure term_id is a standard string
      $aid = $advising_session_id_array [$term_id];
      if ($aid != "") 
       {
        $term_name = get_term_description($term_id, FALSE, $school_id);

        $turl = fp_url("advise/popup-display-summary", "advising_session_id=$aid");

        $click_links .= "<li class='just-saved-summary'>
                            <a href='javascript: popupLargeIframeDialog(\"" . $turl . "\",\"" . t("Advising Session @term", array("@term" => $term_name)) . "\",\"\");'>
                                <i class='fa fa-window-restore'></i> $term_name
                            </a>
                         </li>";

        $acount++;

      }
    }
    $group_link = "";
    if ($acount > 1) {
      $turl = fp_url("advise/popup-display-summary", "show_as_group=yes&advising_session_id=" . join(",", $advising_session_id_array));
      $on_click = "popupLargeIframeDialog(\"" . $turl . "\",\"" . t("Advising Sessions") . "\",\"\");";
      $group_link = "<a href='javascript:$on_click' class='advising-summary-group-link'><i class='fa fa-list-ul'></i> " . t("View Combined") . "</a>";
    }

    $acount = 0;

    $rtn .= "
        <tr>
          <td colspan='2' width='100%'>
          
        <div class='hypo' 
        align='left' style='border: 1px solid black;
              margin: 10px 0px 10px 0px; padding: 10px; 
              font-size: 12pt; font-weight: bold;'>
        " . t("You have successfully advised") . " " . $db->get_student_name($student_id) . " ($student_id).
        <br>" . t("Click to view a pop-up printable summary for:") . "
         <ul style='margin-top: 5px; margin-bottom: 5px;'>
        $click_links
        </ul>$group_link</div>
        
        </td>
        </tr>
    ";

  }

  $group_link = "";





  $rtn .= "<tr><td width='50%' valign='top'  class='left-side' style='padding-right: 10px;'>
          ";

  ///////////////////////////////////////////////////
  //////////////////////////////////////////////////
  /////////  Advising History
  ///////////////////////////////////////////////////
  $rtn .= fp_render_section_title(t("Advising History"));
  $render_left = array(); // creating a new render array.
  $render_left ["#id"] = "advise_history_left_column";
  $render_left ["#student_id"] = $student_id;

  $school_id = db_get_school_id_for_student_id($student_id);

  $old_session_d_t = 0;
  $last_session_id = 0;
  $a_count = 0;
  $c = 0;
  $is_empty = TRUE;
  $first_style = "color: maroon; font-weight:bold;";
  $advising_session_id_array = array();

  $on_mouse_over = "
            onmouseover='$(this).addClass(\"selection_highlight\");'
            onmouseout='$(this).removeClass(\"selection_highlight\");'
    ";




  $advising_session_groups_array = array();
  $previous_sessions = array();
  $session_group_code = $old_session_group_code = "";



  // First, find all of the advising session "groups".  That is, advising sessions over multiple
  // terms which were submitted together.
  $res = db_query("SELECT * FROM advising_sessions
                    WHERE student_id = ?
                    AND is_draft = 0
                    AND is_empty = 0
                    AND delete_flag = 0
                    GROUP BY advising_session_token
                    ORDER BY `posted` DESC                    
                     ", $student_id);
  while ($cur = db_fetch_array($res)) {
    $html = "";
    $is_empty = FALSE;
    $advtoken = $cur ['advising_session_token'];
    $bool_is_empty = FALSE;
    $faculty_id = $cur ['faculty_id'];
    $dt = date("m/d/Y g:ia", convert_time($cur ['posted']));

    $group_link = "";

    // If this has more than one session for this token, then show a group_link
    $sessions_arr = advise_get_advising_sessions_for_advising_token($advtoken);

    if ($sessions_arr && count($sessions_arr) > 1) {
      $turl = fp_url("advise/popup-display-summary", "show_as_group=yes&advising_session_id=" . join(",", $sessions_arr));
      $on_click = "popupLargeIframeDialog(\"" . $turl . "\",\"" . t("Advising Sessions - @date", array("@date" => $dt)) . "\",\"\");";
      $group_link = "<a href='javascript:$on_click' class='advising-summary-group-link'><i class='fa fa-list-ul'></i> " . t("View Combined") . "</a>";
    }


    $advised_by = "<div class='history-advised-row history-advised-row-$a_count'>
            <strong>" . t("Advised by") . " " . fp_get_faculty_name($cur ['faculty_id'], FALSE) . "</strong>$group_link
          </div>";


    $html .= "<div class=''>$advised_by</div>";

    $a_count++;
    if ($a_count > 1) {
      $first_style = "";
    }





    $res2 = db_query("SELECT * FROM advising_sessions
                      WHERE advising_session_token = ?
                      AND is_empty = 0
                      AND delete_flag = 0
                      ORDER BY term_id DESC", array($advtoken));
    while ($cur2 = db_fetch_array($res2)) {



      // Are we supposed to "delete" an advising session?  We will double-check the user has all needed permissions if so.
      if (intval(@$_GET ['deladv']) === intval($cur2 ['advising_session_id'])) {
        if (user_has_permission('can_advise_students') && user_has_permission('can_delete_own_advising_session_3_months') && $cur2 ['faculty_id'] == $user->cwid) {

          $del_range = strtotime("now -3 months");
          $then = intval($cur2 ["posted"]);
          if ($then > $del_range) {
            db_query("UPDATE advising_sessions 
                      SET delete_flag = 1
                      WHERE advising_session_id = ?", array($cur2 ['advising_session_id']));
            fp_add_message(t("Advising session has been successfully deleted."));
            fp_goto("history", "current_student_id=$current_student_id");
            die; // redirect from fp_goto above anyway.    
          }

        }
      } // if we are trying to delete          





      $turl = fp_url("advise/popup-display-summary", "advising_session_id={$cur2 ['advising_session_id']}");
      $advising_session_id_array [] = $cur2 ['advising_session_id'];
      $term = get_term_description($cur2 ['term_id'], FALSE, $school_id);
      $on_click = "popupLargeIframeDialog(\"" . $turl . "\",\"" . t("Advising Session @term - @date", array("@term" => $term, "@date" => $dt)) . "\",\"\");";


      $delete_html = "";
      // Should we show the "delete" link?      
      if (user_has_permission('can_advise_students') && user_has_permission('can_delete_own_advising_session_3_months') && $cur2 ['faculty_id'] == $user->cwid) {

        $del_range = strtotime("now -3 months");
        $then = intval($cur ["posted"]);
        if ($then > $del_range) {

          $safe_term = $term;
          $safe_term = str_replace("'", "", $safe_term);
          $safe_term = str_replace('"', "", $safe_term);
          $safe_term = str_replace(';', "", $safe_term);
          $safe_term = str_replace('\\', "", $safe_term);

          $confirm_link = fp_get_js_confirm_link(t("Are you sure you wish to delete the advising session from @dt for @term?  \\n\\nThis action cannot be undone.", array("@dt" => $dt, "@term" => $safe_term)), 
          "window.location=\"" . fp_url("history", "current_student_id=$current_student_id&deladv=" . $cur2 ['advising_session_id']) . "\";", "<i class='fa fa-remove'></i>", "action-link-remove", t("Delete?"));
          $delete_html .= "<div class='delete-adv-wrapper'>
                      $confirm_link                      
                    </div>";


        }


      } // user had permission to delete        


      $html .= "<div $on_mouse_over style='cursor: pointer; $first_style' class='advhist-row' onClick='$on_click'>
                  <div class='advhist-term' style='display: inline-block; padding-left:20px; width:165px;'>$term</div>
                  <div class='advhist-datetime' style='display: inline-block;'>$dt</div>                
                </div>
                $delete_html";



      // If this is more than X number, let's hide the rest in a collapsible fieldset.
      if ($c < 5) {
        $render_left ["advising_history_$c"] = array(
          "value" => $html,
          "weight" => $c,
        );
      }
      else {
        // Let's place in a collapsible fieldset!
        if (!isset($render_left ["advising_history_fs"])) {
          $render_left ["advising_history_fs"] = array(
            "type" => "cfieldset",
            "label" => t("Show complete advising history"),
            "start_closed" => TRUE,
            "elements" => array(),
            "weight" => $c,
          );
        }
        $render_left ["advising_history_fs"]["elements"][] = array("advising_history_$c" => array(
          "value" => $html,
        ));


      }

      $html = "";

      $c++;






    } // while cur2


  } // while cur group by advising session token 


  if ($is_empty == true) {
    //$rtn .= "<div class=' '>No advising history available.</div>";

    $render_left ["markup_no_adv_history"] = array(
      "value" => t("No advising history available."),
    );
  }
  else {

    $print_all_url = fp_url("advise/popup-display-summary", "advising_session_id=" . join(",", $advising_session_id_array));

    $render_left ["markup_print_all"] = array(
      "value" => "<a href='javascript: popupLargeIframeDialog(\"" . $print_all_url . "\",\"" . t("Complete Advising History") . "\",\"\");' class='view-print-all'>
                      <i class='fa fa-window-restore'></i> " . t("View Complete History") . "
                  </a>
          ",
      "weight" => -1,
    );
  }

  // Okay, we can render the left-hand side now.
  $rtn .= fp_render_content($render_left);




  //----------------------------------------------------------------------------------------
  //------------------------------ COMMENT HISTORY -----------------------------------------
  //----------------------------------------------------------------------------------------
  $rtn .= "</td><td width='50%' class='right-side' valign='top'>";
  $rtn .= fp_render_section_title(t("Comment History"));
  //$rtn .= "<table border='0' cellspacing='0'>";

  // Prepare a render array for the right-hand side.
  $render_right = array();
  $render_right ["#id"] = "advise_history_right_column";
  $render_right ["#student_id"] = $student_id;

  $html = "";

  $old_term_id = "";
  $first_style = "first";
  $is_empty = true;
  $has_admin_category = false;
  $access_line = "";

  //if (!user_has_permission("view_faculty_comments")) { 
  //  $access_line = "and `access_type`='public' ";    
  //}

  $access_types = (user_has_permission("view_faculty_comments")) ? array("faculty", "public") : array("public");


  $turl = fp_url("comments/popup-display-all-comments");


  $html .= "<div class='advising-comments-header'>
        <!--STARTCOM--><div style='padding-top: 10px;'>
          <strong>" . t("Advising Comments") . "</strong>
          &nbsp; 
          <a href='javascript: popupLargeIframeDialog(\"" . $turl . "\",\"" . t("All Comments for Student") . "\",\"\");' class='view-print-all'>
            <i class='fa fa-window-restore'></i> " . t("View All Comments") . "
          </a>
        </div><!--ENDCOM-->
        </div>";


  // Use the function comments_get_comments instead of a direct query.

  $res = comments_get_comments($student_id, FALSE, $access_types);
  foreach ($res as $cur) 
   {
    $dt = format_date(convert_time($cur ['posted']), 'custom', 'm/d/Y g:ia');

    if ($first_style == "first") {
      $first_style = "color: maroon; font-weight:bold;";
    }


    $turl = fp_url("comments/popup-display-comment", "id=" . $cur ['id']);

    $on_click = "popupLargeIframeDialog(\"" . $turl . "\",\"" . t("Comment @date", array("@date" => $dt)) . "\",\"\");";


    $html .= "<div $on_mouse_over class='history-comment-row' style='cursor:pointer; $first_style $extra_style'
          onClick='$on_click'>
          <div class=' ' style='padding-left: 20px; width:165px; display:inline-block;'>
            " . fp_get_faculty_name($cur ['faculty_id'], false) . "
          </div>
          <div class=' ' style='display: inline-block;'>
              $dt$ast
          </div>
        </div>";

    $is_empty = false;
    $first_style = "";
  }

  if ($is_empty == true) {

    $render_right ["markup_no_comment_history"] = array(
      "value" => "<span class='no-comment-history-msg'>" . t("No comment history available.") . "</span>",
    );

  }

  $render_right ["comment_history"] = array(
    "value" => "<span class='advising-comment-history-block'>" . $html . "</span>",
    "weight" => 0,
  );

  //$rtn .= "</table>";

  // Render our render array now...
  $rtn .= fp_render_content($render_right);




  $rtn .= "</td></tr>";




  $rtn .= "</table>";


  // Let's set our breadcrumbs
  $db = get_global_database_handler();
  $crumbs = array();
  $crumbs [] = array(
    'text' => 'Students',
    'path' => 'student-search',
  );
  $crumbs [] = array(
    'text' => $db->get_student_name($current_student_id) . " ({$current_student_id})",
    'path' => 'student-profile',
    'query' => "current_student_id={$current_student_id}",
  );
  fp_set_breadcrumbs($crumbs);


  watchdog("advise", "display_history $current_student_id", array(), WATCHDOG_DEBUG);


  return $rtn;
}