'.$qry.'

'); $res = mysql_db_query($database, $qry); while ($row = mysql_fetch_row($res)) { $values['option'][] = $row[0]; $values['value'][] = $row[1]; } return $values; } function fully_qualified_name($master_table, $field_defs, $field_name, $format='N') { if (isset($field_defs[$field_name]['values']['description'])) { $fqn = $field_defs[$field_name]['values']['table'].'.`'.$field_defs[$field_name]['values']['description'].'`'; } else { $fqn.= $master_table.'.`'.$field_name.'`'; if ( (isset($field_defs[$field_name]['format'])) && ($format == 'Y') ) { $fqn = 'DATE_FORMAT('.$fqn.',\''; $fqn = $fqn.'%'.$field_defs[$field_name]['format'][0].$field_defs[$field_name]['format'][3]; $fqn = $fqn.'%'.$field_defs[$field_name]['format'][1].$field_defs[$field_name]['format'][3]; $fqn = $fqn.'%'.$field_defs[$field_name]['format'][2].'\')'; } } return $fqn; } function create_column_list($master_table, $field_defs) { $select = 'SELECT DISTINCT'; $kwd = ' '; for ($k = 0; $k < $this->num_fds; $k++) { $fd = $this->fds[$k]; $select = $select.$kwd.$this->fully_qualified_name($master_table, $field_defs, $fd, 'Y'); $kwd = ','; } return $select; } function create_where_clause($master_table, $field_defs) { $kwd = ' WHERE ('; for ($k = 0 ; $k < $this->num_fds; $k++) { $fd = $this->fds[$k]; if (isset($field_defs[$fd]['values']['description'])) { $where = $where.$kwd.$master_table.'.`'.$this->fds[$k].'`='.$field_defs[$fd]['values']['table'].'.`'.$field_defs[$fd]['values']['column'].'`)'; $kwd = ' AND ('; } } return $where; } function create_from_clause($master_table, $field_defs) { $tbs[] = $master_table; for ($k = 0 ; $k < sizeof($this->fds); $k++) { $fd = $this->fds[$k]; if (isset($field_defs[$fd]['values']['description'])) { if (!in_array($field_defs[$fd]['values']['table'],$tbs)) { $tbs[]=$field_defs[$fd]['values']['table']; } } } $kwd = ''; $from = ' FROM '; for ($k = 0; $k < sizeof($tbs); $k++) { $from = $from.$kwd.$tbs[$k]; $kwd = ','; } return $from; } function add_enabled () { return (stristr ($this->options, 'A')); } function change_enabled () { return (stristr ($this->options, 'C')); } function delete_enabled () { return (stristr ($this->options, 'D')); } function filter_enabled () { return (stristr ($this->options, 'F')); } function initial_sort_suppressed () { return (stristr ($this->options, 'I')); } function add_operation () { return (($this->operation == $this->labels[1] or $this->saveadd == $this->labels[7] ) and $this->add_enabled ()); } function more_operation () /*Add More*/ { return (($this->moreadd == $this->labels[8]) and $this->add_enabled ()); } function change_operation () { return (($this->operation == $this->labels[2] or $this->savechange == $this->labels[7] ) and $this->change_enabled()); } function delete_operation () { return (($this->operation == $this->labels[3] or $this->savedelete == $this->labels[7] ) and $this->delete_enabled()); } function filter_operation () { return (isset($this->filter) and $this->filter_enabled ()); } function displayed($k) { return (!isset($this->fdd[$this->fds[$k]]['options']) or ($this->add_operation() and stristr($this->fdd[$this->fds[$k]]['options'],'A')) or ($this->more_operation() and stristr($this->fdd[$this->fds[$k]]['options'],'A')) or ($this->change_operation() and stristr($this->fdd[$this->fds[$k]]['options'],'C')) or ($this->delete_operation() and stristr($this->fdd[$this->fds[$k]]['options'],'D')) ); } function create_javascripts () { if ($this->add_operation() or $this->change_operation() or $this->more_operation()) { echo '' . "\n"; /* echo */ echo '
'."\n"; } else { echo ''."\n"; } } function display_add_record () { for ($k = 0; $k < $this->num_fds; $k++) { if ( $this->displayed($k) ) { echo ' '."\n"; echo ' '.$this->fdd[$this->fds[$k]]['name'].''."\n"; if (isset ($this->fdd[$this->fds[$k]]['values']['table']) and isset ($this->fdd[$this->fds[$k]]['values']['column']) and isset ($this->fdd[$this->fds[$k]]['values']['description'])) { echo ' '."\n"; } elseif (isset ($this->fdd[$this->fds[$k]]['values']['table']) and isset ($this->fdd[$this->fds[$k]]['values']['column'])) { echo ' '."\n"; } elseif (isset ($this->fdd[$this->fds[$k]]['values'])) { echo ' '."\n"; } elseif (isset ($this->fdd[$this->fds[$k]]['textarea'])) { echo ' '."\n"; } else { /* Simple edit box required */ echo ' '."\n"; } /* if elseif else */ echo ' '."\n"; } } /* for k < this->num_fds */ } function display_change_delete_record () { /* for delete or change: SQL SELECT to retrieve the selected record */ $qry = $this->create_column_list ($this->tb, $this->fdd); if (!in_array ($this->key, $this->fds)) { $qry = $qry.','.$this->fully_qualified_name ($this->tb, $this->fdd, $this->key); } $qry = $qry.$this->create_from_clause ($this->tb, $this->fdd); $qry_select = $this->create_where_clause ($this->tb, $this->fdd); if ($qry_select == '') { $kwd = ' WHERE '; } else { $kwd = ' AND '; } $qry = $qry.$qry_select.$kwd.'('.$this->fully_qualified_name($this->tb,$this->fdd,$this->key).' = '.$this->key_delim.$this->rec.$this->key_delim.')'; // echo '

'.$qry.'

'; $res = mysql_db_query ($this->db, $qry); if ($row = mysql_fetch_array ($res)) { for ($k = 0; $k < $this->num_fds; $k++) { if ($this->change_operation ()) { if ( $this->displayed($k) ) { echo ' '."\n"; echo ' '.$this->fdd[$this->fds[$k]]['name'].''."\n"; $this->display_change_field ($row, $k); echo ' '."\n"; } } if ($this->delete_operation ()) { if ( $this->displayed($k) ) { echo ' '."\n"; echo ' '.$this->fdd[$this->fds[$k]]['name'].''."\n"; $this->display_delete_field ($row, $k); echo ' '."\n"; } } } /* for */ } /* if row */ } function display_change_field($row, $k) { if (isset ($this->fdd[$this->fds[$k]]['values']['table']) and isset ($this->fdd[$this->fds[$k]]['values']['column']) and isset ($this->fdd[$this->fds[$k]]['values']['description'])) { echo ' '."\n"; } elseif (isset ($this->fdd[$this->fds[$k]]['values']['table']) and isset ($this->fdd[$this->fds[$k]]['values']['column'])) { echo ' '."\n"; } elseif (isset ($this->fdd[$this->fds[$k]]['values'])) { echo ' '."\n"; } elseif (isset ($this->fdd[$this->fds[$k]]['textarea'])) { echo ' '."\n"; } else { echo ' '."\n"; } /* if elseif else */ } function display_delete_field ($row, $k) { if ($row[$k] == '') { echo '  '."\n"; } else { echo ' '.nl2br(htmlentities($row[$k])).''."\n"; } } function web2plain($x) { if (isset($x)) { if (is_array($x)) { for ($n=0; $nweb2plain($x[$n]); } } else { $x = rawurldecode($x); } } return $x; } function plain2web($x) { if (isset($x)) { if (is_array($x)) { for ($n=0; $nplain2web($x[$n]); } } else { $x = rawurlencode($x); } } return $x; } function get_http_get_var_by_name ($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 */ return $v; } function get_http_post_var_by_name ($name) { global $HTTP_POST_VARS; if (is_array($HTTP_POST_VARS)) $v = $HTTP_POST_VARS[$name]; /* $v could be an array if we allowed bidimensional form fields */ return $v; } function print_get_vars ($miss = "No GET variables found") /*debug only*/ { global $HTTP_GET_VARS; /* we parse form GET variables */ if (is_array($HTTP_GET_VARS)) { echo "

Variables per GET "; foreach ($HTTP_GET_VARS as $k => $v) { if (is_array($v)) { foreach ($v as $akey => $aval) { // $HTTP_GET_VARS[$k][$akey] = strip_tags($aval); // $$k[$akey] = strip_tags($aval); echo "$k\[$akey\]=$aval "; } } else { // $HTTP_GET_VARS[$k] = strip_tags($val); // $$k = strip_tags($val); echo "$k=$v "; } } echo "

"; } else { echo "

"; echo "$miss"; echo "

"; } } function print_post_vars($miss = "No POST variables found") /*debug only*/ { global $HTTP_POST_VARS; /* we parse form POST variables */ if (is_array($HTTP_POST_VARS)) { echo "

Variables per POST "; foreach ($HTTP_POST_VARS as $k => $v) { if (is_array($v)) { foreach ($v as $akey => $aval) { // $HTTP_POST_VARS[$k][$akey] = strip_tags($aval); // $$k[$akey] = strip_tags($aval); echo "$k\[$akey\]=$aval "; } } else { // $HTTP_POST_VARS[$k] = strip_tags($val); // $$k = strip_tags($val); echo "$k=$v "; } } echo "

"; } else { echo "

"; echo "$miss"; echo "

"; } } function print_vars ($miss = "Current instance variables") /*debug only*/ { echo "$miss "; echo "page_name=".$this->page_name." "; echo "hn=".$this->hn." "; echo "un=".$this->un." "; echo "pw=".$this->pw." "; echo "db=".$this->db." "; echo "tb=".$this->tb." "; echo "key=".$this->key." "; echo "key_type=".$this->key_type." "; echo "inc=".$this->inc." "; echo "options=".$this->options." "; echo "fdd=".$this->fdd." "; echo "fl=".$this->fl." "; echo "fm=".$this->fm." "; echo "sfn=".$this->sfn." "; echo "qfn=".$this->qfn." "; echo "sw=".$this->sw." "; echo "rec=".$this->rec." "; echo "prev=".$this->prev." "; echo "next=".$this->next." "; echo "saveadd=".$this->saveadd." "; echo "moreadd=".$this->moreadd." "; echo "savechange=".$this->savechange." "; echo "savedelete=".$this->savedelete." "; echo "operation=".$this->operation." "; echo "\n"; } function list_table () { /* Process any navigation buttons */ if (!isset ($this->fm)) { $this->fm = 0; } if ($this->prev == $this->labels[0]) { /*Prev*/ $this->fm = $this->fm - $this->inc; if ($this->fm < 0) { $this->fm = 0; } } if ($this->next == $this->labels[4]) { /*Next*/ $this->fm = $this->fm + $this->inc; } /* Process filters */ if (!isset ($this->fl)) { $this->fl = 0; } /* by default, no filters */ /* filter switch has been pressed */ if (isset ($this->sw)) { if ($this->sw == 'v') { $this->fl = 1; } if ($this->sw == '^') { $this->fl = 0; } } /* If user is allowed to Change/Delete records, we need an extra column to allow users to select a record */ $select_recs = (($this->change_enabled () or $this->delete_enabled ()) and ($this->key != '')); /* Default is to sort on first field */ if ($this->sfn == '' and ! ($this->initial_sort_suppressed()) ) { $this->sfn = 0; } /* Display the MySQL table in an HTML table */ echo ''."\n"; echo ' '."\n"; echo ' '."\n"; /* if the filter input boxes are not displayed, we need to preserve the filter */ if (!$this->fl) { for ($k = 0; $k < $this->num_fds; $k++) { $l = 'qf'.$k; global $$l; $m = $this->web2plain($$l); if (isset ($m)) { if (is_array($m)) /*multiple selection has been used*/ { if (!in_array('*',$m)) /*one '*' in a multiple selection is all you need*/ { for ($n=0; $nplain2web($m[$n]) != '') { echo ' '."\n"; } } } } else { if ($this->plain2web($m) != '') { $this->qfn = $this->qfn.'&qf'.$k.'='.$this->plain2web($m); echo ' '."\n"; } } } } } /* Set up the URLs which allow sorting by clicking on column headings */ $prev_qfn = $this->qfn; $this->qfn = ''; for ($k = 0; $k < $this->num_fds; $k++) { $l = 'qf'.$k; global $$l; $m = $this->web2plain($$l); if (isset ($m)) { if (is_array($m)) /*multiple selection has been used*/ { if (!in_array('*',$m)) /*one '*' in a multiple selection is all you need*/ { for ($n=0; $nplain2web($m[$n]) != '') { $this->qfn = $this->qfn.'&qf'.$k.'['.$n.']='.$this->plain2web($m[$n]); } } } } else { if ($this->plain2web($m)!='') { $this->qfn = $this->qfn.'&qf'.$k.'='.$this->plain2web($m); } } } } echo ' '."\n"; /* if sort sequence has changed, restart listing */ if ($this->qfn != $prev_qfn) { $this->fm = 0; } /* descending sort order is flagged by a minus sign */ if (isset ($this->sfn)) { $sort_asc = (substr ($this->sfn, 0, 1) != '-'); if (!$sort_asc) { $this->sfn = substr ($this->sfn, 1); } } echo ' '."\n"; echo ' '."\n"; echo ' '."\n"; /* we need an initial column if we have filters, or Changes or Deletes enabled */ if ($this->filter_enabled () or $select_recs) { if ($this->filter_enabled ()) { if ($this->fl) { echo ' '."\n"; } else { echo ' '."\n"; } } else { echo ' '."\n"; } } for ($k = 0; $k < $this->num_fds; $k++) { $fd = $this->fds[$k]; if (stristr($this->fdd[$fd]['options'],'L') or !isset ($this->fdd[$fd]['options'])) { $fdn = $this->fdd[$fd]['name']; if (isset ($this->fdd[$fd]['width'])) { $w = ' width="'.$this->fdd[$fd]['width'].'"'; } else { $w = ''; } if ($this->fdd[$fd]['sort']) { /* clicking on the current sort field reverses the sort order */ if (($k == $this->sfn) and ($sort_asc)) { echo ' '.$fdn.''."\n";; } else { echo ' '.$fdn.''."\n";; } } else { echo ' '.$fdn.''."\n"; } } /* if */ } /* for */ echo ' '."\n"; /* Prepare the SQL Query from the data definition file */ $qry = $this->create_column_list ($this->tb, $this->fdd); /* Even if the key field isn't displayed, we still need its value */ if ($select_recs) { if (!in_array ($this->key, $this->fds)) { $qry = $qry.','.$this->fully_qualified_name($this->tb, $this->fdd, $this->key); }; } $qry = $qry.$this->create_from_clause ($this->tb, $this->fdd); $qry_select = $this->create_where_clause ($this->tb, $this->fdd); if ($qry_select == '') { $kwd = ' WHERE '; } else { $kwd = ' AND '; } for ($k = 0; $k < $this->num_fds; $k++) { $l = 'qf'.$k; global $$l; $m = $this->web2plain($$l); if (isset ($m)) { if (is_array($m)) /*multiple selection has been used*/ { if (!in_array('*',$m)) /*one '*' in a multiple selection is all you need*/ { for ($n=0; $nfully_qualified_name($this->tb,$this->fdd,$this->fds[$k]).$afilter.') '; $kwd = ' AND '; } } else { $afilter = $m; if (($afilter != '') AND ($afilter != '*')) { if (strstr ($afilter, '*')) { $afilter = str_replace ('*', '%', $afilter); $qry_select = $qry_select.$kwd.' ('.$this->fully_qualified_name($this->tb,$this->fdd,$this->fds[$k]).' like \''.$afilter.'\') '; } else { $qry_select = $qry_select.$kwd.' ('.$this->fully_qualified_name($this->tb,$this->fdd,$this->fds[$k]).' = \''.$afilter.'\') '; } $kwd = ' AND '; } } } /* if */ } /* for */ $qry = $qry.$qry_select; if (isset ($this->sfn)) { $qry = $qry.' ORDER BY '.$this->fully_qualified_name ($this->tb, $this->fdd, $this->fds[$this->sfn]); if (!$sort_asc) { $qry = $qry.' DESC'; } } $to = $this->fm + $this->inc; $qry = $qry.' LIMIT '.$this->fm.','.$this->inc; /* Each row of the HTML table is one record from the SQL Query */ // echo ''."\n"; $res = mysql_db_query ($this->db, $qry); $first = true; $eot = $this->inc; while ($row = mysql_fetch_array ($res)) { echo ' '."\n"; /* Draw the filter and fill it with any data typed in last pass and stored in the array parameter keyword 'filter'. Prepare the SQL WHERE clause. */ if ($first AND $this->fl) { echo ' '."\n"; for ($k = 0; $k < $this->num_fds; $k++) { $fd = $this->fds[$k]; $l = 'qf'.$k; global $$l; $m = $this->web2plain($$l); if (stristr($this->fdd[$fd]['options'],'L') or !isset ($this->fdd[$fd]['options'])) { if ($this->fdd[$fd]['select'] == 'D' or $this->fdd[$fd]['select'] == 'M') { if (isset ($this->fdd[$this->fds[$k]]['values']['table']) and isset ($this->fdd[$this->fds[$k]]['values']['column']) and isset ($this->fdd[$this->fds[$k]]['values']['description'])) { $x = $this->set_values_from_table($this->db, $this->tb.','.$this->fdd[$this->fds[$k]]['values']['table'], $this->fdd[$this->fds[$k]]['values']['table'].'.`'.$this->fdd[$this->fds[$k]]['values']['column'].'`', $this->fdd[$this->fds[$k]]['values']['table'].'.`'.$this->fdd[$this->fds[$k]]['values']['description'].'`', ' WHERE ('.$this->fdd[$this->fds[$k]]['values']['table'].'.`'.$this->fdd[$this->fds[$k]]['values']['column'].'` = '.$this->tb.'.`'.$fd.'`)'); } else { $x = $this->set_values_from_table ($this->db, $this->tb, '`'.$fd.'`'); } /* Multiple fields processing - default size is 2 and array required for values */ if (!isset($this->multiple)) {$this->multiple=2;} if ($this->fdd[$fd]['select'] == 'M') { $a = ' multiple size="'.$this->multiple.'"'; } else { $a=''; } echo ' '."\n"; } elseif ($this->fdd[$fd]['select'] == 'T') { echo ' '."\n"; } else { echo ' '."\n"; } /* if elseif else */ } /* end if bro1 */ } /* for */ echo ' '."\n"; echo ' '."\n"; } /* if first and fl */ if ($select_recs) { if ($first) { echo ' '."\n"; } else { echo ' '."\n"; } } elseif ($this->filter_enabled ()) { echo ' '."\n"; } $first = false; for ($k = 0; $k < $this->num_fds; $k++) { $fd = $this->fds[$k]; if (stristr($this->fdd[$fd]['options'],'L') or !isset($this->fdd[$fd]['options'])) { if ((trim ($row[$k]) == '') or ($row[$k] == 'NULL')) { echo ' '."\n"; } else { $row[$k] = nl2br(htmlentities ($row[$k])); /* Make clickable items clickable */ if (!isset($this->fdd[$this->fds[$k]]['URL'])) { echo ' '."\n"; } else { echo ' '."\n"; } } /* if else */ } /* if */ } /* for */ echo ' '."\n"; --$eot; } /* while */ echo '
 
'.$qry.'
'."\n"; if (( is_array($m) and in_array('*',$m)) or ($m == '*')) { echo ' '."\n"; } else { echo ' '."\n"; } for ($j = 0; $j < count ($x['option']); $j++) { if (is_array($m)) { if (in_array($x['value'][$j],$m)) { echo ' '."\n"; } else { echo ' '."\n"; } } else { if ($x['value'][$j] == $m) { echo ' '."\n"; } else { echo ' '."\n"; } } } /* for */ echo '  
  '.$row[$k].''.$row[$k].'
'."\n"; /* note that \n \n"; if ($this->fm > 0) { echo ' '."\n"; } else { echo ' '."\n"; } if ($this->add_enabled ()) { echo ' '."\n"; } if ($first) { if ($this->change_enabled ()) { echo ' '."\n"; } if ($this->delete_enabled ()) { echo ' '."\n"; } } else { if ($this->change_enabled ()) { echo ' '."\n"; } if ($this->delete_enabled ()) { echo ' '."\n"; } } /* if else */ if ($eot == 0) { echo ' '."\n"; } else { echo ' '."\n"; } /* Display the current page and the total pages */ echo ' '."\n"; $total = 0; $qry = 'select count(*) as nbrecno '.$this->create_from_clause($this->tb,$this->fdd).$qry_select; // echo('

'.$qry.'

'); $res = mysql_db_query($this->db, $qry); while ($row = mysql_fetch_row($res)) { $values[] = $row[0]; } $total = $values[0]; echo ' '."\n"; echo ' '."\n"; echo '
  '.$this->labels[5].': '.(($this->fm/$this->inc)+1).' / '.Ceil($total/$this->inc).' '.$this->labels[6].': '.$total.'
'."\n"; echo ''."\n"; } function display_record() { $this->create_javascripts(); echo ''."\n"; echo ' '."\n"; echo ' '."\n"; echo ' '."\n"; echo ' '."\n"; /* preserve the values of any filter fields qf0..qfn for Pass 3 */ for ($k = 0; $k < $this->num_fds; $k++) { $l = 'qf'.$k; global $$l; $m = $this->web2plain($$l); if (isset ($m)) { if (is_array($m)) /*multiple selection has been used*/ { if (!in_array('*',$m)) /*one '*' in a multiple selection is all you need*/ { for ($n=0; $nplain2web($m[$n]) != '') { echo ' '."\n"; } } } } else { if ($this->plain2web($m) != '') { $this->qfn = $this->qfn.'&qf'.$k.'='.$m; echo ' '."\n"; } } } } echo ' '."\n"; if ($this->add_operation() or $this->more_operation() ) { $this->display_add_record (); } else { $this->display_change_delete_record (); } echo '
'."\n"; echo '
'."\n"; if ($this->add_operation() or $this->more_operation()) { echo ''."\n"; echo ''."\n"; echo ''."\n"; } if ($this->change_operation ()) { echo ''."\n"; echo ''."\n"; } if ($this->delete_operation ()) { echo ''."\n"; echo ''."\n"; } echo ''."\n"; } function do_add_record() { $qry = ''; for ($k = 0; $k < $this->num_fds; $k++) { if ( $this->displayed($k) ) { $fd = $this->fds[$k]; if ($qry == '') { $qry = 'INSERT INTO '.$this->tb.' (`'.$fd.'`'; } else { $qry = $qry.',`'.$fd.'`'; } } } $val = ''; for ($k = 0; $k < $this->num_fds; $k++) { if ( $this->displayed($k) ) { $fd = $this->fds[$k]; $fn = $this->get_http_post_var_by_name($fd); if (isset($this->fdd[$fd]['format'])) /*handle fancy date formats*/ { $l = $this->fdd[$fd]['format'][3]; /*delimiter*/ $fna = explode($l,$fn); /*split using user's delim*/ $fn = $fna[strpos($this->fdd[$fd]['format'],'y')]; /*Year*/ $fn = $fn.'-'.$fna[strpos($this->fdd[$fd]['format'],'m')]; /*Month*/ $fn = $fn.'-'.$fna[strpos($this->fdd[$fd]['format'],'d')]; /*Day*/ } if ($val == '') { $val = ') VALUES (\''.addslashes($fn).'\''; } else { $val = $val.',\''.addslashes($fn).'\''; } } } $qry = $qry.$val.')'; // echo '

