<div style="clear: both; height: 6px;"></div>

        <div style="width: 100%; background-color: black; color: white; height: 20px; font-weight: bold; font-size: 12px; text-align: right; padding-top: 10px;">
        &nbsp;&nbsp;
        </div>
        
        <ul style="PADDING-RIGHT: 0px; PADDING-LEFT: 4px; FLOAT: left; PADDING-BOTTOM: 0px; MARGIN: 15px 0px; WIDTH: 100%; PADDING-TOP: 0px; LIST-STYLE-TYPE: none;">
          <?php 
/*$ruta=sfContext::getInstance()->getUser()->getAttribute('ruta_legedia',null);*/
$ruta = UsuarioPeer::getRuta();
$i = 1;
foreach ($tablas as $tabla) {
    $c = new Criteria();
    $c->addAnd(FormularioPeer::ID_TABLA, $tabla->getIdTabla(), Criteria::EQUAL);
    $c->addDescendingOrderByColumn(FormularioPeer::FECHA);
    $formularios = FormularioPeer::doSelect($c);
    if (sizeof($formularios) > 0) {
        $ult_mod = format_date($formularios[0]->getFecha(), "d");
    } else {
        $ult_mod = "-";
    }
    if ($i % 2 == 0) {
        $textalign = "right";
    } else {
        $textalign = "left";
    }
    echo '<li style=\'PADDING-RIGHT: 4px; DISPLAY: inline; PADDING-LEFT: 4px; FLOAT: left; PADDING-BOTTOM: 4px; WIDTH: 48%; PADDING-TOP: 4px; text-align:' . $textalign . '\'>';
    echo '<a href="' . $ruta . '/formularios/create/?id_tabla=' . $tabla->getIdTabla() . '" style=\'text-decoration: none; font-weight: bold; font-size: 12px\'><!--class="clientes" ' . __('AƱadir registro a ') . '-->' . strtoupper($tabla->getNombre()) . '</a>';
    echo '<br /><a href="' . $ruta . '/formularios/list/?filters[id_empresa]=' . $id_empresa_sel . '&filters[id_tabla]=' . $tabla->getIdTabla() . '&filter=filter" style=\'text-decoration: none; \' >' . (sizeof($formularios) . __(' registros')) . '</a> <br /> Ult. Mod: ' . $ult_mod;
    echo '</li>';
    $i++;
 /**
  * Retrieve multiple objects by pkey.
  *
  * @param      array $pks List of primary keys
  * @param      PropelPDO $con the connection to use
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function retrieveByPKs($pks, PropelPDO $con = null)
 {
     if ($con === null) {
         $con = Propel::getConnection(FormularioPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria(FormularioPeer::DATABASE_NAME);
         $criteria->add(FormularioPeer::ID_FORMULARIO, $pks, Criteria::IN);
         $objs = FormularioPeer::doSelect($criteria, $con);
     }
     return $objs;
 }
 /**
  * Gets an array of Formulario objects which contain a foreign key that references this object.
  *
  * If this collection has already been initialized with an identical Criteria, it returns the collection.
  * Otherwise if this Usuario has previously been saved, it will retrieve
  * related FormulariosRelatedByIdUsuarioCreador from storage. If this Usuario is new, it will return
  * an empty collection or the current collection, the criteria is ignored on a new object.
  *
  * @param      PropelPDO $con
  * @param      Criteria $criteria
  * @return     array Formulario[]
  * @throws     PropelException
  */
 public function getFormulariosRelatedByIdUsuarioCreador($criteria = null, PropelPDO $con = null)
 {
     if ($criteria === null) {
         $criteria = new Criteria(UsuarioPeer::DATABASE_NAME);
     } elseif ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
     }
     if ($this->collFormulariosRelatedByIdUsuarioCreador === null) {
         if ($this->isNew()) {
             $this->collFormulariosRelatedByIdUsuarioCreador = array();
         } else {
             $criteria->add(FormularioPeer::ID_USUARIO_CREADOR, $this->id_usuario);
             FormularioPeer::addSelectColumns($criteria);
             $this->collFormulariosRelatedByIdUsuarioCreador = FormularioPeer::doSelect($criteria, $con);
         }
     } else {
         // criteria has no effect for a new object
         if (!$this->isNew()) {
             // the following code is to determine if a new query is
             // called for.  If the criteria is the same as the last
             // one, just return the collection.
             $criteria->add(FormularioPeer::ID_USUARIO_CREADOR, $this->id_usuario);
             FormularioPeer::addSelectColumns($criteria);
             if (!isset($this->lastFormularioRelatedByIdUsuarioCreadorCriteria) || !$this->lastFormularioRelatedByIdUsuarioCreadorCriteria->equals($criteria)) {
                 $this->collFormulariosRelatedByIdUsuarioCreador = FormularioPeer::doSelect($criteria, $con);
             }
         }
     }
     $this->lastFormularioRelatedByIdUsuarioCreadorCriteria = $criteria;
     return $this->collFormulariosRelatedByIdUsuarioCreador;
 }
 public function executeExcel()
 {
     $formato = $this->getRequestParameter("formato", "CSV");
     $this->filters = $this->getUser()->getAttributeHolder()->getAll('sf/formulario/filters');
     $c = $this->getCriterio();
     $this->addFiltersCriteria($c);
     $this->addSortCriteria($c);
     $c->setDistinct();
     $datos = FormularioPeer::doSelect($c);
     foreach ($datos as $formulario) {
         break;
     }
     if (!isset($formulario)) {
         $id_tabla = isset($this->filters['id_tabla']) ? $this->filters['id_tabla'] : null;
         if (isset($id_tabla) && $id_tabla != '') {
             $tabla = TablaPeer::retrievebypk($id_tabla);
             $formulario = $tabla->getFormulario();
         } else {
             $formulario = new Formulario();
         }
     }
     $nombre_archivo_tmp = tempnam(sfConfig::get('app_directorio_tmp'), "datos_");
     rename($nombre_archivo_tmp, $nombre_archivo_tmp . ".xls");
     $nombre_archivo = $nombre_archivo_tmp . ".xls";
     error_reporting(E_ALL);
     $libro_campania = new Spreadsheet_Excel_Writer($nombre_archivo);
     $cabecera =& $libro_campania->addFormat();
     //
     $cabecera->setBold();
     $titulo =& $libro_campania->addFormat();
     //
     $titulo->setBold();
     $titulo->setSize(15);
     if ($formulario->getTabla()) {
         $nombre_hoja = utf8_decode($formulario->getTabla()->getNombreyEmpresa());
     } else {
         $nombre_hoja = utf8_decode("--");
     }
     $hoja =& $libro_campania->addWorksheet($nombre_hoja);
     $hoja->writeString(0, 0, "Registros de " . $nombre_hoja, $titulo);
     $lista_campos_extra = $formulario->getTabla()->getCamposFormularioOrdenados();
     //CABECERA
     $fila = 1;
     $col = 0;
     foreach ($lista_campos_extra as $campo) {
         if (!$campo->getBorrado()) {
             if ($campo->esTipoLista()) {
                 $campo_txt = "id_item_base";
             }
             if ($campo->esTipoTextoCorto()) {
                 $campo_txt = "texto_corto";
             }
             if ($campo->esTipoTextoLargo()) {
                 $campo_txt = "texto_largo";
             }
             if ($campo->esTipoNumero()) {
                 $campo_txt = "numero";
             }
             if ($campo->esTipoFecha()) {
                 $campo_txt = "fecha";
             }
             if ($campo->esTipoBooleano()) {
                 $campo_txt = "si_no";
             }
             if ($campo->esTipoSelectPeriodo()) {
                 $campo_txt = "id_item_base";
             }
             if ($campo->esTipoTabla()) {
                 $campo_txt = "numero";
             }
             if ($campo->esTipoObjeto()) {
                 $campo_txt = "numero";
             }
             $hoja->writeString($fila, $col, $campo->__toString(), $cabecera);
             $col++;
         }
     }
     //FILAS
     foreach ($datos as $formulario) {
         $col = 0;
         $fila++;
         $items_formulario = $formulario->getArrayItems();
         foreach ($lista_campos_extra as $campo) {
             if (!$campo->getBorrado()) {
                 if (!$campo->esTipoLista()) {
                     $item_base = $campo->getElementoUnico();
                     $item = isset($items_formulario[$item_base->getIdItemBase()]) ? $items_formulario[$item_base->getIdItemBase()] : null;
                 } else {
                     $item = null;
                     $lista = $campo->getItemBases();
                     foreach ($lista as $ib) {
                         if (isset($items_formulario[$ib->getIdItemBase()])) {
                             $item = $items_formulario[$ib->getIdItemBase()];
                             break;
                         }
                     }
                 }
                 if ($item) {
                     $hoja->write($fila, $col, utf8_decode($item->__toString(true)));
                 }
                 $col++;
             }
         }
     }
     $libro_campania->send("Registros de " . $nombre_hoja . ".xls");
     //cabeceras HTTP
     $libro_campania->close();
     $gestor = fopen($nombre_archivo, "rb");
     fpassthru($gestor);
     fclose($gestor);
     @unlink($nombre_archivo);
     exit;
 }