<?php // BEGIN PHP

//session_set_cookie_params(['lifetime' => 0, 'path' => '/', 'domain' => '', 'secure' => true, 'httponly' => true, 'samesite' => 'Lax');
session_start(); // start session

includeContainer('_library_page_lib.php', 1);
setSessionLang();
$weblangs->load("marketplace@marketplace", "languages");
$langs->load("languages");

// Get available langs for the website
$website_langs = getAvailableLangs();
$available_langs = $website_langs['langs'];
$langs_code_shortcode = $website_langs['langs_code_shortcode'];



$mc_website_id = getDolGlobalInt("MARKETPLACE_WEBSITE_ID");
if (empty($mc_website_id)) {
  print $weblangs->trans("variableNotDefined", 'MARKETPLACE_WEBSITE_ID');
  exit;
}

$mc_secret_key = getDolGlobalString("MARKETPLACE_SECRET_KEY");
if (empty($mc_secret_key)) {
  print $weblangs->trans("variableNotDefined", 'MARKETPLACE_SECRET_KEY');
  exit;
}

if (!(isModEnabled('paypal') || isModEnabled('stripe') || isModEnabled('paybox'))) {
    print $weblangs->trans("noPaymentModuleIsActivated");
    exit;
}

$tag = GETPOST('tag', 'alpha');
$cat_id = GETPOST('cat', 'alpha');
$search = GETPOST('search_query', 'alpha');
// END PHP 
?>
<script type="text/javascript">
  var shopping_cart_url = "_service_page_ajax.php";
  //var shopping_cart_url = "<?php //echo DOL_URL_ROOT . '/custom/dolibarr-foundation/marketplace/doctemplates/websites/website_template-dolistore/containers/shopping_cart.php'; ?>";
