function course_search_get_offering_csv

4.x course_search.edit.inc course_search_get_offering_csv()
5.x course_search.edit.inc course_search_get_offering_csv()

File

modules/course_search/course_search.edit.inc, line 563
This file contains functions relating to editing the course info, like rotation schedule and syllabus

Code

function course_search_get_offering_csv() {
  $csv = "";
  $csv .= "SUBJ, NUM, COL, DEPT, SYL UPDATED, ";

  $catalog_year = variable_get("current_catalog_year", "");

  $course_term_array = array();
  $check_term_array = array();

  $term_array = csv_to_array(variable_get("course_search_avail_term_id_suffix_order"));

  for ($t = $catalog_year; $t <= $catalog_year + 5; $t++) 
   {
    foreach ($term_array as $x) 
     {
      $check_year = $t;

      $term_id = $check_year . $x;

      $check_term_array [] = $term_id;

      $new_course = new Course();
      $new_course->term_id = $term_id;
      $disp_name = $new_course->get_term_description(TRUE);

      $csv .= " " . $disp_name . " ($term_id) ,";

      // While we are here, we are going to get an array of ALL the courses
      // which have an entry for this term in our table.  This should make
      // it faster to look up later.
      $res = db_query("SELECT * FROM course_rotation_schedule
													WHERE `term_id`='?' ", $term_id);
      while ($cur = db_fetch_array($res)) {
        $course_term_array [$term_id][$cur ["course_id"]] = TRUE;
      }

    }
  }

  // Take off last comma of csv.
  $csv = substr($csv, 0, -1);

  //var_dump($courseTermArray);

  //debugCT($csv);

  $csv .= "\n";
  //return;

  $result = db_query("SELECT * FROM courses
                        WHERE 
                        `catalog_year`='?'                         
                        AND `delete_flag`='0'
                        AND `exclude`='0'
                        ORDER BY `subject_id`, `course_num` ", $catalog_year);
  while ($cur = db_fetch_array($result)) {
    extract($cur, 3, "db");
    //debugCT($db_subject_id . $db_course_num);

    $csv .= "$db_subject_id, $db_course_num, ";


    // What college does this course belong to?
    $res2 = db_query("SELECT * FROM subjects
                          WHERE subject_id = '?' ", $db_subject_id);
    $cur2 = db_fetch_array($res2);
    $college = $cur2 ["college"];
    $dept_name = $cur2 ["title"];

    $csv .= "$college, $dept_name, ";

    // Also, when was their last syllabus submitted?
    $syl = "";
    $res2 = db_query("SELECT * FROM course_syllabi WHERE course_id = '?'", $db_course_id);
    $cur2 = db_fetch_array($res2);
    $syl = format_date($cur2 ["posted"]);

    $csv .= "$syl, ";


    // Now, get course offerings for the next X terms...
    foreach ($check_term_array as $term_id) {
      // See if this term is offered for this course
      if ($course_term_array [$term_id][$db_course_id] == TRUE) {
        $csv .= " X,";
      }
      else {
        $csv .= ",";
      }
    }

    // Take off last comma of csv.
    $csv = substr($csv, 0, -1);
    $csv .= "\n";

  }

  header('Content-type: text/csv');
  header('Content-Disposition: attachment; filename="report_ant_offering.csv"');
  print $csv;
  die;
}