<?php include 'inc_classes.php'; 
include "admin_authentication.php";
// include "include/headHeader.php";
// include "include/functions.php"; 

?>
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Add Performance Key Points</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>
<?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>
                    Key Performance Point
                    <!--<small>Version 2.0</small>-->
                </h1>
                <ol class="breadcrumb">
                    <li><a href="#"><i class="fa fa-dashboard"></i>Home</a></li>
                    <li class="active">Dashboard</li>
                </ol>
            </section>

            <?php
                  if($_REQUEST['id']!='')
                  {
                      $record_id=$_REQUEST['id'];
                      $query="select * from pm_key_performance_point where key_id='$record_id'";
                      $ptr_data_3=mysql_query($query);
                      $data=mysql_fetch_array($ptr_data_3);
                  }
                  else
                  {
                      $record_id='';  
                  }
                  if(isset($_REQUEST['submit']))
                    {
                         if (empty($_POST['key_title'])){
                             $title_Err = "Field is required";
                            }
                        else{
                            $key_title=addslashes($_POST['key_title']);
                            }
                        if (empty($_POST['points'])){
                            $points_Err = "Field is required";
                            }
                        else{
                            $points=addslashes($_POST['points']);
                            }
                        if (empty($_POST['emp_type'])){
                            $emp_Err = "Field is required";
                            }
                        else{
                            $emp_type=addslashes($_POST['emp_type']);
                            }

                           $admin_id =$_SESSION['admin_id'];

                        // project upadting
                        if($record_id)
                        {
                            if($key_title !="" &&  $points !="")
                            {
                                $upd_proj="update pm_key_performance_point set `key_title`='".$key_title."',`point`='".$points."',`employee_type`='".$emp_type."',`admin_id`='".$admin_id."',`added_date`='".date('Y-m-d')."' where key_id='".$record_id."' ";
                                $ptr_upd_proj=mysql_query($upd_proj); 
                                if ($ptr_upd_proj)
                                { 
                                    ?>
                                    <!--updating altert meassage box   -->
                                    <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="perforamance_key_point.php";', 1000);</script>
                                    <?php
                                }       
                            }  
                        }
                        else
                        {
                            if($key_title !="" &&  $points !="")
                            {
                                $insert_key="insert into pm_key_performance_point(`key_title`,`point`,`employee_type`,`admin_id`,`added_date`) values('".$key_title."','".$points."','".$emp_type."','".$admin_id."','".date('Y-m-d')."')";
                                $ptr_ins_key=mysql_query($insert_key);
                                if ($ptr_ins_key)
                                { 
                                ?>
                                    <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="perforamance_key_point.php";', 1000);</script>
                                    <?php
                                }
                          }
                        }
                    }
                    if($_REQUEST['deleteRecord']!='' && $_REQUEST['id']!='')
                    {
                        $id=$_REQUEST['id'];
                        $query_1="delete from pm_key_performance_point where key_id='".$id."'";
                        $ptr_data_delete=mysql_query($query_1);
                        if ($ptr_data_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>
                                //  if(confirm("Are you sure, you want to delete selected record(s)?"))
                                setTimeout('document.location.href="perforamance_key_point.php";', 1000);
                            </script>
                            <?php     
                        }
                    }
                    ?>
            <!-- Main content -->
            <section class="content">
                <div class="box box-default">
                    <form name="task_form" method="post">
                        <div class="box-body">
                            <div class="row">
                                <div class="col-md-6">
                                    <p style="color:red"> * Required Field</p>

                                    <div class="form-group">
                                        <label><span style="color:red">*</span>Key Title &nbsp;&nbsp;<span
                                                style="color:red">
                                                <?php echo $title_Err ;?>
                                            </span> </label>
                                        <input type="text" class="form-control" name="key_title" id="key_title"
                                            value="<?=$data['key_title']?>" placeholder="">
                                    </div>
                                    <div class="form-group">
                                        <label><span style="color:red">*</span>Points &nbsp;&nbsp;<span
                                                style="color:red">
                                                <?php echo $points_Err ;?>
                                            </span> </label>
                                        <input type="text" class="form-control" name="points" id="point1"
                                            value="<?=$data['point']?>" placeholder="">
                                    </div>
                                    <div class="form-group">
                                        <label><span style="color:red">*</span>Employee Type &nbsp;&nbsp;<span
                                                style="color:red">
                                                <?php echo $emp_Err ;?>
                                            </span> </label>
                                        <select class="form-control select2" style="width:" name="emp_type"
                                            id="emp_type">
                                            <option value="">Select </option>
                                            <?php
                                        $sel_hour="select distinct(designation), type from site_setting";
                                        $hour_query=mysql_query($sel_hour);
                                        while($data_hour=mysql_fetch_array($hour_query))
                                       {
                                            $sel='';
                                            if($data['employee_type']==$data_hour['type'])
                                            {
                                              $sel='selected="selected"';
                                            }
                                            ?>
                                            <option <?php echo $sel;?> value="
                                                <?php echo $data_hour['type'] ;?>">
                                                <?php echo $data_hour['designation'] ;?>
                                            </option>
                                            <?php
                                        }
                                        ?>
                                        </select>
                                    </div>
                                    <!-- project submit button -->
                                    <div class="form-group">
                                        <div class="">
                                            <input type="submit" name="submit"
                                                value="<?php if($record_id) echo 'Update'; else echo 'Submit'; ?>"
                                                class="btn btn-block btn-success">
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
                <!-- manage project and project table -->
                <div class="row">
                    <div class="col-md-12">
                        <div class="box box-info">
                            <div class="box-header with-border">
                                <h3 class="box-title">Manage Key Point</h3>
                            </div>
                            <!-- filter for project -->
                            <!-- <div class="">
                                <form method="post" name="search">
                                    <div class="input-group" style="padding:0% 2% 0% 82%; ">
                                        <input type="text" class="form-control" name="keyword" id="search_project"
                                            value="<?php if($_REQUEST['search']!=" search") echo $_REQUEST['search'];?>"
                                        placeholder="Search KPI">
                                        <div class="input-group-btn">
                                            <input type="image" src="images/search.jpg" name="search" value="search"
                                                style="height:34px;">
                                        </div>
                                    </div>
                                </form>
                            </div> -->
                            <div class="box-body">
                                <div class="table-responsive">
                                    <?php
                                    $i=1;
                                    // if($_REQUEST['keyword']!="keyword")
                                    // $search=trim($_REQUEST['keyword']);
                                    // if($search)
                                    // {
                                    //     $pro_search=" and proj_name like '%".$search."%'";           // filter code for serching projects 
                                    // }
                                    // else{
                                    //     $pro_search="";
                                    // }
                                    
                                        ?>
                                        <table class="table no-margin">
                                            <thead>
                                                <tr>
                                                    <th>Sr. No.</th>
                                                    <th>Title</th>
                                                    <th>Points</th>
                                                    <th>EMP_Type</th>
                                                    <th>Action</th>
                                                </tr>
                                            </thead>
                                            <tbody class="pagedata">
                                                <?php
                                                $sel_project="select * from pm_key_performance_point where 1  order by key_id desc";
                                                // $ptr_sel_project=mysql_query($sel_project);
                                                $no_of_records=mysql_num_rows($db->query($sel_project));
                                                if($no_of_records)
                                                {
                                                    $bgColorCounter=1;
                                                    $query_string='&keyword='.$search;
                                                    $query_string1=$query_string;
                                                    $pager = new PS_Pagination($sel_project,$_SESSION['show_records'],5,$query_string1);
                                                    $all_records= $pager->paginate();
                                                    while($project_data=mysql_fetch_array($all_records))
                                                    {
                                                        if($bgColorCounter%2==0)
                                                            $bgcolor='class="grey_td"';
                                                            else
                                                            $bgcolor=""; 
                                                            include "include/paging_script.php";
                                                        $p_admin="select name from site_setting where 1 and admin_id='".$project_data['admin_id']."'";
                                                        $ptr_p_admin=mysql_query($p_admin);
                                                        $proj_admin_data=mysql_fetch_array($ptr_p_admin);
                                                        ?>
                                                        <tr>
                                                            <td>
                                                                <?php echo $sr_no ?>
                                                            </td>
                                                            <td>
                                                                <?php  echo $project_data['key_title'];   ?>
                                                            </td>
                                                            <td>
                                                                <?php echo $project_data['point'];?>
                                                            </td>
                                                            <td>
                                                                <?php echo ucfirst($project_data['employee_type']);?>
                                                            </td>
                                                            <td>
                                                                <a
                                                                    href="perforamance_key_point.php?id=<?= $project_data['key_id']?>">
                                                                    <i class="fa fa-edit"></i></a>&nbsp;&nbsp;&nbsp;&nbsp;
                                                                <a
                                                                    href="perforamance_key_point.php?deleteRecord=1&id=<?= $project_data['key_id']?>">
                                                                    <i class="fa fa-trash"></i></a>
                                                            </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
                                                }
                                                else
                                                {
                                                    ?> 
                                                    <tr ><td colspan="5"><h4 style="background-color:;text-align:center"> No Record Avialable According To Your Creteria</h4></td></tr>
                                                    <?php
                                                }
                                                ?>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                            <!--end project tabel -->
                            <!-- /.box -->
                        </div>
                        <!-- /.col -->
                    </div>
                    <!--end manage project and project table -->
                    <!-- /.box -->
            </section>
            <!-- /.content -->
        </div>
        <?php include "include/footer-main.php"; ?>
        <!-- /.content-wrapper -->
    </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: '-1d',
                Default: true,
                todayHighlight: true
            })
            $('#datepicker1').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'
            })

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

            //Timepicker
            $('.timepicker').timepicker({
                showInputs: false
            })
        })
    </script>
    <!-- <script>
        let userdata = null;
        $.ajax({
            url:"ajax_project.php",
            type: "get",
            async: false,
            success: function(users){
                userdata = users.data;
            }
        });

        var currentpage = 0;
        let pages = "";
        let page_size = 5;
        pages = paginate(userdata, page_size);
        page = pages[currentpage];
        printRow(pages);
        function printRow(arr){
            arr.forEach(element =>{
                $(".pagedata").append("<tr><td>"+element.id+"<td><td>"+element.proj_name+"<td><td>"+element.added_date+"<td><td>"+element.admin_id+"<td></tr>")
            })
        }
        function paginate(arr,size){
            return arr.reduce((acc,val,i) => {
                let idx=Math.floor(i / size)
                let page = acc[idx] || (acc[idx] = [])
                page.push(val)
                return acc
            },[])
        }
    </script> -->
</body>

</html>