2006-04-16 23:16:22 +02:00
|
|
|
<?PHP
|
|
|
|
|
|
|
|
if( !function_exists("db_query"))
|
|
|
|
{
|
2006-11-20 23:59:30 +01:00
|
|
|
function db_querry_getDatenAssocArray($SQL)
|
2006-04-16 23:16:22 +02:00
|
|
|
{
|
2006-11-20 23:59:30 +01:00
|
|
|
global $con;
|
|
|
|
|
2006-04-16 23:16:22 +02:00
|
|
|
$Erg = mysql_query($SQL, $con);
|
|
|
|
echo mysql_error($con);
|
|
|
|
|
2006-11-20 23:59:30 +01:00
|
|
|
$Daten = array();
|
|
|
|
for( $i=0; $i<mysql_num_rows($Erg); $i++)
|
|
|
|
$Daten[$i] = mysql_fetch_assoc($Erg);
|
|
|
|
|
|
|
|
return $Daten;
|
|
|
|
}
|
|
|
|
|
|
|
|
function db_querry_diffDaten($Daten1, $Daten2)
|
|
|
|
{
|
|
|
|
$gefunden=False;
|
2006-04-16 23:16:22 +02:00
|
|
|
|
2006-11-20 23:59:30 +01:00
|
|
|
$Diff = "\n<table border=1>\n";
|
|
|
|
$Diff .= "<tr>\n\t<th>Feldname</th>\n\t<th>old Value</th>\n\t<th>new Value</th>\n";
|
|
|
|
$Diff .= "</tr>\n";
|
|
|
|
foreach($Daten1 as $DataKey => $Data1)
|
2006-04-16 23:16:22 +02:00
|
|
|
{
|
2006-11-20 23:59:30 +01:00
|
|
|
$Data2 = $Daten2[$DataKey];
|
|
|
|
foreach($Data1 as $key => $value)
|
|
|
|
if( $value != $Data2[$key])
|
|
|
|
{
|
|
|
|
$Gefunden=TRUE;
|
|
|
|
$Diff .= "<tr>\n\t<td>$key</td>\n\t<td>$value</td>\n\t<td>".$Data2[$key]."</rd>\n</tr>";
|
|
|
|
}
|
2006-04-16 23:16:22 +02:00
|
|
|
}
|
2006-11-20 23:59:30 +01:00
|
|
|
$Diff .= "</table>\n";
|
|
|
|
|
|
|
|
if( $Gefunden)
|
|
|
|
return $Diff;
|
|
|
|
else
|
|
|
|
return "\nno changes Fount\n";
|
2006-04-16 23:16:22 +02:00
|
|
|
}
|
2006-11-20 23:59:30 +01:00
|
|
|
|
2006-04-16 23:16:22 +02:00
|
|
|
function db_query( $SQL, $comment)
|
|
|
|
{
|
2006-04-19 19:29:11 +02:00
|
|
|
global $con, $Page;
|
2006-04-19 23:02:00 +02:00
|
|
|
$Diff = "";
|
2006-04-16 23:16:22 +02:00
|
|
|
|
|
|
|
//commed anlyse udn daten sicherung
|
|
|
|
if( strpos( "#$SQL", "UPDATE") > 0)
|
|
|
|
{
|
|
|
|
//Tabellen name ermitteln
|
|
|
|
$Table_Start = strpos( $SQL, "`");
|
|
|
|
$Table_End = strpos( $SQL, "`", $Table_Start+1);
|
|
|
|
$Table = substr( $SQL, $Table_Start, ($Table_End-$Table_Start+1));
|
2006-04-19 19:29:11 +02:00
|
|
|
|
|
|
|
//SecureTest
|
|
|
|
if( $Table_Start == 0 || $Table_End == 0) die("<h1>funktion_db ERROR SQL: '$SQL' nicht OK</h1>");
|
2006-04-16 23:16:22 +02:00
|
|
|
|
|
|
|
//WHERE ermitteln
|
|
|
|
$Where_Start = strpos( $SQL, "WHERE");
|
|
|
|
$Where = substr( $SQL, $Where_Start);
|
2006-04-17 16:09:30 +02:00
|
|
|
if( $Where_Start == 0) $Where = ";";
|
2006-04-19 23:02:00 +02:00
|
|
|
|
|
|
|
if( strlen( $Where) < 2)
|
|
|
|
{
|
|
|
|
$Diff = "can't show, too mutch data (no filter was set)";
|
|
|
|
$querry_erg = mysql_query($SQL, $con);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-11-20 23:59:30 +01:00
|
|
|
$Daten1 = db_querry_getDatenAssocArray( "SELECT * FROM $Table $Where");
|
|
|
|
$querry_erg = mysql_query($SQL, $con);
|
|
|
|
$Daten2 = db_querry_getDatenAssocArray( "SELECT * FROM $Table $Where");
|
|
|
|
$Diff = db_querry_diffDaten($Daten1, $Daten2);
|
2006-04-19 23:02:00 +02:00
|
|
|
}
|
2006-04-16 23:16:22 +02:00
|
|
|
}
|
2006-04-17 12:08:14 +02:00
|
|
|
elseif( strpos( "#$SQL", "DELETE") > 0)
|
|
|
|
{
|
|
|
|
$TableWhere = substr( $SQL, 6);
|
|
|
|
$Diff .= Ausgabe_Daten( "SELECT * $TableWhere");
|
|
|
|
|
|
|
|
//execute command
|
|
|
|
$querry_erg = mysql_query($SQL, $con);
|
|
|
|
}
|
2006-04-17 11:36:27 +02:00
|
|
|
elseif( strpos( "#$SQL", "INSERT") > 0)
|
|
|
|
{
|
2006-04-19 23:02:00 +02:00
|
|
|
//execute command
|
|
|
|
$querry_erg = mysql_query($SQL, $con);
|
2006-04-17 11:36:27 +02:00
|
|
|
}
|
2006-04-16 23:16:22 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
//execute command
|
|
|
|
$querry_erg = mysql_query($SQL, $con);
|
|
|
|
}
|
|
|
|
|
2006-04-19 23:02:00 +02:00
|
|
|
$SQLCommand = "SQL:<br>". htmlentities( $SQL, ENT_QUOTES);
|
|
|
|
if( strlen($Diff) > 0)
|
|
|
|
$SQLCommand .= "<br><br>Diff:<br>$Diff";
|
2006-04-17 16:09:30 +02:00
|
|
|
|
2006-04-19 19:29:11 +02:00
|
|
|
$Commend = htmlentities( ($Page["Name"]. ": ". $comment), ENT_QUOTES);
|
2006-04-16 23:16:22 +02:00
|
|
|
//LOG commands in DB
|
|
|
|
$SQL_SEC = "INSERT INTO `ChangeLog` ( `UID` , `SQLCommad` , `Commend` ) ".
|
2006-04-19 23:02:00 +02:00
|
|
|
" VALUES ( '". $_SESSION['UID']. "', ".
|
|
|
|
"'". mysql_escape_string( $SQLCommand). "', ".
|
|
|
|
"'". mysql_escape_string( $Commend). "' );";
|
2006-04-16 23:16:22 +02:00
|
|
|
$erg = mysql_query($SQL_SEC, $con);
|
|
|
|
echo mysql_error($con);
|
|
|
|
return $querry_erg;
|
|
|
|
}//function db_query(
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|