<?php
session_start();
include("systemControler.php");
ob_start();
ini_set('session.bug_compat_warn', 0);
ini_set('session.bug_compat_42', 1);
include("db.php");
include("jdf.php");
 $pdate1=jdate("Y-m-d");
  
 //$date = "1998-08-14";
 

$page_title = "ورود به سیستم";

    unset($_SESSION['userName']);
	unset($_SESSION['password']);  
if(isset($_POST['submit'])){

        $day   =$_POST['day'];
        $month =$_POST['month'];
        $year  =$_POST['year'];

        $todaydate=$year."-".$month."-".$day;
		$miladi=jalali_to_gregorian($year,$month,$day,'-');
		 
		$username=$_POST['username'];
		$password=$_POST['password'];
		$newpassword = md5($password);
		
	    $sql="SELECT * FROM admin WHERE username='$username' AND password='$newpassword'";
	    $res = $db->query($sql);
		$row=$res ->fetch_array();
		
		 $username=$row['username'];
		 
		$password=$row['password'];
		
		 
       if(isset($username) and isset($password)){
	     //=======Checking Dailly Asset============================================
	            $checkingAsset_sql="select * from dailyasset where date='$previousDate' ";
	            $checkingAsset_Query= $db ->query($checkingAsset_sql);
				$checkingAsset_Row=$checkingAsset_Query ->fetch_array();
	            $checkingAsset=$checkingAsset_Row['amount'];
				
				 $_SESSION['username']=$username;
	             $_SESSION['password']=$password;
				 
				if(!isset($checkingAsset)){
				 $emptyTable_sql="TRUNCATE today_date";
				 $emptyTable_query= $db ->query($emptyTable_sql);
				 
				 $insert_date_sql="insert into today_date(date,miladi) value('$todaydate','$miladi')";
				 $insert_date_query=$db ->query($insert_date_sql);
				 
				 
				 // header("Location: backup_1.php");
				  header("Location: index.php");
				
				}
				if(isset($checkingAsset)){
				
				 header("Location: index.php");
				
				}	
	   }
       else{
	     $error="نام کاربری یا رمز عبور را اشتباه وارد کرده اید";
	   
	   }
	}  
?>
<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]> <html lang="en" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<html lang="en" dir="rtl">
<!--<![endif]-->
<!-- BEGIN HEAD -->
<head>
<meta charset="utf-8"/>
<title><?php echo $page_title;?></title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta content="width=device-width, initial-scale=1.0" name="viewport"/>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<meta content="" name="description"/>
<meta content="" name="author"/>
<!-- BEGIN GLOBAL MANDATORY STYLES -->
<link href="../../assets/global/plugins/simple-line-icons/simple-line-icons.min.css" rel="stylesheet" type="text/css"/>
<link href="../../assets/global/plugins/bootstrap/css/bootstrap-rtl.min.css" rel="stylesheet" type="text/css"/>
<link href="../../assets/global/plugins/uniform/css/uniform.default.css" rel="stylesheet" type="text/css"/>
<!-- END GLOBAL MANDATORY STYLES -->
<!-- BEGIN PAGE LEVEL STYLES -->
<link href="../../assets/admin/pages/css/login-rtl.css" rel="stylesheet" type="text/css"/>
<!-- END PAGE LEVEL SCRIPTS -->
<!-- BEGIN THEME STYLES -->
<link href="../../assets/global/css/components-md-rtl.css" id="style_components" rel="stylesheet" type="text/css"/>
<link href="../../assets/global/css/plugins-md-rtl.css" rel="stylesheet" type="text/css"/>
<link href="../../assets/admin/layout/css/layout-rtl.css" rel="stylesheet" type="text/css"/>
<link href="../../assets/admin/layout/css/themes/darkblue-rtl.css" rel="stylesheet" type="text/css" id="style_color"/>
<link href="../../assets/admin/layout/css/custom-rtl.css" rel="stylesheet" type="text/css"/>
<!-- END THEME STYLES -->
<link rel="shortcut icon" href="favicon.ico"/>
</head>
<!-- END HEAD -->
<!-- BEGIN BODY -->
<body class="page-md login">
<!-- BEGIN SIDEBAR TOGGLER BUTTON -->
<div class="menu-toggler sidebar-toggler">
</div>
<!-- END SIDEBAR TOGGLER BUTTON -->
<!-- BEGIN LOGO -->
<div class="logo">
	<!--<a href="index.php">
	<img src="logo.png" alt="logo"/>
	</a>-->
