function advise_what_if_selection_form

6.x advise.module advise_what_if_selection_form($bool_undergrad_only = TRUE)
5.x advise.module advise_what_if_selection_form($bool_undergrad_only = TRUE)

File

modules/advise/advise.module, line 1696

Code

function advise_what_if_selection_form($bool_undergrad_only = TRUE) {
  global $screen, $current_student_id;

  if ($screen && $screen->bool_print) {
    return array();
  }

  fp_add_js(fp_get_module_path("advise") . "/js/advise.what-if-selection.js");
  fp_add_css(fp_get_module_path("advise") . "/css/advise.css");

  $student_school_id = intval(db_get_school_id_for_student_id($current_student_id));

  $form = array();
  $m = 0;

  fp_set_title(""); // Remove the default form's title

  $db = get_global_database_handler();

  $major_codes = array();

  $form ["mark" . $m++] = array(
    "value" => fp_render_section_title("What if I change my degree to...") . "<br>",
  );



  $catalog_year = variable_get_for_school("current_catalog_year", 0, $student_school_id);
  $current_catalog_year = $catalog_year; // keep track of what the current catalog year is.
  $earliest_catalog_year = intval(variable_get_for_school("earliest_catalog_year", 2006, $student_school_id));


  // Use the student's catalog year, based on a setting instead?
  if (variable_get_for_school("what_if_catalog_year_mode", "current", $student_school_id) == "student") {
    $db = get_global_database_handler();
    $catalog_year = $db->get_student_catalog_year($current_student_id);
  }

  $form ["mark_cat_year"] = array(
    "value" => "<div class='mark-select-from-cat-year'>" . t("Please select from the %cat catalog year:", array("%cat" => $catalog_year . "-" . ($catalog_year + 1))) . "</div>",
  );



  // We cannot go beyond the current catalog year, so if the catalog_year is now > than current, we must stop
  // the user.
  if ($catalog_year > $current_catalog_year || $catalog_year < $earliest_catalog_year) {
    $form ["mark_cat_year_past_current"] = array(
      "value" => "<p class='cat-year-past-current'>" . t("Sorry, but the catalog year %cat is not available yet within
                                                            FlightPath.  Please speak with your adviser about how to proceed
                                                            with advising.", array("%cat" => $catalog_year . "-" . ($catalog_year + 1))) . "</p>",
    );

    return $form;


  }




  $form ["catalog_year"] = array(
    "type" => "hidden",
    "value" => $catalog_year,
  );

  $bool_use_draft = FALSE; // leave as false for now.  Because you can't select
  // degree options, and if you click submit it really does
  // save it.  Better to just use blank degrees.

  $c = 100;


  /////////////////////
  // Select a major....


  $options = array();
  if ($degree_array = $db->get_degrees_in_catalog_year($catalog_year, FALSE, $bool_use_draft, $bool_undergrad_only, array(1), $student_school_id)) {

    foreach ($degree_array as $major_code => $value) {
      if (trim($value ["title"]) == "") {
        continue;
      }
      $options [$major_code] = $value ["title"];
      $major_codes [$major_code] = $major_code;
    }
  }

  // Place in a fieldset...
  $e1 ["select_level_1_degrees"] = array(
    "type" => "checkboxes",
    "label" => "",
    "options" => $options,
  );

  $form ["cfieldset_level_1"] = array(
    "type" => "cfieldset",
    "label" => "Select Major &raquo;",
    "elements" => array($e1),
    "start_closed" => FALSE,
  );


  /////////////////////////
  // Select a minor....
  $options = array();
  if ($degree_array = $db->get_degrees_in_catalog_year($catalog_year, FALSE, $bool_use_draft, $bool_undergrad_only, array(2), $student_school_id)) {
    foreach ($degree_array as $major_code => $value) {
      if (trim($value ["title"]) == "") {
        continue;
      }
      $options [$major_code] = $value ["title"];
      $major_codes [$major_code] = $major_code;
    }
  }


  if (count($options) > 0) {
    $e2 ["select_level_2_degrees"] = array(
      "type" => "checkboxes",
      "label" => "",
      "options" => $options,
    );

    $form ["cfieldset_level_2"] = array(
      "type" => "cfieldset",
      "label" => "Select Minor &raquo;",
      "elements" => array($e2),
    );
  }


  /////////////////////
  // All the tracks...

  if (variable_get_for_school("show_level_3_on_what_if_selection", "yes", $student_school_id) == 'yes') {

    foreach ($major_codes as $major_code => $temp) {
      // Let's see if this major has any tracks...
      if ($tracks = $db->get_degree_tracks($major_code, $catalog_year, $student_school_id)) {
        // Let's load the original degree plan.
        $degree_plan = $db->get_degree_plan($major_code, $catalog_year, TRUE, $student_school_id);
        $degree_plan->load_degree_plan_ancillary();

        // Yes, there are indeed tracks for THIS major.  Let's load them up...
        // First, organize them by degree_class...
        $tracks_by_class = array();
        foreach ($tracks as $track) {
          $t_degree_plan = $db->get_degree_plan($major_code . "|_" . $track, $catalog_year, TRUE, $student_school_id);
          $t_degree_plan->load_degree_plan_ancillary();
          $degree_class = trim($t_degree_plan->degree_class);
          if ($degree_class) {
            $tracks_by_class [$degree_class][] = $t_degree_plan;
          }
        }

        // Now, create the form element...      
        foreach ($tracks_by_class as $degree_class => $c) {
          $options = array();

          $temp = fp_get_degree_classification_details($degree_class);
          $class_title = $temp ["title"];


          // Are there any special requirements or defaults for this degree_class selection?
          $tsca = $degree_plan->track_selection_config_array;
          $default_tracks_array = @csv_to_array($tsca [$degree_class]["default_tracks"]);

          $min_tracks = @intval($tsca [$degree_class]["min_tracks"]);
          $max_tracks = @intval($tsca [$degree_class]["max_tracks"]);
          $element_type = "checkboxes";
          $element_value = array();

          // If we require exactly 1 selection, then make this a radio button, and pre-select either the first element
          // or the first default track.
          if ($min_tracks == 1 && $max_tracks == 1) {
            $element_type = "radios";
            $element_value = array($default_tracks_array [0] => $default_tracks_array [0]);
          }

          // Actually build up the options...        
          foreach ($tracks_by_class [$degree_class] as $t_degree_plan) {
            //$degree_id = $t_degree_plan->degree_id;  

            $tmajor_code = "" . trim($t_degree_plan->major_code);

            $options [$tmajor_code] = $t_degree_plan->get_title2(FALSE, TRUE);
            if (trim($t_degree_plan->track_description) != "") {
              $options [$tmajor_code] .= "<div class='what-if-selection-track-desc what-if-selection-track-desc-for-" . fp_get_machine_readable($tmajor_code) . "'
                                                  >" . $t_degree_plan->track_description . "</div>";
            }

            // Is this a "default" major code?
            if (in_array(trim($tmajor_code), $default_tracks_array)) {
              $element_value [$tmajor_code] = $tmajor_code; // make it be selected            
            }
          }

          $min_max_options = "<div class='what-if-select-track-min-max what-if-select-track-between'>Please select between $min_tracks and $max_tracks $class_title options.</div>";
          if ($min_tracks == $max_tracks) {
            $min_max_options = "<div class='advise-select-track-min-max advise-select-track-exact-number'>Please select $max_tracks $class_title options.</div>";
          }
          if ($min_tracks == $max_tracks && $max_tracks == 1) {
            $min_max_options = "<div class='what-if-select-track-min-max what-if-select-track-exactly-one'>Please select 1 $class_title option.</div>";
          }

          if ($min_tracks > 0 && $max_tracks == 0) {
            // Meaning, there is no maximum.  It's infinite.
            $min_max_options = "<div class='what-if-select-track-min-max what-if-select-track-at-least-one'>Please select at least $min_tracks $class_title option(s) for this degree.</div>";
          }

          if ($min_tracks == $max_tracks && $max_tracks == 0) {
            $min_max_options = "<div class='what-if-select-track-min-max what-if-select-track-optional'>Optional: You are not required to select any additional $class_title options.</div>";
          }




          $form ["L3__sel__{$degree_class}__for__{$major_code}__xx"] = array(//ends with xx so we can be sure when the major code ends.
            "type" => $element_type,
            "label" => "Select $class_title for " . $degree_plan->get_title2(),
            "options" => $options,
            "description" => "$min_max_options",
            "value" => $element_value,
          );

          // Save min and max options for quick look-up later.
          $form ["L3__ops__{$degree_class}__for__{$major_code}__xx"] = array(
            "type" => "hidden",
            "value" => "$min_tracks~$max_tracks",
          );


        }




      } // if tracks
    } // foreach major codes

  } // if level-3 selection...



  $form ["submit_btn"] = array(
    "value" => "<div align='right'>
      " . fp_render_button("Try It Out!", "showUpdate(true);$(\"#fp-form-advise_what_if_selection_form\").submit(); ") . "
                </div>",
  );



  $form ["current_student_id"] = array(
    "type" => "hidden",
    "value" => $current_student_id,
  );


  watchdog("advise", "what_if_selection_form $current_student_id", array());

  return $form;
}