<?php
  $askData=$db->prepare("SELECT * FROM orders where order_id=:order_id");
  $askData->execute(array(
    'order_id' => $_GET["order_id"]
    ));
  $checkData=$askData->fetch(PDO::FETCH_ASSOC);

  // $_GET null or nothing
  if ($_GET['order_id'] == null) {
    Header("Location:packetOrderList");
  }elseif($_GET['order_id'] != $checkData['order_id']){
    Header("Location:packetOrderList");
  }
?>
<div class="card">
  <div class="card-body table-responsive">
    <div id="invoice">
      <div class="invoice overflow-auto">
        <div style="min-width: 600px">
          <header>
            <div class="row">
              <div class="col company-details">
                <h2 class="name">
                  <?php echo $generalSettingCheck['site_title'] ?>
                </h2>
                <div><?php echo $generalSettingCheck['contact_adress']; ?></div>
                <div><?php echo $langArray['CONTACT_PHONE']; ?>: <?php echo $generalSettingCheck['contact_land_phone']; ?></div>
                <div><?php echo $langArray['GENERAL_FORM_SITE_EMAIL']; ?>: <?php echo $generalSettingCheck['site_email']; ?></div>
              </div>
            </div>
          </header>
          <main>
            <div class="row contacts">
              <div class="col invoice-to">
                <h2 class="to"><?php echo $checkData['name_surname']; ?></h2>
                <div class="address"><?php echo $checkData['adress']; ?></div>
                <div class="email"><?php echo $checkData['email']; ?></div>
                <div class="email"><?php echo $checkData['phone']; ?></div>
              </div>
              <div class="col invoice-details">
                <h6 class="invoice-id"><?php echo $langArray['TABLE_CODE']; ?>: #<?php echo $checkData['order_code']; ?></h6>
                <div class="date"><?php echo $langArray['TABLE_DATE']; ?>: <?php echo $checkData['dates']; ?></div>
              </div>
            </div>
            <table>
              <thead>
                <tr>
                  <th></th>
                  <th><?php echo $langArray['TABLE_QUANTITY']; ?></th>
                  <th><?php echo $langArray['TABLE_PRODUCT']; ?></th>
                  <th><?php echo $langArray['DESCRIPTION']; ?></th>
                  <th><?php echo $langArray['GLOBAL_FORM_TABLE_PRICE']; ?></th>
                </tr>
              </thead>
              <tbody>
                <tr>
                  <td></td>
                  <td><?php echo $checkData['quantity']; ?></td>
                  <td>
                    <?php
                      $allPackAsk1->execute(array(
                        'packet_id' => $checkData['product']
                      ));
                      $packCheck=$allPackAsk1->fetch(PDO::FETCH_ASSOC);
                      echo $packCheck['title'];
                    ?>
                  </td>
                  <td><?php echo $checkData['description']; ?></td>
                  <td><?php echo $checkData['price']; ?></td>
                </tr>
              </tbody>
              <tfoot>
                <tr>
                  <td colspan="2"></td>
                  <td colspan="2"><?php echo $langArray['GLOBAL_FORM_TABLE_PRICE']; ?></td>
                  <td>
                    <?php
                      $productDetailAsk=$db->prepare("SELECT * FROM products WHERE product_post_id=:product_post_id");
                      $productDetailAsk->execute(array(
                        'product_post_id' => $packCheck['packet_id']
                      ));
                      $productDetailCheck=$productDetailAsk->fetch(PDO::FETCH_ASSOC);

                      $price=$checkData['price'];
                      $quantity=$checkData['quantity'];
                      $total = $price*$quantity;
                      echo $total .' ' . $packCheck['currency'];
                    ?>
                  </td>
                </tr>
              </tfoot>
            </table>
            <div class="row no-print">
              <div class="col-12">
                <?php echo $langArray['TABLE_STATUS']; ?> :
                <?php if ($checkData['status']==0) {?>
                 <a href="system/operation.php?order_id=<?php echo $checkData['order_id'] ?>&status=1&packOrderStatus=ok">
                   <button class="btn btn-danger btn-sm"><?php echo $langArray['TABLE_STATUS_DECLINE']; ?></button>
                 </a>
               <?php } elseif ($checkData['status']==1) {?>
                 <a href="system/operation.php?order_id=<?php echo $checkData['order_id'] ?>&status=0&packOrderStatus=ok">
                   <button class="btn btn-success  btn-sm"><?php echo $langArray['TABLE_STATUS_ACCEPT']; ?></button>
                 </a>
               <?php } ?>
              </div>
            </div>
          </main>
         </div>
      </div>
    </div>
  </div>
</div>
