<?php include 'inc_classes.php'; 
include "admin_authentication.php";
// $edit_access='';
// $sel_acc="select * from edit_previleges where admin_id='".$_SESSION['admin_id']."' and privilege_id='392'";
// $ptr_access=mysql_query($sel_acc);
// if(mysql_num_rows($ptr_access))
// {
// 	$edit_access='yes';
// }
?>
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title> Issue/Accolades </title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.7 -->
    <link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="bower_components/font-awesome/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="bower_components/Ionicons/css/ionicons.min.css">
    <!-- daterange picker -->
    <link rel="stylesheet" href="bower_components/bootstrap-daterangepicker/daterangepicker.css">
    <!-- bootstrap datepicker -->
    <link rel="stylesheet" href="bower_components/bootstrap-datepicker/dist/css/bootstrap-datepicker.min.css">
    <!-- iCheck for checkboxes and radio inputs -->
    <link rel="stylesheet" href="plugins/iCheck/all.css">
    <!-- Bootstrap Color Picker -->
    <link rel="stylesheet" href="bower_components/bootstrap-colorpicker/dist/css/bootstrap-colorpicker.min.css">
    <!-- Bootstrap time Picker -->
    <link rel="stylesheet" href="plugins/timepicker/bootstrap-timepicker.min.css">
    <!-- Select2 -->
    <link rel="stylesheet" href="bower_components/select2/dist/css/select2.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="dist/css/AdminLTE.min.css">
    <!-- paginate style -->
    <link rel="stylesheet" href="dist/css/paginate.min.css">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
       folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" href="dist/css/skins/_all-skins.min.css">
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  <![endif]-->
    <!-- Google Font -->
    <link rel="stylesheet"
        href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">
</head>
<script>
   function submitAction(action)
	{
		var chks = document.getElementsByName('chkRecords[]');
		var hasChecked = false;
		for (var i = 0; i < chks.length; i++)
		{
			if (chks[i].checked)
			{
				hasChecked = true;
				break;
			}
		}
		if (hasChecked == false)
		{
			alert("Please select at least one record to do operation");
			$('#selAction').val('');
			return false;
		}

		document.getElementById('formAction').value=action;
		if(action=="delete")
		{
			if(confirm("Are you sure, you want to delete selected record(s)?"))
				document.frmTakeAction.submit();
			else
			{
				$('#selAction').val('');
				return false;
			}
		}
		else
			document.frmTakeAction.submit();
	}
	function redirect1(value,value1)
	{           
		//alert(value);
	   // alert(value1);
		window.location.href=value+value1;
	}

	function validationToDelete(type)
	{
		if(confirm("Are you sure, you want to delete selected record(s)?"))
			return true;
		else
			return false;
	}
	function getstaffDetails(branch_id)
	{
		var data1="action=sel_staff&branch_id="+branch_id;	
		$.ajax({
		url: "tk_fill_kpi_ajax.php", type: "post", data: data1, cache: false,
		success: function (html)
		{
			if(html !='')
			{
				document.getElementById("staff_ids").innerHTML=html;
				$("#staff_id").chosen({allow_single_deselect:true});
			}
		},
		error:function(exception){alert('Exception:'+exception);}
		});
	}
