<commit_before><?php

if (isset($_POST['upload_doc']))
    if (isset($_POST['csrf_token'])) {
        if ($_SESSION['csrf_token'] != $_POST['csrf_token'])
            throw new Error("csrf","csrf token mismatch!");
    }
    else
        throw new Error("csrf","csrf token missing!");

function upload_identity_doc($num)
{
    global $is_logged_in;

    $file = "file$num";
    $description = post("description$num");

    if (!isset($_FILES[$file]))
        return 0;

    $info = $_FILES[$file];
    if ($info['error'])
        return 0;

    $filename = cleanup_string(basename($info['name']));
    $type = $info['type'];
    $source = $info['tmp_name'];
    $size = $info['size'];

    $dir = DOCDIR . "/$is_logged_in";
    @mkdir($dir, 0755);
    $base = "$filename";
    $index = $dir . "/00-README.txt";

    $dest = $base;
    $count = 1;
    while (file_exists($dir . "/$dest") || file_exists($dir . "/$dest.gpg")) {
        $count++;
        $dest = sprintf("upload-%d-of-%s", $count, $base);
    }

    $fp = fopen("$index", 'a');
    fprintf($fp, "%s\n  %s\n    %s\n\n", date('r'), "$dest.gpg", $description);
    fclose($fp);

    $dest = $dir . "/$dest";

    rename($source, $dest);
    encrypt_file($dest, array('<EMAIL>', '<EMAIL>'));
    @unlink($dest);

    echo "<p>File '$filename' was uploaded and encrypted successfully.</p>\n";

    return 1;
}

function handle_uploaded_identity_docs()
{
?>
    <div class='content_box'>
    <h3>Upload Results</h3>
<?php
    $uploaded = 0;
    for ($i = 0; $i < ID_FILE_UPLOAD_SLOTS; $i++)
        $uploaded += upload_identity_doc($i);

    echo "<p>" . _("Documents uploaded") . ": $uploaded</p>\n"
?>
    </div>
<?php<commit_msg>Send email when user uploads documents.<commit_after><?php

if (isset($_POST['upload_doc']))
    if (isset($_POST['csrf_token'])) {
        if ($_SESSION['csrf_token'] != $_POST['csrf_token'])
            throw new Error("csrf","csrf token mismatch!");
    }
    else
        throw new Error("csrf","csrf token missing!");

function upload_identity_doc($num)
{
    global $is_logged_in;

    $file = "file$num";
    $description = post("description$num");

    if (!isset($_FILES[$file]))
        return 0;

    $info = $_FILES[$file];
    if ($info['error'])
        return 0;

    $filename = cleanup_string(basename($info['name']));
    $type = $info['type'];
    $source = $info['tmp_name'];
    $size = $info['size'];

    $dir = DOCDIR . "/$is_logged_in";
    @mkdir($dir, 0755);
    $base = "$filename";
    $index = $dir . "/00-README.txt";

    $dest = $base;
    $count = 1;
    while (file_exists($dir . "/$dest") || file_exists($dir . "/$dest.gpg")) {
        $count++;
        $dest = sprintf("upload-%d-of-%s", $count, $base);
    }

    $fp = fopen("$index", 'a');
    fprintf($fp, "%s\n  %s\n    %s\n\n", date('r'), "$dest.gpg", $description);
    fclose($fp);

    $dest = $dir . "/$dest";

    rename($source, $dest);
    encrypt_file($dest, array('<EMAIL>', '<EMAIL>'));
    @unlink($dest);

    echo "<p>File '$filename' was uploaded and encrypted successfully.</p>\n";

    return 1;
}

function handle_uploaded_identity_docs()
{
    global $is_logged_in;
?>
    <div class='content_box'>
    <h3>Upload Results</h3>
<?php
    $uploaded = 0;
    for ($i = 0; $i < ID_FILE_UPLOAD_SLOTS; $i++)
        $uploaded += upload_identity_doc($i);

    echo "<p>" . _("Documents uploaded") . ": $uploaded</p>\n";
    echo "</div>\n";
    email_tech(_("User Uploaded New Identity Documents"),
               sprintf(_("User %s uploaded %s new file(s)."),
                       $is_logged_in, $uploaded));
{'fraction_non_alphanumeric': 0.2144244105409154, 'fraction_numerical': 0.007766990291262136, 'mean_word_length': 2.9582875960482986, 'pattern_counts': {'":': 2, '<': 30, '<?xml version=': 0, '>': 26, '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': '1008617', 'n_tokens_mistral': 1325, 'n_tokens_neox': 1272, 'n_words': 265}