Location: PHPKode > projects > Netautor Professional > netautor/napro4/admin/workflow/procs.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.15 $										  |
   +----------------------------------------------------------------------+*/

/**
 * Process editor.
 * @author Various coding artist
 */

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

includeNaPro( 'array,file,form,procs,string' );

$GLOBALS['LOCALE']->textdomain('proc');

if(isset($blank))
{
	exit();
}

$errordescription	= '';
$process['proc_namealt'] = (empty($process['proc_namealt']) ? '' :  $process['proc_namealt']);

/**
 * Prozess-Parameter rekurisv durchlaufen und in eine halbwegse Form bringen
 */
function proc_printRecursiveParams($array)
{
	$result = '';
	foreach ($array as $key => $value)
	{
		$result.="\"{$key}\" => ";
		if (is_array($value))
		{
			$sub_result = proc_printRecursiveParams($value);
			$result.=" array ( {$sub_result} ),";
		}
		else
		{
			$result.="\"{$value}\",\r";
		}
	}
	// Trimmen und letztes , wegnehmen
	$result = trim($result);
	if (substr($result,-1) == ',') $result=substr($result,0,-1);
	return $result;
}

// Editiermodus abbrechen
if(isset($abort))
{
	$process['proc_name'] = ($editproc == 'create' ? '' : $process['proc_name'] );
	$editproc = '';
}

// Standard -Prozessverzeichnis
$process['proc_path'] = $GLOBALS['DC_ENV']->startpath.'config/workflow/';
File_MkDirs( $process['proc_path'] );

// Standard-Logverzeichnis
$process['proc_logpath'] = $GLOBALS['DC_ENV']->logs_path;
if(!empty($process['proc_name']))
 File_MkDirs( $process['proc_logpath'] );

$process['log_names'] = isset($log_name)?$log_name:false;

// Prozeß löschen
if(isset($delete))
{
	$process['proc_name'] = (empty($process['proc_name']) ? $process['content']['basic']['name'] : $process['proc_name']);

	$filename 		= $process['proc_path'].$process['proc_name'].'.cfg';
	$logfilepath 	= $process['proc_logpath'].$process['proc_name'].'/';
	$was 			= $GLOBALS['LOCALE']->gettext('process');
	$angabe[] = $process['proc_name'];
	$angabe[] = $was;
	File_MkDirs( $logfilepath );

	if( file_exists( $filename ) )
	{ 
		$errorcheck = unlink($filename);
	}
	else
	{	// Config nicht gefunden
		$errorcheck = 0;
		$errordescription = $GLOBALS['LOCALE']->gettext('mess_proc_not_found');
	}

	if($errorcheck)
	{
		// Prozeß gelöscht 
		$DC_ENV->message[] = $GLOBALS['LOCALE']->gettext('mess_proc_del');
		$DC_ENV->errnr = '313';
	}
	else
	{
		// Prozeß nicht gelöscht
		$DC_ENV->message[]= $GLOBALS['LOCALE']->gettext('mess_proc_not_del');
		$DC_ENV->errnr = '315';

		if($errordescription)
		{
			$DC_ENV->message[]= $errordescription;
		}
		else
		{
			// Berechtigungsfehler
			$DC_ENV->message[]= $GLOBALS['LOCALE']->gettext('mess_right_eroor');
			$DC_ENV->errnr = '316';
		}
	}
}

// Prozesse einlesen, Prozessfenstergröße checken
$process['procs'] 	 = get_procs($process['proc_path']);
$process['procs_anz']= count($process['procs']);
$leer 				 = $GLOBALS['LOCALE']->gettext('mess_empty_poclist');
$process['procs'][0] = ( $process['procs_anz'] > 0 ? $process['procs'][0] : $leer );

// Daten aus der Edit-Maske übergeben
if(isset($editmask))
{
	$process = convert_process($process, $params);
}

