<?php
require_once('../config.php');
$user_id = $_SESSION['user_id'];
$emp_id = $_SESSION['emp_id'];
$user_role = $_SESSION['user_role'];


// SQL server connection information
// $sql_details = $search_db;
$sql_details = $search_db;

if(!isset($_GET['isset'])){
    exit();
}

$today_date = date("Y-m-d");
$table = <<<EOT
(
    SELECT 
        ROW_NUMBER() OVER(ORDER BY id DESC) row_num,
        id,
        employee_id,
        name,
        email,
        phone,
        probation_date
    FROM users 
    where probation_date!='' and probation_date<='$today_date' and COALESCE(con_after_prob,'')=''
) join_table
EOT;


$whereResult = null;
$whereAll = null;
if (isset($_GET['where_condition']) && !empty($_GET['where_condition'])) {
    $whereAll = $_GET['where_condition'];
}

// Table's primary key
$primaryKey = 'id';

// Array of database columns which should be read and sent back to DataTables.
// The `db` parameter represents the column name in the database, while the `dt`
// parameter represents the DataTables column identifier. In this case simple
// indexes
$columns = array(
    array('db' => 'row_num', 'dt' => 'row_num'),
    array('db' => 'employee_id', 'dt' => 'employee_id'),
    array('db' => 'name', 'dt' => 'name'),
    array('db' => 'email', 'dt' => 'email'),
    array('db' => 'phone', 'dt' => 'phone'),
    array(
        'db' => 'probation_date', 
        'dt' => 'probation_date',
        'formatter' => function($cell, $row){
            $returnValue = (!empty($user['probation_date']))?date("d M Y", strtotime($user['probation_date'])):'';
            return $returnValue;
        }
    ),
    array(
        'db' => 'id', 
        'dt' => 'id',
        'formatter' => function($cell, $row){
            $returnValue = '
            <a href="fun/function?probation_id='.$row['employee_id'].'&probation_value=Yes" class="btn btn-sm btn-success" title="Yes">Yes</a>
            <a href="fun/function?probation_id='.$row['employee_id'].'&probation_value=No" class="btn btn-sm btn-danger" title="No">No</a>';
            return $returnValue;
        }
    ),
    
);


/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * If you just want to use the basic configuration for DataTables with PHP
 * server-side, there is no need to edit below this line.
 */
require('ssp.class.php');

echo json_encode(
    // SSP::simple($_GET, $sql_details, $table, $primaryKey, $columns)
    SSP::complex($_GET, $sql_details, $table, $primaryKey, $columns, $whereResult, $whereAll)
);
