<?php
ob_start();
include_once 'classes/common.php';
include_once 'classes/DB.class.php';
include_once 'session/admin-session.php';

$db = new DB();

$added_by = $_SESSION['rcuesr_room_admin_id'];
$event_pk_id = common::StrToDB($_REQUEST['EventID']);

/*Event Details */
$EventDetailsArr = $db->selectWithCols("rcuesr_event_tbl", "*", "event_pk_id='$event_pk_id'");
$event_name = $EventDetailsArr['0']['event_name'];
$event_details = $EventDetailsArr['0']['event_details'];
?>
<div class="row">
    <div class="col-md-12 col-sm-12 col-xs-12 ">
        <h3>Event Edit</h3>
        <div class="box box-primary">
            <div class="box-body">
                <div class="row" id="result_msg" style="padding-left: 5px;"></div>
                <form action="" method="POST" id="event_form_id" enctype="multipart/form-data">
                    <div class="row">
                        <div class="col-md-4 col-sm-4 col-xs-4">
                            <div class="form-group">
                                <label>Event Name</label>
                                <input type="text" name="event_name" id="event_name" class="form-control input-lg" required="" value="<?php echo common::StrFromDb($event_name); ?>"/>

                            </div>
                        </div>
                        <div class="col-md-6 col-sm-6 col-xs-6">
                            <div class="form-group">
                                <label>Event Details</label>
                                <input type="text" name="event_details" id="event_details" class="form-control input-lg" required="" value="<?php echo common::StrFromDb($event_details); ?>"/>

                            </div>
                        </div>
                        <div class="clearfix"></div>
                        <div class="col-md-2 col-sm-2 col-xs-2">
                            <div class="form-group">
                                <label><br/></label>
                                <input type="hidden" name="action" id="action" value="event-edit"/>
                                <input type="hidden" name="event_pk_id" id="event_pk_id" value="<?php echo $event_pk_id; ?>"/>
                                <input type="hidden" name="added_by" id="added_by" value="<?php echo $added_by; ?>"/>
                                <input type="submit" name="event_update_btn" id="event_update_btn" class="btn btn-warning btn-block text-uppercase" value="Update"/>
                            </div>
                        </div>
                    </div>
                </form>
            </div>

        </div>
    </div>
</div>
<div class="clearfix"></div><br/><br/>
<?php
$mainpagecontent = ob_get_contents();
ob_clean();
include 'admin-master.php';
?>
<script type="text/javascript">
    $(function () {
        $("#event_form_id").validate({
            rules: {
                event_name: {
                    required: true,
                    minlength: 3
                },
                event_details: {
                    required: true
                }
            },
            messages: {
                 event_name: {
                    required: "Please Enter Event Name",
                    minlength: 3
                },
                event_details: {
                    required: "Please Enter Event Details"
                }
            }
        });
        $("#event_update_btn").click(function () {
            $("#result_msg").html("");
            if ($("#event_form_id").valid()) {
               var formData = new FormData($('#event_form_id')[0]);
                $.ajax({
                    type: "POST",
                    url: "server/action-post.php",
                    data: formData,
                    contentType: false,
                    cache: false,
                    processData: false,
                    success: function (data) {
                        if (data.res_status == 1) {
                            $("#result_msg").html("<span style='color: green;'>Detail is updated successfully!</span>");
                           
                        } else {
                            $("#result_msg").html("<span style='color: red;'>" + data.res_msg + "</span>");

                        }
                    }
                });
            }
            return false;
        });




    });


</script>