<commit_before><?php
require "lib/headerphp.php";
require "../lib/app.php";


// $db is already open!

if (!empty($_POST)) {

    #print "<h1>Processing changes</h1>";
    #print_r($_POST);

    if (array_key_exists("action", $_POST)) {

        $action = $_POST["action"];
        unset($_POST["action"]);

        if ($action=="save") {



            if (! isset($_POST['email'])) {
                echo "no email in POST";
                var_dump($_POST);
                die(1);
            }


            /*
                init to default values
                because checkboxes only give a value if checked..
                all others could be set to null

                make sure here are only fields that settings.php defines!!
            */
            $vals = [
                "title" => "",
                "firstname" => "",
                "lastname" => "",
                "email" => "",
                "affiliation" => "",
                "address" => "",
                "isPassive" => TRUE,

                "needInet" => FALSE,
                "nPersons" => 1,
                "isVeggie" => FALSE,
                "isImpaired" => FALSE,
                "lookingForRoomMate" => FALSE,

                "hasPayed" => TRUE,
                "price" => 0,

                "talkType" => 0,
                'isAbstractSubmitted' => NULL,
            ];

            // read post fields
            foreach ($tableFields as $key => $arr) {
                $sqltype = $arr[0];
                $type = $arr[1];
                $choices = (isset($arr[2])) ? $arr[2] : NULL ;

                if (isset($_POST[$key])) {
                    $x = $_POST[$key];
                    if ($type == 'string') {
                        $vals[$key] = strval($x);
                    }
                    elseif ($type == "integer") {
                        $vals[$key] = intval($x);
                    }
                    elseif ($type == "boolean") {
                        $vals[$key] = boolval($x);
                    }
                    elseif ($type == "choice") {
                        $vals[$key] = intval(array_search($x, $choices, TRUE)); # if not found this returns False, which gets casted to 0, the first and default choice
                    }
                    elseif ($type == "date") {
                        $dt = new DateTime($x);
                        $vals[$key] = $dt->format($datetime_db_fstr);
                    }
                }
                else { # if no default value is set, set to null
                    if (!isset($vals[$key])) {
                        $vals[$key] = NULL;
                    }
                }
            }

            // fill in other fields
<commit_msg>admin: fix add user talk type choice int or str<commit_after><?php
require "lib/headerphp.php";
require "../lib/app.php";


// $db is already open!

if (!empty($_POST)) {

    #print "<h1>Processing changes</h1>";
    #print_r($_POST);

    if (array_key_exists("action", $_POST)) {

        $action = $_POST["action"];
        unset($_POST["action"]);

        if ($action=="save") {



            if (! isset($_POST['email'])) {
                echo "no email in POST";
                var_dump($_POST);
                die(1);
            }

            var_dump($_POST);
            /*
                init to default values
                because checkboxes only give a value if checked..
                all others could be set to null

                make sure here are only fields that settings.php defines!!
            */
            $vals = [
                "title" => "",
                "firstname" => "",
                "lastname" => "",
                "email" => "",
                "affiliation" => "",
                "address" => "",
                "isPassive" => TRUE,

                "needInet" => FALSE,
                "nPersons" => 1,
                "isVeggie" => FALSE,
                "isImpaired" => FALSE,
                "lookingForRoomMate" => FALSE,

                "hasPayed" => TRUE,
                "price" => 0,

                "talkType" => 0,
                'isAbstractSubmitted' => NULL,
            ];

            // read post fields
            foreach ($tableFields as $key => $arr) {
                $sqltype = $arr[0];
                $type = $arr[1];
                $choices = (isset($arr[2])) ? $arr[2] : NULL ;

                if (isset($_POST[$key])) {
                    $x = $_POST[$key];
                    if ($type == 'string') {
                        $vals[$key] = strval($x);
                    }
                    elseif ($type == "integer") {
                        $vals[$key] = intval($x);
                    }
                    elseif ($type == "boolean") {
                        $vals[$key] = boolval($x);
                    }
                    elseif ($type == "choice") {
                        if (is_numeric($x)) {
                            $vals[$key] = intval($x);
                        }
                        else {
                            $vals[$key] = intval(array_search($x, $choices, TRUE)); # if not found this returns False, which gets casted to 0, the first and default choice
                        }
                    }
                    elseif ($type == "date") {
                        $dt = new DateTime($x);
                        $vals[$key] = $dt->format($datetime_db_fstr);
                    }
                }
                else { # if no default value is set, set to null
                    if (!isset($vals[$key])) {
                        $vals[$key] = NULL;
                    }
                }
            }

            // fill in other fields

{'fraction_non_alphanumeric': 0.13964435146443516, 'fraction_numerical': 0.0038354253835425384, 'mean_word_length': 1.0045422781271838, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 43, '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': '4181423', 'n_tokens_mistral': 1541, 'n_tokens_neox': 1406, 'n_words': 357}