<?php session_start();
		if (isset($_SESSION['logged']) && $_SESSION['logged'] == 'yes') {
		include ('classes.php');
		if ($_SESSION['lang']=="EN"){include ('../lang/en.php'); }elseif ($_SESSION['lang']=="GR"){include ('../lang/gr.php');}else {include ('../lang/en.php');}
        $array = getGlobalSettings(); foreach ($array as $settings){extract($settings);}			
        $page_title = $lbl_webnail_configuration;
        $mode = $lbl_webnail_configuration;
        $mod = $_GET['mod'];	
?>			
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $page_title ?></title>
<link rel="shortcut icon" href="../img/favicon.gif" />
<link href="../cms1.css" rel="stylesheet" type="text/css" />
</head>
<body>
<script>
top.document.title=self.document.title;
</script>
	<div>
		<fieldset>
		<legend><?php echo $mode ?></legend>
<?php if ($mod=='' and $_SESSION['user']=='webnail'){ ?>
		<div  class="align-left" style="padding:10px; margin-bottom:10px;border-radius:4px; border:solid 1px #CCCCCC; background-color:#FFFFAA">
		<img src="../img/attention.gif" title="Attention" width="20" /> 
		<?php echo $attention_truncate_msg ?>
		</div>
		<div style="margin-bottom:5px">
		<form name="clear" action="initialization.php?mod=delete" method="post">
		<input name="initialize" type="submit" class="button" value="<?php echo $lbl_initialize ?>" onclick="return confirm('<?php echo $attention_truncate_msg ?>');">
		</form></div>
		<div>
		<form name="disable" action="initialization.php?mod=disable" method="post">
		<input name="initialize" type="submit" class="button" value="<?php echo $lbl_disable_initialization ?>" onclick="return confirm('<?php echo $lbl_disable_initialization."?" ?>');">
		</form>
		</div>
<?php }elseif ($mod=='delete' and $_SESSION['user']=='webnail' and $_SERVER['REQUEST_METHOD'] == 'POST'){
		mysqli_query ($mysqli, "TRUNCATE cls_transactions") or die(mysqli_error($mysqli));
		mysqli_query ($mysqli, "TRUNCATE cls_customers") or die(mysqli_error($mysqli));
		mysqli_query ($mysqli, "TRUNCATE bi_sales;") or die(mysqli_error($mysqli));
		mysqli_query ($mysqli, "TRUNCATE bi_sales_items;") or die(mysqli_error($mysqli));
        mysqli_query ($mysqli, "TRUNCATE sms_outbox;") or die(mysqli_error($mysqli));
		mysqli_query ($mysqli, "INSERT INTO bi_sales (bi_month, bi_year) VALUES (MONTH(NOW()), YEAR(NOW()))") or die(mysqli_error($mysqli));
		mysqli_query ($mysqli, "UPDATE users SET params=''") or die(mysqli_error($mysqli));
		//Update roufianos.log
			$filename = "../logs/roufianos.log";
			$content = stripslashes("\r\n".date("d-m-Y")." USER #$user# INITIALIZED SYSTEM ".date("H:i:s")); 
			$fp = fopen($filename,"a") or die ("Error opening file in write mode!");
			fputs($fp,$content);
			fclose($fp) or die ("Error closing log file!");
		//end of updating roufianos.log
		?>
		<div class="align-left" style="padding:10px; margin-bottom:10px;border-radius:4px; border:solid 1px #CCCCCC; background-color:#F4F9FB">
		<img src="../img/ok.gif" title="OK"/> 
		<?php echo $lbl_initialization_is_done; ?>
		<ul>
			<li>cls_categories </li>
			<li>cls_customer_groups</li> 
			<li>cls_modules</li>
			<li>core_calibrations</li> 
			<li>core_printers</li>
			<li>core_printouts</li>
			<li>core_regions</li>
			<li>core_settings</li>
			<li>namedays</li>
			<li>users</li>
			<li>usertypes</li>
		</ul>
		<?php echo $lbl_tables_truncated; ?>
		<ul>
			<li>cls_transactions </li>
			<li>cls_customers </li>
			<li>bi_sales </li>
			<li>bi_sales_items </li>
            <li>sms_outbox </li>
		</ul>
		<div>
		<form name="disable" action="initialization.php?mod=disable" method="post">
		<input name="initialize" type="submit" class="button" value="<?php echo $lbl_disable_initialization ?>" onclick="return confirm('<?php echo $lbl_disable_initialization."?" ?>');">
		</form>
		</div>		
		</div>
<?php }elseif ($mod=='disable' and $_SESSION['user']=='webnail' and $_SERVER['REQUEST_METHOD'] == 'POST'){
		rename("initialization.php", "initialization_disabled.php");
		echo $lbl_initilization_has_been_disabled; ?>
		<script>
			parent.leftFrame.location.href = "../menu.php";
		</script>				
<?php
}else{exit;}
?>	
	</fieldset>
</div>	
</body>
</html>
<?php
} else {
    header('Location: login.php');
}
?>

