<?php 
session_start();
$title = "Events";
$group = "event";
$menu = "event";
include('header.php');
$_SESSION['isEdit']=false;
?>
<script>
function getXMLHTTP() { //fuction to return the xml http object
	var xmlhttp=false;	
	try{
		xmlhttp=new XMLHttpRequest();
	}
	catch(e)	{		
		try{			
			xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e){
			try{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch(e1){
				xmlhttp=false;
			}
		}
	}
	 	
	return xmlhttp;
}


function loadEvents(showloading) {
	if(showloading == 1)		
	document.getElementById('load').innerHTML='<img src="img/loading.gif"/>';
	var searchkey = document.getElementById('searchkey').value;
	var fromdate =  document.getElementById('fromdate').value;
	var todate =  document.getElementById('todate').value;
	var strURL="../load/load_events.php?searchkey="+searchkey+"&startdate="+fromdate+"&enddate="+todate;
	//alert(strURL);
	var req = getXMLHTTP();
	
	if (req) {
		
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				// only if "OK"
				if (req.status == 200) {						
					document.getElementById('load').innerHTML=req.responseText;						
				} else {
					alert("There was a problem while using XMLHTTP:\n" + req.statusText);
				}
			}				
		}			
		req.open("GET", strURL, true);
		req.send(null);
	}		
}

function Delete(id)
{
	if(confirm("Delete Event and all this events photos?"))
	{
    	var datastring = {'id':id,'delete':'event_list'};
    	$.ajax({
    	            type: "POST",
    	            url: "../include/delete_ajax.php",
    	            data: datastring,
    	            dataType: 'json',
    	            cache: false,
    	            success: function(data) {
    	            	if(data.success == 1)
    	            	{       
    	            		loadEvents(0);    		
    	            		setTimeout(function() {
    	                        toastr.options = {
    	                            closeButton: true,
    	                            progressBar: true,
    	                            positionClass: "toast-top-full-width",
    	                            showMethod: 'slideDown',
    	                            timeOut: 4000
    	                        };
    	                        toastr.success('Event and photos deleted successfully');
    	                        
    	                    }, 1300);
    	            	}
    	            	else
    	            	{
    	            		setTimeout(function() {
    	                        toastr.options = {
    	                            closeButton: true,
    	                            progressBar: true,
    	                            positionClass: "toast-top-full-width",
    	                            showMethod: 'slideDown',
    	                            timeOut: 4000
    	                        };
    	                        toastr.error('Error');
    
    	                    }, 1300);
    	            	}
    	            },
    	            error: function(){
    	                  alert('error handling here');
    	            }
    	        });
	}
}

$(document).ready(function(){
	loadEvents(1);
	$('.filter').change(function(){
		loadEvents(1);
	})
});


$(document).ready(function(){
	$('#data_5 .input-daterange').datepicker({
	    keyboardNavigation: false,
	    forceParse: false,
	    autoclose: true
	});
})
</script>

<div class="content-body">
        	<div class="row">
                    <div id="recent-transactions" class="col-12">
                        <div class="card">
                            <div class="card-header">
                                <h4 class="card-title">Event List</h4>
                            </div>
                            <div class="card-content">
							<div class="row row-pad">
                                
                                <div class="col-md-4">
                                    <input type="text" class="form-control filter" id="searchkey" placeholder="Search Title"/>
                                </div>
                                <div class="col-md-5" id="data_5">
                                        <div class="input-daterange input-group" id="datepicker" style="width: 100%">
                                            <input type="text" class="input-sm form-control filter" id="fromdate"/>
                                            <span class="input-group-addon">to</span>
                                            <input type="text" class="input-sm form-control filter" id="todate"/>
                                        </div>
                                 </div>
                                <div class="col-md-3"><a class="btn btn-info pull-right" href="event_setup">Add new</a></div>
                            </div>
                            <div class="row row-pad">
                                <div class="col-lg-12">
                                    <div class="table-responsive">
                                       <table class="table table-striped table-bordered table-hover table-advanced smaller">
                                            <thead>
                                                <tr>
                                                    <th>S/N</th>
                                                    <th>Title</th>
                                                    <th>Event Date</th>  
                                                    <th>Status</th>  
                                                    <th colspan="3">Actions</th>                             
                                                </tr>
                                            </thead>
                                            <tbody id="load">
                                                    
                                            </tbody>
                                       </table>
                                   </div>
                                </div>
                            </div>
                            </div>
                        </div>
                    </div>
                </div>
                <!--/ Recent Transactions -->

   </div>

       
    
    <?php    
        include('footer.php');
    ?>

   
