<?php session_start();
		if (isset($_SESSION['logged']) && $_SESSION['logged'] == 'yes') {
			include ('../../../scripts/classes.php'); //Retrieve functions
			if ($_SESSION['lang']=="EN"){include ('../../../lang/en.php');}elseif ($_SESSION['lang']=="GR"){include ('../../../lang/gr.php');}else{include ('../../../lang/en.php');}
			$user = $_SESSION['user'];	
				
			$array = getGlobalSettings(); //Retrieve Global Settings	
			$page_title = $lbl_grid_default_printer; //Assign Page Title
			$mode = $lbl_grid_default_printer; //Assign Mode
			
			if (isset($_POST['but_submit'])){
        		$username = $_SESSION['user'];
        		$default_printer = $_POST['f1default'];
        		$_SESSION['default_printer'] = $default_printer; //added for pos module
        
        		//fetch email account
        		$mail = mysqli_query($mysqli, "SELECT * FROM users WHERE username='$username'");
        		$mail_result = mysqli_fetch_array($mail, MYSQLI_ASSOC);
        		$email=$mail_result['email'];
        		$uid=$mail_result['id'];
        		//update password
        		mysqli_query($mysqli, "SET NAMES 'utf8' " ); //Gia Ellinika
        		$update = mysqli_query($mysqli, "UPDATE users SET default_printer='$default_printer' WHERE id='$uid'") or die("Query failed : " . mysqli_error($mysqli)); 						
        				?>
        
        				<script type="text/javascript">
        				parent.frames['topFrame'].location = '../../../top.php'
        				window.location = "../../../main.php"; 
        				</script>
        				<?php }else{

?>	
<!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.png" />
<link href="../../../cms1.css" rel="stylesheet" type="text/css" /> 
<script src="../../../scripts/gen_validatorv4.js" type="text/javascript"></script>
</head>
<body>
<script>top.document.title=self.document.title;</script>
	<div>
		<fieldset>
		<legend><?php echo $mode ?></legend>
				<div class="critical" id="change_pass_errorloc">
				</div>
			<div class="align-left">
   			<form name="change_pass" id="change_pass" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
   			  <table cellpadding="0" cellspacing="0"  class="width-100-percent">
                <tr>
                  <td class="align-left" width="160"><label class="labels"><?php echo $lbl_grid_username ?></label></td>
                  <td><input type="text" name="usaname" class="addform" disabled="disabled" value="<?php echo $user; ?>"/></td>
                </tr>
                <tr>
                  <td class="align-left"><label class="labels"><?php echo $lbl_grid_default_printer ?></label></td>
                  <td><select name="f1default" class="addform_drop">
                      <?php 
							//QUERY TO DATABASE - TABLE USERTYPES TP POPULATE DROPDOWN MENU
							$sql="SELECT * FROM core_printers WHERE active='1'";
							$result = mysqli_query($mysqli, $sql);
							echo "<option value=\"\">$lbl_pick_list</option>";
							while($row = mysqli_fetch_assoc($result)){
							echo "<option value=\"{$row['id']}\">{$row['alias']}</option>"; }
							?>
                    </select>
                  </td>
                </tr>
   			    <tr>
   			      <td  colspan="2" class="align-right"><input name="but_submit" type="submit" class="button" value="<?php echo $lbl_button_save ?>" />
                      <input name="but_back" type="button" class="button" value="<?php echo $lbl_button_back ?>" onclick="window.location='../../../main.php';" />
                  </td>
		        </tr>
              </table>
   			</form>
						<script type="text/javascript">
						 var frmvalidator  = new Validator("change_pass");
							frmvalidator.EnableOnPageErrorDisplaySingleBox();
							frmvalidator.EnableMsgsTogether();
							frmvalidator.addValidation("newpass1","req","<?php echo $lbl_error_pass_req ?>");
							frmvalidator.addValidation("newpass1","minlen=5","<?php echo $lbl_error_pass_min_len_5 ?>");
							frmvalidator.addValidation("newpass1","eqelmnt=newpass2", "<?php echo $lbl_error_pass_confirm ?>");

					</script>
			</div>
		</fieldset>
	</div>
</body>
</html>
	<?php //not submitted
    }
mysqli_close($mysqli);
} else {
    header('Location: login.php');
}
?>
