[PHPVortex-Commit] phpvortex DB_Base.class.php,1.8,1.9 DB_PostgreSQL.class.php,1.1,1.2 FT_Base.class
Brought to you by:
nop144666
From: Thiago R. <nop...@us...> - 2005-09-29 20:23:26
|
Update of /cvsroot/phpvortex/phpvortex In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8777 Modified Files: DB_Base.class.php DB_PostgreSQL.class.php FT_Base.class.php FT_DateTime.class.php FT_Hidden.class.php FT_List.class.php FT_ListArray.class.php FT_Text.class.php RS_PostgreSQL.class.php SEC_Edit.class.php TB_Base.class.php Log Message: Added a Select function to DB_Base class, changed other classes to use it and fixed some assorted bugs. Index: FT_Text.class.php =================================================================== RCS file: /cvsroot/phpvortex/phpvortex/FT_Text.class.php,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** FT_Text.class.php 5 Oct 2004 19:35:09 -0000 1.4 --- FT_Text.class.php 29 Sep 2005 20:23:17 -0000 1.5 *************** *** 47,51 **** * @param string $value Value to load the control with. */ ! function ShowForm($value) { if ($this->rows > 1) { --- 47,51 ---- * @param string $value Value to load the control with. */ ! function ShowForm($value, $origin = FT_OR_DB) { if ($this->rows > 1) { *************** *** 61,65 **** * @param string $value Value to load the control with. */ ! function ShowPlain($value) { echo nl2br($value); --- 61,65 ---- * @param string $value Value to load the control with. */ ! function ShowPlain($value, $origin = FT_OR_DB) { echo nl2br($value); Index: FT_ListArray.class.php =================================================================== RCS file: /cvsroot/phpvortex/phpvortex/FT_ListArray.class.php,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** FT_ListArray.class.php 20 Oct 2004 20:10:18 -0000 1.1 --- FT_ListArray.class.php 29 Sep 2005 20:23:17 -0000 1.2 *************** *** 42,46 **** * @param string $value Value to load the control with. */ ! function ShowForm($value) { global $vortex_msgs; --- 42,46 ---- * @param string $value Value to load the control with. */ ! function ShowForm($value, $origin = FT_OR_DB) { global $vortex_msgs; *************** *** 59,63 **** * @param string $value Value to load the control with. */ ! function ShowPlain($value) { echo $this->list_array[$value]; --- 59,63 ---- * @param string $value Value to load the control with. */ ! function ShowPlain($value, $origin = FT_OR_DB) { echo $this->list_array[$value]; Index: FT_Base.class.php =================================================================== RCS file: /cvsroot/phpvortex/phpvortex/FT_Base.class.php,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** FT_Base.class.php 4 Oct 2004 21:13:08 -0000 1.9 --- FT_Base.class.php 29 Sep 2005 20:23:17 -0000 1.10 *************** *** 100,104 **** * @param bool $form Show field as a INPUT object? */ ! function Show(&$data, $form = TRUE) { if (empty($data) || !isset($data[$this->name_db])) { --- 100,104 ---- * @param bool $form Show field as a INPUT object? */ ! function Show(&$data, $form = TRUE, $origin = FT_OR_DB) { if (empty($data) || !isset($data[$this->name_db])) { *************** *** 109,117 **** if ($form) { echo "<tr class='ft_{$this->name}'><th>".$this->label.'</th><td>'; ! $this->ShowForm($value); echo "</td></tr>\n"; } else { echo $this->label.': '; ! $this->ShowPlain($value); } } --- 109,117 ---- if ($form) { echo "<tr class='ft_{$this->name}'><th>".$this->label.'</th><td>'; ! $this->ShowForm($value, $origin); echo "</td></tr>\n"; } else { echo $this->label.': '; ! $this->ShowPlain($value, $origin); } } *************** *** 123,127 **** * @param string $value Value to load the control with. */ ! function ShowForm($value) { } --- 123,127 ---- * @param string $value Value to load the control with. */ ! function ShowForm($value, $origin = FT_OR_DB) { } *************** *** 132,136 **** * @param string $value Value to load the control with. */ ! function ShowPlain($value) { echo $value; --- 132,136 ---- * @param string $value Value to load the control with. */ ! function ShowPlain($value, $origin = FT_OR_DB) { echo $value; Index: DB_Base.class.php =================================================================== RCS file: /cvsroot/phpvortex/phpvortex/DB_Base.class.php,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** DB_Base.class.php 5 Oct 2004 19:02:33 -0000 1.8 --- DB_Base.class.php 29 Sep 2005 20:23:17 -0000 1.9 *************** *** 86,89 **** --- 86,127 ---- /** + * Execute a SELECT query at the database. + * + * @param array $opts Parameters to the SELECT query, as 'option' => 'value'. + * @return RS_Base Returns a RecordSet object if there is a result to the query or FALSE if a error occurred. + */ + function &Select($opts = array()) + { + $sel = "SELECT "; + if (isset($opts['distinct'])) $sel .= "DISTINCT "; + if (isset($opts['fields'])) { + $fl = ''; + foreach ($opts['fields'] as $a => $f) if (is_int($a)) { + $fl .= (strlen($fl)?', ':'') . $f; + } else { + $fl .= (strlen($fl)?', ':'') . $f . ' as ' . $a; + } + $sel .= $fl . ' '; + } else { + $sel .= "* "; + } + if (isset($opts['from'])) { + $fl = ''; + foreach ($opts['from'] as $a => $f) if (is_int($a)) { + $fl .= (strlen($fl)?', ':'') . $f; + } else { + $fl .= (strlen($fl)?', ':'') . $f . ' as ' . $a; + } + $sel .= "FROM $fl "; + } + if (isset($opts['where'])) $sel .= "WHERE {$opts['where']} "; + if (isset($opts['group'])) $sel .= "GROUP BY {$opts['group']} "; + if (isset($opts['having'])) $sel .= "HAVING {$opts['having']} "; + if (isset($opts['order'])) $sel .= "ORDER BY {$opts['order']} "; + if (!empty($GLOBALS['debug'])) dv(3, 'SELECT SQL', $sel); + return $this->Query($sel); + } + + /** * Execute a INSERT INTO query at the database. * *************** *** 101,105 **** } $sql = "INSERT INTO $table ($fl) VALUES ($vl)"; ! if (!empty($debug)) dv(3, 'INSERT SQL', $sql); return $this->Query($sql); } --- 139,143 ---- } $sql = "INSERT INTO $table ($fl) VALUES ($vl)"; ! if (!empty($GLOBALS['debug'])) dv(3, 'INSERT SQL', $sql); return $this->Query($sql); } *************** *** 120,124 **** } $sql = "UPDATE $table SET $sl WHERE $where"; ! if (!empty($debug)) dv(3, 'UPDATE SQL', $sql); return $this->Query($sql); } --- 158,162 ---- } $sql = "UPDATE $table SET $sl WHERE $where"; ! if (!empty($GLOBALS['debug'])) dv(3, 'UPDATE SQL', $sql); return $this->Query($sql); } *************** *** 134,138 **** { $sql = "DELETE FROM $table WHERE $where"; ! if (!empty($debug)) dv(3, 'DELETE SQL', $sql); return $this->Query($sql); } --- 172,176 ---- { $sql = "DELETE FROM $table WHERE $where"; ! if (!empty($GLOBALS['debug'])) dv(3, 'DELETE SQL', $sql); return $this->Query($sql); } Index: FT_List.class.php =================================================================== RCS file: /cvsroot/phpvortex/phpvortex/FT_List.class.php,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** FT_List.class.php 20 Oct 2004 20:10:18 -0000 1.2 --- FT_List.class.php 29 Sep 2005 20:23:17 -0000 1.3 *************** *** 75,85 **** * @param string $value Value to load the control with. */ ! function ShowForm($value) { global $vortex_msgs; ! $sql = "SELECT {$this->rel_key}, {$this->rel_label} FROM {$this->rel_table}".(empty($this->rel_order)?'':" ORDER BY {$this->rel_order}"); ! if (!empty($debug)) dv(3, 'FT_List::ShowForm() SELECT', $sql); ! if (!($rs = $this->db->Query($sql))) { return; } --- 75,88 ---- * @param string $value Value to load the control with. */ ! function ShowForm($value, $origin = FT_OR_DB) { global $vortex_msgs; ! $sel = array( ! 'fields' => array($this->rel_key, $this->rel_label), ! 'from' => array($this->rel_table) ! ); ! if (!empty($this->rel_order)) $sel['order'] = $this->rel_order; ! if (!($rs = $this->db->Select($sel))) { return; } *************** *** 87,91 **** echo "\t<option value='-1'".((-1 == $value)?' selected':'').">{$vortex_msgs['list_default']}</option>\n"; while ($row = $rs->Row()) { ! echo "\t<option value='{$row['$this->rel_key']}'".(($this->rel_key == $value)?' selected':'').">{$this->rel_label}</option>\n"; } echo "</select>\n"; --- 90,94 ---- echo "\t<option value='-1'".((-1 == $value)?' selected':'').">{$vortex_msgs['list_default']}</option>\n"; while ($row = $rs->Row()) { ! echo "\t<option value='{$row[$this->rel_key]}'".(($row[$this->rel_key] == $value)?' selected':'').">{$row[$this->rel_label]}</option>\n"; } echo "</select>\n"; *************** *** 97,105 **** * @param string $value Value to load the control with. */ ! function ShowPlain($value) { ! $sql = "SELECT {$this->rel_label} FROM {$this->rel_table} WHERE {$this->rel_key} = $value"; ! if (!empty($debug)) dv(3, 'FT_List::ShowPlain() SELECT', $sql); ! if (!($rs = $this->db->Query($sql))) { return; } --- 100,106 ---- * @param string $value Value to load the control with. */ ! function ShowPlain($value, $origin = FT_OR_DB) { ! if (!($rs = $this->db->Select(array('from' => array($this->rel_table), 'fields' => array($this->rel_label), 'where' => "{$this->rel_key} = $value")))) { return; } Index: RS_PostgreSQL.class.php =================================================================== RCS file: /cvsroot/phpvortex/phpvortex/RS_PostgreSQL.class.php,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RS_PostgreSQL.class.php 28 Sep 2005 19:04:21 -0000 1.1 --- RS_PostgreSQL.class.php 29 Sep 2005 20:23:17 -0000 1.2 *************** *** 42,56 **** function Row($row = -1, $type = RS_ROW_ASSOC) { ! if ($row != -1) $this->row = $row; $this->row++; switch ($type) { case RS_ROW_NUM: ! return pg_fetch_row($this->result, $this->row - 1); break; case RS_ROW_ASSOC: ! return pg_fetch_assoc($this->result, $this->row - 1); break; case RS_ROW_BOTH: ! return pg_fetch_array($this->result, $this->row - 1); break; } --- 42,70 ---- function Row($row = -1, $type = RS_ROW_ASSOC) { ! if ($row != -1) { ! $this->row = $row + 1; ! switch ($type) { ! case RS_ROW_NUM: ! return pg_fetch_row($this->result, $this->row - 1); ! break; ! case RS_ROW_ASSOC: ! return pg_fetch_assoc($this->result, $this->row - 1); ! break; ! case RS_ROW_BOTH: ! return pg_fetch_array($this->result, $this->row - 1); ! break; ! } ! return FALSE; ! } $this->row++; switch ($type) { case RS_ROW_NUM: ! return pg_fetch_row($this->result); break; case RS_ROW_ASSOC: ! return pg_fetch_assoc($this->result); break; case RS_ROW_BOTH: ! return pg_fetch_array($this->result); break; } *************** *** 67,71 **** { $this->row = $row; ! return TRUE; } --- 81,89 ---- { $this->row = $row; ! if (pg_result_seek($this->result, $row) === FALSE) { ! return FALSE; ! } else { ! return TRUE; ! } } Index: FT_DateTime.class.php =================================================================== RCS file: /cvsroot/phpvortex/phpvortex/FT_DateTime.class.php,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** FT_DateTime.class.php 24 Apr 2005 21:38:02 -0000 1.1 --- FT_DateTime.class.php 29 Sep 2005 20:23:17 -0000 1.2 *************** *** 102,108 **** * @param string $value Value to load the control with. */ ! function ShowForm($value) { ! echo "<input type='text' name='{$this->name_form}' value='".($this->ConsistTest($value)?date($this->format, strtotime($value)):$value)."' />"; } --- 102,112 ---- * @param string $value Value to load the control with. */ ! function ShowForm($value, $origin = FT_OR_DB) { ! if ($origin == FT_OR_DB) { ! echo "<input type='text' name='{$this->name_form}' value='".($this->ConsistTest($value)?date($this->format, strtotime($value)):$value)."' />"; ! } else { ! echo "<input type='text' name='{$this->name_form}' value='$value' />"; ! } } *************** *** 112,118 **** * @param string $value Value to load the control with. */ ! function ShowPlain($value) { ! echo (empty($value)?'':date($this->format, strtotime($value))); } --- 116,126 ---- * @param string $value Value to load the control with. */ ! function ShowPlain($value, $origin = FT_OR_DB) { ! if ($origin == FT_OR_DB) { ! echo (empty($value)?'':date($this->format, strtotime($value))); ! } else { ! echo (empty($value)?'':$value); ! } } Index: DB_PostgreSQL.class.php =================================================================== RCS file: /cvsroot/phpvortex/phpvortex/DB_PostgreSQL.class.php,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** DB_PostgreSQL.class.php 28 Sep 2005 19:04:21 -0000 1.1 --- DB_PostgreSQL.class.php 29 Sep 2005 20:23:17 -0000 1.2 *************** *** 53,56 **** --- 53,57 ---- function &Query($sql) { + if (!empty($GLOBALS['debug'])) dv(5, 'QUERY SQL', $sql); $rs = pg_query($this->link, $sql); if ($rs === FALSE) { Index: FT_Hidden.class.php =================================================================== RCS file: /cvsroot/phpvortex/phpvortex/FT_Hidden.class.php,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** FT_Hidden.class.php 7 Oct 2004 21:19:44 -0000 1.1 --- FT_Hidden.class.php 29 Sep 2005 20:23:17 -0000 1.2 *************** *** 27,31 **** * @param bool $form Show field as a INPUT object? */ ! function Show(&$data, $form = TRUE) { if (empty($data) || !isset($data[$this->name_db])) { --- 27,31 ---- * @param bool $form Show field as a INPUT object? */ ! function Show(&$data, $form = TRUE, $origin = FT_OR_DB) { if (empty($data) || !isset($data[$this->name_db])) { *************** *** 35,41 **** } if ($form) { ! $this->ShowForm($value); } else { ! $this->ShowPlain($value); } } --- 35,41 ---- } if ($form) { ! $this->ShowForm($value, $origin); } else { ! $this->ShowPlain($value, $origin); } } *************** *** 46,50 **** * @param string $value Value to load the control with. */ ! function ShowForm($value) { echo "<input type='hidden' name='{$this->name_form}' value='$value' />"; --- 46,50 ---- * @param string $value Value to load the control with. */ ! function ShowForm($value, $origin = FT_OR_DB) { echo "<input type='hidden' name='{$this->name_form}' value='$value' />"; Index: SEC_Edit.class.php =================================================================== RCS file: /cvsroot/phpvortex/phpvortex/SEC_Edit.class.php,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** SEC_Edit.class.php 28 Sep 2005 19:05:06 -0000 1.3 --- SEC_Edit.class.php 29 Sep 2005 20:23:17 -0000 1.4 *************** *** 31,34 **** --- 31,40 ---- /** + * DB connection. + * @var DB_Base + */ + var $db = NULL; + + /** * Specify a table class to instantiate. * *************** *** 170,175 **** if (!empty($this->table_class)) { include_once($this->table_class.'.class.php'); ! $this->table =& new $this->table_class($this->table_opts); ! ); // See what to do and perform the action --- 176,181 ---- if (!empty($this->table_class)) { include_once($this->table_class.'.class.php'); ! $this->table =& new $this->table_class($this->db, $this->table_opts); ! } // See what to do and perform the action *************** *** 193,201 **** ) ); ! if (!(empty($_REQUEST["{$this->table->name}_action"]) || strcmp($_REQUEST["{$this->table->name}_action"], 'F'))) { ! $opts['data'] = array(); ! foreach ($this->table->fields_form as $field) { ! if (!empty($_REQUEST[$field->name_form])) $opts['data'][$field->name_form] = $_REQUEST[$field->name_form]; ! } } --- 199,204 ---- ) ); ! if (isset($_SESSION['vortex_find_'.$this->table->name])) { ! $opts['data'] = $_SESSION['vortex_find_'.$this->table->name]; } *************** *** 228,232 **** 'code' => "<div class='div_error'>{$vortex_errors[TB_ERR_INCONSIST]}</div>" )); ! $this->table->LoadForm($_REQUEST); break; default: --- 231,235 ---- 'code' => "<div class='div_error'>{$vortex_errors[TB_ERR_INCONSIST]}</div>" )); ! $this->table->LoadForm($_REQUEST, FT_OR_USER); break; default: *************** *** 239,246 **** --- 242,254 ---- } elseif (!strcmp($action, 'F')) { $this->table->Seek($_REQUEST); + $_SESSION['vortex_find_'.$this->table->name] = array(); + foreach ($this->table->fields_form as $field) { + if (isset($_REQUEST[$field->name_form]) && ($_REQUEST[$field->name_form] != $field->default)) $_SESSION['vortex_find_'.$this->table->name][$field->name_form] = $_REQUEST[$field->name_form]; + } } elseif (!strcmp($action, 'N')) { $this->table->Seek(); } elseif (!strcmp($action, 'R')) { $this->table->Seek(); + unset($_SESSION['vortex_find_'.$this->table->name]); } elseif (!strcmp($action, 'D')) { if ($this->table->Delete($_REQUEST)) { *************** *** 281,284 **** --- 289,296 ---- } elseif (!strcmp($button, 'R')) { $url =& new URL(); + foreach ($this->table->fields as $field) if ($field->pkey) { + unset($url->parameters[$field->name_db]); + } + unset($url->parameters["page_{$this->table->name}"]); $url->parameters["{$this->table->name}_action"] = 'R'; $code .= "<script language='JavaScript'>\n\tfunction {$this->table->name}_Reset() {\n\t\tdocument.form_{$this->table->name}.action = '".$url->Get()."';\n\t\tdocument.form_{$this->table->name}.submit();\n\t}\n</script>\n"; *************** *** 308,311 **** --- 320,324 ---- } elseif (!strcmp($button, 'F')) { $url =& new URL(); + unset($url->parameters["page_{$this->table->name}"]); $url->parameters["{$this->table->name}_action"] = 'F'; $code .= "<script language='JavaScript'>\n\tfunction {$this->table->name}_Find() {\n\t\tdocument.form_{$this->table->name}.action = '".$url->Get()."';\n\t\tdocument.form_{$this->table->name}.submit();\n\t}\n</script>\n"; Index: TB_Base.class.php =================================================================== RCS file: /cvsroot/phpvortex/phpvortex/TB_Base.class.php,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** TB_Base.class.php 8 Oct 2004 17:14:47 -0000 1.14 --- TB_Base.class.php 29 Sep 2005 20:23:17 -0000 1.15 *************** *** 92,101 **** /** * Constructor: Init the object, and define the table's fields and relationships. * * @param DB_Base $db Database where the table is. */ ! function TB_Base(&$db) { $this->db =& $db; is_null($this->name_db) and $this->name_db = $this->name; --- 92,113 ---- /** + * Origin of $data. + * @var int + */ + var $data_origin = FT_OR_DB; + + /** * Constructor: Init the object, and define the table's fields and relationships. * * @param DB_Base $db Database where the table is. + * @param array $opts Parameters for the object, as 'var' => 'value'. */ ! function TB_Base(&$db, $opts = array()) { + $keys = array_keys($opts); + foreach ($keys as $key) { + $this->$key =& $opts[$key]; + } + $this->db =& $db; is_null($this->name_db) and $this->name_db = $this->name; *************** *** 136,142 **** return FALSE; } ! $sql = "SELECT * FROM {$this->name_db} WHERE $where"; ! if (!empty($debug)) dv(3, 'SEEK SELECT', $sql); ! if (!($rs = $this->db->Query($sql))) { $this->data = array(); $this->error = TB_ERR_DB; --- 148,152 ---- return FALSE; } ! if (!($rs = $this->db->Select(array('from' => array($this->name_db), 'where' => $where)))) { $this->data = array(); $this->error = TB_ERR_DB; *************** *** 157,161 **** * @param array $data Array containing the data to load as 'field' => 'value'. */ ! function LoadForm($data) { $this->data = array(); --- 167,171 ---- * @param array $data Array containing the data to load as 'field' => 'value'. */ ! function LoadForm($data, $origin = FT_OR_DB) { $this->data = array(); *************** *** 163,166 **** --- 173,177 ---- if (isset($data[$field->name_form])) $this->data[$field->name_db] = $data[$field->name_form]; } + $this->data_origin = $origin; } *************** *** 181,184 **** --- 192,199 ---- foreach ($this->fields as $field) { if (($value = $field->Consist($data)) === FALSE) { + if (!empty($GLOBALS['debug'])) { + dv(1, 'INCONSISTENT FIELD', $field); + dv(1, 'DATA', $data); + } $this->error = TB_ERR_INCONSIST; return FALSE; *************** *** 205,209 **** return FALSE; } ! if (!($rs = $this->db->Query("SELECT COUNT(*) AS cnt FROM {$this->name_db} WHERE $where"))) { $this->error = TB_ERR_DB; return FALSE; --- 220,224 ---- return FALSE; } ! if (!($rs = $this->db->Select(array('fields' => array('cnt' => 'COUNT(*)'), 'from' => array($this->name_db), 'where' => $where)))) { $this->error = TB_ERR_DB; return FALSE; *************** *** 268,279 **** function ShowList($url = NULL, $page = -1, $data = NULL) { ! $fields = ''; foreach ($this->fields_list as $field) { ! $fields .= (strlen($fields)?', ':'').$field->name_db; } foreach ($this->fields as $field) if ($field->pkey) { ! $fields .= (strlen($fields)?', ':'').$field->name_db; } - $sql = "SELECT $fields FROM {$this->name_db}"; if (!empty($data)) { $where = ''; --- 283,295 ---- function ShowList($url = NULL, $page = -1, $data = NULL) { ! $sel = array( ! 'from' => array($this->name_db) ! ); foreach ($this->fields_list as $field) { ! $sel['fields'][] = $field->name_db; } foreach ($this->fields as $field) if ($field->pkey) { ! $sel['fields'][] = $field->name_db; } if (!empty($data)) { $where = ''; *************** *** 281,296 **** if (isset($data[$field->name_form])) $where .= (strlen($where)?' AND ':'').$field->Where($data[$field->name_form]); } ! if (strlen($where)) $sql .= " WHERE $where"; } ! if (!empty($this->list_order)) $sql .= " ORDER BY {$this->list_order}"; ! if ($page >= 0) $sql .= ' LIMIT '.($this->list_recspage * $page).", {$this->list_recspage}"; ! if (!empty($debug)) dv(3, "ShowList SELECT", $sql); ! if (!($rs = $this->db->Query($sql))) { $this->error = TB_ERR_DB; return FALSE; } ! if (!($rows = $rs->All())) { ! $this->error = TB_ERR_EMPTY; ! return FALSE; } echo "<div class='div_list'><table id='tb_{$this->name}'>\n<thead><tr>\n"; --- 297,318 ---- if (isset($data[$field->name_form])) $where .= (strlen($where)?' AND ':'').$field->Where($data[$field->name_form]); } ! if (strlen($where)) $sel['where'] = $where; } ! if (!empty($this->list_order)) $sel['order'] = $this->list_order; ! if (!($rs = $this->db->Select($sel))) { $this->error = TB_ERR_DB; return FALSE; } ! if ($page >= 0) { ! if ($page > 0) $rs->SetRow($this->list_recspage * $page); ! $rows = array(); ! for ($i = 0; $i < $this->list_recspage; $i++) { ! if (!($rows[] = $rs->Row())) break; ! } ! } else { ! if (!($rows = $rs->All())) { ! $this->error = TB_ERR_EMPTY; ! return FALSE; ! } } echo "<div class='div_list'><table id='tb_{$this->name}'>\n<thead><tr>\n"; *************** *** 299,303 **** } echo "</tr></thead>\n<tbody>\n"; ! foreach ($rows as $row) { echo "<tr>\n"; if (!empty($url)) { --- 321,325 ---- } echo "</tr></thead>\n<tbody>\n"; ! foreach ($rows as $row) if (!empty($row)) { echo "<tr>\n"; if (!empty($url)) { *************** *** 327,331 **** function NumPages($data = NULL) { ! $sql = "SELECT COUNT(*) as cnt FROM {$this->name_db}"; if (!empty($data)) { $where = ''; --- 349,356 ---- function NumPages($data = NULL) { ! $sel = array( ! 'fields' => array('cnt' => 'COUNT(*)'), ! 'from' => array($this->name_db) ! ); if (!empty($data)) { $where = ''; *************** *** 333,340 **** if (isset($data[$field->name_form])) $where .= (strlen($where)?' AND ':'').$field->Where($data[$field->name_form]); } ! if (strlen($where)) $sql .= " WHERE $where"; } ! if (!empty($debug)) dv(3, "NumPages SELECT", $sql); ! if (!($rs = $this->db->Query($sql))) { $this->error = TB_ERR_DB; return FALSE; --- 358,364 ---- if (isset($data[$field->name_form])) $where .= (strlen($where)?' AND ':'').$field->Where($data[$field->name_form]); } ! if (strlen($where)) $sel['where'] = $where; } ! if (!($rs = $this->db->Select($sel))) { $this->error = TB_ERR_DB; return FALSE; *************** *** 387,394 **** END; foreach ($this->fields as $field) if ($field->pkey) { ! $field->Show($this->data); } foreach ($this->fields_form as $field) { ! $field->Show($this->data); } echo "<tr class='submit' id='submit_$name'><td colspan='2'>".(empty($submit)?"<input type='submit' /> <input type='reset' />":$submit)."</td></tr>"; --- 411,418 ---- END; foreach ($this->fields as $field) if ($field->pkey) { ! $field->Show($this->data, TRUE, $this->data_origin); } foreach ($this->fields_form as $field) { ! $field->Show($this->data, TRUE, $this->data_origin); } echo "<tr class='submit' id='submit_$name'><td colspan='2'>".(empty($submit)?"<input type='submit' /> <input type='reset' />":$submit)."</td></tr>"; |