Location: PHPKode > projects > ZZ/OSS Installer > zic-1.1.0dev1/installer/config_components.php
<?php   
    /*
    Copyright (C) 2001-2004 ZZOSS GbR, http://www.zzoss.com

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library 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
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    */
    
    /**
    @version $Id: config_components.php,v 1.3 2004/02/09 18:16:10 ordnas Exp $
    @copyright Copyright &copy; 2001-2004 ZZ/OSS GbR, http://www.zzoss.com
    @license http://opensource.org/licenses/lgpl-license.php GNU Lesser General Public License
    */

	// execute init file
	require_once 'inc/init.php';

    // RMDIR 
    // -------- 
    // removes directory recursively, even if non-empty 
	function zi_rmdir ($dirName) { 
		$d = opendir ($dirName); 
		while($entry = readdir($d)) { 
			if ($entry != "." && $entry != ".." && $entry != "") { 
				if (is_dir($dirName."/".$entry)) { 
					zi_rmdir($dirName."/".$entry); 
				} else { 
					unlink($dirName."/".$entry); 
				} 
			} 
		} 
		closedir($d); 
		rmdir($dirName); 
	} 

	function zi_process()
	{
		// save the parameters for later installations
		$file = 'data/config_components.reg';
		$fp = fopen($file, "w");  
		fputs( $fp, serialize( $_REQUEST ));
		fclose( $fp );
		
		$_REQUEST = zi_default();
		
		// search and replace config files
		
		// compose replace array
		$values = $_REQUEST['ZI_VALUES'];
		if(is_array($values) && count($values)){
		  	foreach($values as $key => $val){
			  	//echo $key.' = '.$val.'<br/>';
			  	$replace_values['{ZI_'.$key.'}'] = htmlspecialchars($val);
			}
		}
		/*
		echo '<pre>';
		print_r($replace);
		echo '</pre>';
		die();
		*/
		
		// clean the data/config directory
		if(is_dir('data/config')){
			zi_rmdir('data/config/');
		}
		mkdir('data/config/', 0777);
		
		// iterate components
		$components = $GLOBALS['ZI_CONFIG']['component'];
		if(is_array($components) && count($components)){
		  	require_once 'ZZOSS_File/Replace.php';
			$replace = new ZZOSS_FileReplace;
		  	foreach($components as $component_name => $component_params){
			  	// compose paths to configuration file
				
				// check if it is the statistics component, obviously, a hack
				if($component_name == 'statistics'){
				  	$config_dist = $component_params['path'].'config/phpOpenTracker.ini.dist';
					$config = 'data/config/phpOpenTracker.ini';
					$replace->file($config_dist);
					$replace->replace($replace_values);
					$replace->writeout($config);
					
					$copy_src = $component_params['path'].'config/hosts.ini';
					$copy_dest = 'data/config/hosts.ini';
					copy($copy_src, $copy_dest);
					$copy_src = $component_params['path'].'config/operating_systems.ini';
					$copy_dest = 'data/config/operating_systems.ini';
					copy($copy_src, $copy_dest);
					$copy_src = $component_params['path'].'config/user_agents.ini';
					$copy_dest = 'data/config/user_agents.ini';
					copy($copy_src, $copy_dest);
				}
				
				$config_dist = $component_params['path'].'config/config.xml-dist';
				$config = 'data/config/'.$component_name.'.xml';
				
			  	$replace->file($config_dist);
				$replace->replace($replace_values);
				$replace->writeout($config);
			}
		}
	}

	// assign default values
	function zi_default()
	{
	  	$_REQUEST['ZI_VALUES'] = array();
		
	  	// get global connector values
		$file = 'data/config_components.reg';
		if(file_exists($file)){
		  	// create serialized default data
			$fp = fopen($file,"r");
			$ser = fread ($fp, filesize ($file));  
			fclose($fp);
			$params = unserialize($ser);
			$_REQUEST['ZI_VALUES'] = $_REQUEST['ZI_VALUES'] + $params['ZI_VALUES'];
			//copy('data/config_components.reg-dist', 'data/config_components.reg');
		} else {
		  	$_REQUEST['ZI_VALUES']['default_api'] = 'ZZOSS::Repository::PEAR::DB';
			$_REQUEST['ZI_VALUES']['default_authorization_api'] = 'ZZOSS::Authorization::PEAR::DB';
		}
		/*
	  	$fp = fopen($file,"r");
		$ser = fread ($fp, filesize ($file));  
		fclose($fp);
		$params = unserialize($ser);
		$_REQUEST['ZI_VALUES'] = $_REQUEST['ZI_VALUES'] + $params['ZI_VALUES'];
		*/
	  	// get global paths values
		$file = 'data/application_settings.reg';
		if(file_exists($file)){
		  	$fp = fopen($file,"r");
			$ser = fread ($fp, filesize ($file));  
			fclose($fp);
			$params = unserialize($ser);
			$_REQUEST['ZI_VALUES'] = $_REQUEST['ZI_VALUES'] + $params['ZI_VALUES'];
		}

	  	// get global connector values
		$file = 'data/config_global_connector.reg';
		if(file_exists($file)){
		  	$fp = fopen($file,"r");
			$ser = fread ($fp, filesize ($file));  
			fclose($fp);
			$params = unserialize($ser);
			$_REQUEST['ZI_VALUES'] = $_REQUEST['ZI_VALUES'] + $params['ZI_VALUES'];
		}

		//$_REQUEST['ZI_VALUES'] = $global_paths['ZI_VALUES'] + $global_connector['ZI_VALUES'] + $config_components['ZI_VALUES'];
		/*
		echo '<pre>';
		print_r($_REQUEST);
		echo '</pre>';
		*/
		return $_REQUEST;
	}
	
	// read installation type data
	$file = 'data/installation_type.reg';
	if(file_exists($file)){
	  	$fp = fopen($file,"r");
		$ser = fread ($fp, filesize ($file));  
		fclose($fp);  
		$installation_type =& unserialize($ser);
		//print_r($installation_type);
		$installation_type = $installation_type['ZI_VALUES'];
		//print_r($installation_type);
		//die();
	}
	
  	// we ask for a new installer admin username and password
	include 'themes/'.$GLOBALS['ZI']['theme'].'/header.php';
