File: D:/HostingSpaces/SBogers45/smuldersinterieurprojecten.nl/wwwroot/admin/php/photoalbumManager.php
<?php
if(isset($_GET['sub']) || isset($_SESSION['tmp_linkname'])){
if(isset($_GET['sub'])){
$linkname = $_GET['sub'];
}
else if(isset($_SESSION['tmp_linkname'])){
$linkname = $_SESSION['tmp_linkname'];
unset($_SESSION['tmp_linkname']);
}
$result = mysql_query('SELECT label FROM _pages WHERE name="'.$linkname.'" LIMIT 1');
$record = mysql_fetch_assoc($result);
$label = $record['label'];
//contentOutput is a variable in index.php
$output .= initPhotoalbumManager($linkname, $label);
}
else{
$output .= 'something wen’t wrong';
}
function initPhotoalbumManager($linkname, $pageLabel){
//get text
$siteText = getSiteText();
//check if the needed tables are created
checkDatabase($linkname);
//show header in case of get
$output = '';
//header
if(isset($_GET['action']) && !isset($_POST['back'])){
$action = $_GET['action'];
if($action == 'newAlbum' || $action == 'editAlbum' || $action == 'deleteAlbum'){
$output .= '<div class="header-bar top-rounded content-bar">';
if($action == 'newAlbum'){
$output .= strtolower($pageLabel).' // '.$siteText['addAlbum'];
}
else if($action == 'editAlbum'){
$output .= strtolower($pageLabel).' // '.$siteText['editAlbum'];
}
else if($action == 'deleteAlbum'){
$output .= strtolower($pageLabel).' // '.$siteText['deleteAlbum'];
}
$output .= '</div>';
}
}
//if else structure $_POST and $_GET
if(isset($_POST['back'])){
if(isset($_GET['location'])){
$temp = explode('-',$_GET['location']);
$str = '?page='.$temp[0].'&action='.$temp[1];
if($temp[1] == 'edit') $str .= '&id='.$temp[2];
header('location: '.$str);
}
else{
$output .= showList($linkname, $pageLabel);
}
}
else if(isset($_POST['showChangeOrder'])){
$output .= showChangeOrder($linkname, $pageLabel);
}
else if(isset($_POST['do_submit_albums'])) {
sbmChangeAlbumOrder();
}
else if(isset($_POST['showChangeOrderPhotos'])){
$output .= showChangeOrderPhotos($linkname, $pageLabel);
}
else if(isset($_POST['do_submit_photos'])) {
sbmChangePhotosOrder();
}
else if(isset($_POST['back-photos'])){
header('location: ../../album'.$_POST['albumId'].'/');
}
//shows the question if you really want to delete the stuf
else if(isset($_POST['deleteSelected'])){
$output .= deleteSelected($linkname);
}
else if(isset($_POST['deleteSelectedPhotos'])){
$output .= deleteSelectedPhotos($linkname);
}
//moves selected to trash
else if(isset($_POST['moveSelectedToTrash'])){
$output .= moveSelectedToTrash($linkname);
correctAlbumOrderAfterDelete($linkname);
}
else if(isset($_POST['moveSelectedPhotosToTrash'])){
$output .= moveSelectedPhotosToTrash($linkname);
}
else if(isset($_POST['newAlbum_submit'])){
$output .= validateAddEditForm($linkname,'newAlbum');
}
else if(isset($_POST['editAlbum_submit'])){
$output .= validateAddEditForm($linkname,'editAlbum');
}
else if(isset($_POST['submitAddPhotos'])){
$output .= validateAddPhotos($linkname);
}
else if(isset($_POST['submitEditPhotos'])){
$output .= validateEditPhotos($linkname);
}
else if(isset($_GET['action'])){
$action = $_GET['action'];
if($action == 'newAlbum'){
$output .= showAddEditAlbumForm($linkname, 'newAlbum');
}
else if($action == 'editFile'){
$output .= showAddEditAlbumForm($linkname, 'editAlbum',$_GET['id']);
}
else if($action == 'editPhotos'){
$output .= showEditPhotosForm($linkname);
}
else if($action == 'moveAlbumUp'){
move('up',$_GET['id'], $linkname.'_albums', 'albumOrder', $linkname );
}
else if($action == 'moveAlbumDown'){
move('down',$_GET['id'], $linkname.'_albums', 'albumOrder', $linkname );
}
else if(substr($action,0,5) == 'album'){
$albumId = substr($action,5);
if(isset($_GET['id'])){
$albumAction = $_GET['id'];
if($albumAction == 'new-photos'){
$output .= addPhotos($linkname, $pageLabel,$albumId);
}
else{
$output .= showPhotos($linkname, $pageLabel,$albumId);
}
}
else{
$output .= showPhotos($linkname, $pageLabel,$albumId);
}
}
else if(substr($action,0,11) == 'changeThumb'){
setNewAlbumThumb();
}
/*else if($action == 'movePhotoUp'){
$result = mysql_query('SELECT albumId FROM '.$linkname.'_photos WHERE id = '.$_GET['id']);
$record = mysql_fetch_assoc($result);
$albumId = $record['albumId'];
movePhotos('up', $albumId, $_GET['id'], $linkname.'_photos', 'photoOrder', $linkname.'&albumId='.$albumId );
}
else if($action == 'movePhotoDown'){
$result = mysql_query('SELECT albumId FROM '.$linkname.'_photos WHERE id = '.$_GET['id']);
$record = mysql_fetch_assoc($result);
$albumId = $record['albumId'];
movePhotos('down', $albumId, $_GET['id'], $linkname.'_photos', 'photoOrder', $linkname.'&albumId='.$albumId );
}*/
}
else{
$output .= showList($linkname, $pageLabel);
}
return $output;
}
/************************************************************************
SHOWLIST
************************************************************************/
function showList($linkname, $pageLabel){
//get text
$siteText = getSiteText();
//start output
$output = '';
//header
$output .= '<div class="header-bar top-rounded content-bar">'.strtolower($pageLabel).' // '.$siteText['albums'].'</div>';
//menu
$output .= '<div class="pages-group-options">';
$output .= '<strong>'.ucfirst($siteText['albumOverviewTitle']).'</strong>';
$output .= '</div>';
$output .= '<div class="pages-action-menu';
$output .= '">';
$output .= '<ul>
<li><a href="./pages/'.$linkname.'/newAlbum/"><img src="./images/icons/plus.png" alt="add"/> '.ucfirst($siteText['addAlbum']).'</a></li>
<div class="clear"></div>
</ul>';
$output .= '</div>';
$output .= '<div class="clear"></div>';
//form
$output .= '<form action="" name="chkForm" method="post">';
//sub menu
$output .= '<div class="med-sub-nav">';
$output .= '<span class="med-check-all"><input type="checkbox" name="'.$linkname.'_checkCtrl" value="checkAll" onClick="check_all(this);" class="med-check-all-box"> (Un)check all </span>';
$output .= '<input type="submit" id="deleteSelected" name="deleteSelected" value="'.ucfirst($siteText['deleteSelected']).'" class="button fully-rounded med-delete-selected"/>';
$output .= '<input type="submit" id="showChangeOrder" name="showChangeOrder" value="'.$siteText['changeOrder'].'" class="button fully-rounded med-change-order"/>';
$output .= '<div class="clear"></div>';
$output .= '</div>';
$output .= '<div class="clear"></div>';
$output .= '<br />';
//get the total items
$numItemsQuery = 'SELECT a.id, a.linkname, a.title, a.thumb, a.description, a.albumOrder
FROM '.$linkname.'_albums AS a, status AS s
WHERE s.page="'.$linkname.'"
AND s.itemId = a.id
AND s.active=1
ORDER BY a.albumOrder DESC';
$numItemsResult = mysql_query($numItemsQuery);
$numTotalItems = mysql_num_rows($numItemsResult);
//set max items
$maxItems = 15;
$numPages = ceil($numTotalItems / $maxItems);
if($numPages == 0) $numPages = 1;
if(isset($_GET['pageId'])){
$thispage = $_GET['pageId'];
}
else{
$thispage = 1;
}
$limitFrom = ($thispage * $maxItems)-$maxItems;
$query = $numItemsQuery .= ' LIMIT '.$limitFrom.','.$maxItems;
$result = mysql_query($query);
$numItems = mysql_num_rows($result);
$colCount = 0;
$count = 0;
$output .= '<div class="med-thumb-row">';
while($record = mysql_fetch_assoc($result)){
$itemId = $record['id'];
$title = fromDatabase($record['title']);
$description = fromDatabase($record['description']);
$albumLinkname = $record['linkname'];
$order = $record['albumOrder'];
$trimThumb = trim($record['thumb']);
if(!empty($trimThumb) && $trimThumb != ""){
$thumb = '../images/'.$linkname.'/'.$itemId.'/thumb/'.$record['thumb'];
}
else{
$thumb = './images/structure/nophotos.jpg';
}
$hoverThumb = $thumb;
$actionSuffix = 'File';
if($colCount == 0 && $count != 0){
$output .= '<div class="clear"></div>';
$output .= '</div>';
$output .= '<div class="med-thumb-row">';
}
//hover output
/*$str = '';
$str .='<div class=\\\'med-hover-img\\\'>';
$str .= '<img src=\\\''.$hoverThumb.'\\\' width=\\\'198\\\' />';
$str .= '</div>';
$str .= '<div class=\\\'med-hover-title\\\'>';
$str .= '"'.inDatabase($title).'"';
$str .= '</div>';
$str .= '<div class=\\\'med-hover-actions\\\'>';
$str .= '<a href=\\\'./pages/'.$linkname.'/edit'.$actionSuffix.'/'.$itemId.'/\\\' /><img src=\\\'./images/icons/edit.png\\\' class=\\\'mp-box-icon\\\' /></a>';
$str .= '</div>';
//thumb output
$output .= '<div class="med-thumb" onMouseOver="mediaOver('.$itemId.', \''.$str.'\');" onMouseOut="thumbDivMouseOut('.$itemId.');" >
<input type="checkbox" name="option[]" id="option" value="'.$itemId.'" class="med-thumb-img-cb"/>
<a href="./pages/'.$linkname.'/album'.$itemId.'/"><img src="'.$thumb.'" id="med-img-'.$itemId.'" alt="'.$title.'" class="med-thumb-img" height="105"/></a>
</div>';*/
$output .='<div class="med-album">';
$output .='<div class="med-album-img">';
$output .= '<input type="checkbox" name="option[]" id="option" value="'.$itemId.'" class="med-thumb-img-cb"/>';
$output .= '<a href="./pages/'.$linkname.'/album'.$itemId.'/"><img src="'.$hoverThumb.'" width="165" /></a>';
$output .= '</div>';
$output .= '<div class="med-album-actions">';
$output .= '<a href="./pages/'.$linkname.'/edit'.$actionSuffix.'/'.$itemId.'/" /><img src="./images/icons/edit_w.png" class="mp-box-icon" /></a>';
$output .= '</div>';
$output .= '<div class="med-album-title">';
$output .= '"'.inDatabase($title).'"';
$output .= '</div>';
$output .= '</div>';
$colCount++;
$count++;
if($colCount == 4){
$colCount = 0;
}
}
$output .= '<div class="clear"></div>';
$output .= '</div>';
$output .= '</form>';
/*
$output .= '<div class="mediaRow'.$row.'">';
$output .= '<div class="mediaCheckbox"><input type="checkbox" name="option[]" id="option" value="'.$itemId.'" /></div>';
$output .= '<div class="mediaImage"><img src="'.$thumb.'" alt="'.$name.'" width="50" height="50"/></div>';
$output .= '<div class="mediaTitle"><a href="?page='.$linkname.'&albumId='.$itemId.'">'.$name.'</a></div>';
$output .= '<div class="mediaShortcode">'.substr($description,0, 30);
if(strlen($description) > 30){ $output .='..' ;}
$output .= '</div>';
$output .= '<div class="mediaButtons">';
if($order != $numItems) $output .= '<a href="?page='.$linkname.'&action=moveAlbumUp&id='.$itemId.'"><img src="images/arrowup.png" class="btnSpace" /></a>';
if($order != 1) $output .= '<a href="?page='.$linkname.'&action=moveAlbumDown&id='.$itemId.'"><img src="images/arrowdown.png" class="btnSpace"/></a>';
$output .= '<a href="?page='.$linkname.'&action='.$actionEdit.'&id='.$itemId.'"><img src="images/edit.png" width="10"/></a>';
$output .= '</div>
</div>';
*/
$output .= '<div class="pageControl">';
if($thispage != 1){ $output .= '<div class="prevPage"><a href="?page=media&pageId='.($thispage-1).'">'.$siteText['prevPage'].'</a></div>'; }
if($thispage != $numPages){ $output .= '<div class="nextPage"><a href="?page=media&pageId='.($thispage+1).'">'.$siteText['prevPage'].'</a></div>'; }
$output .= '</div>';
return $output;
}
/************************************************************************
ADD ALBUMS
************************************************************************/
function showAddEditAlbumForm($linkName, $action, $albumId = ''){
//get text
$siteText = getSiteText();
if(!isset($_SESSION['addAlbums']['value']['albumName'])){
$_SESSION['addAlbums']['errors'] = '';
$_SESSION['addAlbums']['value']['albumName'] = '';
$_SESSION['addAlbums']['value']['albumLinkname'] = '';
$_SESSION['addAlbums']['value']['albumDesc'] = '';
}
if($action == 'editAlbum'){
$query = 'SELECT title, linkname, description FROM '.$linkName.'_albums WHERE id="'.$albumId.'" LIMIT 1';
$result = mysql_query($query);
$record = mysql_fetch_assoc($result);
$_SESSION['addAlbums']['value']['albumName'] = $record['title'];
$_SESSION['addAlbums']['value']['albumLinkname'] = $record['linkname'];
$_SESSION['addAlbums']['value']['albumDesc'] = $record['description'];
}
$formOutput = '';
$formOutput .= '<div class="double-column-content">';
if(!empty($_SESSION['addAlbums']['errors'])){
$formOutput .= '<span class="errForm">'.$_SESSION['addAlbums']['errors'].'</span><br />';
}
$formOutput .= '<form action="" method="post" name="addAlbums" enctype="multipart/form-data">';
//Name
$formOutput .= '<div class="input-total column-margin-right">';
$formOutput .= '<div class="input-title">';
$formOutput .= $siteText['albumFormTitle'];
$formOutput .= '</div>';
$formOutput .= '<input type="text" name="albumName" value="'.$_SESSION['addAlbums']['value']['albumName'].'"/>';
$formOutput .= '</div>';
//Linkname
/* $formOutput .= '<div class="input-total">';
$formOutput .= '<div class="input-title">';
$formOutput .= $siteText['albumFormLinkname'];
$formOutput .= '</div>';
$formOutput .= '<input type="text" name="albumLinkname" value="'.$_SESSION['addAlbums']['value']['albumLinkname'].'"/>';
$formOutput .= '</div>'; */
//clear row
$formOutput .= '<div class="clear"></div>';
//Thumb
/* Removed in version 1.1
if($action == 'newAlbum'){
$formOutput .= '<div class="input-total">';
$formOutput .= '<div class="input-title">';
$formOutput .= $siteText['albumFormThumb'];
$formOutput .= '</div>';
$formOutput .= '<input type="file" name="images[]" value=""/>';
$formOutput .= '</div>';
}*/
//clear row
$formOutput .= '<div class="clear"></div>';
//Description
$formOutput .= '<div class="input-title">';
$formOutput .= $siteText['albumFormDesc'];
$formOutput .= '</div>';
$formOutput .= '<textarea cols="5" name="albumDesc" class="wysiwyg" rows="10">'.$_SESSION['addAlbums']['value']['albumDesc'].'</textarea>';
//clear row
$formOutput .= '<div class="clear"></div>';
if($action == 'editAlbum') $formOutput .= '<input type="hidden" name="editId" value="'.$albumId.'" />';
$formOutput .= '<input type="submit" name="'.$action.'_submit" value="'; if($action == 'newAlbum'){ $formOutput .= ucfirst($siteText['addAlbum']); } else{ $formOutput .= ucfirst($siteText['editAlbum']); } $formOutput .= '" class="button fully-rounded"/>
<input type="submit" name="back" value="'.$siteText['formBack'].'" class="button fully-rounded"/>
<div class="clear"></div>';
$formOutput .= '</form>';
$formOutput .= '</div>';
return $formOutput;
}
/************************************************************************
EDIT ALBUMS
************************************************************************/
function validateAddEditForm($linkname, $action){
//get text
$siteText = getSiteText();
if(!empty($_POST['albumName'])){
$albumName = $_SESSION['value']['albumName'] = inDatabase($_POST['albumName']);
$albumLinkname = $_SESSION['value']['albumLinkname'] = linkname($_POST['albumName']);
$albumDescription = $_SESSION['value']['albumDesc'] = inDatabase($_POST['albumDesc']);
$timest = time();
if($action == 'newAlbum'){
//VALID:
//set errors to empty
$_SESSION['addAlbums']['errors'] = '';
$albumOrder = 1;
//get albumOrder
$orderQuery = mysql_query('SELECT albumOrder FROM '.$linkname.'_albums ORDER by albumOrder DESC LIMIT 1');
if(mysql_num_rows($orderQuery) > 0){
$orderRecord = mysql_fetch_assoc($orderQuery);
$albumOrder = $orderRecord['albumOrder'];
$albumOrder++;
}
$query = 'INSERT INTO '.$linkname.'_albums(linkname, title, description, thumb, timest, albumOrder)
VALUES("'.$albumLinkname.'","'.$albumName.'","'.$albumDescription.'", "", "'.$timest.'", "'.$albumOrder.'")';
mysql_query($query);
$insertId = mysql_insert_id();
$statusQuery = mysql_query('INSERT INTO status(itemId, page, active) VALUES("'.$insertId.'", "'.$linkname.'", "1")');
unset($_SESSION['addAlbums']['value']);
header('location: ../');
}
else{
//edit album
mysql_query('UPDATE '.$linkname.'_albums
SET title = "'.$albumName.'", linkname = "'.$albumLinkname.'", description = "'.$albumDescription.'"
WHERE id = '.$_POST['editId'].'
LIMIT 1');
unset($_SESSION['value']['albumName']);
unset($_SESSION['value']['albumLinkname']);
unset($_SESSION['value']['albumDesc']);
header('location: ../../');
}
}
else{
$_SESSION['addAlbums']['errors'] = $siteText['emptyField2'];
header('location: ./');
}
}
/************************************************************************
SHOW LIST PHOTOS
************************************************************************/
function showPhotos($linkname, $pageLabel, $albumId){
//get text
$siteText = getSiteText();
//start output
$output = '';
//get albumName
$query = 'SELECT title, description FROM '.$linkname.'_albums WHERE id='.$albumId.' LIMIT 1';
$result = mysql_query($query);
$record = mysql_fetch_assoc($result);
$albumTitle = fromDatabase($record['title']);
$albumDescription = fromDatabase($record['description']);
//header
$output .= '<div class="header-bar top-rounded content-bar">'.strtolower($pageLabel).' // '.$siteText['albums'].' // '.strtolower($albumTitle).'</div>';
//menu
$output .= '<div class="pages-group-options">';
$output .= '<strong>"'.$albumTitle.'"</strong>';
$output .= '<a href="./pages/'.$linkname.'/editFile/'.$albumId.'/" /><img src="./images/icons/edit.png" class="mp-box-icon pages-group-icon" /></a>';
$output .= '</div>';
$output .= '<div class="pages-action-menu';
$output .= '">';
$output .= '<ul>
<li><a href="./pages/'.$linkname.'/album'.$albumId.'/new-photos/"><img src="./images/icons/plus.png" alt="add"/> '.$siteText['addPhotos'].'</a></li>
<div class="clear"></div>
</ul>';
$output .= '</div>';
$output .= '<div class="clear"></div>';
//form
$output .= '<form action="" name="chkForm" method="post">';
//sub menu
$output .= '<div class="med-sub-nav">';
$output .= '<span class="med-check-all"><input type="checkbox" name="'.$linkname.'_checkCtrl" value="checkAll" onClick="check_all(this);" class="med-check-all-box">'.$siteText['checkAll'].'</span>';
$output .= '<input type="submit" id="deleteSelected" name="deleteSelectedPhotos" value="'.$siteText['deleteSelected'].'" class="button fully-rounded med-delete-selected"/>';
$output .= '<input type="submit" name="showChangeOrderPhotos" value="'.$siteText['changeOrder'].'" class="button fully-rounded med-change-order"/>';
$output .= '<div class="clear"></div>';
$output .= '</div>';
$output .= '<div class="clear"></div>';
$descNoSpaces = trim($albumDescription);
$descNoSpaces = strip_tags($descNoSpaces);
if(!empty($albumDescription)){
$output .= '<div class="double-column-content">';
$output .= '<strong>'.$siteText['formInputDesc'].'</strong><br />';
$output .= $albumDescription;
$output .= '</div>';
}
if(isset($_SESSION['fails'])){
if($_SESSION['fails']['num'] > 0){
$output .= '<div class="double-column-content errForm">';
$output .= '<strong>'.$_SESSION['fails']['num'].' error(s) occured</strong><br />';
$output .= $_SESSION['fails']['output'];
$output .= '</div>';
$output .= '<div class="clear"></div>';
}
unset($_SESSION['fails']);
}
//get the total items
$numItemsQuery = 'SELECT a.id AS albumId, a.thumb AS albumThumb ,p.id AS photoId, p.title AS photoName, p.thumb, p.description, a.linkname AS albumName, p.photoOrder
FROM '.$linkname.'_photos AS p,'.$linkname.'_albums AS a
WHERE p.albumId = '.$albumId.'
AND p.albumId = a.id
ORDER BY p.photoOrder DESC';
//echo $numItemsQuery;
$numItemsResult = mysql_query($numItemsQuery);
$numTotalItems = mysql_num_rows($numItemsResult);
//rows
$output .= '<div class="med-thumb-row">';
$count = 0;
$colCount = 0;
while($record = mysql_fetch_assoc($numItemsResult)){
$photoId = $record['photoId'];
$albumId = $record['albumId'];
$title = $record['photoName'];
$albumLinkname = $record['albumName'];
$thumb = '../images/'.$linkname.'/'.$albumId.'/thumb/'.$record['thumb'];
$order = $record['photoOrder'];
$hoverThumb = $thumb;
$actionSuffix = 'Photos';
if($colCount == 0 && $count != 0){
$output .= '<div class="clear"></div>';
$output .= '</div>';
$output .= '<div class="med-thumb-row">';
}
//hover output
/*$str = '';
$str .='<div class=\\\'med-hover-img\\\'>';
$str .= '<img src=\\\''.$hoverThumb.'\\\' width=\\\'198\\\' />';
$str .= '</div>';
$str .= '<div class=\\\'med-hover-title\\\'>';
$str .= '"'.$title.'"';
$str .= '</div>';
$str .= '<div class=\\\'med-hover-actions\\\'>';
$str .= '<a href=\\\'./pages/'.$linkname.'/changeThumb_'.$albumId.'/'.$photoId.'/\\\' /><img src=\\\'./images/icons/thumb.png\\\' class=\\\'mp-box-icon\\\' /></a>';
$str .= '<a href=\\\'./pages/'.$linkname.'/edit'.$actionSuffix.'/'.$photoId.'/\\\' /><img src=\\\'./images/icons/edit.png\\\' class=\\\'mp-box-icon\\\' /></a>';
$str .= '</div>';
//thumb output
$output .= '<div class="med-thumb" onMouseOver="mediaOver('.$photoId.', \''.$str.'\' );" onMouseOut="thumbDivMouseOut('.$photoId.');" >
<input type="checkbox" name="option[]" id="option" value="'.$photoId.'" class="med-thumb-img-cb"/>
<img src="'.$thumb.'" id="med-img-'.$photoId.'" alt="'.$title.'" class="med-thumb-img" height="105"/>';
if($record['thumb'] == $record['albumThumb']){
$output .= '<div class="med-thumb-img-isThumb">
<img src="./images/icons/thumb.png" alt="is thumb"/>
</div>';
}
$output .= '</div>';
*/
$output .='<div class="med-hover">';
$output .='<div class="med-hover-img">';
$output .= '<input type="checkbox" name="option[]" id="option" value="'.$photoId.'" class="med-thumb-img-cb"/>';
$output .= '<img src="'.$hoverThumb.'" width="130" />';
$output .= '</div>';
$output .= '<div class="med-hover-title">';
$output .= '"'.$title.'"';
$output .= '</div>';
$output .= '<div class="med-hover-actions">';
$output .= '<a href="./pages/'.$linkname.'/changeThumb_'.$albumId.'/'.$photoId.'/" />';
if($record['thumb'] == $record['albumThumb']){
$output .= '<img src="./images/icons/thumb_blue.png" class="mp-box-icon" />';
}
else{
$output .= '<img src="./images/icons/thumb.png" class="mp-box-icon" />';
}
$output .= '</a>';
$output .= '<a href="./pages/'.$linkname.'/edit'.$actionSuffix.'/'.$photoId.'/" /><img src="./images/icons/edit.png" class="mp-box-icon" /></a>';
$output .= '</div>';
$output .= '</div>';
$colCount++;
$count++;
if($colCount == 5){
$colCount = 0;
}
}
$output .= '</div>';
return $output;
}
/************************************************************************
ADD PHOTOS
************************************************************************/
function addPhotos($linkname, $pageLabel, $albumId){
//get text
$siteText = getSiteText();
$formOutput = '';
$formOutput .= '<div class="header-bar top-rounded content-bar">add photos</div>';
$formOutput .= '<div class="triple-column-content">';
$formOutput .= '<form action="" method="post" name="addAlbums" enctype="multipart/form-data">';
for($i=0;$i<5;$i++){
$formOutput .= '<div class="input-total column-margin-right">';
$formOutput .= '<div class="input-title">';
$formOutput .= $siteText['photo'].' '.$i;
$formOutput .= '</div>';
$formOutput .= '<input type="file" name="photos[]" value=""/>';
$formOutput .= '</div>';
//IF TITLE & DESCRIPTION
/*$formOutput .= '<div class="input-total column-margin-right">';
$formOutput .= '<div class="input-title">';
$formOutput .= $siteText['namePhoto'].' '.$i;
$formOutput .= '</div>';
$formOutput .= '<input type="text" name="photoName[]" value=""/>';
$formOutput .= '</div>';
$formOutput .= '<div class="input-total">';
$formOutput .= '<div class="input-title">';
$formOutput .= $siteText['formInputDesc'].' '.$i;
$formOutput .= '</div>';
$formOutput .= '<input type="text" name="photoDesc[]" value=""/>';
$formOutput .= '</div>';*/
//IF NO TITLE & DESCRIPTION
$formOutput .= '<input type="hidden" name="photoName[]" value=""/>';
$formOutput .= '<input type="hidden" name="photoDesc[]" value=""/>';
//clear row
$formOutput .= '<div class="clear"></div>';
}
$formOutput .= '<input type="hidden" name="albumId" value="'.$albumId.'"/>';
$formOutput .= '<input type="submit" name="submitAddPhotos" value="'.$siteText['addPhotos'].'" class="button fully-rounded"/>
<input type="submit" name="back" value="'.$siteText['formBack'].'" class="button fully-rounded"/>
<div class="clear"></div>';
$formOutput .= '</form>';
$formOutput .= '</div>';
return $formOutput;
}
function validateAddPhotos($linkname){
$numFails = 0;
$_SESSION['fails'] = '';
$_SESSION['fails']['num'] = 0;
$_SESSION['fails']['output'] = '';
$numSucces = 0;
$albumId = $_POST['albumId'];
foreach ($_FILES['photos']['name'] as $key => $value){
if(!empty($value)){
$photoName = $_POST['photoName'][$key];
$photoDesc = $_POST['photoDesc'][$key];
$timest = time();
//GET ALBUM LINKNAME
$result = mysql_query('SELECT linkname FROM '.$linkname.'_albums WHERE id = '.$albumId);
$record = mysql_fetch_assoc($result);
$albumLinkname = $record['linkname'];
//get the filesize
$file_size[$key] = $_FILES['photos']['size'][$key];
$limit_size = 50000000;
//when the file isn't to big
if($file_size[$key] <= $limit_size){
//VALID:
$fileExtArr = explode('.', $value);
//the last part of this array is the extention
$fileExt = strtolower($fileExtArr[count($fileExtArr) - 1]);
if($fileExt == 'jpg' || $fileExt == 'png' || $fileExt == 'gif' || $fileExt == 'jpeg' ){
$fileName = str_replace('.'.$fileExt, '', $value).'_'.md5(microtime()).'.'.$fileExt;
//make sure the filename has no spaces
$fileName = str_replace(' ','_', $fileName);
$thumbName = str_replace('.'.$fileExt, '', $value).'_thumb'.md5(microtime()).'.'.$fileExt;
//make sure the filename has no spaces
$thumbName = str_replace(' ','_', $thumbName);
$dirpad = '../images/'.$linkname.'/'.$albumId.'/';
if(!file_exists($dirpad)){
mkdir($dirpad, 0777);
mkdir($dirpad.'thumb/', 0777);
}
//PHOTO
$pad = $dirpad.$fileName;
createImageByWidth($_FILES['photos']['tmp_name'][$key], $pad, 1000);
//THUMBS
$tPad = $dirpad.'thumb/'.$thumbName;
createImage($_FILES['photos']['tmp_name'][$key], $tPad, 300, 200);
$photoOrder = 1;
//get photoOrder
$orderQuery = mysql_query('SELECT photoOrder FROM '.$linkname.'_photos WHERE albumId = "'.$albumId.'" ORDER by photoOrder DESC LIMIT 1');
if(mysql_num_rows($orderQuery) > 0){
$orderRecord = mysql_fetch_assoc($orderQuery);
$photoOrder = $orderRecord['photoOrder'];
$photoOrder++;
}
$query = 'INSERT INTO '.$linkname.'_photos(albumId, title, description, thumb, filename, timest, photoOrder)
VALUES('.$albumId.',"'.$photoName.'","'.$photoDesc.'", "'.$thumbName.'", "'.$fileName.'", '.$timest.', '.$photoOrder.')';
mysql_query($query);
/* added in v 1.1 */
if($photoOrder == 1){
//if first photo?
mysql_query('UPDATE '.$linkname.'_albums
SET thumb = "'.$thumbName.'"
WHERE id = '.$albumId.'
LIMIT 1');
}
$insertId = mysql_insert_id();
//$statusQuery = mysql_query('INSERT INTO status(itemId, page, active) VALUES("'.$insertId.'", "'.$linkname.'", "1")');
}
else{
$_SESSION['fails']['num']++;
$_SESSION['fails']['output'] .= ($key + 1).' : file extention incorrect (should be jpg/png/gif)<br />';
}
}
else{
$_SESSION['fails']['num']++;
$_SESSION['fails']['output'] .= ($key + 1).' : file too big (max 5mb)<br />';
}
}
}
header('location: ../album'.$_POST['albumId'].'/');
}
/************************************************************************
EDIT PHOTOS
************************************************************************/
function showEditPhotosForm($linkname){
//get text
$siteText = getSiteText();
// ## GET INFO
$photoId = $_GET['id'];
$result = mysql_query('SELECT p.albumId, p.title, p.description, p.thumb
FROM '.$linkname.'_photos AS p
WHERE p.id = '.$photoId.'
LIMIT 1');
$record = mysql_fetch_assoc($result);
$albumId = $record['albumId'];
$title = fromDatabase($record['title']);
$description = fromDatabase($record['description']);
$thumb = '../images/'.$linkname.'/'.$albumId.'/thumb/'.$record['thumb'];
// ## OUTPUT
$formOutput = '';
$formOutput .= '<div class="header-bar top-rounded content-bar">'.$siteText['editPhotos'].' // '.strtolower($title).'</div>';
$formOutput .= '<div class="triple-column-content">';
$formOutput .= '<div class="med-thumb"><img src="'.$thumb.'" alt="'.$title.'" width="105"></div>';
$formOutput .= '<div class="clear"></div><br /><br />';
//form
$formOutput .= '<form action="" method="post" name="addAlbums" enctype="multipart/form-data">';
//title
$formOutput .= '<div class="input-total">';
$formOutput .= '<div class="input-title">';
$formOutput .= $siteText['namePhoto'];
$formOutput .= '</div>';
$formOutput .= '<input type="text" name="photoName" value="'.$title.'"/>';
$formOutput .= '</div>';
$formOutput .= '<div class="clear"></div>';
//description
$formOutput .= '<div class="input-total">';
$formOutput .= '<div class="input-title">';
$formOutput .= $siteText['formInputDesc'];
$formOutput .= '</div>';
$formOutput .= '<input type="text" name="photoDesc" value="'.$description.'" />';
$formOutput .= '</div>';
//clear row
$formOutput .= '<div class="clear"></div>';
//hidden info
$formOutput .= '<input type="hidden" name="photoId" value="'.$photoId.'"/>';
$formOutput .= '<input type="hidden" name="albumId" value="'.$albumId.'"/>';
//submit
$formOutput .= '<input type="submit" name="submitEditPhotos" value="'.$siteText['editPhoto'].'" class="button fully-rounded"/>
<input type="submit" name="back-photos" value="'.$siteText['formBack'].'" class="button fully-rounded"/>';
$formOutput .= '<div class="clear"></div>';
$formOutput .= '</form>';
$formOutput .= '</div>';
return $formOutput;
}
function validateEditPhotos($linkname){
$albumId = $_POST['albumId'];
$photoId = $_POST['photoId'];
$photoName = inDatabase($_POST['photoName']);
$photoDesc = inDatabase($_POST['photoDesc']);
if(!empty($photoId)){
mysql_query('UPDATE '.$linkname.'_photos
SET title = "'.$photoName.'", description="'.$photoDesc.'"
WHERE id = '.$photoId.'
LIMIT 1');
}
header('location: ../../album'.$_POST['albumId'].'/');
}
/************************************************************************
CHECK DATABASE
************************************************************************/
function checkDatabase($linkname){
//auto create tables
$sql="SELECT * FROM ".$linkname."_albums";
$result=@mysql_query($sql);
if (!$result){
mysql_query("
CREATE TABLE `".$linkname."_albums` (
`id` int(8) NOT NULL AUTO_INCREMENT,
`linkname` varchar(64) NOT NULL,
`title` varchar(64) NOT NULL,
`description` text,
`thumb` varchar(128) NOT NULL,
`timest` int(16) NOT NULL,
`albumOrder` int(4) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;");
mysql_query("
CREATE TABLE `".$linkname."_photos` (
`id` int(8) NOT NULL AUTO_INCREMENT,
`albumId` int(8) NOT NULL,
`title` varchar(64) NOT NULL,
`description` text,
`thumb` varchar(128) NOT NULL,
`filename` varchar(128) NOT NULL,
`timest` int(16) NOT NULL,
`photoOrder` int(4) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;");
}
if(!file_exists('../images/'.$linkname)){
mkdir('../images/'.$linkname, 0777);
}
}
/************************************************************************
DELETE SELECTED ?
************************************************************************/
function deleteSelected($linkname){
//get text
$siteText = getSiteText();
if(isset($_POST['option'])){
$numSelected = 0;
foreach($_POST['option'] as $key => $itemId){
if(isset($itemId)){
$query = 'SELECT id, linkname, title, thumb FROM '.$linkname.'_albums WHERE id ="'.$itemId.'"';
$result = mysql_query($query);
$record = mysql_fetch_assoc($result);
$albumId = $record['id'];
$albumLinkname = $record['linkname'];
$trimThumb = trim($record['thumb']);
if(!empty($trimThumb) && $trimThumb != ""){
$thumb = '../images/'.$linkname.'/'.$albumId.'/thumb/'.$record['thumb'];
}
else{
$thumb = './images/structure/nophotos.jpg';
}
$arr['id'][$numSelected] = $itemId;
$arr['image'][$numSelected] = $thumb;
$arr['name'][$numSelected] = fromDatabase($record['title']);
$numSelected++;
}
}
$output = '';
$output .= '<div class="triple-column-container">';
$output .= '<div class="header-bar top-rounded content-bar">'.$siteText['deleteSelected'].'</div>';
$output .= '<div class="triple-column-content">';
$output .= '<form action="" method="post">';
$output .= $siteText['areYouSureDelete'].'<br /><br/>';
//thumbs
$colCount = 0;
$output .= '<div class="med-thumb-row">';
for($i=0;$i<$numSelected;$i++){
if($colCount == 0 && $i != 0){
$output .= '<div class="clear"></div>';
$output .= '</div>';
$output .= '<div class="med-thumb-row">';
}
$output .= '<div class="med-thumb"><img src="'.$arr['image'][$i].'" alt="'.$arr['name'][$i].'" /></div>';
$colCount++;
if($colCount == 6){
$colCount = 0;
}
}
$output .= '</div>';
$output .= '<div class="clear"></div>';
$output .= '<br /><br/>';
for($i=0;$i<$numSelected;$i++){
$output .= '<input type="hidden" name="idArray[]" value="'.$arr['id'][$i].'" />';
}
$output .= '<input type="submit" name="moveSelectedToTrash" value="'.$siteText['formBtnYes'].'" class="button fully-rounded" /> ';
$output .= '<input type="submit" name="back" value="'.$siteText['formBtnNo'].'" class="button fully-rounded" />';
$output .= '</form>';
$output .= '</div>';
$output .= '</div>';
return $output;
}
else{
header('location: ./');
}
}
function deleteSelectedPhotos($linkname){
//get text
$siteText = getSiteText();
if(isset($_POST['option'])){
$numSelected = 0;
foreach($_POST['option'] as $key => $itemId){
if(isset($itemId)){
$query = 'SELECT a.id, a.linkname, a.title, p.thumb
FROM '.$linkname.'_photos AS p,'.$linkname.'_albums AS a
WHERE p.id ="'.$itemId.'"
AND a.id = p.albumId';
$result = mysql_query($query);
$record = mysql_fetch_assoc($result);
$albumLinkname = $record['linkname'];
$albumId = $record['id'];
$thumb = '../images/'.$linkname.'/'.$albumId.'/thumb/'.$record['thumb'];
$arr['id'][$numSelected] = $itemId;
$arr['image'][$numSelected] = $thumb;
$arr['name'][$numSelected] = fromDatabase($record['title']);
$numSelected++;
}
}
$output = '';
$output .= '<div class="triple-column-container">';
$output .= '<div class="header-bar top-rounded content-bar">'.$siteText['albums'].' // '.$siteText['deleteSelected'].'</div>';
$output .= '<div class="triple-column-content">';
$output .= '<form action="" method="post">';
$output .= 'Are you sure you want to delete this ';
$numSelected > 1 ? $output .= $numSelected.' photos' : $output .= $numSelected.' photo';
$output .= '?<br />
You can’t undo this action!<br/><br/>';
//thumbs
$colCount = 0;
$output .= '<div class="med-thumb-row">';
for($i=0;$i<$numSelected;$i++){
if($colCount == 0 && $i != 0){
$output .= '<div class="clear"></div>';
$output .= '</div>';
$output .= '<div class="med-thumb-row">';
}
$output .= '<div class="med-thumb"><img src="'.$arr['image'][$i].'" alt="'.$arr['name'][$i].'" /></div>';
$colCount++;
if($colCount == 6){
$colCount = 0;
}
}
$output .= '</div>';
$output .= '<div class="clear"></div>';
$output .= '<br /><br/>';
for($i=0;$i<$numSelected;$i++){
$output .= '<input type="hidden" name="idArray[]" value="'.$arr['id'][$i].'" />';
}
$output .= '<input type="submit" name="moveSelectedPhotosToTrash" value="'.$siteText['formBtnYes'].'" class="button fully-rounded" /> ';
$output .= '<input type="submit" name="back" value="'.$siteText['formBtnNo'].'" class="button fully-rounded" />';
$output .= '</form>';
$output .= '</div>';
$output .= '</div>';
return $output;
}
else{
header('location: ./');
}
}
/************************************************************************
MOVE TO TRASH
************************************************************************/
function moveSelectedToTrash($linkname){
foreach($_POST['idArray'] as $key => $itemId){
$updateQuery = 'UPDATE status SET active="0" WHERE page="'.$linkname.'" AND itemId="'.$itemId.'";';
mysql_query($updateQuery);
}
header('location: ../');
}
function moveSelectedPhotosToTrash($linkname){
foreach($_POST['idArray'] as $key => $itemId){
$query = 'SELECT a.linkname, a.thumb AS albumThumb, a.title, p.thumb, p.filename, p.albumId, p.photoOrder
FROM '.$linkname.'_photos AS p,'.$linkname.'_albums AS a
WHERE p.id ="'.$itemId.'"
AND a.id = p.albumId';
$result = mysql_query($query);
$record = mysql_fetch_assoc($result);
$albumLinkname = $record['linkname'];
$albumId = $record['albumId'];
$currentOrder = $record['photoOrder'];
$photoThumb = $record['thumb'];
$photoFilename = $record['filename'];
//SET ORDER
//set everything with a larger ordernr to order--
$orderresult = mysql_query('SELECT id, photoOrder FROM '.$linkname.'_photos WHERE photoOrder > "'.$currentOrder.'" AND albumId="'.$albumId.'"');
while($orderrecord = mysql_fetch_assoc($orderresult)){
$thisId = $orderrecord['id'];
$thisOrder = $orderrecord['photoOrder'];
$thisOrder--;
$updateQuery = 'UPDATE '.$linkname.'_photos SET photoOrder = "'.$thisOrder.'" WHERE id="'.$thisId.'" LIMIT 1;';
mysql_query($updateQuery);
}
//delete from DB
$deleteQuery1 = 'DELETE FROM '.$linkname.'_photos WHERE id="'.$itemId.'" LIMIT 1;';
mysql_query($deleteQuery1);
//SET NEW THUMB (added in v 1.1)
if($record['thumb'] == $record['albumThumb']){
//set first photo al thumbnail
$firstResult = mysql_query('SELECT thumb FROM '.$linkname.'_photos WHERE photoOrder = 1');
if(mysql_num_rows($firstResult) > 0){
$firstRecord = mysql_fetch_assoc($firstResult);
$newAlbumthumb = $firstRecord['thumb'];
}
else{
$newAlbumthumb = '';
}
mysql_query('UPDATE '.$linkname.'_albums
SET thumb = "'.$newAlbumthumb.'"
WHERE id = '.$albumId.'
LIMIT 1');
}
//delete file
if(is_file('../images/'.$linkname.'/'.$albumId.'/thumb/'.$photoThumb)){
unlink('../images/'.$linkname.'/'.$albumId.'/thumb/'.$photoThumb);
}
else{
echo 'THUMB: ../images/'.$linkname.'/'.$albumId.'/thumb/'.$photoThumb;
}
if(is_file('../images/'.$linkname.'/'.$albumId.'/'.$photoFilename)){
unlink('../images/'.$linkname.'/'.$albumId.'/'.$photoFilename);
}
else{
echo 'FILE: ../images/'.$linkname.'/'.$albumId.'/'.$photoFilename;
}
}
header('location: ../album'.$albumId.'/');
}
function movePhotos($dir, $albumId, $itemId, $table, $orderName = 'itemOrder', $pageName = ''){
//get country and current order
$result = mysql_query('SELECT '.$orderName.' FROM '.$table.' WHERE id="'.$itemId.'" LIMIT 1');
$record = mysql_fetch_assoc($result);
$currentOrder = $record[$orderName];
$tempOrder = 1234;
$dir == 'up' ? $newOrder = (int)$currentOrder+1 : $newOrder = (int)$currentOrder-1;
//move this itemId one up or down
//set current to temp
mysql_query('UPDATE '.$table.' SET '.$orderName.' = "'.$tempOrder.'" WHERE id="'.$itemId.'" AND albumId = "'.$albumId.'" LIMIT 1;');
//set newOrder to currentOrder
mysql_query('UPDATE '.$table.' SET '.$orderName.' = "'.$currentOrder.'" WHERE '.$orderName.'="'.$newOrder.'" AND albumId = "'.$albumId.'" LIMIT 1;');
//reset temp to newOrder
mysql_query('UPDATE '.$table.' SET '.$orderName.' = "'.$newOrder.'" WHERE '.$orderName.'="'.$tempOrder.'" AND albumId = "'.$albumId.'" LIMIT 1;');
if(empty($pageName)){
$pageName = $table;
}
header('location: ./');
}
function correctAlbumOrderAfterDelete($table){
foreach($_POST['idArray'] as $key => $itemId){
//get order of this item
$result = mysql_query('SELECT albumOrder FROM '.$table.'_albums WHERE id="'.$itemId.'" LIMIT 1');
$record = mysql_fetch_assoc($result);
$currentOrder = $record['albumOrder'];
//set order of this item to zero (because its sort of deleted)
mysql_query('UPDATE '.$table.'_albums SET albumOrder = "0" WHERE id="'.$itemId.'" LIMIT 1;');
//set everything with a larger ordernr to order--
$result = mysql_query('SELECT id, albumOrder FROM '.$table.'_albums WHERE albumOrder > "'.$currentOrder.'"');
while($record = mysql_fetch_assoc($result)){
$thisId = $record['id'];
$thisOrder = $record['albumOrder'];
$thisOrder--;
$updateQuery = 'UPDATE '.$table.'_albums SET albumOrder = "'.$thisOrder.'" WHERE id="'.$thisId.'" LIMIT 1;';
mysql_query($updateQuery);
}
}
header('location: ./');
}
/*
function showChangeOrder($linkname, $pageLabel){
//get text
$siteText = getSiteText();
$output = '';
$output .= getToolmanSource($linkname);
// header
$output .= '<div class="header-bar top-rounded content-bar">'.strtolower($pageLabel).' // '.strtolower($siteText['changeOrder']).'</div>';
$output .= '<div class="triple-column-content">';
$output .= $siteText['changeOrderHelp'];
//Get Info for the list
$query = 'SELECT a.id, a.linkname, a.title, a.thumb, a.albumOrder
FROM '.$linkname.'_albums AS a, status AS s
WHERE s.page="'.$linkname.'"
AND s.itemId = a.id
AND s.active=1
ORDER BY a.albumOrder DESC';
$result = mysql_query($query );
//start list
$output .= '<ul id="'.$linkname.'_boxes" class="changeOrderList">';
while($record = mysql_fetch_assoc($result)){
$itemId = $record['id'];
$title = fromDatabase($record['title']);
$order = $record['albumOrder'];
//add list item id = table-fieldname-id
$output .= '<li id="albumOrder|'.$linkname.'_albums|'.$itemId.'">'.$title.'</li>';
}
//close list
$output .= '</ul>';
//save
$output .= '<input type="button" value="'.$siteText['save'].'" onclick="junkdrawer.inspectListOrder(\''.$linkname.'_boxes\',\'./pages/'.$linkname.'/\')" class="button fully-rounded"/>';
$output .= '</div>';
return $output;
}*/
//CHANGE ORDER BY DAVID WALSH
//http://davidwalsh.name/mootools-drag-drop
function showChangeOrder($linkname, $pageLabel){
//get text
$siteText = getSiteText();
$output = '';
// header
$output .= '<div class="header-bar top-rounded content-bar">'.strtolower($pageLabel).' // '.strtolower($siteText['changeOrder']).'</div>';
$output .= '<div class="triple-column-content">';
$output .= $siteText['changeOrderHelp'];
$output .= '<form action="'.$_SERVER['REQUEST_URI'].'" id="dd-form" name="dd-form" method="post">';
$output .= '<ul id="sortable-list">';
$order = array();
$count = 1;
//Get Info for the list
$query = 'SELECT a.id, a.linkname, a.title, a.thumb, a.albumOrder
FROM '.$linkname.'_albums AS a, status AS s
WHERE s.page="'.$linkname.'"
AND s.itemId = a.id
AND s.active=1
ORDER BY a.albumOrder DESC';
$result = mysql_query($query );
$result = mysql_query($query );
while($item = mysql_fetch_assoc($result))
{
$output .= '<li title="'.$item['id'].'">'.$item['title'].'</li>';
$order[] = $item['albumOrder'];
}
$output .= '</ul>';
$output .= '<br />';
$output .= '<input type="hidden" name="sort_order" id="sort_order" value="'.implode(',',$order).'" />';
$output .= '<input type="hidden" name="linkname" value="'.$linkname.'" />';
$output .= '<input type="submit" name="do_submit_albums" value="Save" class="button fully-rounded" />';
$output .= '</form>';
$output .= '</div>';
$output .= '<script type="text/javascript"> initSortableList(); </script>';
return $output;
}
function sbmChangeAlbumOrder(){
/* split the value of the sortation */
$ids = explode(',',$_POST['sort_order']);
/* run the update query for each id */
foreach($ids as $index=>$id) {
$id = (int) $id;
if($id != '') {
$linkname = $_POST['linkname'];
mysql_query('UPDATE '.$linkname.'_albums SET albumOrder = '.($index + 1).' WHERE id = '.$id.' LIMIT 1');
}
}
/* now what? */
// if($_POST['byajax']) { die(); } else { $message = 'Sortation has been saved.'; }
header('location: ./');
}
/*
function showChangeOrderPhotos($linkname, $pageLabel){
//get text
$siteText = getSiteText();
$output = '';
$output .= getToolmanSource($linkname);
//get albumId
$albumId = substr($_GET['action'],5);
//get albumName
$query = 'SELECT title FROM '.$linkname.'_albums WHERE id='.$albumId.' LIMIT 1';
$result = mysql_query($query);
$record = mysql_fetch_assoc($result);
$albumTitle = $record['title'];
//header
$output .= '<div class="header-bar top-rounded content-bar">'.strtolower($pageLabel).' // '.$siteText['albums'].' // '.strtolower($albumTitle).' // '.strtolower($siteText['changeOrder']).'</div>';
$output .= '<div class="triple-column-content">';
$output .= $siteText['changeOrderHelp'];
//Get Info for the list
$query = 'SELECT a.id AS albumId, p.id AS photoId, p.title AS photoName, p.thumb, p.description, a.linkname AS albumName, p.photoOrder
FROM '.$linkname.'_photos AS p,'.$linkname.'_albums AS a
WHERE p.albumId = '.$albumId.'
AND p.albumId = a.id
ORDER BY p.photoOrder DESC';
$result = mysql_query($query );
//start list
$output .= '<ul id="'.$linkname.'_boxes" class="changeOrderThumb">';
while($record = mysql_fetch_assoc($result)){
$photoId = $record['photoId'];
$title = fromDatabase($record['photoName']);
$order = $record['photoOrder'];
$thumb = '../images/'.$linkname.'/'.$albumId.'/thumb/'.$record['thumb'];
//add list item id = table-fieldname-id
$output .= '<li id="photoOrder|'.$linkname.'_photos|'.$photoId.'"><img src="'.$thumb.'" alt="photo-'.$title.'" class="med-thumb"/></li>';
}
//close list
$output .= '</ul>';
$output .= '<div class="clear"></div>';
//save
$output .= '<input type="button" value="'.$siteText['save'].'" onclick="junkdrawer.inspectListOrder(\''.$linkname.'_boxes\',\'./pages/'.$linkname.'/album'.$albumId.'/\')" class="button fully-rounded"/>';
$output .= '</div>';
return $output;
}
*/
function showChangeOrderPhotos($linkname, $pageLabel){
//get text
$siteText = getSiteText();
//get albumId
$albumId = substr($_GET['action'],5);
$output = '';
// header
$output .= '<div class="header-bar top-rounded content-bar">'.strtolower($pageLabel).' // '.strtolower($siteText['changeOrder']).'</div>';
$output .= '<div class="triple-column-content">';
$output .= $siteText['changeOrderHelp'];
$output .= '<form action="'.$_SERVER['REQUEST_URI'].'" id="dd-form" name="dd-form" method="post">';
$output .= '<ul id="sortable-list">';
$order = array();
$count = 1;
//Get Info for the list
$query = 'SELECT a.id AS albumId, p.id AS photoId, p.title AS photoName, p.thumb, p.description, a.linkname AS albumName, p.photoOrder
FROM '.$linkname.'_photos AS p,'.$linkname.'_albums AS a
WHERE p.albumId = '.$albumId.'
AND p.albumId = a.id
ORDER BY p.photoOrder DESC';
$result = mysql_query($query );
while($item = mysql_fetch_assoc($result))
{
$thumb = '../images/'.$linkname.'/'.$albumId.'/thumb/'.$item['thumb'];
$output .= '<li title="'.$item['photoId'].'" class="li-photo"><img src="'.$thumb.'" alt="photo-'.$item['photoId'].'" height="100"/></li>';
$order[] = $item['photoOrder'];
}
$output .= '</ul>';
$output .= '<div class="clear"></div>';
$output .= '<br />';
$output .= '<input type="hidden" name="sort_order" id="sort_order" value="'.implode(',',$order).'" />';
$output .= '<input type="hidden" name="linkname" value="'.$linkname.'" />';
$output .= '<input type="hidden" name="albumId" value="'.$albumId.'" />';
$output .= '<input type="submit" name="do_submit_photos" value="Save" class="button fully-rounded" />';
$output .= '</form>';
$output .= '<script type="text/javascript"> initSortableList(); </script>';
$output .= '</div>';
return $output;
}
function sbmChangePhotosOrder(){
/* split the value of the sortation */
$ids = explode(',',$_POST['sort_order']);
/* run the update query for each id */
foreach($ids as $index=>$id) {
$id = (int) $id;
if($id != '') {
$linkname = $_POST['linkname'];
mysql_query('UPDATE '.$linkname.'_photos SET photoOrder = '.($index + 1).' WHERE id = '.$id.' LIMIT 1');
}
}
$albumId = $_POST['albumId'];
/* now what? */
// if($_POST['byajax']) { die(); } else { $message = 'Sortation has been saved.'; }
header('location: ./');
}
/* added in v 1.1 */
function setNewAlbumThumb(){
$linkname = $_GET['sub'];
$temp = explode('_',$_GET['action']);
$albumId = $temp[1];
$photoId = $_GET['id'];
$result = mysql_query('SELECT thumb FROM '.$linkname.'_photos WHERE id = '.$photoId.' LIMIT 1');
if(mysql_num_rows($result) > 0){
$record = mysql_fetch_assoc($result);
$thumb = $record['thumb'];
mysql_query('UPDATE '.$linkname.'_albums
SET thumb = "'.$thumb.'"
WHERE id = '.$albumId.'
LIMIT 1');
}
header('location: ../../album'.$albumId);
}
?>