<?php
require ("../connect.php");
require ("../user.php");
$role_code1=$_REQUEST['role_id'];
 $smc=$_REQUEST['smc'];
?>
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
		<link rel="icon" href="logo.png" sizes="50x50" type="image/png">
        <meta name="description" content="">
        <meta name="author" content="">

        <title>Professional</title>

         <link href="../css/bootstrap.min.css" rel="stylesheet">

        <!-- MetisMenu CSS -->
        <link href="../css/metisMenu.min.css" rel="stylesheet">

        <!-- Custom CSS -->
        <link href="../css/startmin.css" rel="stylesheet">

        <!-- Custom Fonts -->
        <link href="../css/font-awesome.min.css" rel="stylesheet" type="text/css">
		
		        <link rel="stylesheet" href="../css/sweet-alert.css" />   
<!--datatables-->

<link  href="../css/dataTables/dataTables.min.css" rel="stylesheet" type="text/css">
 
                <script type="text/javascript" src="../js/dataTables.min.js" ></script>

  
  </head>
  <body>
  <style>
.loader {
    position: fixed;
    left: 0px;
    top: 0px;
    width: 100%;
    height: 100%;
    z-index: 9999;
    background: url('../images/pageLoader.gif') 50% 50% no-repeat rgb(249,249,249);
    opacity: .8;
}
</style>
<div class="loader"></div>
  <?php
require("header.php");
?>


        <div id="wrapper">

        

            <div id="page-wrapper">
                <div class="row">
                    <div class="col-lg-12">
                       <h4 class="page-header">Edit Role </h4>
						<a href="role_master.php?smc=<?php echo $smc;?>"> <button style="margin-bottom:25px;"  type="button" class="btn btn-success"><i class="fa fa-backward"></i>Back</button></a>
                    </div>
                    <!-- /.col-lg-12 -->
                </div>
                <!-- /.row -->
                <div class="row">
                    <div class="col-lg-12">
                        <div class="panel panel-default">
                            
                                       <form class="form-floating" id="form-validation" name="area"  method="post">
                     
                      
						<div class="form-group">
					<?php 
						$role=mysql_fetch_array(mysql_query("select * from role_master where code='$role_code1'"));
						$r_name=$role['role_name'];
					?>
                      <label for="exampleInputEmail1">Role Name</label>
                      <input type="text"  id="role_name" name="role_name" value="<?php echo $r_name;  ?>" class="" autocomplete="off">
                    </div>
                    <?php
			 $menu=mysql_query("select id,menu_code from menu_master order by id");
			  $r=1;
			while($menu_code=mysql_fetch_array($menu)) 
			{
				
				?><b style="padding: 5px 0px;color:blue;"><?php echo $menu_code['menu_code']; ?></b><br>
				<?php
				 $men=$menu_code['id']; 
				 
				  $submenu=mysql_query("select m.menu_name,s.submenu_code,r.view_only,r.approval,r.submenu_id from role_detail r right join menu_master m on r.menu_id=m.id right join submenu_master s on r.submenu_id=s.id where r.code='$role_code1' and r.menu_id='$men' order by r.id  ");
				  
				  //echo "select m.menu_name,s.submenu_code,r.view_only,,r.approvalr.submenu_id from role_detail r join menu_master m on r.menu_id=m.id join submenu_master s on r.submenu_id=s.id where r.code='$role_code1' and r.menu_id='$men' order by r.id  ";
				 
				  while($sub_menu_code=mysql_fetch_array($submenu)) { 
					  $ck=$sub_menu_code['view_only'];
					$app=$sub_menu_code['approval'];
					  $sid=$sub_menu_code['submenu_id'];
					  $s=1;
				?>
				<div style="width:100%;float:left;padding: 5px 0px;">
				<input class="checkbox" style="width:2%;float:left;" type="checkbox" name="checkbox<?php echo $r;?>" id="checkbox<?php echo $r;?>" onclick="enablebox(this.id)"/>
				<div style="width:30%;float:left;">&emsp;<?php echo $sub_menu_code['submenu_code']; ?></div>
					 <input type="hidden"  id="menu" name="menu[]" class="form-control"  value="<?php echo $men.":".$sid;?>" >
				 <input type="hidden"  id="submenu" name="submenu[]" class="form-control"  value="<?php echo $sid;?>" >
				<?php
				if ($ck=="View")
				{
					?>
					<div style="width:10%;float:left;"><input type="radio" name="new<?php echo $r ; ?>" id="new<?php echo $r.$s++ ; ?>" checked value="View"  />&emsp;VIEW</div>
				<div style="width:10%;float:left;"><input type="radio" name="new<?php echo $r ; ?>" id="new<?php echo $r.$s++ ; ?>" value="Edit"  />&emsp;EDIT</div>
				<div style="width:10%;float:left;"><input type="radio" name="new<?php echo $r ; ?>" id="new<?php echo $r.$s++ ; ?>"  value="All"   />&emsp;ALL</div>
				</div>
					<?php
				}
				elseif ($ck=="Edit")
				{
					?>
					<div style="width:10%;float:left;"><input type="radio" name="new<?php echo $r ; ?>" id="new<?php echo $r.$s++ ; ?>" value="View"  />&emsp;VIEW</div>
				<div style="width:10%;float:left;"><input type="radio" name="new<?php echo $r ; ?>" id="new<?php echo $r.$s++ ; ?>" checked value="Edit"  />&emsp;EDIT</div>
				<div style="width:10%;float:left;"><input type="radio" name="new<?php echo $r ; ?>" id="new<?php echo $r.$s++ ; ?>"  value="All"   />&emsp;ALL</div>
				</div>
					<?php
				}
				elseif ($ck=="All")
				{
					?>
					<div style="width:10%;float:left;"><input type="radio" name="new<?php echo $r ; ?>" id="new<?php echo $r.$s++ ; ?>" value="View"/>&emsp;VIEW</div>
				<div style="width:10%;float:left;"><input type="radio" name="new<?php echo $r ; ?>" id="new<?php echo $r.$s++ ; ?>" value="Edit"  />&emsp;EDIT</div>
				<div style="width:10%;float:left;"><input type="radio" name="new<?php echo $r ; ?>" id="new<?php echo $r.$s++ ; ?>" checked value="All"   />&emsp;ALL</div>
				</div>
					<?php
				}
				elseif ($ck=="")
				{
					?>
					<div style="width:10%;float:left;"><input type="radio" name="new<?php echo $r ; ?>" id="new<?php echo $r.$s++ ; ?>" value="View"  />&emsp;VIEW</div>
				<div style="width:10%;float:left;"><input type="radio" name="new<?php echo $r ; ?>" id="new<?php echo $r.$s++ ; ?>" value="Edit"  />&emsp;EDIT</div>
				<div style="width:10%;float:left;"><input type="radio" name="new<?php echo $r ; ?>" id="new<?php echo $r.$s++ ; ?>"  value="All"   />&emsp;ALL</div>
				</div>
					<?php
				}
				  $r++;
				  }
			}
			 
			 ?>
			   <table class="table table-hover" style="font-family:'Times New Roman', Times, serif">
			  
