<?php
/*
  osConcert Seat Booking Software
  https://www.osconcert.com
  Copyright (c) 2026 osConcert
  Released under the GNU General Public License
*/
defined('_FEXEC') or die();
?>

<div class="container-fluid cart-page">
  <div class="section-header cart-page__header">
    <h2 class="cart-page__title"><?php echo HEADING_TITLE; ?></h2>
  </div>

  <div class="index_static cart-page__body">

    <?php
    if (isset($_GET['error']) && $_GET['error'] === 'no_ticket_for_food') {
      echo '<div class="alert alert-danger cart-page__alert cart-page__alert--danger">';
      echo TEXT_WARNING_MENU_PRODUCT;
      echo '</div>';
    }

    include_once('includes/functions/ga_tickets.php');
    ga_cart_check();
    ga_kill_sessions();

    echo tep_draw_form('cart_quantity', tep_href_link(FILENAME_SHOPPING_CART, 'action=update_product'));

    if ($messageStack->size('shopping_cart') > 0) {
      echo '<div class="cart-page__messages">' . $messageStack->output('shopping_cart') . '</div>';
    }

    if ($cart->count_contents() > 0) {

      if ($quantity_error !== TEXT_GA_CART_HEADING) {
        echo '<div class="alert alert-warning cart-page__alert cart-page__alert--warning">';
        echo $quantity_error;
        echo '</div>';
      }
    ?>

      <div class="cart-page__table-wrap">
        <table class="table cart-table">
          <thead>
            <tr class="cart-table__head-row">
              <th class="cart-table__heading cart-col cart-col--remove"><?php echo TABLE_HEADING_REMOVE; ?></th>
              <th class="cart-table__heading cart-col cart-col--image"><?php echo TABLE_HEADING_PRODUCTS; ?></th>
              <th class="cart-table__heading cart-col cart-col--details heading-products"></th>
              <th class="cart-table__heading cart-col cart-col--qty"><?php echo TABLE_HEADING_QUANTITY; ?></th>
              <th class="cart-table__heading cart-col cart-col--total text-end"><?php echo TABLE_HEADING_TOTAL; ?></th>
            </tr>
          </thead>
          <tbody>

          <?php
          $any_out_of_stock = 0;
          $any_out_of_stock_ga = 0;
          $products = $cart->get_products();
          $switch_continue_shopping = true;
          $show_shipping = false;

          require_once(DIR_WS_INCLUDES . 'functions/categories_lookup.php');

          $products_name = '';
          for ($i = 0, $n = sizeof($products); $i < $n; $i++) {

            $id = tep_db_input($products[$i]['id']);
            list($heading_name, $heading_venue, $heading_date, $heading_time) = categories_lookup();

            $products_name .= '<tr id="p' . $products[$i]['id'] . '" class="cart-row cart-row--' . $products[$i]['product_type'] . '">';

            if (basename($PHP_SELF) == 'shopping_cart.php') {

              $family = '';
              if ($products[$i]['product_type'] == 'F') {
                $family = '<br><small class="cart-product__family">' . FAMILY_TICKET . ' x ' . FAMILY_TICKET_QTY . '</small>';
              }

              $products_name .= '<td class="cart-row__remove">';
              $products_name .= tep_draw_button('', 'bi bi-arrow-clockwise', NULL, NULL, NULL, 'btn-info btn-xs');
              $products_name .= ' ';
              $products_name .= tep_draw_button('', 'bi bi-x-circle', tep_href_link('shopping_cart.php', 'products_id=' . $products[$i]['sh_id'] . '&action=remove_product'), NULL, NULL, 'btn-danger btn-xs');
              $products_name .= '</td>';

              $products_name .= '<td class="cart-row__image heading-products-image">';
              $products_name .= '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products[$i]['id']) . '">';
              $products_name .= tep_product_small_image($products[$i]['image'], htmlspecialchars($products[$i]['title']));
              $products_name .= '</a>';
              $products_name .= '</td>';

              $products_name .= '<td class="cart-row__details cart-text">';
              $products_name .= '<a class="cart-product__title" href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products[$i]['id']) . '"><strong>' . $products[$i]['name'] . '</strong></a><br>';
              $products_name .= '<div class="cart-product__meta">';
              $products_name .= $heading_name . '<br>' . $heading_venue . '<br>' . $heading_date . ' ' . $heading_time . ' ' . $family;
              $products_name .= '</div>';

              if ($products[$i]['product_type'] == 'P') {
                if (STOCK_CHECK == 'true') {
                  $stock_check = tep_check_stock($products[$i]['id'], $products[$i]['quantity']);
                  if (tep_not_null($stock_check)) {
                    $any_out_of_stock = 1;
                    $products_name .= '<div class="cart-product__stock">' . $stock_check . '</div>';
                  }
                }

                if (isset($products[$i]['discount_whole_text'])) {
                  $products_name .= '<div class="cart-product__discount">' . $products[$i]['discount_whole_text'] . '</div>';
                }

              } elseif ($products[$i]['product_type'] == 'G') {

                if (STOCK_CHECK == 'true') {
                  $stock_check_ga = tep_check_stock_ga($products[$i]['id'], $products[$i]['quantity']);
                  if (tep_not_null($stock_check_ga)) {
                    $any_out_of_stock_ga = 1;
                    $products_name .= '<div class="cart-product__stock">' . $stock_check_ga . '</div>';
                  }
                }

                if ($FSESSION->is_registered('ga_quantity') && $FSESSION->is_registered('ga_prod_id')) {
                  if ($_SESSION['ga_prod_id'] == $products[$i]['id']) {
                    $products_name .= '<div class="cart-product__stock markProductOutOfStock">' . STOCK_CHANGE_LEFT . $_SESSION['ga_quantity'] . STOCK_CHANGE_RIGHT . '</div>';
                  }
                }

                if (isset($products[$i]['discount_whole_text'])) {
                  $products_name .= '<div class="cart-product__discount">' . $products[$i]['discount_whole_text'] . '</div>';
                }
              }

              $products_name .= '</td>';
            }

            if (STOCK_CHECK == 'true') {
              $stock_check = tep_check_stock($products[$i]['id'], $products[$i]['quantity']);
              if (tep_not_null($stock_check)) {
                $any_out_of_stock = 1;
                $products_name .= $stock_check;
              }
            }

            if ($products[$i]['weight'] > 0) {
              $show_shipping = true;
            }

            if ($is_price_breaks_result["products_price_break"] == 'Y') {
              $input_text = tep_draw_pull_down_menu('cart_quantity[]', $products[$i]["price_breaks"], $products[$i]['quantity']);
            }

            if ($products[$i]['product_type'] == 'P' || $products[$i]['sku'] == 6) {
              $input_text = tep_draw_hidden_field('cart_quantity[]', '1') . '1';
            } else {
              $input_text = tep_draw_input_field('cart_quantity[]', $products[$i]['quantity'], 'size="4" class="cart-qty-input text-center"');
            }

            $products_name .= '<td class="cart-row__qty cart-text">';
            $products_name .= $input_text . tep_draw_hidden_field('products_id[]', $products[$i]['sh_id']);
            $products_name .= '</td>';

            $products_name .= '<td class="cart-row__total cart-text text-end" valign="top"><strong>';
            $products_name .= $currencies->display_price($products[$i]['final_price'], tep_get_tax_rate($products[$i]['tax_class_id']), $products[$i]['quantity']);
            $products_name .= '</strong></td>';

            $products_name .= '</tr>';
          }

          echo $products_name;
          ?>

          </tbody>
        </table>
      </div>

      <div class="cart-page__tools">
        <a
          href="<?php echo tep_href_link(FILENAME_SHOPPING_CART, 'cPath=' . (int)$cPath . '&action=clear_cart'); ?>"
          class="btn btn-outline-danger cart-page__clear"
          onclick="return confirm('<?php echo addslashes(CLEAR_CART_MESSAGE); ?>');"
        >
          <?php echo CLEAR_CART; ?>
        </a>
      </div>

      <div class="cart-page__summary text-end">
        <strong>
          <?php
          if (basename($PHP_SELF) == 'shopping_cart.php') {
            echo SUB_TITLE_SUB_TOTAL;
          } else {
            echo SUB_TITLE_TOTAL;
          }

          global $FSESSION;
          $fp1 = 0;

          if (ALLOW_GUEST_TO_SEE_PRICES == 'true' && !($FSESSION->is_registered('customer_id'))) {
            echo '<span id="cart_subtotal" class="cart-page__subtotal">&nbsp;' . $currencies->format($cart->show_total()) . '</span>';
          } elseif ($FSESSION->is_registered('customer_id')) {
            $fp1 = $currencies->format($cart->show_total());
            echo '<span id="cart_subtotal" class="cart-page__subtotal">&nbsp;' . $fp1 . '&nbsp;&nbsp;</span>';
          } else {
            echo PRICES_LOGGED_IN_TEXT;
          }
          ?>
        </strong>
      </div>

      <div class="cart-page__warnings">
        <?php
        if ($any_out_of_stock == 1) {
          if (STOCK_ALLOW_CHECKOUT == 'true') {
            echo '<div class="stockWarning cart-page__warning"><br>' . OUT_OF_STOCK_CAN_CHECKOUT . '</div>';
          } else {
            echo '<div class="stockWarning cart-page__warning"><br>' . OUT_OF_STOCK_CANT_CHECKOUT . '</div>';
          }
        }

        if ($any_out_of_stock_ga == 1) {
          if (STOCK_ALLOW_CHECKOUT == 'true') {
            echo '<div class="stockWarning cart-page__warning"><br>' . OUT_OF_STOCK_CAN_CHECKOUT_GA . '</div>';
          } else {
            echo '<div class="stockWarning cart-page__warning"><br>' . OUT_OF_STOCK_CANT_CHECKOUT_GA . '</div>';
          }
        }

        if ($FSESSION->is_registered('ga_quantity')) {
          echo '<div class="stockWarning cart-page__warning"><br>' . OUT_OF_STOCK_CANT_CHECKOUT_GA_MASTER . '</div>';
          $FSESSION->remove('ga_quantity');
          $FSESSION->remove('ga_prod_id');
        }
        ?>
      </div>

      <div class="cart-page__actions">
        <div class="cart-page__actions-right">
          <?php
          if (basename($PHP_SELF) == 'shopping_cart.php') {
            echo '<a class="cart-page__continue" href="' . tep_href_link(FILENAME_FEATURED_CATEGORIES, '') . '">'
              . tep_template_image_button_basic('', IMAGE_BUTTON_CONTINUE_SHOPPING)
              . '</a>';
          }
          ?>
        </div>

        <div class="cart-page__actions-right">
          <?php
          if ($_SESSION['customer_country_id'] == 999 && isset($_SESSION['box_office_refund'])) {
          ?>
            <script type="text/javascript">
              function confirmation() {
                var answer = confirm("<?php echo BO_REFUND; ?>");
                if (answer) {
                  return true;
                } else {
                  return false;
                }
              }
            </script>
            <div id="btnCheckOut" class="cart-page__checkout">
              <?php echo '<a onclick="return confirmation()" title="' . IMAGE_BUTTON_REFUND . '" href="' . tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL') . '">' . tep_template_image_button('button_checkout.gif', IMAGE_BUTTON_REFUND) . '</a>'; ?>
            </div>
          <?php
          } elseif ($_SESSION['customer_country_id'] == 999 && isset($_SESSION['box_office_reservation'])) {
          ?>
            <script type="text/javascript">
              function confirmation() {
                var answer = confirm("<?php echo BOR_CONFIRM_RESERVATIONS; ?>");
                if (answer) {
                  return true;
                } else {
                  return false;
                }
              }
            </script>
            <div id="btnCheckOut" class="cart-page__checkout">
              <?php echo '<a onclick="return confirmation()" title="' . IMAGE_BUTTON_REFUND . '" href="' . tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL') . '">' . tep_template_image_button('button_checkout.gif', IMAGE_BUTTON_REFUND) . '</a>'; ?>
            </div>
          <?php
          } else {
            echo '<div class="cart-page__checkout">';
            echo '<a href="' . tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL') . '">' . tep_template_image_button_basic('button_checkout.gif', IMAGE_BUTTON_CHECKOUT) . '</a>';
            echo '</div>';
          }
          ?>
        </div>
      </div>

      </form>

    <?php
    } else {
    ?>

      <div class="cart-page__empty">
        <div class="cart-empty"><?php echo TEXT_CART_EMPTY; ?></div>

        <div class="cart-page__empty-actions d-flex justify-content-end gap-2">
          <?php
          echo '<a href="' . tep_href_link(FILENAME_FEATURED_CATEGORIES) . '">' . tep_template_image_button_basic('', IMAGE_BUTTON_CONTINUE_SHOPPING) . '</a>';
          echo '&nbsp;&nbsp;&nbsp;<a href="' . tep_href_link(FILENAME_DEFAULT) . '">' . tep_template_image_button_basic('', IMAGE_BUTTON_CONTINUE) . '</a>';
          ?>
        </div>
      </div>

    <?php
    }
    ?>

  </div>
</div>

<?php
include_once('wannabuy');
wannabuy();
?>