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_has_search" => FALSE,
  15. "page_banner_is_link" => TRUE,
  16. "page_hide_report_error" => TRUE,
  17. "target" => "_blank",
  18. "menu_icon" => fp_theme_location() . "/images/popup.gif",
  19. ),
  20. "type" => MENU_TYPE_NORMAL_ITEM,
  21. "weight" => 10,
  22. );
  23. $items["blank-degrees/display"] = array(
  24. "title" => "Blank Degrees - Display",
  25. "page_callback" => "blank_degrees_display_blank_degree",
  26. "access_arguments" => array('access_blank_degrees'),
  27. "page_settings" => array(
  28. "display_currently_advising" => TRUE,
  29. "page_has_search" => FALSE,
  30. "page_banner_is_link" => TRUE,
  31. "page_hide_report_error" => TRUE,
  32. "page_show_title" => TRUE,
  33. "menu_links" => array(
  34. 0 => array(
  35. "text" => "Change degree",
  36. "path" => "tools/blank-degrees",
  37. "query" => "blank_catalog_year=%BLANK_CATALOG_YEAR%",
  38. ),
  39. ),
  40. ),
  41. "type" => MENU_TYPE_NORMAL_ITEM,
  42. );
  43. return $items;
  44. }
  45. /**
  46. * This is an implementation of hook_menu_handle_replacement_pattern.
  47. * It will search for and replace replacement patterns which we are aware of it in $str.
  48. */
  49. function blank_degrees_menu_handle_replacement_pattern($str) {
  50. if (strpos($str, "%BLANK_CATALOG_YEAR%") !== 0) {
  51. // It contains this replacement pattern!
  52. $str = str_replace("%BLANK_CATALOG_YEAR%", @$_REQUEST["blank_catalog_year"], $str);
  53. }
  54. return $str;
  55. }
  56. /**
  57. * Implements hook_prereqs_get_prereq_warnings_for_course
  58. *
  59. * For a blank degree, we don't want to worry about any warnings.
  60. */
  61. function blank_degrees_prereqs_get_prereq_warnings_for_course(&$rtn, $course, $student) {
  62. if (isset($_REQUEST['blank_degree_id']) && $_REQUEST['blank_degree_id'] != '') {
  63. // We are on a blank degree, so remove any prereq warnings.
  64. $rtn = array();
  65. }
  66. }
  67. function blank_degrees_display_blank_degree() {
  68. global $screen, $student, $fp;
  69. $blank_degree_id = $_REQUEST["blank_degree_id"];
  70. $blank_catalog_year = $_REQUEST["blank_catalog_year"];
  71. @$blank_print = $_REQUEST["blank_print"];
  72. @$blank_view = $_REQUEST["blank_view"];
  73. // If we used the word "current" for catalog_year, then find out what the current is.
  74. if (strtolower($blank_catalog_year) == "current") {
  75. $blank_catalog_year = variable_get("current_catalog_year", 2006);
  76. }
  77. // If the blank_degree_id begins with "major_code_" then figure out the degree based on major_code.
  78. if (strstr($blank_degree_id, "major_code_")) {
  79. $blank_major_code = str_replace("major_code_", "", $blank_degree_id);
  80. // Okay, figure out the degree id based on the major code and catalog year.
  81. $db = get_global_database_handler();
  82. $blank_degree_id = $db->get_degree_id($blank_major_code, $blank_catalog_year);
  83. if (!$blank_degree_id) {
  84. // Couldn't be found!
  85. $rtn = "<br>Checking for major code: $blank_major_code, year: $blank_catalog_year
  86. <br><br>
  87. Sorry, but that major code/track combination and catalog year could not be found. Please check your URL and try again.";
  88. return $rtn;
  89. }
  90. }
  91. else {
  92. // Find out the major_code for this blank_degree_id...
  93. $blank_degree = new DegreePlan($blank_degree_id, NULL, TRUE);
  94. $blank_major_code = $blank_degree->major_code;
  95. // If there is a track, tack it on.
  96. if ($blank_degree->track_code != "") {
  97. if (!strstr($blank_major_code, "|")) $blank_major_code .= "|";
  98. $blank_major_code .= "_" . $blank_degree->track_code;
  99. }
  100. }
  101. $rtn = "";
  102. // Are we in draft mode?
  103. if ($_SESSION["fp_draft_mode"] == "yes") {
  104. $GLOBALS["fp_advising"]["bool_use_draft"] = true;
  105. }
  106. else {
  107. $GLOBALS["fp_advising"]["bool_use_draft"] = false;
  108. }
  109. fp_add_js(fp_get_module_path("advise") . "/js/advise.js");
  110. $student = new Student();
  111. $student->load_student();
  112. $student->student_id = "000000000";
  113. $student->name = "Blank Degree";
  114. $degree_plan = new DegreePlan($blank_degree_id);
  115. $degree_plan->load_descriptive_data();
  116. $student->catalog_year = $degree_plan->catalog_year;
  117. $fp = new FlightPath($student, $degree_plan);
  118. $screen = new AdvisingScreen("", $fp, "not_advising");
  119. if ($blank_view == "type")
  120. {
  121. $screen = new AdvisingScreenTypeView("", $fp, "not_advising");
  122. $screen->view = "type";
  123. }
  124. $screen->bool_blank = true;
  125. if ($blank_print == "yes")
  126. {
  127. $screen->bool_print = true;
  128. }
  129. $screen->build_screen_elements();
  130. $title = $degree_plan->title;
  131. if ($degree_plan->track_title != "") {
  132. $title .= " - " . $degree_plan->track_title;
  133. }
  134. fp_set_title($title);
  135. $rtn .= "<table class='fp-semester-table'>";
  136. $rtn .= $screen->display_screen();
  137. $rtn .= "</table><br><br>";
  138. if (user_has_permission("blank_degrees_view_url_options") && !$screen->bool_print) {
  139. // If the user has permissions, show them the extra URL options. (but don't bother in print mode)
  140. $rtn .= fp_render_c_fieldset("
  141. <div style='font-size: 0.85em;'>
  142. " . t("This degree may be linked to directly using the following URLs:") . "
  143. <ul>
  144. <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", FALSE) . "'>Link</a></li>
  145. <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", FALSE) . "'>Link</a></li>
  146. <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", FALSE) . "'>Link</a></li>
  147. </ul>
  148. </div>
  149. ", t("View URL Options"), TRUE);
  150. }
  151. // Add in the required "advising variables"
  152. //$rtn .= $screen->get_hidden_advising_variables("save_draft");
  153. // Figure out what the page's sub-tabs should be, and set them.
  154. $tab_array = array();
  155. $tab_array[0]["title"] = "Display by Year";
  156. $tab_array[0]["active"] = ($screen->view != "type");
  157. $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") . "\";";
  158. $tab_array[1]["title"] = "Display by Type";
  159. $tab_array[1]["active"] = ($screen->view == "type");
  160. $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") . "\";";
  161. if (!fp_screen_is_mobile()) {
  162. $tab_array[2]["title"] = "Print";
  163. $tab_array[2]["type"] = "link";
  164. $tab_array[2]["active"] = FALSE;
  165. $tab_array[2]["on_click"] = "popupPrintWindow(\"" . fp_url("blank-degrees/display", "blank_degree_id=$blank_degree_id&blank_catalog_year=$blank_catalog_year&blank_view=$blank_view&blank_print=yes") . "\");";
  166. }
  167. fp_set_page_sub_tabs($tab_array);
  168. watchdog("blank_degrees", "User viewed blank degree: @year,@degree,@title", array("@year" => $blank_catalog_year, "@degree" => $blank_degree_id, "@title" => $title), WATCHDOG_DEBUG);
  169. return $rtn;
  170. }
  171. function blank_degrees_perm() {
  172. return array(
  173. 'access_blank_degrees' => array(
  174. 'title' => t('Access blank degrees'),
  175. 'description' => t('This permission allows the user to view the blank degrees.'),
  176. ),
  177. "blank_degrees_view_url_options" => array(
  178. "title" => t("View URL options"),
  179. "description" => t("View URL options at the bottom of blank degrees"),
  180. ));
  181. }
  182. /**
  183. * This form lets the user select which degree they wish to view.
  184. */
  185. function blank_degrees_select_degree_form() {
  186. $form = array();
  187. $m = 0;
  188. $bool_show_continue = TRUE;
  189. // Are we in draft mode?
  190. if ($_SESSION["fp_draft_mode"] == "yes") {
  191. $GLOBALS["fp_advising"]["bool_use_draft"] = true;
  192. }
  193. else {
  194. $GLOBALS["fp_advising"]["bool_use_draft"] = false;
  195. }
  196. if (fp_screen_is_mobile()) {
  197. fp_add_css(fp_get_module_path("blank_degrees") . "/css/mobile.css");
  198. }
  199. @$blank_catalog_year = $_REQUEST["blank_catalog_year"];
  200. // If we used the word "current" for catalog_year, then find out what the current is.
  201. if (strtolower($blank_catalog_year) == "current") {
  202. $blank_catalog_year = variable_get("current_catalog_year", 2006);
  203. }
  204. if ($blank_catalog_year == "") {
  205. // The user must first select the desired catalog year.
  206. $catalog_year_options = array();
  207. $current_catalog_year = variable_get("current_catalog_year", 2006);
  208. if ($GLOBALS["fp_advising"]["bool_use_draft"]) {
  209. $current_catalog_year = variable_get("current_draft_catalog_year", 2006);
  210. }
  211. $earliest_catalog_year = variable_get("earliest_catalog_year", 2006);
  212. for($t = $current_catalog_year; $t >= $earliest_catalog_year; $t--) {
  213. $catalog_year_options[$t] = "$t-" . ($t+1);
  214. }
  215. $form["blank_catalog_year"] = array(
  216. "type" => "select",
  217. "label" => t("Please begin by selecting a catalog year:"),
  218. "options" => $catalog_year_options,
  219. );
  220. }
  221. else {
  222. // Catalog year WAS specified. So, ask the user to select a degree now.
  223. $form["blank_catalog_year"] = array(
  224. "type" => "hidden",
  225. "value" => $blank_catalog_year,
  226. );
  227. $form["mark" . $m++] = array(
  228. "value" => t("Searching degrees in %year.", array("%year" => $blank_catalog_year . "-" . ($blank_catalog_year+1))) . "
  229. " . l(t("Change?"), "tools/blank-degrees"),
  230. );
  231. $mobile_markup = "";
  232. $degree_options = array();
  233. $db = get_global_database_handler();
  234. if ($degree_array = $db->get_degrees_in_catalog_year($blank_catalog_year, true, $GLOBALS["fp_advising"]["bool_use_draft"], FALSE)) {
  235. foreach($degree_array as $major_code => $value) {
  236. if (trim($value["title"]) == ""){continue;}
  237. $degree_id = $value["degree_id"];
  238. $title = $value["title"];
  239. if ($value["degree_class"] == "G") {
  240. $title = "(" . t("Graduate") . ") " . $title;
  241. }
  242. // if title is too long, shorten it.
  243. $maxlen = 95;
  244. if (strlen($title) > $maxlen) {
  245. $title = substr($title, 0, $maxlen - 3) . "...";
  246. }
  247. $degree_options[$degree_id] = $title;
  248. $mobile_markup .= "<a class='degree-search-degree-row'
  249. href='" . fp_url("blank-degrees/display", "blank_degree_id=$degree_id&blank_catalog_year={$_REQUEST["blank_catalog_year"]}") . "'>
  250. <div class='degree-search-degree-title'>$title</div>
  251. </a>";
  252. }
  253. }
  254. if (fp_screen_is_mobile()) {
  255. $form["mark" . $m++] = array(
  256. "value" => $mobile_markup,
  257. );
  258. $bool_show_continue = FALSE;
  259. }
  260. else {
  261. // NOT mobile
  262. $form["blank_degree_id"] = array(
  263. "label" => t("Please select a degree"),
  264. "type" => "select",
  265. "options" => $degree_options,
  266. );
  267. }
  268. }
  269. if ($bool_show_continue) {
  270. $form["submit"] = array(
  271. "type" => "submit",
  272. "prefix" => "<hr>",
  273. "value" => t("Continue") . " -&gt;",
  274. );
  275. }
  276. return $form;
  277. }
  278. /**
  279. * Submit handler for degree selection
  280. */
  281. function blank_degrees_select_degree_form_submit($form, $form_state) {
  282. // If all the user did was select catalog year, we need to redirect
  283. // back to the form with blank_catalog_year set.
  284. if ($form_state["values"]["blank_degree_id"] == "" && $form_state["values"]["blank_catalog_year"] != "") {
  285. // Go to degree selection.
  286. fp_goto("tools/blank-degrees", "blank_catalog_year=" . $form_state["values"]["blank_catalog_year"]);
  287. return;
  288. }
  289. else if ($form_state["values"]["blank_degree_id"] != "" && $form_state["values"]["blank_catalog_year"] != ""){
  290. // Send them to the blank degree page
  291. fp_goto("blank-degrees/display", "blank_degree_id=" . $form_state["values"]["blank_degree_id"] . "&blank_catalog_year=" . $form_state["values"]["blank_catalog_year"]);
  292. return;
  293. }
  294. }

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