</script>
<header id="header">
  <div class="nav">
    <div class="container">
      <div class="row">
        <nav>
            <?php if (!empty($_SESSION['user']['pseudo'])): ?>
                <div class="header_user_info">
                	<a href="myaccount.php" title="<?php print $weblangs->trans("viewMyCustomerAccount"); ?>" class="account" rel="nofollow"><span><?php print $_SESSION['user']['pseudo']; ?></span></a>
                </div>
            <?php endif ?>
          <div class="header_user_info">
            <?php if (empty($_SESSION['user']['id_user'])): ?>
                <a class="login" href="login-register.php" rel="nofollow" title="<?php print $weblangs->trans("logInToYourCustomerAccount"); ?>"> <?php print $weblangs->trans("signIn"); ?> </a>
            <?php else: ?>
                <a class="login" href="myaccount.php?action=logout" rel="nofollow" title="<?php print $weblangs->trans("logOutFromYourCustomerAccount"); ?>"> <?php print $weblangs->trans("logOut"); ?> </a>
            <?php endif ?>
            
          </div>
          <div id="languages-block-top" class="languages-block">
            <div class="current">
              <span><?php print trim(explode('(', $langs->trans("Language_".$langs_code_shortcode[$_SESSION['lang']['shortcode']]))[0]); ?></span>
            </div>
            <ul id="first-languages" class="languages-block_ul toogle_content">
                <?php foreach ($available_langs as $key => $value) : ?>
                    <?php $value = trim(explode('(', $langs->trans("Language_".$langs_code_shortcode[$key]))[0]); ?>
                    <?php if ($key == $_SESSION['lang']['shortcode']): ?>
		                <li class="selected">
                            <span><?php print $value; ?></span>
                        </li>
                	<?php else: ?>
                		<li>
                          <form id="languageForm-<?php print $key; ?>" method="post" action="#">
                            <input type="hidden" name="l" value="<?php print $key; ?>">
                            <!--<a href="#" title="<?php //print $langs->trans("Language_".$langs_code_shortcode[$key]); ?>" onclick="document.getElementById('languageForm-<?php //print $key; ?>').submit(); return false;">-->
                            <a href="#" title="<?php print $langs->trans("Language_".$langs_code_shortcode[$key]); ?>" onclick="
                                   const form = document.getElementById('languageForm-<?php print $key; ?>');
                                   const parser = document.createElement('a');
                                   parser.href = form.action || window.location.href;
                                   const params = new URLSearchParams(parser.search);
                                   params.delete('l');
                                   parser.search = params.toString();
                                   form.action = parser.href;
                                   form.submit();
                                   return false;
                               ">    
                              <span><?php print $value ; ?></span>
                            </a>
                          </form>
                        </li>
                	<?php endif ?>
                <?php endforeach ?>
            </ul>
          </div>
        </nav>
      </div>
    </div>
  </div>
  <div>
    <div class="container">
      <div class="row">
        <div id="header_logo">
          <?php
          if(getDolGlobalString('MARKETPLACE_URL_FOR_LOGO')){
              $html_logo = '<img class="logo img-responsive-logo img-responsive" alt="" widthold="520" src="'.getDolGlobalString('MARKETPLACE_URL_FOR_LOGO').'">';
          }else{
              $path = getImageFileNameForSize($mysoc->logo_squarred ? $mysoc->logo_squarred : $mysoc->logo, '_small');
              $html_logo = '<img class="logo img-responsive-logo img-responsive" alt="" widthold="520" src="' . DOL_URL_ROOT . '/viewimage.php?modulepart=mycompany&file='.urlencode('logos/'.$path).'">';
          }
          ?>
          <a href="index.php" title="DoliStore">
            <?php print $html_logo; ?>
          </a>
        </div>
        <div id="search_block_top" class="col-sm-4 clearfix">
          <?php $test = "11"; ?>
          <form id="searchbox" method="get" action="index.php">
            <input type="hidden" name="controller" value="search" />
            <input type="hidden" name="orderby" value="position" />
            <input type="hidden" name="orderway" value="desc" />
            <input type="hidden" name="tag" value="<?php (isset($tag)) ? print $tag : ''; ?>" />
            <input type="hidden" name="website" value="<?php print $websitekey; ?>" />
            <input class="search_query form-control" type="text" id="search_query_top" name="search_query" placeholder="<?php print $weblangs->trans("Search"); ?>" value="<?php print GETPOST('search_query', 'alpha'); ?>" />
            <button type="submit" name="submit_search" class="btn btn-default button-search">
              <span><?php print $weblangs->trans("Search"); ?></span>
            </button>
          </form>
          <div class="filterbyversion">
          <?php (!empty($tag)) ? print $weblangs->trans("filteredByVersion") . ' ' . $tag . ' - <a href="index.php">' . $weblangs->trans("removeFilter") . '</a>' : ''; ?>
          </div>
        </div>
        <div class="col-sm-4 clearfix">
            
        <?php if ($websitepage->ref != "payment"): ?>
            <div class="shopping_cart">
            <a href="order.php" title="<?php print $weblangs->trans("viewMyCart"); ?>" rel="nofollow">
              <b><?php print $weblangs->trans("Cart"); ?></b>
              <span class="ajax_cart_quantity unvisible">0</span>
              <span class="ajax_cart_product_txt unvisible"><?php print $weblangs->trans("product"); ?></span>
              <span class="ajax_cart_product_txt_s unvisible"><?php print $weblangs->trans("products"); ?></span>
              <span class="ajax_cart_total unvisible"></span>
                <?php if (!empty($_SESSION['products'])): ?>
                    <span class="ajax_cart_no_product"><?php print count($_SESSION['products']); ?></span> Product<?php if(count($_SESSION['products']) > 1){ print 's';} ?>
                <?php else: ?>
                    <span class="ajax_cart_no_product">0</span> <?php print $weblangs->trans("product"); ?>
                <?php endif ?>
            </a>
            <div class="cart_block block exclusive">
              <div class="block_content">
                <div class="cart_block_list">
                    
                  <p class="cart-buttons">
                    <a id="button_order_cart" class="btn btn-default button button-small" href="order.php" title="Check out" rel="nofollow">
                      <span> <?php print $weblangs->trans("checkOut"); ?> <i class="icon-chevron-right right"></i>
                      </span>
                    </a>
                  </p>

                    <?php if (!$_SESSION['products']): ?>
                        <p class="cart_block_no_products"> <?php print $weblangs->trans("noProducts"); ?> </p>
                    <?php else: ?>
                        <?php $total = 0; ?>
                        <?php foreach ($_SESSION['products'] as $cart_product): ?>
                            <dl class="products">
                               <dt class="item" data-id="cart_block_product_<?php print $cart_product['product_id']; ?>" style="display: block;">
                                  <a class="cart-images" href="product.php?id=<?php print $cart_product['product_id']; ?>" title="<?php print $cart_product['product_name']; ?>"><img src="<?php print $cart_product['product_thumb']; ?>" alt="<?php print $cart_product['product_name']; ?>"></a>
                                  <div class="cart-info">
                                     <div class="product-name"><span class="quantity-formated"><span class="quantity"><?php print $cart_product['product_qty']; ?></span>&nbsp;x&nbsp;</span><a href="product.php?id=<?php print $cart_product['product_id']; ?>" title="<?php print $cart_product['product_name']; ?>" class="cart_block_product_name truncate3"><?php print $cart_product['product_name']; ?></a></div>
                                     <span class="price"><?php print price($cart_product['product_price']); ?> €</span>
                                  </div>
                                  <span class="remove_link"><a rel="nofollow" class="ajax_cart_block_remove_link" href="" data-code="<?php print $cart_product['product_id']; ?>"> </a></span>
                               </dt>
                            </dl>	
                            <?php
                                $subtotal = ($cart_product['product_price'] * $cart_product['product_qty']);
                                $total = ($total + $subtotal);
                            ?>
                        <?php endforeach ?>
                    <?php endif ?>

                  <div class="cart-prices">
                    <!--
                    <div class="cart-prices-line first-line">
                      <span class="price cart_block_shipping_cost ajax_cart_shipping_cost"> <?php print $weblangs->trans("freeShipping"); ?> </span>
                      <span> <?php print $weblangs->trans("Shipping"); ?> </span>
                    </div>
                    -->
                    <div class="cart-prices-line last-line">
                      <span class="price cart_block_total ajax_block_cart_total"><?php print $total; ?> €</span>
                      <span><?php print $weblangs->trans("Total"); ?></span>
                    </div>
                    <p> <?php print $weblangs->trans("pricesMayVaryDependingOnYourCountry"); ?> </p>
                  </div>
                  

                </div>
              </div>
            </div>
        </div>
        <?php endif ?>
        
        
        
        </div>
        <div id="layer_cart" class="lightbox3">
            <div id="content3">
                <div class="clearfix">
            <div class="layer_cart_product col-xs-12 col-md-6">
              <span class="cross" title="Close window"></span>
              <h2>
                <i class="icon-ok"></i><?php print $weblangs->trans("productAddedToCart"); ?>
              </h2>
              <div class="product-image-container layer_cart_img">
                  
              </div>
              <div id="layer_cart_product_info">
                <span id="layer_cart_product_title" class="product-name"></span>
                <span id="layer_cart_product_attributes"></span>
                <div>
                  <strong class="dark"><?php print $weblangs->trans("quantity"); ?></strong>
                  <span id="layer_cart_product_quantity"></span>
                </div>
                <div>
                  <strong class="dark"><?php print $weblangs->trans("total"); ?></strong>
                  <span id="layer_cart_product_price"></span>
                </div>
              </div>
            </div>
            <div class="layer_cart_cart col-xs-12 col-md-6">
              <h2>
                <span class="ajax_cart_product_txt_s  unvisible"> <?php print $weblangs->trans("nbrItemsInCart"); ?> </span>
                <span class="ajax_cart_product_txt "> <?php print $weblangs->trans("thereIsItemInYourCart"); ?> </span>
              </h2>
              <div class="layer_cart_row">
                <strong class="dark"> <?php print $weblangs->trans("totalProductsTaxIncl"); ?> </strong>
                <span class="ajax_block_products_total"></span>
              </div>
              <div class="layer_cart_row">
                <strong class="dark"> <?php print $weblangs->trans("totalShippingTaxIncl"); ?> </strong>
                <span class="ajax_cart_shipping_cost"> <?php print $weblangs->trans("freeShipping"); ?> </span>
              </div>
              <div class="layer_cart_row">
                <strong class="dark"><?php print $weblangs->trans("tax"); ?></strong>
                <span class="price cart_block_tax_cost ajax_cart_tax_cost">0,00 €</span>
              </div>
              <div class="layer_cart_row">
                <strong class="dark"> <?php print $weblangs->trans("totalTaxIncl"); ?> </strong>
                <span class="ajax_block_cart_total"></span>
              </div>
              <div class="button-container">
                <span class="continue btn btn-default button exclusive-medium" title="<?php print $weblangs->trans("continueShopping"); ?>">
                  <span>
                    <i class="icon-chevron-left left"></i><?php print $weblangs->trans("continueShopping"); ?> </span>
                </span>
                <a class="btn btn-default button button-medium" href="order.php" title="<?php print $weblangs->trans("proceedToCheckout"); ?>" rel="nofollow">
                  <span> <?php print $weblangs->trans("proceedToCheckout"); ?> <i class="icon-chevron-right right"></i>
                  </span>
                </a>
              </div>
            </div>
          </div>
            </div>
        </div>
        <div id="layer_cart">
          <div class="clearfix">
            <div class="layer_cart_product col-xs-12 col-md-6">
              <span class="cross" title="Close window"></span>
              <h2>
                <i class="icon-ok"></i><?php print $weblangs->trans("productAddedToCart"); ?>
              </h2>
              <div class="product-image-container layer_cart_img">
                  
              </div>
              <div id="layer_cart_product_info">
                <span id="layer_cart_product_title" class="product-name"></span>
                <span id="layer_cart_product_attributes"></span>
                <div>
                  <strong class="dark"><?php print $weblangs->trans("quantity"); ?></strong>
                  <span id="layer_cart_product_quantity"></span>
                </div>
                <div>
                  <strong class="dark"><?php print $weblangs->trans("total"); ?></strong>
                  <span id="layer_cart_product_price"></span>
                </div>
              </div>
            </div>
            <div class="layer_cart_cart col-xs-12 col-md-6">
              <h2>
                <span class="ajax_cart_product_txt_s  unvisible"> <?php print $weblangs->trans("nbrItemsInCart"); ?> </span>
                <span class="ajax_cart_product_txt "> <?php print $weblangs->trans("thereIsItemInYourCart"); ?> </span>
              </h2>
              <div class="layer_cart_row">
                <strong class="dark"> <?php print $weblangs->trans("totalProductsTaxIncl"); ?> </strong>
                <span class="ajax_block_products_total"></span>
              </div>
              <div class="layer_cart_row">
                <strong class="dark"> <?php print $weblangs->trans("totalShippingTaxIncl"); ?> </strong>
                <span class="ajax_cart_shipping_cost"> <?php print $weblangs->trans("freeShipping"); ?> </span>
              </div>
              <div class="layer_cart_row">
                <strong class="dark"><?php print $weblangs->trans("tax"); ?></strong>
                <span class="price cart_block_tax_cost ajax_cart_tax_cost">0,00 €</span>
              </div>
              <div class="layer_cart_row">
                <strong class="dark"> <?php print $weblangs->trans("totalTaxIncl"); ?> </strong>
                <span class="ajax_block_cart_total"></span>
              </div>
              <div class="button-container">
                <span class="continue btn btn-default button exclusive-medium" title="Continue shopping">
                  <span>
                    <i class="icon-chevron-left left"></i><?php print $weblangs->trans("continueShopping"); ?> </span>
                </span>
                <a class="btn btn-default button button-medium" href="order.php" title="<?php print $weblangs->trans("proceedToCheckout"); ?>" rel="nofollow">
                  <span> <?php print $weblangs->trans("proceedToCheckout"); ?> <i class="icon-chevron-right right"></i>
                  </span>
                </a>
              </div>
            </div>
          </div>
          <div class="crossseling"></div>
        </div>
        <div class="layer_cart_overlay"></div>
      </div>
    </div>
  </div>
    
    <!-- The div for the image preview -->
    <div id="lightbox" class="marketplacelightbox" style="display: none;">
      <p><?php print $weblangs->trans("clickToClose"); ?></p>
      <div id="content" class="marketplacelightbox2"><!-- Do not include a img src tag here, it will generate a load by the parent page --></div>
    </div>
