← Back
Editing: fotogallerie_ed.php
<?php #______________________________________________________________________# ### made with SmaDIB: Smart Database Interface Builder 0.4.0 ### ### by Smartmedia 2000 http://www.smartmedia2000.it/ ### ### info email: smadib@smartmedia2000.it ### ###___###___###___###___###____###____###____###___###___###___###___### require_once ("../funct.php"); require_once ("sess.php"); require_once ("conn.php"); $ptitolo = "Galleria fotografica"; $table = "foto"; if ($_REQUEST['az'] == "ord") { $ajOrd = "y"; $ptitolo = "LightBox"; } $query = new doQuery(); $uplFl = $_REQUEST['uplFl']; $foto = $_REQUEST['foto']; $userfile = $_FILES[userfile]; $ordine = $_REQUEST['ordine']; $ordineOld = $_REQUEST['ordineOld']; $id_galleriasel = array (); require "upload.php"; $updir = $_SESSION['perc_strutt']."fotogal/"; $save_path = $updir; # recupare la dimensione stabilita delle foto da inserire $sqlD = "SELECT `dim_foto`, `dim_thumb`, `dim_grande` FROM `utenti` WHERE `id` = $id_utente"; $rowD = $query->freeQuery ($sqlD, 0); $dim_foto = $rowD[0]->dim_grande; $dim_thumb = $rowD[0]->dim_thumb; $dim_grande = 0; $id_galleria_id = array (); $id_galleria_nome = array (); $sqlG = "SELECT `id`, `nome_it` FROM `gallerie` WHERE `id_utente` = $id_utente ORDER BY `ordine` ASC"; $rowsG = $query->freeQuery ($sqlG, 0); foreach ($rowsG AS $rowG) { $id_galleria_id[] = $rowG->id; $id_galleria_nome[] = $rowG->nome_it; } $id_galleria = $_REQUEST['id_galleria'] ? $_REQUEST['id_galleria'] : $id_galleria_id[0]; $noModPar = "?id_galleria=$id_galleria"; $urlParam = "?id_galleria=$id_galleria&uplFl=$uplFl"; require_once ("testacoda.php"); if ($op == "ord") { # riordino forzato per id $rows = $query->freeQuery ("SELECT `id`, `ordine` FROM `$table` WHERE `id_galleria`= $id_galleria ORDER BY `ordine` ASC", 0); foreach ($rows as $i=>$row) $query->freeQuery ("UPDATE `$table` SET `ordine`='".($i+1)."' WHERE `id`=".$row->id, 0); } $foto_id = array (0); $foto_ordine = array (1000); $sqlF = "SELECT `id`, `ordine` FROM `$table` WHERE `id_utente` = $id_utente AND `id_galleria` = $id_galleria ORDER BY `ordine`, `id` ASC"; $rowsF = $query->freeQuery ($sqlF, 0); foreach ($rowsF AS $rowF) { $foto_id[] = $rowF->id; $foto_ordine[] = $rowF->ordine; $maxOrd = $rowF->ordine; } $posOrd = array_search ($ordine, $foto_ordine); if ($posOrd == "") $posOrd = count ($foto_ordine); if ($ordine == "") $ordine = $maxOrd+1; if (count ($_POST['canc']) > 0) { foreach ($_POST['canc'] AS $id) { $sql = "SELECT `foto` FROM `foto` WHERE `id`=$id LIMIT 1"; $row = $query->freeQuery ($sql, 0); if ($row[0]->foto != "") { unlink ($updir.$row[0]->foto); unlink ($updir."p_".$row[0]->foto); unlink ($updir."g_".$row[0]->foto); } $ord = $query->selectFldAs ($table, array ('ordine'=>'ordine'), 1); for ($i=$ord[0]; $i<=count($foto_id); $i++) $query->freeQuery ("UPDATE `$table` SET `ordine` = ".$i." WHERE `id_utente` = $id_utente AND `id_galleria` = $id_galleria AND `ordine` = ".($i+1), 0); $query->delete (); // for ($i=$posOrd; $i<count($foto_ordine); $i++) { // $sql = "UPDATE `$table` SET `ordine` = ".($foto_ordine[$i]-1)." WHERE `id` = ".$foto_id[$i]; // $query->freeQuery ($sql, 0); // } } header("Location: ".$_SERVER['PHP_SELF'].$urlParam); } 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, $dim_foto, $dim_thumb, $dim_grande); $query->freeQuery ("INSERT INTO `$table` (`id_utente`, `foto`, `id_galleria`, `ordine`) VALUES ($id_utente, '$foto', '$id_galleria', '$ordine')", 0); for ($i=$posOrd; $i<count($foto_ordine); $i++) $query->freeQuery ("UPDATE `$table` SET `ordine` = ".($foto_ordine[$i]+1)." WHERE `id` = ".$foto_id[$i], 0); } header("Location: ".$_SERVER['PHP_SELF'].$urlParam); } 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, $dim_foto, $dim_thumb, $dim_grande); } } $sql = "UPDATE `$table` SET `foto`='$foto', `id_galleria`='$id_galleria', `ordine`='$ordine' WHERE `id`=$id LIMIT 1"; $query->freeQuery ($sql, 0); 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'].$urlParam); } if ($az == "ord") { # riordino ajax $id_galleria0 = array_search ($row->id_galleria, $id_galleria_id); $selGal = $id_galleria_nome [$id_galleria0]; $sql = "SELECT * FROM `$table` WHERE `id_utente` = $id_utente AND `id_galleria` = $id_galleria ORDER BY `ordine`, `foto` ASC"; $rows = $query->freeQuery ($sql, 0); $elenco.= "<tr><td height=\"1\"><div id=\"changeNotification\" style=\"display:none;\"> </div></td></tr> <tr><td><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.".$dominio."/fotogal/p_".$row->foto."\" />\n"; $elenco.= "</td></tr> </table> </form>"; echo $testa; ?> <div align="center"> <h2><div align="center"><?php echo $ptitolo; ?></div></h2> <h3><div align="center"><?php echo $selGal; ?></div></h3> <div align="center"> <table align="center"> <?php echo $elenco; ?> </table> <input type="button" value="Fine ordinamento" onclick="document.location='<?php echo $_SERVER['PHP_SELF'].$urlParam; ?>&az=ord2'" /> </div> <?php echo $coda; } else if ($az == "ord2") { $sql0 = "SELECT `id`, `ordine` FROM `".$table."` WHERE `id_utente` = ".$id_utente." AND `id_galleria` = ".$id_galleria; $rows0 = $query->freeQuery ($sql0, 0); //print_r($rows0); foreach ($rows0 as $row0) { $sql = "UPDATE `".$table."` SET `ordine` = ".$row0->ordine." WHERE `id` = ".$row0->id; $query->freeQuery ($sql, 0); //echo "<br />".$sql; } header ("Location: ".$_SERVER['PHP_SELF'].$urlParam); } else { # modifica o visualizza normalmente if ($az=="ed") { $row = $query->selectById (0); $id = $row->id; $ordine = $row->ordine; $valop = "up"; $id_galleria0 = array_search($row->id_galleria,$id_galleria_id); $id_galleriasel[$id_galleria0] = "selected"; $selGal.= "<option value=\"".$row->id_galleria."\">".$id_galleria_nome [$id_galleria0]."</option>\n"; $form = "<td width=\"450\">$ordine </td><td>".$row->foto."<input type=\"hidden\" name=\"id_galleria\" value=\"$id_galleria\" /></td>"; } else { $valop = "ds"; if ($id_galleria) { $id_galleria0 = array_search($id_galleria, $id_galleria_id); $id_galleriasel[$id_galleria0] = "selected"; } 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"; $form = "<td><select name=\"ordine\"><option value=\"".$ordine."\">$ordine</option>\n"; for ($s=1; $s<=$maxOrd; $s++) $form.= "<option value=\"$s\">$s</option>\n"; $form.= "</select></td><td> <input name=\"foto\" type=\"hidden\" value=\"".$row->foto."\"> ".$row->foto."<input type=\"file\" name=\"userfile\" value=\"".$row->foto."\" size=\"30\"></td>"; } if ($uplFl == "y") $elenco = "<div id=\"allbox\"> <p>Puoi caricare un massimo di 20 immagini alla volta</p> <p><script type=\"text/javascript\"> <!-- AC_FL_RunContent('width','300','height','50','flashVars','configFile=config.xml&IDValue=xml','movie','uploader-advanced','id','imageUploader','quality','high','allowScriptAccess','sameDomain'); //--> </script> <noscript> <!--[if lte IE 6]> <object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0\" type=\"application/x-shockwave-flash\" width=\"120\" height=\"30\" id=\"imageUploader\"> <![endif]--> <!--[if gt IE 6]><!--> <object type=\"application/x-shockwave-flash\" width=\"300\" height=\"50\" data=\"uploader-advanced.swf\" id=\"imageUploader\"> <!--<![endif]--> <param name=\"movie\" value=\"uploader-advanced.swf\" /> <param name=\"allowScriptAccess\" value=\"sameDomain\" /> <param name=\"flashVars\" value=\"configFile=config.xml&IDValue=xml\" /> <param name=\"quality\" value=\"high\" /> </object> </noscript> </p> <form action=\"processform.php\" method=\"post\" enctype=\"multipart/form-data\" id=\"myForm\"> <input type=\"hidden\" name=\"save_path\" value=\"".$save_path."\" /> <div><p>Stato: <b id=\"statusbox\" style=\"color:#080\">pronto</b></p> Immagini da elaborare: <input type=\"text\" id=\"imCounter\" name=\"imCounter\" size=\"4\" /><br /> <br /> <table width=\"400\" align=\"center\"><tr><td> <div id=\"dynamicArea\"> </div> </td></tr></table> <br clear=\"all\" /> <div id=\"dynamicButton\"> </div> <input type=\"hidden\" name=\"id_galleria\" value=\"$id_galleria\" /> <input type=\"hidden\" name=\"uplFl\" value=\"$uplFl\" /> </form> </div><br /> </td></tr>\n"; else $elenco.= "<p>$form </p> <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\" /> </form>\n"; $elenco.= "<form name=\"canc\" method=\"post\" action=\"".$_SERVER['PHP_SELF']."\"> <input type=\"hidden\" name=\"uplFl\" value=\"$uplFl\" /> <input type=\"hidden\" name=\"id_galleria\" value=\"$id_galleria\" /> <table align=\"center\" width=\"100%\">\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); foreach ($rows AS $cc=>$row) { $bgcolor = colriga ($cc); $elenco.= "<tr bgcolor=\"#$bgcolor\"><!-- td width=\"20\">"; if ($az != "ed") $elenco.= "<a href=\"".$_SERVER['PHP_SELF']."?id=".$row->id."&id_galleria=$id_galleria&uplFl=$uplFl&az=ed\"><img src=\"images/edit.gif\" border=\"0\" hspace=5 title=\"modifica riga\"></a>"; $elenco.= " </td --><td align=\"right\" width=\"40\" nowrap><input type=\"checkbox\" name=\"canc[".$row->id."]\" value=\"".$row->id."\" /></td> <td align=\"left\"><a href=\"javascript:PopIt('http://www.".$dominio."/fotogal/".$row->foto."')\" title=\"".$row->foto."\"><img src=\"http://www.".$dominio."/fotogal/p_".$row->foto."\" border=\"0\" align=\"absmiddle\"></a> ".$row->foto."</td></tr>\n"; } echo $testa; ?> <script language="JavaScript"> <!-- function changeGal() { //document.forms['form1'].userfile.value = ''; //document.forms['form1'].submit(); var id_gall = document.getElementById('id_galleria').value document.location='<?php echo $_SERVER['PHP_SELF']."?id_galleria='+ id_gall +'&uplFl=$uplFl"; ?>'; } function confDelM(id) { if (confirm('Vuoi cancellare le foto selezionate? Premi OK per confermare.')) document.canc.submit(); } //--> <?php if ($uplFl == "y") { ?> <!-- window.onload = function() { document.getElementById('imCounter').value = 0; } function uploaderReady() { document.getElementById('statusbox').innerHTML = 'pronto'; document.getElementById('statusbox').style.color = '#080'; } function uploaderBusy() { document.getElementById('statusbox').innerHTML = 'sto lavorando'; document.getElementById('statusbox').style.color = '#880'; } function uploaderMaxReached() { document.getElementById('statusbox').innerHTML = 'Puoi caricare un massimo di 12 immagini alla volta'; document.getElementById('statusbox').style.color = '#800'; } //--> <?php } ?> </script> <h2><div align="center"><?php echo $ptitolo; ?></div></h2> <div align="center"> <?php if ($uplFl == "y") echo "<p><a href=\"".$_SERVER['PHP_SELF']."?id_galleria=$id_galleria\">(uploader del browser)</a></p>\n"; else echo "<p><a href=\"".$_SERVER['PHP_SELF']."?id_galleria=$id_galleria&uplFl=y\">(uploader flash)</a></p> <form name=\"form1\" method=\"post\" action=\"".$_SERVER['PHP_SELF']."\" enctype=\"multipart/form-data\">\n"; ?> <select name="id_galleria" id="id_galleria" onchange="javascript:changeGal()"> <?php echo $selGal; ?> </select><br /> <?php echo $elenco; ?> </table></form> <br /> <input type="button" value="Ordina foto" onclick="javascript:document.location='<?php echo $_SERVER['PHP_SELF'].$urlParam; ?>&az=ord'" /> <input type="button" value="Cancella foto selezionate" onclick="confDelM();" /><br /> </div> <?php echo $coda; } ?>
Save File
Cancel