blank_degrees.module

  1. 7.x modules/blank_degrees/blank_degrees.module
  2. 6.x modules/blank_degrees/blank_degrees.module
  3. 4.x modules/blank_degrees/blank_degrees.module
  4. 5.x modules/blank_degrees/blank_degrees.module

File

modules/blank_degrees/blank_degrees.module
View source
  1. <?php
  2. /**
  3. * Implementation of hook_menu
  4. */
  5. function blank_degrees_menu() {
  6. $items = array();
  7. $items["tools/blank-degrees"] = array(
  8. "title" => "Blank Degree Search",
  9. "description" => "Browse through available degree plans as they appear in " . variable_get("system_name", "FlightPath"),
  10. "page_callback" => "fp_render_form",
  11. "page_arguments" => array("blank_degrees_select_degree_form"),
  12. "access_arguments" => array('access_blank_degrees'),
  13. "page_settings" => array(
  14. "page_hide_report_error" => TRUE,
  15. "target" => "_blank",
  16. ),
  17. "type" => MENU_TYPE_NORMAL_ITEM,
  18. "weight" => 10,
  19. );
  20. $items["blank-degrees/display"] = array(
  21. "title" => "Blank Degrees - Display",
  22. "page_callback" => "blank_degrees_display_blank_degree",
  23. "access_arguments" => array('access_blank_degrees'),
  24. "page_settings" => array(
  25. "display_currently_advising" => TRUE,
  26. "page_hide_report_error" => TRUE,
  27. "page_show_title" => TRUE,
  28. "menu_links" => array(
  29. 0 => array(
  30. "text" => "Degrees",
  31. "path" => "tools/blank-degrees",
  32. "query" => "blank_catalog_year=%BLANK_CATALOG_YEAR%&school_id=%SCHOOL_ID%",
  33. ),
  34. ),
  35. ),
  36. "tab_family" => "blank_degrees",
  37. "type" => MENU_TYPE_TAB,
  38. );
  39. return $items;
  40. }
  41. /**
  42. * This is an implementation of hook_menu_handle_replacement_pattern.
  43. * It will search for and replace replacement patterns which we are aware of it in $str.
  44. */
  45. function blank_degrees_menu_handle_replacement_pattern($str) {
  46. if (strpos($str, "%BLANK_CATALOG_YEAR%") !== 0) {
  47. // It contains this replacement pattern!
  48. $bcy = (string) @$_REQUEST["blank_catalog_year"];
  49. $str = str_replace("%BLANK_CATALOG_YEAR%", $bcy, $str);
  50. }
  51. $school_id = 0;
  52. if (isset($_REQUEST['school_id'])) {
  53. $school_id = intval($_REQUEST['school_id']);
  54. }
  55. if (strpos($str, "%SCHOOL_ID%") !== 0) {
  56. // It contains this replacement pattern!
  57. $str = str_replace("%SCHOOL_ID%", $school_id, $str);
  58. }
  59. return $str;
  60. }
  61. /**
  62. * Implements hook_prereqs_get_prereq_warnings_for_course
  63. *
  64. * For a blank degree, we don't want to worry about any warnings.
  65. */
  66. function blank_degrees_prereqs_get_prereq_warnings_for_course(&$rtn, $course, $student) {
  67. if (isset($_REQUEST['blank_degree_id']) && $_REQUEST['blank_degree_id'] != '') {
  68. // We are on a blank degree, so remove any prereq warnings.
  69. $rtn = array();
  70. }
  71. }
  72. function blank_degrees_display_blank_degree() {
  73. global $screen, $student, $fp;
  74. $blank_degree_id = $_REQUEST["blank_degree_id"];
  75. $blank_catalog_year = $_REQUEST["blank_catalog_year"];
  76. $school_id = 0;
  77. if (isset($_REQUEST['school_id'])) {
  78. $school_id = intval($_REQUEST['school_id']);
  79. }
  80. @$blank_print = $_REQUEST["blank_print"];
  81. @$blank_view = $_REQUEST["blank_view"];
  82. // If we used the word "current" for catalog_year, then find out what the current is.
  83. if (strtolower($blank_catalog_year) == "current") {
  84. $blank_catalog_year = variable_get_for_school("current_catalog_year", 2006, $school_id);
  85. }
  86. $blank_degree = NULL;
  87. // If the blank_degree_id begins with "major_code_" then figure out the degree based on major_code.
  88. if (strstr($blank_degree_id, "major_code_")) {
  89. $blank_major_code = str_replace("major_code_", "", $blank_degree_id);
  90. // Okay, figure out the degree id based on the major code and catalog year.
  91. $db = get_global_database_handler();
  92. $blank_degree_id = $db->get_degree_id($blank_major_code, $blank_catalog_year);
  93. if (!$blank_degree_id) {
  94. // Couldn't be found!
  95. $rtn = "<br>" . t("Checking for major code: %blank_major_code, year: %blank_catalog_year
  96. <br><br>
  97. Sorry, but that major code/track combination and catalog year could not be found. Please check your URL and try again.", array('%blank_major_code' => $blank_major_code, '%blank_catalog_year' => $blank_catalog_year));
  98. return $rtn;
  99. }
  100. }
  101. else {
  102. // Find out the major_code for this blank_degree_id...
  103. $blank_degree = new DegreePlan($blank_degree_id, NULL, TRUE);
  104. $blank_major_code = $blank_degree->major_code;
  105. // If there is a track, tack it on.
  106. if ($blank_degree->track_code != "") {
  107. if (!strstr($blank_major_code, "|")) $blank_major_code .= "|";
  108. $blank_major_code .= "_" . $blank_degree->track_code;
  109. }
  110. }
  111. $render = array();
  112. $render['#id'] = 'blank_degrees_display_blank_degree';
  113. $render['#view'] = $blank_view;
  114. // Are we in draft mode?
  115. if ($_SESSION["fp_draft_mode"] == "yes") {
  116. $GLOBALS["fp_advising"]["bool_use_draft"] = true;
  117. }
  118. else {
  119. $GLOBALS["fp_advising"]["bool_use_draft"] = false;
  120. }
  121. fp_add_css(fp_get_module_path("advise") . "/css/advise.css");
  122. fp_add_js(fp_get_module_path("advise") . "/js/advise.js");
  123. $student = new Student();
  124. $student->load_student();
  125. $student->student_id = "000000000";
  126. $student->school_id = $school_id;
  127. $student->name = "Blank Degree";
  128. $degree_plan = new DegreePlan($blank_degree_id);
  129. $degree_plan->load_descriptive_data();
  130. $degree_plan->school_id = $school_id;
  131. $student->catalog_year = $degree_plan->catalog_year;
  132. $fp = new FlightPath($student, $degree_plan);
  133. $screen = new AdvisingScreen("", $fp, "not_advising");
  134. if ($blank_view == "type")
  135. {
  136. $screen = new AdvisingScreenTypeView("", $fp, "not_advising");
  137. $screen->view = "type";
  138. }
  139. $screen->bool_blank = TRUE;
  140. if ($blank_print == "yes")
  141. {
  142. $screen->bool_print = TRUE;
  143. }
  144. $screen->build_screen_elements();
  145. $title = $degree_plan->title;
  146. if ($degree_plan->track_title != "") {
  147. $title .= " - " . $degree_plan->track_title;
  148. }
  149. fp_set_title($title);
  150. $render['#fp'] = $fp;
  151. $render['#degree_plan'] = $blank_degree;
  152. $render['#blank_catalog_year'] = $blank_catalog_year;
  153. $render['#screen'] = $screen;
  154. $render['#student'] = $student;
  155. $render['degree_plan_wrapper_top'] = array(
  156. 'value' => "<div class='degree-plan-wrapper'>",
  157. 'weight' => 100,
  158. );
  159. $render['semester_table_start'] = array(
  160. 'value' => "<table class='fp-semester-table'>",
  161. 'weight' => 200,
  162. );
  163. $render['screen_display_screen'] = array(
  164. 'value' => $screen->display_screen(),
  165. 'weight' => 300,
  166. );
  167. $render['semester_table_end'] = array(
  168. 'value' => "</table>",
  169. 'weight' => 400,
  170. );
  171. $render['degree_plan_wrapper_bottom'] = array(
  172. 'value' => "</div>",
  173. 'weight' => 500,
  174. );
  175. if (user_has_permission("blank_degrees_view_url_options") && !$screen->bool_print) {
  176. // If the user has permissions, show them the extra URL options. (but don't bother in print mode)
  177. $render['url_options_html'] = array(
  178. 'value' => fp_render_c_fieldset("
  179. <div style='font-size: 0.85em;'>
  180. " . t("This degree may be linked to directly using the following URLs:") . "
  181. <ul>
  182. <li>Internal ID for $blank_catalog_year: <a href='" . $GLOBALS["fp_system_settings"]["base_url"] . "/" . fp_url("blank-degrees/display", "blank_degree_id=$blank_degree_id&blank_catalog_year=$blank_catalog_year&school_id=$school_id", FALSE) . "'>Link</a></li>
  183. <li>Major-code $blank_major_code for $blank_catalog_year: <a href='" . $GLOBALS["fp_system_settings"]["base_url"] . "/" . fp_url("blank-degrees/display", "blank_degree_id=major_code_$blank_major_code&blank_catalog_year=$blank_catalog_year&school_id=$school_id", FALSE) . "'>Link</a></li>
  184. <li>Major-code $blank_major_code always <b>current</b> catalog: <a href='" . $GLOBALS["fp_system_settings"]["base_url"] . "/" . fp_url("blank-degrees/display", "blank_degree_id=major_code_$blank_major_code&blank_catalog_year=current&school_id=$school_id", FALSE) . "'>Link</a></li>
  185. </ul>
  186. </div>
  187. ", t("View URL Options"), TRUE, 'view-url-options-fs'),
  188. 'weight' => 2000,
  189. );
  190. }
  191. // Add in the required "advising variables"
  192. //$rtn .= $screen->get_hidden_advising_variables("save_draft");
  193. // Figure out what the page's sub-tabs should be, and set them.
  194. $tab_array = array();
  195. $tab_array[0]["title"] = "Display by Year";
  196. $tab_array[0]["active"] = ($screen->view != "type");
  197. $tab_array[0]["on_click"] = "window.location=\"" . fp_url("blank-degrees/display", "blank_degree_id=$blank_degree_id&blank_catalog_year=$blank_catalog_year&blank_view=year&school_id=$school_id") . "\";";
  198. $tab_array[1]["title"] = "Display by Type";
  199. $tab_array[1]["active"] = ($screen->view == "type");
  200. $tab_array[1]["on_click"] = "window.location=\"" . fp_url("blank-degrees/display", "blank_degree_id=$blank_degree_id&blank_catalog_year=$blank_catalog_year&blank_view=type&school_id=$school_id") . "\";";
  201. fp_set_page_sub_tabs($tab_array);
  202. watchdog("blank_degrees", "User viewed blank degree: @year,@degree,@title", array("@year" => $blank_catalog_year, "@degree" => $blank_degree_id, "@title" => $title));
  203. return fp_render_content($render);
  204. }
  205. function blank_degrees_perm() {
  206. return array(
  207. 'access_blank_degrees' => array(
  208. 'title' => t('Access blank degrees'),
  209. 'description' => t('This permission allows the user to view the blank degrees.'),
  210. ),
  211. "blank_degrees_view_url_options" => array(
  212. "title" => t("View URL options"),
  213. "description" => t("View URL options at the bottom of blank degrees. Useful if you allow anonymous users to access blank degrees."),
  214. ));
  215. }
  216. function blank_degrees_select_school_form() {
  217. $form = array();
  218. $options = schools_get_schools_for_fapi(TRUE, FALSE); // we don't need special permissions to view.
  219. $form['school_id'] = array(
  220. 'type' => 'select',
  221. 'label' => t('Please begin by selecting a school:'),
  222. 'options' => $options,
  223. 'value' => @$_REQUEST['school_id'],
  224. 'hide_please_select' => TRUE,
  225. 'required' => TRUE,
  226. );
  227. $form['from_select_school'] = array(
  228. 'type' => 'hidden',
  229. 'value' => 'yes',
  230. );
  231. $form['submit_btn'] = array(
  232. 'type' => 'submit',
  233. 'value' => t("Continue"),
  234. );
  235. return $form;
  236. }
  237. /**
  238. * This form lets the user select which degree they wish to view.
  239. */
  240. function blank_degrees_select_degree_form() {
  241. $form = array();
  242. $m = 0;
  243. $bool_show_continue = TRUE;
  244. // Are we in draft mode?
  245. if ($_SESSION["fp_draft_mode"] == "yes") {
  246. $GLOBALS["fp_advising"]["bool_use_draft"] = true;
  247. }
  248. else {
  249. $GLOBALS["fp_advising"]["bool_use_draft"] = false;
  250. }
  251. $school_id = 0;
  252. if (module_enabled("schools")) { // The schools module is enabled. We need to first ask what school we want to look at.
  253. if (!isset($_REQUEST['school_id'])) {
  254. $form = blank_degrees_select_school_form();
  255. return $form;
  256. } // not isset school_id
  257. $school_id = intval($_REQUEST['school_id']);
  258. $form['mark_current_school'] = array(
  259. 'value' => "<div class='current-school'>" . t("Current school: ") . "<strong>" . schools_get_school_name_for_id($school_id) . "</strong>
  260. - " . l(t("Change?"), "tools/blank-degrees") . "</div>",
  261. );
  262. }
  263. $form['school_id'] = array(
  264. 'type' => 'hidden',
  265. 'value' => $school_id,
  266. );
  267. $blank_catalog_year = (string) @$_REQUEST["blank_catalog_year"];
  268. // If we used the word "current" for catalog_year, then find out what the current is.
  269. if (strtolower($blank_catalog_year) == "current") {
  270. $blank_catalog_year = variable_get_for_school("current_catalog_year", 2006, $school_id);
  271. }
  272. if ($blank_catalog_year == "") {
  273. // The user must first select the desired catalog year.
  274. $catalog_year_options = array();
  275. $current_catalog_year = variable_get_for_school("current_catalog_year", 2006, $school_id);
  276. if ($GLOBALS["fp_advising"]["bool_use_draft"]) {
  277. $current_catalog_year = variable_get_for_school("current_draft_catalog_year", 2006, $school_id);
  278. }
  279. $earliest_catalog_year = variable_get_for_school("earliest_catalog_year", 2006, $school_id);
  280. for($t = $current_catalog_year; $t >= $earliest_catalog_year; $t--) {
  281. $catalog_year_options[$t] = "$t-" . ($t+1);
  282. }
  283. $form["blank_catalog_year"] = array(
  284. "type" => "select",
  285. "label" => t("Please select a catalog year:"),
  286. "hide_please_select" => TRUE,
  287. "options" => $catalog_year_options,
  288. "weight" => 10,
  289. );
  290. }
  291. else {
  292. // Catalog year WAS specified. So, ask the user to select a degree now.
  293. $form["blank_catalog_year"] = array(
  294. "type" => "hidden",
  295. "value" => $blank_catalog_year,
  296. );
  297. $form["mark_searching_in_year"] = array(
  298. "value" => "<div class='search-degrees-in-catalog-year'>" . t("Searching degrees in %year.", array("%year" => $blank_catalog_year . "-" . ($blank_catalog_year+1))) . "
  299. " . l(t("Change?"), "tools/blank-degrees", "school_id=$school_id") . "</div>",
  300. "weight" => 0,
  301. );
  302. $school_id = 0;
  303. if (isset($_REQUEST['school_id'])) {
  304. $school_id = intval($_REQUEST['school_id']);
  305. }
  306. $mobile_markup = "";
  307. $degree_options = array();
  308. $db = get_global_database_handler();
  309. if ($degree_array = $db->get_degrees_in_catalog_year($blank_catalog_year, TRUE, $GLOBALS["fp_advising"]["bool_use_draft"], FALSE, array(1,2), $school_id)) {
  310. foreach($degree_array as $major_code => $value) {
  311. if (trim($value["title"]) == ""){continue;}
  312. $degree_id = $value["degree_id"];
  313. $title = $value["title"];
  314. if ($value["degree_class"] == "G") {
  315. $title = "(" . t("Graduate") . ") " . $title;
  316. }
  317. // if title is too long, shorten it.
  318. $maxlen = 95;
  319. if (strlen($title) > $maxlen) {
  320. $title = substr($title, 0, $maxlen - 3) . "...";
  321. }
  322. $degree_options[$degree_id] = $title;
  323. $mobile_markup .= "<a class='degree-search-degree-row'
  324. href='" . fp_url("blank-degrees/display", "blank_degree_id=$degree_id&blank_catalog_year={$_REQUEST["blank_catalog_year"]}") . "'>
  325. <div class='degree-search-degree-title'>$title</div>
  326. </a>";
  327. }
  328. }
  329. $form["blank_degree_id"] = array(
  330. "label" => t("Please select a degree"),
  331. "type" => "select",
  332. "options" => $degree_options,
  333. "weight" => 50,
  334. );
  335. }
  336. if ($bool_show_continue) {
  337. $form["submit"] = array(
  338. "type" => "submit",
  339. "prefix" => "",
  340. "value" => t("Continue"),
  341. "weight" => 100,
  342. );
  343. }
  344. return $form;
  345. }
  346. /**
  347. * Submit handler for degree selection
  348. */
  349. function blank_degrees_select_degree_form_submit($form, $form_state) {
  350. // Are we first selecting a school?
  351. if (isset($form_state['POST']['from_select_school']) && $form_state['POST']['from_select_school'] == 'yes') {
  352. fp_goto('tools/blank-degrees', 'school_id=' . intval($form_state['POST']['school_id']));
  353. return;
  354. }
  355. $school_id = intval($form_state['values']['school_id']);
  356. // If all the user did was select catalog year, we need to redirect
  357. // back to the form with blank_catalog_year set.
  358. if ($form_state["values"]["blank_degree_id"] == "" && $form_state["values"]["blank_catalog_year"] != "") {
  359. // Go to degree selection.
  360. fp_goto("tools/blank-degrees", "blank_catalog_year=" . $form_state["values"]["blank_catalog_year"] . "&school_id=$school_id");
  361. return;
  362. }
  363. else if ($form_state["values"]["blank_degree_id"] != "" && $form_state["values"]["blank_catalog_year"] != ""){
  364. // Send them to the blank degree page
  365. fp_goto("blank-degrees/display", "blank_degree_id=" . $form_state["values"]["blank_degree_id"] . "&blank_catalog_year=" . $form_state["values"]["blank_catalog_year"] . "&school_id=$school_id");
  366. return;
  367. }
  368. }

Functions

Namesort descending Description
blank_degrees_display_blank_degree
blank_degrees_menu Implementation of hook_menu
blank_degrees_menu_handle_replacement_pattern This is an implementation of hook_menu_handle_replacement_pattern. It will search for and replace replacement patterns which we are aware of it in $str.
blank_degrees_perm
blank_degrees_prereqs_get_prereq_warnings_for_course Implements hook_prereqs_get_prereq_warnings_for_course
blank_degrees_select_degree_form This form lets the user select which degree they wish to view.
blank_degrees_select_degree_form_submit Submit handler for degree selection
blank_degrees_select_school_form