// Prozeß in eine Datei wegschreiben
if(isset($save) || isset($update))
{
	$datum 	= getdate(time());
	$datum1 = sprintf("%04d%02d%02d%02d%02d", $datum['year'], $datum['mon'], $datum['mday'], $datum['hours'], $datum['minutes']);
	$dummy	="                    ";
	$dquote = chr(34);
	$dollar = chr(36);
	$slashdquote = chr(92).chr(34);
	$slashdollar = chr(92).chr(36);
	$slash 	= chr(92);
	$dslash = chr(92).chr(92);
	$string = '<?php
	$config = array(
					\'basic\'  => array(
									   ';
									   
	foreach($process['content']['basic']  as $key=>$value)
	{
		$value = str_replace($dquote, $slashdquote, $value);
		$value = str_replace($dollar, $slashdollar, $value);
		$value = str_replace($dslash, $slash, $value);
		$value = addslashes($value);
		$beistrich = ($key == 'logpath' ? ',' : ',');
		$string.=									 '\''.$key.'\''.substr($dummy,0,(20-strlen($key))).'=> \''.$value.'\' '.$beistrich.'
									   ';
									   
									   
	}
	
	$string.=									 '),
					\'method\' => array(
									   ';
	while(list($key,$value) = each($process['content']['method']))
	{
		$value = str_replace($dquote, $slashdquote, $value);
		$value = str_replace($dollar, $slashdollar, $value);
		$value = str_replace($dslash, $slash, $value);
		if(!empty($process['content']['params']))
		{
			$beistrich = ',';
		}
		else
		{
			$beistrich = ($key == 'methods' ? ' ' : ',');
		}
		$string.=									 '\''.$key.'\''.substr($dummy,0,(20-strlen($key))).'=> "'.$value.'" '.$beistrich.'
									   ';
	}
	if(is_array($process['content']['params']))
	{
		$string.=									 '\'params\''.substr($dummy,0,(20-strlen('params'))).'=> array(
																	   ';
		$i=0;
		$anz = count($process['content']['params']);
		while(list($key,$value) = each($process['content']['params']))
		{
			$value = str_replace($dquote, $slashdquote, $value);
			$value = str_replace($dollar, $slashdollar, $value);
			$value = str_replace($dslash, $slash, $value);
			$i++;
			$beistrich = ($i >= $anz ? ' ' : ',');
			$string.='"'.$key.'"'.substr($dummy,0,(20-strlen($key))).'=> "'.$value.'" '.$beistrich.'
																	   ';
		}
		$string.=														')
									   )
					)
?>';
	}
	elseif(!empty($process['content']['params']))
	{
		$string.=									 '\'params\''.substr($dummy,0,(20-strlen('params'))).'=> array( '.$process['content']['params'].' )
									   )
					)
?>';
	}
	else
	{
		$string.=										')
					)
?>';
	}


	// auf korrekte Verzeichnisseinträge prüfen (Syntax)
	$writeenabled = "true";

	if($process['content']['method']['scandir']!='nofiles')
	{
		$writeenabled = (($process['content']['method']['scandir'] != '') && (substr($process['content']['method']['scandir'], -1) != '/') ? 'false' : $writeenabled );
		$writeenabled = (($process['content']['method']['error'] != '') && (substr($process['content']['method']['error'], -1) != '/') ? 'false' : $writeenabled );
		$writeenabled = (($process['content']['method']['temp'] != '') && (substr($process['content']['method']['temp'], -1) != '/') ? 'false' : $writeenabled );
		$writeenabled = (($process['content']['method']['done'] != '') && (substr($process['content']['method']['done'], -1) != '/') ? 'false' : $writeenabled );
		$writeenabled = (($process['content']['method']['target'] != '') && (substr($process['content']['method']['target'], -1) != '/') ? 'false' : $writeenabled );
	}

	if($writeenabled == 'true')
	{
		$process['proc_name'] = ($editproc == 'create' ? $process['content']['basic']['name'] : $process['content']['basic']['name']);
		$writeenabled = ($process['proc_name'] == '' ? 'false' : $writeenabled );
		if($writeenabled == 'true')
		{
			// Datei wegschreiben
			$filename = $process['proc_path'].$process['proc_name'].'.cfg';
			if($editproc == 'create')
			{
				$existcheck = file_exists($filename);
				$writeenabled = ($existcheck ? 'false' : $writeenabled );
			}
			if($writeenabled == 'true')
			{
				$fp = fopen($filename, 'wb');
				if($fp)
				{
					$noerror = fwrite($fp, $string);
					if($noerror)
					{
						// Prozeß erfolgreich weggeschrieben
						if($create)
						{
							$DC_ENV->message[] = $GLOBALS['LOCALE']->gettext('mess_proc_save');
							$DC_ENV->errnr = '320';
						}
						else
						{
							$DC_ENV->message[] = $GLOBALS['LOCALE']->gettext('mess_proc_update');
							$DC_ENV->errnr = '321';
						}
						$editproc = '';
						$reload = 'true';
					}
					else
					{
						// Prozeß nicht erfolgreich weggeschrieben
						$DC_ENV->message[] = $GLOBALS['LOCALE']->gettext('mess_proc_save_error');
						$DC_ENV->errnr = '322';
					}
				}
				else
				{
					// Keine Schreibberechtigung im Prozessverzeichnis
					$DC_ENV->message[] = $GLOBALS['LOCALE']->gettext('mess_right_error');
					$DC_ENV->errnr = '316';
				}
				fclose($fp);
			}
			else
			{
				// Prozeßname existiert bereits
				$DC_ENV->message[] = $GLOBALS['LOCALE']->gettext('mess_proc_exists');
				$DC_ENV->errnr = '310';
			}
		}
		else
		{
			// Keine Prozeßname definiert
			$DC_ENV->message[] = $GLOBALS['LOCALE']->gettext('mess_no_proc_name');
			$DC_ENV->errnr = '323';
		}
	}
	else
	{
		// Fehlerhafte Directoryeingaben
		$DC_ENV->message[] = $GLOBALS['LOCALE']->gettext('mess_dir_error');
		$DC_ENV->errnr = '324';
	}
	if($reload)
	{
		$process['procs'] 		= get_procs($process['proc_path']);
		$process['procs_anz']	= count($process['procs']);
		$process['proc'][0] 	= ( $process['procs_anz'] > 0 ? $process["procs"][0] : $leer );
	}
}

