<?php
session_start();
?>

<!DOCTYPE html>
<html>
    <head>
 <?php include("header-js.php");?>	
		
<!-----hrm-------------->		
<link rel="stylesheet" href="css/style.css" />
<!-- Responsive -->
<link rel="stylesheet" href="css/responsive.css" />

<script src="js/jquery-ui.js"></script>
<link rel="stylesheet" href="css/jquery-ui.css" />

<!-----hrm-------------->

    </head>


    <body class="skin-blue">
 <?php 
	include("header.php");
	$users = $db->fetchQuery('select * from menu where sort_order!=0');
	 $count  =   mysql_num_rows(mysql_query('select * from menu where sort_order!=0'));
	$userss =$_GET['id'];
	
	 $user_name =  mysql_fetch_array(mysql_query("SELECT * FROM employee where e_id='$userss'"));
	 
	  $deisgss =  mysql_fetch_array(mysql_query("SELECT * FROM designation where desig_id=7"));
	  
	 $thePostIdArray = explode(',', $deisgss['desig_rights']);
	// print_r($thePostIdArray);
?>

                    <!-- Small boxes (Stat box) -->
                    

                    <!-- Main row -->
                    <div class="row">
                    
					<div id="wrapper">



<div class="content">

<div class="report-tab">
<div class="employee-title">
<div class="report-left"><h2><translate>User Settings</translate> <span></span></h2></div>

<!-- /report-category -->
<div class="clear-float"></div>
</div><!-- /employee-title -->


<div class="clear-float"></div>

<div class="report-cell-02" id="m_divs">
<form name="mforms" id="mforms" method="post">

<table width="100%" border="0" cellspacing="0" cellpadding="0" class="list-leavesu">
								  <tr><td style="border-right:0px;"><a href="user_settings.php"><img src="images/back1.png" width="40px;"></a></td>
			<td width="15%" colspan="7" style="border-left:0px;" align="center"><b><translate>PRIVILEGE SETTINGS OF <?php echo $user_name['e_fname'];?></translate></b></td></tr>
											
										  <tr>
											<td width="15%"><translate>Main Menu</translate></td>
											<td width="15%"><translate></translate></td>
											<td width="15%"><translate>Add</translate></td>
											<td width="10%"><translate>Edit</translate></td>
											<td width="10%"><translate>View</translate></td>
											<td width="10%"><translate>Delete</translate></td>
											<td width="10%"><translate>Select All</translate></td>
											<td width="5%"><translate>Action</translate></td>
										 </tr>
