Location: PHPKode > projects > Netautor Professional > netautor/napro4/admin/install/install_pck_5.php
<?php 
/* +----------------------------------------------------------------------+
   | Netautor Professional Application Server                             |
   +----------------------------------------------------------------------+
   | Copyright (C) 1998-2005 digiconcept GmbH. <www.digiconcept.net>      |
   +----------------------------------------------------------------------+
   | This file is subject to license, that is bundled with this package   |
   | in the file LICENSE.TXT, and is available at through the             |
   | world-wide-web at http://www.netautor.com/license/                   |
   |                                                                      |
   | If you did not receive a copy of the license and are unable to       |
   | obtain it through the world-wide-web, please send a note to          |
   | hide@address.com so we can mail you a copy.                      |
   +----------------------------------------------------------------------+
   | Authors: Stefan Rottensteiner <hide@address.com>    |
   |          Marek  Kadziela      <hide@address.com>	      |
   |          Gregor Wollner                                              |
   |          Helli  Kleinhans											  |
   +----------------------------------------------------------------------+ */

/**
 * Install given package(s)
 *
 * @author 	Stefan Rottensteiner
 * @package setup
 * @version	$Revision: 1.10 $
 */

if (empty($_GET['SETUP_CHECK']) && empty($_POST['SETUP_CHECK']) && empty($SETUP_CHECK))
{
	?>
	<html>
	<body>
		<script language="JavaScript" type="text/javascript">	
		if (window.parent.opener)
		{
			window.parent.opener.document.location.href="setup.html";
			window.close();
		}
		else
		{
			document.location.href="setup.html"
		}	
		</script>
	</body>
	</html>
	<?php 
	exit();
}

	includeNaPro	('array');

	if (!empty($_GET['whichone'])) $whichone = $_GET['whichone'];

	if (isset($whichone) && !is_array($whichone)) $whichone=array($whichone);
?>
	<script language="JavaScript" type="text/javascript">
	<!--
	setBusy(true);
	//-->
	</script>

	<table width="700" border="0" align="center" class="bgwindow700">
		<tr>
			<td valign="top" class="head" width="694">
				<img src="../../grafik/pixel.gif" width="694" height="7" border="0" ><br>
				<?php echo ($SETUP_LANGUAGE_TEXT['package']['title']);?><br>
				<img src="../../grafik/pixel.gif" alt="" width="694" height="1" hspace="0" vspace="0" border="0"><br>
			</td>
		</tr>
		<tr>
			<td><?php 
		ob_end_flush();
		flush();
		$connected = $sql_world->sql_connect();
		if ($connected)
		{
			?>
				<span class="textgreen"><?php echo $SETUP_LANGUAGE_TEXT['setup_test_3']['db_okay']; ?></span>
			<?php 
		}
		else
		{
			?>
				<span class="textred"><?php echo $SETUP_LANGUAGE_TEXT['setup_test_3']['db_error']; ?></span>
			<?php 
		}
		$sql_world->sql_disconnect();

 		if (!$connected)
		{
				?>
			</td>
		</tr>
	</table>
	<img src="../../grafik/bgwindow_482_stop.gif" width="700" height="14"><br>
	<br>
	<br>
	</form>
</body>
</html>
				<?php 
				exit();
		}
		?>
			</td>
		</tr>
	</table>
	<img src="../../grafik/bgwindow_482_stop.gif" width="700" height="14"><br>
