Location: PHPKode > projects > Netautor Professional > netautor/napro4/admin/exchange/set_mdoc_id.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  									      |
   +----------------------------------------------------------------------+*/

	/**
	 * @author	Marek  Kadziela
	 * @version $Revision: 1.4 $
	 */

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

	$LOCALE->textdomain('exchange');
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
	<title>digiconcept/netautor/export/action</title>
	<meta http-equiv="pragma" 			content="no-cache"> 
	<meta http-equiv="cache-control" 	content="no-cache">
	<meta name		="robots" 			content="noindex">		
	<link rel="stylesheet" type="TEXT/CSS" media="screen" href="../../include/netautor.css">
<script language="JavaScript"><!-- 
	var prev_value = '';
	var prev_text = '';
	
	function sqlSearch()
	{
		document.forms[0].elements['sql_search'].value = 'yes';
		setTimeout("document.forms[0].submit()",200);
	}
	
	function showDocs()
	{
		//document.forms[0].elements['sql_search'].value = 'yes';
		setTimeout("document.forms[0].submit()",200);
	}
	
	function resultReplace(f,fs)
	{
		fm = document.forms[0].elements['doc_result'];
		l = fm.length;
		d = '';
		for(i=0; i<l; i++)
		{
			if(fm.options[i].selected)
			{
				if(d != '') d+=',';
				d+=fm.options[i].value;
			}
		}
		parent.frames[f].document.forms[0].elements['doc_selection'].value = d;
		top.main.document.getElementById(fs).rows='*,0';
	}
	
	function resultAdd(f,fs)
	{
		q = parent.frames[f].document.forms[0].elements['doc_selection'].value;
		if(q != '') q+= ',';
		
		fm = document.forms[0].elements['doc_result'];
		l = fm.length;
		d = '';
		for(i=0; i<l; i++)
		{
			if(fm.options[i].selected)
			{
				if(d != '') d+=',';
				d+=fm.options[i].value;
			}
		}
		
		parent.frames[f].document.forms[0].elements['doc_selection'].value = q + d;
		top.main.document.getElementById(fs).rows='*,0';
	}
	
	function closeFrame(fs)
	{
		top.main.document.getElementById(fs).rows='*,0';
	}
	
	function setPreviewVars(p)
	{
		//alert(v+' - '+t);
		fm = document.forms[0];
		prev_value = fm.elements['doc_result'].options[ fm.elements['doc_result'].selectedIndex ].value;
		prev_text = fm.elements['doc_result'].options[ fm.elements['doc_result'].selectedIndex ].text;
		previewDoc(p);
	}
	
	function previewDoc(p)
	{/*
		if (window.getSelection) alert(window.getSelection());
   		else if (document.getSelection) alert(document.getSelection());
        else if (document.selection) alert(document.selection.createRange().text);
		*/
		/*
		fm = document.forms[0];
		d = '&mdoc_id='+fm.elements['doc_result'].options[ fm.elements['doc_result'].selectedIndex ].value;
		if(fm.elements['app_path']) d+= '&app_path='+fm.elements['app_path'].value;
		if(fm.elements['app_name']) d+= '&app_name='+fm.elements['app_name'].value;
		d+= '&app_table='+fm.elements['doc_result'].options[ fm.elements['doc_result'].selectedIndex ].text;
		window_url = 'set_mdoc_id.php?frame='+p+d;
		window.open(window_url,'DOCPREVIEW','width=500,height=600,scrollbars=yes,resizable=yes');
		*/
		fm = document.forms[0];
		d = '&mdoc_id='+prev_value;
		if(fm.elements['app_path']) d+= '&app_path='+fm.elements['app_path'].value;
		if(fm.elements['app_name']) d+= '&app_name='+fm.elements['app_name'].value;
		d+= '&app_table='+prev_text;
		window_url = 'set_mdoc_id.php?frame='+p+d;
		window.open(window_url,'DOCPREVIEW','width=500,height=600,scrollbars=yes,resizable=yes');
	}
	
	function showAllExport(p)
	{
		view = 'mdocs.mdoc_id as mdoc_id,mdoc_mn_naid';
		from = 'mdocs';
		where = '';
		order = 'mdocs.mdoc_id';
		
		fm = document.forms[0];
		s_field = parent.frames['mainexport'].document.forms[0].elements['db_selection[]'];
		
		for(i=0; i<s_field.length; i++)
		{
			if(s_field.options[i].selected && s_field.options[i].value != '')
			{
				if(from != '') from+= ',';
				from+= 'na_'+s_field.options[i].value;
				
				if(where != '') where+= ' OR ';
				where+= 'na_'+s_field.options[i].value+'.mdoc_id = mdocs.mdoc_id';
			}
		}
		if(from != '' && where != '')
		{
			q = 'SELECT '+view+' FROM '+from+' WHERE '+where+' ORDER BY '+order+'';
			fm.elements['sql_statement'].value = q;
			if(p && p == 'submit') sqlSearch();
		}
		else
		{
			alert('Wählen Sie zuerst ein Netautor-Schema');
		}
	}
	
	function showAllImport(p)
	{
		fm = document.forms[0];
		s_field = parent.frames['mainimport'].document.forms[0].elements['app_tables[]'];
		
		fm.elements['app_path'].value = parent.frames['mainimport'].document.forms[0].elements['app_path'].value;
		fm.elements['app_name'].value = parent.frames['mainimport'].document.forms[0].elements['app_name'].value;
		
		fm.elements['doc_tables[]'].length = s_field.length;
		for(i=0; i<s_field.length; i++)
		{
			fm.elements['doc_tables[]'].options[i].value = s_field.options[i].value;
			fm.elements['doc_tables[]'].options[i].text = s_field.options[i].text;
			fm.elements['doc_tables[]'].options[i].selected = false;
			if(s_field.options[i].selected) fm.elements['doc_tables[]'].options[i].selected = true;
		}
		if(p && p == 'submit') showDocs();
	}
	
	function selectAll(f,p)
	{
		fm = document.forms[0];
		if(f && f == 'import') s_field = fm.elements['doc_result'];
		if(f && f == 'export') s_field = fm.elements['doc_result'];
		for(i=0; i<s_field.length; i++)
		{
			if(p && p == 'no') s_field.options[i].selected = false;
			if(p && p == 'yes' && s_field.options[i].value != '') s_field.options[i].selected = true;
		}
	}
