function stats_report_course_use_summary

7.x stats.module stats_report_course_use_summary()
6.x stats.module stats_report_course_use_summary()
5.x stats.module stats_report_course_use_summary()

This report will display everywhere a particular course is used in FlightPath (groups and degrees)

File

modules/stats/stats.module, line 333
This module displays statistics and reports for FlightPath

Code

function stats_report_course_use_summary() {
  $rtn = "";

  $draft = "";
  $use_draft = FALSE;

  $school_id = 0; // TODO: school is selectable / based on user's school?

  $subject_id = $course_num = $draft_check = "";

  if (isset($_GET ["subject_id"])) {
    $subject_id = trim($_GET ["subject_id"]);
    $course_num = trim($_GET ["course_num"]);
    // $school_id = intval($_GET["school_id"]);  // TODO: not supported yet.
    if (isset($_GET ['draft'])) {
      $draft_check = $_GET ["draft"];
    }
  }

  if ($draft_check == "checked") {
    $draft = "draft_";
    $use_draft = TRUE;
  }

  $rtn .= "<form action='" . fp_url("stats/reports/course-use-summary") . "' method='GET' >";
  $rtn .= "Please enter a course's subject ID and course number to search:<br>";

  if (module_enabled("schools")) {
    $options = schools_get_schools_for_fapi();
    $rtn .= "<select name='school_id'>";
    foreach ($options as $k => $v) {
      $sel = "";
      if (intval($k) === $school_id) {
        $sel = "selected";
      }
      $rtn .= "<option value='$k' $sel>" . t("School: ") . $v . "</option>";
    }
    $rtn .= "</select> &nbsp; ";
  }


  $rtn .= " 
            <input type='text' name='subject_id' placeholder='Subject ID' size='10' value='$subject_id'> &nbsp;
            <input type='text' name='course_num' placeholder='Course Num' size='10' value='$course_num'> &nbsp;
            <input type='checkbox' name='draft' value='checked' $draft_check>Check draft tables? &nbsp;
            <input type='submit' value='Search'>
            <br><b>Note:</b> This may take up to a minute to run, please be patient.";

  $rtn .= "</form>";

  if ($subject_id && $course_num) {
    $rtn .= "<hr>";

    // First, look up this course's ID.
    $db = get_global_database_handler();
    $course_id = $db->get_course_id($subject_id, $course_num, '', $use_draft, $school_id);

    if ($course_id) {
      $rtn .= "<h2>Course $subject_id $course_num (id is $course_id)</h2>";

      // Groups
      $rtn .= "<div><b>Groups:</b></div>
                <table border='1'>
                  <tr>
                    <th>ID</th>
                    <th>Name</th>
                    <th>Title</th>
                    <th>Year</th>
                    
                  </tr>";
      $res = db_query("SELECT * FROM {$draft}group_requirements WHERE course_id = ?
                        order by `id`", $course_id);
      while ($cur = db_fetch_array($res)) {
        $group_id = $cur ["group_id"];
        $group = new Group($group_id, $db, -1, false, $use_draft);
        if (!$group->title) {
          // This is possibly a child group.  Look for its parent.
          $res2 = db_query("SELECT * FROM {$draft}group_requirements WHERE child_group_id = ?", $group_id);
          $cur2 = db_fetch_array($res2);
          if ($cur2 ["group_id"] != "") {
            $group_id = $cur2 ["group_id"];
            $group = new Group($group_id, $db, -1, false, $use_draft);
          }
        }
        $rtn .= "<tr>
                    <td>$group_id</td>
                    <td>$group->group_name</td>
                    <td>$group->title</td>
                    <td>$group->catalog_year</td>
                  </tr>";
      }
      $rtn .= "</table>";

      // Now, look for degrees...

      $rtn .= "<br><br><br>
                <b>Degrees:</b>
               <table border='1'>
               <tr>
                <th>ID</th>
                <th>Title</th>
                <th>MAJR</th>
                <th>Track</th>
                <th>Sem</th>
                <th>Year</th>
               </tr>";

      $res = db_query("SELECT * FROM {$draft}degree_requirements WHERE course_id = ? ORDER BY `id`", $course_id);
      while ($cur = db_fetch_array($res)) {
        $degree_id = $cur ["degree_id"];
        $degree = new DegreePlan($degree_id, $db, TRUE, FALSE, $use_draft);

        $rtn .= "<tr>
                    <td>$degree_id</td>
                    <td>$degree->title</td>
                    <td>$degree->major_code</td>
                    <td>$degree->track_code</td>
                    <td>" . $cur ["semester_num"] . "</td>
                    <td>$degree->catalog_year</td>
                  </tr>";
      }



      $rtn .= '</table>';

    } // if course_id
    else {
      $rtn .= "<div>Course could not be found.  Check spelling.";
    }

  }


  watchdog('stats', "report_course_use_summary subject_id:$subject_id, course_num:$course_num, school_id:$school_id, draft_check:$draft_check", array());


  return $rtn;

}