"#cccccc")); setdefault("table",array("cellpadding"=>"0","cellspacing"=>"0","bgcolor"=>"#99aacc","width"=>"650","height"=>"500")); setdefault("text",array("size"=>"1.5", "face" =>"verdana,arial,helvetica")); newhtml(&$w); insert($w, $h = wheader("PHP Photo Gallery")); //// INCLUDE JAVASCRIPT FOR WINDOW POPUPS include("include/js.php"); //insert($h,style($m,"include/style.css"); // GENERATE HEADER TITLE BAR insert($w,$t = table(array("cellpadding"=>"0","cellspacing"=>"0","cols"=>"1","width"=>"800","height"=>"5"))); insert($t,$c = cell(array("colspan"=>"1","valign"=>"top","align"=>"center"))); insert($t,$t2 = table(array("cellpadding"=>"1","cellspacing"=>"0","cols"=>"3","width"=>"800","height"=>"5"))); insert($t2,$c = cell(array("colspan"=>"1","valign"=>"top","align"=>"left"))); insert($c,text("PHP Photo Gallery",array("color"=>"white"))); insert($t2,$c = cell(array("colspan"=>"1","valign"=>"top","align"=>"right"))); insert($c,anchor("index.php","Album")); insert($t2,$c = cell(array("colspan"=>"1","valign"=>"top","align"=>"right"))); insert($c,anchor("upload.php","Upload")); //// GENERATE RED BAR WITH FINAL SUBMIT BUTTON AND WARNING if (($_POST["crop"]) || ($_POST["directory"])) { insert($t,$c33 = cell(array("colspan"=>"1","valign"=>"top","align"=>"center"))); insert($c33, $f = form(array("name"=>"uploadall","method"=>"post","action"=>$_SERVER['PHP_SELF']))); insert($f, hidden(array("name"=>"alldone","value"=>"true"))); insert($f,$t22 = table(array("cellpadding"=>"6","cellspacing"=>"0","cols"=>"2","width"=>"800","height"=>"5","bgcolor"=>"#ccaaaa"))); insert($t22,$c = cell(array("colspan"=>"1","valign"=>"top","align"=>"left"))); insert($c, submit(array("value"=>"I'm done... continue"))); insert($t22,$c = cell(array("colspan"=>"1","valign"=>"top","align"=>"right"))); insert($c,text("Edit images individually, when all are done click here to continue uploading them to the database",array("color"=>"black"))); } $tmp_dir =$_SERVER["DOCUMENT_ROOT"]."/album/photos/"; //// PAGE IS SETUP AND NOW TO ## UPLOAD AND EDIT IMAGES if ($_POST["alldone"]=="true") { //// GENERATE FINAL PAGE, PHOTOS ADDED TO DATABASE insert($w,$t3 = table(array("cellpadding"=>"6","cellspacing"=>"0","bgcolor"=>"#cccccc","cols"=>"1","width"=>"800","height"=>"460"))); insert($t3,$c = cell(array("colspan"=>"1","valign"=>"top"))); insert($c,text("Photos have been added",array("size"=>"2", "face" =>"verdana,arial,helvetica"))); // ESTABLISH DB CONN $dbconn2 = pg_connect ("host=localhost port=5432 dbname=sessions user=postgres"); $dbconn3 = pg_connect ("host=localhost port=5432 dbname=photo_album user=postgres"); if (!$dbconn2 || !$dbconn3) { print "could not connect
"; } // GENERATE QUERY AND LOOP TO GET INFO $query = "SELECT * FROM tmp_images"; $result = pg_query ($dbconn2,$query); while ($i = pg_fetch_array($result)) { $tmplink = $i["link"]; $tmpmod = $i["mod"]; $tmpignore = $i["ignore"]; $tmprotate = $i["rotate"]; $tmpgrp = $i["grp"]; $tmpcrop=$i["crop"]; switch ($tmpcrop) { case 100: $crop_top = 0; $crop_bottom = 134; break; case 75: $crop_top = 34; $crop_bottom = 100; break; case 50: $crop_top = 67; $crop_bottom = 67; break; case 25: $crop_top = 100; $crop_bottom = 34; break; case 0: $crop_top = 134; $crop_bottom = 0; break; } $output_dir_thumb = $_SERVER["DOCUMENT_ROOT"]."/album/images/photos/thumbnails/".$tmplink; $output_dir_normal = $_SERVER["DOCUMENT_ROOT"]."/album/images/photos/normalsize/".$tmplink; $output_dir_fullsize = $_SERVER["DOCUMENT_ROOT"]."/album/images/photos/fullresolution/".$tmplink; /// NOW CREATE THE REAL IMAGES passthru("cp photos/".$tmplink." ".$output_dir_fullsize); /// MAKE the cropped good image $cc->loadImage($output_dir_fullsize); $cc->cropToDimensions(0, $crop_top, 1599, (1200-$crop_bottom)); $cc->saveImage($output_dir_fullsize, 95); /// MAKE the thumbnail and larger size image_resize_jpeg($output_dir_fullsize, $output_dir_normal, 85,800); image_resize_jpeg($output_dir_fullsize, $output_dir_thumb, 70,120); /// NOW rotate all images except the main good one if ($tmprotate=="t") { $file= $output_dir_normal; $src_img = ImageCreateFromJPEG($file); $src_img = ImageRotate($src_img,270,0); ImageJPEG($src_img, $file, 80); $file= $output_dir_thumb; $src_img = ImageCreateFromJPEG($file); $src_img = ImageRotate($src_img,270,0); ImageJPEG($src_img, $file, 70); } ////////// GET IMAGE CREATION DATE/TIME FROM EXIF DATA IN IMAGE $exif = exif_read_data ("photos/".$tmplink); $mytimetmp=$exif['DateTime']; $tmp1 = explode(" ",$mytimetmp); $td1 = explode (":",$tmp1[0]); ///this is the date $td2 = explode (":",$tmp1[1]); ///this is the time $mytime = mktime($td2[0], $td2[1], $td2[2], $td1[1], $td1[2], $td1[0]); //// FINALLY UPDATE PHOTOS DATABASE if ($tmpignore=="f") { $query2 = "INSERT INTO photos VALUES (nextval('public.photos_id_seq'::text),'".$output_dir_thumb."','".$output_dir_normal."','".$output_dir_fullsize."','".$mytime."','".$tmpgrp."')"; $result2 = pg_query ($dbconn3,$query2); passthru("rm -f photos/".$tmpmod); } } $firstform = 1; } ///////// ## START ## UPLOAD CODE //------------------------------------------ if ($_POST["directory"]) { $count=0; $dbconn2 = pg_connect ("host=localhost port=5432 dbname=sessions user=postgres"); if (!$dbconn2) { print "could not connect
"; } if ($handle = opendir($tmp_dir)) { // Reads all files in /images while (false !== ($file = readdir($handle))) { if (($file != ".") && ($file != "..") && ($file != "1")) { ////// DB CODE - ADD TMP IMAGE INFO TO DB $query = "INSERT INTO tmp_images VALUES (nextval('public.tmp_images_id_seq'::text), '".$file."', '_tmp_".$file."', '50', 'all', 'f', 'f','".time()."','f')"; $result = pg_query ($dbconn2,$query); /// NOW CROP THE TMP IMAGE image_resize_jpeg($tmp_dir.$file, $tmp_dir."_tmp_".$file, 65,161); $cc->loadImage($tmp_dir."_tmp_".$file); $cc->cropToDimensions(0, 7, 160, 114); $cc->saveImage($tmp_dir."_tmp_".$file); //// UOPDATE COUNT TO COMPLETE THE LOOP $count++; } } } } elseif (!($_POST["crop"]) && !($_POST["directory"]) && !($_POST["alldone"])) { insert($w,$t3 = table(array("cellpadding"=>"6","cellspacing"=>"0","bgcolor"=>"#cccccc","cols"=>"1","width"=>"800","height"=>"460"))); insert($t3,$c = cell(array("colspan"=>"1","valign"=>"top"))); insert($c,text("Enter the photo directory:",array("size"=>"2", "face" =>"verdana,arial,helvetica"))); insert($c, $f = form(array("name"=>"upload","method"=>"post","action"=>$_SERVER[PHP_SELF]))); insert($f, input_text(array("name"=>"directory","value"=>"photos/","size"=>"20"))); insert($f, submit(array("value"=>"Add Images"))); $firstform = 1; } // ### END ### UPLOAD CODE //------------------------------------------ if ($_POST["crop"]) { $dbconn2 = pg_connect ("host=localhost port=5432 dbname=sessions user=postgres"); if (!$dbconn2) { print "could not connect
"; } /// GRAB THE ID TO USE FROM POST $tmp_id=$_POST["submitted_id"]; $query = "SELECT * FROM tmp_images WHERE id='".$tmp_id."'"; $result = pg_query ($dbconn2,$query); $i = pg_fetch_array($result); $p =$i["link"]; $p2 =$i["mod"]; $pathfile = "photos/".$p; $mod_pathfile = "photos/".$p2; //160x120 original needs to go to 160x107 //1600x1200 goes to 1600x1066 // NOW GRAB OTHER POST VARIABLES AND MAKE NEW VARS if ($_POST["crop"]) { $tmpcrop = $_POST["crop"]; switch ($tmpcrop) { case 100: $crop_top = 0; $crop_bottom = 13; break; case 75: $crop_top = 4; $crop_bottom = 9; break; case 50: $crop_top = 7; $crop_bottom = 6; break; case 25: $crop_top = 9; $crop_bottom = 4; break; case 0: $crop_top = 13; $crop_bottom = 0; break; } /// NOW CROP THE TMP IMAGE image_resize_jpeg($pathfile, $mod_pathfile, 65,161); $cc->loadImage($mod_pathfile); $cc->cropToDimensions(0, $crop_top, 160, (120-$crop_bottom)); //$cc->showImage('png'); $cc->saveImage($mod_pathfile, 65); } if ($_POST["grp"]) { $tmpgrp = $_POST["grp"]; } if ($_POST["rotate"]=="t") { $tmprotate = $_POST["rotate"]; $file= $mod_pathfile; $src_img = ImageCreateFromJPEG($file); $src_img = ImageRotate($src_img,270,0); ImageJPEG($src_img, $file, 100); } else { $tmprotate = "f"; } if ($_POST["ignore"]=="t") { $tmpignore = $_POST["ignore"]; }else { $tmpignore = "f"; } if ($_POST["complete"]=="t") { $tmpcomplete = $_POST["complete"]; }else { $tmpcomplete = "f"; } ///// NOW TO UPDATE THE DB FOR THIS RECORD $query = "UPDATE tmp_images SET crop='".$tmpcrop."', grp='".$tmpgrp."', rotate='".$tmprotate."', ignore='".$tmpignore."', last_accessed='".time()."', complete='".$tmpcomplete."' WHERE id='".$tmp_id."'"; $result = pg_query ($dbconn2,$query); /// DONE CONTINUE LOADING PAGE..... >> } if ($firstform==0) { ///////// ## START ## DISPLAY PAGE // print body table insert($w,$t5 = table(array("cellpadding"=>"0","cellspacing"=>"0","cols"=>"1","width"=>"800","height"=>"460"))); $tmp_dir =$_SERVER["DOCUMENT_ROOT"]."/album/photos/"; //include("include/resize_images.php"); insert($t5,$c2 = cell(array("colspan"=>"1","bgcolor"=>"#cccccc","valign"=>"top"))); insert($c2,$tt = table(array("cellpadding"=>"0","cellspacing"=>"0","cols"=>"1","width"=>"800","height"=>"10","bgcolor"=>"#dddddd"))); /// SETUP DATABASE CONN $dbconn2 = pg_connect ("host=localhost port=5432 dbname=sessions user=postgres"); if (!$dbconn2) { print "could not connect
"; } /// LOOP THRU AND GRAB INFO $query = "SELECT * FROM tmp_images ORDER BY last_accessed DESC"; $result = pg_query ($dbconn2,$query); $count=0; while($i = pg_fetch_array($result)) { insert($tt,$cc = cell(array("colspan"=>"1","bgcolor"=>"#cccccc","valign"=>"top"))); insert($cc, $f = form(array("name"=>"update_photo","method"=>"post","action"=>$_SERVER[PHP_SELF]))); insert($f,$t6 = table(array("cellpadding"=>"8","cellspacing"=>"0","cols"=>"3","width"=>"800","height"=>"10","bgcolor"=>"#dddddd"))); //DO ALTERNATE ROW COLOURS if (($count%2)==0) { if ($i["complete"]=="t") { $row_alt="#ccddcc"; } else { $row_alt="#dddddd"; } } else { if ($i["complete"]=="t") { $row_alt="#bbccbb"; } else { $row_alt="#cccccc"; } } $image_link = "photos/".$i["link"]; $mod_link = "photos/".$i["mod"]; /// **** DISPLAY ORIGINAL IMAGE insert($t6,$c4 = cell(array("colspan"=>"1","bgcolor"=>"$row_alt","valign"=>"middle","align"=>"center"))); insert($c4,anchor("Javascript:Start('".$image_link."')",image($image_link, array("width"=>"160","height"=>"120","alt"=>"Image ID: ".$i['id'],"border"=>"0")))); /// **** DISPLAY ADJUSTED IMAGE insert($t6,$c4 = cell(array("colspan"=>"1","bgcolor"=>"$row_alt","valign"=>"middle","align"=>"center"))); insert($c4,anchor("Javascript:Start('".$mod_link."')",image($mod_link, array("alt"=>"Image ID: ".$i['id'],"border"=>"0")))); /// **** DISPLAY FORM TO ADJUST PICS insert($t6,$c4 = cell(array("colspan"=>"1","bgcolor"=>"$row_alt","valign"=>"top","align"=>"center"))); insert($c4,$t7 = table(array("cellpadding"=>"6","cellspacing"=>"0","cols"=>"2","width"=>"100%","height"=>"10"))); insert($t7,$c5 = cell(array("cellpadding"=>"0","cellspacing"=>"0","colspan"=>"1","valign"=>"top","bgcolor"=>"$row_alt"))); ///// SETUP IGNORE CHECKBOX if ($i["ignore"] == "t") { insert($c5, checkbox(array("name"=>"ignore","value"=>"t")," ","checkecd")); } else { insert($c5, checkbox(array("name"=>"ignore","value"=>"t")," ")); } insert($c5,text(" do not upload this image now")); ///// SETUP SUBMIT BUTTON insert($t7,$c5 = cell(array("cellpadding"=>"0","cellspacing"=>"0","colspan"=>"1","bgcolor"=>"$row_alt","valign"=>"top","align"=>"center"))); insert($c5, submit(array("value"=>"Update this image now"))); insert($c5, hidden(array("name"=>"submitted_id","value"=>$i["id"]))); ///// SETUP CROP AREA insert($t7,$c5 = cell(array("cellpadding"=>"0","cellspacing"=>"0","colspan"=>"1","bgcolor"=>"$row_alt","valign"=>"top"))); insert($c5,text("Crop:
")); if ($i["crop"] == "100") { insert($c5, radio(array("name"=>"crop","value"=>"100")," ","checkecd")); } else { insert($c5, radio(array("name"=>"crop","value"=>"100")," ")); } insert($c5,text("100% top, 0% bottom
")); if ($i["crop"] == "75") { insert($c5, radio(array("name"=>"crop","value"=>"75")," ","checkecd")); } else { insert($c5, radio(array("name"=>"crop","value"=>"75")," ")); } insert($c5,text("75% top, 25% bottom
")); if ($i["crop"] == "50") { insert($c5, radio(array("name"=>"crop","value"=>"50")," ","checkecd")); } else { insert($c5, radio(array("name"=>"crop","value"=>"50")," ")); } insert($c5,text("50% top, 50% bottom
")); if ($i["crop"] == "25") { insert($c5, radio(array("name"=>"crop","value"=>"25")," ","checkecd")); } else { insert($c5, radio(array("name"=>"crop","value"=>"25")," ")); } insert($c5,text("25% top, 75% bottom
")); if ($i["crop"] == "none") { insert($c5, radio(array("name"=>"crop","value"=>"none")," ","checkecd")); } else { insert($c5, radio(array("name"=>"crop","value"=>"none")," ")); } insert($c5,text("0% top, 100% bottom")); //// ROTATE insert($t7,$c5 = cell(array("cellpadding"=>"0","cellspacing"=>"0","colspan"=>"1","bgcolor"=>"$row_alt","valign"=>"top"))); insert($c5,text("
Rotate image:
")); ///// SETUP ROTATE CHECKBOX if ($i["rotate"] == "t") { insert($c5, checkbox(array("name"=>"rotate","value"=>"t")," ","checkecd")); } else { insert($c5, checkbox(array("name"=>"rotate","value"=>"t")," ")); } insert($c5,text(" 90 degrees clockwise
")); ///// SETUP GROUPS AREA insert($c5,text("grp:
")); ///// if ($i["grp"] == "all") { insert($c5, radio(array("name"=>"grp","value"=>"all")," ","checkecd")); } else { insert($c5, radio(array("name"=>"grp","value"=>"all")," ")); } insert($c5,text("All")); ///// if ($i["grp"] == "marks") { insert($c5, radio(array("name"=>"grp","value"=>"marks")," ","checkecd")); } else { insert($c5, radio(array("name"=>"grp","value"=>"marks")," ")); } insert($c5,text("Mark's")); ///// if ($i["grp"] == "crystelles") { insert($c5, radio(array("name"=>"grp","value"=>"crystelles")," ","checkecd")); } else { insert($c5, radio(array("name"=>"grp","value"=>"crystelles")," ")); } insert($c5,text("Crystelle's
")); ///// SETUP COMPLETE CHECKBOX if ($i["complete"] == "t") { insert($c5, checkbox(array("name"=>"complete","value"=>"t")," ","checkecd")); } else { insert($c5, checkbox(array("name"=>"complete","value"=>"t")," ")); } insert($c5,text(" changes complete

")); $count++; } // end while } // end if // PRINT FOOTER TABLE $exec_time = array_sum(explode(' ', microtime())) - $t_start; insert($w,$t = table(array("cellpadding"=>"1","cols"=>"1","width"=>"800","height"=>"10"))); insert($t,$c = cell(array("colspan"=>"1"))); insert($c,text("Page generated in " . sprintf("%0.2f",$exec_time) . " seconds", array("size"=>"1", "face" =>"verdana,arial,helvetica","color"=>"black"))); printhtml($w); ?>