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. * This is the form which we will use to manage a student's courses they've taken.
  8. */
  9. function user_student_edit_student_courses_form() {
  10. fp_add_js(fp_get_module_path("user") . "/js/user.js");
  11. $m = 0;
  12. $form = array();
  13. $student_cwid = $_REQUEST["student_cwid"]; // now getting it from argument
  14. $user_id = db_get_user_id_from_cwid($student_cwid, "student");
  15. $de_catalog_year = @$_REQUEST["de_catalog_year"];
  16. // Figure out what the page's sub-tabs should be, and set them.
  17. $tab_array = array();
  18. $tab_array[0]["title"] = t("Edit Student");
  19. $tab_array[0]["active"] = FALSE;
  20. $tab_array[0]["on_click"] = "window.location=\"" . fp_url("admin/users/edit-student-user", "student_cwid=$student_cwid&de_catalog_year=$de_catalog_year") . "\"";
  21. $tab_array[1]["title"] = t("Edit Student Courses");
  22. $tab_array[1]["active"] = TRUE;
  23. $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") . "\"";
  24. fp_set_page_sub_tabs($tab_array);
  25. if ($student_cwid != "new") {
  26. $name = fp_get_student_name($student_cwid);
  27. fp_set_title(t("Edit Student Courses @name (@id)", array("@name" => $name, "@id" => $student_cwid)));
  28. }
  29. else {
  30. // A new student! We can't create a new student until a CWID is assigned.
  31. fp_set_title(t("Create New Student User"));
  32. $form["mark_sorry"] = array(
  33. "type" => "markup",
  34. "value" => "<p>" . t("Sorry, but you cannot add student courses until the student
  35. has been fully created (and given a CWID). Use the Edit Student button above
  36. to return to that screen.") . "</p>",
  37. );
  38. return $form;
  39. }
  40. $form["user_id"] = array(
  41. "type" => "hidden",
  42. "value" => $user_id,
  43. );
  44. $form["perform_action2"] = array(
  45. "type" => "hidden",
  46. "value" => "",
  47. );
  48. $form["student_cwid"] = array(
  49. "type" => "hidden",
  50. "value" => $student_cwid,
  51. );
  52. // Okay, let's create a table in which we will place the student's courses.
  53. $form["mark" . $m++] = array(
  54. "value" => "<p>
  55. " . ("Enter the student's local (non-transfer) courses they have enrolled in at your institution.") . "
  56. <ul>
  57. <li>" . t("Course: Enter the full course subject ID and num, separated by a space. Ex: ACCT 101") . "</li>
  58. <li>" . t("Term: Enter the term code that this student enrolled in this course. Ex: 201540") . "</li>
  59. <li>" . t("Grade: Enter the grade they earned. Ex: B") . "</li>
  60. <li>" . t("Hrs: Enter the hours awarded. Ex: 3") . "</li>
  61. <li>" . t("Lvl: (optional), enter the level code for this course. Ex: UG") . "</li>
  62. </ul>
  63. " . t("<b>Note:</b> If you have any routines which might overwrite this data (in the student_courses table), then this
  64. data may be ignored or deleted!") . "
  65. </p>",
  66. );
  67. $form["warn_me"] = array(
  68. "type" => "checkbox",
  69. "label" => t("Warn me if I enter a course which doesn't exist in draft_courses (good for catching typos)"),
  70. "value" => "yes",
  71. );
  72. $form["mark" . $m++] = array(
  73. "value" => "
  74. <table border='0' width='100%' cellpadding='3' cellspacing='0'>
  75. <tr>
  76. <th>" . t("Course") . "</th>
  77. <th>" . t("Term") . "</th>
  78. <th>" . t("Grade") . "</th>
  79. <th>" . t("Hrs") . "</th>
  80. <th>" . t("Lvl") . "</th>
  81. </tr>",
  82. );
  83. // Let's get an array of what courses the student has already taken (if any)
  84. $courses = array();
  85. $res = db_query("SELECT * FROM student_courses
  86. WHERE student_id = '?'
  87. ORDER BY subject_id, course_num", $student_cwid);
  88. while ($cur = db_fetch_array($res)) {
  89. $courses[] = array(
  90. "course" => $cur["subject_id"] . " " . $cur["course_num"],
  91. "term" => $cur["term_id"],
  92. "grade" => $cur["grade"],
  93. "hrs" => $cur["hours_awarded"] * 1, // will trim excess zeroes if there
  94. "lvl" => $cur["level_code"],
  95. );
  96. }
  97. // Let's add 10 additional (blank) lines to the courses array.
  98. for ($t = 0; $t < 10; $t++) {
  99. $courses[] = array(
  100. "course" => "",
  101. "term" => "",
  102. "grade" => "",
  103. "hrs" => "",
  104. "lvl" => "",
  105. );
  106. }
  107. // Okay, now let's go through the courses array and display in the table...
  108. $stripe = "";
  109. foreach ($courses as $t => $val) {
  110. if ($stripe == "") {
  111. $stripe = "style='background-color: beige;'";
  112. }
  113. else {
  114. $stripe = "";
  115. }
  116. $form["course_$t"] = array(
  117. "prefix" => "<tr $stripe >
  118. <td valign='top'>",
  119. "type" => "textfield",
  120. "size" => 12,
  121. "suffix" => "</td>",
  122. "value" => $val["course"],
  123. );
  124. $form["term_$t"] = array(
  125. "prefix" => "<td valign='top'>",
  126. "type" => "textfield",
  127. "size" => 8,
  128. "suffix" => "</td>",
  129. "value" => $val["term"],
  130. );
  131. $form["grade_$t"] = array(
  132. "prefix" => "<td valign='top'>",
  133. "type" => "textfield",
  134. "size" => 4,
  135. "suffix" => "</td>",
  136. "value" => $val["grade"],
  137. );
  138. $form["hrs_$t"] = array(
  139. "prefix" => "<td valign='top'>",
  140. "type" => "textfield",
  141. "size" => 4,
  142. "suffix" => "</td>",
  143. "value" => $val["hrs"],
  144. );
  145. $form["lvl_$t"] = array(
  146. "prefix" => "<td valign='top'>",
  147. "type" => "textfield",
  148. "size" => 4,
  149. "suffix" => "</td>
  150. </tr>",
  151. "value" => $val["lvl"],
  152. );
  153. } // for loop
  154. $form["number_of_courses"] = array(
  155. "type" => "hidden",
  156. "value" => count($courses),
  157. );
  158. // close table.
  159. $form["mark" . $m++] = array(
  160. "value" => "</table>
  161. <p>" . t("Rows without Course entered will be skipped.
  162. <br><br><b>Note:</b> To add more blank rows, save your work. When the page reloads, there will be additional
  163. blank rows to add new courses.") . "</p>",
  164. );
  165. $form["submit_btn"] = array(
  166. "type" => "submit",
  167. "value" => "Submit",
  168. );
  169. return $form;
  170. } // user_student_edit_student_courses_form
  171. function user_student_edit_student_courses_form_validate($form, $form_state) {
  172. // If the user requested it, check to see if the course exists (in the draft_courses table)
  173. if ($form_state["values"]["warn_me"] === TRUE) {
  174. // Yes, the user wants to be warned if they entered a course which doesn't exist.
  175. $number_of_courses = intval($form_state["values"]["number_of_courses"]);
  176. for ($t = 0; $t < $number_of_courses; $t++) {
  177. $course = trim($form_state["values"]["course_$t"]);
  178. if ($course == "") continue;
  179. $temp = explode(" ", $course);
  180. $subject_id = trim($temp[0]);
  181. $course_num = trim($temp[1]);
  182. // Check to see that this course exists.
  183. $res = db_query("SELECT subject_id FROM draft_courses
  184. WHERE subject_id = '?'
  185. AND course_num = '?' ", $subject_id, $course_num);
  186. $cur = db_fetch_array($res);
  187. if ($cur["subject_id"] != $subject_id) {
  188. 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.",
  189. array("%subject_id" => $subject_id, "%course_num" => $course_num)));
  190. }
  191. }
  192. }
  193. }
  194. function user_student_edit_student_courses_form_submit($form, $form_state) {
  195. $student_id = $form_state["values"]["student_cwid"];
  196. // Erase what's there already:
  197. db_query("DELETE FROM student_courses WHERE student_id = '?' ", $student_id);
  198. $number_of_courses = intval($form_state["values"]["number_of_courses"]);
  199. for ($t = 0; $t < $number_of_courses; $t++) {
  200. $course = trim($form_state["values"]["course_$t"]);
  201. if ($course == "") continue;
  202. $temp = explode(" ", $course);
  203. $subject_id = trim($temp[0]);
  204. $course_num = trim($temp[1]);
  205. $term_id = trim($form_state["values"]["term_$t"]);
  206. $grade = trim($form_state["values"]["grade_$t"]);
  207. $hours_awarded = trim($form_state["values"]["hrs_$t"]);
  208. $level_code = trim($form_state["values"]["lvl_$t"]);
  209. // Add to table
  210. db_query("INSERT INTO student_courses (student_id, subject_id, course_num, hours_awarded, grade, term_id, level_code)
  211. VALUES ('?', '?', '?', '?', '?', '?', '?')", $student_id, $subject_id, $course_num, $hours_awarded, $grade, $term_id, $level_code);
  212. }
  213. fp_add_message(t("Student courses updated."));
  214. } // student_courses_form_submit
  215. /**
  216. * Let the user edit a studentuser's information.
  217. */
  218. function user_edit_student_user_form() {
  219. fp_add_js(fp_get_module_path("user") . "/js/user.js");
  220. $form = array();
  221. $m = 0;
  222. $student_cwid = @$_REQUEST["student_cwid"]; // now getting it from argument
  223. $de_catalog_year = @$_REQUEST["de_catalog_year"];
  224. $user_id = db_get_user_id_from_cwid($student_cwid, "student");
  225. $db = get_global_database_handler();
  226. // Figure out what the page's sub-tabs should be, and set them.
  227. $tab_array = array();
  228. $tab_array[0]["title"] = t("Edit Student");
  229. $tab_array[0]["active"] = TRUE;
  230. $tab_array[0]["on_click"] = "window.location=\"" . fp_url("admin/users/edit-student-user", "student_cwid=$student_cwid&de_catalog_year=$de_catalog_year") . "\"";
  231. $tab_array[1]["title"] = t("Edit Student Courses");
  232. $tab_array[1]["active"] = FALSE;
  233. $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") . "\"";
  234. fp_set_page_sub_tabs($tab_array);
  235. if ($student_cwid != "new") {
  236. $name = fp_get_student_name($student_cwid);
  237. fp_set_title(t("Edit Student User @name (@id)", array("@name" => $name, "@id" => $student_cwid)));
  238. }
  239. else {
  240. // A new student!
  241. fp_set_title(t("Create New Student User"));
  242. }
  243. $form["user_id"] = array(
  244. "type" => "hidden",
  245. "value" => $user_id,
  246. );
  247. $form["perform_action2"] = array(
  248. "type" => "hidden",
  249. "value" => "",
  250. );
  251. $form["student_cwid"] = array(
  252. "type" => "hidden",
  253. "value" => $student_cwid,
  254. );
  255. // TODO: At the moment, only faculty can be assigned roles in FP. However, this could change
  256. // one day, so I am going to leave this code in place for students, but commented out.
  257. /*
  258. $user_roles = system_get_roles_for_user($user_id);
  259. //fpm($user_roles);
  260. $default_values = array();
  261. foreach ($user_roles as $rid => $val) {
  262. $default_values[$rid] = $rid;
  263. }
  264. // Show a list of roles in the system which we may select from, and check the ones
  265. // all ready assigned to this user.
  266. $options = array();
  267. $res = db_query("SELECT * FROM roles ORDER BY rid");
  268. while ($cur = db_fetch_array($res)) {
  269. $key = $cur["rid"];
  270. $value = $cur["name"];
  271. if ($key > 2) {
  272. $options[$key] = $value;
  273. }
  274. }
  275. //fpm($default_values);
  276. $form["roles"] = array(
  277. "label" => t("Check which roles this user should have."),
  278. "type" => "checkboxes",
  279. "options" => $options,
  280. "value" => $default_values,
  281. );
  282. */
  283. // Let's present the form elements to allow some basic editing of this user.
  284. // Only if we are making a new student...
  285. if ($student_cwid == "new") {
  286. $form["new_student_cwid"] = array(
  287. "label" => t("Enter a new CWID, unique to students:"),
  288. "type" => "textfield",
  289. "size" => 20,
  290. "required" => TRUE,
  291. "description" => t("Enter an ID for this student. It may be the same
  292. as a faculty member, but may not be the same as any existing
  293. student. You will not be able to edit this value, once saved."),
  294. "weight" => 10,
  295. );
  296. $form["new_user_name"] = array(
  297. "label" => t("Enter a new username, unique to all users:"),
  298. "type" => "textfield",
  299. "size" => 20,
  300. "required" => TRUE,
  301. "description" => t("Enter a username for this user. This is what the user will
  302. use to log in. It must be unique to all users (cannot have both
  303. a faculty and a student with the same username). You will not
  304. be able to edit this value, once saved."),
  305. "weight" => 10,
  306. );
  307. $cur = array();
  308. }
  309. else {
  310. // NOT a new student. Load their information normally.
  311. $res = db_query("SELECT * FROM users u, students s
  312. WHERE u.cwid = '?'
  313. AND u.is_student = '1'
  314. AND u.cwid = s.cwid", $student_cwid);
  315. $cur = db_fetch_array($res);
  316. }
  317. $user_name = @$cur["user_name"];
  318. if ($user_name != "") {
  319. $form["mark" . $m++] = array(
  320. "value" => "<p><b>Username:</b> $user_name</p>",
  321. );
  322. }
  323. $form["new_password"] = array(
  324. "label" => t("Enter a new password for this user:"),
  325. "type" => "textfield",
  326. "size" => 20,
  327. "required" => ($student_cwid == "new") ? TRUE : FALSE,
  328. "description" => t("If you enter any value here, it will change the
  329. user's password in FlightPath. If you are using the LDAP module,
  330. the LDAP password will be unaffected."),
  331. "weight" => 20,
  332. );
  333. $form["email"] = array(
  334. "label" => t("Email:"),
  335. "type" => "textfield",
  336. "value" => @$cur["email"],
  337. "weight" => 30,
  338. );
  339. $form["f_name"] = array(
  340. "label" => t("First name:"),
  341. "type" => "textfield",
  342. "value" => @$cur["f_name"],
  343. "weight" => 40,
  344. );
  345. $form["l_name"] = array(
  346. "label" => t("Last name:"),
  347. "type" => "textfield",
  348. "value" => @$cur["l_name"],
  349. "weight" => 50,
  350. );
  351. $form["is_disabled"] = array(
  352. "label" => t("Is disabled:"),
  353. "type" => "textfield",
  354. "value" => @$cur["is_disabled"],
  355. "size" => 5,
  356. "description" => t("Enter only 1 or 0 (number one for 'yes', or number zero for 'no'). This setting means the user will
  357. be ignored by FlightPath, and they will not be able to log in or be searched for.
  358. It is safer to disable a user, than delete them."),
  359. "weight" => 60,
  360. );
  361. // Unique to students...
  362. $form["cumulative_hours"] = array(
  363. "label" => t("Cumulative hours:"),
  364. "type" => "textfield",
  365. "value" => @$cur["cumulative_hours"],
  366. "size" => 5,
  367. "description" => t("How many hours has the student earned? NOTE: If FlightPath is set to
  368. calculate this, rather than read from the database, whatever you enter here
  369. will be ignored, and instead this value will be calculated on the fly when
  370. the student is loaded."),
  371. "weight" => 70,
  372. );
  373. $form["gpa"] = array(
  374. "label" => t("GPA:"),
  375. "type" => "textfield",
  376. "value" => @$cur["gpa"],
  377. "size" => 5,
  378. "description" => t("What is the student's GPA? NOTE: If FlightPath is set to
  379. calculate this, rather than read from the database, whatever you enter here
  380. will be ignored, and instead this value will be calculated on the fly when
  381. the student is loaded."),
  382. "weight" => 80,
  383. );
  384. $form["rank_code"] = array(
  385. "label" => t("Rank or Classification:"),
  386. "type" => "textfield",
  387. "value" => @$cur["rank_code"],
  388. "size" => 5,
  389. "description" => t("For example, FR, SO, JR, SR, GR for Freshman, Sophomore, Junior, Senior, and Graduate.") . "
  390. <br><b>" . t("Important:") . "</b> " . t("You must enter a code from the Allowed Student Ranks field
  391. on the System Settings form. For example, FR. If you do not do this, you will not be able to search
  392. for this student in FlightPath.") . "<br>&nbsp; &nbsp; &nbsp;" . t("Current value for Allowed Student Ranks:") . "
  393. <i>" . variable_get("allowed_student_ranks", "") . "</i>",
  394. "weight" => 90,
  395. );
  396. $major_code_array = $db->get_student_majors_from_db($student_cwid, TRUE, FALSE, FALSE);
  397. $temp = "";
  398. foreach ($major_code_array as $details) {
  399. if ((string)$details["is_editable"] == "1") {
  400. $temp .= "* ";
  401. }
  402. $temp .= $details["major_code"] . "\n";
  403. }
  404. $form["major_codes"] = array(
  405. "label" => t("Major code(s) and Directives:"),
  406. "type" => "textarea",
  407. "value" => $temp,
  408. "cols" => 40,
  409. "rows" => 5,
  410. "description" => t("Enter the student's major codes, one per line.
  411. <br>Ex:
  412. <br>&nbsp; &nbsp; ACCT
  413. <br>&nbsp; &nbsp; MATH
  414. <br>Advanced: If any of the level 3 (add-on) major codes can be 'editable' by the advisor or another
  415. privileged user during normal advising, add an asterisk
  416. at the beginning. For example: <b>*</b> ACCT|_COSC. If you are unsure what this means, do not enter an asterisk.
  417. <br>
  418. <br>Available directives (advanced):
  419. <ul>
  420. <li>LOCKED ~ level_3_class_code
  421. <ul>
  422. <li>
  423. 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
  424. level 3 classification. For example, to prevent additions or removals from Concentrations (CONC) for this student, you would enter:
  425. <br> &nbsp; &nbsp; &nbsp; LOCKED ~ CONC
  426. <br>(notice the single tilde ~ character between the LOCKED keyword and the code for the degree class).
  427. </li>
  428. </ul>
  429. </li>
  430. </ul>
  431. "),
  432. "weight" => 100,
  433. );
  434. $form["catalog_year"] = array(
  435. "label" => t("Catalog year:"),
  436. "type" => "textfield",
  437. "value" => @$cur["catalog_year"],
  438. "size" => 10,
  439. "description" => t("Only the leading year is used. For example, for the
  440. catalog year 2008-2009, you would just enter 2008."),
  441. "weight" => 110,
  442. );
  443. $form["is_active"] = array(
  444. "label" => t("Is active:"),
  445. "type" => "textfield",
  446. "value" => @$cur["is_active"],
  447. "size" => 5,
  448. "description" => t("Enter only 1 or 0 (number one for 'yes', or number zero for 'no'). This setting means the student
  449. will not appear in searches automatically, unless the advisor specifies to search
  450. for inactive students."),
  451. "weight" => 120,
  452. );
  453. $form["submit"] = array(
  454. "type" => "submit",
  455. "value" => "Submit",
  456. "prefix" => "<hr>",
  457. "weight" => 500,
  458. );
  459. if ($student_cwid != "new" && user_has_permission("delete_users")) {
  460. $form["mark" . $m++] = array(
  461. "type" => "markup",
  462. "value" => "<div align='right'>
  463. " . t("Delete this student?") . " <input type='button' value='X'
  464. onClick='userDeleteStudent();'>
  465. </div>",
  466. "weight" => 510,
  467. );
  468. }
  469. return $form;
  470. }
  471. /**
  472. * Validate handler for editing student users.
  473. */
  474. function user_edit_student_user_form_validate($form, $form_state) {
  475. $values = $form_state["values"];
  476. // If a password was given, make sure it is appropriate.
  477. if (trim($values["new_password"]) != "") {
  478. if (strlen(trim($values["new_password"])) < 5) {
  479. form_error("new_password", t("Please enter a password that is at least 5 characters long."));
  480. return;
  481. }
  482. }
  483. // If creating a new user, make sure new_student_cwid and new_user_name are not
  484. // already in use.
  485. if ($values["student_cwid"] == "new") {
  486. $new_cwid = trim($values["new_student_cwid"]);
  487. $new_user_name = trim($values["new_user_name"]);
  488. /* // CWIDS are no longer required to be numeric.
  489. // Check that cwid is numeric.
  490. if (!is_numeric($new_cwid)) {
  491. form_error("new_student_cwid", t("The cwid you entered is not numeric. CWIDs must contain only numbers.
  492. Please select a different cwid."));
  493. return;
  494. }
  495. */
  496. // Check that username is at least 4 characters
  497. if (strlen($new_user_name) < 4) {
  498. form_error("new_user_name", t("The username you entered is too short. It must be at least 4 characters.
  499. Please select a different username."));
  500. return;
  501. }
  502. // Check cwid isn't already in use.
  503. $test = db_result(db_query("SELECT cwid FROM users WHERE cwid = '?' AND is_student = '1'", $new_cwid));
  504. if ($test == $new_cwid) {
  505. form_error("new_student_cwid", t("The cwid you entered is already in use. Please select a different cwid."));
  506. return;
  507. }
  508. // Check user_name isn't already in use.
  509. $test = db_result(db_query("SELECT user_name FROM users WHERE user_name = '?' ", $new_user_name));
  510. if ($test == $new_user_name) {
  511. form_error("new_user_name", t("The username you entered is already in use. Please select a different username."));
  512. return;
  513. }
  514. }
  515. }
  516. /**
  517. * Submit handler for editing student users.
  518. */
  519. function user_edit_student_user_form_submit($form, $form_state) {
  520. $values = $form_state["values"];
  521. foreach ($values as $key => $val) {
  522. if (!is_array($val)) {
  523. $values[$key] = trim($val);
  524. }
  525. }
  526. //fpm($values);
  527. $user_id = $values["user_id"];
  528. $student_cwid = $values["student_cwid"];
  529. // Are we supposed to DELETE a student?
  530. if ($values["perform_action2"] == "delete_student" && user_has_permission("delete_users")) {
  531. db_query("DELETE FROM students WHERE cwid = '?' ", $student_cwid);
  532. db_query("DELETE FROM users WHERE cwid = '?' AND is_student = '1' ", $student_cwid);
  533. fp_add_message(t("User has been deleted."));
  534. fp_goto("admin/users/students");
  535. return;
  536. }
  537. $bool_is_new = FALSE;
  538. if ($student_cwid != "new") {
  539. // NOT a new student! Insert values normally.
  540. // First-- was there a password given? If so, insert that separate.
  541. if (trim($values["new_password"]) != "") {
  542. $new_pass = user_hash_password(trim($values["new_password"]));
  543. db_query("UPDATE users
  544. SET password = '?'
  545. WHERE cwid = '?'
  546. AND is_student = '1' ", $new_pass, $student_cwid);
  547. }
  548. // Okay, now we can just update everything else.
  549. // Update users table first...
  550. db_query("UPDATE users
  551. SET email = '?',
  552. f_name = '?',
  553. l_name = '?',
  554. is_disabled = '?'
  555. WHERE cwid = '?'
  556. AND is_student = '1' ", $values["email"], $values["f_name"],
  557. $values["l_name"], $values["is_disabled"],
  558. $student_cwid);
  559. // Now, update the students table entry.
  560. db_query("UPDATE students
  561. SET cumulative_hours = '?',
  562. gpa = '?',
  563. rank_code = '?',
  564. catalog_year = '?',
  565. is_active = '?'
  566. WHERE cwid = '?'", $values["cumulative_hours"], $values["gpa"], $values["rank_code"],
  567. $values["catalog_year"],
  568. $values["is_active"], $student_cwid);
  569. fp_add_message(t("User updated successfully."));
  570. }
  571. else {
  572. // This is a NEW user! We need to perform inserts. Thanks to our validate handler,
  573. // we know all of the values we have are valid.
  574. $bool_is_new = TRUE;
  575. if (trim($values["l_name"]) == "") {
  576. $values["l_name"] = $values["new_user_name"]; // force a last name if none supplied
  577. }
  578. db_query("INSERT INTO users (user_name, password, is_student, email, cwid, f_name, l_name, is_disabled)
  579. VALUES ('?', '?', '1', '?', '?', '?', '?', '?')
  580. ", $values["new_user_name"], user_hash_password($values["new_password"]), $values["email"], $values["new_student_cwid"],
  581. $values["f_name"], $values["l_name"], intval($values["is_disabled"]));
  582. db_query("INSERT INTO students (cwid, cumulative_hours, gpa, rank_code, catalog_year, is_active)
  583. VALUES ('?', '?', '?', '?', '?', '?')
  584. ", $values["new_student_cwid"], $values["cumulative_hours"], $values["gpa"], $values["rank_code"],
  585. $values["catalog_year"], intval($values["is_active"]));
  586. fp_add_message(t("User created successfully."));
  587. $student_cwid = $values["new_student_cwid"];
  588. }
  589. // Now, regardless if this was a new student or not, we need to update the student_degrees table.
  590. // First, delete what's there for this CWID.
  591. db_query("DELETE FROM student_degrees WHERE student_id = ?", $student_cwid);
  592. // Now, insert.
  593. $temp = explode("\n", $values["major_codes"]);
  594. foreach ($temp as $mc) {
  595. $mc = trim($mc);
  596. if ($mc == "") continue;
  597. $is_editable = "0";
  598. if (strstr($mc, "*")) {
  599. $is_editable = "1";
  600. $mc = trim(str_replace("*", "", $mc)); // remove the asterisk.
  601. }
  602. // Now, insert into the table.
  603. db_query("INSERT INTO student_degrees (student_id, major_code, is_editable)
  604. VALUES (?, ?, ?) ", array($student_cwid, $mc, $is_editable));
  605. }
  606. if ($bool_is_new) {
  607. // If new, we need to go to the regular edit form for this newly created student.
  608. fp_goto("admin/users/edit-student-user", "student_cwid=" . $values["new_student_cwid"]);
  609. }
  610. // If not new, it just reloads the form normally.
  611. }

Functions

Namesort descending Description
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