'.$qry.'

'; $res = mysql_db_query ($this->db, $qry); echo '
'.mysql_affected_rows().' '.$this->labels[10].'
'."\n"; } function do_change_record () { $qry = ''; for ($k = 0; $k < $this->num_fds; $k++) { if ( $this->displayed($k) ) { $fd = $this->fds[$k]; $fn = $this->get_http_post_var_by_name($fd); if (isset($this->fdd[$fd]['format'])) /*handle fancy date formats*/ { $l = $this->fdd[$fd]['format'][3]; /*delimiter*/ $fna = explode($l,$fn); /*split using user's delim*/ $fn = $fna[strpos($this->fdd[$fd]['format'],'y')]; /*Year*/ $fn = $fn.'-'.$fna[strpos($this->fdd[$fd]['format'],'m')]; /*Month*/ $fn = $fn.'-'.$fna[strpos($this->fdd[$fd]['format'],'d')]; /*Day*/ } if ($qry == '') { $qry = 'UPDATE '.$this->tb.' SET `'.$fd.'`=\''.addslashes($fn).'\''; } else { $qry = $qry.',`'.$fd.'`=\''.addslashes($fn).'\''; } } } $qry = $qry.' WHERE ('.$this->key.' = '.$this->key_delim.$this->rec.$this->key_delim.')'; // echo '

