<?php
session_start();
include('../include/connection.php');
$sql="select * from event";

$conditions = array();
$fields=array();

if(isset($_GET['searchkey']) && $_GET['searchkey'] !="") {
    $conditions[] = "n.title like :searchkey";
    $keyword = '%'.$_GET['searchkey'].'%';
    $fields[':searchkey'] = $keyword;
}

if (count($conditions) > 0) {
    $sql .= " WHERE " . implode(' AND ', $conditions);
}

$sql .= " order by id DESC";
$r=$con->select_query($sql,$fields);
$sn=1;
foreach($r as $value)
{
    $row_exist = true;
    $date_created = date('d-m-Y', strtotime($value['event_date']));
    if(!empty($_GET['startdate']))
    {
        if(strtotime($date_created) < strtotime($_GET['startdate']))
        {
            $row_exist = false;
        }
    }
    if(!empty($_GET['enddate']))
    {
        if(strtotime($date_created) > strtotime($_GET['enddate']))
        {
            $row_exist = false;
        }
    }
    
    if($row_exist)
    {
        if($value['status']==1)
        {
            $status="<span class='label label-primary'>Published</span>";
        }
        else
        {
            $status="<span class='label label-default'>Not Published</span>";
        }
         
        echo '<tr>
                                                                <td style="font-size:12px;">'.$sn.'</td>
                                                                <td>'.$value['title'].'</td>
                                                                <td>'.date('d-m-Y', strtotime($value['event_date'])).'</td>
                                                                <td>'.$status.'</td>
                                                                <td><a href="event_photos?id='.$value['id'].'" class="btn btn-info btn-sm">Photos</a></td>
                                                                <td>
                                                                    <form method="post" action="../admin/event_setup">
                                                                        <input type="hidden" name="eventid" value="'.$value['id'].'"/>
                                                                        <input type="submit" name="event" value="Edit" class="btn btn-warning btn-sm"/>
                                                                    </form>
                                                                </td>
                                                                <td><button onclick="Delete('.$value['id'].')" class="btn btn-danger btn-sm">Delete</button></td>
                                                            </tr>';
        $sn++;
    }
}

?>