| version 1.13, 2002/10/12 10:59:35 |
version 1.14, 2002/10/17 21:06:46 |
|
|
| <?php |
<?php |
| |
|
| // $Id$ |
/* |
| |
* phpMyEdit - MySQL table editor |
| |
* |
| |
* phpMyEdit.class.php - main table editor class definition file |
| |
* ____________________________________________________________ |
| |
* |
| |
* Copyright (c) 1999-2002 John McCreesh <jpmcc@users.sourceforge.net> |
| |
* Copyright (c) 2001-2002 Jim Kraai <jkraai@users.sourceforge.net> |
| |
* Versions 5.0 and higher developed by Ondrej Jombik <nepto@php.net> |
| |
* Copyright (c) 2002 Platon SDG, http://www.platon.sk/ |
| |
* All rights reserved. |
| |
* |
| |
* See README file for more information about this software. |
| |
* See COPYING file for license information. |
| |
* |
| |
* Download the latest version from |
| |
* http://www.platon.sk/projects/phpMyEdit/ |
| |
*/ |
| |
|
| |
/* $Platon: phpWebFileManager/index.php,v 1.32 2002/10/16 21:19:20 nepto Exp $ */ |
| |
|
| /* phpMyEdit intro {{{ */ |
/* phpMyEdit intro {{{ */ |
| /* |
/* |
|
|
| /* }}} */ |
/* }}} */ |
| |
|
| if (@require_once dirname(__FILE__).'/timer.class') { |
if (@require_once dirname(__FILE__).'/timer.class') { |
| $timer = new timerClass(); |
$phpMyEdit_timer = new timerClass(); |
| } |
} |
| |
|
| function debug_var($name,$val) |
#function debug_var($name,$val) /* {{{ */ |
| { |
#{ |
| if (is_array($val)) { |
# if (is_array($val)) { |
| echo "<pre>$name\n"; |
# echo "<pre>$name\n"; |
| print_r($val); |
# print_r($val); |
| echo "</pre>\n"; |
# echo "</pre>\n"; |
| } else { |
# } else { |
| echo "$name::$val::<br>\n"; |
# echo "$name::$val::<br>\n"; |
| } |
# } |
| } |
#} /* }}} */ |
| |
|
| if (! function_exists('array_search')) { /* {{{ */ |
if (! function_exists('array_search')) { /* {{{ */ |
| function array_search($needle, $haystack) |
function array_search($needle, $haystack) |
|
|
| echo '<h4>MySQL query at line '.$line.'</h4>'.htmlspecialchars($qry).'<hr>'."\n"; |
echo '<h4>MySQL query at line '.$line.'</h4>'.htmlspecialchars($qry).'<hr>'."\n"; |
| } |
} |
| $this->elog("qry: $qry",$line); |
$this->elog("qry: $qry",$line); |
| $ret = @mysql_db_query($this->db,$qry); |
$ret = @mysql_db_query($this->db, $qry); |
| if (! $ret) { |
if (! $ret) { |
| $this->elog(mysql_errno().": ".mysql_error().' in '.$qry,__LINE__); |
$this->elog(mysql_errno().": ".mysql_error().' in '.$qry,__LINE__); |
| } |
} |
| return $ret; |
return $ret; |
| } /* }}} */ |
} /* }}} */ |
| |
|
| function htmlDisplay($field,$str,$usemask=true,$usecodec=true) /* {{{ */ |
function htmlDisplay($field, $str, $usemask = true, $usecodec = true) /* {{{ */ |
| { |
{ |
| // undo the add slashes |
// undo the add slashes |
| $str = stripslashes($str); |
$str = stripslashes($str); |
|
|
| } |
} |
| $values = array(); |
$values = array(); |
| $res = $this->myquery($this->query_make($qparts), __LINE__); |
$res = $this->myquery($this->query_make($qparts), __LINE__); |
| while ($row = mysql_fetch_row($res)) { |
while ($row = @mysql_fetch_array($res, MYSQL_NUM)) { |
| if ($desc) { |
$values[$row[0]] = $desc ? $row[1] : $row[0]; |
| $values[$row[0]] = $row[1]; |
|
| } else { |
|
| $values[$row[0]] = $row[0]; |
|
| } |
|
| } |
} |
| |
$values2 = $this->fdd[$field_num]['values2']; |
| |
is_array($values2) && $values = $values2 + $values; |
| |
is_array($prepend) && $values = $prepend + $values; |
| |
/* old wrong prepending -- REMOVE ME at December 2002 |
| if (is_array($prepend)) { |
if (is_array($prepend)) { |
| // old wrong prepending -- REMOVE ME at December 2002 |
$values[$prepend[0]] = $prepend[1]; |
| //$values[$prepend[0]] = $prepend[1]; |
|
| $values = $prepend + $values; |
|
| } |
} |
| |
*/ |
| return $values; |
return $values; |
| } /* }}} */ |
} /* }}} */ |
| |
|
| /* |
/* |
| * get the table/field name |
* get the table/field name |
| */ |
*/ |
| function fqn($field, $use_qfx = false, $dont_desc = false) /* {{{ */ |
function fqn($field, $use_qfx = false, $dont_desc = false, $dont_cols = false) /* {{{ */ |
| { |
{ |
| if (is_string($field)) { |
if (is_string($field)) { |
| $field = array_search($field,$this->fds); |
$field = array_search($field,$this->fds); |
|
|
| } else { |
} else { |
| $ret = 'JoinTable'.$field.'.'.$this->fdd[$this->fds[$field]]['values']['description']; |
$ret = 'JoinTable'.$field.'.'.$this->fdd[$this->fds[$field]]['values']['description']; |
| } |
} |
| } elseif ($this->fdd[$this->fds[$field]]['values']['column']) { |
} elseif ($this->fdd[$this->fds[$field]]['values']['column'] && ! $dont_cols) { |
| $ret = 'JoinTable'.$field.'.'.$this->fdd[$this->fds[$field]]['values']['column']; |
$ret = 'JoinTable'.$field.'.'.$this->fdd[$this->fds[$field]]['values']['column']; |
| } else { |
} else { |
| $ret = 'Table0.'.$this->fds[$field]; |
$ret = 'Table0.'.$this->fds[$field]; |
| } |
} |
| |
// TODO: not neccessary, remove me! |
| |
if (is_array($this->fdd[$this->fds[$field]]['values2'])) { |
| |
} |
| } |
} |
| |
|
| // what to do with $format XXX |
// what to do with $format XXX |
|
|
| { |
{ |
| $fields = array(); |
$fields = array(); |
| for ($k = 0; $k < $this->num_fds; $k++) { |
for ($k = 0; $k < $this->num_fds; $k++) { |
| |
if (! $this->displayed[$k]) |
| |
continue; |
| if ($this->col_is_date($k)) { |
if ($this->col_is_date($k)) { |
| //$fields[] = 'DATE_FORMAT('.$this->fqn($k).',"%Y%m%d%H%i%s") AS qf'.$k; |
//$fields[] = 'DATE_FORMAT('.$this->fqn($k).',"%Y%m%d%H%i%s") AS qf'.$k; |
| $fields[] = $this->fqn($k).' AS qf'.$k; |
$fields[] = $this->fqn($k).' AS qf'.$k; |
| } else { |
} else { |
| $fields[] = $this->fqn($k).' AS qf'.$k; |
$fields[] = $this->fqn($k).' AS qf'.$k; |
| |
if ($this->col_has_values($k)) { |
| |
$fields[] = $this->fqn($k, false, true, true).' AS qf'.$k.'_idx'; |
| |
} |
| //echo '[['.$this->fqn($k).' AS qf'.$k.']]<br>'; |
//echo '[['.$this->fqn($k).' AS qf'.$k.']]<br>'; |
| } |
} |
| } |
} |
|
|
| /* |
/* |
| * get_cgi_var() |
* get_cgi_var() |
| */ |
*/ |
| function get_cgi_var($name, $default_value = null) |
function get_cgi_var($name, $default_value = null) /* {{{ */ |
| { |
{ |
| global $HTTP_GET_VARS; |
global $HTTP_GET_VARS; |
| $var = $HTTP_GET_VARS[$name]; |
$var = $HTTP_GET_VARS[$name]; |
|
|
| } |
} |
| |
|
| return $var; |
return $var; |
| } |
} /* }}} */ |
| |
|
| /* |
/* |
| * functions for get/post/query args |
* functions for get/post/query args |
|
|
| $qf_val = "'".addslashes($m[$key])."'"; |
$qf_val = "'".addslashes($m[$key])."'"; |
| $afilter =" IN ('".addslashes($m[$key])."'"; |
$afilter =" IN ('".addslashes($m[$key])."'"; |
| } else { |
} else { |
| $afilter =$afilter.",'".addslashes($m[$key])."'"; |
$afilter = $afilter.",'".addslashes($m[$key])."'"; |
| $qf_val .= ",'".addslashes($m[$key])."'"; |
$qf_val .= ",'".addslashes($m[$key])."'"; |
| } |
} |
| } |
} |
| $afilter = $afilter.')'; |
$afilter = $afilter.')'; |
| // XXX: nasty $dont_desc hack |
// XXX: $dont_desc and $dont_cols hack |
| $dont_desc = isset($this->fdd[$k]['values']['description']); |
$dont_desc = isset($this->fdd[$k]['values']['description']); |
| $qo[$this->fqn($k, false, $dont_desc)] = |
$dont_cols = isset($this->fdd[$k]['values']['column']); |
| |
$qo[$this->fqn($k, false, $dont_desc, $dont_cols)] = |
| array( 'oper' => $qf_op, 'value' => '('.$qf_val.')'); |
array( 'oper' => $qf_op, 'value' => '('.$qf_val.')'); |
| } |
} |
| } else { |
} else { |
|
|
| if ($this->fdd[$k]['values']['description']) { |
if ($this->fdd[$k]['values']['description']) { |
| // DEBUG |
// DEBUG |
| // echo htmlspecialchars(' k = '.$k.' | fqn($k) = '.$this->fqn($k, false, true)); |
// echo htmlspecialchars(' k = '.$k.' | fqn($k) = '.$this->fqn($k, false, true)); |
| $qo[$this->fqn($k, false, true)] = |
$qo[$this->fqn($k, false, true, true)] = |
| array('oper' => '=', 'value' => "'".$afilter."'"); |
array('oper' => '=', 'value' => "'".$afilter."'"); |
| } elseif ($this->fdd[$k]['values']['column']) { |
} elseif ($this->fdd[$k]['values']['column']) { |
| $qo[$this->fqn($k)] = |
$qo[$this->fqn($k, false, true, true)] = |
| array('oper' => '=', 'value' => "'".$afilter."'"); |
array('oper' => '=', 'value' => "'".$afilter."'"); |
| } elseif ($this->col_is_string($k)) { |
} elseif ($this->col_is_string($k)) { |
| // massage the filter for a string comparison |
// massage the filter for a string comparison |
|
|
| $qo[$this->fqn($k)] = |
$qo[$this->fqn($k)] = |
| array('oper' => 'like', 'value' => "'".$afilter."'"); |
array('oper' => 'like', 'value' => "'".$afilter."'"); |
| } |
} |
| } elseif($this->fdd[$k]['values']) { |
} elseif($this->col_has_values($k)) { |
| //debug_var('col_is_string',$this->fdd[$k]['name'].'::'.$this->fdd[$k]['type']); |
//debug_var('col_is_string',$this->fdd[$k]['name'].'::'.$this->fdd[$k]['type']); |
| $qo[$this->fqn($k)] = |
$qo[$this->fqn($k)] = |
| array( 'oper' => '=', 'value' => "'".$afilter."'"); |
array( 'oper' => '=', 'value' => "'".$afilter."'"); |
|
|
| * type functions |
* type functions |
| */ |
*/ |
| |
|
| function col_is_date($k) { return in_array($this->fdd[$k]['type'], $this->dateTypes ); } |
function col_is_date($k) { return in_array($this->fdd[$k]['type'], $this->dateTypes ); } |
| function col_is_number($k) { return in_array($this->fdd[$k]['type'], $this->numberTypes); } |
function col_is_number($k) { return in_array($this->fdd[$k]['type'], $this->numberTypes); } |
| function col_is_string($k) { return in_array($this->fdd[$k]['type'], $this->stringTypes); } |
function col_is_string($k) { return in_array($this->fdd[$k]['type'], $this->stringTypes); } |
| function col_is_set($k) { return $this->fdd[$k]['type'] == 'set'; } |
function col_is_set($k) { return $this->fdd[$k]['type'] == 'set'; } |
| |
function col_has_values($k) { return isset($this->fdd[$k]['values']) || isset($this->fdd[$k]['values2']); } |
| |
|
| /* |
/* |
| * functions for indicating whether navigation style is enabled |
* functions for indicating whether navigation style is enabled |
|
|
| function copy_enabled() { return stristr($this->options, 'P') && $this->add_enabled(); } |
function copy_enabled() { return stristr($this->options, 'P') && $this->add_enabled(); } |
| function hidden($k) { return stristr($this->fdd[$k]['options'],'H'); } |
function hidden($k) { return stristr($this->fdd[$k]['options'],'H'); } |
| function password($k) { return stristr($this->fdd[$k]['options'],'P'); } |
function password($k) { return stristr($this->fdd[$k]['options'],'P'); } |
| function readonly($k) { return stristr($this->fdd[$k]['options'],'R') |
function readonly($k) { return stristr($this->fdd[$k]['options'],'R') || $this->fdd[$k]['expression']; } |
| || $this->fdd[$k]['expression']; } |
|
| |
|
| function add_operation() { |
|
| return ( $this->operation == $this->labels['Add'] |
|
| /* or $this->saveadd == $this->labels['Save'] */) |
|
| and $this->add_enabled(); |
|
| } |
|
| |
|
| function more_operation() { |
|
| return (0/* $this->moreadd == $this->labels['More'] */) |
|
| and $this->add_enabled(); |
|
| } |
|
| |
|
| # function display_operation() { |
function add_operation() { return $this->operation == $this->labels['Add'] && $this->add_enabled(); } |
| # return ($this->operation == $this->labels['Delete'] |
function change_operation() { return $this->operation == $this->labels['Change'] && $this->change_enabled(); } |
| # /* or $this->savedelete == $this->labels['Save'] */) |
function copy_operation() { return $this->operation == $this->labels['Copy'] && $this->add_enabled(); } |
| # and $this->delete_enabled(); |
function delete_operation() { return $this->operation == $this->labels['Delete'] && $this->delete_enabled(); } |
| # } |
function view_operation() { return $this->operation == $this->labels['View'] && $this->view_enabled(); } |
| |
function filter_operation() { return isset($this->filter) && $this->filter_enabled(); } |
| function change_operation() { |
|
| return ($this->operation == $this->labels['Change'] |
function processed($k) /* {{{ */ |
| /* or $this->savechange == $this->labels['Save'] */) |
{ |
| and $this->change_enabled(); |
$options = $this->fdd[$k]['options']; |
| } |
return empty($options) || |
| |
($this->saveadd == $this->labels['Save'] && stristr($options, 'A')) || |
| function copy_operation() { |
($this->moreadd == $this->labels['More'] && stristr($options, 'A')) || |
| return ($this->operation == $this->labels['Copy'] |
($this->savechange == $this->labels['Save'] && stristr($options, 'C')) || |
| /* or $this->savechange == $this->labels['Save'] */) |
($this->savechange == $this->labels['Save'] && stristr($options, 'P')) || |
| and $this->add_enabled(); |
($this->savedelete == $this->labels['Save'] && stristr($options, 'D')); |
| } |
} /* }}} */ |
| |
|
| function delete_operation() { |
|
| return ($this->operation == $this->labels['Delete'] |
|
| /* or $this->savedelete == $this->labels['Save'] */) |
|
| and $this->delete_enabled(); |
|
| } |
|
| |
|
| function view_operation() { |
|
| return $this->operation == $this->labels['View'] |
|
| and $this->view_enabled(); |
|
| } |
|
| |
|
| function filter_operation() { |
|
| return isset($this->filter) and $this->filter_enabled(); |
|
| } |
|
| |
|
| function displayed($k) /* {{{ */ |
function displayed($k) /* {{{ */ |
| { |
{ |
| if (is_numeric($k)) { |
if (is_numeric($k)) { |
| $k = $this->fds[$k]; |
$k = $this->fds[$k]; |
| } |
} |
| //echo $k.': '.$this->fdd[$k]['options'].'<hr>'; |
$options = $this->fdd[$k]['options']; |
| |
|
| return empty($this->fdd[$k]['options']) || |
return empty($options) || |
| ( ! $this->hidden($k) && ( |
(! $this->hidden($k) && ( |
| ( $this->add_operation() and stristr($this->fdd[$k]['options'],'A')) || |
($this->add_operation() && stristr($options,'A')) || |
| ( $this->more_operation() and stristr($this->fdd[$k]['options'],'A')) || |
($this->view_operation() && stristr($options,'V')) || |
| ( $this->view_operation() and stristr($this->fdd[$k]['options'],'V')) || |
($this->change_operation() && stristr($options,'C')) || |
| ( $this->change_operation() and stristr($this->fdd[$k]['options'],'C')) || |
($this->delete_operation() && stristr($options,'D')) || |
| ( $this->delete_operation() and stristr($this->fdd[$k]['options'],'D')) || |
($this->filter_operation() && stristr($options,'F')) || |
| ( $this->filter_operation() and stristr($this->fdd[$k]['options'],'F')) || |
(stristr($options,'L') && |
| ( stristr($this->fdd[$k]['options'],'L') and |
! $this->add_operation() && |
| ! $this->add_operation() && |
! $this->view_operation() && |
| ! $this->more_operation() && |
|
| ! $this->view_operation() && |
|
| ! $this->change_operation() && |
! $this->change_operation() && |
| ! $this->delete_operation() && |
! $this->delete_operation() && |
| ! $this->filter_operation()) |
! $this->filter_operation()) |
| ) |
)); |
| ); |
|
| } /* }}} */ |
} /* }}} */ |
| |
|
| /* |
/* |
|
|
| $fdd['fieldname']['validate']['php_regex']='something'; |
$fdd['fieldname']['validate']['php_regex']='something'; |
| */ |
*/ |
| |
|
| if ($this->add_operation() or $this->change_operation() or $this->more_operation()) { |
if ($this->add_operation() or $this->change_operation()) { |
| echo '<script type="text/javascript">'."\n"; |
echo '<script type="text/javascript">'."\n"; |
| echo '// <!-- |
echo '// <!-- |
| function form_control(theForm) |
function form_control(theForm) |
| { |
{ |
| '; // echo |
'; // echo |
| for ($k = 0; $k < $this->num_fds; $k++) { |
for ($k = 0; $k < $this->num_fds; $k++) { |
| if ($this->displayed($k) and $this->fdd[$k]['required']) { |
if ($this->displayed[$k] && $this->fdd[$k]['required'] && !$this->col_has_values($k)) { |
| if (! isset ($this->fdd[$k]['values']) |
if (isset($this->fdd[$k]['regex']['js'])) { |
| and isset ($this->fdd[$k]['regex']['js'])) { |
// use a javascript regex to validate it |
| // use a javascript regex to validate it |
// |
| // |
// XXX not done yet |
| // XXX not done yet |
// |
| // |
echo " |
| echo " |
|
| if ( theForm.".$this->fds[$k].".value.length == 0 ) { |
if ( theForm.".$this->fds[$k].".value.length == 0 ) { |
| alert( '".$this->labels['Please enter']." ".$this->fdd[$k]['name']." .' ); |
alert( '".$this->labels['Please enter']." ".$this->fdd[$k]['name']." .' ); |
| theForm.".$this->fds[$k].".focus(); |
theForm.".$this->fds[$k].".focus(); |
| return false; |
return false; |
| } |
} |
| "; // echo |
"; // echo |
| } elseif (!isset ($this->fdd[$k]['values'])) { |
} else { |
| // confirm that it's not empty |
// confirm that it's not empty |
| echo " |
echo " |
| if ( theForm.".$this->fds[$k].".value.length == 0 ) { |
if ( theForm.".$this->fds[$k].".value.length == 0 ) { |
| alert( '".$this->labels['Please enter']." ".$this->fdd[$k]['name']." .' ); |
alert( '".$this->labels['Please enter']." ".$this->fdd[$k]['name']." .' ); |
| theForm.".$this->fds[$k].".focus(); |
theForm.".$this->fds[$k].".focus(); |
| return false; |
return false; |
| } |
} |
| "; // echo |
"; // echo |
| } |
|
| } |
|
| } |
} |
| |
} |
| |
} |
| |
|
| echo ' |
echo ' |
| theForm.submit(); |
theForm.submit(); |
| return true; |
return true; |
| } |
} |
|
|
| echo ' </tr>'."\n"; |
echo ' </tr>'."\n"; |
| for ($k = 0; $k < $this->num_fds; $k++) { |
for ($k = 0; $k < $this->num_fds; $k++) { |
| echo ' <tr>'."\n"; |
echo ' <tr>'."\n"; |
| if ( $this->displayed($k) ) { |
if ($this->displayed[$k]) { |
| echo ' <td>'.$this->fdd[$k]['name'].'</td>'."\n"; |
echo ' <td>'.$this->fdd[$k]['name'].'</td>'."\n"; |
| |
|
| if ($this->fdd[$k]['select'] == 'M') |
if ($this->fdd[$k]['select'] == 'M') |
| { $a = ' multiple size="'.$this->multiple.'"'; } else { $a=''; } |
{ $a = ' multiple size="'.$this->multiple.'"'; } else { $a=''; } |
| if (isset ($this->fdd[$k]['values'])) { |
if ($this->col_has_values($k)) { |
| echo ' <td>' ."\n"; |
echo ' <td>' ."\n"; |
| if (isset($this->fdd[$k]['values']['table'])) { |
$vals = isset($this->fdd[$k]['values']['table']) |
| $vals = /* array(''=>'') + */ $this->set_values_from_table($k); |
? $this->set_values_from_table($k) |
| } else { |
: (array) $this->fdd[$k]['values2'] + (array) $this->fdd[$k]['values']; |
| $vals = /* array(''=>'') + */ $this->fdd[$k]['values']; |
|
| } |
|
| echo $this->htmlSelect($this->fds[$k], $vals, '', $this->col_is_set($k)); |
echo $this->htmlSelect($this->fds[$k], $vals, '', $this->col_is_set($k)); |
| echo ' </td>'."\n"; |
echo ' </td>'."\n"; |
| } elseif (isset ($this->fdd[$k]['textarea'])) { |
} elseif (isset ($this->fdd[$k]['textarea'])) { |
|
|
| .$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->query_make($qparts),__LINE__); |
| if ($row = mysql_fetch_array($res)) { |
if ($row = @mysql_fetch_array($res, MYSQL_ASSOC)) { |
| for ($k = 0; $k < $this->num_fds; $k++) { |
for ($k = 0; $k < $this->num_fds; $k++) { |
| if ($this->copy_operation()) { |
if ($this->copy_operation()) { |
| if ($this->displayed($k)) { |
if ($this->displayed[$k]) { |
| echo ' <tr>'; |
echo ' <tr>'; |
| echo ' <td>'.$this->fdd[$k]['name'].'</td>'."\n"; |
echo ' <td>'.$this->fdd[$k]['name'].'</td>'."\n"; |
| if ($this->readonly($k)) { |
if ($this->readonly($k)) { |
| echo $this->display_delete_field($row, $k); |
echo $this->display_delete_field($row, $k); |
| } elseif ($this->password($k)) { |
} elseif ($this->password($k)) { |
| echo ' <td><input type="password" name="'.$this->fds[$k] |
echo ' <td><input type="password" name="'.$this->fds[$k] |
| .'" value="'.$this->htmlDisplay($this->fdd[$k],$row[$k],false) |
.'" value="'.$this->htmlDisplay($this->fdd[$k], $row["qf$k"], false) |
| .'" /></td>'; |
.'" /></td>'; |
| } else { |
} else { |
| echo $this->display_change_field($row, $k); |
echo $this->display_change_field($row, $k); |
|
|
| elseif ($this->hidden($k)) { |
elseif ($this->hidden($k)) { |
| if ($k != $this->key_num) { |
if ($k != $this->key_num) { |
| echo '<input type="hidden" name="'.$this->fds[$k] |
echo '<input type="hidden" name="'.$this->fds[$k] |
| .'" value="'.$this->htmlDisplay($this->fdd[$k],$row[$k],false) |
.'" value="'.$this->htmlDisplay($this->fdd[$k], $row["qf$k"], false) |
| .'" />'."\n"; |
.'" />'."\n"; |
| } |
} |
| } |
} |
| } elseif ($this->change_operation()) { |
} elseif ($this->change_operation()) { |
| if ( $this->hidden($k) ) { |
if ($this->hidden($k)) { |
| echo '<input type="hidden" name="'.$this->fds[$k] |
echo '<input type="hidden" name="'.$this->fds[$k] |
| .'" value="'.$this->htmlDisplay($this->fdd[$k],$row[$k],false) |
.'" value="'.$this->htmlDisplay($this->fdd[$k], $row["qf$k"], false) |
| .'" />'."\n"; |
.'" />'."\n"; |
| } elseif ( $this->displayed($k)) { |
} elseif ($this->displayed[$k]) { |
| echo ' <tr>'."\n"; |
echo ' <tr>'."\n"; |
| echo ' <td>'.$this->fdd[$k]['name'].'</td>'."\n"; |
echo ' <td>'.$this->fdd[$k]['name'].'</td>'."\n"; |
| $this->display_change_field($row, $k); |
$this->display_change_field($row, $k); |
|
|
| echo ' </tr>'."\n"; |
echo ' </tr>'."\n"; |
| } |
} |
| } elseif ($this->delete_operation() || $this->view_operation()) { |
} elseif ($this->delete_operation() || $this->view_operation()) { |
| if ($this->displayed($k)) { |
if ($this->displayed[$k]) { |
| echo ' <tr>'."\n"; |
echo ' <tr>'."\n"; |
| echo ' <td>'.$this->fdd[$k]['name'].'</td>'."\n"; |
echo ' <td>'.$this->fdd[$k]['name'].'</td>'."\n"; |
| $this->display_delete_field($row, $k); |
$this->display_delete_field($row, $k); |
|
|
| { |
{ |
| echo '<td>'."\n"; |
echo '<td>'."\n"; |
| |
|
| if (isset($this->fdd[$k]['values'])) { |
if ($this->col_has_values($k)) { |
| if (isset($this->fdd[$k]['values']['table'])) { |
$vals = isset($this->fdd[$k]['values']['table']) |
| $vals = $this->set_values_from_table($k); |
? $this->set_values_from_table($k) |
| } else { |
: (array) $this->fdd[$k]['values2'] + (array) $this->fdd[$k]['values']; |
| $vals = $this->fdd[$k]['values']; |
echo $this->htmlSelect($this->fds[$k], $vals, $row["qf$k"], $this->col_is_set($k)); |
| } |
|
| echo $this->htmlSelect($this->fds[$k], $vals, $row[$k], $this->col_is_set($k)); |
|
| } elseif (isset($this->fdd[$k]['textarea'])) { |
} elseif (isset($this->fdd[$k]['textarea'])) { |
| echo '<textarea name="'.$this->fds[$k].'"'; |
echo '<textarea name="'.$this->fds[$k].'"'; |
| // rows attr |
// rows attr |
|
|
| echo ' wrap="virtual"'; |
echo ' wrap="virtual"'; |
| } |
} |
| echo '>'; |
echo '>'; |
| echo $this->htmlDisplay($this->fdd[$k], $row[$k], false); |
echo $this->htmlDisplay($this->fdd[$k], $row["qf$k"], false); |
| echo $row[$this->fds[$k]]; |
echo $row[$this->fds[$k]]; |
| echo '</textarea>'."\n"; |
echo '</textarea>'."\n"; |
| } else { |
} else { |
|
|
| } |
} |
| echo '<input type="text" '.($this->readonly($k)?'disabled ':'') |
echo '<input type="text" '.($this->readonly($k)?'disabled ':'') |
| .'name="'.$this->fds[$k].'" value="' |
.'name="'.$this->fds[$k].'" value="' |
| .$this->htmlDisplay($this->fdd[$k],$row[$k],false) |
.$this->htmlDisplay($this->fdd[$k],$row["qf$k"],false) |
| .'" size="'.$displaylen.'"/>'; |
.'" size="'.$displaylen.'"/>'; |
| } elseif ($this->col_is_date($k)) { |
} elseif ($this->col_is_date($k)) { |
| # date type, get date components |
# date type, get date components |
|
|
| } |
} |
| echo '<input type="text" '.($this->readonly($k)?'disabled ':'') |
echo '<input type="text" '.($this->readonly($k)?'disabled ':'') |
| .'name="'.$this->fds[$k].'" value="' |
.'name="'.$this->fds[$k].'" value="' |
| .$this->htmlDisplay($this->fdd[$k],$row[$k],false) |
.$this->htmlDisplay($this->fdd[$k],$row["qf$k"],false) |
| .'" size="'.$displaylen.'"/>'; |
.'" size="'.$displaylen.'"/>'; |
| } else { |
} else { |
| // unknown type |
// unknown type |
| echo '<input type="text" '.($this->readonly($k)?'disabled ':'') |
echo '<input type="text" '.($this->readonly($k)?'disabled ':'') |
| .'name="'.$this->fds[$k].'" value="' |
.'name="'.$this->fds[$k].'" value="' |
| .$this->htmlDisplay($this->fdd[$k],$row[$k],false).'" />'; |
.$this->htmlDisplay($this->fdd[$k],$row["qf$k"],false).'" />'; |
| } |
} |
| echo "\n"; |
echo "\n"; |
| } // if elseif else |
} // if elseif else |
|
|
| * @param multiple bool for mulptiple selection |
* @param multiple bool for mulptiple selection |
| * @param nat_sort bool for natural sorting |
* @param nat_sort bool for natural sorting |
| */ |
*/ |
| function htmlSelect($name, $kv_array, $selected, $multiple = false, $nat_sort = false) /* {{{ */ |
function htmlSelect($name, $kv_array, $selected = null, $multiple = false, $nat_sort = false) /* {{{ */ |
| { |
{ |
| $ret = '<select name="'.htmlspecialchars($name); |
$ret = '<select name="'.htmlspecialchars($name); |
| if ($multiple) { |
if ($multiple) { |
|
|
| uasort($kv_array,'strnatcasecmp'); |
uasort($kv_array,'strnatcasecmp'); |
| } |
} |
| if (! is_array($selected)) { |
if (! is_array($selected)) { |
| $selected = array($selected); |
$selected = $selected === null ? array() : array($selected); |
| } |
} |
| |
|
| //$keys = array_keys($kv_array); |
//$keys = array_keys($kv_array); |
|
|
| $found = false; |
$found = false; |
| foreach ($kv_array as $key => $value) { |
foreach ($kv_array as $key => $value) { |
| $ret .= '<option value="'.htmlspecialchars($key).'"'; |
$ret .= '<option value="'.htmlspecialchars($key).'"'; |
| if ((! $found || $multiple) && is_numeric(array_search($key, $selected))) { |
if ((! $found || $multiple) && is_numeric(array_search($key, $selected)) |
| |
|| (count($selected) == 0 && ! $found)) { |
| $ret .= ' selected'; |
$ret .= ' selected'; |
| $found = true; |
$found = true; |
| } |
} |
|
|
| |
|
| function display_delete_field($row, $k) /* {{{ */ |
function display_delete_field($row, $k) /* {{{ */ |
| { |
{ |
| if ($row[$k] == '') { |
echo '<td>'; |
| echo ' <td> </td>'."\n"; |
if ($row["qf$k"] === null) { |
| |
echo $this->fdd[$k]['values2'][$row['qf'.$k.'_idx']]; |
| |
} else if ($row["qf$k"] == '') { |
| |
echo ' '; |
| } else { |
} else { |
| echo ' <td>'.nl2br($this->htmlDisplay($this->fdd[$k],$row[$k])).'</td>'."\n"; |
echo nl2br($this->htmlDisplay($this->fdd[$k], $row["qf$k"])); |
| } |
} |
| |
echo '</td>'."\n"; |
| } /* }}} */ |
} /* }}} */ |
| |
|
| function web2plain($x) /* {{{ */ |
function web2plain($x) /* {{{ */ |
|
|
| if ($this->change_operation()) { |
if ($this->change_operation()) { |
| echo '<input type="submit" name="savechange" value="'.$this->labels['Save'].'" />'."\n"; |
echo '<input type="submit" name="savechange" value="'.$this->labels['Save'].'" />'."\n"; |
| echo '<input type="button" name="cancel" value="'.$this->labels['Cancel'].'" onClick="form.submit();" />'."\n"; |
echo '<input type="button" name="cancel" value="'.$this->labels['Cancel'].'" onClick="form.submit();" />'."\n"; |
| } elseif ($this->add_operation() or $this->more_operation()) { |
} elseif ($this->add_operation()) { |
| echo '<input type="submit" name="saveadd" value="'.$this->labels['Save'].'" />'."\n"; |
echo '<input type="submit" name="saveadd" value="'.$this->labels['Save'].'" />'."\n"; |
| echo '<input type="submit" name="moreadd" value="'.$this->labels['More'].'" />'."\n"; |
echo '<input type="submit" name="moreadd" value="'.$this->labels['More'].'" />'."\n"; |
| echo '<input type="button" name="cancel" value="'.$this->labels['Cancel'].'" onClick="form.submit();" />'."\n"; |
echo '<input type="button" name="cancel" value="'.$this->labels['Cancel'].'" onClick="form.submit();" />'."\n"; |
|
|
| //echo "sfn::".$this->sfn."::<br>\n"; |
//echo "sfn::".$this->sfn."::<br>\n"; |
| |
|
| // Default is to sort on first displayed field |
// Default is to sort on first displayed field |
| if ( |
if (! is_numeric($this->sfn) && ! $this->initial_sort_suppressed() |
| ! is_numeric($this->sfn) && |
&& ! isset($this->default_sort_columns)) { |
| ! $this->initial_sort_suppressed() && |
|
| ! isset($this->default_sort_columns) |
|
| ) { |
|
| $k = 0; |
$k = 0; |
| while (! $this->displayed($k)) { |
while (! $this->displayed[$k]) { |
| $k++; |
$k++; |
| } |
} |
| $this->sfn = $k; |
$this->sfn = $k; |
| } |
} |
| |
|
| // Are we doing a listall? |
// Are we doing a listall? |
| $listall = false; |
$listall = $this->inc < 0; |
| if ($this->inc == -1) |
|
| $listall = true; |
|
| |
|
| /* |
/* |
| * Display the MySQL table in an HTML table |
* Display the MySQL table in an HTML table |
|
|
| 'where' => $this->make_where_from_query_opts() |
'where' => $this->make_where_from_query_opts() |
| ); |
); |
| $res = $this->myquery($this->query_make($count_parts),__LINE__); |
$res = $this->myquery($this->query_make($count_parts),__LINE__); |
| $row = mysql_fetch_row($res); |
$row = @mysql_fetch_array($res, MYSQL_ASSOC); |
| $total_recs = $row[0]; |
$total_recs = $row['num_rows']; |
| |
|
| if ($this->nav_up()) { |
if ($this->nav_up()) { |
| $this->display_list_table_buttons($total_recs); |
$this->display_list_table_buttons($total_recs); |
|
|
| $fd = $this->fds[$k]; |
$fd = $this->fds[$k]; |
| |
|
| /* |
/* |
| if ( |
if ((stristr($this->fdd[$fd]['options'],'L') || ! isset ($this->fdd[$fd]['options'])) && |
| ( |
|
| stristr($this->fdd[$fd]['options'],'L') || |
|
| ! isset ($this->fdd[$fd]['options']) |
|
| ) && |
|
| ! $this->hidden($k) |
! $this->hidden($k) |
| ) |
) |
| */ |
*/ |
| if ($this->displayed($k)) { |
if ($this->displayed[$k]) { |
| $fdn = $this->fdd[$fd]['name']; |
$fdn = $this->fdd[$fd]['name']; |
| if (isset ($this->fdd[$fd]['width'])) { |
if (isset ($this->fdd[$fd]['width'])) { |
| $w = ' width="'.$this->fdd[$fd]['width'].'"'; |
$w = ' width="'.$this->fdd[$fd]['width'].'"'; |
|
|
| /* |
/* |
| * 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->create_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) { |
|
|
| $qparts['from'] = $this->create_join_clause(); |
$qparts['from'] = $this->create_join_clause(); |
| $qparts['where'] = $this->make_where_from_query_opts(); |
$qparts['where'] = $this->make_where_from_query_opts(); |
| // build up the ORDER BY clause |
// build up the ORDER BY clause |
| if ( |
if (is_numeric($this->sfn) || isset($this->default_sort_columns)) { |
| is_numeric($this->sfn) || |
|
| isset($this->default_sort_columns) |
|
| ) { |
|
| $raw_sort_fields = array(); |
$raw_sort_fields = array(); |
| $sort_fields = array(); |
$sort_fields = array(); |
| $sort_fields_w = array(); |
$sort_fields_w = array(); |
|
|
| $widthStyle = ' STYLE=\'width: "'.(6*$this->fdd[$fd]['width']).'px"\''; |
$widthStyle = ' STYLE=\'width: "'.(6*$this->fdd[$fd]['width']).'px"\''; |
| |
|
| $opened = false; |
$opened = false; |
| if ($this->displayed($k)) { |
if ($this->displayed[$k]) { |
| echo '<td '.$widthStyle.'>'; |
echo '<td '.$widthStyle.'>'; |
| $opened = true; |
$opened = true; |
| } |
} |
| |
|
| |
|
| $type = $this->fdd[$fd]['type']; |
$type = $this->fdd[$fd]['type']; |
| if (isset ($this->fdd[$k]['values'])) { |
if ($this->col_has_values($k)) { |
| $type='string'; |
$type = 'string'; |
| } |
} |
| |
|
| /* |
/* |
|
|
| !isset ($this->fdd[$fd]['options']) |
!isset ($this->fdd[$fd]['options']) |
| ) |
) |
| */ |
*/ |
| if ($this->displayed($k)) { |
if ($this->displayed[$k]) { |
| if ($this->fdd[$fd]['select'] == 'D' or $this->fdd[$fd]['select'] == 'M') { |
if ($this->fdd[$fd]['select'] == 'D' or $this->fdd[$fd]['select'] == 'M') { |
| /* |
/* |
| * Multiple fields processing - default size is 2 and array required for values |
* Multiple fields processing - default size is 2 and array required for values |
| */ |
*/ |
| $multiple = $this->fdd[$fd]['select'] == 'M'; |
$multiple = $this->fdd[$fd]['select'] == 'M'; |
| $selected = ''; |
$selected = $m; |
| if ($m != '') { |
$x = isset($this->fdd[$k]['values']['table']) || !$this->col_has_values($k) |
| $selected = $m; |
? $this->set_values_from_table($k, array('*' => '*')) |
| } |
: array('*' => '*') + (array) $this->fdd[$k]['values2'] + (array) $this->fdd[$k]['values']; |
| if ($this->fdd[$k]['values']['table']) { |
|
| $x = $this->set_values_from_table($k, array('*' => '*')); |
|
| } elseif ($this->fdd[$k]['values']) { |
|
| $x = array('*' => '*') + $this->fdd[$k]['values']; |
|
| } else { |
|
| // redunand |
|
| $x = $this->set_values_from_table($k, array('*' => '*')); |
|
| } |
|
| echo $this->htmlSelect($l, $x, $selected, $multiple); |
echo $this->htmlSelect($l, $x, $selected, $multiple); |
| } elseif ($this->fdd[$fd]['select'] == 'T') { |
} elseif ($this->fdd[$fd]['select'] == 'T') { |
| // this is where we put the comparison selects |
// this is where we put the comparison selects |
|
|
| $qpdeleteStr = '?'.join('&',$qpdelete); |
$qpdeleteStr = '?'.join('&',$qpdelete); |
| } |
} |
| |
|
| while ($row = mysql_fetch_array ($res)) { |
while ($row = @mysql_fetch_array($res, MYSQL_ASSOC)) { |
| |
if (0) { // TODO: delete me! |
| |
echo '<pre>'; |
| |
var_dump($row); |
| |
echo '</pre>'; |
| |
continue; |
| |
} |
| |
|
| echo '<tr class="'.(($rowCount++%2)?'pme_tr_o':'pme_tr_e')."\">\n"; |
echo '<tr class="'.(($rowCount++%2)?'pme_tr_o':'pme_tr_e')."\">\n"; |
| if ($sys_cols) { |
if ($sys_cols) { |
| $key_rec = $row[$this->key_num]; |
$key_rec = $row['qf'.$this->key_num]; |
| $qviewStr = $qpviewStr .'&rec='.$key_rec; |
$qviewStr = $qpviewStr .'&rec='.$key_rec; |
| $qcopyStr = $qpcopyStr .'&rec='.$key_rec; |
$qcopyStr = $qpcopyStr .'&rec='.$key_rec; |
| $qchangeStr = $qpchangeStr.'&rec='.$key_rec; |
$qchangeStr = $qpchangeStr.'&rec='.$key_rec; |
|
|
| } |
} |
| if ($this->nav_buttons()) { |
if ($this->nav_buttons()) { |
| echo '<td NOWRAP align=center>'; |
echo '<td NOWRAP align=center>'; |
| echo '<input type="radio" name="rec" value="'.$row[$this->key_num].'"'; |
echo '<input type="radio" name="rec" value="'.htmlspecialchars($key_rec).'"'; |
| if ($first) { |
if ($first) { |
| echo ' checked'; |
echo ' checked'; |
| $first = false; |
$first = false; |
|
|
| ! isset($this->fdd[$fd]['options']) |
! isset($this->fdd[$fd]['options']) |
| ) { |
) { |
| */ |
*/ |
| } elseif ($this->displayed($k)) { |
} elseif ($this->displayed[$k]) { |
| // XXX: echo 'displayed: '.$k.'-'.$fd; |
// XXX: echo 'displayed: '.$k.'-'.$fd; |
| if ((trim ($row[$k]) == '') or ($row[$k] == 'NULL')) { |
|
| |
/* TODO: what's this?! |
| |
|
| |
if ((trim($row[$k]) == '') or ($row[$k] == 'NULL')) { |
| echo ' <td> </td>'."\n"; |
echo ' <td> </td>'."\n"; |
| } else { |
} else { */ |
| // display the contents |
|
| $colattrs = $this->fdd[$fd]['colattrs']; |
// display the contents |
| if ($colattrs != '') |
$colattrs = $this->fdd[$fd]['colattrs']; |
| $colattrs = ' '.$colattrs; |
if ($colattrs != '') |
| if ($this->fdd[$fd]['nowrap']) |
$colattrs = ' '.$colattrs; |
| $colattrs .= ' NOWRAP'; |
if ($this->fdd[$fd]['nowrap']) |
| if (isset($this->fdd[$fd]['width'])) { |
$colattrs .= ' NOWRAP'; |
| $colattrs .= ' width="'.$this->fdd[$fd]['width'].'"'; |
if (isset($this->fdd[$fd]['width'])) { |
| } |
$colattrs .= ' width="'.$this->fdd[$fd]['width'].'"'; |
| echo ' <td'.$colattrs.'>'; |
} |
| if (! $this->hidden($k) && ! $this->password($k)) { |
echo ' <td'.$colattrs.'>'; |
| // displayable |
if (! $this->hidden($k) && ! $this->password($k)) { |
| if (isset($this->fdd[$k]['URL']) |
// displayable |
| || isset($this->fdd[$k]['URLprefix']) |
if (isset($this->fdd[$k]['URL']) |
| || isset($this->fdd[$k]['URLpostfix'])) { |
|| isset($this->fdd[$k]['URLprefix']) |
| /* It's an URL |
|| isset($this->fdd[$k]['URLpostfix'])) { |
| Put some conveniences in the namespace for the user |
/* It's an URL |
| to be able to use in the URL string. */ |
Put some conveniences in the namespace for the user |
| $key = $row[$this->key_num]; |
to be able to use in the URL string. */ |
| $name = $this->fds[$k]; |
$key = $key_rec; |
| $value = $row[$k]; |
$name = $this->fds[$k]; |
| $page = $this->page_name; |
$value = $row["qf$k"]; |
| $urlstr = $urlqueryproto.'&rec='.$key; |
$page = $this->page_name; |
| $urllink = isset($this->fdd[$k]['URL']) |
$urlstr = $urlqueryproto.'&rec='.$key; |
| ? eval('return "'.$this->fdd[$k]['URL'].'";') |
$urllink = isset($this->fdd[$k]['URL']) |
| : $value; |
? eval('return "'.$this->fdd[$k]['URL'].'";') |
| $urldisp = isset($this->fdd[$k]['URLdisp']) |
: $value; |
| ? eval('return "'.$this->fdd[$k]['URLdisp'].'";') |
$urldisp = isset($this->fdd[$k]['URLdisp']) |
| : $value; |
? eval('return "'.$this->fdd[$k]['URLdisp'].'";') |
| $target = isset($this->fdd[$k]['URLtarget']) |
: $value; |
| ? 'target="'.htmlspecialchars($this->fdd[$k]['URLtarget']).'" ' |
$target = isset($this->fdd[$k]['URLtarget']) |
| : ''; |
? 'target="'.htmlspecialchars($this->fdd[$k]['URLtarget']).'" ' |
| isset($this->fdd[$k]['URLprefix']) && $urllink = $this->fdd[$k]['URLprefix'].$urllink; |
: ''; |
| isset($this->fdd[$k]['URLpostfix']) && $urllink .= $this->fdd[$k]['URLpostfix']; |
isset($this->fdd[$k]['URLprefix']) && $urllink = $this->fdd[$k]['URLprefix'].$urllink; |
| $urllink = htmlspecialchars($urllink); |
isset($this->fdd[$k]['URLpostfix']) && $urllink .= $this->fdd[$k]['URLpostfix']; |
| $urldisp = htmlspecialchars($urldisp); |
$urllink = htmlspecialchars($urllink); |
| echo '<a '.$target.'class="pme_a_u" href="'.$urllink.'">'.$urldisp.'</a>'; |
$urldisp = htmlspecialchars($urldisp); |
| } elseif (isset($this->fdd[$k]['datemask'])) { |
echo '<a '.$target.'class="pme_a_u" href="'.$urllink.'">'.$urldisp.'</a>'; |
| // display date according to a mask if any |
} elseif (isset($this->fdd[$k]['datemask'])) { |
| //echo $this->mdate_set($row[$k],$this->fdd[$k]['type'],$this->fdd[$k]['datemask']); |
// display date according to a mask if any |
| //echo |
//echo $this->mdate_set($row[$k],$this->fdd[$k]['type'],$this->fdd[$k]['datemask']); |
| // $this->mdate_displayPlain( |
//echo |
| // $this->mdate_from_mysql( |
// $this->mdate_displayPlain( |
| // $row[$k]), |
// $this->mdate_from_mysql( |
| // ( |
// $row[$k]), |
| // $this->fdd[$k]['datemask']? |
// ( |
| // $this->fdd[$k]['datemask'] |
// $this->fdd[$k]['datemask']? |
| // : |
// $this->fdd[$k]['datemask'] |
| // $this->mdate_masks[$this->fdd[$k]['type']] |
// : |
| // ) |
// $this->mdate_masks[$this->fdd[$k]['type']] |
| // ); |
// ) |
| //echo $row[$k]; |
// ); |
| // it's a normal field |
//echo $row[$k]; |
| if (isset($this->fdd[$k]['trimlen'])) { |
// it's a normal field |
| if (strlen($row[$k]) > $this->fdd[$k]['trimlen']) { |
if (isset($this->fdd[$k]['trimlen']) |
| $shortdisp = ereg_replace("[\r\n\t ]+",' ',$row[$k]); |
&& strlen($row["qf$k"]) > $this->fdd[$k]['trimlen']) { |
| $shortdisp = substr($shortdisp,0,$this->fdd[$k]['trimlen']-3).'...'; |
$shortdisp = ereg_replace("[\r\n\t ]+", ' ', $row["qf$k"]); |
| } else { |
$shortdisp = substr($shortdisp,0,$this->fdd[$k]['trimlen']-3).'...'; |
| $shortdisp = $row[$k]; |
|
| } |
|
| echo nl2br( |
|
| $this->htmlDisplay ( |
|
| $this->fdd[$k], |
|
| $shortdisp |
|
| ) |
|
| ); |
|
| } else { |
|
| echo nl2br($this->htmlDisplay($this->fdd[$k],$row[$k])); |
|
| } |
|
| } else { |
} else { |
| // it's a normal field |
$shortdisp = $row["qf$k"]; |
| if (isset($this->fdd[$k]['trimlen'])) { |
} |
| if (strlen($row[$k]) > $this->fdd[$k]['trimlen']) { |
echo nl2br($this->htmlDisplay($this->fdd[$k], $shortdisp)); |
| $shortdisp = ereg_replace("[\r\n\t ]+",' ',$row[$k]); |
} else { |
| $shortdisp = substr($shortdisp,0,$this->fdd[$k]['trimlen']-3).'...'; |
// it's a normal field |
| } else { |
if ($row["qf$k"] === null) { |
| $shortdisp = $row[$k]; |
$shortdisp = $this->fdd[$k]['values2'][$row['qf'.$k.'_idx']]; |
| } |
//$shortdisp .= ' ('.$row['qf'.$k.'_idx'].')'; |
| echo nl2br( |
!isset($shortdisp) && $shortdisp = ''; |
| $this->htmlDisplay ( |
} else { |
| $this->fdd[$k], |
if (isset($this->fdd[$k]['trimlen']) |
| $shortdisp |
&& strlen($row["qf$k"]) > $this->fdd[$k]['trimlen']) { |
| ) |
$shortdisp = ereg_replace("[\r\n\t ]+",' ',$row["qf$k"]); |
| ); |
$shortdisp = substr($shortdisp,0,$this->fdd[$k]['trimlen']-3).'...'; |
| } else { |
} else { |
| echo nl2br($this->htmlDisplay($this->fdd[$k],$row[$k])); |
$shortdisp = $row["qf$k"]; |
| } |
} |
| } |
} |
| } else { |
echo nl2br($this->htmlDisplay($this->fdd[$k], $shortdisp)); |
| // it's hidden or a password |
|
| echo '<i>hidden</i>'; |
|
| } |
} |
| echo '</td>'."\n"; |
} else { |
| } // if else |
// it's hidden or a password |
| |
echo '<i>hidden</i>'; |
| |
} |
| |
echo '</td>'."\n"; |
| |
/* } // if else */ |
| } // if |
} // if |
| } // for |
} // for |
| |
|
|
|
| $tot_query = $this->query_make($qp); |
$tot_query = $this->query_make($qp); |
| //$this->elog('TOT_QRY: '.$tot_query,__LINE__); |
//$this->elog('TOT_QRY: '.$tot_query,__LINE__); |
| $totals_result = $this->myquery($tot_query,__LINE__); |
$totals_result = $this->myquery($tot_query,__LINE__); |
| $tot_row=mysql_fetch_array($totals_result); |
$tot_row = @mysql_fetch_array($totals_result, MYSQL_ASSOC); |
| //} |
//} |
| $qp_aggr = $qp; |
$qp_aggr = $qp; |
| echo "\n".'<tr>'."\n".'<td> </td>'."\n"; |
echo "\n".'<tr>'."\n".'<td> </td>'."\n"; |
|
|
| } |
} |
| echo ' <input type="hidden" name="qfn" value="'.$this->qfn.'" />'."\n"; |
echo ' <input type="hidden" name="qfn" value="'.$this->qfn.'" />'."\n"; |
| |
|
| if ($this->add_operation() or $this->more_operation() ) { |
if ($this->add_operation()) { |
| $this->display_add_record (); |
$this->display_add_record(); |
| } else { |
} else { |
| $this->display_copy_change_delete_record (); |
$this->display_copy_change_delete_record(); |
| } |
} |
| |
|
| echo '</table>'."\n"; |
echo '</table>'."\n"; |
|
|
| if ($this->nav_down()) { |
if ($this->nav_down()) { |
| //display buttons at bottom of page - sparky |
//display buttons at bottom of page - sparky |
| echo " <hr />\n"; |
echo " <hr />\n"; |
| $this->display_record_buttons (); |
$this->display_record_buttons(); |
| } |
} |
| |
|
| echo '</form>'."\n"; |
echo '</form>'."\n"; |
|
|
| $key_col_val = ''; |
$key_col_val = ''; |
| $qry = ''; |
$qry = ''; |
| for ($k = 0; $k < $this->num_fds; $k++) { |
for ($k = 0; $k < $this->num_fds; $k++) { |
| if ($this->displayed($k)) { |
if ($this->processed($k)) { |
| $fd = $this->fds[$k]; |
$fd = $this->fds[$k]; |
| if ($fd == $this->key) { |
if ($fd == $this->key) { |
| $key_col_val = addslashes($this->encode($this->fdd[$k],$fn)); |
$key_col_val = addslashes($this->encode($this->fdd[$k],$fn)); |
|
|
| $vals = array(); |
$vals = array(); |
| for ($k = 0; $k < $this->num_fds; $k++) { |
for ($k = 0; $k < $this->num_fds; $k++) { |
| $type = $this->fdd[$k]['type']; |
$type = $this->fdd[$k]['type']; |
| if ( $this->displayed($k) ) { |
if ($this->processed($k)) { |
| $fd = $this->fds[$k]; |
$fd = $this->fds[$k]; |
| $fn = $this->get_http_post_var_by_name($fd); |
$fn = $this->get_http_post_var_by_name($fd); |
| /* |
/* |
|
|
| if ($res) { |
if ($res) { |
| $tim = true; |
$tim = true; |
| } |
} |
| $this->message = mysql_affected_rows().' '.$this->labels['record added']; |
$this->message = @mysql_affected_rows().' '.$this->labels['record added']; |
| } |
} |
| if ( |
if ( |
| $tib && |
$tib && |
|
|
| $user = $REMOTE_ADDR; |
$user = $REMOTE_ADDR; |
| $body = 'A new item was added to '.$this->page_name." by ".$user." with the following fields:\n"; |
$body = 'A new item was added to '.$this->page_name." by ".$user." with the following fields:\n"; |
| for ($k=0;$k<$this->num_fds;$k++) { |
for ($k=0;$k<$this->num_fds;$k++) { |
| if ( $this->displayed($k) ) { |
if ($this->processed($k)) { |
| $body .= $this->fdd[$k]['name'].': '.$vals[$k]."\n"; |
$body .= $this->fdd[$k]['name'].': '.$vals[$k]."\n"; |
| $kv[$this->fds[$k]] = $vals[$k]; |
$kv[$this->fds[$k]] = $vals[$k]; |
| } |
} |
|
|
| // note change in log table |
// note change in log table |
| if ($this->logtable) { |
if ($this->logtable) { |
| $this->myquery( |
$this->myquery( |
| "insert into ".$this->logtable." values (". |
"INSERT INTO ".$this->logtable." VALUES (". |
| "now(),". |
"NOW(),". |
| "'".$REMOTE_USER."',". |
"'".$REMOTE_USER."',". |
| "'".$REMOTE_ADDR."',". |
"'".$REMOTE_ADDR."',". |
| "'insert','". |
"'insert','". |
|
|
| $qry_old_rec = ''; |
$qry_old_rec = ''; |
| for ($k = 0; $k < $this->num_fds; $k++) { |
for ($k = 0; $k < $this->num_fds; $k++) { |
| $type = $this->fdd[$k]['type']; |
$type = $this->fdd[$k]['type']; |
| if ($this->displayed($k) && ! $this->readonly($k)) { |
if ($this->processed($k) && ! $this->readonly($k)) { |
| $fd = $this->fds[$k]; |
$fd = $this->fds[$k]; |
| if ($fd == $this->key) { |
if ($fd == $this->key) { |
| $key_col_val = addslashes($this->get_http_post_var_by_name($fd)); |
$key_col_val = addslashes($this->get_http_post_var_by_name($fd)); |
|
|
| $qry = $qry.' WHERE ('.$this->key.' = '.$this->key_delim.$this->rec.$this->key_delim.')'; |
$qry = $qry.' WHERE ('.$this->key.' = '.$this->key_delim.$this->rec.$this->key_delim.')'; |
| $qry_old_rec .= ' FROM '.$this->tb.' WHERE ('.$this->key.' = '.$this->key_delim.$this->rec.$this->key_delim.')'; |
$qry_old_rec .= ' FROM '.$this->tb.' WHERE ('.$this->key.' = '.$this->key_delim.$this->rec.$this->key_delim.')'; |
| // get the old data |
// get the old data |
| $res_old = $this->myquery($qry_old_rec,__LINE__); |
$res_old = $this->myquery($qry_old_rec, __LINE__); |
| $oldvalues = mysql_fetch_array($res_old); |
$oldvalues = mysql_fetch_array($res_old); |
| // update the data |
// update the data |
| //echo "\n<h4>$qry</h4>\n"; |
//echo "\n<h4>$qry</h4>\n"; |
|
|
| // find and accumulate the changes |
// find and accumulate the changes |
| $changes=array(); |
$changes=array(); |
| for ($k = 0; $k < $this->num_fds; $k++) { |
for ($k = 0; $k < $this->num_fds; $k++) { |
| if ($this->displayed($k)) { |
if ($this->processed($k)) { |
| if ($oldvalues[$this->fds[$k]] != stripslashes($newvalues[$this->fds[$k]])) { |
if ($oldvalues[$this->fds[$k]] != stripslashes($newvalues[$this->fds[$k]])) { |
| $changes[$this->fds[$k]] = array(); |
$changes[$this->fds[$k]] = array(); |
| $changes[$this->fds[$k]]['was'] = $oldvalues[$this->fds[$k]]; |
$changes[$this->fds[$k]]['was'] = $oldvalues[$this->fds[$k]]; |
| Line 2453 echo '</pre>'."\n"; |
|
| Line 2432 echo '</pre>'."\n"; |
|
| echo '<h5>'.mysql_affected_rows ().' '.$this->labels['Change'].'</h5>'."\n"; |
echo '<h5>'.mysql_affected_rows ().' '.$this->labels['Change'].'</h5>'."\n"; |
| */ |
*/ |
| |
|
| $this->message = mysql_affected_rows().' '.$this->labels['record changed']; |
$this->message = @mysql_affected_rows().' '.$this->labels['record changed']; |
| } |
} |
| if ( |
if ( |
| $tub && |
$tub && |
| Line 2477 echo '<h5>'.mysql_affected_rows ().' '.$ |
|
| Line 2456 echo '<h5>'.mysql_affected_rows ().' '.$ |
|
| .$this->key_delim.$this->rec.$this->key_delim |
.$this->key_delim.$this->rec.$this->key_delim |
| .' was updated by '.$user.' in '.$this->page_name." with the following fields:\n"; |
.' was updated by '.$user.' in '.$this->page_name." with the following fields:\n"; |
| foreach ($changes as $key=>$vals) { |
foreach ($changes as $key=>$vals) { |
| if ( $this->displayed($k) ) { |
if ($this->processed($k)) { |
| $fieldName = $this->fdd[$key]['name']; |
$fieldName = $this->fdd[$key]['name']; |
| $body .= |
$body .= |
| $fieldName.":\n". |
$fieldName.":\n". |
| Line 2493 echo '<h5>'.mysql_affected_rows ().' '.$ |
|
| Line 2472 echo '<h5>'.mysql_affected_rows ().' '.$ |
|
| // note change in log table |
// note change in log table |
| if ($this->logtable) { |
if ($this->logtable) { |
| foreach ($changes as $key=>$vals) { |
foreach ($changes as $key=>$vals) { |
| $qry = "insert into ".$this->logtable." values (". |
$qry = "INSERT INTO ".$this->logtable." VALUES (". |
| "now(),'".$REMOTE_USER."','".$REMOTE_ADDR."','update','". |
"NOW(),'".$REMOTE_USER."','".$REMOTE_ADDR."','update','". |
| $this->tb."','".$key_col_val."','".$key."','". |
$this->tb."','".$key_col_val."','".$key."','". |
| addslashes($vals['was'])."','". |
addslashes($vals['was'])."','". |
| addslashes($vals['is'])."')"; |
addslashes($vals['is'])."')"; |
| Line 2520 echo '<h5>'.mysql_affected_rows ().' '.$ |
|
| Line 2499 echo '<h5>'.mysql_affected_rows ().' '.$ |
|
| // before trigger returned good status |
// before trigger returned good status |
| // let's do the main operation |
// let's do the main operation |
| for ($k = 0; $k < $this->num_fds; $k++) { |
for ($k = 0; $k < $this->num_fds; $k++) { |
| if ( $this->displayed($k) ) { |
if ($this->processed($k)) { |
| $fd = $this->fds[$k]; |
$fd = $this->fds[$k]; |
| if ($fd == $this->key) { |
if ($fd == $this->key) { |
| $key_col_val = addslashes($this->encode($this->fdd[$k],$fn)); |
$key_col_val = addslashes($this->encode($this->fdd[$k],$fn)); |
| Line 2539 echo '<h5>'.mysql_affected_rows ().' '.$ |
|
| Line 2518 echo '<h5>'.mysql_affected_rows ().' '.$ |
|
| if ($res) { |
if ($res) { |
| $tdm = true; |
$tdm = true; |
| } |
} |
| $this->message = mysql_affected_rows().' '.$this->labels['record deleted']; |
$this->message = @mysql_affected_rows().' '.$this->labels['record deleted']; |
| } |
} |
| if ( |
if ( |
| $tdb && |
$tdb && |
| Line 2590 echo '<h5>'.mysql_affected_rows ().' '.$ |
|
| Line 2569 echo '<h5>'.mysql_affected_rows ().' '.$ |
|
| set_magic_quotes_runtime(0); // let's do explicit quoting ... it's safer |
set_magic_quotes_runtime(0); // let's do explicit quoting ... it's safer |
| |
|
| // XXX fix this to use col_is_[type] |
// XXX fix this to use col_is_[type] |
| if (in_array($this->key_type,array('string','blob','date','time','datetime','timestamp','year'))) |
if (in_array($this->key_type, |
| { |
array('string','blob','date','time','datetime','timestamp','year'))) { |
| $this->key_delim = '"'; |
$this->key_delim = '"'; |
| } else { |
} else { |
| $this->key_delim = ''; |
$this->key_delim = ''; |
| Line 2603 echo '<h5>'.mysql_affected_rows ().' '.$ |
|
| Line 2582 echo '<h5>'.mysql_affected_rows ().' '.$ |
|
| $this->gather_post_vars(); |
$this->gather_post_vars(); |
| $this->unify_opts(); |
$this->unify_opts(); |
| |
|
| // debug code - uncomment to enable |
// DEBUG - uncomment to enable |
| |
/* |
| // phpinfo(); |
//phpinfo(); |
| // $this->print_get_vars(); |
$this->print_get_vars(); |
| // $this->print_post_vars(); |
$this->print_post_vars(); |
| // $this->print_vars(); |
$this->print_vars(); |
| // echo "<pre>query opts:\n"; |
echo "<pre>query opts:\n"; |
| // echo print_r($this->query_opts); |
echo print_r($this->query_opts); |
| // echo "</pre>\n"; |
echo "</pre>\n"; |
| // echo "<pre>get vars:\n"; |
echo "<pre>get vars:\n"; |
| // echo print_r($this->get_opts); |
echo print_r($this->get_opts); |
| // echo "</pre>\n"; |
echo "</pre>\n"; |
| |
*/ |
| |
|
| if (!isset ($this->db)) { |
if (!isset($this->db)) { |
| die("<h1>phpMyEdit: no database defined</h1>\n</body>\n</html>\n"); |
echo '<h1>phpMyEdit: no database defined</h1>'."\n"; |
| |
return; |
| } |
} |
| if (!isset ($this->tb)) { |
if (!isset ($this->tb)) { |
| die ("<h1>phpMyEdit: no table defined</h1>\n</body>\n</html>\n"); |
echo '<h1>phpMyEdit: no table defined</h1>'."\n"; |
| |
return; |
| } |
} |
| |
|
| $dbl = @mysql_pconnect($this->hn, $this->un, $this->pw) |
if ($dbl = @mysql_pconnect($this->hn, $this->un, $this->pw)) ; |
| or die("<h1>phpMyEdit: could not connect to MySQL</h1>\n</body>\n</html>\n"); |
else { |
| |
echo '<h1>phpMyEdit: could not connect to MySQL</h1>'."\n"; |
| |
return; |
| |
} |
| |
|
| /* |
/* |
| * ====================================================================== |
* ====================================================================== |
| Line 2652 echo '<h5>'.mysql_affected_rows ().' '.$ |
|
| Line 2637 echo '<h5>'.mysql_affected_rows ().' '.$ |
|
| * selected an editing button on Pass 1 through this page |
* selected an editing button on Pass 1 through this page |
| * ====================================================================== |
* ====================================================================== |
| */ |
*/ |
| if ($this->add_operation() || $this->more_operation() |
if ($this->add_operation() |
| || $this->change_operation() || $this->delete_operation() |
|| $this->change_operation() || $this->delete_operation() |
| || $this->view_operation() || $this->copy_operation()) { |
|| $this->view_operation() || $this->copy_operation()) { |
| $this->display_record(); |
$this->display_record(); |
| Line 2668 echo '<h5>'.mysql_affected_rows ().' '.$ |
|
| Line 2653 echo '<h5>'.mysql_affected_rows ().' '.$ |
|
| $this->list_table(); |
$this->list_table(); |
| } |
} |
| |
|
| //phpinfo(); |
global $phpMyEdit_timer; |
| global $timer; |
if ($this->display['time'] && $phpMyEdit_timer) { |
| if ($this->display['time'] && $timer) { |
echo $phpMyEdit_timer->end(); |
| echo $timer->end(); |
|
| } |
} |
| } /* }}} */ |
} /* }}} */ |
| |
|
| Line 2763 echo '<h5>'.mysql_affected_rows ().' '.$ |
|
| Line 2747 echo '<h5>'.mysql_affected_rows ().' '.$ |
|
| /* |
/* |
| * form variables all around |
* form variables all around |
| */ |
*/ |
| //global $operation, $apply, $fl, $fm, $sfn, $qfn, $sw, $rec, $prev, $next; |
|
| //global $saveadd, $moreadd, $savechange, $savedelete; |
|
| |
|
| $this->operation = $this->get_cgi_var('operation'); |
$this->operation = $this->get_cgi_var('operation'); |
| $this->apply = $this->get_cgi_var('apply'); |
$this->apply = $this->get_cgi_var('apply'); |
| Line 2787 echo '<h5>'.mysql_affected_rows ().' '.$ |
|
| Line 2769 echo '<h5>'.mysql_affected_rows ().' '.$ |
|
| $this->savedelete = $this->get_cgi_var('savedelete'); |
$this->savedelete = $this->get_cgi_var('savedelete'); |
| |
|
| /* |
/* |
| * Extract SQL Field Names and number of fields |
* Extract SQL Field Names and number of fields |
| */ |
*/ |
| $this->guidance = false; |
$this->guidance = false; |
| $field_num = 0; |
$field_num = 0; |
| Line 2797 echo '<h5>'.mysql_affected_rows ().' '.$ |
|
| Line 2779 echo '<h5>'.mysql_affected_rows ().' '.$ |
|
| if ($sfn == '' && $akey == $sort_field) { |
if ($sfn == '' && $akey == $sort_field) { |
| $this->sfn = $field_num; |
$this->sfn = $field_num; |
| } |
} |
| if ($this->displayed($field_num)) |
/* We must use here displayed() function, because displayed[] array |
| |
is not created yet. We will simultaneously create that array as well. */ |
| |
if ($this->displayed[$field_num] = $this->displayed($field_num)) { |
| $num_fields_displayed++; |
$num_fields_displayed++; |
| |
} |
| |
/* I *really* want to know what does this foreach() do! |
| |
-- Nepto [17/10/2002] */ |
| if (is_array($aval['values']) && (! $aval['values']['table'])) { |
if (is_array($aval['values']) && (! $aval['values']['table'])) { |
| $values = array(); |
$values = array(); |
| foreach ($aval['values'] as $val) { |
foreach ($aval['values'] as $val) { |
| $values[$val]=$val; |
$values[$val] = $val; |
| } |
} |
| $aval['values'] = $values; |
$aval['values'] = $values; |
| } |
} |
| $this->fdd[$field_num] = $aval; |
$this->fdd[$field_num] = $aval; |
| /* |
$aval['help'] && $this->guidance = true; |
| // prep for full text search |
|
| if ($aval['type'] == 'string' || $aval['type'] == 'blob') { |
|
| $this->string_fields[] = $akey; |
|
| } |
|
| */ |
|
| if ($aval['help']) |
|
| $this->guidance = true; |
|
| $field_num++; |
$field_num++; |
| } |
} |
| $this->num_fds = $field_num; |
|
| $this->num_fields_displayed = $num_fields_displayed; |
$this->num_fds = $field_num; |
| |
$this->num_fields_displayed = $num_fields_displayed; |
| $this->key_num = array_search($this->key,$this->fds); |
$this->key_num = array_search($this->key,$this->fds); |
| |
|
| /* |
/* |
| * Constants |
* Constants |
| */ |
*/ |
| |
|
| // code to use this is commented out |
// code to use this is commented out |
| $this->sql_aggrs = array(''=>'','sum'=>'Total','avg'=>'Average','min'=>'Minimum','max'=>'Maximum','count'=>'Count'); |
$this->sql_aggrs = array(''=>'','sum'=>'Total','avg'=>'Average','min'=>'Minimum','max'=>'Maximum','count'=>'Count'); |
| |
|
| // to support quick type checking |
// to support quick type checking |
| $this->stringTypes = array('string','blob','set','enum'); |
$this->stringTypes = array('string','blob','set','enum'); |
| $this->numberTypes = array('int','real'); |
$this->numberTypes = array('int','real'); |
| $this->dateTypes = array('date','datetime','timestamp','time','year'); |
$this->dateTypes = array('date','datetime','timestamp','time','year'); |
| |
|
| // mdate constants |
// mdate constants |
| $this->mdate_masks = array( |
$this->mdate_masks = array( |
| 'date'=>'%Y-%m-%d', |
'date'=>'%Y-%m-%d', |
| 'datetime'=>'%Y-%m-%d %H:%i:%s', |
'datetime'=>'%Y-%m-%d %H:%i:%s', |
| 'timestamp'=>'%Y%m%d%H%i%s', |
'timestamp'=>'%Y%m%d%H%i%s', |
| 'time'=>'%H:%i:%s', |
'time'=>'%H:%i:%s', |
| 'year'=>'%Y'); |
'year'=>'%Y'); |
| |
|
| $this->mdate_daterange = range(date('Y')-10,date('Y')+10); |
$this->mdate_daterange = range(date('Y')-10,date('Y')+10); |
| |
|
| $this->months_short = array( |
$this->months_short = array( |
| '~~PME~~'=>0, |
'~~PME~~'=>0, |
| 'Jan'=>1, 'Feb'=>2, 'Mar'=>3, 'Apr'=>4, |
'Jan'=>1, 'Feb'=>2, 'Mar'=>3, 'Apr'=>4, |
| 'May'=>5, 'Jun'=>6, 'Jul'=>7, 'Aug'=>8, |
'May'=>5, 'Jun'=>6, 'Jul'=>7, 'Aug'=>8, |
| 'Sep'=>9, 'Oct'=>10, 'Nov'=>11, 'Dec'=>12); |
'Sep'=>9, 'Oct'=>10, 'Nov'=>11, 'Dec'=>12); |
| $this->months_long = array( |
$this->months_long = array( |
| '~~PME~~'=>0, |
'~~PME~~'=>0, |
| 'January'=>1,'February'=>2,'March'=>3, |
'January'=>1,'February'=>2,'March'=>3, |
| 'April'=>4,'May'=>5,'June'=>6, |
'April'=>4,'May'=>5,'June'=>6, |
| 'July'=>7,'August'=>8,'September'=>9, |
'July'=>7,'August'=>8,'September'=>9, |
| 'October'=>10,'November'=>11,'December'=>12); |
'October'=>10,'November'=>11,'December'=>12); |
| $this->months_long_keys = array_keys($this->months_long); |
$this->months_long_keys = array_keys($this->months_long); |
| |
|
| /* If you are phpMyEdit developer, set this to 1. |
/* If you are phpMyEdit developer, set this to 1. |
| You can also hide some new unfinished and/or untested features under |
You can also hide some new unfinished and/or untested features under |
| if ($this->development) { new_feature(); } statement. |
if ($this->development) { new_feature(); } statement. |
| |
|
| Also note, that this is currently unused. */ |
Also note, that this is currently unused. */ |
| $this->development = 0; |
$this->development = 0; |
| |
|
| // Call to Action |
// Call to Action |
| // Moved this from the setup.php generated file to here |
// Moved this from the setup.php generated file to here |
| $this->execute(); |
$this->execute(); |
| } /* }}} */ |
} /* }}} */ |
| |
|
| } // end of phpMyEdit class |
} // end of phpMyEdit class |
| |
|