<?php $chkcnt=0; $chkcntedt=0; $chkcntvw=0;$chkcntdel=0; $s_cnt=0; $rcnt=0; $sub_rcnt=0; foreach($users as $usrs){ $rcnt=$rcnt+1;
											 
											 $sub_loop=mysql_query("select * from menu_sub where menu_id='$usrs[menu_id]' and flag1=0");
					                         $qury_cnt=mysql_num_rows($sub_loop);
											 
$select_usr_rights=mysql_fetch_array(mysql_query("select * from tbl_user_rights where m_menu_id='$usrs[menu_id]' and s_submenu_id=0 and user_id='$user_name[e_id]'"));

										
											 
											 ?>
											 
											 
<?php 
if($select_usr_rights['add_right']==1 ){ $chkcnt=$chkcnt+1;} 
if($select_usr_rights['edit_right']==1 ){ $chkcntedt=$chkcntedt+1;} 
if($select_usr_rights['view_right']==1 ){ $chkcntvw=$chkcntvw+1;} 
if($select_usr_rights['delete_right']==1 ){ $chkcntdel=$chkcntdel+1;}  
 //&& $sub_rights['edit_right']==1 && $sub_rights['view_right']==1 && $sub_rights['delete_right']==1
 ?>
 								 
											 
<tr class="reportime_users<?php echo $usrs['menu_id'];?>" id="parent_expand<?php echo $rcnt;?>">
<td width="15%" id="m_list<?php echo $rcnt;?>"><?php echo $usrs['menu_name'];?><input type="hidden" name="m_menuid<?php echo $rcnt;?>" id="m_menuid<?php echo $rcnt;?>" value="<?php echo $usrs['menu_id'];?>"></td>
<?php if($qury_cnt >0){?>
<td width="15%" id="m_exp<?php echo $rcnt;?>" onClick="row_expan('<?php echo $rcnt;?>','<?php echo $count;?>')"  ><icon id="icons<?php echo $rcnt; ?>" class="glyphicon glyphicon-plus"></i></td>
<?php } else {?>
		<td width="15%"   id="m_exp<?php echo $rcnt;?>"></td>
<?php } ?>	

	
	<td width="15%" id="m_add<?php echo $rcnt;?>">
	<?php if($usrs['add_right']==1){?>
<input type="checkbox" name="chkadd<?php echo $rcnt;?>" id="chkadd<?php echo $rcnt;?>" value="1"  <?php if($select_usr_rights['add_right']==1){?>checked="checked"<?php }?> onClick="chek_suball('<?php echo $rcnt;?>','<?php echo $s_cnt;?>','<?php echo $qury_cnt;?>',this,1);">
<?php } ?>	

</td>

	
<td width="5%" id="m_edit<?php echo $rcnt;?>">
<?php if($usrs['edit_right']==1){?>
<input type="checkbox" name="chkedit<?php echo $rcnt;?>" id="chkedit<?php echo $rcnt;?>" value="1"  <?php if($select_usr_rights['edit_right']==1){?>checked="checked"<?php }?> onClick="chek_suball('<?php echo $rcnt;?>','<?php echo $s_cnt;?>','<?php echo $qury_cnt;?>',this,2);">
<?php } ?>	

</td>

<td width="5%" id="m_view<?php echo $rcnt;?>">
<?php if($usrs['view_right']==1){?>
<input type="checkbox" name="chkeview<?php echo $rcnt;?>" id="chkeview<?php echo $rcnt;?>" value="1" <?php if($select_usr_rights['view_right']==1){?>checked="checked"<?php }?> onClick="chek_suball('<?php echo $rcnt;?>','<?php echo $s_cnt;?>','<?php echo $qury_cnt;?>',this,3);">
<?php } ?>
</td>

<td width="5%" id="m_del<?php echo $rcnt;?>">
<?php if($usrs['delet_right']==1){?>
<input type="checkbox" name="chkdel<?php echo $rcnt;?>" id="chkdel<?php echo $rcnt;?>" value="1" <?php if($select_usr_rights['delete_right']==1){?>checked="checked"<?php }?> onClick="chek_suball('<?php echo $rcnt;?>','<?php echo $s_cnt;?>','<?php echo $qury_cnt;?>',this,4);">
<?php } ?>
</td>


<?php if($select_usr_rights['add_right']==1 && $select_usr_rights['edit_right']==1 && $select_usr_rights['view_right']==1 && $select_usr_rights['delete_right']==1){?>
<td width="5%" id="m_act<?php echo $rcnt;?>"><input type="checkbox"  name="slect" id="slect" onClick="select_all('<?php echo $rcnt;?>',this);" checked="checked"></td>
<?php } else {?>
<td width="5%" id="m_act<?php echo $rcnt;?>"><input type="checkbox"  name="slect" id="slect" onClick="select_all('<?php echo $rcnt;?>',this);"></td>
<?php } ?>


					    <td width="5%" id="m_acts<?php echo $rcnt;?>"><icon class="glyphicon glyphicon-edit" onclick="update_main_menu('<?php echo $rcnt;?>');"></i></td>
													 </tr>
													 
													 
													 
						
						  <tr class="row_to_expand" style="display:none;" id="child_expand<?php echo $rcnt;?>">
			<td colspan="8">
				<table class="table table-bordered" width="80%">
					<thead>
						<tr style="background-color:#fff;color:#000">
							<th style="width:50%;" colspan="8"><center><translate>Update Submenus</translate></center></th>
						
						</tr>
					</thead>
					
					<tbody>
				<?php if($qury_cnt >0){?>
						<tr style="background-color:#fff;color:#000">
					
					<td >Sub Menu</td>
				<td ></td>
					
					<td>Add</td>
					<td>Edit</td>
					<td>View</td>
					<td>Delete</td>
					<td>Select All</td>
					<td>Action</td>
						</tr>
				<?php	
				
				
					
						$hrs=0; $s_chkcnt=0; $s_chkcntedt=0; $s_chkcntvw=0;$s_chkcntdel=0;
			while($row_sub=mysql_fetch_array($sub_loop))
			{
	
			$sub_rights=mysql_fetch_array(mysql_query("select * from tbl_user_rights where m_menu_id='$usrs[menu_id]' and s_submenu_id='$row_sub[s_id]' and user_id='$user_name[e_id]' "));
			$s_cnt=$s_cnt+1;
			$hrs=$hrs+1;
			
			
			
			
			$sub_loop_sub=mysql_query("select * from menu_sub where flag1='$row_sub[s_id]' ");
		    $sub_qury_cnt=mysql_num_rows($sub_loop_sub);
			
			
 ?>

<?php 
if($sub_rights['add_right']==1 ){ $s_chkcnt=$s_chkcnt+1;} 
if($sub_rights['edit_right']==1 ){ $s_chkcntedt=$s_chkcntedt+1;} 
if($sub_rights['view_right']==1 ){ $s_chkcntvw=$s_chkcntvw+1;} 
if($sub_rights['delete_right']==1 ){ $s_chkcntdel=$s_chkcntdel+1;}  
?>

			
			<tr style="background-color:#fff;color:#000" id="parent_expand_ss<?php echo $s_cnt;?>">
			
 <td ><?php echo $row_sub['s_menu_name'];?><input type="hidden" name="s_menuid<?php echo $s_cnt;?>" id="s_menuid<?php echo $s_cnt;?>" value="<?php echo $row_sub['s_id'];?>"></td>
			
	<?php if($sub_qury_cnt >0){?>
<td width="15%" id="m_sub_s<?php echo $s_cnt;?>" onClick="row_expan_sub('<?php echo $s_cnt;?>','<?php echo $count;?>')"  ><icon id="icons_sub<?php echo $s_cnt; ?>" class="glyphicon glyphicon-plus"></i></td>
<?php } else {?>
		<td width="15%"   id="m_exp<?php echo $rcnt;?>"></td>
<?php } ?>			
<td>
<?php if($row_sub['add_right']==1){?>

<input type="checkbox" name="s_chkadd<?php echo $s_cnt;?>" id="s_chkadd<?php echo $s_cnt;?>" value="1" <?php if($sub_rights['add_right']==1){?>checked="checked"<?php }?>></td>
<?php } ?>
<td>  
<?php if($row_sub['edit_right']==1){?>
 <input type="checkbox" name="s_chkedit<?php echo $s_cnt;?>" id="s_chkedit<?php echo $s_cnt;?>" value="1" <?php if($sub_rights['edit_right']==1){?>checked="checked"<?php }?>>
 <?php } ?>
 </td>
<td> 
<?php if($row_sub['view_right']==1){?>
<input type="checkbox" name="s_chkeview<?php echo $s_cnt;?>" id="s_chkeview<?php echo $s_cnt;?>" value="1" <?php if($sub_rights['view_right']==1){?>checked="checked"<?php }?>>
 <?php } ?>
</td>
<td> 
<?php if($row_sub['delet_right']==1){?>
 <input type="checkbox" name="s_chkdel<?php echo $s_cnt;?>" id="s_chkdel<?php echo $s_cnt;?>" value="1" <?php if($sub_rights['delete_right']==1){?>checked="checked"<?php }?>>
  <?php } ?>
 </td>

<?php if($sub_rights['add_right']==1 && $sub_rights['edit_right']==1 && $sub_rights['view_right']==1 && $sub_rights['delete_right']==1){?>
<td width="5%" id="m_act<?php echo $rcnt;?>"><input type="checkbox"  name="s_select" id="s_select" onClick="select_all_subs('<?php echo $s_cnt;?>',this);" checked="checked"></td>
<?php } else {?>
<td width="5%" id="m_act<?php echo $rcnt;?>"><input type="checkbox"  name="s_select" id="s_select" onClick="select_all_subs('<?php echo $s_cnt;?>',this);"></td>
<?php } ?>

			     <td><icon class="glyphicon glyphicon-edit" onclick="update_sub_menu('<?php echo $s_cnt;?>','<?php echo $rcnt;?>');"></i></td>
			 </tr >
			 
			 <tr class="row_to_expandss"  id="child_expandss<?php echo $s_cnt;?>" style="display:none;" title="child_expandss<?php echo $s_cnt;?>">
			 <td colspan="8">
			 
			 
			 <table class="table table-bordered"  width="80%">
			 
			 		<thead>
						<tr style="background-color:#fff;color:#000">
							<th style="width:50%;" colspan="8"><center><translate>Update Submenus</translate></center></th>
						
						</tr>
					</thead>
					
					
										<tbody>
				<?php if($sub_qury_cnt >0){?>
						<tr style="background-color:#fff;color:#000">
					
					<td >Sub Menu</td>
				<td ></td>
					
					<td>Add</td>
					<td>Edit</td>
					<td>View</td>
					<td>Delete</td>
					<td>Select All</td>
					<td>Action</td>
						</tr>
						
											
					<?php	$s_hrs=0; $s_chkcnt_s=0; $s_chkcntedt_s=0; $s_chkcntvw_s=0;$s_chkcntdel_s=0;
			while($row_sub_sub=mysql_fetch_array($sub_loop_sub))
			{  
			
			$sub_rcnt=$sub_rcnt+1;
			$s_hrs=$s_hrs+1;
			
			$sub_rights_sub=mysql_fetch_array(mysql_query("select * from tbl_user_rights where m_menu_id='$usrs[menu_id]' and s_submenu_id='$row_sub_sub[s_id]' and user_id='$user_name[e_id]' "));
			?>
	
		<?php 
if($sub_rights_sub['add_right']==1 ){ $s_chkcnt_s=$s_chkcnt_s+1;} 
if($sub_rights_sub['edit_right']==1 ){ $s_chkcntedt_s=$s_chkcntedt_s+1;} 
if($sub_rights_sub['view_right']==1 ){ $s_chkcntvw_s=$s_chkcntvw_s+1;} 
if($sub_rights_sub['delete_right']==1 ){ $s_chkcntdel_s=$s_chkcntdel_s+1;}  
?>		
				
							<tr style="background-color:#fff;color:#000" id="parent_expand_ss<?php echo $s_cnt;?>">
			
 <td ><?php echo $row_sub_sub['s_menu_name'];?><input type="hidden" name="s_menuid_s<?php echo $sub_rcnt;?>" id="s_menuid_s<?php echo $sub_rcnt;?>" value="<?php echo $row_sub_sub['s_id'];?>"></td>
			

		<td width="5%"   id="m_exp_ss<?php echo $rcnt;?>"></td>
		
<td>
<input type="checkbox" name="s_chkadd_s<?php echo $sub_rcnt;?>" id="s_chkadd_s<?php echo $sub_rcnt;?>" value="1" <?php if($sub_rights_sub['add_right']==1){?>checked="checked"<?php }?>></td>

<td>   <input type="checkbox" name="s_chkedit_s<?php echo $sub_rcnt;?>" id="s_chkedit_s<?php echo $sub_rcnt;?>" value="1" <?php if($sub_rights_sub['edit_right']==1){?>checked="checked"<?php }?>></td>
<td> <input type="checkbox" name="s_chkeview_s<?php echo $sub_rcnt;?>" id="s_chkeview_s<?php echo $sub_rcnt;?>" value="1" <?php if($sub_rights_sub['view_right']==1){?>checked="checked"<?php }?>></td>
<td>  <input type="checkbox" name="s_chkdel_s<?php echo $sub_rcnt;?>" id="s_chkdel_s<?php echo $sub_rcnt;?>" value="1" <?php if($sub_rights_sub['delete_right']==1){?>checked="checked"<?php }?>></td>

<?php if($sub_rights_sub['add_right']==1 && $sub_rights_sub['edit_right']==1 && $sub_rights_sub['view_right']==1 && $sub_rights_sub['delete_right']==1){?>
<td width="5%" id="m_act_ss<?php echo $sub_rcnt;?>"><input type="checkbox"  name="s_select" id="s_select" onClick="subselect_all('<?php echo $sub_rcnt;?>',this);" checked="checked"></td>
<?php } else {?>
<td width="5%" id="m_act_ss<?php echo $sub_rcnt;?>"><input type="checkbox"  name="s_select" id="s_select" onClick="subselect_all('<?php echo $sub_rcnt;?>',this);"></td>
<?php } ?>

			     <td><icon class="glyphicon glyphicon-edit" onclick="update_sub_menu_sub('<?php echo $sub_rcnt;?>','<?php echo $rcnt;?>','<?php echo $s_cnt;?>');"></i></td>
			 </tr >
						
						
				<?php  }?>
				
												<tr  style="background-color:#C7C7C7">
		<td><font color="#000000">Select All</font></td>
			<td></td>
	<td width="15%" id="m_add">
<input type="checkbox" name="s_chkadd_ss" id="s_chkadd_ss" value="1" onClick="sel_row_all_sub_sub('<?php echo $sub_rcnt;?>',this,1,'<?php echo $s_hrs?>')" <?php if($s_chkcnt_s==$s_hrs){?>checked="checked"<?php }?>></td>
<td width="15%" id="m_add">
<input type="checkbox" name="s_chkadd_ss" id="s_chkadd_ss" value="1" onClick="sel_row_all_sub_sub('<?php echo $sub_rcnt;?>',this,2,'<?php echo $s_hrs?>')" <?php if($s_chkcntedt_s==$s_hrs){?>checked="checked"<?php }?>>
</td>
	<td width="15%" id="m_add">
<input type="checkbox" name="s_chkadd_ss" id="s_chkadd_ss" value="1" onClick="sel_row_all_sub_sub('<?php echo $sub_rcnt;?>',this,3,'<?php echo $s_hrs?>')" <?php if($s_chkcntvw_s==$s_hrs){?>checked="checked"<?php }?>>
</td>
	<td width="15%" id="m_add">
<input type="checkbox" name="s_chkadd_ss" id="s_chkadd_ss" value="1" onClick="sel_row_all_sub_sub('<?php echo $sub_rcnt;?>',this,4,'<?php echo $s_hrs?>')" <?php if($s_chkcntdel_s==$s_hrs){?>checked="checked"<?php }?>>
</td>
<td width="15%" id="m_add" colspan="2"><input type="button" name="ups" id="ups" value="Update Sub Menu" style="width:118px;" onClick="update_all_sub_menu_sub('<?php echo $rcnt;?>','<?php echo $sub_rcnt;?>','<?php echo $s_hrs;?>');"></td>
		</tr>
				
				
				<?php  } ?>		
						
							</tbody>
					
			 </table>
			 
			 
			 </td>
			 </tr>
			 
			 
		<?php	}?>
		
											<tr  style="background-color:#C7C7C7">
		<td><font color="#000000">Select All</font></td>
		<td></td>
	<td width="15%" id="m_add">
<input type="checkbox" name="s_chkadd" id="s_chkadd" value="1" onClick="sel_row_all_sub('<?php echo $s_cnt;?>',this,1,'<?php echo $hrs?>')" <?php if($s_chkcnt==$hrs){?>checked="checked"<?php }?>></td>
<td width="15%" id="m_add">
<input type="checkbox" name="s_chkadd" id="s_chkadd" value="1" onClick="sel_row_all_sub('<?php echo $s_cnt;?>',this,2,'<?php echo $hrs?>')" <?php if($s_chkcntedt==$hrs){?>checked="checked"<?php }?>>
</td>
	<td width="15%" id="m_add">
<input type="checkbox" name="s_chkadd" id="s_chkadd" value="1" onClick="sel_row_all_sub('<?php echo $s_cnt;?>',this,3,'<?php echo $hrs?>')" <?php if($s_chkcntvw==$hrs){?>checked="checked"<?php }?>>
</td>
	<td width="15%" id="m_add">
<input type="checkbox" name="s_chkadd" id="s_chkadd" value="1" onClick="sel_row_all_sub('<?php echo $s_cnt;?>',this,4,'<?php echo $hrs?>')" <?php if($s_chkcntdel==$hrs){?>checked="checked"<?php }?>>
</td>
<td width="15%" id="m_add" colspan="2"><input type="button" name="ups" id="ups" value="Update Sub Menu" style="width:118px;" onClick="update_all_sub_menu('<?php echo $rcnt;?>','<?php echo $s_cnt;?>','<?php echo $hrs;?>');"></td>
		</tr>
		
		
		
			<?php	}?>
		
						
					</tbody>
				</table>
			</td>
		</tr>
		
		
						
													 
									<?php } ?>	
									
									
									<tr  style="background-color:#E1DCE9">
		<td><font color="#000000">Select All</font></td>
			<td width="15%" id="m_add"></td>
	<td width="15%" id="m_add">
	<input type="checkbox" name="chkadd" id="chkadd" value="1" onClick="sel_row_all('<?php echo $rcnt;?>',this,1)" <?php if($chkcnt==$rcnt){?>checked="checked"<?php }?>></td>
	<td width="15%" id="m_add">
	<input type="checkbox" name="chkadd" id="chkadd" value="1" onClick="sel_row_all('<?php echo $rcnt;?>',this,2)" <?php if($chkcntedt==$rcnt){?>checked="checked"<?php }?>></td>
	<td width="15%" id="m_add">
	<input type="checkbox" name="chkadd" id="chkadd" value="1" onClick="sel_row_all('<?php echo $rcnt;?>',this,3)" <?php if($chkcntvw==$rcnt){?>checked="checked"<?php }?>></td>
	<td width="15%" id="m_add">
	<input type="checkbox" name="chkadd" id="chkadd" value="1" onClick="sel_row_all('<?php echo $rcnt;?>',this,4)" <?php if($chkcntdel==$rcnt){?>checked="checked"<?php }?>></td>
			<td width="15%" id="m_add" colspan="2"><input type="button" name="ups" id="ups" value="Update" onClick="update_all('<?php echo $rcnt;?>','<?php echo $s_cnt;?>');"></td>
		</tr>
										</table>
