--- phpMyEdit.class.php 2003-08-18 22:31:58.000000000 +0200 +++ phpMyEdit.class.new.php 2003-10-07 11:37:22.789106400 +0200 @@ -168,6 +168,8 @@ { return $this->fdd[$k]['select'] == 'M' && ! $this->fdd[$k]['values']['table']; } function col_has_datemask($k) { return isset($this->fdd[$k]['datemask']) || isset($this->fdd[$k]['strftimemask']); } + function col_has_sqlw($k) { return !$this->virtual($k) && isset($this->fdd[$k]['sqlw']); } + function col_has_sql($k) { return isset($this->fdd[$k]['sql']); } /* * functions for indicating whether navigation style is enabled @@ -193,7 +195,8 @@ function tabs_enabled() { return $this->display['tabs'] && count($this->tabs) > 0; } function hidden($k) { return stristr($this->fdd[$k]['options'],'H'); } function password($k) { return stristr($this->fdd[$k]['options'],'W'); } - function readonly($k) { return stristr($this->fdd[$k]['options'],'R'); } + function virtual($k) { return @$this->fdd[$k]['virtual'] && $this->col_has_sql($k); } + function readonly($k) { return stristr($this->fdd[$k]['options'],'R') || $this->virtual($k) || ($this->col_has_sqlw($k) && !stristr($this->fdd[$k]['sqlw'], '$val') ); } function add_operation() { return $this->operation == $this->labels['Add'] && $this->add_enabled(); } function change_operation() { return $this->operation == $this->labels['Change'] && $this->change_enabled(); } @@ -213,6 +216,9 @@ function processed($k) /* {{{ */ { + if ($this->virtual($k)) { + return false; + } $options = @$this->fdd[$k]['options']; if (! isset($options)) { return true; @@ -223,7 +229,8 @@ ($this->savechange == $this->labels['Save'] && stristr($options, 'C')) || ($this->morechange == $this->labels['Apply'] && stristr($options, 'C')) || ($this->savechange == $this->labels['Save'] && stristr($options, 'P')) || - ($this->savedelete == $this->labels['Save'] && stristr($options, 'D')); + ($this->savedelete == $this->labels['Save'] && stristr($options, 'D')) || + $this->col_has_sqlw($k); } /* }}} */ function displayed($k) /* {{{ */ @@ -339,7 +346,7 @@ $desc = &$this->fdd[$field_num]['values']['description']; $qparts['type'] = 'select'; if ($table) { - $qparts['select'] = 'DISTINCT '.$key; + $qparts['select'] = 'DISTINCT '.$table.'.'.$key; if ($desc && is_array($desc) && is_array($desc['columns'])) { $qparts['select'] .= ',CONCAT('; // ) $num_cols = sizeof($desc['columns']); @@ -362,20 +369,29 @@ } else if ($desc && is_array($desc)) { // TODO } else if ($desc) { - $qparts['select'] .= ','.$desc; + $qparts['select'] .= ','.$table.'.'.$desc; $qparts['orderby'] = $desc; } else if ($key) { $qparts['orderby'] = $key; } //$qparts['from'] = "$db.$table.$sel; $qparts['from'] = "$db.$table"; + if (isset($this->fdd[$field_num]['values']['left join'])) { + $qparts['from'] .= ' LEFT JOIN '.$this->fdd[$field_num]['values']['left join']; + } $qparts['where'] = $this->fdd[$field_num]['values']['filters']; if ($this->fdd[$field_num]['values']['orderby']) { $qparts['orderby'] = $this->fdd[$field_num]['values']['orderby']; } } else { /* simple value extraction */ - $qparts['select'] = 'DISTINCT '.$this->fds[$field_num]; - $qparts['from'] = $this->db.'.'.$this->tb; + if ($this->virtual($field_num)) { + $key = $this->fqn($field_num); + } else { + $key = &$this->fds[$field_num]; + } + $qparts['select'] = 'DISTINCT '.$key.' AS PME_KEY'; + $qparts['orderby'] = 'PME_KEY'; + $qparts['from'] = $db.'.'.$this->tb; } $values = array(); $res = $this->myquery($this->query_make($qparts), __LINE__); @@ -389,13 +405,13 @@ { is_numeric($field) || $field = array_search($field, $this->fds); // if read SQL expression exists use it - if (isset($this->fdd[$field]['sql'])) - return $this->fdd[$field]['sql']; + if ($this->col_has_sql($field)) + return $this->print_sql_sqlw_string($this->fdd[$this->fds[$field]]['sql'], true); // on copy/change always use simple key retrieving if ($this->add_operation() || $this->copy_operation() || $this->change_operation()) { - $ret = 'PMEtable0.'.$this->fds[$field]; + $ret = $this->alias['tb'].'.'.$this->fds[$field]; } else { if ($this->fdd[$this->fds[$field]]['values']['description'] && ! $dont_desc) { $desc = &$this->fdd[$this->fds[$field]]['values']['description']; @@ -424,7 +440,7 @@ } elseif (0 && $this->fdd[$this->fds[$field]]['values']['column'] && ! $dont_cols) { $ret = 'PMEjoin'.$field.'.'.$this->fdd[$this->fds[$field]]['values']['column']; } else { - $ret = 'PMEtable0.'.$this->fds[$field]; + $ret = $this->alias['tb'].'.'.$this->fds[$field]; } // TODO: not neccessary, remove me! if (is_array($this->fdd[$this->fds[$field]]['values2'])) { @@ -437,7 +453,9 @@ { $fields = array(); for ($k = 0; $k < $this->num_fds; $k++) { - if (! $this->displayed[$k] && $k != $this->key_num) { + if (! $this->displayed[$k] && $k != $this->key_num + && $k != $this->css['row_cond_num'] + && $k != $this->css['cell_cond_num'] ){ continue; } $fields[] = $this->fqn($k).' AS qf'.$k; @@ -501,7 +519,7 @@ function create_join_clause() /* {{{ */ { $tbs[] = $this->tb; - $join = $this->tb.' AS PMEtable0'; + $join = $this->tb.' AS '.$this->alias['tb']; for ($k = 0,$numfds = sizeof($this->fds); $k<$numfds; $k++) { $field = $this->fds[$k]; if($this->fdd[$field]['values']['db']) { @@ -516,7 +534,7 @@ $alias = 'PMEjoin'.$k; if (!in_array($alias,$tbs)) { $join .= " LEFT OUTER JOIN $db.$table AS $alias"; - $join .= " ON $alias.$id = PMEtable0.$field"; + $join .= " ON $alias.$id = ".$this->alias['tb'].".$field"; $tbs[]=$alias; } } @@ -524,6 +542,20 @@ return $join; } /* }}} */ + /* + * replace $tb_alias with PMEtable0 or '' and optionally $val if defined + */ + + function print_sql_sqlw_string($sql_or_sqlw = '', $subst_tb_alias = true, $val = '') /* {{{ */ + { + if ($subst_tb_alias) { + $tb_alias = $this->alias['tb'].'.'; + } else { + $tb_alias = ''; + } + return StripSlashes(eval('return "'.addslashes($sql_or_sqlw).'"; ')); + } /* }}} */ + function make_where_from_query_opts($qp = null, $text = 0) /* {{{ */ { if ($qp == null) { @@ -933,8 +965,12 @@ $qparts['type'] = 'select'; $qparts['select'] = $this->create_column_list(); $qparts['from'] = $this->create_join_clause(); - $qparts['where'] = '('.$this->fqn($this->key).'=' - .$this->key_delim.$this->rec.$this->key_delim.')'; + if ($this->col_has_sql($this->key_num) && !$this->virtual($this->key_num)) { + $qparts['where'] = '('.$this->key; + } else { + $qparts['where'] = '('.$this->fqn($this->key); + } + $qparts['where'] .= '='.$this->key_delim.$this->rec.$this->key_delim.')'; $res = $this->myquery($this->query_make($qparts),__LINE__); if (! ($row = @mysql_fetch_array($res, MYSQL_ASSOC))) { @@ -1070,7 +1106,7 @@ /** * Returns CSS class name */ - function getCSSclass($name, $position = null, $divider = null, $postfix = null) /* {{{ */ + function getCSSclass($name, $position = null, $divider = null, $postfix = null, $force = null) /* {{{ */ { static $div_idx = -1; $elements = array($this->css['prefix'], $name); @@ -1079,17 +1115,21 @@ $elements[] = $this->page_types[$this->page_type]; } } - if ($position && $this->css['position']) { - $elements[] = $position; + if ($this->css['divider'] && $divider === 'next') { + $div_idx++; + if ($this->css['divider'] > 0 && $div_idx >= $this->css['divider']) { + $div_idx = 0; + } } - if ($divider && $this->css['divider']) { - if ($divider === 'next') { - $div_idx++; - if ($this->css['divider'] > 0 && $div_idx >= $this->css['divider']) { - $div_idx = 0; - } + if ($force) { + $elements[] = $force; + } else { + if ($position && $this->css['position']) { + $elements[] = $position; + } + if ($divider) { + $elements[] = $div_idx; } - $elements[] = $div_idx; } if ($postfix) { $elements[] = $postfix; @@ -1761,7 +1801,7 @@ //$raw_sort_field = 'qf'.$field; $sort_field = $this->fqn($field); $sort_field_w = $this->fdd[$field]['name']; - $this->fdd[$field]['sql'] && $sort_field_w .= ' (sql)'; + $this->col_has_sql($field) && $sort_field_w .= ' (sql)'; if ($desc) { $sort_field .= ' DESC'; $sort_field_w .= ' '.$this->labels['descending']; @@ -1948,7 +1988,7 @@ while ((!$fetched && ($row = @mysql_fetch_array($res, MYSQL_ASSOC)) != false) || ($fetched && $row != false)) { $fetched = false; - echo '