<?php $this->loadCss('/admin/media/css/dtree.css'); ?>
<?php $this->loadJavascript('/admin/media/js/dtree.js'); ?>

<div id="accoes_bg" style="z-index:1;">
    <div id="titulo_accao" style="z-index:1;">
        <?php if (isset($section_title)): ?>
        <?php echo translateAdmin('Listagem de'); ?> <?php echo $section_title; ?>
        <?php endif; ?>
    </div>
    
    <div id="pesquisa" style="z-index:1;">
    <div class="pesquisaLeft"></div>
    <div class="pesquisaForm">
        <?php echo $form_search->start(); ?>
		<?php echo $form_search->search->input; ?>
        <?php echo $form_search->submit->input; ?>
        <?php echo $form_search->end(); ?>
    </div>
    <div class="pesquisaRight"></div>
    </div>
    
</div>

<script type="text/javascript">
<!--
var selection = false;

function invert() {
    if ( selection == false ) {
        selection = true; 
    } else {
        selection = false;
    }

    for (var i=0; i<document.deleteList.elements.length; i++) {
        var e = document.deleteList.elements[i];
        if ( selection == true ) {
            e.checked = true;
        } else {
            e.checked = false; 
        }
    }
}

function clean() {
    selection = false;
    document.deleteList.selectAll.checked = false;
}
-->
</script>
<div id="conteudo">
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <?php if (isset($tree)): ?>
    <td rowspan="2" valign="top" id="tr_tree">
        <div id="tree">
            <?php echo $tree->getTitle(); ?> | <a href="<?php echo $tree->openAllLink(); ?>"><?php echo translateAdmin('Expandir tudo');?></a> | <a href="<?php echo $tree->closeAllLink(); ?>"><?php echo translateAdmin('Fechar tudo');?></a><?php echo $this->br(); ?><?php echo $this->br(); ?>
            <?php echo $tree->render(); ?>
        </div>
    </td>
    <?php endif; ?>
    <td height="320" valign="top" id="manutencaodisplay">
        <div class="acessibilidade">
        
        <span>
	
            <?php if ($links['add'] != '' && !is_null($links['add'])): ?>
            <input type="button" id="inserir_top" name="inserir" class="form_inserir" value="<?php echo translateAdmin('Inserir');?>" onclick="location='<?php echo $this->link($links['add']); ?>';" />
            <?php endif; ?>
  
            <?php  if (!is_null($links['excel']) && $links['excel'] != ''): ?>
            <input type="button" id="excel_top_csv" name="excel_csv" class="form_exportar" title="csv" value="<?php echo translateAdmin('Exportar');?>" onclick="location='<?php echo $this->link($links['list'].'export/csv/'); ?>';" />
            <input type="button" id="excel_top_xls" name="excel_xls" class="form_exportar_xls" title="xls" value="<?php echo translateAdmin('Exportar');?>" onclick="location='<?php echo $this->link($links['list'].'export/xls/'); ?>';" />
            <input type="button" id="excel_top_xlsx" name="excel_xlsx" class="form_exportar_xlsx" title="xlsx" value="<?php echo translateAdmin('Exportar');?>" onclick="location='<?php echo $this->link($links['list'].'export/xlsx/'); ?>';" />
            <?php endif; ?>

            <?php if (isset($links['import'])) : ?>
            <input type="button" id="importar" name="importar" class="form_importar" value="<?php echo translateAdmin('Importar');?>" onClick="location='<?php echo $this->link($links['import']); ?>';">
            <?php endif; ?>
        </span>
        
        </div>
        <br style="clear:both;" />
        <?php if ($rowset): ?>
      	<form name="deleteList" id="deleteList" action="<?php echo $this->link($links['deletelist'], "page={$page}"); ?>" method="post">
		<table border="1" align="center" cellspacing="0" width="98%">
        <thead>
         <tr>
            <?php if (!is_null($links['deletelist'])): ?>
            <th class="actions" style="width:20px; text-align:center; white-space:nowrap;">
               <input type="checkbox" name="selectAll" id="selectAll" onclick="invert();" style="padding:0; margin:0;" class="checkbox" />
            </th>
            <?php endif; ?>
            <?php foreach($cols as $col): ?>
                <?php if ($ordering == $col): ?>
                    <?php if ($sorting == 'desc'): ?>
                        <th class="sorted" style="padding-left:5px; white-space:nowrap;"><a href="<?php echo $this->link($links['list'], "ordering=$col&sorting=asc"); ?>" class="asc"><?php echo $labels[$col]; ?></a></th>
                    <?php else: ?>
                        <th class="sorted" style="padding-left:5px; white-space:nowrap;"><a href="<?php echo $this->link($links['list'], "ordering=$col&sorting=desc"); ?>" class="desc"><?php echo $labels[$col]; ?></a></th>
                    <?php endif; ?>
                <?php else: ?>
                    <th class="labellist" style="padding-left:5px; white-space:nowrap;"><a href="<?php echo $this->link($links['list'], "ordering=$col&sorting=desc"); ?>"><?php echo $labels[$col]; ?></a></th>
                <?php endif; ?>
            <?php endforeach; ?>
            <?php if (!is_null($links['delete']) || (isset($list_actions) && is_array($list_actions) && count($list_actions) > 0)): ?>
            <th class="actions"><?php echo translateAdmin('Ac&ccedil;&otilde;es');?></th>
            <?php endif; ?>
         </tr>         
      	</thead>
      <tbody>
         <?php
         $cycle = $this->cycle('row1', 'row2', 'row3');
         $i = 0; // alteracao - Thiago Brito
         ?>
         <?php foreach($rowset as $row): ?>
            <?php
            // alteracao - Thiago Brito - para colocar onmouseover e onmouseout nas linhas //
            $i++;
            $currentClass = "";
            $currentClass = $cycle->getCurrent();
            if (!isset($cant_edit) || (is_array($cant_edit) && !in_array($row->id, $cant_edit))){
                $on_click = "location='" . $this->link($links['edit'] . $row->{$primary} . "/", "page={$page}") . "';";
            } else {
                $on_click = "alert('" . translateAdmin("Este elemento n&atilde;o poder editado!!")."');";
            }
            $on_over  = "$('line_" . $i . "').className='" . $cycle->getOverValue() . "';";
            $on_out   = "$('line_" . $i . "').className='" . $currentClass . "';";
            //
            // altera&ccedil;&atilde;o - Thiago Brito - para colocar onmouseover e onmouseout nas linhas //
            ?>
            <tr id="line_<?php echo $i; ?>" class="<?php echo $currentClass; ?>">
                <?php if (!is_null($links['deletelist'])): ?>
                <td align="center" style="width:20px; text-align:center;">
                <?php if (!isset($cant_delete) || (is_array($cant_delete) && !in_array($row->id, $cant_delete))):?>
                <input type="checkbox" name="ids[]" value="<?php echo $row->id; ?>" style="padding:0; margin:0;" class="checkbox" />
                <?php else:?>
                &nbsp;
                <?php endif;?>
                </td>
                <?php endif; ?>
                <?php foreach($cols as $col): ?>
                    <?php if ($col == $to_string): ?>        
                        <td onmouseover="<?php echo $on_over; ?>" onmouseout="<?php echo $on_out; ?>" style="cursor:pointer;" onclick="<?php echo $on_click; ?>"><?php echo $row->{$col}; ?></td>
                    <?php elseif (array_key_exists($col, $modelCols) && $modelCols[$col]->getType() == 'Boolean'): ?>
                        <td onmouseover="<?php echo $on_over; ?>" onmouseout="<?php echo $on_out; ?>" style="cursor:pointer;" onclick="<?php echo $on_click; ?>" align="center"><?php echo $this->img('/admin/media/images/icon_' . (($row->{$col} == '1') ? 'true' : 'false') . '.gif', array('border' => 0));?></td>
                    <?php elseif (array_key_exists($col, $modelCols) && $modelCols[$col]->getType() == 'Image' && $row->{$col}): ?>
                        <td onmouseover="<?php echo $on_over; ?>" onmouseout="<?php echo $on_out; ?>" style="cursor:pointer;" onclick="<?php echo $on_click; ?>">
                        <?php $sizes = $modelCols[$col]->getParam('sizes')?>
                        <?php $size = current($sizes)?>
                        <?php if (!$size) $size = 'small';?>
                        <?php echo $this->img($modelCols[$col]->getParam('target') . '/' . $size . '_' . $row->{$col});?></td>
                        </td>
                    <?php elseif (array_key_exists($col, $modelCols) && $modelCols[$col]->getType() == 'ColorPicker' && $row->{$col}): ?>
                    	<td onmouseover="<?php echo $on_over; ?>" onmouseout="<?php echo $on_out; ?>" style="cursor:pointer;" onclick="<?php echo $on_click; ?>">
                    	<div style="background-color: <?php echo $row->{$col}?>; width: 100%; height: 20px;"></div>
                    	</td>
                    <?php else: ?>
                        <td onmouseover="<?php echo $on_over; ?>" onmouseout="<?php echo $on_out; ?>" style="cursor:pointer;" onclick="<?php echo $on_click; ?>"><?php echo $row->{$col}; ?></td>
                    <?php endif; ?>
                <?php endforeach; ?>
                <?php if (!is_null($links['delete']) || (isset($list_actions) && is_array($list_actions) && count($list_actions) > 0)): ?>
                <td onmouseover="<?php echo $on_over; ?>" onmouseout="<?php echo $on_out; ?>" align="center">
                <?php if (isset($list_actions) && is_array($list_actions) && count($list_actions) > 0): ?>
                <?php foreach ($list_actions as $list_action):?>
                <a href="<?php echo $this->link($list_action['link'] . $row->{$primary} . '/', "page={$page}"); ?>"><?php echo $this->img($list_action['img'], array('alt' => translateAdmin($list_action['alt']), 'border' => 0))?></a>
                <?php endforeach;?>
                <?php endif;?>
                <?php if (!is_null($links['delete']) && (!isset($cant_delete) || (is_array($cant_delete) && !in_array($row->id, $cant_delete)))): ?>
                <a href="<?php echo $this->link($links['delete'] . $row->{$primary} . '/', "page={$page}"); ?>" class="deletelink" onclick="javascript:return confirm('<?php echo translateAdmin('Tem a certeza que deseja remover o item seleccionado');?>?');"><?php echo $this->img('/admin/media/images/icon_trash.gif', array('alt' => translateAdmin('Remover'), 'border' => 0))?></a>
                <?php endif; ?>
                </td>
                <?php endif; ?>
         </tr>
         <?php endforeach; ?>
         <?php if (!is_null($links['deletelist'])): ?>
         <tr>
            <td colspan="<?php echo (count($cols) + 2); ?>">
               <a href="#" class="deletelink" onclick="javascript:questionSubmitForm('deleteList', '<?php echo translateAdmin('Tem a certeza que deseja remover os itens seleccionados');?>?');"><?php echo translateAdmin('Remover itens seleccionados');?></a>
            </td>
         </tr>
         <?php endif; ?>    
      </tbody>
   		</table> 
      </form>
      <?php endif; ?>
    </td>
  </tr>
  <tr>
    <td valign="top"><?php echo $this->br(); ?>
        <div class="acessibilidade" style="z-index:1;">
            <span>
                <?php if ($links['add'] != '' && !is_null($links['add'])): ?>
                <input type="button" id="inserir_bottom" name="inserir" class="form_inserir" value="<?php echo translateAdmin('Inserir');?>" onclick="location='<?php echo $this->link($links['add']); ?>';" />
                <?php endif; ?>
  
                <?php  if (!is_null($links['excel']) && $links['excel'] != ''): ?>
                <input type="button" id="excel_top_csv2" name="excel_csv" class="form_exportar" title="csv" value="<?php echo translateAdmin('Exportar');?>" onclick="location='<?php echo $this->link($links['list'].'export/csv/'); ?>';" />
                <input type="button" id="excel_top_xls2" name="excel_xls" class="form_exportar_xls" title="xls" value="<?php echo translateAdmin('Exportar');?>" onclick="location='<?php echo $this->link($links['list'].'export/xls/'); ?>';" />
                <input type="button" id="excel_top_xlsx2" name="excel_xlsx" class="form_exportar_xlsx" title="xlsx" value="<?php echo translateAdmin('Exportar');?>" onclick="location='<?php echo $this->link($links['list'].'export/xlsx/'); ?>';" />
                <?php endif; ?>
            </span>
        </div>
        <div class="paginator"><?php echo $paginator_output; ?></div>
    </td>
  </tr>
</table>
</div>