stats.module

  1. 7.x modules/stats/stats.module
  2. 6.x modules/stats/stats.module
  3. 4.x modules/stats/stats.module
  4. 5.x modules/stats/stats.module

This module displays statistics and reports for FlightPath

File

modules/stats/stats.module
View source
  1. <?php
  2. /**
  3. * @file
  4. * This module displays statistics and reports for FlightPath
  5. *
  6. * @return unknown
  7. */
  8. /**
  9. * Implementation of hook_menu
  10. *
  11. * @return unknown
  12. */
  13. function stats_menu() {
  14. $items = array();
  15. $items["stats"] = array(
  16. "title" => "Analytics & Reports",
  17. "page_callback" => "stats_display_main",
  18. "access_arguments" => array("can_access_stats"),
  19. "page_settings" => array(
  20. "page_show_title" => TRUE,
  21. ),
  22. "type" => MENU_TYPE_NORMAL_ITEM,
  23. );
  24. $items["stats/select-school"] = array(
  25. "title" => "Select School",
  26. "page_callback" => "fp_render_form",
  27. "page_arguments" => array("stats_select_school_form"),
  28. "access_arguments" => array("can_access_stats"),
  29. "page_settings" => array(
  30. "page_show_title" => TRUE,
  31. "bool_print" => FALSE,
  32. "menu_links" => array(
  33. 0 => array(
  34. "text" => t("Analytics"),
  35. "path" => "stats",
  36. ),
  37. ),
  38. ),
  39. "type" => MENU_TYPE_CALLBACK,
  40. );
  41. $items["stats/reports/access"] = array(
  42. "title" => "Access Stats",
  43. "description" => "See recent access within the system. This can be useful to see if anyone is currently using the system.",
  44. "page_callback" => "stats_report_access_stats",
  45. "access_arguments" => array("can_access_stats"),
  46. "page_settings" => array(
  47. "page_show_title" => TRUE,
  48. "menu_links" => array(
  49. 0 => array(
  50. "text" => t("Analytics"),
  51. "path" => "stats",
  52. ),
  53. ),
  54. ),
  55. "type" => MENU_TYPE_NORMAL_ITEM,
  56. "weight" => 100,
  57. );
  58. $items["stats/reports/major-counts"] = array(
  59. "title" => "Major Counts",
  60. "description" => "Displays the number of students within each major or major/concentration.",
  61. "page_callback" => "stats_report_major_counts",
  62. "access_arguments" => array("can_access_stats"),
  63. "page_settings" => array(
  64. "page_show_title" => TRUE,
  65. "menu_links" => array(
  66. 0 => array(
  67. "text" => t("Analytics"),
  68. "path" => "stats",
  69. ),
  70. ),
  71. ),
  72. "type" => MENU_TYPE_NORMAL_ITEM,
  73. "weight" => 150,
  74. );
  75. $items["stats/reports/major-students-progress"] = array(
  76. "title" => "Major Students Progress",
  77. "description" => "Students in a major, and their progress percentages in that major.",
  78. "page_callback" => "fp_render_form",
  79. "page_arguments" => array("stats_report_major_students_progress_form"),
  80. "access_arguments" => array("can_access_stats"),
  81. "page_settings" => array(
  82. "bool_print" => FALSE,
  83. "menu_links" => array(
  84. 0 => array(
  85. "text" => t("Analytics"),
  86. "path" => "stats",
  87. ),
  88. ),
  89. ),
  90. "type" => MENU_TYPE_NORMAL_ITEM,
  91. "weight" => 170,
  92. "file" => menu_get_module_path("stats") . "/reports.major-students-progress.inc",
  93. );
  94. $items["stats/reports/advisor-use"] = array(
  95. "title" => "Advisor Use",
  96. "description" => "How many students an advisor has advised over a specified time range.",
  97. "page_callback" => "stats_report_advisor_use",
  98. "access_arguments" => array("can_access_stats"),
  99. "page_settings" => array(
  100. "page_show_title" => TRUE,
  101. "bool_print" => FALSE,
  102. "menu_links" => array(
  103. 0 => array(
  104. "text" => t("Analytics"),
  105. "path" => "stats",
  106. ),
  107. ),
  108. ),
  109. "type" => MENU_TYPE_NORMAL_ITEM,
  110. "weight" => 250,
  111. );
  112. $system_name = variable_get("system_name", "FlightPath");
  113. $items["stats/reports/student-course-list"] = array(
  114. "title" => "Student Course List",
  115. "description" => "List courses a student has taken, which $system_name is aware of.",
  116. "page_callback" => "stats_report_student_course_list",
  117. "access_arguments" => array("can_access_stats"),
  118. "page_settings" => array(
  119. "page_show_title" => TRUE,
  120. "menu_links" => array(
  121. 0 => array(
  122. "text" => t("Analytics"),
  123. "path" => "stats",
  124. ),
  125. ),
  126. ),
  127. "type" => MENU_TYPE_NORMAL_ITEM,
  128. "weight" => 300,
  129. );
  130. $items["stats/reports/flightpath-use-summary"] = array(
  131. "title" => "$system_name Use Summary",
  132. "description" => "A detailed report on how $system_name is being used over a specified time range.",
  133. "page_callback" => "stats_report_flightpath_use_summary",
  134. "access_arguments" => array("can_access_stats"),
  135. "page_settings" => array(
  136. "page_show_title" => TRUE,
  137. "menu_links" => array(
  138. 0 => array(
  139. "text" => t("Analytics"),
  140. "path" => "stats",
  141. ),
  142. ),
  143. ),
  144. "type" => MENU_TYPE_NORMAL_ITEM,
  145. "weight" => 350,
  146. );
  147. $items["stats/reports/course-use-summary"] = array(
  148. "title" => "Course Use Summary",
  149. "description" => "A report of everywhere a particular course is used in $system_name (groups or degrees).",
  150. "page_callback" => "stats_report_course_use_summary",
  151. "access_arguments" => array("can_access_stats"),
  152. "page_settings" => array(
  153. "page_show_title" => TRUE,
  154. "menu_links" => array(
  155. 0 => array(
  156. "text" => t("Analytics"),
  157. "path" => "stats",
  158. ),
  159. ),
  160. ),
  161. "type" => MENU_TYPE_NORMAL_ITEM,
  162. "weight" => 450,
  163. );
  164. // Lets the user download a CSV file stored in the batch_queue table, with a batch_id.
  165. $items["stats/download-csv-from-batch/%"] = array(
  166. "page_callback" => "stats_download_csv_from_batch",
  167. "page_arguments" => array(2),
  168. "access_arguments" => array("can_access_stats"),
  169. "type" => MENU_TYPE_CALLBACK,
  170. );
  171. return $items;
  172. }
  173. /**
  174. * Lets the user download a CSV file from a completed batch.
  175. *
  176. * There are no permissions on this, except the can_access_stats permission.
  177. *
  178. * @param unknown_type $batch_id
  179. */
  180. function stats_download_csv_from_batch($batch_id) {
  181. $filename = fp_get_machine_readable(strtolower($_REQUEST["filename"]));
  182. $batch = batch_get($batch_id);
  183. watchdog('stats', "download_csv_from_batch batch_id:$batch_id, filename:$filename.csv", array());
  184. // Give it to the browser...
  185. header('Content-type: text/csv');
  186. header('Content-Disposition: attachment; filename="' . $filename . '.csv"');
  187. print $batch["csv"];
  188. die;
  189. }
  190. /**
  191. * Implementation of hook_perm().
  192. * Expects to return an array of permissions recognized by
  193. * this module.
  194. *
  195. * Ex: $a = array(
  196. * "deCanDoSomething" => array (
  197. * "title" => "Can Do Something",
  198. * "description" => "Allow the user to do something."
  199. * )
  200. * );
  201. *
  202. */
  203. function stats_perm() {
  204. $perms = array (
  205. "can_access_stats" => array(
  206. "title" => t("Access/view stats & analytics"),
  207. "description" => t("This allows the user to access the stats module, letting them run
  208. reports on usage."),
  209. ),
  210. );
  211. return $perms;
  212. }
  213. /**
  214. * Return the HTML for a pulldown containing the catalog years available for selection.
  215. *
  216. * @param unknown_type $selected
  217. * @param unknown_type $display_submit
  218. */
  219. function stats_draw_catalog_year_pulldown($selected = "", $display_submit = FALSE) {
  220. $rtn = "";
  221. $rtn .= "
  222. <table border='0'>
  223. <td valign='middle'>
  224. <select name='catalog_year' id='catalog_year'><option value=''>
  225. " . t("Please select a catalog year") . "</option>
  226. <option value=''>-----------------------------------</option>";
  227. $current_catalog_year = variable_get("current_catalog_year", ""); // TODO: school_id?
  228. if ($selected == "") $selected = $current_catalog_year;
  229. $res = db_query("SELECT DISTINCT (catalog_year) FROM degrees
  230. WHERE exclude = '0'
  231. ORDER BY catalog_year DESC");
  232. while ($cur = db_fetch_array($res)) {
  233. $sel = ($cur["catalog_year"] == $selected) ? "selected=selected" : "";
  234. $rtn .= "<option value='{$cur["catalog_year"]}' $sel>{$cur["catalog_year"]}-" . ($cur["catalog_year"] + 1) . "</option>";
  235. }
  236. $rtn .= " </select> </td>";
  237. if ($display_submit == true)
  238. {
  239. $rtn .= "<td valign='middle'><input type='submit' value='" . t("Select") . "'></td>";
  240. }
  241. $rtn .= "</table>";
  242. return $rtn;
  243. }
  244. /**
  245. * This report will display everywhere a particular course is used in FlightPath (groups and degrees)
  246. *
  247. */
  248. function stats_report_course_use_summary() {
  249. $rtn = "";
  250. $draft = "";
  251. $use_draft = FALSE;
  252. $school_id = 0; // TODO: school is selectable / based on user's school?
  253. $subject_id = $course_num = $draft_check = "";
  254. if (isset($_GET["subject_id"])) {
  255. $subject_id = trim($_GET["subject_id"]);
  256. $course_num = trim($_GET["course_num"]);
  257. // $school_id = intval($_GET["school_id"]); // TODO: not supported yet.
  258. if (isset($_GET['draft'])) {
  259. $draft_check = $_GET["draft"];
  260. }
  261. }
  262. if ($draft_check == "checked") {
  263. $draft = "draft_";
  264. $use_draft = TRUE;
  265. }
  266. $rtn .= "<form action='" . fp_url("stats/reports/course-use-summary") . "' method='GET' >";
  267. $rtn .= "Please enter a course's subject ID and course number to search:<br>";
  268. if (module_enabled("schools")) {
  269. $options = schools_get_schools_for_fapi();
  270. $rtn .= "<select name='school_id'>";
  271. foreach ($options as $k => $v) {
  272. $sel = "";
  273. if (intval($k) === $school_id) $sel = "selected";
  274. $rtn .= "<option value='$k' $sel>" . t("School: ") . $v . "</option>";
  275. }
  276. $rtn .= "</select> &nbsp; ";
  277. }
  278. $rtn .= "
  279. <input type='text' name='subject_id' placeholder='Subject ID' size='10' value='$subject_id'> &nbsp;
  280. <input type='text' name='course_num' placeholder='Course Num' size='10' value='$course_num'> &nbsp;
  281. <input type='checkbox' name='draft' value='checked' $draft_check>Check draft tables? &nbsp;
  282. <input type='submit' value='Search'>
  283. <br><b>Note:</b> This may take up to a minute to run, please be patient.";
  284. $rtn .= "</form>";
  285. if ($subject_id && $course_num) {
  286. $rtn .= "<hr>";
  287. // First, look up this course's ID.
  288. $db = get_global_database_handler();
  289. $course_id = $db->get_course_id($subject_id, $course_num, '', $use_draft, $school_id);
  290. if ($course_id) {
  291. $rtn .= "<h2>Course $subject_id $course_num (id is $course_id)</h2>";
  292. // Groups
  293. $rtn .= "<div><b>Groups:</b></div>
  294. <table border='1'>
  295. <tr>
  296. <th>ID</th>
  297. <th>Name</th>
  298. <th>Title</th>
  299. <th>Year</th>
  300. </tr>";
  301. $res = db_query("SELECT * FROM {$draft}group_requirements WHERE course_id = ?
  302. order by `id`", $course_id);
  303. while ($cur = db_fetch_array($res)) {
  304. $group_id = $cur["group_id"];
  305. $group = new Group($group_id, $db, -1, false, $use_draft);
  306. if (!$group->title) {
  307. // This is possibly a child group. Look for its parent.
  308. $res2 = db_query("SELECT * FROM {$draft}group_requirements WHERE child_group_id = ?", $group_id);
  309. $cur2 = db_fetch_array($res2);
  310. if ($cur2["group_id"] != "") {
  311. $group_id = $cur2["group_id"];
  312. $group = new Group($group_id, $db, -1, false, $use_draft);
  313. }
  314. }
  315. $rtn .= "<tr>
  316. <td>$group_id</td>
  317. <td>$group->group_name</td>
  318. <td>$group->title</td>
  319. <td>$group->catalog_year</td>
  320. </tr>";
  321. }
  322. $rtn .= "</table>";
  323. // Now, look for degrees...
  324. $rtn .= "<br><br><br>
  325. <b>Degrees:</b>
  326. <table border='1'>
  327. <tr>
  328. <th>ID</th>
  329. <th>Title</th>
  330. <th>MAJR</th>
  331. <th>Track</th>
  332. <th>Sem</th>
  333. <th>Year</th>
  334. </tr>";
  335. $res = db_query("SELECT * FROM {$draft}degree_requirements WHERE course_id = ? ORDER BY `id`", $course_id);
  336. while ($cur = db_fetch_array($res)) {
  337. $degree_id = $cur["degree_id"];
  338. $degree = new DegreePlan($degree_id, $db, TRUE, FALSE, $use_draft);
  339. $rtn .= "<tr>
  340. <td>$degree_id</td>
  341. <td>$degree->title</td>
  342. <td>$degree->major_code</td>
  343. <td>$degree->track_code</td>
  344. <td>" . $cur["semester_num"] . "</td>
  345. <td>$degree->catalog_year</td>
  346. </tr>";
  347. }
  348. $rtn .= '</table>';
  349. } // if course_id
  350. else {
  351. $rtn .= "<div>Course could not be found. Check spelling.";
  352. }
  353. }
  354. watchdog('stats', "report_course_use_summary subject_id:$subject_id, course_num:$course_num, school_id:$school_id, draft_check:$draft_check", array());
  355. return $rtn;
  356. }
  357. /**
  358. * This report will show which degree options are being selected for degrees which offer options.
  359. *
  360. * @return unknown
  361. */
  362. function z__stats_report_selected_degree_options() {
  363. $rtn = "";
  364. // What major have they selected?
  365. $major = fp_trim((string) @$_GET["major"]);
  366. $rtn .= "<form action='" . fp_url("stats/reports/selected-degree-options") . "' method='GET' >";
  367. $rtn .= stats_draw_majors_pulldown($major, TRUE, TRUE, t("Please select a major with degree options"));
  368. $rtn .= "</form>";
  369. $db = get_global_database_handler();
  370. if ($major != "")
  371. {
  372. $count_in_major = 0;
  373. $degree_option_count = array();
  374. $sql = "SELECT * FROM students a, student_degrees b
  375. WHERE substring_index(major_code, '|', 1) = '?'
  376. AND rank_code IN %RANKIN%
  377. AND a.cwid = b.student_id
  378. %EXTRA_STUDENTSEARCH_CONDITIONS%
  379. GROUP BY a.cwid";
  380. $rank_in = "( '" . join("', '", csv_to_array(variable_get("allowed_student_ranks",''))) . "' )";
  381. $sql = str_replace("%RANKIN%", $rank_in, $sql);
  382. $sql = str_replace("%EXTRA_STUDENTSEARCH_CONDITIONS%", variable_get("extra_student_search_conditions",''), $sql);
  383. $result = db_query($sql, $major);
  384. while($cur = db_fetch_array($result))
  385. {
  386. extract($cur, 3, "db");
  387. $count_in_major++;
  388. $track = "";
  389. // Does this student have a track (degree option) specified?
  390. //$student_settings = $db->get_student_settings($db_cwid);
  391. $student_major_codes = $db->get_student_majors_from_db($db_cwid);
  392. // Look through all the major codes for this student, and see if any
  393. // have a |_ in them. If they do, that means they are a track.
  394. foreach ($student_major_codes as $mc) {
  395. if (strstr($mc, $major . "|_")) {
  396. $track = $mc; // Yes, so this is a track for this major.
  397. // Init if not already...
  398. if (!isset($degree_option_count[$track])) {
  399. $degree_option_count[$track] = 0;
  400. }
  401. $degree_option_count[$track]++;
  402. }
  403. }
  404. // No track found. Add that one, too.
  405. if ($track == "")
  406. {
  407. $track = t("None selected");
  408. // Init if not already...
  409. if (!isset($degree_option_count[$track])) {
  410. $degree_option_count[$track] = 0;
  411. }
  412. $degree_option_count[$track]++;
  413. }
  414. } // while db_fetch_array
  415. arsort($degree_option_count);
  416. $rtn .= "<table border='1'>
  417. <tr>
  418. <th>" . t("Degree Option") . "</th>
  419. <th>" . t("Count") . "</th>
  420. <th>" . t("Description") . "</th>
  421. </tr>";
  422. foreach($degree_option_count as $d_option => $value)
  423. {
  424. //$desc = get_track_title($major,$d_option);
  425. // figure out the title of the track...
  426. $temp = explode("-", $db_catalog_year);
  427. $cy = $temp[0];
  428. $degree_id = $db->get_degree_id($d_option, $cy);
  429. $dp = new DegreePlan();
  430. $dp->degree_id = $degree_id;
  431. $dp->load_descriptive_data();
  432. $desc = $dp->get_title2(TRUE, TRUE);
  433. $rtn .= "<tr><td valign='top'>
  434. $d_option
  435. </td>
  436. <td valign='top'>
  437. $value
  438. </td>
  439. <td valign='top'>
  440. $desc
  441. </td>
  442. </tr>";
  443. }
  444. $rtn .= "</table>" . t("Total number of students:") . " $count_in_major.";
  445. }
  446. return $rtn;
  447. }
  448. /**
  449. * Display a major selection pulldown, used by other reports.
  450. *
  451. * If bool_only_majors_with_tracks == TRUE, then we will only display the majors which
  452. * have tracks associated with them.
  453. *
  454. * If bool_exclude_tracks == TRUE, then we will skip over any major_code with a "_" in it,
  455. * meaning, this code describes a track and not the base major.
  456. *
  457. * If bool_only_current_catalog_year == TRUE, then only degrees from the current catalog year
  458. * will be displayed.
  459. *
  460. */
  461. function stats_draw_majors_pulldown($smajor = "", $display_submit = FALSE, $bool_only_majors_with_tracks = FALSE, $label = "Please select a major", $bool_exclude_tracks = FALSE, $bool_only_current_catalog_year = TRUE, $bool_return_options_array = FALSE, $school_id = 0)
  462. {
  463. $rtn = "";
  464. $db = get_global_database_handler();
  465. $major_array = array();
  466. $options_array = array();
  467. $current_catalog_year = variable_get_for_school("current_catalog_year", "", $school_id);
  468. $m_a_count = 0;
  469. if ($bool_only_current_catalog_year) {
  470. $query = "SELECT * FROM degrees
  471. WHERE catalog_year = ?
  472. AND school_id = ?
  473. AND `exclude`='0'
  474. ORDER BY major_code ";
  475. $result = db_query($query, $current_catalog_year, $school_id);
  476. }
  477. else { // current catalog year not important.
  478. $query = "SELECT * FROM degrees
  479. WHERE `exclude`='0'
  480. AND school_id = ?
  481. GROUP BY major_code
  482. ORDER BY major_code ";
  483. $result = db_query($query, $school_id);
  484. }
  485. while ($cur_row = $db->db_fetch_array($result)) {
  486. $major = trim($cur_row["major_code"]);
  487. if ($bool_exclude_tracks && strpos($major, "_")) {
  488. continue;
  489. }
  490. if ($bool_only_majors_with_tracks && !$db->get_degree_tracks($major, $current_catalog_year))
  491. { // only get majors that also have tracks!
  492. continue;
  493. }
  494. $description = trim($cur_row["title"]);
  495. $type = trim($cur_row["degree_type"]);
  496. $school_id = intval($cur_row['school_id']);
  497. $major_array[$m_a_count]["description"] = $description;
  498. $major_array[$m_a_count]["major"] = $major;
  499. $major_array[$m_a_count]["type"] = $type;
  500. $major_array[$m_a_count]["school_id"] = $school_id;
  501. if (module_enabled("schools")) {
  502. $major_array[$m_a_count]["school_name"] = t("School: ") . schools_get_school_name_for_id($school_id);
  503. }
  504. $m_a_count++;
  505. }
  506. $rtn .= "
  507. <table border='0'>
  508. <td valign='middle'>
  509. <select name='major' id='major'>
  510. <option value=''>" . $label . "</option>
  511. <option value=''>-----------------------------------</option>";
  512. for ($t = 0; $t < $m_a_count; $t++)
  513. {
  514. $sel = "";
  515. if ($major_array[$t]["major"] == $smajor && $smajor != "")
  516. {
  517. $sel = "selected";
  518. }
  519. $hyph = "-";
  520. if ($major_array[$t]["type"] == "" || $major_array[$t]["type"] == "NA")
  521. {
  522. $hyph = "";
  523. $major_array[$t]["type"] = "";
  524. }
  525. $rtn .= "<option value='" . $major_array[$t]["major"] . "' $sel>(" . $major_array[$t]["major"] . ")
  526. " . $major_array[$t]["description"] . " $hyph " . $major_array[$t]["type"] . "
  527. </option>";
  528. if (module_enabled("schools")) {
  529. // Create an options array multi-dimentional, organized by school name.
  530. $options_array[$major_array[$t]["school_name"]][$major_array[$t]["major"]] = "(" . $major_array[$t]["major"] . ") " . $major_array[$t]["description"] . " $hyph " . $major_array[$t]["type"];
  531. }
  532. else {
  533. // Just create a "flat" options array
  534. $options_array[$major_array[$t]["major"]] = "(" . $major_array[$t]["major"] . ") " . $major_array[$t]["description"] . " $hyph " . $major_array[$t]["type"];
  535. }
  536. }
  537. $rtn .= " </select> </td>";
  538. if ($display_submit == true)
  539. {
  540. $rtn .= "<td valign='middle'><input type='submit' value='" . t("Select") . "'></td>";
  541. }
  542. $rtn .= "</table>";
  543. if ($bool_return_options_array) return $options_array;
  544. return $rtn;
  545. }
  546. /**
  547. * Draws a simple form for entering a student's CWID, used by other reports.
  548. *
  549. * @param unknown_type $path
  550. * @param unknown_type $student_cwid
  551. * @return unknown
  552. */
  553. function z__stats_draw_student_cwid_form($path, $student_cwid = "") {
  554. $rtn = "";
  555. $rtn .= "<form action='" . fp_url($path) . "' method='GET' >
  556. " . t("Enter a student's CWID to see their courses") . "
  557. <br>
  558. <span class='form-element element-type-textfield'>
  559. <input type='textfield' value='$student_cwid' name='student_cwid'>
  560. </span>
  561. <span class='buttons form-element element-type-submit'>
  562. <input type='submit' value='" . t("Submit") . "'>
  563. </span>
  564. </form> <hr>
  565. ";
  566. return $rtn;
  567. }
  568. function stats_select_school_form() {
  569. $form = array();
  570. if (isset($_REQUEST['title'])) {
  571. fp_set_title(strip_tags($_REQUEST['title']));
  572. }
  573. $redirect_path = $_REQUEST['redirect'];
  574. $options = schools_get_schools_for_fapi();
  575. $form['school_id'] = array(
  576. 'type' => 'select',
  577. 'label' => t("Please select a school:"),
  578. 'options' => $options,
  579. 'hide_please_select' => TRUE,
  580. );
  581. $form['select_school'] = array(
  582. 'type' => 'hidden',
  583. 'value' => 'yes',
  584. );
  585. $form['redirect'] = array(
  586. 'type' => 'hidden',
  587. 'value' => base64_encode($redirect_path),
  588. );
  589. $form['submit_btn'] = array(
  590. 'type' => 'submit',
  591. 'value' => t("Continue"),
  592. );
  593. // change breadcrumbs based on REQUEST
  594. if (isset($_REQUEST['crumbs'])) {
  595. $crumbs = unserialize(base64_decode($_REQUEST['crumbs']));
  596. fp_set_breadcrumbs($crumbs);
  597. }
  598. return $form;
  599. }
  600. function stats_select_school_form_submit($form, $form_state) {
  601. // We are simply trying to select the school. Return to the form with our selection.
  602. $school_id = intval($form_state['values']['school_id']);
  603. $redirect_path = base64_decode($form_state['values']['redirect']);
  604. fp_goto($redirect_path, 'school_id=' . $school_id);
  605. return;
  606. }
  607. /**
  608. * This report shows how many students are in each major.
  609. *
  610. * @return unknown
  611. */
  612. function stats_report_major_counts() {
  613. $rtn = "";
  614. $rtn .= "<p>" . t("This report shows number of students in each major or concentration, as defined in FlightPath.") . "</p>";
  615. $rtn .= "<table border='1'>
  616. <tr>";
  617. if (module_enabled('schools')) {
  618. $rtn .= "<th>" . t("School") . "</th>";
  619. }
  620. $rtn .= "
  621. <th>" . t("Major") . "</th>
  622. <th>" . t("Count") . "</th>
  623. <th colspan='2'>" . t("Description") . "</th>
  624. </tr>";
  625. $total = 0;
  626. $result = db_query("SELECT * FROM degrees
  627. GROUP BY major_code
  628. ORDER BY school_id, major_code, title ");
  629. while ($cur = db_fetch_array($result)) {
  630. $count = 0;
  631. $major_code = $cur["major_code"];
  632. $title = $cur["title"];
  633. $degree_type = $cur["degree_type"];
  634. $school_id = intval($cur['school_id']);
  635. $school_code = "#$school_id";
  636. if ($school_id === 0) $school_code = "-";
  637. if (module_enabled("schools")) {
  638. $school_code = schools_get_school_code_for_id($school_id);
  639. }
  640. // Find out how many students have this major code.
  641. $sql = "SELECT count(cwid) AS count FROM students a, student_degrees b
  642. WHERE b.major_code = ?
  643. AND a.cwid = b.student_id
  644. AND rank_code IN %RANKIN%
  645. %EXTRA_STUDENTSEARCH_CONDITIONS% ";
  646. $rank_in = "( '" . join("', '", csv_to_array(variable_get("allowed_student_ranks", "FR,SO,JR,SR"))) . "' )";
  647. $sql = str_replace("%RANKIN%", $rank_in, $sql);
  648. $sql = str_replace("%EXTRA_STUDENTSEARCH_CONDITIONS%", variable_get("extra_student_search_conditions",""), $sql);
  649. $res2 = db_query($sql, $major_code);
  650. $cur2 = db_fetch_array($res2);
  651. if (is_numeric($cur2["count"])) {
  652. $total += $cur2["count"];
  653. }
  654. $res_array[$major_code]["count"] = $cur2["count"] * 1;
  655. $res_array[$major_code]["desc"] = $title;
  656. $res_array[$major_code]["type"] = $degree_type;
  657. $res_array[$major_code]["school_code"] = $school_code;
  658. }
  659. foreach($res_array as $major => $value) {
  660. $rtn .= "<tr>";
  661. if (module_enabled('schools')) {
  662. $rtn .= "<td valign='top' class='tenpt'>{$value["school_code"]}</td>";
  663. }
  664. $rtn .= "
  665. <td valign='top' class='tenpt'>$major</td>
  666. <td valign='top' class='tenpt'>{$value["count"]}</td>
  667. <td valign='top' class='tenpt'>{$value["type"]}</td>
  668. <td valign='top' class='tenpt'>{$value["desc"]}</td>
  669. </tr>";
  670. }
  671. $rtn .= "</table>
  672. " . t("Total student records:") . " $total.";
  673. watchdog('stats', "report_major_counts", array());
  674. return $rtn;
  675. }
  676. /**
  677. * This report shows common usages in FlightPath by all users.
  678. *
  679. * This is a helpful report for determining which functionality is most popular
  680. * in FlightPath
  681. *
  682. * @return unknown
  683. */
  684. function stats_report_flightpath_use_summary() {
  685. $rtn = "";
  686. $start_date = @$_REQUEST["start_date"];
  687. $end_date = @$_REQUEST["end_date"];
  688. $rtn .= stats_draw_date_range_form("stats/reports/flightpath-use-summary", $start_date, $end_date);
  689. if ($start_date == "" || $end_date == "") {
  690. return $rtn;
  691. }
  692. $start_date .= " 00:00:00"; // make it start at midnight of the startDate.
  693. $end_date .= " 23:59:59"; // make it go through to midnight of the endDate.
  694. // Okay, now we get our various counts....
  695. // Logins...
  696. $u_student = stats_get_log_count("display_dashboard","",true,$start_date,$end_date,true);
  697. $t_student = stats_get_log_count("display_dashboard","",false,$start_date,$end_date,true);
  698. $u_staff = stats_get_log_count("display_dashboard","",true,$start_date,$end_date,false);
  699. $t_staff = stats_get_log_count("display_dashboard","",false,$start_date,$end_date,false);
  700. $rtn .= "<b>System Logins / Access</b>
  701. <blockquote>
  702. Unique student logins: $u_student<br>
  703. Total student views of dashboard: $t_student<br>
  704. ------- <br>
  705. Unique faculty/staff logins: $u_staff<br>
  706. Total faculty/staff views of dashboard: $t_staff
  707. </blockquote>
  708. ";
  709. // Advisings...
  710. /* // This legacy code is not accurate. Going to use the "advisor use report" to get this data". - RP 11/30/2023
  711. $regular_advisings = stats_get_log_count("save_adv_active","",false,$start_date,$end_date,false);
  712. $wi_advisings = stats_get_log_count("save_adv_active_whatif","",false,$start_date,$end_date,false);
  713. $total_advisings = $regular_advisings + $wi_advisings;
  714. $rtn .= "<b>Advisings</b>
  715. <blockquote>
  716. Total student advisings: $total_advisings <br>
  717. ------- <br>
  718. Regular advisings: $regular_advisings<br>
  719. What If advisings: $wi_advisings
  720. </blockquote>
  721. ";
  722. */
  723. // Advisings
  724. $_REQUEST['report_type'] = 'unique';
  725. $_REQUEST['is_whatif'] = 'no';
  726. $regular_advisings = stats_report_advisor_use(TRUE);
  727. $_REQUEST['report_type'] = 'unique';
  728. $_REQUEST['is_whatif'] = 'yes';
  729. $wi_advisings = stats_report_advisor_use(TRUE);
  730. $total_advisings = $regular_advisings + $wi_advisings;
  731. $rtn .= "<b>Advisings</b>
  732. <blockquote>
  733. Total unique student advisings: $total_advisings <br>
  734. ------- <br>
  735. Regular unique advisings: $regular_advisings<br>
  736. What If advisings: $wi_advisings
  737. </blockquote>
  738. ";
  739. // Comments...
  740. $total = stats_get_log_count("save_comment","",false,$start_date,$end_date,false);
  741. $unique = stats_get_log_count("save_comment","",true,$start_date,$end_date,false);
  742. $rtn .= "<b>Comments</b>
  743. <blockquote>
  744. Total comments saved: $total <br>
  745. ------- <br>
  746. Unique faculty/staff commentors: $unique
  747. </blockquote>
  748. ";
  749. // Course search...
  750. $u_student = stats_get_log_count("course_search","",true,$start_date,$end_date,true);
  751. //$um_student = stats_get_log_count("course_search","",true,$start_date,$end_date,true,true);
  752. $t_student = stats_get_log_count("course_search","",false,$start_date,$end_date,true);
  753. //$tm_student = stats_get_log_count("course_search","",false,$start_date,$end_date,true, true);
  754. $u_staff = stats_get_log_count("course_search","",true,$start_date,$end_date,false);
  755. $t_staff = stats_get_log_count("course_search","",false,$start_date,$end_date,false);
  756. //$tm_staff = stats_get_log_count("course_search","",false,$start_date,$end_date,false, true);
  757. $rtn .= "<b>Course Search</b>
  758. <blockquote>
  759. Unique student users: $u_student <br>
  760. Total student uses: $t_student <br>
  761. ------- <br>
  762. Unique faculty/staff users: $u_staff<br>
  763. Total faculty/staff (and anonymous) uses: $t_staff </span>
  764. </blockquote>
  765. ";
  766. // Degree search...
  767. $u_student = stats_get_log_count("blank_degrees","",true,$start_date,$end_date,true);
  768. //$um_student = stats_get_log_count("blank_degrees","",true,$start_date,$end_date,true,true);
  769. $t_student = stats_get_log_count("blank_degrees","",false,$start_date,$end_date,true);
  770. //$tm_student = stats_get_log_count("blank_degrees","",false,$start_date,$end_date,true, true);
  771. $u_staff = stats_get_log_count("blank_degrees","",true,$start_date,$end_date,false);
  772. $t_staff = stats_get_log_count("blank_degrees","",false,$start_date,$end_date,false);
  773. //$tm_staff = stats_get_log_count("blank_degrees","",false,$start_date,$end_date,false, true);
  774. $rtn .= "<b>Degree Search (blank degrees)</b>
  775. <blockquote>
  776. Unique student users: $u_student <br>
  777. Total student uses: $t_student <br>
  778. ------- <br>
  779. Unique faculty/staff users: $u_staff<br>
  780. Total faculty/staff (and anonymous) uses: $t_staff </span>
  781. </blockquote>
  782. ";
  783. // View preferences
  784. $t_student_y = stats_get_log_count("view_by_year","",false,$start_date,$end_date,true);
  785. //$tm_student_y = stats_get_log_count("view_by_year","",false,$start_date,$end_date,true, true);
  786. $u_student_y = stats_get_log_count("view_by_year","",true,$start_date,$end_date,true);
  787. //$um_student_y = stats_get_log_count("view_by_year","",true,$start_date,$end_date,true, true);
  788. $t_staff_y = stats_get_log_count("view_by_year","",false,$start_date,$end_date,false);
  789. $t_student_t = stats_get_log_count("view_by_type","",false,$start_date,$end_date,true);
  790. //$tm_student_t = stats_get_log_count("view_by_type","",false,$start_date,$end_date,true, true);
  791. $u_student_t = stats_get_log_count("view_by_type","",true,$start_date,$end_date,true);
  792. //$um_student_t = stats_get_log_count("view_by_type","",true,$start_date,$end_date,true, true);
  793. $t_staff_t = stats_get_log_count("view_by_type","",false,$start_date,$end_date,false);
  794. $rtn .= "<b>View Preferences</b>
  795. <blockquote>
  796. Unique student view-by-year: $u_student_y <br>
  797. Total student view-by-year: $t_student_y <br>
  798. Total faculty/staff view-by-year: $t_staff_y<br>
  799. ------- <br>
  800. Unqiue student view-by-type: $u_student_t <br>
  801. Total student view-by-type: $t_student_t <br>
  802. Total faculty/staff view-by-type: $t_staff_t<br>
  803. </blockquote>
  804. ";
  805. // Substitutions
  806. $t_staff = stats_get_log_count("save_substitution","",false,$start_date,$end_date,false);
  807. $u_staff = stats_get_log_count("save_substitution","",true,$start_date,$end_date,false);
  808. $rtn .= "<b>Substitutions</b>
  809. <blockquote>
  810. Unique substitutors: $u_staff<br>
  811. Total substitutions: $t_staff<br>
  812. </blockquote>
  813. ";
  814. watchdog('stats', "report_flightpath_use_summary start_date:$start_date, end_date:$end_date", array());
  815. return $rtn;
  816. }
  817. /**
  818. * Used by the use_summary report. This function will simply return log counts
  819. * for the specified parameters in the watchdog table.
  820. *
  821. * @param unknown_type $action
  822. * @param unknown_type $action_array
  823. * @param unknown_type $bool_distinct
  824. * @param unknown_type $start_date
  825. * @param unknown_type $end_date
  826. * @param unknown_type $bool_students
  827. * @param unknown_type $bool_mobile_only
  828. * @return unknown
  829. */
  830. function stats_get_log_count($action = "", $action_array = "", $bool_distinct = false, $start_date = '', $end_date = '', $bool_students = true, $bool_mobile_only = false)
  831. {
  832. $action_line = " `type` = '$action' ";
  833. if (is_array($action_array) && count($action_array) > 1)
  834. {
  835. $action_line = "";
  836. $action_line .= "( ";
  837. foreach($action_array as $action)
  838. {
  839. $action_line .= " `type`='$action' OR";
  840. }
  841. $action_line = substr($action_line, 0, -2);
  842. $action_line .= ") ";
  843. }
  844. $count = "count(wid)";
  845. if ($bool_distinct)
  846. {
  847. $count = "count(distinct `user_id`)";
  848. }
  849. $user_type = "";
  850. if ($bool_students)
  851. {
  852. $user_type = " `is_student` = '1' ";
  853. } else {
  854. $user_type = " `is_faculty` = '1' ";
  855. }
  856. if ($bool_mobile_only) {
  857. $action_line .= " AND is_mobile = '1' ";
  858. }
  859. $start_ts = strtotime($start_date);
  860. $end_ts = strtotime($end_date);
  861. $res = db_query("SELECT $count AS count FROM watchdog
  862. WHERE
  863. `timestamp` > '$start_ts' AND `timestamp` < '$end_ts'
  864. AND $user_type
  865. AND
  866. $action_line
  867. ");
  868. $cur = db_fetch_array($res);
  869. return $cur["count"] * 1;
  870. }
  871. /**
  872. * Displays the HTML for the date range form used by several reports.
  873. * $path is what is the form's ACTION sending to.
  874. *
  875. * start and end date expected in YYYY-MM-DD format
  876. *
  877. */
  878. function stats_draw_date_range_form($path, $start_date = "", $end_date = "", $additional_form_elements = "") {
  879. $rtn = "";
  880. $rtn .= "<form action='" . fp_url($path) . "' method='GET' >
  881. " . t("Select a date range to begin:") . "
  882. <br>
  883. " . t("Start date:") . "
  884. <span class='form-element element-type-date element-size-smaller'>
  885. <input type='date' name='start_date' value='$start_date' id='start_date'>
  886. </span>
  887. &nbsp; &nbsp;
  888. " . t("End date:") . "
  889. <span class='form-element element-type-date'>
  890. <input type='date' name='end_date' value='$end_date' id='end_date'>
  891. </span>
  892. &nbsp; &nbsp;";
  893. if ($additional_form_elements != "") {
  894. $rtn .= $additional_form_elements;
  895. }
  896. fp_add_css(fp_get_module_path("system") . "/css/style.css");
  897. fp_add_js(fp_get_module_path("system") . "/js/spinner.js");
  898. $name = fp_get_machine_readable($path);
  899. $rtn .= "
  900. <span class='buttons form-element element-type-submit'>
  901. <input type='submit' value='" . t("Submit") . "' onclick='$(\".loading-spinner\").show();'>
  902. </span>
  903. <span class='loading-spinner loading-spinner-$name' style='display:none;'></span>
  904. </form> <hr>
  905. ";
  906. return $rtn;
  907. }
  908. /**
  909. * This report shows which advisors are using FlightPath most often.
  910. *
  911. *
  912. * @return unknown
  913. */
  914. function stats_report_advisor_use($bool_only_return_total_number = FALSE) {
  915. $rtn = "";
  916. $start_date = $end_date = $report_type = $whatif = $report_type = "";
  917. if (isset($_REQUEST["start_date"])) {
  918. $start_date = fp_trim(addslashes((string) @$_REQUEST["start_date"]));
  919. $end_date = fp_trim(addslashes((string) @$_REQUEST["end_date"]));
  920. $report_type = fp_trim(addslashes((string) @$_REQUEST["report_type"]));
  921. }
  922. if (isset($_REQUEST['is_whatif'])) {
  923. $whatif = fp_trim((string) @$_REQUEST['is_whatif']);
  924. }
  925. $selall = $selunique = "";
  926. if ($report_type == 'unique') $selunique = 'selected';
  927. $additional_form_elements = t("Report Type:") . "
  928. <span class='form-element element-type-select-smaller'>
  929. <select name='report_type' id='report_type'>
  930. <option value='all' $selall>" . t("All saved advisings") . "</option>
  931. <option value='unique' $selunique>" . t("Unique student advisings") . "</option>
  932. </select>
  933. </span>
  934. &nbsp; &nbsp;";
  935. $rtn .= stats_draw_date_range_form("stats/reports/advisor-use", $start_date, $end_date, $additional_form_elements);
  936. if ($start_date == "" || $end_date == "") {
  937. return $rtn;
  938. }
  939. $start_date .= " 00:00:00"; // make it start at midnight of the startDate.
  940. $end_date .= " 23:59:59"; // make it go through to midnight of the endDate.
  941. $start_ts = strtotime($start_date);
  942. $end_ts = strtotime($end_date);
  943. // Now, what we're doing here is we want the names of the advisors,
  944. // and how many advisings they actually completed for each,
  945. // as well as which college or department they belong to. They need
  946. // to be sorted by college/department.
  947. $f_array = array();
  948. $s_array = array();
  949. $terms = array();
  950. $already_found_student_and_term = array();
  951. // TODO: get by school that user belongs to?
  952. $departments = fp_get_departments();
  953. $s_array = array();
  954. $whatif_line = "";
  955. if ($whatif == 'yes') {
  956. $whatif_line = "AND a.is_whatif = 1 ";
  957. }
  958. else if ($whatif == 'no') {
  959. $whatif_line = "AND a.is_whatif != 1 ";
  960. }
  961. $res = db_query("SELECT *
  962. FROM advising_sessions a, users u, faculty f
  963. WHERE
  964. (`posted` > ? AND `posted` < ?)
  965. AND a.is_empty != 1
  966. AND a.is_draft != 1
  967. AND a.delete_flag != 1
  968. $whatif_line
  969. AND is_faculty = 1
  970. AND a.faculty_id = u.cwid
  971. AND u.cwid = f.cwid
  972. ORDER BY l_name, f_name
  973. ", array($start_ts, $end_ts));
  974. while ($cur = db_fetch_array($res)) {
  975. $faculty_id = $cur['faculty_id'];
  976. $student_id = $cur['student_id'];
  977. $term_id = $cur['term_id'];
  978. $is_whatif = intval($cur['is_whatif']);
  979. if ($report_type == 'unique') {
  980. if (in_array("$faculty_id~$student_id~$term_id~$is_whatif", $already_found_student_and_term)) continue;
  981. $already_found_student_and_term[] = "$faculty_id~$student_id~$term_id~$is_whatif";
  982. }
  983. if (!isset($f_array[$faculty_id])) $f_array[$faculty_id] = 0;
  984. $school_id = intval($cur['school_id']);
  985. $dept_name = @$departments[$cur['department_code']];
  986. if (!$dept_name) $dept_name = $cur['department_code'];
  987. $f_array[$faculty_id] = intval($f_array[$faculty_id]); // make it a number.
  988. $f_array[$faculty_id]++;
  989. $s_array[$faculty_id]["dept_name"] = $dept_name;
  990. $s_array[$faculty_id]["college_name"] = ucwords(strtolower(trim($cur["college"])));
  991. $s_array[$faculty_id]["school_id"] = $school_id;
  992. $s_array[$faculty_id]["name"] = ucwords(strtolower(trim($cur["f_name"]) . " " . trim($cur["l_name"]))) . " ($faculty_id)";
  993. if (!isset($s_array[$faculty_id][$term_id])) $s_array[$faculty_id][$term_id] = 0;
  994. $s_array[$faculty_id][$term_id]++;
  995. $terms[$term_id] = get_term_description($term_id);
  996. }
  997. ksort($terms);
  998. // Sort based on who has advised the most...
  999. //arsort($f_array);
  1000. $start_date = trim(addslashes($_REQUEST["start_date"]));
  1001. $end_date = trim(addslashes($_REQUEST["end_date"]));
  1002. $grand_total = 0;
  1003. // Now, output the results...
  1004. if ($report_type == 'all') {
  1005. $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
  1006. more than once. Deleted advising sessions are not counted.</p>";
  1007. }
  1008. else if ($report_type == 'unique') {
  1009. $rtn .= "<p><b>Note:</b> This Report Type (selected above) shows the number of advising sessions saved by the advisor,
  1010. <em>unique to a student AND What If mode</em>. It ignores sessions which were saved
  1011. more than once, unless the second time was in What If mode. Deleted advising sessions are not counted.</p>";
  1012. }
  1013. $rtn .= "
  1014. <table border='1' cellpadding='10' style='min-width:700px;'>
  1015. <tr>";
  1016. if (module_enabled('schools')) {
  1017. $rtn .= "<th>" . t("School") . "</th>";
  1018. }
  1019. $rtn .= "<th>" . t("Name") . "</th>
  1020. <th>" . t("Dept") . "</th>
  1021. <th>Total #</th>";
  1022. // loop through and add in the terms
  1023. foreach ($terms as $term_id => $term_desc) {
  1024. $rtn .= "<td>$term_desc</td>";
  1025. }
  1026. $rtn .= "</tr>";
  1027. foreach($f_array as $faculty_id => $value)
  1028. {
  1029. $name = $s_array[$faculty_id]["name"];
  1030. $college_name = $s_array[$faculty_id]["college_name"];
  1031. $dept_name = $s_array[$faculty_id]["dept_name"];
  1032. $school_id = $s_array[$faculty_id]["school_id"];
  1033. $grand_total = $grand_total + intval($value);
  1034. $rtn .= "<tr>";
  1035. if (module_enabled('schools')) {
  1036. $rtn .= "<td valign='top'>" . schools_get_school_name_for_id($school_id) . "</td>";
  1037. }
  1038. $rtn .= "
  1039. <td valign='top'>$name</td>
  1040. <td valign='top'>$dept_name</td>
  1041. <td valign='top' align='center'>$value</td>";
  1042. // loop through and add in the terms
  1043. foreach ($terms as $term_id => $term_desc) {
  1044. $rtn .= "<td align='center'>" . $s_array[$faculty_id][$term_id] . "</td>";
  1045. }
  1046. $rtn .= "
  1047. </tr>
  1048. ";
  1049. }
  1050. $rtn .= "</table>";
  1051. $rtn .= "<p><b>Total in selected date range:</b> $grand_total</p>";
  1052. if ($bool_only_return_total_number) {
  1053. return intval($grand_total);
  1054. }
  1055. return $rtn;
  1056. }
  1057. /**
  1058. * This report shows recent activity in FlightPath. It can also be used to see
  1059. * if anyone is "online" in that they would have activity less than 5 minutes old.
  1060. *
  1061. * @return unknown
  1062. */
  1063. function stats_report_access_stats() {
  1064. $rtn = "";
  1065. fp_add_css(fp_get_module_path("admin") . '/css/admin.css');
  1066. $min = intval(@$_REQUEST["min"]);
  1067. if ($min < 1 || $min > 2000)
  1068. {
  1069. $min = "20";
  1070. }
  1071. $rtn .= "
  1072. <form action='" . fp_url("stats/reports/access") . "' method='GET'>
  1073. " . t("Activity over the last") . "
  1074. <input type='text' name='min' value='$min' size='2'>
  1075. ";
  1076. $rtn .= t("minutes") . ": <input type='submit' value='&gt;'>
  1077. </form>
  1078. " . t("Unique students in time frame") . ": <!--STUDENTS-->. " . t("Unique faculty/staff in time frame") . ": <!--STAFF--> <br>";
  1079. $rtn .= "<hr>
  1080. <table class='watchdog-table' cellspacing='0' cellpadding='4'>
  1081. <tr>
  1082. <th>" . t("ID") . "</th>
  1083. <th>" . t("User") . "</th>
  1084. <th>" . t("User Type") . "</th>
  1085. <th>" . t("Action") . "</th>
  1086. <th>" . t("Msg") . "</th>
  1087. <th>" . t("Time") . "</th>
  1088. </tr>";
  1089. $cwid_array = array();
  1090. $student_actions = $staff_actions = 0;
  1091. $interval = time() - ($min * 60);
  1092. $pol = "";
  1093. $res = db_query("SELECT * FROM watchdog
  1094. WHERE `timestamp` > ?
  1095. ORDER BY `timestamp` DESC
  1096. ", $interval);
  1097. while ($cur = db_fetch_array($res)) {
  1098. extract ($cur, 3, "db");
  1099. $wid = $cur['wid'];
  1100. $account = fp_load_user($db_user_id);
  1101. $pol = ($pol == "even") ? "odd" : "even";
  1102. $minago = round((time() - $db_timestamp) / 60, 0);
  1103. $vars = @unserialize($db_variables);
  1104. if (!$vars) $vars = '';
  1105. $message = strip_tags(t($db_message, $vars));
  1106. if (strlen($message) > 100) {
  1107. $message = trim(substr($message, 0, 100)) . "...";
  1108. }
  1109. $pretty_date = format_date(convert_time($db_timestamp));
  1110. $user_type = "";
  1111. if ($account->is_student) {
  1112. $user_type .= "<span>" . t("Student") . "</span>";
  1113. }
  1114. if ($account->is_faculty) {
  1115. $user_type .= "<span style='background-color: lightyellow;'>" . t("Faculty") . "</span>";
  1116. }
  1117. $rtn .= "<tr class='row-$pol'>
  1118. <td valign='top'>" . l($wid, "admin/config/watchdog/$wid") . "</td>
  1119. <td valign='top'>$account->name</td>
  1120. <td valign='top'>$user_type</td>
  1121. <td valign='top'>$db_type</td>
  1122. <td valign='top'>$message</td>
  1123. <td valign='top'>$minago " . t("min ago") . " &nbsp; <em>($pretty_date)</em></td>
  1124. </tr>";
  1125. // Let's increase our counters, if this is a new CWID.
  1126. if (!in_array($db_user_id, $cwid_array)) {
  1127. $cwid_array[] = $db_user_id;
  1128. if ($account->is_student) {
  1129. $student_actions++;
  1130. } else if ($account->is_faculty) {
  1131. $staff_actions++;
  1132. }
  1133. }
  1134. }
  1135. // Add in our student and staff action counts
  1136. $rtn = str_replace("<!--STUDENTS-->",$student_actions,$rtn);
  1137. $rtn = str_replace("<!--STAFF-->",$staff_actions,$rtn);
  1138. $rtn .= "</table>";
  1139. return $rtn;
  1140. }
  1141. /**
  1142. * This report shows a list of all of a student's courses which FlightPath is aware of.
  1143. *
  1144. * @return unknown
  1145. */
  1146. function stats_report_student_course_list() {
  1147. $rtn = "";
  1148. $student_cwid = "";
  1149. if (isset($_REQUEST["student_cwid"])) {
  1150. $student_cwid = trim(addslashes($_REQUEST["student_cwid"]));
  1151. }
  1152. $student_pidm = 0;
  1153. //$rtn .= stats_draw_student_cwid_form("stats/reports/student-course-list", $student_cwid);
  1154. $rtn .= "<form action='" . fp_url("stats/reports/student-course-list") . "' method='GET' >
  1155. " . t("Enter a student's CWID to see their courses:") . "
  1156. <br>
  1157. <span class='form-element element-type-textfield'>
  1158. <input type='textfield' value='$student_cwid' name='student_cwid'>
  1159. </span>
  1160. <span class='buttons form-element element-type-submit'>
  1161. <input type='submit' value='" . t("Submit") . "'>
  1162. </span>
  1163. </form> <hr>";
  1164. if ($student_cwid == "") {
  1165. return $rtn;
  1166. }
  1167. // If we have the banner_integration module installed, then get the pidm from banner too
  1168. if (function_exists("banner_integration_get_pidm_for_cwid")) {
  1169. $student_pidm = intval(banner_integration_get_pidm_for_cwid($student_cwid));
  1170. }
  1171. $student_name = fp_get_student_name($student_cwid);
  1172. $student = new Student($student_cwid);
  1173. $school_id = db_get_school_id_for_student_id($student_cwid);
  1174. $school_name = "";
  1175. if (module_enabled("schools")) {
  1176. $school_name = schools_get_school_name_for_id($school_id);
  1177. }
  1178. $rtn .= "
  1179. <style>
  1180. .zebra-even {
  1181. background-color: white;
  1182. }
  1183. .zebra-odd {
  1184. background-color: #eee;
  1185. }
  1186. </style>
  1187. <h2>$student_name ($student_cwid)
  1188. ";
  1189. if ($student_pidm > 0) {
  1190. $rtn .= "<br>PIDM: $student_pidm";
  1191. }
  1192. if ($school_name) {
  1193. $rtn .= "<br>" . t("School:") . "<em>$school_name</em>";
  1194. }
  1195. $rtn .= "</h2>
  1196. <table border='0' cellspacing='0' cellpadding='6'>
  1197. <tr>
  1198. <th>Subject</th>
  1199. <th>Number</th>
  1200. <th>Grade</th>
  1201. <th>Hours</th>
  1202. <th>Term</th>
  1203. <th>Transfer?</th>
  1204. </tr>";
  1205. // So that we can sort our list of courses, we will add them to
  1206. // 2 arrays, one for local courses, one for transfer.
  1207. $local_array = array();
  1208. $transfer_array = array();
  1209. $pol = "even";
  1210. $local_hours = 0;
  1211. $transfer_hours = 0;
  1212. while($student->list_courses_taken->has_more()) {
  1213. $course = $student->list_courses_taken->get_next();
  1214. $subjectID = $course->subject_id;
  1215. $courseNum = $course->course_num;
  1216. $grade = $course->grade;
  1217. $hours = $course->get_hours_awarded();
  1218. $rnd = mt_rand(0,9999);
  1219. if (is_object($course->course_transfer)) {
  1220. $subjectID = $course->course_transfer->subject_id;
  1221. $courseNum = $course->course_transfer->course_num;
  1222. $grade = $course->course_transfer->grade;
  1223. $hours = $course->course_transfer->get_hours_awarded();
  1224. $transfer_hours += $hours;
  1225. }
  1226. else {
  1227. // local course
  1228. $local_hours += $hours;
  1229. }
  1230. $html_line = "
  1231. <td>$subjectID</td>
  1232. <td>$courseNum</td>
  1233. <td>$grade</td>
  1234. <td>$hours</td>
  1235. <td>$course->term_id</td>
  1236. <td>" . (($course->bool_transfer) ? "T" : "") . "</td>
  1237. ";
  1238. if ($course->bool_transfer) {
  1239. // The $rnd makes sure this is unique, in case a course is showing as repeated in the same term.
  1240. $transfer_array["$course->term_id~$subjectID~$courseNum~$rnd"] = $html_line;
  1241. }
  1242. else {
  1243. // The $rnd makes sure this is unique, in case a course is showing as repeated in the same term.
  1244. $local_array["$course->term_id~$subjectID~$courseNum~$rnd"] = $html_line;
  1245. }
  1246. }
  1247. // Okay, now let's sort our arrays and display them.
  1248. ksort($transfer_array);
  1249. ksort($local_array);
  1250. foreach($local_array as $line) {
  1251. $rtn .= "<tr class='zebra-$pol'>$line</tr>";
  1252. $pol = ($pol == "even")?"odd":"even";
  1253. }
  1254. foreach($transfer_array as $line) {
  1255. $rtn .= "<tr class='zebra-$pol'>$line</tr>";
  1256. $pol = ($pol == "even")?"odd":"even";
  1257. }
  1258. $rtn .= "</table>
  1259. <hr>
  1260. ";
  1261. $rtn .= "<p>" . count($local_array) . " local courses, with $local_hours hours.</p>";
  1262. $rtn .= "<p>" . count($transfer_array) . " transfer courses, with $transfer_hours hours.</p>";
  1263. watchdog('stats', "report_student_course_list student_id:$student_cwid, school_id:$school_id, student_name:$student_name", array());
  1264. return $rtn;
  1265. }
  1266. /**
  1267. * Main menu screen for this module.
  1268. *
  1269. * We will simply display the "menu block" for "stats/reports". That is,
  1270. * any path that begins with stats/reports will show up here.
  1271. *
  1272. * You can create a report in your custom module, and as long as the url begins
  1273. * with stats/reports, and the menu item is of type "MENU_TYPE_NORMAL_ITEM"
  1274. * it will appear on this page. Set the weight to be > 1000 to appear below this list,
  1275. * set weight < 100 to appear above.
  1276. *
  1277. * @return unknown
  1278. */
  1279. function stats_display_main() {
  1280. $rtn = "";
  1281. $rtn .= "<div class='stats-main-menu'>";
  1282. $rtn .= fp_render_menu_block("System Reports", "stats/reports");
  1283. $rtn .= "</div>";
  1284. // If we have other reports which have been exposed using the hook_stats_additional_menublocks function,
  1285. // display them here.
  1286. $reports = invoke_hook('stats_additional_menublocks');
  1287. if ($reports) {
  1288. foreach ($reports as $module_name => $temp) {
  1289. $extraclass = "";
  1290. $extraclass .= "stats-menublock-path-" . strtolower(fp_get_machine_readable(current($reports[$module_name])));
  1291. $rtn .= "<div class='stats-main-menu stats-additional-menublocks $extraclass'>";
  1292. foreach($reports[$module_name] as $title => $menu_block_path) {
  1293. $rtn .= fp_render_menu_block($title, $menu_block_path);
  1294. }
  1295. $rtn .= "</div>";
  1296. }
  1297. }
  1298. return $rtn;
  1299. }

Functions

Namesort descending Description
stats_display_main Main menu screen for this module.
stats_download_csv_from_batch Lets the user download a CSV file from a completed batch.
stats_draw_catalog_year_pulldown Return the HTML for a pulldown containing the catalog years available for selection.
stats_draw_date_range_form Displays the HTML for the date range form used by several reports. $path is what is the form's ACTION sending to.
stats_draw_majors_pulldown Display a major selection pulldown, used by other reports.
stats_get_log_count Used by the use_summary report. This function will simply return log counts for the specified parameters in the watchdog table.
stats_menu Implementation of hook_menu
stats_perm Implementation of hook_perm(). Expects to return an array of permissions recognized by this module.
stats_report_access_stats This report shows recent activity in FlightPath. It can also be used to see if anyone is "online" in that they would have activity less than 5 minutes old.
stats_report_advisor_use This report shows which advisors are using FlightPath most often.
stats_report_course_use_summary This report will display everywhere a particular course is used in FlightPath (groups and degrees)
stats_report_flightpath_use_summary This report shows common usages in FlightPath by all users.
stats_report_major_counts This report shows how many students are in each major.
stats_report_student_course_list This report shows a list of all of a student's courses which FlightPath is aware of.
stats_select_school_form
stats_select_school_form_submit
z__stats_draw_student_cwid_form Draws a simple form for entering a student's CWID, used by other reports.
z__stats_report_selected_degree_options This report will show which degree options are being selected for degrees which offer options.