<?PHP
ob_start();
session_start();
ini_set("memory_limit","100M");
include("../includes/globals.php.inc");
include("../includes/functions.php");
include("../lang/English.php");
if(strtolower($sxSetup['Language']) != 'english') include("../lang/".$sxSetup['Language'].".php");
include("../themes/$THEME_FOLDER/config.php.inc");
protectWriteMode();
if((!userEditor())AND(!userAdmin())) loginError($sxLang['LoginRequired']);
if((userEditor())AND(!$sxSetup['EditorRightsPhotoEdit'])) loginError($sxLang['LoginRequired']);
$date_month = substr($date, 5, 2);
$date_day = substr($date, 8, 2);
$date_year = substr($date, 0, 4);
$timestamp = mktime(0, 0, 0, $date_month, $date_day, $date_year);
$curDateTime = date("YmdHis");
if($Submit)
{
$sxPhotoName = basename($_FILES['PhotoUpload']['name']);
// Check to make sure file is an acceptable image type
if (eregi ("(.)+\\.(jp(e){0,1}g$|gif$|png$|bmp$)", strtolower($sxPhotoName)))
{
// Name photo by incremental id
$sxFileNameParts = explode('.',$sxPhotoName);
$filename = $editid ."_". $curDateTime ."." . $sxFileNameParts[1];
// Copy photo to the raw location
if (@move_uploaded_file($_FILES['PhotoUpload']['tmp_name'], "../".$sxContentDir['PhotoFullsize'].$filename))
{
// Size max width or height - 1 to trim mishap edges
$size_thumb = $sxSetup['GalleryMaxDimensionThumb'] - 1;
$size_scaled = $sxSetup['GalleryMaxDimensionPhoto'] - 1;
// Set JPG compression (for JPG images only)
$compression_thumb = $sxSetup['GalleryCompressionThumb'];
$compression_scaled = $sxSetup['GalleryCompressionPhoto'];
// Read raw image
if((imageCompatibility() == "truecolor")OR(imageCompatibility() == "normal"))
{
$sxImageInfo = getimagesize("../".$sxContentDir['PhotoFullsize'].$filename);
switch($sxImageInfo[2])
{
case 1: $image = imagecreatefromgif("../".$sxContentDir['PhotoFullsize'].$filename); break;
case 2: $image = imagecreatefromjpeg("../".$sxContentDir['PhotoFullsize'].$filename); break;
case 3: $image = imagecreatefrompng("../".$sxContentDir['PhotoFullsize'].$filename); break;
case 6: $image = imagecreatefromwbmp("../".$sxContentDir['PhotoFullsize'].$filename); break;
}
$width_original = $sxImageInfo[0];
$height_original = $sxImageInfo[1];
}
// Get filesize
$filesize_original = filesize("../".$sxContentDir['PhotoFullsize'].$filename);
// Image not watermarked (yet)
$sxImageWatermarked = 0;
// Watermark raw image
if($sxSetup['GalleryWatermarking'] == 1)
{
$sxImageWatermarked = 1;
$sxRawImage = sxWatermarkImage($image, $width_original, $height_original);
// Make image
switch($sxImageInfo[2])
{
case 1: imagegif($sxRawImage, "../".$sxContentDir['PhotoFullsize'].$filename); break;
case 2: imagejpeg($sxRawImage, "../".$sxContentDir['PhotoFullsize'].$filename, 90); break;
case 3: imagepng($sxRawImage, "../".$sxContentDir['PhotoFullsize'].$filename); break;
case 6: imagewbmp($sxRawImage, "../".$sxContentDir['PhotoFullsize'].$filename); break;
}
imagedestroy($sxRawImage);
} // End watermarking
// Check if dimension change needed for scaled image change and make scaled image
if(($width_original > $size_scaled)OR($height_original > $size_scaled))
{
$dimensions = resizeDimensions($width_original, $height_original, $size_scaled);
$sxScaledWidth = $dimensions[0]+1;
$sxScaledHeight = $dimensions[1]+1;
}
else
{
$sxScaledWidth = $width_original;
$sxScaledHeight = $height_original;
}
// Form scaled image
if(imageCompatibility() == "truecolor")
{
$sxScaledImage = imagecreatetruecolor($sxScaledWidth, $sxScaledHeight);
imagecopyresampled($sxScaledImage, $image, 0, 0, 0, 0, $sxScaledWidth, $sxScaledHeight, $width_original, $height_original);
}
elseif(imageCompatibility() == "normal")
{
$sxScaledImage = imagecreate($sxScaledWidth, $sxScaledHeight);
imagecopyresized($sxScaledImage, $image, 0, 0, 0, 0, $sxScaledWidth, $sxScaledHeight, $width_original, $height_original);
}
// Watermark scaled image
if($sxSetup['GalleryWatermarking'] == 1)
$sxScaledImage = sxWatermarkImage($sxScaledImage, $sxScaledWidth, $sxScaledHeight);
// Create scaled image
switch($sxImageInfo[2])
{
case 1: imagegif($sxScaledImage, "../".$sxContentDir['PhotoScaled'].$filename); break;
case 2: imagejpeg($sxScaledImage, "../".$sxContentDir['PhotoScaled'].$filename, $compression_scaled); break;
case 3: imagepng($sxScaledImage, "../".$sxContentDir['PhotoScaled'].$filename); break;
case 6: imagewbmp($sxScaledImage, "../".$sxContentDir['PhotoScaled'].$filename); break;
}
imagedestroy($sxScaledImage);
$filesize_scaled = filesize("../".$sxContentDir['PhotoScaled'].$filename);
// Resize image for thumbnail
$dimensions = resizeDimensions($width_original, $height_original, $size_thumb);
if((imageCompatibility() == "truecolor")OR(imageCompatibility() == "normal"))
{
if(imageCompatibility() == "truecolor")
{
$image_new_thumb = imagecreatetruecolor($dimensions[0]+1, $dimensions[1]+1);
imagecopyresampled($image_new_thumb, $image, 0, 0, 0, 0, $dimensions[0]+1, $dimensions[1]+1, $width_original, $height_original);
}
elseif(imageCompatibility() == "normal")
{
$image_new_thumb = imagecreate($dimensions[0]+1, $dimensions[1]+1);
imagecopyresized($image_new_thumb, $image, 0, 0, 0, 0, $dimensions[0]+1, $dimensions[1]+1, $width_original, $height_original);
}
switch($sxImageInfo[2])
{
case 1: imagegif($image_new_thumb, "../".$sxContentDir['PhotoThumb'].$filename); break;
case 2: imagejpeg($image_new_thumb, "../".$sxContentDir['PhotoThumb'].$filename, $compression_thumb); break;
case 3: imagepng($image_new_thumb, "../".$sxContentDir['PhotoThumb'].$filename); break;
case 6: imagewbmp($image_new_thumb, "../".$sxContentDir['PhotoThumb'].$filename); break;
}
imagedestroy($image_new_thumb);
}
elseif(imageCompatibility() == "imagemagick")
{
$image_new_thumb = imagick_readimage("../".$sxContentDir['PhotoFullsize'].$filename);
imagick_sample($image_new_thumb, $dimensions[0]+1, $dimensions[1]+1);
imagick_writeimage($image_new_thumb, "../".$sxContentDir['PhotoThumb'].$filename);
}
// Set final size/dimension data for db
if($sxSetup['GalleryStoreFullsize'])
{
$width_final = $width_original;
$height_final = $height_original;
$filesize_final = $filesize_original;
$fullsize = 1;
}
else
{
@unlink("../".$sxContentDir['PhotoFullsize'].$filename);
$width_final = $sxScaledWidth;
$height_final = $sxScaledHeight;
$filesize_final = $filesize_scaled;
$fullsize = 0;
}
}
}
$message = $sxLang['MessagePhotoAdded1'] . " '" . stripslashes($filename) . "' " . $sxLang['MessagePhotoAdded2'];
if($hide_random != 1)
$hide_random = 0;
// $query = "UPDATE $DB_Photos SET (height, width, timestamp, fullsize, userid, watermark) VALUES ( '$timestamp', WHERE id='$editid';"
$query = "UPDATE $DB_Photos SET filename='$filename', filesize='$filesize_final', height='$height_final', width='$width_final', fullsize='$fullsize', userid='$THIS_USER', watermark='$sxImageWatermarked', timestamp='$timestamp' WHERE id='$editid'";
$result = mysql_query($query, $Link) or queryError("13", mysql_error());
/* $query = "SELECT * FROM $DB_Photos WHERE filename='$filename'";
$result = mysql_query($query, $Link) or queryError("151", mysql_error());
$ROW = mysql_fetch_object($result); */
if($sxPrevURL)
{
header("Location: ".urldecode($sxPrevURL));
die();
}
else
$message = $sxLang['MessagePhotoUpdated'];
}
$query = "SELECT * FROM $DB_Photos WHERE id='$editid'";
$result = mysql_query($query, $Link) or queryError("176", mysql_error());
$ROW = mysql_fetch_object($result);
$sxTitleAddendum = $sxLang['AdminHeading'];
include("../themes/$THEME_FOLDER/header.php");
?>
<div class="bodyWrapper">
<h1 class="sxAdminHeading"><?PHP echo $sxLang['PhotoHeadingEdit']; ?></h1>
<div class="sxAdminBreadcrumbs"><?PHP if(userAdmin()) { ?><a href="index.php"><?PHP echo $sxLang['AdminBreadcrumb']; ?><?PHP }?><?PHP if(userEditor()) { ?><a href="editor_index.php"><?PHP echo $sxLang['EditorBreadcrumb']; ?><?PHP }?></a> > <a href="photos.php"><?PHP echo $sxLang['PhotoHeadingManager']; ?></a> > <?PHP echo $sxLang['PhotoHeadingEdit']; ?></div>
<?PHP echoMessage($message); ?>
<table border="0" cellspacing="3" cellpadding="5">
<form name="sxFormPhotoEdit" action="<?PHP print $PHP_SELF; ?>" method="post" enctype="multipart/form-data">
<tr>
<td class="sxTdItem"><?PHP echo $sxLang['GeneralItemName']; ?></td>
<td><?PHP echo htmlspecialchars($ROW->name); ?></td>
</tr>
<tr>
<td class="sxTdItem"><?PHP echo $sxLang['GeneralItemFile']; ?></td>
<td><img src="<?PHP echo "../".$sxContentDir['PhotoThumb'].$ROW->filename; ?>" /><br /><?PHP echo $ROW->filename; ?></td>
</tr>
<tr>
<td class="sxTdItem"><?PHP echo $sxLang['PhotoUploadNew']; ?></td>
<td><input type="file" style="width:200px;" id="PhotoUpload" name="PhotoUpload" /></td>
</tr>
<tr>
<td colspan="2" valign="top" align="right">
<input type="hidden" name="editid" value="<?PHP echo $editid; ?>" /><br />
<input type="hidden" name="sxPrevURL" value="<?PHP echo $sxPrevURL; ?>" />
<input type="submit" name="Submit" value="<?PHP echo $sxLang['PhotoButtonReplace']; ?>" class="sxButton" /></td>
</tr></form>
</table>
</div>
<?PHP
include("../themes/$THEME_FOLDER/footer.php");
ob_end_flush();
?>