← Back
Editing: fotogallerie_ed3.php
<?php #______________________________________________________________________# ### made with SmaDIB: Smart Database Interface Builder 0.4.0 ### ### by Smartmedia 2000 http://www.smartmedia2000.it/ ### ### info email: smadib@smartmedia2000.it ### ### released under GPL license http://www.gnu.org/licenses/gpl.txt ### ###___###___###___###___###____###____###____###___###___###___###___### require_once ("../funct.php"); require_once ("sess.php"); require_once ("conn.php"); $ptitolo = "Fotografie gallerie"; $table = "foto"; $ajOrd = "y"; $query = new doQuery(); $foto = $_REQUEST['foto']; $userfile = $_FILES[userfile]; $ordine = $_REQUEST['ordine']; $ordineOld = $_REQUEST['ordineOld']; $id_galleriasel = array (); $fotoRiga = 6; $selGal = ""; $updir = $_SESSION['perc_strutt']."fotogal/"; $id_galleria_id = array (); $id_galleria_nome = array (); $ris = mysql_query ("SELECT `id`, `nome_it` FROM `gallerie` WHERE `id_utente` = $id_utente",$conn) or die("Select foreign key error: ".mysql_error()); while ($row = mysql_fetch_object($ris)) { array_push ($id_galleria_id, $row->id); array_push ($id_galleria_nome, $row->nome_it); } $id_galleria = $_REQUEST['id_galleria'] != "" ? $_REQUEST['id_galleria'] : $id_galleria_id[0]; $noModPar = "?id_galleria=$id_galleria"; require_once ("testacoda.php"); if ($op == "ord") { $rows = $query->freeQuery ("SELECT `id`, `ordine` FROM `$table` WHERE `id_galleria`='$id_galleria' ORDER BY `ordine` ASC", 0, $conn); foreach ($rows as $i=>$row) $query->freeQuery ("UPDATE `$table` SET `ordine`='".($i+1)."' WHERE `id`=".$row->id, 0, $conn); } $foto_id = array (0); $foto_ordine = array (1000); $sql = "SELECT `id`, `ordine` FROM `$table` WHERE `id_utente` = $id_utente AND `id_galleria` = $id_galleria ORDER BY `ordine`, `id` ASC"; $ris = mysql_query($sql, $conn) or die("Select id_galleria $sql: ".mysql_error()); while ($row = mysql_fetch_object($ris)) { array_push ($foto_id, $row->id); array_push ($foto_ordine, $row->ordine); $maxOrd = $row->ordine; } $posOrd = array_search ($ordine, $foto_ordine); if ($posOrd == "") $posOrd = count($foto_ordine); if ($ordine == "") $ordine = $maxOrd+1; if ($az=="canc") { $sql = "SELECT foto FROM foto WHERE id=$id LIMIT 1"; $ris = mysql_query($sql,$conn) or die("6 ".mysql_error()); $row = mysql_fetch_object($ris); if ($row->foto != "") { unlink ($perc.$updir.$row->foto); unlink ($perc.$updir."p_".$row->foto); } $sql = "DELETE FROM `$table` WHERE `id`='$id' LIMIT 1"; mysql_query($sql,$conn) or die ("DELETE error - $sql: ".mysql_error()); for ($i=$posOrd; $i<count($foto_ordine); $i++) { $sql = "UPDATE `$table` SET `ordine` = ".($foto_ordine[$i]-1)." WHERE `id` = ".$foto_id[$i]; mysql_query($sql,$conn) or die($sql.": ".mysql_error()); } header("Location: ".$_SERVER['PHP_SELF']."?id_galleria=$id_galleria"); } if ($op == "ds") { $foto = $_FILES['userfile']['name']; $sql = "SELECT `id` FROM `$table` WHERE `foto`='$foto' AND `id_galleria`='$id_galleria' AND `id_utente`='$id_utente'"; $ris = mysql_query($sql,$conn) or die($sql.": ".mysql_error()); if (!mysql_num_rows($ris) && (strpos(strtolower($foto), '.jpg') || strpos(strtolower($foto), '.gif') || strpos(strtolower($foto), '.png'))) { $risupl = preupload ($userfile,$updir); resampleImg ($foto); $query->freeQuery ("INSERT INTO `$table` (`id_utente`, `foto`, `id_galleria`, `ordine`) VALUES ($id_utente, '$foto', '$id_galleria', '$ordine')", 0, $conn); for ($i=$posOrd; $i<count($foto_ordine); $i++) $query->freeQuery ("UPDATE `$table` SET `ordine` = ".($foto_ordine[$i]+1)." WHERE `id` = ".$foto_id[$i], 0, $conn); } header("Location: ".$_SERVER['PHP_SELF']."?id_galleria=$id_galleria"); } else if ($op == "up") { if ($_FILES['userfile']['name'] != "") { $fotoold = $foto; $foto = $_FILES['userfile']['name']; if (strpos(strtolower($foto), '.jpg') || strpos(strtolower($foto), '.gif') || strpos(strtolower($foto), '.png')) { if ($fotoold != "") { unlink ($perc.$updir.$fotoold); unlink ($perc.$updir."p_".$fotoold); } $risupl = preupload ($userfile,$updir); resampleImg ($foto); } } $sql = "UPDATE `$table` SET `foto`='$foto', `id_galleria`='$id_galleria', `ordine`='$ordine' WHERE `id`=$id LIMIT 1"; $ris = mysql_query($sql,$conn) or die("UPDATE error - $sql: ".mysql_error()); if ($ordine >= $ordineOld) { $nn = -1; $posOrd = array_search ($ordineOld+1, $foto_ordine); $limO = $ordine+1; } else { $nn = 1; $limO = $ordineOld; } if ($ordine != $ordineOld) for ($i=$posOrd; $i<$limO; $i++) { $sql = "UPDATE `$table` SET `ordine` = ".($foto_ordine[$i]+$nn)." WHERE `id` = ".$foto_id[$i]; if ($foto_id[$i] != $id) $query->freeQuery ($sql, 0, $conn); } header("Location: ".$_SERVER['PHP_SELF']."?id_galleria=$id_galleria"); } if ($az=="ed") { $row = $query->selectById (0, $conn); $id = $row->id; $ordine = $row->ordine; $valop = "up"; $id_galleria0 = array_search($row->id_galleria,$id_galleria_id); $id_galleriasel[$id_galleria0] = "selected"; $elenco.= "<input type=\"hidden\" name=\"id_galleria\" value=\"$id_galleria\" />\n"; $inputFoto = $row->foto; } else { $valop = "ds"; if ($id_galleria) { $id_galleria0 = array_search($id_galleria, $id_galleria_id); $id_galleriasel[$id_galleria0] = "selected"; } $selGal = "<select name=\"id_galleria\" onchange=\"javascript:changeGal();\">\n"; for ($s=0;$s<count($id_galleria_id);$s++) $selGal.= "<option value=\"$id_galleria_id[$s]\" $id_galleriasel[$s]>$id_galleria_nome[$s]</option>\n"; $selGal.= "</select>"; $inputFoto = "<input name=\"foto\" type=\"hidden\" value=\"$row->foto\"> <input type=\"file\" name=\"userfile\" value=\"$row->foto\" size=\"30\">"; } $elenco.= "<tr bgcolor=\"white\"> <td><b>Foto</b></td> <td><b>Ordine</b></td> </tr><tr bgcolor=\"#EEEEEE\"> <td>$inputFoto</td> <td><select name=\"ordine\"><option value=\"".$ordine."\">$ordine</option>\n"; for ($s=1; $s<=$maxOrd; $s++) $elenco.= "<option value=\"$s\">$s</option>\n"; $elenco.= "</select></td></tr> <tr bgcolor=\"#EEEEEE\"> <td align=\"center\" colspan=\"3\"><input type=\"submit\" name=\"invio\" value=\"$intesta\"> $noMod <input type=\"hidden\" name=\"op\" value=\"$valop\"> <input type=\"hidden\" name=\"ordineOld\" value=\"$ordine\" /> <input type=\"hidden\" name=\"id\" value=\"$id\" /> <div id=\"changeNotification\" style=\"display:none;\"> </div> </td></tr></form>\n"; $sql = "SELECT * FROM `foto` WHERE `id_utente` = $id_utente"; if ($az=="ed") $sql.= " AND `id` != $id"; $sql.= " AND `id_galleria` = '$id_galleria' ORDER BY `ordine`, `foto` ASC"; $rows = $query->freeQuery ($sql, 0); $elenco.= "<tr><td colspan=\"3\"> <table width=\"600\" align=\"center\"><tr><td width=\"600\"> <div id=\"sortlist\">\n"; foreach ($rows AS $row) $elenco.= " <img class=\"sorting\" alt=\"".$row->foto."\" id=\"pictureId_".$row->id."\" src=\"http://www.".$updir."p_".$row->foto."\" />\n"; $elenco.= "</td></tr> </table> </form>"; echo $testa; ?> <h2 align="center"><?php echo $ptitolo; ?></h2> <form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data"> <div align="center"><?php echo $selGal; ?></div> <br /> <table align="center"> <?php echo $elenco; ?> </table> <input type="button" value="Ricostruisci ordine" onclick="javascript:document.location='<?php echo $_SERVER['PHP_SELF']; ?>?id_galleria=$id_galleria&op=ord'" /> <?php echo $coda; function resampleImg ($foto) { # ridimensiona la foto global $perc; global $updir; list($width, $height) = getimagesize($perc.$updir.$foto); if ($width >= $height) {$newW = 500; $newH = $newW*$height/$width; $newWp = 65; $newHp = $newWp*$height/$width; } else {$newH = 500; $newW = $newH*$width/$height; $newHp = 65; $newWp = $newHp*$width/$height; } $image = imagecreatefromjpeg ($perc.$updir.$foto); $image_sh = imagecreatetruecolor ($newW, $newH); imagecopyresampled ($image_sh, $image, 0, 0, 0, 0, $newW, $newH, $width, $height); imagejpeg ($image_sh, $perc.$updir.$foto, 70); $image_tn = imagecreatetruecolor ($newWp, $newHp); imagecopyresampled ($image_tn, $image, 0, 0, 0, 0, $newWp, $newHp, $width, $height); imagejpeg ($image_tn, $perc.$updir."p_".$foto, 70); chmod ($perc.$updir."p_".$foto, 0666); } ?>
Save File
Cancel