Exemplo n.º 1
0
function main($imp, $cmd)
{
    global $SIDU;
    if (!$SIDU[1]) {
        $err = @lang(2201);
    } elseif ($SIDU['eng'] == 'pg' && !$SIDU[2]) {
        $err = @lang(2202);
    }
    echo "<form action='imp.php?id={$SIDU['0']},{$SIDU['1']},{$SIDU['2']}' method='post' enctype='multipart/form-data'>\n\t<div class='web'><p class='dot'><b>", @lang(2203), ": <i class='red'>DB = {$SIDU['1']}", $SIDU[2] ? ".{$SIDU['2']}" : "", "</i></b></p>";
    if ($err) {
        echo "<p class='err'>{$err}</p></div></form>";
        return;
    }
    if ($cmd) {
        $SIDU[4] = $imp['tab'];
    }
    if ($SIDU[4]) {
        $res = @tm("SQL", "SELECT * FROM " . @goodname($SIDU[4]) . " LIMIT 1");
        $col = @get_sql_col($res, $SIDU['eng']);
        foreach ($col as $v) {
            $imp['cols'][] = $v[0];
        }
    }
    if (!$imp['col']) {
        $imp['col'] = @implode("\n", $imp['cols']);
    }
    if ($cmd) {
        $err = @valid_data($SIDU, $imp);
        if ($err) {
            echo "<p class='err'>{$err}</p>";
        } else {
            return @save_data($SIDU, $imp);
        }
    }
    if ($SIDU['eng'] == 'my') {
        $sql = "SHOW TABLES from `{$SIDU['1']}`";
    } elseif ($SIDU['eng'] == 'sl') {
        $sql = "SELECT name FROM sqlite_master WHERE type='table' ORDER BY 1";
    } else {
        $sql = "SELECT relname FROM pg_class a,pg_namespace b\nWHERE a.relnamespace=b.oid AND b.nspname='public' AND a.relkind='r' ORDER BY 1";
    }
    $arr = @sql2arr($sql, 1);
    $tabs[0] = @lang(2204);
    foreach ($arr as $v) {
        $tabs[$v] = $v;
    }
    echo "<table><tr><td>", @lang(2205), ":</td><td>", @html_form("select", "imp[tab]", $SIDU[4], "", "", "onchange=\"location='imp.php?id={$SIDU['0']},{$SIDU['1']},{$SIDU['2']},r,'+this.options[this.selectedIndex].value\"", $tabs), "</td></tr>";
    if ($SIDU[4]) {
        echo "<tr><td valign='top'>", @lang(2206), ":</td><td>", @html_form("textarea", "imp[col]", $imp['col'], 350, 90), "</td></tr>";
    }
    echo "<tr><td valign='top'>", @lang(2207), ":</td><td><input type='file' name='f'/> ", @lang(2208, '2MB'), "</td></tr></table>\n\t<p class='dot'><br/><b>", @lang(2209), ":</b></p>\n\t<p class='dot'>", @lang(2210), ": ", @html_form("text", "imp[sepC]", $imp['sepC'] ? $imp['sepC'] : ',', 50), " eg \\t , ; « | »\n\t<br/>", @lang(2211), " ", @html_form("text", "imp[cut1]", $imp['cut1'], 50), " ", @lang(2212), " ", @html_form("text", "imp[cut2]", $imp['cut2'], 50), " ", @lang(2213), "\n\t<br/>", @lang(2214), ": ", @html_form("text", "imp[pk]", $imp['pk'], 150), " eg. c1;c2\n\t<br/>", @html_form("checkbox", "imp[del]", $imp['del'], "", "", "", array(1 => '')), @lang(2215), "\n\t<br/>", @html_form("checkbox", "imp[merge]", $imp['merge'], "", "", "", array(1 => '')), @lang(2216), "\n\t<br/>", @html_form("checkbox", "imp[stop]", $imp['stop'], "", "", "", array(1 => '')), @lang(2217), "</p>\n\t<p>", @html_form("submit", "cmd", @lang(2218)), "</p></div></form>";
}
Exemplo n.º 2
0
function main($exp, $cmd)
{
    global $SIDU;
    if ($_GET['sql']) {
        $cook = $SIDU['cook'][$SIDU[0]];
        @tm_use_db($cook[1], $cook[2]);
        $mode = "SQL";
        $_GET['sql'] = @stripslashes($_GET['sql']);
    } else {
        $mode = "DB = {$SIDU['1']}" . ($SIDU[2] ? ".{$SIDU['2']}" : "");
    }
    @valid_data($SIDU, $exp, $cmd);
    if ($cmd) {
        @main_cout($SIDU, $exp, $mode);
    } else {
        @main_form($SIDU, $exp, $mode);
    }
}
	 The 'flighthours' table is indexed by a unique id that is made by appending the
	 4-digit year onto the numeric month.
	 
	 dB Schema example:
	 
	 id			month	year	hours
	 ________________________________
	 72006		7		2006	52.6
	 82006		8		2006	65.0
	 62007		6		2007	38.2
	 102007		10		2007	8.0
	 
	 *********************************************************************************/
$err_msg = "";
if (isset($_POST['hours']) && isset($_POST['year']) && isset($_POST['month'])) {
    if (valid_data()) {
        $id = $_POST['month'] . $_POST['year'];
        $query = "SELECT hours FROM flighthours WHERE id like \"" . $id . "\"";
        $result = mydb::cxn()->query($query);
        if (mydb::cxn()->error != '') {
            die("Testing id existence failed: " . mydb::cxn()->error . "<br>\n" . $query);
        }
        $row = mydb::cxn()->fetch_assoc($result);
        if (is_null($row['hours'])) {
            //This date has no flight hours entered yet - create a new entry
            $query = "\tINSERT INTO flighthours (id,month,year,hours)\n\t\t\t\t\t\t\tVALUES ({$id}," . $_POST['month'] . "," . $_POST['year'] . "," . $_POST['hours'] . ")";
            $result = mydb::cxn()->query($query);
            if (mydb::cxn()->error != '') {
                die("Adding new dB row failed: " . mydb::cxn()->error . "<br>\n" . $query);
            }
        } else {