function select_staff(branch)
{
	var branch_data="action=staff&branch_name="+branch;
    // alert(branch);
	$.ajax({
	url: "tk_fill_kpi_ajax.php",type:"post", data: branch_data,cache: false,
	success: function(retstaff)
	{
		// alert(retstaff);
		document.getElementById("admin_name").innerHTML=retstaff;
	
	}
	});
}
	function isNumber(evt) {
		evt = (evt) ? evt : window.event;
		var charCode = (evt.which) ? evt.which : evt.keyCode;
		if (charCode > 31 && (charCode < 48 || charCode > 57)) {
			return false;
		}
		return true;
	}
	function issue_value(val) {
            var issueRow = document.getElementById("issuevalue");
            if(val == 'issue') {
				// alert("hi");
                issueRow.classList.remove("hidden");
            } else {
                issueRow.classList.add("hidden");
            }
        }
	function check_date(dates) {
		// var dates=document.getElementById("date").value;
		// alert(dates);
		var today_dates=document.getElementById("today_date").value;
		// alert(today_dates);
		if (today_dates > dates) {
				alert("Date are not less than todays date")
                window.location.reload();
            }
	}
	function check_next_date(to_date) {
		// var dates=document.getElementById("date").value;
		// alert(dates);
		var today_dates=document.getElementById("today_date").value;
		// alert(today_dates);
		if (today_dates < to_date) {
				alert("Date are not Greater than todays date")
                window.location.reload();
            }
	}
	function validation()
    {
        // alert("hi");
        var date=document.getElementById("date").value;
        var branch_name=document.getElementById("branch_name").value;
        var staff_id= document.getElementById("staff_id").value;
        var issuse= document.getElementById("issuse").value;
        var tot_points= document.getElementById("tot_points").value;
		var comments= document.getElementById("comments").value;
            error='';
            show_error ='Please Correct The Following Error \n';
            if (date == "") {
                error='yes';
                show_error +='Please Select the Date\n';
            }
            if (branch_name == "") {
                error='yes';
                show_error +='Please Select Branch \n';
            }
            if(staff_id == "") {
                error='yes';
                show_error +='Please Select Staff \n';
            }
            if (issuse == "") {
                error='yes';
                show_error +='Please Select Issue/Accolades \n';
            }
            if (tot_points == "") {
                error='yes';
                show_error +='Please Add Percentage \n';
            }
			if (comments == "") {
                error='yes';
                show_error +='Please Add Comments \n';
            }
            if(error=='yes')
            {
                alert(show_error);
                return false;
            }
            else
            { 
                return true;
            }
    }	
    </script>
    <style>
        .hidden {
			display:none; 
        }
    </style>
</script>
<?php
include "include/ps_pagination.php";
	?>
