<?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;

$fieldName=$id.'input_browse';

$themeObject = $gCms->variables['admintheme'];	


if (!isset ($_FILES[$fieldName]) || !isset ($_FILES)
	|| !is_array ($_FILES[$fieldName]) || !$_FILES[$fieldName]['name'])
{
	// echo $themeObject->ShowErrors($this->Lang('error_nofilesuploaded'));
	echo '<div class="pageerrorcontainer">'.$this->Lang('error_nofilesuploaded').'</div>';
//	$this->DisplayErrorPage( $id, $params, $returnid, 
//		$this->Ling('error_nofilesuploaded'));
	return;
}
else
{
	$file = $_FILES[$fieldName];
	$curdir = (isset($params['curdir']) ? $params['curdir'] : '');
	$uploaddir = $config['image_uploads_path'].$curdir;
	$uploadfile = $uploaddir.'/'. $file['name'];
	
	if (!@move_uploaded_file($file['tmp_name'], $uploadfile))
	{
		// echo $themeObject->ShowErrors('<p class="error">'.$this->Lang('error_nofilesuploaded').'</p>');
		echo '<div class="pageerrorcontainer">'.$this->Lang('error_nofilesuploaded').'</div>';
		//$this->DisplayErrorPage( $id, $params, $returnid,$this->Lang('error_nofilesuploaded'));
		return;
	}
	else
	{
		chmod($uploadfile, 0644);
		$params = array('tab_message' => 'pictureuploaded', 'albumid' => $params['albumid'], 'curdir' => $params['curdir'], 'dir' => $params['dir']);
		$this->Redirect($id, 'addpicture', '', $params);	
			//	header ('Location: '.$params['url']);
			//	$this->Redirect( $id, 'defaultadmin', $returnid );
//	echo $params['url'];
	}
	
}


//$this->Redirect($id, 'defaultadmin', $returnid);
?>
