Esempio n. 1
0
function insert()
{
    global $db;
    $table = _get('table');
    $id = _get('id');
    $pkey = get_pkey($table);
    if ($id) {
        $row = $db->queryRow("SELECT * FROM {$table} WHERE {$pkey} = {$id}");
    }
    $desc = get_desc($table, true);
    foreach ($desc as $Field => $d) {
        if (filter_input(INPUT_POST, $Field . '_is_null')) {
            $values[$Field] = null;
        } elseif (isset($_POST[$Field])) {
            $values[$Field] = $_POST[$Field];
        } elseif ($id) {
            $values[$Field] = $row[$Field];
        } else {
            $values[$Field] = '';
        }
    }
    $keys = implode(',', array_map(function ($key) {
        return "`{$key}`";
    }, array_keys($values)));
    $val = implode(',', array_map(function ($value) use($db) {
        return $value === null ? 'NULL' : $db->quote($value);
    }, $values));
    $confirm_sql = "INSERT INTO `{$table}` ({$keys}) VALUES ({$val})";
    render(__DIR__ . '/view/insert.html', compact('values', 'table', 'pkey', 'confirm_sql'), LAYOUT);
}
Esempio n. 2
0
function get_pkey($table)
{
    $desc = get_desc($table);
    $pkeys = array_filter($desc, function ($e) {
        return $e['Key'] === 'PRI';
    });
    if ($pkeys) {
        return $pkeys[0]['Field'];
    }
    return false;
}
function map_short($mapid)
{
    $link = baselink();
    global $coddb;
    global $game;
    global $separatorline;
    global $t;
    // table names from config
    global $m;
    // map aliases
    global $text;
    $query = "SELECT * \n            FROM {$t['maps']}\n            WHERE id = {$mapid}\n            LIMIT 1";
    $result = $coddb->sql_query($query);
    $row = $coddb->sql_fetchrow($result);
    echo "<table class=\"outertable\" width=\"100%\">";
    if (isset($m[$row['name']])) {
        echo "  <tr><td colspan=\"3\" align=\"center\" valign=\"top\">" . $m[$row['name']] . "</td></tr><tr class=\"innertable\"><td valign=\"top\" width=\"150\">";
    } else {
        echo "  <tr><td colspan=\"3\" align=\"center\" valign=\"top\">{$row['name']}</td></tr><tr class=\"innertable\"><td valign=\"top\" width=\"150\">";
    }
    echo "    <table width=\"150\">";
    echo "      <tr><td class=\"innertable\">" . $text["totkill"] . "</td><td align=\"center\" class=\"innertable\">{$row['kills']}</td></tr>";
    echo "      <tr><td class=\"innertable\">" . $text["totteamkill"] . "</td><td align=\"center\" class=\"innertable\">{$row['teamkills']}</td></tr>";
    echo "      <tr><td class=\"innertable\">" . $text["totsuicide"] . "</td><td align=\"center\" class=\"innertable\">{$row['suicides']}</td></tr>";
    echo "    </table>";
    echo "  </td><td width=\"50\" valign=\"top\">";
    // catch cod1, coduo and cod2 in one imagefolder
    if ($game == "cod1" && !file_exists("images/maps/cod1/")) {
        $gamename = "cod2";
    } elseif ($game == "coduo" && !file_exists("images/maps/coduo/")) {
        $gamename = "cod2";
    } else {
        $gamename = $game;
    }
    get_pic("images/maps/{$gamename}/middle/{$row['name']}");
    echo "  </td><td valign=\"top\" class=\"tiny\">";
    get_desc("map/{$row['name']}");
    echo "  </td></tr>";
    echo "</table>";
}