<!-- Main Content -->
<div class="page-wrapper">
<div class="container-fluid pt-25">
   <div class="row">
      <div class="alert alert-success alert-dismissible" role="alert" <?php if($this->session->flashdata('message')==''){ ?> style="display:none" <?php } ?> >
         <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
         <?php echo $this->session->flashdata('message'); ?>
      </div>
      <div class="alert alert-warning alert-dismissible" role="alert" <?php if($this->session->flashdata('emessage')==''){ ?> style="display:none" <?php } ?> >
         <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
         <?php echo $this->session->flashdata('emessage'); ?>
      </div>
   </div>
   <!-- Row -->
   <div class="row">
      <div class="col-sm-12">
         <div class="panel panel-default card-view">
            <div class="panel-heading">
               <div class="pull-left">
                  <h6 class="panel-title txt-dark">Edit Event</h6>
               </div>
               <div class="clearfix"></div>
            </div>
            <div class="panel-wrapper collapse in">
               <div class="panel-body">
                  <div class="form-wrap">
                     <form id="addPostFrom" class="form-horizontal" action="<?php echo base_url(A."/editPost"); ?>" enctype="multipart/form-data" method='post'>
                        <input type="hidden" name="id" value="<?php echo $post['id']; ?>" />
                        <input type="hidden" name="type" value="<?php echo $post['type']; ?>" />
                        <div class="row">
                           <div class="col-md-12">
                              <div class="form-group">
                                 <label class="col-sm-12">Title:</label>
                                 <div class="col-sm-12">
                                    <input type="text" name="post_title" class="form-control" value="<?php echo $post['post_title']; ?>" required>
                                 </div>
                              </div>
                           </div>
                           <div class="col-md-6">
                              <div class="form-group">
                                 <label class="col-sm-12">Date:</label>
                                 <div class="col-sm-12">
                                    <input type="date" name="publish_date" class="form-control" placeholder="Enter Date" value="<?php echo date('Y-m-d',strtotime($post['publish_date'])); ?>" style="line-height: 18px;">
                                 </div>
                              </div>
                           </div>
                           <div class="col-md-6">
                              <?php if($post['image']!=''){ ?>
                              <div class="form-group col-sm-12">
                                 <img src="<?php echo base_url($post['image']); ?>" alt="image" style="width:100px;">
                              </div>
                              <?php } ?>                              
                              <div class="form-group col-sm-12">
                                 <label class="">Image (Image Size - 890x596px)</label>
                                 <input type="file" name="image" class="form-control">
                                 <input type="hidden" name="old_image" class="form-control" value="<?php echo $post['image']; ?>">
                              </div>
                           </div>
                           <div class="col-md-12">
                              <div class="form-group">
                                 <label class="col-sm-12">Description:</label>
                                 <div class="col-sm-12">
                                    <!-- <div class="fileUpload btn btn-default">
                                       <span>Add Media</span>
                                       <input id="file_2" type="file" name="" class="upload" />
                                    </div> -->
                                    <textarea name="post_description" class="ckeditor_full"  id="ckeditor_full" placeholder="Enter Post Description"><?php echo $post['post_description'] ?></textarea>
                                 </div>
                              </div>
                           </div>
                           <div class="col-md-12">
                              <div class="form-group">
                                 <label class="col-sm-12">Gallery Images (Size : 500x500 px) :</label>
                                 <div class="col-sm-12">
                                    <input type="file" class="form-control" name="blog_image[]" multiple style="border:2px solid #9CCC65;">
                                 </div>
                              </div>
                           </div>
                           <div class="col-md-12">
                              <?php 
                                 $gcount = 0;
                                 $gallery = $this->common->getData('blog_media',array('postid'=>$post['id']));
                                 if(isset($gallery) && !empty($gallery)){ 
                                    $gcount = 1;
                              ?>
                                 <div class="form-group">
                                    <div class="row">
                                       <div class="col-md-12">
                                          <?php foreach ($gallery as $key => $value) { 
                                             if($value['blog_image'] !==''){
                                          ?>
                                             <div class="col-md-2 text-center">
                                                 <div class="thumbnail count-thumb">
                                                     <img src="<?php echo base_url($value['blog_image']); ?>" style="width:100px; height:100px;">
                                                     <a href="javascript:void(0)" class="delete_blogMedia" data-id="<?php echo $value['id'];?>" style="color:red;"><i class="fa fa-trash"></i></a>
                                                 </div>
                                             </div>
                                         <?php } } ?>                                              
                                       </div>
                                    </div>
                                 </div>
                              <?php } ?>
                           </div>
                           <div class="col-md-12">
                              <div class="form-group mb-0">
                                 <div class="col-sm-12">
                                    <button type="submit" class="btn btn-success btn-anim pull-right"><i class="icon-rocket"></i><span class="btn-text">Update Post</span></button>
                                 </div>
                              </div>
                           </div>
                        </div>
                     </form>
                  </div>
               </div>
            </div>
         </div>
      </div>
   </div>
   <!-- /Row -->