// --></script> 
</head>
<body class="blue">
<table width="462" border="0" cellspacing="0" cellpadding="4">
	<form action="set_mdoc_id.php" method="post">
	<input type="hidden" name="frame" value="<? echo($frame); ?>">
<?php 
if($frame == 'export')
{
	includeNaPro('mdb,array');
	
	function readSchemas(&$DBList)
	{
		$sql 		= $GLOBALS[ 'sql_world' ];
		$erg		= $sql->select('SELECT mn_name, mn_naid FROM mnames ORDER BY mn_name',0,0,2);
		if (!empty($erg))
		{
			$max_erg = count($erg);
			for ($i=0;$i<$max_erg;$i++)
			{
				$DBList[ $erg[$i]['mn_naid'] ] = $erg[$i]['mn_name'];
			}
		}
	}
	
	readSchemas($DBList);
	
	if( !empty($sql_search) && !empty($sql_statement) && strpos(strtoupper(trim($sql_statement)),'SELECT') == 0 )
	{
		$sql_statement = trim($sql_statement);
		$result = $sql_world->select($sql_statement,0,0,2);
		if($result)
		{
			foreach($result as $idx => $val)
			{
				$result[ $idx ]['mdoc_id'] = $val['mdoc_id'];
				$result[ $idx ]['mdoc_mn_naid'] = $DBList[ $val['mdoc_mn_naid'] ];
			}
			
			if(count($result) > 0)
			{
				$show_result = 'yes';
				$msg_vars = array(count($result));
				$sql_message = $LOCALE->gettext('result_found',$msg_vars);
			}
			else
			{
				$sql_message = '<b>'.$LOCALE->gettext('result_not_found').'</b>';
			}
		}
		else
		{
			$sql_message = '<b>'.$LOCALE->gettext('result_not_found').'</b>';
		}
	}
 ?>
	<input type="hidden" name="sql_search" value="">
	<tr>
		<td width="362" align="left" valign="top" class="text">	
			<?php echo( $LOCALE->gettext('sql_query') ); ?>:<br>
			<textarea class="input319" style="width:354px;height:150px;" name="sql_statement"><?php echo($sql_statement); ?></textarea><br>
		</td>
		<td width="100" align="left" valign="top" class="text">	
			<br>
			<input type="button" value="<?php echo( $LOCALE->gettext('button_go_search') ); ?>" onClick="sqlSearch();" class="create" style="width:100px"><br>
			<br>
			<input type="button" value="<?php echo( $LOCALE->gettext('button_close') ); ?>" onClick="closeFrame('f_export');" class="new" style="width:100px"><br>
			<br>
			<input type="button" value="<?php echo( $LOCALE->gettext('button_refresh') ); ?>" onClick="showAllExport('');" class="new" style="width:100px"><br>
			<!--<br>
			<input type="button" value="<?php echo( $LOCALE->gettext('button_all_docs') ); ?>" onClick="showAllExport('submit');" class="new" style="width:100px"><br>-->
		</td>
	</tr>

	<tr>
		<td width="362" align="left" valign="top" class="text">	
			<?php echo( $LOCALE->gettext('found_documents') ); ?>:<br>
			<select name="doc_result" multiple="multiple" class="select319m" style="width:354px;height:150px;">
<?php 
				if(empty($result))
				{
					echo('<option value="">----------------</option>');
				}
				else
				{
					foreach($result as $idx => $val)
					{
						echo('<option value="'.$val['mdoc_id'].'">'.($idx+1).' - '.(!empty($val['mdoc_mn_naid']) ? $val['mdoc_mn_naid'].' - ' : '').$val['mdoc_id'].'</option>');
					}
				}
?>
			</select><br>
<?php 
			if(!empty($sql_message)) echo('<font class="textred">'.$sql_message.'</font><br>');
 ?>
		</td>
		<td width="100" align="left" valign="top" class="text">	
			<br>
			<input type="button" value="<?php echo( $LOCALE->gettext('button_replace') ); ?>" onClick="resultReplace('mainexport','f_export');" class="new" style="width:100px"><br>
			<br>
			<input type="button" value="<?php echo( $LOCALE->gettext('button_add') ); ?>" onClick="resultAdd('mainexport','f_export');" class="new" style="width:100px"><br>
			<br>
			<input type="button" value="<?php echo( $LOCALE->gettext('button_preview') ); ?>" onClick="setPreviewVars('previewExport');" class="new" style="width:100px"><br>
			<br>
			<input type="button" value="<?php echo( $LOCALE->gettext('button_select_all') ); ?>" onClick="selectAll('export','yes');" class="new" style="width:100px"><br>
			<br>
			<input type="button" value="<?php echo( $LOCALE->gettext('button_unselect_all') ); ?>" onClick="selectAll('export','no');" class="new" style="width:100px"><br>
		</td>
	</tr>
<?php 
}
elseif($frame == 'import') // frame export, import or preview
{
	$GLOBALS['na_tables'] = array();
	$GLOBALS['message'] = '';
	
	function get_tables($app_path,$app_name,$app_tables)
	{
		includeNaPro( 'array,file,form,string,xml' );
		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>';
				$GLOBALS['na_tables'][ $value ] = $name;
				$GLOBALS['na_tables'][ $name ] = $value;
			}
		}
		
		if(!empty($text))
		{
			echo($text);
		}
		else
		{
			echo('<option value="">----------------</option>');
		}
	}
	
	function get_mdocs($app_path,$app_name,$app_tables,$doc_selection)
	{
		includeNaPro('xml,nal_compiler');
		$path 		= $app_path.'/'.$app_name.'/mdocs_';
		$text 		= '';
		$counter 	= 0;
		
		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		= '';
				$doc_id 		= $result['ROW'][0]['mdoc_id'][0];
				if(!empty($doc_id))
				{
					$counter++;
					$selected = (in_array($doc_id,$doc_selection) ? ' selected' : '');
					$text.= '<option value="'.$doc_id.'"'.$selected.'>'.$counter.' - '.$GLOBALS['na_tables'][ $value ].' - '.$doc_id.'</option>';
				}
			}
		}
		if(!empty($text))
		{
			$msg_vars = array($counter);
			$GLOBALS['message'] = $GLOBALS['LOCALE']->gettext('result_found',$msg_vars);
			echo($text);
		}
		else
		{
			if(!empty($app_path) && !empty($app_name) && !empty($app_tables))
			{
				$GLOBALS['message'] = $GLOBALS['LOCALE']->gettext('no_docs_found');
			}
			echo('<option value="">----------------</option>');
		}
		//dumpvar($result);
	}
