admin_display_courses

5.x admin.courses.inc admin_display_courses()
4.x admin.courses.inc admin_display_courses()

This function displays all of our courses for us to edit.

File

modules/admin/admin.courses.inc, line 9

Code

function admin_display_courses() {
  $rtn = "";


  // Do this using $render array, so it can be altered
  // by hook_content_alter
  $render = array();
  $render['#id'] = 'admin_display_courses';




  $de_catalog_year = admin_get_de_catalog_year();

  fp_add_css(fp_get_module_path("admin") . "/css/admin.css");

  $cc = 1;

  $show_hidden = trim(@$_GET["show_hidden"]);
  if ($show_hidden != "") {
    $_SESSION["dehidden"] = $show_hidden;
  }
  else {
    $show_hidden = @$_SESSION["dehidden"];
  }

  // Get the "upper range" (UR) and
  // lower range (LR) of the courses in question...
  $ur = trim(@$_GET["ur"]);
  $lr = trim(@$_GET["lr"]);
  if ($ur == "") {
    // meaning, no range was set.  Use A - AZZZZZ, so, all of the A's.
    $ur = @$_SESSION["dec_ur"];
    $lr = @$_SESSION["dec_lr"];
    if ($ur == "") {
      // if still blank, assign it..
      $ur = "A";
      $lr = "AZZZZ";
    }

  }
  $_SESSION["dec_ur"] = $ur;
  $_SESSION["dec_lr"] = $lr;


  //fp_set_title(t("Courses for @year", array("@year" => $de_catalog_year)));

  $render['title_top'] = array(
    'value' => "<h2 class='title'>" . t("Courses for @year", array("@year" => $de_catalog_year)) . "</h2>",
  );




  $html = "";

  $letter_ranges = array(
    "A" => array("A", "AZZZZ"),
    "B" => array("B", "BZZZZ"),
    "C-CN" => array("C", "CNZZZ"),
    "CO-CZ" => array("CO", "CZZZZ"),
    "D" => array("D", "DZZZZ"),
    "E" => array("E", "EZZZZ"),
    "F" => array("F", "FZZZZ"),
    "G" => array("G", "GZZZZ"),
    "H" => array("H", "HZZZZ"),
    "I-L" => array("I", "LZZZZ"),
    "M-MR" => array("M", "MRZZZ"),
    "MS-MZ" => array("MS", "MZZZZ"),
    "N-O" => array("N", "OZZZZ"),
    "P" => array("P", "PZZZZ"),
    "Q-R" => array("Q", "RZZZZ"),
    "S-SO" => array("S", "SOZZZ"),
    "SP-SZ" => array("SP", "SZZZZ"),
    "T-Z" => array("T", "ZZZZZ"),
  );


  $html .= "<div class='admin-courses-select-letter-bar'>
          ";
  foreach ($letter_ranges as $disp => $vals) {
    $html .= l($disp, "admin/courses", "de_catalog_year=$de_catalog_year&ur=" . $vals[0] . "&lr=" . $vals[1], array("class" => "admin-courses-letter-link")) . " &nbsp; ";
  }

  $html .= "</div>                       
        <div class='tenpt'>             
        <div style='padding: 5px;'>          
        " . l(t("Add a course for @year", array("@year" => $de_catalog_year)), "admin/courses/edit-course", "course_id=new&de_catalog_year=$de_catalog_year") . "
        </div>          
                       Legend:  <br>&nbsp; &nbsp;[e] = Course has at least one add'l excluded name.  
                            &nbsp; &nbsp;[v] = Course has at least one add'l valid name.
                            
         </div>

         ";

  $exclude_line = "and exclude != 1";
  if ($show_hidden == "yes") {
    $html .= "<div class='tenpt'><b>" . t("Showing excluded courses.") . " ";
    $html .= l(t("Hide?"), "admin/courses", "de_catalog_year=$de_catalog_year&show_hidden=no");
    $html .= "</b></div>";
    $exclude_line = "";

  }
  else {
    $html .= "<div class='tenpt'><b>" . t("Hiding excluded courses.") . " ";
    $html .= l(t("Show?"), "admin/courses", "de_catalog_year=$de_catalog_year&show_hidden=yes");
    $html .= "</b></div>";
  }

  $html .= "<hr><br>";



  $render['upper_links'] = array(
    'value' => $html,
  );



  $render['courses_table_top'] = array(
    'value' => "<table border='0' cellpadding='3' cellspacing='0' class='disp-courses-table'>",
  );


  $q = "SELECT * FROM draft_courses
                        WHERE 
                          catalog_year = '?'
                          AND subject_id BETWEEN '?' AND '?'
                          AND delete_flag = '0'
                          $exclude_line
                        ORDER BY subject_id, course_num";
  $result = db_query($q, $de_catalog_year, $ur, $lr);
  while ($cur = db_fetch_array($result)) {
    extract($cur, 3, "db");

    $ex_names = "";
    $val_names = "";
    // Check to see if this course has more than one name...
    // removed AND `catalog_year`='$de_catalog_year' from query,
    // because we don't care what other cat year it came from.
    $res2 = db_query("SELECT * FROM draft_courses
                  WHERE course_id = '?'
                    ", $db_course_id);
    while ($cur2 = db_fetch_array($res2)) {
      if ($cur2["subject_id"] == $db_subject_id && $cur2["course_num"] == $db_course_num) {
        continue;
      }

      if ($cur2["exclude"] == "1") {
        $ex_names = "[e]";
      }
      else {
        $val_names = "[v]";
      }

    }


    $spanstyle = "";

    if ($db_exclude == "1") {
      $spanstyle = "background-color: #ddd;";
    }

    $temp_course = new Course();
    $db_title = $temp_course->fix_title($db_title);

    $db_min_hours = $db_min_hours * 1;
    $db_max_hours = $db_max_hours * 1;
    $db_repeat_hours = $db_repeat_hours * 1;

    $hrs = $db_min_hours;
    if (trim($db_min_hours) != trim($db_max_hours)) {
      $hrs .= " - $db_max_hours";
    }

    $hrs .= " hrs.";

    $rep_hours = "";
    if ($db_repeat_hours > $db_min_hours) {
      $rep_hours = " rep to $db_repeat_hours hrs.";
    }

    // remove special chars from subject_id...
    $display_subject_id = $db_subject_id;
    $db_subject_id = str_replace("&", "_A_", $db_subject_id);

    $render['course_row_' . $db_course_id] = array(
      'value' => "
                    <tr style='$spanstyle'>
                      <td valign='top' width='90%'>
                          <a name='course_$db_course_id'></a>
                          <div style='$spanstyle padding:3px;'>
    
           " . l("$display_subject_id $db_course_num - $db_title", "admin/courses/edit-course", "course_id=$db_course_id&subject_id=$db_subject_id&course_num=$db_course_num&de_catalog_year=$de_catalog_year") . " - $hrs$rep_hours</div>

                  </td>
                  <td valign='top' width='5%'>
                      $ex_names
                  </td>
                  
                  <td valign='top' width='5%'>
                        $val_names
                  </td>
                </tr>",
      'data' => array(
        'course_id' => $db_course_id,
        'catalog_year' => $de_catalog_year,
        'db_row' => $cur,
        'subject_id' => $db_subject_id,
        'course_num' => $db_course_num,
      ),
    );





  } // while


  $render['courses_table_bottom'] = array(
    'value' => "</table>",
  );




  $rtn .= fp_render_content($render);


  return $rtn;

}