<div class="clear-float"></div>

</form>
</div><!-- /report-cell-02 -->


<div id="masterlist"></div>

<div class="clear-float"></div>
</div><!-- /report-tab -->

<div class="clear-float"></div>
</div><!-- /content -->

<div class="footer">
<strong>© <translate>add-HRM</translate></strong><br />
<span><translate>Developed by</translate> <a href="http://www.aadhocc.com" target="_blank"><translate>Aadhocc</translate></a></span></div>
<!-- /footer -->

</div>
					
					
                    </div><!-- /.row (main row) -->

                </section><!-- /.content -->
            </aside><!-- /.right-side -->
        </div><!-- ./wrapper -->

        <!-- add new calendar event modal -->

<!--<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.0/jquery-ui.min.js"></script>-->
        <!-- jQuery 2.0.2 -->
              <?php 
	include("footer-js.php");
?>
	
		
		<!--------------scripts for employee list-------------->



<script type="text/javascript" src="js/jquery.timepicker.js"></script>
<link rel="stylesheet" type="text/css" href="js/jquery.timepicker.css" />
<script type="text/javascript" src="js/lib/bootstrap-datepicker.js"></script>

	<!--------------scripts for employee list-------------->
	
	
	
	

    </body>
</html>

<style>
div.pagination {
padding: 3px;
margin: 3px;
text-align:center;
}