?>
<a name="top"></a>
<h1>Advanced Configuration</h1>
<p>Please provide the parameters for the components. The parameters displayed fit a basic 
installation with one database.</p>
<?php
	// initialise widget class of installer
	require_once 'ZZOSS_Installer/Widget.php';
	$zi_widget = new ZZOSS_InstallerWidget;
	if(isset($zi_errors)){
        $zi_widget->setErrors($zi_errors);
    }
	
	$components = $GLOBALS['ZI_CONFIG']['component'];
	// iterate components for installation
	if(is_array($components) && count($components)){
	  	foreach($components as $component_name => $component_params){
		  	// include the configuration form
			$component_form = $component_params['path'].'configuration.php';
			//echo $component_form.'<br/>';
		  	if(file_exists($component_form)){
			  	$zi_widget->setHelpPath($component_params['path'].'help/');
				//echo 'exists';
				?>
				<hr size="1" noshade/>
				<b><a name="<?php echo $component_name; ?>"></a><?php echo str_replace('_', ' ', $component_name); ?></b><br/><br/>
				<table border="0" cellspacing="0" cellpadding="4" align="left">
				<?php
		  	  	include_once $component_form;
				?>
				</table><br clear="all"/>
				<p align="right"><a href="#top">up</a>&nbsp;|&nbsp;<a href="#bottom">down</a></p>
				<?php
			}
		}
	}
?>
<a name="bottom"></a>
<?php
if($installation_type["type"]=="change_components_config") {
?>
<!-- where we redirect after data processing -->
<input type="hidden" name="ZI_LOCATION_NEXT" value="../">
<?php } else { ?>
<!-- where we redirect after data processing -->
<input type="hidden" name="ZI_LOCATION_NEXT" value="exec.php">
<?php } ?>
<!-- where we go back -->
<input type="hidden" name="ZI_LOCATION_BACK" value="config_global_paths.php">

<?php
	include 'themes/'.$GLOBALS['ZI']['theme'].'/footer.php';
?>
Return current item: ZZ/OSS Installer