<?
########## Confixx(R) 3.0 Professional ############
####### Copyright SWsoft, Inc. 2004-2005 ##########
#### http://www.sw-soft.com - info@sw-soft.com ####

include_once("auth.php");
include_once("../include/cron_functions.php");

if( !defined('CONFIXX') ) 
{
	define('CONFIXX', 1);
}

## mysql verbindung aufbauen
db_connect($db_host, $db_user, $db_pass);
## /mysql verbindung aufbauen



$alerts = array();
$vars = array("minute" => ltext("cron_minute"), "hour" => ltext("cron_hour"), "dom" => ltext("cron_day_of_month"), "month" => ltext("cron_month"), "dow" => ltext("cron_day_of_week"), "cmd" => ltext("cron_cmd"));
$var_values = array();
$bad_values = false;

$cron_rec = load_cron();
$cron_content = ($cron_rec == false) 
	? array('') 
	: explode("\n", $cron_rec['cronfile']);
$crn = new Crontab($cron_content); 

$id = safe_query2( "SELECT maxcronjobs FROM kunden WHERE kunde=?", new SQLString($PHP_AUTH_USER));
$werte = db_fetch_array($id);
$maxcronjobs = $werte["maxcronjobs"];

if (($maxcronjobs > -1) && $crn->count_jobs() >= $maxcronjobs && $new_job )
{
	$alerts[] = js_message(ltext("cron_limit_error", array($maxcronjobs)));
	$new_job = false;
	if( $crn->count_jobs() > $maxcronjobs && $edit )
	{
		$edit = false;
	}
}

//echo $maxcronjobs;

// read cronjobs list from the system
if ($read_jobs) {
	include_once('module.Informer.php');
	message(NOTE, ltext('cron_reread_note'));
	if ($cron_rec['neu'] == 1) {
		include_once('../include/page_functions.php');
		$js_confirmation .= js_f_confirm(ltext('cron_confirm_refuse_changes'), js_f_goto('tools_cron.php'));
	}
	read_cron($PHP_AUTH_USER);
}

// delete cronjob from the system
if ($delete)
{
	if ($cron_rec['neu'] == 2) {
		include_once('../include/page_functions.php');
		$js_confirmation .= js_f_confirm(ltext('cron_confirm_refuse_reread'), js_f_goto('tools_cron.php'));		
	}
	if ($delent = &$crn->getEntry(base64_decode($delete)))
	{
		$delent->Remove();	
		save_cron( $crn->export() );
	}
}
//echo "<pre>"; print_r($crn);

// save cronjob to the system
if ($save)
{ 
	if ($cron_rec['neu'] == 2) {
		include_once('../include/page_functions.php');
		$js_confirmation .= js_f_confirm(ltext('cron_confirm_refuse_reread'), js_f_goto('tools_cron.php'));		
	}
	if($edkey)
	{
		$edent = &$crn->changeEntry(base64_decode($edkey), true, $minute, $hour, $dom, $month, $dow, $cmd);
	}
	else
	{
		$edent = &$crn->addEntry(true, true, $minute, $hour, $dom, $month, $dow, $cmd);
	}
	
	if($edent)
	{
		if($bad_values = $edent->getBadValues())
		{
			if(!$edkey)
			{
				$edent->Remove();
			}
			$new_job = true;
			foreach (array_keys($vars) as $k)
			{
				$var_values[$k] = $$k;
			}
		}
		else
		{
			save_cron( $crn->export() );
		}
	}
	else
	{
		$alerts[] = "System error!";
	}
	
}	
?>
<HTML>
<HEAD>
<META content="text/html; charset=<? echo $lang_html_charset; ?>" http-equiv=Content-Type>
<LINK href="<?=$strSkinName?>/style.css" rel=stylesheet type=text/css>
<SCRIPT>
<?=$js_confirmation?>
</SCRIPT>
</HEAD>

<BODY bgColor=#ffffff bottomMargin=0 leftMargin=0 topMargin=0 MARGINHEIGHT="0" MARGINWIDTH="0">
<br><? include("../fehler.inc.php"); ?>
<script>
function doChange()
{
document.forms[0].submit();
}
</script>
<?
if($edit || $new_job)
{
	include("cron_inc/edit_job.php");
}
else
{
	include("cron_inc/list_jobs.php");
}


?>

<? if( is_array($alerts) && sizeof($alerts) ): ?>
<script>
error = "";
<? foreach ($alerts as $a): ?>
error += "<?=strip_tags($a)?>\n";
<? endforeach; ?>
alert(error);
</script>
<? endif; ?>

</BODY>
</HTML>
<?
//()
db_close();
?>
