user.module

  1. 6.x modules/user/user.module
  2. 4.x modules/user/user.module
  3. 5.x modules/user/user.module

File

modules/user/user.module
View source
  1. <?php
  2. /**
  3. * Implementation of hook_menu
  4. */
  5. function user_menu() {
  6. $items = array();
  7. // This one will appear in our admin menu
  8. $items["admin/config/users"] = array(
  9. "title" => "Users",
  10. "description" => "Search and manage FlightPath users",
  11. "page_callback" => "user_subtab_switchboard",
  12. "access_arguments" => array("manage_users"),
  13. "type" => MENU_TYPE_NORMAL_ITEM,
  14. "tab_parent" => "admin-tools/admin",
  15. "page_settings" => array(
  16. "menu_icon" => fp_get_module_path('user') . "/icons/group.png",
  17. ),
  18. );
  19. // Subtab for which type of user we want to work on.
  20. $items["admin/users/faculty"] = array(
  21. "title" => "Faculty / Staff Users",
  22. "description" => "Search and manage faculty/staff users",
  23. "page_callback" => "user_display_users",
  24. "access_arguments" => array("manage_users"),
  25. "page_settings" => array(
  26. "page_has_search" => FALSE,
  27. "page_banner_is_link" => TRUE,
  28. "page_hide_report_error" => TRUE,
  29. "menu_links" => array(
  30. 0 => array(
  31. "text" => "Admin Console",
  32. "path" => "admin-tools/admin",
  33. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  34. ),
  35. ),
  36. ),
  37. "type" => MENU_TYPE_SUB_TAB,
  38. "tab_family" => "users",
  39. "tab_parent" => "admin-tools/admin",
  40. "weight" => 100,
  41. );
  42. $items["admin/users/students"] = array(
  43. "title" => "Student Users",
  44. "page_callback" => "user_display_student_users",
  45. "access_arguments" => array("manage_users"),
  46. "page_settings" => array(
  47. "page_has_search" => FALSE,
  48. "page_banner_is_link" => TRUE,
  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_SUB_TAB,
  59. "tab_family" => "users",
  60. "tab_parent" => "admin-tools/admin",
  61. );
  62. $items["admin/config/user-roles"] = array(
  63. "title" => "User roles",
  64. "description" => "Manage roles for users. Ex: advisors, viewers, etc.",
  65. "page_callback" => "fp_render_form",
  66. "page_arguments" => array("user_user_roles_form"),
  67. "access_arguments" => array("can_edit_user_roles"),
  68. "page_settings" => array(
  69. "menu_icon" => fp_get_module_path('user') . "/icons/medal_gold_1.png",
  70. "page_has_search" => FALSE,
  71. "page_banner_is_link" => TRUE,
  72. "page_hide_report_error" => TRUE,
  73. "menu_links" => array(
  74. 0 => array(
  75. "text" => "Admin Console",
  76. "path" => "admin-tools/admin",
  77. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  78. ),
  79. ),
  80. ),
  81. "type" => MENU_TYPE_NORMAL_ITEM,
  82. "tab_parent" => "admin-tools/admin",
  83. );
  84. $items["admin/users/edit-user"] = array(
  85. "title" => "Edit Faculty/Staff User",
  86. "page_callback" => "fp_render_form",
  87. "page_arguments" => array("user_edit_user_form"),
  88. "access_arguments" => array("manage_users"),
  89. "page_settings" => array(
  90. "page_has_search" => FALSE,
  91. "page_banner_is_link" => TRUE,
  92. "page_hide_report_error" => TRUE,
  93. "menu_links" => array(
  94. 0 => array(
  95. "text" => "Admin Console",
  96. "path" => "admin-tools/admin",
  97. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  98. ),
  99. 1 => array(
  100. "text" => "Back to Users list",
  101. "path" => "admin/users/faculty",
  102. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  103. ),
  104. ),
  105. ),
  106. "type" => MENU_TYPE_NORMAL_ITEM,
  107. "tab_parent" => "admin-tools/admin",
  108. );
  109. $items["admin/users/edit-user/advisees"] = array(
  110. "title" => "Edit Faculty/Staff User Advisees",
  111. "page_callback" => "fp_render_form",
  112. "page_arguments" => array("user_edit_user_advisees_form"),
  113. "access_arguments" => array("manage_users"),
  114. "page_settings" => array(
  115. "page_has_search" => FALSE,
  116. "page_banner_is_link" => TRUE,
  117. "page_hide_report_error" => TRUE,
  118. "menu_links" => array(
  119. 0 => array(
  120. "text" => "Admin Console",
  121. "path" => "admin-tools/admin",
  122. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  123. ),
  124. 1 => array(
  125. "text" => "Back to Users list",
  126. "path" => "admin/users/faculty",
  127. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  128. ),
  129. ),
  130. ),
  131. "type" => MENU_TYPE_NORMAL_ITEM,
  132. "tab_parent" => "admin-tools/admin",
  133. );
  134. $items["admin/users/edit-student-user"] = array(
  135. "title" => "Edit Student",
  136. "page_callback" => "fp_render_form",
  137. "page_arguments" => array("user_edit_student_user_form"),
  138. "access_arguments" => array("manage_users"),
  139. "page_settings" => array(
  140. "page_has_search" => FALSE,
  141. "page_banner_is_link" => TRUE,
  142. "page_hide_report_error" => TRUE,
  143. "menu_links" => array(
  144. 0 => array(
  145. "text" => "Admin Console",
  146. "path" => "admin-tools/admin",
  147. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  148. ),
  149. 1 => array(
  150. "text" => "Back to Users list",
  151. "path" => "admin/users/students",
  152. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  153. ),
  154. ),
  155. ),
  156. "type" => MENU_TYPE_NORMAL_ITEM,
  157. "tab_parent" => "admin-tools/admin",
  158. "file" => menu_get_module_path("user") . "/user.student.inc",
  159. );
  160. $items["admin/users/edit-student-user/courses"] = array(
  161. "title" => "Edit Student Courses",
  162. "page_callback" => "fp_render_form",
  163. "page_arguments" => array("user_student_edit_student_courses_form"),
  164. "access_arguments" => array("manage_users"),
  165. "page_settings" => array(
  166. "page_has_search" => FALSE,
  167. "page_banner_is_link" => TRUE,
  168. "page_hide_report_error" => TRUE,
  169. "menu_links" => array(
  170. 0 => array(
  171. "text" => "Admin Console",
  172. "path" => "admin-tools/admin",
  173. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  174. ),
  175. 1 => array(
  176. "text" => "Back to Users list",
  177. "path" => "admin/users/students",
  178. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  179. ),
  180. ),
  181. ),
  182. "type" => MENU_TYPE_CALLBACK,
  183. "tab_parent" => "admin-tools/admin",
  184. "file" => menu_get_module_path("user") . "/user.student.inc",
  185. );
  186. $items["admin/config/permissions"] = array(
  187. "title" => "Permissions",
  188. "description" => "Manage permissions for user roles in FlightPath",
  189. "page_callback" => "fp_render_form",
  190. "page_arguments" => array("user_permissions_form"),
  191. "access_arguments" => array("can_edit_permissions"),
  192. "page_settings" => array(
  193. "menu_icon" => fp_get_module_path('user') . "/icons/key.png",
  194. "page_has_search" => FALSE,
  195. "page_banner_is_link" => TRUE,
  196. "page_hide_report_error" => TRUE,
  197. "menu_links" => array(
  198. 0 => array(
  199. "text" => "Admin Console",
  200. "path" => "admin-tools/admin",
  201. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  202. ),
  203. ),
  204. ),
  205. "type" => MENU_TYPE_NORMAL_ITEM,
  206. "tab_parent" => "admin-tools/admin",
  207. );
  208. return $items;
  209. }
  210. /**
  211. * Decide what should happen when we go to "admin/config/users" by itself
  212. */
  213. function user_subtab_switchboard() {
  214. // For now, we will just always go to the faculty section, though this function
  215. // is helpful if that needs to change one day.
  216. $de_catalog_year = admin_get_de_catalog_year();
  217. fp_goto("admin/users/faculty", "de_catalog_year=$de_catalog_year");
  218. }
  219. function user_perm() {
  220. return array(
  221. "can_edit_user_roles" => array(
  222. "title" => t("Edit user roles"),
  223. "description" => t("The user may add/edit/delete user roles in the system."),
  224. ),
  225. "can_edit_permissions" => array(
  226. "title" => t("Edit permissions"),
  227. "description" => t("The user may assign permissions to different roles in the system."),
  228. ),
  229. "manage_users" => array(
  230. "title" => t("Manage users"),
  231. "description" => t("This is a powerful permission! It allows the user to edit the details
  232. of other users, as well as create users."),
  233. ),
  234. "delete_users" => array(
  235. "title" => t("Delete users"),
  236. "description" => t("This is a powerful permission! It allows the user delete users from the system."),
  237. ),
  238. );
  239. }
  240. /**
  241. * This is the permissions form, where users can set which roles have which permissions.
  242. */
  243. function user_permissions_form() {
  244. $form = array();
  245. fp_add_css(fp_get_module_path("user") . "/css/user.css");
  246. // Let's get all of our permissions from the permissions table.
  247. $permissions = array();
  248. $res = db_query("SELECT * FROM role_permissions");
  249. while ($cur = db_fetch_array($res)) {
  250. $permissions[$cur["rid"]][] = $cur["perm"];
  251. }
  252. $cb = $m = 1;
  253. $form["mark" . $m++] = array(
  254. "value" => t("Use this form to assign permissions to roles in the system.
  255. These permissions are defined by module."),
  256. );
  257. $roles = array();
  258. $res = db_query("SELECT * FROM roles ORDER BY rid ");
  259. while ($cur = db_fetch_array($res)) {
  260. $roles[$cur["rid"]] = $cur["name"];
  261. }
  262. $col_count = count($roles) + 1;
  263. $form["mark" . $m++] = array(
  264. "value" => "<table class='admin-perm-table' width='100%' cellpadding='0' cellspacing='0'>
  265. ",
  266. );
  267. // Go through all of the modules, then call hook_perm for them, to get their permissions.
  268. $modules = modules_implement_hook("perm");
  269. //fpm($modules);
  270. foreach ($modules as $module) {
  271. $form["mark" . $m++] = array(
  272. "value" => "<tr><td colspan='$col_count' class='perm-module-name'>" . ucwords($module) . " " . t("module") . "</td></tr>",
  273. );
  274. // Draw the headers...
  275. $form["mark" . $m++] = array(
  276. "value" => "<tr class='headers'><th style='min-width: 400px;'>" . t("Permission") . "</th>",
  277. );
  278. foreach ($roles as $key => $role) {
  279. $form["mark" . $m++] = array(
  280. "value" => "<th style='min-width: 100px;'>" . $role . "</th>",
  281. );
  282. }
  283. $form["mark" . $m++] = array(
  284. "value" => "</tr>",
  285. );
  286. // End of headers
  287. $zebra = "even";
  288. // Let's get all the perms.
  289. $perms = call_user_func($module . "_perm");
  290. foreach ($perms as $perm_name => $perm_details) {
  291. $title = @$perm_details["title"];
  292. $desc = @$perm_details["description"];
  293. $zebra = ($zebra == "even") ? "odd" : "even";
  294. $form["mark" . $m++] = array(
  295. "value" => "<tr class='perm-cb-row perm-cb-row-$zebra'><td class='perm-details' valign='top'>
  296. <div class='perm-title' title='$perm_name'>$title</div>
  297. <div class='perm-desc' title='$perm_name'>$desc</div>
  298. </td>",
  299. );
  300. foreach ($roles as $key => $role) {
  301. // Should this be checked by default (cause it was all ready in our table?)
  302. $default_value = array();
  303. if (@is_array($permissions[$key]) && in_array($perm_name, $permissions[$key])) {
  304. // Yes, it was in there! Set up the default_value as an array that
  305. // looks like array(key => key). That is how we set a checkbox to be checked
  306. // by default.
  307. $default_value = array($key . "___$perm_name" => $key . "___$perm_name");
  308. }
  309. $form["perm_cb_" . $cb++] = array(
  310. "type" => "checkboxes",
  311. "options" => array("$key" . "___$perm_name" => ""),
  312. "value" => $default_value,
  313. "prefix" => "<td class='perm-cb'>",
  314. "suffix" => "</td>",
  315. );
  316. }
  317. $form["mark" . $m++] = array(
  318. "value" => "</tr>",
  319. );
  320. }
  321. }
  322. $form["mark" . $m++] = array(
  323. "value" => "</table>",
  324. );
  325. $form["submit"] = array(
  326. "type" => "submit",
  327. "value" => t("Save permissions"),
  328. "prefix" => "<hr>",
  329. );
  330. return $form;
  331. }
  332. /**
  333. * Submit handler for the permissions form.
  334. */
  335. function user_permissions_form_submit($form, $form_submit) {
  336. $values = $form_submit["values"];
  337. // We should begin by truncating our permissions table, then re-inserting
  338. // everything we get from this submission.
  339. db_query("TRUNCATE TABLE role_permissions");
  340. // Find all the perm checkboxes.
  341. foreach($values as $key => $val) {
  342. if (strstr($key, "perm_cb_")) {
  343. if (is_array($val)) {
  344. $cb = current($val);
  345. if (strstr($cb, "___")) {
  346. $temp = explode("___", $cb);
  347. $rid = $temp[0];
  348. $perm = $temp[1];
  349. // Okay, save this to our table.
  350. db_query("INSERT INTO role_permissions (rid, perm)
  351. VALUES (?, ?) ", $rid, $perm);
  352. }
  353. }
  354. }
  355. }
  356. fp_add_message(t("Permissions saved successfully."));
  357. }
  358. /**
  359. * This form allows the user to manage the roles in the system.
  360. */
  361. function user_user_roles_form() {
  362. $form = array();
  363. $m = 0;
  364. fp_add_css(fp_get_module_path("user") . "/css/user.css");
  365. fp_add_js(fp_get_module_path("admin") . "/js/admin.js");
  366. $form["mark" . $m++] = array(
  367. "type" => "markup",
  368. "value" => t("Roles are able to be assigned permissions in FlightPath, and then users are assigned
  369. those roles. You may not remove the two roles, 'anonymous user' and 'authenticated user'.
  370. Those are assigned automatically when the user logs in or out.
  371. However, you may add as many more roles as you wish.")
  372. . "<br><br><b>" . t("roles:") . "</b>
  373. <table style='padding-left: 20px;'>",
  374. );
  375. $res = db_query("SELECT * FROM roles ORDER BY rid");
  376. while ($cur = db_fetch_array($res)) {
  377. $key = $cur["rid"];
  378. $value = $cur["name"];
  379. $prompt_link = fp_get_js_prompt_link("Enter a new name to change this role to:", $value, "document.getElementById(\"element-perform_action2\").value=\"edit~_~$key~_~\" + response; document.getElementById(\"fp-form-user_user_roles_form\").submit(); ", t("edit")) . " | ";
  380. $confirm_link = fp_get_js_confirm_link(t("Are you sure you wish to delete this role?\\nIt will be removed from users' accounts. This action cannot be undone.\\n\\nProceed?"), "document.getElementById(\"element-perform_action2\").value=\"del~_~$key\"; document.getElementById(\"fp-form-user_user_roles_form\").submit(); ", t("delete"));
  381. if ($key == 1 || $key == 2) {
  382. $prompt_link = $confirm_link = "";
  383. }
  384. $form["mark" . $m++] = array(
  385. "type" => "markup",
  386. "value" => "<tr><td>$value</td><td>" . $prompt_link . "
  387. " . $confirm_link . "</td></tr>",
  388. );
  389. }
  390. $form["mark" . $m++] = array(
  391. "type" => "markup",
  392. "value" => "</table>",
  393. );
  394. $form["perform_action2"] = array(
  395. "type" => "hidden",
  396. );
  397. $form["new_role"] = array(
  398. "type" => "textfield",
  399. "label" => t("Add a new role:"),
  400. );
  401. $form["submit"] = array(
  402. "type" => "submit",
  403. "value" => t("Add new"),
  404. );
  405. return $form;
  406. }
  407. function user_user_roles_form_submit($form, $form_state) {
  408. $values = $form_state["values"];
  409. if (trim($values["new_role"]) != "") {
  410. $new_role = strtolower(trim($values["new_role"]));
  411. // Clean up any trouble chars
  412. $new_role = preg_replace("/[^a-zA-Z0-9_]/", " ", $new_role);
  413. // Okay, add to the roles table.
  414. db_query("INSERT INTO roles (name) VALUES (?) ", $new_role);
  415. fp_add_message("The new role has been added successfully.");
  416. }
  417. if (strstr($values["perform_action2"], "del~_~")) {
  418. $temp = explode("~_~", $values["perform_action2"]);
  419. $i = trim($temp[1]);
  420. // Remove this rid from the table.
  421. db_query("DELETE FROM roles WHERE rid = ? ", $i);
  422. fp_add_message("The role has been deleted successfully.");
  423. }
  424. if (strstr($values["perform_action2"], "edit~_~")) {
  425. $temp = explode("~_~", $values["perform_action2"]);
  426. $i = trim($temp[1]);
  427. $new_name = strtolower(trim($temp[2]));
  428. $new_name = preg_replace("/[^a-zA-Z0-9_]/", " ", $new_name);
  429. if (trim($new_name) != "") {
  430. // Let's update the table.
  431. db_query("UPDATE roles SET name = ? WHERE rid = ? ", $new_name, $i);
  432. fp_add_message("The role has been edited successfully.");
  433. }
  434. }
  435. }
  436. /**
  437. * This form lets us populate the advisor_student table
  438. */
  439. function user_edit_user_advisees_form() {
  440. $form = array();
  441. $faculty_cwid = $_REQUEST["faculty_cwid"];
  442. $user_id = db_get_user_id_from_cwid($faculty_cwid);
  443. $de_catalog_year = @$_REQUEST["de_catalog_year"];
  444. // Figure out what the page's sub-tabs should be, and set them.
  445. $tab_array = array();
  446. $tab_array[0]["title"] = t("Edit Faculty/Staff User");
  447. $tab_array[0]["active"] = FALSE;
  448. $tab_array[0]["on_click"] = "window.location=\"" . fp_url("admin/users/edit-user", "faculty_cwid=$faculty_cwid&de_catalog_year=$de_catalog_year") . "\"";
  449. $tab_array[1]["title"] = t("Edit Faculty Advisees");
  450. $tab_array[1]["active"] = TRUE;
  451. $tab_array[1]["on_click"] = "window.location=\"" . fp_url("admin/users/edit-user/advisees", "faculty_cwid=$faculty_cwid&de_catalog_year=$de_catalog_year") . "\"";
  452. fp_set_page_sub_tabs($tab_array);
  453. if ($faculty_cwid != "new") {
  454. $name = fp_get_faculty_name($faculty_cwid);
  455. fp_set_title(t("Edit Faculty/Staff Advisees of @name (@id)", array("@name" => $name, "@id" => $faculty_cwid)));
  456. }
  457. else {
  458. // A new student! We can't create a new student until a CWID is assigned.
  459. fp_set_title(t("Create New Faculty/Staff User"));
  460. $form["mark_sorry"] = array(
  461. "type" => "markup",
  462. "value" => "<p>" . t("Sorry, but you cannot add advisees to this faculty member until the faculty member
  463. has been fully created (and given a CWID). Use the Edit Faculty/Staff User button above
  464. to return to that screen.") . "</p>",
  465. );
  466. return $form;
  467. }
  468. $form["user_id"] = array(
  469. "type" => "hidden",
  470. "value" => $user_id,
  471. );
  472. $form["perform_action2"] = array(
  473. "type" => "hidden",
  474. "value" => "",
  475. );
  476. $form["faculty_cwid"] = array(
  477. "type" => "hidden",
  478. "value" => $faculty_cwid,
  479. );
  480. // We are good to go... display the box for entering CWIDS
  481. $form["markup_explain"] = array(
  482. "value" => "<p>" . t("
  483. If this faculty user is an advisor, you may enter their advisees' CWIDs in the box below, one
  484. per line. This will be used to populate the advisor_student table.
  485. <br><br>
  486. <i>Anything after a # sign will be ignored. It is for your benefit only, it will NOT be saved.</i>
  487. <br><br>
  488. <b>Important:</b> If you have any routines which modify or edit the advisor_student table,
  489. this data will be overwritten.") . "</p>",
  490. );
  491. $contents = "";
  492. $db = get_global_database_handler();
  493. // begin by reading what's already there.
  494. $res = db_query("SELECT * FROM advisor_student WHERE faculty_id = ? ", $faculty_cwid);
  495. while ($cur = db_fetch_array($res)) {
  496. $contents .= trim($cur["student_id"]);
  497. // If this student exists, get their name and other info as well, to help with display.
  498. $name = $db->get_student_name($cur["student_id"]);
  499. $majors = $db->get_student_majors_from_db($cur["student_id"], TRUE);
  500. if ($name || $majors) {
  501. $contents .= " # $name - $majors ";
  502. }
  503. $contents .= "\n";
  504. }
  505. $contents = trim($contents);
  506. $form["students"] = array(
  507. "type" => "textarea",
  508. "label" => t("Advisee Student CWIDs:"),
  509. "value" => $contents,
  510. "rows" => 20,
  511. "cols" => 50,
  512. "description" => t("Enter advisee student CWIDs for this faculty user, one per line."),
  513. );
  514. $form["warn_me"] = array(
  515. "type" => "checkbox",
  516. "label" => t("Warn me if I enter a student CWID which doesn't exist in the students/users table yet (good for catching typos)"),
  517. "value" => "yes",
  518. );
  519. $form["submit_btn"] = array(
  520. "type" => "submit",
  521. "value" => "Submit",
  522. );
  523. return $form;
  524. } // edit_user_advisees_form
  525. /**
  526. * Check to see if we entered a CWID which doesn't exist in students table.
  527. */
  528. function user_edit_user_advisees_form_validate($form, $form_state) {
  529. if ($form_state["values"]["warn_me"] === TRUE) {
  530. $students = trim($form_state["values"]["students"]);
  531. $lines = explode("\n", $students);
  532. foreach($lines as $line) {
  533. $temp = explode("#", $line);
  534. $line = trim($temp[0]);
  535. if ($line == "") continue;
  536. // $line should now contain the CWID
  537. // Otherwise, check that it exists.
  538. $uid = db_get_user_id_from_cwid($line, "student");
  539. if ($uid < 2 || !$uid) {
  540. form_error("students", t("The CWID %cwid could not be found in the users table as a student. Your data has NOT been saved.", array("%cwid" => $line)));
  541. }
  542. }
  543. }
  544. }
  545. /**
  546. * Save to the advisor_student table
  547. */
  548. function user_edit_user_advisees_form_submit($form, $form_state) {
  549. // Begin by clearing the table for this advisor.
  550. $faculty_cwid = trim($form_state["values"]["faculty_cwid"]);
  551. db_query("DELETE FROM advisor_student WHERE faculty_id = ? ", $faculty_cwid);
  552. $students = trim($form_state["values"]["students"]);
  553. $lines = explode("\n", $students);
  554. foreach($lines as $line) {
  555. $temp = explode("#", $line);
  556. $line = trim($temp[0]);
  557. if ($line == "") continue;
  558. // Okay, $line should now contain the CWID.
  559. // Insert into db. (use REPLACE to prevent an error if data was entered twice)
  560. db_query("REPLACE INTO advisor_student (faculty_id, student_id)
  561. VALUES (?, ?) ", $faculty_cwid, $line);
  562. }
  563. fp_add_message(t("The advisees have been updated for this faculty member."));
  564. }
  565. /**
  566. * Let the user edit a user's roles and other information.
  567. */
  568. function user_edit_user_form() {
  569. fp_add_js(fp_get_module_path("user") . "/js/user.js");
  570. $form = array();
  571. $m = 0;
  572. $faculty_cwid = $_REQUEST["faculty_cwid"];
  573. $user_id = db_get_user_id_from_cwid($faculty_cwid);
  574. $de_catalog_year = @$_REQUEST["de_catalog_year"];
  575. $name = fp_get_faculty_name($faculty_cwid);
  576. fp_set_title(t("Edit Faculty/Staff User @name (@id)", array("@name" => $name, "@id" => $faculty_cwid)));
  577. // Figure out what the page's sub-tabs should be, and set them.
  578. $tab_array = array();
  579. $tab_array[0]["title"] = t("Edit Faculty/Staff User");
  580. $tab_array[0]["active"] = TRUE;
  581. $tab_array[0]["on_click"] = "window.location=\"" . fp_url("admin/users/edit-user", "faculty_cwid=$faculty_cwid&de_catalog_year=$de_catalog_year") . "\"";
  582. $tab_array[1]["title"] = t("Edit Faculty Advisees");
  583. $tab_array[1]["active"] = FALSE;
  584. $tab_array[1]["on_click"] = "window.location=\"" . fp_url("admin/users/edit-user/advisees", "faculty_cwid=$faculty_cwid&de_catalog_year=$de_catalog_year") . "\"";
  585. fp_set_page_sub_tabs($tab_array);
  586. $user_roles = system_get_roles_for_user($user_id);
  587. //fpm($user_roles);
  588. $default_values = array();
  589. foreach ($user_roles as $rid => $val) {
  590. $default_values[$rid] = $rid;
  591. }
  592. $form["user_id"] = array(
  593. "type" => "hidden",
  594. "value" => $user_id,
  595. );
  596. $form["perform_action2"] = array(
  597. "type" => "hidden",
  598. "value" => "",
  599. );
  600. $form["faculty_cwid"] = array(
  601. "type" => "hidden",
  602. "value" => $faculty_cwid,
  603. );
  604. // Show a list of roles in the system which we may select from, and check the ones
  605. // all ready assigned to this user.
  606. if ($faculty_cwid != "new") {
  607. // Not for new users, since we don't have a user_id for them yet.
  608. $options = array();
  609. $res = db_query("SELECT * FROM roles ORDER BY rid");
  610. while ($cur = db_fetch_array($res)) {
  611. $key = $cur["rid"];
  612. $value = $cur["name"];
  613. if ($key > 2) {
  614. $options[$key] = $value;
  615. }
  616. }
  617. //fpm($default_values);
  618. $form["roles"] = array(
  619. "label" => t("Check which roles this user should have."),
  620. "type" => "checkboxes",
  621. "options" => $options,
  622. "value" => $default_values,
  623. );
  624. }
  625. /////////////////////
  626. // Let's present the form elements to allow some basic editing of this user.
  627. // Only if we are making a new user...
  628. if ($faculty_cwid == "new") {
  629. $form["new_faculty_cwid"] = array(
  630. "label" => t("Enter a new CWID, unique to faculty:"),
  631. "type" => "textfield",
  632. "size" => 20,
  633. "required" => TRUE,
  634. "description" => t("Enter a numeric ID for this faculty. It may be the same
  635. as a student, but may not be the same as any existing
  636. faculty. You will not be able to edit this value, once saved."),
  637. );
  638. $form["new_user_name"] = array(
  639. "label" => t("Enter a new username, unique to all users:"),
  640. "type" => "textfield",
  641. "size" => 20,
  642. "required" => TRUE,
  643. "description" => t("Enter a username for this user. This is what the user will
  644. use to log in. It must be unique to all users (cannot have both
  645. a faculty and a student with the same username). You will not
  646. be able to edit this value, once saved."),
  647. );
  648. $cur = array();
  649. }
  650. else {
  651. // NOT a new faculty. Load their information normally.
  652. $res = db_query("SELECT * FROM users u, faculty s
  653. WHERE u.cwid = ?
  654. AND u.is_faculty = '1'
  655. AND u.cwid = s.cwid", $faculty_cwid);
  656. $cur = db_fetch_array($res);
  657. }
  658. @$user_name = $cur["user_name"];
  659. if ($user_name != "") {
  660. $form["mark" . $m++] = array(
  661. "value" => "<p><b>Username:</b> $user_name</p>",
  662. );
  663. }
  664. $form["new_password"] = array(
  665. "label" => t("Enter a new password for this user:"),
  666. "type" => "textfield",
  667. "size" => 20,
  668. "required" => ($faculty_cwid == "new") ? TRUE : FALSE,
  669. "description" => t("If you enter any value here, it will change the
  670. user's password in FlightPath. If you are using the LDAP module,
  671. the LDAP password will be unaffected."),
  672. );
  673. $form["email"] = array(
  674. "label" => t("Email:"),
  675. "type" => "textfield",
  676. "value" => @$cur["email"],
  677. );
  678. $form["f_name"] = array(
  679. "label" => t("First name:"),
  680. "type" => "textfield",
  681. "value" => @$cur["f_name"],
  682. );
  683. $form["l_name"] = array(
  684. "label" => t("Last name:"),
  685. "type" => "textfield",
  686. "value" => @$cur["l_name"],
  687. );
  688. $form["is_disabled"] = array(
  689. "label" => t("Is disabled:"),
  690. "type" => "textfield",
  691. "value" => @$cur["is_disabled"],
  692. "size" => 5,
  693. "description" => t("Enter only 1 or 0 (number one for 'yes', or number zero for 'no'). This setting means the user will
  694. be ignored by FlightPath, and they will not be able to log in or be searched for.
  695. It is safer to disable a user, than delete them."),
  696. );
  697. // Unique to faculty...
  698. $form["college"] = array(
  699. "label" => t("College:"),
  700. "type" => "textfield",
  701. "value" => @$cur["college"],
  702. "size" => 5,
  703. );
  704. $form["department"] = array(
  705. "label" => t("Department:"),
  706. "type" => "textfield",
  707. "value" => @$cur["department"],
  708. "size" => 30,
  709. );
  710. $form["major_code_csv"] = array(
  711. "label" => t("Major code CSV:"),
  712. "type" => "textfield",
  713. "value" => @$cur["major_code_csv"],
  714. "size" => 60,
  715. "maxlength" => 255,
  716. "description" => t("Enter the major codes which this faculty member is over, separated by commas. Ex: ACCT,MATH
  717. <br>If the user is only over 1 major code, just enter that one major code."),
  718. );
  719. $form["submit"] = array(
  720. "type" => "submit",
  721. "value" => "Submit",
  722. "prefix" => "<hr>",
  723. );
  724. if ($faculty_cwid != "new" && user_has_permission("delete_users")) {
  725. $form["mark" . $m++] = array(
  726. "type" => "markup",
  727. "value" => "<div align='right'>
  728. " . t("Delete this faculty member?") . " <input type='button' value='X'
  729. onClick='userDeleteFaculty();'>
  730. </div>",
  731. );
  732. }
  733. return $form;
  734. }
  735. /**
  736. * Validate handler for editing faculty users.
  737. */
  738. function user_edit_user_form_validate($form, $form_state) {
  739. $values = $form_state["values"];
  740. // If a password was given, make sure it is appropriate.
  741. if (trim($values["new_password"]) != "") {
  742. if (strlen(trim($values["new_password"])) < 5) {
  743. form_error("new_password", t("Please enter a password that is at least 5 characters long."));
  744. return;
  745. }
  746. }
  747. // If creating a new user, make sure new_student_cwid and new_user_name are not
  748. // already in use.
  749. if ($values["faculty_cwid"] == "new") {
  750. $new_cwid = trim($values["new_faculty_cwid"]);
  751. $new_user_name = trim($values["new_user_name"]);
  752. /* // CWIDs are no longer required to be numeric.
  753. // Check that cwid is numeric.
  754. if (!is_numeric($new_cwid)) {
  755. form_error("new_faculty_cwid", t("The cwid you entered is not numeric. CWIDs must contain only numbers.
  756. Please select a different cwid."));
  757. return;
  758. }
  759. */
  760. // Check that username is at least 4 characters
  761. if (strlen($new_user_name) < 4) {
  762. form_error("new_user_name", t("The username you entered is too short. It must be at least 4 characters.
  763. Please select a different username."));
  764. return;
  765. }
  766. // Check cwid isn't already in use.
  767. $test = db_result(db_query("SELECT cwid FROM users WHERE cwid = ? AND is_faculty = '1'", $new_cwid));
  768. if ($test == $new_cwid) {
  769. form_error("new_faculty_cwid", t("The cwid you entered is already in use. Please select a different cwid."));
  770. return;
  771. }
  772. // Check user_name isn't already in use.
  773. $test = db_result(db_query("SELECT user_name FROM users WHERE user_name = ? ", $new_user_name));
  774. if ($test == $new_user_name) {
  775. form_error("new_user_name", t("The username you entered is already in use. Please select a different username."));
  776. return;
  777. }
  778. }
  779. }
  780. /**
  781. * Submit handler for our edit faculty form
  782. */
  783. function user_edit_user_form_submit($form, $form_state) {
  784. $values = $form_state["values"];
  785. foreach ($values as $key => $val) {
  786. if (!is_array($val)) {
  787. $values[$key] = trim($val);
  788. }
  789. }
  790. $user_id = $values["user_id"];
  791. $faculty_cwid = $values["faculty_cwid"];
  792. // Save the roles into the database for this user.
  793. // Begin by deleting what's there all ready.
  794. db_query("DELETE FROM user_roles WHERE user_id = ? ", $user_id);
  795. if (is_array($values["roles"])) {
  796. foreach ($values["roles"] as $rid) {
  797. //fpm("inserting $rid");
  798. db_query("INSERT INTO user_roles (user_id, rid)
  799. VALUES (?, ?) ", $user_id, $rid);
  800. }
  801. }
  802. // Are we supposed to DELETE a faculty?
  803. if ($values["perform_action2"] == "delete_faculty" && user_has_permission("delete_users")) {
  804. db_query("DELETE FROM faculty WHERE cwid = ? ", $faculty_cwid);
  805. db_query("DELETE FROM users WHERE cwid = ? AND is_faculty = '1' ", $faculty_cwid);
  806. fp_add_message(t("User has been deleted."));
  807. fp_goto("admin/users/faculty");
  808. return;
  809. }
  810. if ($faculty_cwid != "new") {
  811. // NOT a new faculty! Insert values normally.
  812. // First-- was there a password given? If so, insert that separate.
  813. if (trim($values["new_password"]) != "") {
  814. $new_pass = user_hash_password(trim($values["new_password"]));
  815. db_query("UPDATE users
  816. SET password = ?
  817. WHERE cwid = ?
  818. AND is_faculty = '1' ", $new_pass, $faculty_cwid);
  819. }
  820. // Okay, now we can just update everything else.
  821. // Update users table first...
  822. db_query("UPDATE users
  823. SET email = ?,
  824. f_name = ?,
  825. l_name = ?,
  826. is_disabled = ?
  827. WHERE cwid = ?
  828. AND is_faculty = '1' ", $values["email"], $values["f_name"],
  829. $values["l_name"], $values["is_disabled"],
  830. $faculty_cwid);
  831. // Now, update the faculty table entry.
  832. db_query("UPDATE faculty
  833. SET college = ?,
  834. department = ?,
  835. major_code_csv = ?
  836. WHERE cwid = ? ", $values["college"], $values["department"],
  837. $values["major_code_csv"], $faculty_cwid);
  838. }
  839. else {
  840. // This is a NEW user! We need to perform inserts. Thanks to our validate handler,
  841. // we know all of the values we have are valid.
  842. if (trim($values["l_name"]) == "") {
  843. // No last name? Set to username.
  844. $values['l_name'] = $values['new_user_name'];
  845. }
  846. db_query("INSERT INTO users (user_name, password, is_faculty, email, cwid, f_name, l_name, is_disabled)
  847. VALUES (?, ?, '1', ?, ?, ?, ?, ?)
  848. ", $values["new_user_name"], user_hash_password($values["new_password"]), $values["email"], $values["new_faculty_cwid"],
  849. $values["f_name"], $values["l_name"], $values["is_disabled"]);
  850. db_query("INSERT INTO faculty (cwid, college, department, major_code_csv)
  851. VALUES (?, ?, ?, ?)
  852. ", $values["new_faculty_cwid"], $values["college"], $values["department"], $values["major_code_csv"]);
  853. fp_add_message(t("User created successfully."));
  854. fp_goto("admin/users/edit-user", "faculty_cwid=" . $values["new_faculty_cwid"]);
  855. }
  856. fp_add_message(t("User updated successfully."));
  857. }
  858. /**
  859. * Similar to user_display_users, except only for student users.
  860. */
  861. function user_display_student_users() {
  862. global $db, $screen;
  863. $de_catalog_year = @$GLOBALS["de_catalog_year"];
  864. if ($db == NULL) {
  865. $db = get_global_database_handler();
  866. }
  867. $cc = 1;
  868. $rtn = "";
  869. fp_add_css(fp_get_module_path("user") . "/css/user.css");
  870. // First, let's get our list of departments...
  871. $major_code_array = array();
  872. $d = 0;
  873. // Let's pull the needed variables out of our settings, so we know what
  874. // to query, because this is a non-FlightPath table.
  875. $res = db_query("SELECT DISTINCT major_code FROM student_degrees ORDER BY major_code ");
  876. while ($cur = db_fetch_array($res)) {
  877. if (trim($cur["major_code"]) == "")
  878. {// skip if blank
  879. continue;
  880. }
  881. $major_code_array[$d] = trim(ucwords($cur["major_code"]));
  882. $d++;
  883. }
  884. $rtn .= "<h2 class='title' style='margin-bottom:0;'>" . t("Edit Student Users") . "</h2>";
  885. $rtn .= "<div class='add-new-student-user'>" . l(t("Create a new student user"), "admin/users/edit-student-user", "student_cwid=new&de_catalog_year=$de_catalog_year") . "</div>";
  886. $letter_ranges = array(
  887. "A" => array("A", "AZZZZ"),
  888. "B" => array("B", "BZZZZ"),
  889. "C" => array("C", "CZZZ"),
  890. "D" => array("D", "DZZZZ"),
  891. "E" => array("E", "EZZZZ"),
  892. "F" => array("F", "FZZZZ"),
  893. "G" => array("G", "GZZZZ"),
  894. "H" => array("H", "HZZZZ"),
  895. "I" => array("I", "IZZZ"),
  896. "J" => array("J", "JZZZ"),
  897. "K" => array("K", "KZZZ"),
  898. "L" => array("L", "LZZZ"),
  899. "M" => array("M", "MZZZ"),
  900. "N" => array("N", "NZZZ"),
  901. "O" => array("O", "OZZZ"),
  902. "P" => array("P", "PZZZ"),
  903. "Q-R" => array("Q", "RZZZZ"),
  904. "S" => array("S", "SZZZ"),
  905. "T" => array("T", "TZZZZ"),
  906. "U" => array("U", "UZZZ"),
  907. "V-Z" => array("V", "ZZZZ"),
  908. );
  909. $rtn .= "<div class='user-select-letter-bar' style='padding-top: 20px;'>
  910. ";
  911. foreach($letter_ranges as $disp => $vals) {
  912. $rtn .= l($disp, "admin/users/students", "de_catalog_year=$de_catalog_year&ur=" . $vals[0] . "&lr=" . $vals[1], array("class" => "admin-courses-letter-link")) . " &nbsp; ";
  913. }
  914. // Figure out what type of students to display-- active, inactive, or both
  915. $set_disp = @$_REQUEST["set_disp"];
  916. if ($set_disp == "") {
  917. $set_disp = @$_SESSION["user_set_disp"];
  918. if ($set_disp == "") {
  919. $set_disp = "only_active";
  920. }
  921. }
  922. // Save into session for ease later
  923. $_SESSION["user_set_disp"] = $set_disp;
  924. $in_active_query_line = "";
  925. $sel_only_active = $sel_only_inactive = $sel_both = "";
  926. if ($set_disp == "only_active") {
  927. $sel_only_active = "selected";
  928. $in_active_query_line = " AND is_active = '1' ";
  929. }
  930. if ($set_disp == "only_inactive") {
  931. $sel_only_inactive = "selected";
  932. $in_active_query_line = " AND is_active = '0' ";
  933. }
  934. if ($set_disp == "both") {
  935. $sel_both = "selected";
  936. }
  937. $clean_urls = variable_get("clean_urls", FALSE);
  938. $rtn .= "</div>";
  939. $rtn .= "
  940. <form class='filters' action='" . fp_url("admin/users/students") . "' method='GET' >
  941. <input type='hidden' name='performAction' value='editUsers'>";
  942. if (!$clean_urls) {
  943. // Hack to support non-clean URL sites
  944. $rtn .= "<input type='hidden' name='q' value='admin/users/students'>";
  945. }
  946. $get_search = @$_GET["search"];
  947. $rtn .= "
  948. " . t("Search:") . " <input type='text' class='smallinput' name='search' value='$get_search' size='15'>
  949. <input type='submit' name='searchsubmit' class='smallinput' value=' -> '>
  950. &nbsp; &nbsp; " . t("or") . " &nbsp; &nbsp;
  951. <select name='major_code' class='smallinput'>
  952. <option value=''>" . t("Select a major code...") . "</option>
  953. <option value=''>--------------------------</option>
  954. <!--MAJORCODESEARCH-->
  955. </select>
  956. <input type='submit' name='major_code_submit' class='smallinput' value=' -> '>
  957. &nbsp; &nbsp; " . t("Set disp:") . "
  958. <select name='set_disp'>
  959. <option value='only_active' $sel_only_active>" . t("only active") . "</option>
  960. <option value='only_inactive' $sel_only_inactive>" . t("only inactive") . "</option>
  961. <option value='both' $sel_both>" . t("show both") . "</option>
  962. </select>
  963. <input type='submit' name='show_inactive_submit' class='smallinput' value=' -> '>
  964. </form>
  965. <br>
  966. ";
  967. $displaying = "";
  968. $ur = trim(@$_GET["ur"]);
  969. $lr = trim(@$_GET["lr"]);
  970. if ($ur != "" || $lr != "")
  971. {
  972. $_SESSION["prev_user_search"] = "";
  973. }
  974. if ($ur == "")
  975. { // meaning, no range was set. Use A - C
  976. $ur = @$_SESSION["ur"];
  977. $lr = @$_SESSION["lr"];
  978. if ($ur == "")
  979. { // if still blank, assign it..
  980. $ur = "A";
  981. $lr = "AZZZZ";
  982. }
  983. }
  984. $_SESSION["ur"] = $ur;
  985. $_SESSION["lr"] = $lr;
  986. $search = trim(@$_GET["search"]);
  987. $major_code = trim(@$_GET["major_code"]);
  988. if ($search != "" || $major_code != "")
  989. {
  990. $_SESSION["prev_user_search"] = "";
  991. }
  992. if (@$_SESSION["prev_user_search"] != "")
  993. {
  994. $temp = explode("%%",$_SESSION["prev_user_search"]);
  995. if ($temp[0] == "search")
  996. {
  997. $search = $temp[1];
  998. }
  999. if ($temp[0] == "major_code")
  1000. {
  1001. $_GET["major_codesubmit"] = "1";
  1002. $major_code = $temp[1];
  1003. }
  1004. }
  1005. $_SESSION["prev_user_search"] = "";
  1006. // Let's pull the needed variables out of our settings, so we know what
  1007. // to query, because this is a non-FlightPath table.
  1008. //$tsettings = $GLOBALS["fp_system_settings"]["extra_tables"]["human_resources:faculty_staff"];
  1009. //$tf = (object) $tsettings["fields"]; //Convert to object, makes it easier to work with.
  1010. //$table_name = $tsettings["table_name"];
  1011. // TODO: Check if we are searching through "active" as well!
  1012. if ($search != "" && !($_GET["major_code_submit"]))
  1013. {
  1014. // Something was searched for, and the major_code submit button was not pushed.
  1015. $major_code = "";
  1016. $temp = explode(" ",$search);
  1017. $search1 = $temp[0];
  1018. $search2 = trim($temp[1]);
  1019. $_SESSION["prev_user_search"] = "search%%$search";
  1020. $displaying = $search;
  1021. $second_part = "";
  1022. if ($search2 != "")
  1023. {
  1024. // Two search terms, probably a name...
  1025. $result = db_query("SELECT * FROM users u, students s
  1026. WHERE
  1027. u.is_student = 1
  1028. AND u.cwid = s.cwid
  1029. $in_active_query_line
  1030. AND (l_name LIKE ?
  1031. AND f_name LIKE ?)
  1032. ORDER BY l_name, f_name ", "%$search2%", "%$search1%");
  1033. }
  1034. else {
  1035. // One search term....
  1036. $result = db_query("SELECT * FROM users u, students s
  1037. WHERE
  1038. u.is_student = 1
  1039. AND u.cwid = s.cwid
  1040. $in_active_query_line
  1041. AND (u.cwid LIKE ?
  1042. OR l_name LIKE ?
  1043. OR f_name LIKE ?)
  1044. ORDER BY l_name, f_name ", "%$search1%", "%$search1%", "%$search1%");
  1045. }
  1046. }
  1047. else if ($major_code != "" && $_GET["major_code_submit"]) {
  1048. // User select a major_code. Look for it...
  1049. $search = "";
  1050. $_SESSION["prev_user_search"] = "major_code%%$major_code";
  1051. $result = db_query("SELECT * FROM users a, students b, student_degrees c
  1052. WHERE a.cwid = b.cwid
  1053. AND a.cwid = c.student_id
  1054. AND a.is_student = 1
  1055. AND c.major_code = ?
  1056. $in_active_query_line
  1057. ORDER BY l_name, f_name ", $major_code);
  1058. $displaying = $major_code;
  1059. }
  1060. else
  1061. { // No search, so look for the range...
  1062. $result = db_query("SELECT * FROM users u, students s
  1063. WHERE
  1064. u.is_student = 1
  1065. AND u.cwid = s.cwid
  1066. $in_active_query_line
  1067. AND l_name BETWEEN ? AND ?
  1068. ORDER BY l_name, f_name ", $ur, $lr);
  1069. $displaying = $ur;
  1070. }
  1071. $rtn .= "<div class='tenpt' style='padding-bottom: 5px;'><b>" . t("Displaying:") . "</b> $displaying</div>
  1072. <table border='0' width='100%' cellpadding='3' cellspacing='0' class='user-list'>
  1073. <tr>
  1074. <th>CWID</th>
  1075. <th>Name</th>
  1076. <th></th>
  1077. <th>Major code(s)</th>
  1078. <th>Active?</th>
  1079. <th>&nbsp;</th>
  1080. </tr>
  1081. ";
  1082. while ($cur = db_fetch_array($result)) {
  1083. $user_id = $cur["user_id"];
  1084. $l_name = trim(ucwords(strtolower($cur["l_name"])));
  1085. $f_name = trim(ucwords(strtolower($cur["f_name"])));
  1086. $student_cwid = trim($cur["cwid"]);
  1087. //$disp_major_code = trim($cur["major_code"]);
  1088. $disp_major_code = join(", ", $db->get_student_majors_from_db($student_cwid, FALSE, FALSE));
  1089. $is_active = ($cur["is_active"] == "1") ? "Y" : "N";
  1090. $ast = "";
  1091. $reason = "";
  1092. $fgcol = "black";
  1093. $rtn .= "<tr class='is-active-$is_active'>
  1094. <td valign='top' width='15%'>$student_cwid</td>
  1095. <td valign='top' width='15%'>$f_name</td>
  1096. <td valign='top' width='15%'>$l_name</td>
  1097. <td valign='top'>$disp_major_code</td>
  1098. <td valign='top'>$is_active</td>
  1099. <td valign='top'>" . l(t("edit"), "admin/users/edit-student-user", "student_cwid=$student_cwid&de_catalog_year=$de_catalog_year") . "</td>
  1100. </tr>";
  1101. } // while
  1102. $rtn .= "</table>";
  1103. // Put in the major_code pulldown....
  1104. $bC = "";
  1105. for ($t = 0; $t<count($major_code_array); $t++)
  1106. {
  1107. $dd = $major_code_array[$t];
  1108. $sel = "";
  1109. if ($dd == $major_code)
  1110. {
  1111. $sel = "selected";
  1112. }
  1113. $bC .= "<option value='$dd' $sel>{$major_code_array[$t]}</option> \n";
  1114. }
  1115. $rtn = str_replace("<!--MAJORCODESEARCH-->",$bC,$rtn);
  1116. return $rtn;
  1117. }
  1118. /**
  1119. * Display our list of faculty/staff users in the system.
  1120. */
  1121. function user_display_users() {
  1122. global $db, $screen;
  1123. $de_catalog_year = @$GLOBALS["de_catalog_year"];
  1124. $cc = 1;
  1125. $rtn = "";
  1126. fp_add_css(fp_get_module_path("user") . "/css/user.css");
  1127. // First, let's get our list of departments...
  1128. $dept_array = array();
  1129. $d = 0;
  1130. // Let's pull the needed variables out of our settings, so we know what
  1131. // to query, because this is a non-FlightPath table.
  1132. //$tsettings = $GLOBALS["fp_system_settings"]["extra_tables"]["human_resources:faculty_staff"];
  1133. //$tf = (object) $tsettings["fields"]; //Convert to object, makes it easier to work with.
  1134. //$table_name = $tsettings["table_name"];
  1135. $res = db_query("SELECT DISTINCT department FROM faculty ORDER BY department ");
  1136. while ($cur = db_fetch_array($res)) {
  1137. if (trim($cur["department"]) == "")
  1138. {// skip if blank
  1139. continue;
  1140. }
  1141. $dept_array[$d] = trim(ucwords(strtolower($cur["department"])));
  1142. $d++;
  1143. }
  1144. $rtn .= "<h2 class='title' style='margin-bottom: 0;'>" . t("Edit Faculty / Staff Users") . "</h2>";
  1145. $rtn .= "<div class='add-new-user'>" . l(t("Create a new faculty/staff user"), "admin/users/edit-user", "faculty_cwid=new&de_catalog_year=$de_catalog_year") . "</div>";
  1146. $letter_ranges = array(
  1147. "A" => array("A", "AZZZZ"),
  1148. "B" => array("B", "BZZZZ"),
  1149. "C" => array("C", "CZZZ"),
  1150. "D" => array("D", "DZZZZ"),
  1151. "E" => array("E", "EZZZZ"),
  1152. "F" => array("F", "FZZZZ"),
  1153. "G" => array("G", "GZZZZ"),
  1154. "H" => array("H", "HZZZZ"),
  1155. "I" => array("I", "IZZZ"),
  1156. "J" => array("J", "JZZZ"),
  1157. "K" => array("K", "KZZZ"),
  1158. "L" => array("L", "LZZZ"),
  1159. "M" => array("M", "MZZZ"),
  1160. "N" => array("N", "NZZZ"),
  1161. "O" => array("O", "OZZZ"),
  1162. "P" => array("P", "PZZZ"),
  1163. "Q-R" => array("Q", "RZZZZ"),
  1164. "S" => array("S", "SZZZ"),
  1165. "T" => array("T", "TZZZZ"),
  1166. "U" => array("U", "UZZZ"),
  1167. "V-Z" => array("V", "ZZZZ"),
  1168. );
  1169. $rtn .= "<div class='user-select-letter-bar' style='padding-top: 20px;'>
  1170. ";
  1171. foreach($letter_ranges as $disp => $vals) {
  1172. $rtn .= l($disp, "admin/users/faculty", "de_catalog_year=$de_catalog_year&ur=" . $vals[0] . "&lr=" . $vals[1], array("class" => "admin-courses-letter-link")) . " &nbsp; ";
  1173. }
  1174. $clean_urls = variable_get("clean_urls", FALSE);
  1175. $rtn .= "</div>";
  1176. $rtn .= "
  1177. <form class='filters' action='" . fp_url("admin/users/faculty") . "' method='GET' >";
  1178. if (!$clean_urls) {
  1179. // Hack to support non-clean URL sites
  1180. $rtn .= "<input type='hidden' name='q' value='admin/users/faculty'>";
  1181. }
  1182. $get_search = @$_GET["search"];
  1183. $rtn .= "
  1184. <input type='hidden' name='performAction' value='editUsers'>
  1185. " . t("Search:") . " <input type='text' class='smallinput' name='search' value='$get_search' size='15'>
  1186. <input type='submit' name='searchsubmit' class='smallinput' value=' -> '>
  1187. &nbsp;&nbsp;" . t("or") . "&nbsp;&nbsp;
  1188. <select name='department' class='smallinput'>
  1189. <option value=''>" . t("Select a department:") . "</option>
  1190. <option value=''>--------------------------</option>
  1191. <!--DEPTSEARCH-->
  1192. </select>
  1193. <input type='submit' name='deptsubmit' class='smallinput' value=' -> '>
  1194. &nbsp;&nbsp;" . t("or") . "&nbsp;&nbsp;
  1195. <select name='role' class='smallinput'>
  1196. <option value=''>" . t("Select a role:") . "</option>
  1197. <option value=''>--------------------------</option>
  1198. ";
  1199. // Show list of roles
  1200. $res = db_query("SELECT * FROM roles ORDER BY rid");
  1201. while ($cur = db_fetch_array($res)) {
  1202. $key = $cur["rid"];
  1203. $value = $cur["name"];
  1204. $dispval = $value;
  1205. // Skip anonymous and authenticated
  1206. if ($key == 1 || $key == 2) continue;
  1207. if (strlen($dispval) > 25) {
  1208. $dispval = trim(substr($dispval, 0, 22)) . "...";
  1209. }
  1210. $sel = "";
  1211. if ($key == intval(@$_GET["role"])) {
  1212. $sel = "selected";
  1213. }
  1214. $rtn .= "<option value='$key' $sel>$dispval</option>";
  1215. }
  1216. $rtn .= "</select>
  1217. <input type='submit' name='rolesubmit' class='smallinput' value=' -> '>
  1218. </form>
  1219. <br>
  1220. ";
  1221. $displaying = "";
  1222. $ur = trim(@$_GET["ur"]);
  1223. $lr = trim(@$_GET["lr"]);
  1224. if ($ur != "" || $lr != "")
  1225. {
  1226. $_SESSION["prev_user_search"] = "";
  1227. }
  1228. if ($ur == "")
  1229. { // meaning, no range was set. Use A - C
  1230. $ur = @$_SESSION["ur"];
  1231. $lr = @$_SESSION["lr"];
  1232. if ($ur == "")
  1233. { // if still blank, assign it..
  1234. $ur = "A";
  1235. $lr = "AZZZZ";
  1236. }
  1237. }
  1238. $_SESSION["ur"] = $ur;
  1239. $_SESSION["lr"] = $lr;
  1240. $search = trim(@$_GET["search"]);
  1241. $dept = trim(@$_GET["department"]);
  1242. $role = trim(@$_GET["role"]);
  1243. if ($search != "" || $dept != "")
  1244. {
  1245. $_SESSION["prev_user_search"] = "";
  1246. }
  1247. if (@$_SESSION["prev_user_search"] != "")
  1248. {
  1249. $temp = explode("%%",$_SESSION["prev_user_search"]);
  1250. if ($temp[0] == "search")
  1251. {
  1252. $search = $temp[1];
  1253. }
  1254. if ($temp[0] == "dept")
  1255. {
  1256. @$_GET["deptsubmit"] = "1";
  1257. $dept = $temp[1];
  1258. }
  1259. if ($temp[0] == "role" && ($role == "" || intval($role) == 0)) {
  1260. @$_GET["rolesubmit"] = "1";
  1261. $role = $temp[1];
  1262. }
  1263. }
  1264. $_SESSION["prev_user_search"] = "";
  1265. // Let's pull the needed variables out of our settings, so we know what
  1266. // to query, because this is a non-FlightPath table.
  1267. //$tsettings = $GLOBALS["fp_system_settings"]["extra_tables"]["human_resources:faculty_staff"];
  1268. //$tf = (object) $tsettings["fields"]; //Convert to object, makes it easier to work with.
  1269. //$table_name = $tsettings["table_name"];
  1270. if ($search != "" && !(@$_GET["deptsubmit"]) && !(@$_GET["rolesubmit"]))
  1271. {
  1272. // Something was searched for, and the dept submit button was not pushed, nor role submit
  1273. $dept = "";
  1274. $temp = explode(" ",$search);
  1275. $search1 = @$temp[0];
  1276. $search2 = trim(@$temp[1]);
  1277. $_SESSION["prev_user_search"] = "search%%$search";
  1278. $displaying = $search;
  1279. $second_part = "";
  1280. if ($search2 != "")
  1281. {
  1282. // Two search terms, probably a name...
  1283. $result = db_query("SELECT * FROM users u, faculty f
  1284. WHERE
  1285. u.is_faculty = 1
  1286. AND u.cwid = f.cwid
  1287. AND (l_name LIKE ?
  1288. AND f_name LIKE ?)
  1289. ORDER BY l_name, f_name ", "%$search2%", "%$search1%");
  1290. }
  1291. else {
  1292. // One search term....
  1293. $result = db_query("SELECT * FROM users u, faculty f
  1294. WHERE
  1295. u.is_faculty = 1
  1296. AND u.cwid = f.cwid
  1297. AND (u.cwid LIKE ?
  1298. OR l_name LIKE ?
  1299. OR f_name LIKE ?)
  1300. ORDER BY l_name, f_name ", "%$search1%", "%$search1%", "%$search1%");
  1301. }
  1302. }
  1303. else if ($dept != "" && $_GET["deptsubmit"]) {
  1304. // User select a department. Look for it...
  1305. $search = "";
  1306. $_SESSION["prev_user_search"] = "dept%%$dept";
  1307. $result = db_query("SELECT * FROM users a, faculty b
  1308. WHERE a.cwid = b.cwid
  1309. AND a.is_faculty = 1
  1310. AND department = ?
  1311. ORDER BY l_name, f_name ", $dept);
  1312. $displaying = $dept;
  1313. }
  1314. else if ($role != "" && $_GET["rolesubmit"]) {
  1315. // User select a role. Look for it...
  1316. $search = "";
  1317. $_SESSION["prev_user_search"] = "role%%$role";
  1318. $result = db_query("SELECT * FROM users a, faculty b, user_roles c
  1319. WHERE a.cwid = b.cwid
  1320. AND a.is_faculty = 1
  1321. AND a.user_id = c.user_id
  1322. AND c.rid = ?
  1323. ORDER BY l_name, f_name ", $role);
  1324. $displaying = user_get_role_name($role);
  1325. }
  1326. else
  1327. { // No search, so look for the range...
  1328. $result = db_query("SELECT * FROM users u, faculty f
  1329. WHERE
  1330. u.is_faculty = 1
  1331. AND u.cwid = f.cwid
  1332. AND l_name BETWEEN ? AND ?
  1333. ORDER BY l_name, f_name ", $ur, $lr);
  1334. $displaying = $ur;
  1335. }
  1336. $rtn .= "<div class='tenpt' style='padding-bottom: 5px;'><b>" . t("Displaying:") . "</b> $displaying</div>
  1337. <table border='0' width='100%' cellpadding='3' cellspacing='0' class='user-list'>
  1338. <tr>
  1339. <th>CWID</th>
  1340. <th>Name</th>
  1341. <th></th>
  1342. <th>Department</th>
  1343. <th>Roles</th>
  1344. <th>&nbsp;</th>
  1345. </tr>
  1346. ";
  1347. while ($cur = db_fetch_array($result)) {
  1348. $user_id = $cur["user_id"];
  1349. $l_name = trim(ucwords(strtolower($cur["l_name"])));
  1350. $f_name = trim(ucwords(strtolower($cur["f_name"])));
  1351. $faculty_cwid = trim($cur["cwid"]);
  1352. $dept_name = trim(ucwords(strtolower($cur["department"])));
  1353. $ast = "";
  1354. $reason = "";
  1355. $fgcol = "black";
  1356. $roles = "";
  1357. $roles_classes = "no-roles";
  1358. $temp = system_get_roles_for_user($user_id);
  1359. if (count($temp) > 1) $roles_classes = "";
  1360. foreach ($temp as $rid => $t) {
  1361. if ($rid > 2) {
  1362. // rid 1 and 2 are anonymous and authenticated-- no need to show them.
  1363. $roles .= "<div class='list-role'>$t</div>";
  1364. $roles_classes .= " role-" . fp_get_machine_readable($t);
  1365. }
  1366. }
  1367. // $pC .= "<a href='edit_users.php?action=load&course_id=$course_id'> user: $f_name $mid_name $l_name </a><br>";
  1368. $rtn .= "<tr class='$roles_classes'>
  1369. <td valign='top' width='15%'>$faculty_cwid</td>
  1370. <td valign='top' width='15%'>$f_name</td>
  1371. <td valign='top' width='15%'>$l_name</td>
  1372. <td valign='top'>$dept_name</td>
  1373. <td valign='top'>$roles</td>
  1374. <td valign='top'>" . l(t("edit"), "admin/users/edit-user", "faculty_cwid=$faculty_cwid&de_catalog_year=$de_catalog_year") . "</td>
  1375. </tr>";
  1376. } // while
  1377. $rtn .= "</table>";
  1378. // Put in the dept pulldown....
  1379. $bC = "";
  1380. for ($t = 0; $t<count($dept_array); $t++)
  1381. {
  1382. $dd = $dept_array[$t];
  1383. $sel = "";
  1384. if ($dd == $dept)
  1385. {
  1386. $sel = "selected";
  1387. }
  1388. $dispval = $dd;
  1389. if (strlen($dispval) > 40) {
  1390. $dispval = trim(substr($dispval, 0, 37)) . "...";
  1391. }
  1392. $bC .= "<option value='$dd' $sel>$dispval</option> \n";
  1393. }
  1394. $rtn = str_replace("<!--DEPTSEARCH-->",$bC,$rtn);
  1395. return $rtn;
  1396. }
  1397. /**
  1398. * Simple function to return the human-readable name for a role, by rid.
  1399. *
  1400. * @param unknown_type $rid
  1401. */
  1402. function user_get_role_name($rid) {
  1403. $name = db_result(db_query("SELECT name FROM roles WHERE rid = ? ", $rid));
  1404. return $name;
  1405. }

Functions

Namesort descending Description
user_display_student_users Similar to user_display_users, except only for student users.
user_display_users Display our list of faculty/staff users in the system.
user_edit_user_advisees_form This form lets us populate the advisor_student table
user_edit_user_advisees_form_submit Save to the advisor_student table
user_edit_user_advisees_form_validate Check to see if we entered a CWID which doesn't exist in students table.
user_edit_user_form Let the user edit a user's roles and other information.
user_edit_user_form_submit Submit handler for our edit faculty form
user_edit_user_form_validate Validate handler for editing faculty users.
user_get_role_name Simple function to return the human-readable name for a role, by rid.
user_menu Implementation of hook_menu
user_perm
user_permissions_form This is the permissions form, where users can set which roles have which permissions.
user_permissions_form_submit Submit handler for the permissions form.
user_subtab_switchboard Decide what should happen when we go to "admin/config/users" by itself
user_user_roles_form This form allows the user to manage the roles in the system.
user_user_roles_form_submit