}
 }
 $all_objectives = array_merge($PRIMARY_OBJECTIVES, $SECONDARY_OBJECTIVES, $TERTIARY_OBJECTIVES);
 $active_objectives = Models_Course_Objective::fetchAllByCourseID($COURSE_ID, "course");
 if ($active_objectives) {
     // deactivate the objectives that have been removed.
     foreach ($active_objectives as $objective) {
         if (!in_array($objective->getObjectiveID(), $all_objectives)) {
             $objective->fromArray(array("active" => "0", "objective_finish" => time()))->update();
         }
     }
 }
 $objectives_added = 0;
 if (!empty($all_objectives)) {
     foreach ($all_objectives as $objective_id) {
         $course_objective = new Models_Course_Objective(array("course_id" => $COURSE_ID, "objective_id" => $objective_id, "importance" => $objective_importance[$objective_id], "objective_type" => "course", "objective_details" => $objective_details[$objective_id]["details"], "objective_start" => time(), "objective_finish" => NULL, "updated_date" => time(), "updated_by" => $ENTRADA_USER->getID(), "active" => "1"));
         if ($course_objective->insert()) {
             $objectives_added++;
         }
     }
 }
 if (isset($PROCESSED["course_report_ids"]) && count($PROCESSED["course_report_ids"]) > 0) {
     //remove existing course_reports for this course before adding the new set of course reports.
     $query = "DELETE FROM `course_reports` WHERE `course_id` = " . $db->qstr($COURSE_ID);
     if (!$db->Execute($query)) {
         add_error("An error occurred while editing course reports.  The system administrator was informed of this error; please try again later.");
         application_log("error", "Error inserting course reports for course id: " . $COURSE_ID);
     }
     if (!has_error()) {
         foreach ($PROCESSED["course_report_ids"] as $index => $course_report_id) {
             $PROCESSED["course_report_id"] = $course_report_id;
 }
 if (is_array($PRIMARY_OBJECTIVES) && count($PRIMARY_OBJECTIVES)) {
     foreach ($PRIMARY_OBJECTIVES as $objective_id) {
         $objective = new Models_Course_Objective(array("course_id" => $COURSE_ID, "objective_id" => $objective_id, "importance" => "1", "objective_type" => "course", "objective_start" => time(), "objective_finish" => NULL, "updated_date" => time(), "updated_by" => $ENTRADA_USER->getID(), "active" => "1"));
         $objective->insert();
     }
 }
 if (is_array($SECONDARY_OBJECTIVES) && count($SECONDARY_OBJECTIVES)) {
     foreach ($SECONDARY_OBJECTIVES as $objective_id) {
         $objective = new Models_Course_Objective(array("course_id" => $COURSE_ID, "objective_id" => $objective_id, "importance" => "2", "objective_type" => "course", "objective_start" => time(), "objective_finish" => NULL, "updated_date" => time(), "updated_by" => $ENTRADA_USER->getID(), "active" => "1"));
         $objective->insert();
     }
 }
 if (is_array($TERTIARY_OBJECTIVES) && count($TERTIARY_OBJECTIVES)) {
     foreach ($TERTIARY_OBJECTIVES as $objective_id) {
         $objective = new Models_Course_Objective(array("course_id" => $COURSE_ID, "objective_id" => $objective_id, "importance" => "3", "objective_type" => "course", "objective_start" => time(), "objective_finish" => NULL, "updated_date" => time(), "updated_by" => $ENTRADA_USER->getID(), "active" => "1"));
         $objective->insert();
     }
 }
 if (isset($PROCESSED["periods"]) && is_array($PROCESSED["periods"]) && $PROCESSED["periods"]) {
     foreach ($PROCESSED["periods"] as $period_id => $period) {
         foreach ($period as $key => $audience) {
             $audience["course_id"] = $COURSE_ID;
             if (!$db->AutoExecute("course_audience", $audience, "INSERT")) {
                 add_error("An error occurred while adding the student with id " . $member . " as an audience member.");
             }
         }
     }
 }
 if (isset($PROCESSED["course_report_ids"]) && count($PROCESSED["course_report_ids"]) > 0) {
     foreach ($PROCESSED["course_report_ids"] as $index => $course_report_id) {