kod jest dosyc bardzo niestaranny, chcialem umiescic po poprawkach, ale okey:
<?php
if(!isset($_POST['generuj'])) {
?>
<form action=\"\" method=\"POST\">
Nazwa klasy: <input type=\"text\" name=\"nazwa_klasy\"><BR>
Zapytanie SQL tworzące:<BR> <textarea name=\"zapytanie\" rows=6 cols=80></textarea><BR>
<input type=\"submit\" value=\"Generuj\" name='generuj'>
</form>
<?
}
else
{
$nazwa_klasy = $_POST['nazwa_klasy'];
$zapytanie = $_POST['zapytanie'];
$zapytanie = explode(\"`\", $zapytanie);
$nazwa_tabeli = $zapytanie['1'];
$ilosc_pol = ((count($zapytanie)-5
)/2
); for($i=3;$i<((count($zapytanie)-3
));$i+=2
){ $pola[] = $zapytanie[$i];
}
<?php
class '.$nazwa_klasy.'{
';
for($i=0;$i<$ilosc_pol;$i++)
{
var $'.$pola[$i].';';
}
function '.$nazwa_klasy.'($id = null)
{
if($id != null){
$sql = mysql_query(\"SELECT * FROM `\".PREFIX.\"'.$nazwa_tabeli.'`\");
$row = mysql_fetch_assoc($sql);
';
for($i = 0; $i<$ilosc_pol;$i++){
$this->'.$pola[$i].' = stripslashes($row[''.$pola[$i].'']);';
}
}
}
function insert()
{
if($this->id == ''){
$sql = mysql_query(\"INSERT INTO `\".PREFIX.\"'.$nazwa_tabeli.'`
( `id` ,`';
/* for($i=0; $i<$ilosc_pol;$i++){
echo '`'.$pola[$i].'` ';
}*/
VALUES
( '' , '\".addslashes($this->';
$asd = implode(').\"', '\".addslashes($this->', $pola); \");
}
}
function delete()
{
if($this->id != ''){
$sql = mysql_query(\"DELETE FROM `\".PREFIX.\"'.$nazwa_tabeli.'` WHERE id = \".$this->id.\" LIMIT 1\"); }
}
function update()
{
if($this->id != ''){
$sql = mysql_query( \"UPDATE `\".PREFIX.\"'.$nazwa_tabeli.'` SET ';
for($i=1; $i<$ilosc_pol; $i++){
$ret .= ' `'.$pola[$i].'` = '\".addslashes($this->'.$pola[$i].').\"',
';
}
$ret = substr($ret, 0, -3);
echo $ret.'
';
echo ' WHERE
`id` = '\".$this->id.\"'\");
}
}
';
echo '}?>';
$form = '
<?
if(isset($_POST['zapisz'])) {
if($_POST['id'] != '')
{
$oDane = new '.$nazwa_klasy.'($_POST[''.$pola[0].'']);
foreach($_POST as $key =>$val){
$oDane->$key = $val;
}
$oDane->update();
}
else
{
$oDane = new '.$nazwa_klasy.'();
foreach($_POST as $key =>$val){
$oDane->$key = $val;
}
$oDane->insert();
}
}
<form action=\"\" method=\"POST\">
<table>
<td><input type=\"hidden\" name=\"'.$pola[0].'\" value=\"'.$_POST[''.$pola[0].''].'\"></td>
';
for($i =1; $i<$ilosc_pol; $i++)
{
$form .= '<tr>
<td>'.$pola[$i].':</td>
<td><input type=\"text\" name=\"'.$pola[$i].'\" value=\"'.$_POST[''.$pola[$i].''].'\"></td>
</tr>
';
}
$form .= '
<tr><TD colspan=2><input type=\"submit\" name=\"zapisz\" value=\"Zapisz\"></td></tr>
</table>
</form>';?>';
$var = ob_get_contents();
ob_end_clean();
highlight_string($var);
echo '<hr>';
highlight_string($form);
}
?>