<?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>Key Performance Index </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 show_records(value)
{
    table=value.split("-");
	if(table[0]=="non_tech")
	{
		document.getElementById("tbl1").style.display = 'block';
        document.getElementById("tbl2").style.display = 'none';
	}
	else if(table[0]=="faculty")
	{
		document.getElementById("tbl1").style.display = 'none';
        document.getElementById("tbl2").style.display = 'block';
	}
}
function check_value(cst_val,ids,id)
{
    if(cst_val=='yes')
	{
        document.getElementById("absent_status"+id).style.display = 'none';
        setTimeout(cal_points(cst_val,ids,id),10);
    }
    else if(cst_val=='no')
	{
        document.getElementById("absent_status"+id).style.display = 'block';
        document.getElementById("percentage"+id).value=0;
		document.getElementById("tot_points"+id).value=0;
		document.getElementById("final_point"+id).value=0;

    }
}
function cal_points(cst_val,ids,id)
{
	var ok='';	
    this1='';
    sta=document.getElementById("status"+id).value;
    if(sta=='yes'){
        if(cst_val=='yes')
        {
            ok=document.getElementById("class_start_time_mark"+ids).value;
            this1=ok;
        }
        else if(cst_val=='no')
        {
            ok=document.getElementById("class_start_time_mark"+ids).value;
            this1='-'+ ok;
        }
        document.getElementById("pointing"+ids).value=this1;
        setTimeout(calculate_total(id),500);
    }
    else if (sta=='no'){
        alert('Please Make Staff first Present');
        setTimeout(window.location.reload(),500);
    }
}
function calculate_total(id) {
    total_points = 0;
    final_point = 0;
    var ids_array = document.getElementById("ids_array" + id).value;
    var new_array = ids_array.split(",");
    var total_cnt = document.getElementById("total_cnt").value;
    var result = "";
    for (var i = 0; i < new_array.length; i++) {
        var value = new_array[i];
        var ok = document.getElementById("pointing" + value).value;
        result += ok;
        if (i < new_array.length - 1) {
            result += ","; 
        }
        total_points += Number(ok);
        var poi = document.getElementById("class_start_time_mark" + value).value;
        final_point += Number(poi);
    }
    // result += "";
    val1 = total_points / final_point;
    tot_per = val1 * 100;
    document.getElementById("percentage" + id).value = Math.round(tot_per);
    document.getElementById("tot_points" + id).value = Math.round(total_points);
    document.getElementById("final_point" + id).value = final_point;
    document.getElementById("value_array" + id).value = result;
}
    
    function submit_data(adminid,id)
	{
	    //alert(adminid."-".id);
        branch_name=document.getElementById("branch_name").value;
        dates=document.getElementById("date").value;
        tot_points=document.getElementById("tot_points"+id).value;
        percentage=document.getElementById("percentage"+id).value;
        comment=document.getElementById("comment"+id).value;
        status=document.getElementById("status"+id).value;
        absent_status=document.getElementById("absent_status"+id).value;
        key_array=document.getElementById("key_array"+id).value;
        value_array=document.getElementById("value_array"+id).value;
        var type_data="action=add_kpi&branch_name="+branch_name+"&adminid="+adminid+"&dates="+dates+"&tot_points="+tot_points+"&percentage="+percentage+"&comment="+comment+"&status="+status+"&absent_status="+absent_status+"&key_array="+key_array+"&value_array="+value_array;
	    $.ajax({
            url: "tk_fill_kpi_ajax.php",type:"post", data: type_data,cache: false,
            success: function(rettype)
            {
                 alert(rettype);
                alert('Recored Added Successfully');
                setTimeout(window.location.reload(),500);
            }
        });
    }
    function absent_points(info,id)
	{
			if(info=='yes'){
				point='-'+100;
			}
			else{
				point=0;
			}
			document.getElementById("percentage"+id).value=point;
            document.getElementById("tot_points"+id).value=point;
            document.getElementById("final_point"+id).value=point;
	}
