<commit_before><?php
/* Copyright (c) 2012 Association France-ioi, MIT License http://opensource.org/licenses/MIT */
// means that connect.php won't make any sql connection if in dynamoDB mode
$noSQL = true;
$noSessions = true;
use Aws\DynamoDb\Exception;
require_once("../shared/connect.php");
require_once("../shared/tinyORM.php");

$tinyOrm = new tinyOrm();
$testMode = $config->db->testMode;

if (get_magic_quotes_gpc()) {
    function stripslashes_gpc(&$value)
    {
        $value = stripslashes($value);
    }
    array_walk_recursive($_GET, 'stripslashes_gpc');
    array_walk_recursive($_POST, 'stripslashes_gpc');
    array_walk_recursive($_COOKIE, 'stripslashes_gpc');
    array_walk_recursive($_REQUEST, 'stripslashes_gpc');
}

// The encoding used for multi-bytes string in always UTF-8
mb_internal_encoding("UTF-8");

function handleAnswers($db, $tinyOrm) {
   global $testMode;
   $teamID = $_POST["teamID"];
   $teamPassword = $_POST["teamPassword"];
   try {
      $rows = $tinyOrm->select('team', array('password', 'startTime'), array('ID' => $teamID));
  } catch (Aws\DynamoDb\Exception\DynamoDbException $e) {
      error_log($e->getAwsErrorCode() . " - " . $e->getAwsErrorType());
      error_log('DynamoDB error trying to get record: teamID: '.$teamID);
      echo json_encode((object)array("success" => false, 'error' => 'DynamoDB', 'message' => $e->getMessage()));
      return;
   }
   if ($testMode == false && (!count($rows) || $teamPassword != $rows[0]['password'])) {
      echo json_encode(array("success" => false, "message" => "Requête invalide (password)"));
      return;
   }
   $row = $rows[0];
   $answers = $_POST["answers"];
   $curTime = time();
   $startTime = new DateTime($row['startTime']);
   $startTime = intval($startTime->format('U'));
   $nbMinutes = 60; // TEMPORARY. TODO : fix
   // We leave 2 extra minutes to handle network lag. The interface already prevents trying to answer after the end.
   if ((($curTime - $startTime) > ((intval($nbMinutes) + 2) * 60)) && !$testMode) { 
      echo json_encode(array("success" => false, 'error' => 'invalid', "message" => "La réponse a été envoyée après la fin de l'épreuve"));
      error_log("submission by team ".$teamID." after the time limit of the contest! curTime : ".$curTime." startTime :".$startTime." nbMinutes : ".$nbMinutes);
   } else {
      $curTimeDB = new DateTime();
      $curTimeDB = $curTimeDB->format('Y-m-d H:i:s');<commit_msg>use session to determine contest length<commit_after><?php
/* Copyright (c) 2012 Association France-ioi, MIT License http://opensource.org/licenses/MIT */
// means that connect.php won't make any sql connection if in dynamoDB mode
$noSQL = true;
//$noSessions = true;
use Aws\DynamoDb\Exception;
require_once("../shared/connect.php");
include_once("../shared/common.php");
require_once("../shared/tinyORM.php");

initSession();

$tinyOrm = new tinyOrm();
$testMode = $config->db->testMode;

if (get_magic_quotes_gpc()) {
    function stripslashes_gpc(&$value)
    {
        $value = stripslashes($value);
    }
    array_walk_recursive($_GET, 'stripslashes_gpc');
    array_walk_recursive($_POST, 'stripslashes_gpc');
    array_walk_recursive($_COOKIE, 'stripslashes_gpc');
    array_walk_recursive($_REQUEST, 'stripslashes_gpc');
}

// The encoding used for multi-bytes string in always UTF-8
mb_internal_encoding("UTF-8");

function handleAnswers($db, $tinyOrm) {
   global $testMode;
   $teamID = $_POST["teamID"];
   $teamPassword = $_POST["teamPassword"];
   try {
      $rows = $tinyOrm->select('team', array('password', 'startTime'), array('ID' => $teamID));
  } catch (Aws\DynamoDb\Exception\DynamoDbException $e) {
      error_log($e->getAwsErrorCode() . " - " . $e->getAwsErrorType());
      error_log('DynamoDB error trying to get record: teamID: '.$teamID);
      echo json_encode((object)array("success" => false, 'error' => 'DynamoDB', 'message' => $e->getMessage()));
      return;
   }
   if ($testMode == false && (!count($rows) || $teamPassword != $rows[0]['password'])) {
      echo json_encode(array("success" => false, "message" => "Requête invalide (password)"));
      return;
   }
   $row = $rows[0];
   $answers = $_POST["answers"];
   $curTime = time();
   $startTime = new DateTime($row['startTime']);
   $startTime = intval($startTime->format('U'));
   $nbMinutes = $_SESSION["nbMinutes"];
   // We leave 2 extra minutes to handle network lag. The interface already prevents trying to answer after the end.
   if ((($curTime - $startTime) > ((intval($nbMinutes) + 2) * 60)) && !$testMode) { 
      echo json_encode(array("success" => false, 'error' => 'invalid', "message" => "La réponse a été envoyée après la fin de l'épreuve"));
      error_log("submission by team ".$teamID." after the time limit of the contest! curTime : ".$curTime." startTime :".$startTime." nbMinutes : ".$nbMinutes);
   } else {
      $curTimeDB = new DateTime();
      $curTimeDB = $curTimeDB->format('Y-m-d H:i:s');
{'fraction_non_alphanumeric': 0.17643504531722054, 'fraction_numerical': 0.0052366565961732125, 'mean_word_length': 4.249471458773784, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6930319', 'n_tokens_mistral': 1698, 'n_tokens_neox': 1658, 'n_words': 385}