<?php
ini_set('display_errors', 0);
//error_reporting(E_ALL);
//ini_set('display_errors', 1);

session_start();
ob_start();

require_once('configuration/server_connect.php');
require_once('configuration/all_function.php');

$active_id=$_REQUEST['active_id'];
$menu_id=$_REQUEST['menu_id'];

$found_user_id=$_REQUEST['user_id'];

// Common Information

$page_title="User Roll Activity";
$page="81_user_roll.php?active_id=".$active_id."&menu_id=".$menu_id."";
$table='page_setup';	
$unique='id';

// End Common Information


if(isset($_POST['run_data']))
{
$user_name = $_REQUEST['user_name'];
$user=explode(' :: ',$user_name);
$user_id=$user[0];


header("location:".$page.'&user_id='.$user_id."");
?>

<!--<script language="javascript">
window.location.href = "<?php echo $page;?>&user_id=<?=$user_id?>";
</script>-->

<?php }


?>

<!DOCTYPE html>
<html lang="en">

 <?php require_once('inc_files/inc_head.php'); ?>
 
 <?php
  do_calander('#att_date');
  ?>
 
 
 <script>



function getXMLHTTP() { //fuction to return the xml http object



		var xmlhttp=false;	



		try{



			xmlhttp=new XMLHttpRequest();



		}



		catch(e)	{		



			try{			



				xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");

			}

			catch(e){



				try{



				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");



				}



				catch(e1){



					xmlhttp=false;



				}



			}



		}



		 	



		return xmlhttp;



    }



	function update_value(id)
	{

var order_no=id; // Rent

var user_id=(document.getElementById('user_id').value); 

var page_name=(document.getElementById('page_name_'+id).value);

var page_id=(document.getElementById('page_id_'+id).value); 

var flag=(document.getElementById('flag_'+id).value); 

var strURL="81_user_roll_ajax.php?order_no="+order_no+"&user_id="+user_id+"&page_name="+page_name+"&page_id="+page_id+"&flag="+flag;



		var req = getXMLHTTP();



		if (req) {



			req.onreadystatechange = function() {

				if (req.readyState == 4) {

					// only if "OK"

					if (req.status == 200) {						

						document.getElementById('divi_'+id).style.display='inline';

						document.getElementById('divi_'+id).innerHTML=req.responseText;						

					} else {

						alert("There was a problem while using XMLHTTP:\n" + req.statusText);

					}

				}				

			}

			req.open("GET", strURL, true);

			req.send(null);

		}	



}




</script>

