admin.degrees.inc

  1. 6.x modules/admin/admin.degrees.inc
  2. 4.x modules/admin/admin.degrees.inc
  3. 5.x modules/admin/admin.degrees.inc

File

modules/admin/admin.degrees.inc
View source
  1. <?php
  2. function admin_display_degrees_popup_add_group() {
  3. $semester_num = trim($_GET["semester_num"]);
  4. $de_catalog_year = admin_get_de_catalog_year();
  5. fp_add_js(fp_get_module_path("admin") . "/js/admin.js");
  6. $rtn = "";
  7. $rtn .= "<b>" . t("Add an elective group to semester: @semester_num in @de_catalog_year", array("@semester_num" => $semester_num, "@de_catalog_year" => $de_catalog_year)) . "</b><br>
  8. <span class='tenpt'>" . t("Use keyboard shortcut CTRL-F to find groups quickly.") . "</span>
  9. <br><br>
  10. First, select a group (from $de_catalog_year):
  11. <div class='tenpt'
  12. style='height:200px; overflow-y: scroll; border: 1px solid black;
  13. margin:5px;'>
  14. <table border='0' cellspacing='5'>";
  15. $res = db_query("SELECT * FROM draft_groups
  16. WHERE catalog_year = '?'
  17. AND delete_flag = '0'
  18. ORDER BY title ", $de_catalog_year);
  19. while($cur = db_fetch_array($res)) {
  20. extract($cur, 3, "db");
  21. $rtn .= "<tr><td valign='middle'>
  22. <input type='radio' name='rgroups' value='$db_group_id'></td>
  23. <td valign='top' class='tenpt'>
  24. $db_title<br><i>$db_group_name</i>
  25. </td>
  26. </tr>
  27. ";
  28. }
  29. $rtn .= "</table></div>
  30. " . t("Next, select properties for this group:") . "
  31. <a href='javascript: popupAlertHelp(\"group_properties\");'>?</a>
  32. <div class='tenpt' style='padding-top: 5px;'>
  33. Hrs: <input type='text' name='hours' id='hours' size='2'>
  34. Min Grade: <select name='min_grade' id='min_grade'>
  35. <option value=''>--</option>
  36. <option value='C'>C</option>
  37. <option value='B'>B</option>
  38. <option value='A'>A</option>
  39. </select>
  40. Type: <select name='type' id='type'>
  41. <option value='m'>m - Major</option>
  42. <option value='c'>c - Core</option>
  43. <option value='s'>s - Supporting</option>
  44. <option value='e'>e - Elective</option>
  45. </select>
  46. &nbsp; &nbsp;
  47. " . fp_render_button("Add group &raquo;", "adminPopupAddGroup(\"$semester_num\");") . "
  48. </div>";
  49. return $rtn;
  50. }
  51. /**
  52. * This form lets the user copy a degree and all of it's tracks & concentrations.
  53. */
  54. function admin_copy_degree_form() {
  55. $de_catalog_year = admin_get_de_catalog_year();
  56. fp_set_title(t("Copy Degree for") . " $de_catalog_year");
  57. $form = array();
  58. $form["mark" . $m++] = array(
  59. "type" => "markup",
  60. "value" => t("Use this form to duplicate a degree plan in this catalog year.
  61. <b>IMPORTANT:</b> If you specify a destination major code which
  62. already exists, <b>all of its tracks and concentrations</b> will be
  63. deleted for @year!", array("@year" => $de_catalog_year)),
  64. );
  65. $form["de_catalog_year"] = array(
  66. "type" => "hidden",
  67. "value" => $de_catalog_year,
  68. );
  69. $form["source_major_code"] = array(
  70. "type" => "textfield",
  71. "size" => 15,
  72. "label" => t("Enter the SOURCE major code you wish to copy:"),
  73. "required" => TRUE,
  74. "description" => t("Ex: ART or GBUS. Do not enter any track or concentration codes here."),
  75. );
  76. $form["include_tracks"] = array(
  77. "type" => "checkboxes",
  78. "label" => t("Include tracks and concentrations?"),
  79. "options" => array("yes" => "Include tracks and concentrations."),
  80. "description" => t("Check this box if you wish to also copy any tracks and concentrations
  81. this major code may have associated with it. If you do not check this box,
  82. only the base degree will be copied. If the major does not have
  83. tracks and concentrations, leave this unchecked."),
  84. );
  85. $form["destination_major_code"] = array(
  86. "type" => "textfield",
  87. "size" => 15,
  88. "label" => t("Enter the DESTINATION major code you wish to create/overwrite:"),
  89. "required" => TRUE,
  90. "description" => t("Ex: CHEM or XYZ. Do not enter any track or concentration codes here. If the destination
  91. major already exists, it and <b>all of its tracks and concentrations</b> will be
  92. deleted for this catalog year!"),
  93. );
  94. // Our submit button.
  95. $form["submit"] = array(
  96. "type" => "submit",
  97. "value" => "Submit",
  98. "prefix" => "<hr>",
  99. );
  100. return $form;
  101. }
  102. function admin_copy_degree_form_submit($form, $form_submit) {
  103. //fpm($form_submit);
  104. global $db;
  105. $values = $form_submit["values"];
  106. $de_catalog_year = $values["de_catalog_year"];
  107. $source_major_code = trim(strtoupper($values["source_major_code"]));
  108. $destination_major_code = trim(strtoupper($values["destination_major_code"]));
  109. $include_tracks = $values["include_tracks"]["yes"];
  110. // First thing's first. Make sure the sourceMajorCode exists.
  111. $res = db_query("SELECT * FROM draft_degrees
  112. WHERE (major_code = '?'
  113. OR major_code LIKE '?|%')
  114. AND catalog_year='?' ", $source_major_code, $source_major_code, $de_catalog_year) ;
  115. if (db_num_rows($res) == 0) {
  116. // Meaning, it could not be found.
  117. form_error("source_major_code", t("The source major, %source, could not be found for %year", array("%source" => $source_major_code, "%year" => $de_catalog_year)));
  118. return;
  119. }
  120. // Alright, if we got to here, we can proceed. We need to
  121. // delete everything involving the destination major.
  122. // First, get the degree_id's in a select...
  123. $res = db_query("SELECT * FROM draft_degrees
  124. WHERE (major_code = '?'
  125. OR major_code LIKE '?|%')
  126. AND catalog_year='?' ", $destination_major_code, $destination_major_code, $de_catalog_year) ;
  127. if (db_num_rows($res) > 0) {
  128. while ($cur = db_fetch_array($res)) {
  129. $degree_id = $cur["degree_id"];
  130. $res2 = db_query("DELETE FROM draft_degree_requirements
  131. WHERE degree_id='?' ", $degree_id) ;
  132. $res2 = db_query("DELETE FROM draft_degrees
  133. WHERE degree_id = '?' ", $degree_id) ;
  134. }
  135. // Now, delete the tracks.
  136. $res2 = db_query("DELETE FROM draft_degree_tracks
  137. WHERE major_code = '?'
  138. AND catalog_year='?' ", $destination_major_code, $de_catalog_year) ;
  139. }
  140. // Okay, with the destination major good and deleted, we can proceed with
  141. // the copy.
  142. // Let's build up an array of all the degrees we will be copying.
  143. $source_array = array();
  144. // First, the base degree...
  145. $res = db_query("SELECT * FROM draft_degrees
  146. WHERE major_code = '?'
  147. AND catalog_year='?' ", $source_major_code, $de_catalog_year) ;
  148. $cur = db_fetch_array($res);
  149. $source_array[] = $cur;
  150. // Now, any tracks or concentrations?
  151. if ($include_tracks == "yes") {
  152. $res = db_query("SELECT * FROM draft_degrees
  153. WHERE major_code LIKE '?|%'
  154. AND catalog_year='?' ", $source_major_code, $de_catalog_year) ;
  155. while ($cur = db_fetch_array($res)) {
  156. $source_array[] = $cur;
  157. }
  158. // While we're here, let's go ahead and make a copy of the tracks.
  159. $res = db_query("SELECT * FROM draft_degree_tracks
  160. WHERE (major_code = '?'
  161. OR major_code LIKE '?|%' )
  162. AND catalog_year='?' ", $source_major_code, $source_major_code, $de_catalog_year) ;
  163. while($cur = db_fetch_array($res)) {
  164. extract($cur, 3, "db");
  165. $dest_code = $destination_major_code;
  166. if (strstr($db_major_code, "|")) {
  167. // We need to adjust the destCode to match
  168. //the source.
  169. $dest_code = str_replace("$source_major_code|", "$destination_major_code|", $db_major_code);
  170. }
  171. $res2 = db_query("INSERT INTO draft_degree_tracks
  172. (catalog_year, major_code, track_code,
  173. track_title, track_short_title, track_description)
  174. VALUES
  175. ('?', '?', '?', '?', '?', '?') ",
  176. $de_catalog_year, $dest_code, $db_track_code,
  177. $db_track_title, $db_track_short_title,
  178. $db_track_description) ;
  179. }
  180. }
  181. $db = get_global_database_handler();
  182. //var_dump($source_array);
  183. // Okay, now it's time to go through the sourceArray
  184. // and duplicate them.
  185. foreach ($source_array as $src) {
  186. extract($src, 3, "src");
  187. $dest_code = $destination_major_code;
  188. if (strstr($src_major_code, "|")) {
  189. // We need to adjust the destCode to match
  190. //the source.
  191. $dest_code = str_replace("$source_major_code|", "$destination_major_code|", $src_major_code);
  192. }
  193. //var_dump($dest_code);
  194. $dest_degree_id = $db->request_new_degree_id();
  195. // Create the entry in the degrees table.
  196. $res = db_query("INSERT INTO draft_degrees
  197. (degree_id, major_code, degree_type, degree_class, title,
  198. public_note, semester_titles_csv,
  199. catalog_year, exclude)
  200. VALUES
  201. ('?', '?', '?', '?', '?', '?', '?', '?', '?') ",
  202. $dest_degree_id, $dest_code, $src_degree_type, $src_degree_class, $src_title,
  203. $src_public_note, $src_semester_titles_csv,
  204. $de_catalog_year, $src_exclude);
  205. // Now, go through the source's degree requirements and copy those over.
  206. $res = db_query("SELECT * FROM draft_degree_requirements
  207. WHERE degree_id = '$src_degree_id' ");
  208. while ($cur = db_fetch_array($res)) {
  209. extract($cur, 3, "db");
  210. $res2 = $db->db_query("INSERT INTO draft_degree_requirements
  211. (degree_id, semester_num, group_id,
  212. group_requirement_type,
  213. group_hours_required,
  214. group_min_grade, course_id,
  215. course_min_grade,
  216. course_requirement_type,
  217. data_entry_value)
  218. VALUES
  219. ('?', '?', '?', '?', '?',
  220. '?', '?',
  221. '?',
  222. '?',
  223. '?') ",
  224. $dest_degree_id, $db_semester_num, $db_group_id,
  225. $db_group_requirement_type,
  226. $db_group_hours_required,
  227. $db_group_min_grade, $db_course_id,
  228. $db_course_min_grade,
  229. $db_course_requirement_type,
  230. $db_data_entry_value);
  231. }
  232. }
  233. // Make a - entry into the draft_instruction table so it will
  234. // remind the administrator to apply draft changes.
  235. $res = db_query("INSERT INTO draft_instructions
  236. (instruction) VALUES ('-') ");
  237. fp_add_message(t("Degree %source has been copied to %dest for %year",
  238. array("%source" => $source_major_code, "%dest" => $destination_major_code, "%year" => $de_catalog_year)));
  239. }
  240. /**
  241. * This form lets the user add a degree to the database.
  242. */
  243. function admin_add_degree_form() {
  244. $de_catalog_year = admin_get_de_catalog_year();
  245. fp_set_title(t("Add Degree for") . " " . $de_catalog_year);
  246. $form = array();
  247. $form["markup" . $m++] = array(
  248. "type" => "markup",
  249. "value" => t("You may use this screen to add a new degree,
  250. by entering a new major, concentration, or track (degree option)"),
  251. );
  252. $form["de_catalog_year"] = array(
  253. "type" => "hidden",
  254. "value" => $de_catalog_year,
  255. );
  256. $form["new_major"] = array(
  257. "type" => "radios",
  258. "label" => t("Please select: are you entering a new major code [and concentration]
  259. or an existing major code [and concentration] (so you can add a new track)?"),
  260. "options" => array(
  261. "new" => t("Entering a <b>new</b> major code [and concentration]"),
  262. "existing" => t("Entering an <b>existing</b> major code [and concentration] (only adding a new track)"),
  263. ),
  264. "required" => TRUE,
  265. );
  266. $form["major_code"] = array(
  267. "type" => "textfield",
  268. "size" => 15,
  269. "label" => t("Major|Conc code:"),
  270. "description" => t("To enter a concentration code, use MAJOR|CONC.
  271. The | character is call the pipe, and it should under the backspace key.
  272. If adding a new concentration to an existing major, you still put this in as a
  273. NEW major code. Do not have any spaces in this box. The concentration code
  274. is optional. If the major does not have a concentration,
  275. then simply enter the major code by itself."),
  276. "required" => TRUE,
  277. );
  278. $form["new_track"] = array(
  279. "type" => "radios",
  280. "label" => t("Please select: are you entering a new track code?"),
  281. "options" => array(
  282. "new" => t("Entering a <b>new</b> track code"),
  283. "none" => t("None - Not adding a track. Leave blank"),
  284. ),
  285. "required" => TRUE,
  286. );
  287. $form["track_code"] = array(
  288. "type" => "textfield",
  289. "size" => 15,
  290. "label" => t("Track code:"),
  291. "description" => t("Leave blank if you selected None above."),
  292. );
  293. // Our submit button.
  294. $form["submit"] = array(
  295. "type" => "submit",
  296. "value" => "Submit",
  297. "prefix" => "<hr>",
  298. );
  299. return $form;
  300. }
  301. /**
  302. * Submit handler for the add_degree_form.
  303. */
  304. function admin_add_degree_form_submit($form, $form_submit) {
  305. $values = $form_submit["values"];
  306. $de_catalog_year = $values["de_catalog_year"];
  307. // This will be used to add a new degree (and possibly track)
  308. // to the database.
  309. $major_code = trim(strtoupper($values["major_code"]));
  310. $track_code = trim(strtoupper($values["track_code"]));
  311. $new_major = $values["new_major"];
  312. $new_track = $values["new_track"];
  313. //////////////////////////////////////////////
  314. if ($new_track == "new" && $track_code == "") {
  315. form_error("track_code", t("You selected to add a track, but did not specify a track code."));
  316. }
  317. // Make sure user did not enter an underscore (_) in either
  318. // the track or major code!
  319. if (strstr($track_code, "_") || strstr($major_code, "_")) {
  320. form_error("major_code", t("You are not allowed to enter underscores (_) in either the track code
  321. or major code. FlightPath will add that for you. Please re-enter
  322. your new degree without using an underscore."));
  323. }
  324. // Return since we have errors all ready.
  325. if (form_has_errors()) {
  326. return;
  327. }
  328. ////////////////////////////////////////////////////
  329. // First, deal with the major/concentration.
  330. // Firstly, check to see if it already exists...
  331. $res = db_query("SELECT * FROM draft_degrees
  332. WHERE catalog_year = '?'
  333. AND major_code = '?' ", $de_catalog_year, $major_code);
  334. if (db_num_rows($res) > 0 && $new_major == "new") {
  335. // Meaning, it already exists, yet we are trying to add it as a new
  336. // major. This is an error!
  337. fp_add_message(t("The major code %major_code already exists for %year. You cannot add it as a new major.", array("%major_code" => $major_code, "%year" => $de_catalog_year)), "error");
  338. return;
  339. }
  340. if (db_num_rows($res) == 0 && $new_major == "existing") {
  341. // This is another error. We are trying to add a track to an existing
  342. // major code, but none was found.
  343. fp_add_message(t("The major code %major_code could not be found in the system for %year. Perhaps you need to add it first?", array("%major_code" => $major_code, "%year" => $de_catalog_year)), "error");
  344. return;
  345. }
  346. if (db_num_rows($res) == 0 && $new_major == "new") {
  347. // This means we are trying to add a new major to the degrees table.
  348. // We may proceed with this.
  349. $db2 = new DatabaseHandler();
  350. $degree_id = $db2->request_new_degree_id();
  351. $db2->db_query("INSERT INTO draft_degrees
  352. (degree_id, major_code, catalog_year)
  353. values ('?', '?', '?') ", $degree_id, $major_code, $de_catalog_year);
  354. }
  355. if ($new_track == "new") {
  356. //////////////////////////////////////////////////
  357. // Now, let's see about adding ourself a track...
  358. // First, check to see if it exists...
  359. $res = db_query("SELECT * FROM draft_degree_tracks
  360. WHERE catalog_year = '?'
  361. AND major_code = '?'
  362. AND track_code = '?' ", $de_catalog_year, $major_code, $track_code);
  363. if (db_num_rows($res) > 0) {
  364. // Meaning, it already existed, so we can't create it.
  365. fp_add_message(t("The major and track code %major_code already exists for %year. You cannot add it as a new major/track code.", array("%major_code" => "$major_code $track_code", "%year" => $de_catalog_year)), "error");
  366. return;
  367. }
  368. else {
  369. // We can add it to the tracks table...
  370. $db2 = new DatabaseHandler();
  371. $db2->db_query("INSERT INTO draft_degree_tracks
  372. (catalog_year, major_code, track_code)
  373. values ('?', '?', '?') ", $de_catalog_year, $major_code, $track_code);
  374. // Now, we also need to add this major & track code to the degrees table.
  375. $new_major_code = $major_code;
  376. if (strstr($major_code, "|")) {
  377. // Already has a pipe, so it has a concentration.
  378. $new_major_code .= "_$track_code";
  379. }
  380. else {
  381. // No concentration...
  382. $new_major_code .= "|_$track_code";
  383. }
  384. $degree_id = $db2->request_new_degree_id();
  385. $db2->db_query("INSERT INTO draft_degrees
  386. (degree_id, major_code, catalog_year)
  387. values ('?', '?', '?') ", $degree_id, $new_major_code, $de_catalog_year);
  388. }
  389. }
  390. // Success! We are done.
  391. fp_add_message(t("The new degree %major_code was added successfully for %year.
  392. You may add another degree, or use the menu at the top of the page to return to your list
  393. of degrees, so you may begin editing the degree.", array("%major_code" => "$major_code $track_code", "%year" => $de_catalog_year)));
  394. clear_session_form_values("admin_add_degree_form");
  395. }
  396. /*
  397. * This function lists all of our degrees on the screen, for a given year
  398. */
  399. function admin_display_degrees() {
  400. $de_catalog_year = admin_get_de_catalog_year();
  401. $rtn = "";
  402. fp_add_css(fp_get_module_path("admin") . "/css/admin.css");
  403. $rtn .= "<h2 class='title'>" . t("Degrees for @year", array("@year" => $de_catalog_year)) . "</h2>";
  404. $rtn .= "<div class='admin-degrees-upper-links'>";
  405. $rtn .= l("Add new degree plan (major, degree plan, or track)", "admin/degrees/add-degree", "de_catalog_year=$de_catalog_year");
  406. $rtn .= " &nbsp; &nbsp; | &nbsp; &nbsp; ";
  407. $rtn .= l("Copy a degree plan", "admin/degrees/copy-degree", "de_catalog_year=$de_catalog_year");
  408. $rtn .= "</div>";
  409. $rtn .= "<div class='list-degree-row-excluded'>
  410. " . t("Majors or Tracks marked as \"exclude\" are shaded. You may pull up students with these
  411. majors in FlightPath, but they will not be options in the What If mode.") . "
  412. </div>
  413. <br>
  414. <div class='tenpt' align='center'>
  415. " . t("Use CTRL-F to find degrees more quickly.") . "
  416. </div>";
  417. $res = db_query("SELECT * FROM draft_degrees
  418. WHERE catalog_year = '?'
  419. ORDER BY degree_type, major_code, title ", $de_catalog_year);
  420. while($cur = db_fetch_array($res)) {
  421. $db_exclude = 0;
  422. extract($cur, 3, "db");
  423. if ($db_degree_type == "NA" && strstr($db_major, "|")) {
  424. $db_degree_type = " -- ";
  425. }
  426. $extra_class = "";
  427. if ($db_exclude == "1") {
  428. $extra_class = "list-degree-row-excluded";
  429. }
  430. // get JUST the major code...
  431. $temp = explode("|", $db_major_code);
  432. $just_major = trim($temp[0]);
  433. $just_conc = trim($temp[1]);
  434. $outside = "";
  435. //if ($just_conc != "" && strstr($just_conc, "_"))
  436. if (strstr($just_conc, "_")) {
  437. // If the concentration has an underscore, it's actually
  438. // a track. Let's get the track title...
  439. $temp2 = explode("_",$just_conc);
  440. $just_track = trim($temp2[1]);
  441. // Might need to add the first part BACK onto the major...
  442. if (trim($temp2[0]) != "")
  443. {
  444. $just_major .= "|" . trim($temp2[0]);
  445. }
  446. $res2 = db_query("SELECT * FROM draft_degree_tracks
  447. WHERE catalog_year = '?'
  448. AND major_code = '?'
  449. AND track_code = '?' ", $de_catalog_year, $just_major, $just_track);
  450. if (db_num_rows($res2) > 0) {
  451. $cur2 = db_fetch_array($res2);
  452. $db_title = trim($cur2["track_title"]);
  453. $outside = "----&gt;";
  454. if (strstr($just_major, "|")) {
  455. // both a conc AND a track. Denote it special.
  456. $outside = ">>" . $outside;
  457. }
  458. $db_degree_type = "";
  459. }
  460. }
  461. else if($just_conc != "") {
  462. // Meaning, this is a concentration, NOT a track.
  463. $db_degree_type = "";
  464. $outside = "&gt;&gt;";
  465. }
  466. $rtn .= "<div class='admin-degrees-list-degree'>
  467. <a name='degree_$db_degree_id'></a>";
  468. $rtn .= "<div class='list-degree-row $extra_class'>
  469. $outside
  470. " . l("$db_degree_type $db_title $db_major_code", "admin/degrees/edit-degree", "de_catalog_year=$de_catalog_year&major_code=$db_major_code", array("class" => "degree-$db_degree_class")) . "
  471. </div>
  472. </div>";
  473. }
  474. return $rtn;
  475. }
  476. function admin_handle_edit_degree_submit() {
  477. $de_catalog_year = $_REQUEST["de_catalog_year"];
  478. $db = get_global_database_handler();
  479. // This will UPDATE a degree in the system with the courses
  480. // and groups that the user selected.
  481. $perform_action2 = trim($_POST["perform_action2"]);
  482. if (strstr($perform_action2, "delGroup")) {
  483. $temp = explode("_",$perform_action2);
  484. $del_group = new Group();
  485. $del_group->bool_use_draft = true;
  486. $del_group->group_id = $temp[1];
  487. $del_group->assigned_to_semester_num = $temp[2];
  488. }
  489. $major_code = trim($_POST["major_code"]);
  490. if ($major_code == ""){ die("Fatal error: major_code not found.");}
  491. // Since we are making a change to the draft table(s), let's add a row
  492. // to draft instructions.
  493. $db->add_draft_instruction("-");
  494. $degree_id = "";
  495. // First things first, if this degree already exists in this
  496. // catalog year, then we need to delete it first.
  497. if ($degree_id = $db->get_degree_id($major_code, $de_catalog_year, true)) {
  498. $degree = new DegreePlan($degree_id, null, false, false, true);
  499. $degree->load_descriptive_data();
  500. // Delete from degree_requirements WHERE this degree_id exists.
  501. $res = db_query("DELETE FROM draft_degree_requirements
  502. WHERE degree_id = '?' ", $degree_id);
  503. // Are we trying to DELETE this degree? If so, keep deleting!
  504. if ($perform_action2 == "delete_degree") {
  505. $res = db_query("DELETE FROM draft_degrees
  506. WHERE degree_id = '?' ", $degree_id);
  507. // Also need to get rid of the track, if there is one for this
  508. // degree.
  509. $res = db_query("DELETE FROM draft_degree_tracks
  510. WHERE major_code = '$degree->major_code'
  511. AND track_code = '$degree->track_code'
  512. AND catalog_year = '?' LIMIT 1", $de_catalog_year);
  513. // Okay, we have deleted everything. We need to go back to
  514. // just the list of degrees.
  515. //display_edit_degrees("<font color='green'><b>The degree $major_code ($de_catalog_year) has been deleted.</b></font>");
  516. //die;
  517. fp_add_message("The degree $major_code ($de_catalog_year) has been deleted.");
  518. fp_goto("admin/degrees", "de_catalog_year=$de_catalog_year");
  519. return;
  520. }
  521. }
  522. else {
  523. // We need to generate a new degreeID for this major_code and catalog_year,
  524. // because one does not already exist!
  525. if (!$degree_id = $db->request_new_degree_id()) {
  526. die ("Error. Could not create new degreeID.");
  527. }
  528. }
  529. // Save the entire post to the log.
  530. $errors = "";
  531. $semester_titles_c_s_v = "";
  532. $highest_semester_num = 0; // What is the largest semester_num in the system?
  533. // Okay, now get the various courses...
  534. for ($semester_num = 0; $semester_num < 50; $semester_num++)
  535. {
  536. // Assuming no more than 50 semesters.
  537. $courses = trim($_POST["courses_$semester_num"]);
  538. if ($courses == "") {
  539. continue;
  540. }
  541. if ($semester_num > $highest_semester_num) {
  542. $highest_semester_num = $semester_num;
  543. }
  544. $course_rows = explode("\n",$courses);
  545. for ($t = 0; $t < count($course_rows); $t++) {
  546. $line = trim($course_rows[$t]);
  547. if ($line == "") {
  548. continue;
  549. }
  550. // Take out extra whitespace between tokens.
  551. $line = str_replace(" ", " ", $line);
  552. $line = str_replace(" ", " ", $line);
  553. $line = str_replace(" ", " ", $line);
  554. $line = str_replace(" ", " ", $line);
  555. $tokens = explode(" ", $line);
  556. $subject_id = $tokens[0];
  557. $course_num = $tokens[1];
  558. $requirement_type = strtolower($tokens[2]);
  559. if ($requirement_type == "") {
  560. // major type by default.
  561. $requirement_type = "m";
  562. }
  563. $min_grade = strtoupper($tokens[3]);
  564. if (strstr($requirement_type, "(")) {
  565. // This means there was no requirement_type specified, so it's "m",
  566. // and a min_grade was found in its place.
  567. $min_grade = strtoupper($requirement_type);
  568. $requirement_type = "m";
  569. }
  570. $min_grade = str_replace("(","",$min_grade);
  571. $min_grade = str_replace(")","",$min_grade);
  572. /////////////////////////////////////////////
  573. // Okay, we now have enough information to insert the course.
  574. // Find out what the course_id is.
  575. if ($course_id = $db->get_course_id($subject_id, $course_num, "", true)) // don't care about catalog year.
  576. {
  577. $query = "INSERT INTO draft_degree_requirements
  578. (degree_id, semester_num, course_id, course_min_grade, course_requirement_type, data_entry_value)
  579. values ('?','?','?','?','?','?~?') ";
  580. $res = db_query($query, $degree_id, $semester_num, $course_id, $min_grade, $requirement_type, $subject_id, $course_num);
  581. //debug_c_t($query);
  582. } else {
  583. // The course_id could not be found!
  584. $errors .= "<br><font color='red'><b>Course Not Found!</b>
  585. In Block " . ($semester_num+1) . ", you specified the course
  586. <b>$subject_id $course_num</b> as a requirement, but this course
  587. could not be found.
  588. It was removed from that block.
  589. Are you sure you typed it correctly? Please go to this
  590. semester, check your spelling, and add the course again.</font>";
  591. }
  592. }
  593. }
  594. // Get the groups....
  595. foreach($_POST as $key => $value) {
  596. if (!strstr($key, "group_")) {
  597. continue;
  598. }
  599. // Only look at the groups...
  600. $temp = explode("_", $value);
  601. $group_id = $temp[0];
  602. $semester_num = $temp[1];
  603. $hours = $temp[2];
  604. $type = $temp[3];
  605. $min_grade = trim($temp[4]);
  606. if ($semester_num > $highest_semester_num) {
  607. $highest_semester_num = $semester_num;
  608. }
  609. // Do not add if we are supposed to be deleting this group!
  610. if (is_object($del_group)) {
  611. if ($del_group->group_id == $group_id && $del_group->assigned_to_semester_num == $semester_num) {
  612. continue;
  613. }
  614. }
  615. // We now have enough information to insert this group.
  616. //debugCT("group: $group_id $semester_num $hours $type");
  617. $query = "INSERT INTO draft_degree_requirements
  618. (`degree_id`,`semester_num`,`group_id`,
  619. `group_requirement_type`,`group_hours_required`,`group_min_grade`)
  620. values ('?','?','?',
  621. '?','?','?') ";
  622. $res = db_query($query, $degree_id, $semester_num, $group_id, $type, $hours, $min_grade);
  623. }
  624. // Was there a group added or deleted?
  625. if (strstr($perform_action2,"addGroup")) {
  626. $temp = explode("_",$perform_action2);
  627. $group_id = $temp[1];
  628. $semester_num = $temp[2];
  629. $hours = trim($temp[3]);
  630. $type = $temp[4];
  631. $min_grade = trim($temp[5]);
  632. $query = "INSERT INTO draft_degree_requirements
  633. (`degree_id`,`semester_num`,`group_id`,
  634. `group_requirement_type`,`group_hours_required`,`group_min_grade`)
  635. VALUES ('?','?','?','?','?','?') ";
  636. $res = db_query($query, $degree_id, $semester_num, $group_id, $type, $hours, $min_grade);
  637. }
  638. // Make the semesterTitlesCSV...
  639. for ($semester_num = 0; $semester_num <= $highest_semester_num; $semester_num++) {
  640. $semester_titles_csv .= trim($_POST["semester_title_$semester_num"]) . ",";
  641. }
  642. // Before we UPDATE, also grab the degree title, degree_type,
  643. // and exclude value, etc....
  644. $degree_title = trim($_POST["title"]);
  645. $degree_type = trim($_POST["degree_type"]);
  646. $degree_class = strtoupper(trim($_POST["degree_class"]));
  647. $exclude = trim($_POST["exclude"]);
  648. $public_note = trim($_POST["public_note"]);
  649. $res = db_query("UPDATE draft_degrees
  650. SET `semester_titles_csv`='?',
  651. `title`='?',
  652. `degree_type`='?',
  653. `degree_class`='?',
  654. `exclude`='?',
  655. `public_note`='?'
  656. WHERE `degree_id`='?' ",
  657. $semester_titles_csv, $degree_title, $degree_type, $degree_class, $exclude, $public_note, $degree_id);
  658. //// Was there a track title/description? If so, UPDATE that in the tracks
  659. // table...
  660. if (strstr($major_code, "_")) {
  661. // There was a track. Update track description.
  662. $temp = explode("_",$major_code);
  663. $major = trim($temp[0]);
  664. // major might now have a | at the end. If so, take it out.
  665. if (substr($major, strlen($major)-1, 1) == "|") {
  666. $major = str_replace("|","",$major);
  667. }
  668. $track = trim($temp[1]);
  669. $track_description = trim($_POST["track_description"]);
  670. $track_title = trim($_POST["track_title"]);
  671. //debugCT($track_description);
  672. $res = db_query("UPDATE draft_degree_tracks
  673. SET `track_description`='?',
  674. `track_title`='?'
  675. WHERE `track_code`='?'
  676. AND `major_code`='?'
  677. AND `catalog_year`='?' ", $track_description, $track_title, $track, $major, $de_catalog_year);
  678. }
  679. //$msg = "<font color='green' size='4'>Degree updated successfully at " . get_current_time() . ".</font>";
  680. fp_add_message("Degree updated succesfully.");
  681. $bool_scroll = $bool_button_msg = true;
  682. if ($errors != "")
  683. {
  684. fp_add_message("ERROR(s): $errors");
  685. $bool_scroll = $bool_button_msg = false;
  686. }
  687. fp_goto("admin/degrees/edit-degree", "de_catalog_year=$de_catalog_year&major_code=$major_code&scroll_top=" . $_REQUEST["scroll_top"] . "&button_msg=" . urlencode("Degree updated successfully at " . date("H:i:s")));
  688. return;
  689. }
  690. /**
  691. * This screen displays the form which allows the user to actually
  692. * edit a degree.
  693. */
  694. function admin_display_edit_degree() {
  695. $de_catalog_year = admin_get_de_catalog_year();
  696. $rtn = "";
  697. $major_code = $_REQUEST["major_code"];
  698. // Add in our CSS and JS
  699. fp_add_js(fp_get_module_path("admin") . "/js/admin.js");
  700. fp_add_css(fp_get_module_path("admin") . "/css/admin.css");
  701. $button_msg = trim(addslashes($_REQUEST["button_msg"]));
  702. $db = get_global_database_handler();
  703. $degree_id = intval($db->get_degree_id($major_code, $de_catalog_year, true));
  704. // The intval says, if it's false, make it = 0. otherwise keep the number
  705. // that is returned.
  706. $degree = new DegreePlan($degree_id, null, false, false, true);
  707. $degree->load_descriptive_data();
  708. if (user_has_permission("can_view_advanced")) {
  709. $rtn .= " <span class='tenpt' style='background-color: yellow; margin-left: 20px;'>
  710. advanced: degreeID = $degree_id.
  711. </span>";
  712. }
  713. $rtn .= "<form id='mainform' action='" . base_path() . "/admin/degrees/handle-edit-degree-submit' method='POST'>
  714. <input type='hidden' name='perform_action2' id='perform_action2'>
  715. <input type='hidden' name='de_catalog_year' value='$de_catalog_year'>
  716. <input type='hidden' name='scroll_top' id='scroll_top' value=''>
  717. <input type='hidden' name='major_code' value='$major_code'>
  718. ";
  719. $rtn .= "<div style='font-size: 16pt; font-weight:bold; padding-top: 20px;'>$degree->degree_type $degree->title<br>$major_code ($de_catalog_year)</div>";
  720. $rtn .= "
  721. <table>
  722. <tr>
  723. <td valign='top' class='tenpt' width='15%'>Degree Type:</td>
  724. <td valign='top' class='tenpt' width='15%'><input type='text' name='degree_type' value='$degree->degree_type' size='5' maxlength='20'></td>
  725. <td valign='top' class='tenpt' width='15%'>Degree Class:</td>
  726. <td valign='top' class='tenpt'><input type='text' name='degree_class' value='$degree->degree_class' size='2' maxlength='1'>
  727. <a href='javascript: adminPopupAlertHelp(\"degree_class\");'>?</a></td>
  728. </tr>
  729. </tr>
  730. <tr>
  731. <td valign='top' class='tenpt'>Degree Title:</td>
  732. <td valign='top' class='tenpt' colspan='3'><input type='text' name='title' value='$degree->title' size='80' maxlength='100'></td>
  733. </tr>
  734. <tr>
  735. <td valign='top' class='tenpt'>Exclude:</td>
  736. <td valign='top' class='tenpt' colspan='3'><input type='text' name='exclude' value='$degree->db_exclude' size='2' maxlength='1'>
  737. <a href='javascript: adminPopupAlertHelp(\"degree_exclude\");'>?</a></td>
  738. </tr>
  739. </table> ";
  740. if (strstr($major_code, "_"))
  741. {
  742. $rtn .= "<b>Edit track information:</b>
  743. <blockquote style='margin-top: 0px; margin-bottom: 0px;'>
  744. <font size='2'>Track title: <input type='text' name='track_title' value='$degree->track_title' size='60' maxlength='100'></font><br>
  745. <font size='2'>Track description: <a href='javascript: adminPopupAlertHelp(\"edit_formatting\");'>(Help - Formatting)</a>
  746. <a href='javascript: adminPopupAlertHelp(\"track_description\");'>(Help - Track Descriptions)</a>
  747. </font><br>
  748. <textarea name='track_description' cols='60' rows='3'>" . filter_markup($degree->track_description) . "</textarea>
  749. </blockquote>
  750. ";
  751. }
  752. $rtn .= "<div class='tenpt' align='center'>(Scroll to the bottom of the page for more options)</div>";
  753. $degree->list_semesters->reset_counter();
  754. while ($degree->list_semesters->has_more()) {
  755. $semester = $degree->list_semesters->get_next();
  756. if ($semester->semester_num < 0) {
  757. continue;
  758. }
  759. $sem_default_title = admin_get_semester_name($semester->semester_num);
  760. if ($semester->title == $sem_default_title) {
  761. $semester->title = "";
  762. }
  763. $rtn .= "<div class='elevenpt' style='padding-bottom: 30px;'>
  764. <b>Block number: " . ($semester->semester_num +1) . "</b>
  765. &nbsp; &nbsp; &nbsp; &nbsp;
  766. Default title: $sem_default_title
  767. &nbsp; &nbsp;
  768. Override: <input type='text' name='semester_title_$semester->semester_num' value='$semester->title' size='20'>
  769. <a href='javascript: adminPopupAlertHelp(\"semester_title\");'>?</a>
  770. <table border='1' width='100%'>
  771. ";
  772. // Get the courses.
  773. $rtn .= "<tr><td valign='top'>
  774. <textarea name='courses_$semester->semester_num' rows='10' cols='20'>";
  775. $semester->list_courses->sort_alphabetical_order();
  776. $semester->list_courses->reset_counter();
  777. while($semester->list_courses->has_more()) {
  778. $course = $semester->list_courses->get_next();
  779. $course->load_descriptive_data();
  780. $rtn .= "$course->subject_id $course->course_num $course->requirement_type";
  781. if ($course->min_grade != "D" && $course->min_grade != "") {
  782. $rtn .= " ($course->min_grade)";
  783. }
  784. $rtn .= "\n";
  785. }
  786. $rtn .= "</textarea>
  787. <div class='tenpt'>(<a href='javascript: adminPopupAlertHelp(\"degree_entry\");'>Help - entering requirements, min grades, and repeats</a>)</div>
  788. </td>";
  789. // Get the groups...
  790. $rtn .= "<td valign='top' class='tenpt' width='100%'>
  791. <table width='100%' border='0' cellspacing='5'>
  792. <tr>
  793. <td valign='top' class='tenpt' width='1'>&nbsp;</td>
  794. <td valign='top' class='tenpt'>Group</td>
  795. <td valign='top' class='tenpt' width='5'>hrs</td>
  796. <td valign='top' class='tenpt' width='5'>grd</td>
  797. <td valign='top' class='tenpt' width='5'>type</td>
  798. </tr>";
  799. $semester->list_groups->sort_alphabetical_order();
  800. $semester->list_groups->reset_counter();
  801. while($semester->list_groups->has_more()) {
  802. $group = $semester->list_groups->get_next();
  803. $group->load_descriptive_data();
  804. $rtn .= "<tr><td valign='middle'>
  805. <a href='javascript: adminDelGroup(\"$group->group_id\",\"$semester->semester_num\");'><img src='" . fp_theme_location() . "/images/delete.png' border='0'></a>
  806. <td valign='top' class='tenpt'>
  807. $group->title<br><i>$group->group_name</i></td>
  808. <td valign='top' class='tenpt'>$group->hours_required</td>
  809. <td valign='top' class='tenpt'>$group->min_grade</td>
  810. <td valign='top' class='tenpt'>$group->requirement_type
  811. <input type='hidden' name='group_" . $group->group_id . "_" . rand(1,999999) . "' value='$group->group_id" . "_$semester->semester_num" . "_$group->hours_required" . "_$group->requirement_type" . "_$group->min_grade'>
  812. </td>";
  813. }
  814. $rtn .= "</table>
  815. <div style='margin-top: 10px; margin-left: 20px;'>
  816. <a href='javascript: adminPopupWindow(\"" . base_path() . "/admin/degrees/popup-add-group&semester_num=$semester->semester_num&de_catalog_year=$de_catalog_year\");'>Add an elective group</a>
  817. </div>
  818. </td>";
  819. $rtn .= "</table><br>
  820. " . fp_render_button(t("Save for @year", array("@year" => $de_catalog_year)), "adminSubmitForm();") . "
  821. <span class='admin-button-msg'>$button_msg</span>
  822. </div>
  823. ";
  824. $s_count = $semester->semester_num+1;
  825. }
  826. // Always add an additional 4 semesters to the bottom.
  827. for ($t = 0; $t < 4; $t++) {
  828. $sem = $t + $s_count;
  829. if ($sem > 99) {
  830. // Max number of semesters. More or less arbitrarily set number.
  831. $rtn .= "<br>" . t("Maximum number of semesters created.") . "<br>";
  832. break;
  833. }
  834. $rtn .= "<div class='elevenpt' style='padding-bottom: 30px;'>
  835. <b>Block number: " . ($sem+1) . "</b>
  836. &nbsp; &nbsp; &nbsp; &nbsp;
  837. Default title: " . admin_get_semester_name($sem) . "
  838. &nbsp; &nbsp;
  839. Override: <input type='text' name='semester_title_$sem' value='' size='20'>
  840. <a href='javascript: adminPopupAlertHelp(\"semester_title\");'>?</a>
  841. <table border='1' width='100%'>
  842. ";
  843. $rtn .= "<tr><td valign='top'>
  844. <textarea name='courses_$sem' rows='10' cols='20'>";
  845. $rtn .= "</textarea></td>";
  846. // the groups...
  847. $rtn .= "<td valign='top' class='tenpt' width='100%'>
  848. <table width='100%' border='0' cellspacing='5'>
  849. <tr>
  850. <td valign='top' class='tenpt' width='1'>&nbsp;</td>
  851. <td valign='top' class='tenpt'>Group</td>
  852. <td valign='top' class='tenpt'>hrs</td>
  853. <td valign='top' class='tenpt'>grd</td>
  854. <td valign='top' class='tenpt'>type</td>
  855. </tr>";
  856. $rtn .= "</table>
  857. <div style='margin-top: 10px; margin-left: 20px;'>
  858. <a href='javascript: adminPopupWindow(\"" . base_path() . "/admin/degrees/popup-add-group&semester_num=$sem&de_catalog_year=$de_catalog_year\");'>Add an elective group</a>
  859. </td>";
  860. $rtn .= "</table><br>
  861. " . fp_render_button(t("Save for @year", array("@year" => $de_catalog_year)), "adminSubmitForm();") . "
  862. <span class='admin-button-msg'>$button_msg</span>
  863. </div>";
  864. }
  865. $rtn .= "<div class='elevenpt'>If you need more semester boxes, simply save this page, and additional blank
  866. boxes will appear below.</div>
  867. <br><br>
  868. <div class='elevenpt'><b>More Options:</b><br>
  869. Enter a public note for this degree:
  870. <a href='javascript: adminPopupAlertHelp(\"public_note\");'>(Help - Public Note)</a>
  871. <a href='javascript: adminPopupAlertHelp(\"edit_formatting\");'>(Help - Formatting)</a>
  872. <br>
  873. <textarea name='public_note' rows='4' cols='80'>$degree->public_note</textarea>
  874. </div>
  875. ";
  876. $rtn .= "</form>";
  877. $rtn .= " <div align='right'>
  878. Delete this degree? <input type='button' value='X'
  879. onClick='adminDeleteDegree(\"$degree_id\");'>
  880. </div>
  881. ";
  882. //$pC .= get_j_s();
  883. if ($_REQUEST["serialize"] != "")
  884. {
  885. print "<br><textarea rows=20 cols=80>" . serialize($degree) . "</textarea>";
  886. }
  887. return $rtn;
  888. }

Functions

Namesort descending Description
admin_add_degree_form This form lets the user add a degree to the database.
admin_add_degree_form_submit Submit handler for the add_degree_form.
admin_copy_degree_form This form lets the user copy a degree and all of it's tracks & concentrations.
admin_copy_degree_form_submit
admin_display_degrees
admin_display_degrees_popup_add_group
admin_display_edit_degree This screen displays the form which allows the user to actually edit a degree.
admin_handle_edit_degree_submit