schools.module

  1. 7.x modules/schools/schools.module
  2. 6.x modules/schools/schools.module

Schools module.

Lets some of FlightPath's functionality (and the degrees, etc) be separated by "schools" or any other arbitrary separation

File

modules/schools/schools.module
View source
  1. <?php
  2. /**
  3. * @file
  4. * Schools module.
  5. *
  6. * Lets some of FlightPath's functionality (and the degrees, etc) be separated by "schools" or any other arbitrary
  7. * separation
  8. */
  9. function __schools_add_school_id_to_fp5_tables() {
  10. set_time_limit ( 999 ); // might take a while
  11. $tables = array(
  12. 'courses', 'draft_courses', 'degrees', 'draft_degrees', 'groups', 'draft_groups',
  13. 'colleges *',
  14. 'degree_college',
  15. 'degree_tracks', 'draft_degree_tracks',
  16. 'draft_instructions',
  17. 'standardized_tests',
  18. 'student_tests',
  19. 'subjects *',
  20. 'transfer_courses',
  21. 'transfer_institutions',
  22. 'users',
  23. 'watchdog',
  24. );
  25. $needs_primary = array();
  26. $show_create = array();
  27. foreach ($tables as $table) {
  28. $bool_primary = FALSE;
  29. if (strstr($table, "*")) {
  30. $table = trim(str_replace("*", "", $table));
  31. $bool_primary = TRUE;
  32. }
  33. $show_create[] = $table;
  34. // If we were supposed to ALSO add as a primary key, then we should output a message to the user, so they know to do that.
  35. if ($bool_primary) {
  36. $needs_primary[] = $table;
  37. }
  38. // Does this table already have school_id field?
  39. $res = db_query("show columns from `$table` WHERE `Field` = 'school_id'");
  40. $cur = db_fetch_array($res);
  41. $test = @trim($cur['Field']);
  42. if ($test == 'school_id') continue;
  43. // Otherwise, we need to add the column to the table, and a key!
  44. fpm("Adding to $table...");
  45. $q = "ALTER TABLE `$table` ADD COLUMN `school_id` INT NOT NULL DEFAULT 0";
  46. db_query($q);
  47. // Add regular key
  48. $q = "ALTER TABLE `$table` ADD KEY `school_id` (`school_id`)";
  49. db_query($q);
  50. } // foreach
  51. fpm($needs_primary);
  52. //////////////////////////////////////
  53. // Set our new primary keys
  54. foreach ($needs_primary as $table) {
  55. $res = db_query("SHOW KEYS FROM `$table` WHERE Key_name = 'PRIMARY'");
  56. $keys = array();
  57. while ($cur = db_fetch_array($res)) {
  58. $cn = $cur['Column_name'];
  59. if ($cn == 'school_id') continue; // already in there.
  60. $keys[] = $cn;
  61. }
  62. $keys[] = 'school_id';
  63. $kline = join(", ", $keys);
  64. db_query("ALTER TABLE `$table`
  65. DROP PRIMARY KEY,
  66. ADD PRIMARY KEY ($kline)");
  67. }
  68. $rtn = "";
  69. foreach ($show_create as $table) {
  70. $res = db_query("SHOW CREATE TABLE `$table`");
  71. $cur = db_fetch_array($res);
  72. $create = $cur['Create Table'];
  73. $create = str_ireplace("USING BTREE", "", $create);
  74. $create = str_ireplace("CHARACTER SET latin1", "", $create);
  75. $create = str_ireplace("COLLATE utf8mb4_unicode_ci", "", $create);
  76. $temp = explode("ENGINE=", $create);
  77. $create = trim($temp[0]);
  78. $rtn .= $create . "; \n\n\n\n";
  79. }
  80. fpm("<textarea>$rtn</textarea>");
  81. } // end function
  82. /**
  83. * Implements hook_init
  84. */
  85. function schools_init() {
  86. // Is there an urgent message to display based on school?
  87. global $user;
  88. $school_id = $user->school_id;
  89. $defs = schools_get_school_definitions();
  90. $urgent_msg = trim(variable_get("urgent_msg_$school_id", ""));
  91. if ($urgent_msg) {
  92. fp_add_message("<b>" . t("Important Message (%school_desc):", array("%school_desc" => @$defs[$school_id])) . "</b> " . $urgent_msg, "status", TRUE);
  93. }
  94. } // hook_init
  95. /**
  96. * Implements hook_menu
  97. */
  98. function schools_menu() {
  99. $items = array();
  100. $items['admin/config/schools'] = array(
  101. 'title' => 'Schools settings',
  102. 'description' => 'Administer and define the Schools at your institution',
  103. 'page_callback' => 'fp_render_form',
  104. 'page_arguments' => array('schools_administer_schools_form'),
  105. 'access_arguments' => array('administer_schools'),
  106. "page_settings" => array(
  107. "page_show_title" => TRUE,
  108. "menu_icon" => fp_get_module_path('system') . "/icons/building.png",
  109. "menu_links" => array(
  110. 0 => array(
  111. "text" => "Admin Console",
  112. "path" => "admin-tools/admin",
  113. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  114. ),
  115. ),
  116. ),
  117. 'type' => MENU_TYPE_NORMAL_ITEM,
  118. );
  119. // For each school we have defined, let's create a menu item for configuring
  120. // school-specific settings.
  121. $defs = schools_get_school_definitions(TRUE);
  122. $weight = 0;
  123. foreach ($defs as $cur) {
  124. $school_name = $cur['name'];
  125. $school_id = intval($cur['school_id']);
  126. if ($school_id === 0) continue; // skip default since that wil be there already
  127. $items["admin/config/school-data/$school_id"] = array(
  128. "title" => $school_name,
  129. "page_callback" => "fp_render_form",
  130. "page_arguments" => array("system_school_data_form", "system_settings", 3),
  131. "access_arguments" => array("de_can_administer_school_data"), // TODO: make sure we can administer THIS school data. Add new perms.
  132. "page_settings" => array(
  133. "page_hide_report_error" => TRUE,
  134. "menu_icon" => fp_get_module_path('system') . "/icons/cog_edit.png",
  135. "menu_links" => array(
  136. 0 => array(
  137. "text" => "Admin Console",
  138. "path" => "admin-tools/admin",
  139. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  140. ),
  141. ),
  142. ),
  143. "type" => MENU_TYPE_TAB,
  144. "tab_family" => "config_school_settings",
  145. "weight" => $weight,
  146. );
  147. $items["admin/edit-advising-settings/$school_id"] = array(
  148. "title" => $school_name,
  149. "page_callback" => "fp_render_form",
  150. "page_arguments" => array("admin_advising_settings_form", "system_settings", 2),
  151. "access_arguments" => array("can_edit_advising_settings"),
  152. "page_settings" => array(
  153. "page_hide_report_error" => TRUE,
  154. "menu_links" => array(
  155. 0 => array(
  156. "text" => "Admin Console",
  157. "path" => "admin-tools/admin",
  158. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  159. ),
  160. ),
  161. ),
  162. "type" => MENU_TYPE_TAB,
  163. "tab_family" => "edit_advising_settings",
  164. "weight" => $weight,
  165. );
  166. $items["admin/config/course-search/$school_id"] = array(
  167. "title" => $school_name,
  168. "page_callback" => "fp_render_form",
  169. "page_arguments" => array("course_search_settings_form", "system_settings", 3),
  170. "access_arguments" => array("administer_course_search"),
  171. "page_settings" => array(
  172. "page_hide_report_error" => TRUE,
  173. "menu_links" => array(
  174. 0 => array(
  175. "text" => "Admin Console",
  176. "path" => "admin-tools/admin",
  177. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  178. ),
  179. ),
  180. ),
  181. "type" => MENU_TYPE_TAB,
  182. "tab_family" => "course_search_settings",
  183. "weight" => $weight,
  184. );
  185. $items["admin/config/appointments/$school_id"] = array(
  186. 'title' => $school_name,
  187. 'page_callback' => 'fp_render_form',
  188. 'page_arguments' => array('calendar_appointment_settings_form', 'system_settings', 3),
  189. 'access_arguments' => array('administer_appointment_settings'),
  190. "page_settings" => array(
  191. "page_hide_report_error" => TRUE,
  192. "menu_links" => array(
  193. 0 => array(
  194. "text" => "Admin Console",
  195. "path" => "admin-tools/admin",
  196. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  197. ),
  198. ),
  199. ),
  200. 'type' => MENU_TYPE_TAB,
  201. "tab_family" => "appointment_settings", // REMEMBER TO ALSO EDIT SCHOOLS_MENU_ALTER
  202. 'weight' => $weight,
  203. );
  204. $items["admin/config/alerts-settings/$school_id"] = array(
  205. "title" => $school_name,
  206. "page_callback" => "fp_render_form",
  207. "page_arguments" => array("alerts_settings_form", "system_settings", 3),
  208. "access_arguments" => array("administer_alerts"),
  209. "page_settings" => array(
  210. "page_hide_report_error" => TRUE,
  211. "menu_links" => array(
  212. 0 => array(
  213. "text" => "Admin Console",
  214. "path" => "admin-tools/admin",
  215. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  216. ),
  217. ),
  218. ),
  219. "type" => MENU_TYPE_TAB,
  220. "tab_family" => "alerts_settings",
  221. "weight" => $weight,
  222. );
  223. $items["admin/config/audit-settings/$school_id"] = array(
  224. "title" => $school_name,
  225. "page_callback" => "fp_render_form",
  226. "page_arguments" => array("audit_settings_form", "system_settings", 3),
  227. "access_arguments" => array("administer_audit"),
  228. "page_settings" => array(
  229. "page_hide_report_error" => TRUE,
  230. "menu_links" => array(
  231. 0 => array(
  232. "text" => "Admin Console",
  233. "path" => "admin-tools/admin",
  234. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  235. ),
  236. ),
  237. ),
  238. "type" => MENU_TYPE_TAB,
  239. "tab_family" => "audit_settings",
  240. "weight" => $weight,
  241. );
  242. $weight = $weight + 10;
  243. }
  244. return $items;
  245. } // hook_menu
  246. /**
  247. * hook_menu_alter
  248. *
  249. * We want to alter some system menu items, so we can make sure to check
  250. * our new custom permissions.
  251. */
  252. function schools_menu_alter(&$items) {
  253. if (!is_array($items)) return;
  254. foreach ($items as $path => $item) {
  255. if ($path == 'admin/degrees/edit-degree/%/%') {
  256. // alter access_callback and arguments to make sure
  257. // the user is able to edit THIS degree.
  258. $items[$path]['access_callback'] = 'schools_check_access';
  259. $items[$path]['access_arguments'] = array(2, 3, 4);
  260. }
  261. // The path for editing a group looks like this:
  262. // admin/groups/edit-group?group_id=XXX&de_catalog_year=XXX
  263. if ($path == 'admin/groups/edit-group') {
  264. $items[$path]['access_callback'] = 'schools_check_access';
  265. $items[$path]['access_arguments'] = array(2, "request_group_id", "group_catalog_year");
  266. }
  267. // The path for editing a course looks like this:
  268. // admin/courses/edit-course?course_id=XXX&de_catalog_year=XXX
  269. if ($path == 'admin/courses/edit-course') {
  270. $items[$path]['access_callback'] = 'schools_check_access';
  271. $items[$path]['access_arguments'] = array(2, "request_course_id", "course_catalog_year");
  272. }
  273. // We want to make this a default tab, because we are going to
  274. // have our other schools have their own tabs as well.
  275. if ($path == 'admin/config/school-data') {
  276. $items[$path]['type'] = MENU_TYPE_DEFAULT_TAB;
  277. $items[$path]['tab_family'] = 'config_school_settings';
  278. $items[$path]['page_settings']['tab_title'] = t('Default');
  279. unset($items[$path]['tab_parent']);
  280. }
  281. if ($path == 'admin/edit-advising-settings') {
  282. $items[$path]['type'] = MENU_TYPE_DEFAULT_TAB;
  283. $items[$path]['tab_family'] = 'edit_advising_settings';
  284. $items[$path]['page_settings']['tab_title'] = t('Default');
  285. unset($items[$path]['tab_parent']);
  286. }
  287. if ($path == 'admin/config/course-search') {
  288. $items[$path]['type'] = MENU_TYPE_DEFAULT_TAB;
  289. $items[$path]['tab_family'] = 'course_search_settings';
  290. $items[$path]['page_settings']['tab_title'] = t('Default');
  291. unset($items[$path]['tab_parent']);
  292. }
  293. if ($path == 'admin/config/alerts-settings') {
  294. $items[$path]['type'] = MENU_TYPE_DEFAULT_TAB;
  295. $items[$path]['tab_family'] = 'alerts_settings';
  296. $items[$path]['page_settings']['tab_title'] = t('Default');
  297. unset($items[$path]['tab_parent']);
  298. }
  299. if ($path == 'admin/config/audit-settings') {
  300. $items[$path]['type'] = MENU_TYPE_DEFAULT_TAB;
  301. $items[$path]['tab_family'] = 'audit_settings';
  302. $items[$path]['page_settings']['tab_title'] = t('Default');
  303. unset($items[$path]['tab_parent']);
  304. }
  305. if ($path == 'admin/config/appointments') {
  306. $items[$path]['type'] = MENU_TYPE_DEFAULT_TAB;
  307. $items[$path]['tab_family'] = 'appointment_settings';
  308. $items[$path]['page_settings']['tab_title'] = t('Default');
  309. unset($items[$path]['tab_parent']);
  310. }
  311. } // foreach
  312. } // hook_menu_alter
  313. /**
  314. * this is our custom access callback.
  315. *
  316. * op is expected to be 'edit-degree', 'edit-course', or 'edit-group'
  317. * entity_code is the degree_id for degrees, group_id for groups, and course_id for courses.
  318. *
  319. *
  320. */
  321. function schools_check_access($op, $entity_code, $catalog_year) {
  322. // If the user doesn't have this base permission, they can't edit anything
  323. // at all.
  324. if (!user_has_permission("can_edit_data_entry")) {
  325. return FALSE;
  326. }
  327. $school_id = $entity_type = "";
  328. $db = get_global_database_handler();
  329. /////////////////////
  330. if ($op == 'edit-degree') {
  331. $entity_type = 'degree';
  332. $school_id = db_result(db_query("SELECT school_id FROM draft_degrees
  333. WHERE degree_id = ?
  334. AND catalog_year = ?", $entity_code, $catalog_year));
  335. }
  336. ///////////////////////
  337. // The path for editing a group looks like this:
  338. // admin/groups/edit-group?group_id=XXX&de_catalog_year=XXX
  339. if ($op == 'edit-group') {
  340. $entity_type = "group";
  341. $group_id = $_REQUEST['group_id'];
  342. if ($group_id == 'new') return TRUE;
  343. $school_id = intval(db_result(db_query("SELECT school_id FROM draft_groups WHERE group_id = ?", $group_id)));
  344. }
  345. ///////////////////////
  346. // The path for editing a course looks like this:
  347. // admin/courses/edit-course?course_id=XXX&de_catalog_year=XXX
  348. if ($op == 'edit-course') {
  349. $entity_type = "course";
  350. $course_id = $_REQUEST['course_id'];
  351. if ($course_id == 'new') return TRUE;
  352. $school_id = intval(db_result(db_query("SELECT school_id FROM draft_courses WHERE course_id = ?", $course_id)));
  353. }
  354. // Actually check the permission, IF there is a school_id set.
  355. if ($school_id != "" && $entity_type != "") {
  356. if (!user_has_permission('administer_' . $school_id . '_' . $entity_type . '_data')) {
  357. return FALSE;
  358. }
  359. }
  360. // If we got here, then we didn't fail any permission checks, so we can let the user proceed.
  361. return TRUE;
  362. } // schools_check_access
  363. /**
  364. * Return a list of schools in an array, for use in the "options" of
  365. * a select list in the Form API.
  366. *
  367. * If $bool_check_perm is true, then we will check permissions before adding it to the array.
  368. */
  369. function schools_get_schools_for_fapi($bool_include_default = TRUE, $bool_check_perm = FALSE, $check_perm_type = "degree", $bool_include_school_code = FALSE) {
  370. $rtn = array();
  371. $defs = schools_get_school_definitions(TRUE);
  372. if ($bool_include_default) {
  373. $rtn[0] = t(' - Default -');
  374. }
  375. foreach ($defs as $school_id => $val) {
  376. $title = $val['name'];
  377. if ($bool_include_school_code) {
  378. $title = $val['school_code'] . ' - ' . $val['name'];
  379. }
  380. if ($bool_check_perm) {
  381. if (user_has_permission('administer_' . $school_id . '_' . $check_perm_type . '_data') || user_has_permission('manage_' . $school_id . '_' . $check_perm_type . '_data')) {
  382. $rtn[$school_id] = $title;
  383. }
  384. }
  385. else {
  386. $rtn[$school_id] = $title;
  387. }
  388. }
  389. return $rtn;
  390. }
  391. function schools_content_alter(&$render, $render_id) {
  392. $defs = schools_get_school_definitions(TRUE);
  393. if ($render_id == 'admin_display_degrees') {
  394. //fpm($render);
  395. // Add the school to the table.
  396. $v = $render['degrees_table_top']['value'];
  397. $v = str_replace("</tr>", "<th>School</th></tr>", $v);
  398. $render['degrees_table_top']['value'] = $v;
  399. foreach ($render as $key => $val) {
  400. if (strstr($key, 'degree_row_')) {
  401. // Find out the school_id for this degree, if it exists.
  402. $school_id = intval($val['data']['db_row']['school_id']);
  403. $school_code = "-";
  404. if ($school_id != 0) {
  405. $school_code = $defs[$school_id]['school_code'];
  406. }
  407. // Fill in the school code as the last td in the table row.
  408. $render[$key]['value'] = str_replace('</tr>', "<td class='degree-school'>$school_code</td></tr>", $render[$key]['value']);
  409. if ($school_id == 0) continue; // Everyone can edit school_id 0
  410. // A school id has indeed been set, so we need to see if this user is allowed to edit it or not.
  411. if (!user_has_permission('administer_' . $school_id . '_degree_data')) {
  412. // No, so let's remove it.
  413. unset($render[$key]);
  414. }
  415. }
  416. } // foreach
  417. } // admin_display_degrees
  418. /////////////////////////////////
  419. if ($render_id == 'admin_display_groups') {
  420. // Add school to our table top.
  421. $v = $render['groups_table_top']['value'];
  422. $v = str_replace("</tr>", "<th>School</th></tr>", $v);
  423. $render['groups_table_top']['value'] = $v;
  424. foreach ($render as $key => $val) {
  425. if (strstr($key, 'group_row_')) {
  426. // Find out the school_id for this group, if it exists.
  427. $school_id = intval($val['data']['db_row']['school_id']);
  428. $school_code = "-";
  429. if ($school_id != 0) {
  430. $school_code = $defs[$school_id]['school_code'];
  431. }
  432. // Fill in the school code as the last td in the table row.
  433. $render[$key]['value'] = str_replace('</tr>', "<td class='group-school'>$school_code</td></tr>", $render[$key]['value']);
  434. if ($school_id == 0) continue; // everyone can edit school_id 0
  435. // A school id has indeed been set, so we need to see if this user is allowed to edit it or not.
  436. if (!user_has_permission('administer_' . $school_id . '_group_data')) {
  437. // No, so let's hide it.
  438. unset($render[$key]);
  439. }
  440. }
  441. } // foreach
  442. } // admin_display_groups
  443. ///////////////////////////////
  444. if ($render_id == 'admin_display_courses') {
  445. // Add school to our table top.
  446. $v = $render['courses_table_top']['value'];
  447. $v = str_replace("</tr>", "<th>School</th></tr>", $v);
  448. $render['courses_table_top']['value'] = $v;
  449. foreach ($render as $key => $val) {
  450. if (strstr($key, 'course_row_')) {
  451. // Find out the school_id for this degree, if it exists.
  452. $school_id = intval($val['data']['db_row']['school_id']);
  453. $school_code = "-";
  454. if ($school_id != 0) {
  455. $school_code = $defs[$school_id]['school_code'];
  456. }
  457. // Fill in the school code as the last td in the table row.
  458. $render[$key]['value'] = str_replace('</tr>', "<td class='course-school'>$school_code</td></tr>", $render[$key]['value']);
  459. if ($school_id == 0) continue; // everyone can edit school id 0
  460. // A school id has indeed been set, so we need to see if this user is allowed to edit it or not.
  461. if (!user_has_permission('administer_' . $school_id . '_course_data')) {
  462. // No, so let's hide it.
  463. unset($render[$key]);
  464. }
  465. }
  466. } // foreach
  467. } // admin_display_courses
  468. if ($render_id == 'user_display_users') {
  469. // Add school to our table top.
  470. $v = $render['users_table_top']['value'];
  471. $v = str_replace("</tr>", "<th>School</th></tr>", $v);
  472. $render['users_table_top']['value'] = $v;
  473. foreach ($render as $key => $val) {
  474. if (strstr($key, 'user_row_')) {
  475. // Find out the school_id for this degree, if it exists.
  476. $school_id = intval($val['data']['db_row']['school_id']);
  477. $school_code = "-";
  478. if ($school_id != 0) {
  479. $school_code = $defs[$school_id]['school_code'];
  480. }
  481. // Fill in the school code as the last td in the table row.
  482. $render[$key]['value'] = str_replace('</tr>', "<td class='course-school'>$school_code</td></tr>", $render[$key]['value']);
  483. if ($school_id == 0) continue; // everyone can edit school id 0
  484. // A school id has indeed been set, so we need to see if this user is allowed to edit it or not.
  485. if (!user_has_permission('manage_' . $school_id . '_user_data')) {
  486. // No, so let's hide it.
  487. unset($render[$key]);
  488. }
  489. }
  490. } // foreach
  491. } // user_display_users
  492. } // hook_content_alter
  493. /**
  494. * Implements hook_form_alter
  495. */
  496. function schools_form_alter(&$form, $form_id) {
  497. $forms_to_alter = array(
  498. 'admin_edit_degree_form',
  499. 'admin_edit_group_form',
  500. 'admin_edit_course_form',
  501. 'user_edit_user_form',
  502. 'user_edit_student_user_form',
  503. );
  504. // Add "school" dropdown to the degrees, groups, and courses form
  505. if (in_array($form_id, $forms_to_alter)) {
  506. fp_add_js(fp_get_module_path("schools") . '/js/schools.js');
  507. $db = get_global_database_handler();
  508. $school_id = 0; // default
  509. $entity_id = 0; // default
  510. if ($form_id == 'admin_edit_degree_form') {
  511. $entity_type = 'degree';
  512. $degree_id = @intval($form['degree_id']['value']);
  513. $entity_id = $degree_id;
  514. if ($degree_id) {
  515. $school_id = $db->get_school_id_for_degree_id($degree_id, TRUE);
  516. }
  517. $weight = 1120;
  518. @$catalog_year = $form['de_catalog_year']['value'];
  519. if ($catalog_year == "") {
  520. @$catalog_year = $form['catalog_year']['value'];
  521. }
  522. }
  523. // Is this a "group" we are editing?
  524. if ($form_id == "admin_edit_group_form") {
  525. $entity_type = 'group';
  526. $weight = 45;
  527. $group_id = @$form['group_id']['value'];
  528. $entity_id = $group_id;
  529. $school_id = $db->get_school_id_for_group_id($group_id, TRUE);
  530. }
  531. if ($form_id == 'admin_edit_course_form') {
  532. $entity_type = 'course';
  533. $course_id = @intval($form['course_id']['value']);
  534. $entity_id = $course_id;
  535. $weight = 55;
  536. $school_id = $db->get_school_id_for_course_id($course_id, TRUE);
  537. // We also want to adjust the description for the "update for all years" checkbox.
  538. $form['all_years']['options']['yes'] = t('Update title, description, hour info, and school selection for all years of this course.');
  539. }
  540. if ($form_id == 'user_edit_user_form' || $form_id == 'user_edit_student_user_form') {
  541. $entity_type = 'user';
  542. $user_id = intval($form['user_id']['value']);
  543. $entity_id = $user_id;
  544. $school_id = $db->get_school_id_for_user_id($user_id, TRUE);
  545. $weight = 95;
  546. } // user edit form
  547. $options = schools_get_schools_for_fapi(TRUE, TRUE, $entity_type, TRUE);
  548. $form['schools_school'] = array(
  549. 'type' => 'select',
  550. 'label' => t('School:'),
  551. 'options' => $options,
  552. 'attributes' => array('onchange' => "return schoolsConfirmChangeSchool($school_id);"),
  553. 'value' => $school_id,
  554. 'hide_please_select' => TRUE,
  555. 'weight' => $weight,
  556. 'popup_description' => t('Please select a school which this @datatype belongs to. Schools are defined under the Admin Console -> Configure Schools.', array('@datatype' => $entity_type)),
  557. 'description' => t("<strong>Caution:</strong> changing this value could have unexpected consequences. If unsure what to do, set to Default."),
  558. );
  559. $form['schools_entity_type'] = array(
  560. 'type' => 'hidden',
  561. 'value' => $entity_type,
  562. );
  563. $form['schools_entity_id'] = array(
  564. 'type' => 'hidden',
  565. 'value' => $entity_id,
  566. );
  567. // We also need to add our custom submit handler so that our selection gets saved correctly.
  568. // Also, use unshift so it's the first thing we do.
  569. //$form['#submit_handlers'][] = 'schools_data_form_submit';
  570. if (!isset($form['#submit_handlers'])) $form['#submit_handlers'] = array();
  571. array_unshift($form['#submit_handlers'], 'schools_data_form_submit');
  572. // If this is a NEW group, then don't show them anything!
  573. if (($entity_type == 'group' && @$form['group_id']['value'] === 'new') || ($entity_type == 'course' && @$form['course_id']['value'] === 'new') || ($entity_type == 'user' && @intval($form['user_id']['value']) === 0)) {
  574. $form['schools_school'] = array(
  575. 'type' => 'markup',
  576. 'label' => t('School:'),
  577. 'value' => t('<b>Please save this @dt at least once (to establish an ID in the database). Once you have done this,
  578. the School selection box will appear.</b>', array('@dt' => $entity_type)),
  579. 'weight' => $weight,
  580. );
  581. }
  582. } // if in_array forms to alter
  583. // When we copy a degree, make sure we have a chance to interact (so we can
  584. // indicate the degree as well.
  585. if ($form_id == "admin_copy_degree_form") {
  586. $options = schools_get_schools_for_fapi(TRUE, TRUE, 'degree', TRUE);
  587. $form['school_id'] = array(
  588. 'type' => 'select',
  589. 'label' => 'Source School:',
  590. 'options' => $options,
  591. 'hide_please_select' => TRUE,
  592. 'weight' => 25,
  593. 'popup_description' => t('Please select a school which this degree belongs to. Schools are defined under the Admin Console -> Configure Schools.'),
  594. 'description' => t("This must match the source degree. If you do not know the source degree's school, or are unsure what to select, set to Default."),
  595. );
  596. $form['destination_school_id'] = array(
  597. 'type' => 'select',
  598. 'label' => 'Destination School:',
  599. 'options' => $options,
  600. 'hide_please_select' => TRUE,
  601. 'weight' => 35,
  602. 'popup_description' => t('Please select a school which you wish to save the new degree into. Schools are defined under the Admin Console -> Configure Schools.'),
  603. 'description' => t("Please select a school which you wish to save the new degree into. If you are unsure what to select, set to Default."),
  604. );
  605. //if (!isset($form['#validate_handlers'])) $form['#validate_handlers'] = array();
  606. //array_unshift($form['#validate_handlers'], 'schools_admin_copy_degree_form_validate');
  607. }
  608. if ($form_id == 'admin_add_degree_form') {
  609. $options = schools_get_schools_for_fapi(TRUE, TRUE, 'degree', TRUE);
  610. $form['school_id'] = array(
  611. 'type' => 'select',
  612. 'label' => 'School:',
  613. 'options' => $options,
  614. 'value' => $school_id,
  615. 'hide_please_select' => TRUE,
  616. 'weight' => 15,
  617. 'popup_description' => t('Please select a school which this degree belongs to. Schools are defined under the Admin Console -> Configure Schools.'),
  618. 'description' => t("This must match the source degree. If you do not know the source degree's school, or are unsure what to select, set to Default."),
  619. );
  620. }
  621. // Alter the "urgent message" form, to include new verbiage about how the main one is "global", and add new
  622. // boxes for each school.
  623. if ($form_id == 'admin_urgent_message_form') {
  624. $form["mark_school"] = array(
  625. 'value' => '<br><hr><p>' . t('<h2>Schools</h2>The following boxes are provided by the Schools module, so that you may display
  626. urgent messages to <b>students</b> and <b>faculty/staff</b>, based on the school they have been assigned to.') . "</p>",
  627. );
  628. $defs = schools_get_school_definitions();
  629. foreach ($defs as $school_id => $school_desc) {
  630. if ($school_id == 0) continue;
  631. $form["urgent_msg_$school_id"] = array(
  632. "type" => "textarea",
  633. "label" => t("Urgent Message for users in %school_desc:", array("%school_desc" => $school_desc)),
  634. "value" => variable_get("urgent_msg_$school_id", ""),
  635. 'description' => t("To delete this message, simple delete all the text in this box and save."),
  636. );
  637. }
  638. $form['mark_below_school'] = array(
  639. 'value' => '<br><hr><br>',
  640. );
  641. } // form is admin_urgent_message_form
  642. // Forms for which we should allow override values per school.
  643. $oforms = array('alerts_settings_form',"system_school_data_form",'admin_advising_settings_form',"course_search_settings_form",'audit_settings_form','calendar_appointment_settings_form');
  644. if (in_array($form_id,$oforms)) {
  645. // We want to add a "use default" checkbox at the top, which, if set, will disable all of the form elements.
  646. fp_add_js(fp_get_module_path('schools') . '/js/schools.js');
  647. fp_add_css(fp_get_module_path('system') . '/css/style.css');
  648. fp_add_css(fp_get_module_path('schools') . '/css/style.css');
  649. $school_id = intval($form['school_id']['value']);
  650. if ($school_id !== 0) {
  651. $school_name = schools_get_school_name_for_id($school_id);
  652. $form['markup_school_use_default_school_values'] = array(
  653. 'type' => 'markup',
  654. 'value' => "<div>" . t("Since this is not the Default school, you have the option to <em>override</em> the Default school's values for each field.
  655. <br>If <strong>checked</strong>, the value you enter will be used for students, degrees, etc, belonging to this school (%school).
  656. <br>If <strong>unchecked</strong>, the value you enter will be ignored, and the Default school's value will be used instead.
  657. <br><br>If unsure what to do, leave these 'Override' boxes unchecked.
  658. ", array("%school" => $school_name)) . "</div>",
  659. 'weight' => -100,
  660. );
  661. // Add a checkbox to every form element!
  662. $fields_to_edit = array('textfield', 'textarea', 'select', 'checkboxes');
  663. $fields_to_check_override = "";
  664. foreach ($form as $fieldname => $element) {
  665. if (in_array($element['type'], $fields_to_edit)) {
  666. // Add an "override" checkbox for this field.
  667. $checked = "";
  668. if (variable_get("school_override__$fieldname", "") === "yes") {
  669. $checked = "checked=checked";
  670. }
  671. if (!isset($form[$fieldname]['prefix'])) $form[$fieldname]['prefix'] = "";
  672. $n_fieldname = $fieldname;
  673. if ($element['type'] == 'checkboxes') {
  674. $n_fieldname = 'inner-wrapper-' . $fieldname;
  675. }
  676. $css_id = md5($fieldname) . mt_rand(9,9999);
  677. $form[$fieldname]['prefix'] .= "<span class='schools-override-cb'>
  678. <label><input type='checkbox' name='school_override__$n_fieldname' class='school-override-cb' id='school_override__$css_id' value='yes' $checked>" . t("Override Default school value?") . "</label></span>";
  679. // Also add this fieldname to our "fields_to_check_override" string, so we can put it in a hidden textarea for later use in the _submit function.
  680. $fields_to_check_override .= $fieldname . ",";
  681. }
  682. } // foreach
  683. $form['markup_fields_to_override'] = array(
  684. 'value' => "<textarea name='fields_to_check_override' style='display:none;'>$fields_to_check_override</textarea>",
  685. 'weight' => 999,
  686. );
  687. // We also need to add a custom submit handler, so we can save the "override" values.
  688. $form['#submit_handlers'][] = 'schools_override_elements_form_submit';
  689. } // school != 0
  690. } // system_school_data_form
  691. } // hook_form_alter
  692. function schools_override_elements_form_submit($form, $form_state) {
  693. // our override values will be in the POST, not the regular "values" area.
  694. $school_id = intval($form_state['values']['school_id']);
  695. $fields_to_check_override = explode(",", $form_state['POST']['fields_to_check_override']);
  696. foreach($fields_to_check_override as $fieldname) {
  697. if ($fieldname == "") continue;
  698. // get the base fieldname (minus any school designation).
  699. $temp = explode("~~", $fieldname);
  700. $base_fieldname = $temp[0];
  701. if (@$form_state['POST']["school_override__$fieldname"] === 'yes') {
  702. // We are overriding the fieldname.
  703. variable_set("school_override__$fieldname", "yes");
  704. } // if override == yes
  705. else {
  706. // We are NOT overriding it.
  707. variable_set("school_override__$fieldname", "no");
  708. }
  709. } //foreach
  710. }
  711. function schools_get_school_code_for_id($school_id) {
  712. if (isset($GLOBALS["fp_cache_school_code_for_id"][intval($school_id)])) {
  713. return $GLOBALS["fp_cache_school_code_for_id"][intval($school_id)];
  714. }
  715. $defs = schools_get_school_definitions(TRUE);
  716. $rtn = @$defs[$school_id]['school_code'];
  717. if ($rtn == "") {
  718. $rtn .= t("School ID# ") . $school_id;
  719. }
  720. if (intval($school_id) === 0) {
  721. $rtn = "-";
  722. }
  723. $GLOBALS["fp_cache_school_code_for_id"][intval($school_id)] = $rtn;
  724. return $rtn;
  725. }
  726. function schools_get_school_name_for_id($school_id) {
  727. if (isset($GLOBALS["fp_cache_school_name_for_id"][intval($school_id)])) {
  728. return $GLOBALS["fp_cache_school_name_for_id"][intval($school_id)];
  729. }
  730. $defs = schools_get_school_definitions(FALSE);
  731. $rtn = @$defs[$school_id];
  732. if ($rtn == "") {
  733. $rtn .= t("School ID# ") . $school_id;
  734. }
  735. $GLOBALS["fp_cache_school_name_for_id"][intval($school_id)] = $rtn;
  736. return $rtn;
  737. }
  738. function z__schools_admin_copy_degree_form_validate($form, &$form_state) {
  739. $values = $form_state['values'];
  740. $source_major_code = $values['source_major_code'];
  741. $school_id = $values['schools_school'];
  742. $form_state['values']['school_id'] = intval($school_id);
  743. // Make sure that this major code exists for this school.
  744. $res = db_query("SELECT * FROM draft_degrees WHERE major_code = ? AND school_id = ?", array($source_major_code, $school_id));
  745. $cur = db_fetch_array($res);
  746. if (!$cur) {
  747. form_error("source_major_code", t("Sorry, but the source major code could not be found for the selected school. Please verify the school that the source degree belongs to."));
  748. form_error("schools_school", "");
  749. }
  750. }
  751. function schools_data_form_submit($form, &$form_state) {
  752. $schools_entity_type = $form_state['values']['schools_entity_type'];
  753. $entity_id = $form_state['values']['schools_entity_id'];
  754. @$degree_id = intval($form_state['values']['degree_id']);
  755. @$group_id = intval($form_state['values']['group_id']);
  756. @$course_id = intval($form_state['values']['course_id']);
  757. @$user_id = intval($form_state['values']['user_id']);
  758. @$catalog_year = $form_state['values']['de_catalog_year'];
  759. if ($catalog_year == "") {
  760. @$catalog_year = $form_state['values']['catalog_year'];
  761. }
  762. $school_id = intval($form_state['values']['schools_school']);
  763. $form_state['values']['school_id'] = $school_id;
  764. // Update the table in question.
  765. $table_name = 'draft_degrees';
  766. $field_name = "degree_id";
  767. if ($schools_entity_type == "group") {
  768. $table_name = "draft_groups";
  769. $field_name = "group_id";
  770. }
  771. if ($schools_entity_type == "course") {
  772. $table_name = "draft_courses";
  773. $field_name = "course_id";
  774. }
  775. if ($schools_entity_type == 'user') {
  776. $table_name = "users";
  777. $field_name = "user_id";
  778. }
  779. db_query("UPDATE `$table_name` SET school_id = ? WHERE $field_name = ?", array($school_id, $entity_id));
  780. // This section of code no longer applies.
  781. /*
  782. if ($schools_entity_type == 'course') {
  783. // If this is a course, we might have selected the 'all years' option. If so, we need to
  784. // look up all catalog years that this course exists, and set our data for each catalog year.
  785. if (@$form_state['values']['all_years']['yes'] == 'yes') {
  786. // First, find all catalog years for this course_id.
  787. $res = db_query("SELECT distinct(catalog_year) FROM draft_courses WHERE course_id = ?", array($course_id));
  788. while($cur = db_fetch_object($res)) {
  789. // Delete existing data...
  790. db_query("DELETE FROM draft_schools_data
  791. WHERE degree_id = ?
  792. AND group_id = ?
  793. AND course_id = ?
  794. AND catalog_year = ?
  795. ", array($degree_id, $group_id, $course_id, $cur->catalog_year));
  796. // Now, insert.
  797. db_query("INSERT INTO draft_schools_data
  798. (school_id, degree_id, group_id, course_id, catalog_year)
  799. VALUES (?, ?, ?, ?, ?)", array($school_id, $degree_id, $group_id, $course_id, $cur->catalog_year));
  800. } // while
  801. } // yes, we selected 'all years'
  802. } // if entity_type is course
  803. */
  804. }
  805. // NOTE: We no longer need to do anything when we apply draft changes.
  806. /**
  807. * Implements hook_apply_draft_changes
  808. *
  809. * This runs when the user "applies draft changes". We want to
  810. * copy from our draft_ table to our production table.
  811. */
  812. function z__schools_apply_draft_changes() {
  813. /*
  814. $table_name = "schools_data";
  815. $draft_table_name = "draft_$table_name";
  816. // First, truncate existing...
  817. $query = "truncate table $table_name";
  818. $res = db_query($query);
  819. // Now, copy in draft changes...
  820. $query = "INSERT INTO $table_name
  821. SELECT * FROM $draft_table_name ";
  822. $res = db_query($query);
  823. */
  824. } // hook_apply_draft_changes
  825. function schools_administer_schools_form() {
  826. $form = array();
  827. $form = array();
  828. $m = 0;
  829. fp_add_css(fp_get_module_path("alerts") . "/css/style.css");
  830. fp_add_css(fp_get_module_path("user") . "/css/user.css");
  831. fp_add_js(fp_get_module_path("admin") . "/js/admin.js");
  832. $form["mark" . $m++] = array(
  833. "type" => "markup",
  834. "value" => t("Schools can be divisions within your institution (ex: School of Nursing, School of Pharmacy, etc), distinct campuses
  835. (ex: Washington Campus, South Campus, etc), or divisions of graduate level (Undergrad, Graduate).
  836. The default school is simply called 'Default' and all users and degree data will be placed under the Default school unless otherwise specified.
  837. <br>If you are unsure what to do, <b>leave this page blank</b>.") . "
  838. <br><br>
  839. <a href='https://getflightpath.com/node/11879' target='_blank'>" . t("For a more thorough explanation of Schools, view this help page (loads in a new window)") . "</a>"
  840. . "<br><br><b>" . t("Schools:") . "</b>
  841. <table class='advisees-alerts' style='margin-left: 10px;' cellpadding=5>
  842. <tr>
  843. <th width='10%'>" . t("Actions") . "</th>
  844. <th width='10%'>" . t("Internal ID") . "</th>
  845. <th width='10%'>" . t("Code") . "</th>
  846. <th>" . t("Name") . "</th>
  847. </tr>",
  848. );
  849. $form["mark" . $m++] = array(
  850. "type" => "markup",
  851. "value" => "<tr><td>-</td><td>0</td><td>-</td><td>" . t("Default") . "</td></tr>",
  852. );
  853. $res = db_query("SELECT * FROM schools ORDER BY school_id");
  854. while ($cur = db_fetch_array($res)) {
  855. $school_id = $cur["school_id"];
  856. $code = $cur["school_code"];
  857. $value = $cur["name"];
  858. $prompt_link = fp_get_js_prompt_link("Enter a new code (up to 5 chars) and name separated by tilda ~ \\n(ex: ULM ~ University of Louisiana Monroe)\\nto change this school to:", "$code ~ $value", "document.getElementById(\"element-perform_action2\").value=\"edit~_~$school_id~_~\" + response; document.getElementById(\"fp-form-schools_administer_schools_form\").submit(); ", "<i class='fa fa-pencil'></i>");
  859. $confirm_link = fp_get_js_confirm_link(t("Are you sure you wish to delete this school_id?\\nNo data will be deleted, but the record connecting the id $school_id to this school will be removed from the 'schools' database table.\\n\\nProceed?"), "document.getElementById(\"element-perform_action2\").value=\"del~_~$school_id\"; document.getElementById(\"fp-form-schools_administer_schools_form\").submit(); ", "<i class='fa fa-remove'></i>", "action-link-remove");
  860. if ($school_id == 0 ) {
  861. $prompt_link = $confirm_link = "";
  862. }
  863. $form["mark" . $m++] = array(
  864. "type" => "markup",
  865. "value" => "<tr>
  866. <td >$prompt_link &nbsp; $confirm_link</td>
  867. <td>$school_id</td>
  868. <td>$code</td>
  869. <td>$value</td>
  870. </tr>",
  871. );
  872. }
  873. $form["mark" . $m++] = array(
  874. "type" => "markup",
  875. "value" => "</table>
  876. <br><div style='border: 1px solid gold; padding: 10px;'><strong>" . t("Important:") . "</strong> " . t("Even if you are not overriding any settings per school, you must still visit each school's <em>Configure school settings</em>
  877. screen from the Admin Console and press the Submit button. Otherwise, some features in FlightPath may not function correctly.</div>"),
  878. );
  879. $form["perform_action2"] = array(
  880. "type" => "hidden",
  881. );
  882. $form["new_school"] = array(
  883. "type" => "textfield",
  884. "label" => t("Add a new school as <i>code ~ name</i>:"),
  885. "description" => t("Enter a unique, 1 to 5 character, code for this school, then the name, separated by a tilda (~).
  886. <br> Ex: ULM ~ University of Louisiana Monroe"),
  887. );
  888. $form['schools_allow_courses_from_default_school'] = array(
  889. 'type' => 'select',
  890. 'label' => t("Allow courses (in degrees and groups) from the Default school as well as their assigned school?"),
  891. 'options' => array('yes' => t('Yes (default)'), 'no' => t('No')),
  892. 'hide_please_select' => TRUE,
  893. 'value' => variable_get('schools_allow_courses_from_default_school', 'yes'),
  894. 'description' => t("This setting has a <b>very powerful</b> implication.
  895. <br>&bull; If set to 'No', it means that degrees and groups must <b>only</b> use
  896. courses belonging to the same school as them. For example, this is useful if you have multiple institutions within FlightPath,
  897. each with a course named ENGL 101, and you need to be explicit about <em>which</em> ENGL 101 you mean.
  898. <br>&bull; If set to 'Yes', it means that degrees and groups will allow courses from their same school <b>as well as</b> courses
  899. from the Default school. This is good if you keep the majority of your courses under Default, and have <em>no duplicates
  900. across schools</em>. For example, if you have separate schools for 'School of Business' and 'School of Nursing' at the same institution, then
  901. a course like ENGL 101 might be used by degrees in both schools. So, ENGL 101 would be placed in the Default school.
  902. <br>
  903. If you are unsure what to select, choose 'Yes'."),
  904. );
  905. $form["submit"] = array(
  906. "type" => "submit",
  907. "value" => t("Submit"),
  908. );
  909. return $form;
  910. } // administer_schools_form
  911. function schools_administer_schools_form_submit($form, $form_state) {
  912. $values = $form_state["values"];
  913. variable_set("schools_allow_courses_from_default_school", $values["schools_allow_courses_from_default_school"]);
  914. fp_add_message(t("Settings saved successfully."));
  915. if (trim($values["new_school"]) != "") {
  916. $new_school = trim($values["new_school"]);
  917. if (!strstr($new_school, "~")) {
  918. form_error("new_school", t("Sorry, but the format you entered was not correct. Plase enter a unique 1 to 5 character code for this school, tilda (~), then the name.
  919. <br> Ex: ULM ~ University of Louisiana Monroe"));
  920. return;
  921. }
  922. $temp = explode("~", $new_school);
  923. $code = trim(strtoupper($temp[0]));
  924. $new_school = trim($temp[1]);
  925. // Clean up any trouble chars
  926. $new_school = preg_replace("/[^a-zA-Z0-9_\-]/", " ", $new_school);
  927. $code = preg_replace("/[^a-zA-Z0-9_]/", "", $code);
  928. if ($code == "" || strlen($code) > 5) {
  929. form_error("new_school", t("Sorry, but the format you entered was not correct. Plase enter a unique 1 to 5 character code for this school, tilda (~), then the name.
  930. <br> Ex: ULM ~ University of Louisiana Monroe"));
  931. return;
  932. }
  933. // Check that code is not already in use.
  934. $temp = schools_get_school_id_from_school_code($code);
  935. if ($temp) {
  936. form_error("new_school", t("Sorry, but the code you specified is already in use."));
  937. return;
  938. }
  939. // Okay, add to the roles table.
  940. db_query("INSERT INTO schools (school_code, name) VALUES (?,?) ", strtoupper($code), $new_school);
  941. fp_add_message(t("The new school has been added successfully."));
  942. }
  943. if (strstr($values["perform_action2"], "del~_~")) {
  944. $temp = explode("~_~", $values["perform_action2"]);
  945. $i = trim($temp[1]);
  946. // Remove this rid from the table.
  947. db_query("DELETE FROM schools WHERE school_id = ? ", $i);
  948. fp_add_message(t("The school has been deleted successfully. All data linking to this school id (%i) still exists.", array("%i" => $i)));
  949. }
  950. if (strstr($values["perform_action2"], "edit~_~")) {
  951. $temp = explode("~_~", $values["perform_action2"]);
  952. $i = trim($temp[1]);
  953. $new_school = trim($temp[2]);
  954. if (!strstr($new_school, "~")) {
  955. form_error("", t("Sorry, but the format you entered was not correct. Plase enter a unique 1 to 5 character code for this school, tilda (~), then the name.
  956. <br> Ex: ULM ~ University of Louisiana Monroexxx"));
  957. return;
  958. }
  959. $temp = explode("~", $new_school);
  960. $code = trim(strtoupper($temp[0]));
  961. $new_school = trim($temp[1]);
  962. $new_school = preg_replace("/[^a-zA-Z0-9_\-]/", " ", $new_school);
  963. $code = preg_replace("/[^a-zA-Z0-9_]/", "", $code);
  964. // Check that code is not already in use
  965. $temp = schools_get_school_id_from_school_code($code);
  966. if ($temp) {
  967. if ($temp != $i) { // meaning, it's not the school we are editing.
  968. form_error("new_school", t("Sorry, but the code you specified is already in use."));
  969. return;
  970. }
  971. }
  972. if ($code == "" || strlen($code) > 5) {
  973. form_error("", t("Sorry, but the format you entered was not correct. Plase enter a unique 1 to 5 character code for this school, tilda (~), then the name.
  974. <br> Ex: ULM ~ University of Louisiana Monroe"));
  975. return;
  976. }
  977. if (trim($new_school) != "") {
  978. // Let's update the table.
  979. db_query("UPDATE schools SET name = ?, school_code = ?
  980. WHERE school_id = ? ", $new_school, strtoupper($code), $i);
  981. fp_add_message(t("The school has been edited successfully."));
  982. }
  983. } // if edit
  984. // Rebuild the menu cache, since other modules have tabs and/other menu items based on schools
  985. menu_rebuild_cache(FALSE);
  986. } // _submit
  987. function schools_get_school_id_from_school_code($code) {
  988. return db_result(db_query("SELECT school_id FROM schools WHERE school_code = ?", strtoupper(trim($code))));
  989. }
  990. function schools_get_school_id_for_user($user_id) {
  991. return db_result(db_query("SELECT school_id FROM users WHERE user_id = ?", array($user_id)));
  992. }
  993. // Return an array of school_ids to their names
  994. function schools_get_school_definitions($bool_return_db_rows = FALSE) {
  995. $rtn = array();
  996. $rtn[0] = t("Default");
  997. if ($bool_return_db_rows) {
  998. $rtn[0] = array(
  999. 'school_id' => 0,
  1000. 'school_code' => '',
  1001. 'name' => t('Default'),
  1002. );
  1003. }
  1004. $res = db_query("SELECT * FROM schools ORDER BY school_id");
  1005. while ($cur = db_fetch_array($res)) {
  1006. $key = intval($cur["school_id"]);
  1007. $value = $cur["name"];
  1008. $rtn[$key] = $value;
  1009. if ($bool_return_db_rows) {
  1010. $rtn[$key] = $cur;
  1011. }
  1012. }
  1013. return $rtn;
  1014. }
  1015. function schools_perm() {
  1016. $rtn = array();
  1017. $rtn['administer_schools'] = array('title' => 'Administer schools module', 'description' => 'Only give to admin role.');
  1018. // Add in permissions per school.
  1019. $defs = schools_get_school_definitions();
  1020. $types = array('degree', 'group', 'course');
  1021. foreach ($types as $type) {
  1022. foreach ($defs as $school_id => $school_desc) {
  1023. $rtn['administer_' . $school_id . '_' . $type . '_data'] = array('title' => t('Administer %school_desc @type data', array('%school_desc' => $school_desc, '@type' => $type)),
  1024. 'description' => t('The user is allowed to edit @type data for %school_desc.
  1025. Note: The user MUST also be given the Edit Data Entry permission under Admin module.',
  1026. array('%school_desc' => $school_desc, '@type' => $type)));
  1027. $rtn['manage_' . $school_id . '_user_data'] = array('title' => t('Administer %school_desc users', array('%school_desc' => $school_desc)),
  1028. 'description' => t('The user is allowed to edit and create users for %school_desc.
  1029. Note: the user MUST also be given the Manage users permission under the User module.
  1030. ',array('%school_desc' => $school_desc, '@type' => $type)));
  1031. $rtn['search_students_' . $school_id] = array('title' => t('Search for students in %school_desc', array('%school_desc' => $school_desc)),
  1032. 'description' => t('The user is allowed to search for students belonging to %school_desc.
  1033. Note: To advise, the user will need additional permissions.',
  1034. array('%school_desc' => $school_desc)));
  1035. }
  1036. }
  1037. return $rtn;
  1038. }

Functions