<body>

  <!-- ======= Header ======= -->
  <?php 
  require_once('inc_files/inc_header.php');
  ?><!-- End Header -->

  <!-- ======= Sidebar ======= -->
  <?php  require_once('inc_files/inc_menu.php'); ?><!-- End Sidebar-->

  <main id="main" class="main">

    <div class="pagetitle">
      <h1><?php echo $page_title?></h1>
      <nav>
        <ol class="breadcrumb">
          <li class="breadcrumb-item"><a href="home.php">Home</a></li>
          <li class="breadcrumb-item">Admin Panel</li>
          <li class="breadcrumb-item active"><?php echo $page_title?></li>
        </ol>
      </nav>
    </div><!-- End Page Title -->

    <section class="section">
      <div class="row">
	  
        <div class="col-lg-12"> 

          <div class="card">
            <div class="card-body">
			 <?php if($found_user_id=="") {?>
			<br>
            <form class="row g-3" action="" method="post" name="codz" id="codz">
   		       
			
	<table width="80%" border="0" align="center">
      
      
        <tr height="50">
          <td width="14%" align="right">User Name:&nbsp;&nbsp;</td>
          <td width="15%" align="left">
		  <?php
			 auto_complete_from_db_sql($conn,'SELECT concat(user_id," :: ",fname), concat(user_id," :: ",fname) FROM user_management
			WHERE 1 order by user_id','user_name');
		?>
       <input type="text" class="form-control" id="user_name" name="user_name" value="<?php echo $_REQUEST['user_name']?>" required >		  </td>
          <td width="15%" rowspan="5" align="center" ><strong>
            &nbsp;&nbsp;&nbsp;
            <button type="submit" name="run_data" id="run_data" class="btn btn-success rounded-pill btn-sm">&nbsp;<i class="bi bi-filter me-1"></i> Run Report&nbsp;&nbsp;</button>
          </strong></td>
        </tr>
    </table>
               
  </form>
  <br>
	<?php }?>
	
	<?php if($found_user_id>0) {?>
	
	<?php 
   $emp_sql="SELECT * FROM user_management  WHERE user_id='".$_REQUEST['user_id']."'";
   $emp_data = find_all_field_sql($conn,$emp_sql);
   ?>
			<br>
            <form class="row g-3" action="" method="post" name="codz" id="codz">
   		       
			
	<table width="80%" border="0" align="center">
      
      
        <tr height="50">
          <td width="13%" align="right"><strong>User ID:</strong>&nbsp;&nbsp;</td>
          <td width="15%" align="left"><input type="text" class="form-control" id="user_id" name="user_id" value="<?php echo $emp_data->user_id?>" required  readonly=""></td>
          <td width="17%" align="right"><strong>User Name:</strong>&nbsp;&nbsp;</td>
          <td width="35%" align="left">
		 
       <input type="text" class="form-control" id="user_name" name="user_name" value="<?php echo $emp_data->fname?>" required  readonly="" style="width:90%">		  </td>
          <td width="20%" rowspan="5" align="center" >
              <img src="uploads/<?php echo $emp_data->emp_code;?>.jpg" alt="Profile" class="rounded-circle" style="border:1px solid #999999;" width="100">
           </td>
        </tr>
    </table>
               
  </form>
  <br>
	<?php }?>
              <!-- Table with stripped rows -->
              <table width="100%" class="table table-sm" style="font-size:12px;">
                <thead>
                  <tr style="text-transform:uppercase; color:#012970; background:#f6f9ff;  border-top: 1px solid #CCCCCC;">
                    <th width="11%" scope="col"><span class="card-title" style="font-size:12px; text-transform:uppercase;"> Page ID </span></th>
                    <th width="21%" scope="col"><span class="card-title" style="font-size:12px; text-transform:uppercase;"> Feature Name </span></th>
                    <th width="18%" scope="col"><span class="card-title" style="font-size:12px; text-transform:uppercase;">Page Name </span></th>
                    <th width="15%" scope="col"><span class="card-title" style="font-size:12px; text-transform:uppercase;">Page No </span></th>
                    <th width="10%" scope="col"><span class="card-title" style="font-size:12px; text-transform:uppercase;">Action</span></th>
                  </tr>
                </thead>
                <tbody>
					<?php
					
$employee_name = $_REQUEST['employee_name'];
  $employee=explode(' :: ',$employee_name);
   $employee_code=$employee[0];
  
if($employee_code!=''){
$employee_con=" and emp_code='".$employee_code."' ";
}

if($_POST['department']!=''){
$department_con=" and department='".$_POST['department']."' ";
}

if($_POST['designation']!=''){
$designation_con=" and designation='".$_POST['designation']."' ";
}

if($_POST['job_status']!=''){
$job_status_con=" and job_status='".$_POST['job_status']."' ";
}


$start_date = ''.$_POST['year'].'-'.$_POST['mon'].'-01';
$end_date = date("Y-m-t", strtotime($start_date));

$fdate = strtotime($start_date);
$tdate = strtotime($end_date);
$datediff = $tdate - $fdate;

$day_count=$datediff / (60 * 60 * 24)+1;

	 	$sql = "select id, feature_name from feature_setup where 1 group by id";
		 $query = mysqli_query($conn,$sql);
		 while($info=mysqli_fetch_object($query)){
  		 $feature_name[$info->id]=$info->feature_name;
		}			
		
		 $sql = "select order_no, page_id from user_roll_manage where user_id='".$_REQUEST['user_id']."' group by order_no";
		 $query = mysqli_query($conn,$sql);
		 while($info=mysqli_fetch_object($query)){
		 $page_id[$info->order_no]=$info->page_id;
  		
		}
		
		
			
					    $sql = 'select * from '.$table.' where page_id>0 and status="Active" order by feature_id, page_id';
						$query = mysqli_query($conn,$sql);
						while ($data = mysqli_fetch_object($query)) {

					?>
	<?php if($_REQUEST['user_id']>0){?>		
      <tr>
      <td><?php echo $data->id;?></td>
      <td><?php echo $feature_name[$data->feature_id];?></td>
      <td><?php echo $data->page_name;?>
	   <input name="page_name_<?php echo $data->id?>" type="hidden" id="page_name_<?php echo $data->id?>" value="<?php echo $data->page_name;?>" />
	   <input name="page_id_<?php echo $data->id?>" type="hidden" id="page_id_<?php echo $data->id?>" value="<?php echo $data->page_id;?>" />
	  </td>
	  <td><?php echo $data->page_id;?></td>
      <td>
	  <span id="divi_<?php echo $data->id?>">

            <?php
			  if($page_id[$data->id]>0)
			  {?>
			  <input name="flag_<?php echo $data->id?>" type="hidden" id="flag_<?php echo $data->id?>" value="1" />
			  <input class="form-control" type="button" name="Button" value="Delete"  onclick="update_value(<?php echo $data->id?>)" style="width:80%; height:30px; background-color:#FF3366; font-weight:700; font-size:12px;"/>
			  
			  <?php
			  }
			  else
			  {
			  ?>
			  <input name="flag_<?php echo $data->id?>" type="hidden" id="flag_<?php echo $data->id?>" value="0" />
			  <input class="form-control" type="button" name="Button" value="Save"  onclick="update_value(<?php echo $data->id?>)" style="width:80%; height:30px;background-color:#66CC66;   font-weight:700; font-size:12px;"/><?php }?>
          </span>	  </td>
      </tr>
				  <?php }}?>
                </tbody>
              </table>
              <!-- End Table with stripped rows -->

            </div>
          </div>

        </div>

        
      </div>
    </section>

  </main><!-- End #main -->

  <!-- ======= Footer ======= -->
  <?php require_once('inc_files/inc_footer.php'); ?>
 <!-- ======= Footer ======= -->

</body>

</html>