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. /**
  3. * Meant to return results of the ajax autocomplete field, for selecting a student by name or cwid.
  4. * Code inspiration from: https://www.drupal.org/node/854216
  5. *
  6. * Output format can be: default, cwid_pound_name
  7. * default = First Last (CWID)
  8. * cwid_pound_name = CWID # First Last
  9. *
  10. */
  11. function student_search_ajax_autocomplete_student($output_format = "default") {
  12. $term = $_GET['term']; // this is what the user is starting to type.
  13. // actually search based on this term. make use of the studentsearch module
  14. // Use the student_search module to query based on what we've typed so far.
  15. $_REQUEST["search_for"] = $term;
  16. $form = student_search_search_form(5); // limit to only 5 results.
  17. $matches = array();
  18. // Result will be in $form['adv_array']['value'];
  19. //watchdog('debug', pretty_print($form['adv_array']['value'], TRUE));
  20. $adv_array = $form['adv_array']['value'];
  21. if (is_array($adv_array)) {
  22. foreach ($adv_array as $cwid => $details) {
  23. $line = "";
  24. if ($output_format == 'cwid_pound_name') {
  25. // Output like: 12345 # first last
  26. $line = "$cwid # " . $details['first_name'] . " " . $details['last_name'];
  27. }
  28. else {
  29. // default
  30. $line = $details['first_name'] . " " . $details['last_name'] . " ($cwid)";
  31. }
  32. $matches[] = $line;
  33. }
  34. }
  35. header('Content-Type: application/json');
  36. print json_encode($matches);
  37. die;
  38. }
  39. function student_search_menu() {
  40. $items = array();
  41. $items["admin/config/student-search-settings"] = array(
  42. "title" => "Student Search settings",
  43. "description" => "Configure settings for the Student Search function",
  44. "page_callback" => "fp_render_form",
  45. "page_arguments" => array("student_search_settings_form", "system_settings"),
  46. "access_arguments" => array("administer_student_search"),
  47. "page_settings" => array(
  48. "menu_icon" => fp_get_module_path('student_search') . "/icons/database_gear.png",
  49. "page_hide_report_error" => TRUE,
  50. "menu_links" => array(
  51. 0 => array(
  52. "text" => "Admin Console",
  53. "path" => "admin-tools/admin",
  54. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  55. ),
  56. ),
  57. ),
  58. "type" => MENU_TYPE_NORMAL_ITEM,
  59. "tab_parent" => "admin-tools/admin",
  60. );
  61. $items['student-search/autocomplete-student/%'] = array(
  62. 'page_callback' => 'student_search_ajax_autocomplete_student',
  63. 'page_arguments' => array(2),
  64. 'access_arguments' => array('access_logged_in_content'),
  65. 'type' => MENU_TYPE_CALLBACK,
  66. );
  67. $items["student-search"] = array(
  68. "title" => t("Advisees"),
  69. "page_callback" => "student_search_subtab_switchboard",
  70. "access_callback" => "search_user_can_search_for_some_advisees",
  71. "type" => MENU_TYPE_NORMAL_ITEM,
  72. "weight" => 20,
  73. );
  74. $items["student-select"] = array(
  75. "page_callback" => "student_search_student_select_switchboard",
  76. "access_callback" => "search_user_can_search_for_some_advisees",
  77. "type" => MENU_TYPE_NORMAL_ITEM,
  78. "weight" => 20,
  79. );
  80. $items["student-search/my-advisees"] = array(
  81. "title" => t("My Advisees"),
  82. "page_callback" => "student_search_display_my_advisees",
  83. "access_arguments" => array("display_my_advisees_subtab"),
  84. "type" => MENU_TYPE_TAB,
  85. "tab_family" => "student_search",
  86. "page_settings" => array (
  87. "screen_mode" => "not_advising",
  88. ),
  89. "weight" => 10,
  90. );
  91. $items["student-search/search"] = array(
  92. "title" => t("Search"),
  93. "page_callback" => "fp_render_form",
  94. "page_arguments" => array("student_search_search_form"),
  95. "access_arguments" => array("display_search_subtab"),
  96. "type" => MENU_TYPE_TAB,
  97. "tab_family" => "student_search",
  98. "page_settings" => array (
  99. "screen_mode" => "not_advising",
  100. "page_has_search" => TRUE,
  101. ),
  102. "weight" => 30,
  103. );
  104. return $items;
  105. }
  106. /**
  107. * The user has selected a student (clicked on a row) from the Search or My Advisees screen.
  108. *
  109. * We now decide where the user is sent to, based on their settings.
  110. * Ex: Do they go to the Student Profile page, do they go to the Degree tab, etc?
  111. */
  112. function student_search_student_select_switchboard() {
  113. // As in the advise_display_view, we need to "initialize" this student fresh...
  114. global $user, $fp, $degree_plan, $screen, $current_student_id;
  115. // Do we need to rebuild the course inventory cache?
  116. if (system_check_course_inventory_should_be_reloaded()) {
  117. system_reload_and_cache_course_inventory();
  118. }
  119. $GLOBALS["fp_advising"]["advising_what_if"] = "no";
  120. $_REQUEST["advising_what_if"] = "no";
  121. // Initialize everything we need to initialize for this advising session.
  122. advise_init_screen();
  123. $_SESSION["last_student_selected"] = $current_student_id;
  124. // At this point, we decide where they are going to be redirected to, using fp_goto.
  125. $goto_tab = @$user->settings['default_student_load_tab'];
  126. if (!$goto_tab || $goto_tab == "") {
  127. // No specific setting, so use the system's default setting.
  128. $goto_tab = variable_get('system_default_student_load_tab', 'profile');
  129. }
  130. ////////////////////////
  131. if ($goto_tab == "profile") {
  132. fp_goto("student-profile");
  133. }
  134. if ($goto_tab == 'engagements') {
  135. fp_goto("engagements");
  136. }
  137. if ($goto_tab == "degree") {
  138. // Do we mean their normal "view" URL, or do we mean What If?
  139. $query = "";
  140. $path = "view";
  141. if (@$_REQUEST['what_if_major_code'] != "") {
  142. $path = "what-if";
  143. //&what_if_major_code=$what_if_major_code&what_if_track_code=$what_if_track_code&what_if_catalog_year=$what_if_catalog_year
  144. $query = "what_if_major_code=" . $_REQUEST['what_if_major_code'] . "&what_if_track_code=" . $_REQUEST['what_if_track_code'] . "&what_if_catalog_year=" . $_REQUEST['what_if_catalog_year'];
  145. }
  146. fp_goto($path, $query);
  147. }
  148. return "";
  149. }
  150. /**
  151. * This is a system_settings form for configuring our module.
  152. *
  153. */
  154. function student_search_settings_form() {
  155. $form = array();
  156. $form["extra_student_search_conditions"] = array(
  157. "type" => "textarea",
  158. "label" => t("Extra student search conditions:"),
  159. "value" => variable_get("extra_student_search_conditions", ""),
  160. "description" => t("This is mysql which will get appended to end of the WHERE clause of every query
  161. relating to searching for students. It is so you can easily add global conditions,
  162. especially if you are overriding the student_search module. For example,
  163. to check that the students are admitted or enrolled. If you are unsure what to do, leave this blank."),
  164. );
  165. // TODO: This setting isn't really necessary anymore. We should just add is_active = 1 to the stats/report that uses it.
  166. $form["enrolled_student_search_conditions"] = array(
  167. "type" => "textarea",
  168. "label" => t("Enrolled student search conditions:"),
  169. "value" => variable_get("enrolled_student_search_conditions", " AND is_active = 1 "),
  170. "description" => t("<b>Soon to be deprecated.</b> Similar to the one above it, this is a clause which will only bring up students
  171. who are enrolled at the university, and taking courses. This might be identical to the
  172. one above it. At the moment, this is only being used in the Stats module, and not
  173. for any logic in FlightPath, so you should consider it optional.
  174. <br>Default is: AND is_active = 1 "),
  175. );
  176. return $form;
  177. }
  178. /**
  179. * The primary purpose of this function is to decide which
  180. * "sub tab" function to send the user off to. This is based
  181. * on whatever their previous selection was.
  182. */
  183. function student_search_subtab_switchboard() {
  184. $last_tab = $_SESSION["student_search_last_tab"];
  185. if ($last_tab == "") {
  186. $last_tab = 'search';
  187. // TODO: If the user has a setting for this, use that instead.
  188. }
  189. fp_goto("student-search/$last_tab");
  190. }
  191. /**
  192. * This is meant to be called directly from the theme template, to draw
  193. * the small search box in the corner of the screen.
  194. *
  195. * As such, we need to include any javascript we need here, rather than using
  196. * fp_add_js.
  197. */
  198. function student_search_render_small_search() {
  199. global $current_student_id;
  200. $rtn = "";
  201. $url = fp_url("student-search/search");
  202. $rtn .= "<form action='" . $url . "' method='post' id='small-search-form' >
  203. <input type='text' class='smallinput' name='search_for' id='search_bar_value' autocomplete='off' placeholder = '" . t("Search students by name or CWID") . "'>
  204. <a href='javascript:void(0);' class='small-search-submit' onClick='this.closest(\"form\").submit();'><i class='fa fa-search'></i></a>
  205. <input type='hidden' name='current_student_id' value='$current_student_id'>
  206. <input type='hidden' name='did_search' value='true'>
  207. </form>
  208. ";
  209. return $rtn;
  210. }
  211. /**
  212. * Displays this user's advisees, if there are any assigned.
  213. */
  214. function student_search_display_my_advisees($bool_only_return_adv_array = FALSE, $use_cwid = NULL, $force_school_id = NULL, $limit = 20) {
  215. global $user, $pager_total_items;
  216. $rtn = "";
  217. fp_set_title('');
  218. $_SESSION["student_search_last_tab"] = "my-advisees";
  219. if ($use_cwid == NULL) {
  220. $faculty_cwid = $user->cwid;
  221. }
  222. else {
  223. $faculty_cwid = $use_cwid;
  224. }
  225. // Get all the school ids this user is allowed to search.
  226. $school_ids = student_search_get_school_ids_user_is_allowed_to_search();
  227. $school_id_list = join(",", $school_ids);
  228. if ($force_school_id != NULL) $school_id_list = intval($force_school_id);
  229. $query = "SELECT u.user_id, f_name, u.cwid, l_name, major_code, rank_code, a.catalog_year, priority_value, u.school_id
  230. FROM (users u, students a, advisor_student c, student_degrees d)
  231. LEFT JOIN student_priority ON (student_priority.student_id = u.cwid)
  232. WHERE
  233. c.faculty_id = :faculty_cwid
  234. AND c.student_id = a.cwid
  235. AND c.student_id = d.student_id
  236. AND u.cwid = a.cwid
  237. AND u.school_id IN ($school_id_list)
  238. AND u.is_student = 1
  239. AND u.is_disabled = 0
  240. AND rank_code IN %RANKIN%
  241. %EXTRA_STUDENTSEARCH_CONDITIONS%
  242. GROUP BY u.cwid
  243. %ORDERBY%
  244. ";
  245. $adv_array = student_search_query_advisees($query, array(":faculty_cwid" => $faculty_cwid), $limit, $bool_only_return_adv_array);
  246. if ($bool_only_return_adv_array) return $adv_array;
  247. $s = (count($adv_array) == 1) ? "" : "s";
  248. $rtn .= "<div class='student-search-my-advisees'>" . student_search_render_advisees($adv_array, t("My Advisees Results") . " &nbsp; ({$pager_total_items[0]} " . t("student$s") . ")") . "</div>";
  249. return $rtn;
  250. }
  251. /**
  252. * Basically, can the user see the "Advisees" tab at all?
  253. * The answer is TRUE if they have any of the permissions that let them do so.
  254. */
  255. function search_user_can_search_for_some_advisees() {
  256. if (user_has_permission("display_search_subtab")) return TRUE;
  257. if (user_has_permission("display_my_advisees_subtab")) return TRUE;
  258. return FALSE;
  259. }
  260. /**
  261. * Implementation of hook_perm
  262. *
  263. * @return unknown
  264. */
  265. function student_search_perm() {
  266. return array(
  267. "administer_student_search" => array(
  268. "title" => t("Administer Student Search"),
  269. "description" => t("Configure settings for the student search module."),
  270. ),
  271. "display_search_subtab" => array(
  272. "title" => t("Display Search subtab"),
  273. "description" => t("The user may view the Search subtab under the Advisees tab."),
  274. ),
  275. "display_my_advisees_subtab" => array(
  276. "title" => t("Display My Advisees subtab"),
  277. "description" => t("The user may view the My Advisees subtab under the Advisees tab."),
  278. ),
  279. /*
  280. "display_my_majors_subtab" => array(
  281. "title" => t("Display My Majors subtab"),
  282. "description" => t("The user may view the My Majors subtab under the Advisees tab."),
  283. ),
  284. "display_majors_subtab" => array(
  285. "title" => t("Display Majors subtab"),
  286. "description" => t("The user may view the Majors (search) subtab under the Advisees tab."),
  287. ),
  288. *
  289. */
  290. );
  291. }
  292. function student_search_get_school_ids_user_is_allowed_to_search($account = NULL) {
  293. global $user;
  294. if ($account == NULL) $account = $user;
  295. $rtn = array();
  296. $rtn[] = intval($account->school_id);
  297. // Go through permissions for what we are allowed to search
  298. if (module_enabled("schools")) {
  299. $defs = schools_get_school_definitions();
  300. foreach ($defs as $school_id => $name) {
  301. if (user_has_permission("search_students_$school_id")) {
  302. if (!in_array(intval($school_id), $rtn)) {
  303. $rtn[] = intval($school_id);
  304. }
  305. }
  306. }
  307. }
  308. if (!in_array(0, $rtn)) {
  309. $rtn[] = 0;
  310. }
  311. return $rtn;
  312. }
  313. /**
  314. * Returns an array of majors from the database, suitable for use with our Form API.
  315. */
  316. function student_search_get_majors_for_fapi() {
  317. global $user;
  318. $rtn = array();
  319. $extra_line = "";
  320. // Get all the school ids this user is allowed to search.
  321. $school_ids = student_search_get_school_ids_user_is_allowed_to_search();
  322. $school_id_list = join(",", $school_ids);
  323. $params = array();
  324. // Removing "group by major_code" line, as duplicate major codes in more than one school were not showing correctly in the select list.
  325. $res = db_query("SELECT * FROM degrees
  326. WHERE exclude = 0
  327. AND school_id IN ($school_id_list)
  328. $extra_line
  329. ORDER BY school_id, title
  330. ", $params);
  331. while ($cur = db_fetch_object($res)) {
  332. $degree_class_details = fp_get_degree_classification_details($cur->degree_class);
  333. // Exclude major codes if they are "degree options", meaning, the code has an
  334. // underscore in it.
  335. if (strpos($cur->major_code, "_")) continue;
  336. // If the title is risking being too long, let's truncate it
  337. $title = $cur->title;
  338. $max_chars = 50;
  339. if (strlen($title) > $max_chars) {
  340. $title = trim(substr($title, 0, $max_chars)) . "...";
  341. }
  342. $school_name = "";
  343. if (module_enabled("schools")) {
  344. $school_name = schools_get_school_name_for_id($cur->school_id);
  345. // Getting fancy. We are going to have optgroup in this set of options.
  346. $rtn[$school_name][$cur->major_code . "~~school_" . $cur->school_id] = "$cur->major_code : $title ({$degree_class_details["title"]})";
  347. }
  348. else {
  349. $rtn[$cur->major_code . "~~school_" . $cur->school_id] = "$cur->major_code : $title ({$degree_class_details["title"]})";
  350. }
  351. }
  352. return $rtn;
  353. }
  354. /**
  355. * Display the majors search sub-tab, where we can select a major and see the students
  356. * assigned to it.
  357. *
  358. */
  359. function student_search_display_majors_search($limit = 20) {
  360. global $user;
  361. $rtn = "";
  362. $_SESSION["student_search_last_tab"] = "majors-search";
  363. // Get the $major_code from the REQUEST, or from the user's saved settings.
  364. $major_code = trim(@$_REQUEST["major_code"]);
  365. if ($major_code == "") {
  366. // Get from their settings
  367. $major_code = db_get_user_setting($user->id, "major_search");
  368. }
  369. else {
  370. // They did set something in the post. Save it to their settings.
  371. db_set_user_setting($user->id, "major_search", $major_code);
  372. }
  373. $url = fp_url("student-search/majors-search");
  374. $rtn .= "
  375. <form method='POST' action='" . $url . "'
  376. class='major-search-form'>
  377. <label>" . t("Select an available major from the list below:") . "</label>
  378. <br><select name='major_code'>
  379. <option value=''>- " . t("Please Select") . " -</option>
  380. ";
  381. // Do we have any extra settings for this search?
  382. $current_catalog_year = variable_get("current_catalog_year", 2006);
  383. $cur_only = variable_get("student_search_major_search_cur_year", FALSE);
  384. $extra_line = "";
  385. $params = array();
  386. if ($cur_only == TRUE) {
  387. $extra_line = " AND catalog_year = :cur_cat_year ";
  388. $params[":cur_cat_year"] = $current_catalog_year;
  389. }
  390. $res = db_query("SELECT * FROM degrees
  391. WHERE exclude = '0'
  392. $extra_line
  393. GROUP BY major_code
  394. ORDER BY title
  395. ", $params);
  396. while ($cur = db_fetch_object($res)) {
  397. $sel = ($major_code == $cur->major_code) ? "selected" : "";
  398. $degree_class_details = fp_get_degree_classification_details($cur->degree_class);
  399. // Exclude major codes if they are "degree options", meaning, the code has an
  400. // underscore in it.
  401. if (strpos($cur->major_code, "_")) continue;
  402. // If the title is risking being too long, let's truncate it
  403. $title = $cur->title;
  404. $max_chars = 50;
  405. if (strlen($title) > $max_chars) {
  406. $title = trim(substr($title, 0, $max_chars)) . "...";
  407. }
  408. $rtn .= "<option value='$cur->major_code' $sel>$cur->major_code : $title ({$degree_class_details["title"]})</option>";
  409. }
  410. $rtn .= "
  411. </select>
  412. <input type='submit' value='" . t("Search") . "'>
  413. </form>";
  414. $rtn .= student_search_get_advanced_search_tips();
  415. // Update the query to search for exact major code.
  416. $query = "SELECT u.user_id, f_name, l_name, u.cwid, major_code, rank_code, a.catalog_year
  417. FROM users u, students a, student_degrees b
  418. WHERE
  419. major_code = :major_code
  420. AND u.cwid = a.cwid
  421. AND u.cwid = b.student_id
  422. AND u.is_student = 1
  423. AND u.is_disabled = 0
  424. AND rank_code IN %RANKIN%
  425. %EXTRA_STUDENTSEARCH_CONDITIONS%
  426. ORDER BY %ORDERBY%
  427. ";
  428. $adv_array = student_search_query_advisees($query, array(":major_code" => $major_code), $limit);
  429. $s = (count($adv_array) == 1) ? "" : "s";
  430. $rtn .= student_search_render_advisees($adv_array, t("Major @major Results", array("@major" => $major_code)) . " &nbsp; ( " . count($adv_array) . " " . t("student$s") . " )");
  431. return $rtn;
  432. }
  433. /**
  434. * Displays students belonging to the current user's major code.
  435. */
  436. function student_search_display_my_majors() {
  437. global $user;
  438. $rtn = "";
  439. $_SESSION["student_search_last_tab"] = "my-majors";
  440. $adv_array = array();
  441. // Figure out this user's major_code from the faculty table.
  442. $db = get_global_database_handler();
  443. $faculty_user_major_code_csv = $db->get_faculty_major_code_csv($user->cwid);
  444. $temp = explode(",", $faculty_user_major_code_csv);
  445. foreach ($temp as $major_code) {
  446. $major_code = trim($major_code);
  447. if ($major_code == "") continue;
  448. $query = "SELECT u.user_id, f_name, l_name, u.cwid, major_code, rank_code, a.catalog_year
  449. FROM users u, students a, student_degrees b
  450. WHERE
  451. substring_index(major_code, '|', 1) = :major_code
  452. AND u.cwid = a.cwid
  453. AND u.cwid = b.student_id
  454. AND u.is_student = 1
  455. AND u.is_disabled = 0
  456. AND rank_code IN %RANKIN%
  457. %EXTRA_STUDENTSEARCH_CONDITIONS%
  458. GROUP BY u.cwid
  459. %ORDERBY%
  460. ";
  461. $adv_array = student_search_query_advisees($query, array(":major_code" => $major_code));
  462. $s = (count($adv_array) == 1) ? "" : "s";
  463. $rtn .= student_search_render_advisees($adv_array, t("Major @major Results", array("@major" => $major_code)) . " &nbsp; ( " . count($adv_array) . " " . t("student$s") . " )");
  464. }
  465. return $rtn;
  466. }
  467. function student_search_search_form() {
  468. $form = array();
  469. global $pager_total_items;
  470. fp_add_css(fp_get_module_path("student_search") . "/css/student_search.css");
  471. // Keep up with our last-visited tab
  472. $_SESSION["student_search_last_tab"] = "search";
  473. fp_set_title('');
  474. $search_for = trim(@$_REQUEST["search_for"]);
  475. if ($search_for == "") {
  476. $search_for = trim(@$_SESSION["student_search_for"]);
  477. }
  478. else {
  479. $_SESSION['student_search_for'] = $search_for;
  480. }
  481. $o_search_for = $search_for;
  482. $major_code = trim(@$_REQUEST["major_code"]);
  483. if ($major_code == "") {
  484. $major_code = trim(@$_SESSION["student_search_major_code"]);
  485. }
  486. $selected_school_id = -1;
  487. $o_major_code = "";
  488. if ($major_code != "") {
  489. $o_major_code = $major_code;
  490. $temp = explode("~~school_", $major_code);
  491. $major_code = $temp[0];
  492. if (isset($temp[1])) {
  493. $selected_school_id = intval($temp[1]);
  494. }
  495. }
  496. $form['search_for'] = array(
  497. 'label' => t('Search for students by name or CWID:'),
  498. 'type' => 'search',
  499. 'value' => $o_search_for,
  500. );
  501. // Also show the majors as a list.
  502. $options = array('' => t(" - All Majors -")) + student_search_get_majors_for_fapi();
  503. $form['major_code'] = array(
  504. 'label' => t('Search within major:'),
  505. 'type' => 'select',
  506. 'options' => $options,
  507. 'value' => $o_major_code,
  508. 'hide_please_select' => TRUE,
  509. );
  510. $form['submit_btn'] = array(
  511. 'type' => 'submit',
  512. 'value' => t("Search"),
  513. );
  514. $form['reset_btn'] = array(
  515. 'type' => 'submit',
  516. 'value' => t("Reset"),
  517. );
  518. $search_options = @$_SESSION["student_search_search_options"];
  519. $form['search_options'] = array(
  520. 'label' => 'Options:',
  521. 'type' => 'checkboxes',
  522. 'options' => array('inactive' => t('Include inactive students')),
  523. 'value' => $search_options,
  524. );
  525. /////////////////////////////////////////
  526. // Logic to query for searched students
  527. /////////////////////////////////////////
  528. $mark = "";
  529. // If the user entered an asterisk with their search, we will
  530. // skip the extra search conditions (and show more results).
  531. $bool_bypass_extra_search_conditions = FALSE;
  532. if (strstr($search_for, "*")) {
  533. $bool_bypass_extra_search_conditions = TRUE;
  534. $search_for = trim(str_replace("*", "", $search_for));
  535. }
  536. // If the user entered an =, then remove all spaces from the query.
  537. if (strstr($search_for, "=")) {
  538. $search_for = trim(str_replace(" ", "", $search_for));
  539. }
  540. // remove trouble characters
  541. $search_for = str_replace("'","",$search_for);
  542. $search_for = str_replace('"','',$search_for);
  543. $search_action = '';
  544. $adv_array = array();
  545. //Get my list of advisees...
  546. // This time, we want to specify an SQL statement that will perform
  547. // our search.
  548. $params = array();
  549. if(strlen($search_for) > 2 || $major_code != "")
  550. { // If they typed something greater than 2 chars...
  551. if ($search_for) {
  552. $search_action = " AND (u.cwid LIKE :like_search_for1
  553. OR l_name LIKE :like_search_for2
  554. OR f_name LIKE :like_search_for3 )
  555. ";
  556. $params[":like_search_for1"] = "%$search_for%";
  557. $params[":like_search_for2"] = "%$search_for%";
  558. $params[":like_search_for3"] = "%$search_for%";
  559. $temp = explode(" ",$search_for);
  560. if (trim(@$temp[1]) != "")
  561. {
  562. $fn = trim(@$temp[0]);
  563. $ln = trim(@$temp[1]);
  564. // If there was a comma, then these should be reversed,
  565. // as they probably entered last, first.
  566. if (strstr($search_for, ",")) {
  567. $ln = trim(@$temp[0]);
  568. $fn = trim(@$temp[1]);
  569. $ln = trim(str_replace(",", "", $ln)); // remove comma
  570. $fn = trim(str_replace(",", "", $fn)); // remove comma
  571. }
  572. $search_action = " AND (l_name LIKE :like_ln
  573. AND f_name LIKE :like_fn )
  574. ";
  575. $params[":like_ln"] = "%$ln%";
  576. $params[":like_fn"] = "%$fn%";
  577. // Remove unneeded like_search_for index.
  578. unset($params[":like_search_for1"]);
  579. unset($params[":like_search_for2"]);
  580. unset($params[":like_search_for3"]);
  581. }
  582. }
  583. $other_table = "";
  584. $major_search = "";
  585. if ($major_code != "")
  586. {
  587. $mjsearch = $major_code;
  588. $other_table = ", degrees b";
  589. $major_search = " AND substring_index(c.major_code,'|',1) = b.major_code
  590. AND b.school_id = :b_school_id
  591. AND (b.major_code LIKE :like_mjsearch ) ";
  592. $params[":like_mjsearch"] = "%$mjsearch%";
  593. $params[":b_school_id"] = $selected_school_id;
  594. //unset($params[':like_search_for']);
  595. }
  596. $group_by = " GROUP BY u.cwid ";
  597. ///////////////////////////////////////
  598. // Now THIS is odd... what is this strange piece of code here?
  599. // I'm no cryptographic genius, but it looks like it is set to display a message when
  600. // you search for "info=production" on the Students search...
  601. if (hash('sha256', (strtolower(@$search_for)))=="5b260fa2e077d779082ce7e5e7869554a7be02d537ae235a61a4387a9c853981"){
  602. $mark .= base64_decode("PHA+CjxiPlRoZSBvcmlnaW5hbCBGbGlnaHRQYXRoIFByb2R1Y3Rpb24gVGVhbSAodmVyc2lvbiAxLjApLCBjaXJjYSAyMDA3LCBhdCBUaGUgVW5pdmVyc2l0eSBvZiBMb3Vpc2lhbmEgTW9ucm9lOjwvYj4KPHVsPgo8bGk+UmljaGFyZCBQZWFjb2NrIC0gUHJvamVjdCBsZWFkIGFuZCBwcm9ncmFtbWVyLjwvbGk+CjxsaT5Kb2UgTWFuc291ciAtIFVMTSBtYWluZnJhbWUgZGF0YSBjb29yZGluYXRvci48L2xpPgo8bGk+Sm9hbm4gUGVycmVyIC0gVUxNIERhdGEgZW50cnkgYW5kIHRlc3RpbmcuPC9saT4KPGxpPlBhdWwgR3VsbGV0dGUgLSBDbGFzc2ljIHRoZW1lIGRlc2lnbmVyICh1c2VkIGJ5IHZlcnNpb25zIDEuMCB0aHJvdWdoIDQuMCkuPC9saT4KPGxpPjxiPk90aGVyIGNvbnRyaWJ1dGluZyBzdGFmZiBmcm9tIFVMTTwvYj46IEJhcmJhcmEgTWljaGFlbGlkZXMsIEFuZ2VsYSBSb2JpbnNvbiwgQ2hhcmxlcyBGcm9zdCwgQnJpYW4gVGF5bG9yLCBSb2IgR2xhemUuPC9saT4KPC91bD4KPHA+SW4gTWFyY2ggb2YgMjAxMywgdGhlIFVMTSBhZG1pbmlzdHJhdGlvbiBkZWNpZGVkIHRvIHJlbGVhc2UgRmxpZ2h0UGF0aCBhcyBvcGVuIHNvdXJjZSBpbiBvcmRlciB0byBlbnJpY2ggc2Nob29scyBhbmQgaW5zdGl0dXRpb25zIGFyb3VuZCB0aGUgd29ybGQuICBPdmVyIHRoZSB5ZWFycywgRmxpZ2h0UGF0aCBoYXMgYmVlbiByZS13cml0dGVuIGZyb20gc2NyYXRjaCA8Yj50d2ljZTwvYj4gYnkgUmljaGFyZCBQZWFjb2NrLCB3aG8gcmVtYWlucyB0aGUgcHJpbWFyeSBkZXZlbG9wZXIgb2YgdGhlIG9wZW4tc291cmNlIHZlcnNpb24sIGF2YWlsYWJsZSBhdCBodHRwczovL2dldGZsaWdodHBhdGguY29tLgo8YnI+PGJyPgpUbyBldmVyeW9uZSB3aG8gaGVscGVkIG1ha2UgRmxpZ2h0UGF0aCBwb3NzaWJsZTogPGVtPlRoYW5rIFlvdTwvZW0+Lgo8L3A+");
  603. }
  604. ///////////////////////////////////////
  605. // Get all the school ids this user is allowed to search.
  606. $school_ids = student_search_get_school_ids_user_is_allowed_to_search();
  607. $school_id_list = join(",", $school_ids);
  608. if ($selected_school_id !== -1) {
  609. // Meaning, a specific school was selected. So, we only want to return results of students from THAT school.
  610. $school_id_list = intval($selected_school_id);
  611. }
  612. $query = "SELECT u.user_id, f_name, l_name, u.cwid, rank_code, a.catalog_year, u.school_id, priority_value
  613. FROM (users u, students a, student_degrees c $other_table)
  614. LEFT JOIN student_priority ON (student_priority.student_id = u.cwid)
  615. WHERE
  616. u.cwid = a.cwid
  617. AND u.cwid = c.student_id
  618. AND u.is_student = 1
  619. AND u.school_id IN ($school_id_list)
  620. AND u.is_disabled = 0
  621. $search_action
  622. $major_search
  623. AND rank_code IN %RANKIN%
  624. %EXTRA_STUDENTSEARCH_CONDITIONS%
  625. ";
  626. if (!isset($search_options['inactive'])) {
  627. $query .= " AND is_active = 1 ";
  628. }
  629. $query .= "
  630. $group_by
  631. %ORDERBY%
  632. ";
  633. $adv_array = student_search_query_advisees($query, $params);
  634. }
  635. $s = (count($adv_array) == 1) ? "" : "s";
  636. $form['adv_array'] = array(
  637. 'type' => 'do_not_render',
  638. 'value' => $adv_array,
  639. );
  640. $student_count = @intval($pager_total_items[0]);
  641. $mark .= student_search_render_advisees($adv_array, t("Search Results") . " &nbsp; ($student_count " . t("student$s") . ")");
  642. $form['mark_search_results'] = array(
  643. 'type' => 'markup',
  644. 'value' => $mark,
  645. );
  646. return $form;
  647. } // search_form
  648. function student_search_search_form_submit($form, $form_state) {
  649. if (@$form_state['values']['reset_btn'] != "") {
  650. unset($_SESSION["student_search_for"]);
  651. unset($_SESSION["last_student_selected"]);
  652. unset($_SESSION["student_search_major_code"]);
  653. unset($_SESSION["student_search_search_options"]);
  654. return;
  655. }
  656. // Special for the search options (checkboxes). If none are checked, then
  657. // set it to _none=_none. This fixes a bug where checking to see if it isset() was always failing.
  658. if (@$form_state['values']['search_options'] == '') {
  659. $form_state['values']['search_options'] = array('_none' => '_none');
  660. }
  661. // Save values in session for next time.
  662. $_SESSION["student_search_for"] = @$form_state['values']['search_for'];
  663. $_SESSION["student_search_major_code"] = @$form_state['values']['major_code'];
  664. $_SESSION["student_search_search_options"] = @$form_state['values']['search_options'];
  665. fp_goto('student-search/search', 'did_search=true');
  666. } // search_form_submit
  667. /**
  668. * Simply returns the HTML to display the "advanced search tips" collapsible fieldset
  669. * and instructions.
  670. *
  671. */
  672. function student_search_get_advanced_search_tips() {
  673. $rtn = "";
  674. // Display advanced tips
  675. $advanced_tips_html = "
  676. <div class='student-search-advanced-tips'>
  677. " . t("@FlightPath displays students who are currently enrolled or are newly admitted for
  678. an upcoming term. Use the following tips to expand your search options:", array("@FlightPath" => variable_get("system_name", "FlightPath"))) . "
  679. <ul>
  680. <li>" . t("To search for inactive students, as well as active, add an asterisk (*)
  681. after your search.
  682. <br>&nbsp; &nbsp; &nbsp;
  683. Ex: <em>smith*</em> &nbsp; &nbsp; or &nbsp; &nbsp; <em>10035744*</em>") . "
  684. </li>
  685. <li>" . t("Search by major by typing major=CODE in the search box.
  686. <br>&nbsp; &nbsp; &nbsp;
  687. Ex: <em>major=ENGL</em> &nbsp; &nbsp; or &nbsp; &nbsp; <em>major=ENGL*</em>") . "
  688. </li>
  689. </ul>
  690. </div>";
  691. $rtn .= "<div class='student-search-advanced-tips-wrapper'>
  692. <label>" . t("Can't find the student you're looking for?") . "</label>
  693. " . fp_render_c_fieldset($advanced_tips_html, t("View advanced search tips"), TRUE) . "
  694. </div>";
  695. return $rtn;
  696. }
  697. function z__student_search_render_advisees($adv_array, $title) {
  698. $rtn = "";
  699. fp_add_css(fp_get_module_path("student_search") . "/css/student_search.css");
  700. $bool_redirect_one = FALSE;
  701. if (count($adv_array) == 1 && @$_REQUEST["did_search"] == "true")
  702. {
  703. // Since there was only 1 result, we want to redirect this person directly.
  704. // Draw this person's name...
  705. $student_id = $adv_array[0]["student_id"];
  706. $first_name = $adv_array[0]["first_name"];
  707. $last_name = $adv_array[0]["last_name"];
  708. $rtn .= "<div class='hypo' style='border: 1px solid black;
  709. margin: 10px 0px 10px 0px; padding: 10px;
  710. font-size: 12pt; font-weight: bold;'>
  711. " .t("Loading") . " <span style='color:blue;'>$first_name $last_name</span> ($student_id).
  712. &nbsp; " . t("Please wait...") . "
  713. </div>";
  714. $bool_redirect_one = TRUE;
  715. }
  716. $rtn .= fp_render_curved_line($title);
  717. $rtn .= "<table width='100%' align='left'
  718. border='0' cellpadding='0' cellspacing='0'>
  719. ";
  720. // Do not show headers at all if mobile
  721. if (!fp_screen_is_mobile()) {
  722. $rtn .= "
  723. <tr>
  724. <td width='5%' valign='top'>&nbsp; </td>
  725. <td width='12%' valign='top' class='tenpt'><b>" . t("CWID") . "</b></td>
  726. <td width='15%' valign='top' class='tenpt'><b>" . t("First Name") . "</b></td>
  727. <td width='20%' valign='top' class='tenpt'><b>" . t("Last Name") . "</b></td>
  728. <td width='15%' valign='top' class='tenpt'><b>" . t("Major Code") . "</b></td>
  729. <td width='10%' valign='top' class='tenpt'><b>" . t("Rank") . "</b></td>
  730. <td width='15%' valign='top' class='tenpt'><b>" . t("Catalog Year") . "</b></td>
  731. </tr> ";
  732. }
  733. $rtn .= "
  734. ";
  735. $db = get_global_database_handler();
  736. for ($t = 0; $t < count($adv_array); $t++)
  737. {
  738. $student_id = $adv_array[$t]["student_id"];
  739. $first_name = $adv_array[$t]["first_name"];
  740. $last_name = $adv_array[$t]["last_name"];
  741. $major = $adv_array[$t]["major"];
  742. $advising_what_if = @$adv_array[$t]["advising_what_if"];
  743. $what_if_major_code = @$adv_array[$t]["what_if_major_code"];
  744. $what_if_track_code = @$adv_array[$t]["what_if_track_code"];
  745. $what_if_catalog_year = @$adv_array[$t]["what_if_catalog_year"];
  746. $degree_id = @$adv_array[$t]["degree_id"];
  747. $rank = @$adv_array[$t]["rank"];
  748. $catalog_year = @$adv_array[$t]["catalog_year"];
  749. // There is no $screen variable-- old code?
  750. //if ($screen->page_is_mobile) {
  751. // $catalog_year = get_shorter_catalog_year_range($catalog_year, false, true);
  752. //}
  753. $advising_session_id = $adv_array[$t]["advising_session_id"];
  754. $advised_image = $adv_array[$t]["advised_image"];
  755. //fpm($adv_array);
  756. /*
  757. $on_mouse = "onmouseover=\"style.backgroundColor='#FFFF99'\"
  758. onmouseout=\"style.backgroundColor='white'\"
  759. ";
  760. */
  761. $on_mouse = "
  762. onmouseover='$(this).addClass(\"selection_highlight\");'
  763. onmouseout='$(this).removeClass(\"selection_highlight\");'
  764. ";
  765. // No screen var defined. Old code?
  766. //if ($screen->page_is_mobile) $on_mouse = ""; // Causes problems on mobile devices.
  767. // Build up the URL we want to go to when we click this row.
  768. $path = "view";
  769. $advising_what_if = "no";
  770. if ($what_if_major_code != "") {
  771. $path = "what-if";
  772. $advising_what_if = "yes";
  773. }
  774. // Add in the query part.
  775. $query = "";
  776. $query .= "advising_student_id=$student_id&current_student_id=$student_id&advising_major_code=$major&advising_what_if=$advising_what_if";
  777. $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";
  778. $url = fp_url($path, $query);
  779. // old onCLick:
  780. //<!-- onClick='selectStudent(\"$student_id\",\"$major\",\"$what_if_major_code\",\"$what_if_track_code\")' -->
  781. $disp_major = "";
  782. $temp = csv_to_array($major);
  783. foreach ($temp as $code) {
  784. $csscode = fp_get_machine_readable($code);
  785. // Was this a track code or not? Meaning, did it contain |_
  786. $is_track = "no";
  787. if (strstr($code, "|_")) {
  788. $is_track = "yes";
  789. }
  790. $disp_major .= "<div class='ss-major-code ss-major-code-$csscode ss-major-code-is-track-$is_track'>$code</div>";
  791. }
  792. $rtn .= "
  793. <tr height='19'>
  794. <td colspan='7'>
  795. <table border='0'
  796. $on_mouse
  797. onClick='showUpdate(true); window.location=\"$url\"; '
  798. width='100%'
  799. class='student_search_advisee_results'>
  800. <tr height='20'>
  801. <td width='5%' class='ss-advised-image'>$advised_image</td>
  802. <td width='12%' class='ss-student-id'>$student_id</td>
  803. <td width='15%' class='ss-student-fn'>$first_name</td>
  804. <td width='20%' class='ss-student-ln'>$last_name</td>
  805. <td width='15%' class='ss-student-major'>$disp_major</td>
  806. <td width='10%' class='ss-student-rank'>$rank</td>
  807. <td width='15%' class='ss-student-catalog-year'>$catalog_year</td>
  808. </tr>
  809. </table>
  810. </td>
  811. </tr>
  812. ";
  813. } // for t advisee array
  814. $rtn .= "</table>";
  815. if ($bool_redirect_one) {
  816. // There was only one result, and it was a search, so we want to redirect
  817. // this person.
  818. // We will use the URL we created in the foreach loop above. It will still contain exactly
  819. // what we need.
  820. $rtn .= "<script type='text/javascript'>
  821. $(document).ready(function() {
  822. setTimeout('window.location=\"$url\";', 0);
  823. });
  824. </script>";
  825. }
  826. // Required to make the changeTab function work...
  827. $rtn .= "<form id='mainform' method='POST'>
  828. <input type='hidden' id='scrollTop'>
  829. <input type='hidden' id='performAction' name='performAction'>
  830. <input type='hidden' id='advisingWhatIf' name='advisingWhatIf'>
  831. <input type='hidden' id='currentStudentID' name='currentStudentID'>
  832. <input type='hidden' id='advisingStudentID' name='advisingStudentID'>
  833. <input type='hidden' id='advisingMajorCode' name='advisingMajorCode'>
  834. <input type='hidden' id='whatIfMajorCode' name='whatIfMajorCode'>
  835. <input type='hidden' id='whatIfTrackCode' name='whatIfTrackCode'>
  836. <input type='hidden' id='advisingLoadActive' name='advisingLoadActive'>
  837. <input type='hidden' id='clearSession' name='clearSession'>
  838. </form>";
  839. //// IMPORTANT///////////
  840. $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.
  841. ///////////////////
  842. return $rtn;
  843. }
  844. function student_search_get_advisee_table_headers() {
  845. $table_headers = array();
  846. $table_headers[] = array("label" => "&nbsp;");
  847. $table_headers[] = array("label" => t("CWID"), "field" => "u.cwid");
  848. $table_headers[] = array("label" => "Student", 'field' => 'l_name');
  849. if (module_enabled("schools")) {
  850. $table_headers[] = array("label" => "School");
  851. }
  852. $table_headers[] = array("label" => "Major");
  853. $table_headers[] = array("label" => "Rank", "field" => 'a.rank_code');
  854. $table_headers[] = array("label" => "Catalog<span class='mobile-hidden'> Year</span>", "field" => "a.catalog_year");
  855. $table_headers[] = array("label" => "<span class='mobile-hidden'>Academic </span>Priority", "field" => "priority_value");
  856. return $table_headers;
  857. }
  858. function student_search_render_advisees($adv_array, $title) {
  859. $rtn = "";
  860. fp_add_css(fp_get_module_path("student_search") . "/css/student_search.css");
  861. fp_add_css(fp_get_module_path('student_profile') . '/css/style.css');
  862. $bool_redirect_one = FALSE;
  863. if (count($adv_array) == 1 && @$_REQUEST["did_search"] == "true")
  864. {
  865. // Since there was only 1 result, we want to redirect this person directly.
  866. // Draw this person's name...
  867. $details = reset($adv_array);
  868. $student_id = $details["student_id"];
  869. $first_name = $details["first_name"];
  870. $last_name = $details["last_name"];
  871. $rtn .= "<div class='hypo' style='border: 1px solid black;
  872. margin: 10px 0px 10px 0px; padding: 10px;
  873. font-size: 12pt; font-weight: bold;'>
  874. " .t("Loading") . " $first_name $last_name ($student_id).
  875. &nbsp; " . t("Please wait...") . "
  876. </div>";
  877. $bool_redirect_one = TRUE;
  878. }
  879. $rtn .= fp_render_section_title($title, "search-results");
  880. $table_headers = student_search_get_advisee_table_headers();
  881. $rtn .= "<table border='0' class='advisee-search-results-table'>";
  882. // Draw our our table headers, with links....
  883. $rtn .= theme_table_header_sortable($table_headers);
  884. $db = get_global_database_handler();
  885. foreach ($adv_array as $t => $details) {
  886. $student_id = $adv_array[$t]["student_id"];
  887. $first_name = $adv_array[$t]["first_name"];
  888. $last_name = $adv_array[$t]["last_name"];
  889. $major = $adv_array[$t]["major"];
  890. $school_id = $adv_array[$t]["school_id"];
  891. $priority_value = floatval($adv_array[$t]["priority_value"]);
  892. $advising_what_if = @$adv_array[$t]["advising_what_if"];
  893. $what_if_major_code = @$adv_array[$t]["what_if_major_code"];
  894. $what_if_track_code = @$adv_array[$t]["what_if_track_code"];
  895. $what_if_catalog_year = @$adv_array[$t]["what_if_catalog_year"];
  896. $degree_id = @$adv_array[$t]["degree_id"];
  897. $rank = @$adv_array[$t]["rank"];
  898. $catalog_year = @$adv_array[$t]["catalog_year"];
  899. // There is no $screen variable-- old code?
  900. //if ($screen->page_is_mobile) {
  901. // $catalog_year = get_shorter_catalog_year_range($catalog_year, false, true);
  902. //}
  903. $advising_session_id = $adv_array[$t]["advising_session_id"];
  904. $advised_image = $adv_array[$t]["advised_image"];
  905. $on_mouse = "
  906. onmouseover='$(this).addClass(\"selection_highlight\");'
  907. onmouseout='$(this).removeClass(\"selection_highlight\");'
  908. ";
  909. // Build up the URL we want to go to when we click this row.
  910. $path = 'student-select';
  911. /*
  912. $path = "view";
  913. $advising_what_if = "no";
  914. if ($what_if_major_code != "") {
  915. $path = "what-if";
  916. $advising_what_if = "yes";
  917. }
  918. */
  919. // Add in the query part.
  920. $query = "";
  921. $query .= "advising_student_id=$student_id&current_student_id=$student_id&advising_major_code=$major&advising_what_if=$advising_what_if";
  922. $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";
  923. $url = fp_url($path, $query);
  924. // old onCLick:
  925. //<!-- onClick='selectStudent(\"$student_id\",\"$major\",\"$what_if_major_code\",\"$what_if_track_code\")' -->
  926. $disp_major = "";
  927. $temp = csv_to_array($major);
  928. foreach ($temp as $code) {
  929. $csscode = fp_get_machine_readable($code);
  930. // Was this a track code or not? Meaning, did it contain |_
  931. $is_track = "no";
  932. if (strstr($code, "|_")) {
  933. $is_track = "yes";
  934. }
  935. $disp_major .= "<div class='ss-major-code ss-major-code-$csscode ss-major-code-is-track-$is_track'>$code</div>";
  936. }
  937. $student_name = "<span class='student-first-name student-fnf'>$first_name</span><span class='student-last-name'>$last_name</span>";
  938. $priority = t("N/A");
  939. if ($priority_value > 0) {
  940. $temp = student_priority_get_student_academic_priority_label($priority_value);
  941. $machine = $temp['machine'];
  942. $label = $temp['label'];
  943. $priority = "<span class='profile-priority-bar priority-$machine'><span class='desc'>$label</desc></span>";
  944. }
  945. $rtn .= "
  946. <tr class='search-result-row' $on_mouse onClick='showUpdate(true); window.location=\"$url\"; '>
  947. <td class='ss-advised-image'>$advised_image</td>
  948. <td class='ss-student-id'>$student_id</td>
  949. <td class='ss-student-name'>$student_name</td>";
  950. if (module_enabled("schools")) {
  951. $rtn .= "<td class='ss-student-school'>" . schools_get_school_code_for_id($school_id) . "</td>";
  952. }
  953. $rtn .= "
  954. <td class='ss-student-major'>$disp_major</td>
  955. <td class='ss-student-rank'>$rank</td>
  956. <td class='ss-student-catalog-year'>$catalog_year</td>
  957. <td class='ss-student-priority-value'>$priority</td>
  958. </tr>
  959. ";
  960. } // for t advisee array
  961. $rtn .= "</table>";
  962. $rtn .= theme_pager();
  963. if ($bool_redirect_one) {
  964. // There was only one result, and it was a search, so we want to redirect
  965. // this person.
  966. // We will use the URL we created in the foreach loop above. It will still contain exactly
  967. // what we need.
  968. $rtn .= "<script type='text/javascript'>
  969. $(document).ready(function() {
  970. setTimeout('fp_show_loading(\"" . t("Loading...") . "\");window.location=\"$url\";', 0);
  971. });
  972. </script>";
  973. }
  974. return $rtn;
  975. }
  976. function z______student_search_render_advisees($adv_array, $title) {
  977. $rtn = "";
  978. fp_add_css(fp_get_module_path("student_search") . "/css/student_search.css");
  979. $bool_redirect_one = FALSE;
  980. if (count($adv_array) == 1 && @$_REQUEST["did_search"] == "true")
  981. {
  982. // Since there was only 1 result, we want to redirect this person directly.
  983. // Draw this person's name...
  984. $details = reset($adv_array);
  985. $student_id = $details["student_id"];
  986. $first_name = $details["first_name"];
  987. $last_name = $details["last_name"];
  988. $rtn .= "<div class='hypo' style='border: 1px solid black;
  989. margin: 10px 0px 10px 0px; padding: 10px;
  990. font-size: 12pt; font-weight: bold;'>
  991. " .t("Loading") . " <span style='color:blue;'>$first_name $last_name</span> ($student_id).
  992. &nbsp; " . t("Please wait...") . "
  993. </div>";
  994. $bool_redirect_one = TRUE;
  995. }
  996. $rtn .= fp_render_section_title($title, "search-results");
  997. $rtn .= "<table width='100%' align='left'
  998. border='0' cellpadding='0' cellspacing='0'>
  999. <tr class='headers'>
  1000. <th width='5%' valign='top'>&nbsp; </td>
  1001. <th width='12%' >" . t("CWID") . "</th>
  1002. <th width='15%' >" . t("First Name") . "</th>
  1003. <th width='20%' >" . t("Last Name") . "</th>
  1004. <th width='15%' >" . t("Major Code") . "</th>
  1005. <th width='10%' >" . t("Rank") . "</th>
  1006. <th width='15%' >" . t("Catalog Year") . "</th>
  1007. </tr> ";
  1008. $rtn .= "
  1009. ";
  1010. $db = get_global_database_handler();
  1011. foreach ($adv_array as $t => $details) {
  1012. $student_id = $adv_array[$t]["student_id"];
  1013. $first_name = $adv_array[$t]["first_name"];
  1014. $last_name = $adv_array[$t]["last_name"];
  1015. $major = $adv_array[$t]["major"];
  1016. $advising_what_if = @$adv_array[$t]["advising_what_if"];
  1017. $what_if_major_code = @$adv_array[$t]["what_if_major_code"];
  1018. $what_if_track_code = @$adv_array[$t]["what_if_track_code"];
  1019. $what_if_catalog_year = @$adv_array[$t]["what_if_catalog_year"];
  1020. $degree_id = @$adv_array[$t]["degree_id"];
  1021. $rank = @$adv_array[$t]["rank"];
  1022. $catalog_year = @$adv_array[$t]["catalog_year"];
  1023. // There is no $screen variable-- old code?
  1024. //if ($screen->page_is_mobile) {
  1025. // $catalog_year = get_shorter_catalog_year_range($catalog_year, false, true);
  1026. //}
  1027. $advising_session_id = $adv_array[$t]["advising_session_id"];
  1028. $advised_image = $adv_array[$t]["advised_image"];
  1029. $on_mouse = "
  1030. onmouseover='$(this).addClass(\"selection_highlight\");'
  1031. onmouseout='$(this).removeClass(\"selection_highlight\");'
  1032. ";
  1033. // No screen var defined. Old code?
  1034. //if ($screen->page_is_mobile) $on_mouse = ""; // Causes problems on mobile devices.
  1035. // TODO: The path could be the student profile instead, depending on the user's settings.
  1036. // Build up the URL we want to go to when we click this row.
  1037. $path = 'student-select';
  1038. /*
  1039. $path = "view";
  1040. $advising_what_if = "no";
  1041. if ($what_if_major_code != "") {
  1042. $path = "what-if";
  1043. $advising_what_if = "yes";
  1044. }
  1045. */
  1046. // Add in the query part.
  1047. $query = "";
  1048. $query .= "advising_student_id=$student_id&current_student_id=$student_id&advising_major_code=$major&advising_what_if=$advising_what_if";
  1049. $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";
  1050. $url = fp_url($path, $query);
  1051. // old onCLick:
  1052. //<!-- onClick='selectStudent(\"$student_id\",\"$major\",\"$what_if_major_code\",\"$what_if_track_code\")' -->
  1053. $disp_major = "";
  1054. $temp = csv_to_array($major);
  1055. foreach ($temp as $code) {
  1056. $csscode = fp_get_machine_readable($code);
  1057. // Was this a track code or not? Meaning, did it contain |_
  1058. $is_track = "no";
  1059. if (strstr($code, "|_")) {
  1060. $is_track = "yes";
  1061. }
  1062. $disp_major .= "<div class='ss-major-code ss-major-code-$csscode ss-major-code-is-track-$is_track'>$code</div>";
  1063. }
  1064. $rtn .= "
  1065. <tr class='search-result-row' $on_mouse onClick='showUpdate(true); window.location=\"$url\"; '>
  1066. <td class='ss-advised-image'>$advised_image</td>
  1067. <td class='ss-student-id'>$student_id</td>
  1068. <td class='ss-student-fn'>$first_name</td>
  1069. <td class='ss-student-ln'>$last_name</td>
  1070. <td class='ss-student-major'>$disp_major</td>
  1071. <td class='ss-student-rank'>$rank</td>
  1072. <td class='ss-student-catalog-year'>$catalog_year</td>
  1073. </tr>
  1074. ";
  1075. } // for t advisee array
  1076. $rtn .= "</table>";
  1077. if ($bool_redirect_one) {
  1078. // There was only one result, and it was a search, so we want to redirect
  1079. // this person.
  1080. // We will use the URL we created in the foreach loop above. It will still contain exactly
  1081. // what we need.
  1082. $rtn .= "<script type='text/javascript'>
  1083. $(document).ready(function() {
  1084. setTimeout('window.location=\"$url\";', 0);
  1085. });
  1086. </script>";
  1087. }
  1088. return $rtn;
  1089. }
  1090. /**
  1091. * The limit is how many we will query, and also how many will appear on the page at one time.
  1092. */
  1093. function student_search_query_advisees($sql, $params = array(), $limit = 20, $bool_only_return_adv_array = FALSE) {
  1094. $db = get_global_database_handler();
  1095. $rank_in = "( '" . join("', '", csv_to_array(variable_get("allowed_student_ranks",''))) . "' )";
  1096. $order_by = "";
  1097. if (!$bool_only_return_adv_array) {
  1098. $table_headers = student_search_get_advisee_table_headers();
  1099. // Set our initial sort, if none is already set.
  1100. theme_table_header_sortable_set_initial_sort('l_name', 'ASC');
  1101. // Get our order by clause based on selected table header, if any.
  1102. $order_by = theme_table_header_sortable_order_by($table_headers);
  1103. }
  1104. // Replace the replacement portion with our derrived variables.
  1105. $sql = str_replace("%RANKIN%", $rank_in, $sql);
  1106. $sql = str_replace("%ORDERBY%", $order_by, $sql); // now handled by the table header sortable function
  1107. // By default, the extra_studentsearch_conditions will be adding nothing to the query. But, the user may override this
  1108. // in the settings.
  1109. $extra_student_search_conditions = variable_get("extra_student_search_conditions", "");
  1110. $sql = str_replace("%EXTRA_STUDENTSEARCH_CONDITIONS%", $extra_student_search_conditions, $sql);
  1111. // Returns an array of all of this teacher's advisees.
  1112. $rtn_array = array();
  1113. $r = 0;
  1114. $faculty_advisees = advise_get_advisees();
  1115. //$result = db_query($sql, $params);
  1116. // Now, we are going to search for these students, in the form of a pager query.
  1117. $result = pager_query($sql, $params, $limit, 0, NULL, "SELECT COUNT(DISTINCT(u.cwid))");
  1118. while ($cur = db_fetch_array($result))
  1119. {
  1120. $student_id = trim($cur["cwid"]);
  1121. // If this user does NOT have the "view any advising session" and DOES have the "view advisee advising sessions only",
  1122. // then see if this student is in their advisees list before continuing.
  1123. if (!user_has_permission("view_any_advising_session") && user_has_permission("view_advisee_advising_session")) {
  1124. if (!in_array($student_id, $faculty_advisees)) {
  1125. // Nope, this student is NOT one of their advisees! Skip it.
  1126. continue;
  1127. }
  1128. }
  1129. $rtn_array[$student_id]["student_id"] = $student_id;
  1130. $rtn_array[$student_id]["school_id"] = intval($cur['school_id']);
  1131. $rtn_array[$student_id]["first_name"] = ucwords(strtolower($cur["f_name"]));
  1132. $rtn_array[$student_id]["last_name"] = ucwords(strtolower($cur["l_name"]));
  1133. $rtn_array[$student_id]["rank"] = $cur["rank_code"];
  1134. $rtn_array[$student_id]["catalog_year"] = $cur["catalog_year"];
  1135. $rtn_array[$student_id]["priority_value"] = $cur["priority_value"];
  1136. //$rtn_array[$r]["major"] = $cur["major_code"];
  1137. // Need to get the major_code_csv for this student.
  1138. // Are there more majors for this user?
  1139. $major = "";
  1140. // Get a CSV of this student's majors
  1141. $major = fp_get_student_majors($student_id, TRUE, FALSE, FALSE);
  1142. $rtn_array[$student_id]["major"] = $major;
  1143. // We should also mark if the student has been advised for this semester
  1144. // or not.
  1145. // Get the current default advising term id.
  1146. $term_id = variable_get_for_school("advising_term_id", "", $cur['school_id']);
  1147. $advised_image = "";
  1148. $advising_session_id = "";
  1149. $res2 = db_query("SELECT * FROM advising_sessions WHERE
  1150. student_id = ? AND
  1151. term_id = ?
  1152. AND is_draft = 0
  1153. AND is_empty = 0
  1154. AND delete_flag = 0
  1155. ORDER BY posted DESC", $student_id, $term_id);
  1156. if (db_num_rows($res2) > 0) {
  1157. $cur = db_fetch_array($res2);
  1158. $advised_image = "<img src='" . fp_theme_location() . "/images/small_check.gif' class='advisedImage'>";
  1159. if ($cur["is_whatif"] == "1")
  1160. { // Last advising was a What If advising.
  1161. $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>";
  1162. $db_major_code_csv = $cur["major_code_csv"];
  1163. $rtn_array[$student_id]["what_if_major_code"] = $db_major_code_csv;
  1164. // Capture the catalog year that was saved with what_if
  1165. $rtn_array[$student_id]["what_if_catalog_year"] = $cur["catalog_year"];
  1166. $rtn_array[$student_id]["last_advised_what_if"] = TRUE;
  1167. }
  1168. }
  1169. $rtn_array[$student_id]["advising_session_id"] = $advising_session_id;
  1170. $rtn_array[$student_id]["advised_image"] = $advised_image;
  1171. $r++;
  1172. }
  1173. return $rtn_array;
  1174. }

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_ajax_autocomplete_student Meant to return results of the ajax autocomplete field, for selecting a student by name or cwid. Code inspiration from: https://www.drupal.org/node/854216
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_get_advanced_search_tips Simply returns the HTML to display the "advanced search tips" collapsible fieldset and instructions.
student_search_get_advisee_table_headers
student_search_get_majors_for_fapi Returns an array of majors from the database, suitable for use with our Form API.
student_search_get_school_ids_user_is_allowed_to_search
student_search_menu
student_search_perm Implementation of hook_perm
student_search_query_advisees The limit is how many we will query, and also how many will appear on the page at one time.
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_search_form
student_search_search_form_submit
student_search_settings_form This is a system_settings form for configuring our module.
student_search_student_select_switchboard The user has selected a student (clicked on a row) from the Search or My Advisees screen.
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.
z__student_search_render_advisees
z______student_search_render_advisees