<?php 
session_start();
$title = "Event Setup";
$group = "cms";
$menu = "event";
include('header.php');

$status="";
$title="";
$desc="";
$event_date = date('d-m-Y');
if(isset($_POST['eventid']))
{
    $_SESSION['eventid']=$_POST['eventid'];

    $sql="select * from event where id=:id";
    $value=array(':id'=>$_SESSION['eventid']);
    $r=$con->select_query($sql,$value);
    foreach($r as $value)
    {
        $status=$value['status'];
        $desc=$value['description'];
        $title=$value['title'];
        $event_date = $value['event_date'];
        $_SESSION['isEdit']=true;
    }
}
?>
<script type="text/javascript" src="../tinymce/tinymce.min.js"></script>
<script type="text/javascript">
                     
                     
                        tinymce.init({
                            selector: "textarea",
                            theme: "modern",
                            plugins: [
                                "advlist autolink lists link image charmap print preview hr anchor pagebreak",
                                "searchreplace wordcount visualblocks visualchars code fullscreen",
                                "insertdatetime media nonbreaking save table contextmenu directionality",
                                "emoticons template paste textcolor colorpicker textpattern imagetools"
                            ],
                            toolbar1: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image",
                            toolbar2: "print preview media | forecolor backcolor emoticons",
                            image_advtab: true,
                            templates: [
                                {title: 'Test template 1', content: 'Test 1'},
                                {title: 'Test template 2', content: 'Test 2'}
                            ]
                        });
                        
                        </script>
<script>

function SaveInsert()
{
	var ed = tinyMCE.get('alt_body');
	//alert(ed.getContent());
	$('#bodytxt').val(ed.getContent());
    
	var data = $("#eventform").serialize();
	
	var l = $( '.ladda-button-demo1' ).ladda();
	l.ladda( 'start');	
	$.ajax({
	            type: "POST",
	            url: "../include/insert_ajax.php",
	            data: data,
	            dataType: 'json',
	            cache: false,
	            success: function(data) {
	            	l.ladda( 'stop' );
	            	if(data.success == 1)
	            	{
	            		setTimeout(function() {
	                        toastr.options = {
	                            closeButton: true,
	                            progressBar: true,
	                            positionClass: "toast-top-full-width",
	                            showMethod: 'slideDown',
	                            timeOut: 4000
	                        };
	                        toastr.success('Event added successfully');
	                        $("input[type='text'], textarea, input[type='password'], input[type='number']").val("");
	                    }, 1300);
	                    window.location="event_photos?id="+data.id;
	            	}
	            	else if(data.success == 3)
	            	{
	            		setTimeout(function() {
	                        toastr.options = {
	                            closeButton: true,
	                            progressBar: true,
	                            positionClass: "toast-top-full-width",
	                            showMethod: 'slideDown',
	                            timeOut: 4000
	                        };
	                        toastr.error('Error, please enter required fields');

	                    }, 1300);
	            	}
	            },
	            error: function(){
	                  alert('error handling here');
	                  l.ladda( 'stop' );
	            }
	        });
}

function SaveUpdate()
{
	var ed = tinyMCE.get('alt_body');
	//alert(ed.getContent());
	$('#bodytxt').val(ed.getContent());
	
	var data = $("#eventform").serialize();
	var l = $( '.ladda-button-demo2' ).ladda();
	l.ladda( 'start');
	$.ajax({
	            type: "POST",
	            url: "../include/update_ajax.php",
	            data: data,
	            dataType: 'json',
	            cache: false,
	            success: function(data) {
	            	l.ladda( 'stop' );
	            	if(data.success == 1)
	            	{
	            		setTimeout(function() {
	                        toastr.options = {
	                            closeButton: true,
	                            progressBar: true,
	                            positionClass: "toast-top-full-width",
	                            showMethod: 'slideDown',
	                            timeOut: 4000
	                        };
	                        toastr.success('Event saved successfully');
	                    }, 1300);
	            	}
	            	else if(data.success == 3)
	            	{
	            		setTimeout(function() {
	                        toastr.options = {
	                            closeButton: true,
	                            progressBar: true,
	                            positionClass: "toast-top-full-width",
	                            showMethod: 'slideDown',
	                            timeOut: 4000
	                        };
	                        toastr.error('Error, please enter required fields');

	                    }, 1300);
	            	}
	            },
	            error: function(){
	                  alert('error handling here');
	                  l.ladda( 'stop' );
	            }
	        });
}
</script>
<script>
$(document).ready(function(){
	$('#data_5 .input-daterange').datepicker({
	    keyboardNavigation: false,
	    forceParse: false,
	    autoclose: true
	});
})
</script>
   <style>
