<?php $this->loadCss('/admin/media/css/calendar.css'); ?>
<?php $this->loadJavascript('/admin/media/js/jscalendar/calendar.js'); ?>
<?php $this->loadJavascript('/admin/media/js/jscalendar/calendar-setup.js'); ?>
<?php $this->loadJavascript('/admin/media/js/jscalendar/lang/calendar-pt.js'); ?>
<?php $this->loadCss('/admin/media/css/dtree.css'); ?>
<?php $this->loadJavascript('/admin/media/js/dtree.js'); ?>
<?php $this->loadJavascript('/admin/media/js/ajax.js'); ?>

<div id="accoes_bg">
    <div id="titulo_accao"><?php echo $action; ?> <?php echo translateAdmin('de');?> <?php echo $section_singular; ?></div>
</div>

<div id="conteudo">
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <?php if (isset($tree)) : ?>
    <td valign="top" id="tr_tree">
        <div id="tree">
            <p><?php echo translateAdmin('P&aacute;ginas') ?> | <a href="<?php echo $tree->openAllLink(); ?>"><?php echo translateAdmin('Expandir tudo');?></a> | <a href="<?php echo $tree->closeAllLink(); ?>"><?php echo translateAdmin('Fechar tudo');?></a></p>
            <?php echo $tree->render(); ?>
        </div>
    </td>
    <?php $align = "left"; ?>
    <?php else: ?>
    <?php $align = "center"; ?>
    <?php endif; ?>
    <td align="center" valign="top" id="manutencaodisplay">
        <?php echo $form->start(); ?>
        <div class="acessibilidade">
        	<span>
            <?php if (isset($delete_link)) : ?>
            <input type="button" id="delete_link" name="delete_link" value="<?php echo translateAdmin('Remover');?>" class="form_delete" onclick="if (confirm('<?php echo translateAdmin('Tem a certeza que deseja remover o item seleccionado');?>?')) { location='<?php echo $this->link($delete_link); ?>'; } "/>
            <?php endif; ?>
            <?php echo $form->submit_and_new->input; ?>&nbsp;&nbsp;<?php echo $form->submit_and_continue->input; ?>&nbsp;&nbsp;<?php echo $form->submit->input; ?>
            </span>
        </div>
        <div id="rte">
        <table border="0" cellpadding="2">
            <?php foreach ($form->getElementsNames() as $element): ?>
            <?php if (in_array($element, array("promocao_fim", "promocao_inicio")) && $model->colExists('promocao_fim')) continue; ?>
                <?php if ($this->form->{$element}->type != 'tafeltree' && $form->{$element}->type != 'submit' && $form->{$element}->type != 'button' && $form->{$element}->type != 'hidden'): ?>
                <tr>
                    <?php if ($this->form->{$element}->type == 'rte'): ?>
                    <td colspan="2" align="left"><?php if ($form->{$element}->getErrorMessage()): ?>
                        <div class="error_message">
                        <?php echo $form->{$element}->getErrorMessage(); ?>
                        </div>
                        <?php endif; ?>
                        <?php echo $form->{$element}->input; ?>
                    </td>
                    <?php else: ?>
                    <td width="10%" nowrap="nowrap" bgcolor="#f0f0ee"><?php echo $form->{$element}->label; ?>:</td>
                    <td width="90%" bgcolor="#f0f0ee" align="left">
                        <?php if ($form->{$element}->getErrorMessage()): ?>
                        <div class="error_message">
                            <?php echo $form->{$element}->getErrorMessage(); ?>
                        </div>
                        <?php endif; ?>
                        
                        <?php if (is_array($form->{$element}->input)) : ?>
                            <?php foreach ($form->{$element}->input as $label => $input) : ?>
                            <?php echo $input; ?>&nbsp;<?php echo $label; ?><br />
                            <?php endforeach; ?>
                        <?php else: ?>
                        <?php if (isset($fieldsUpdate) && in_array($element, $fieldsUpdate)):?>
                        <div id="div_<?php echo $element?>">
                        <?php endif;?>
                        <?php if ($element == "promocao"): ?><div style="float:left; padding-right:10px;"><?php endif; ?>
                        <?php echo $form->{$element}->input; ?>
                        <?php if ($element == "promocao"): ?></div>
                         <div style="float:left; margin:-0.4em 0; display:none;" id="promocao_datas">
                            <div style="float:left; padding-right:10px;"><?php echo $form->promocao_inicio->label; ?>: <?php echo $form->promocao_inicio->input; ?></div>
                            <div style="float:left;"><?php echo $form->promocao_fim->label; ?>: <?php echo $form->promocao_fim->input; ?></div>
                         </div>
                    	<?php endif; ?>

                        <?php if ($form->elementExists($element . '_tafel')):?>
                        <?php 
                            goweb::loadJavascript('/admin/media/js/prototype.js');
                            goweb::loadJavascript('/admin/media/js/scriptaculous/scriptaculous.js');
                            goweb::loadJavascript('/admin/media/js/scriptaculous/effects.js');
                            goweb::loadJavascript('/admin/media/js/modalbox.js');
                            goweb::loadCss('/admin/media/css/modalbox.css');
                        ?>
                        <?php echo $form->{$element. '_tafel'}->input; ?>
                        <?php endif;?>
                        <?php if (isset($fieldsUpdate) && in_array($element, $fieldsUpdate)):?>
                        </div>
                        <?php endif;?>
                        <?php endif; ?>
                        
                        <?php if ($model->colExists($element) && $model->getCol($element)->getType() == 'Image' && $model->{$element}): ?>
                        <?php
                           $imagem = $model->{$element};
                           $uploadPath = WWW_PATH . $model->getCol($element)->getParam('target') . '/';
                           $sizes = $model->getCol($element)->getParam('sizes');
                           $tamanho = current($sizes);
                           if (!$tamanho) $tamanho = 'small';
                           $sizes = array_reverse($sizes);
                           foreach ($sizes as $size){
                               if (file_exists($uploadPath . $size . '_' . $imagem)) {
                                  $imageSize = getimagesize($uploadPath . $size . '_' . $imagem);
                                  $imagem = $size . '_' . $imagem;
                                  break 1;
                               }
                           }
                        ?>
                        <?php if (isset($imageSize)):?>
                        <?php if(!$model->getColParam($element, 'notnull')):?>
                        	<input type="checkbox" name="<?php echo $element; ?>_del" class="checkbox" />
                            <?php echo translateAdmin('Remover');?>
                        <?php endif;?>
                        <div style="padding-top:5px;">
                        <a href="" onclick="windowPopup('<?php echo $baseUrl . $model->getCol($element)->getParam('target'); ?>/<?php echo $imagem; ?>', 'Imagem', '<?php echo $imageSize[0] + 15; ?>', '<?php echo $imageSize[1] + 15; ?>'); return false;"><?php echo $this->img($model->getCol($element)->getParam('target') . '/' . $tamanho . '_' . $model->{$element}, array('border' => 0));?></a> </div>
                        <?php endif;?>
                        <?php elseif ($model->colExists($element) && $model->getCol($element)->getType() == 'File' && $model->{$element} && !$model->getColParam($element, 'notnull')): ?>
                        <div style="padding-top:5px;">
                        	<input type="checkbox" name="<?php echo $element; ?>_del"  class="checkbox"/><?php echo translateAdmin('&nbsp;Remover&nbsp;&nbsp;&nbsp;');?><a href="<?php echo $baseUrl . $model->getCol($element)->getParam('target'); ?>/<?php echo $model->{$element}; ?>" target="_blank">[ <?php echo translateAdmin('Ver ficheiro');?> ]</a>
                        </div>
                        <?php endif; ?>

                        <?php if ($form->{$element}->help): ?>
                        	<br /><label class="helper"><?php echo $form->{$element}->help; ?></label>
                        <?php endif; ?>
                    </td>
                    <?php endif; ?>
                </tr>
                <?php endif; ?>
                
                <?php if ((isset($combo)) && ($element == 'db_pass')) : ?>
                <tr>
                    <td align="left" bgcolor="#f0f0ee">&nbsp;</td>
                    <td align="left" bgcolor="#f0f0ee">
                    <div id="div_connection_test">
                        <?php echo $this->img('/media/images/icon_warning.png');?>&nbsp;<a href="javascript:testarConexao($('db_type'), $('db_host'), $('db_user'), $('db_pass'));" style="color:#666666;"><?php echo translateAdmin('Testar Conex&atilde;o');?></a>
                    </div>
                    </td>
                </tr>
                <?php endif; ?>
                
            <?php endforeach; ?>
           <?php if ($ficha): ?>
           <?php foreach ($ficha->getElementsNames() as $element): ?>
           <tr>
              <td width="10%" nowrap="nowrap" bgcolor="#f0f0ee"><?php echo $ficha->{$element}->label; ?>:</td>
              <td width="90%" bgcolor="#f0f0ee" align="left">
                 <?php if ($ficha->{$element}->getErrorMessage()): ?>
                 <div class="error_message">
                    <?php echo $ficha->{$element}->getErrorMessage(); ?>
                 </div>
                 <?php endif; ?>
                        
                 <?php if (is_array($ficha->{$element}->input)) : ?>
                    <?php foreach ($ficha->{$element}->input as $label => $input) : ?>
                    <?php echo $input; ?>&nbsp;<?php echo $label; ?><br />
                    <?php endforeach; ?>
                 <?php else: ?>
                    <?php echo $ficha->{$element}->input; ?>
                 <?php endif; ?>
                    <?php if (isset($fichaModel) && $fichaModel->colExists($element) && $fichaModel->getCol($element)->getType() == 'Image' && $fichaModel->{$element}): ?>
                        <?php
                           $imagem = $fichaModel->{$element};
                           $uploadPath = WWW_PATH . $fichaModel->getCol($element)->getParam('target') . '/';
                           $sizes = $fichaModel->getCol($element)->getParam('sizes');
                           $tamanho = current($sizes);
                           if (!$tamanho) $tamanho = 'small';
                           $sizes = array_reverse($sizes);
                           foreach ($sizes as $size){
                               if (file_exists($uploadPath . $size . '_' . $imagem)) {
                                  $imageSize = getimagesize($uploadPath . $size . '_' . $imagem);
                                  $imagem = $size . '_' . $imagem;
                                  break 1;
                               }
                           }
                        ?>
                        <?php if (isset($imageSize)):?>
                            <?php if(!$fichaModel->getColParam($element, 'notnull')):?>
                                <input type="checkbox" name="<?php echo $element; ?>_del" class="checkbox" />
                                <?php echo translateAdmin('Remover');?>
                            <?php endif;?>
                            <div style="padding-top:5px;">
                            <a href="" onclick="windowPopup('<?php echo $baseUrl . $fichaModel->getCol($element)->getParam('target'); ?>/<?php echo $imagem; ?>', 'Imagem', '<?php echo $imageSize[0] + 15; ?>', '<?php echo $imageSize[1] + 15; ?>'); return false;"><?php echo $this->img($fichaModel->getCol($element)->getParam('target') . '/' . $tamanho . '_' . $fichaModel->{$element}, array('border' => 0));?></a> </div>
                        <?php endif;?>
                    <?php elseif (isset($fichaModel) && $fichaModel->colExists($element) && $fichaModel->getCol($element)->getType() == 'File' && $fichaModel->{$element} && !$fichaModel->getColParam($element, 'notnull')): ?>
                        <div style="padding-top:5px;">
                            <input type="checkbox" name="<?php echo $element; ?>_del"  class="checkbox"/><?php echo translateAdmin('&nbsp;Remover&nbsp;&nbsp;&nbsp;');?><a href="<?php echo $baseUrl . $fichaModel->getCol($element)->getParam('target'); ?>/<?php echo $fichaModel->{$element}; ?>" target="_blank">[ <?php echo translateAdmin('Ver ficheiro');?> ]</a>
                        </div>
                    <?php endif; ?>
              </td>
              
           </tr>
           <?php endforeach; ?>
           <?php endif; ?>
        </table>
        <div align="right"></div>
        <br />
        <div class="acessibilidade">
        	<span>
            <?php if (isset($delete_link)) : ?>
            <input type="button" id="delete_link2" name="delete_link" value="<?php echo translateAdmin('Remover');?>" class="form_delete" onclick="if (confirm('<?php echo translateAdmin('Tem a certeza que deseja remover o item seleccionado');?>?')) { location='<?php echo $this->link($delete_link); ?>'; } "/>
            <?php endif; ?>
            <?php echo $form->submit_and_new->input; ?>&nbsp;&nbsp;<?php echo $form->submit_and_continue->input; ?>&nbsp;&nbsp;<?php echo $form->submit->input; ?>
            </span>
        </div>
        
        </div>
        <?php foreach ($form->getElementsNames() as $element): ?>
            <?php if ($form->{$element}->type == 'hidden'):?>
                <?php echo $form->{$element}->input; ?>
            <?php endif;?>
        <?php endforeach;?>
        <?php echo $form->getJsValidate()?>
        <?php if ($ficha):?>
        <?php echo $ficha->getJsValidate()?>
        <?php endif;?>
        <?php echo $form->end(); ?>
    </td>
  </tr>
</table>
</div>

<script type="text/javascript">
//<![CDATA[
if ($F('promocao') == '1') {
	new Effect.Grow('promocao_datas');
}

Event.observe('promocao', 'click', function(event) {
   if ($F('promocao') == '1') {
	   new Effect.Grow('promocao_datas');
   } else {
	   new Effect.Shrink('promocao_datas');
   }
});
//]]>
</script>