function check_value_f(cst_val,ids,id)
{
    if(cst_val=='yes')
	{
        document.getElementById("absent_status_f"+id).style.display = 'none';
        setTimeout(cal_points_f(cst_val,ids,id),100);
    }
    else if(cst_val=='no')
	{
        document.getElementById("absent_status_f"+id).style.display = 'block';
        document.getElementById("percentage_f"+id).value=0;
		document.getElementById("tot_points_f"+id).value=0;
		document.getElementById("final_point_f"+id).value=0;
    }
}
function cal_points_f(cst_val,ids,id)
{
	var ok='';	
    this1='';
    sta=document.getElementById("status_f"+id).value;
    if(sta=='yes'){
        if(cst_val=='yes')
        {
            ok=document.getElementById("faculty_kpi"+ids).value;
            this1=ok;
        }
        else if(cst_val=='no')
        {
            ok=document.getElementById("faculty_kpi"+ids).value;
            this1='-'+ ok;
        }
        // alert(this1)
        document.getElementById("pointing_f"+ids).value=this1;
        setTimeout(calculate_total_f(id),500);
    }
    else if (sta=='no'){
        alert('Please Make Staff first Present');
        setTimeout(window.location.reload(),500);
    }
}
function calculate_total_f(id)
	{
        // alert(id);
		total_points = 0;
		final_point= 0;
        var ids_array_f=document.getElementById("ids_array_f"+id).value;
        var new_array_f = ids_array_f.split(",");
        var result_f = "";
		var total_cnt=document.getElementById("total_cnt").value;
        for (var i = 0; i < new_array_f.length; i++) {
            var value = new_array_f[i];
            var ok = document.getElementById("pointing_f" + value).value;
            result_f += ok;
            if (i < new_array_f.length - 1) {
                result_f += ","; 
            }
            total_points += Number(ok);
            var poi = document.getElementById("faculty_kpi" + value).value;
            final_point += Number(poi);
        }
        val1=total_points /final_point;
        tot_per=val1*100;
        document.getElementById("percentage_f"+id).value=Math.round(tot_per);
		document.getElementById("tot_points_f"+id).value=Math.round(total_points);
		document.getElementById("final_point_f"+id).value=Math.round(final_point);
        document.getElementById("value_array_f" + id).value = result_f;
	}
    function absent_points_f(info,id)
	{
			if(info=='yes'){
				point='-'+100;
			}
			else{
				point=0;
			}
			document.getElementById("percentage_f"+id).value=point;
            document.getElementById("tot_points_f"+id).value=point;
            document.getElementById("final_point_f"+id).value=point;
	}
    function submit_data_f(adminid_f,id)
	{
        branch_name=document.getElementById("branch_name").value;
        dates=document.getElementById("date").value;
        tot_points_f=document.getElementById("tot_points_f"+id).value;
        percentage_f=document.getElementById("percentage_f"+id).value;
        comment_f=document.getElementById("comment_f"+id).value;
        status_f=document.getElementById("status_f"+id).value;
        absent_status_f=document.getElementById("absent_status_f"+id).value;
        key_array_f=document.getElementById("key_array_f"+id).value;
        value_array_f=document.getElementById("value_array_f"+id).value;
        var type_data1="action=add_kpi_f&branch_name="+branch_name+"&adminid_f="+adminid_f+"&dates="+dates+"&tot_points_f="+tot_points_f+"&percentage_f="+percentage_f+"&comment_f="+comment_f+"&status_f="+status_f+"&absent_status_f="+absent_status_f+"&key_array_f="+key_array_f+"&value_array_f="+value_array_f;
        // alert(type_data1);
	    $.ajax({
            url: "tk_fill_kpi_ajax.php",type:"post", data: type_data1,cache: false,
            success: function(ret)
            {
                alert('Recored Added Successfully');
                setTimeout(window.location.reload(),500);
            }
        });
    }
