<?php

define('RENDER_MODE', 'catalyz');

$node = $page->getNode();

use_helper('Form');

$properties = array();
$properties['page'] = $page;
$properties['node'] = $node;
$properties['ContentTree'] = $ContentTree;

ob_start();
use_helper('I18N');

$allLanguages = sfConfig::get('app_translations_available_languages');
$default = sfConfig::get('app_translations_default_language');
// $existing_languages = $node->getAvailableTranslations();
$allLanguages = Catalyz::getAllTranslations();
unset($allLanguages[$default]);
// $perms = array();
// $available_languages = array();
// foreach($allLanguages as $iso => $name) {
// if (!isset($existing_languages[$iso])) {
// $available_languages[$iso] = ucfirst($name);
// }
// $perms[$iso]['edit'] = true;
// $perms[$iso]['delete'] = ($iso != $default);
// }
// include_partial('catalyz/header');

?>

<div class="content-add01">
	<div class="heading01"><h1>MON PANIER</h1></div>
</div>

<?php $cart =/*(KataoCart)*/ $sf_user->getInstance()->getCart() ?>
<?php if (0 < $cart->countProducts()): ?>
	<ul class="plus">
	<?php foreach($cart->getKataoCartProductsJoinKataoProduct() as/*(KataoCartProduct)*/ $katao_cart_product): ?>
		<?php $quantity = $katao_cart_product->getQuantity() ?>
		<?php $katao_product = $katao_cart_product->getKataoProduct() ?>
		<li>
			<div class="image01">
				<div class="top"></div>
				<div class="center">
					<div><?php echo thumbnail_tag($katao_product->getRealPicture(), 77, 88, array('alt' => $katao_product->getName())) ?></div>
				</div>
				<div class="bottom"></div>
			</div>
			<div class="plus-add">
				<h3><?php echo $katao_product->getName() ?></h3>
			<?php if ('' != $katao_product->getDescription()): ?>
				<p><?php echo $katao_product->getDescription() ?></p>
			<?php endif ?>
				<p>Prix : <?php echo Utils::formatCurrencyEuro($katao_product->getTotalPriceWithTaxes()) ?> dont <?php echo $katao_product->getMaxSolAmountStr() ?></p>
				<p>Commande : <?php echo $katao_product->getOrderDetails($cart->getKataoPeriodId(), $cart->getKataoNodeId()) ?></p>

				<div style="clear: both">
					<div style="float: left; padding-right: 10px">
						<input type="text" name="quantity_<?php echo $katao_product->getId() ?>" id="quantity_<?php echo $katao_product->getId() ?>" value="<?php echo $quantity ?>" style="width: 20px; text-align: center;" />
					</div>
					<div style="float: left; padding-right: 10px; padding-top: 4px">
						<a class="btn-plus" href="javascript://" onclick="window.location = '<?php echo url_for('@katao_cart_add_js') ?>?product=<?php echo $katao_product->getUrlIdentifier() ?>&quantity='+document.getElementById('quantity_<?php echo $katao_product->getId() ?>').value;">Mettre à jour</a>
					</div>
					<div style="float: left; padding-right: 10px; padding-top: 4px">
						<a class="btn-plus" href="<?php echo url_for('@katao_cart_remove?product=' . $katao_product->getUrlIdentifier()) ?>" onclick="return confirm('Etes-vous sûr de vouloir supprimer ce produit de votre panier ?');">Supprimer</a>
					</div>
				</div>
			</div>
		</li>
	<?php endforeach ?>
	</ul>

	<?php $cart_total = $cart->sumProducts() ?>
	TOTAL : <?php echo Utils::formatCurrencyEuro($cart_total) ?> et <?php echo Utils::formatCurrencySol($cart->sumSols()) ?>

	<?php $katao_member = $sf_user->getInstance()->getKataoMember() ?>

	<?php if (!$katao_member->getIsMember()): ?>
				<p style="color: #F39B00;font-weight: bold;">VOUS NE POUVEZ PAS VALIDER VOTRE PANIER CAR VOUS N'ETES PAS ADHERENT.</p>
	<?php else: ?>
		<?php if (KataoCart::STATUS_IN_PROGRESS == $cart->getStatus()): ?>
			<?php if ($cart_total > $katao_member->getCurrentAmountEuro()): ?>
				<p style="color: #F39B00;font-weight: bold;">VOUS NE POUVEZ PAS VALIDER VOTRE PANIER CAR VOTRE SOLDE EST UNSUFFISANT. MERCI DE BIEN VOULOIR LE CREDITER.</p>
			<?php else: ?>
				<br /><a class="btn-commander" href="<?php echo url_for('@katao_cart_validate') ?>" onclick="return confirm('Etes-vous sûr de vouloir valider ce panier ?');">VALIDER</a>
			<?php endif ?>
		<?php else: ?>
				<p style="color: #F39B00;font-weight: bold;">VOTRE PANIER EST VALIDE</p>
		<?php endif ?>
	<?php endif ?>
<?php else: ?>
	<p>Aucun produit</p>
<?php endif ?>

<?php

                    $content = ob_get_contents();

                ob_end_clean();
                // $layout = LayoutManager::instance()->getCatalyzTemplate($ContentTreeNode->getCurrentLayoutNameForAction());
                $properties['layout_family'] = 'katao';
                $properties['layout_name'] = 'default';
                $properties['content'] = $content;

                include_component($properties['layout_family'], $properties['layout_name'], $properties);

                ?>