$course_details = $db->GetRow($query);
 if ($course_details && $ENTRADA_ACL->amIAllowed(new CourseResource($course_details["course_id"], $course_details["organisation_id"]), "update")) {
     $HEAD[] = "<script type=\"text/javascript\">var SITE_URL = '" . ENTRADA_URL . "';</script>";
     $HEAD[] = "<script type=\"text/javascript\">var DELETE_IMAGE_URL = '" . ENTRADA_URL . "/images/minus-sign.png';</script>";
     $HEAD[] = "<script type=\"text/javascript\" src=\"" . ENTRADA_URL . "/javascript/picklist.js\"></script>\n";
     $HEAD[] = "<script type=\"text/javascript\" src=\"" . ENTRADA_URL . "/javascript/AutoCompleteList.js?release=" . html_encode(APPLICATION_VERSION) . "\"></script>";
     $HEAD[] = "<script type=\"text/javascript\" src=\"" . ENTRADA_URL . "/javascript/objectives.js?release=" . html_encode(APPLICATION_VERSION) . "\"></script>";
     $HEAD[] = "<script type=\"text/javascript\" src=\"" . ENTRADA_URL . "/javascript/objectives_course.js?release=" . html_encode(APPLICATION_VERSION) . "\"></script>";
     $HEAD[] = "<script type=\"text/javascript\" src=\"" . ENTRADA_URL . "/javascript/keywords_course.js?release=" . html_encode(APPLICATION_VERSION) . "\"></script>";
     $BREADCRUMB[] = array("url" => ENTRADA_URL . "/admin/" . $MODULE . "?" . replace_query(array("section" => "edit", "id" => $COURSE_ID, "step" => false)), "title" => "Editing " . $module_singular_name);
     /**
      * Fetch the Clinical Presentation details.
      */
     $clinical_presentations_list = array();
     $clinical_presentations = array();
     $results = fetch_clinical_presentations();
     if ($results) {
         foreach ($results as $result) {
             $clinical_presentations_list[$result["objective_id"]] = $result["objective_name"];
         }
     } else {
         $clinical_presentations_list = false;
     }
     if (isset($_POST["clinical_presentations"]) && is_array($_POST["clinical_presentations"]) && count($_POST["clinical_presentations"])) {
         foreach ($_POST["clinical_presentations"] as $objective_id) {
             if ($objective_id = clean_input($objective_id, array("trim", "int"))) {
                 $query = "SELECT a.`objective_id`\n\t\t\t\t\t\t\t\t\t\tFROM `global_lu_objectives` AS a\n\t\t\t\t\t\t\t\t\t\tJOIN `objective_organisation` AS b\n\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\tWHERE a.`objective_id` = " . $db->qstr($objective_id) . "\n\t\t\t\t\t\t\t\t\t\tAND b.`organisation_id` = " . $db->qstr($ENTRADA_USER->getActiveOrganisation()) . "\n\t\t\t\t\t\t\t\t\t\tORDER BY a.`objective_order` ASC";
                 $result = $db->GetRow($query);
                 if ($result) {
                     $clinical_presentations[$objective_id] = $clinical_presentations_list[$objective_id];
                 }
                     $associated_proxy_ids[] = (int) $result["audience_value"];
                     break;
                 case "organisation_id":
                     $query = "SELECT `organisation_title` FROM `" . AUTH_DATABASE . "`.`organisations` WHERE `organisation_id` = " . $db->qstr($result["audience_value"]);
                     $associated_organisation = $db->GetOne($query);
                     break;
             }
         }
     }
 }
 /**
  * Fetch the Clinical Presentation details.
  */
 $clinical_presentations_list = array();
 $clinical_presentations = array();
 $results = fetch_clinical_presentations(0, array(), $event_info["course_id"]);
 if ($results) {
     foreach ($results as $result) {
         $clinical_presentations_list[$result["objective_id"]] = $result["objective_name"];
     }
 }
 if (isset($_POST["clinical_presentations"]) && is_array($_POST["clinical_presentations"]) && count($_POST["clinical_presentations"])) {
     foreach ($_POST["clinical_presentations"] as $objective_id) {
         if ($objective_id = clean_input($objective_id, array("trim", "int"))) {
             $query = "\tSELECT a.`objective_id`\n                                    FROM `global_lu_objectives` AS a\n                                    JOIN `course_objectives` AS b\n                                    ON b.`course_id` = " . $event_info["course_id"] . "\n                                    AND a.`objective_id` = b.`objective_id`\n                                    JOIN `objective_organisation` AS c\n                                    ON a.`objective_id` = c.`objective_id`\n                                    WHERE a.`objective_id` = " . $db->qstr($objective_id) . "\n                                    AND c.`organisation_id` = " . $db->qstr($ENTRADA_USER->getActiveOrganisation()) . "\n                                    AND b.`objective_type` = 'event'\n                                    AND a.`objective_active` = '1'\n                                    AND b.`active` = '1'";
             $result = $db->GetRow($query);
             if ($result) {
                 $clinical_presentations[$objective_id] = $clinical_presentations_list[$objective_id];
             }
         }
     }
 $output = array();
 $appendix = array();
 $courses_included = array();
 $eventtype_legend = array();
 echo "<h2 style=\"page-break-before: avoid\">Curriculum Review Report</h2>";
 echo "<div class=\"content-small\" style=\"margin-bottom: 10px\">\n";
 echo "\t<strong>Date Range:</strong> " . date(DEFAULT_DATE_FORMAT, $_SESSION[APPLICATION_IDENTIFIER][$MODULE]["reporting_start"]) . " <strong>to</strong> " . date(DEFAULT_DATE_FORMAT, $_SESSION[APPLICATION_IDENTIFIER][$MODULE]["reporting_finish"]) . ".";
 echo "</div>\n";
 if ($_SESSION[APPLICATION_IDENTIFIER][$MODULE]["organisation_id"] != -1) {
     $organisation_where = " AND (b.`organisation_id` = " . $_SESSION[APPLICATION_IDENTIFIER][$MODULE]["organisation_id"] . ")";
 } else {
     $organisation_where = "";
 }
 $eventtype_legend[$event_type["eventtype_id"]] = $event_type["eventtype_title"];
 $presentation_ids = array();
 $mcc_presentations = fetch_clinical_presentations(309);
 if ($mcc_presentations) {
     foreach ($mcc_presentations as $mcc_presentation) {
         $presentation_ids[] = $mcc_presentation["objective_id"];
     }
 }
 foreach ($_SESSION[APPLICATION_IDENTIFIER][$MODULE]["course_ids"] as $course_id) {
     $query = "\tSELECT a.`event_id`, b.`course_name`, b.`organisation_id`, a.`event_title`, a.`event_objectives`, a.`event_description`\n\t\t\t\t\t\tFROM `events` AS a\n\t\t\t\t\t\tLEFT JOIN `courses` AS b\n\t\t\t\t\t\tON b.`course_id` = a.`course_id`\n\t\t\t\t\t\tWHERE (a.`event_start` BETWEEN " . $db->qstr($_SESSION[APPLICATION_IDENTIFIER][$MODULE]["reporting_start"]) . " AND " . $db->qstr($_SESSION[APPLICATION_IDENTIFIER][$MODULE]["reporting_finish"]) . ")\n\t\t\t\t\t\tAND a.`course_id` = " . $db->qstr($course_id) . $organisation_where . ($show_children == false ? "AND (a.`parent_id` IS NULL OR a.`parent_id` = '0')" : "") . "\n\t\t\t\t\t\tORDER BY a.`event_start` ASC";
     $results = $db->CacheGetAll(LONG_CACHE_TIMEOUT, $query);
     if ($results) {
         $courses_included[$course_id] = $course_list[$course_id]["code"] . " - " . $course_list[$course_id]["name"];
         foreach ($results as $result) {
             $output[$course_id][] = $result;
             if (!isset($appendix[$course_id][$result["event_id"]])) {
                 $appendix[$course_id][$result["event_id"]] = $result;
             }
     if ($curriculum_types) {
         foreach ($curriculum_types as $curriculum_type) {
             if (isset($_SESSION[APPLICATION_IDENTIFIER]["events"]["filters"]["term"]) && is_array($_SESSION[APPLICATION_IDENTIFIER]["events"]["filters"]["term"]) && in_array($curriculum_type["curriculum_type_id"], $_SESSION[APPLICATION_IDENTIFIER]["events"]["filters"]["term"])) {
                 $checked = "checked=\"checked\"";
             } else {
                 $checked = "";
             }
             $terms[$ENTRADA_USER->getActiveOrganisation()]["options"][] = array("text" => $curriculum_type["curriculum_type_name"], "value" => "term_" . $curriculum_type["curriculum_type_id"], "checked" => $checked);
         }
     }
     echo lp_multiple_select_popup("term", $terms, array("title" => "Select Terms:", "submit_text" => "Apply", "cancel" => true, "submit" => true));
     break;
 case "cp":
     // Clinical Presentations aka MCC Presentations or Objectives.
     $presentations = $organisation;
     $clinical_presentations = fetch_clinical_presentations();
     if ($clinical_presentations) {
         foreach ($clinical_presentations as $clinical_presentation) {
             if (isset($_SESSION[APPLICATION_IDENTIFIER]["events"]["filters"]["cp"]) && is_array($_SESSION[APPLICATION_IDENTIFIER]["events"]["filters"]["cp"]) && in_array($clinical_presentation["objective_id"], $_SESSION[APPLICATION_IDENTIFIER]["events"]["filters"]["cp"])) {
                 $checked = "checked=\"checked\"";
             } else {
                 $checked = "";
             }
             $presentations[$ENTRADA_USER->getActiveOrganisation()]["options"][] = array("text" => $clinical_presentation["objective_name"], "value" => "cp_" . $clinical_presentation["objective_id"], "checked" => $checked);
         }
     }
     echo lp_multiple_select_popup("cp", $presentations, array("title" => "Select Clinical Presentations:", "submit_text" => "Apply", "cancel" => true, "submit" => true));
     break;
 case "co":
     // Curriculum Objectives
     $objectives = $organisation;
function fetch_clinical_presentations($parent_id = 0, $presentations = array(), $course_id = 0, $presentation_ids = false, $org_id = 0)
{
    global $db, $ENTRADA_USER, $translate;
    $parent_id = (int) $parent_id;
    $course_id = (int) $course_id;
    $org_id = $org_id == 0 ? $ENTRADA_USER->getActiveOrganisation() : (int) $org_id;
    if ($course_id) {
        $presentation_ids = array();
        $query = "\tSELECT `objective_id`\n\t\t\t\t\tFROM `course_objectives`\n\t\t\t\t\tWHERE `course_id` = " . $db->qstr($course_id) . "\n\t\t\t\t\tAND `objective_type` = 'event'\n                    AND `active` = '1'";
        $allowed_objectives = $db->GetAll($query);
        if ($allowed_objectives) {
            foreach ($allowed_objectives as $presentation) {
                $presentation_ids[] = $presentation["objective_id"];
            }
        }
    }
    if ($parent_id) {
        $query = "\tSELECT a.*\n\t\t\t\t\tFROM `global_lu_objectives` AS a\n\t\t\t\t\tJOIN `objective_organisation` AS b\n\t\t\t\t\tON a.`objective_id` = b.`objective_id`\n\t\t\t\t\tWHERE `objective_active` = '1'\n\t\t\t\t\tAND `objective_parent` = " . $db->qstr($parent_id) . "\n\t\t\t\t\tAND b.`organisation_id` = " . $db->qstr($org_id);
    } else {
        $objective_name = $translate->_("events_filter_controls");
        $objective_name = $objective_name["cp"]["global_lu_objectives_name"];
        $query = "\tSELECT a.*\n\t\t\t\t\tFROM `global_lu_objectives` AS a\n\t\t\t\t\tJOIN `objective_organisation` AS b\n\t\t\t\t\tON a.`objective_id` = b.`objective_id`\n\t\t\t\t\tWHERE a.`objective_active` = '1'\n\t\t\t\t\tAND b.`organisation_id` = " . $db->qstr($org_id) . "\n\t\t\t\t\tAND a.`objective_name` = " . $db->qstr($objective_name);
    }
    $results = $db->GetAll($query);
    if ($results) {
        foreach ($results as $result) {
            if ($parent_id) {
                $presentations[] = $result;
            }
            $presentations = fetch_clinical_presentations($result["objective_id"], $presentations, 0, isset($presentation_ids) && $presentation_ids ? $presentation_ids : array(), $org_id);
        }
    }
    if (!$parent_id && is_array($presentation_ids)) {
        foreach ($presentations as $key => $presentation) {
            if (array_search($presentation["objective_id"], $presentation_ids) === false) {
                unset($presentations[$key]);
            }
        }
    }
    return $presentations;
}