<?php session_start();
include('accesscheck2.php'); 
require_once('Connections/courier.php');
require_once('functions/functions.php');

$id = $_POST['id'];
list($row_rsodest1, $count_user) = fetchDataOne('users', array('*'), array('id'=>$id));
list($row_rsodest2, $count) = fetchDataMore('securitylevel', array('*'), array('main_menu'=>'yes'), 'ORDER BY menu_place, menu_position');
$userpermid=$id;

function getPermissions($userpermid, $id) {
    $LoginRS__query = mysql_query("select * from securitypermissions where user_id='$userpermid' AND securitylevel_id='$id'");
    $loginFoundUser = mysql_num_rows($LoginRS__query);
    if ($loginFoundUser > 0) {
        return 'yes';
    } else {
        return 'no';
    }
}?>

<head>
    <style type="text/css">
       
div.wrapper
{
  float: left;
  width: 28%;
}
div.wrapper li
{
	list-style-type:none;
}
br
{
  clear: left;
}
    </style>
    </head>

<div class="page-bar">
    <ul class="page-breadcrumb">
        <li>
            <i class="icon-home"></i>
            <a href="#">Home</a>
            <i class="fa fa-angle-right"></i>
        </li>
        <li>
            <span>Users</span>
            <i class="fa fa-angle-right"></i>
        </li>
        <li>
            <span>Add New User</span>
        </li>
    </ul>
    <div class="page-toolbar">
        <div class="btn-group pull-right">
            <button type="button" class="btn btn-fit-height grey-salt dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" data-delay="1000" data-close-others="true"> Actions
                <i class="fa fa-angle-down"></i>
            </button>
            <ul class="dropdown-menu pull-right" role="menu">
                <li onclick="getstep('<?php echo $action; ?>', '<?php echo $id; ?>');">
                    <a href="#">
                        <i class="icon-refresh"></i> Refresh 
                    </a>
                </li>
                <li onclick="getstep('list_of_users');">
                    <a href="#">
                        <i class="fa fa-list"></i> List of Users 
                    </a>
                </li>
            </ul>
        </div>
    </div>
</div>
                    <!-- END PAGE HEADER-->
                    <div class="row">
                        <div class="col-md-12">
                            <div class="profile-content">
                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="portlet light ">
                                            <div class="portlet-title">
                                                <div class="caption caption-md">
                                                    <i class="icon-globe theme-font hide"></i>
                                                    <span class="caption-subject bold uppercase font-dark"> PERMISSIONS FOR  <?php echo $row_rsodest1['firstnames'].' '.$row_rsodest1['surname']; ?> </span>
                                                </div>
                                            </div>
                                            
                                             <div class="portlet-body form">
                                                 <div class="row">
                                                     <form id="save_new_user" name="save_new_user" role="form" action="#" class="form-horizontal" onsubmit="getProcessInfo('update_permission', '#save_new_user', '<?php echo $id; ?>', '#currentarea');return false;">
                                                         <div class="form-body">
                                                             <div class="row">    
                                                                 <div class="col-lg-12 col-xs-12 col-md-12" style="float: left;">
                                                                     <div class="portlet-body" style="float: left;">
                                                                         <div id="menu_permission">
                                                                             <?php
                                                                             foreach ($row_rsodest2 as $key => $row_rsodest){ ?>	
                                                                             <div class="wrapper" style="min-height: <?php if($row_rsodest['menu_name']=='Admin Utilities'){echo '40px';}else{ echo '460px'; }?> ">
                                                                                     <ul>
                                                                                         <li class='redbold1'><span class="" style="display: inline-block;width: 320px;height: 30px;padding-bottom: 10px;padding-top: 5px;padding-left: 5px;padding-right: 5px;font-weight:bold;color: blue;"><?php echo $row_rsodest['menu_name']; ?></span><hr />
                                                                                             <?php
                                                                                             $menuplace = $row_rsodest['menu_place'];
                                                                                             list($row_rsodest_sub2, $totalRows_rsodest_sub) = fetchDataMore('securitylevel', array('*'), array('menu_place'=>$menuplace), 'and menu_position>0 ORDER BY menu_position');
                                                                                              ?>
                                                                                             <ul>
                                                                                                 <?php  foreach ($row_rsodest_sub2 as $key => $row_rsodest_sub) { ?>
                                                                                                     <li class="bodytxthm222">
                                                                                                         <label class="mt-checkbox mt-checkbox-outline">
                                                                                                                     <input type="checkbox" name="item<?php echo $row_rsodest_sub['id']; ?>" type="checkbox" id="item<?php echo $row_rsodest_sub['id']; ?>" value="<?php echo $row_rsodest_sub['id']; ?>" <?php if (getPermissions($userpermid, $row_rsodest_sub['id']) == 'yes') { ?>checked="checked" <?php } ?>> <?php echo $row_rsodest_sub['menu_name']; ?>
                                                                                                                     <span></span>
                                                                                                         </label>
                                                                                                     </li>
                                                                                                     <?php } ?>  
                                                                                             </ul>
                                                                                         </li>
                                                                                     </ul>
                                                                                     <br />
                                                                                </div>
                                                                             <?php } ?>
                                                                         </div>
                                                                     </div>
                                                                 </div>
                                                             </div>
                                                         </div>

                                                         <div class="form-actions right">
                                                             <button  type="submit" class="btn green"> Update Permission <i class="fa fa-check"></i> </button>
                                                             <button type="reset" class="btn default"> <i class="fa fa-refresh"></i> Reset </button>
                                                         </div>
                                                     </form>
                                                 </div>
    </div>
                                          
                                </div>
                            </div>
                        </div>
                    </div>
