<?PHP
ob_start();
session_start();
ini_set("memory_limit","-1");
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['EditorRightsPhotoBatchAdd'])) loginError($sxLang['LoginRequired']);
if($Submit)
{
// Figure out if batch has already occured before and adjust photo count number
$count = 1;
if(count($albums) < 2)
{
$query = "SELECT * FROM $DB_Photos_Assoc, $DB_Photos
WHERE $DB_Photos_Assoc.albumid = '$albums[0]' AND
$DB_Photos_Assoc.photoid = $DB_Photos.id
ORDER BY $DB_Photos_Assoc.position DESC LIMIT 0,1";
$result = mysql_query($query, $Link) or queryError("150", mysql_error());
if(mysql_num_rows($result))
{
$ROW = mysql_fetch_object($result);
$name_array = explode(' ', $ROW->name);
$last_int = intval(array_pop($name_array));
$name_array = implode(' ', $name_array);
if(($name_array == $name)AND($last_int > 0))
$count = $last_int + 1;
}
}
$sxFileEntries = array();
$current_dir = opendir("../".$sxContentDir['PhotoBatch']);
while($entryname = readdir($current_dir))
{
if($entryname != "." and $entryname!="..")
array_push($sxFileEntries, $entryname);
}
closedir($current_dir);
sort($sxFileEntries);
foreach($sxFileEntries as $entryname)
{
// Check to make sure file is an acceptable file format
if (eregi ("(.)+\\.(jp(e){0,1}g$|gif$|png$|bmp$)", strtolower($entryname)))
{
$sxFileNameParts = explode('.', strtolower($entryname));
$query = "SELECT * FROM $DB_Photos ORDER BY id DESC LIMIT 0,1";
$result = mysql_query($query, $Link) or queryError("12", mysql_error());
if(mysql_num_rows($result))
{
$ROW = mysql_fetch_object($result);
$filename = ($ROW->id + 1) . "." . $sxFileNameParts[1];
}
else
$filename = "1." . $sxFileNameParts[1];
if (@copy("../".$sxContentDir['PhotoBatch'].$entryname, "../".$sxContentDir['PhotoFullsize'].$filename))
{
if(!(ini_get('safe_mode')))
set_time_limit(30);
// 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['MessagePhotoBatch'];
$name_final = $name . ' ' . $count;
$query = "INSERT INTO $DB_Photos (name, filename, photographer, filesize, height, width, description, timestamp, fullsize, userid, watermark) VALUES ('$name_final', '$filename', '$photographer', '$filesize_final', '$height_final', '$width_final', '$description', '$NOW', '$fullsize', '$THIS_USER', '$sxImageWatermarked')";
$result = mysql_query($query, $Link) or queryError("13", mysql_error());
$count = $count + 1;
$query = "SELECT * FROM $DB_Photos WHERE filename='$filename'";
$result = mysql_query($query, $Link) or queryError("14", mysql_error());
$ROW = mysql_fetch_object($result);
for($i = 0; $i < count($albums); $i++)
{
$result = mysql_query("INSERT INTO $DB_Photos_Assoc (photoid, albumid) VALUES ('$ROW->id', '$albums[$i]')", $Link);
$query2 = "SELECT * FROM $DB_Photos_Assoc WHERE albumid='$albums[$i]' AND position!='0' ORDER BY position DESC LIMIT 0,1";
$result2 = mysql_query($query2, $Link) or queryError("150", mysql_error());
if(mysql_num_rows($result2))
{
$ROW2 = mysql_fetch_object($result2);
$new_position = $ROW2->position + 1;
}
else
$new_position = 1;
$result = mysql_query("UPDATE $DB_Photos_Assoc SET position='$new_position' WHERE photoid='$ROW->id' AND albumid='$albums[$i]'", $Link) or queryError("154", mysql_error());
}
$keywords_array = explode(", ", $keywords);
foreach($keywords_array as $k)
$keywords_array[$k] = trim($keywords_array[$k]);
for($i = 0; $i < count($keywords_array); $i++)
{
if($keywords_array[$i] != '') $result = mysql_query("INSERT INTO $DB_Photos_Keywords (photoid, keyword) VALUES ('$ROW->id', '$keywords_array[$i]')", $Link) or queryError("154", mysql_error());
}
}
else
$message = $sxLang['MessageFileCopyError'];
@unlink("../".$sxContentDir['PhotoBatch'].$entryname);
}
else
$message = $sxLang['MessagePhotoResourceError'];
}
}
$sxTitleAddendum = $sxLang['AdminHeading'];
include("../themes/$THEME_FOLDER/header.php");
?>
<div class="bodyWrapper">
<h1 class="sxAdminHeading"><?PHP echo $sxLang['PhotoHeadingBatch']; ?></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['PhotoHeadingBatch']; ?></div>
<?PHP echoMessage($message); ?>
<p><?PHP echo $sxLang['PhotoBatchInfo']; ?></p>
<table border="0" cellspacing="3" cellpadding="5">
<form name="sxFormPhotoAddBatch" action="<?PHP print $PHP_SELF; ?>" method="post" enctype="multipart/form-data"><tr>
<td class="sxTdItem"><?PHP echo $sxLang['GeneralItemName']; ?></td>
<td><input name="name" style="width:150px;" type="text" id="name" /></td>
</tr>
<tr>
<td class="sxTdItem"><?PHP echo $sxLang['PhotoItemPhotographer']; ?></td>
<td><input name="photographer" style="width:150px;" type="text" id="photographer" /></td>
</tr>
<tr>
<td class="sxTdItem"><?PHP echo $sxLang['PhotoItemAlbums']; ?></td>
<td><select style="height:150px; width:300px;" name="albums[]" size="6" multiple>
<?PHP
$query = "SELECT * FROM $DB_Photos_Albums ORDER BY id DESC";
$result = mysql_query($query, $Link);
while($ROW = mysql_fetch_object($result))
echo '<option value="' . $ROW->id . '">' . $ROW->name . '</option>';
?></select>
<br />
<span class="sxSmallText">(<?PHP echo $sxLang['PhotoHoldSelections']; ?>)</span></td>
</tr>
<tr>
<td class="sxTdItem"><?PHP echo $sxLang['PhotoItemKeywords']; ?></td>
<td valign="top"><textarea name="keywords" style="width:300px; height:100px;" id="keywords"></textarea></td>
</tr>
<tr>
<td colspan="2" valign="top" align="right"><input type="submit" name="Submit" value="<?PHP echo $sxLang['PhotoButtonBatchAdd']; ?>" class="sxButton" /></td>
</tr></form>
</table>
</div>
<?PHP
include("../themes/$THEME_FOLDER/footer.php");
ob_end_flush();
?>