//
// $Id$
+function printfl()
+{
+ $args = func_get_args();
+ $args[0] .= "\n";
+ call_user_func_array('printf', $args);
+}
+
/**
* Listador genérico de ítems. Usa las variables de GET lista_from.
*/
-function listar($item, $summary = null, $caption = null, $cant = 15, $link = '')
+function listar($item, $link = '', $summary = null, $caption = null, $cant = 15)
{
if (!$summary) $summary = 'Listado de ' . get_class($item) . 's';
- printf('<table border="1" summary="%s">\n', $summary);
- if ($caption) printf(' <caption>%s</caption>\n', $caption);
- printf(' <thead>\n');
- printf(' <tr>\n');
+ printfl('<table border="1" summary="%s">', $summary);
+ if ($caption) printfl(' <caption>%s</caption>', $caption);
+ printfl(' <thead>');
+ printfl(' <tr>');
foreach ($item->getHeaderArray() as $header)
- printf(' <th>%s</th>\n', $header);
- printf(' </tr>\n');
- printf(' </thead>\n');
- printf(' <tbody>\n');
+ printfl(' <th>%s</th>', $header);
+ printfl(' </tr>');
+ printfl(' </thead>');
+ printfl(' <tbody>');
$total = $item->getTotal();
$from = intval(@$_GET["lista_from"]);
$c = min($total - $from, $cant);
$item->seek($from);
while ($item->next() and $c--)
{
- printf(' <tr>\n');
- foreach ($item->asArray() as $i) printf(' <td>%s</td>\n', $i);
- printf(' </tr>\n');
+ printfl(' <tr>');
+ foreach ($item->asArray() as $i) printfl(' <td>%s</td>', $i);
+ printfl(' </tr>');
}
- printf(' </tbody>\n');
- printf('</table>\n');
- printf('<table summary="Paginador" border="0"><tr>\n');
+ printfl(' </tbody>');
+ printfl('</table>');
+ printfl('<table summary="Paginador" border="0"><tr>');
$pags = ceil($total / $cant);
+ if ($pags == 1) return; // Si tengo una sóla página, para qué el paginador?
for ($i = 0; $i < $pags; ++$i)
{
- printf('<td><a href="%s?lista_from=%d">%s</a></td>\n', $link, $i * $cant, $i + 1);
+ printfl('<td><a href="%s?lista_from=%d">%s</a></td>', $link, $i * $cant, $i + 1);
}
- printf('</tr></table>\n');
+ printfl('</tr></table>');
}
?>
\ No newline at end of file