/**
 * Processes the various sections of the MSPR module
 */
function process_manage_award_details()
{
    if (isset($_POST['action'])) {
        $action = $_POST['action'];
        switch ($action) {
            case "add_award_recipient":
                $award_id = isset($_POST['award_id']) ? $_POST['award_id'] : 0;
                $user_id = isset($_POST['internal_award_user_id']) ? $_POST['internal_award_user_id'] : 0;
                if ($user_id && $award_id) {
                    $year = $_POST['internal_award_year'];
                    $info = array("award_id" => $award_id, "user_id" => $user_id, "year" => $year);
                    InternalAwardReceipt::create($info);
                }
                break;
            case "remove_award_recipient":
                $id = isset($_POST['internal_award_id']) ? $_POST['internal_award_id'] : 0;
                if ($id) {
                    $recipient = InternalAwardReceipt::get($id);
                    if ($recipient) {
                        $recipient->delete();
                    }
                }
                break;
            case "edit_award_details":
                $award_id = isset($_POST['award_id']) ? $_POST['award_id'] : 0;
                $disabled = (bool) $_POST['award_disabled'];
                $title = clean_input($_POST['award_title'], array("notags", "specialchars"));
                $terms = clean_input($_POST['award_terms'], array("notags", "specialchars", "nl2br"));
                if (!$title || !$terms) {
                    add_error("Insufficient information please check the fields and try again");
                } else {
                    if ($award_id) {
                        $award = InternalAward::get($award_id);
                        if ($award) {
                            edit_award_details($award, $title, $terms, $disabled);
                        }
                    } else {
                        add_error("Award not found");
                    }
                }
                break;
            case "new_award":
                $title = clean_input($_POST['award_title'], array("notags", "specialchars"));
                $terms = clean_input($_POST['award_terms'], array("notags", "specialchars", "nl2br"));
                if (!$title || !$terms) {
                    add_error("Insufficient information please check the fields and try again");
                } else {
                    InternalAward::create($title, $terms);
                }
                break;
            case "remove_award":
                $award_id = isset($_POST['award_id']) ? $_POST['award_id'] : 0;
                if ($award_id) {
                    $award = InternalAward::get($award_id);
                    $award->delete();
                }
                break;
        }
    }
}