?>
	<input type="hidden" name="app_path" value="<? echo($app_path); ?>">
	<input type="hidden" name="app_name" value="<? echo($app_name); ?>">
	<tr>
		<td width="362" align="left" valign="top" class="text">	
			<?php echo( $LOCALE->gettext('na_schema') ); ?>:<br>
			<select name="doc_tables[]" multiple="multiple" class="select319m" style="width:354px;height:150px;">
<?php 
				$doc_tables=(!empty($doc_tables) ? $doc_tables :'');
				get_tables($app_path,$app_name,$doc_tables);
?>
			</select><br>	
		</td>
		<td width="100" align="left" valign="top" class="text">	
			<br>
			<input type="button" value="<?php echo( $LOCALE->gettext('button_go_search') ); ?>" onClick="showDocs();" class="create" style="width:100px"><br>
			<br>
			<input type="button" value="<?php echo( $LOCALE->gettext('button_close') ); ?>" onClick="closeFrame('f_import');" class="new" style="width:100px"><br>
			<br>
			<input type="button" value="<?php echo( $LOCALE->gettext('button_refresh') ); ?>" onClick="showAllImport('');" class="new" style="width:100px"><br>
			<!--<br>
			<input type="button" value="<?php echo( $LOCALE->gettext('button_all_docs') ); ?>" onClick="showAllImport('submit');" class="new" style="width:100px"><br>-->
		</td>
	</tr>
	<tr>
		<td width="362" align="left" valign="top" class="text">	
			<?php echo( $LOCALE->gettext('exists_documents') ); ?>:<br>
			<select name="doc_result" multiple="multiple" class="select319m" style="width:354px;height:150px;">
