Location: PHPKode > projects > SiteX > admin/photos.php
<?PHP
ob_start();
session_start();
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");

if((!userEditor())AND(!userAdmin()))  loginError($sxLang['LoginRequired']);
if((userEditor())AND(!$sxSetup['EditorRightsPhotoEdit']))  loginError($sxLang['LoginRequired']);

if($delete)
{
	deletePhoto($delete);	
	$message = $sxLang['MessagePhotoDeleted'];
}
if($DeleteAllFinal)
{
	foreach($photo as $key => $value) deletePhoto($key);
	$message = $sxLang['MessagePhotosDeleted'];
}
if($EditAllFinal)
{
	foreach($photo as $key => $value)
	{
		if($check_photographer)
		{
			$query = "UPDATE $DB_Photos SET photographer='$photographer' WHERE id='$key'";
			$result = mysql_query($query, $Link) or queryError("11", mysql_error());
		}
		if($check_description)
		{
			$query = "UPDATE $DB_Photos SET description='$description' WHERE id='$key'";
			$result = mysql_query($query, $Link) or queryError("11", mysql_error());
		}
		if($check_albums)
		{
			editAlbumAssociation($key, $albums);
		}
		if($check_keywords)
		{
			$query = "DELETE FROM $DB_Photos_Keywords WHERE photoid='$key'";
			$result = mysql_query($query, $Link) or queryError("11", mysql_error());
			
			$keywords2 = explode(", ", $keywords);
			foreach($keywords2 as $k) 
				$keywords2[$k] = trim($keywords2[$k]);
			
			for($i = 0; $i < count($keywords2); $i++)
			{	
				if($keywords2[$i] != '')
					$result = mysql_query("INSERT INTO $DB_Photos_Keywords (photoid, keyword) VALUES ('$key', '$keywords2[$i]')", $Link) or queryError("11", mysql_error());
			}
		}		
	}
	$message = $sxLang['MessagePhotosEdited'];
	
}
if($albumid)
{
	$query = "SELECT * FROM $DB_Photos, $DB_Photos_Assoc
		      WHERE $DB_Photos.id=$DB_Photos_Assoc.photoid AND
			        $DB_Photos_Assoc.albumid='$albumid'";
	$result = mysql_query($query, $Link) or queryError("11", mysql_error());
	$totalPics = mysql_num_rows($result);
}
elseif($sxOrphans)
{
	$query = "SELECT * FROM $DB_Photos LEFT JOIN $DB_Photos_Assoc ON $DB_Photos.id=$DB_Photos_Assoc.photoid
		      WHERE  $DB_Photos_Assoc.id IS NULL";
	$result = mysql_query($query, $Link) or queryError("11", mysql_error());
	$totalPics = mysql_num_rows($result);
	$sxOrphans = TRUE;
}
else
{
	$query = "SELECT * FROM $DB_Photos";
	$result = mysql_query($query, $Link) or queryError("11", mysql_error());
	$totalPics = mysql_num_rows($result);
}

$admin_pics_per_page = 15;
if(!$page)
	$page = 1;
$start = ($page - 1)*$admin_pics_per_page;

