if (!defined("PARENT_INCLUDED") || !defined("IN_PUBLIC_OBSERVERSHIPS")) {
    exit;
} elseif (!isset($_SESSION["isAuthorized"]) || !$_SESSION["isAuthorized"]) {
    header("Location: " . ENTRADA_URL);
    exit;
} else {
    $BREADCRUMB[] = array("url" => ENTRADA_URL . "/profile/observerships?section=delete", "title" => "Delete Observerships");
    require_once "Models/mspr/Observership.class.php";
    require_once "Models/mspr/Observerships.class.php";
    ?>
	<h1>My Observerships</h1>
	<?php 
    if ($_POST["delete"]) {
        if (is_array($_POST["delete"])) {
            foreach ($_POST["delete"] as $observership_id) {
                $observership = Observership::get($observership_id);
                if ($observership->getStatus() == "pending" || $observership->getStatus() == "approved" || $observership->getStatus() == "rejected") {
                    $valid_observerships[] = $observership;
                }
            }
        }
        switch ($STEP) {
            case 2:
                foreach ($valid_observerships as $observership) {
                    $title = $observership->getTitle();
                    if ($observership->getStatus() == "pending" || $observership->getStatus() == "approved" || $observership->getStatus() == "rejected") {
                        if ($observership->delete()) {
                            $deleted[] = $title;
                        } else {
                            add_error("An error ocurred while attempting to delete the observership <strong>" . $title . "</strong>. An administrator has been informed, please try again later.\n\t\t\t\t\t\t\t\t\t\t<br />You will be automatically redirected to the My Observerships page in 5 seconds, or you can <a href=\"" . ENTRADA_URL . "/profile/observerships\">click here</a>.");
                        }
function get_mspr_entity($type, $entity_id)
{
    switch ($type) {
        case 'studentships':
            $entity = Studentship::get($entity_id);
            break;
        case 'clineval':
            $entity = ClinicalPerformanceEvaluation::get($entity_id);
            break;
        case 'internal_awards':
            $entity = InternalAwardReceipt::get($entity_id);
            break;
        case 'external_awards':
            $entity = ExternalAwardReceipt::get($entity_id);
            break;
        case 'contributions':
            $entity = Contribution::get($entity_id);
            break;
        case 'student_run_electives':
            $entity = StudentRunElective::get($entity_id);
            break;
        case 'observerships':
            $entity = Observership::get($entity_id);
            break;
        case 'int_acts':
            $entity = InternationalActivity::get($entity_id);
            break;
        case 'critical_enquiry':
            $entity = CriticalEnquiry::get($entity_id);
            break;
        case 'community_based_project':
            $entity = CommunityBasedProject::get($entity_id);
            break;
        case 'research_citations':
            $entity = ResearchCitation::get($entity_id);
            break;
    }
    return $entity;
}
 public function getObservership()
 {
     return Observership::get($this->observership_id);
 }
require_once 'core/library/Models/mspr/Observership.class.php';
if (!defined("PARENT_INCLUDED") || !defined("IN_PUBLIC_OBSERVERSHIPS")) {
    exit;
} elseif (!isset($_SESSION["isAuthorized"]) || !$_SESSION["isAuthorized"]) {
    header("Location: " . ENTRADA_URL);
    exit;
}
if (isset($_GET["id"]) && ($tmp = clean_input($_GET["id"], array("int")))) {
    $OBSERVERSHIP_ID = $tmp;
} else {
    echo display_error("Invalid observership ID provided. Returning to your Observerships index.");
    $ONLOAD[] = "setTimeout('window.location=\\'" . ENTRADA_URL . "/profile/observerships\\'', 5000)";
    return;
}
$BREADCRUMB[] = array("url" => ENTRADA_URL . "/profile/observerships?section=edit&id=" . $OBSERVERSHIP_ID, "title" => "Update Observership");
$OBSERVERSHIP = Observership::get($OBSERVERSHIP_ID);
if (!$OBSERVERSHIP) {
    echo display_error("Invalid observership ID provided. Returning to your Observerships index.");
    $ONLOAD[] = "setTimeout('window.location=\\'" . ENTRADA_URL . "/profile/observerships\\'', 5000)";
    return;
}
if ($OBSERVERSHIP->getStudentId() !== $ENTRADA_USER->getActiveId() || !in_array(strtolower($OBSERVERSHIP->getStatus()), array('pending', 'rejected'))) {
    echo display_error("You are not authorized to update the selected Observership. Returning to your Observerships index.");
    $ONLOAD[] = "setTimeout('window.location=\\'" . ENTRADA_URL . "/profile/observerships\\'', 5000)";
    return;
}
switch ($STEP) {
    case 2:
        echo "<h1>Update Observership</h1>";
        $observership_array = $_POST;
        if ($OBSERVERSHIP->getStatus() == "rejected") {