Location: PHPKode > projects > Netautor Professional > netautor/napro4/admin/exchange/appl_import.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                                              |
   |          Christian Unger                                             |
   |          Helli  Kleinhans  									      |
   +----------------------------------------------------------------------+*/

   /**
    *	@version	$Revision: 1.16 $
	*/

	require_once('../../include/init.inc');
	if(!$USER->check_feature('Admin') && !$USER->check_feature('ac_import'))
	{
		$USER->login_call();
	}

	//	--- include necessary functions
	includeNaPro( 'array,file,form,string,xml' );

/**
* Executes import actions
* @version	$Revision: 1.16 $
* @author	Helmut Kleinhans
* @author	Stefan Rottensteiner
*/
	//error_reporting(65535);
	
	// app_import_x wird aus historischen gründen genommen, um den import-knopf zu identifizieren

	$app_path = ( !empty($app_path) ? $app_path : $DC_ENV->startpath.'export/' );
	if (substr($app_path,-1) != '/') $app_path.='/';

	$app_path	= preg_replace(array('/ /','/\/+/'),array('','/'),str_replace('\\','/',$app_path));

	if (empty($app_mdocs_from))	$app_mdocs_from	=0;
	if (empty($app_mdocs_to) || ($app_mdocs_to < $app_mdocs_from))	$app_mdocs_to	=0;
	/**
	* rangetype=COUNT: import from 'app_mdocs_from'-the mdoc up 'app_mdocs_to'-th document
	* rangetype=ID: import from document-id 'app_mdocs_from' up to document-id 'app_mdocs_to'
	*/
	if (empty($app_mdocs_rangetype))  $app_mdocs_rangetype='COUNT';
	/*
	* app_mdocs_importtype = IDENTITY: identity insert, reuse mdoc_id, overwrite existing mdocs
	* app_mdocs_importtype = ADD: additional insert, create new mdoc-id
	*/
	if (empty($app_mdocs_importtype))  		$app_mdocs_importtype	='IDENTITY';
	if (empty($app_mlayouts_importtype))  	$app_mlayouts_importtype='IDENTITY';

	if (empty($app_mlayouts_from))	$app_mlayouts_from	=0;
	if (empty($app_mlayouts_to) || ($app_mlayouts_to < $app_mlayouts_from))	$app_mlayouts_to	=0;
	if (empty($app_mlayouts_rangetype))  $app_mlayouts_rangetype='COUNT';

	/**
	 *
	 *
	 */
	function app_selection($app_path)
	{
		$files = '';
		$files = get_dirs( $app_path );	// in file.fnc
		$text	= '<select name="app_name" id="app_name" onChange="check_this(this.form)" style="font-size:8pt;"><option value=""></option>';

		if(!empty($files))
		{
			foreach ($files	as $key => $value)
			{	// Solange files
				$extra = ( !empty($GLOBALS['app_name']) && $value == $GLOBALS['app_name'] ? 'SELECTED' : '' );
				$text.= '<option '.$extra.' value="'.$value.'">'.$value."</option>\r\n";
			}	// ENDE: while
		}
		echo( $text.'</SELECT>' );
	}	// ENDE: function app_selection

	/**
	 *
	 *
	 */
	function get_tables($app_path,$app_name,$app_tables)
	{
		if(!empty($app_name))
		{
			$filename = $app_path.$app_name.'/mnames.xml';
			$result	  = array();

			$parameter['unique'] = false ;
			//$parameter['doctype']= "XML_MAGIC";
			XML_FileToArray( $filename, $result , $parameter );	// (xml.fnc)
		}

		$checkstring = ','.(	is_array($app_tables) ?	implode(',',$app_tables) : $app_tables ).',';

		$text = '';
		for($i=0;$i<count($result['XML_MAGIC'][0]['ROW']);$i++)
		{
			$name = $result['XML_MAGIC'][0]['ROW'][$i]['mn_name'][0];

			if( $result['XML_MAGIC'][0]['METADATA'][0]['VERSION'][0] == '1.0' )	// Versionskontrolle
			{
				$value=$result['XML_MAGIC'][0]['ROW'][$i]['mn_id'][0];
			}
			else
			{
				$value=$result['XML_MAGIC'][0]['ROW'][$i]['mn_naid'][0];
			}

			if(!empty($value))
			{
				$selected = ( strstr($checkstring,','.$value.',') ? 'SELECTED' : '');
				$text.="<option value='$value' ".$selected.' >'.$name.'</option>';
			}
		}
		
		if(!empty($text))
		{
			echo($text);
		}
		else
		{
			echo('<option value="">----------------</option>');
		}
	}

	/**
	 *
	 *
	 */
	function get_layouts($app_path,$app_name,$app_tables,$layout_selection)
	{
		includeNaPro('xml,nal_compiler');
		$path = $app_path.'/'.$app_name.'/mlayouts_';
		$text 		= '';
		
		while( list( $key, $value ) = each( $app_tables ) )	// Solange Dateien vorhanden
		{
			$parameter		= array('unique'=>0);
			$filename		= $path.$value.'.xml';
			
			$file_line = '';
			$result='';
			
			if(file_exists($filename))
			{
				$fp = fopen($filename,'r');

				$buffer 	= fgets($fp,10000);

				while(!strstr($buffer,'</METADATA>') && !feof($fp) )
				{
					$buffer=fgets($fp,10000);
				}

				//XML_ToArray( $file_line, $result, $parameter );	// (xml.fnc)
			}
			
			$file_line 	= '';
			$result 	= '';
			
			while ($buffer=fgets($fp,100000))
			{
				$file_line.=$buffer;
				if( !strstr($file_line,'</ROW>') )	{	continue;	}

				$result='';
				XML_ToArray( $file_line, $result, $parameter );	// (xml.fnc)

				$file_line		= '';
				$lay_id 		= $result['ROW'][0]['mlay_id'][0];
				$lay_name		= $result['ROW'][0]['mlay_name'][0];
				if(!empty($lay_id))
				{
					$selected = (in_array($lay_id,$layout_selection) ? ' selected' : '');
					$text.= '<option value="'.$lay_id.'"'.$selected.'>'.$lay_id.'-'.$lay_name.'</option>';
				}
			}
		}
		if(!empty($text))
		{
			echo($text);
		}
		else
		{
			echo('<option value="">----------------</option>');
		}
		//dumpvar($result);
	}

	$log_text='';

	if( !empty($app_import_x)  )	// Wenn Import-Knopf gedrückt
	{
		$auswahl=0;
		ob_end_flush();
		includeNaPro('app_import');

		if (!empty($app_tables))
		{
			//**********************************************	SCHEMA
			if( !empty($app_mnames) )
			{
				$log_text.='<br><b>'.$GLOBALS['LOCALE']->dgettext('exchange','msg_import_tables')."\r".'</b><br>';
				import_mnames( $app_path, $app_name , $app_tables , $log_text );
				$auswahl++;
			}

			//**********************************************	ELEMENTE
			if( !empty($app_melements) )
			{
				$log_text.='<br><b>'.$GLOBALS['LOCALE']->dgettext('exchange','msg_import_elements')."\r".'</b><br>';
				import_melements( $app_path, $app_name , $app_tables , $log_text);
				$auswahl++;
			}

			//**********************************************	LAYOUTS
			if( !empty($app_mlayouts) )
			{
				$log_text.='<br><b>'.$GLOBALS['LOCALE']->dgettext('exchange','msg_import_layouts')."\r".'</b><br>';
				@$imp_options	= 	array (	'range.type'	=> $app_mlayouts_rangetype,
											'from'			=> $app_mlayouts_from,
											'to'			=> $app_mlayouts_to,
											'selection'		=> $app_mlayouts_selection,
											'mode'			=> strtoupper($app_mlayouts_importtype)
										  );
				import_mlayouts( $app_path, $app_name , $app_tables , $log_text, $imp_options);
				$auswahl++;
			}
	
			//**********************************************	DOKUMENTE
			if( !empty($app_mdocs) )
			{
				$log_text.='<br><b>'.$GLOBALS['LOCALE']->dgettext('exchange','msg_import_documents')."\r".'</b><br>';
				if(empty($app_mdocs_from)) $app_mdocs_from = 0;
				if(empty($app_mdocs_to)) $app_mdocs_to = 0;
				
				if(!empty($doc_selection))
				{
					$doc_selection = explode(',',$doc_selection);
					$doc_selection = array_unique($doc_selection);
					foreach($doc_selection as $idx => $val)
					{
						if(empty($val)) unset($doc_selection[ $idx ]);
					}
				}
				else
				{
					$doc_selection = array();
				}
				if(empty($doc_operator)) $doc_operator = 'IN';
				if(!empty($doc_replace))
				{
					
					$doc_replace = array_unique($doc_replace);
					
					$temp_doc_replace = array();
					foreach($doc_replace as $idx => $val)
					{
						$val = trim($val);
						$temp_array = explode(',',$val);
						if(count($temp_array) == 3)
						{
							$replace_from	= '<'.trim($temp_array[0]).'>'.trim($temp_array[1]).'</'.trim($temp_array[0]).'>';
							$replace_to		= '<'.trim($temp_array[0]).'>'.trim($temp_array[2]).'</'.trim($temp_array[0]).'>';
							$temp_doc_replace['mdoc_content']['like'][ $replace_from ] = $replace_to;
						}
					}
					
					$doc_replace = $temp_doc_replace;
					
					if(count($doc_replace) == 0) $doc_replace = '';
					
				}
				else
				{
					$doc_replace = array();
				}
				
				$imp_options	= 	array (	'range.type'	=> $app_mdocs_rangetype,
											'from'			=> $app_mdocs_from,
											'to'			=> $app_mdocs_to,
											'mode'			=> strtoupper($app_mdocs_importtype),
											'mdocs'			=> $doc_selection,
											'mdoc_operator'	=> $doc_operator,
											'mdoc_replace'	=> $doc_replace
										  );
				import_mdocs( $app_path, $app_name , $app_tables , $log_text, $imp_options);
				$auswahl++;
			}
		}
		//**********************************************	USER
		if( !empty($app_user) )
		{
			$log_text.='<br><b>'.$GLOBALS['LOCALE']->dgettext('exchange','msg_import_user')."\r".'</b><br>';
			$auswahl++;
			$imp_options	=	array	(	'mode'			=>'IDENTITY',
											'msg_update'	=>$GLOBALS['LOCALE']->dgettext('exchange','msg_imported_update_user')."\r",
											'msg_update_err'=>$GLOBALS['LOCALE']->dgettext('exchange','msg_imported_update_user_err')."\r",
											'msg_insert'	=>$GLOBALS['LOCALE']->dgettext('exchange','msg_imported_insert_user')."\r",
											'msg_insert_err'=>$GLOBALS['LOCALE']->dgettext('exchange','msg_imported_insert_user_err')."\r"
											);
			import_direct_table( $app_path, $app_name, 'users.xml', $log_text, $imp_options);
		}

		//**********************************************	GROUP
		if( !empty($app_groups) )
		{
			$log_text.='<br><b>'.$GLOBALS['LOCALE']->dgettext('exchange','msg_import_groups')."\r".'</b><br>';
			$auswahl++;
			$imp_options	=	array	(	'mode'			=> 'IDENTITY',
											'msg_update'	=>$GLOBALS['LOCALE']->dgettext('exchange','msg_imported_update_group')."\r",
											'msg_update_err'=>$GLOBALS['LOCALE']->dgettext('exchange','msg_imported_update_group_err')."\r",
											'msg_insert'	=>$GLOBALS['LOCALE']->dgettext('exchange','msg_imported_insert_group')."\r",
											'msg_insert_err'=>$GLOBALS['LOCALE']->dgettext('exchange','msg_imported_insert_group_err')."\r"
											);
			import_direct_table( $app_path, $app_name, 'group_users.xml', $log_text, $imp_options);
		}

		//**********************************************	USER ASSIGNEMENTS
		if( !empty($app_groups) && !empty($app_user) )
		{
			$log_text.='<br><b>'.$GLOBALS['LOCALE']->dgettext('exchange','msg_import_gto')."\r".'</b><br>';
			$auswahl++;
			$imp_options	=	array	(	'mode'			=> 'IDENTITY',
											'msg_update'	=>$GLOBALS['LOCALE']->dgettext('exchange','msg_imported_update_gto')."\r",
											'msg_update_err'=>$GLOBALS['LOCALE']->dgettext('exchange','msg_imported_update_gto_err')."\r",
											'msg_insert'	=>$GLOBALS['LOCALE']->dgettext('exchange','msg_imported_insert_gto')."\r",
											'msg_insert_err'=>$GLOBALS['LOCALE']->dgettext('exchange','msg_imported_insert_gto_err')."\r"
											);
			import_direct_table( $app_path, $app_name, 'gto.xml', $log_text, $imp_options);
		}

		if( !empty($app_groups) || !empty($app_user) )
		{
			//**********************************************	FEATURE DEFINITIONS
			if(  file_exists(trim($app_path.$app_name.'/feature.xml')) )
			{
				$log_text.='<br><b>'.$GLOBALS['LOCALE']->dgettext('exchange','msg_import_feature')."\r".'</b><br>';
				$auswahl++;
				$imp_options	=	array	(	'mode'			=> 'IDENTITY',
												'msg_update'	=>$GLOBALS['LOCALE']->dgettext('exchange','msg_imported_update_feature')."\r",
												'msg_update_err'=>$GLOBALS['LOCALE']->dgettext('exchange','msg_imported_update_feature_err')."\r",
												'msg_insert'	=>$GLOBALS['LOCALE']->dgettext('exchange','msg_imported_insert_feature')."\r",
												'msg_insert_err'=>$GLOBALS['LOCALE']->dgettext('exchange','msg_imported_insert_feature_err')."\r"
												);
				import_direct_table( $app_path, $app_name, 'feature.xml', $log_text, $imp_options);
			}

			//**********************************************	FEATURE VALUES
			if( file_exists(trim($app_path.$app_name.'/fto.xml')) )
			{
				$log_text.='<br><b>'.$GLOBALS['LOCALE']->dgettext('exchange','msg_import_fto')."\r".'</b><br>';
				$auswahl++;
				$imp_options	=	array	(	'mode'			=> 'IDENTITY',
												'msg_update'	=>$GLOBALS['LOCALE']->dgettext('exchange','msg_imported_update_fto')."\r",
												'msg_update_err'=>$GLOBALS['LOCALE']->dgettext('exchange','msg_imported_update_fto_err')."\r",
												'msg_insert'	=>$GLOBALS['LOCALE']->dgettext('exchange','msg_imported_insert_fto')."\r",
												'msg_insert_err'=>$GLOBALS['LOCALE']->dgettext('exchange','msg_imported_insert_fto_err')."\r"
												);
				import_direct_table( $app_path, $app_name, 'fto.xml', $log_text, $imp_options);
			}

		}


		if($auswahl==0) $DC_ENV->message[]=$GLOBALS['LOCALE']->dgettext('exchange','msg_invalid_import_part')."\r";
	}
	else if(isset($app_import_x))
	{
		$DC_ENV->message[]=$GLOBALS['LOCALE']->dgettext('exchange','msg_invalid_import_part')."\r";
	}

	$message='';
	if(!empty($DC_ENV->message))
	{
		$message.= (is_array($DC_ENV->message) ? implode('<br>',$DC_ENV->message) : $DC_ENV->message.'<br>' );
	}

	/* Im Laufe des Code kommt ein Drucheinander an /r und <br> zusammen*/
	$message.='<br>'.str_replace("\r",'<br>',str_replace('<br>',"\r",$log_text));

	/* Entsprechende Maske laden*/
	if(empty($msk)) $msk = 'appl_import';
	include ($msk.'.msk');
?>
Return current item: Netautor Professional