<?php
// $Id: language_installer.php,v 1.5 2003/11/11 00:17:32 saka_car Exp $
/**
* Language installer event handler
* @package Mambo Open Source
* @Copyright (C) 2000 - 2003 Miro International Pty Ltd
* @ All rights reserved
* @ Mambo Open Source is Free Software
* @ Released under GNU/GPL License: http://www.gnu.org/copyleft/gpl.html
* @version $Revision: 1.5 $
**/

// ensure this file is being included by a parent file
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

require_once($mosConfig_absolute_path . "/administrator/classes/html/HTML_installer.php");
require_once($mosConfig_absolute_path . "/administrator/includes/installer_common.php");
// Extract functions
require_once($mosConfig_absolute_path . "/administrator/classes/pclzip.lib.php");
require_once($mosConfig_absolute_path . "/administrator/classes/pclerror.lib.php");
require_once($mosConfig_absolute_path . "/administrator/classes/pcltrace.lib.php");
require_once($mosConfig_absolute_path . "/administrator/classes/pcltar.lib.php");

$task		= mosGetParam( $_REQUEST, "task", "" );

// Check that the zlib is available
if(!extension_loaded('zlib'))
{
	HTML_installer::showInstallMessage("The installer can't continue before zlib is installed",'Installer - Error',$option);
	exit();
}


switch($task)
{
	case "uploadfile":
	if(!isset($userfile) || $userfile == "")
	{
		HTML_installer::showInstallMessage('No file selected','Upload new language - error',$option);
		exit();
	}
	$resultdir = uploadFile($userfile,$userfile_name,$option,$msg);
	if(! $resultdir === false)
	{
		$installer = new mosInstallerLanguage($userfile_name);
		if(!$installer->install())
		{
			HTML_installer::showInstallMessage($installer->getError(),'Upload new language - error', $option);
			cleanupInstall($userfile_name,$installer->unpackDir());
			exit();
		}
		cleanupInstall($userfile_name,$installer->unpackDir());
	} else {
		HTML_installer::showInstallMessage("Installation failed, please make sure that all directories have required permissions.",'Upload new language -  error',$option);
		exit();
	}
	mosRedirect("index2.php?option=com_languages");
	break;

	default:
	//showInstalledModules($option);
	HTML_installer::showInstallForm('Upload new language',$option,dirname(__FILE__));
	break;
}

function showInstalledModules($_option)
{
	global $database;

	$database->setQuery( "SELECT * FROM #__modules WHERE module LIKE 'mod_%' ORDER BY module" );
	$res = $database->query();
	$rows = $database->loadObjectList();
	HTML_installer::showInstalledModules($rows, $_option);

}

?>