.input-daterange input {
    text-align: left;
}
</style>     
    <!--<div class="wrapper wrapper-content animated fadeInRight">
            <div class="row">
                <div class="col-lg-10">
                     <div class="ibox float-e-margins">
                          <div class="ibox-title">
                                <h5>Event Setup</h5>
                          </div>
                          <div class="ibox-content">
                            <form method="post" action="event_setup" id="eventform">
                                <div class="row row-pad">
                                    <div class="col-md-2">
                                        <label for="name">Event Date</label>
                                    </div>
                                    <div class="col-md-10" id="data_5">
                                        <div class="input-daterange input-group" id="datepicker" style="width: 100%">
                                            <input type="text" class="form-control" name="event_date" value="<?php echo $event_date?>"/>
                                        </div>
                                    </div>
                                </div>
                                <div class="row row-pad">
                                    <div class="col-md-2">
                                        <label for="name">Title</label>
                                    </div>
                                    <div class="col-md-10">
                                        <input type="text" name="title" class="form-control" value="<?php echo $title;?>" required/>
                                    </div>
                                </div>
                                
                                <div class="row row-pad">
                                    <div class="col-md-2">
                                        <label for="name">Description</label>
                                    </div>
                                    <div class="col-md-10">
                                        <input type="hidden" name="body" id="bodytxt"/>
                                        <textarea name="alt_body" id="alt_body" style="height: 300px"><?php echo $desc?></textarea>
                                    </div>
                                </div>
                                          
                                <div class="row row-pad">
                                    <div class="col-md-2">
                                        
                                    </div>
                                    <div class="col-md-6">
                                        <label> <input type="checkbox" id="status" name="status" <?php echo ($status==1 ? "checked" : "")?>/> Publish </label>
                                    </div>
                                </div>
                               
                                <div class="row row-pad">
                                    <div class="col-md-2">
                                        
                                    </div>
                                    <div class="col-md-6">
                                    <?php 
                                        if($_SESSION['isEdit']==true){
                                            echo '
                                            <input type="hidden" name="update" value="event_setup"/>
                                            <button type="button" onclick="SaveUpdate()" class="ladda-button ladda-button-demo2 btn btn-primary"  data-style="zoom-in">Update Event</button>';
                                        } else {
                                            echo '
                                            <input type="hidden" name="insert" value="event_setup"/>
                                            <button type="button" onclick="SaveInsert()" class="ladda-button ladda-button-demo1 btn btn-primary"  data-style="zoom-in">Add Event</button>';
                                        }
                                    ?>
                                        <a href="event_list" class="btn btn-warning">Cancel</a>
                                    </div>
                                </div>
                                </form>
                            
                        </div>
                    </div>
            </div>
        </div>
   </div>-->
   
   
   
<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 Setup</h4>
                            </div>
                            <div class="card-content">
                            	<form method="post" action="event_setup" id="eventform">
                                <div class="row row-pad">
                                    <div class="col-md-2">
                                        <label for="name">Event Date</label>
                                    </div>
                                    <div class="col-md-10" id="data_5">
                                        <div class="input-daterange input-group" id="datepicker" style="width: 100%">
                                            <input type="date" class="form-control" name="event_date" value="<?php echo $event_date?>"/>
                                        </div>
                                    </div>
                                </div>
                                <div class="row row-pad">
                                    <div class="col-md-2">
                                        <label for="name">Title</label>
                                    </div>
                                    <div class="col-md-10">
                                        <input type="text" name="title" class="form-control" value="<?php echo $title;?>" required/>
                                    </div>
                                </div>
                                
                                <div class="row row-pad">
                                    <div class="col-md-2">
                                        <label for="name">Description</label>
                                    </div>
                                    <div class="col-md-10">
                                        <input type="hidden" name="body" id="bodytxt"/>
                                        <textarea name="alt_body" id="alt_body" style="height: 300px"><?php echo $desc?></textarea>
                                    </div>
                                </div>
                                          
                                <div class="row row-pad">
                                    <div class="col-md-2">
                                        
                                    </div>
                                    <div class="col-md-6">
                                        <label> <input type="checkbox" id="status" name="status" <?php echo ($status==1 ? "checked" : "")?>/> Publish </label>
                                    </div>
                                </div>
                               
                                <div class="row row-pad">
                                    <div class="col-md-2">
                                        
                                    </div>
                                    <div class="col-md-6">
                                    <?php 
                                        if($_SESSION['isEdit']==true){
                                            echo '
                                            <input type="hidden" name="update" value="event_setup"/>
                                            <button type="button" onclick="SaveUpdate()" class="ladda-button ladda-button-demo2 btn btn-primary"  data-style="zoom-in">Update Event</button>';
                                        } else {
                                            echo '
                                            <input type="hidden" name="insert" value="event_setup"/>
                                            <button type="button" onclick="SaveInsert()" class="ladda-button ladda-button-demo1 btn btn-primary"  data-style="zoom-in">Add Event</button>';
                                        }
                                    ?>
                                        <a href="event_list" class="btn btn-warning">Cancel</a>
                                    </div>
                                </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
                <!--/ Recent Transactions -->

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

   
