stats.module

  1. 6.x modules/stats/stats.module
  2. 4.x modules/stats/stats.module
  3. 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["admin-tools/stats"] = array(
  16. "title" => "Usage Stats & Reports",
  17. "page_callback" => "stats_display_main",
  18. "access_arguments" => array("can_access_stats"),
  19. "page_settings" => array(
  20. "page_show_title" => TRUE,
  21. "menu_icon" => fp_theme_location() . "/images/popup.gif",
  22. "target" => "_blank",
  23. ),
  24. "type" => MENU_TYPE_NORMAL_ITEM,
  25. );
  26. $items["stats/major-counts"] = array(
  27. "title" => "Major Counts",
  28. "page_callback" => "stats_report_major_counts",
  29. "access_arguments" => array("can_access_stats"),
  30. "page_settings" => array(
  31. "page_show_title" => TRUE,
  32. "bool_print" => FALSE,
  33. "menu_links" => array(
  34. 0 => array(
  35. "text" => "Main menu",
  36. "path" => "admin-tools/stats",
  37. ),
  38. ),
  39. ),
  40. "type" => MENU_TYPE_CALLBACK,
  41. );
  42. $items["stats/selected-degree-options"] = array(
  43. "title" => "Selected Degree Options",
  44. "page_callback" => "stats_report_selected_degree_options",
  45. "access_arguments" => array("can_access_stats"),
  46. "page_settings" => array(
  47. "page_show_title" => TRUE,
  48. "bool_print" => FALSE,
  49. "menu_links" => array(
  50. 0 => array(
  51. "text" => "Main menu",
  52. "path" => "admin-tools/stats",
  53. ),
  54. ),
  55. ),
  56. "type" => MENU_TYPE_CALLBACK,
  57. );
  58. $items["stats/access"] = array(
  59. "title" => "Access Stats",
  60. "page_callback" => "stats_report_access_stats",
  61. "access_arguments" => array("can_access_stats"),
  62. "page_settings" => array(
  63. "page_show_title" => TRUE,
  64. "bool_print" => FALSE,
  65. "menu_links" => array(
  66. 0 => array(
  67. "text" => "Main menu",
  68. "path" => "admin-tools/stats",
  69. ),
  70. ),
  71. ),
  72. "type" => MENU_TYPE_CALLBACK,
  73. );
  74. $items["stats/advisor-use"] = array(
  75. "title" => "Advisor Use",
  76. "page_callback" => "stats_report_advisor_use",
  77. "access_arguments" => array("can_access_stats"),
  78. "page_settings" => array(
  79. "page_show_title" => TRUE,
  80. "bool_print" => FALSE,
  81. "menu_links" => array(
  82. 0 => array(
  83. "text" => "Main menu",
  84. "path" => "admin-tools/stats",
  85. ),
  86. ),
  87. ),
  88. "type" => MENU_TYPE_CALLBACK,
  89. );
  90. $items["stats/student-course-list"] = array(
  91. "title" => "Student Course List",
  92. "page_callback" => "stats_report_student_course_list",
  93. "access_arguments" => array("can_access_stats"),
  94. "page_settings" => array(
  95. "page_show_title" => TRUE,
  96. "bool_print" => FALSE,
  97. "menu_links" => array(
  98. 0 => array(
  99. "text" => "Main menu",
  100. "path" => "admin-tools/stats",
  101. ),
  102. ),
  103. ),
  104. "type" => MENU_TYPE_CALLBACK,
  105. );
  106. $items["stats/flightpath-use-summary"] = array(
  107. "title" => "FlightPath Use Summary",
  108. "page_callback" => "stats_report_flightpath_use_summary",
  109. "access_arguments" => array("can_access_stats"),
  110. "page_settings" => array(
  111. "page_show_title" => TRUE,
  112. "bool_print" => FALSE,
  113. "menu_links" => array(
  114. 0 => array(
  115. "text" => "Main menu",
  116. "path" => "admin-tools/stats",
  117. ),
  118. ),
  119. ),
  120. "type" => MENU_TYPE_CALLBACK,
  121. );
  122. return $items;
  123. }
  124. /**
  125. * Implementation of hook_perm().
  126. * Expects to return an array of permissions recognized by
  127. * this module.
  128. *
  129. * Ex: $a = array(
  130. * "deCanDoSomething" => array (
  131. * "title" => "Can Do Something",
  132. * "description" => "Allow the user to do something."
  133. * )
  134. * );
  135. *
  136. */
  137. function stats_perm() {
  138. $perms = array (
  139. "can_access_stats" => array(
  140. "title" => t("Can access/view stats"),
  141. "description" => t("This allows the user to access the stats module, letting them run
  142. reports on usage."),
  143. ),
  144. );
  145. return $perms;
  146. }
  147. /**
  148. * This report will show which degree options are being selected for degrees which offer options.
  149. *
  150. * @return unknown
  151. */
  152. function stats_report_selected_degree_options() {
  153. $rtn = "";
  154. // What major have they selected?
  155. $major = trim($_GET["major"]);
  156. $rtn .= "<form action='" . fp_url("stats/selected-degree-options") . "' method='GET' >";
  157. $rtn .= stats_draw_majors_with_options_pulldown($major, true);
  158. $rtn .= "</form>";
  159. $db = get_global_database_handler();
  160. if ($major != "")
  161. {
  162. $count_in_major = 0;
  163. $degree_option_count = array();
  164. $sql = "SELECT * FROM students
  165. WHERE substring_index(major_code, '|', 1) = '?'
  166. AND rank_code IN %RANKIN%
  167. %EXTRA_STUDENTSEARCH_CONDITIONS% ";
  168. $rank_in = "( '" . join("', '", csv_to_array($GLOBALS["fp_system_settings"]["allowed_student_ranks"])) . "' )";
  169. $sql = str_replace("%RANKIN%", $rank_in, $sql);
  170. $sql = str_replace("%EXTRA_STUDENTSEARCH_CONDITIONS%", $GLOBALS["fp_system_settings"]["extra_student_search_conditions"], $sql);
  171. $result = db_query($sql, $major);
  172. while($cur = db_fetch_array($result))
  173. {
  174. extract($cur, 3, "db");
  175. $count_in_major++;
  176. $track = "";
  177. // Does this student have a track (degree option) specified?
  178. $student_settings = $db->get_student_settings($db_cwid);
  179. if ($student_settings["major_code"] == $major)
  180. {
  181. $track = $student_settings["track_code"];
  182. }
  183. if ($track == "")
  184. {
  185. $track = t("None selected");
  186. }
  187. // Init if not already...
  188. $degree_option_count[$track] = $degree_option_count[$track]*1;
  189. $degree_option_count[$track]++;
  190. }
  191. arsort($degree_option_count);
  192. $rtn .= "<table border='1'>
  193. <tr>
  194. <th>" . t("Degree Option") . "</th>
  195. <th>" . t("Count") . "</th>
  196. <th>" . t("Description") . "</th>
  197. </tr>";
  198. foreach($degree_option_count as $d_option => $value)
  199. {
  200. //$desc = get_track_title($major,$d_option);
  201. // figure out the title of the track...
  202. $temp = explode("-", $db_catalog_year);
  203. $cy = $temp[0];
  204. $degree_id = $db->get_degree_id($major . "|_" . $d_option, $cy);
  205. $dp = new DegreePlan();
  206. $dp->degree_id = $degree_id;
  207. $dp->load_descriptive_data();
  208. $desc = $dp->track_title;
  209. $rtn .= "<tr><td valign='top'>
  210. $d_option
  211. </td>
  212. <td valign='top'>
  213. $value
  214. </td>
  215. <td valign='top'>
  216. $desc
  217. </td>
  218. </tr>";
  219. }
  220. $rtn .= "</table>" . t("Total number of results:") . " $count_in_major.";
  221. }
  222. return $rtn;
  223. }
  224. /**
  225. * Draws a simple form for entering a student's CWID, used by other reports.
  226. *
  227. * @param unknown_type $path
  228. * @param unknown_type $student_cwid
  229. * @return unknown
  230. */
  231. function stats_draw_student_cwid_form($path, $student_cwid = "") {
  232. $rtn = "";
  233. $rtn .= "<form action='" . fp_url($path) . "' method='GET' >
  234. " . t("Enter a student's CWID to see their courses") . "
  235. <br>
  236. <input type='textfield' value='$student_cwid' name='student_cwid'>
  237. <br>
  238. <input type='submit' value='" . t("Submit") . "'>
  239. </form> <hr>
  240. ";
  241. return $rtn;
  242. }
  243. /**
  244. * Display a major selection pulldown, used by other reports.
  245. *
  246. * @param unknown_type $smajor
  247. * @param unknown_type $display_submit
  248. * @return unknown
  249. */
  250. function stats_draw_majors_with_options_pulldown($smajor = "", $display_submit = false)
  251. {
  252. $db = get_global_database_handler();
  253. $major_array = array();
  254. $current_catalog_year = variable_get("current_catalog_year", "");
  255. $m_a_count = 0;
  256. $query = "SELECT * FROM degrees
  257. WHERE catalog_year = '?'
  258. AND `exclude`='0'
  259. ORDER BY `title` ";
  260. $result = db_query($query, $current_catalog_year);
  261. while ($cur_row = $db->db_fetch_array($result)) {
  262. $major = trim($cur_row["major_code"]);
  263. if (!$db->get_degree_tracks($major, $current_catalog_year))
  264. { // only get majors that also have tracks!
  265. continue;
  266. }
  267. $description = trim($cur_row["title"]);
  268. $type = trim($cur_row["degree_type"]);
  269. $major_array[$m_a_count]["description"] = $description;
  270. $major_array[$m_a_count]["major"] = $major;
  271. $major_array[$m_a_count]["type"] = $type;
  272. $m_a_count++;
  273. }
  274. $rtn .= "
  275. <table border='0'>
  276. <td valign='middle'>
  277. <select name='major' id='major'><option value=''>" . t("Please select a major with degree options") . "</option>
  278. <option value=''>-----------------------------------</option>";
  279. for ($t = 0; $t < $m_a_count; $t++)
  280. {
  281. $sel = "";
  282. if ($major_array[$t]["major"] == $smajor && $smajor != "")
  283. {
  284. $sel = "selected";
  285. }
  286. $hyph = "-";
  287. if ($major_array[$t]["type"] == "" || $major_array[$t]["type"] == "NA")
  288. {
  289. $hyph = "";
  290. $major_array[$t]["type"] = "";
  291. }
  292. $rtn .= "<option value='" . $major_array[$t]["major"] . "' $sel>
  293. " . $major_array[$t]["description"] . " $hyph " . $major_array[$t]["type"] . "
  294. </option>";
  295. }
  296. $rtn .= " </select> </td>";
  297. if ($display_submit == true)
  298. {
  299. $rtn .= "<td valign='middle'><input type='submit' value='" . t("Select") . "'></td>";
  300. }
  301. $rtn .= "</table>";
  302. return $rtn;
  303. }
  304. /**
  305. * This report shows how many students are in each major.
  306. *
  307. * @return unknown
  308. */
  309. function stats_report_major_counts() {
  310. $rtn = "";
  311. $rtn .= "<table border='1'>
  312. <tr>
  313. <th>" . t("Major") . "</th>
  314. <th>" . t("Count") . "</th>
  315. <th colspan='2'>" . t("Description") . "</th>
  316. </tr>";
  317. $result = db_query("SELECT * FROM degrees
  318. GROUP BY major_code
  319. ORDER BY title, major_code ");
  320. while ($cur = db_fetch_array($result)) {
  321. $count = 0;
  322. $major_code = $cur["major_code"];
  323. $title = $cur["title"];
  324. $degree_type = $cur["degree_type"];
  325. // If this is a degree option, skip it, as we do not expect
  326. // the students table to record degree option choices.
  327. if (strstr($major_code, "|_")) continue;
  328. // Find out how many students have this major.
  329. $sql = "SELECT count(cwid) AS count FROM students
  330. WHERE major_code = '?'
  331. AND rank_code IN %RANKIN%
  332. %EXTRA_STUDENTSEARCH_CONDITIONS% ";
  333. $rank_in = "( '" . join("', '", csv_to_array($GLOBALS["fp_system_settings"]["allowed_student_ranks"])) . "' )";
  334. $sql = str_replace("%RANKIN%", $rank_in, $sql);
  335. $sql = str_replace("%EXTRA_STUDENTSEARCH_CONDITIONS%", $GLOBALS["fp_system_settings"]["extra_student_search_conditions"], $sql);
  336. $res2 = db_query($sql, $major_code);
  337. $cur2 = db_fetch_array($res2);
  338. if (is_numeric($cur2["count"])) {
  339. $total += $cur2["count"];
  340. }
  341. $res_array[$major_code]["count"] = $cur2["count"] * 1;
  342. $res_array[$major_code]["desc"] = $title;
  343. $res_array[$major_code]["type"] = $degree_type;
  344. }
  345. foreach($res_array as $major => $value) {
  346. $rtn .= "<tr>
  347. <td valign='top' class='tenpt'>$major</td>
  348. <td valign='top' class='tenpt'>{$value["count"]}</td>
  349. <td valign='top' class='tenpt'>{$value["type"]}</td>
  350. <td valign='top' class='tenpt'>{$value["desc"]}</td>
  351. </tr>";
  352. }
  353. $rtn .= "</table>
  354. " . t("Total student records:") . " $total.";
  355. return $rtn;
  356. }
  357. /**
  358. * This report shows common usages in FlightPath by all users.
  359. *
  360. * This is a helpful report for determining which functionality is most popular
  361. * in FlightPath
  362. *
  363. * @return unknown
  364. */
  365. function stats_report_flightpath_use_summary() {
  366. $rtn = "";
  367. $start_date = trim(addslashes($_REQUEST["start_date"]));
  368. $end_date = trim(addslashes($_REQUEST["end_date"]));
  369. $rtn .= stats_draw_date_range_form("stats/flightpath-use-summary", $start_date, $end_date);
  370. if ($start_date == "" || $end_date == "") {
  371. return $rtn;
  372. }
  373. $start_date .= " 00:00:00"; // make it start at midnight of the startDate.
  374. $end_date .= " 23:59:59"; // make it go through to midnight of the endDate.
  375. // Okay, now we get our various counts....
  376. // Logins...
  377. $u_student = stats_get_log_count("login","",true,$start_date,$end_date,true);
  378. $t_student = stats_get_log_count("login","",false,$start_date,$end_date,true);
  379. $u_staff = stats_get_log_count("login","",true,$start_date,$end_date,false);
  380. $t_staff = stats_get_log_count("login","",false,$start_date,$end_date,false);
  381. $rtn .= "<b>System Logins</b>
  382. <blockquote>
  383. Unique student logins: $u_student<br>
  384. Total student logins: $t_student<br>
  385. ------- <br>
  386. Unique faculty/staff logins: $u_staff<br>
  387. Total faculty/staff logins: $t_staff
  388. </blockquote>
  389. ";
  390. // Advisings...
  391. $regular_advisings = stats_get_log_count("save_adv_active","",false,$start_date,$end_date,false);
  392. $wi_advisings = stats_get_log_count("save_adv_active_whatif","",false,$start_date,$end_date,false);
  393. $total_advisings = $regular_advisings + $wi_advisings;
  394. $rtn .= "<b>Advisings</b>
  395. <blockquote>
  396. Total student advisings: $total_advisings <br>
  397. ------- <br>
  398. Regular advisings: $regular_advisings<br>
  399. What If advisings: $wi_advisings
  400. </blockquote>
  401. ";
  402. // Comments...
  403. $total = stats_get_log_count("save_comment","",false,$start_date,$end_date,false);
  404. $unique = stats_get_log_count("save_comment","",true,$start_date,$end_date,false);
  405. $rtn .= "<b>Comments</b>
  406. <blockquote>
  407. Total comments saved: $total <br>
  408. ------- <br>
  409. Unique faculty/staff commentors: $unique
  410. </blockquote>
  411. ";
  412. // Course search...
  413. $u_student = stats_get_log_count("course_search","",true,$start_date,$end_date,true);
  414. $um_student = stats_get_log_count("course_search","",true,$start_date,$end_date,true,true);
  415. $t_student = stats_get_log_count("course_search","",false,$start_date,$end_date,true);
  416. $tm_student = stats_get_log_count("course_search","",false,$start_date,$end_date,true, true);
  417. $u_staff = stats_get_log_count("course_search","",true,$start_date,$end_date,false);
  418. $t_staff = stats_get_log_count("course_search","",false,$start_date,$end_date,false);
  419. $tm_staff = stats_get_log_count("course_search","",false,$start_date,$end_date,false, true);
  420. $rtn .= "<b>Course Search</b>
  421. <blockquote>
  422. Unique student users: $u_student <span class='s-mobile'>($um_student mobile)</span><br>
  423. Total student uses: $t_student <span class='s-mobile'>($tm_student mobile)</span><br>
  424. ------- <br>
  425. Unique faculty/staff users: $u_staff<br>
  426. Total faculty/staff (and anonymous) uses: $t_staff <span class='s-mobile'>($tm_staff mobile)</span>
  427. </blockquote>
  428. ";
  429. // Degree search...
  430. $u_student = stats_get_log_count("blank_degrees","",true,$start_date,$end_date,true);
  431. $um_student = stats_get_log_count("blank_degrees","",true,$start_date,$end_date,true,true);
  432. $t_student = stats_get_log_count("blank_degrees","",false,$start_date,$end_date,true);
  433. $tm_student = stats_get_log_count("blank_degrees","",false,$start_date,$end_date,true, true);
  434. $u_staff = stats_get_log_count("blank_degrees","",true,$start_date,$end_date,false);
  435. $t_staff = stats_get_log_count("blank_degrees","",false,$start_date,$end_date,false);
  436. $tm_staff = stats_get_log_count("blank_degrees","",false,$start_date,$end_date,false, true);
  437. $rtn .= "<b>Degree Search (blank degrees)</b>
  438. <blockquote>
  439. Unique student users: $u_student <span class='s-mobile'>($um_student mobile)</span><br>
  440. Total student uses: $t_student <span class='s-mobile'>($tm_student mobile)</span><br>
  441. ------- <br>
  442. Unique faculty/staff users: $u_staff<br>
  443. Total faculty/staff (and anonymous) uses: $t_staff <span class='s-mobile'>($tm_staff mobile)</span>
  444. </blockquote>
  445. ";
  446. // View preferences
  447. $t_student_y = stats_get_log_count("view_by_year","",false,$start_date,$end_date,true);
  448. $tm_student_y = stats_get_log_count("view_by_year","",false,$start_date,$end_date,true, true);
  449. $u_student_y = stats_get_log_count("view_by_year","",true,$start_date,$end_date,true);
  450. $um_student_y = stats_get_log_count("view_by_year","",true,$start_date,$end_date,true, true);
  451. $t_staff_y = stats_get_log_count("view_by_year","",false,$start_date,$end_date,false);
  452. $t_student_t = stats_get_log_count("view_by_type","",false,$start_date,$end_date,true);
  453. $tm_student_t = stats_get_log_count("view_by_type","",false,$start_date,$end_date,true, true);
  454. $u_student_t = stats_get_log_count("view_by_type","",true,$start_date,$end_date,true);
  455. $um_student_t = stats_get_log_count("view_by_type","",true,$start_date,$end_date,true, true);
  456. $t_staff_t = stats_get_log_count("view_by_type","",false,$start_date,$end_date,false);
  457. $rtn .= "<b>View Preferences</b>
  458. <blockquote>
  459. Unique student view-by-year: $u_student_y <span class='s-mobile'>($um_student_y mobile)</span><br>
  460. Total student view-by-year: $t_student_y <span class='s-mobile'>($tm_student_y mobile)</span><br>
  461. Total faculty/staff view-by-year: $t_staff_y<br>
  462. ------- <br>
  463. Unqiue student view-by-type: $u_student_t <span class='s-mobile'>($um_student_t mobile)</span><br>
  464. Total student view-by-type: $t_student_t <span class='s-mobile'>($tm_student_t mobile)</span><br>
  465. Total faculty/staff view-by-type: $t_staff_t<br>
  466. </blockquote>
  467. ";
  468. // Substitutions
  469. $t_staff = stats_get_log_count("save_substitution","",false,$start_date,$end_date,false);
  470. $u_staff = stats_get_log_count("save_substitution","",true,$start_date,$end_date,false);
  471. $rtn .= "<b>Substitutions</b>
  472. <blockquote>
  473. Unique substitutors: $u_staff<br>
  474. Total substitutions: $t_staff<br>
  475. </blockquote>
  476. ";
  477. return $rtn;
  478. }
  479. /**
  480. * Used by the use_summary report. This function will simply return log counts
  481. * for the specified parameters in the watchdog table.
  482. *
  483. * @param unknown_type $action
  484. * @param unknown_type $action_array
  485. * @param unknown_type $bool_distinct
  486. * @param unknown_type $start_date
  487. * @param unknown_type $end_date
  488. * @param unknown_type $bool_students
  489. * @param unknown_type $bool_mobile_only
  490. * @return unknown
  491. */
  492. function stats_get_log_count($action = "", $action_array = "", $bool_distinct = false, $start_date, $end_date, $bool_students = true, $bool_mobile_only = false)
  493. {
  494. $action_line = " `type` = '$action' ";
  495. if (count($action_array) > 1)
  496. {
  497. $action_line = "";
  498. $action_line .= "( ";
  499. foreach($action_array as $action)
  500. {
  501. $action_line .= " `type`='$action' OR";
  502. }
  503. $action_line = substr($action_line, 0, -2);
  504. $action_line .= ") ";
  505. }
  506. $count = "count(wid)";
  507. if ($bool_distinct)
  508. {
  509. $count = "count(distinct `user_id`)";
  510. }
  511. $user_type = "";
  512. if ($bool_students)
  513. {
  514. $user_type = " `is_student` = '1' ";
  515. } else {
  516. $user_type = " `is_faculty` = '1' ";
  517. }
  518. if ($bool_mobile_only) {
  519. $action_line .= " AND is_mobile = '1' ";
  520. }
  521. $start_ts = strtotime($start_date);
  522. $end_ts = strtotime($end_date);
  523. $res = db_query("SELECT $count AS count FROM watchdog
  524. WHERE
  525. `timestamp` > '$start_ts' AND `timestamp` < '$end_ts'
  526. AND $user_type
  527. AND
  528. $action_line
  529. ");
  530. $cur = db_fetch_array($res);
  531. return $cur["count"] * 1;
  532. }
  533. /**
  534. * Displays the HTML for the date range form used by several reports.
  535. * $path is what is the form's ACTION sending to.
  536. */
  537. function stats_draw_date_range_form($path, $start_date = "", $end_date = "") {
  538. $rtn = "";
  539. $rtn .= "<form action='" . fp_url($path) . "' method='GET' >
  540. " . t("Enter dates in the format YYYY-MM-DD (ex: 2012-01-01)") . "
  541. <br>
  542. " . t("Start date:") . " <input type='text' name='start_date' value='$start_date' id='start_date'>
  543. &nbsp; &nbsp;
  544. " . t("End date:") . " <input type='text' name='end_date' value='$end_date' id='end_date'>
  545. &nbsp; &nbsp;
  546. <input type='submit' value='" . t("Submit") . "'>
  547. </form> <hr>
  548. <script type='text/javascript'>
  549. $(function() {
  550. $('#start_date').datepicker({ dateFormat: 'yy-mm-dd'});
  551. $('#end_date').datepicker({ dateFormat: 'yy-mm-dd'});
  552. });
  553. </script>";
  554. return $rtn;
  555. }
  556. /**
  557. * This report shows which advisors are using FlightPath most often.
  558. *
  559. *
  560. * @return unknown
  561. */
  562. function stats_report_advisor_use() {
  563. $rtn = "";
  564. $start_date = trim(addslashes($_REQUEST["start_date"]));
  565. $end_date = trim(addslashes($_REQUEST["end_date"]));
  566. $rtn .= stats_draw_date_range_form("stats/advisor-use", $start_date, $end_date);
  567. if ($start_date == "" || $end_date == "") {
  568. return $rtn;
  569. }
  570. $start_date .= " 00:00:00"; // make it start at midnight of the startDate.
  571. $end_date .= " 23:59:59"; // make it go through to midnight of the endDate.
  572. $start_ts = strtotime($start_date);
  573. $end_ts = strtotime($end_date);
  574. // Now, what we're doing here is we want the names of the advisors,
  575. // and how many advisings they actually completed for each,
  576. // as well as which college or department they belong to. They need
  577. // to be sorted by college/department.
  578. $f_array = array();
  579. $s_array = array();
  580. $result = db_query("SELECT * FROM watchdog a, faculty b, users c
  581. WHERE
  582. a.timestamp > '?' AND a.timestamp < '?'
  583. AND
  584. (a.type = 'save_adv_active' OR a.type = 'save_adv_active_whatif')
  585. AND a.cwid = b.cwid
  586. AND a.cwid = c.cwid
  587. AND c.is_faculty = 1
  588. ORDER BY b.department ", $start_ts, $end_ts);
  589. while($cur = db_fetch_array($result)) {
  590. $faculty_id = trim($cur["cwid"]);
  591. $f_array[$faculty_id] = $f_array[$faculty_id] * 1; // make it a number.
  592. $f_array[$faculty_id]++;
  593. $s_array[$faculty_id]["dept_name"] = ucwords(strtolower(trim($cur["department"])));
  594. $s_array[$faculty_id]["college_name"] = ucwords(strtolower(trim($cur["college"])));
  595. $s_array[$faculty_id]["name"] = ucwords(strtolower(trim($cur["f_name"]) . " " . trim($cur["l_name"])));
  596. }
  597. // Sort based on who has advised the most...
  598. //arsort($f_array);
  599. $start_date = trim(addslashes($_REQUEST["start_date"]));
  600. $end_date = trim(addslashes($_REQUEST["end_date"]));
  601. // Now, output the results...
  602. $rtn .= "
  603. <table border='1' width='650'>
  604. <tr>
  605. <th>" . t("Name") . "</th>
  606. <th>" . t("Dept") . "</th>
  607. <th>#</th>
  608. </tr>";
  609. foreach($f_array as $faculty_id => $value)
  610. {
  611. $name = $s_array[$faculty_id]["name"];
  612. $college_name = $s_array[$faculty_id]["college_name"];
  613. $dept_name = $s_array[$faculty_id]["dept_name"];
  614. $rtn .= "<tr>
  615. <td valign='top'>$name</td>
  616. <td valign='top'>$dept_name</td>
  617. <td valign='top' align='center'>$value</td>
  618. </tr>
  619. ";
  620. }
  621. $rtn .= "</table>";
  622. return $rtn;
  623. }
  624. /**
  625. * This report shows recent activity in FlightPath. It can also be used to see
  626. * if anyone is "online" in that they would have activity less than 5 minutes old.
  627. *
  628. * @return unknown
  629. */
  630. function stats_report_access_stats() {
  631. $rtn = "";
  632. $min = trim(addslashes($_REQUEST["min"]));
  633. if ($min == "")
  634. {
  635. $min = "20";
  636. }
  637. $rtn .= "
  638. <form action='" . fp_url("stats/access") . "' method='GET'>
  639. " . t("Activity over the last") . "
  640. <input type='text' name='min' value='$min' size='2'>
  641. ";
  642. $rtn .= t("minutes") . ": <input type='submit' value='->'>
  643. </form>
  644. " . t("Unique students in time frame") . ": <!--STUDENTS-->. " . t("Unique faculty/staff in time frame") . ": <!--STAFF--> <br>";
  645. $rtn .= "<table border='1' width='700'>";
  646. $cwid_array = array();
  647. $student_actions = $staff_actions = 0;
  648. $interval = time() - ($min * 60);
  649. $res = db_query("SELECT * FROM watchdog
  650. WHERE `timestamp` > '?'
  651. ORDER BY `timestamp` DESC ", $interval);
  652. while ($cur = db_fetch_array($res)) {
  653. extract ($cur, 3, "db");
  654. $account = fp_load_user($db_user_id);
  655. $bgcol = "white";
  656. if ($account->is_student) {
  657. $bgcol = "lightblue";
  658. }
  659. else if ($account->is_faculty){
  660. $bgcol = "pink";
  661. }
  662. $minago = round((time() - $db_timestamp) / 60, 0);
  663. $extra_data = trim(substr($db_extra_data, 0, 18));
  664. if (strlen($extra_data) < strlen($db_extra_data))
  665. {
  666. $extra_data .= "...";
  667. }
  668. $pretty_date = format_date($db_timestamp);
  669. $user_type = "";
  670. if ($account->is_student) {
  671. $user_type .= "<div>" . t("student") . "</div>";
  672. }
  673. if ($account->is_faculty) {
  674. $user_type .= "<div>" . t("faculty") . "</div>";
  675. }
  676. $rtn .= "<tr style='background-color:$bgcol'>
  677. <td valign='top' class='tenpt'>$account->name</td>
  678. <td valign='top' class='tenpt'>$account->cwid</td>
  679. <td valign='top' class='tenpt'>$account->id</td>
  680. <td valign='top' class='tenpt'>$account->f_name $account->l_name</td>
  681. <td valign='top' class='tenpt'>$user_type</td>
  682. <td valign='top' class='tenpt'>$db_type</td>
  683. <td valign='top' class='tenpt'>" . t($db_message, unserialize($db_variables)) . "</td>
  684. <td valign='top' class='tenpt'>$minago " . t("min ago") . " &nbsp; <font size='1'>$pretty_date</font></td>
  685. </tr>";
  686. // Let's increase our counters, if this is a new CWID.
  687. if (!in_array($db_user_id, $cwid_array)) {
  688. $cwid_array[] = $db_user_id;
  689. if ($account->is_student) {
  690. $student_actions++;
  691. } else if ($account->is_faculty) {
  692. $staff_actions++;
  693. }
  694. }
  695. }
  696. // Add in our student and staff action counts
  697. $rtn = str_replace("<!--STUDENTS-->",$student_actions,$rtn);
  698. $rtn = str_replace("<!--STAFF-->",$staff_actions,$rtn);
  699. $rtn .= "</table>";
  700. return $rtn;
  701. }
  702. /**
  703. * This report shows a list of all of a student's courses which FlightPath is aware of.
  704. *
  705. * @return unknown
  706. */
  707. function stats_report_student_course_list() {
  708. $rtn = "";
  709. $student_cwid = trim(addslashes($_REQUEST["student_cwid"]));
  710. $rtn .= stats_draw_student_cwid_form("stats/student-course-list", $student_cwid);
  711. if ($student_cwid == "") {
  712. return $rtn;
  713. }
  714. // If we have the banner_integration module installed, then get the pidm from banner too
  715. if (function_exists("banner_integration_get_pidm_for_cwid")) {
  716. $student_pidm = banner_integration_get_pidm_for_cwid($student_cwid);
  717. }
  718. $student_name = fp_get_student_name($student_cwid);
  719. $student = new Student($student_cwid);
  720. //var_dump($student->listCoursesTaken->arrayList);
  721. $rtn .= "
  722. <style>
  723. .zebra-even {
  724. background-color: white;
  725. }
  726. .zebra-odd {
  727. background-color: #ddd;
  728. }
  729. </style>
  730. <h2>$student_name ($student_cwid)
  731. ";
  732. if ($student_pidm) {
  733. $rtn .= "<br>PIDM: $student_pidm";
  734. }
  735. $rtn .= "</h2>
  736. <table border='0' cellspacing='0' cellpadding='6'>
  737. <tr>
  738. <th>Subject</th>
  739. <th>Number</th>
  740. <th>Grade</th>
  741. <th>Hours</th>
  742. <th>Term</th>
  743. <th>Transfer?</th>
  744. </tr>";
  745. // So that we can sort our list of courses, we will add them to
  746. // 2 arrays, one for local courses, one for transfer.
  747. $local_array = array();
  748. $transfer_array = array();
  749. $pol = "even";
  750. $local_hours = 0;
  751. $transfer_hours = 0;
  752. while($student->list_courses_taken->has_more()) {
  753. $course = $student->list_courses_taken->get_next();
  754. $subjectID = $course->subject_id;
  755. $courseNum = $course->course_num;
  756. $grade = $course->grade;
  757. $hours = $course->hours_awarded;
  758. if (is_object($course->course_transfer)) {
  759. $subjectID = $course->course_transfer->subject_id;
  760. $courseNum = $course->course_transfer->course_num;
  761. $grade = $course->course_transfer->grade;
  762. $hours = $course->course_transfer->hours_awarded;
  763. $transfer_hours += $hours;
  764. }
  765. else {
  766. // local course
  767. $local_hours += $hours;
  768. }
  769. $html_line = "
  770. <td>$subjectID</td>
  771. <td>$courseNum</td>
  772. <td>$grade</td>
  773. <td>$hours</td>
  774. <td>$course->term_id</td>
  775. <td>" . (($course->bool_transfer) ? "T" : "") . "</td>
  776. ";
  777. if ($course->bool_transfer) {
  778. $transfer_array["$course->term_id~$subjectID~$courseNum"] = $html_line;
  779. }
  780. else {
  781. $local_array["$course->term_id~$subjectID~$courseNum"] = $html_line;
  782. }
  783. }
  784. // Okay, now let's sort our arrays and display them.
  785. ksort($transfer_array);
  786. ksort($local_array);
  787. foreach($local_array as $line) {
  788. $rtn .= "<tr class='zebra-$pol'>$line</tr>";
  789. $pol = ($pol == "even")?"odd":"even";
  790. }
  791. foreach($transfer_array as $line) {
  792. $rtn .= "<tr class='zebra-$pol'>$line</tr>";
  793. $pol = ($pol == "even")?"odd":"even";
  794. }
  795. $rtn .= "</table>
  796. <hr>
  797. ";
  798. $rtn .= "<p>" . count($local_array) . " local courses, with $local_hours hours.</p>";
  799. $rtn .= "<p>" . count($transfer_array) . " transfer courses, with $transfer_hours hours.</p>";
  800. return $rtn;
  801. }
  802. /**
  803. * Main menu screen for this module.
  804. *
  805. * @return unknown
  806. */
  807. function stats_display_main() {
  808. $rtn = "";
  809. $rtn .= "<ul>";
  810. $rtn .= "<li>" . l(t("Access Stats"), "stats/access") . "
  811. <br>
  812. " . t("See recent access within the system. This can be useful to see if anyone is currently using the system.") . "
  813. </li>";
  814. $rtn .= "<li>" . l(t("Major Counts"), "stats/major-counts") . "
  815. <br>
  816. " . t("Displays the number of students within each major or major/concentration.") . "
  817. </li>";
  818. $rtn .= "<li>" . l(t("Selected Degree Options"), "stats/selected-degree-options") . "
  819. <br>
  820. " . t("This report will display information about which degree options students/advisors are selecting for particular majors
  821. (ex: General Studies)") . "
  822. </li>";
  823. $rtn .= "<li>" . l(t("Advisor Use Report"), "stats/advisor-use") . "
  824. <br>
  825. " . t("How many students an advisor has advised over a specified time range.") . "
  826. </li>";
  827. $rtn .= "<li>" . l(t("Student Course List"), "stats/student-course-list") . "
  828. <br>
  829. " . t("List courses a student has taken, which FlightPath is aware of.") . "
  830. </li>";
  831. $rtn .= "<li>" . l(t("FlightPath Use Summary"), "stats/flightpath-use-summary") . "
  832. <br>
  833. " . t("A detailed report on how FlightPath is being used over a specified time range.") . "
  834. </li>";
  835. $rtn .= "</ul>";
  836. return $rtn;
  837. }

Functions

Namesort descending Description
stats_display_main Main menu screen for this module.
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_with_options_pulldown Display a major selection pulldown, used by other reports.
stats_draw_student_cwid_form Draws a simple form for entering a student's CWID, 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_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_selected_degree_options This report will show which degree options are being selected for degrees which offer options.
stats_report_student_course_list This report shows a list of all of a student's courses which FlightPath is aware of.