</script>
<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>
                    Key Performance Index
                </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                   
            ?>
            <section class="content">
                <div class="box box-default">
                    <div class="box-body">
                        <div class="row">
                            <div class="col-md-12">
                                <form method="GET" id="jqueryForm" name="jqueryForm" enctype="multipart/form-data" >                              
                                    <div class="row justify-content-center">
                                        <div class="col-md-6">
                                            <!-- <div id="phonenumber" class="masked-number">9172083288</div>
                                            <input type="button" id="btns" onclick="show_no()" value='show'/>
                                            <script>
                                                const phoneNumberElement = document.getElementById('phonenumber');
                                                const actualPhoneNumber = phoneNumberElement.textContent;

                                                const maskedPhoneNumber = actualPhoneNumber.replace(/\d(?=\d{2})/g, '*');
                                                phoneNumberElement.textContent = maskedPhoneNumber;

                                                function show_no() {
                                                    if (phoneNumberElement.textContent === maskedPhoneNumber) {
                                                        phoneNumberElement.textContent = actualPhoneNumber;
                                                        document.getElementById('btns').value='Hide';
                                                    } else {
                                                        phoneNumberElement.textContent = maskedPhoneNumber;
                                                        document.getElementById('btns').value='Show';
                                                    }
                                                }
                                            </script> -->
                                            <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($_REQUEST['date']) echo $_REQUEST['date']; 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" class="form-control select2" onchange="getstaffDetails(this.value)">
                                                        <option value="">Select Branch</option>
                                                        <?php 
                                                        $sel_branch="select branch_id,branch_name from branch where status='Active'";
                                                        $ptr_sel=mysql_query($sel_branch);
                                                        while($data_branch=mysql_fetch_array($ptr_sel))
                                                        {
                                                            $sel='';
                                                            if($data_branch['branch_name']==$_GET['branch_name'] || $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 for="staff_type">
                                                    <span class="text-danger">*</span> Types 
                                                    <span class="text-danger"><?php echo $task_Err ;?></span>
                                                </label>
                                                <select name="staff_type" id="staff_type" class="form-control select2">
                                                    <!-- <option value="">Select</option> -->
                                                    <option value="non_tech" <?php if ($_GET['staff_type'] == "non_tech") echo "selected='selected'";?>>Non Technical</option>  
                                                    <option value="faculty" <?php if ($_GET['staff_type'] == "faculty") echo "selected='selected'";?>>Faculty</option> 
                                                </select>
                                            </div>
                                            <div class="form-group text-center">
                                                <input type="submit" onclick="return validme()" name="save_changes" value="Check Record" class="btn btn-success">
                                            </div>
                                        </div>
                                    </div>
                                </form>
                                <div class="box-body">
                                    <?php
                                    if($_REQUEST['date'])
                                    {
                                        $frm_date=explode("/",$_REQUEST['date']);
                                        $frm_dates=$frm_date[2]."-".$frm_date[1]."-".$frm_date[0];
                                        $start_date=$frm_dates;
                                    }
                                    else{
                                        $start_date=date("Y-m-d");
                                    }
                                    if($_REQUEST['branch_name']!='')
                                        {
                                            $branch_name=$_REQUEST['branch_name'];
                                            $select_cm_id="select cm_id from site_setting where branch_name='".$branch_name."' and type='A'";
                                            $ptr_cm_id=mysql_query($select_cm_id);
                                            $data_cm_id=mysql_fetch_array($ptr_cm_id);
                                            $cm_ids=$data_cm_id['cm_id'];
                                            $search_cm_id="and cm_id='".$data_cm_id['cm_id']."'";
                                        }
                                    else
                                        {
                                            $search_cm_id="";
                                        }
                                    if($_REQUEST['staff_type']=='non_tech')
                                    {    
                                        ?>        
                                        <table id="tbl1" class="table no-margin" style="text-align:center">
                                            <tr>
                                                <td width="10%" style="background-color:#E6FFE6"><strong>Positive (+)</strong></td>
                                                <td width="10%" style="background-color:#FFE6E6"><strong>Negative (-)</strong></td>
                                                <td width="80%" colspan="09" align="center"><div style="font-size: 24px;"><b>Not Technical Staff ( <?php if($_REQUEST['branch_name']!='') echo ucfirst($_GET['branch_name']) ; else echo 'Pune' ;?>)  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue"><?php echo date('d-m-Y',strtotime($start_date)) ; ?></span></b></div> </td>
                                            </tr>
                                            <tr style="text-align:center">
                                                <td align="center"><strong>Sr. No.</strong></td>
                                                <td align="center"><strong>Staff Name</strong></td>
                                                <?php
                                                $sel_type1 = "SELECT * FROM pm_key_performance_point WHERE employee_type != 'F' ORDER BY key_id ASC";
                                                $ptr_type1 = mysql_query($sel_type1);
                                                $cnt = mysql_num_rows($ptr_type1);
                                                $i = 1;
                                                while ($type_data1 = mysql_fetch_array($ptr_type1)) {
                                                    ?>
                                                    <td>
                                                        <table class="" style="text-align:center; width: 100%;">
                                                            <tr>
                                                                <td colspan="2"><strong><?php echo $type_data1['key_title']; ?></strong></td>
                                                            </tr>
                                                            <tr>
                                                                <td colspan="2" ><strong><?php echo $type_data1['point']; ?></strong></td>
                                                            </tr>
                                                            <!-- <tr>
                                                                <td style="background-color:#E6FFE6"><strong>Yes</strong></td>
                                                                <td style="background-color:#FFE6E6"><strong>No</strong></td>
                                                            </tr> -->
                                                        </table>
                                                    </td>
                                                    <?php
                                                }
                                                ?>
                                                <td align="center"><strong>Presence</strong></td>
                                                <td align="center"><strong>Total Point Get</strong></td>
                                                <td align="center"><strong>Total Percentage %</strong></td>
                                            </tr>

                                            <?php
                                            $bgColorCounter=1;
                                            if($search_cm_id)
                                            $sel_staff="select admin_id,name,type from site_setting where 1 and system_status='Enabled' and type!='F' ". $search_cm_id." order by name asc";
                                            $ptr_staff=mysql_query( $sel_staff);
                                            $s=1;
                                            while($data_staff=mysql_fetch_array( $ptr_staff))
                                            {
                                                if($bgColorCounter%2==0){
                                                    $bgcolor='class="grey_td"';
                                                }
                                                else{
                                                    $bgcolor="";    
                                                }            
                                                $listed_record_id=$data_staff['admin_id'];
                                                '<br>'.$sel_pres="select attendance_id,total_hrs from pr_daily_attendance where employee_id='".$listed_record_id."' ".$search_cm_id." and DATE(date)='".$start_date."'";
                                                    $ptr_pres=mysql_query($sel_pres);
                                                    $data_pres=mysql_fetch_array($ptr_pres); 
                                                ?>
                                                <tr <?php echo $bgcolor ?> style="text-align:center">
                                                    <td width="" align="center"><?php echo $i++;?></td>
                                                    <td width="" align="center"><?php echo ucwords($data_staff['name']);?></td>
                                                    <?php
                                                    $sel_type="select * from pm_key_performance_point where 1 and employee_type !='F'  order by key_id ASC";
                                                    $ptr_type=mysql_query($sel_type);
                                                    $cnt=mysql_num_rows($ptr_type);
                                                    $keyids='';
                                                    $key_array='';
                                                    $kl=1;
                                                    $dt='';
                                                    while($type_data=mysql_fetch_array($ptr_type))
                                                    {
                                                        $kid=$type_data['key_id'];
                                                        if($cnt==$kl){
                                                            $keyids.= $kid.''.$s;
                                                            $key_array.=$type_data['key_id'];
                                                        }
                                                        else
                                                        {
                                                            $keyids.= $kid.''.$s.',';
                                                            $key_array.=$type_data['key_id'].',';
                                                        }
                                                        $kl++;
                                                        $sel_perfo="SELECT * FROM `pm_total_keypoint_performancee` WHERE 1 ". $search_cm_id." and employee_id='".$data_staff['admin_id']."' and DATE(date)='".$start_date."' ";
                                                        $ptr_perfo=mysql_query($sel_perfo);
                                                        $no_recs=mysql_num_rows($ptr_perfo);
                                                        $data_recs=mysql_fetch_array($ptr_perfo);

                                                        $sel_fill="select * from pm_daily_keypoint_performance where 1 and employee_id='".$listed_record_id."' ".$search_cm_id." and DATE(date)='".$start_date."' and key_point_id='".$type_data['key_id']."'";
                                                        $ptr_fill=mysql_query($sel_fill);
                                                        $tot_fill=mysql_num_rows($ptr_fill);
                                                        $data_fill=mysql_fetch_array($ptr_fill);

                                                        $checkedt = '';
                                                        $checked = ''; 
                                                        if($no_recs){
                                                            $disabled = 'disabled';
                                                        }
                                                        else{
                                                            $disabled = '';
                                                        }
                                                        if ($data_recs['status'] == 'absent') {
                                                            $checkedt = '';
                                                            $checked = ''; 
                                                        } elseif ($data_fill['presence'] == 'yes') {
                                                            if ($data_fill['points'] == $type_data['point']) {
                                                                $checked = 'checked="checked"';
                                                                $nob = 2;
                                                            } elseif ($data_fill['points'] != $type_data['point'] || $data_fill['points'] < 0) {
                                                                $checkedt = 'checked="checked"';
                                                                $nob = 3; 
                                                            }
                                                        } else {
                                                            $checkedt = '';
                                                            $checked = 'checked="checked"';
                                                            $nob = 4; 
                                                        }
                                                        ?>
                                                        <td>
                                                            <div id="keys<?php echo $s ?>" >
                                                                <table class="table no-margin" style="text-align:center; width: 100%;">
                                                                    <tr>
                                                                        <td width="" colspan="" style="background-color:#E6FFE6" align="center">
                                                                            <input type="radio" name="check1'<?php echo $kid.''.$s ?>" id="class_start_time_r_y<?php echo $kid.''.$s ?>" onchange="cal_points(this.value,<?php echo $kid.''.$s ?>,<?php echo $s?>)" <?php echo  $checked ?> class="input_radio" value="yes" placeholder="hi" <?php echo  $disabled ?> >
                                                                        </td>
                                                                        <td width="" colspan="" style="background-color:#FFE6E6" align="center">
                                                                            <input type="radio" name="check1'<?php echo $kid.''.$s ?>" id="class_start_time_r_n<?php echo $kid.''.$s ?>" onchange="cal_points(this.value,<?php echo $kid.''.$s ?>,<?php echo $s ?>)" <?php echo  $checkedt ?> class="input_radio" value="no" <?php echo  $disabled ?>>
                                                                        </td>
                                                                        <input type="hidden" name="" style="text-align:center;" class="form-control" id="class_start_time_mark<?php echo $kid.''.$s ?>" value="<?php echo $type_data['point'] ?>">
                                                                        <input type="hidden" name="pointing<?php echo $kid.''.$s ?>" style="text-align:center;" class="form-control" id="pointing<?php echo $kid.''.$s ?>" value="<?php echo $type_data['point'] ?>">
                                                                    </tr>
                                                                </table>
                                                            </div>
                                                        </td>
                                                        <?php
                                                        $t2++;
                                                        $dt=$kid.''.$s;
                                                    }
                                                    echo '<input type="hidden" name="ids_array'.$s.'" id="ids_array'.$s.'" value="'.$keyids.'" />';
                                                    echo '<input type="hidden" name="key_array'.$s.'" id="key_array'.$s.'" value="'.$key_array.'" />';
                                                    echo '<input type="hidden" name="value_array'.$s.'" id="value_array'.$s.'" value="" />';
                                                    echo '<input type="hidden" name="total_cnt" id="total_cnt" value="'.$cnt.'" />';
                                                    ?>
                                                    <?php
                                                    if($data_pres['attendance_id']!='')
                                                        {
                                                            $present="'yes'";
                                                            ?>
                                                            <script>
                                                                document.addEventListener("DOMContentLoaded", function() {
                                                                check_value(<?php echo $present.','.$dt.','.$s?>);
                                                            });

                                                            </script>
                                                            <?php
                                                        }
                                                        else{
                                                            $present="'no'";
                                                            ?>
                                                            <script>
                                                                document.addEventListener("DOMContentLoaded", function() {
                                                                check_value(<?php echo $present.','.$dt.','.$s?>);
                                                            });

                                                            </script>
                                                            <?php
                                                        }
                                                        ?>
                                                    <td width="" align="center">
                                                        <div style="display:flex;">
                                                            <select name="status<?php echo $s ?>" id="status<?php echo $s ?>" class="form-control" style="width:70px" onChange="check_value(this.value,<?php echo $dt.','.$s ?>)">
                                                                <?php
                                                                if($data_recs['status']=='present'){
                                                                    ?>
                                                                    <option value="yes" >Yes</option>  
                                                                    <?php
                                                                }
                                                                elseif ($data_recs['status']=='absent'){
                                                                    ?>
                                                                    <option value="no" >No</option>  
                                                                    <?php
                                                                }
                                                                else{
                                                                    ?>
                                                                    <option value="yes" <?php if($data_pres['attendance_id']!='') echo "selected='selected'";?>>Yes</option>  
                                                                    <option value="no" <?php if($data_pres['attendance_id']=='') echo "selected='selected'";?>>No</option>
                                                                    <?php
                                                                }
                                                                ?>
                                                            </select>&nbsp;
                                                            <?php
                                                            
                                                            if($no_recs==''){
                                                                ?>
                                                                <select name="absent_status<?php echo $s ?>" id="absent_status<?php echo $s ?>" style="display:none;width:70px" class="form-control"  onChange="absent_points(this.value,<?php echo $s ?>)">
                                                                    <option value="no">No</option>
                                                                    <option value="yes">Yes</option>  
                                                                </select>
                                                                <?php
                                                            }
                                                            ?>
                                                        </div>
                                                    </td>
                                                    <td width="" align="center"><strong>
                                                    <?php 
                                                    if($no_recs){
                                                        $vali1=$data_recs['total_point'];
                                                        $vali2=$data_recs['total_percentage'];
                                                        $read='readonly="readonly"';
                                                    }
                                                    else{
                                                        $vali1=' ';
                                                        $vali2=' ';
                                                        $read='';
                                                    }
                                                            ?>
                                                        <input type="text" name="points" class="form-control" readonly="readonly" id="tot_points<?php echo $s ?>" title="points" value="<?php  echo $vali1?>">
                                                        <input type="hidden" name="final_point" class="form-control" readonly="readonly" id="final_point<?php echo $s ?>" value="">    
                                                    </td>
                                                    <td width="" align="center"><strong>
                                                        <input type="text" name="percentage" class="form-control" readonly="readonly" id="percentage<?php echo $s ?>" value="<?php  echo $vali2?>">
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td colspan="2" align="right"> <b>Comment : </b></td>
                                                    <td colspan="6" align=""><input type="text" name="comment<?php echo $s ?>" style="width:400px;margin-left:50px" class="form-control" id="comment<?php echo $s ?>" <?php echo $read ?> value="<?php echo $data_recs['comment'] ?>"></td>
                                                    <td align="right" colspan="3">
                                                        <?php
                                                        if( $no_recs){
                                                            ?>
                                                            <img src="images/enroll_cmpleted1.png" width="90px"/>
                                                            <?php
                                                        }
                                                        else{
                                                            ?>
                                                            <input type="button" class="btn btn-success btn-sm" onclick="submit_data(<?php echo $listed_record_id.','.$s?>)" style="width:100px" value="Save"  />
                                                            <?php
                                                        }
                                                        ?>
                                                    </td>
                                                </tr>
                                                <?php
                                                    $bgColorCounter++;
                                                    $s++;
                                            }
                                            ?>
                                        </table>
                                        <?php
                                    }
                                    if($_REQUEST['staff_type']=='faculty')
                                    {    
                                        ?>
                                        <div style="overflow-x: auto;">
                                            <table border="0" class="table no-margin" style="text-align:center;width: 100%;" id='tbl2'>
                                                <tr>
                                                    <td width="98%" colspan="17" align="center">
                                                        <div style="display:flex">
                                                            <div style="background-color:#E6FFE6;width:100px"><strong>Positive (+)</strong></div>
                                                            <div  style="background-color:#FFE6E6;width:100px"><strong>Negative (-)</strong></div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                                            <div style="font-size: 24px;margin-left:27%"><b>Faculty Staff  ( <?php if($_REQUEST['branch_name']!='') echo ucfirst($_GET['branch_name']) ; else echo 'Pune' ;?>)  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue"><?php echo date('d-m-Y',strtotime($start_date)) ; ?></span></b></div> 
                                                        </div> 
                                                    </td>
                                                </tr>
                                                <tr class="" style="text-align:center">
                                                    <td width="" align="center"><strong>Sr. No.</strong></td>
                                                    <td width="" align="center"><strong>Staff Name</strong></td>
                                                    <?php
                                                    $sel_type1="select * from pm_key_performance_point where 1 and employee_type ='F'  order by key_id ASC";
                                                    $ptr_type1=mysql_query($sel_type1);
                                                    $cnt=mysql_num_rows($ptr_type1);
                                                    $i=1;
                                                    while($type_data1=mysql_fetch_array($ptr_type1))
                                                    {
                                                        ?>
                                                        <td>
                                                            <table class="" style="text-align:center; width: 100%;">
                                                                <tr>
                                                                    <td colspan="2"><strong><?php echo $type_data1['key_title']; ?></strong></td>
                                                                </tr>
                                                                <tr>
                                                                    <td colspan="2" ><strong><?php echo $type_data1['point']; ?></strong></td>
                                                                </tr>
                                                                <!-- <tr>
                                                                    <td style="background-color:#E6FFE6"><strong>Yes</strong></td>
                                                                    <td style="background-color:#FFE6E6"><strong>No</strong></td>
                                                                </tr> -->
                                                            </table>
                                                        </td>
                                                        <?php
                                                    }
                                                    ?>
                                                    <td align="center"><strong>Presence</strong></td>
                                                    <td align="center"><strong>Total Point Get</strong></td>
                                                    <td align="center"><strong>Total Perc. %</strong></td>
                                                </tr>
                                                <?php
                                                $bgColorCounter=1;
                                                if($search_cm_id)
                                                $sel_staff="select admin_id,name,type from site_setting where 1 and system_status='Enabled' and type='F' ". $search_cm_id." order by name asc";
                                                $ptr_staff=mysql_query( $sel_staff);
                                                $s1=1;
                                                while($data_staff=mysql_fetch_array( $ptr_staff))
                                                {
                                                    if($bgColorCounter%2==0){
                                                        $bgcolor='class="grey_td"';
                                                    }
                                                    else{
                                                        $bgcolor="";    
                                                    }            
                                                    $listed_record_id=$data_staff['admin_id'];
                                                    '<br>'.$sel_pres="select attendance_id,total_hrs from pr_daily_attendance where employee_id='".$listed_record_id."' ".$search_cm_id." and DATE(date)='".$start_date."'";
                                                        $ptr_pres=mysql_query($sel_pres);
                                                        $data_pres=mysql_fetch_array($ptr_pres); 
                                                    ?>
                                                    <tr <?php echo $bgcolor ?> style="text-align:center">
                                                        <td width="" align="center"><?php echo $i++;?></td>
                                                        <td width="" align="center"><?php echo ucwords($data_staff['name']);?></td>
                                                        <?php
                                                        $sel_type="select * from pm_key_performance_point where 1 and employee_type ='F'  order by key_id ASC";
                                                        $ptr_type=mysql_query($sel_type);
                                                        $cnt=mysql_num_rows($ptr_type);
                                                        $keyids_f='';
                                                        $key_array_f='';
                                                        $kl=1;
                                                        $dt='';
                                                        while($type_data=mysql_fetch_array($ptr_type))
                                                        {
                                                            $kid1=$type_data['key_id'];
                                                            if($cnt==$kl){
                                                                $keyids_f.= $kid1.''.$s1;
                                                                $key_array_f.=$type_data['key_id'];
                                                            }
                                                            else
                                                            {
                                                                $keyids_f.= $kid1.''.$s1.',';
                                                                $key_array_f.=$type_data['key_id'].',';
                                                            }
                                                            $kl++;
                                                            $sel_perfo="SELECT * FROM `pm_total_keypoint_performancee` WHERE 1 ". $search_cm_id." and employee_id='".$data_staff['admin_id']."' and DATE(date)='".$start_date."' ";
                                                            $ptr_perfo=mysql_query($sel_perfo);
                                                            $no_recs=mysql_num_rows($ptr_perfo);
                                                            $data_recs=mysql_fetch_array($ptr_perfo);
                                                            $sel_fill="select * from pm_daily_keypoint_performance where 1 and employee_id='".$data_staff['admin_id']."' ".$search_cm_id." and DATE(date)='".$start_date."' and key_point_id='".$type_data['key_id']."'";
                                                            $ptr_fill=mysql_query($sel_fill);
                                                            $tot_fill=mysql_num_rows($ptr_fill);
                                                            $data_fill=mysql_fetch_array($ptr_fill);

                                                            $checkedt = '';
                                                            $checked = ''; 
                                                            if($no_recs){
                                                                $disabled = 'disabled';
                                                            }
                                                            else{
                                                                $disabled = '';
                                                            }
                                                            if ($data_recs['status'] == 'absent') {
                                                                $checkedt = '';
                                                                $checked = ''; 
                                                            } elseif ($data_fill['presence'] == 'yes') {
                                                                if ($data_fill['points'] == $type_data['point']) {
                                                                    $checked = 'checked="checked"';
                                                                } elseif ($data_fill['points'] != $type_data['point'] || $data_fill['points'] < 0) {
                                                                    $checkedt = 'checked="checked"';
                                                                }
                                                            } else {
                                                                $checkedt = '';
                                                                $checked = 'checked="checked"';
                                                            }
                                                            ?>
                                                            <td align="center" style="width: 10%;">
                                                                <div id="keys<?php echo $s1; ?>">
                                                                    <div style="display: flex; justify-content: center;">
                                                                        <div style="background-color:#E6FFE6; width: 50%;"><input type="radio" name="check1<?php echo $kid1 . $s1; ?>" onchange="cal_points_f(this.value, <?php echo $kid1 . $s1; ?>, <?php echo $s1; ?>)" value="yes" <?php echo  $checked ?> <?php echo  $disabled ?>></div>
                                                                        <div style="background-color:#FFE6E6; width: 50%;"><input type="radio" name="check1<?php echo $kid1 . $s1; ?>" onchange="cal_points_f(this.value, <?php echo $kid1 . $s1; ?>, <?php echo $s1; ?>)" value="no" <?php echo  $checkedt ?> <?php echo  $disabled ?>></div>
                                                                    </div>
                                                                    <input type="hidden" id="faculty_kpi<?php echo $kid1 . $s1; ?>" value="<?php echo $type_data['point']; ?>">
                                                                    <input type="hidden" id="pointing_f<?php echo $kid1 . $s1; ?>" value="<?php echo $type_data['point']; ?>">
                                                                </div>
                                                            </td>
                                                            <?php
                                                            $t2++;
                                                            $d1t=$kid1.''.$s1;
                                                        }
                                                        echo '<input type="hidden" name="ids_array_f'.$s1.'" id="ids_array_f'.$s1.'" value="'.$keyids_f.'" />';
                                                        echo '<input type="hidden" name="key_array_f'.$s1.'" id="key_array_f'.$s1.'" value="'.$key_array_f.'" />';
                                                        echo '<input type="hidden" name="value_array_f'.$s1.'" id="value_array_f'.$s1.'" value="" />';
                                                        echo '<input type="hidden" name="total_cnt" id="total_cnt" value="'.$cnt.'" />';
                                                        ?>
                                                        <?php
                                                        if($data_pres['attendance_id']!='')
                                                            {
                                                                $present="'yes'";
                                                                ?>
                                                                <script>
                                                                    document.addEventListener("DOMContentLoaded", function() {
                                                                        check_value_f(<?php echo $present.','.$d1t.','.$s1?>);
                                                                });

                                                                </script>
                                                                <?php
                                                            }
                                                            else{
                                                                $present="'no'";
                                                                ?>
                                                                <script>
                                                                    document.addEventListener("DOMContentLoaded", function() {
                                                                        check_value_f(<?php echo $present.','.$d1t.','.$s1?>);
                                                                });

                                                                </script>
                                                                <?php
                                                            }
                                                            ?>
                                                        <td width="" align="center">
                                                            <div style="display:flex;">
                                                                <select name="status_f<?php echo $s1 ?>" id="status_f<?php echo $s1 ?>" class="form-control" style="width:70px" onChange="check_value_f(this.value,<?php echo $d1t.','.$s1 ?>)">
                                                                <?php
                                                                    if($data_recs['status']=='present'){
                                                                        ?>
                                                                        <option value="yes" >Yes</option>  
                                                                        <?php
                                                                    }
                                                                    elseif ($data_recs['status']=='absent'){
                                                                        ?>
                                                                        <option value="no" >No</option>  
                                                                        <?php
                                                                    }
                                                                    else{
                                                                        ?>
                                                                            <option value="yes" <?php if($data_pres['attendance_id']!='') echo "selected='selected'";?>>Yes</option>  
                                                                            <option value="no" <?php if($data_pres['attendance_id']=='') echo "selected='selected'";?>>No</option>
                                                                            <?php
                                                                    }
                                                                    ?>
                                                                </select>&nbsp;
                                                                <?php
                                                                if($no_recs=='')
                                                                {
                                                                    ?>
                                                                    <select name="absent_status_f<?php echo $s1 ?>" id="absent_status_f<?php echo $s1 ?>" style="display:none;width:70px" class="form-control" onChange="absent_points_f(this.value,<?php echo $s1 ?>)">
                                                                        <option value="no">No</option>
                                                                        <option value="yes">Yes</option>  
                                                                    </select>
                                                                    <?php
                                                                }
                                                                ?>
                                                            </div>
                                                        </td>
                                                        <td width="" align="center"><strong>
                                                            <?php 
                                                            if($no_recs){
                                                                // $col="";
                                                                $vali1=$data_recs['total_point'];
                                                                $vali2=$data_recs['total_percentage'];
                                                                $read='readonly="readonly"';
                                                            }
                                                            else{
                                                                $vali1=' ';
                                                                $vali2=' ';
                                                                $read='';
                                                            }
                                                                ?>
                                                            <input type="text" name="tot_points_f<?php echo $s1 ?>" style="width:55px" class="form-control" readonly="readonly" id="tot_points_f<?php echo $s1 ?>" title="points" value="<?php  echo $vali1?>">
                                                            <input type="hidden" name="final_point_f<?php echo $s1 ?>" class="form-control" readonly="readonly" id="final_point_f<?php echo $s1 ?>" value="">    
                                                        </td>
                                                        <td width="" align="center"><strong>
                                                            <input type="text" name="percentage_f<?php echo $s1 ?>" style="width:55px" class="form-control" readonly="readonly" id="percentage_f<?php echo $s1 ?>" value="<?php echo $vali2?>">
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td colspan="2" align="right"> <b>Comment : </b></td>
                                                        <td colspan="12" align=""><input type="text" name="comment_f<?php echo $s1 ?>" style="width:400px;margin-left:50px" class="form-control" id="comment_f<?php echo $s1 ?>" <?php echo $read ?> value="<?php echo $data_recs['comment']?>"></td>
                                                        <td align="right" colspan="3">
                                                            <?php
                                                            if($no_recs){

                                                                ?>
                                                                <img src="images/enroll_cmpleted1.png" width="90px"/>
                                                                <?php
                                                            }
                                                            else{
                                                                ?>
                                                                <input type="Button" onclick="submit_data_f(<?php echo $listed_record_id.','.$s1?>)" class="btn btn-success btn-sm"  value="Save"  />
                                                                <?php
                                                            }
                                                            ?>
                                                        </td>
                                                    </tr>
                                                    <?php
                                                    $bgColorCounter++;
                                                    $s1++;
                                                }
                                                ?>
                                            </table>
                                        </div>
                                        <?php
                                    }
                                    ?>
                                </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()
            //Date picker
            $('#datepicker').datepicker({
                autoclose: true,
                format: 'dd/mm/yyyy',
                // startDate: '-0d',
                Default: true,
                todayHighlight: true
            })
            $('#date').datepicker({
                autoclose: true,
                format: 'dd/mm/yyyy',
                Default: true,
                todayHighlight: true
            })
            //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>