div.pagination a {
padding: 2px 5px 2px 5px;
margin: 2px;
border: 1px solid #AAAADD;

text-decoration: none; /* no underline */
color: #000099;
}
div.pagination a:hover, div.digg a:active {
border: 1px solid #000099;

color: #000;
}
div.pagination span.current {
padding: 2px 5px 2px 5px;
margin: 2px;
border: 1px solid #B0B7D1;

font-weight: bold;
background-color: #939399;
color: #FFF;
}
div.pagination span.disabled {
padding: 2px 5px 2px 5px;
margin: 2px;
border: 1px solid #EEE;

color: #DDD;
}

</style>

<script type="text/javascript">
function row_expan_sub(id,cnt)
{

//icons_sub
var cls= $("#icons_sub"+id).hasClass('glyphicon glyphicon-plus');

if(cls==true)
{
$("#icons_sub"+id).addClass('glyphicon-minus').removeClass('glyphicon-plus');
}
else
{
$("#icons_sub"+id).addClass('glyphicon-plus').removeClass('glyphicon-minus');
}

var currentDetails = $('#parent_expand_ss'+id).next('#child_expandss'+id);

for(i=1;i<=cnt;i++)
{


if(i!=id)
{
$("#icons_sub"+i).addClass('glyphicon-plus').removeClass('glyphicon-minus');

$('#child_expandss'+i).hide();
}
}
				
				currentDetails.toggle();

}