<?php 
	flush();
	error_reporting(E_ALL);
	$base_path 		= $DC_ENV->installpath.'admin/install/packages/';
	foreach ($whichone as $package_number => $package_name)
	{

		$pck_files 	= array();
		$pck_tables	= array();
		$pck_views 	= array();
		$pck_data  	= array();
		$pck_dirs	= array();
		$pck_files	= array();

		$package_file 	= $base_path.$package_name.'.pck';

?>	
	<table width="700" border="0" align="center" class="bgwindow700">
		<tr>
			<td valign="top" class="head" width="694">
				<img src="../../grafik/pixel.gif" width="694" height="7" border="0" ><br>
				<?php echo ($SETUP_LANGUAGE_TEXT['package']['read_pck']);?>
			</td>
		</tr>
			<?php 
			if (!file_exists($package_file))
			{
				?>
		<tr>
			<td valign="top" >				
				<span class="textred">&nbsp;<?php echo $SETUP_LANGUAGE_TEXT['package']['read_pck_failed']; ?> [<?php echo $package_name; ?>]</span>
			</td>
		</tr>
	</table>
	<img src="../../grafik/bgwindow_482_stop.gif" width="700" height="14"><br>
				<?php 
				continue;
			}

		include($package_file);	
	?>
	</table>
	<img src="../../grafik/bgwindow_482_stop.gif" width="700" height="14"><br>	
	
	<!-- Tabellen anlegen -->
	<table width="700" border="0" align="center" class="bgwindow700" style="background-repeat: repeat-y;">
		<tr>
			<td valign="top" class="head" width="694" colspan="2">
				<img src="../../grafik/pixel.gif" width="694" height="7" border="0" ><br>
				<?php echo ($SETUP_LANGUAGE_TEXT['package']['create_table']);?><br>
			</td>
		</tr>
		<?php 
			if (empty($pck_tables))
			{
				?>
		<tr>
			<td valign="top" class="textgreen" colspan="2">				
				<?php echo ($SETUP_LANGUAGE_TEXT['package']['no_tables']);?><br>
			</td>
		<tr>
				<?php
			}
			else
			{
				foreach($pck_tables as $i => $table_path)
				{
		?>
		<tr>
		<?php 
					flush();
					@set_time_limit(0);
					echo "<script>setTitle('Table ".($i+1)."/".count($pck_tables)."');</script>";
		  ?><td valign="top" class="text" width="10%">
		  		<?php echo sprintf('%04d. ',($i+1));?><br>
			</td>
			<?php 
			if (file_exists($base_path."$package_name/".$table_path))
			{
				
				$table = array();
				include ($base_path."$package_name/".$table_path);
				if (empty($table['name']))
				{
				?>
			<td valign="top" class="text">
				<span class="textred"><?php echo $SETUP_LANGUAGE_TEXT['package']['table_nf']." [$table_path]"; ?><br></span>
			</td>
				<?php 
				}
				else
				{
					$error = $sql_world->sql_create_table($table);
					if (!$sql_world->errnr)
					{
						$sql_world->ensure_table_def($table['name'],true);
				?>
			<td valign="top" class="text">
				<span class="texgreen"><?php echo $SETUP_LANGUAGE_TEXT['package']['create_table_okay']." [".$table['name']."]"; ?><br></span>
			</td>
				<?php 
					}
					else
					{
				?>
			<td valign="top" class="text">
				<span class="textred"><?php echo $SETUP_LANGUAGE_TEXT['package']['create_table_failed']." [".$table['name']."]"; ?><br></span>
				<?php echo $sql_world->errstr; ?><br>
			</td>
				<?php 
					}
				}
			}
			else
			{
				?>
			<td valign="top" class="text">
				<span class="textred"><?php echo $SETUP_LANGUAGE_TEXT['package']['table_nf']." [".$table_path."]"; ?><br></span>
				<?php echo $sql_world->errstr; ?>
			</td>
				<?php 
			}
			echo("<!-------- DUMMY DUMMY DUMMY ------>\r\n");
			@ob_flush();
			?>
		</tr>
			<?php 
				}
			}
		?>
	</table>
	<img src="../../grafik/bgwindow_482_stop.gif" width="700" height="14"><br>
	<?php @ob_flush(); ?>

	<!-- Daten importieren -->
	<table width="700" border="0" align="center" class="bgwindow700" style="background-repeat: repeat-y;">
		<tr>
			<td valign="top" class="head" width="694" colspan="2">
				<img src="../../grafik/pixel.gif" width="694" height="7" border="0" ><br>
				<?php echo ($SETUP_LANGUAGE_TEXT['package']['import_data']);?><br>
			</td>
		</tr>
		<?php 
			if (empty($pck_data))
			{
				?>
		<tr>
			<td valign="top" class="textgreen" colspan="2">
				<?php echo ($SETUP_LANGUAGE_TEXT['package']['no_data']);?><br>
			</td>
		<tr>
				<?php
			}
			else
			{
				foreach($pck_data as $i => $data)
				{
				?>
		<tr>
		<?php
					flush();
					echo "<script>setTitle('Data ".($i+1)."/".count($pck_data)."');</script>";
		  ?><td valign="top" class="text" width="10%">
		  		<?php echo sprintf('%04d. ',($i+1));?><br>
			</td>
			<?php 
					@set_time_limit(0);
					$mode 		= (empty($data['mode'])?'insert':$data['mode']);
					$primary 	= (!empty($data['prim_key'])?$data['prim_key']:'');
					if ($mode=='update')
					{ // Test if mode 'update' is valid
						if (empty($primary)) 
						{ // No primary key given, change mode to 'insert'
							$mode='insert';
						}
						else
						{// Wrong primary key given, change mode to 'insert'
							$tab_def= $sql_world->get_table_def($data['table']);
							if ($tab_def['primary'] != $primary) $mode='insert';
						}
					}

					if ($mode=='insert')
					{
						$result	= $sql_world->insert($data['table'],$data['fields'],$data['values'],$primary);
					}
					else
					{
		  ?>
		  	<td valign="top" class="textred">
		  		Mode UPDATE not yet implemented<br>
			</td>
			<?php 
					}

					if (empty($sql_world->errnr))
					{
		  ?>
		  	<td valign="top" class="textgreen">
		  		<?php echo $SETUP_LANGUAGE_TEXT['package']['import_data_okay']; ?><br>
			</td>
			<?php 
					}
					else
					{
			?>
			<td valign="top" class="text">
				<span class="textred"><?php echo $SETUP_LANGUAGE_TEXT['package']['import_data_failed']." [".$data['table']."]"; ?><br></span>
				<?php echo $sql_world->errstr; ?><br>
			</td>
			<?php 
					}
				}
			}
		?>		
		</tr>
	</table>
	<img src="../../grafik/bgwindow_482_stop.gif" width="700" height="14"><br>
	<?php @ob_flush(); ?>

	<?php
	/* Helping array for the package. Feel free to use this aliases */
	$translator_array	=	array	(	'%PATH_PACKAGE%'	=> $base_path.$package_name.'/',
										'%PATH_INSTALL%'	=> $GLOBALS['DC_ENV']->installpath,
										'%PATH_START%'		=> $GLOBALS['DC_ENV']->startpath,
										'%PATH_LAYOUTS%'	=> $GLOBALS['DC_ENV']->layoutspath,
										'%PATH_INCLUDE%'	=> $GLOBALS['DC_ENV']->includepath,
										'%PATH_EXTERNAL%'	=> $GLOBALS['DC_ENV']->external_func_path,
										'%PATH_GRAFIX%'		=> $GLOBALS['DC_ENV']->gfxpath);
	?>

	<!-- Verzeichnisse anlegen -->
	<?php 
	if (!empty($pck_dirs))
	{
		?>
	<script>setTitle('<?php echo $SETUP_LANGUAGE_TEXT['package']['create_dirs'];?>');</script>		
	<table width="700" border="0" align="center" class="bgwindow700" style="background-repeat: repeat-y;">
		<tr>
			<td valign="top" class="head" width="694" colspan="2">
				<img src="../../grafik/pixel.gif" width="694" height="7" border="0" ><br>
				<?php echo ($SETUP_LANGUAGE_TEXT['package']['create_dirs']);?><br>
			</td>
		</tr>
		<?php

		includeNaPro('file');
		foreach ($pck_dirs as $i => $data)
		{
		?>
		<tr>
		<?php 
			if (empty($data)) continue;
			flush();
			@set_time_limit(0);
			$data = strtr($data,$translator_array);
			File_MkDirs($data);
			echo "<script>setTitle('Folder ".($i+1)."/".count($pck_dirs)."');</script>";
			?>
			<td class="text" valign="top" width="10%">
				<?php echo sprintf('%03d. ',($i+1));?>
			</td>
			<?php
			$trans = array ('%1%' => $data);
			if (File_MkDirs($data))
			{
			?>
			<td class="textgreen">
				<?php echo (strtr($SETUP_LANGUAGE_TEXT['package']['create_dirs_okay'],$trans)); ?><br>
			</td>
			<?php
			}
			else
			{
			?>
			<td class="textred">
				<?php echo (strtr($SETUP_LANGUAGE_TEXT['package']['create_dirs_failed'],$trans)); ?><br>
			</td>
			<?php
			}
		?>
		</tr>
		<?php 
		}
	?>
	</table>
	<img src="../../grafik/bgwindow_482_stop.gif" width="700" height="14"><br>
	<?php @ob_flush(); ?>

	<?php
	}
?>	

	<!-- Files kopieren -->
	<?php 
	if (!empty($pck_files))
	{
		?>	
	<script>setTitle('<?php echo $SETUP_LANGUAGE_TEXT['package']['copy_files'];?>');</script>
	<table width="700" border="0" align="center" class="bgwindow700" style="background-repeat: repeat-y;">
		<tr>
			<td valign="top" class="head" width="694" colspan="2">
				<img src="../../grafik/pixel.gif" width="694" height="7" border="0" ><br>
				<?php echo ($SETUP_LANGUAGE_TEXT['package']['copy_files']);?><br>
			</td>
		</tr>
		<?php
		foreach ($pck_files as $i => $data)
		{
		?>
		<tr>
		<?php 
			if (empty($data)) continue;
			flush();
			@set_time_limit(0);
			echo "<script>setTitle('File ".($i+1)."/".count($pck_files)."');</script>";
			?>
			<td class="text" valign="top" width="10%">
				<?php echo sprintf('%03d. ',(1+$i));?>
			</td>
			<?php

			$copy_to	= strtr($data['to']		,$translator_array);
			$copy_from	= strtr($data['from']	,$translator_array);

			if (file_exists($copy_to))	unlink($copy_to);
			if (file_exists($copy_from))
			{
				$trans 		= array ('%1%' => basename($copy_from),'%2%' => $copy_to );
				if (copy ($copy_from, $copy_to))
				{
				?>
			<td class="textgreen">
				<?php echo (strtr($SETUP_LANGUAGE_TEXT['package']['copy_files_okay'],$trans)); ?><br>
			</td>
				<?php
				}
				else
				{
				?>
			<td class="textred">
				<?php echo (strtr($SETUP_LANGUAGE_TEXT['package']['copy_files_failed'],$trans)); ?><br>
			</td>
				<?php
				}
			}
			else
			{
				$trans 		= array ('%1%' => $copy_from,'%2%' => $copy_to );
			?>
			<td class="textred">
				<?php echo (strtr($SETUP_LANGUAGE_TEXT['package']['copy_files_no_src'],$trans)); ?><br>
			</td>
			<?php 
			}
		?>
		</tr>
		<?php
		}
	?>
	</table>
	<img src="../../grafik/bgwindow_482_stop.gif" width="700" height="14"><br>
	<?php @ob_flush(); ?>

	<?php
	}
?>

	<!-- XML Daten importieren -->
	<?php 
	$app_name	= 'import';
	$app_path	= $base_path."$package_name/";

	if (!empty($pck_xml_import) && file_exists($app_path.$app_name.'/mnames.xml'))
	{
		?>
	<script>setTitle('<?php echo $SETUP_LANGUAGE_TEXT['package']['import_xml'];?>');</script>
	<table width="700" border="0" align="center" class="bgwindow700" style="background-repeat: repeat-y;">
		<tr>
			<td valign="top" class="head" width="694" colspan="2">
				<img src="../../grafik/pixel.gif" width="694" height="7" border="0" ><br>
				<?php echo ($SETUP_LANGUAGE_TEXT['package']['import_xml']);?><br>
			</td>		
		</tr>	
	</table>
	<img src="../../grafik/bgwindow_482_stop.gif" width="700" height="14"><br>
		<?php 

		flush();
		/* read available databases and check them against "user whish"*/
		includeNaPro('xml,app_import');
		$app_path	= $base_path.$package_name.'/';

		$xml_params	= array();
		$xml_string	= implode("\n",file($app_path.$app_name.'/mnames.xml'));
		$xml_result	= array();
		$xml_dbs	= XML_ToArray($xml_string,$xml_result,$xml_params);
		@set_time_limit(0);
		$app_tables	= array();
		foreach ($xml_result['XML_MAGIC'][0]['ROW'] as $xml_index => $xml_data) {
			if ($pck_xml_import=='*' || strpos($pck_xml_import,$xml_data['mn_name'][0])>=0) {
				$app_tables[]= $xml_data['mn_naid'][0];
			}
		}

		if (empty($app_tables))
		{
		?>
	<table width="700" border="0" align="center" class="bgwindow700" style="background-repeat: repeat-y;">
		<tr>
			<td valign="top" class="head" width="694" colspan="2">
				<img src="../../grafik/pixel.gif" width="694" height="7" border="0" ><br>
				<?php echo ($SETUP_LANGUAGE_TEXT['package']['no_xml_import']);?><br>
			</td>		
		</tr>	
	</table>
	<img src="../../grafik/bgwindow_482_stop.gif" width="700" height="14"><br>		
		<?php 
		}
		else 
		{
		?>

	<?php @ob_flush(); ?>
	<?php 
			includeNaPro('file,form,string');
			?>

			<!-- Import Netautor Schemata -->			
			<?php 
			@set_time_limit(0);
			echo "<script>setTitle('".$SETUP_LANGUAGE_TEXT['package']['import_xml_mnames']."');</script>";
			flush();
			?>
			<table width="700" border="0" align="center" class="bgwindow700" style="background-repeat: repeat-y;">
				<tr>
					<td valign="top" class="head" width="694" >
						<img src="../../grafik/pixel.gif" width="694" height="7" border="0" ><br>
						<?php echo ($SETUP_LANGUAGE_TEXT['package']['import_xml_mnames']);?><br>
					</td>
				</tr>
				<tr>
					<td valign="top" class="text">
					<?php 
						$log_text			= '';
						import_mnames( $app_path, $app_name , $app_tables , $log_text );
						echo(str_replace("\r","<br>",$log_text));flush();
					?>
					</td>
				<tr>	
			</table>
			<img src="../../grafik/bgwindow_482_stop.gif" width="700" height="14"><br>
			<?php @ob_flush(); ?>

			<!-- Import Netautor Elements -->
			<?php 
			@set_time_limit(0);
			echo "<script>setTitle('".$SETUP_LANGUAGE_TEXT['package']['import_xml_melements']."');</script>";
			flush();
			?>
			<table width="700" border="0" align="center" class="bgwindow700" style="background-repeat: repeat-y;">
				<tr>
					<td valign="top" class="head" width="694" >
						<img src="../../grafik/pixel.gif" width="694" height="7" border="0" ><br>
						<?php echo ($SETUP_LANGUAGE_TEXT['package']['import_xml_melements']);?><br>
					</td>
				</tr>
				<tr>
					<td valign="top" class="text">
					<?php 
						$log_text			= '';
						import_melements( $app_path, $app_name , $app_tables , $log_text );
						echo(str_replace("\r","<br>",$log_text));flush();
						flush();
					?>
					</td>
				<tr>	
			</table>
			<img src="../../grafik/bgwindow_482_stop.gif" width="700" height="14"><br>
			<?php @ob_flush(); ?>

			<!-- Import Netautor Layouts -->
			<?php 
			@set_time_limit(0);
			echo "<script>setTitle('".$SETUP_LANGUAGE_TEXT['package']['import_xml_mlayouts']."');</script>";
			flush();
			?>
			<table width="700" border="0" align="center" class="bgwindow700" style="background-repeat: repeat-y;">
				<tr>
					<td valign="top" class="head" width="694" >
						<img src="../../grafik/pixel.gif" width="694" height="7" border="0" ><br>
						<?php echo ($SETUP_LANGUAGE_TEXT['package']['import_xml_mlayouts']);?><br>
					</td>
				</tr>
				<tr>
					<td valign="top" class="text">
					<?php 
						$log_text			= '';
						import_mlayouts( $app_path, $app_name , $app_tables , $log_text );
						echo(str_replace("\r","<br>",$log_text));
						flush();
					?>
					</td>
				<tr>	
			</table>
			<img src="../../grafik/bgwindow_482_stop.gif" width="700" height="14"><br>
			<?php @ob_flush(); ?>

			<!-- Import Netautor Documents -->
			<?php 
			@set_time_limit(0);
			echo "<script>setTitle('".$SETUP_LANGUAGE_TEXT['package']['import_xml_mdocs']."');</script>";
			flush();
			?>
			<table width="700" border="0" align="center" class="bgwindow700" style="background-repeat: repeat-y;">
				<tr>
					<td valign="top" class="head" width="694" >
						<img src="../../grafik/pixel.gif" width="694" height="7" border="0" ><br>
						<?php echo ($SETUP_LANGUAGE_TEXT['package']['import_xml_mdocs']);?><br>
					</td>
				</tr>
				<tr>
					<td valign="top" class="text">
					<?php 
						$log_text			= '';
						import_mdocs( $app_path, $app_name , $app_tables , $log_text );
						echo(str_replace("\r","<br>",$log_text));
						flush();
					?>
					</td>
				<tr>	
			</table>
			<img src="../../grafik/bgwindow_482_stop.gif" width="700" height="14"><br>
			<?php @ob_flush(); ?>
						
			<?php 
		}
	}
	?>
<?php 
	} // End of 'foreach ($whichone as $package_number as $package_name)'
?>
Return current item: Netautor Professional