<?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";

	$act  = $_REQUEST['act'];
	$user_id  = $_REQUEST['user_id'];
	
	if($act == 1)
	{
		$user_id  = $_REQUEST['user_id'];
		$new  = $_REQUEST['new'];
		$confirm  = $_REQUEST['confirmnew'];
		$branch  = $_REQUEST['branch'];
		$query = mysql_num_rows(mysql_query("select user_id from tbl_admin where user_id = '$user_id'"));
		if($query >= 1)
	{
	?>
 <script language="javascript">
 	alert("Username already exists");
	document.location="add_user.php";
	</script>
 <?php
	}
	elseif($user_id == "")
	{
	?>
 <script language="javascript">
	alert("Please input username");
	document.location="add_user.php";
	</script>
 <?php
	}
	elseif($new == "")
	{
	?>
 <script language="javascript">
	alert("Please input new password");
	document.location="add_user.php";
	</script>
 <?php
	}
	elseif($confirm == "")
	{
	?>
 <script language="javascript">
	alert("Please input confirm new password");
	document.location="add_user.php";
	</script>
 <?php
	}
	elseif($new <> $confirm)
	{
	?>
 <script language="javascript">
	alert("New password and Confirm New Password must same");
	document.location="add_user.php";
	</script>
 <?php
	}
	else
	{
			$update = mysql_query("insert tbl_admin (user_id,id_branch,password) values ('$user_id','$branch','".md5($new)."')");
			if($update)
			{
			?>
			<script language="javascript">
			alert("Successfully Add User");
			document.location="master_user.php";
			</script>
			<?php
			}
	}
	}
	?>
<body>
<?php include "include/head2.php"; ?>
<?php include "include/leftmenu.php"; ?>
<?php include "include/top.php"; ?>
  <h1><i class="icon-user"></i> Add User</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="add_user.php?act=1" role="form" class="form-horizontal">
                        <div class="form-group">
                          <label class="col-md-4 control-label">Username</label>
                          <div class="col-md-8">
                            <input type="text" class="form-control" name="user_id" id="user_id" >
                          </div>
                        </div>
                        <div class="form-group">
                          <label class="col-md-4 control-label">Branch</label>
                          <div class="col-md-8">
                            <select class="form-control" name="branch" id="branch">
                              <?php
                                              $sql3 = "select * from tbl_branch where status_branch=1 order by nama_branch";
                                              $rs3 = mysql_query($sql3);
                                              while($fetch3 = mysql_fetch_array($rs3))
                                              {
                                               ?>
                                          <option  value="<?php echo $fetch3['id_branch']; ?>"><?php echo $fetch3['nama_branch']; ?></option>
                                                      <?php
                                              }
                                             ?>
                            </select>
                          </div>
                        </div>
                        <div class="form-group">
                          <label class="col-md-4 control-label"> Password</label>
                          <div class="col-md-8">
                            <input type="password" class="form-control" placeholder="Enter Password"  name="new" id="new">
                          </div>
                        </div>
                        <div class="form-group">
                          <label class="col-md-4 control-label">Confirm Password</label>
                          <div class="col-md-8">
                            <input type="password" class="form-control" placeholder="Enter Confirm 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>
                            <button type="reset" class="btn btn-default">Reset</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>