function row_expan(id,cnt)
{
var cls= $("#icons"+id).hasClass('glyphicon glyphicon-plus');

if(cls==true)
{
$("#icons"+id).addClass('glyphicon-minus').removeClass('glyphicon-plus');
}
else
{
$("#icons"+id).addClass('glyphicon-plus').removeClass('glyphicon-minus');
}

var currentDetails = $('#parent_expand'+id).next('#child_expand'+id);

for(i=1;i<=cnt;i++)
{
$('#m_list'+id).css('backgroundColor', 'pink');
$('#m_exp'+id).css('backgroundColor', 'pink');
$('#m_add'+id).css('backgroundColor', 'pink');
$('#m_edit'+id).css('backgroundColor', 'pink');
$('#m_view'+id).css('backgroundColor', 'pink');
$('#m_del'+id).css('backgroundColor', 'pink');
$('#m_act'+id).css('backgroundColor', 'pink');
$('#m_acts'+id).css('backgroundColor', 'pink');

if(i!=id)
{
$("#icons"+i).addClass('glyphicon-plus').removeClass('glyphicon-minus');

$('#m_list'+i).css('backgroundColor', '#F4F4F4');
$('#m_exp'+i).css('backgroundColor', '#F4F4F4');
$('#m_add'+i).css('backgroundColor', '#F4F4F4');
$('#m_edit'+i).css('backgroundColor', '#F4F4F4');
$('#m_view'+i).css('backgroundColor', '#F4F4F4');
$('#m_del'+i).css('backgroundColor', '#F4F4F4');
$('#m_act'+i).css('backgroundColor', '#F4F4F4');
$('#m_acts'+i).css('backgroundColor', '#F4F4F4');
$('#child_expand'+i).hide();
}
}
				
				currentDetails.toggle();

}

