/* USE : generik.php3?db=BASE&table=TABLE&kn=USED_INDEX_NAME&key=ID_OF_INDEX */
echo "
" ;
$mysql_link = mysql_connect("localhost", $db, "PUT YOUR PASSWORD HERE ");
mysql_select_db($db, $mysql_link);
function BZ_ShowSet ( $row_table_def , $data )
{
$field = $row_table_def["Field"];
$set = str_replace("set(", "", $row_table_def["Type"]);
$set = ereg_replace("\)$", "", $set);
$set = explode (",", $set ) ;
for ($vals = explode(",", $data); list($t, $k) = each($vals);) {
$vset[$k] = 1;
}
$size = min(4, count($set));
for ($j=0; $j {
echo " if ($vset[substr($set[$j], 1, -1)])
echo " checked";
echo "> ".htmlspecialchars(substr($set[$j], 1, -1))."
\n";
}
}
function BZ_ShowEnum ( $row_table_def , $data )
{
$field = $row_table_def["Field"];
$set = str_replace("enum(", "", $row_table_def["Type"]);
$set = ereg_replace("\)$", "", $set);
$set = explode (",", $set ) ;
echo "";
}
function BZ_CalcSet ($setName )
{
$out = 0 ;
$bitVal = 1 ;
for ( $bit = 0 ; $bit < 64 ; ++$bit )
{
$theGlobalName = $setName.$bit ;
eval ( "global $"."$theGlobalName ; " ) ;
$theString = "$"."thevalue = $".$theGlobalName.";" ;
eval ( $theString );
if ( $thevalue ) { $out |= $bitVal ; } ;
$bitVal<<= 1;
}
return $out ;
}
/* START */
$table_def = mysql_db_query($db , "SHOW FIELDS FROM $table") ;
if (isset($action))
{
if ( $table_def )
{
if( $action =="update" ) $query =" UPDATE $table SET " ;
if( $action =="write" ) $query =" INSERT into $table VALUES ( " ;
$virgule = "" ;
for ($i=0;$i {
$row_table_def = mysql_fetch_array($table_def);
$field = $row_table_def["Field"];
if ( "TIME_UPDT" == $field )
{
$value = date("Y-m-d H:i:s", time());
$theString = "$"."$field = '".$value ."';" ;
eval ($theString) ;
}
if ($action =="write" && "TIME_CREA" == $field )
{
$value = date("Y-m-d H:i:s", time());
$theString = "$"."$field = '".$value ."';" ;
eval ($theString) ;
}
$theString = "$"."value = $"."$field ; " ;
switch (ereg_replace("\\(.*", "", $row_table_def['Type'])) {
case "set":
$value = BZ_CalcSet ( $field) ;
if( $action =="update" ) $query .= "$virgule $field = (($field &0 ) | $value ) ";
if( $action =="write" ) $query .= "$virgule $value ";
break;
default:
eval ( $theString );
$value = addslashes ($value );
if( $action =="write" ) $query .= "$virgule '$value' ";
if( $action =="update" ) $query .= "$virgule $field= '$value' ";
break;
}
$virgule ="," ;
}
}
if( $action =="update" ) $query .= "WHERE ID = '$ID' " ;
if( $action =="write" ) $query .= ")" ;
if ( mysql_query ( $query ) )
{
echo "Success
" ;
}
else
{
echo "Wrong query
" ;
}
echo $query ;
exit ;
}
if (isset($kn))
{
$result = mysql_db_query($db, "SELECT * FROM $table WHERE $kn = '$key' ");
$row = mysql_fetch_array($result);
}
else
{
$result = mysql_db_query($db, "SELECT * FROM $table LIMIT 1");
}
if (!$table_def)
{
exit();
}
else
{
echo " ";
echo " Edit a ". $table ." record on database ".$db."
";
echo " ";
?>
\n \n \n" ;
?>