<?php

// -----------------------------------------------------------------------
// This file is part of AROUNDMe
//
// Copyright (C) 2003 - 2007 Barnraiser
// http://www.barnraiser.org/
// info@barnraiser.org
//
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option) any
// later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with program; see the file COPYING. If not, write to the Free
// Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
// 02110-1301, USA.
// -----------------------------------------------------------------------

$cron_str = "# cronjob charts.php\n";
$cron_str .= "# creates charts of the activities in your instance of AROUNDMe\n";
$batch_file = dirname(dirname(dirname($_SERVER['SCRIPT_FILENAME']."..")."..")."..")."/aroundme/batch/charts.php";
$cron_str .= "0 0 * * * /usr/bin/php -f ".$batch_file . "\n";
$cron_str .= "#EO cronjob charts.php\n";
$cron_str .= "#EOF";

function write_cronjob($arr) {
	GLOBAL $batch_file;
	
	if(!$file = fopen(dirname($batch_file."..")."/cron.batch", "w+")) {
		echo "error1";
		return false;
	}
	
	if (!fwrite($file, $arr['frm_cron_file'])) {
		echo "error2";
		return false;
	}
	
	fclose($file);
	
	return true;
}

?>

	<?php if (isset($_POST['frm_send'])) { ?>
	
		<div class="message">
			<?php if (write_cronjob($_POST)) { header("location: install.php?step=7"); exit; } ?>	
		</div>
	
	<?php } ?>
	
	<form method="post" action="install.php" name="frm">
		<input type="hidden" name="step" value="6" />
		<p><?php echo $lang['txt_step_6']; ?></p>
		
		<textarea name="frm_cron_file"><?php echo $cron_str; ?></textarea>
	
		<p align="right">
			<input type="submit" value="<?php echo $lang['frm_step_6_next_step']; ?>" name="frm_send" /> 
		</p>
	</form>