function advise_init_screen

6.x advise.module advise_init_screen()
7.x advise.module advise_init_screen()
4.x advise.module advise_init_screen()
5.x advise.module advise_init_screen()

File

modules/advise/advise.module, line 2553

Code

function advise_init_screen() {

  global $degree_plan, $student, $fp, $window_mode, $user, $current_student_id, $screen;

  $db = get_global_database_handler();

  $faculty_id = $user->cwid;

  // Insert our advising vars into the GLOBALS array for easy use later.
  advise_init_advising_variables();


  $perform_action = trim(addslashes(@$_REQUEST ["perform_action"]));

  if (@$_REQUEST ["clear_session"] == "yes") {
    //advise_save_advising_variables_to_db();
    // reload our advising vars into the GLOBALS array for easy use later.
    //$GLOBALS["fp_advising"] = advise_load_advising_variables_from_db($current_student_id, $user->id);

  }

  // Insert our advising vars into the GLOBALS array for easy use later.
  //$GLOBALS["fp_advising"] = advise_load_advising_variables_from_db($current_student_id, $user->id);

  $bool_what_if = false;

  $csid = $current_student_id;

  $cache = @$_SESSION ["cache_fp$csid"];

  if (@$GLOBALS ["fp_advising"]["advising_what_if"] == "yes") {
    $major_code = @$GLOBALS ["fp_advising"]["what_if_major_code"];
    $track_code = @$GLOBALS ["fp_advising"]["what_if_track_code"];
    $bool_what_if = true;
    $cache = @$_SESSION ["cache_what_if$csid"];
  }

  $bool_draft = true;


  if (@$GLOBALS ["fp_advising"]["advising_load_active"] == "yes") {
    // If we are loading from Active, then rebuild the cache as well.
    $bool_draft = false;
    @$GLOBALS ["fp_advising"]["load_from_cache"] = "no";
  }

  $student_school_id = $db->get_school_id_for_student_id($csid);


  ///////////////////////
  ///  Disable student data Caching....
  //$GLOBALS["load_from_cache"] = "no";


  // Attempt to load the course inventory cache...  
  if ($course_inventory = unserialize(@$_SESSION ["fp_cache_course_inventory"])) {
    $GLOBALS ["fp_course_inventory"] = $course_inventory;
  }

  $bool_loaded = FALSE;
  if ($GLOBALS ["fp_advising"]["load_from_cache"] == "yes" && $cache != "" && $fp = unserialize($cache)) {
    $bool_loaded = TRUE;
    $fp->db = get_global_database_handler();
    $student = $fp->student;
    if ($student->student_id == "") {
      $bool_loaded = FALSE;
    }
    $degree_plan = $fp->degree_plan;
    $student->db = get_global_database_handler();
    $degree_plan->db = get_global_database_handler();

  }


  if (!$bool_loaded) {
    $fp = new FlightPath();
    $fp->init();
    $student = $fp->student;
    $degree_plan = $fp->degree_plan;
    $GLOBALS ["fp_advising"]["load_from_cache"] = "no";
    $bool_loaded = TRUE;
  }





  // If the form has been saved, this token is expected.  This protects
  // against XSS attacks.
  $form_token = md5("advise_display_view" . fp_token());
  if ($perform_action == "save_draft") {
    if ($_REQUEST ["form_token"] != $form_token) {
      die(t("Sorry, but you have encountered an error.  A form submission was flagged
      as possibly being an invalid or forged submission.  This may constitute a bug
      in the system.  Please report this error to your Systems Administrator."));
    }

    // Save, then reload the student.
    $adv_id_array = $fp->save_advising_session_from_post(0, true);

    $bool_draft = TRUE; // load draft, since we just saved it (and changed something)


  }
  else if ($perform_action == "save_active") {
    if ($_REQUEST ["form_token"] != $form_token) {
      die(t("Sorry, but you have encountered an error.  A form submission was flagged
      as possibly being an invalid or forged submission.  This may constitute a bug
      in the system.  Please report this error to your Systems Administrator."));
    }

    // Save, then go to the history screen.
    $adv_id_array = $fp->save_advising_session_from_post(0, false);

    // Use an fp_goto command here to go to the History screen
    // Serialize the adv_id_array so we can send it along in our fp_goto command...
    $adv_id_serialized = serialize($adv_id_array);

    fp_goto("history", "adv_id_array_serialized=" . urlencode($adv_id_serialized));
    return;

  }


  // Is the user trying to view "by type" or by year?
  if ($GLOBALS ["fp_advising"]["advising_view"] == "type") {
    $screen = new AdvisingScreenTypeView("", $fp);
    $screen->view = "type";

  }
  else {
    // Default advising view.  "View by Year"
    $screen = new AdvisingScreen("", $fp);
    $screen->view = "year";
  }


  if (@$_REQUEST ["bool_blank"] == "true" || @$_REQUEST ["blank_degree_id"] != "") {
    $screen->bool_blank = TRUE;
  }



  if ($bool_what_if == true && @$GLOBALS ["fp_advising"]["what_if_major_code"] == "") {
    // In other words, we are on the WhatIf tab, but we have not
    // selected a major.  So, just exit out.  We will give the user
    // a display_screen later.
    return;
  }


  if (@$GLOBALS ["fp_advising"]["load_from_cache"] != "yes") {
    // do not load from cache....  load the student fresh....

    // Only do if we need to re-init after save
    if (@$_REQUEST ['reinit_fp_after_draft_save'] == 'yes') {

      $fp = new FlightPath();
      $fp->init();
      $student = $fp->student;
      $degree_plan = $fp->degree_plan;

      $GLOBALS ["fp_advising"]["load_from_cache"] = "no";

    }

    $student->load_student();
    $student->load_student_substitutions();
    $student->load_unassignments();

    // Make sure we assign the freshly-loaded student, and re-establish all of our connections.
    $fp->student = $student;
    $screen->flightpath = $fp;
    $screen->student = $fp->student;
    $screen->degree_plan = $fp->degree_plan;

    $fp->flag_outdated_substitutions();
    $fp->assign_courses_to_semesters(); // bare degree plan. not groups.
    $fp->assign_courses_to_groups();

    ////////////
    /*
    // Good place to output a serialization, in case we need it for testing.
    $student->name = "Test Student2";
    $student->student_id = "123457";
    $temp = serialize($screen);
    file_put_contents(fp_get_files_path() . "/test.txt", $temp);
    /////////////*/




  }
  else {


  }




  if (@$GLOBALS ["fp_advising"]["save_to_cache"] != "no" && $window_mode != "popup") {
    if ($bool_what_if == false) {
      // NOT in whatIf mode.  Normal.

      $_SESSION ["cache_fp$csid"] = serialize($fp);


    }
    else {
      // We are in WhatIf mode.
      $_SESSION ["cache_what_if$csid"] = serialize($fp);



    }
  }


  // If we are loading from draft, then load the faculty_id which saved draft last.  If we are
  // loading fresh, not from draft, then load *any* faculty that saved last. 
  $use_faculty_id = $faculty_id;
  if (!$bool_draft) {
    $use_faculty_id = 0;
  }


  // We shouldn't supply the advising_term_id, so that it will load all terms available.
  $fp->load_advising_session_from_database($use_faculty_id, "", $bool_what_if, $bool_draft, 0, $faculty_id);


  // Once we have loaded the advising session, we should always try to load
  // from draft from then on out.
  $GLOBALS ["fp_advising"]["advising_load_active"] = "";



}