<?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();
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 id="catalyz-content">
<div id="catalyz-content-internal">
<h1><?php echo __('Translation overview', null, 'catalyz'); ?></h1>
<?php include_partial('catalyz/flash'); ?>

<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, $indentLevels)
{
    $existing_languages = $ContentTreeNode->getAvailableTranslations();

    ?>
<tr>
	<td><?php
    for($i = 0; $i < $indentLevels; $i++) {
        echo '&nbsp; &nbsp; ';
    }
    echo sprintf('<a href="%s">%s</a>', $ContentTreeNode->getUrl(), $ContentTreeNode->getTitle());

    ?></td>
	<?php

    $allTranslations = Catalyz::getAllTranslations();
    unset($allTranslations[sfConfig::get('app_translations_default_language')]);

    foreach($allTranslations as $code => $language) {?>
	<td align="center">

<a href="<?php echo url_for('@node-translation-add-and-edit?node_id=' . $ContentTreeNode->getId() . '&language=' . $code); ?>"><?php if (isset($existing_languages[$code])) {?>
<img src="/images/catalyz/accept.png" width="16" height="16" alt="" border="0" />
<?php

        } else {?>
<img src="/images/catalyz/cross.png" width="16" height="16" alt="" border="0" />
<?php
        }
        ?></a></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);

?>