Ejemplo n.º 1
0
            break;
        case "5":
            $submission_msg = "Unknown error while running program.";
            //			$submission_result = "Unknown error while running program.";
            // TODO log
            break;
        default:
            $submission_result = "Unknown error.";
            app_log(sprintf("ERROR: User %d has a last_status_code of %d which is invalid. (scoreboard status display)", $specified_user->user_id, $specified_user->last_status_code));
            break;
    }
    $submission_result = $last_processed . "<br /><b>" . $submission_msg . "</b>";
    $submission_result = "<span>" . $submission_result . "</span>";
}
// ***Program flow starts here***
process_contest_status();
read_in_all_users();
process_submission_results();
rank_users();
process_specified_user();
// ***Output starts here***
require 'header.inc';
?>
<div id="main">  
  <table border="0" width="100%">
    <tr>
      <td valign="top" align="left">
<!-- <body> -->
  <div id="content">
<!-- title and login name -->
  <h1>ACM Coding Contest Scoreboard</h1>
Ejemplo n.º 2
0
function process_submission()
{
    // Variable that will be used to display the page
    global $message;
    global $user_id;
    global $contest_root;
    $users_file = $contest_root . '/manager/conf/users.txt';
    $submission_time = date("H:i:s");
    if (!($users = file($users_file))) {
        $message = "Manager error: Opening users file failed.";
        return;
    }
    foreach ($users as $index => $user) {
        $users[$index] = strtok($user, ':');
    }
    if (!array_key_exists("id", $_POST)) {
        $message = 'You came here from a bad form.';
        return;
    }
    $user_id = $_POST["id"];
    if (!in_array($user_id, $users)) {
        $message = "You tried to submit a file using an invalid user id.";
        unset($GLOBALS['user_id']);
        // unset $user_id would only destroy it in this function's scope
        return;
    }
    $upload = $_FILES["program"];
    $allowable_types = array("text/x-c++src", "text/x-csrc", "text/x-java", "text/plain", "application/octet-stream", "text/x-csharp");
    if ($upload["error"] != 0) {
        // TODO this doesn't seem to be working
        $message = sprintf("An error occured while uploading your file. Error: %d", $upload["error"]);
        return;
    } else {
        if (!in_array($upload["type"], $allowable_types)) {
            $message = sprintf("Error uploading file. We don't accept %s files.", $upload["type"]);
            return;
        } else {
            if ($upload["size"] == 0) {
                $message = "You tried to upload a blank file.";
                return;
            } else {
                if ($upload["size"] > 100 * 1024) {
                    $message = "You tried to upload a file that is too big.";
                    return;
                }
            }
        }
    }
    global $contest_status;
    global $times_file;
    require 'contest_status.inc';
    process_contest_status();
    //echo "<pre>"; print_r($GLOBALS); echo "</pre>";
    if ($contest_status != 1) {
        $message = "You can not submit a file now because the contest is not in progress.";
        return;
    }
    // Ok to upload file
    if ($_POST["lang"] == "auto") {
        if (strpos($upload['name'], '.') === false) {
            $message = "File name doesn't have an extension so the type could not be automatically detected.";
            return;
        }
        $extension = stristr($upload['name'], '.');
    } else {
        $extension = '.' . $_POST['lang'];
    }
    $allowable_extensions = array('.java', '.c', '.cpp', '.cs');
    // TODO move to config file
    if (!in_array($extension, $allowable_extensions)) {
        $message = "Invalid language specified.";
        return;
    }
    $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890';
    $random_chars = '';
    for ($i = 0; $i < 15; $i++) {
        $random_chars .= $chars[mt_rand(0, strlen($chars) - 1)];
    }
    $tempfile = $upload["tmp_name"];
    $filename = 'submission-' . $user_id . '-' . $submission_time . '-' . $_POST['progno'] . '-' . $random_chars . $extension;
    $filename_with_path = $contest_root . '/temp_web/' . $filename;
    $result = copy($tempfile, $filename_with_path);
    if ($result === false) {
        $message = "ERROR: Could not copy submitted file to temp_web/.";
        return;
    }
    $message = "The program was successfully uploaded. Thanks!";
}