function update_main_menu(ids)
{

var u_id='<?php echo $user_name['e_id'];?>'; 
var dataString=$('#mforms').serialize();
     $.ajax({
           type: "POST",
           url: "add_user_rights.php?action=main_m&rid="+ids+"&usr_id="+u_id,
           data: dataString,
           cache: false,
           success: function(result){
           $(".flash").hide();
		   alert("Menu Updated Successfully");
$('#m_list'+ids).css('backgroundColor', '#F4F4F4');
$('#m_exp'+ids).css('backgroundColor', '#F4F4F4');
$('#m_add'+ids).css('backgroundColor', '#F4F4F4');
$('#m_edit'+ids).css('backgroundColor', '#F4F4F4');
$('#m_view'+ids).css('backgroundColor', '#F4F4F4');
$('#m_del'+ids).css('backgroundColor', '#F4F4F4');
$('#m_act'+ids).css('backgroundColor', '#F4F4F4');
$('#m_acts'+ids).css('backgroundColor', '#F4F4F4');

/*$('#child_expand'+ids).hide();

var cls= $("#icons"+ids).hasClass('glyphicon glyphicon-plus');

if(cls==true)
{
$("#icons"+ids).addClass('glyphicon-minus').removeClass('glyphicon-plus');
}
else
{
$("#icons"+ids).addClass('glyphicon-plus').removeClass('glyphicon-minus');
}*/

              //   $("#m_divs").html(result);
           }
      });
}

