<?php

define('RENDER_MODE', 'catalyz');

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

$ContentTreeNode = $ContentTree->getCurrentNode();

ob_start();

use_helper('Javascript');
use_helper('Form');
use_helper('I18N');

//use_javascript('jquery.ui-1.6b/jquery-1.2.6.js');
//use_stylesheet('/js/jquery.ui-1.6b/themes/smoothness/jquery-ui-1.7.custom.css', '', array('media' => 'screen', 'title' => 'Flora (Default)'));
//use_javascript('jquery.ui-1.6b/ui/ui.core.js');
//use_javascript('jquery.ui-1.6b/ui/ui.tabs.js');

echo javascript_tag('$(function() {
	$("#tabs").tabs();
	});');

use_helper('Object', 'Catalyz');

if ($node->getId()) {
	echo form_tag('@node-edit?node_id=' . (int)$node->getId(), array('name' => 'catalyzEdit'));
} else {
	echo form_tag('@node-edit-new', array('name' => 'catalyzEdit'));
}
?>
<div id="catalyz-content">

<?php
include_partial('catalyz/header');

?>

<div id="catalyz-content-internal">
<?php
if ($page instanceof ICatalyzTranslatable) {?>

<div style="float: right"><img src="/images/catalyz/translations/<?php echo $culture; ?>.gif" width="16" height="11" alt="" border="0" /></div>
<?php
}

?>
<?php

echo input_hidden_tag('culture', $culture);
if ($node->isNew()) {
    echo '<h1>';

    $parentPage = $parentNode->getPage();
    if ($parentPage instanceof ICatalyzToolbarActionStringManager) {
        echo $parentPage->getCatalyzToolbarAddCaption();
    } else {
        echo __('Add a page', null, 'catalyz');
    }
    echo '</h1>';

    echo input_hidden_tag('parent_id', $node->getTreeParent());
    echo input_hidden_tag('page_type', $node->getNodeClass());
} else {
    printf('<h1>' . __('Editing page "%s"', null, 'catalyz') . '</h1>',
    	sprintf('<a href="%s">%s</a>', $ContentTreeNode->getUrl(), $ContentTreeNode->getTitle()));
    echo input_hidden_tag('current_node', $node->getId());
}

$tabs = array();
$tabs['<img src="/images/catalyz/content.png" width="16" height="16" alt="" border="0" align="top" />&nbsp;'
	.__('Content', null, 'catalyz')] = 'edit_content';
if (!$page instanceof ICatalyzSubNode && Catalyz::isTabEnabled('seo')) {
	$tabs['<img src="/images/catalyz/seo.png" width="16" height="16" alt="" border="0" align="top" />&nbsp;'
		.__('Search Engine Optimization', null, 'catalyz')] = 'edit_seo';
} else {
    include_partial('edit_seo_default', $properties);
}
if (!$page instanceof ICatalyzSubNode && Catalyz::getLoginHandler() instanceof ILoginHandlerPermissionAdminProvider && Catalyz::getLoginHandler()->hasAccessToPermsTab() && Catalyz::isTabEnabled('perms')) {
	$tabs['<img src="/images/catalyz/permissions.png" width="16" height="16" alt="" border="0" align="top" />&nbsp;'
		.__('Permissions', null, 'catalyz')] = Catalyz::getLoginHandler()->getEditPermissionTemplate();
} else {
    include_partial('catalyzLoginHandlerViewGroup/edit_perms_default', $properties);
}
if (!$page instanceof ICatalyzSubNode && Catalyz::isTabEnabled('layout')) {
	$tabs['<img src="/images/catalyz/layout.png" width="16" height="16" alt="" border="0" align="top" />&nbsp;'
		.__('Layout', null, 'catalyz')] = 'edit_layout';
} else {
    include_partial('edit_layout_default', $properties);
}

?>
</div>
<div id="tabs">

            <ul>
			<?php
$tabIndex = 1;
foreach($tabs as $tabCaption => $tabContent) {
    printf('<li><a href="#fragment-%d"><span>%s</span></a></li>', $tabIndex++, __($tabCaption));
}

?>
            </ul>

<?php
$tabIndex = 1;

$options = $properties;
$options['properties'] = $properties;
$options['availableLayouts'] = $availableLayouts;
foreach($tabs as $tabCaption => $tabContent) {
    printf('<div id="fragment-%d" style="min-height: 300px">', $tabIndex++);
    include_partial($tabContent, $options);
    echo '</div>';
}

?>


</div>
<div style="margin-top: 10px;">
<?php
$actions = array();

if ($page instanceof ICatalyzEditActionManager) {
	$actions = $page->getEditActions();
} else {
	$actions = CatalyzActionControler::getDefaultActions();
}
echo implode('&nbsp;', $actions);

?>
</div>
</div>
</form>
<?php

$content = ob_get_contents();

ob_end_clean();

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

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

?>