.
*/
include("./include/include.php");
include("./include/db_bodies.php");
if( (!isset($_SESSION['sess_uid']) || !($_SESSION['sess_uid']>=1)) AND !(isset($_GET['login']) OR isset($_POST['login'])) ) {
// User needs to log in first
header("location: ".$_SERVER['PHP_SELF']."?login");
exit;
}
page_header();
$photocount=-1;
if( isset($_GET['reset']) ) {
// Reset session vars for this page
$_SESSION['addphoto_start']=NULL;
$_SESSION['addphoto_count']=NULL;
$_SESSION['addphoto_book']=NULL;
}
$cmd=get_var("cmd");
$photoid=get_int("photo");
if( $cmd=="edit" ) {
$query="SELECT `width_thumb`, `height_thumb`, `comment`, `filename` FROM `photo` WHERE `id`=".addslashes($photoid);
if( @mysql_num_rows( $res=doquery($query) )==1 ) {
$row=mysql_fetch_array($res);
$photoheight=$row['height_thumb'];
$photowidth=$row['width_thumb'];
$photocomment=$row['comment'];
$photofilename=$row['filename'];
if( strlen($photofilename)<1 ) $photofilename="Photo-".$photoid.".jpg";
}else {
$cmd="";
}
}
if( get_int("book")>0 ) {
// Reset
$_SESSION['addphoto_start']=0;
}
if( get_int("book")>0 ) {
$_SESSION['addphoto_book']=get_int("book");
}
// Get info about book
$query="SELECT `book`.`photocount` AS `photocount`, `book`.`title` AS `title`, `book`.`comment` AS `comment`,
`event`.`bodycode` AS `bodycode`, `event`.`bodycode2` AS `bodycode2`, `event`.`title` AS `eventtitle`,
`event`.`topic` AS `topic`, `event`.`projectname` AS `projectname`, `event`.`location` AS `location`,
`event`.`datestart` AS `datestart`, `event`.`dateend` AS `dateend`, `event`.`eventtype` AS `eventtype`,
`event`.`area` AS `area`, `event`.`eventrating` AS `eventrating`, `event`.`documentid` AS `documentid`,
`event`.`eventcode` AS `eventcode`, `user`.`name` AS `owner`, `user`.`bodycode` AS `ownerbodycode`
FROM `book`, `event`, `user`
WHERE `book`.`eventcode`=`event`.`eventcode` AND `book`.`uid`=`user`.`uid` AND
`book`.`id`=".addslashes($_SESSION['addphoto_book'])." AND `user`.`uid`=".addslashes($_SESSION['sess_uid']);
if( @mysql_num_rows( $res=doquery($query) )==1 ) {
$bookinfo=mysql_fetch_array($res);
$photocount=$bookinfo['photocount'];
}else {
$_SESSION['addphoto_book']=0;
echoln("You are trying to edit a book that is not yours. Access denied.");
page_footer();
exit;
}
if( $cmd=="save" ) {
#################
### Save edit ###
#################
$photoid=get_int("photo");
$photocomment=get_var("comment");
$photofilename=get_var("filename");
$Error[0]=false;
if( strlen($photofilename)>16 ) {
echoln("The filename is too long (maximum 16 characters)
");
$Error['filename']=true;
$Error[0]=true;
}
if( $Error[0] ) {
$query="SELECT `width_thumb`, `height_thumb` FROM `photo` WHERE `id`=".addslashes($photoid);
if( @mysql_num_rows( $res=doquery($query) )==1 ) {
$row=mysql_fetch_array($res);
$photoheight=$row['height_thumb'];
$photowidth=$row['width_thumb'];
$cmd="edit";
}else {
$cmd="";
}
}else {
$query="UPDATE `photo` SET `comment`='".addslashes($photocomment)."', `filename`='".addslashes($photofilename)."'
WHERE `id`=".addslashes($photoid)." AND `book_id`=".addslashes($_SESSION['addphoto_book']);
if( doquery($query) ) {
// OK
echoln("Saved comment successfully.
"); }else { // Failed echoln("Failed saving comment.
");
}
}
}
if( $cmd=="move" ) {
############
### Move ###
############
$photoid=get_int("photo");
$direction=get_var("dir");
$query="SELECT `nr` FROM `photo` WHERE `id`=".addslashes($photoid)." AND `book_id`=".addslashes($_SESSION['addphoto_book']);
if( @mysql_num_rows( $res=doquery($query) )==1 ) {
$row=mysql_fetch_array($res);
$photonr=$row['nr'];
$query=array();
switch( $direction ) {
case "left":
if( $photonr>1 ) {
$query[]="UPDATE `photo` SET `nr`=".addslashes($photonr)."
WHERE `nr`=".addslashes($photonr-1)." AND `book_id`=".addslashes($_SESSION['addphoto_book']);
$query[]="UPDATE `photo` SET `nr`=".addslashes($photonr-1)."
WHERE `id`=".addslashes($photoid)." AND `book_id`=".addslashes($_SESSION['addphoto_book']);
}
break;
case "up":
if( $photonr>$MAXPHOTOTHUMBCOLS ) {
for( $i=$photonr-1; $i>=($photonr-$MAXPHOTOTHUMBCOLS); $i-- ) {
$query[]="UPDATE `photo` SET `nr`=".addslashes($i+1)."
WHERE `nr`=".addslashes($i)." AND `book_id`=".addslashes($_SESSION['addphoto_book']);
}
$query[]="UPDATE `photo` SET `nr`=".addslashes($photonr-$MAXPHOTOTHUMBCOLS)."
WHERE `id`=".addslashes($photoid)." AND `book_id`=".addslashes($_SESSION['addphoto_book']);
}
break;
case "down":
if( $photonr<=$photocount-$MAXPHOTOTHUMBCOLS ) {
for( $i=$photonr+1; $i<=($photonr+$MAXPHOTOTHUMBCOLS); $i++ ) {
$query[]="UPDATE `photo` SET `nr`=".addslashes($i-1)."
WHERE `nr`=".addslashes($i)." AND `book_id`=".addslashes($_SESSION['addphoto_book']);
}
$query[]="UPDATE `photo` SET `nr`=".addslashes($photonr+$MAXPHOTOTHUMBCOLS)."
WHERE `id`=".addslashes($photoid)." AND `book_id`=".addslashes($_SESSION['addphoto_book']);
}
break;
case "right":
if( $photonr<$photocount ) {
$query[]="UPDATE `photo` SET `nr`=".addslashes($photonr)."
WHERE `nr`=".addslashes($photonr+1)." AND `book_id`=".addslashes($_SESSION['addphoto_book']);
$query[]="UPDATE `photo` SET `nr`=".addslashes($photonr+1)."
WHERE `id`=".addslashes($photoid)." AND `book_id`=".addslashes($_SESSION['addphoto_book']);
}
break;
default:
debug("Unknown direction");
}
$error=false;
for( $i=0; $i ");
}
}else {
// No big photo available
$query="UPDATE `photo`
SET `photo_normal`='".addslashes($photo_normal)."', `height_normal`=".addslashes($row['width_normal']).",
`width_normal`=".addslashes($row['height_normal']).",
`photo_thumb`='".addslashes($photo_thumb)."', `height_thumb`=".addslashes($row['width_thumb']).",
`width_thumb`=".addslashes($row['height_thumb'])."
WHERE `id`=".addslashes($photoid)." AND `book_id`=".addslashes($_SESSION['addphoto_book']);
}
if( $query!="" ) {
if( doquery($query) ) {
echoln("Successfully rotated photo. ");
}else {
echoln("Failed saving rotated photo. ");
}
}
}else {
echoln("Failed rotating normal sized photo. Rotating aborted. ");
}
}else {
echoln("Failed rotating thumb sized photo. Rotating aborted. ");
}
}else {
echoln("Photo not found, rotating not possible. ");
}
}else {
echoln("Unknown direction, rotating not possible. ");
}
}
// Get count
if( get_int("count")>0 ) $_SESSION['addphoto_count']=get_int("count");
if( $_SESSION['addphoto_count']<1 ) $_SESSION['addphoto_count']=$MAXPHOTOVIEW;
// Get start
if( strlen(get_var("start"))>0 ) $_SESSION['addphoto_start']=get_int("start");
if( $_SESSION['addphoto_start']<=0 ) $_SESSION['addphoto_start']=0;
// Limit
$mysql_limit="LIMIT ".$_SESSION['addphoto_count']." OFFSET ".$_SESSION['addphoto_start'];
// Show back button if info available
echoln("Back to events ");
// Get info about book, but only when we show all pics
if( $_SESSION['addphoto_photo']==0 AND isset($bookinfo) ) {
##################
### Album info ###
##################
echoln("Event: ".$bookinfo['eventtitle']." From ".get_date($bookinfo['datestart'])." until ".get_date($bookinfo['dateend'])."");
if( strlen($el=get_eventlink($bookinfo['eventcode'], $bookinfo['documentid']))>0 ) echoln("   ".$el."info");
echoln(" Photos by: ".$bookinfo['owner']." (".$db_bodies[ $bookinfo['ownerbodycode'] ]['bodyname'].")");
echoln(" Book: ".$bookinfo['title']);
if( $cmd!="savenew" ) echoln(" (".$bookinfo['photocount']." photos)");
if( strlen($bookinfo['comment'])>3 ) echoln(" Processing photo upload:");
for( $i=0; $i<$MAXPHOTOSPERUPLOAD; $i++ ) {
if( $_FILES['photo'.$i]['error']!=4 ) {
// We only handle the photo if something was uploaded.
echoln(" ");
}
if( $cmd=="delok" ) {
#################
### Delete OK ###
#################
$query="SELECT `nr` FROM `photo` WHERE `book_id`=".addslashes($_SESSION['addphoto_book'])." AND `id`=".addslashes($photoid);
if( @mysql_num_rows( $res=doquery($query) )==1 ) {
$row=mysql_fetch_array($res);
$photonr=$row['nr'];
$query="SELECT `id`, `nr` FROM `photo`
WHERE `book_id`=".addslashes($_SESSION['addphoto_book'])." AND `nr`>".addslashes($photonr)."
ORDER BY `nr` ASC";
if( $res=doquery($query) ) {
$query=array();
$query[]="DELETE FROM `photo` WHERE `book_id`=".addslashes($_SESSION['addphoto_book'])." AND `id`=".addslashes($photoid);
$nr=$photonr;
while( $row=mysql_fetch_array($res) ) {
$query[]="UPDATE `photo` SET `nr`=".addslashes($nr)." WHERE `book_id`=".addslashes($_SESSION['addphoto_book'])." AND `id`=".addslashes($row['id']);
$nr++;
}
$queryerror=false;
for( $i=0; $i Successfully deleted photo.");
}
}else {
echoln(" Failed selecting the other photos in this book. Deleting not possible.");
}
}else {
echoln(" The photo you are trying to delete does not exist in this book.");
}
$photocount=photo_updatecount($_SESSION['addphoto_book']);
}
############################
### Previous-next button ###
############################
if( $_SESSION['addphoto_photo']>0 ) {
//One photo per time
$butprevnext =" ";
if( $_SESSION['addphoto_photo']>1 ) {
$butprevnext.="";
$butprevnext.="";
}
$butprevnext.=" ";
if( $_SESSION['addphoto_photo']<$photocount ) {
$butprevnext.="";
$butprevnext.="";
}
$butprevnext.=" ";
$butprevnext.="";
$butprevnext.="";
}elseif( $photocount>$_SESSION['addphoto_count'] ) {
//List (several photos on one page, more than one page in total)
$butprevnext =" ";
if( $_SESSION['addphoto_start']>0 ) {
$butprevnext.="";
$butprevnext.="";
}
$butprevnext.=" ";
if( ($_SESSION['addphoto_start']+$_SESSION['addphoto_count'])<=($photocount-1) ) {
$butprevnext.="";
$butprevnext.="";
}
}else {
//List (several photos on one page, one page in total)
$butprevnext ="";
}
if( $cmd=="edit" ) {
#################
### Edit form ###
#################
echoln(" You can upload up to ".$MAXPHOTOSPERUPLOAD." photos in the JPEG format of maximum ".get_bytesize($MAXPHOTOFILESIZE)." each. ");
echoln(" The total upload cannot exceed ".get_bytesize($MAXUPLOADSIZE).".");
echoln(" Are you sure you want to delete photo ".$row['nr']."?");
echoln(" yes");
echoln(" no");
}else {
echoln("Cannot delete photo, not found.");
echoln(" Return to overview.");
}
}else {
#################
### Show list ###
#################
echoln(" Add new photos");
echoln($butprevnext);
$query="SELECT `id`, `nr`, `height_thumb` AS `height`, `width_thumb` AS `width`, `comment`, `date_add`
FROM `photo`
WHERE `book_id`=".addslashes($_SESSION['addphoto_book']);
if( $_SESSION['addphoto_photo']>0 ) $query.=" AND `nr`=".addslashes($_SESSION['addphoto_photo']);
$query.=" ORDER BY `nr` ";
if( $_SESSION['addphoto_photo']==0 ) $query.=$mysql_limit;
if( @mysql_num_rows( $res=doquery($query) )>0 ) {
echoln(" No photos found
Organized by: ".$db_bodies[ $bookinfo['bodycode'] ]['bodyname']);
if( strlen($bookinfo['bodycode2'])>0 ) echoln(" & ".$db_bodies[ $bookinfo['bodycode2'] ]['bodyname']);
#if( strlen($bookinfo['topic'])>0 ) echoln("
Topic: ".$bookinfo['topic']);
#if( strlen($bookinfo['projectname'])>0 ) echoln("
Part of project: ".$bookinfo['projectname']);
#if( strlen($bookinfo['location'])>0 ) echoln("
Location: ".$bookinfo['location']);
#if( strlen($bookinfo['eventtype'])>0 ) echoln("
Event type: ".$bookinfo['eventtype']);
#if( strlen($bookinfo['area'])>0 ) echoln("
Area: ".$bookinfo['area']);
#if( strlen($bookinfo['eventrating'])>0 ) echoln("
Rating: ".$bookinfo['eventrating']);
#echoln("
Comment: ".$bookinfo['comment']);
}
if( $cmd=="savenew" ) {
#######################
### Save new photos ###
#######################
// Uploading photos
echoln("
Photo ".($i+1)." (".$_FILES['photo'.$i]['name']."): ");
switch( $_FILES['photo'.$i]['error'] ) {
case 0:
// Ok, handle this upload
if( $_FILES['photo'.$i]['type']=="image/jpeg" OR $_FILES['photo'.$i]['type']=="image/jpg" OR $_FILES['photo'.$i]['type']=="image/pjpeg" ) {
if( $_FILES['photo'.$i]['size']<=$MAXPHOTOFILESIZE ) {
echoln("reading... ");
doflush();
if( $im=ImageCreateFromJPEG( $_FILES['photo'.$i]['tmp_name'] ) ) {
$orig_x=imagesx($im);
$orig_y=imagesy($im);
$img_big=NULL;
echoln("resizing... ");
doflush();
if( $orig_x>$MAXSIZENORMAL+50 OR $orig_y>$MAXSIZENORMAL+50 ) {
// Make big image as well
if( $img_big=photo_resize($im, $orig_x, $orig_y, $MAXSIZEBIG) ) {
echoln("big ");
}else {
echoln("big failed ");
}
}else {
// Image is small, don't create the big version
//echoln("big skipped, photo too small ");
}
doflush();
if( $img_normal=photo_resize($im, $orig_x, $orig_y, $MAXSIZENORMAL) ) {
echoln("normal ");
doflush();
if( $img_thumb=photo_resize($im, $orig_x, $orig_y, $MAXSIZETHUMB) ) {
echoln("thumb ");
echoln("saving... ");
doflush();
$photonr=photo_getnextnum($_SESSION['addphoto_book']);
$query ="INSERT INTO `photo` (`book_id`, `nr`,";
if( $img_big!=false ) $query.="`photo_big`, `height_big`, `width_big`,";
$query.="`photo_normal`, `height_normal`, `width_normal`, `photo_thumb`, `height_thumb`, `width_thumb`,
`comment`, `date_add`, `filename`)
VALUES (".addslashes($_SESSION['addphoto_book']).", ".addslashes($photonr).",";
if( $img_big!=false ) $query.="'".addslashes($img_big['data'])."', ".addslashes($img_big['height']).", ".addslashes($img_big['width']).",";
$query.="'".addslashes($img_normal['data'])."', ".addslashes($img_normal['height']).",
".addslashes($img_normal['width']).", '".addslashes($img_thumb['data'])."',
".addslashes($img_thumb['height']).", ".addslashes($img_thumb['width']).",
'".addslashes($_POST['comment'])."', '".addslashes( date("Y-m-d H:m:i") )."',
'".addslashes($_FILES['photo'.$i]['name'])."')";
if( doquery($query) ) {
echoln("ok. Photo processed");
}else {
echoln("failed. Not processed.");
}
doflush();
}else {
echoln("thumb failed. Not processed.");
doflush();
}
}else {
echoln("normal failed. Not processed.");
doflush();
}
imagedestroy($im);
}else {
// Failed
echoln("failed. Not processed.");
doflush();
}
}else {
// File too big
echoln("Error: the uploaded file is too big (".get_bytesize($_FILES['photo'.$i]['size'])." instead of ".get_bytesize($MAXPHOTOFILESIZE)."). Not processed.");
}
}else {
// Invalid file type
echoln("Error: invalid file type (".$_FILES['photo'.$i]['type']."). Not processed.");
}
break;
case 1:
// Error, file exceeds max size as defined in PHP config
echoln("Error: file size exceeds maximum as defined in server config. Not processed.");
break;
case 2:
// Error, file exceeds max size as defined in form
echoln("Error: file size exceeds maximum as defined in page config. Not processed.");
break;
case 3:
// Error, file only partially uploaded
echoln("Error: file only partially uploaded. Not processed.");
break;
default:
// Unknown
echoln("Error: unknown error (".$_FILES['photo'.$i]['error']."). Not processed.");
}
}
}
$photocount=photo_updatecount($_SESSION['addphoto_book']);
echoln("
");
echoln("");
$thumbcellwidth="width=\"".(100/$MAXPHOTOTHUMBCOLS)."%\"";
$i=0;
while( $row=mysql_fetch_array($res) ) {
if( ($i%$MAXPHOTOTHUMBCOLS)==0 ) echoln("
");
}else {
echoln("");
echoln(" ");
$i++;
}
while( ($i%$MAXPHOTOTHUMBCOLS)!=0 ) {
echoln(" ");
if( strlen($row['comment'])>0 )
echoln(" ");
else
echoln(" ");
echoln(" ");
if( ($i%$MAXPHOTOTHUMBCOLS)==($MAXPHOTOTHUMBCOLS-1) ) echoln("
edit");
echoln(" delete");
echoln("
Move ");
if( $row['nr']>1 ) echoln(" left");
if( $row['nr']>$MAXPHOTOTHUMBCOLS ) echoln(" up");
if( $row['nr']<=($photocount-$MAXPHOTOTHUMBCOLS) ) echoln(" down");
if( $row['nr']<$photocount ) echoln(" right");
echoln("
Rotate ");
echoln(" left");
echoln(" right");
echoln(" ");
echoln(" ");
echoln(" ");
if( ($i%$MAXPHOTOTHUMBCOLS)==($MAXPHOTOTHUMBCOLS-1) ) echoln(" ");
$i++;
}
echoln("