| version 1.25, 2002/11/02 19:19:34 |
version 1.26, 2002/11/03 15:29:10 |
|
|
| * http://www.platon.sk/projects/phpMyEdit/ |
* http://www.platon.sk/projects/phpMyEdit/ |
| */ |
*/ |
| |
|
| /* $Platon: phpMyEdit/phpMyEdit.class.php,v 1.24 2002/11/02 13:24:28 nepto Exp $ */ |
/* $Platon: phpMyEdit/phpMyEdit.class.php,v 1.25 2002/11/02 19:19:34 nepto Exp $ */ |
| |
|
| /* phpMyEdit intro {{{ */ |
/* phpMyEdit intro {{{ */ |
| /* |
/* |
|
|
| */ |
*/ |
| /* }}} */ |
/* }}} */ |
| |
|
| if (@require_once dirname(__FILE__).'/timer.class') { |
if (@include_once dirname(__FILE__).'/timer.class') { |
| $phpMyEdit_timer = new timerClass(); |
$phpMyEdit_timer = new timerClass(); |
| } |
} |
| |
|
|
|
| return $ret; |
return $ret; |
| } /* }}} */ |
} /* }}} */ |
| |
|
| function htmlDisplay($field, $str, $usemask = true, $usecodec = true, $disallow_empty = true, $escape = true) /* {{{ */ |
|
| { |
|
| // undo the add slashes |
|
| $str = stripslashes($str); |
|
| |
|
| // if there's a field mask, use it as first arg to sprintf |
|
| if (isset($field['mask']) && $usemask) { |
|
| $str = sprintf($field['mask'], $str); |
|
| } |
|
| if ($usecodec) { // if db codec is in effect, use it |
|
| isset($field['dbdecode']) && $str = eval('return '.$field['dbdecode'].'(\''.$str.'\');'); |
|
| $escape && $str = htmlspecialchars($str); |
|
| } |
|
| if ($disallow_empty) { |
|
| strlen($str) <= 0 && $str = ' '; |
|
| } |
|
| |
|
| return $str; |
|
| } /* }}} */ |
|
| |
|
| function encode($field,$str) /* {{{ */ |
function encode($field,$str) /* {{{ */ |
| { |
{ |
| if (isset($field['dbencode'])) { |
if (isset($field['dbencode'])) { |
|
|
| function create_javascripts() /* {{{ */ |
function create_javascripts() /* {{{ */ |
| { |
{ |
| /* |
/* |
| Need a lot of work in here |
Need a lot of work in here |
| using something like: |
using something like: |
| $fdd['fieldname']['validate']['js_regex']='/something/'; |
$fdd['fieldname']['validate']['js_regex']='/something/'; |
| $fdd['fieldname']['validate']['php_regex']='something'; |
$fdd['fieldname']['validate']['php_regex']='something'; |
| */ |
*/ |
| |
$page_name = htmlspecialchars($this->page_name); |
| |
|
| |
if ($this->add_operation() || $this->change_operation()) { |
| |
$required_ar = array(); |
| |
for ($k = 0; $k < $this->num_fds; $k++) { |
| |
if ($this->displayed[$k] |
| |
&& $this->fdd[$k]['required'] |
| |
&& ! $this->col_has_values($k)) { |
| |
$required_ar[] = $k; |
| |
if (isset($this->fdd[$k]['regex']['js'])) { |
| |
/* TODO: Use a javascript regex to validate it */ |
| |
} |
| |
} |
| |
} |
| |
|
| if ($this->add_operation() or $this->change_operation()) { |
if (count($required_ar) > 0) { |
| echo '<script type="text/javascript">'."\n"; |
echo '<script type="text/javascript"><!--'."\n"; |
| echo '// <!-- |
echo ' |
| function form_control(theForm) |
function form_control(theForm) |
| { |
{'."\n"; |
| '; // echo |
foreach ($required_ar as $field_num) { |
| for ($k = 0; $k < $this->num_fds; $k++) { |
echo ' |
| if ($this->displayed[$k] && $this->fdd[$k]['required'] && !$this->col_has_values($k)) { |
if (theForm.'.$this->fds[$field_num].'.value.length == 0) { |
| if (isset($this->fdd[$k]['regex']['js'])) { |
alert("'.$this->labels['Please enter'].' '.$this->fdd[$field_num]['name'].'."); |
| // use a javascript regex to validate it |
theForm.'.$this->fds[$field_num].'.focus(); |
| // |
|
| // XXX not done yet |
|
| // |
|
| echo " |
|
| if ( theForm.".$this->fds[$k].".value.length == 0 ) { |
|
| alert( '".$this->labels['Please enter']." ".$this->fdd[$k]['name']." .' ); |
|
| theForm.".$this->fds[$k].".focus(); |
|
| return false; |
return false; |
| } |
}'."\n"; |
| "; // echo |
} |
| } else { |
echo ' |
| // confirm that it's not empty |
theForm.submit(); |
| echo " |
return true; |
| if ( theForm.".$this->fds[$k].".value.length == 0 ) { |
}'."\n\n"; |
| alert( '".$this->labels['Please enter']." ".$this->fdd[$k]['name']." .' ); |
echo '// --></script>' . "\n"; |
| theForm.".$this->fds[$k].".focus(); |
echo '<form action="'.$page_name.'" method="POST" onSubmit="return form_control(this);">'."\n"; |
| return false; |
return true; |
| } |
|
| "; // echo |
|
| } |
} |
| } |
} |
| } |
|
| |
|
| echo ' |
|
| theForm.submit(); |
|
| return true; |
|
| } |
|
| //--> |
|
| </script>' . "\n"; // echo |
|
| |
|
| echo '<form action="'.$this->page_name.'" method="POST" onSubmit="return form_control(this);">'."\n"; |
echo '<form action="'.$page_name.'" method="POST">'."\n"; |
| } else { |
return true; |
| echo '<form action="'.$this->page_name.'" method="POST">'."\n"; |
|
| } |
|
| } /* }}} */ |
} /* }}} */ |
| |
|
| /* |
/* |
|
|
| } |
} |
| echo 'name="'.$this->fds[$k].'" wrap="virtual">'; |
echo 'name="'.$this->fds[$k].'" wrap="virtual">'; |
| echo $this->htmlDisplay( |
echo $this->htmlDisplay( |
| $this->fdd[$k], |
$this->fdd[$k], $this->fdd[$k]['default'], |
| $this->fdd[$k]['default'], |
false, false, false); |
| false, false); |
|
| echo '</textarea></td>'."\n"; |
echo '</textarea></td>'."\n"; |
| } else { |
} else { |
| // Simple edit box required |
// Simple edit box required |
| $type = $this->fdd[$k]['type']; |
$type = $this->fdd[$k]['type']; |
| echo '<td>'; |
echo '<td>'; |
| if ($this->readonly($k)) { |
if ($this->readonly($k)) { |
| echo $this->htmlDisplay($this->fdd[$k],'',false,false) |
echo $this->htmlDisplay($this->fdd[$k], '', false, false, false) |
| .'<input type="hidden" name="' |
.'<input type="hidden" name="' |
| .$this->fds[$k] |
.$this->fds[$k] |
| .'" value="' |
.'" value="' |
| .$this->htmlDisplay($this->fdd[$k],$this->fdd[$k]['default'],false,false) |
.$this->htmlDisplay($this->fdd[$k], $this->fdd[$k]['default'], |
| |
false, false, false) |
| .'" />'; |
.'" />'; |
| } else { |
} else { |
| if ($this->col_is_string($k) || $this->col_is_number($k)) { |
if ($this->col_is_string($k) || $this->col_is_number($k)) { |
|
|
| echo '<input type="text" name="'.$this->fds[$k] |
echo '<input type="text" name="'.$this->fds[$k] |
| .'" size="'.$size.'" maxlength="'.$maxwidth.'" value="' |
.'" size="'.$size.'" maxlength="'.$maxwidth.'" value="' |
| .$this->htmlDisplay($this->fdd[$k],$this->fdd[$k]['default'], |
.$this->htmlDisplay($this->fdd[$k],$this->fdd[$k]['default'], |
| false, false) |
false, false, false) |
| .'" />'; |
.'" />'; |
| } 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" name="'.$this->fds[$k] |
echo '<input type="text" name="'.$this->fds[$k] |
| .'" size="'.$size.'" maxlength="'.$maxwidth.'" value="' |
.'" size="'.$size.'" maxlength="'.$maxwidth.'" value="' |
| .$this->htmlDisplay($this->fdd[$k],$this->fdd[$k]['default'], |
.$this->htmlDisplay($this->fdd[$k],$this->fdd[$k]['default'], |
| false, false) |
false, false, false) |
| .'" />'; |
.'" />'; |
| } else { |
} else { |
| // unknown type |
// unknown type |
| echo '<input type="text" name="'.$this->fds[$k].'" value="' |
echo '<input type="text" name="'.$this->fds[$k].'" value="' |
| .$this->htmlDisplay($this->fdd[$k],$this->fdd[$k]['default'], |
.$this->htmlDisplay($this->fdd[$k],$this->fdd[$k]['default'], |
| false, false) |
false, false, false) |
| .'" />'; |
.'" />'; |
| } |
} |
| } |
} |
|
|
| 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["qf$k"], false) |
.'" value="'.$this->htmlDisplay($this->fdd[$k], $row["qf$k"], |
| |
false, true, 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["qf$k"], false) |
.'" value="'.$this->htmlDisplay($this->fdd[$k], $row["qf$k"], |
| |
false, true, 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["qf$k"], false) |
.'" value="'.$this->htmlDisplay($this->fdd[$k], $row["qf$k"], |
| |
false, true, false) |
| .'" />'."\n"; |
.'" />'."\n"; |
| } elseif ($this->displayed[$k]) { |
} elseif ($this->displayed[$k]) { |
| echo '<tr>'."\n"; |
echo '<tr>'."\n"; |
|
|
| echo ' wrap="virtual"'; |
echo ' wrap="virtual"'; |
| } |
} |
| echo '>'; |
echo '>'; |
| echo $this->htmlDisplay($this->fdd[$k], $row["qf$k"], false); |
echo $this->htmlDisplay($this->fdd[$k], $row["qf$k"], false, true, 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["qf$k"],false) |
.$this->htmlDisplay($this->fdd[$k], $row["qf$k"], |
| |
false, true, 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["qf$k"],false) |
.$this->htmlDisplay($this->fdd[$k], $row["qf$k"], |
| .'" size="'.$displaylen.'"/>'; |
false, true, false) |
| |
.'" 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["qf$k"],false).'" />'; |
.$this->htmlDisplay($this->fdd[$k],$row["qf$k"], false, true, false).'">'; |
| } |
} |
| echo "\n"; |
echo "\n"; |
| } // if elseif else |
} // if elseif else |
|
|
| { |
{ |
| echo '<td>'; |
echo '<td>'; |
| if ($this->is_values2($k, $row["qf$k"])) { |
if ($this->is_values2($k, $row["qf$k"])) { |
| echo nl2br($this->htmlDisplay($k, $this->fdd[$k]['values2'][$row['qf'.$k.'_idx']], true, true, true, false)); |
echo nl2br($this->htmlDisplay($k, $this->fdd[$k]['values2'][$row['qf'.$k.'_idx']], |
| |
true, true, true, false)); |
| } else { |
} else { |
| echo nl2br($this->htmlDisplay($this->fdd[$k], $row["qf$k"])); |
echo nl2br($this->htmlDisplay($this->fdd[$k], $row["qf$k"])); |
| } |
} |
|
|
| return $ret; |
return $ret; |
| } /* }}} */ |
} /* }}} */ |
| |
|
| |
/** |
| |
* Returns HTML text |
| |
* |
| |
* @param field field name/number |
| |
* @param str str to print |
| |
* @param usemask flag if field mask should be used |
| |
* @param usecodec flag if field codec should be used |
| |
* @param disallow_empty flag if empty string is forbidden on output |
| |
* @param escape flag if output should be HTML escaped |
| |
*/ |
| |
function htmlDisplay($field, $str, /* ...) {{{ */ |
| |
$usemask = true, |
| |
$usecodec = true, |
| |
$disallow_empty = true, |
| |
$escape = true) |
| |
{ |
| |
// undo the add slashes |
| |
$str = stripslashes($str); |
| |
|
| |
// if there's a field mask, use it as first arg to sprintf |
| |
if (isset($field['mask']) && $usemask) { |
| |
$str = sprintf($field['mask'], $str); |
| |
} |
| |
// if db codec is in effect, use it |
| |
if ($usecodec && isset($field['dbdecode'])) { |
| |
$str = eval('return '.$field['dbdecode'].'(\''.$str.'\');'); |
| |
} |
| |
if ($escape) { |
| |
$str = htmlspecialchars($str); |
| |
} |
| |
if ($disallow_empty) { |
| |
strlen($str) <= 0 && $str = ' '; |
| |
} |
| |
return $str; |
| |
} /* }}} */ |
| |
|
| function get_qf_hidden_fields() /* {{{ */ |
function get_qf_hidden_fields() /* {{{ */ |
| { |
{ |
|
|
| $shortdisp = substr($shortdisp,0,$this->fdd[$k]['trimlen']-3).'...'; |
$shortdisp = substr($shortdisp,0,$this->fdd[$k]['trimlen']-3).'...'; |
| } |
} |
| } |
} |
| echo nl2br($this->htmlDisplay($this->fdd[$k], $shortdisp, true, true, true, $escape_flag)); |
echo nl2br($this->htmlDisplay($this->fdd[$k], $shortdisp, |
| |
true, true, true, $escape_flag)); |
| } |
} |
| } else { |
} else { |
| // it's hidden or a password |
// it's hidden or a password |
| Line 2660 echo '<h5>'.mysql_affected_rows ().' '.$ |
|
| Line 2677 echo '<h5>'.mysql_affected_rows ().' '.$ |
|
| /* |
/* |
| * Error handling function |
* Error handling function |
| */ |
*/ |
| function error($message) |
function error($message) /* {{{ */ |
| { |
{ |
| echo '<h1>phpMyEdit error: '.htmlspecialchars($message).'</h1>'."\n"; |
echo '<h1>phpMyEdit error: '.htmlspecialchars($message).'</h1>'."\n"; |
| return false; |
return false; |
| } |
} /* }}} */ |
| |
|
| /* |
/* |
| * Database connection function |
* Database connection function |