</div>
<!-- END LOGO -->
<!-- BEGIN LOGIN -->
<div class="content">
	<!-- BEGIN LOGIN FORM -->
	<form class="login-form" action="login.php" method="post">
	 
	      <div style="border: 0px solid #000;text-align: center;color: red;font-weight: bold">
		  <?php  echo $error ?>
		  
		  </div> 
		  <div style="margin: auto;border: 0px solid red;text-align: center"><img src="off/logo.png" style="width:100px;height: 160px"></div>
		<h3 class="form-title">ورود به سیستم</h3>
		
		<div class="form-group">
			<!--ie8, ie9 does not support html5 placeholder, so we just show field title for that-->
			<label class="control-label visible-ie8 visible-ie9">Username</label>
			<input class="form-control form-control-solid placeholder-no-fix" type="text" name="username"   autocomplete="off" placeholder="اسم کاربر" name="username"/>
		</div>
		<div class="form-group">
			<label class="control-label visible-ie8 visible-ie9">Password</label>
			<input class="form-control form-control-solid placeholder-no-fix" type="password" name="password"  autocomplete="off" placeholder="رمز کاربر" name="password"/>
		</div>
		<div class="form-group">
			 <table border='0' style='width: 100%' dir="rlt">
			 <tr>
			     <td>تاریخ</td>
			     <td><?php include("datepicker.php"); ?></td>
			 </tr>
			 </table>
			 
		</div>
		
		
		<div class="form-actions">
			<button type="submit" class="btn btn-success uppercase" name="submit">ورود</button>
			<label class="rememberme check">
			<!--<input type="checkbox" name="remember" />از سیستم خارج نشوم </label>
			<a href="javascript:;" id="forget-password" class="forget-password">رمز را فراموش کرده ام</a>-->
		</div>
		<div class="create-account" style="height: 60px">
			<!--<p>
				<a href="javascript:;" id="register-btn" class="uppercase">ایجاد حساب جدید</a>
			</p>-->
		</div>
	</form>
	<!-- END LOGIN FORM -->
	<!-- BEGIN FORGOT PASSWORD FORM -->
	<form class="forget-form" action="index.php" method="post">
		<!--<h3>رمز را فراموش کرده اید؟</h3>
		<p>
			برای عوض کردن رمز ورود لطفا ایمیل آدرس خود را وارد کنید
		</p>-->
		<div class="form-group">
			<input class="form-control placeholder-no-fix" type="text" autocomplete="off" placeholder="ایمیل" name="email"/>
		</div>
		<div class="form-actions">
			<button type="button" id="back-btn" class="btn btn-default">بازگشت</button>
			<button type="submit" class="btn btn-success uppercase pull-right">ادامه</button>
		</div>
	</form>
	<!-- END FORGOT PASSWORD FORM -->
	<!-- BEGIN REGISTRATION FORM -->
	<form class="register-form" action="index.html" method="post">
		<h3>Sign Up</h3>
		<p class="hint">
			 Enter your personal details below:
		</p>
		<div class="form-group">
			<label class="control-label visible-ie8 visible-ie9">Full Name</label>
			<input class="form-control placeholder-no-fix" type="text" placeholder="Full Name" name="fullname"/>
		</div>
		<div class="form-group">
			<!--ie8, ie9 does not support html5 placeholder, so we just show field title for that-->
			<label class="control-label visible-ie8 visible-ie9">Email</label>
			<input class="form-control placeholder-no-fix" type="text" placeholder="Email" name="email"/>
		</div>
		<div class="form-group">
			<label class="control-label visible-ie8 visible-ie9">Address</label>
			<input class="form-control placeholder-no-fix" type="text" placeholder="Address" name="address"/>
		</div>
		<div class="form-group">
			<label class="control-label visible-ie8 visible-ie9">City/Town</label>
			<input class="form-control placeholder-no-fix" type="text" placeholder="City/Town" name="city"/>
		</div>
		 
		<p class="hint">
			 Enter your account details below:
		</p>
		<div class="form-group">
			<label class="control-label visible-ie8 visible-ie9">Username</label>
			<input class="form-control placeholder-no-fix" type="text" autocomplete="off" placeholder="Username" name="username"/>
		</div>
		<div class="form-group">
			<label class="control-label visible-ie8 visible-ie9">Password</label>
			<input class="form-control placeholder-no-fix" type="password" autocomplete="off" id="register_password" placeholder="Password" name="password"/>
		</div>
		<div class="form-group">
			<label class="control-label visible-ie8 visible-ie9">Re-type Your Password</label>
			<input class="form-control placeholder-no-fix" type="password" autocomplete="off" placeholder="Re-type Your Password" name="rpassword"/>
		</div>
		<div class="form-group margin-top-20 margin-bottom-20">
			<label class="check">
			<input type="checkbox" name="tnc"/> I agree to the <a href="javascript:;">
			Terms of Service </a>
			& <a href="javascript:;">
			Privacy Policy </a>
			</label>
			<div id="register_tnc_error">
			</div>
		</div>
		<div class="form-actions">
			<button type="button" id="register-back-btn" class="btn btn-default">Back</button>
			<button type="submit" id="register-submit-btn" class="btn btn-success uppercase pull-right">Submit</button>
		</div>
	</form>
	<!-- END REGISTRATION FORM -->
