<?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');

?>

<?php $katao_product_category = $sf_request->getParameter('category') ?>
<?php $katao_product_family = $sf_request->getParameter('family') ?>
<?php $katao_product = $sf_request->getParameter('product') ?>
<?php if ($katao_product_category && !$katao_product_family && !$katao_product): ?>
	<?php include_partial('katao/products', array('pager' => KataoProductPeer::getPagerForAllByProductCategoryUrlIdentifier($katao_product_category, $sf_request->getParameter('page', 1)), 'url' => '@katao_boutique_rayon_paginee?category=' . $katao_product_category, 'katao_product_category' => $katao_product_category, 'katao_product_family' => $katao_product_family)) ?>
<?php elseif ($katao_product_category && $katao_product_family && !$katao_product): ?>
	<?php include_partial('katao/products', array('pager' => KataoProductPeer::getPagerForAllByProductFamilyUrlIdentifier($katao_product_family, $sf_request->getParameter('page', 1)), 'url' => '@katao_boutique_famille_paginee?category=' . $katao_product_category . '&family=' . $katao_product_family, 'katao_product_category' => $katao_product_category, 'katao_product_family' => $katao_product_family)) ?>
<?php elseif ($katao_product_category && $katao_product_family && $katao_product): ?>
	<?php $katao_product = KataoProductPeer::retrieveByUrlIdentifier($katao_product) ?>
	<?php $katao_product_cartable = $katao_product->isCartable() ?>
	<ul class="plus01">
		<li>
			<div class="image02">
				<div class="top"></div>
				<div class="center">
					<?php use_helper('fancybox') ?>
					<div><?php echo fancybox_tag($katao_product->getRealPicture(), 143, 168, $katao_product->getName()) ?></div>
				</div>
				<div class="bottom"></div>
			</div>
			<div class="plus01-add">
				<h3><?php echo $katao_product->getName() ?></h3>
				<ul>
				<?php if ('' != $katao_product->getReference()): ?>
					<li>Référence : <?php echo $katao_product->getReference() ?></li>
				<?php endif ?>
				<?php if (null != $katao_supplier = $katao_product->getKataoSupplier()): ?>
					<li>Fournisseur : <?php echo link_to($katao_supplier->getName(), '@katao_fournisseurs_details?supplier=' . $katao_supplier->getUrlIdentifier()) ?></li>
				<?php endif ?>
				<?php if ($katao_product->getDeliveryDelay()): ?>
					<li>Délai de livraison : <?php echo $katao_product->getDeliveryDelay() ?> jour(s)</li>
				<?php endif ?>
					<li>&nbsp;</li>
					<li>Prix : <?php echo Utils::formatCurrencyEuro($katao_product->getTotalPriceWithTaxes()) ?> dont <?php echo $katao_product->getMaxSolAmountStr() ?></li>
				<?php if ($katao_product_cartable && $sf_user->isAuthenticated() && $sf_user->hasCredential('member')): ?>
					<li>Commande : <?php echo $katao_product->getOrderDetails($sf_user->getActivePeriod()->getId(), $sf_user->getActiveNode()->getId()) ?></li>
				<?php endif ?>
				</ul>
			<?php if ($sf_user->isAuthenticated() && $sf_user->hasCredential('member')): ?>
				<div style="clear: both; margin-top: 40px">
				<?php if ($katao_product_cartable): ?>
					<div style="float: left; padding-right: 10px">
						<a href="javascript://" onclick="document.getElementById('quantity').value = Math.max(1, parseInt(document.getElementById('quantity').value) - 1)" title="Diminuer la quantité"><?php echo image_tag('minus.png', array('alt' => 'Diminuer la quantité', 'align' => 'top')) ?></a>
						<input type="text" name="quantity" id="quantity" value="1" style="width: 20px; text-align: center;" />
						<a href="javascript://" onclick="document.getElementById('quantity').value = parseInt(document.getElementById('quantity').value) + 1" title="Augmenter la quantité"><?php echo image_tag('plus.png', array('alt' => 'Augmenter la quantité', 'align' => 'top')) ?></a>
					</div>
					<div style="float: left">
						<a class="btn-commander" href="javascript://" onclick="window.location = '<?php echo url_for('@katao_cart_add_js') ?>?product=<?php echo $katao_product->getUrlIdentifier() ?>&quantity='+document.getElementById('quantity').value;">Commander</a>
					</div>
				<?php else: ?>
					<i>Ce produit est momentanément indisponible</i>
				<?php endif ?>
				</div>
			<?php endif ?>
			</div>
			<div style="clear: both; padding-top: 7px"><?php echo $katao_product->getDescription() ?></div>
		</li>
	</ul>
<?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);

                                        ?>