<?php
    $astuce = Document::get($_REQUEST['id']);
?>
<div class="modal-header bg-primary white">
    <h4 style="margin:0;" class="modal-title" id="myModalLabel8">Modifier un document</h4>
    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
        <span aria-hidden="true">&times;</span>
    </button>
</div>
<form action="document/modifier" method="POST" enctype="multipart/form-data">
    <input type="hidden" name="id" value="<?=$_REQUEST['id']?>">   
    <div class="modal-body">
        <fieldset class="form-group">
            <label for="helpInputTop">Titre</label>
            <input type="text" class="form-control" required name="titre" value="<?=$astuce->titre?>" id="helpInputTop">
        </fieldset>
        <fieldset class="form-group">
            <label for="helpInputTop">Menu</label>
            <select class="form-control" name="menu">
              <option value="can" <?=$astuce->menu == 'can' ? 'selected' : ''?>>Can do training</option>
              <option value="coja" <?=$astuce->menu == 'coja' ? 'selected' : ''?>>Coja</option>
              <option value="cpam" <?=$astuce->menu == 'cpam' ? 'selected' : ''?>>Cpam</option>
              <option value="agenda" <?=$astuce->menu == 'agenda' ? 'selected' : ''?>>Agenda</option>
            </select>
        </fieldset>
        <fieldset class="form-group">
            <label for="helpInputTop">Joindre un document (<a href="../images/document/<?=$astuce->lien?>" target="_blank">voir</a>)</label>
            <input type="file" class="form-control" name="document" id="helpInputTop">
        </fieldset>
    </div>
    <div class="modal-footer">
        <button type="button" class="btn grey btn-outline-secondary" data-dismiss="modal">Fermer</button>
        <button type="submit" class="btn btn-outline-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>