← Back
Editing: fotogallerie_ed.zold
<?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 = "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"; $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 ($perc.$updir.$row[0]->foto); unlink ($perc.$updir."p_".$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.".$updir."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="javascript:document.location='<?php echo $_SERVER['PHP_SELF'].$urlParam; ?>'" /> </div> <?php echo $coda; } else { # modifica o visualizza normalmente 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"; $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 class=\"fieldset flash\" id=\"fsUploadProgress\"> </div> <div id=\"divStatus\">0 file caricati</div> <input id=\"btnCancel\" type=\"button\" value=\"Ferma i caricamenti\" onclick=\"swfu.cancelQueue();\" disabled=\"disabled\" /> <span id=\"spanButtonPlaceHolder\" style=\"align: right;\"></span> <input type=\"hidden\" name=\"ordineOld\" value=\"$ordine\" /> <input type=\"hidden\" name=\"id\" value=\"$id\" /> <input type=\"hidden\" name=\"uplFl\" value=\"$uplFl\" /> <input type=\"hidden\" name=\"userfile\" /> </form>\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>".$row->ordine." <input type=\"checkbox\" name=\"canc[".$row->id."]\" value=\"".$row->id."\" /></td> <td align=\"left\"><a href=\"javascript:PopIt('http://www.".$updir.$row->foto."')\" title=\"".$row->foto."\"><img src=\"http://www.".$updir."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") { ?> var swfu; window.onload = function() { var settings = { flash_url : "swfupload.swf", upload_url: "upload_sw.php?id_galleria=<?php echo $id_galleria; ?>", post_params: {"PHPSESSID" : "<?php echo session_id(); ?>"}, file_size_limit : "100 MB", file_types : "*.*", file_types_description : "All Files", file_upload_limit : 100, file_queue_limit : 0, custom_settings : { progressTarget : "fsUploadProgress", cancelButtonId : "btnCancel" }, debug: false, // Button settings button_image_url: "/images/swfupload.png", button_width: "220", button_height: "25", button_placeholder_id: "spanButtonPlaceHolder", button_text: '<span class="theFont">clicca per caricare le foto</span>', button_text_style: ".theFont { font-size: 12; font-family: Verdana; }", button_text_left_padding: 25, button_text_top_padding: 0, // The event handler functions are defined in handlers.js file_queued_handler : fileQueued, file_queue_error_handler : fileQueueError, file_dialog_complete_handler : fileDialogComplete, upload_start_handler : uploadStart, upload_progress_handler : uploadProgress, upload_error_handler : uploadError, upload_success_handler : uploadSuccess, upload_complete_handler : uploadComplete, queue_complete_handler : queueComplete // Queue plugin event }; swfu = new SWFUpload(settings); }; <?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