<?php
    $astuce = Actualite::get($_REQUEST['id']);
?>
<div class="modal-header bg-primary white">
    <h4 style="margin:0;" class="modal-title" id="myModalLabel8">Modifier une actualité</h4>
    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
        <span aria-hidden="true">&times;</span>
    </button>
</div>
<form action="actualite/modifier" method="POST" enctype="multipart/form-data">
    <input type="hidden" name="id" value="<?=$_REQUEST['id']?>">   
    <div class="modal-body">
        <fieldset class="form-group" style="text-align: center;">
            <img src="<?=strlen($astuce->image) == 0 ? 'assets/images/camera_icon.png' : 'https://www.savanafinance.com/media/'.$astuce->image?>" alt="choisir une image" id="imgpreview" style="max-width: 100%;height: 145px;cursor: pointer;    border: 1px solid;">
            <input type="file" style="display: none;" class="form-control" name="fichier" id="inputimg" placeholder="">
        </fieldset>
        <fieldset class="form-group">
            <label for="helpInputTop">Titre</label>
            <input type="text" class="form-control" required name="titre" value="<?=$astuce->titre?>" id="helpInputTop">
        </fieldset>
        <div class="row">
            <div class="col-md-6">
                <fieldset class="form-group">
                    <label for="helpInputTop">Auteur</label>
                    <input type="text" class="form-control" required name="auteur" value="<?=$astuce->auteur?>" id="helpInputTop">
                </fieldset>
            </div>
            <div class="col-md-6">
                <fieldset class="form-group">
                    <label for="helpInputTop">Fait le</label>
                    <input type="date" class="form-control" required name="faitle" value="<?=date('Y-m-d',strtotime($astuce->date))?>" id="helpInputTop">
                </fieldset>
            </div>
        </div>
        <fieldset class="form-group">
            <label for="helpInputTop">Description</label>
            <textarea class="form-control summernote" required name="description" id="helpInputTop"><?=$astuce->contenu?></textarea>
        </fieldset>
    </div>
    <div class="modal-footer">
        <button type="button" class="btn grey btn-secondary" data-dismiss="modal">Fermer</button>
        <button type="submit" class="btn btn-primary" >Enregistrer</button>
    </div>
</form>
<script type="text/javascript">
    
    $(document).on('click','#imgpreview',function(){
        $('#inputimg').trigger('click');
    });
    function readURL(input, ids) {
          if (input.files && input.files[0]) {
              var reader = new FileReader();
              
              reader.onload = function (e) {
                  $('#'+ids).attr('src', e.target.result);
                  var src = $('#'+ids).attr('src');
                  
              }
              
              reader.readAsDataURL(input.files[0]);
          }
      }
          
      $(document).on('change','#inputimg',function(){
          //alert();
          readURL(this,'imgpreview');
          
          //saveImage(false,'uploadImage1');
      });
</script>