| version 1.15, 2002/10/18 20:58:11 |
version 1.16, 2002/10/20 22:04:19 |
|
|
| * http://www.platon.sk/projects/phpMyEdit/ |
* http://www.platon.sk/projects/phpMyEdit/ |
| */ |
*/ |
| |
|
| /* $Platon: phpMyEdit/phpMyEdit.class.php,v 1.14 2002/10/17 21:06:46 nepto Exp $ */ |
/* $Platon: phpMyEdit/phpMyEdit.class.php,v 1.15 2002/10/18 20:58:11 nepto Exp $ */ |
| |
|
| /* phpMyEdit intro {{{ */ |
/* phpMyEdit intro {{{ */ |
| /* |
/* |
|
|
| { |
{ |
| $fields = array(); |
$fields = array(); |
| for ($k = 0; $k < $this->num_fds; $k++) { |
for ($k = 0; $k < $this->num_fds; $k++) { |
| if (! $this->displayed[$k]) |
if (! $this->displayed[$k] && $k != $this->key_num) |
| continue; |
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; |
|
|
| } /* }}} */ |
} /* }}} */ |
| |
|
| /* |
/* |
| * get_cgi_var() |
|
| */ |
|
| function get_cgi_var($name, $default_value = null) /* {{{ */ |
|
| { |
|
| global $HTTP_GET_VARS; |
|
| $var = $HTTP_GET_VARS[$name]; |
|
| |
|
| if (! isset($var)) { |
|
| global $HTTP_POST_VARS; |
|
| $var = $HTTP_POST_VARS[$name]; |
|
| } |
|
| |
|
| if (isset($var)) { |
|
| if (is_array($var)) { |
|
| foreach (array_keys($var) as $key) { |
|
| $var[$key] = stripslashes($var[$key]); |
|
| } |
|
| } else { |
|
| $var = stripslashes($var); |
|
| } |
|
| } else { |
|
| $var = $default_value; |
|
| } |
|
| |
|
| return $var; |
|
| } /* }}} */ |
|
| |
|
| /* |
|
| * functions for get/post/query args |
* functions for get/post/query args |
| */ |
*/ |
| |
|
|
|
| function copy_operation() { return $this->operation == $this->labels['Copy'] && $this->add_enabled(); } |
function copy_operation() { return $this->operation == $this->labels['Copy'] && $this->add_enabled(); } |
| function delete_operation() { return $this->operation == $this->labels['Delete'] && $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 view_operation() { return $this->operation == $this->labels['View'] && $this->view_enabled(); } |
| function filter_operation() { return $this->fl && $this->filter_enabled(); } // huh?! XXX FIXME |
function filter_operation() { return $this->fl && $this->filter_enabled(); } |
| |
function next_operation() { return $this->next == $this->labels['Next']; } |
| |
function prev_operation() { return $this->prev == $this->labels['Prev']; } |
| |
|
| |
function is_values2($k, $val = 'X') /* {{{ */ |
| |
{ |
| |
return $val === null || |
| |
(isset($this->fdd[$k]['values2']) && !isset($this->fdd[$k]['values']['table'])); |
| |
} /* }}} */ |
| |
|
| function processed($k) /* {{{ */ |
function processed($k) /* {{{ */ |
| { |
{ |
|
|
| function display_delete_field($row, $k) /* {{{ */ |
function display_delete_field($row, $k) /* {{{ */ |
| { |
{ |
| echo '<td>'; |
echo '<td>'; |
| if ($row["qf$k"] === null) { |
if ($this->is_values2($k, $row["qf$k"])) { |
| echo $this->fdd[$k]['values2'][$row['qf'.$k.'_idx']]; |
echo $this->fdd[$k]['values2'][$row['qf'.$k.'_idx']]; |
| } else if ($row["qf$k"] == '') { |
} else if ($row["qf$k"] == '') { |
| echo ' '; |
echo ' '; |
|
|
| $ret .= ' selected'; |
$ret .= ' selected'; |
| $found = true; |
$found = true; |
| } |
} |
| $ret .= '>'.htmlspecialchars(urldecode($value)).'</option>'."\n"; |
$ret .= '>'.htmlspecialchars(urldecode(strip_tags($value))).'</option>'."\n"; |
| //debug_var("array search $key",is_numeric(array_search($key,$selected))); |
//debug_var("array search $key",is_numeric(array_search($key,$selected))); |
| } |
} |
| $ret .= '</select>'; |
$ret .= '</select>'; |
|
|
| } |
} |
| return $x; |
return $x; |
| } /* }}} */ |
} /* }}} */ |
| |
|
| function get_http_get_var_by_name($name) /* {{{ */ |
function get_cgi_var($name, $default_value = null) /* {{{ */ |
| { |
{ |
| |
//echo 'get_cgi_var(): requested: '.htmlspecialchars($name).'<br>'; |
| |
if (isset($this) && isset($this->cgi['overwrite'][$name])) { |
| |
return $this->cgi['overwrite'][$name]; |
| |
} |
| global $HTTP_GET_VARS; |
global $HTTP_GET_VARS; |
| |
$var = $HTTP_GET_VARS[$name]; |
| |
|
| |
if (! isset($var)) { |
| |
global $HTTP_POST_VARS; |
| |
$var = $HTTP_POST_VARS[$name]; |
| |
} |
| |
|
| if (is_array($HTTP_GET_VARS)) |
if (isset($var)) { |
| $v = $HTTP_GET_VARS[$name]; |
if (is_array($var)) { |
| |
foreach (array_keys($var) as $key) { |
| |
$var[$key] = stripslashes($var[$key]); |
| |
} |
| |
} else { |
| |
$var = stripslashes($var); |
| |
} |
| |
} else { |
| |
$var = $default_value; |
| |
} |
| |
|
| |
if (isset($this) && $var === null && isset($this->cgi['append'][$name])) { |
| |
return $this->cgi['append'][$name]; |
| |
} |
| |
|
| |
return $var; |
| |
} /* }}} */ |
| |
|
| |
function get_http_get_var_by_name($name) /* {{{ */ |
| |
{ |
| |
return phpMyEdit::get_cgi_var($name); |
| |
/* |
| |
global $HTTP_GET_VARS; |
| |
|
| |
if (is_array($HTTP_GET_VARS)) |
| |
$v = $HTTP_GET_VARS[$name]; |
| // $v could be an array if we allowed bidimensional form fields |
// $v could be an array if we allowed bidimensional form fields |
| return $v; |
return $v; |
| |
*/ |
| } /* }}} */ |
} /* }}} */ |
| |
|
| function get_http_post_var_by_name ($name) /* {{{ */ |
function get_http_post_var_by_name ($name) /* {{{ */ |
| { |
{ |
| global $HTTP_POST_VARS; |
return phpMyEdit::get_cgi_var($name); |
| |
/* |
| |
global $HTTP_POST_VARS; |
| |
|
| if (is_array($HTTP_POST_VARS)) |
if (is_array($HTTP_POST_VARS)) |
| $v = $HTTP_POST_VARS[$name]; |
$v = $HTTP_POST_VARS[$name]; |
| // $v could be an array if we allowed bidimensional form fields |
// $v could be an array if we allowed bidimensional form fields |
| return $v; |
return $v; |
| |
*/ |
| } /* }}} */ |
} /* }}} */ |
| |
|
| /* |
/* |
|
|
| */ |
*/ |
| function display_list_table_buttons($total_recs) /* {{{ */ |
function display_list_table_buttons($total_recs) /* {{{ */ |
| { |
{ |
| |
// Are we doing a listall? |
| |
$listall = $this->inc <= 0; |
| |
|
| // note that <input disabled isn\'t valid HTML but most browsers support it |
// note that <input disabled isn\'t valid HTML but most browsers support it |
| // TODO: classify this table and cells |
// TODO: classify this table and cells |
| echo '<table border=0 cellpadding=0 cellspacing=0 width="100%" style="border:0;padding:0;">'; |
echo '<table border=0 cellpadding=0 cellspacing=0 width="100%" style="border:0;padding:0;">'; |
| echo '<tr><td align=left style="text-align:left;border:0;padding:0;" nowrap>' . "\n"; |
echo '<tr><td align=left style="text-align:left;border:0;padding:0;" nowrap>' . "\n"; |
| if ($this->fm > 0) { |
if ($this->fm > 0 && ! $listall) { |
| echo '<input type="submit" name="prev" value="'.$this->labels['Prev'].'"> '; |
echo '<input type="submit" name="prev" value="'.$this->labels['Prev'].'"> '; |
| } else { |
} else { |
| echo '<input disabled type="submit" name="dprev" value="'.$this->labels['Prev'].'"> '; |
echo '<input disabled type="submit" name="dprev" value="'.$this->labels['Prev'].'"> '; |
|
|
| } |
} |
| |
|
| |
|
| if (($this->fm+$this->inc) < $total_recs) { |
if ($this->fm + $this->inc < $total_recs && ! $listall) { |
| echo '<input type="submit" name="next" value="'.$this->labels['Next'].'">'; |
echo '<input type="submit" name="next" value="'.$this->labels['Next'].'">'; |
| } else { |
} else { |
| echo '<input disabled type="submit" name="dnext" value="'.$this->labels['Next'].'">'; |
echo '<input disabled type="submit" name="dnext" value="'.$this->labels['Next'].'">'; |
|
|
| echo $this->labels['Page'].': 1 '.$this->labels['of'].' 1'; |
echo $this->labels['Page'].': 1 '.$this->labels['of'].' 1'; |
| } else { |
} else { |
| echo $this->labels['Page'].': '; |
echo $this->labels['Page'].': '; |
| echo (($this->fm/$this->inc)+1); |
echo (($this->fm / $this->inc)+1); |
| echo ' '.$this->labels['of'].' '; |
echo ' '.$this->labels['of'].' '; |
| echo max(1,ceil($total_recs/abs($this->inc))); |
echo max(1, ceil($total_recs / abs($this->inc))); |
| } |
} |
| echo ' '.$this->labels['Records'].': '.$total_recs; |
echo ' '.$this->labels['Records'].': '.$total_recs; |
| echo '</td></tr></table>'."\n"; |
echo '</td></tr></table>'."\n"; |
|
|
| if ($this->fm == '') { |
if ($this->fm == '') { |
| $this->fm = 0; |
$this->fm = 0; |
| } |
} |
| if ($this->prev == $this->labels['Prev']) { // Prev |
if ($this->prev_operation()) { |
| $this->fm = $this->fm - $this->inc; |
$this->fm = $this->fm - $this->inc; |
| if ($this->fm < 0) { |
if ($this->fm < 0) { |
| $this->fm = 0; |
$this->fm = 0; |
| } |
} |
| } |
} |
| if ($this->next == $this->labels['Next']) { // Next |
if ($this->next_operation()) { |
| $this->fm += $this->inc; |
$this->fm += $this->inc; |
| } |
} |
| |
|
|
|
| } |
} |
| |
|
| // Are we doing a listall? |
// Are we doing a listall? |
| $listall = $this->inc < 0; |
$listall = $this->inc <= 0; |
| |
|
| /* |
/* |
| * Display the MySQL table in an HTML table |
* Display the MySQL table in an HTML table |
|
|
| $mc = $this->web2plain($$lc); // get the comparison operator for numeric/date types |
$mc = $this->web2plain($$lc); // get the comparison operator for numeric/date types |
| |
|
| $widthStyle = ''; |
$widthStyle = ''; |
| if (isset($this->fdd[$fd]['width'])); |
if (isset($this->fdd[$fd]['width'])) { |
| $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]) { |
|
|
| } 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 |
| if (! $this->password($k) && ! $this->hidden($k)) { |
if (! $this->password($k) && ! $this->hidden($k)) { |
| |
$maxlen = intval($this->fdd[$k]['maxlen']); |
| |
!$maxlen && $maxlen = mysql_field_len($res, "qf$k"); |
| |
$size = $maxlen < 30 ? min($maxlen, 8) : 12; |
| if ($this->col_is_string($k)) { |
if ($this->col_is_string($k)) { |
| // it's treated as a string |
// it's treated as a string |
| echo '<input type="text" name="qf'.$k.'"'; |
echo '<input type="text" name="qf'.$k.'"'; |
| echo ' value="'.stripslashes($m).'"'; |
echo ' value="'.stripslashes($m).'"'; |
| if ($type != 'blob') { |
if ($type != 'blob') { |
| echo ' size="'.min($this->fdd[$k]['maxlen'],20).'"'; |
echo ' size="'.$size.'" maxlength="'.$maxlen.'"'; |
| echo ' maxlength="'.$this->fdd[$k]['maxlen'].'"'; |
|
| } |
} |
| echo '/>'; |
echo '/>'; |
| } elseif ($this->col_is_date($k)) { |
} elseif ($this->col_is_date($k)) { |
|
|
| echo '<input type="text" name="qf'.$k.'"'; |
echo '<input type="text" name="qf'.$k.'"'; |
| echo ' value="'.stripslashes($m).'"'; |
echo ' value="'.stripslashes($m).'"'; |
| if ($type != 'blob') { |
if ($type != 'blob') { |
| echo ' size="'.min($this->fdd[$k]['maxlen'],20).'"'; |
echo ' size="'.$size.'" maxlength="'.$maxlen.'"'; |
| echo ' maxlength="'.$this->fdd[$k]['maxlen'].'"'; |
|
| } |
} |
| echo '/>'; |
echo '/>'; |
| } elseif ($this->col_is_number($k)) { |
} elseif ($this->col_is_number($k)) { |
| // it's a number |
// it's a number |
| echo $this->htmlSelect($l.'_comp',$comp_ops,$$lc); |
echo $this->htmlSelect($l.'_comp',$comp_ops,$$lc); |
| // it's treated as a string |
// it's treated as a string |
| echo '<input type="text" name="qf'.$k.'"'. |
echo '<input type="text" name="qf'.$k.'"' |
| ' value="'.$m.'"'. |
.' value="'.$m.'"' |
| ' size="'.min($this->fdd[$k]['maxlen'],20).'"'. |
.' size="'.$size.'" maxlength="'.$maxlen.'"' |
| ' maxlength="'.$this->fdd[$k]['maxlen'].'"'. |
.'/>'; |
| '/>'; |
|
| } else { |
} else { |
| // type is 'unknown' or not set, it's treated as a string |
// type is 'unknown' or not set, it's treated as a string |
| echo '<input type="text" name="qf'.$k.'"'; |
echo '<input type="text" name="qf'.$k.'"'; |
| echo ' value="'.stripslashes($m).'"'; |
echo ' value="'.stripslashes($m).'"'; |
| if ($type != 'blob') { |
if ($type != 'blob') { |
| echo ' size="'.min($this->fdd[$k]['maxlen'],20).'"'; |
echo ' size="'.$size.'" maxlength="'.$maxlen.'"'; |
| echo ' maxlength="'.$this->fdd[$k]['maxlen'].'"'; |
|
| } |
} |
| echo '/>'; |
echo '/>'; |
| } |
} |
|
|
| echo nl2br($this->htmlDisplay($this->fdd[$k], $shortdisp)); |
echo nl2br($this->htmlDisplay($this->fdd[$k], $shortdisp)); |
| } else { |
} else { |
| // it's a normal field |
// it's a normal field |
| if ($row["qf$k"] === null) { |
if ($this->is_values2($k, $row["qf$k"])) { |
| $shortdisp = $this->fdd[$k]['values2'][$row['qf'.$k.'_idx']]; |
$shortdisp = $this->fdd[$k]['values2'][$row['qf'.$k.'_idx']]; |
| //$shortdisp .= ' ('.$row['qf'.$k.'_idx'].')'; |
//$shortdisp .= ' ('.$row['qf'.$k.'_idx'].')'; |
| !isset($shortdisp) && $shortdisp = ''; |
!isset($shortdisp) && $shortdisp = ''; |
| |
echo $shortdisp; |
| } else { |
} else { |
| if (isset($this->fdd[$k]['trimlen']) |
if (isset($this->fdd[$k]['trimlen']) |
| && strlen($row["qf$k"]) > $this->fdd[$k]['trimlen']) { |
&& strlen($row["qf$k"]) > $this->fdd[$k]['trimlen']) { |
|
|
| } else { |
} else { |
| $shortdisp = $row["qf$k"]; |
$shortdisp = $row["qf$k"]; |
| } |
} |
| |
echo nl2br($this->htmlDisplay($this->fdd[$k], $shortdisp)); |
| } |
} |
| echo nl2br($this->htmlDisplay($this->fdd[$k], $shortdisp)); |
|
| } |
} |
| } else { |
} else { |
| // it's hidden or a password |
// it's hidden or a password |
| Line 2604 echo '<h5>'.mysql_affected_rows ().' '.$ |
|
| Line 2627 echo '<h5>'.mysql_affected_rows ().' '.$ |
|
| * Creting URL variables |
* Creting URL variables |
| */ |
*/ |
| $this->url['images'] = 'images/'; |
$this->url['images'] = 'images/'; |
| |
isset($opts['url']['images']) && $this->url['images'] = $opts['url']['images']; |
| |
|
| /* |
/* |
| * Instance class variables |
* Instance class variables |
| Line 2620 echo '<h5>'.mysql_affected_rows ().' '.$ |
|
| Line 2644 echo '<h5>'.mysql_affected_rows ().' '.$ |
|
| $this->options = $opts['options']; |
$this->options = $opts['options']; |
| $this->fdd = $opts['fdd']; |
$this->fdd = $opts['fdd']; |
| $this->multiple = intval($opts['multiple']); |
$this->multiple = intval($opts['multiple']); |
| if ($this->multiple <= 0) { |
$this->multiple <= 0 && $this->multiple = 2; |
| $this->multiple = 2; |
|
| } |
|
| $this->display = $opts['display']; |
$this->display = $opts['display']; |
| if ($opts['language']) { |
if ($opts['language']) { |
| $this->labels = $this->make_language_labels($opts['language']); |
$this->labels = $this->make_language_labels($opts['language']); |
| Line 2634 echo '<h5>'.mysql_affected_rows ().' '.$ |
|
| Line 2656 echo '<h5>'.mysql_affected_rows ().' '.$ |
|
| $this->triggers = $opts['triggers']; |
$this->triggers = $opts['triggers']; |
| $this->logtable = $opts['logtable']; |
$this->logtable = $opts['logtable']; |
| |
|
| |
|
| $this->page_name = $this->tb; |
$this->page_name = $this->tb; |
| if ($opts['page_name']) |
$opts['page_name'] && $this->page_name = $opts['page_name']; |
| $this->page_name = $opts['page_name']; |
|
| |
|
| // alternate row background colors |
// alternate row background colors |
| /* What's this?! |
/* What's this?! |
| Line 2668 echo '<h5>'.mysql_affected_rows ().' '.$ |
|
| Line 2688 echo '<h5>'.mysql_affected_rows ().' '.$ |
|
| $this->navigation .= 'D'; // down position is default |
$this->navigation .= 'D'; // down position is default |
| } |
} |
| |
|
| |
// CGI variables |
| |
$this->cgi['append'] = $opts['cgi']['append']; |
| |
$this->cgi['overwrite'] = $opts['cgi']['overwrite']; |
| |
|
| /* |
/* |
| * Find the URL to post forms |
* Find the URL to post forms |
| */ |
*/ |
| Line 2738 echo '<h5>'.mysql_affected_rows ().' '.$ |
|
| Line 2762 echo '<h5>'.mysql_affected_rows ().' '.$ |
|
| $this->guidance = false; |
$this->guidance = false; |
| $field_num = 0; |
$field_num = 0; |
| $num_fields_displayed = 0; |
$num_fields_displayed = 0; |
| |
$this->fds = array(); |
| foreach ($this->fdd as $akey => $aval) { |
foreach ($this->fdd as $akey => $aval) { |
| $this->fds[] = $akey; |
$this->fds[] = $akey; |
| if ($sfn == '' && $akey == $sort_field) { |
if ($sfn == '' && $akey == $sort_field) { |
| Line 2764 echo '<h5>'.mysql_affected_rows ().' '.$ |
|
| Line 2789 echo '<h5>'.mysql_affected_rows ().' '.$ |
|
| |
|
| $this->num_fds = $field_num; |
$this->num_fds = $field_num; |
| $this->num_fields_displayed = $num_fields_displayed; |
$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 |
| Line 2810 echo '<h5>'.mysql_affected_rows ().' '.$ |
|
| Line 2835 echo '<h5>'.mysql_affected_rows ().' '.$ |
|
| |
|
| // 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(); |
!isset($opts['execute']) && $opts['execute'] = 1; |
| |
$opts['execute'] && $this->execute(); |
| } /* }}} */ |
} /* }}} */ |
| |
|
| } // end of phpMyEdit class |
} // end of phpMyEdit class |