Codice PHP:
<script language="php">
include("dbconnect.php");
global $tableDefSet;
global $tableDefHgt;
if(!isset($tableDefSet)||$tableDefSet=="") { $tableDefSet = ""; } // Table selected by default in table list
if(!isset($tableDefHgt)||$tableDefHgt=="") { $tableDefHgt = "0"; } // Height of table list: 0 = include all tables
if(!isset($tableFilter)||$tableFilter=="") { $tableFilter = ""; } // Table name filter
if(!isset($FilterToggle)||$FilterToggle=="") { $FilterToggle = "show"; } // Show or Hide table names with filter string
//
</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Modifica News</title>
<script language="JavaScript" type="text/javascript">
function isNum (item)
{ if (!areAllNumbers(item.value)) { alert('Only Numeric characters allowed.'); item.focus();} else { return true; } }
function areAllNumbers (item)
{ for (j=0; j<item.length; j++) { if (!isNumber (item.charAt (j))) {return false} } return true; }
function isNumber (item)
{ numeric = "0123456789-"; for (var i=0; i<numeric.length; i++) { if (item == numeric.charAt (i)) {return true} } return false }
function returnconfirm(c)
{ var comment=confirm(c); if (comment) return true; else return false; }
</script>
<style type="text/css">
<!--
BODY { font-family: arial, verdana, helvetica, sans-serif; font-size: medium; color: White; }
P { font-family: arial, verdana, helvetica, sans-serif; font-size: medium; color: White; }
TD { font-family: arial, verdana, helvetica, sans-serif; font-size: small; color: White; }
TD.N { font-family: arial, verdana, helvetica, sans-serif; font-size: small; color: White; }
TD.G { font-family: arial, verdana, helvetica, sans-serif; font-size: small; color: White; }
TD.S { font-family: arial, verdana, helvetica, sans-serif; font-size: small; color: White; }
H1 { font-family: arial, verdana, helvetica, sans-serif; font-size: large; color: White; font-weight : bold; margin-top : 0; margin-bottom : 0; margin : 0px 0px 0px 0px; }
H2 { font-family: arial, verdana, helvetica, sans-serif; font-size: small; color: White; font-weight : bold; margin-top : 0; margin-bottom : 0; margin : 0px 0px 0px 0px; }
A { color: #0000FF; text-decoration: none; }
A:visited { color: #3344FF; text-decoration: none; }
A:hover { color: Red; ttext-decoration : underline; background-color:#E6E9FE; }
SMALL.x { font-size : small; }
SMALL.xg { font-size : small; color: White; }
STRONG { font-size : x-small; color: White; }
//-->
</style>
</head>
<body>
<table width="700" border="0" cellspacing="0" cellpadding="0" align="center">
<tr><td>
<H1>Modifica Database</H1>
<?PHP
$readyFor = "3"; // 1=Edt, 3=Edt/Del, 7=Edt/Del/Cpy, 11=Edt/Del/Cpy/Add (11 not implemented yet)
if (isset($_POST["GetTableName"]))
{ $tableDef = $_POST["GetTableName"]; }
elseif ($tableDefSet != "")
{ $tableDef = $tableDefSet; }
else { $tableDef = ""; }
if (isset($_POST["GetTableName"])) {
echo "</td><td><a href=\"".$_SERVER['PHP_SELF']."\">Pagina iniziale per modificare Record</a></td>";
} else {
$appdescription = <<<appdescription
appdescription;
echo $appdescription . "</td><td></td>";
}
?>
</tr><tr><td colspan="2"><hr color="Maroon" size="3"></td></tr>
</table>
<table width="700" border="0" cellspacing="0" cellpadding="3" align="center"><tr><td colspan="3">
<? if ((isset($_POST["GetTableName"]))&&($tableDef!=""))
{ $tablename = $tableDef;
if (isset($_POST["GetIt"]))
{ if ($_POST["GetIt"]=="Modifica")
{ $getDataQueryT = "SELECT * FROM ".$tablename." ";
$getDataQueryT .= "WHERE `".$_POST["FieldUniqueName"]."`='".$_POST["FieldUniqueData"]."'";
$getDataQuery = mysql_query($getDataQueryT) or die("Unable to get record. Please try again later.
".mysql_error());
$getFieldCount = mysql_num_fields($getDataQuery);
echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"2\">";
echo "<form name=\"PutItForm\" action=\"".$_SERVER['PHP_SELF']."\" method=\"POST\">";
echo "<input type=\"hidden\" name=\"GetTableName\" value=\"".$tablename."\">";
echo "<input type=\"hidden\" name=\"GetTableListFieldCount\" value=\"".$_POST["GetTableListFieldCount"]."\">";
echo "<input type=\"hidden\" name=\"GetTableListRecordS\" value=\"".$_POST["GetTableListRecordS"]."\">";
echo "<input type=\"hidden\" name=\"GetTableListRecordT\" value=\"".$_POST["GetTableListRecordT"]."\">";
echo "<input type=\"hidden\" name=\"FieldUniqueName\" value=\"".$_POST["FieldUniqueName"]."\">";
echo "<input type=\"hidden\" name=\"FieldUniqueData\" value=\"".$_POST["FieldUniqueData"]."\">";
echo "<tr><td colspan=\"2\" class=\"N\">Nome Tabella: [b]".$tablename."[/b] | Vai a: [b]<a href=\"#GetRecords\">Lista dei records</a> / <a href=\"#GetTableNames\">Lista Tabelle</a>[/b]
<hr size=\"1\" color=\"Maroon\" noshade></td></tr>";
for ($icnt=0; $icnt<$getFieldCount; $icnt++)
{ $metaGet = mysql_fetch_field($getDataQuery, $icnt);
echo "<tr><td>" . mysql_field_name($getDataQuery, $icnt);
if ($metaGet->primary_key == "1")
{ echo "
<small style=\"color:Maroon;\">Primary Key</small>"; }
echo "</td><td>";
if ($metaGet->blob == "1")
{ echo "<textarea name=\"".mysql_field_name($getDataQuery, $icnt)."\" cols=\"64\" rows=\"2\">" . mysql_result($getDataQuery,0,$icnt) . "</textarea></td>"; }
else { echo "<input type=\"text\" name=\"".mysql_field_name($getDataQuery, $icnt)."\" value=\"" . str_replace("\"", """, mysql_result($getDataQuery,0,$icnt)) . "\" size=\"85\" maxlength=\"".mysql_field_len($getDataQuery, $icnt)."\"></td>"; }
}
echo "<tr><td colspan=\"2\"><input type=\"submit\" value=\"Save\" name=\"PutIt\"></td></tr>";
echo "</form></table>";
echo "<hr size=\"3\" color=\"Navy\" noshade>";
mysql_free_result($getDataQuery);
}
elseif ($_POST["GetIt"]=="Cp")
{ $getDataQueryT = "SELECT * FROM ".$tablename." WHERE `".$_POST["FieldUniqueName"]."`='".$_POST["FieldUniqueData"]."'";
echo "[b]gDQT:[/b] " . $getDataQueryT . "
";
$getDataQueryQ = mysql_query($getDataQueryT);
$getDataQueryT1 = "";
$getDataQueryT2 = "";
// $fields_names = array();
// $fields_types = array();
// while ($row = mysql_fetch_array($getDataQueryQ)) {
// $fields_names[] = $row['Field'];
// // loic1: set or enum types: slashes single quotes inside options
// if (preg_match('@^(set|enum)\((.+)\)$@i', $row['Type'], $tmp)) {
// $tmp[2] = substr(preg_replace('@([^,])\'\'@', '\\1\\\'', ',' . $tmp[2]), 1);
// $fields_types[] = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
// } else {
// $fields_types[] = $row['Type'];
// }
// } // end while
while ($row=mysql_fetch_array($getDataQueryQ))
{ $icnt=0;
while ($icnt < mysql_num_fields($getDataQueryQ))
{ if ((strpos(mysql_field_flags($getDataQueryQ, $icnt), "auto_increment")===false)) // Not a primary field
{
$flagIt = mysql_fetch_field($getDataQueryQ, $icnt);
if (!$flagIt) { echo "Nessuna indormazione disponibile
\n"; }
else {
echo "Field " . $icnt . " : ";
if ($flagIt->name == 1) { echo "[b]".$flagIt->name."[/b]"; } else { echo $flagIt->name; } echo " / P:";
if ($flagIt->primary_key == 1) { echo "[b]".$flagIt->primary_key."[/b]"; } else { echo $flagIt->primary_key; } echo " / U:";
if ($flagIt->unique_key == 1) { echo "[b]".$flagIt->unique_key."[/b]"; } else { echo $flagIt->unique_key; } echo " / M:";
if ($flagIt->multiple_key == 1) { echo "[b]".$flagIt->multiple_key."[/b]"; } else { echo $flagIt->multiple_key; } echo " / Max:";
echo $flagIt->max_length;
echo "
";
}
// THIS IS AN OBJECT: MAY NEED TO DO WHILE LOOP TO DETERMINE IF unique_key IS AN ATTRIBUTE
$getDataQueryT1 .= mysql_field_name($getDataQueryQ, $icnt).", ";
$getDataQueryT2 .= $row[$icnt]."', '";
}
else
{
echo "Field " . $icnt . " : ";
print("[b]Primary:[/b] ".mysql_field_name($getDataQueryQ, $icnt)."
"); }
$icnt++;
}
}
$getDataQueryT = "INSERT INTO `".$tablename."` (".substr($getDataQueryT1, 0, strlen($getDataQueryT1)-2).") VALUES ('".substr($getDataQueryT2, 0, strlen($getDataQueryT2)-4)."');";
echo "[b]gDQT:[/b] " . $getDataQueryT . "
";
// $getDataQuery = mysql_query($getDataQueryT) or die("Unable to copy record. Please try again later.
".mysql_error());
}
elseif ($_POST["GetIt"]=="X")
{ $getDataQueryT = "DELETE FROM ".$tablename." ";
$getDataQueryT .= "WHERE `".$_POST["FieldUniqueName"]."`='".$_POST["FieldUniqueData"]."'";
$getDataQuery = mysql_query($getDataQueryT) or die("Unable to delete record. Please try again later.
".mysql_error());
}
}
elseif (isset($_POST["PutIt"]))
{ $getDataQueryT = "SELECT * FROM ".$tablename;
$getDataQuery = mysql_query($getDataQueryT) or die("Impossibile ottenere un record. Per favore riprova
".mysql_error());
$getFieldCount = mysql_num_fields($getDataQuery);
$insertquery = "UPDATE ".$tablename." ";
$insertquery .= "SET ";
for ($icnt=0; $icnt<$getFieldCount; $icnt++)
{ $insertquery .= "`".mysql_field_name($getDataQuery, $icnt)."` = ";
$insertquery .= "'".htmlspecialchars($_POST[mysql_field_name($getDataQuery, $icnt)])."', "; }
//$insertquery .= "'".addAslash($_POST[mysql_field_name($getDataQuery, $icnt)])."', "; }
$insertquery = substr($insertquery, 0, strlen($insertquery)-2);
$insertquery .= " WHERE `".$_POST["FieldUniqueName"]."`='".$_POST["FieldUniqueData"]."';";
echo "[b]Query:[/b] " . $insertquery . "
";
mysql_query($insertquery) or die ("Unable to save data. Please try again later.".mysql_error());
$goodtogo = "<font face='Arial' size='+1' color='Blue'><strong style=\"font-size:small;color:blue;\">";
$goodtogo .= "Data has been saved - Thank you![/b]</font>";
echo $goodtogo . "
";
mysql_free_result($getDataQuery);
}
if ($_POST["GetTableListRecordS"]=="" || $_POST["GetTableListRecordS"]=="0")
{ $GetTableListRecordS = "0"; }
else { $GetTableListRecordS = ((int)$_POST["GetTableListRecordS"])-1; }
if ($_POST["GetTableListRecordT"]=="" || $_POST["GetTableListRecordT"]=="0")
{ $getDataQueryNR = mysql_query("SELECT * FROM ".$tablename) or die("Impossibile ottenere il record 1. Riprova più tardi.
".mysql_error());
$GetTableListRecordT = mysql_num_rows($getDataQueryNR);
$GetTableListRecordTT = $GetTableListRecordT;
mysql_free_result($getDataQueryNR);
}
else { $getDataQueryNR = mysql_query("SELECT * FROM ".$tablename) or die("Impossibile ottenere il record 1. Riprova più tardi.
".mysql_error());
$GetTableListRecordTT = mysql_num_rows($getDataQueryNR);
mysql_free_result($getDataQueryNR);
$GetTableListRecordT = $_POST["GetTableListRecordT"];
}
$getDataQuery = mysql_query("SELECT * FROM ".$tablename." LIMIT ".$GetTableListRecordS.",".$GetTableListRecordT) or die("Impossibile ottenere il record 2. Riprova più tardi.
".mysql_error());
$getFieldCount = mysql_num_fields($getDataQuery);
if (($_POST["GetTableListFieldCount"]>0)&&($_POST["GetTableListFieldCount"]<=99))
{ if ($getFieldCount > $_POST["GetTableListFieldCount"])
{ $getFieldCountShow = $_POST["GetTableListFieldCount"]; }
else { $getFieldCountShow = $getFieldCount; }
} else { $getFieldCountShow = $getFieldCount; }
if (mysql_num_rows($getDataQuery)>0)
{ if (isset($_POST["tname"])) { echo "<input type=\"text\" name=\"tname\" value=\"".$_POST["tname"]."\">"; }
echo "<table border=\"1\" cellspacing=\"0\" cellpadding=\"5\">";
echo "<tr><td colspan=\"".($getFieldCountShow+2)."\" class=\"N\">";
echo "<a name=\"GetRecords\"></a>Nome Tabella: [b]".$tablename."[/b] | ";
echo "Righe: [b]".$GetTableListRecordTT."[/b] | ";
echo "Totale dei campi: [b]".$getFieldCount."[/b] | ";
if ($getFieldCountShow < $getFieldCount)
{ echo "<strong style=\"color:red;\">Campi mostrati: ".$getFieldCountShow."[/b] | "; }
</html>