<?php namespace App\Http\Controllers;?>
<!DOCTYPE html>
<html>

<head>

    <title>Event | Admin |  Samuhik Saving & Co-Operative Society Ltd.</title>
    @include('Admin.Parts.MetaCSS')
    <style type="text/css">
         .img-wrap {
         position: relative;
         display: inline-block;
         border: 1px #e1e1e1 solid;
         font-size: 0;
         }
         .img-wrap .close {
         position: absolute;
         top: 2px;
         right: 2px;
         z-index: 100;
         background-color: #FFF;
         padding: 5px 2px 2px;
         color: #000;
         font-weight: bold;
         cursor: pointer;
         opacity: .2;
         text-align: center;
         font-size: 22px;
         line-height: 10px;
         border-radius: 50%;
         }
         .img-wrap:hover .close {
         opacity: 1;
         }
      </style>
      <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
   
      <script type="text/javascript">
         $(document).ready(function(){

           $('.close').on('click', function() {
           var id = $(this).siblings().data('id');
           var index = $(this).siblings().data('index');


                 $.ajax({
           url     : 'deleventimage',
           data : { token:id,index:index},
           method  : 'get',
           headers:
           {
           'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
           },
           success : function(response){

           } ,
           error:function(exception){;
           console.log(exception);
           }
           });
                   $(this).parent().css("display","none");
                   $(this).siblings().css("display","none");
         });

         });
      </script>

   <script>
        
        $(document).ready(function(){
            
            
            $('table > tbody  > tr').each(function() {
        $(this).find('td:eq(4)').html( $(this).find('td:eq(4)').html().replace(/(<([^>]+)>)/ig,"").substring(0,300));
        
            
            });
            
        });
    </script>
</head>

<body>

<!--====================================================
                     MAIN NAVBAR
======================================================-->
    @include('Admin.Parts.TopHeader')

<!--====================================================
                    PAGE CONTENT
======================================================-->
    <div class="page-content d-flex align-items-stretch">

        <!--***** SIDE NAVBAR *****-->
        @include('Admin.Parts.LeftNav')

        <div class="content-inner form-cont">
            <div class="row">
                <div class="col-md-12">
                    <div class="row">
                        <div class="col-md-6 col-lg-6">
                           @if (session('info'))
                           <div class="alert alert-success" style="text-transform: capitalize;">
                              {{session('info')}}
                           </div>
                           @endif
                           @php
                               $event=session('avisd');
                           @endphp
                           @if ($errors->any())
                           <div class="alert alert-danger">
                              <ul>
                                 @foreach ($errors->all() as $error)
                                 <li>{{ $error }}</li>
                                 @endforeach
                              </ul>
                           </div>
                           @endif
                        </div>
                     </div>
                    <div class="card form" id="form1">
                        <div class="card-header">
                            <h3>Add Event</h3>
                        </div>
                        <br>
                        @if(!$event)
                        <form action="admin_event" method="post" enctype="multipart/form-data">
                            @else
                            <form action="{{url('admin_event/update',array($event->id))}}" method="post" enctype="multipart/form-data">
                            @endif
                            <div class="row">
                                <div class="col-md-12">
                                    <div class="form-group">
                                        <label for="title">Title<i style="color: red">*</i></label>
                                        <input type="text" class="form-control" id="title" placeholder="Enter Title" name="title" value="<?php if($event) {echo $event->title;}?>">
                                        
                                    </div>
                                    <div class="form-group">
                                        <label for="title">Title in Nepali</label>
                                        <a rel="nofollow" href="http://naya.com.np" title="Nepali Social Network" class="naya_convert" data-site="dark"></a>
                                        <input type="text" class="form-control" id="title" placeholder="Enter Title in Nepali" name="title_nepali" value="<?php if($event) {echo $event->title_nepali;}?>">
                                        
                                    </div>
                                    
                                    <div class="form-group">
                                        <label for="date">Date<i style="color: red">*</i></label>
                                        <input type="date" class="form-control" id="date"  name="date" value="<?php if($event) {echo $event->date;}?>">
                                        
                                    </div>

                                    <div class="form-group">
                                        <label for="title">Location<i style="color: red">*</i></label>
                                        <input type="text" class="form-control" id="title" placeholder="Enter Location" name="location" value="<?php if($event) {echo $event->location;}?>">
                                        
                                    </div>


                                    <div class="form-group">
                                        <label for="exampleInputFile">Image<i style="color: red">*</i> <i style="margin-left: 20px; font-size: 10px;">multiple image</i></label>
                                       @if(!$event)
                                        <input type="file" class="form-control-file" id="exampleInputFile" name="image[]" multiple required>
                                        
                                       
                                    </div>
                                    @else
                                    <input type="file" class="form-control-file" id="exampleInputFile" name="image[]" multiple >
                                    <div class="row" style="margin-left: 17%;margin-bottom: 1%;">
                                          @if($event)
                                          @foreach(AdminlogController::getimagefromtoken($event->token) as $dd)
                                          <div class="img-wrap">
                                             <span class="close">&times;</span>
                                             <img src="img/Event/{{$dd->file_name}}?t={{rand()}}" style="width: 200px;height: auto;float: left;" class="img-responsive "  data-index={{$dd->file_name}} data-id={{$dd->token}}>
                                          </div>
                                          @endforeach
                                          @endif
                                       </div>
                                       @endif

                                    <div class="form-group">
                                        <label for="exampleTextarea">Description<i style="color: red">*</i></label>
                                        <textarea class="form-control ckeditor" id="exampleTextarea" rows="3" name="description"><?php if($event) {echo $event->description;}?></textarea>
                                    </div>

                                    <div class="form-group">
                                        <label for="exampleTextarea">Description in Nepali</label>
                                        <a rel="nofollow" href="http://naya.com.np" title="Nepali Social Network" class="naya_convert" data-site="dark"></a>
                                        <textarea class="form-control" id="exampleTextarea" rows="8" name="description_nepali"><?php if($event) {echo $event->description_nepali;}?></textarea>
                                    </div>
                                   
                                    
                                </div>
                                
                            </div>
                            <input type="hidden" name="_token" value="{{csrf_token()}}">
                            
                            <button type="reset" class="btn btn-general btn-white">Cancel</button>

                            <button type="submit" class="btn btn-general btn-blue mr-2"><?php if($event){echo "Update";}else {echo "Save";}?></button>
                        </form>
                    </div>

       <div class="card form" id="form1">           
        <div class="row">
           <div class="col-md-12">
            <div class="box">
              <div class="box-header">
                <h3 class="box-title">Data Table</h3>
              </div>
             <!-- /.box-header -->
             <div class="box-body" >
              <table id="example2" class="table table-bordered table-hover">
                <thead>
                  <tr>
                  <th width="5%">SN</th>
                
                  <th width="15%">Title</th>
                  <th width="10%">Date</th>
                  <th width="10%">Location</th>
                  <th width="40%">Description</th>
                  <th width="20%">Action</th>
                </tr>
                </thead>
                <tbody>
     
                  <tbody>
                  
                    <?php
                    echo AdminlogController::table_generator('events',array('title','date','location','description'), 'admin_event','Event');?>
  
           
                </tbody>
               
              </table>
            </div>
            <!-- /.box-body -->
            </div>
          </div>
        </div>
    </div>

                  
                
                </div>
            </div>
        </div>
    </div>

@include('Admin.Parts.Js')
</body>

</html>