function update_sub_menu(ids,m_mids)
{

var u_id='<?php echo $user_name['e_id'];?>'; 
var dataString=$('#mforms').serialize();
     $.ajax({
           type: "POST",
           url: "add_user_rights.php?action=sub_m&rid="+ids+"&usr_id="+u_id+"&m_mid="+m_mids,
           data: dataString,
           cache: false,
           success: function(result){
           $(".flash").hide();
		   alert("Menu Updated Successfully");
                // $("#m_divs").html(result);
           }
      });
}

function update_sub_menu_sub(ids,m_mids,s_sid)
{

var u_id='<?php echo $user_name['e_id'];?>'; 

var dataString=$('#mforms').serialize();
     $.ajax({
           type: "POST",
           url: "add_user_rights.php?action=sub_sub&rid="+ids+"&usr_id="+u_id+"&m_mid="+m_mids+"&s_sub="+s_sid,
           data: dataString,
           cache: false,
           success: function(result){
           $(".flash").hide();
		   alert("Menu Updated Successfully");
                //$("#m_divs").html(result);
           }
      });
}



function select_all(id,obj)
{

     if(obj.checked==true)
	 {
    $("#chkadd"+id).prop("checked", true);
	$("#chkedit"+id).prop("checked", true);
	$("#chkeview"+id).prop("checked", true);
	$("#chkdel"+id).prop("checked", true);
	 }
	 else
	 {
	 $("#chkadd"+id).prop("checked", false);
	 $("#chkedit"+id).prop("checked", false);
	 $("#chkeview"+id).prop("checked", false);
	 $("#chkdel"+id).prop("checked", false);
	 }
}

function select_all_subs(id,obj)
{
      if(obj.checked==true)
	 {
    $("#s_chkadd"+id).prop("checked", true);
	$("#s_chkedit"+id).prop("checked", true);
	$("#s_chkeview"+id).prop("checked", true);
	$("#s_chkdel"+id).prop("checked", true);
	 }
	 else
	 {
	 $("#s_chkadd"+id).prop("checked", false);
	 $("#s_chkedit"+id).prop("checked", false);
	 $("#s_chkeview"+id).prop("checked", false);
	 $("#s_chkdel"+id).prop("checked", false);
	 }
}


function subselect_all(id,obj)
{
        if(obj.checked==true)
	 {
    $("#s_chkadd_s"+id).prop("checked", true);
	$("#s_chkedit_s"+id).prop("checked", true);
	$("#s_chkeview_s"+id).prop("checked", true);
	$("#s_chkdel_s"+id).prop("checked", true);
	 }
	 else
	 {
	 $("#s_chkadd_s"+id).prop("checked", false);
	 $("#s_chkedit_s"+id).prop("checked", false);
	 $("#s_chkeview_s"+id).prop("checked", false);
	 $("#s_chkdel_s"+id).prop("checked", false);
	 }
}


function sel_row_all(cnts,obj,j)
{


   for(i=1;i<=cnts;i++)
   {
      if(obj.checked==true)
	 {
	      if(j==1)
		  {
    $("#chkadd"+i).prop("checked", true);
	      }
		   if(j==2)
		  {
	$("#chkedit"+i).prop("checked", true);
	      }
		   if(j==3)
		  {
	$("#chkeview"+i).prop("checked", true);
	      }
		   if(j==4)
		  {
	$("#chkdel"+i).prop("checked", true);
	      }
	 }
	 else
	 {
	   	  if(j==1)
		  {
	 $("#chkadd"+i).prop("checked", false);
	      }
		  if(j==2)
		  {
	 $("#chkedit"+i).prop("checked", false);
	      }
		  if(j==3)
		  {
	 $("#chkeview"+i).prop("checked", false);
	      }
		  if(j==4)
		  {
	 $("#chkdel"+i).prop("checked", false);
	      }
	 }
   }
}


function update_all(m_cnt,s_cnt)
{
/*alert(m_cnt);
alert(s_cnt);*/

var u_id='<?php echo $user_name['e_id'];?>'; 
var dataString=$('#mforms').serialize();
     $.ajax({
           type: "POST",
           url: "add_user_rights.php?action=m_s_menus&s_id="+s_cnt+"&usr_id="+u_id+"&m_mid="+m_cnt,
           data: dataString,
           cache: false,
           success: function(result){
           $(".flash").hide();
		   alert("Menu Updated Successfully");
                // $("#m_divs").html(result);
           }
      });

}


