<?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']);
$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);
if($Submit)
{
if($hide_random != 1)
$hide_random = 0;
$query = "UPDATE $DB_Photos SET name='$name', photographer='$photographer', description='$description', timestamp='$timestamp', hide_random='$hide_random' WHERE id='$editid'";
$result = mysql_query($query, $Link) or queryError("13", mysql_error());
$query = "DELETE FROM $DB_Photos_Keywords WHERE photoid='$editid'";
$result = mysql_query($query, $Link) or queryError("41", mysql_error());
editAlbumAssociation($editid, $albums);
$keywords = explode(", ", $keywords);
foreach($keywords as $k)
$keywords[$k] = trim($keywords[$k]);
for($i = 0; $i < count($keywords); $i++)
{
if($keywords[$i] != '') $result = mysql_query("INSERT INTO $DB_Photos_Keywords (photoid, keyword) VALUES ('$editid', '$keywords[$i]')", $Link) or queryError("41", mysql_error());
}
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><input name="name" type="text" style="width:150px;" id="name" value="<?PHP echo htmlspecialchars($ROW->name); ?>" /></td>
</tr>
<tr>
<td class="sxTdItem"><?PHP echo $sxLang['GeneralItemFile']; ?></td>
<td><?PHP echo '<a href="photo_replace.php?editid=' . $ROW->id . '&sxPrevURL='.urlencode("http://{$HTTP_HOST}{$REQUEST_URI}"). '" title="' . $sxLang['PhotoButtonReplace']; ?>"><img src="<?PHP echo "../".$sxContentDir['PhotoThumb'].$ROW->filename; ?>" alt="<?PHP echo $sxLang['PhotoButtonReplace']; ?>" /></a><br /><?PHP echo $ROW->filename; ?></td>
</tr>
<tr>
<td class="sxTdItem"><?PHP echo $sxLang['PhotoItemPhotographer']; ?></td>
<td><input name="photographer" style="width:150px;" type="text" id="photographer" value="<?PHP echo htmlspecialchars($ROW->photographer); ?>" /></td>
</tr>
<tr>
<td class="sxTdItem"><?PHP echo $sxLang['PhotoItemHideRandom']; ?></td>
<td><input name="hide_random" type="checkbox" id="hide_random" value="1"<?PHP if($ROW->hide_random == 1) echo ' checked="checked"'; ?> /></td>
</tr>
<tr>
<td class="sxTdItem"><?PHP echo $sxLang['GeneralItemDate']; ?></td>
<td><div id="calendarForForm"><input type="text" name="date" id="date" readonly="readonly" value="<?PHP echo date("Y-m-d", $ROW->timestamp); ?>" />
<script type="text/javascript" src="../includes/datepicker/dhtmlSuite-config.js"></script>
<script type="text/javascript" src="../includes/datepicker/dhtmlSuite-common.js"></script>
<script type="text/javascript" src="../includes/datepicker/dhtmlSuite-calendar.js"></script>
<script type="text/javascript" src="../includes/datepicker/dhtmlSuite-dragDropSimple.js"></script>
<script type="text/javascript">
var calendarObjForForm = new DHTMLSuite.calendar({minuteDropDownInterval:1,numberOfRowsInHourDropDown:5,callbackFunctionOnDayClick:'getDateFromCalendar',isDragable:true,displayTimeBar:false});
function pickDate(buttonObj,inputObject)
{
calendarObjForForm.setCalendarPositionByHTMLElement(inputObject,0,inputObject.offsetHeight+2); // Position the calendar right below the form input
calendarObjForForm.setInitialDateFromInput(inputObject,'yyyy-mm-dd'); // Specify that the calendar should set it's initial date from the value of the input field.
calendarObjForForm.addHtmlElementReference('myDate',inputObject); // Adding a reference to this element so that I can pick it up in the getDateFromCalendar below(myInput is a unique key)
if(calendarObjForForm.isVisible()){
calendarObjForForm.hide();
}else{
calendarObjForForm.resetViewDisplayedMonth(); // This line resets the view back to the inital display, i.e. it displays the inital month and not the month it displayed the last time it was open.
calendarObjForForm.display();
}
}
function getDateFromCalendar(inputArray)
{
var references = calendarObjForForm.getHtmlElementReferences(); // Get back reference to form field.
references.myDate.value = inputArray.year + '-' + inputArray.month + '-' + inputArray.day;
calendarObjForForm.hide();
}
</script>
<img alt="<?PHP echo $sxLang['GeneralTooltipPickDate']; ?>" title="<?PHP echo $sxLang['GeneralTooltipPickDate']; ?>" style="cursor:Pointer;cursor:hand;" src="../images/calendar.gif" onclick="pickDate(this,document.sxFormPhotoEdit.date);" align="absmiddle" /><br /><span class="sxSmallText">(<?PHP echo $sxLang['DateFormatYYYYMMDD']; ?>)</span></div>
</td>
</tr>
<tr>
<td class="sxTdItem"><?PHP echo $sxLang['GeneralItemDescription']; ?></td>
<td><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><select style="height:150px; width:300px;" name="albums[]" size="6" multiple>
<?PHP
$query2 = "SELECT * FROM $DB_Photos_Albums";
$result2 = mysql_query($query2, $Link) or queryError("177", 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("178", mysql_error());
if(mysql_num_rows($result3)) $selected = " selected";
else $selected = "";
echo ' <option value="' . $ROW2->id . '"' . $selected . '>' . $ROW2->name . '</option>'."\n";
}
?>
</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>
<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("179", mysql_error());
while($ROW2 = mysql_fetch_object($result2))
{
if(!$first) echo ", ";
echo $ROW2->keyword;
$first = false;
}
?></textarea>
</p></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['PhotoButtonEdit']; ?>" class="sxButton" /></td>
</tr></form>
</table>
</div>
<?PHP
include("../themes/$THEME_FOLDER/footer.php");
ob_end_flush();
?>