function stats_report_major_counts

7.x stats.module stats_report_major_counts()
6.x stats.module stats_report_major_counts()
4.x stats.module stats_report_major_counts()
5.x stats.module stats_report_major_counts()

This report shows how many students are in each major.

Return value

unknown

File

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

Code

function stats_report_major_counts() {
  $rtn = "";


  $rtn .= "<p>" . t("This report shows number of students in each major or concentration, as defined in FlightPath.") . "</p>";



  $rtn .= "<table border='1'>
        <tr>";
  if (module_enabled('schools')) {
    $rtn .= "<th>" . t("School") . "</th>";
  }
  $rtn .= "          
          <th>" . t("Major") . "</th>
          <th>" . t("Count") . "</th>
          <th colspan='2'>" . t("Description") . "</th>          
        </tr>";

  $total = 0;

  $result = db_query("SELECT * FROM degrees
                          GROUP BY major_code 
                          ORDER BY school_id, major_code, title ");
  while ($cur = db_fetch_array($result)) {
    $count = 0;
    $major_code = $cur ["major_code"];
    $title = $cur ["title"];
    $degree_type = $cur ["degree_type"];
    $school_id = intval($cur ['school_id']);
    $school_code = "#$school_id";
    if ($school_id === 0) {
      $school_code = "-";
    }
    if (module_enabled("schools")) {
      $school_code = schools_get_school_code_for_id($school_id);
    }

    // Find out how many students have this major code.

    $sql = "SELECT count(cwid) AS count FROM students a, student_degrees b
            WHERE b.major_code = ?
            AND a.cwid = b.student_id
            AND rank_code IN %RANKIN%
            %EXTRA_STUDENTSEARCH_CONDITIONS% ";

    $rank_in = "( '" . join("', '", csv_to_array(variable_get("allowed_student_ranks", "FR,SO,JR,SR"))) . "' )";
    $sql = str_replace("%RANKIN%", $rank_in, $sql);
    $sql = str_replace("%EXTRA_STUDENTSEARCH_CONDITIONS%", variable_get("extra_student_search_conditions", ""), $sql);

    $res2 = db_query($sql, $major_code);
    $cur2 = db_fetch_array($res2);

    if (is_numeric($cur2 ["count"])) {
      $total += $cur2 ["count"];
    }
    $res_array [$major_code]["count"] = $cur2 ["count"] * 1;
    $res_array [$major_code]["desc"] = $title;
    $res_array [$major_code]["type"] = $degree_type;
    $res_array [$major_code]["school_code"] = $school_code;

  }


  foreach ($res_array as $major => $value) {

    $rtn .= "<tr>";
    if (module_enabled('schools')) {
      $rtn .= "<td valign='top' class='tenpt'>{$value ["school_code"]}</td>";
    }
    $rtn .= "
          <td valign='top' class='tenpt'>$major</td>
          <td valign='top' class='tenpt'>{$value ["count"]}</td>
          <td valign='top' class='tenpt'>{$value ["type"]}</td>
          <td valign='top' class='tenpt'>{$value ["desc"]}</td>
        </tr>";
  }

  $rtn .= "</table>
      " . t("Total student records:") . " $total.";


  watchdog('stats', "report_major_counts", array());

  return $rtn;
}