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

$ContentTreeNode = $ContentTree->getCurrentNode();
// $existing_languages = $node->getAvailableTranslations();
$allLanguages = Catalyz::getAllTranslations();
// $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 id="catalyz-content">
<div id="catalyz-content-internal">
<h1><?php echo __('Cache status', array(), 'catalyz'); ?></h1>
<?php include_partial('catalyz/flash'); ?>

<ul>
	<li><a href="<?php echo url_for('@cache-refresh'); ?>"><?php echo __('Refresh cache', array(), 'catalyz') ?></a></li>
	<li><a href="<?php echo url_for('@cache-create'); ?>"><?php echo __('Create the cache for all pages and cultures', array(), 'catalyz') ?></a></li>
	<li><a href="<?php echo url_for('@cache-clear'); ?>"><?php echo __('Clear the cache for all pages and cultures', array(), 'catalyz') ?></a></li>
</ul>

<table border="0" cellpadding="3" cellspacing="1">
<thead>
<tr>
	<th><?php echo __('Page', null, 'catalyz'); ?></th>
	<?php foreach($allLanguages as $code => $language) {?>
	<th width="70"><?php echo ucfirst($language); ?></th>
	<?php } ?>
</tr>
</thead>
<tbody>
<?php function showPage(ContentTreeNode $ContentTreeNode, $indentLevels)
{
	$existing_languages = $ContentTreeNode->getAvailableTranslations();
	?>
<tr>
	<td><?php
	for($i = 0; $i < $indentLevels; $i++){
		echo '&nbsp; &nbsp; ';
	}
	echo $ContentTreeNode->getTitle();

	?></td>
	<?php foreach(Catalyz::getAllTranslations() as $code => $language) {?>
	<?php $is_translation_available = $ContentTreeNode->isTranslationAvailable($code)  ?>
	<td align="center">
<?php if($is_translation_available && is_file($ContentTreeNode->getPathToCacheFile($code))){
?>
<a href="<?php echo url_for('@node-cache-clear?node_id='.$ContentTreeNode->getId().'&culture='.$code); ?>" title="<?php echo __('Clear the cache for this page and culture', array(), 'catalyz') ?>">
	<img src="/images/catalyz/accept.png" width="16" height="16" alt="" border="0" />
</a>
<?php

	}elseif($is_translation_available){
?>
<a href="<?php echo url_for('@node-cache-create?node_id='.$ContentTreeNode->getId().'&culture='.$code); ?>" title="<?php echo __('Create the cache for this page and culture', array(), 'catalyz') ?>">
	<img src="/images/catalyz/cross.png" width="16" height="16" alt="" border="0" />
</a>
<?php
}?></td>
	<?php } ?>
</tr>

<?php
    foreach($ContentTreeNode->children as $child) {
        showPage($child, $indentLevels + 1);
    }
}

showPage($ContentTree->getRoot(), 0);

?>



</tbody>
</table>

</div>
</div>
<?php

$content = ob_get_contents();

ob_end_clean();

$layout = LayoutManager::instance()->getCatalyzTemplate($ContentTreeNode->getCurrentLayoutNameForAction());
$properties['layout_family'] = $layout[0];
$properties['layout_name'] = $layout[1];
$properties['content'] = $content;

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

?>