/**
  * Returns all award receipts for the given user
  * @param User $user
  * @return InternalAwardReceipts
  */
 private static function getByUser(User $user)
 {
     global $db;
     $query = "SELECT a.`id` as `award_receipt_id`, c.`id` as award_id, a.`user_id` , c.title, c.award_terms, c.disabled, a.year \n\t\t\t\tFROM `" . DATABASE_NAME . "`.`student_awards_internal` a \n\t\t\t\tleft join `" . DATABASE_NAME . "`.`student_awards_internal_types` c on c.id = a.award_id \n\t\t\t\tWHERE a.`user_id` = " . $db->qstr($user->getID()) . " \n\t\t\t\torder by a.year desc";
     $results = $db->GetAll($query);
     $receipts = array();
     if ($results) {
         foreach ($results as $result) {
             $award = InternalAward::fromArray($result);
             //for caching purposes
             $receipt = InternalAwardReceipt::fromArray($result);
             $receipts[] = $receipt;
         }
     }
     return new self($receipts);
 }
 /**
  * 
  * @param bool $refresh
  * @return array:
  */
 static function get($refresh = false)
 {
     global $db;
     if (!self::$initialized || $refresh) {
         self::$awards = array();
         $query = "SELECT *, `id` as award_id FROM `student_awards_internal_types` order by title asc";
         $results = $db->GetAll($query);
         foreach ($results as $result) {
             array_push(self::$awards, InternalAward::fromArray($result));
         }
         self::$initialized = true;
     }
     return self::$awards;
     //return new self(self::$awards);
 }
 /**
  * 
  * @param int $award_receipt_id
  * @return AwardRecipient
  */
 public static function get($award_receipt_id)
 {
     global $db;
     $query = "SELECT a.id as award_receipt_id, user_id, award_id, c.title, c.award_terms, c.disabled, a.year \n\t\t\t\tFROM `" . DATABASE_NAME . "`.`student_awards_internal` a \n\t\t\t\tleft join `" . DATABASE_NAME . "`.`student_awards_internal_types` c on c.id = a.award_id \n\t\t\t\tWHERE a.id = " . $db->qstr($award_receipt_id);
     $result = $db->GetRow($query);
     if ($result) {
         $award = InternalAward::fromArray($result);
         return InternalAwardReceipt::fromArray($result);
     } else {
         add_error("Failed to retreive award receipt from database.");
         application_log("error", "Unable to retrieve a student_awards_internal record. Database said: " . $db->ErrorMsg());
     }
 }
function process_awards_admin()
{
    if (isset($_POST['action'])) {
        $action = $_POST['action'];
        switch ($action) {
            case "add_award_recipient":
            case "remove_award_recipient":
            case "edit_award_details":
                $award_id = isset($_POST['award_id']) ? $_POST['award_id'] : 0;
                if ($award_id) {
                    $award = InternalAward::get($award_id);
                    process_manage_award_details();
                    display_status_messages();
                    echo award_recipients_list($award);
                }
                break;
            case "remove_award":
                $award_id = isset($_POST['award_id']) ? $_POST['award_id'] : 0;
                if (!$award_id) {
                    break;
                }
            case "new_award":
                process_manage_award_details();
                display_status_messages();
                $awards = InternalAwards::get(true);
                if ($awards) {
                    echo awards_list($awards);
                }
                break;
        }
    }
}
    header("Location: " . ENTRADA_URL);
    exit;
} elseif (!$ENTRADA_ACL->amIAllowed("awards", "update", false)) {
    add_error("Your account does not have the permissions required to use this feature of this module.<br /><br />If you believe you are receiving this message in error please contact <a href=\"mailto:" . html_encode($AGENT_CONTACTS["administrator"]["email"]) . "\">" . html_encode($AGENT_CONTACTS["administrator"]["name"]) . "</a> for assistance.");
    echo display_error();
    application_log("error", "Group [" . $_SESSION["permissions"][$ENTRADA_USER->getAccessId()]["group"] . "] and role [" . $_SESSION["permissions"][$ENTRADA_USER->getAccessId()]["role"] . "] does not have access to this module [" . $MODULE . "]");
} else {
    if (isset($_GET["id"]) && ($tmp_input = clean_input($_GET["id"], array("trim", "int")))) {
        $award_id = $tmp_input;
    } else {
        $award_id = 0;
    }
    if ($award_id) {
        require_once "Models/awards/InternalAwards.class.php";
        process_manage_award_details();
        $award = InternalAward::get($award_id);
        echo "<div id=\"award_messages\">";
        display_status_messages();
        echo "</div>";
        $BREADCRUMB[] = array("url" => ENTRADA_URL . "/admin/awards?section=award_details&id=" . $award_id, "title" => "Award: " . $award->getTitle());
        $PAGE_META["title"] = "Award Details: " . $award->getTitle();
        $PAGE_META["description"] = "";
        $PAGE_META["keywords"] = "";
        ?>
<script type="text/javascript">
	jQuery(document).ready(function($) {
		if (location.hash !== '') $('a[href="' + location.hash + '"]').tab('show');

		return $('a[data-toggle="tab"]').on('shown', function(e) {
			return location.hash = $(e.target).attr('href').substr(1);
		});