<?php 
				$doc_selection=(!empty($doc_selection) ? $doc_selection :'');
				get_mdocs($app_path,$app_name,$doc_tables,$doc_selection);
?>
			</select><br>
<?php 
			if(!empty($GLOBALS['message'])) echo('<font class="textred">'.$GLOBALS['message'].'</font><br>');
 ?>
		</td>
		<td width="100" align="left" valign="top" class="text">	
			<br>
			<input type="button" value="<?php echo( $LOCALE->gettext('button_replace') ); ?>" onClick="resultReplace('mainimport','f_import');" class="new" style="width:100px"><br>
			<br>
			<input type="button" value="<?php echo( $LOCALE->gettext('button_add') ); ?>" onClick="resultAdd('mainimport','f_import');" class="new" style="width:100px"><br>
			<br>
			<input type="button" value="<?php echo( $LOCALE->gettext('button_preview') ); ?>" onClick="setPreviewVars('previewImport');" class="new" style="width:100px"><br>
			<br>
			<input type="button" value="<?php echo( $LOCALE->gettext('button_select_all') ); ?>" onClick="selectAll('import','yes');" class="new" style="width:100px"><br>
			<br>
			<input type="button" value="<?php echo( $LOCALE->gettext('button_unselect_all') ); ?>" onClick="selectAll('import','no');" class="new" style="width:100px"><br>
		</td>
	</tr>
