Ejemplo n.º 1
0
include "../include/common.php";
include "../config.php";
include "../include/db_connect.php";
include "../include/session.php";
include "../include/apply_gen.php";
include "../include/apply_submit.php";
include "../include/latex.php";
if (isset($_SESSION['user_id'])) {
    if (isset($_REQUEST['app_id']) && isset($_REQUEST['club_id'])) {
        $club_id = $_REQUEST['club_id'];
        $app_id = $_REQUEST['app_id'];
        if ($club_id != 0) {
            //cannot submit general application
            //check for errors in general application and supplement
            $gen_app_id = getApplicationByUserClub($_SESSION['user_id'], 0);
            $genCheck = checkCompletedApplication($_SESSION['user_id'], 0, $gen_app_id);
            $appCheck = checkCompletedApplication($_SESSION['user_id'], $club_id, $app_id);
            if (count($appCheck) == 0 && count($genCheck) == 0) {
                if (isset($_REQUEST['confirm'])) {
                    //require confirmation before final submission
                    $result = submitApplication($_SESSION['user_id'], $app_id);
                    if (is_array($result)) {
                        //true on success, string on failure
                        get_page_advanced("message", "apply", array("title" => "Application submission", "message" => "Application submitted successfully"));
                    } else {
                        get_page_advanced("message", "apply", array("title" => "Application submission", "message" => "There was an error while submitting your application: " . $result));
                    }
                } else {
                    get_page_advanced("submit_confirm", "apply", array("club_id" => $club_id, "app_id" => $app_id));
                }
Ejemplo n.º 2
0
function submitApplication($user_id, $application_id, $do_submit = true)
{
    $user_id = escape($user_id);
    $application_id = escape($application_id);
    //verify application belongs to user and hasn't been submitted
    $checkResult = checkApplication($user_id, $application_id, true);
    if ($checkResult[0] !== 0) {
        return "check failed";
    }
    //verify that the user is not trying to submit the general application
    if ($checkResult[1] == 0) {
        return "";
    }
    //verify that the application can be submitted at this time
    // (checkResult checks view_time, not open_time)
    if (!isAvailableWindow($checkResult[1], true)) {
        return "application cannot be submitted at this time";
    }
    //verify that enough peer recommendations have been inputted; grab the filenames while we're at it
    $result = mysql_query("SELECT num_recommend FROM clubs WHERE id = '" . $checkResult[1] . "'");
    $recommendResult = mysql_query("SELECT filename FROM recommendations WHERE user_id = '{$user_id}' AND status = '1'");
    if ($row = mysql_fetch_array($result)) {
        if ($row[0] > mysql_num_rows($recommendResult)) {
            return "not enough peer recommendations";
        }
    } else {
        return "internal error, club not found";
    }
    $peerString = "";
    while ($row = mysql_fetch_array($recommendResult)) {
        $peerString .= ":" . $row[0];
    }
    //create supplement PDF
    $createSupplementResult = createApplicationPDF($user_id, $application_id, "../submit/");
    if ($createSupplementResult[0] === FALSE) {
        //true is success, string is error message
        return $createSupplementResult[1];
    }
    //create general application PDF
    $gen_app_id = getApplicationByUserClub($user_id, 0);
    $createGeneralResult = createApplicationPDF($user_id, $gen_app_id, "../submit/");
    if ($createGeneralResult[0] === FALSE) {
        //true is success, string is error message
        return $createGeneralResult[1];
    }
    //update database
    if ($do_submit) {
        $submitName = escape($createGeneralResult[1] . ":" . $createSupplementResult[1] . $peerString);
        //handle files
        $result = mysql_query("SELECT val FROM answers WHERE application_id = '{$application_id}' AND val LIKE 'file:%'");
        while ($row = mysql_fetch_array($result)) {
            $fileParts = explode(":", $row[0], 3);
            $submitName .= escape(":*" . $fileParts[1] . "," . $fileParts[2]);
            //:*file_id,filename
        }
        $result = mysql_query("SELECT val FROM answers WHERE application_id = '{$gen_app_id}' AND val LIKE 'file:%'");
        while ($row = mysql_fetch_array($result)) {
            $fileParts = explode(":", $row[0], 3);
            $submitName .= escape(":*" . $fileParts[1] . "," . $fileParts[2]);
            //:*file_id,filename
        }
        mysql_query("UPDATE applications SET submitted='{$submitName}' WHERE id='{$application_id}' AND user_id='{$user_id}'");
    }
    //some maintenance
    include includePath() . "/chk.php";
    checkExtraPDFs(true, true);
    //delete old, extra PDFs
    return array($createGeneralResult[1], $createSupplementResult[1]);
}