<?php
/*
 * Smarty plugin
 * -------------------------------------------------------------
 * File:     function.installer.php
 * Type:     Adminmenu
 * Name:     Installer
 * Owner:	 Michael Ruhl
 * -------------------------------------------------------------
 */
function smarty_function_admin_installer($params, &$smarty)
{

	if(!isset($_SESSION['addons']))
	{
		$addons = array();
		
		$ordner = BASE_DIR . "/addons/";
		{ 
		$handle = opendir($ordner); 
		while ($file = readdir ($handle)) { 
				if($file{0} != '.') {
						if(is_dir($ordner.'/'.$file)) { 
								$folderArray[] = $file; 
						} 
				} 
		} 
		closedir($handle); 
	
		if(isset($folderArray)) { 
				asort($folderArray); 
				foreach($folderArray as $row) { 
					unset($folderArray2);
					if(is_file(BASE_DIR . "/addons/" . $row . "/addon.". $row .".php")) array_push($addons, $row);
				} 
			} 
		}
		
		$_SESSION['addons'] = implode(",", $addons);

	}
	else $addons = explode(",", $_SESSION['addons']);


	foreach($addons as $add)
	{
		$sql = $GLOBALS['db']->Query("SELECT Id FROM " . PREFIX . "_installer WHERE Ordner = '".$add."'");
		$num = $sql->numrows();
		
		if(file_exists(BASE_DIR . "/addons/" . $add . "/templates/main.tpl") and $num == 1)
		{
			include_once(BASE_DIR ."/addons/".$add."/addon.".$add.".php");
			
			$lang = file_exists(BASE_DIR . "/addons/".$add."/lang/".$_SESSION['admin_lang'].".txt") ? $_SESSION['admin_lang'] : $modul['slang'];
			
			$GLOBALS['tmpl']->config_load(BASE_DIR . "/addons/".$add."/lang/".$lang.".txt");
			$config_vars = $GLOBALS['tmpl']->get_config_vars();
			
			$GLOBALS['tmpl']->assign("config_vars", $config_vars); 
			$GLOBALS['tmpl']->assign("imgpath_mod", "http://".$_SERVER['HTTP_HOST'].str_replace("admin/index.php","",$_SERVER['PHP_SELF'])."addons/".$add."/images"); 
			
			echo $GLOBALS['tmpl']->fetch(BASE_DIR . "/addons/" . $add . "/templates/main.tpl");
		
		}	
	} 
	
		   
}

?>