user.student.inc

  1. 6.x modules/user/user.student.inc
  2. 5.x modules/user/user.student.inc

Keep track of functions dealing specifically with student user management

File

modules/user/user.student.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Keep track of functions dealing specifically with student user management
  5. */
  6. /**
  7. * Similar to user_display_users, except only for student users.
  8. */
  9. function user_display_student_users() {
  10. global $db, $screen;
  11. $de_catalog_year = @$GLOBALS["de_catalog_year"];
  12. if (!$de_catalog_year) {
  13. $de_catalog_year = @intval($_REQUEST['de_catalog_year']);
  14. }
  15. if ($db == NULL) {
  16. $db = get_global_database_handler();
  17. }
  18. $cc = 1;
  19. // Do this using $render array, so it can be altered
  20. // by hook_content_alter
  21. $render = array();
  22. $render['#id'] = 'user_display_users';
  23. fp_add_css(fp_get_module_path("admin") . "/css/admin.css");
  24. fp_add_css(fp_get_module_path("user") . "/css/user.css");
  25. if (@$_REQUEST['clear_filters'] == 'true') {
  26. // Meaning, a letter was specified, so let's reset the filter values.
  27. unset($_SESSION['users_filter_name']);
  28. foreach ($_SESSION as $key => $val) {
  29. if ($key == 'users_filter_active') continue; // we preserve the "active" filter setting
  30. if (strstr($key,"users_filter_")) {
  31. unset($_SESSION[$key]);
  32. }
  33. }
  34. }
  35. $html = "";
  36. $html .= "<div class='add-new-student-user'>" . l("<i class='fa fa-plus'></i> " . t("Create a new student user"), "admin/users/edit-student-user", "student_cwid=new&de_catalog_year=$de_catalog_year") . "</div>";
  37. $letter_ranges = array(
  38. "A" => array("A", "AZZZZ"),
  39. "B" => array("B", "BZZZZ"),
  40. "C" => array("C", "CZZZ"),
  41. "D" => array("D", "DZZZZ"),
  42. "E" => array("E", "EZZZZ"),
  43. "F" => array("F", "FZZZZ"),
  44. "G" => array("G", "GZZZZ"),
  45. "H" => array("H", "HZZZZ"),
  46. "I" => array("I", "IZZZ"),
  47. "J" => array("J", "JZZZ"),
  48. "K" => array("K", "KZZZ"),
  49. "L" => array("L", "LZZZ"),
  50. "M" => array("M", "MZZZ"),
  51. "N" => array("N", "NZZZ"),
  52. "O" => array("O", "OZZZ"),
  53. "P" => array("P", "PZZZ"),
  54. "Q-R" => array("Q", "RZZZZ"),
  55. "S" => array("S", "SZZZ"),
  56. "T" => array("T", "TZZZZ"),
  57. "U" => array("U", "UZZZ"),
  58. "V-Z" => array("V", "ZZZZ"),
  59. );
  60. $ur = trim(@$_GET["ur"]);
  61. $lr = trim(@$_GET["lr"]);
  62. if ($ur == "" && !isset($_SESSION['users_filter_submit'])) {
  63. //if ($ur == "") {
  64. $ur = "A";
  65. $lr = "AZZZZZ"; // first time through.
  66. }
  67. // If we are going by filters, show that as option and select it.
  68. if (isset($_SESSION['users_filter_submit'])) {
  69. $letter_ranges[t(" - Filter -")] = array("filter", "filter");
  70. }
  71. $html .= "<div class='user-select-letter-bar' style='padding-top: 20px;'>
  72. ";
  73. foreach($letter_ranges as $disp => $vals) {
  74. $selected_class = "";
  75. if ($ur == $vals[0]) {
  76. $selected_class = "selected";
  77. }
  78. if ($vals[0] == 'filter') {
  79. $selected_class = "selected";
  80. $html .= "<a href='javascript:void(0);' class='admin-courses-letter-link filter-indicator $selected_class'>$disp</a> &nbsp; ";
  81. continue;
  82. }
  83. $html .= l($disp, "admin/users/students", "de_catalog_year=$de_catalog_year&clear_filters=true&ur=" . $vals[0] . "&lr=" . $vals[1], array("class" => "admin-courses-letter-link $selected_class")) . " &nbsp; ";
  84. }
  85. $html .= "</div>";
  86. $render['upper_links'] = array(
  87. 'value' => $html,
  88. );
  89. if ($ur == "")
  90. { // meaning, no range was set. Use A - C
  91. $ur = @$_SESSION["ur"];
  92. $lr = @$_SESSION["lr"];
  93. if ($ur == "")
  94. { // if still blank, assign it..
  95. $ur = "A";
  96. $lr = "AZZZZ";
  97. }
  98. }
  99. $_SESSION["ur"] = $ur;
  100. $_SESSION["lr"] = $lr;
  101. $mark = "";
  102. $mark .= "<div class='degrees-filter'>";
  103. $mark .= fp_render_form("user_student_list_filter_form");
  104. $mark .= "</div>";
  105. $render['users_filter'] = array(
  106. 'value' => $mark,
  107. );
  108. $extra_where_conditions = "";
  109. $params = array();
  110. $params[":ur"] = $ur;
  111. $params[":lr"] = $lr;
  112. if (isset($_SESSION['users_filter_submit'])) {
  113. // We clicked to filter, so the letter range should be ignored.
  114. $params[":ur"] = "A";
  115. $params[":lr"] = "ZZZZZZZZZZZZ";
  116. }
  117. $filter_name = @trim($_SESSION['users_filter_name']);
  118. $filter_school = @intval($_SESSION['users_filter_school']);
  119. $filter_major = @trim($_SESSION['users_filter_major']);
  120. $filter_active = @trim($_SESSION['users_filter_active']);
  121. if ($filter_name) {
  122. $extra_where_conditions .= " AND (l_name LIKE :search1 OR f_name LIKE :search2 OR u.cwid LIKE :search3) ";
  123. $params[":search1"] = "%$filter_name%";
  124. $params[":search2"] = "%$filter_name%";
  125. $params[":search3"] = "%$filter_name%";
  126. // If we are searching by name, then we do not care about what letters we selected.
  127. $params[":ur"] = "A";
  128. $params[":lr"] = "ZZZZZZZZZZZZZZ";
  129. }
  130. $extra_where_conditions .= " AND u.school_id = :school_id ";
  131. $params[":school_id"] = $filter_school;
  132. if ($filter_major != '') {
  133. $extra_where_conditions .= " AND major_code = :major_code ";
  134. $params[":major_code"] = $filter_major;
  135. }
  136. if ($filter_active) {
  137. $vals = array();
  138. if ($filter_active == 'active') {
  139. $vals[] = 1;
  140. }
  141. if ($filter_active == 'inactive') {
  142. $vals[] = 0;
  143. }
  144. if ($filter_active == 'all') {
  145. $vals = array(1, 0);
  146. }
  147. $extra_where_conditions .= " AND is_active IN (" . join(",", $vals) . ") ";
  148. }
  149. watchdog("user", "Viewed admin student user list. Range: $ur - $lr. Name: $filter_name. Major: $filter_major. Active: $filter_active. School: $filter_school", array(), WATCHDOG_DEBUG);
  150. $html = "";
  151. $html .= "
  152. <table border='0' width='100%' cellpadding='3' cellspacing='0' class='user-list'>
  153. <tr>
  154. <th width='5%'>Actions</th>
  155. <th>CWID</th>
  156. <th>Name</th>
  157. <th></th>
  158. <th>Major code(s)</th>
  159. <th>Active?</th>
  160. <th>Last Login</th>
  161. </tr>
  162. ";
  163. $render['users_table_top'] = array(
  164. 'value' => $html,
  165. );
  166. $limit = 30;
  167. $result = pager_query("SELECT * FROM (users u, students s)
  168. LEFT JOIN student_degrees d ON (s.cwid = d.student_id)
  169. WHERE
  170. u.is_student = 1
  171. AND u.cwid = s.cwid
  172. AND l_name BETWEEN :ur AND :lr
  173. $extra_where_conditions
  174. GROUP BY u.cwid
  175. ORDER BY l_name, f_name
  176. ", $params, $limit, 0, NULL, "SELECT COUNT(DISTINCT(u.cwid))");
  177. while ($cur = db_fetch_array($result)) {
  178. $user_id = $cur["user_id"];
  179. $l_name = trim(ucwords(strtolower($cur["l_name"])));
  180. $f_name = trim(ucwords(strtolower($cur["f_name"])));
  181. $student_cwid = trim($cur["cwid"]);
  182. //$disp_major_code = trim($cur["major_code"]);
  183. $disp_major_code = join(", ", $db->get_student_majors_from_db($student_cwid, FALSE, FALSE));
  184. $is_active = ($cur["is_active"] == "1") ? "Y" : "N";
  185. $last_login = intval($cur['last_login']);
  186. if ($last_login == 0) {
  187. $last_login = t("Never");
  188. }
  189. else {
  190. $last_login = format_date(convert_time($last_login), 'short');
  191. }
  192. $ast = "";
  193. $reason = "";
  194. $fgcol = "black";
  195. $render['user_row_' . $student_cwid] = array(
  196. 'value' => "<tr class='is-active-$is_active'>
  197. <td valign='top'>" . l("<i class='fa fa-pencil' title='Edit'></i>", "admin/users/edit-student-user", "student_cwid=$student_cwid&de_catalog_year=$de_catalog_year") . "</td>
  198. <td valign='top' width='15%'>$student_cwid</td>
  199. <td valign='top' width='15%'>$f_name</td>
  200. <td valign='top' width='15%'>$l_name</td>
  201. <td valign='top'>$disp_major_code</td>
  202. <td valign='top'>$is_active</td>
  203. <td valign='top'>$last_login</td>
  204. </tr>",
  205. 'data' => array(
  206. 'is_student' => 1,
  207. 'cwid' => $student_cwid,
  208. 'db_row' => $cur,
  209. ),
  210. );
  211. } // while
  212. $render['users_table_bottom'] = array(
  213. 'value' => "</table>",
  214. );
  215. $render['users_pager'] = array(
  216. 'value' => theme_pager(),
  217. );
  218. $rtn = fp_render_content($render);
  219. return $rtn;
  220. }
  221. function user_student_list_filter_form() {
  222. $form = array();
  223. $form['mark_top'] = array(
  224. 'type' => 'markup',
  225. 'value' => "<strong>" . t('Filter by...') . "</strong>",
  226. 'weight' => 0,
  227. );
  228. $form['de_catalog_year'] = array(
  229. 'type' => 'hidden',
  230. 'value' => @$_REQUEST['de_catalog_year'],
  231. );
  232. $filter_name_value = @trim($_SESSION['users_filter_name']);
  233. $form['filter_name'] = array(
  234. 'type' => 'textfield',
  235. 'label' => '',
  236. 'attributes' => array("placeholder" => t("Name or CWID")),
  237. 'value' => $filter_name_value,
  238. 'size' => 20,
  239. 'weight' => 10,
  240. );
  241. // Show list of majors (which are also in FlightPath, and in the selected school, if any)
  242. $options = array();
  243. $test_school_id = @intval($_SESSION['users_filter_school']);
  244. $test_school_options = array();
  245. if (module_enabled('schools')) {
  246. $test_school_options = schools_get_schools_for_fapi(TRUE, TRUE, 'user', TRUE);
  247. }
  248. $res = db_query("SELECT DISTINCT(b.major_code) FROM students a, student_degrees b, `degrees` c
  249. WHERE a.cwid = b.student_id
  250. AND b.major_code = c.major_code
  251. AND school_id = ?
  252. ORDER BY b.major_code ", array($test_school_id));
  253. while ($cur = db_fetch_array($res)) {
  254. if (trim($cur["major_code"]) == "")
  255. {// skip if blank
  256. continue;
  257. }
  258. if (count($test_school_options) <= 1) {
  259. $options[$cur['major_code']] = trim(ucwords($cur["major_code"]));
  260. }
  261. else {
  262. $options[$test_school_options[$test_school_id]][$cur['major_code']] = trim(ucwords($cur["major_code"]));
  263. }
  264. }
  265. $filter_major_value = @trim($_SESSION['users_filter_major']);
  266. $form['filter_major'] = array(
  267. 'type' => 'select',
  268. 'label' => t('Major:'),
  269. 'options' => $options,
  270. 'value' => $filter_major_value,
  271. 'weight' => 20,
  272. );
  273. // Show list of active/inactive options
  274. $options = array();
  275. $options['active'] = t('Show Active');
  276. $options['inactive'] = t('Show Inactive');
  277. $options['all'] = t('Show All');
  278. $filter_active_value = @$_SESSION['users_filter_active'];
  279. $form['filter_active'] = array(
  280. 'type' => 'select',
  281. 'label' => t('Active:'),
  282. 'options' => $options,
  283. 'hide_please_select' => TRUE,
  284. 'value' => $filter_active_value,
  285. 'weight' => 30,
  286. );
  287. // If we have enabled the schools module, then have a selector for that as well
  288. if (module_enabled('schools')) {
  289. $filter_school_value = @intval($_SESSION['users_filter_school']);
  290. $options = schools_get_schools_for_fapi(TRUE, TRUE, 'user', TRUE);
  291. $options[0] = t('- Default -');
  292. $form['filter_school'] = array(
  293. 'type' => 'select',
  294. 'label' => t('School:'),
  295. 'options' => $options,
  296. 'value' => $filter_school_value,
  297. 'weight' => 40,
  298. 'hide_please_select' => TRUE,
  299. );
  300. } // if schools enabled
  301. $form['submit_btn'] = array(
  302. 'type' => 'submit',
  303. 'value' => t('Apply'),
  304. 'weight' => 100,
  305. );
  306. $form['reset_btn'] = array(
  307. 'type' => 'submit',
  308. 'value' => t('Reset'),
  309. 'weight' => 110,
  310. );
  311. return $form;
  312. }
  313. function user_student_list_filter_form_submit($form, $form_state) {
  314. $values = $form_state['values'];
  315. unset($_SESSION['users_filter_name']);
  316. unset($_SESSION['users_filter_school']);
  317. unset($_SESSION['users_filter_major']);
  318. unset($_SESSION['users_filter_active']);
  319. unset($_SESSION['users_filter_submit']);
  320. if ($values['submit_btn'] != '') {
  321. $_SESSION['users_filter_name'] = trim($values['filter_name']);
  322. $_SESSION['users_filter_school'] = $values['filter_school'];
  323. $_SESSION['users_filter_major'] = $values['filter_major'];
  324. $_SESSION['users_filter_active'] = $values['filter_active'];
  325. $_SESSION['users_filter_submit'] = "yes"; // simply notes that we did indeed press the submit btn.
  326. // If "active" was the only one changed, then we do not set this users_filter_submit
  327. if (trim($values['filter_name']) == "" && intval($values['filter_school']) == 0 && $values['filter_major'] == "") {
  328. unset($_SESSION['users_filter_submit']);
  329. }
  330. }
  331. fp_goto("admin/users/students", "de_catalog_year=" . $values['de_catalog_year']);
  332. }
  333. /**
  334. * This is the form which we will use to manage a student's courses they've taken.
  335. */
  336. function user_student_edit_student_courses_form() {
  337. fp_add_js(fp_get_module_path("user") . "/js/user.js");
  338. $m = 0;
  339. $form = array();
  340. $student_cwid = $_REQUEST["student_cwid"]; // now getting it from argument
  341. $user_id = db_get_user_id_from_cwid($student_cwid, "student");
  342. $de_catalog_year = @$_REQUEST["de_catalog_year"];
  343. // Figure out what the page's sub-tabs should be, and set them.
  344. $tab_array = array();
  345. $tab_array[0]["title"] = t("Edit Student");
  346. $tab_array[0]["active"] = FALSE;
  347. $tab_array[0]["on_click"] = "window.location=\"" . fp_url("admin/users/edit-student-user", "student_cwid=$student_cwid&de_catalog_year=$de_catalog_year") . "\"";
  348. $tab_array[1]["title"] = t("Edit Student Courses");
  349. $tab_array[1]["active"] = TRUE;
  350. $tab_array[1]["on_click"] = "window.location=\"" . fp_url("admin/users/edit-student-user/courses", "student_cwid=$student_cwid&de_catalog_year=$de_catalog_year") . "\"";
  351. // If there are attributes for a student, then show the tab.
  352. $attributes = user_get_registered_attributes();
  353. foreach ($attributes as $def) {
  354. if (@$def['settings']['user_type'] == 'student' || @$def['settings']['user_type'] == 'all') {
  355. $tab_array[2]["title"] = t("Edit User Attributes");
  356. $tab_array[2]["active"] = FALSE;
  357. $tab_array[2]["on_click"] = "window.location=\"" . fp_url("admin/users/edit-student-user/attributes", "user_id=$user_id&user_type=student&student_cwid=$student_cwid&de_catalog_year=$de_catalog_year") . "\"";
  358. break;
  359. }
  360. }
  361. fp_set_page_sub_tabs($tab_array);
  362. if ($student_cwid != "new") {
  363. $name = fp_get_student_name($student_cwid);
  364. fp_set_title(t("Edit Student Courses @name (@id)", array("@name" => $name, "@id" => $student_cwid)));
  365. }
  366. else {
  367. // A new student! We can't create a new student until a CWID is assigned.
  368. fp_set_title(t("Create New Student User"));
  369. $form["mark_sorry"] = array(
  370. "type" => "markup",
  371. "value" => "<p>" . t("Sorry, but you cannot add student courses until the student
  372. has been fully created (and given a CWID). Use the Edit Student button above
  373. to return to that screen.") . "</p>",
  374. );
  375. return $form;
  376. }
  377. $form["user_id"] = array(
  378. "type" => "hidden",
  379. "value" => $user_id,
  380. );
  381. $form["perform_action2"] = array(
  382. "type" => "hidden",
  383. "value" => "",
  384. );
  385. $form["student_cwid"] = array(
  386. "type" => "hidden",
  387. "value" => $student_cwid,
  388. );
  389. // Okay, let's create a table in which we will place the student's courses.
  390. $form["mark" . $m++] = array(
  391. "value" => "<p>
  392. " . ("Enter the student's local (non-transfer) courses they have enrolled in at your institution.") . "
  393. <ul>
  394. <li>" . t("Course: Enter the full course subject ID and num, separated by a space. Ex: ACCT 101") . "</li>
  395. <li>" . t("Term: Enter the term code that this student enrolled in this course. Ex: 201540") . "</li>
  396. <li>" . t("Grade: Enter the grade they earned. Ex: B") . "</li>
  397. <li>" . t("Hrs: Enter the hours awarded. Ex: 3") . "</li>
  398. <li>" . t("Lvl: (optional), enter the level code for this course. Ex: UG") . "</li>
  399. </ul>
  400. " . t("<b>Note:</b> If you have any routines which might overwrite this data (in the student_courses table), then this
  401. data may be ignored or deleted!") . "
  402. </p>",
  403. );
  404. $form["warn_me"] = array(
  405. "type" => "checkbox",
  406. "label" => t("Warn me if I enter a course which doesn't exist in draft_courses (good for catching typos)"),
  407. "value" => "yes",
  408. );
  409. $form["mark" . $m++] = array(
  410. "value" => "
  411. <table border='0' width='100%' cellpadding='3' cellspacing='0'>
  412. <tr>
  413. <th>" . t("Course") . "</th>
  414. <th>" . t("Term") . "</th>
  415. <th>" . t("Grade") . "</th>
  416. <th>" . t("Hrs") . "</th>
  417. <th>" . t("Lvl") . "</th>
  418. </tr>",
  419. );
  420. // Let's get an array of what courses the student has already taken (if any)
  421. $courses = array();
  422. $res = db_query("SELECT * FROM student_courses
  423. WHERE student_id = '?'
  424. ORDER BY subject_id, course_num", $student_cwid);
  425. while ($cur = db_fetch_array($res)) {
  426. $courses[] = array(
  427. "course" => $cur["subject_id"] . " " . $cur["course_num"],
  428. "term" => $cur["term_id"],
  429. "grade" => $cur["grade"],
  430. "hrs" => $cur["hours_awarded"] * 1, // will trim excess zeroes if there
  431. "lvl" => $cur["level_code"],
  432. );
  433. }
  434. // Let's add 10 additional (blank) lines to the courses array.
  435. for ($t = 0; $t < 10; $t++) {
  436. $courses[] = array(
  437. "course" => "",
  438. "term" => "",
  439. "grade" => "",
  440. "hrs" => "",
  441. "lvl" => "",
  442. );
  443. }
  444. // Okay, now let's go through the courses array and display in the table...
  445. $stripe = "";
  446. foreach ($courses as $t => $val) {
  447. if ($stripe == "") {
  448. $stripe = "style='background-color: beige;'";
  449. }
  450. else {
  451. $stripe = "";
  452. }
  453. $form["course_$t"] = array(
  454. "prefix" => "<tr $stripe >
  455. <td valign='top'>",
  456. "type" => "textfield",
  457. "size" => 12,
  458. "suffix" => "</td>",
  459. "value" => $val["course"],
  460. );
  461. $form["term_$t"] = array(
  462. "prefix" => "<td valign='top'>",
  463. "type" => "textfield",
  464. "size" => 8,
  465. "suffix" => "</td>",
  466. "value" => $val["term"],
  467. );
  468. $form["grade_$t"] = array(
  469. "prefix" => "<td valign='top'>",
  470. "type" => "textfield",
  471. "size" => 4,
  472. "suffix" => "</td>",
  473. "value" => $val["grade"],
  474. );
  475. $form["hrs_$t"] = array(
  476. "prefix" => "<td valign='top'>",
  477. "type" => "textfield",
  478. "size" => 4,
  479. "suffix" => "</td>",
  480. "value" => $val["hrs"],
  481. );
  482. $form["lvl_$t"] = array(
  483. "prefix" => "<td valign='top'>",
  484. "type" => "textfield",
  485. "size" => 4,
  486. "suffix" => "</td>
  487. </tr>",
  488. "value" => $val["lvl"],
  489. );
  490. } // for loop
  491. $form["number_of_courses"] = array(
  492. "type" => "hidden",
  493. "value" => count($courses),
  494. );
  495. // close table.
  496. $form["mark" . $m++] = array(
  497. "value" => "</table>
  498. <p>" . t("Rows without Course entered will be skipped.
  499. <br><br><b>Note:</b> To add more blank rows, save your work. When the page reloads, there will be additional
  500. blank rows to add new courses.") . "</p>",
  501. );
  502. $form["submit_btn"] = array(
  503. "type" => "submit",
  504. "value" => "Submit",
  505. );
  506. return $form;
  507. } // user_student_edit_student_courses_form
  508. function user_student_edit_student_courses_form_validate($form, $form_state) {
  509. // If the user requested it, check to see if the course exists (in the draft_courses table)
  510. if ($form_state["values"]["warn_me"] === TRUE) {
  511. // Yes, the user wants to be warned if they entered a course which doesn't exist.
  512. $number_of_courses = intval($form_state["values"]["number_of_courses"]);
  513. for ($t = 0; $t < $number_of_courses; $t++) {
  514. $course = trim($form_state["values"]["course_$t"]);
  515. if ($course == "") continue;
  516. $temp = explode(" ", $course);
  517. $subject_id = trim($temp[0]);
  518. $course_num = trim($temp[1]);
  519. // Check to see that this course exists.
  520. $res = db_query("SELECT subject_id FROM draft_courses
  521. WHERE subject_id = '?'
  522. AND course_num = '?' ", $subject_id, $course_num);
  523. $cur = db_fetch_array($res);
  524. if ($cur["subject_id"] != $subject_id) {
  525. form_error("course_$t", t("The course %subject_id %course_num could not be found in the draft_courses table. A typo? Your data has NOT been saved.",
  526. array("%subject_id" => $subject_id, "%course_num" => $course_num)));
  527. }
  528. }
  529. }
  530. }
  531. function user_student_edit_student_courses_form_submit($form, $form_state) {
  532. $student_id = $form_state["values"]["student_cwid"];
  533. $db = get_global_database_handler();
  534. // Erase what's there already:
  535. db_query("DELETE FROM student_courses WHERE student_id = '?' ", $student_id);
  536. $school_id = $db->get_school_id_for_student_id($student_id);
  537. $number_of_courses = intval($form_state["values"]["number_of_courses"]);
  538. for ($t = 0; $t < $number_of_courses; $t++) {
  539. $course = trim($form_state["values"]["course_$t"]);
  540. if ($course == "") continue;
  541. $temp = explode(" ", $course);
  542. $subject_id = trim($temp[0]);
  543. $course_num = trim($temp[1]);
  544. $course_id = intval($db->get_course_id($subject_id, $course_num, "", FALSE, $school_id));
  545. $term_id = trim($form_state["values"]["term_$t"]);
  546. $grade = trim($form_state["values"]["grade_$t"]);
  547. $hours_awarded = trim($form_state["values"]["hrs_$t"]);
  548. $level_code = trim($form_state["values"]["lvl_$t"]);
  549. // Add to table
  550. db_query("INSERT INTO student_courses (student_id, subject_id, course_num, hours_awarded, grade, term_id, level_code, course_id)
  551. VALUES (?, ?, ?, ?, ?, ?, ?, ?)", array($student_id, $subject_id, $course_num, $hours_awarded, $grade, $term_id, $level_code, $course_id));
  552. }
  553. watchdog("user_edit_courses", "Update student (@cwid) courses values: @other", array("@cwid" => $student_id, "@other" => ppm($form_state['values'], TRUE)));
  554. fp_add_message(t("Student courses updated."));
  555. } // student_courses_form_submit
  556. /**
  557. * Let the user edit a studentuser's information.
  558. */
  559. function user_edit_student_user_form() {
  560. fp_add_js(fp_get_module_path("user") . "/js/user.js");
  561. $form = array();
  562. $m = 0;
  563. $student_cwid = @$_REQUEST["student_cwid"]; // now getting it from argument
  564. $de_catalog_year = @$_REQUEST["de_catalog_year"];
  565. $user_id = db_get_user_id_from_cwid($student_cwid, "student");
  566. $db = get_global_database_handler();
  567. // Figure out what the page's sub-tabs should be, and set them.
  568. $tab_array = array();
  569. $tab_array[0]["title"] = t("Edit Student");
  570. $tab_array[0]["active"] = TRUE;
  571. $tab_array[0]["on_click"] = "window.location=\"" . fp_url("admin/users/edit-student-user", "student_cwid=$student_cwid&de_catalog_year=$de_catalog_year") . "\"";
  572. $tab_array[1]["title"] = t("Edit Student Courses");
  573. $tab_array[1]["active"] = FALSE;
  574. $tab_array[1]["on_click"] = "window.location=\"" . fp_url("admin/users/edit-student-user/courses", "student_cwid=$student_cwid&de_catalog_year=$de_catalog_year") . "\"";
  575. // If there are attributes for a student, then show the tab.
  576. $attributes = user_get_registered_attributes();
  577. foreach ($attributes as $def) {
  578. if (@$def['settings']['user_type'] == 'student' || @$def['settings']['user_type'] == 'all') {
  579. $tab_array[2]["title"] = t("Edit User Attributes");
  580. $tab_array[2]["active"] = FALSE;
  581. $tab_array[2]["on_click"] = "window.location=\"" . fp_url("admin/users/edit-student-user/attributes", "user_id=$user_id&user_type=student&student_cwid=$student_cwid&de_catalog_year=$de_catalog_year") . "\"";
  582. break;
  583. }
  584. }
  585. fp_set_page_sub_tabs($tab_array);
  586. if ($student_cwid != "new") {
  587. $name = fp_get_student_name($student_cwid);
  588. fp_set_title(t("Edit Student User @name (@id)", array("@name" => $name, "@id" => $student_cwid)));
  589. }
  590. else {
  591. // A new student!
  592. fp_set_title(t("Create New Student User"));
  593. }
  594. $form["user_id"] = array(
  595. "type" => "hidden",
  596. "value" => $user_id,
  597. );
  598. $form["perform_action2"] = array(
  599. "type" => "hidden",
  600. "value" => "",
  601. );
  602. $form["student_cwid"] = array(
  603. "type" => "hidden",
  604. "value" => $student_cwid,
  605. );
  606. // TODO: At the moment, only faculty can be assigned roles in FP. However, this could change
  607. // one day, so I am going to leave this code in place for students, but commented out.
  608. /*
  609. $user_roles = system_get_roles_for_user($user_id);
  610. //fpm($user_roles);
  611. $default_values = array();
  612. foreach ($user_roles as $rid => $val) {
  613. $default_values[$rid] = $rid;
  614. }
  615. // Show a list of roles in the system which we may select from, and check the ones
  616. // all ready assigned to this user.
  617. $options = array();
  618. $res = db_query("SELECT * FROM roles ORDER BY rid");
  619. while ($cur = db_fetch_array($res)) {
  620. $key = $cur["rid"];
  621. $value = $cur["name"];
  622. if ($key > 2) {
  623. $options[$key] = $value;
  624. }
  625. }
  626. //fpm($default_values);
  627. $form["roles"] = array(
  628. "label" => t("Check which roles this user should have."),
  629. "type" => "checkboxes",
  630. "options" => $options,
  631. "value" => $default_values,
  632. );
  633. */
  634. // Let's present the form elements to allow some basic editing of this user.
  635. // Only if we are making a new student...
  636. if ($student_cwid == "new") {
  637. $form["new_student_cwid"] = array(
  638. "label" => t("Enter a new CWID, unique to students:"),
  639. "type" => "textfield",
  640. "size" => 20,
  641. "required" => TRUE,
  642. "description" => t("Enter an alpha-numeric ID for this student. It may be the same
  643. as a faculty member, but may not be the same as any existing
  644. student. You will not be able to edit this value, once saved."),
  645. "weight" => 10,
  646. );
  647. $form["new_user_name"] = array(
  648. "label" => t("Enter a new username, unique to all users:"),
  649. "type" => "textfield",
  650. "size" => 20,
  651. "required" => TRUE,
  652. "description" => t("Enter a username for this user. This is what the user will
  653. use to log in. It must be unique to all users (cannot have both
  654. a faculty and a student with the same username). You will not
  655. be able to edit this value, once saved."),
  656. "weight" => 10,
  657. );
  658. $cur = array();
  659. }
  660. else {
  661. // NOT a new student. Load their information normally.
  662. $res = db_query("SELECT * FROM users u, students s
  663. WHERE u.cwid = '?'
  664. AND u.is_student = '1'
  665. AND u.cwid = s.cwid", $student_cwid);
  666. $cur = db_fetch_array($res);
  667. }
  668. $user_name = @$cur["user_name"];
  669. if ($user_name != "") {
  670. $form["mark" . $m++] = array(
  671. "value" => "<p><b>Username:</b> $user_name</p>",
  672. );
  673. }
  674. $form["new_password"] = array(
  675. "label" => t("Enter a new password for this user:"),
  676. "type" => "textfield",
  677. "size" => 20,
  678. "required" => ($student_cwid == "new") ? TRUE : FALSE,
  679. "description" => t("If you enter any value here, it will change the
  680. user's password in FlightPath. If you are using a single-sign-on or similar module (CAS, SAML, LDAP, etc)
  681. for external user password management, the password will be <strong>unaffected</strong> by this setting."),
  682. "weight" => 20,
  683. );
  684. $form["email"] = array(
  685. "label" => t("Email:"),
  686. "type" => "textfield",
  687. "value" => @$cur["email"],
  688. "weight" => 30,
  689. );
  690. $form["f_name"] = array(
  691. "label" => t("First name:"),
  692. "type" => "textfield",
  693. "value" => @$cur["f_name"],
  694. "weight" => 40,
  695. );
  696. $form["l_name"] = array(
  697. "label" => t("Last name:"),
  698. "type" => "textfield",
  699. "value" => @$cur["l_name"],
  700. "weight" => 50,
  701. );
  702. $form["is_disabled"] = array(
  703. "label" => t("Is disabled:"),
  704. "type" => "textfield",
  705. "value" => @$cur["is_disabled"],
  706. "size" => 5,
  707. "description" => t("Enter only 1 or 0 (number one for 'yes', or number zero for 'no'). This setting means the user will
  708. be ignored by FlightPath, and they will not be able to log in or be searched for.
  709. It is safer to disable a user, than delete them."),
  710. "weight" => 60,
  711. );
  712. // Unique to students...
  713. $form["cumulative_hours"] = array(
  714. "label" => t("Cumulative hours:"),
  715. "type" => "textfield",
  716. "value" => @$cur["cumulative_hours"],
  717. "size" => 5,
  718. "description" => t("How many hours has the student earned? NOTE: If FlightPath is set to
  719. calculate this, rather than read from the database, whatever you enter here
  720. will be ignored, and instead this value will be calculated on the fly when
  721. the student is loaded."),
  722. "weight" => 70,
  723. );
  724. $form["gpa"] = array(
  725. "label" => t("GPA:"),
  726. "type" => "textfield",
  727. "value" => @$cur["gpa"],
  728. "size" => 5,
  729. "description" => t("What is the student's GPA? NOTE: If FlightPath is set to
  730. calculate this, rather than read from the database, whatever you enter here
  731. will be ignored, and instead this value will be calculated on the fly when
  732. the student is loaded."),
  733. "weight" => 80,
  734. );
  735. $form["rank_code"] = array(
  736. "label" => t("Rank or Classification:"),
  737. "type" => "textfield",
  738. "value" => @$cur["rank_code"],
  739. "size" => 5,
  740. "description" => t("For example, FR, SO, JR, SR, GR for Freshman, Sophomore, Junior, Senior, and Graduate.") . "
  741. <br><b>" . t("Important:") . "</b> " . t("You must enter a code from the Allowed Student Ranks field
  742. on the System Settings form. For example, FR. If you do not do this, you will not be able to search
  743. for this student in FlightPath.") . "<br>&nbsp; &nbsp; &nbsp;" . t("Current value for Allowed Student Ranks:") . "
  744. <i>" . variable_get("allowed_student_ranks", "") . "</i>",
  745. "weight" => 90,
  746. );
  747. $major_code_array = $db->get_student_majors_from_db($student_cwid, TRUE, FALSE, FALSE);
  748. $temp = "";
  749. foreach ($major_code_array as $details) {
  750. if ((string)$details["is_editable"] == "1") {
  751. $temp .= "* ";
  752. }
  753. $temp .= $details["major_code"] . "\n";
  754. }
  755. $form["major_codes"] = array(
  756. "label" => t("Major code(s) and Directives:"),
  757. "type" => "textarea",
  758. "value" => $temp,
  759. "cols" => 40,
  760. "rows" => 5,
  761. "description" => t("Enter the student's major codes, one per line.
  762. <br>Ex:
  763. <br>&nbsp; &nbsp; ACCT
  764. <br>&nbsp; &nbsp; MATH
  765. <br>Advanced: If any of the level 3 (add-on) major codes can be 'editable' by the advisor or another
  766. privileged user during normal advising, add an asterisk
  767. at the beginning. For example: <b>*</b> ACCT|_COSC. If you are unsure what this means, do not enter an asterisk.
  768. <br>
  769. <br>Available directives (advanced):
  770. <ul>
  771. <li>LOCKED ~ level_3_class_code
  772. <ul>
  773. <li>
  774. This will tell FlightPath not to allow a user to make any changes (except in What If mode) to this student's degrees for the specified
  775. level 3 classification. For example, to prevent additions or removals from Concentrations (CONC) for this student, you would enter:
  776. <br> &nbsp; &nbsp; &nbsp; LOCKED ~ CONC
  777. <br>(notice the single tilde ~ character between the LOCKED keyword and the code for the degree class).
  778. </li>
  779. </ul>
  780. </li>
  781. </ul>
  782. "),
  783. "weight" => 100,
  784. );
  785. $form["catalog_year"] = array(
  786. "label" => t("Catalog year:"),
  787. "type" => "textfield",
  788. "value" => @$cur["catalog_year"],
  789. "size" => 10,
  790. "description" => t("Only the leading year is used. For example, for the
  791. catalog year 2008-2009, you would just enter 2008."),
  792. "weight" => 110,
  793. );
  794. $form["is_active"] = array(
  795. "label" => t("Active?:"),
  796. "type" => "select",
  797. "options" => array(1 => t("Y - Active"), 0 => t("N - Inactive")),
  798. "hide_please_select" => TRUE,
  799. "value" => @$cur["is_active"],
  800. "size" => 5,
  801. "description" => t("This setting means the student
  802. will not appear in searches automatically, unless the advisor specifies to search
  803. for inactive students."),
  804. "weight" => 120,
  805. );
  806. $form["submit"] = array(
  807. "type" => "submit",
  808. "value" => "Submit",
  809. "prefix" => "<hr>",
  810. "weight" => 500,
  811. );
  812. if ($student_cwid != "new" && user_has_permission("delete_users")) {
  813. $form["mark" . $m++] = array(
  814. "type" => "markup",
  815. "value" => "<div align='right'>
  816. " . t("Delete this student?") . " <input type='button' value='X'
  817. onClick='userDeleteStudent();'>
  818. </div>",
  819. "weight" => 600,
  820. );
  821. }
  822. return $form;
  823. }
  824. /**
  825. * Validate handler for editing student users.
  826. */
  827. function user_edit_student_user_form_validate($form, $form_state) {
  828. $values = $form_state["values"];
  829. // If a password was given, make sure it is appropriate.
  830. if (trim($values["new_password"]) != "") {
  831. if (strlen(trim($values["new_password"])) < 5) {
  832. form_error("new_password", t("Please enter a password that is at least 5 characters long."));
  833. return;
  834. }
  835. }
  836. // If creating a new user, make sure new_student_cwid and new_user_name are not
  837. // already in use.
  838. if ($values["student_cwid"] == "new") {
  839. $new_cwid = trim($values["new_student_cwid"]);
  840. $new_user_name = trim($values["new_user_name"]);
  841. // Check that username is at least 4 characters
  842. if (strlen($new_user_name) < 4) {
  843. form_error("new_user_name", t("The username you entered is too short. It must be at least 4 characters.
  844. Please select a different username."));
  845. return;
  846. }
  847. // Check cwid isn't already in use.
  848. $test = db_result(db_query("SELECT cwid FROM users WHERE cwid = '?' AND is_student = '1'", $new_cwid));
  849. if ($test == $new_cwid) {
  850. form_error("new_student_cwid", t("The cwid you entered is already in use. Please select a different cwid."));
  851. return;
  852. }
  853. // Check user_name isn't already in use.
  854. $test = db_result(db_query("SELECT user_name FROM users WHERE user_name = '?' ", $new_user_name));
  855. if ($test == $new_user_name) {
  856. form_error("new_user_name", t("The username you entered is already in use. Please select a different username."));
  857. return;
  858. }
  859. }
  860. }
  861. /**
  862. * Submit handler for editing student users.
  863. */
  864. function user_edit_student_user_form_submit($form, $form_state) {
  865. $values = $form_state["values"];
  866. foreach ($values as $key => $val) {
  867. if (!is_array($val)) {
  868. $values[$key] = trim($val);
  869. }
  870. }
  871. //fpm($values);
  872. $user_id = $values["user_id"];
  873. $student_cwid = $values["student_cwid"];
  874. // Are we supposed to DELETE a student?
  875. if ($values["perform_action2"] == "delete_student" && user_has_permission("delete_users")) {
  876. db_query("DELETE FROM students WHERE cwid = '?' ", $student_cwid);
  877. db_query("DELETE FROM users WHERE cwid = '?' AND is_student = '1' ", $student_cwid);
  878. watchdog("user_edit", "Deleted student user $user_id (cwid $student_cwid)");
  879. fp_add_message(t("User has been deleted."));
  880. fp_goto("admin/users/students");
  881. return;
  882. }
  883. $bool_is_new = FALSE;
  884. if ($student_cwid != "new") {
  885. // NOT a new student! Insert values normally.
  886. // First-- was there a password given? If so, insert that separate.
  887. if (trim($values["new_password"]) != "") {
  888. $new_pass = user_hash_password(trim($values["new_password"]));
  889. db_query("UPDATE users
  890. SET password = '?'
  891. WHERE cwid = '?'
  892. AND is_student = '1' ", $new_pass, $student_cwid);
  893. unset($values['new_password']);
  894. watchdog("user_edit", "Update student user with cwid @cwid with new password", array("@cwid" => $student_cwid));
  895. }
  896. // Okay, now we can just update everything else.
  897. // Update users table first...
  898. db_query("UPDATE users
  899. SET email = '?',
  900. f_name = '?',
  901. l_name = '?',
  902. is_disabled = '?'
  903. WHERE cwid = '?'
  904. AND is_student = '1' ", trim(strtolower($values["email"])), $values["f_name"],
  905. $values["l_name"], $values["is_disabled"],
  906. $student_cwid);
  907. // Now, update the students table entry.
  908. db_query("UPDATE students
  909. SET cumulative_hours = '?',
  910. gpa = '?',
  911. rank_code = '?',
  912. catalog_year = '?',
  913. is_active = '?'
  914. WHERE cwid = '?'", $values["cumulative_hours"], $values["gpa"], $values["rank_code"],
  915. $values["catalog_year"],
  916. $values["is_active"], $student_cwid);
  917. watchdog("user_edit", "Update student user with various values: @other", array("@other" => ppm($values, TRUE)));
  918. fp_add_message(t("User updated successfully."));
  919. }
  920. else {
  921. // This is a NEW user! We need to perform inserts. Thanks to our validate handler,
  922. // we know all of the values we have are valid.
  923. $bool_is_new = TRUE;
  924. if (trim($values["l_name"]) == "") {
  925. $values["l_name"] = $values["new_user_name"]; // force a last name if none supplied
  926. }
  927. db_query("INSERT INTO users (user_name, password, is_student, email, cwid, f_name, l_name, is_disabled)
  928. VALUES ('?', '?', '1', '?', '?', '?', '?', '?')
  929. ", $values["new_user_name"], user_hash_password($values["new_password"]), trim(strtolower($values["email"])), $values["new_student_cwid"],
  930. $values["f_name"], $values["l_name"], intval($values["is_disabled"]));
  931. db_query("INSERT INTO students (cwid, cumulative_hours, gpa, rank_code, catalog_year, is_active)
  932. VALUES ('?', '?', '?', '?', '?', '?')
  933. ", $values["new_student_cwid"], $values["cumulative_hours"], $values["gpa"], $values["rank_code"],
  934. $values["catalog_year"], intval($values["is_active"]));
  935. fp_add_message(t("User created successfully."));
  936. $student_cwid = $values["new_student_cwid"];
  937. unset($values['new_password']);
  938. watchdog("user_edit", "Create new student user with various values: @other", array("@other" => ppm($values, TRUE)));
  939. }
  940. // Now, regardless if this was a new student or not, we need to update the student_degrees table.
  941. // First, delete what's there for this CWID.
  942. db_query("DELETE FROM student_degrees WHERE student_id = ?", $student_cwid);
  943. // Now, insert.
  944. $temp = explode("\n", $values["major_codes"]);
  945. foreach ($temp as $mc) {
  946. $mc = trim($mc);
  947. if ($mc == "") continue;
  948. $is_editable = "0";
  949. if (strstr($mc, "*")) {
  950. $is_editable = "1";
  951. $mc = trim(str_replace("*", "", $mc)); // remove the asterisk.
  952. }
  953. // Now, insert into the table.
  954. db_query("INSERT INTO student_degrees (student_id, major_code, is_editable)
  955. VALUES (?, ?, ?) ", array($student_cwid, $mc, $is_editable));
  956. }
  957. if ($bool_is_new) {
  958. // If new, we need to go to the regular edit form for this newly created student.
  959. fp_goto("admin/users/edit-student-user", "student_cwid=" . $values["new_student_cwid"]);
  960. }
  961. // If not new, it just reloads the form normally.
  962. }

Functions

Namesort descending Description
user_display_student_users Similar to user_display_users, except only for student users.
user_edit_student_user_form Let the user edit a studentuser's information.
user_edit_student_user_form_submit Submit handler for editing student users.
user_edit_student_user_form_validate Validate handler for editing student users.
user_student_edit_student_courses_form This is the form which we will use to manage a student's courses they've taken.
user_student_edit_student_courses_form_submit
user_student_edit_student_courses_form_validate
user_student_list_filter_form
user_student_list_filter_form_submit