<commit_before><?php

function validateGCG($gcg_file, $point_sum) {
    $gcg = file($gcg_file, FILE_IGNORE_NEW_LINES);
    foreach(array_reverse($gcg) as $line) {
        if ($line[0] == '>') {
            $lsp = explode(' ', $line);
            if (!isset($playerA)) {
                    $playerA = array($lsp[0], end($lsp));
                }
            elseif ($lsp[0] != $playerA[0]) {
                $playerB = array($lsp[0], end($lsp));
                $sum_gcg = $playerA[1] + $playerB[1];
                if ($sum_gcg != $point_sum) {
                    return array(FALSE, 'Suma punktów się nie zgadza (.gcg: ' . $sum_gcg . ', PFS: ' . $point_sum . ').');
                }
                else {
                    return 1;
                }
            }
        }
    }
}


//http://stackoverflow.com/questions/9676084/how-do-i-return-a-proper-success-error-message-for-jquery-ajax-using-php
header('Content-type: application/json');
$response_array['status'] = 'error';

$validation = validateGCG($_FILES['file']['tmp_name'], $_POST['sum_points']);

    if ( 0 < $_FILES['file']['error'] ) {
        $response_array['errormsg'] = $_FILES['file']['error'];
    }
    elseif ($_FILES["file"]["size"] > 3000) {
        $response_array['errormsg'] = 'Zbyt duży plik (ograniczenie do 3kB)';
    }
    elseif ($validation != 1) {
        
        $response_array['errormsg'] = $validation[1];
    }
    else {
        include "config.php";
   
        $con = mysqli_connect($mysqlhost,$mysqluser, $mysqlpwd, $mysqldbname);

        if (!$con) {
            die('Could not connect: ' . mysqli_error($con));
            $response_array['status'] = 'error';
        }
        $new_fname = $_POST['turniej'] . '_' . $_POST['runda'] . '_' . $_POST['player1'] . '_' . $_POST['player2'];<commit_msg>on upload, check individual scores<commit_after><?php

function validateGCG($gcg_file, $p1, $p2) {
    $gcg = file($gcg_file, FILE_IGNORE_NEW_LINES);
    foreach(array_reverse($gcg) as $line) {
        if (substr($line, 0, 1) == '>') {
            $lsp = explode(' ', $line);
           
            if (!isset($playerA) && substr($lsp[2], 0, 1) == '(') {
                $letters_value = intval(substr($lsp[3], 1)) / 2;
                $playerA = array($lsp[0], intval(end($lsp))-$letters_value);
            }
            elseif ($lsp[0] != $playerA[0]) {
                $playerB = array($lsp[0], intval(end($lsp))-$letters_value);
                if (($playerA[1] == $p1 && $playerB[1] == $p2) || ($playerA[1] == $p2 && $playerB[1])) {
                    return 1;
                }
                else {
                    return array(FALSE, 'Wynik się nie zgadza (.gcg: ' . $p1 . '–' . $p2 . ', PFS: ' . $playerA[1] . '–' . $playerB[1] . ').');
                }
            }
        }
    }
}


//http://stackoverflow.com/questions/9676084/how-do-i-return-a-proper-success-error-message-for-jquery-ajax-using-php
header('Content-type: application/json');
$response_array['status'] = 'error';

$validation = validateGCG($_FILES['file']['tmp_name'], $_POST['p1pts'], $_POST['p2pts']);

    if ( 0 < $_FILES['file']['error'] ) {
        $response_array['errormsg'] = $_FILES['file']['error'];
    }
    elseif ($_FILES["file"]["size"] > 3000) {
        $response_array['errormsg'] = 'Zbyt duży plik (ograniczenie do 3kB)';
    }
    elseif ($validation != 1) {
        
        $response_array['errormsg'] = $validation[1];
    }
    else {
        include "config.php";
   
        $con = mysqli_connect($mysqlhost,$mysqluser, $mysqlpwd, $mysqldbname);

        if (!$con) {
            die('Could not connect: ' . mysqli_error($con));
            $response_array['status'] = 'error';
        }
        $new_fname = $_POST['turniej'] . '_' . $_POST['runda'] . '_' . $_POST['player1'] . '_' . $_POST['player2'];
{'fraction_non_alphanumeric': 0.20026143790849674, 'fraction_numerical': 0.018300653594771243, 'mean_word_length': 2.1830282861896837, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '556175', 'n_tokens_mistral': 1374, 'n_tokens_neox': 1309, 'n_words': 207}