function advise_display_popup_change_track

6.x advise.module advise_display_popup_change_track()
4.x advise.module advise_display_popup_change_track()
5.x advise.module advise_display_popup_change_track()

File

modules/advise/advise.module, line 625

Code

function advise_display_popup_change_track() {
  global $degree_plan, $student;
  $rtn = "";

  advise_init_screen();

  fp_add_js(fp_get_module_path("advise") . "/js/advise.js");
  fp_add_css(fp_get_module_path("advise") . "/css/advise.css");


  if ($degree_plan->db_allow_dynamic == 0) {

    // Since this is NOT a degree plan which can be combined with others, we
    // want to display this popup like in FlightPath 4.x.
    return advise_display_popup_change_track_non_dynamic_degree();

  }


  $top_level_majors_csv = "";

  $degree_plan_array = array();
  if ($degree_plan->is_combined_dynamic_degree_plan == FALSE) {
    // NOT a combined degree plan.  Just use the 1 degree plan we gots.
    $degree_plan_array [$degree_plan->degree_id] = $degree_plan;

  }
  else {
    // It IS a combined degree plan, so we need to get all the plans out of there.
    foreach ($degree_plan->combined_degree_ids_array as $t_degree_id) {
      $t_degree_plan = fp_load_degree($t_degree_id);
      $t_degree_plan->load_descriptive_data();

      if ($t_degree_plan->get_available_tracks()) {
      }

      $degree_plan_array [$t_degree_plan->degree_id] = $t_degree_plan;

    }
  }



  $locked_array = array(); // keep track of any degree classes which are "locked".

  // From What If mode...  
  if (@$GLOBALS ["fp_advising"]["advising_what_if"] == "yes") {
    $student_majors_array = @csv_to_array($_SESSION ["what_if_major_code" . $student->student_id]);
  }
  else {
    // Not in what if mode-- get the data from the normal student_majors table.
    $student_majors_array = fp_get_student_majors($student->student_id, FALSE, TRUE);

    // Also see if any degree classes should be "locked" for this student.
    $db = get_global_database_handler();
    $temp = $db->get_student_majors_from_db($student->student_id, FALSE, FALSE, FALSE);
    foreach ($temp as $line) {
      $t = explode("~", $line);
      if (trim(strtoupper($t [0])) == "LOCKED") {
        $locked_array [] = trim($t [1]);
      }
    }

  } //else




  $rtn .= fp_render_curved_line(t("Select a Degree Option"));
  $rtn .= "<div class='tenpt'>
            " . t("The student's degree has one or more degree options, which affects which courses are required. 
              Please select a degree option (or track) from the list below.") . "
              <br><br>
            " . t("If you are unsure of what to do, simply close this window.") . "
          </div>
      ";

  // Loop through available degrees here
  foreach ($degree_plan_array as $t_degree_plan) {

    $t_degree_plan->load_descriptive_data();

    // Skip any degree plan that isn't level 1 or level 2.  In other words,
    // if this is already a track, then skip it.
    $details = fp_get_degree_classification_details($t_degree_plan->degree_class);

    if ($details ["level_num"] == 3) {
      continue;
    }


    // Go through each type of classification in this degree's track_selection_config_array.    
    //foreach ($t_degree_plan->track_selection_config_array as $machine_name => $tdetails) {
    $degree_classes = fp_get_degree_classifications();

    foreach ($degree_classes ["levels"][3] as $machine_name => $class_title) {

      $extra_css_class = "";
      $class_is_empty = TRUE;
      $is_locked = FALSE;
      if (in_array($machine_name, $locked_array)) {
        $is_locked = TRUE;
        $extra_css_class = "degree-class-is-locked";
      }

      $html = "";

      $min_max_options = "";
      // Check to see what we have in this degree's track_selection_config_array        
      $min_tracks = @intval($t_degree_plan->track_selection_config_array [$machine_name]["min_tracks"]);
      $max_tracks = @intval($t_degree_plan->track_selection_config_array [$machine_name]["max_tracks"]);
      $default_tracks = @trim($t_degree_plan->track_selection_config_array [$machine_name]["default_tracks"]);
      $default_tracks_array = csv_to_array($default_tracks);


      $degree_id = $t_degree_plan->degree_id;



      // Add this information to our javascript settings...
      $js = array(
        "degree_min_max_tracks_" . $degree_id . "_split_" . $machine_name => $min_tracks . "~" . $max_tracks,
        "degree_name_" . $degree_id => $t_degree_plan->get_title2(FALSE, FALSE, FALSE),
        "class_title_" . $machine_name => $class_title,
      );

      fp_add_js($js, "setting");

      $min_max_options = "<div class='advise-select-track-min-max advise-select-track-between'>Please select between $min_tracks and $max_tracks $class_title options.</div>";
      if ($min_tracks == $max_tracks && $max_tracks == 1) {
        $min_max_options = "<div class='advise-select-track-min-max advise-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='advise-select-track-min-max advise-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='advise-select-track-min-max advise-select-track-optional'>Optional: You are not required to select any additional $class_title options.</div>";
      }



      // Let's look to see what "tracks" this degree has.

      $html .= "<br>
                <div class='advise-track-selection-tracks $extra_css_class'>
                <div class='tenpt'><span class='advise-select-degree-title'>" . $t_degree_plan->title . "</span> <span class='advise-select-class-title'>$class_title</span> options:</div>
                <div class='advise-track-min-max-options advise-track-min-$min_tracks advise-track-max-$max_tracks'>$min_max_options</div>
                  <!--DEFAULT_$machine_name-->
                  <div class='advise-track-options-region'>
          ";

      $major_code = $t_degree_plan->major_code;

      $top_level_majors_csv .= $major_code . ",";

      // Get the list of available tracks for this student.
      if (!$tracks = $t_degree_plan->get_available_tracks()) 
       {
        $html .= "<div class='advise-select-track-none'>&nbsp; &nbsp; &bull; " . t("This degree has no degree options.") . "</div>";
      }

      // Is there a "default" message for all tracks, which will override
      // any other track descriptions?
      // We need to look through all the tracks for the
      // characters:  "DEFAULT:"
      // If we find this, then this is the default description
      // which applies to all the tracks, and it should be displayed
      // at the top.
      $bool_default_description = false;
      for ($t = 0; $t < count($tracks); $t++) 
       {
        $temp = explode(" ~~ ", $tracks [$t]);
        $track_code = trim(@$temp [0]);
        $track_title = trim(@$temp [1]);
        $track_description = trim(@$temp [2]);

        // if this track is NOT of the same classification as the current machine_code, we skip it.        
        $track_machine_name = trim(@$temp [4]);

        if ($track_machine_name != $machine_name) {
          continue; // not the right degree_class
        }

        if (strstr($track_description, "DEFAULT:")) {
          // Yes!  We found a default message.
          $bool_default_description = true;
          $track_description = filter_markup(trim(str_replace("DEFAULT:", "", $track_description)));
          $track_description = "<div style='padding-top: 10px;' class='tenpt advise-select-track-description'>$track_description</div>";
          $html = str_replace("<!--DEFAULT_$machine_name-->", $track_description, $rtn);
          break;
        }

      }

      ///////////////////
      // Okay, go through the tracks, 

      for ($t = 0; $t < count($tracks); $t++) 
       {
        $temp = explode(" ~~ ", $tracks [$t]);
        $track_code = trim(@$temp [0]);
        $track_title = trim(@$temp [1]);
        $track_degree_id = intval(trim(@$temp [3]));
        $track_description = "";

        // if this track is NOT of the same classification as the current machine_code, we skip it.
        $track_machine_name = trim(@$temp [4]);
        if ($track_machine_name != $machine_name) {
          continue; // not the right degree_class
        }


        $selected = $disabled = "";

        // If this track has been selected already, mark it as such
        if (isset($degree_plan_array [$track_degree_id])) {
          // Meaning yes, this was already selected for this student.
          $selected = "checked=checked";
        }

        // Is this track marked as NOT is_editable?
        $is_editable = 1;
        if (isset($student_majors_array [$t_degree_plan->major_code . "|_" . $track_code])) {
          $is_editable = intval(@$student_majors_array [$t_degree_plan->major_code . "|_" . $track_code]["is_editable"]);
        }

        if ($is_editable != 1 || $is_locked == TRUE) {
          $disabled = "disabled=disabled";
        }


        if ($bool_default_description == false) {
          $track_description = filter_markup(trim(@$temp [2]));
        }

        $temp_tc = $track_code;
        if ($temp_tc == "") {
          $temp_tc = "none";
        }


        $link = fp_get_js_confirm_link(t("Are you sure you wish to change degree options?"), "opener.changeTrack(\"$temp_tc\"); window.close(); ", $track_title);



        // We actually don't need to do anything special for what_if, I think.  When
        // we save, it should automatically detect it and set the appropriate values.
        $is_whatif = 0;
        if ($GLOBALS ["fp_advising"]["advising_what_if"] == "yes") {
          $is_whatif = 1;
        }



        $track_degree_plan = fp_load_degree($track_degree_id, NULL, TRUE); // load minimally

        $input_type = "checkbox";
        $input_name = "track_degree_id_$track_degree_id";

        // We are extected to select EXACTLY 1 track...
        if ($min_tracks == $max_tracks && $max_tracks == 1) {
          $input_type = "radio";
          $input_name = "track_degree_id_" . $degree_id; // needs to be the same for all options. 
        }


        if ($track_degree_plan->db_allow_dynamic == 1) {

          $extra_class = "";
          $is_default = FALSE;
          if (in_array($t_degree_plan->major_code . "|_" . $track_code, $default_tracks_array)) {
            $extra_class = "advise-select-track-default-track";
            $is_default = TRUE;
          }

          $html .= "<div class='track-option $extra_class'>";
          $html .= "          
                      <label>
                        <input type='$input_type' name='$input_name' degree_id_class='{$degree_id}_class_{$machine_name}'
                                is_editable='$is_editable' 
                                value='$track_degree_id' $selected $disabled> 
                        <span class='track-title'>" . $track_degree_plan->get_title2(TRUE, TRUE) . "
                        ";

          if ($is_default) {
            $html .= "<span class='track-default-track'>" . t("(Default)") . "</span>";
          }
          $html .= "                        
                        </span>
                      </label>";
          if (!$is_editable) {
            $html .= "<div class='track-not-editable'>" . t("You are not allowed to modify this option.") . "</div>";
          }

          $html .= "
                      
                      <div class='track-description'>
                        $track_description
                      </div>
                    </div>";


          $class_is_empty = FALSE;

        }


      } // for (count(tracks))

      if ($is_locked) {
        $html .= "<div class='track-class-is-locked-msg'>" . t("Selections from this degree classification are locked.  You may use What If mode to explore
                                                                other options, or ask your advisor about changing these options officially.") . "</div>";
      }


      $html .= "</div>";


      $html .= "</div>"; // advise-track-selection-tracks  

      if (!$class_is_empty) {
        $rtn .= $html;
      }


    }

  } // foreach degree_plan_array

  $rtn .= "<input type='button' value='" . t("Apply Selections") . "'
              onClick='if(confirm(\"Are you sure you wish to apply these selections to the degree plan?\")) { popupChangeTrackSelections($is_whatif);  }'>";

  // Keep track of what our top-level majors were.
  $top_level_majors_csv = rtrim($top_level_majors_csv, ","); // remove trailing comma if exists
  $rtn .= "<input type='hidden' name='top_level_majors_csv' id='top_level_majors_csv' value='$top_level_majors_csv'>";

  return $rtn;
}