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

<head>

    <title>Affiliation/Samuhik Saving and credit coopertaive Society Ltd. </title>
    @include('Admin.Parts.MetaCSS')
</head>
@php
$affiliation=session('edit');
@endphp
<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('message'))
                        <div class="alert alert-success" role="alert">
                            {{ session('message') }}
                        </div>
        @endif
     
                                         @if($errors->any())
                                           <div class="alert alert-danger" role="alert">
                                            <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>Affiliation</h3>
                        </div>
                        <br>
                        @if(!$affiliation)
                        <form action="admin_affiliation" method="post" enctype="multipart/form-data">
                            @else
                            <form action="{{url('admin_affiliation/update',array($affiliation->id))}}" method="post" enctype="multipart/form-data">
                            @endif
                            <div class="row">
                                <div class="col-md-12">
                                    <div class="form-group">
                                        <label for="title">Name<i style="color: red">*</i></label>
                                        <input type="text" class="form-control" id="title" placeholder="" name="title" value="<?php if($affiliation) {echo $affiliation->name;}?>" required>
                                        
                                    </div>

                                    <div class="form-group">
                                        <label for="file">Image<i style="color: red">*</i></label>
                                        <input type="file" class="form-control-file" id="" name="image" placeholder="" onchange="readURL(this);" >
                                        <br> 
                                        <br>
                                        <img id="blah" src="#" alt="" height="100px" width="100px" padding="30px" />
                                                @if($affiliation)
                                                <img src="img/upload/{{$affiliation->filename}}" height="100px" width="100px" >
                                                @endif
                                    </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($affiliation){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>Name</th>
                  <th >Image</th>
                  <th >Action</th>
                </tr>
                </thead>
                <tbody>
                @foreach($save as $tt)
                <tr class="table-active">
                <td>{{$tt->name}}</td>
                <td><img src="{{url('img/upload/'.$tt->filename)}}" style="height: 100px;width: 100px;"></td>
                 <td><a class="btn btn-success"  href="{{url('admin_affiliation/edit',array($tt->id))}}">Edit</a></td>
                 <td><a class="btn btn-danger"  href="{{url('admin_affiliation/delete',array($tt->id))}}">Delete</a></td>
                
                </tr>
                </tbody>
               @endforeach
              </table>
            </div>
            <!-- /.box-body -->
            </div>
          </div>
        </div>
    </div>

                  
                
                </div>
            </div>
        </div>
    </div>
<script>
       function readURL(input) {
            if (input.files && input.files[0]) {
                var reader = new FileReader();

                reader.onload = function (e) {
                    $('#blah')
                        .attr('src', e.target.result);
                };

                reader.readAsDataURL(input.files[0]);
            }
        }
</script>
@include('Admin.Parts.Js')
</body>

</html>
