| version 1.158, 2004/12/27 17:57:54 |
version 1.159, 2004/12/30 19:58:51 |
|
|
| * http://platon.sk/projects/phpMyEdit/ |
* http://platon.sk/projects/phpMyEdit/ |
| */ |
*/ |
| |
|
| /* $Platon: phpMyEdit/phpMyEdit.class.php,v 1.157 2004/12/27 03:10:27 nepto Exp $ */ |
/* $Platon: phpMyEdit/phpMyEdit.class.php,v 1.158 2004/12/27 17:57:54 nepto Exp $ */ |
| |
|
| /* This is a generic table editing program. The table and fields to be |
/* This is a generic table editing program. The table and fields to be |
| edited are defined in the calling program. |
edited are defined in the calling program. |
|
|
| $qparts['from'] = $this->dbp.$this->tb; |
$qparts['from'] = $this->dbp.$this->tb; |
| } |
} |
| $values = array(); |
$values = array(); |
| $res = $this->myquery($this->query_make($qparts), __LINE__); |
$res = $this->myquery($this->get_SQL_query($qparts), __LINE__); |
| while ($row = @mysql_fetch_array($res, MYSQL_NUM)) { |
while ($row = @mysql_fetch_array($res, MYSQL_NUM)) { |
| $values[$row[0]] = $desc ? $row[1] : $row[0]; |
$values[$row[0]] = $desc ? $row[1] : $row[0]; |
| } |
} |
|
|
| return $ret; |
return $ret; |
| } /* }}} */ |
} /* }}} */ |
| |
|
| function create_column_list() /* {{{ */ |
function get_SQL_query($parts) /* {{{ */ |
| { |
|
| $fields = array(); |
|
| for ($k = 0; $k < $this->num_fds; $k++) { |
|
| if (! $this->displayed[$k] && $k != $this->key_num) { |
|
| continue; |
|
| } |
|
| $fields[] = $this->fqn($k).' AS qf'.$k; |
|
| if ($this->col_has_values($k)) { |
|
| $fields[] = $this->fqn($k, true, true).' AS qf'.$k.'_idx'; |
|
| } |
|
| if ($this->col_has_datemask($k)) { |
|
| $fields[] = 'UNIX_TIMESTAMP('.$this->fqn($k).') AS qf'.$k.'_timestamp'; |
|
| } |
|
| } |
|
| return join(',', $fields); |
|
| } /* }}} */ |
|
| |
|
| function query_make($parts) /* {{{ */ |
|
| { |
{ |
| foreach ($parts as $k => $v) { |
foreach ($parts as $k => $v) { |
| $parts[$k] = trim($parts[$k]); |
$parts[$k] = trim($parts[$k]); |
|
|
| return $ret; |
return $ret; |
| } /* }}} */ |
} /* }}} */ |
| |
|
| function create_join_clause() /* {{{ */ |
function get_SQL_column_list() /* {{{ */ |
| |
{ |
| |
$fields = array(); |
| |
for ($k = 0; $k < $this->num_fds; $k++) { |
| |
if (! $this->displayed[$k] && $k != $this->key_num) { |
| |
continue; |
| |
} |
| |
$fields[] = $this->fqn($k).' AS qf'.$k; |
| |
if ($this->col_has_values($k)) { |
| |
$fields[] = $this->fqn($k, true, true).' AS qf'.$k.'_idx'; |
| |
} |
| |
if ($this->col_has_datemask($k)) { |
| |
$fields[] = 'UNIX_TIMESTAMP('.$this->fqn($k).') AS qf'.$k.'_timestamp'; |
| |
} |
| |
} |
| |
return join(',', $fields); |
| |
} /* }}} */ |
| |
|
| |
function get_SQL_join_clause() /* {{{ */ |
| { |
{ |
| $main_table = 'PMEtable0'; |
$main_table = 'PMEtable0'; |
| $join_clause = $this->tb." AS $main_table"; |
$join_clause = $this->tb." AS $main_table"; |
|
|
| return $join_clause; |
return $join_clause; |
| } /* }}} */ |
} /* }}} */ |
| |
|
| function make_where_from_query_opts($qp = null, $text = 0) /* {{{ */ |
function get_SQL_where_from_query_opts($qp = null, $text = 0) /* {{{ */ |
| { |
{ |
| if ($qp == null) { |
if ($qp == null) { |
| $qp = $this->query_opts; |
$qp = $this->query_opts; |
|
|
| return join(' AND ',$where); |
return join(' AND ',$where); |
| } |
} |
| } |
} |
| return false; |
return ''; /* empty string */ |
| } /* }}} */ |
} /* }}} */ |
| |
|
| function gather_query_opts() /* {{{ */ |
function gather_query_opts() /* {{{ */ |
| Line 992 function '.$this->js['prefix'].'filter_h |
|
| Line 992 function '.$this->js['prefix'].'filter_h |
|
| */ |
*/ |
| |
|
| $qparts['type'] = 'select'; |
$qparts['type'] = 'select'; |
| $qparts['select'] = $this->create_column_list(); |
$qparts['select'] = $this->get_SQL_column_list(); |
| $qparts['from'] = $this->create_join_clause(); |
$qparts['from'] = $this->get_SQL_join_clause(); |
| $qparts['where'] = '('.$this->fqn($this->key).'=' |
$qparts['where'] = '('.$this->fqn($this->key).'=' |
| .$this->key_delim.$this->rec.$this->key_delim.')'; |
.$this->key_delim.$this->rec.$this->key_delim.')'; |
| |
|
| $res = $this->myquery($this->query_make($qparts),__LINE__); |
$res = $this->myquery($this->get_SQL_query($qparts),__LINE__); |
| if (! ($row = @mysql_fetch_array($res, MYSQL_ASSOC))) { |
if (! ($row = @mysql_fetch_array($res, MYSQL_ASSOC))) { |
| return false; |
return false; |
| } |
} |
| Line 1815 function '.$this->js['prefix'].'filter_h |
|
| Line 1815 function '.$this->js['prefix'].'filter_h |
|
| $count_parts = array( |
$count_parts = array( |
| 'type' => 'select', |
'type' => 'select', |
| 'select' => 'count(*)', |
'select' => 'count(*)', |
| 'from' => $this->create_join_clause(), |
'from' => $this->get_SQL_join_clause(), |
| 'where' => $this->make_where_from_query_opts()); |
'where' => $this->get_SQL_where_from_query_opts()); |
| $res = $this->myquery($this->query_make($count_parts), __LINE__); |
$res = $this->myquery($this->get_SQL_query($count_parts), __LINE__); |
| $row = @mysql_fetch_array($res, MYSQL_NUM); |
$row = @mysql_fetch_array($res, MYSQL_NUM); |
| $total_recs = $row[0]; |
$total_recs = $row[0]; |
| if ($this->last_operation()) { |
if ($this->last_operation()) { |
| Line 1893 function '.$this->js['prefix'].'filter_h |
|
| Line 1893 function '.$this->js['prefix'].'filter_h |
|
| * Prepare the SQL Query from the data definition file |
* Prepare the SQL Query from the data definition file |
| */ |
*/ |
| $qparts['type'] = 'select'; |
$qparts['type'] = 'select'; |
| $qparts['select'] = $this->create_column_list(); |
$qparts['select'] = $this->get_SQL_column_list(); |
| // Even if the key field isn't displayed, we still need its value |
// Even if the key field isn't displayed, we still need its value |
| if ($select_recs) { |
if ($select_recs) { |
| if (!in_array ($this->key, $this->fds)) { |
if (!in_array ($this->key, $this->fds)) { |
| $qparts['select'] .= ','.$this->fqn($this->key); |
$qparts['select'] .= ','.$this->fqn($this->key); |
| } |
} |
| } |
} |
| $qparts['from'] = $this->create_join_clause(); |
$qparts['from'] = $this->get_SQL_join_clause(); |
| $qparts['where'] = $this->make_where_from_query_opts(); |
$qparts['where'] = $this->get_SQL_where_from_query_opts(); |
| // build up the ORDER BY clause |
// build up the ORDER BY clause |
| if (isset($this->sfn)) { |
if (isset($this->sfn)) { |
| // WTF $raw_sort_fields? |
// WTF $raw_sort_fields? |
| Line 1945 function '.$this->js['prefix'].'filter_h |
|
| Line 1945 function '.$this->js['prefix'].'filter_h |
|
| * mysql_field_len() function. We will also fetch the first row to get |
* mysql_field_len() function. We will also fetch the first row to get |
| * the field names. |
* the field names. |
| */ |
*/ |
| $query = $this->query_make($qparts); |
$query = $this->get_SQL_query($qparts); |
| $res = $this->myquery($query, __LINE__); |
$res = $this->myquery($query, __LINE__); |
| if ($res == false) { |
if ($res == false) { |
| $this->error('invalid SQL query', $query); |
$this->error('invalid SQL query', $query); |
| Line 1964 function '.$this->js['prefix'].'filter_h |
|
| Line 1964 function '.$this->js['prefix'].'filter_h |
|
| $filter_row = $row; |
$filter_row = $row; |
| if (! is_array($filter_row)) { |
if (! is_array($filter_row)) { |
| unset($qparts['where']); |
unset($qparts['where']); |
| $query = $this->query_make($qparts); |
$query = $this->get_SQL_query($qparts); |
| $res = $this->myquery($query, __LINE__); |
$res = $this->myquery($query, __LINE__); |
| if ($res == false) { |
if ($res == false) { |
| $this->error('invalid SQL query', $query); |
$this->error('invalid SQL query', $query); |
| Line 2067 function '.$this->js['prefix'].'filter_h |
|
| Line 2067 function '.$this->js['prefix'].'filter_h |
|
| /* |
/* |
| * Display the current query |
* Display the current query |
| */ |
*/ |
| $text_query = $this->make_where_from_query_opts(null, true); |
$text_query = $this->get_SQL_where_from_query_opts(null, true); |
| if ($text_query != '' && $this->display['query']) { |
if ($text_query != '' && $this->display['query']) { |
| $css_class_name = $this->getCSSclass('queryinfo'); |
$css_class_name = $this->getCSSclass('queryinfo'); |
| echo '<tr class="',$css_class_name,'">',"\n"; |
echo '<tr class="',$css_class_name,'">',"\n"; |
| Line 2232 function '.$this->js['prefix'].'filter_h |
|
| Line 2232 function '.$this->js['prefix'].'filter_h |
|
| $qp = array(); |
$qp = array(); |
| $qp['type'] = 'select'; |
$qp['type'] = 'select'; |
| $qp['select'] = $aggr_from_clause; |
$qp['select'] = $aggr_from_clause; |
| $qp['from'] = $this->create_join_clause (); |
$qp['from'] = $this->get_SQL_join_clause(); |
| $qp['where'] = $this->make_where_from_query_opts(); |
$qp['where'] = $this->get_SQL_where_from_query_opts(); |
| $tot_query = $this->query_make($qp); |
$tot_query = $this->get_SQL_query($qp); |
| $totals_result = $this->myquery($tot_query,__LINE__); |
$totals_result = $this->myquery($tot_query,__LINE__); |
| $tot_row = @mysql_fetch_array($totals_result, MYSQL_ASSOC); |
$tot_row = @mysql_fetch_array($totals_result, MYSQL_ASSOC); |
| //} |
//} |