<?php
#-------------------------------------------------------------------------
# Album - Photo Albums
# Version 1.11
# This module allows you to add photo albums to your website
# maintained by Fernando Morgado AKA Jo Morg
# since 2013
#-------------------------------------------------------------------------
#
# Previously maintained by:
# dam & Elijah Lofgren <elijahlofgren@elijahlofgren.com>
#
#-------------------------------------------------------------------------
#
# Album is a CMS Made Simple module that enables the web developer to 
# add photo albums to a website
#
#-------------------------------------------------------------------------
# BEGIN_LICENSE
#-------------------------------------------------------------------------
# This file is part of Album
# Album program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# Album program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# Or read it online: http://www.gnu.org/licenses/licenses.html#GPL
#
#-------------------------------------------------------------------------
# END_LICENSE
#-------------------------------------------------------------------------
if( !defined('CMS_VERSION') ) exit;
if(! $this->CheckPermission( 'Use Album' ) ) exit;

$pictureid = (isset($params['pictureid']) ? $params['pictureid'] : '');
$albumid = (isset($params['albumid']) ? $params['albumid'] : '');

if ($pictureid == '' && $albumid=='')
	$this->Redirect($id, 'defaultadmin', $returnid);

if ($albumid=='' && (isset($params['cancel']) || isset($params['filename'])))
{
	$albumid = $this->GetAlbumId($pictureid);
}

if (isset($params['cancel']))
{
	if (isset($albumid))
		$this->Redirect($id, 'editalbum', $returnid,array('albumid'=>$albumid));
	else
		$this->Redirect($id, 'defaultadmin', $returnid);
}


if (isset($params['filename'])) 
{
	$newthumb = $params['filename'];

	if ($pictureid!='')
	{
		$query = 'UPDATE '.cms_db_prefix().'module_album_pictures SET thumbnail_path=? WHERE picture_id = ?';
		$db->Execute($query, array($newthumb,$pictureid));
	}
	elseif ($albumid!='')
	{
		if ($params['filename']!='')
		{
			$query = 'UPDATE '.cms_db_prefix().'module_album_albums SET thumbnail_path=? WHERE album_id = ?';
			$db->Execute($query, array($newthumb,$albumid));
		}
		else
		{
			$query = 'UPDATE '.cms_db_prefix().'module_album_albums SET thumbnail_path=NULL WHERE album_id = ?';
			$db->Execute($query, array($albumid));
		}
	}

	if (isset($albumid))
		$this->Redirect($id, 'editalbum', $returnid,array('albumid'=>$albumid));
	else
		$this->Redirect($id, 'defaultadmin', $returnid);
}
	
include dirname(__FILE__).'/lib.browsepictures.php';


?>