Example #1
0
function validateinput($input, $fields_def, $field_list)
{
    $validated = array();
    $nberrors = 0;
    foreach ($field_list as $field_name) {
        $field_value = $input[$field_name];
        if (!array_key_exists($field_name, $fields_def)) {
            print "No definition found for field {$field_name}<BR>\n";
            $nberrors++;
        } else {
            if (validate_field($field_name, $field_value, $fields_def[$field_name])) {
                # required fields are already handled at this point,
                # so if the field is not set it's alright not to copy
                # it over
                if (isset($input[$field_name])) {
                    $validated[$field_name] = $field_value;
                }
            } else {
                $nberrors++;
            }
        }
    }
    if ($nberrors) {
        return False;
    } else {
        return $validated;
    }
}
function check_form_submit($tid, $gid, $fields, $main)
{
    if (!isset($_POST['update'])) {
        return array('submit' => FALSE);
    }
    $new_values = array();
    $errors = array();
    foreach ($fields as $field => $opts) {
        $val = "";
        if (isset($_POST[$field])) {
            $val = trim($_POST[$field]);
        }
        if ($opts['type'] == 'date') {
            $val = $val . " 00:00:00";
            // Don't care about time component.
            //$date = DateTime::createFromFormat("M-d-Y H:i:s", $val);
            //if($date) $val = $date->format("Y-m-d H:i:s");
        }
        $new_values[$field] = $val;
        if ($opts['required'] && $val == "") {
            $errors[$field] = _T('IDS_Form_Message_REQUIRED', $main->ChessCFGFileLocation);
            continue;
        }
        // Got a value. Must validate it.
        $res = validate_field($val, $opts, $main->ChessCFGFileLocation);
        if ($res['error']) {
            $errors[$field] = $res['msg'];
            continue;
        }
    }
    //var_dump($errors);
    //var_dump($new_values);
    // If there were no errors, can update the object.
    if (count($errors) == 0) {
        // Update record in game table.
        $query = sprintf("UPDATE game SET status = '%s', completion_status = '%s' WHERE game_id = '%s'", mysql_real_escape_string($new_values['status']), mysql_real_escape_string($new_values['completion_status']), mysql_real_escape_string($gid));
        $str = _T('IDS_Admin_Tournament_Games_Edit_ERRORUPDATING', $main->ChessCFGFileLocation);
        mysql_query($query, $main->link) or die(preg_replace("/\\{mysql_err\\}/", mysql_error(), $str));
    }
    return array('submit' => TRUE, 'errors' => $errors, 'new_values' => $new_values);
}
Example #3
0
function is_valid_syntax($code, $text)
{
    if (DEV_INGNORE_SYNTAX) {
        return true;
    }
    return validate_field($code, $text);
}
function check_form_submit($id, $fields, $oR3DCQuery, $config)
{
    if (!isset($_POST['create'])) {
        return array('submit' => FALSE);
    }
    $new_values = array();
    $errors = array();
    foreach ($fields as $field => $opts) {
        $val = "";
        if (isset($_POST[$field])) {
            $val = trim($_POST[$field]);
        }
        if ($opts['type'] == 'date') {
            $val = $val . " 00:00:00";
            // Don't care about time component.
            //$date = DateTime::createFromFormat("Y-m-d H:i:s", $val);
            //if($date) $val = $date->format("Y-m-d H:i:s");
        }
        $new_values[$field] = $val;
        if ($opts['required'] && $val == "") {
            $errors[$field] = _T('IDS_Form_Message_REQUIRED', $config);
            continue;
        }
        // Got a value. Must validate it.
        $res = validate_field($val, $opts, $config);
        if ($res['error']) {
            $errors[$field] = $res['msg'];
            continue;
        }
    }
    //var_dump($errors);
    //var_dump($new_values);
    // If there were no errors, can update the object.
    if (count($errors) == 0) {
        $query = sprintf("INSERT INTO c4m_tournament (t_name, t_type, t_playernum, t_cutoffdate, t_startdate, t_comment, t_status) VALUES('%s','%s','%s','%s','%s','%s','%s')", mysql_real_escape_string($new_values['t_name']), mysql_real_escape_string($new_values['t_type']), mysql_real_escape_string($new_values['t_playernum']), mysql_real_escape_string($new_values['t_cutoffdate']), mysql_real_escape_string($new_values['t_startdate']), mysql_real_escape_string($new_values['t_comment']), mysql_real_escape_string($new_values['t_status']));
        $result = mysql_query($query, $oR3DCQuery->link);
        if ($result === FALSE) {
            exit(_T('IDS_Admin_Tournament_Add_CREATEFAILED', $config));
        }
    }
    return array('submit' => TRUE, 'errors' => $errors, 'new_values' => $new_values);
}
function check_form_submit($tid, $gid, $fields, $main)
{
    if (!isset($_POST['create'])) {
        return array('submit' => FALSE);
    }
    $new_values = array();
    $errors = array();
    foreach ($fields as $field => $opts) {
        $val = "";
        if (isset($_POST[$field])) {
            $val = trim($_POST[$field]);
        }
        if ($opts['type'] == 'date') {
            $val = $val . " 00:00:00";
            // Don't care about time component.
            //$date = DateTime::createFromFormat("M-d-Y H:i:s", $val);
            //if($date) $val = $date->format("Y-m-d H:i:s");
        }
        if ($opts['type'] == 'time controls') {
            $m1 = $_POST['tc_m1'];
            $m2 = $_POST['tc_m2'];
            $t1 = $_POST['tc_t1'];
            $t2 = $_POST['tc_t2'];
            $val = array('m1' => $m1, 't1' => $t1, 'm2' => $m2, 't2' => $t2);
            $new_values[$field] = $val;
            if ($m1 !== '') {
                if ($t1 === '') {
                    $errors[$field] = _T('IDS_Form_Message_REQUIRED', $main->ChessCFGFileLocation);
                    continue;
                }
                if ($m2 !== '' && $t2 === '') {
                    $errors[$field] = _T('IDS_Form_Message_REQUIRED', $main->ChessCFGFileLocation);
                    continue;
                }
            }
            //var_dump($val);
        } else {
            $new_values[$field] = $val;
        }
        if ($opts['required'] && $val == "") {
            $errors[$field] = _T('IDS_Form_Message_REQUIRED', $main->ChessCFGFileLocation);
            continue;
        }
        // Got a value. Must validate it.
        $res = validate_field($val, $opts, $main->link);
        if ($res['error']) {
            $errors[$field] = $res['msg'];
            continue;
        }
    }
    // Custom stuff - black and white players cannot be the same.
    if ($new_values['w_player_id'] == $new_values['b_player_id']) {
        $errors['black'] = _T('IDS_Admin_Tournament_Games_Add_SAMEPLAYER', $main->ChessCFGFileLocation);
    }
    // var_dump($errors);
    // var_dump($new_values);
    // If there were no errors, can update the object.
    $game_id = '';
    // exit();
    if (count($errors) == 0) {
        // Create a record in the game table. Need to work out whose turn it is and castling status from the FEN.
        $game_id = $main->gen_unique();
        $parts = preg_split('/ /', $new_values['fen']);
        //var_dump($parts);
        $next_move = $parts[1];
        $cast_ws = strstr($parts[2], 'K') ? 1 : 0;
        $cast_wl = strstr($parts[2], 'Q') ? 1 : 0;
        $cast_bs = strstr($parts[2], 'k') ? 1 : 0;
        $cast_bl = strstr($parts[2], 'q') ? 1 : 0;
        $query = sprintf("INSERT INTO game (game_id, initiator, w_player_id, b_player_id, status, completion_status, start_time, next_move, cast_ws, cast_wl, cast_bs, cast_bl) VALUES('%s', '0', '%s', '%s', 'A', 'I', '%s', '%s', '%s', '%s', '%s', '%s')", mysql_real_escape_string($game_id), mysql_real_escape_string($new_values['w_player_id']), mysql_real_escape_string($new_values['b_player_id']), mysql_real_escape_string(time()), mysql_real_escape_string($next_move), mysql_real_escape_string($cast_ws), mysql_real_escape_string($cast_wl), mysql_real_escape_string($cast_bs), mysql_real_escape_string($cast_bl));
        mysql_query($query, $main->link) or die(_T('IDS_Admin_Tournament_Games_Add_ERRORINSERTGAME', $main->ChessCFGFileLocation) . '<br>' . mysql_error());
        // When using a custom FEN need to store it here.
        if ($new_values['fen'] != 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1') {
            $query = $query = sprintf("INSERT INTO c4m_newgameotherfen VALUES('%s', '%s')", mysql_real_escape_string($game_id), mysql_real_escape_string($new_values['fen']));
            mysql_query($query, $main->link) or die(_T('IDS_Admin_Tournament_Games_Add_ERRORFEN', $main->ChessCFGFileLocation) . '<br>' . mysql_error());
        }
        // Store the game timing mode (snail, slow, normal, fast or blitz)
        $query = sprintf("INSERT INTO cfm_game_options VALUES('%s', 'grated', '%s', 1)", mysql_real_escape_string($game_id), mysql_real_escape_string($new_values['timing_mode']));
        mysql_query($query, $main->link) or die(_T('IDS_Admin_Tournament_Games_Add_ERROROPTIONS', $main->ChessCFGFileLocation) . '<br>' . mysql_error());
        // Store the time controls if they have been set.
        $tc = $new_values['time_controls'];
        if ($tc['m1'] !== '') {
            $query = sprintf("INSERT INTO timed_games VALUES('%s', %s, %s, %s, %s)", mysql_real_escape_string($game_id), mysql_real_escape_string((int) $tc['m1']), mysql_real_escape_string((int) $tc['t1']), mysql_real_escape_string((int) $tc['m2']), mysql_real_escape_string((int) $tc['t2']));
            mysql_query($query, $main->link) or die(__l('Error inserting record into timed_games table') . '<br>' . mysql_error());
        }
        // Associates the game with the tournament.
        $query = sprintf("INSERT INTO c4m_tournamentgames VALUES(NULL, '%s', '%s', '%s', '%s', '', '', '' )", mysql_real_escape_string($tid), mysql_real_escape_string($game_id), mysql_real_escape_string($new_values['w_player_id']), mysql_real_escape_string($new_values['b_player_id']));
        mysql_query($query, $main->link) or die(_T('IDS_Admin_Tournament_Games_Add_ERRORINSERTASSOC', $main->ChessCFGFileLocation) . '<br>' . mysql_error());
    }
    return array('submit' => TRUE, 'errors' => $errors, 'new_values' => $new_values, 'game_id' => $game_id);
}