</div>
<div class="copyright">
	<!--HeratHost IT Service Co &copy; 2014-->
</div>
<!-- END LOGIN -->
<!-- BEGIN JAVASCRIPTS(Load javascripts at bottom, this will reduce page load time) -->
<!-- BEGIN CORE PLUGINS -->
<!--[if lt IE 9]>
<script src="../../assets/global/plugins/respond.min.js"></script>
<script src="../../assets/global/plugins/excanvas.min.js"></script> 
<![endif]-->
<script src="../../assets/global/plugins/jquery.min.js" type="text/javascript"></script>
<script src="../../assets/global/plugins/jquery-migrate.min.js" type="text/javascript"></script>
<script src="../../assets/global/plugins/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
<script src="../../assets/global/plugins/jquery.blockui.min.js" type="text/javascript"></script>
<script src="../../assets/global/plugins/jquery.cokie.min.js" type="text/javascript"></script>
<script src="../../assets/global/plugins/uniform/jquery.uniform.min.js" type="text/javascript"></script>
<!-- END CORE PLUGINS -->
<!-- BEGIN PAGE LEVEL PLUGINS -->
<script src="../../assets/global/plugins/jquery-validation/js/jquery.validate.min.js" type="text/javascript"></script>
<!-- END PAGE LEVEL PLUGINS -->
<!-- BEGIN PAGE LEVEL SCRIPTS -->
<script src="../../assets/global/scripts/metronic.js" type="text/javascript"></script>
<script src="../../assets/admin/layout/scripts/layout.js" type="text/javascript"></script>
<script src="../../assets/admin/layout/scripts/demo.js" type="text/javascript"></script>
<script src="../../assets/admin/pages/scripts/login.js" type="text/javascript"></script>
<!-- END PAGE LEVEL SCRIPTS -->
<script>
jQuery(document).ready(function() {     
Metronic.init(); // init metronic core components
Layout.init(); // init current layout
Login.init();
Demo.init();
});
</script>
<!-- END JAVASCRIPTS -->
</body>
<!-- END BODY -->
</html>