campo-sirio/corsi/admin/elenco.php
alex cf0c1133fd Patch level :
Files correlati     :
Ricompilazione Demo : [ ]
Commento            :
Versione FAD del 11/10/2001


git-svn-id: svn://10.65.10.50/trunk@9917 c028cbd2-c16b-5b4b-a496-9718f37d4682
2001-10-11 12:55:16 +00:00

249 lines
7.6 KiB
PHP
Executable File

<html>
<head>
<title></title>
<LINK rel="stylesheet" type="text/css" href="stile.css">
</head>
<body>
<?php
include("required.php");
$db = mysql_connect($ip, $user, $password);
mysql_select_db($dataname,$db);
if ($mostra == 'canc')
{
if (isset($tbl) && isset($id))
{
$query = "DELETE FROM $tbl WHERE id = $id ";
//echo $query;
$canc = mysql_query($query, $db);
if (!$canc)
echo "<br><br><p class=error>Cancellazione non effettuata!</p><br><br>";
}
}
if (isset ($aggiorna))
{
if (isset($tbl))
{
$criteri = "SELECT * FROM $tbl ";
$result = mysql_query($criteri, $db);
$myrow = mysql_fetch_array($result);
$num_fields = mysql_num_fields($result);
$query = "UPDATE $tbl SET ";
for($x = 0; $x < $num_fields-1; $x++)
$query .= " ".mysql_field_name($result, $x)." = '".$valori[mysql_field_name($result, $x)]."',";
$query .= " ".mysql_field_name($result, $num_fields-1)." = '".$valori[mysql_field_name($result, $num_fields-1)]."'";
$query .= " WHERE id = $id ";
//echo $query;
$agg = mysql_query($query, $db);
if (!$agg)
echo "<br><br><p class=error>Aggiornamento non effettuato!</p><br><br>";
}
}
if (isset ($salva))
{
if (isset($tbl))
{
$criteri = "SELECT * FROM $tbl ";
$result = mysql_query($criteri, $db);
$myrow = mysql_fetch_array($result);
$num_fields = mysql_num_fields($result);
$query = "INSERT INTO $tbl (";
for($x = 0; $x < $num_fields-1; $x++)
$query .= " ".mysql_field_name($result, $x).",";
$query .= " ".mysql_field_name($result, $num_fields-1)."";
$query .= ") VALUES ( ";
for($x = 0; $x < $num_fields-1; $x++)
$query .= " '".$valori[mysql_field_name($result, $x)]."',";
$query .= " '".$valori[mysql_field_name($result, $x)]."')";
//echo $query;
$sal = mysql_query($query, $db);
if (!$sal)
echo "<br><br><p class=error>Salvataggio non riuscito!</p><br><br>";
}
}
//if ($mostra == 'deletesicuro')
if ($mostra == 'mod')
{
if (isset($tbl))
{
echo "<p class=titolo>Aggiornamento dati<br></p>";
if (isset($id)) $criteri = "SELECT * FROM $tbl WHERE id = $id ";
else $criteri = "SELECT * FROM $tbl ";
//echo $criteri;
$result = mysql_query($criteri, $db);
$myrow = mysql_fetch_array($result);
$num_fields = mysql_num_fields($result);
echo "<form name=form1 action=elenco.php method=post><table border=0 align=center>";
//$valori = array();
for($x = 0; $x < $num_fields; $x++)
{
//$tipo = "<td>".mysql_field_type($result, $x)."</td>"; // Visualizza il tipo del campo
$dati = "";
$t = ereg_replace("'", "", $myrow[mysql_field_name($result, $x)]); // Rimozione delle stringhe del singolo apice
if (isset($id)) $dati = $t;
if ($riga == true)
{
echo "<tr class=chiaro><td>".mysql_field_name($result, $x)."</td>";
$riga = false;
}
else
{
echo "<tr class=scuro><td>".mysql_field_name($result, $x)."</td>";
$riga = true;
}
if (mysql_field_type($result, $x) == "blob")
//if (mysql_field_type($result, $x) == "blob" || mysql_field_len($result, $x) > 30 )
echo "$tipo<td><textarea cols=25 rows=3 name='valori[".mysql_field_name($result, $x)."]' wrap=hard>$dati</textarea></td></tr>";
else
echo "$tipo</td><td><input type=text size=20 name='valori[".mysql_field_name($result, $x)."]' value='$dati'></td></tr>";
}
echo "<tr><td><br></td></tr>";
echo "<tr><td align=left><input type=hidden name=tbl value=$tbl><input type=hidden name=id value=$id>";
if (isset($id)) echo "<input type=submit name=aggiorna value=Aggiorna></td></tr>";
else echo "<input type=submit name=salva value=Salva></td></tr>";
echo "</table></form>";
}
}
elseif ($mostra == 'delete')
{
echo "<table><tr><td>La tabella '$tbl' verr&aacute; vuotata. Proseguire?";
echo "<form name=deletesicuro action=elenco.php method=post><input type=submit name=drop value=SI class=bottoni>&nbsp;";
echo "<input type=hidden name=tbl value=$tbl><input type=submit value=NO name=drop class=bottoni></form></td></tr></table>";
}
else
{
if ($drop == "SI")
{
if (isset($tbl))
{
$query = "DELETE FROM $tbl ";
//echo $query;
$del = mysql_query($query, $db);
if (!$del)
echo "<br><br><p class=error>Cancellazione non riuscita!</p><br><br>";
}
}
if (isset($tbl))
{
if (isset($links_shown1)) $links_shown = $links_shown1;
if (isset($links_shown_p1)) $links_shown = $links_shown_p1;
$row_max = 30; // Numero di righe per pagina
if (!$links_shown)
$links_shown = 0;
else
$old_link = $links_shown;
echo "<p class=titolo>Tabella: <b>$tbl</b><br></p>";
$sql = "SELECT count(*) as conto FROM $tbl";
if (isset($total_result) == false)
{
$result1 = mysql_query($sql,$db);
$myrow1 = mysql_fetch_array($result1);
$total_result = $myrow1["conto"];
}
$criteri = "SELECT * FROM $tbl limit $links_shown, $row_max";
//echo $criteri;
$result = mysql_query($criteri, $db);
$myrow = mysql_fetch_array($result);
$dati = array();
$num_fields = mysql_num_fields($result);
//echo $total_result;
if ($total_result > 0)
{
for($x = 0; $x < $num_fields; $x++)
$dati[] = mysql_field_name($result, $x);
$table = array();
do
{
$temp = array();
foreach($dati as $nome)
$temp[] = $myrow[$nome];
array_push($table,$temp);
}while ($myrow = mysql_fetch_array($result));
echo "<table align=center border=0>";
echo "<tr>";
foreach($dati as $headers)
echo "<th>$headers</th>";
echo "<td><br></td><td><br></td></tr>";
foreach($table as $y)
{
if ($riga == true)
{
echo "<tr class=chiaro>";
$riga = false;
}
else
{
echo "<tr class=scuro>";
$riga = true;
}
foreach($y as $xcell)
{
if ($xcell != "")
echo "<td>$xcell</td>";
else
echo "<td><br></td>";
}
//echo "<td><a href=elenco.php?mostra=mod&tbl=$tbl&id=$y[0]>Modifica</a></td><td><a href=elenco.php?mostra=canc&tbl=$tbl&id=$y[0]>Cancella</a></td></tr>";
//echo "<td><a href=elenco.php?mostra=mod&tbl=$tbl&id=$y[0]>Modifica</a></td>";
//echo "<td><a href=elenco.php?mostra=canc&tbl=$tbl&id=$y[0]>Cancella</a></td></tr>";
echo "<td><a href=elenco.php?mostra=mod&tbl=$tbl&id=$y[0]><img src='images/modifica.gif' alt=Modifica border=0></a></td>";
echo "<td><a href=elenco.php?mostra=canc&tbl=$tbl&id=$y[0]><img src='images/elimina.gif' alt=Elimina border=0></a></td></tr>";
}
echo "<tr><td><br></td></tr><tr><td colspan=$num_fields align=left><a href=elenco.php?mostra=delete&tbl=$tbl>Vuota la tabella</a></td></tr>";
}
else
{
echo "<table align=center border=0><tr><td class=titolo>La Tabella non contiene record</font></td></tr>";
}
$links_shown = $links_shown + $row_max;
echo "<tr><td><br></td></tr><tr><td colspan=$num_fields align=left><a href=elenco.php?mostra=mod&tbl=$tbl>Aggiungi nuovo record</a></td></tr>";
echo "</table>";
$links_shown = $links_shown - 1;
if (($links_shown + 1) != $row_max)
{
$links_on_this_page = $links_shown - $old_link;
$links_shown_prev = $links_shown - (($row_max + $links_on_this_page));
}
if ($links_shown != ($total_result-1))
$links_shown = ($links_shown + 1);
echo "<table align=center><tr>";
if ($total_result > $row_max)
{
if (isset($links_shown_prev)==true)
echo "<td><a href=elenco.php?tbl=$tbl&links_shown=$links_shown_prev&total_result=$total_result>Precedente</a></td>";
echo "<td><br></td>";
//if ($links_shown!=$total_result-1)
if ($links_shown < ($total_result - 1))
echo "<td><a href=elenco.php?tbl=$tbl&links_shown=$links_shown&total_result=$total_result>Successivo</a></td>";
echo "</tr></table>";
}
}
}
//echo "<p><a href=# onclick=history.back()>Torna</a></p>";
?>
</body>
</html>