// Prozeß anzeigen
if(isset($show))	$editproc = 'show';

// Prozeß bearbeiten
if(isset($edit))	$editproc = 'edit';

// Prozeß 'Neu Anlegen'
if(isset($proc_new))
{
	$editproc = 'create';
	$process['proc_name'] = '';
}

// Logverzeichnis
$process['proc_logpath'] 	= (empty($process['proc_logpath']) 		? $standardlogpath 			: $process['proc_logpath'] );
$process['proc_logpathalt'] = (empty($process['proc_logpathalt']) 	? $process['proc_logpath'] 	: $process['proc_logpathalt'] );
// Korrektur, bei falscher Benutzereingabe
$process['proc_logpath'] = (substr($process['proc_logpath'],-1) == '/' ? $process['proc_logpath'] : $process['proc_logpath'].'/' );
if(!file_exists($process['proc_logpath']) && $editproc)
{
	$DC_ENV->message[] 		= $GLOBALS['LOCALE']->gettext('mess_dir_not_found',array($process['proc_logpath']));
	$DC_ENV->errnr 			= '325';
	$process['proc_logpath']= $process['proc_logpathalt'];
	$process["patherror"] 	= 1;
}

// Daten einlesen -----
if( !empty($editproc) && $editproc != 'create' && empty($editmask) && ( !empty($process['proc_name']) || isset($logshow)) )
{
	$configfile = $process['proc_path'].$process['proc_name'].'.cfg';
	include($configfile);
	$config['basic']['logtype'] = ( empty($config['basic']['logtype']) == '' ? 'file' : $config['basic']['logtype']);
	$process['content'] = $config;
	$process['content']['params'] = $config['method']['params'];
	$process['focus'] = '"abort"';
}

if(!empty($editproc) && $editproc == 'show')
{
	// Prozessanzeigemaske includieren
	include('procs_show.msk');
}
else if(isset($logshow))
{
	// Prozessbearbeitungsmaske includieren
	include('procs_log.msk');
}
else if(isset($editproc))
{
	$process['proc_name'] = (empty($process['proc_name']) ? '' : $process['proc_name']);
	$process['fileorg'] = ($editproc == 'edit' ? (empty($process['fileorg']) ? $process['proc_name'] : $process['fileorg']) : '');
	// Prozessbearbeitungsmaske includieren
	include('procs.msk');
}
else
{
	// Prozessauswahlmaske includieren
	include('procs.msk');
}
?>
Return current item: Netautor Professional