}
            if (isset($_POST["primary_ids"]) && $_POST["primary_ids"]) {
                $primary_ids = explode(",", $_POST["primary_ids"]);
                if (!is_array($primary_ids)) {
                    $primary_ids = array($_POST["primary_ids"]);
                }
            } else {
                $primary_ids = array();
            }
            if (isset($_POST["secondary_ids"]) && $_POST["secondary_ids"]) {
                $secondary_ids = explode(",", $_POST["secondary_ids"]);
                if (!is_array($secondary_ids)) {
                    $secondary_ids = array($_POST["secondary_ids"]);
                }
            } else {
                $secondary_ids = array();
            }
            if (isset($_POST["tertiary_ids"]) && $_POST["tertiary_ids"]) {
                $tertiary_ids = explode(",", $_POST["tertiary_ids"]);
                if (!is_array($tertiary_ids)) {
                    $tertiary_ids = array($_POST["tertiary_ids"]);
                }
            } else {
                $tertiary_ids = array();
            }
            list($objectives, $top_level_id) = courses_fetch_objectives($org_id, $course_ids, -1, 0, false, array("primary" => $primary_ids, "secondary" => $secondary_ids, "tertiary" => $tertiary_ids), $event_id);
            echo course_objectives_in_list($objectives, $top_level_id, $top_level_id, true, false, 1, false, true, "primary", true);
        }
    }
    exit;
}
                    ?>
 Objectives</h2>
					<div id="course-objectives-section">
					<?php 
                    if (clean_input($course_details["course_objectives"], array("notags", "nows"))) {
                        $course_objectives_section = true;
                        echo trim(strip_selected_tags($course_details["course_objectives"], array("font")));
                    }
                    ?>


					<h3>Curriculum Objectives</h3>
					<p>The learner will be able to:</p>
					<div id="objectives_list">
						<?php 
                    echo course_objectives_in_list($objectives, $top_level_id, $top_level_id);
                    ?>
					</div>
					<?php 
                    $query = "\tSELECT b.*\n\t\t\t\t\t\t\t\tFROM `course_objectives` AS a\n\t\t\t\t\t\t\t\tJOIN `global_lu_objectives` AS b\n\t\t\t\t\t\t\t\tON a.`objective_id` = b.`objective_id`\n\t\t\t\t\t\t\t\tJOIN `objective_organisation` AS c\n\t\t\t\t\t\t\t\tON b.`objective_id` = c.`objective_id`\n\t\t\t\t\t\t\t\tAND c.`organisation_id` = " . $db->qstr($ENTRADA_USER->getActiveOrganisation()) . "\n\t\t\t\t\t\t\t\tWHERE a.`objective_type` = 'event'\n                                AND a.`active` = '1'\n\t\t\t\t\t\t\t\tAND b.`objective_active` = '1'\n\t\t\t\t\t\t\t\tAND a.`course_id` = " . $db->qstr($COURSE_ID) . "\n\t\t\t\t\t\t\t\tGROUP BY b.`objective_id`\n\t\t\t\t\t\t\t\tORDER BY b.`objective_order`";
                    $results = $db->GetAll($query);
                    if ($results) {
                        ?>
					<h3>Clinical Presentations</h3>
					<ul class="objectives">
					<?php 
                        $HEAD[] = "<script type=\"text/javascript\" defer=\"defer\">Event.observe(window, 'load', function() {";
                        foreach ($results as $result) {
                            $HEAD[] = "new Control.Modal(\$('objective-" . $result["objective_id"] . "-details'), {\n                                overlayOpacity:\t0.75,\n                                closeOnClick:\t'overlay',\n                                className:\t\t'modal-description',\n                                fade:\t\t\ttrue,\n                                fadeDuration:\t0.30\n                            });";
                            if ($result["objective_name"]) {
                                ?>
                echo ENTRADA_URL;
                ?>
/api/objectives.api.php',
                        {
                            method:	'post',
                            parameters: 'course_ids=<?php 
                echo $clean_ids_str;
                ?>
&hierarchy='+hierarchy
                        }
                    );
                }
                </script>
                <?php 
                echo "<strong>The learner will be able to:</strong>";
                echo "<div id=\"objectives_list\">\n" . course_objectives_in_list($objectives, $top_level_id, $top_level_id, false, false, 1, false) . "\n</div>\n";
                break;
            case strpos($PAGE_URL, "mcc_presentations") !== false:
                $query = "\tSELECT b.*\n                            FROM `course_objectives` AS a\n                            JOIN `global_lu_objectives` AS b\n                            ON a.`objective_id` = b.`objective_id`\n                            JOIN `objective_organisation` AS c\n                            ON b.`objective_id` = c.`objective_id`\n                            WHERE a.`objective_type` = 'event'\n                            AND a.`course_id` IN (" . implode(", ", $course_ids) . ")\n                            AND b.`objective_active` = 1\n                            AND c.`organisation_id` = " . $db->qstr($ENTRADA_USER->getActiveOrganisation()) . "\n                            GROUP BY b.`objective_id`\n                            ORDER BY b.`objective_order`";
                $results = $db->GetAll($query);
                if ($results) {
                    echo "<ul class=\"objectives\">\n";
                    foreach ($results as $result) {
                        if ($result["objective_name"]) {
                            echo "<li>" . $result["objective_name"] . "</li>\n";
                        }
                    }
                    echo "</ul>\n";
                }
                break;
            case strpos($PAGE_URL, "course_assignments") !== false:
												parameters: 'course_ids=<?php 
                                echo $event_info["course_id"];
                                ?>
&hierarchy='+hierarchy+'&event_id=<?php 
                                echo $EVENT_ID;
                                ?>
'
											}
										);
									}
									</script>
									<?php 
                                echo "<div class=\"section-holder\">\n";
                                echo "\t<h3>Curriculum Objectives</h3>\n";
                                echo "\t<strong>The learner will be able to:</strong>";
                                echo course_objectives_in_list($curriculum_objectives, $top_level_id, $top_level_id, false, false, 1, true) . "\n";
                                echo "</div>\n";
                            }
                        }
                        $query = "\tSELECT a.*, COALESCE(b.`objective_details`,a.`objective_description`) AS `objective_description`, COALESCE(b.`objective_type`,c.`objective_type`) AS `objective_type`,\n                                    b.`importance`,c.`objective_details`, COALESCE(c.`eobjective_id`,0) AS `mapped`,\n                                    COALESCE(b.`cobjective_id`,0) AS `mapped_to_course`\n                                    FROM `global_lu_objectives` a\n                                    LEFT JOIN `course_objectives` b\n                                    ON a.`objective_id` = b.`objective_id`\n                                    AND b.`course_id` = " . $db->qstr($COURSE_ID) . "\n                                    AND b.`active` = '1'\n                                    LEFT JOIN `event_objectives` c\n                                    ON c.`objective_id` = a.`objective_id`\n                                    AND c.`event_id` = " . $db->qstr($EVENT_ID) . "\n                                    WHERE a.`objective_active` = '1'\n                                    AND (c.`event_id` = " . $db->qstr($EVENT_ID) . " OR b.`course_id` = " . $db->qstr($COURSE_ID) . ")\n                                    GROUP BY a.`objective_id`\n                                    ORDER BY a.`objective_id` ASC";
                        $mapped_objectives = $db->GetAll($query);
                        $explicit_event_objectives = false;
                        if ($mapped_objectives) {
                            foreach ($mapped_objectives as $objective) {
                                //if its mapped to the event, but not the course, then it belongs in the event objective list
                                if ($objective["mapped"] && !$objective["mapped_to_course"]) {
                                    if (!event_objective_parent_mapped_course($objective["objective_id"], $EVENT_ID)) {
                                        $explicit_event_objectives[] = $objective;
                                    }
                                }
                            }
/**
 *
 * @param type $objectives
 * @param type $parent_id
 * @param type $top_level_id
 * @param type $edit_importance
 * @param type $parent_active
 * @param type $importance
 * @param type $selected_only
 * @param type $top
 * @param type $display_importance
 * @param type $hierarchical
 * @return string
 */
function course_objectives_in_list($objectives, $parent_id, $top_level_id, $edit_importance = false, $parent_active = false, $importance = 1, $selected_only = false, $top = true, $display_importance = "primary", $hierarchical = true, $full_objective_list = false, $org_id = 0)
{
    global $ENTRADA_USER;
    $output = "";
    $active = array("primary" => false, "secondary" => false, "tertiary" => false);
    $org_id = $org_id == 0 ? $ENTRADA_USER->getActiveOrganisation() : (int) $org_id;
    if ($top) {
        if ($selected_only) {
            foreach ($objectives["objectives"] as $objective_id => $objective) {
                if (isset($objective["event_objective"]) && $objective["event_objective"]) {
                    if (!$active["primary"] && $objective["primary"]) {
                        $active["primary"] = true;
                    } elseif (!$active["secondary"] && $objective["secondary"]) {
                        $active["secondary"] = true;
                    } elseif (!$active["tertiary"] && $objective["tertiary"]) {
                        $active["tertiary"] = true;
                    }
                }
            }
            if (!$active["primary"]) {
                $display_importance = "secondary";
            } elseif (!$active["secondary"] && !$active["primary"]) {
                $display_importance = "tertiary";
            } elseif (!$active["tertiary"] && !$active["secondary"] && !$active["primary"]) {
                return;
            }
        } else {
            /*
            if (!empty($objectives["primary_ids"])) {
            	$active["primary"] = true;
            } elseif ($display_importance == "primary" && $active["secondary"]) {
            	$display_importance = "secondary";
            }
            if (!empty($objectives["secondary_ids"])) {
            	$active["secondary"] = true;
            } elseif ($display_importance == "secondary" && $active["tertiary"]) {
            	$display_importance = "tertiary";
            }
            if (!empty($objectives["tertiary_ids"])) {
            	$active["tertiary"] = true;
            }
            */
            if ($objectives["primary_ids"]) {
                $active["primary"] = true;
                $display_importance = "primary";
            }
            if ($objectives["secondary_ids"]) {
                $active["secondary"] = true;
                if (empty($objectives["primary_ids"])) {
                    $display_importance = "secondary";
                }
            }
            if ($objectives["tertiary_ids"]) {
                $active["tertiary"] = true;
                if (empty($objectives["primary_ids"]) && empty($objectives["secondary_ids"])) {
                    $display_importance = "tertiary";
                }
            }
        }
        $objectives = $objectives["objectives"];
        if ($display_importance == "primary" && !$active["primary"]) {
            return;
        }
    }
    if (!$full_objective_list) {
        $full_objective_list = events_fetch_objectives_structure($parent_id, $objectives["used_ids"], $org_id);
    }
    $flat_objective_list = events_flatten_objectives($full_objective_list);
    if (is_array($objectives) && count($objectives)) {
        if ((isset($objectives[$parent_id]) && count($objectives[$parent_id]["parent_ids"]) || $hierarchical && (!$selected_only || isset($objective["event_objective"]) && $objective["event_objective"] && (isset($objective[$display_importance]) && $objective[$display_importance]))) && (!isset($objectives[$parent_id]["parent_ids"]) || count($objectives[$parent_id]["parent_ids"]) < 3)) {
            $output .= "\n<ul class=\"objective-list\" id=\"objective_" . $parent_id . "_list\"" . (count($objectives[$parent_id]["parent_ids"]) < 2 && !$hierarchical || $hierarchical && $parent_id == $top_level_id ? " style=\"padding-left: 0; margin-top: 0\"" : "") . ">\n";
        }
        $iterated = false;
        do {
            if ($iterated) {
                if ($display_importance == "primary" && $active["secondary"]) {
                    $display_importance = "secondary";
                } elseif (($display_importance == "secondary" || $display_importance == "primary") && $active["tertiary"]) {
                    $display_importance = "tertiary";
                }
            }
            if ($flat_objective_list && is_array($flat_objective_list)) {
                if ($top) {
                    $output .= "<h2" . ($iterated && !$hierarchical ? " class=\"collapsed\"" : "") . " title=\"" . ucwords($display_importance) . " Objectives\">" . ucwords($display_importance) . " Objectives</h2>\n";
                    $output .= "<div id=\"" . $display_importance . "-objectives\">\n";
                }
                foreach ($flat_objective_list as $objective_id => $objective_active) {
                    $objective = $objectives[$objective_id];
                    if ($objective["parent"] == $parent_id && (($objective["objective_" . $display_importance . "_children"] || (isset($objective[$display_importance]) && $objective[$display_importance] || $parent_active)) && !$selected_only || $selected_only && isset($objective["event_objective"]) && $objective["event_objective"] && (isset($objective[$display_importance]) && $objective[$display_importance]))) {
                        $importance = isset($objective["primary"]) && $objective["primary"] ? 1 : (isset($objective["secondary"]) && $objective["secondary"] ? 2 : (isset($objective["tertiary"]) && $objective["tertiary"] ? 3 : $importance));
                        $output .= "<li" . (($parent_active || isset($objective[$display_importance]) && $objective[$display_importance]) && count($objective["parent_ids"]) > 2 ? " class=\"\"" : "") . " id=\"objective_" . $objective_id . "_row\">\n";
                        if ($edit_importance && (isset($objective[$display_importance]) && $objective[$display_importance])) {
                            $output .= "<select onchange=\"javascript: moveObjective('" . $objective_id . "', this.value);\" style=\"float: right; margin: 5px\">\n";
                            $output .= "\t<option value=\"primary\"" . ($objective["primary"] ? " selected=\"selected\"" : "") . ">Primary</option>\n";
                            $output .= "\t<option value=\"secondary\"" . ($objective["secondary"] ? " selected=\"selected\"" : "") . ">Secondary</option>\n";
                            $output .= "\t<option value=\"tertiary\"" . ($objective["tertiary"] ? " selected=\"selected\"" : "") . ">Tertiary</option>\n";
                            $output .= "</select>";
                        }
                        if (count($objective["parent_ids"]) == 3) {
                            $output .= "\t<div><div class=\"objective-title\">" . $objective["name"] . "</div>";
                            $output .= "\t<div class=\"objective-description content-small\">" . (isset($objective["objective_details"]) && $objective["objective_details"] ? $objective["objective_details"] : $objective["description"]) . "</div>";
                        } else {
                            $output .= "\t<div class=\"objective-title\" id=\"objective_" . $objective_id . "\">" . $objective["name"] . "</div>\n";
                            $output .= "\t<div class=\"objective-description content-small\">" . (isset($objective["objective_details"]) && $objective["objective_details"] ? $objective["objective_details"] : $objective["description"]);
                        }
                        if (isset($objective["event_objective_details"]) && $objective["event_objective_details"]) {
                            $output .= "\t<div class=\"objective-description content-small\"><em>" . $objective["event_objective_details"] . "</em></div>";
                        }
                        $output .= "\t</div>";
                        $output .= "</li>";
                    }
                    if ($objective["parent"] == $parent_id) {
                        $output .= course_objectives_in_list($objectives, $objective_id, $top_level_id, $edit_importance, isset($objective[$display_importance]) && $objective[$display_importance] || $parent_active ? true : false, $importance, $selected_only, false, $display_importance, $hierarchical, $full_objective_list);
                    }
                }
                if ($top) {
                    $output .= "</div>\n";
                }
            }
            $iterated = true;
        } while ($display_importance != "tertiary" && ($display_importance != "secondary" || $active["tertiary"]) && ($display_importance != "primary" || $active["secondary"] || $active["tertiary"]) && $top);
        if ((isset($objectives[$parent_id]) && count($objectives[$parent_id]["parent_ids"]) || $hierarchical && (!$selected_only || isset($objective["event_objective"]) && $objective["event_objective"] && (isset($objective[$display_importance]) && $objective[$display_importance]))) && (!isset($objectives[$parent_id]["parent_ids"]) || count($objectives[$parent_id]["parent_ids"]) < 3)) {
            $output .= "</ul>";
        }
    }
    return $output;
}
         }
         $eventtypes_html .= "</tbody>";
         $eventtypes_html .= "<tfoot>";
         $eventtypes_html .= "<tr>";
         $eventtypes_html .= "<td><strong>Totals</strong></td>";
         $eventtypes_html .= "<td><strong>" . $result["total_events"] . "</strong></td>";
         $eventtypes_html .= "<td><strong>" . display_hours($result["total_duration"]) . " hrs</strong></td>";
         $eventtypes_html .= "</tr>";
         $eventtypes_html .= "</tfoot>";
         $eventtypes_html .= "</table>";
     }
 }
 $ENTRADA_USER = new User();
 $ENTRADA_USER->setActiveOrganisation($org_id);
 list($objectives, $top_level_id) = courses_fetch_objectives($org_id, array($course->getID()), -1, 1, false);
 $pages_html["course_objectives"] = course_objectives_in_list($objectives, $top_level_id, $top_level_id, false, false, 1, false);
 if ($objectives) {
     $pages_html["course_objectives"] = "<h1>Course Objectives</h1>" . $pages_html["course_objectives"];
 } else {
     unset($pages_html["course_objectives"]);
 }
 /* Gradebook */
 $query = "\tSELECT a.`course_id`, a.`assessment_id`, a.`name`, a.`grade_weighting`, a.`order`, c.`title`\n\t\t\t\t\t\t\t\t\tFROM `assessments` AS a\n\t\t\t\t\t\t\t\t\tJOIN `course_audience` AS b\n\t\t\t\t\t\t\t\t\tON a.`course_id` = b.`course_id`\n\t\t\t\t\t\t\t\t\tAND a.`cohort` = b.`audience_value`\n\t\t\t\t\t\t\t\t\tJOIN `assessments_lu_meta` AS c\n\t\t\t\t\t\t\t\t\tON `a`.`characteristic_id` = c.`id`\n\t\t\t\t\t\t\t\t\tWHERE a.`course_id` = " . $db->qstr($course->getID()) . "\n\t\t\t\t\t\t\t\t\tAND a.`active` = 1";
 $results = $db->GetArray($query);
 $gradebook_html = "";
 if ($results) {
     $gradebook_html = "<h1>Gradebook</h1>";
     $query = "\tSELECT a.`course_id`, SUM(a.`grade_weighting`) AS `grade_weighting` \n\t\t\t\t\t\t\t\t\t\tFROM `assessments` AS a\n\t\t\t\t\t\t\t\t\t\tJOIN `course_audience` AS b\n\t\t\t\t\t\t\t\t\t\tON a.`course_id` = b.`course_id`\n\t\t\t\t\t\t\t\t\t\tAND a.`cohort` = b.`audience_value`\n\t\t\t\t\t\t\t\t\t\tWHERE a.`course_id` = " . $db->qstr($course->getID()) . "\n\t\t\t\t\t\t\t\t\t\tAND a.`active` = 1";
     $total_grade_weights = $db->GetAll($query);
     foreach ($results as $result) {
         $query = "\tSELECT a.`objective_type`, b.`objective_name`\n\t\t\t\t\t\t\t\t\t\t\tFROM `assessment_objectives` AS a\n\t\t\t\t\t\t\t\t\t\t\tJOIN `global_lu_objectives` AS b\n\t\t\t\t\t\t\t\t\t\t\tON a.`objective_id` = b.`objective_id`\n\t\t\t\t\t\t\t\t\t\t\tWHERE a.`assessment_id` = " . $db->qstr($result["assessment_id"]) . "\n\t\t\t\t\t\t\t\t\t\t\tORDER BY a.`objective_type`";