function AdvisingScreen::display_popup_substitute

7.x AdvisingScreen.php AdvisingScreen::display_popup_substitute($course_id = 0, $group_id, $semester_num, $hours_avail = "", $req_by_degree_id = 0)
6.x AdvisingScreen.php AdvisingScreen::display_popup_substitute($course_id = 0, $group_id, $semester_num, $hours_avail = "", $req_by_degree_id = 0)

This is used to display the substitution popup to a user, to let them actually make a substitution.

Parameters

int $course_id:

int $group_id:

int $semester_num:

int $hours_avail:

Return value

string

File

classes/AdvisingScreen.php, line 5203

Class

AdvisingScreen

Code

function display_popup_substitute($course_id = 0, $group_id, $semester_num, $hours_avail = "", $req_by_degree_id = 0) 
 {
  global $current_student_id;
  // This lets the user make a substitution for a course.
  $pC = "";

  $school_id = db_get_school_id_for_student_id($current_student_id);

  // Bring in advise's css...
  fp_add_css(fp_get_module_path("advise") . "/css/advise.css");


  $course = new Course($course_id);
  $bool_sub_add = false;

  $req_degree_plan = new DegreePlan();
  $req_degree_plan->degree_id = $req_by_degree_id;
  if ($req_by_degree_id > 0) {
    $course->req_by_degree_id = $req_by_degree_id;
    $req_degree_plan->load_descriptive_data();
  }

  $c_title = t("Substitute for") . " $course->subject_id $course->course_num";
  if ($course_id == 0) 
   {
    $c_title = t("Substitute an additional course");
    $bool_sub_add = true;
  }
  $pC .= fp_render_section_title($c_title);

  if ($req_by_degree_id > 0) {
    $pC .= "<div class='  sub-req-by-degree-title-line'>" . t("This substitution will only affect the <b>%title</b> degree requirements.", array("%title" => $req_degree_plan->get_title2())) . "
              </div>";
  }

  $extra = ".<input type='checkbox' id='cbAddition' value='true' style='display:none;'>";
  if ($group_id > 0) 
   {
    $new_group = new Group($group_id);
    $checked = "";
    if ($bool_sub_add == true) {
      $checked = "checked disabled";
    }
    $extra = " " . t("in the group %newg.", array("%newg" => $new_group->title)) . "
      " . t("Addition only:") . " <input type='checkbox' id='cbAddition' value='true' $checked> 
         <a href='javascript: alertSubAddition();'>?</a>";
  }

  $c_hours = $course->max_hours * 1;
  $c_ghost_hour = "";
  if ($course->bool_ghost_hour == TRUE) {
    $c_ghost_hour = t("ghost") . "<a href='javascript: alertSubGhost();'>?</a>";
  }

  if (($hours_avail * 1 > 0 && $hours_avail < $c_hours) || ($c_hours <= 0)) 
   {

    // Use the remaining hours if we have fewer hours left in
    // the group than the course we are subbing for.
    $c_hours = $hours_avail;
  }

  if ($hours_avail == "" || $hours_avail * 1 <= 0) 
   {
    $hours_avail = $c_hours;
  }

  $pC .= "<div class=' '>
          " . t("Please select a course to substitute
        for %course", array("%course" => "$course->subject_id $course->course_num ($c_hours $c_ghost_hour " . t("hrs") . ")")) . "$extra
        </div>
        ";


  // If this course has ghost hours, and if we've set that you can only sub ghost hours
  // for other ghost hours, then display a message here explaining that.
  $bool_ghost_for_ghost = (variable_get("restrict_ghost_subs_to_ghost_hours", "yes") == "yes" && $course->bool_ghost_hour);

  if ($bool_ghost_for_ghost) {
    $pC .= "<div class=' '>" . t("<b>Note:</b> As per a setting in FlightPath, the only courses which
                may be substituted must be worth zero hours (1 ghost hour).") . "</div>";
  }



  $pC .= "
        <div class=' ' 
          style='height: 175px; overflow: auto; border:1px inset black; padding: 5px;'>
          <table border='0' cellpadding='0' cellspacing='0' width='100%'>
          
          ";

  $this->student->list_courses_taken->sort_alphabetical_order(false, true, FALSE, $req_by_degree_id);

  $school_id = db_get_school_id_for_student_id($this->student->student_id);

  for ($t = 0; $t <= 1; $t++) 
   {
    if ($t == 0) {
      $the_title = variable_get_for_school("school_initials", "DEMO", $school_id) . " " . t("Credits");
      $bool_transferTest = true;
    }
    if ($t == 1) {
      $the_title = t("Transfer Credits");
      $bool_transferTest = false;
    }

    $pC .= "<tr><td colspan='3' valign='top' class=' ' style='padding-bottom: 10px;'>
        $the_title
        </td>
        <td class=' ' valign='top' >" . t("Hrs") . "</td>
        <td class=' ' valign='top' >" . t("Grd") . "</td>
        <td class=' ' valign='top' >" . t("Term") . "</td>
        </tr>";

    $already_seen = array(); // keep track of the courses we've already seen.
    $used_hours_subs = array(); // extra help keeping up with how many hours we've used for particular courses in split up subs.

    $is_empty = true;
    $this->student->list_courses_taken->reset_counter();
    while ($this->student->list_courses_taken->has_more()) 
     {
      $c = $this->student->list_courses_taken->get_next();

      if ($c->bool_transfer == $bool_transferTest) 
       {
        continue;
      }


      if (!$c->meets_min_grade_requirement_of(null, variable_get_for_school("minimum_substitutable_grade", "D", $school_id))) 
       { // Make sure the grade is OK.
        continue;
      }

      $bool_disable_selection = $disabled_msg = FALSE;

      // Should we skip this course, because of a ghost_for_ghost requirement?
      if ($bool_ghost_for_ghost && !$c->bool_ghost_hour) {
        continue;
      }
      // If we are supposed to restrict ghost for ghost, but the course does NOT
      // have a ghost hour, and this $c course does, then disable it
      if (variable_get_for_school("restrict_ghost_subs_to_ghost_hours", "yes", $school_id) == "yes"
       && $course->bool_ghost_hour != TRUE
         && $c->bool_ghost_hour == TRUE) {

        $bool_disable_selection = TRUE;
        $disabled_msg = t("Substitution of this course has been disabled.  
                             As per a setting in FlightPath, courses worth zero hours (1 ghost hour)
                             may only be substituted for course requirements also worth zero hours.");

      }



      $t_flag = 0;
      if ($c->bool_transfer == true) 
       {
        $t_flag = 1;
      }
      $is_empty = false;

      $subject_id = $c->subject_id;
      $course_num = $c->course_num;
      $tcourse_id = $c->course_id;

      if ($bool_transferTest == false) 
       {
        // Meaning, we are looking at transfers now.
        // Does the transfer course have an eqv set up?  If so,
        // we want *that* course to appear.
        if (is_object($c->course_transfer)) 
         {
          $subject_id = $c->course_transfer->subject_id;
          $course_num = $c->course_transfer->course_num;
          $tcourse_id = $c->course_transfer->course_id;
          $t_flag = 1;
        }
      }


      $m_hours = $c->get_hours_awarded($req_by_degree_id);

      /*
         * 
         * We don't want to do this. What it's saying is if the max_hours (from the course database)
         * is LESS than the awarded hours, use the lower hours.  Instead, we want to always use
         * what the student was AWARDED.
         * 
        if ($c->max_hours*1 < $m_hours)
        {
          $m_hours = $c->max_hours*1;

        }
        */

      if (($hours_avail * 1 > 0 && $hours_avail < $m_hours) || ($m_hours == 0)) 
       {
        $m_hours = $hours_avail;
      }

      // is max_hours more than the original course's hours?
      if ($m_hours > $c_hours) 
       {
        $m_hours = $c_hours;
      }

      if ($m_hours > $c->get_hours_awarded($req_by_degree_id)) 
       {
        $m_hours = $c->get_hours_awarded($req_by_degree_id);
      }

      // If we have already displayed this EXACT course, then we shouldn't display it again.  This is to
      // fix a multi-degree bug, where we see the same course however many times it was split for a DIFFERENT degree.
      // If it's never been split for THIS degree, it should just show up as 1 course.
      $ukey = md5($c->course_id . $c->catalog_year . $c->term_id . $m_hours . $tcourse_id . intval(@$c->db_substitution_id_array [$req_by_degree_id]));
      if (isset($already_seen [$ukey])) {
        continue;
      }
      // Else, add it.
      $already_seen [$ukey] = TRUE;

      // We should also keep up with how many hours have been used by this sub...

      // Is this course NOT a substitution for this degree, and NOT an outdated sub? 
      // In other words, are we safe to just display this course as an option for selection?
      if ($c->get_bool_substitution($req_by_degree_id) != TRUE && $c->get_bool_outdated_sub($req_by_degree_id) != TRUE) 
       {


        $h = $c->get_hours_awarded($req_by_degree_id);
        if ($c->bool_ghost_hour == TRUE) {
          $h .= "(ghost<a href='javascript: alertSubGhost();'>?</a>)";
        }

        // If this course was split up, we need to use our 
        // helper array to see what the OTHER, already-used pieces add up to.
        if ($c->get_bool_substitution_split($req_by_degree_id)) {

          $ukey = md5($c->course_id . $c->catalog_year . $c->term_id . $tcourse_id);
          if (isset($used_hours_subs [$ukey])) {
            $used_hours = $used_hours_subs [$ukey];
            // Get the remaining hours by subtracting the ORIGINAL hours for this course against
            // the used hours.

            // Okay, I believe this is a bug.  Somewhere, I have set the hours_awarded to the remaining hours, so
            // this math is no longer needed.
            /*              
              $remaining_hours = $c->get_hours_awarded(0) - $used_hours;  // (0) gets the original hours awarded.
              if ($remaining_hours > 0) {
                $h = $remaining_hours;
                
              }*/

          }

        }




        $pC .= "<tr>
            <td valign='top' class=' ' width='15%'>
              <input type='radio' name='subCourse' id='subCourse' value='$tcourse_id'
               onClick='popupUpdateSubData(\"$m_hours\",\"$c->term_id\",\"$t_flag\",\"$hours_avail\",\"" . $c->get_hours_awarded($req_by_degree_id) . "\");'
               ";
        if ($bool_disable_selection) {
          $pC .= "disabled=disabled";
        }

        $pC .= "   >";

        if ($disabled_msg) {
          $pC .= fp_get_js_alert_link(fp_reduce_whitespace(str_replace("\n", " ", $disabled_msg)), "?");
        }

        $pC .= "
            </td>
            <td valign='top' class='  underline' width='13%'>
              $subject_id
            </td>
            <td valign='top' class='  underline' width='15%'>
              $course_num
            </td>
            

            <td valign='top' class='  underline' width='10%'>
              $h
            </td>
            <td valign='top' class='  underline' width='10%'>
              $c->grade
            </td>
            <td valign='top' class='  underline'>
              " . $c->get_term_description(true) . "
            </td>

            
          </tr>
          ";
      }
      else {

        // Does this course have a substitution for THIS degree?
        if (!is_object($c->get_course_substitution($req_by_degree_id))) {
          continue;
        }

        if (is_object($c->get_course_substitution($req_by_degree_id)) && $c->get_course_substitution($req_by_degree_id)->subject_id == "") 
         { // Load subject_id and course_num of the original
          // requirement.
          $c->get_course_substitution($req_by_degree_id)->load_descriptive_data();
        }
        $extra = "";
        //if ($c->assigned_to_group_id > 0)
        if ($c->get_bool_assigned_to_group_id(-1)) 
         {
          // TODO:  based on degree (hint: probably so...?
          $new_group = new Group($c->get_first_assigned_to_group_id());
          $extra = " in $new_group->title";
        }
        if ($c->get_bool_outdated_sub($req_by_degree_id)) 
         {
          $help_link = fp_get_js_alert_link(t("This substitution is outdated. It was made for a course or group which does not currently appear on the student's degree plan.  You may remove this sub using the Administrator's Toolbox, at the bottom of the View tab."), "?");
          $extra .= " <span style='color:red;'>[" . t("Outdated") . "$help_link]</span>";
        }

        // It has already been substituted!
        $pC .= "<tr style='background-color: beige;'>
            <td valign='top' class=' ' width='15%'>
             " . t("Sub:") . "
            </td>
            <td valign='top' class=' ' colspan='5'>
              $subject_id 
            
              $course_num (" . $c->get_substitution_hours($req_by_degree_id) . ")
               -> " . $c->get_course_substitution($req_by_degree_id)->subject_id . "
               " . $c->get_course_substitution($req_by_degree_id)->course_num . "$extra
            </td>

            
          </tr>
          ";

        // Keep track of how many hours THIS course has been subbed, if it was split.
        $ukey = md5($c->course_id . $c->catalog_year . $c->term_id . $tcourse_id);

        if (!isset($used_hours_subs [$ukey])) {
          $used_hours_subs [$ukey] = 0;
        }
        $used_hours_subs [$ukey] += $c->get_substitution_hours($req_by_degree_id);

      }

      // If this was a transfer course, have an extra line under the course, stating it's title.
      if ($bool_transferTest == FALSE) { // Means this IS INDEED a transfer courses.

        $c->course_transfer->load_descriptive_transfer_data($this->student->student_id, $c->term_id);
        $pC .= "<tr class='advise-substitute-popup-transfer-course-title'>
                    <td colspan='8'>
                      {$c->course_transfer->title} ({$c->course_transfer->institution_name})
                    </td>
                  </tr>";

      }



    } // while list_courses_taken

    if ($is_empty == true) 
     {
      // Meaning, there were no credits (may be the case with
      // transfer credits)
      $pC .= "<tr><td colspan='8' class=' '>
              - " . t("No substitutable credits available.") . "
            </td></tr>";
    }

    $pC .= "<tr><td colspan='4'>&nbsp;</td></tr>";
  }


  $pC .= "</table></div>
    <div class=' ' style='margin-top: 5px;'>
      " . t("Select number of hrs to use:") . "
      <select name='subHours' id='subHours' onChange='popupOnChangeSubHours()'>
        <option value=''>" . t("None Selected") . "</option>
      </select>
      ";

  // If we have entered manual hours (like for decimals), they go here:
  // The subManual span will *display* them, the hidden field keeps them so they can be transmitted.    
  $pC .= "
      <span id='subManual' style='font-style:italic; display:none;'></span>       
      <input type='hidden' id='subManualHours' value=''>

      
    </div>
    <input type='hidden' name='subTransferFlag' id='subTransferFlag' value=''>
    <input type='hidden' name='subTermID' id='subTermID' value=''>    
    <input type='button' value='Save Substitution' onClick='popupSaveSubstitution(\"$course_id\",\"$group_id\",\"$semester_num\",\"$req_by_degree_id\");'>
    
    <div class=' ' style='padding-top: 5px;'><b>" . t("Optional") . "</b> - " . t("Enter remarks:") . " 
    <input type='text' name='subRemarks' id='subRemarks' value='' size='30' maxlength='254'>
    
    </div>
    ";


  return $pC;
}