'.$qry.'

'; $res = mysql_db_query ($this->db, $qry); echo '
'.mysql_affected_rows ().' '.$this->labels[2].'
'."\n"; } function do_delete_record () { $qry = 'DELETE FROM '.$this->tb.' WHERE (`'.$this->key.'` = '.$this->key_delim.$this->rec.$this->key_delim.')'; // echo '

'.$qry.'

'; $res = mysql_db_query ($this->db, $qry); echo '
'.mysql_affected_rows ().' '.$this->labels[12].'
'."\n"; } function execute() { set_magic_quotes_runtime(0); /*let's do explicit quoting ... it's safer */ // debug code - uncomment to enable // phpinfo(); // $this->print_get_vars(); // $this->print_post_vars(); // $this->print_vars(); if ($this->key_type == 'string' or $this->key_type == 'blob' or $this->key_type == 'date' or $this->key_type == 'time' or $this->key_type == 'datetime') { $this->key_delim = '"'; } else { $this->key_delim = ''; } $dbl = @mysql_pconnect ($this->hn, $this->un, $this->pw) or die ("

Could not connect to MySQL

\n\n\n"); if (!isset ($this->db)) { die ("

No Database defined

\n\n\n"); } if (!isset ($this->tb)) { die ("

No Table defined

\n\n\n"); } /* ====================================================================== Pass 3: process any updates generated if the user has selected a save button during Pass 2 ====================================================================== */ $listit = true; if ($this->saveadd == $this->labels[7]) { $this->do_add_record(); $listit = false; } if ($this->moreadd == $this->labels[8]) { $this->do_add_record(); } if ($this->savechange == $this->labels[7]) { $this->do_change_record(); $listit = false; } if ($this->savedelete == $this->labels[3]) { $this->do_delete_record(); $listit = false; } /* ====================================================================== Pass 2: display an input/edit/confirmation screen if the user has selected an editing button on Pass 1 through this page ====================================================================== */ if ( ($this->add_operation() or $this->more_operation() or $this->change_operation() or $this->delete_operation() ) and ( $listit ) ) { $this->display_record(); } /* ====================================================================== Pass 1 and Pass 3: display the MySQL table in a scrolling window on the screen (skip this step in 'Add More' mode) ====================================================================== */ else { $this->list_table(); } } function PHPMyEdit($hn, $un, $pw, $db, $tb, $key, $key_type, $inc, $options, $multiple, $fdd, $labels) { /* Instance class variables */ $this->hn = $hn; $this->un = $un; $this->pw = $pw; $this->db = $db; $this->tb = $tb; $this->key = $key; $this->key_type = $key_type; $this->inc = $inc; $this->options = $options; $this->multiple = $multiple; $this->fdd = $fdd; $this->labels = $labels; /* Find the URL to post forms */ global $HTTP_SERVER_VARS; $this->page_name =basename($HTTP_SERVER_VARS["PHP_SELF"]); /* form variables all around */ global $operation, $apply, $fl, $fm, $sfn, $qfn, $sw, $rec, $prev, $next, $saveadd, $moreadd, $savechange, $savedelete; $this->operation = $operation; $this->apply = $apply; $this->fl = $fl; $this->fm = $fm; $this->sfn = $sfn; $this->qfn = $qfn; $this->sw = $sw; $this->rec = $rec; $this->prev = $prev; $this->next = $next; $this->saveadd = $saveadd; $this->moreadd = $moreadd; $this->savechange = $savechange; $this->savedelete = $savedelete; /* Extract SQL Field Names and number of fields */ foreach ($this->fdd as $akey => $aval) { $this->fds[] = $akey; } $this->num_fds = sizeof ($this->fds); } } /* End of class */ ?>