function stats_report_advisor_use

7.x stats.module stats_report_advisor_use($bool_only_return_total_number = FALSE)
6.x stats.module stats_report_advisor_use($bool_only_return_total_number = FALSE)
4.x stats.module stats_report_advisor_use()
5.x stats.module stats_report_advisor_use()

This report shows which advisors are using FlightPath most often.

Return value

unknown

1 call to stats_report_advisor_use()
stats_report_flightpath_use_summary in modules/stats/stats.module
This report shows common usages in FlightPath by all users.

File

modules/stats/stats.module, line 1222
This module displays statistics and reports for FlightPath

Code

function stats_report_advisor_use($bool_only_return_total_number = FALSE) {
  $rtn = "";

  $start_date = $end_date = $report_type = $whatif = $report_type = "";

  if (isset($_REQUEST ["start_date"])) {
    $start_date = fp_trim(addslashes((string) @$_REQUEST ["start_date"]));
    $end_date = fp_trim(addslashes((string) @$_REQUEST ["end_date"]));
    $report_type = fp_trim(addslashes((string) @$_REQUEST ["report_type"]));
  }
  if (isset($_REQUEST ['is_whatif'])) {
    $whatif = fp_trim((string) @$_REQUEST ['is_whatif']);
  }

  $selall = $selunique = "";
  if ($report_type == 'unique') {
    $selunique = 'selected';
  }

  $additional_form_elements = t("Report Type:") . "
            <span class='form-element element-type-select-smaller'> 
              <select name='report_type' id='report_type'>
                <option value='all' $selall>" . t("All saved advisings") . "</option>
                <option value='unique' $selunique>" . t("Unique student advisings") . "</option>
              </select>
            </span>
            &nbsp; &nbsp;";


  $rtn .= stats_draw_date_range_form("stats/reports/advisor-use", $start_date, $end_date, $additional_form_elements);

  if ($start_date == "" || $end_date == "") {
    return $rtn;
  }

  $start_date .= " 00:00:00"; // make it start at midnight of the startDate.
  $end_date .= " 23:59:59"; // make it go through to midnight of the endDate.

  $start_ts = strtotime($start_date);
  $end_ts = strtotime($end_date);

  // Now, what we're doing here is we want the names of the advisors,
  // and how many advisings they actually completed for each,
  // as well as which college or department they belong to.  They need
  // to be sorted by college/department.
  $f_array = array();
  $s_array = array();
  $terms = array();

  $already_found_student_and_term = array();

  // TODO: get by school that user belongs to?  
  $departments = fp_get_departments();

  $s_array = array();


  $whatif_line = "";
  if ($whatif == 'yes') {
    $whatif_line = "AND a.is_whatif = 1 ";
  }
  else if ($whatif == 'no') {
    $whatif_line = "AND a.is_whatif != 1 ";
  }


  $res = db_query("SELECT * 
                      FROM advising_sessions a, users u, faculty f
                      WHERE 
                      (`posted` > ? AND `posted` < ?)                                                
                      AND a.is_empty != 1
                      AND a.is_draft != 1
                      AND a.delete_flag != 1
                      $whatif_line                                             
                      AND is_faculty = 1
                      AND a.faculty_id = u.cwid
                      AND u.cwid = f.cwid
                      ORDER BY l_name, f_name  
                      ", array($start_ts, $end_ts));
  while ($cur = db_fetch_array($res)) {

    $faculty_id = $cur ['faculty_id'];
    $student_id = $cur ['student_id'];
    $term_id = $cur ['term_id'];

    $is_whatif = intval($cur ['is_whatif']);


    if ($report_type == 'unique') {
      if (in_array("$faculty_id~$student_id~$term_id~$is_whatif", $already_found_student_and_term)) {
        continue;
      }
      $already_found_student_and_term [] = "$faculty_id~$student_id~$term_id~$is_whatif";
    }

    if (!isset($f_array [$faculty_id])) {
      $f_array [$faculty_id] = 0;
    }


    $school_id = intval($cur ['school_id']);
    $dept_name = @$departments [$cur ['department_code']];
    if (!$dept_name) {
      $dept_name = $cur ['department_code'];
    }


    $f_array [$faculty_id] = intval($f_array [$faculty_id]); // make it a number.
    $f_array [$faculty_id];

    ++$s_array [$faculty_id]["dept_name"] = $dept_name;
    $s_array [$faculty_id]["college_name"] = ucwords(strtolower(trim($cur ["college"])));

    $s_array [$faculty_id]["school_id"] = $school_id;
    $s_array [$faculty_id]["name"] = ucwords(strtolower(trim($cur ["f_name"]) . " " . trim($cur ["l_name"]))) . " ($faculty_id)";





    if (!isset($s_array [$faculty_id][$term_id])) {
      $s_array [$faculty_id][$term_id] = 0;
    }
    $s_array [$faculty_id][$term_id];

    ++$terms [$term_id] = get_term_description($term_id);
  }






  ksort($terms);


  // Sort based on who has advised the most...
  //arsort($f_array);

  $start_date = trim(addslashes($_REQUEST ["start_date"]));
  $end_date = trim(addslashes($_REQUEST ["end_date"]));

  $grand_total = 0;

  // Now, output the results...
  if ($report_type == 'all') {
    $rtn .= "<p><b>Note:</b> This Report Type (selected above) shows the total number of advising sessions saved by the advisor, <em>including</em> sessions which were saved
                  more than once.  Deleted advising sessions are not counted.</p>";
  }
  else if ($report_type == 'unique') {

    $rtn .= "<p><b>Note:</b> This Report Type (selected above) shows the number of advising sessions saved by the advisor, 
                  <em>unique to a student AND What If mode</em>. It ignores sessions which were saved
                  more than once, unless the second time was in What If mode.  Deleted advising sessions are not counted.</p>";
  }

  $rtn .= "
      <table border='1' cellpadding='10' style='min-width:700px;'>
        <tr>";

  if (module_enabled('schools')) {
    $rtn .= "<th>" . t("School") . "</th>";
  }

  $rtn .= "<th>" . t("Name") . "</th>
          <th>" . t("Dept") . "</th>
          <th>Total #</th>";

  // loop through and add in the terms          
  foreach ($terms as $term_id => $term_desc) {
    $rtn .= "<td>$term_desc</td>";
  }


  $rtn .= "</tr>";
  foreach ($f_array as $faculty_id => $value) 
   {
    $name = $s_array [$faculty_id]["name"];
    $college_name = $s_array [$faculty_id]["college_name"];
    $dept_name = $s_array [$faculty_id]["dept_name"];
    $school_id = $s_array [$faculty_id]["school_id"];

    $grand_total = $grand_total + intval($value);

    $rtn .= "<tr>";

    if (module_enabled('schools')) {
      $rtn .= "<td valign='top'>" . schools_get_school_name_for_id($school_id) . "</td>";
    }

    $rtn .= "
       <td valign='top'>$name</td>
       <td valign='top'>$dept_name</td>
       <td valign='top' align='center'>$value</td>";

    // loop through and add in the terms          
    foreach ($terms as $term_id => $term_desc) {
      $rtn .= "<td align='center'>" . $s_array [$faculty_id][$term_id] . "</td>";
    }



    $rtn .= "       
      </tr>
      
      ";
  }
  $rtn .= "</table>";
  $rtn .= "<p><b>Total in selected date range:</b> $grand_total</p>";

  if ($bool_only_return_total_number) {
    return intval($grand_total);
  }


  return $rtn;
}