<?php
session_name("AUTHENUSER");
session_start();
$USERNAME = $_SESSION['SES_USERNAME'];
if(!session_name("AUTHENUSER"))
	{
?>
						<script language="javascript">
						 alert("Waktu Login telah habis.Silahkan Login Kembali");
						document.location="index.php";
						</script>
<?php
	}
if(!$USERNAME)
	{
?>
						<script language="javascript">
						 alert("Harap Login Dahulu.");
						document.location="index.php";
						</script>
<?php
	}
	?>
	<?php include "common/config.php";
	include "include/head.php"; ?>?>
     <?php
	$act  = $_REQUEST['act'];
	
	if($act == 1)
	{
		$old  = $_REQUEST['old'];
		$new  = $_REQUEST['new'];
		$confirm  = $_REQUEST['confirmnew'];
		$query = mysql_num_rows(mysql_query("select password from tbl_admin where user_id = '$USERNAME' and password = '".md5($old)."'"));
		if($old == "")
	{
	?>
 <script language="javascript">
 	alert("Please input old password");
	document.location="change_password.php";
	</script>
 <?php
	}
	elseif($new == "")
	{
	?>
 <script language="javascript">
	alert("Please input new password");
	document.location="change_password.php";
	</script>
 <?php
	}
	elseif($confirm == "")
	{
	?>
 <script language="javascript">
	alert("Please input confirm new password");
	document.location="change_password.php";
	</script>
 <?php
	}
	elseif($query == 0)
	{
	?>
 <script language="javascript">
	alert("Wrong old password");
	document.location="change_password.php";
	</script>
 <?php
	}
	elseif($new <> $confirm)
	{
	?>
 <script language="javascript">
	alert("New password and Confirm New Password must same");
	document.location="change_password.php";
	</script>
 <?php
	}
	else
	{
			$update = mysql_query("update tbl_admin set password = '".md5($new)."' where user_id = '$USERNAME'");
			if($update)
			{
			?>
			<script language="javascript">
			alert("Successfully Change Password");
			document.location="logout.php";
			</script>
			<?php
			}
	}
	}
	?>
<body>
<?php include "include/head2.php"; ?>
<?php include "include/leftmenu.php"; ?>
<?php include "include/top.php"; ?>
  <h1><i class="icon-bar-chart"></i> Change Password</h1>
</div>

<!--<ol class="breadcrumb">
  <li><a href="#">Home</a></li>
  <li><a href="#">Bread</a></li>
  <li><a href="#">Crumbs</a></li>
  <li class="active">Example</li>
</ol>-->
          <div class="main-content">
            <div class="row">
                <div class="widget">
                  <div class="widget-content-white glossed">
                    <div class="padded">
                      <form method="post" action="change_password.php?act=1" role="form" class="form-horizontal">
                        <div class="form-group">
                          <label class="col-md-4 control-label">Old Password</label>
                          <div class="col-md-8">
                            <input type="password" class="form-control" placeholder="Enter Old Password" name="old" id="old">
                          </div>
                        </div>
                        <div class="form-group">
                          <label class="col-md-4 control-label">New Password</label>
                          <div class="col-md-8">
                            <input type="password" class="form-control" placeholder="Enter New Password"  name="new" id="new">
                          </div>
                        </div>
                        <div class="form-group">
                          <label class="col-md-4 control-label">Confirm New Password</label>
                          <div class="col-md-8">
                            <input type="password" class="form-control" placeholder="Enter Confirm New Password" name="confirmnew" id="confirmnew">
                          </div>
                        </div>
                   
                        <div class="form-group">
                          <div class="col-md-offset-4 col-md-8">
                            <button type="submit" class="btn btn-default">Submit</button>
                          </div>
                        </div>
                      </form>
                    </div>
                    </div>
                    </div>
                    </div>
                    </div>
                   

<?php include "include/foot.php"; ?>
<script src='assets/js/for_pages/dashboard.js'></script>
</body>

</html>