<?php
} // if frame export, import or preview
elseif($frame == 'previewImport')
{
	function get_tables($app_path,$app_name)
	{
		includeNaPro( 'array,file,form,string,xml' );
		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>';
				$GLOBALS['na_tables'][ $value ] = $name;
				$GLOBALS['na_tables'][ $name ] = $value;
			}
		}
	}
	
	function get_mdoc_xml_content($app_path,$app_name,$app_table,$doc_selection,&$values)
	{
		includeNaPro('xml,nal_compiler,array');
		$path 		= $app_path.'/'.$app_name.'/mdocs_';
		$text 		= '';
		$counter 	= 0;
		$break		= false;
		
		$value		= $app_table;
		
		$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		= '';
			$doc_id 		= $result['ROW'][0]['mdoc_id'][0];
			if(!empty($doc_id) && $doc_id == $doc_selection)
			{
				$temp		= XML_ToArray($result['ROW'][0]['mdoc_content'][0],$values);
				$break		= true;
				if($break) break;
			}
		}
	}
	
	$GLOBALS['na_tables'] = array();
	get_tables($app_path,$app_name);
	$app_table = substr($app_table,(strpos($app_table,' - ')+3));
	$app_table = substr($app_table,0,strpos($app_table,' - '));
	if(!empty($app_table)) $app_table = $GLOBALS['na_tables'][ $app_table ];
	
	$values = array();
	get_mdoc_xml_content($app_path,$app_name,$app_table,$mdoc_id,$values);
	//dumpvar($values);
	$values = $values[ key($values) ][0];
	
	echo('<tr><td colspan="2" class="text"><b>');
	echo($LOCALE->gettext('preview_doc').' - IMPORT - '.$GLOBALS['na_tables'][ $app_table ].' - '.$mdoc_id);
	echo('</b></td></tr>');
	
	echo('<tr><td colspan="2">');
	dumpvar($values);
	echo('</td></tr>');
	
} // if frame export, import or preview
elseif($frame == 'previewExport')
{
	function readSchemas(&$DBList)
	{
		$sql 		= $GLOBALS[ 'sql_world' ];
		$erg		= $sql->select('SELECT mn_name, mn_naid FROM mnames ORDER BY mn_name',0,0,2);
		if (!empty($erg))
		{
			$max_erg = count($erg);
			for ($i=0;$i<$max_erg;$i++)
			{
				$DBList[ $erg[$i]['mn_naid'] ] = $erg[$i]['mn_name'];
			}
		}
	}
	
	readSchemas($DBList);
	
	if(!empty($mdoc_id))
	{
		includeNaPro('mdoc,mdb,xml,array');
		$sql 		= $GLOBALS[ 'sql_world' ];
		$erg		= $sql->select("SELECT mdoc_content,mdoc_mn_naid FROM mdocs WHERE mdoc_id = $mdoc_id",0,0,2);
		$values		= '';
		$conv 		= array(
								'<'	=> '&lt;',
								'>' => '&gt;'
						);
		//$erg[0]['mdoc_content'] = strtr($erg[0]['mdoc_content'],$conv);
		$temp		= XML_ToArray($erg[0]['mdoc_content'],$values);
		$values = $values[ key($values) ][0];
		
		echo('<tr><td colspan="2" class="text"><b>');
		echo($LOCALE->gettext('preview_doc').' - EXPORT - '.$DBList[ $erg[0]['mdoc_mn_naid'] ].' - '.$mdoc_id);
		echo('</b></td></tr>');
		
		echo('<tr><td colspan="2">');
		dumpvar($values);
		echo('</td></tr>');
	}
	else
	{
		
	}
}
 ?>
</table>

<br>

</form>


<script language="JavaScript"><!-- 
	window.focus();
// --></script>
</body>

</html>
Return current item: Netautor Professional