<?php  include_once('../../config/db.php');  //include_once('../config/check.php'); 


$query = "  SELECT a.*,b.fname bfname,b.mname bmname,b.lname blname,
                    c.name cname,d.name dname,e.name ename,f.capacity fcapacity  FROM roomsbooking a
                LEFT JOIN  clients b ON a.client = b.id
                LEFT JOIN  rooms c ON a.hostingtype=c.id
                LEFT JOIN  paymentsmode d ON a.paymentmode=d.id
                LEFT JOIN  roomsbookingstatus e ON a.status=e.id
                LEFT JOIN  roomsrate f ON a.guest=f.id
        ";


$statement = $conn->prepare($query);
$statement->execute();
$number_filter_row = $statement->rowCount();

$result = $statement->fetchAll();

$data = array();



foreach($result as $row)
{
  
     $actions= ' <div class="btn-group" role="group">
              <button type="button" class="btn btn-success  btn-sm  btn-xs bg-purple  dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" style="paddin:0px;border-radius:5px;">
                 Actions
                <span class="caret"></span>
              </button>
              <ul class="dropdown-menu">
                <li><form method="post" action="allgroupsed" >  <button type="submit" style="background:none;border:none;padding:0px; font-color:red; outline:none; " name="GROUPEDIT" value="' . $row["id"] . '"   "> <i class="fa fa-pencil" style="color:green;" ></i> EDIT   </button></form></li>
                <li><form method="post" action="#" >  <button type="submit" style="background:none;border:none;padding:0px; font-color:red; outline:none; " name="GROUPDELETE" value="' . $row["id"] . '"   "> <i class="fa fa-trash" style="color:red;" ></i> DELETE   </button></form></li>

                
              </ul>
            </div>
          ';

 $actionButton = '<input type="radio" name="myradio" class="myradio" value="' . $row["id"] . '" /> </i></a>';
 $edit = ' <form method="post" action="#" >  <button type="submit" style="background:none;border:none;padding:0px; outline:none; " name="edit" value="' . $row["id"] . '"   "> <i class="fa fa-edit" style="color:green;" ></i>  </button></form> ' ; 
 $delete = ' <form method="post" action="#" >  <button type="submit" style="background:none;border:none;padding:0px; font-color:red; outline:none; " name="delete" value="' . $row["id"] . '"   "> <i class="fa fa-trash" style="color:red;" ></i>  </button></form> ' ; 


 $sub_array = array();
 $sub_array[] =  $actionButton  ;
//  $sub_array[] =  $delete  ;
//  $sub_array[] =  $edit  ;
 $sub_array[] = $row['ename'];
 $sub_array[] = $row['bfname'].''.$row['bmname'].''.$row['blname'];
 $sub_array[] = $row['cname'];
 $sub_array[] = $row['startdate'];
 $sub_array[] = $row['enddate'];
 $sub_array[] = $row['fcapacity'];
 $sub_array[] = $row['dname'];
 $sub_array[] = $row['transactions'];
 $sub_array[] =  $actions ;
//  $sub_array[] = $row['code'];
//  $sub_array[] = $row['description'];

 $data[] = $sub_array;

}

function count_all_data($conn,$query)
{
 $statement = $conn->prepare($query);
 $statement->execute();
 return $statement->rowCount();
}

$output = array(
                       "draw"       =>  $number_filter_row ,
                        "recordsTotal"   =>  count_all_data($conn,$query),
                        "recordsFiltered"  =>  $number_filter_row,
                        "data"       =>  $data
);

echo json_encode($output);

?>




