<?php
  if($_GET['gallery_type'] == "product_gallery"){
    $rowControl = $db->prepare("SELECT * FROM posts WHERE post_id=:post_id AND post_type=:post_type");
    $rowControl->execute(array(
      'post_type' => 'post_products',
      'post_id'   => $_GET['gallery_id']
    ));
    if(!$rowControl->rowCount()){
      Header("Location:index.php");
    }
  }elseif($_GET['gallery_type'] == "post_gallery"){
    $rowControl = $db->prepare("SELECT * FROM posts WHERE post_id=:post_id AND post_type=:post_type");
    $rowControl->execute(array(
      'post_type' => 'post_post',
      'post_id' => $_GET['gallery_id']
    ));
    if(!$rowControl->rowCount()){
      Header("Location:index.php");
    }
  }elseif($_GET['gallery_type'] == "image_gallery"){
    $rowControl = $db->prepare("SELECT * FROM posts WHERE post_id=:post_id");
    $rowControl->execute(array(
      'post_id' => $_GET['gallery_id']
    ));
    if(!$rowControl->rowCount()){
      Header("Location:index.php");
    }
  }elseif($_GET['gallery_type'] == "project_gallery"){
    $rowControl = $db->prepare("SELECT * FROM posts WHERE post_id=:post_id AND post_type=:post_type");
    $rowControl->execute(array(
      'post_type' => 'post_projects',
      'post_id' => $_GET['gallery_id']
    ));
    if(!$rowControl->rowCount()){
      Header("Location:index.php");
    }
  }else{
    Header("Location:index.php");
  }
 ?>

<div class="card" id="dropzoneStatus">
  <div class="card-body">
    <form action="system/media.php" class="dropzone" enctype="multipart/form-data" data-parsley-validate>
      <input type="hidden" name="gallery_type" value="<?=$_GET["gallery_type"];?>">
      <input type="hidden" name="gallery_id" value="<?=$_GET["gallery_id"];?>">
    </form>
  </div>
</div>
<div class="card">
  <div class="card-body">
    <div class="row">
      <div class="col-12">
        <div class="col-12">
          <div class="card card-primary">
            <div class="card-header">
              <div class="card-title">
                <?php echo $langArray['LOADED_MEDIA']; ?>
              </div>
            </div>
            <div class="card-body">
              <div class="row">
                 <?php
                   $typeandid = $_GET['gallery_type'].'-'.$_GET['gallery_id'];
                   $allMediaAsk->execute(array(
                     'gallery_type_id'        => $typeandid
                   ));
                   while ($allTypeCheck=$allMediaAsk->fetch(PDO::FETCH_ASSOC)){
                 ?>
                <div class="col-sm-2">
                  <img src="../<?php echo $allTypeCheck['media_medium']; ?>" class="img-fluid mb-2" alt="white sample"/>
                  <div class="form-group">
                    <form action="system/media.php" method="post" enctype="multipart/form-data" data-parsley-validate>
                      <input type="hidden" name="media_id" value="<?php echo $allTypeCheck['media_id']; ?>">
                      <input type="hidden" name="gallery_type" value="<?php echo $_GET['gallery_type']; ?>">
                      <input type="hidden" name="gallery_id" value="<?php echo $_GET['gallery_id']; ?>">
                      <input type="hidden" name="gallery_title" value="<?php echo $_GET['gallery_title']; ?>">
                      <input type="hidden" name="media_full" value="<?php echo $allTypeCheck['media_full']; ?>">
                      <input type="hidden" name="media_large" value="<?php echo $allTypeCheck['media_large']; ?>">
                      <input type="hidden" name="media_medium" value="<?php echo $allTypeCheck['media_medium']; ?>">
                      <input type="hidden" name="media_thumbnail" value="<?php echo $allTypeCheck['media_thumbnail']; ?>">
                      <input class="btn btn-danger btn-block" type="submit" name="mediaDelete" value="<?php echo $langArray['TABLE_DELETE']; ?>">
                    </form>
                  </div>
                </div>
                <?php } ?>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
