<?php
require_once(dirname(__FILE__).'/../functions.php');
if (!defined('DB_HTML_EDIT')) define('DB_HTML_EDIT','Edit');
+if (!defined('DB_HTML_NAV_TOP')) define('DB_HTML_NAV_TOP','<div align="center" class="nav" id="nav_top"></div>'.PHP_EOL);
class table {
public $name;
function nav($count,$tot,$limit) {
+ $html = '';
if ($count<$tot) {
list($x,$y) = strpos($limit,',')!==false
? preg_split('/\s*,\s*/',$limit)
$next = 999999;
}
- echo '<div align="center" class="nav" id="nav_bottom">';
+ $html .= '<div align="center" class="nav" id="nav_bottom">';
- if ($prev>=0) echo '<span class="prev"><a href="'.$this->url_params('limit',preg_replace('/^0,/','',"$prev,$y")).'"><<</a></span> ';
+ if ($prev>=0) $html .= '<span class="prev"><a href="'.$this->url_params('limit',preg_replace('/^0,/','',"$prev,$y")).'"><<</a></span> ';
- echo '<span class="count">'.($tot ? ($x+1) : 0).' - '.($x+$y).' / '.$tot.' results</span>';
+ $html .= '<span class="count">'.($tot ? ($x+1) : 0).' - '.($x+$y).' / '.$tot.' results</span>';
- if ($next<$tot) echo ' <span class="prev"><a href="'.$this->url_params('limit',"$next,$y").'">>></a></span>';
+ if ($next<$tot) $html .= ' <span class="prev"><a href="'.$this->url_params('limit',"$next,$y").'">>></a></span>';
- echo '</div>'.PHP_EOL;
+ $html .= '</div>'.PHP_EOL;
static $js = null;
if ($js === null) {
- echo '<script type="text/javascript"><!-- '.PHP_EOL
+ $html .= '<script type="text/javascript"><!-- '.PHP_EOL
."var rb = document.getElementById('nav_bottom'); var rt = document.getElementById('nav_top'); if (rb && rt) rt.innerHTML = rb.innerHTML;\n"
. ' --></script>'.PHP_EOL
;
$js = '1';
}
+ return $html;
+
}
function form_criterias($opt=array()) {
$format = (!empty($opt['format']) ? $opt['format'] : 'table');
if (!@$opt['is_html']) $opt['is_html'] = preg_match('/^(table)$/',$format) ? true : false;
- if ($opt['is_html']) echo '<div align="center" class="nav" id="nav_top"></div>'.PHP_EOL;
$escape = preg_match('/^(table|row|xml)$/',$format) ? true : false;
if (preg_match('/^(1)?$/',$this->db->p('header'))) echo $this->{"rows_begin_$format"}($opt);
}
$count_fields++;
- /* only if in latin1
- if ($this->db->p('format') == 'csv') {
- $row[$f] = utf8_encode($row[$f]);
- } elseif ($spec['extra']) {
- $row[$f] = htmlentities($row[$f]);
-
- }
- */
}
- #debug($this->url_edit($row));
- if ($format == 'table') array_unshift($row,'<a class="edit button" href="'.$this->url_edit($row,'&').'">'.DB_HTML_EDIT.'</a>');
+ if ($opt['is_html']) array_unshift($row,'<a class="edit button" href="'.$this->url_edit($row,'&').'">'.DB_HTML_EDIT.'</a>');
echo $this->{"rows_rec_$format"}($row);
}
+ $opt['count'] = $count;
+ $opt['tot'] = $tot;
+ $opt['limit'] = $limit;
echo $this->{"rows_end_$format"}($opt);
- if ($opt['is_html']) echo $this->nav($count,$tot,$limit);
$st->closeCursor();
-----------------------------------------------------------------*/
function rows_begin_json() {
$this->_row_json = null;
- echo '['.PHP_EOL;
+ return '['.PHP_EOL;
}
function rows_rec_json($row) {
+ $json = '';
if ($this->_row_json === null) {
$this->_row_json = true;
} else {
- echo ',';
+ $json .= ',';
}
- echo json_encode($row).PHP_EOL;
+ return $json . json_encode($row).PHP_EOL;
}
function rows_end_json() {
unset($this->_row_json);
- echo ']'.PHP_EOL;
+ return ']'.PHP_EOL;
}
/*-----------------------------------------------------------------
Yaml
-----------------------------------------------------------------*/
function rows_begin_yaml() {
- echo "---\n";
+ return "---\n";
}
function rows_rec_yaml($row) {
$yaml = preg_replace('/^---\n/','',$yaml);
$yaml = preg_replace('/\n\.\.\.$/','',$yaml);
$yaml = preg_replace('/^/m',' ',$yaml);
- echo '- '.trim($yaml)."\n";
+ return '- '.trim($yaml)."\n";
}
function rows_end_yaml() {
- echo '';
+ return '';
}
/*-----------------------------------------------------------------
Xml
-----------------------------------------------------------------*/
function rows_begin_xml() {
- echo ''
+ return ''
.'<?xml version=“1.0” encoding=“utf-8”?>'.PHP_EOL
.'<db name="'.$this->db->name.'" table="'.$this->name.'" type="'.$this->db->type.'">'.PHP_EOL
;
}
function rows_rec_xml($row) {
- echo "\t<".$this->name.">".PHP_EOL;
+ $xml = '';
+ $xml .= "\t<rows>".PHP_EOL;
foreach (array_keys($this->fields()) as $f) {
- if ($row[$f] !== '') echo ''
+ if ($row[$f] !== '') $xml .= ''
. "\t\t<".$f.'>'
.'<![CDATA['.$row[$f].']]>'
. '</'.$f.'>'
.PHP_EOL;
}
- echo "\t</".$this->name.">".PHP_EOL;
+ $xml .= "\t</rows>".PHP_EOL;
+ return $xml;
}
function rows_end_xml() {
- #echo '</'.$this->name.'>'.PHP_EOL;
- echo '</db>'.PHP_EOL;
+ return '</db>'.PHP_EOL;
}
/*-----------------------------------------------------------------
Csv
-----------------------------------------------------------------*/
function rows_begin_csv() {
- echo join("\t",array_keys($this->fields()))."\n";
+ return join("\t",array_keys($this->fields()))."\n";
}
function rows_rec_csv($row) {
- echo join("\t",array_values($row))."\n";
+ return join("\t",array_values($row))."\n";
}
function rows_end_csv() {
+ return $this->nav($opt['count'],$opt['tot'],$opt['limit']);
+ return '';
}
/*-----------------------------------------------------------------
// NB 14.04.14 function rows_begin_table($opt=array()) {
function rows_begin_table() {
- echo '<table class="'.$this->name.' rows border">'.PHP_EOL;
+ $html = '';
+ $html .= '<table class="'.$this->name.' rows border">'.PHP_EOL;
+
+ if (DB_HTML_NAV_TOP) $html .= '<thead><tr>'
+ . '<td colspan="'.(count($this->fields())+1).'">' . DB_HTML_NAV_TOP . '</td>'
+ . '</tr></thead>'.PHP_EOL
+ ;
- echo '<tr class="'.$this->name.' row bold">';
- echo '<th class="'.DB_HTML_EDIT.'"></th>';
+ $html .= '<tr class="'.$this->name.' row bold">';
+ $html .= '<th class="'.DB_HTML_EDIT.'"></th>';
foreach (array_keys($this->fields()) as $f) {
- echo '<th class="'.$f.'">'.$this->url_sort($f).'</th>';
+ $html .= '<th class="'.$f.'">'.$this->url_sort($f).'</th>';
}
- echo '</tr>'.PHP_EOL;
+ $html .= '</tr>'.PHP_EOL.'<tbody>'.PHP_EOL;
+
+ return $html;
}
function rows_rec_table($row) {
- echo '<tr>';
+ $html = '<tr>';
foreach ($row as $k => $v) {
- echo '<td class="'.$k.'">'.$v.'</td>';
+ $html .= '<td class="'.$k.'">'.$v.'</td>';
}
- echo '</tr>'.PHP_EOL;
+ $html .= '</tr>'.PHP_EOL;
+
+ return $html;
}
- function rows_end_table() {
- echo '</table>'.PHP_EOL;
+ function rows_end_table($opt=array()) {
+ $html = PHP_EOL.'</tbody>'.PHP_EOL;
+
+ if (!empty($opt['count'])) $html .= '<tfoot><tr>'
+ . '<td colspan="'.(count($this->fields())+1).'">'
+ . $this->nav($opt['count'],$opt['tot'],$opt['limit'])
+ . '</td>'
+ . '</tr></tfoot>'.PHP_EOL
+ ;
+
+ $html .= '</table>'.PHP_EOL;
+ return $html;
}
/*-----------------------------------------------------------------
Html Div
-----------------------------------------------------------------*/
function rows_begin_div() {
- echo '<div class="'.$this->name.' rows">'.PHP_EOL;
+ return '<div class="'.$this->name.' rows">'.DB_HTML_NAV_TOP.PHP_EOL;
}
function rows_rec_div($row) {
- echo '<ul class="border rad bgcolor">';
+ $html = '';
+ $html .= '<ul class="border rad bgcolor">';
foreach ($row as $k => $v) {
- echo '<li>'
+ $html .= '<li>'
.'<span class="k">'.$k.'</span>'
.': '
.'<span class="v">'.$v.'</span>'
.'</li>';
}
- echo '</ul>'.PHP_EOL;
+ $html .= '</ul>'.PHP_EOL;
+ return $html;
}
function rows_end_div() {