<?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 = trim($_REQUEST['user_id']);
		$ubah = trim($_REQUEST['ubah']); //echo $ubah; exit;
		$menu = $_POST['klik'];
		if(isset($_POST['Submit']))
		{
				$total = count($_POST['klik']);
				if($total == 0)
				{	
			
				?>
				<script language="javascript">
						alert("Please Choose Menu");
                        document.location="setting_menu.php?act=3&user_id=<?php echo $user_id; ?>";
                </script>
			<?php
                    }
                    else
                    {			
								$sql = mysql_query("delete from  tbl_priviledge where user_id = '$user_id' ");
									for($i=0; $i<count($_POST['klik']); $i++)
								{
									$q = mysql_query("INSERT INTO tbl_priviledge (user_id,ubah,id_application) VALUES ('$user_id','$ubah',trim('".$_POST['klik'][$i]."'))");
								}
			}
		}
			if($q)
			{	
		
		?>
					<script language="javascript">
							document.location="master_menu.php";
					</script>
	
		<?php				
			}
	}
	?>
<script language="javascript">
function semua()
{
	document.location="setting_menu.php?act=2&user_id=<?php echo $_REQUEST['user_id']; ?>&ubah=<?php echo $_REQUEST['ubah']; ?>";
}

function semua1()
{
	document.location="setting_menu.php?act=3&user_id=<?php echo $_REQUEST['user_id']; ?>&ubah=<?php echo $_REQUEST['ubah']; ?>";
}

</script>
<?php if($act == 3) { ?>
<body>
<?php include "include/head2.php"; ?>
<?php include "include/leftmenu.php"; ?>
<?php include "include/top.php"; ?>
  <h1><i class="icon-flag"></i> Edit 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="setting_menu.php?act=1&user_id=<?php echo $user_id; ?>" 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" value="<?php echo $user_id; ?>" readonly="readonly">
                          </div>
                        </div>
                        <div class="form-group">
                          <label class="col-md-4 control-label">Menu Name</label>
                          <div class="col-md-offset-4 col-md-8">
                            <div class="checkbox">
                            <input type="checkbox" name="checkbox" id="checkbox" value="0" onClick="semua()">Semua</br>
                                   <?php $sql = mysql_query("select * from tbl_application"); 
									while($fetch = mysql_fetch_array($sql)) { ?>
                                    <input type="checkbox"  name="klik[]" id="klik[]" value="<?php echo $fetch['id_application']; ?>">
                                    <?php echo $fetch['application'];?></br>
                                    <?php } ?>
                            </div>
                        </div>
                       </div>
                   
                        <div class="form-group">
                          <div class="col-md-offset-4 col-md-8">
                            <button type="submit" name="Submit" value="Submit" id="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>
<?php }elseif($act == 2) { ?>
<body>
<?php include "include/head2.php"; ?>
<?php include "include/leftmenu.php"; ?>
<?php include "include/top.php"; ?>
  <h1><i class="icon-bar-chart"></i> Edit 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="setting_menu.php?act=1&user_id=<?php echo $user_id; ?>" 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" value="<?php echo $user_id; ?>" readonly="readonly">
                          </div>
                        </div>
                        <div class="form-group">
                          <label class="col-md-4 control-label">Menu Name</label>
                          <div class="col-md-offset-4 col-md-8">
                            <div class="checkbox">
                            <input type="checkbox" name="checkbox" id="checkbox" value="0" onClick="semua1()">Semua</br>
                                    <?php $sql = mysql_query("select * from tbl_application"); 
									while($fetch = mysql_fetch_array($sql)) { ?>
                                    <input type="checkbox"  name="klik[]" id="klik[]" value="<?php echo $fetch['id_application']; ?>" checked="checked">
                                    <?php echo $fetch['application'];?></br>
                                    <?php } ?>
                            </div>
                        </div>
                       </div>
                   
                        <div class="form-group">
                          <div class="col-md-offset-4 col-md-8">
                            <button type="submit" name="Submit" value="Submit" id="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>
<?php } ?>
</html>