student_search.module

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

File

modules/student_search/student_search.module
View source
  1. <?php
  2. function student_search_menu() {
  3. $items = array();
  4. $items["admin/config/student-search-settings"] = array(
  5. "title" => "Student Search settings",
  6. "description" => "Configure settings for the Student Search function",
  7. "page_callback" => "fp_render_form",
  8. "page_arguments" => array("student_search_settings_form", "system_settings"),
  9. "access_arguments" => array("administer_student_search"),
  10. "page_settings" => array(
  11. "page_has_search" => FALSE,
  12. "menu_icon" => fp_get_module_path('student_search') . "/icons/database_gear.png",
  13. "page_banner_is_link" => TRUE,
  14. "page_hide_report_error" => TRUE,
  15. "menu_links" => array(
  16. 0 => array(
  17. "text" => "Admin Console",
  18. "path" => "admin-tools/admin",
  19. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  20. ),
  21. ),
  22. ),
  23. "type" => MENU_TYPE_NORMAL_ITEM,
  24. "tab_parent" => "admin-tools/admin",
  25. );
  26. $items["student-search"] = array(
  27. "title" => t("Advisees"),
  28. "page_callback" => "student_search_subtab_switchboard",
  29. "access_callback" => "search_user_can_search_for_some_advisees",
  30. "type" => MENU_TYPE_TAB,
  31. "tab_family" => "system",
  32. "page_settings" => array(
  33. "page_has_search" => TRUE,
  34. ),
  35. "weight" => 20,
  36. );
  37. $items["student-search/my-advisees"] = array(
  38. "title" => t("My Advisees"),
  39. "page_callback" => "student_search_display_my_advisees",
  40. "access_arguments" => array("display_my_advisees_subtab"),
  41. "type" => MENU_TYPE_SUB_TAB,
  42. "tab_family" => "student_search",
  43. "tab_parent" => "student-search",
  44. "page_settings" => array (
  45. "display_currently_advising" => TRUE,
  46. "display_greeting" => TRUE,
  47. "screen_mode" => "not_advising",
  48. "page_has_search" => TRUE,
  49. ),
  50. "weight" => 10,
  51. );
  52. $items["student-search/my-majors"] = array(
  53. "title" => t("My Majors"),
  54. "page_callback" => "student_search_display_my_majors",
  55. "access_arguments" => array("display_my_majors_subtab"),
  56. "type" => MENU_TYPE_SUB_TAB,
  57. "tab_family" => "student_search",
  58. "tab_parent" => "student-search",
  59. "page_settings" => array (
  60. "display_currently_advising" => TRUE,
  61. "display_greeting" => TRUE,
  62. "screen_mode" => "not_advising",
  63. "page_has_search" => TRUE,
  64. ),
  65. "weight" => 20,
  66. );
  67. $items["student-search/majors-search"] = array(
  68. "title" => t("Majors"),
  69. "page_callback" => "student_search_display_majors_search",
  70. "access_arguments" => array("display_majors_subtab"),
  71. "type" => MENU_TYPE_SUB_TAB,
  72. "tab_family" => "student_search",
  73. "tab_parent" => "student-search",
  74. "page_settings" => array (
  75. "display_currently_advising" => TRUE,
  76. "display_greeting" => TRUE,
  77. "screen_mode" => "not_advising",
  78. "page_has_search" => TRUE,
  79. ),
  80. "weight" => 25,
  81. );
  82. $items["student-search/search"] = array(
  83. "title" => t("Search"),
  84. "page_callback" => "student_search_display_search",
  85. "access_arguments" => array("display_search_subtab"),
  86. "type" => MENU_TYPE_SUB_TAB,
  87. "tab_family" => "student_search",
  88. "tab_parent" => "student-search",
  89. "page_settings" => array (
  90. "display_currently_advising" => TRUE,
  91. "display_greeting" => TRUE,
  92. "screen_mode" => "not_advising",
  93. "page_has_search" => TRUE,
  94. ),
  95. "weight" => 30,
  96. );
  97. return $items;
  98. }
  99. /**
  100. * This is a system_settings form for configuring our module.
  101. *
  102. */
  103. function student_search_settings_form() {
  104. $form = array();
  105. $form["student_search_major_search_cur_year"] = array(
  106. "type" => "checkbox",
  107. "label" => "Major search - Only show major choices from current catalog year?",
  108. "value" => variable_get("student_search_major_search_cur_year", FALSE),
  109. "description" => t("If checked, the Majors tab will only allow selections of
  110. unexcluded degrees/majors in the current catalog year.
  111. If not sure what to do, leave this CHECKED."),
  112. );
  113. $form["extra_student_search_conditions"] = array(
  114. "type" => "textarea",
  115. "label" => t("Extra student search conditions:"),
  116. "value" => variable_get("extra_student_search_conditions", " AND is_active = 1 "),
  117. "description" => t("This is mysql which will get appended to end of the WHERE clause of every query
  118. relating to searching for students. It is so you can easily add global conditions,
  119. especially if you are overriding the student_search module. For example,
  120. to check that the students are admitted or enrolled. <b>Probably not necessary</b> if you
  121. are not overriding the student_search module. If you are unsure what to do, leave this set to default.
  122. <br>Default is: AND is_active = 1 "),
  123. );
  124. $form["enrolled_student_search_conditions"] = array(
  125. "type" => "textarea",
  126. "label" => t("Enrolled student search conditions:"),
  127. "value" => variable_get("enrolled_student_search_conditions", " AND is_active = 1 "),
  128. "description" => t("Similar to the one above it, this is a clause which will only bring up students
  129. who are enrolled at the university, and taking courses. This might be identical to the
  130. one above it. At the moment, this is only being used in the Stats module, and not
  131. for any logic in FlightPath, so you should consider it optional.
  132. <br>Default is: AND is_active = 1 "),
  133. );
  134. return $form;
  135. }
  136. /**
  137. * The primary purpose of this function is to decide which
  138. * "sub tab" function to send the user off to. This is based
  139. * on whatever their previous selection was.
  140. */
  141. function student_search_subtab_switchboard() {
  142. $last_tab = $_SESSION["student_search_last_tab"];
  143. if ($last_tab == "") $last_tab = 'search';
  144. fp_goto("student-search/$last_tab");
  145. }
  146. /**
  147. * This is meant to be called directly from the theme template, to draw
  148. * the small search box in the corner of the screen.
  149. *
  150. * As such, we need to include any javascript we need here, rather than using
  151. * fp_add_js.
  152. */
  153. function student_search_render_small_search() {
  154. global $current_student_id;
  155. $rtn = "";
  156. $url = fp_url("student-search/search");
  157. $rtn .= "<form action='" . $url . "' method='post' id='small-search-form'
  158. style='padding:0; margin:0; padding-bottom: 5px;'>
  159. <input type='text' class='smallinput' size='30' name='search_for' id='search_bar_value'
  160. placeholder = '" . t("Search by name or CWID") . "'>
  161. <input type='submit' name='submit' value='=>' class='smallinput'>
  162. <input type='hidden' name='current_student_id' value='$current_student_id'>
  163. <input type='hidden' name='did_search' value='true'>
  164. </form>
  165. ";
  166. return $rtn;
  167. }
  168. /**
  169. * Displays this user's advisees, if there are any assigned.
  170. */
  171. function student_search_display_my_advisees() {
  172. global $user;
  173. $rtn = "";
  174. $rtn .= student_search_get_advanced_search_tips();
  175. $_SESSION["student_search_last_tab"] = "my-advisees";
  176. $faculty_cwid = $user->cwid;
  177. $query = "SELECT u.user_id, f_name, u.cwid, l_name, major_code, rank_code, a.catalog_year
  178. FROM users u, students a, advisor_student c, student_degrees d
  179. WHERE
  180. c.faculty_id = :faculty_cwid
  181. AND c.student_id = a.cwid
  182. AND c.student_id = d.student_id
  183. AND u.cwid = a.cwid
  184. AND u.is_student = 1
  185. AND u.is_disabled = 0
  186. AND rank_code IN %RANKIN%
  187. %EXTRA_STUDENTSEARCH_CONDITIONS%
  188. GROUP BY u.cwid
  189. ORDER BY %ORDERBY%
  190. ";
  191. $adv_array = student_search_query_advisees($query, array(":faculty_cwid" => $faculty_cwid));
  192. $s = (count($adv_array) == 1) ? "" : "s";
  193. $rtn .= student_search_render_advisees($adv_array, t("My Advisees Results") . " &nbsp; ( " . count($adv_array) . " " . t("student$s") . " )");
  194. return $rtn;
  195. }
  196. /**
  197. * Basically, can the user see the "Advisees" tab at all?
  198. * The answer is TRUE if they have any of the permissions that let them do so.
  199. */
  200. function search_user_can_search_for_some_advisees() {
  201. if (user_has_permission("display_search_subtab")) return TRUE;
  202. if (user_has_permission("display_my_advisees_subtab")) return TRUE;
  203. if (user_has_permission("display_my_majors_subtab")) return TRUE;
  204. if (user_has_permission("display_majors_subtab")) return TRUE;
  205. return FALSE;
  206. }
  207. /**
  208. * Implementation of hook_perm
  209. *
  210. * @return unknown
  211. */
  212. function student_search_perm() {
  213. return array(
  214. "administer_student_search" => array(
  215. "title" => t("Administer Student Search"),
  216. "description" => t("Configure settings for the student search module."),
  217. ),
  218. "display_search_subtab" => array(
  219. "title" => t("Display Search subtab"),
  220. "description" => t("The user may view the Search subtab under the Advisees tab."),
  221. ),
  222. "display_my_advisees_subtab" => array(
  223. "title" => t("Display My Advisees subtab"),
  224. "description" => t("The user may view the My Advisees subtab under the Advisees tab."),
  225. ),
  226. "display_my_majors_subtab" => array(
  227. "title" => t("Display My Majors subtab"),
  228. "description" => t("The user may view the My Majors subtab under the Advisees tab."),
  229. ),
  230. "display_majors_subtab" => array(
  231. "title" => t("Display Majors subtab"),
  232. "description" => t("The user may view the Majors (search) subtab under the Advisees tab."),
  233. ),
  234. );
  235. }
  236. /**
  237. * Display the majors search sub-tab, where we can select a major and see the students
  238. * assigned to it.
  239. *
  240. */
  241. function student_search_display_majors_search() {
  242. global $user;
  243. $rtn = "";
  244. $_SESSION["student_search_last_tab"] = "majors-search";
  245. // Get the $major_code from the REQUEST, or from the user's saved settings.
  246. $major_code = trim(@$_REQUEST["major_code"]);
  247. if ($major_code == "") {
  248. // Get from their settings
  249. $major_code = db_get_user_setting($user->id, "major_search");
  250. }
  251. else {
  252. // They did set something in the post. Save it to their settings.
  253. db_set_user_setting($user->id, "major_search", $major_code);
  254. }
  255. $url = fp_url("student-search/majors-search");
  256. $rtn .= "
  257. <form method='POST' action='" . $url . "'
  258. class='major-search-form'>
  259. <label>" . t("Select an available major from the list below:") . "</label>
  260. <br><select name='major_code'>
  261. <option value=''>- " . t("Please Select") . " -</option>
  262. ";
  263. // Do we have any extra settings for this search?
  264. $current_catalog_year = variable_get("current_catalog_year", 2006);
  265. $cur_only = variable_get("student_search_major_search_cur_year", FALSE);
  266. $extra_line = "";
  267. $params = array();
  268. if ($cur_only == TRUE) {
  269. $extra_line = " AND catalog_year = :cur_cat_year ";
  270. $params[":cur_cat_year"] = $current_catalog_year;
  271. }
  272. $res = db_query("SELECT * FROM degrees
  273. WHERE exclude = '0'
  274. $extra_line
  275. GROUP BY major_code
  276. ORDER BY title
  277. ", $params);
  278. while ($cur = db_fetch_object($res)) {
  279. $sel = ($major_code == $cur->major_code) ? "selected" : "";
  280. $degree_class_details = fp_get_degree_classification_details($cur->degree_class);
  281. // Exclude major codes if they are "degree options", meaning, the code has an
  282. // underscore in it.
  283. if (strpos($cur->major_code, "_")) continue;
  284. // If the title is risking being too long, let's truncate it
  285. $title = $cur->title;
  286. $max_chars = 50;
  287. if (strlen($title) > $max_chars) {
  288. $title = trim(substr($title, 0, $max_chars)) . "...";
  289. }
  290. $rtn .= "<option value='$cur->major_code' $sel>$cur->major_code : $title ({$degree_class_details["title"]})</option>";
  291. }
  292. $rtn .= "
  293. </select>
  294. <input type='submit' value='" . t("Search") . "'>
  295. </form>";
  296. $rtn .= student_search_get_advanced_search_tips();
  297. // Update the query to search for exact major code.
  298. $query = "SELECT u.user_id, f_name, l_name, u.cwid, major_code, rank_code, a.catalog_year
  299. FROM users u, students a, student_degrees b
  300. WHERE
  301. major_code = :major_code
  302. AND u.cwid = a.cwid
  303. AND u.cwid = b.student_id
  304. AND u.is_student = 1
  305. AND u.is_disabled = 0
  306. AND rank_code IN %RANKIN%
  307. %EXTRA_STUDENTSEARCH_CONDITIONS%
  308. ORDER BY %ORDERBY%
  309. ";
  310. $adv_array = student_search_query_advisees($query, array(":major_code" => $major_code));
  311. $s = (count($adv_array) == 1) ? "" : "s";
  312. $rtn .= student_search_render_advisees($adv_array, t("Major @major Results", array("@major" => $major_code)) . " &nbsp; ( " . count($adv_array) . " " . t("student$s") . " )");
  313. return $rtn;
  314. }
  315. /**
  316. * Displays students belonging to the current user's major code.
  317. */
  318. function student_search_display_my_majors() {
  319. global $user;
  320. $rtn = "";
  321. $rtn .= student_search_get_advanced_search_tips();
  322. $_SESSION["student_search_last_tab"] = "my-majors";
  323. $adv_array = array();
  324. // Figure out this user's major_code from the faculty table.
  325. $db = get_global_database_handler();
  326. $faculty_user_major_code_csv = $db->get_faculty_major_code_csv($user->cwid);
  327. $temp = explode(",", $faculty_user_major_code_csv);
  328. foreach ($temp as $major_code) {
  329. $major_code = trim($major_code);
  330. if ($major_code == "") continue;
  331. $query = "SELECT u.user_id, f_name, l_name, u.cwid, major_code, rank_code, a.catalog_year
  332. FROM users u, students a, student_degrees b
  333. WHERE
  334. substring_index(major_code, '|', 1) = :major_code
  335. AND u.cwid = a.cwid
  336. AND u.cwid = b.student_id
  337. AND u.is_student = 1
  338. AND u.is_disabled = 0
  339. AND rank_code IN %RANKIN%
  340. %EXTRA_STUDENTSEARCH_CONDITIONS%
  341. GROUP BY u.cwid
  342. ORDER BY %ORDERBY%
  343. ";
  344. $adv_array = student_search_query_advisees($query, array(":major_code" => $major_code));
  345. $s = (count($adv_array) == 1) ? "" : "s";
  346. $rtn .= student_search_render_advisees($adv_array, t("Major @major Results", array("@major" => $major_code)) . " &nbsp; ( " . count($adv_array) . " " . t("student$s") . " )");
  347. }
  348. return $rtn;
  349. }
  350. function student_search_display_search() {
  351. $rtn = "";
  352. $_SESSION["student_search_last_tab"] = "search";
  353. $url = fp_url("student-search/search");
  354. $rtn .= "<table class='fp-semester-table'>
  355. <form id='mainform' name='mainform' method='post'
  356. action='" . $url . "' >
  357. ";
  358. // Get search results from POST -or- past search attempts
  359. // from the session.
  360. $search_for = trim(@$_REQUEST["search_for"]);
  361. if ($search_for == "") {
  362. $search_for = trim(@$_SESSION["student_search_for"]);
  363. }
  364. $o_search_for = $search_for;
  365. // If the user entered an asterisk with their search, we will
  366. // skip the extra search conditions (and show more results).
  367. $bool_bypass_extra_search_conditions = FALSE;
  368. if (strstr($search_for, "*")) {
  369. $bool_bypass_extra_search_conditions = TRUE;
  370. $search_for = trim(str_replace("*", "", $search_for));
  371. }
  372. // If the user entered an =, then remove all spaces from the query.
  373. if (strstr($search_for, "=")) {
  374. $search_for = trim(str_replace(" ", "", $search_for));
  375. }
  376. // remove trouble characters
  377. $search_for = str_replace("'","",$search_for);
  378. $search_for = str_replace('"','',$search_for);
  379. $isize = "25";
  380. // $screen variable is never initialized. Old code?
  381. //if ($screen->page_is_mobile) $isize = "10";
  382. $rtn .= "<tr><td valign='top'>
  383. <table style='text-align: left; width: 100%; height: 60px;'
  384. border='0' cellpadding='0' cellspacing='0'>
  385. <tr>
  386. <td width='30%' align='right'><font size='2'><b>" . t("Search for advisees:") . "&nbsp;&nbsp;</b></td>
  387. <td width='30%'><input name='search_for' ID='input_search_for' TYPE='text' SIZE='$isize' value='$o_search_for'></font>
  388. <input type='hidden' name='did_search' id='input_did_search' value='true'></td>
  389. <td class='tenpt'>";
  390. $rtn .= fp_render_button("Search","jQuery(\"#mainform\").submit();");
  391. $rtn .= "</td><td width='1'>
  392. </td></tr>
  393. </table>";
  394. $rtn .= student_search_get_advanced_search_tips();
  395. $adv_array = array();
  396. //Get my list of advisees...
  397. // This time, we want to specify an SQL statement that will perform
  398. // our search.
  399. $params = array();
  400. if($search_for != "" && strlen($search_for) > 2)
  401. { // If they typed something greater than 2 chars...
  402. $search_action = " AND (u.cwid LIKE :like_search_for
  403. OR l_name LIKE :like_search_for
  404. OR f_name LIKE :like_search_for )
  405. ";
  406. $params[":like_search_for"] = "%$search_for%";
  407. // If you searched for 2 things seperated by a space, it is likely you
  408. // are searching for a name, so check that...
  409. $_SESSION["student_search_for"] = $o_search_for;
  410. $temp = explode(" ",$search_for);
  411. if (trim(@$temp[1]) != "")
  412. {
  413. $fn = trim(@$temp[0]);
  414. $ln = trim(@$temp[1]);
  415. // If there was a comma, then these should be reversed,
  416. // as they probably entered last, first.
  417. if (strstr($search_for, ",")) {
  418. $ln = trim(@$temp[0]);
  419. $fn = trim(@$temp[1]);
  420. $ln = trim(str_replace(",", "", $ln)); // remove comma
  421. $fn = trim(str_replace(",", "", $fn)); // remove comma
  422. }
  423. $search_action = " AND (l_name LIKE :like_ln
  424. AND f_name LIKE :like_fn )
  425. ";
  426. $params[":like_ln"] = "%$ln%";
  427. $params[":like_fn"] = "%$fn%";
  428. // Remove unneeded like_search_for index.
  429. unset($params[":like_search_for"]);
  430. }
  431. $other_table = "";
  432. $major_search = "";
  433. $group_by = " GROUP BY u.cwid ";
  434. $temp = explode("=",$search_for);
  435. if (trim(strtolower($temp[0])) == "major")
  436. {
  437. $mjsearch = trim(@$temp[1]);
  438. $search_action = "";
  439. $other_table = ", degrees b";
  440. $major_search = " AND substring_index(c.major_code,'|',1) = b.major_code
  441. AND (b.major_code LIKE :like_mjsearch ) ";
  442. $params[":like_mjsearch"] = "%$mjsearch%";
  443. unset($params[':like_search_for']);
  444. }
  445. // Now THIS is odd... what is this strange piece of code here?
  446. // I'm no cryptographic genius, but it looks like it is set to display a message when
  447. // you search for "info=production" on the Advisees search tab...
  448. if (md5(strtolower(@$temp[1]))=="fd89784e59c72499525556f80289b2c7"){$rtn .= base64_decode("DQo8cD4NCjxiPlRoZSBvcmlnaW5hbCBGbGlnaHRQYXRoIFByb2R1Y3Rpb24gVGVhbSwgY2lyY2EgMjAwNywgYXQgVGhlIFVuaXZlcnNpdHkgb2YgTG91aXNpYW5hIGF0IE1vbnJvZTo8L2I+DQo8dWw+DQo8bGk+UmljaGFyZCBQZWFjb2NrIC0gUHJvamVjdCBsZWFkIGFuZCBwcmltYXJ5IGxvZ2ljIHByb2dyYW1tZXIuPC9saT4NCjxsaT5Kb2UgTWFuc291ciAtIERhdGFiYXNlIGFkbWluaXN0cmF0b3IgYW5kIG1haW5mcmFtZS9CYW5uZXIgZGF0YSBjb29yZGluYXRvci48L2xpPg0KPGxpPkpvYW5uIFBlcnJlciAtIERhdGEgZW50cnksIHRlc3RpbmcgYW5kIHNvZnR3YXJlIGNvb3JkaW5hdG9yLjwvbGk+DQo8bGk+UGF1bCBHdWxsZXR0ZSAtIENsYXNzaWMgdGhlbWUgZGVzaWduZXIuPC9saT4NCjxsaT48Yj5PdGhlciBjb250cmlidXRpbmcgcHJvZ3JhbW1lcnM8L2I+OiBDaGFybGVzIEZyb3N0LCBCcmlhbiBUYXlsb3IuPC9saT4NCjwvdWw+DQpUbyBldmVyeW9uZSB3aG8gaGVscGVkIG1ha2UgRmxpZ2h0UGF0aCBwb3NzaWJsZTogVGhhbmsgWW91Lg0KPC9wPg==");}
  449. $query = "SELECT u.user_id, f_name, l_name, u.cwid, rank_code, a.catalog_year
  450. FROM users u, students a, student_degrees c $other_table
  451. WHERE
  452. u.cwid = a.cwid
  453. AND u.cwid = c.student_id
  454. AND u.is_student = 1
  455. AND u.is_disabled = 0
  456. $search_action
  457. $major_search
  458. ";
  459. if (!$bool_bypass_extra_search_conditions) {
  460. $query .= "
  461. AND rank_code IN %RANKIN%
  462. %EXTRA_STUDENTSEARCH_CONDITIONS%
  463. ";
  464. }
  465. $query .= "
  466. $group_by
  467. ORDER BY %ORDERBY%
  468. LIMIT 300
  469. ";
  470. $adv_array = student_search_query_advisees($query, $params);
  471. }
  472. $s = (count($adv_array) == 1) ? "" : "s";
  473. // Are we showing the maximum number of students?
  474. if (count($adv_array) == 300) {
  475. $rtn .= "<div class='student-search-max-results'><em>" . t("Showing maximum 300 results. Please narrow search criteria.") . "</em></div>";
  476. }
  477. $rtn .= student_search_render_advisees($adv_array, t("Search Results") . " &nbsp; ( " . count($adv_array) . " " . t("student$s") . " )");
  478. $rtn .= "</form>";
  479. $rtn .= "</table>";
  480. return $rtn;
  481. }
  482. /**
  483. * Simply returns the HTML to display the "advanced search tips" collapsible fieldset
  484. * and instructions.
  485. *
  486. */
  487. function student_search_get_advanced_search_tips() {
  488. $rtn = "";
  489. // Display advanced tips
  490. $advanced_tips_html = "
  491. <div class='student-search-advanced-tips'>
  492. " . t("@FlightPath displays students who are currently enrolled or are newly admitted for
  493. an upcoming term. Use the following tips to expand your search options:", array("@FlightPath" => variable_get("system_name", "FlightPath"))) . "
  494. <ul>
  495. <li>" . t("To search for inactive students, as well as active, add an asterisk (*)
  496. after your search.
  497. <br>&nbsp; &nbsp; &nbsp;
  498. Ex: <em>smith*</em> &nbsp; &nbsp; or &nbsp; &nbsp; <em>10035744*</em>") . "
  499. </li>
  500. <li>" . t("Search by major by typing major=CODE in the search box.
  501. <br>&nbsp; &nbsp; &nbsp;
  502. Ex: <em>major=ENGL</em> &nbsp; &nbsp; or &nbsp; &nbsp; <em>major=ENGL*</em>") . "
  503. </li>
  504. </ul>
  505. </div>";
  506. $rtn .= "<div class='student-search-advanced-tips-wrapper'>
  507. <label>" . t("Can't find the student you're looking for?") . "</label>
  508. " . fp_render_c_fieldset($advanced_tips_html, t("View advanced search tips"), TRUE) . "
  509. </div>";
  510. return $rtn;
  511. }
  512. function student_search_render_advisees($adv_array, $title) {
  513. $rtn = "";
  514. fp_add_css(fp_get_module_path("student_search") . "/css/student_search.css");
  515. $bool_redirect_one = FALSE;
  516. if (count($adv_array) == 1 && @$_REQUEST["did_search"] == "true")
  517. {
  518. // Since there was only 1 result, we want to redirect this person directly.
  519. // Draw this person's name...
  520. $student_id = $adv_array[0]["student_id"];
  521. $first_name = $adv_array[0]["first_name"];
  522. $last_name = $adv_array[0]["last_name"];
  523. $rtn .= "<div class='hypo' style='border: 1px solid black;
  524. margin: 10px 0px 10px 0px; padding: 10px;
  525. font-size: 12pt; font-weight: bold;'>
  526. " .t("Loading") . " <span style='color:blue;'>$first_name $last_name</span> ($student_id).
  527. &nbsp; " . t("Please wait...") . "
  528. </div>";
  529. $bool_redirect_one = TRUE;
  530. }
  531. $rtn .= fp_render_curved_line($title);
  532. $rtn .= "<table width='100%' align='left'
  533. border='0' cellpadding='0' cellspacing='0'>
  534. ";
  535. // Do not show headers at all if mobile
  536. if (!fp_screen_is_mobile()) {
  537. $rtn .= "
  538. <tr>
  539. <td width='5%' valign='top'>&nbsp; </td>
  540. <td width='12%' valign='top' class='tenpt'><b>" . t("CWID") . "</b></td>
  541. <td width='15%' valign='top' class='tenpt'><b>" . t("First Name") . "</b></td>
  542. <td width='20%' valign='top' class='tenpt'><b>" . t("Last Name") . "</b></td>
  543. <td width='15%' valign='top' class='tenpt'><b>" . t("Major Code") . "</b></td>
  544. <td width='10%' valign='top' class='tenpt'><b>" . t("Rank") . "</b></td>
  545. <td width='15%' valign='top' class='tenpt'><b>" . t("Catalog Year") . "</b></td>
  546. </tr> ";
  547. }
  548. $rtn .= "
  549. ";
  550. $db = get_global_database_handler();
  551. for ($t = 0; $t < count($adv_array); $t++)
  552. {
  553. $student_id = $adv_array[$t]["student_id"];
  554. $first_name = $adv_array[$t]["first_name"];
  555. $last_name = $adv_array[$t]["last_name"];
  556. $major = $adv_array[$t]["major"];
  557. $advising_what_if = @$adv_array[$t]["advising_what_if"];
  558. $what_if_major_code = @$adv_array[$t]["what_if_major_code"];
  559. $what_if_track_code = @$adv_array[$t]["what_if_track_code"];
  560. $what_if_catalog_year = @$adv_array[$t]["what_if_catalog_year"];
  561. $degree_id = @$adv_array[$t]["degree_id"];
  562. $rank = @$adv_array[$t]["rank"];
  563. $catalog_year = @$adv_array[$t]["catalog_year"];
  564. // There is no $screen variable-- old code?
  565. //if ($screen->page_is_mobile) {
  566. // $catalog_year = get_shorter_catalog_year_range($catalog_year, false, true);
  567. //}
  568. $advising_session_id = $adv_array[$t]["advising_session_id"];
  569. $advised_image = $adv_array[$t]["advised_image"];
  570. //fpm($adv_array);
  571. /*
  572. $on_mouse = "onmouseover=\"style.backgroundColor='#FFFF99'\"
  573. onmouseout=\"style.backgroundColor='white'\"
  574. ";
  575. */
  576. $on_mouse = "
  577. onmouseover='$(this).addClass(\"selection_highlight\");'
  578. onmouseout='$(this).removeClass(\"selection_highlight\");'
  579. ";
  580. // No screen var defined. Old code?
  581. //if ($screen->page_is_mobile) $on_mouse = ""; // Causes problems on mobile devices.
  582. // Build up the URL we want to go to when we click this row.
  583. $path = "view";
  584. $advising_what_if = "no";
  585. if ($what_if_major_code != "") {
  586. $path = "what-if";
  587. $advising_what_if = "yes";
  588. }
  589. // Add in the query part.
  590. $query = "";
  591. $query .= "advising_student_id=$student_id&current_student_id=$student_id&advising_major_code=$major&advising_what_if=$advising_what_if";
  592. $query .= "&what_if_major_code=$what_if_major_code&what_if_track_code=$what_if_track_code&what_if_catalog_year=$what_if_catalog_year&advising_load_active=yes&clear_session=yes";
  593. $url = fp_url($path, $query);
  594. // old onCLick:
  595. //<!-- onClick='selectStudent(\"$student_id\",\"$major\",\"$what_if_major_code\",\"$what_if_track_code\")' -->
  596. $disp_major = "";
  597. $temp = csv_to_array($major);
  598. foreach ($temp as $code) {
  599. $csscode = fp_get_machine_readable($code);
  600. // Was this a track code or not? Meaning, did it contain |_
  601. $is_track = "no";
  602. if (strstr($code, "|_")) {
  603. $is_track = "yes";
  604. }
  605. $disp_major .= "<div class='ss-major-code ss-major-code-$csscode ss-major-code-is-track-$is_track'>$code</div>";
  606. }
  607. $rtn .= "
  608. <tr height='19'>
  609. <td colspan='7'>
  610. <table border='0'
  611. $on_mouse
  612. onClick='showUpdate(true); window.location=\"$url\"; '
  613. width='100%'
  614. class='student_search_advisee_results'>
  615. <tr height='20'>
  616. <td width='5%' class='ss-advised-image'>$advised_image</td>
  617. <td width='12%' class='ss-student-id'>$student_id</td>
  618. <td width='15%' class='ss-student-fn'>$first_name</td>
  619. <td width='20%' class='ss-student-ln'>$last_name</td>
  620. <td width='15%' class='ss-student-major'>$disp_major</td>
  621. <td width='10%' class='ss-student-rank'>$rank</td>
  622. <td width='15%' class='ss-student-catalog-year'>$catalog_year</td>
  623. </tr>
  624. </table>
  625. </td>
  626. </tr>
  627. ";
  628. } // for t advisee array
  629. $rtn .= "</table>";
  630. if ($bool_redirect_one) {
  631. // There was only one result, and it was a search, so we want to redirect
  632. // this person.
  633. // We will use the URL we created in the foreach loop above. It will still contain exactly
  634. // what we need.
  635. $rtn .= "<script type='text/javascript'>
  636. $(document).ready(function() {
  637. setTimeout('window.location=\"$url\";', 0);
  638. });
  639. </script>";
  640. }
  641. // Required to make the changeTab function work...
  642. $rtn .= "<form id='mainform' method='POST'>
  643. <input type='hidden' id='scrollTop'>
  644. <input type='hidden' id='performAction' name='performAction'>
  645. <input type='hidden' id='advisingWhatIf' name='advisingWhatIf'>
  646. <input type='hidden' id='currentStudentID' name='currentStudentID'>
  647. <input type='hidden' id='advisingStudentID' name='advisingStudentID'>
  648. <input type='hidden' id='advisingMajorCode' name='advisingMajorCode'>
  649. <input type='hidden' id='whatIfMajorCode' name='whatIfMajorCode'>
  650. <input type='hidden' id='whatIfTrackCode' name='whatIfTrackCode'>
  651. <input type='hidden' id='advisingLoadActive' name='advisingLoadActive'>
  652. <input type='hidden' id='clearSession' name='clearSession'>
  653. </form>";
  654. //// IMPORTANT///////////
  655. $rtn .= "&nbsp;"; // Not sure why, but adding this to the end fixes a display bug in Chrome, so I'm going to leave it here.
  656. ///////////////////
  657. return $rtn;
  658. }
  659. /**
  660. * Accepts the SQL, plus an array of parameters compatible with our PDO set up.
  661. * ex:
  662. * $params[":name"] = "Bob"
  663. * and $sql = " SELECT * where name = :name";
  664. *
  665. */
  666. function student_search_query_advisees($sql, $params = array()) {
  667. $db = get_global_database_handler();
  668. $rank_in = "( '" . join("', '", csv_to_array($GLOBALS["fp_system_settings"]["allowed_student_ranks"])) . "' )";
  669. $order_by = " l_name, f_name ";
  670. // Replace the replacement portion with our derrived variables.
  671. $sql = str_replace("%RANKIN%", $rank_in, $sql);
  672. $sql = str_replace("%ORDERBY%", $order_by, $sql);
  673. // By default, the extra_studentsearch_conditions will be checking of is_active = 1. But, the user may override this
  674. // in the settings.
  675. $extra_student_search_conditions = variable_get("extra_student_search_conditions", " AND is_active = 1 ");
  676. $sql = str_replace("%EXTRA_STUDENTSEARCH_CONDITIONS%", $extra_student_search_conditions, $sql);
  677. // Returns an array of all of this teacher's advisees.
  678. $rtn_array = array();
  679. $r = 0;
  680. $faculty_advisees = advise_get_advisees();
  681. $result = db_query($sql, $params);
  682. while ($cur = db_fetch_array($result))
  683. {
  684. $student_id = trim($cur["cwid"]);
  685. // If this user does NOT have the "view any advising session" and DOES have the "view advisee advising sessions only",
  686. // then see if this student is in their advisees list before continuing.
  687. if (!user_has_permission("view_any_advising_session") && user_has_permission("view_advisee_advising_session")) {
  688. if (!in_array($student_id, $faculty_advisees)) {
  689. // Nope, this student is NOT one of their advisees! Skip it.
  690. continue;
  691. }
  692. }
  693. $rtn_array[$r]["student_id"] = $student_id;
  694. $rtn_array[$r]["first_name"] = ucwords(strtolower($cur["f_name"]));
  695. $rtn_array[$r]["last_name"] = ucwords(strtolower($cur["l_name"]));
  696. $rtn_array[$r]["rank"] = $cur["rank_code"];
  697. $rtn_array[$r]["catalog_year"] = $cur["catalog_year"];
  698. //$rtn_array[$r]["major"] = $cur["major_code"];
  699. // Need to get the major_code_csv for this student.
  700. // Are there more majors for this user?
  701. $major = "";
  702. // Get a CSV of this student's majors
  703. $major = fp_get_student_majors($student_id, TRUE, FALSE, FALSE);
  704. $rtn_array[$r]["major"] = $major;
  705. // We should also mark if the student has been advised for this semester
  706. // or not.
  707. // Get the current default advising term id.
  708. $term_id = variable_get("advising_term_id", "");
  709. $advised_image = "&nbsp;";
  710. $advising_session_id = "";
  711. $res2 = db_query("SELECT * FROM advising_sessions WHERE
  712. student_id = ? AND
  713. term_id = ?
  714. AND is_draft = 0
  715. AND is_empty = 0
  716. ORDER BY posted DESC", $student_id, $term_id);
  717. if (db_num_rows($res2) > 0) {
  718. $cur = db_fetch_array($res2);
  719. $advised_image = "<img src='" . fp_theme_location() . "/images/small_check.gif' class='advisedImage'>";
  720. if ($cur["is_whatif"] == "1")
  721. { // Last advising was a What If advising.
  722. $advised_image = "<span title='This student was last advised in What If mode.'><img src='" . fp_theme_location() . "/images/small_check.gif'><sup>wi</sup></span>";
  723. $db_major_code_csv = $cur["major_code_csv"];
  724. $rtn_array[$r]["what_if_major_code"] = $db_major_code_csv;
  725. // Capture the catalog year that was saved with what_if
  726. $rtn_array[$r]["what_if_catalog_year"] = $cur["catalog_year"];
  727. $rtn_array[$r]["last_advised_what_if"] = TRUE;
  728. }
  729. }
  730. $rtn_array[$r]["advising_session_id"] = $advising_session_id;
  731. $rtn_array[$r]["advised_image"] = $advised_image;
  732. $r++;
  733. }
  734. return $rtn_array;
  735. }

Functions

Namesort descending Description
search_user_can_search_for_some_advisees Basically, can the user see the "Advisees" tab at all? The answer is TRUE if they have any of the permissions that let them do so.
student_search_display_majors_search Display the majors search sub-tab, where we can select a major and see the students assigned to it.
student_search_display_my_advisees Displays this user's advisees, if there are any assigned.
student_search_display_my_majors Displays students belonging to the current user's major code.
student_search_display_search
student_search_get_advanced_search_tips Simply returns the HTML to display the "advanced search tips" collapsible fieldset and instructions.
student_search_menu
student_search_perm Implementation of hook_perm
student_search_query_advisees Accepts the SQL, plus an array of parameters compatible with our PDO set up. ex: $params[":name"] = "Bob" and $sql = " SELECT * where name = :name";
student_search_render_advisees
student_search_render_small_search This is meant to be called directly from the theme template, to draw the small search box in the corner of the screen.
student_search_settings_form This is a system_settings form for configuring our module.
student_search_subtab_switchboard The primary purpose of this function is to decide which "sub tab" function to send the user off to. This is based on whatever their previous selection was.