function system_render_advising_snapshop_for_iframe

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

This is meant to be a widget which shows in the dashboard of the advising user, within an iframe, since it can take a while to load.

File

modules/system/system.module, line 4195

Code

function system_render_advising_snapshop_for_iframe() {
  $rtn = "";

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



  if (!isset($_SESSION ["fp_pie_chart_token"])) {
    $_SESSION ["fp_pie_chart_token"] = md5(fp_token());
  }

  $school_ids = array(0);
  if (isset($_REQUEST ['school_id_list'])) {
    $school_ids = explode(",", $_REQUEST ['school_id_list']);

  }

  $selected_school_id = $school_ids [0];
  if (isset($_REQUEST ['selected_school_id'])) {
    $selected_school_id = intval($_REQUEST ['selected_school_id']);
  }


  // Get total number of advisees VS number that have been advised for current term.  
  $adv_array = student_search_display_my_advisees(TRUE, NULL, $selected_school_id, 9999999); // We want to get ALL advisees, so we set the limit very high.
  $total = count($adv_array);

  $advised_count = 0;
  $advised_percent = 0;
  if ($total > 0) {
    foreach ($adv_array as $details) {
      if (@$details ['advised_image'] != "") {
        $advised_count++;
      }
    }

    $advised_percent = round($advised_count / $total * 100, 2);

    $unfinished = 100 - $advised_percent;
    $pie_chart_url_advised_percent = base_path() . "/libraries/pchart/fp_pie_chart.php?size=75&radius=35&progress=$advised_percent&unfinished=$unfinished&unfinished_col=cccccc&progress_col=5780FF&token=" . $_SESSION ["fp_pie_chart_token"];


    $advising_term_id = variable_get_for_school("advising_term_id", "", $selected_school_id);
    $advising_term_desc = get_term_description($advising_term_id, FALSE, $selected_school_id);


    // If we have more than one school, then we should also display a selector which auto-submits when changed.
    $school_selector_html = "";
    if (count($school_ids) > 1 && module_enabled("schools")) {
      fp_add_js(fp_get_module_path("system") . "/js/snapshot.js");

      $url = fp_url("render-advising-snapshot-for-iframe");

      $school_selector_html .= "<div class='snapshot-school-selector'>
                                  <form action='$url' method='GET' id='snapshot-school-selector-form'>
                                  <input type='hidden' name='window_mode' value='popup'>
                                  <input type='hidden' name='school_id_list' value='" . join(",", $school_ids) . "'> 
                                  <strong>School: </strong>                                  
                                  <select name='selected_school_id' id='selected_school_id'>";
      foreach ($school_ids as $school_id) {
        $sel = "";
        if (intval($school_id) === $selected_school_id) {
          $sel = "selected";
        }
        $school_selector_html .= "<option value='$school_id' $sel>" . schools_get_school_name_for_id($school_id) . "</option>";
      }
      $school_selector_html .= "</select>                                
                                </form>
                                </div>";
    }


    $rtn .= "<div class='snapshot-in-iframe'>
              $school_selector_html
              <div class='pie-image'>
                <img src='$pie_chart_url_advised_percent'>
              </div> 
              <div class='pie-term-title'>$advising_term_desc ($advising_term_id)</div>
              <div class='pie-term-caption'>" . t("You have advised %p of your advisees @math", array("%p" => "$advised_percent%", "@math" => "($advised_count/$total)")) . "</div>
             </div>
            ";

  } // if total > 0
  else {
    // Meaning, the user does not have any advisees assigned to them.
    $rtn .= "<div class='snapshot-in-iframe'>
              <div class='pie-term-title'>" . t("No Advisees") . "</div>
              <div class='pie-term-caption'>" . t("You do not have any advisees assigned to you at this time.") . "</div>
             </div>
            ";

  }

  return $rtn;


}