function sel_row_all_sub(cnt,obj,k,m_ccnt)
{


var f_cnt=(Number(cnt)- Number(m_ccnt))+1; 
      for(i=f_cnt;i<=cnt;i++)
   {
      if(obj.checked==true)
	 {
	      if(k==1)
		  {
           $("#s_chkadd"+i).prop("checked", true);
	      }
		   if(k==2)
		  {
	      $("#s_chkedit"+i).prop("checked", true);
	      }
		   if(k==3)
		  {
	      $("#s_chkeview"+i).prop("checked", true);
	      }
		   if(k==4)
		  {
	      $("#s_chkdel"+i).prop("checked", true);
	      }
	 }
	 else
	 {
	      if(k==1)
		  {
           $("#s_chkadd"+i).prop("checked", false);
	      }
		   if(k==2)
		  {
	      $("#s_chkedit"+i).prop("checked", false);
	      }
		   if(k==3)
		  {
	      $("#s_chkeview"+i).prop("checked", false);
	      }
		   if(k==4)
		  {
	      $("#s_chkdel"+i).prop("checked", false);
	      }
	 }
	 
	 
  }	 	  
		  
		  
}


function sel_row_all_sub_sub(cnt,obj,k,m_ccnt)
{



var f_cnt=(Number(cnt)- Number(m_ccnt))+1; 
      for(i=f_cnt;i<=cnt;i++)
   {
      if(obj.checked==true)
	 {
	      if(k==1)
		  {
           $("#s_chkadd_s"+i).prop("checked", true);
	      }
		   if(k==2)
		  {
	      $("#s_chkedit_s"+i).prop("checked", true);
	      }
		   if(k==3)
		  {
	      $("#s_chkeview_s"+i).prop("checked", true);
	      }
		   if(k==4)
		  {
	      $("#s_chkdel_s"+i).prop("checked", true);
	      }
	 }
	 else
	 {
	      if(k==1)
		  {
           $("#s_chkadd_s"+i).prop("checked", false);
	      }
		   if(k==2)
		  {
	      $("#s_chkedit_s"+i).prop("checked", false);
	      }
		   if(k==3)
		  {
	      $("#s_chkeview_s"+i).prop("checked", false);
	      }
		   if(k==4)
		  {
	      $("#s_chkdel_s"+i).prop("checked", false);
	      }
	 }
	 
	 
  }	 	  
		  
		  

}



function update_all_sub_menu(m_cnt,s_cnt,sub_cnt)
{

var u_id='<?php echo $user_name['e_id'];?>'; 
var dataString=$('#mforms').serialize();
     $.ajax({
           type: "POST",
           url: "add_user_rights.php?action=s_menus&s_id="+s_cnt+"&usr_id="+u_id+"&m_mid="+m_cnt+"&m_sub="+sub_cnt,
           data: dataString,
           cache: false,
           success: function(result){
           $(".flash").hide();
		   alert("Menu Updated Successfully");
                // $("#m_divs").html(result);
           }
      });

}



function update_all_sub_menu_sub(m_cnt,s_cnt,sub_cnt)
{

var u_id='<?php echo $user_name['e_id'];?>'; 
var dataString=$('#mforms').serialize();
     $.ajax({
           type: "POST",
           url: "add_user_rights.php?action=s_menus_sub&s_id="+s_cnt+"&usr_id="+u_id+"&m_mid="+m_cnt+"&m_sub="+sub_cnt,
           data: dataString,
           cache: false,
           success: function(result){
           $(".flash").hide();
		   alert("Menu Updated Successfully");
               //  $("#m_divs").html(result);
           }
      });

}

function chek_suball(i,j,k,obj,q)
{
  var ff=Number(j)+1; 
  var gg=Number(j)+Number(k);
  
  for(m=ff;m<=gg;m++)
	{
	
	   if(q==1)
	   {
	         if(obj.checked==true)
	        {
			 $("#s_chkadd"+m).prop("checked", true);
			}
			else
			{
			 $("#s_chkadd"+m).prop("checked", false);
			}
	   }
	   if(q==2)
	   {
	         if(obj.checked==true)
	        {
			 $("#s_chkedit"+m).prop("checked", true);
			}
			else
			{
			 $("#s_chkedit"+m).prop("checked", false);
			}
	   }
	   if(q==3)
	   {
	         if(obj.checked==true)
	        {
			 $("#s_chkeview"+m).prop("checked", true);
			}
			else
			{
			 $("#s_chkeview"+m).prop("checked", false);
			}
	   }	   

	   if(q==4)
	   {
	         if(obj.checked==true)
	        {
			 $("#s_chkdel"+m).prop("checked", true);
			}
			else
			{
			 $("#s_chkdel"+m).prop("checked", false);
			}
	   }
	
	}//for loop end
}

</script>