<body class="hold-transition skin-blue sidebar-mini">
    <div class="wrapper">
        <?php include "include/header-main.php"; ?>
        <!-- Left side column. contains the logo and sidebar -->
        <?php include "include/menu_left.php"; ?>
        <!-- Content Wrapper. Contains page content -->
        <!-- Left side column. contains the logo and sidebar -->
        <!-- Content Wrapper. Contains page content -->
        <div class="content-wrapper">
            <!-- Content Header (Page header) -->
            <section class="content-header">
                <h1>
                    Issue/Accolades
                </h1>
                <ol class="breadcrumb">
                    <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
                    <li class="active">Dashboard</li>
                </ol>
            </section>
            <!-- Main content -->
            <?php   
            if($_REQUEST['record_id'])
            {
                $record_id=$_REQUEST['record_id'];
                $sql_record= "SELECT * FROM pm_emp_extra_performance where id='".$record_id."'";
                if(mysql_num_rows($db->query($sql_record)))
                    $row_record=$db->fetch_array($db->query($sql_record));
                else
                    $record_id=0;
            }    
            if($_POST['save_changes'])
            {
                $branch_name=( ($_POST['branch_name'])) ? $_POST['branch_name'] : "";
                $added_date=date('Y-m-d H:i:s');  
                $admin_id=$_SESSION['admin_id'];

				if($_SESSION['type']=='S' || $_SESSION['branch_access']=='yes')
				{
					$sel_branch="select cm_id ,admin_id from site_setting where branch_name='".$branch_name."' and type='A'";
					$ptr_branch=mysql_query($sel_branch);
					$data_branch=mysql_fetch_array($ptr_branch);
					$cm_id=$data_branch['cm_id'];
					
					$branch_name1=$branch_name;
					$_SESSION['cm_id_notification']=$data_branch['cm_id'];
				}	
				else
				{
					$cm_id=$_SESSION['cm_id'];
					$branch_name1=$_SESSION['branch_name'];
				}
                $ad_date=$_POST['date'];
                $new_dates=explode("/",$ad_date);
                $date=$new_dates[2].'-'.$new_dates[1].'-'.$new_dates[0];
                $type= $_POST['issuse'];
                $damage_val=$_POST['damage_val'];
                $tot_percentage=$_POST['points'];
                $data_record['staff_id'] = $_POST['staff_id'];
                $data_record['date']=$date;
                $data_record['total_percentage']=$tot_percentage;
                $data_record['type'] = $type;
                $data_record['damage_val'] = $damage_val;
                $data_record['comment'] = $_POST['comments'];
                $data_record['admin_id'] =$admin_id;
                $data_record['cm_id'] =$cm_id;
                
                if($record_id)
                {
                    $where_record="id='".$record_id."'";
                    $db->query_update("pm_emp_extra_performance", $data_record,$where_record);
                    if($db)
                    {
                        ?>
                        <div class="alert alert-success alert-dismissible">
                            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                            <h4><i class="icon fa fa-ban"></i> Alert!</h4>
                            <p> Record Updated Successfully.</p>
                        </div>
                        <script>
                            setTimeout('document.location.href="tk_issue_accolades.php";', 500);
                        </script>
                        <?php
                    }
                }
                else
                {
                    $data_record['added_date'] =$added_date;
                    $checkout_prod_map_id=$db->query_insert("pm_emp_extra_performance", $data_record);					
                    if($checkout_prod_map_id)
                    {
                        ?>
                        <div class="alert alert-success alert-dismissible">
                            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                            <h4><i class="icon fa fa-ban"></i> Alert!</h4>
                            <p> Record Inserted Successfully.</p>
                        </div>
                        <script>
                            setTimeout('document.location.href="tk_issue_accolades.php";', 500);
                        </script>
                        <?php
                    }
                }
            }
			if($_REQUEST['deleteRecord']!='' && $_REQUEST['record_ids']!='')
			{
				$id=$_REQUEST['record_ids'];
				$delete="delete from pm_emp_extra_performance where id='".$id."'";  
				$ptr_delete=mysql_query($delete);
				if ($ptr_delete)
                {
                    ?>
                        <div class="alert alert-danger alert-dismissible">
                            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                            <h4><i class="icon fa fa-ban"></i> Alert!</h4>
                            <p> Record Deleted Successfully.</p>
                        </div>
                        <script>
                            setTimeout('document.location.href="tk_issue_accolades.php";', 500);
                        </script>
                    <?php
                }
			}            
            ?>
            <section class="content">
                <div class="box box-default">
                    <div class="box-body">
                        <div class="row">
                            <div class="col-md-12">
                                <form method="POST" id="jqueryForm" name="jqueryForm" enctype="multipart/form-data" onsubmit="return validation()">                              
                                    <div class="col-md-5">
                                        <p class="text-danger">* Required Field</p>
                                        <div class="form-group">
                                            <label for="date">
                                                <span class="text-danger">*</span> Select Date 
                                                <span class="text-danger"><?php echo $task_Err ;?></span>
                                            </label>
                                            <input type="text" name="date" class="form-control" placeholder="Date" id="date" title="Date" value="<?php
                                                if($row_record['date'] !='')
                                                {
                                                    $add_dates=DATE($row_record['date']);
                                                    $expl_date=explode(' ',$add_dates);
                                                    $arrage_date= explode('-',$expl_date[0],3);     
                                                    echo $add=$arrage_date[2].'/'.$arrage_date[1].'/'.$arrage_date[0]; 
                                                }
                                                else echo date('d/m/Y') ?>">
                                        </div>
                                        <div class="form-group">
                                            <label for="branch_name">
                                                <span class="text-danger">*</span> Branch Name 
                                                <span class="text-danger"><?php echo $task_Err ;?></span>
                                            </label>
                                            <?php 
                                            if($_SESSION['type']=='S' || $_SESSION['branch_access']=='yes')
                                            {
                                                ?>
                                                <select name="branch_name" id="branch_name" onchange="getstaffDetails(this.value)" class="form-control select2">
                                                    <option value="">Select Branch</option>
                                                    <?php 
                                                        $sel_branch="select branch_id,branch_name,cm_id from branch where status='Active'";
                                                        $ptr_sel=mysql_query($sel_branch);
                                                        while($data_branch=mysql_fetch_array($ptr_sel))
                                                        {
                                                            $sel='';
                                                            if($record_id){
                                                                if($data_branch['cm_id']==$row_record['cm_id'])
                                                                {
                                                                    $sel='selected="selected"';
                                                                }
                                                            }
                                                            // else if($data_branch['branch_name']=='Pune')
                                                            // {
                                                            //     $sel='selected="selected"';
                                                            // }
                                                            echo '<option '.$sel.' value="'.$data_branch['branch_name'].'" > '.$data_branch['branch_name'].'</option>';
                                                        }
                                                        ?>
                                                </select>
                                                <?php
                                            }
                                            else 
                                            {
                                                ?>
                                                <input type="hidden" name="branch_name" id="branch_name" value="<?php echo $_SESSION['branch_name']; ?>" />
                                                <?php 
                                            }
                                            ?>
                                        </div>
                                        <div class="form-group">
                                            <label>
                                                <span class="text-danger">*</span> Select Staff 
                                            </label>
                                            <div id="staff_ids">
                                                <select name="staff_id" id="staff_id" class="form-control select2">  
                                                    <option value="">Select Staff</option>
                                                    <?php
                                                    if($record_id)
                                                    {
                                                        $sle_name="select admin_id,name from site_setting where 1 ".$_SESSION['where']." and system_status='Enabled' order by name asc"; 
                                                        $ptr_name=mysql_query($sle_name);
                                                        while($data_name=mysql_fetch_array($ptr_name))
                                                        {
                                                            $selected='';
                                                            if($data_name['admin_id'] == $row_record['staff_id'])
                                                            {
                                                                $selected='selected="selected"';
                                                            }
                                                            echo '<option '.$selected.' value="'.$data_name['admin_id'].'">'.$data_name['name'].'</option>';
                                                        }
                                                    }
                                                    ?>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-md-5">
                                        <div class="form-group">
                                            <label >
                                                <span class="text-danger">*</span> Select Issue/Accolades
                                            </label>
                                            <select name="issuse" id="issuse" class="form-control select2" onchange="issue_value(this.value)">  
                                                <option value="">Select </option> 
                                                <option value="issue" <?php if($row_record['type']=='issue') echo 'selected=selected';?>>Issues </option> 
                                                <option value="accolades" <?php if($row_record['type']=='accolades') echo 'selected=selected';?>>Accolades </option> 
                                            </select>
                                        </div>
                                        <div class="form-group">
                                            <div id="issuevalue" <?php if($row_record['type']=='issue') echo '';else echo 'class="hidden"';?>>
                                                <label >
                                                    <span class="text-danger">*</span> Add Issue Damage Value (in Rs)
                                                </label>
                                                <input type="number" name="damage_val" class="form-control" id="damage_val" title="Damage Value" value="<?php if($_POST['save_changes']) echo $_POST['damage_val']; else echo $row_record['damage_val'];?>">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label>
                                                <span class="text-danger">*</span> Add Percentage
                                            </label>
                                            <input type="number" name="points" class="form-control" id="tot_points" title="points" value="<?php if($_POST['save_changes']) echo $_POST['points']; else echo $row_record['total_percentage'];?>">
                                        </div>
                                        <div class="form-group">
                                            <label>
                                                <span class="text-danger">*</span> Comments
                                            </label>
                                            <textarea class="form-control" rows="2"  name="comments" id="comments"><?php if($_POST['save_changes']) echo $_POST['comments']; else echo $row_record['comment'];?></textarea>
                                        </div>
                                    </div>
                                    <div class="col-md-12">
                                        <div class="form-group text-center">
                                            <input type="submit" name="save_changes" value="Save Record" class="btn btn-success">
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-12">
                        <div class="box box-info">
                            <div class="box-header with-border">
                                <h3 class="box-title">Manage Issue/Accolades</h3>
                                <div class="table-responsive">
                                    <form method="get" name="search">
                                        <table class="table no-margin" >
                                            <tr>
                                                <td>
                                                    <?php
                                                    if($_SESSION['type']=='S' || $_SESSION['branch_access']=='yes')
                                                    {
                                                        ?>
                                                        <select class="form-control select2" id="branch_name1"
                                                            style="width:150px" name="branch_name1"
                                                            onchange="select_staff(this.value)" ;>
                                                            <option value="">Select Branch</option>
                                                            <?php 
                                                            $sel_branch="select branch_id,branch_name from branch";
                                                            $ptr_sel=mysql_query($sel_branch);
                                                            while($data_branch=mysql_fetch_array($ptr_sel))
                                                            {
                                                                $sel='';
                                                                if($data_branch['branch_name']==$_GET['branch_name1'])
                                                                {
                                                                    $sel='selected="selected"';
                                                                }
                                                                echo '<option '.$sel.' value="'.$data_branch['branch_name'].'" >'.$data_branch['branch_name'].'</option>';
                                                            }
                                                            ?>
                                                        </select>
                                                        <?php
                                                    }
                                                    else
                                                    {
                                                        ?>
                                                            <input type="hidden" name="branch_names1" id="branch_names1" value="<?php echo $_SESSION['branch_name']; ?>" />
                                                        <?php
                                                    }
                                                    ?>
                                                </td>
                                                <td>
                                                    <select class="form-control select2" style="width:200px" id="admin_name" name="admin_name">
                                                    <option value="">Select Staff</option>
                                                    </select>
                                                </td>
                                                <td>
                                                    <select name="issuse" id="issuse" class="form-control select2" style="width:150px" >  
                                                        <option value="">Select Type</option> 
                                                        <option value="issue" <?php if($_GET['issuse']=='issue') echo 'selected=selected';?>>Issues </option> 
                                                        <option value="accolades" <?php if($_GET['issuse']=='accolades') echo 'selected=selected';?>>Accolades </option> 
                                                    </select>
                                                </td>
                                                <td width="">
                                                    <input type="text" name="add_date" class="form-control datepicker"style="width:110px"
                                                        placeholder="From Date" id="add_date" title="Task Date"
                                                        value="<?php echo $_REQUEST['add_date'];?>">
                                                </td>
                                                <td width="">
                                                    <input type="text" name="to_date" class="form-control datepicker"style="width:110px"
                                                        placeholder="To Date" id="to_date" title="Task Date"
                                                        value="<?php echo $_REQUEST['to_date'];?>">
                                                </td>
                                                <td>
                                                    <input type="text" class="form-control" name="keyword" style="width:100px"
                                                        id="search_project" value="<?php if($_REQUEST['search']!=" search")
                                                        echo $_REQUEST['keyword'];?>" placeholder="search">
                                                </td>
                                                <td>
                                                    <input type="image" src="images/search.jpg" name="search" value="search"
                                                        style="height:32px;">
                                                </td>
                                            </tr>
                                            <style>
                                                th{
                                                    text-align: center;
                                                }
                                            </style>
                                            <tr>
                                                <div class="box-body">
                                                    <table class="table no-margin" style="text-align:center">
                                                        <thead>
                                                            <tr>
                                                                <th>Sr. No.</th>
                                                                <th>Branch Name</th>
                                                                <th>Employee Name </th>
                                                                <th>Date</th>
                                                                <th>Type</th>
                                                                <th>Damage Value(in Rs)</th>
                                                                <th>Points (percentage)</th>
                                                                <th>Description</th>
                                                                <th>Added date</th>
                                                                <th>Action</th>
                                                            </tr>
                                                        </thead>
                                                        <tbody>
                                                            <?php    
                                                            if($_REQUEST['add_date'] && $_REQUEST['add_date']!=="0000-00-00" && $_REQUEST['add_date']!="From Date")
                                                            {
                                                                $frm_date=explode("/",$_REQUEST['add_date']);
                                                                $frm_dates=$frm_date[2]."-".$frm_date[1]."-".$frm_date[0];
                                                                $start_date=$frm_dates;
                                                                $date_start=" and date='".date('Y-m-d',strtotime($frm_dates))."'";
                                                            }
                                                            if($_REQUEST['to_date'] && $_REQUEST['to_date']!=="0000-00-00" && $_REQUEST['to_date']!="To Date")
                                                            {
                                                                $frm_to_date=explode("/",$_REQUEST['to_date']);
                                                                $frm_to_dates=$frm_to_date[2]."-".$frm_to_date[1]."-".$frm_to_date[0];
                                                                $start_to_date=$frm_to_dates;
                                                                $to_date=" and date ='".date('Y-m-d',strtotime($frm_to_dates))."'";
                                                            }
                                                            if($_REQUEST['add_date']!='' && $_REQUEST['to_date']!=''){
                                                                $search_date='and date >="'.$frm_dates.'" and date <="'.$frm_to_dates.'"';
                                                                }
                                                                else{
                                                                  $search_date='';
                                                                }
                                                            if($_SESSION['type']=="S" || $_SESSION['type']=='Z' || $_SESSION['type']=='LD')
                                                            {
                                                                if($_REQUEST['branch_name1']!='')
                                                                {
                                                                    $branch_name=$_REQUEST['branch_name1'];
                                                                    $select_cm_id="select cm_id from site_setting where 1 and system_status='Enabled' and branch_name='".$branch_name."' and type='A'";
                                                                    $ptr_cm_id=mysql_query($select_cm_id);
                                                                    $data_cm_id=mysql_fetch_array($ptr_cm_id);
                                                                    $search_cm_id=" and cm_id='".$data_cm_id['cm_id']."'";
                                                                    $cm_ids=$data_cm_id['cm_id'];
                                                                }
                                                            }
                                                            if($_REQUEST['admin_name'])
                                                            {
                                                                $staff_ids=$_REQUEST['admin_name'];
                                                                $where_staff_id=" and employee_id='".$staff_ids."'";
                                                                $staff_id=" and staff_id='".$staff_ids."'";
                                                            }
                                                            else
                                                            {
                                                                $where_staff_id='';
                                                            }
                                                            if($_REQUEST['issuse'])
                                                            {
                                                                $issues=$_REQUEST['issuse'];
                                                                $search_issue=" and type='".$issues."'";
                                                            }
                                                            else
                                                            {
                                                                $search_issue='';
                                                            }
                                                            if($_REQUEST['page'])
                                                                $page=$_REQUEST['page'];
                                                            else
                                                                $page=0;
                                                            
                                                            if($_REQUEST['show_records'])
                                                                $show=$_REQUEST['show'];
                                                            else
                                                                $show=0;
                                                    
                                                            if($_GET['order']=='asc')
                                                            {
                                                                $order='desc';
                                                                $img = "<img src='images/sort_up.png' border='0'>";
                                                            }
                                                            else if($_GET['order']=='desc')
                                                            {
                                                                $order='asc';
                                                                $img = "<img src='images/sort_down.png' border='0'>";
                                                            }
                                                            else
                                                                $order='desc';
                                                    
                                                            if($_GET['orderby']=='name' )
                                                                $img1 = $img;
                                                    
                                                            if($_GET['order'] !='' && ($_GET['orderby']=='firstname'))
                                                            {
                                                                $select_directory .= " order by ".$_GET['orderby']." " .$_GET['order'] ;
                                                                $date_query='&order='.$_GET['order'].'&orderby='.$_GET['orderby'];
                                                            }                  
                                                            $sql_query= "SELECT * FROM pm_emp_extra_performance where 1 ".$search_cm_id." ".$staff_id." ".$search_issue." ".$search_date." order by id DESC"; 
                                                            $no_of_records=mysql_num_rows($db->query($sql_query));
                                                            if($no_of_records)
                                                            {
                                                                $bgColorCounter=1;
                                                                $query_string='&keyword='.$keyword;
                                                                $query_string1=$query_string.$date_query;
                                                                $pager = new PS_Pagination($sql_query,$_SESSION['show_records'],5,$query_string1);
                                                                $all_records= $pager->paginate();
                                                                while($val_query=mysql_fetch_array($all_records))
                                                                {
                                                                    if($bgColorCounter%2==0)
                                                                        $bgcolor='class="grey_td"';
                                                                    else
                                                                        $bgcolor=""; 

                                                                    if($val_query['type']=='issue')
                                                                    {
                                                                        $tot_percentage='-'.$val_query['total_percentage'];
                                                                    }
                                                                    else{
                                                                        $tot_percentage=$val_query['total_percentage'];
                                                                    }
                                                                    include "include/paging_script.php";
                                                                    $listed_record_id=$val_query['id']; 
                                                                    $sel_branch_name="select branch_id,branch_name,cm_id from branch where 1 and cm_id='".$val_query['cm_id']."'";
                                                                    $ptr_sel_name=mysql_query($sel_branch_name);
                                                                    $data_branch_name=mysql_fetch_array($ptr_sel_name);
                                                                    $emp_name="select name from site_setting where 1 and admin_id='".$val_query['staff_id']."'";
                                                                    $ptr_emp_name=mysql_query($emp_name);
                                                                    $data_emp_name=mysql_fetch_array($ptr_emp_name);
                                                                    ?>
                                                                    <tr>
                                                                        <td>
                                                                            <?php echo $sr_no; ?>
                                                                        </td>
                                                                        <?php
                                                                        if($_SESSION['type']=='S' || $_SESSION['branch_access']=='yes')
                                                                            {   
                                                                                ?>
                                                                                <td align="center"><?php echo ucfirst($data_branch_name['branch_name'])?></td>
                                                                                <?php
                                                                            }
                                                                            ?>
                                                                        <td>
                                                                            <?php echo ucfirst($data_emp_name['name'])?>
                                                                        </td>
                                                                        <td>
                                                                            <?php echo date("d-m-Y",strtotime($val_query['date']))?>
                                                                        </td>
                                                                        <td>
                                                                            <?php 
                                                                            echo ucfirst($val_query['type'])
                                                                            ?>
                                                                        </td>
                                                                        <td>
                                                                            <?php 
                                                                            if($val_query['type']=='issue'){
                                                                                echo $val_query['damage_val'];
                                                                            }
                                                                            else{
                                                                                echo '-';
                                                                            }
                                                                            ?>
                                                                        </td>
                                                                        <td>
                                                                            <?php echo $tot_percentage?>
                                                                        </td>
                                                                        <td>
                                                                            <?php 
                                                                            echo ucfirst($val_query['comment']);
                                                                            ?>
                                                                        </td>
                                                                        <td>
                                                                            <?php echo date("d-m-Y",strtotime($val_query['added_date']))?>
                                                                        </td>
                                                                        <td>
                                                                            <?php
                                                                                // if(in_array($parent_pages_ids,$prevk_edit_ids) || $_SESSION['type']=='S') 
                                                                                // {
                                                                                    echo '<a href="tk_issue_accolades.php?record_id='.$listed_record_id.'" ><i
                                                                                    class="fa fa-edit"></i></a>&nbsp;&nbsp;';
                                                                                // }
                                                                                // if(in_array($parent_pages_ids,$prevk_delete_ids) || $_SESSION['type']=='S') 
                                                                                // {
                                                                                    echo '<a onclick="return validationToDelete(\''.$_SERVER['PHP_SELF'].'\');" href="'.$_SERVER['PHP_SELF'].'?deleteRecord=1&record_ids='.$listed_record_id.'&page='.$_REQUEST['page'].$query_string1.'"><i class="fa fa-trash"></i></a>&nbsp;&nbsp;';
                                                                                // }
                                                                            ?>
                                                                        </td>
                                                                    </tr>
                                                                    <?php
                                                                    $bgColorCounter++;
                                                                }
                                                                ?>
                                                                <tr class="head_td">
                                                                    <td colspan="17">
                                                                        <table cellspacing="0" cellpadding="0" width="100%">
                                                                            <tr>
                                                                                <?php
                                                                        if($no_of_records>10)
                                                                        {
                                                                            echo '<td width="5%" align="left"> Show &nbsp;&nbsp;</td>
                                                                            <td width="20%" align="left"><select class="form-control" name="show_records" onchange="redirect(this.value)">';
                                                                            $show_records=array(0=>'10',1=>'20','50','100','200');
                                                                            for($s=0;$s<count($show_records);$s++)
                                                                            {
                                                                                if($_SESSION['show_records']==$show_records[$s])
                                                                                    echo '<option selected="selected" value="'.$show_records[$s].'">'.$show_records[$s].' Records</option>';
                                                                                else
                                                                                    echo '<option value="'.$show_records[$s].'">'.$show_records[$s].' Records</option>';
                                                                            }
                                                                            echo'</td></select>';
                                                                        }
                                                                        echo '<td width="75%" align="right">'.$pager->renderFullNav().'</td>';
                                                                        ?>
                                                                            </tr>
                                                                        </table>
                                                                    </td>
                                                                </tr>
                                                                <?php
                                                            }
                                                            ?>
                                                        </tbody>
                                                    </table>
                                                </div>
                                            </tr>
                                        </table>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </section>
        </div>
        <?php include "include/footer-main.php"; ?>
    </div>
    <!-- jQuery 3 -->
    <script src="bower_components/jquery/dist/jquery.min.js"></script>
    <!-- Bootstrap 3.3.7 -->
    <script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
    <!-- Select2 -->
    <script src="bower_components/select2/dist/js/select2.full.min.js"></script>
    <!-- InputMask -->
    <script src="plugins/input-mask/jquery.inputmask.js"></script>
    <script src="plugins/input-mask/jquery.inputmask.date.extensions.js"></script>
    <script src="plugins/input-mask/jquery.inputmask.extensions.js"></script>
    <!-- date-range-picker -->
    <script src="bower_components/moment/min/moment.min.js"></script>
    <script src="bower_components/bootstrap-daterangepicker/daterangepicker.js"></script>
    <!-- bootstrap datepicker -->
    <script src="bower_components/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js"></script>
    <!-- bootstrap color picker -->
    <script src="bower_components/bootstrap-colorpicker/dist/js/bootstrap-colorpicker.min.js"></script>
    <!-- bootstrap time picker -->
    <script src="plugins/timepicker/bootstrap-timepicker.min.js"></script>
    <!-- SlimScroll -->
    <script src="bower_components/jquery-slimscroll/jquery.slimscroll.min.js"></script>
    <!-- iCheck 1.0.1 -->
    <script src="plugins/iCheck/icheck.min.js"></script>
    <!-- FastClick -->
    <script src="bower_components/fastclick/lib/fastclick.js"></script>
    <!-- AdminLTE App -->
    <script src="dist/js/adminlte.min.js"></script>
    <!-- AdminLTE for demo purposes -->
    <script src="dist/js/demo.js"></script>
    <!-- Page script -->
    <script>
        $(function () {
            //Initialize Select2 Elements
            $('.select2').select2()

            //Datemask dd/mm/yyyy
            /*$('#datemask').inputmask('dd/mm/yyyy', { 'placeholder': 'dd/mm/yyyy' })
            //Datemask2 mm/dd/yyyy
            $('#datemask2').inputmask('mm/dd/yyyy', { 'placeholder': 'mm/dd/yyyy' })
            //Money Euro
            $('[data-mask]').inputmask()
        
            //Date range picker
            $('#reservation').daterangepicker()
            //Date range picker with time picker
            $('#reservationtime').daterangepicker({ timePicker: true, timePickerIncrement: 30, format: 'MM/DD/YYYY h:mm A' })
            //Date range as a button
            $('#daterange-btn').daterangepicker(
              {
                ranges   : {
                  'Today'       : [moment(), moment()],
                  'Yesterday'   : [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
                  'Last 7 Days' : [moment().subtract(6, 'days'), moment()],
                  'Last 30 Days': [moment().subtract(29, 'days'), moment()],
                  'This Month'  : [moment().startOf('month'), moment().endOf('month')],
                  'Last Month'  : [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
                },
                startDate: moment().subtract(29, 'days'),
                endDate  : moment()
              },
              function (start, end) {
                $('#daterange-btn span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'))
              }
            )*/

            //Date picker
            $('#add_date').datepicker({
                autoclose: true,
                format: 'dd/mm/yyyy',
                // startDate: '-0d',
                Default: true,
                todayHighlight: true
            })
            $('#to_date').datepicker({
                autoclose: true,
                format: 'dd/mm/yyyy',
                Default: true,
                todayHighlight: true
            })
            $('#date').datepicker({
                autoclose: true,
                format: 'dd/mm/yyyy',
                Default: true,
                todayHighlight: true
            })
            //iCheck for checkbox and radio inputs
            $('input[type="checkbox"].minimal, input[type="radio"].minimal').iCheck({
                checkboxClass: 'icheckbox_minimal-blue',
                radioClass: 'iradio_minimal-blue'
            })
            //Red color scheme for iCheck
            $('input[type="checkbox"].minimal-red, input[type="radio"].minimal-red').iCheck({
                checkboxClass: 'icheckbox_minimal-red',
                radioClass: 'iradio_minimal-red'
            })
            //Flat red color scheme for iCheck
            $('input[type="checkbox"].flat-red, input[type="radio"].flat-red').iCheck({
                checkboxClass: 'icheckbox_flat-green',
                radioClass: 'iradio_flat-green'
            })
            $('input[type="checkbox"].flat-red, input[type="radio"].flat-red').iCheck({
                checkboxClass: 'icheckbox_flat-green',
                radioClass: 'iradio_flat-yellow'
            })

            //Colorpicker
            $('.my-colorpicker1').colorpicker()
            //color picker with addon
            $('.my-colorpicker2').colorpicker()

            //Timepicker
            $('.timepicker').timepicker({
                showInputs: false
            })
        })
    </script>
    <?php
	if($_SESSION['type']!='S' || $edit_access!='yes'){
		?>
    <script>
        branch = document.getElementById("branch_name").value;
        select_staff(branch);
    </script>
    <?php
	}
	?>
</body>

</html>