</table>
 <div class="form-group">
                    <input type="submit" class="btn btn-success" value="Submit" name="submit">
                  </div>
                  </div><!-- /.box-body -->

                 
				  <input type="hidden" name="formsent">
                    </form>
                                    </div>
                                    <!-- /.col-lg-6 (nested) -->

                                    <!-- /.col-lg-6 (nested) -->
                                </div>
                                <!-- /.row (nested) -->
                            </div>
                            <!-- /.panel-body -->
                        </div>
                        <!-- /.panel -->
                    </div>
                    <!-- /.col-lg-12 -->
              

          <script src="../js/jquery.min.js"></script>

        <!-- Bootstrap Core JavaScript -->
        <script src="../js/bootstrap.min.js"></script>

        <!-- Metis Menu Plugin JavaScript -->
        <script src="../js/metisMenu.min.js"></script>


        <!-- DataTables JavaScript -->
        <script src="../js/dataTables/jquery.dataTables.min.js"></script>
        <script src="../js/dataTables/dataTables.bootstrap.min.js"></script>

        <!-- Custom Theme JavaScript -->
        <script src="../js/startmin.js"></script>
		
		 <script src="../js/sweet-alert.js"></script>

        <!-- Page-Level Demo Scripts - Tables - Use for reference -->
        <script>
            $(document).ready(function() {
				$(".loader").fadeOut("slow");

                $('#dataTables-example').DataTable({
                        responsive: true
                });
            });
        </script>

<?php
require("footer.php");
?>
    </body>
</html>

<?php
			require ("checkbox.js");
	?> 
<?php  
if(isset($_REQUEST['formsent']))
{
	$role_name=$_REQUEST['role_name'];
	$approve=$_REQUEST['approve'];
	$menu=$_REQUEST['menu'];
	$cnt=count($menu);	 
	
	$n=mysql_query("update role_master set role_name='$role_name' where code='$role_code1'");
		
	
	for($r=0;$r<$cnt;$r++)
	{
		$ra="new".($r+1);
		$new=$_REQUEST[$ra];
		$me=explode(":",$menu[$r]);
		$date=date("Y-m-d");
		$detail=mysql_query("update role_detail set view_only='$new',approval='$approve',modified_by='$user',modified_on='$date' where code='$role_code1' and menu_id='$me[0]' and submenu_id='$me[1]'");
		//echo "update role_detail set view_only='$new',approval='$approve',modified_by='$user',modified_on='$date' where code='$role_code1' and menu_id='$me[0]' and submenu_id='$me[1]'";
	}
	
	if($n)
	{?>
	<script>
    setTimeout(function() {
        swal({
            title: "Successfully",
            text: "Completed!",
            type: "success"
        }, function() {
			var manuid="<?php echo $smc;?>";
            window.location = "role_master.php?smc="+manuid;
        });
    }, 100);
</script> 
    <?php
	}	
	else
	{
	?><script>
    setTimeout(function() {
        swal({
            title: "Not",
            text: "Completed!",
            type: "error"
        }, function() {
				var manuid="<?php echo $smc;?>";
            window.location = "../settings/role_master.php?smc="+manuid;
        });
    }, 100);
</script> 	 
    <?php
	}
}