$sxTitleAddendum = $sxLang['AdminHeading'];
include("../themes/$THEME_FOLDER/header.php");
?>
<script language="JavaScript" type="text/JavaScript">
<!--
function confirmDelete(theID,theName){
	if(confirm("<?PHP echo $sxLang['PhotoAlbumJSDeletePhoto']; ?> '"+theName+"' <?PHP echo $sxLang['GeneralJSDeleteEntry2']; ?>")){
		window.location='<?PHP print $PHP_SELF."?delete="; ?>'+theID;
	}
}
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
function changeState(object_check, object){
	if(object_check.checked == false){
		document.all[object].disabled = true;
	}else{
		document.all[object].disabled = false;
		document.all[object].select();
	}
}
//-->
</script>     
<div class="bodyWrapper">
   <h1 class="sxAdminHeading"><?PHP echo $sxLang['PhotoHeadingManager']; ?></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> > <?PHP echo $sxLang['PhotoHeadingManager']; ?></div>   
   <?PHP echoMessage($message); ?>
   <?PHP 
   	// Orphan checker
	$sxQueryOrphans = "SELECT $DB_Photos.id FROM $DB_Photos LEFT JOIN $DB_Photos_Assoc ON $DB_Photos.id=$DB_Photos_Assoc.photoid WHERE  $DB_Photos_Assoc.id IS NULL";
	$sxResultOrphans = mysql_query($sxQueryOrphans, $Link) or queryError("13152", mysql_error());
	if(mysql_num_rows($sxResultOrphans) > 0)
		$sxWarning = array($sxLang['WarningTitle'], $sxLang['WarningPhotoOrphans'] . '<br /><a href="'. $PHP_SELF.'?sxOrphans=true">' . $sxLang['WarningPhotoOrphansFix'] .'</a>');

	sxEchoWarning($sxWarning);
   ?>
   <form name="sxFormPhotoManager" action="<?PHP echo $PHP_SELF; ?>" method="post">
   <?PHP if((!$DeleteAll)AND(!$EditAll)){ ?>
	<span class="sxSmallText"><?PHP echo $sxLang['PhotoFilterByAlbum']; ?>: 
	<select name="menu1" onChange="MM_jumpMenu('parent',this,0)">
	  <option value="photos.php"<?PHP if(($sxOrphans != TRUE)OR(!$albumid)) echo ' selected="selected"'; ?>><?PHP echo $sxLang['PhotoFilterItemAll']; ?></option>
	  <option value="photos.php?sxOrphans=true"<?PHP if($sxOrphans == TRUE) echo ' selected="selected"'; ?>><?PHP echo $sxLang['PhotoFilterItemOrphans']; ?></option>
	  <?PHP
		$query = "SELECT * FROM $DB_Photos_Albums ORDER BY name ASC";
		$result = mysql_query($query, $Link) or queryError("46", mysql_error());
		while($ROW = mysql_fetch_object($result))
		{
			if($albumid == $ROW->id)
				$selected = " selected";
			else
				$selected = "";
			echo '<option value="' . "$PHP_SELF?albumid=$ROW->id" . '"' . $selected . '>' . $ROW->name . '</option>';
		}
		?>
	</select>
	</span> 
	<div style="padding-top:8px;padding-bottom:8px;font-size:10px;"><?PHP pageTurns("$PHP_SELF?albumid=$albumid&sxOrphans=$sxOrphans&", $totalPics, $page, $admin_pics_per_page); ?></div>
	<table border="0" cellspacing="2" cellpadding="5">
	  <tr>
		<td class="tableColumn">&nbsp;</td>	
		<td class="tableColumn"><?PHP echo $sxLang['PhotoAlbumItemPhoto']; ?></td>
		<td class="tableColumn"><?PHP echo $sxLang['GeneralItemFilename']; ?></td>
		<td class="tableColumn"><?PHP echo $sxLang['GeneralItemOptions']; ?></td>
	  </tr>
		<?PHP
		if($albumid)
		{
			$query = "SELECT $DB_Photos.id, $DB_Photos.filename, $DB_Photos.name FROM $DB_Photos, $DB_Photos_Assoc
					  WHERE $DB_Photos.id=$DB_Photos_Assoc.photoid AND $DB_Photos_Assoc.albumid='$albumid'
					  ORDER BY $DB_Photos.name ASC
					  LIMIT $start, $admin_pics_per_page";
			$result = mysql_query($query, $Link) or queryError("27", mysql_error());
		}
		elseif($sxOrphans == TRUE)
		{
			$query = "SELECT $DB_Photos.id, $DB_Photos.filename, $DB_Photos.name FROM $DB_Photos LEFT JOIN $DB_Photos_Assoc ON $DB_Photos.id=$DB_Photos_Assoc.photoid
		              WHERE $DB_Photos_Assoc.id IS NULL 
					  ORDER BY $DB_Photos.name ASC
					  LIMIT $start, $admin_pics_per_page";
			$result = mysql_query($query, $Link) or queryError("28", mysql_error());
		}
		else
		{
			$query = "SELECT * FROM $DB_Photos ORDER BY name ASC LIMIT $start, $admin_pics_per_page";
			$result = mysql_query($query, $Link) or queryError("29", mysql_error());
		}
		while($ROW = mysql_fetch_object($result))
		{
			echo '  <tr bgcolor="' . $sxTheme['ColorTableRow'] . '">';
			echo '     <td><input type="checkbox" name="photo[' . $ROW->id . ']" id="photo' . $ROW->id . '" value="1" /></td>';
			echo '     <td><img style="float: left;" alt="' . $ROW->filename . '" width="50" src="' . "../".$sxContentDir['PhotoThumb'] . $ROW->filename . '" align="left" hspace="5" /></td>';
			echo '     <td valign="top">' .  htmlspecialchars($ROW->name) . '<br />' . $ROW->filename . '</td>';
			echo '     <td valign="top"><a href="photo_edit.php?editid=' . $ROW->id . '" title="' . $sxLang['ButtonEdit'] . '"><img src="../images/admin_edit.gif" style="border: 0;" alt="' . $sxLang['ButtonEdit'] . '" /></a> ';
			echo '     <a href="photo_replace.php?editid=' . $ROW->id . '&sxPrevURL='.urlencode("http://{$HTTP_HOST}{$REQUEST_URI}"). '" title="' . $sxLang['PhotoButtonReplace'] . '"><img src="../images/admin_reset.gif" style="border: 0;" alt="' . $sxLang['PhotoButtonReplace'] . '" /></a> ';
			echo '     <a href="#" onclick="confirmDelete(' . $ROW->id . ',\'' .  htmlspecialchars(addslashes($ROW->name)) . '\')" title="' . $sxLang['ButtonDelete'] . '"><img src="../images/admin_delete.gif" style="border: 0;" alt="' . $sxLang['ButtonDelete'] . '" /></a></td>';
			echo '  </tr>';
			$photos[$ROW->id] = $ROW->id;
		}
		if(mysql_num_rows($result) == 0)
			echo '<tr bgcolor="' . $sxTheme['ColorTableRow'] . '"><td colspan="3"><div style="width:400px;"><em>' . $sxLang['NoFiles'] . '</em></div></td></tr>';
		?></table>
	  <div style="padding-top:8px;padding-bottom:8px;font-size:10px;">
		<?PHP pageTurns("$PHP_SELF?albumid=$albumid&sxOrphans=$sxOrphans&", $totalPics, $page, $admin_pics_per_page); ?>
	  </div>
	  <div style="padding-top:8px;padding-left:8px;font-size:10px;">
		<img alt="Arrow" src="../images/arrow_ltr.png" /> 
		(<a href="#" onmousedown="javascript: <?PHP if($photos){ foreach($photos as $value) echo "document.sxFormPhotoManager.photo$value.checked=true;"; }?>"><?PHP echo $sxLang['All']; ?></a> / 
		 <a href="#" onmousedown="javascript: <?PHP if($photos) { foreach($photos as $value) echo "document.sxFormPhotoManager.photo$value.checked=false;"; } ?>"><?PHP echo $sxLang['None']; ?></a>) 
		 <?PHP echo $sxLang['PhotoWithSelected']; ?>: 
		<input style=" " type="submit" name="DeleteAll" value="<?PHP echo $sxLang['ButtonDelete']; ?>" class="sxButton" /> 
		<input style=" " type="submit" name="EditAll" value="<?PHP echo $sxLang['ButtonEdit']; ?>" class="sxButton" />
	  </div>
	  <?PHP }if($DeleteAll){ ?>
		<table width="<?PHP echo $sxThemeConfig['ContentWidth']; ?>" border="0" cellspacing="2" cellpadding="5" bgcolor="<?PHP echo $sxTheme['ColorTableRow']; ?>">
		 <tr>
		  <td><strong><?PHP echo $sxLang['PhotoConfirmDeleteAll']; ?></strong><br /><br />
		  <?PHP
		  $first = true;
		  foreach($photo as $key => $value)
		  {
			$query = "SELECT * FROM $DB_Photos WHERE id='$key'";
			$result = mysql_query($query, $Link) or queryError("46", mysql_error());
			$ROW = mysql_fetch_object($result);
			if($first){ echo $ROW->name; $first = false; }
			else echo ', '.$ROW->name;
		  }
		  foreach($photo as $key => $value)
			echo ' <input type="hidden" name="photo[' . $key . ']" value="photo[' . $key . ']" /> '."\n";
		  ?>
		  <p align="center">
			<input style=" " type="submit" name="DeleteAllFinal" value="<?PHP echo $sxLang['Yes']; ?>" class="sxButton" /> 
			<input style=" " type="button" name="Cancel" value="<?PHP echo $sxLang['No']; ?>" onclick="window.location='photos.php'" />
		  </p>
		  </td>
		 </tr>
		</table>
	  <?PHP }if($EditAll){ ?>
	   <p><?PHP echo $sxLang['PhotoEditAllNotes']; ?></p>
	   <p style="background-color:<?PHP echo $sxTheme['ColorTableRow']; ?>; padding: 5px;"><strong><?PHP echo $sxLang['PhotoItemPhotos']; ?>:</strong> 
   <?PHP
	  $first = true;
	  foreach($photo as $key => $value){
		$query3 = "SELECT * FROM $DB_Photos WHERE id='$key'";
		$result3 = mysql_query($query3, $Link) or queryError("46", mysql_error());
		$ROW3 = mysql_fetch_object($result3);
		if($first){ echo $ROW3->name; $first = false; }
		else echo ', '.$ROW3->name;
	  }
	  foreach($photo as $key => $value)
		echo ' <input type="hidden" name="photo[' . $key . ']" value="photo[' . $key . ']" /> '."\n";
	  ?></p>
	<table border="0" cellspacing="3" cellpadding="5">
	  <tr> 
		<td class="sxTdItem"><?PHP echo $sxLang['PhotoItemPhotographer']; ?></td>
		<td><input type="checkbox" id="check_photographer" name="check_photographer" value="1" onclick="changeState(this, 'photographer')" />
		<span class="sxSmallText"><?PHP echo $sxLang['PhotoChangePhotographer']; ?></span><br />
		&nbsp;<input name="photographer" style="width:150px;" type="text" id="photographer"  value="<?PHP echo $ROW->photographer; ?>" /></td>
	  </tr>
	  <tr> 
		<td class="sxTdItem"><?PHP echo $sxLang['GeneralItemDescription']; ?></td>
		<td><input type="checkbox" id="check_description" name="check_description" value="1" onclick="changeState(this, 'description')" />
		<span class="sxSmallText"><?PHP echo $sxLang['PhotoChangeDescription']; ?></span><br />&nbsp;<textarea name="description" style="width:300px; height:100px;" id="description"><?PHP echo $ROW->description; ?></textarea></td>
	  </tr>
	  <tr> 
		<td class="sxTdItem"><?PHP echo $sxLang['PhotoItemAlbums']; ?></td>
		<td><input type="checkbox" id="check_albums" name="check_albums" value="1" onclick="changeState(this, 'albums')" />
		<span class="sxSmallText"><?PHP echo $sxLang['PhotoChangeAlbums']; ?></span><br />&nbsp;<select style="height:150px; width:300px;" name="albums[]" id="albums" size="6" multiple>
			<?PHP
			$query2 = "SELECT * FROM $DB_Photos_Albums";
			$result2 = mysql_query($query2, $Link) or queryError("46", mysql_error());
			while($ROW2 = mysql_fetch_object($result2)){
				$query3 = "SELECT * FROM $DB_Photos_Assoc WHERE photoid='$editid' AND albumid='$ROW2->id'";
				$result3 = mysql_query($query3, $Link) or queryError("46", mysql_error());
				if(mysql_num_rows($result3)) $selected = " selected";
				else $selected = "";
				echo '<option value="' . $ROW2->id . '"' . $selected . '>' . $ROW2->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"> <p> 
			<input type="checkbox" id="check_keywords" name="check_keywords" value="1" onclick="changeState(this, 'keywords')" />
			<span class="sxSmallText"><?PHP echo $sxLang['PhotoChangeKeywords']; ?></span><br />&nbsp;
			<textarea name="keywords" style="width:300px; height:100px;" id="keywords"><?PHP
			$first = true;
			$query2 = "SELECT * FROM $DB_Photos_Keywords WHERE photoid='$editid'";
			$result2 = mysql_query($query2, $Link) or queryError("46", mysql_error());
			while($ROW2 = mysql_fetch_object($result2)){
				if(!$first) echo ", ";
				echo $ROW2->keyword;
				$first = false;
			}
			?></textarea>
		  </p></td>
	  </tr>
	  <tr> 
		<td colspan="2" align="right"><input type="submit" name="EditAllFinal" value="<?PHP echo $sxLang['PhotoButtonEditAll']; ?>" class="sxButton" /></td>
	  </tr>
	</table>
	<script language="JavaScript" type="text/JavaScript">
	<!--
	window.document.form1.photographer.disabled = true;
	window.document.form1.description.disabled = true;
	window.document.form1.albums.disabled = true;
	window.document.form1.keywords.disabled = true;
	//-->
	</script><?PHP } ?>
	</form>
	</div>
<?PHP
include("../themes/$THEME_FOLDER/footer.php");
ob_end_flush();
?>
Return current item: SiteX