</div>
<script src="<?php echo base_url("assets/admin/vendors/ckeditor/ckeditor.js"); ?>"></script>
<script src="<?php echo base_url("assets/admin/vendors/ckeditor/adapters/jquery.js"); ?>"></script>
<style type="text/css">
   #cke_1_contents{height:300px !important;}
   label{color:#000;}
   .fileUpload {
   position: relative;
   overflow: hidden;
   margin: 10px;
   }
   .fileUpload input.upload {
   position: absolute;
   top: 0;
   right: 0;
   margin: 0;
   padding: 0;
   font-size: 20px;
   cursor: pointer;
   opacity: 0;
   filter: alpha(opacity=0);
   }
</style>
<script type="text/javascript">
   $(function() {
        $('textarea.ckeditor_full' ).ckeditor({
            toolbarGroups: [
              /*{ name: "document",    groups: [ "mode", "document" ] },            // Displays document group with its two subgroups.
              { name: "basicstyles", groups: [ "basicstyles", "cleanup" ] },
              { name: 'insert', groups: [ 'insert' ] },
              { name: "links" },*/

               { name: 'clipboard',   groups: [ 'clipboard', 'undo' ] },

              { name: 'editing',     groups: [ 'find', 'selection', 'spellchecker' ] },

              { name: 'links' },

              { name: 'insert' },

              { name: 'forms' },

              { name: 'tools' },

              { name: 'document',       groups: [ 'mode', 'document', 'doctools' ] },

              { name: 'others' },

              '/',

              { name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ] },

              { name: 'paragraph',   groups: [ 'list', 'indent', 'blocks', 'align', 'bidi' ] },

              { name: 'styles' },

              { name: 'colors' },

              { name: 'about' }
            ]
        });
    });
   
   var site_url = "<?php echo base_url(); ?>";
   var urlLink = "<?php echo A; ?>";
   $("#file_1").on("change",function(){
       var file_data = $("#file_1").prop('files')[0];
       var form_data = new FormData(this);
       form_data.append('file', file_data);
       $.ajax({
           url: site_url+urlLink+"/uploadPostImage",
           dataType: 'text',
           cache: false,
           contentType: false,
           processData: false,
           data: form_data,
           type: 'post',
           success: function(result){
               var html='<img src="'+site_url+'assets/post-image/'+result+'">';
               CKEDITOR.instances['ckeditor_full_1'].insertHtml(html);
           }
       });
   });
</script>
<script type="text/javascript">
   var site_url = "<?php echo base_url(); ?>";
   var urlLink = "<?php echo A; ?>";
    $(".delete_blogMedia").on("click",function(){
        var id = $(this).attr("data-id");        
        var result = confirm("Do you Want to delete?");
        if(result) {
            $.ajax({
                url: site_url+urlLink+"/deleteBlogMultiMedia",
                type: "POST",
                data: "id="+id,
                success: function(result){
                    if(result==1)
                    {
                        location.reload();
                    }
                }
            });
        }
    });
</script>

<style>
   .thumbnail
   {
      min-height: 150px;
   }
</style>