Platon Technologies
not logged in Login Registration
EnglishSlovak
open source software development celebrating 10 years of open source development! Thursday, October 15, 2026

Diff for phpMyEdit/phpMyEdit.class.php between version 1.95 and 1.96

version 1.95, 2003/11/20 11:52:29 version 1.96, 2003/12/08 09:17:30
Line 19 
Line 19 
  * http://platon.sk/projects/phpMyEdit/   * http://platon.sk/projects/phpMyEdit/
  */   */
   
 /* $Platon: phpMyEdit/phpMyEdit.class.php,v 1.94 2003/08/18 20:31:58 nepto Exp $ */  /* $Platon: phpMyEdit/phpMyEdit.class.php,v 1.95 2003/11/20 11:52:29 nepto Exp $ */
   
 /*  This is a generic table editing program. The table and fields to be  /*  This is a generic table editing program. The table and fields to be
         edited are defined in the calling program.          edited are defined in the calling program.
Line 161  class phpMyEdit
Line 161  class phpMyEdit
          * column specific functions           * column specific functions
          */           */
   
           function col_has_sql($k)    { return isset($this->fdd[$k]['sql']); }
           function col_has_sqlw($k)   { return isset($this->fdd[$k]['sqlw']) && !$this->virtual($k); }
         function col_has_values($k) { return isset($this->fdd[$k]['values']) || isset($this->fdd[$k]['values2']); }          function col_has_values($k) { return isset($this->fdd[$k]['values']) || isset($this->fdd[$k]['values2']); }
         function col_has_URL($k)    { return isset($this->fdd[$k]['URL'])          function col_has_URL($k)    { return isset($this->fdd[$k]['URL'])
                 || isset($this->fdd[$k]['URLprefix']) || isset($this->fdd[$k]['URLpostfix']); }                  || isset($this->fdd[$k]['URLprefix']) || isset($this->fdd[$k]['URLpostfix']); }
Line 193  class phpMyEdit
Line 195  class phpMyEdit
         function tabs_enabled()   { return $this->display['tabs'] && count($this->tabs) > 0; }          function tabs_enabled()   { return $this->display['tabs'] && count($this->tabs) > 0; }
         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'],'W'); }          function password($k)     { return stristr($this->fdd[$k]['options'],'W'); }
         function readonly($k)     { return stristr($this->fdd[$k]['options'],'R'); }          function readonly($k)     { return stristr($this->fdd[$k]['options'],'R') || $this->virtual($k);     }
           function virtual($k)      { return stristr($this->fdd[$k]['options'],'V') && $this->col_has_sql($k); }
   
         function add_operation()    { return $this->operation == $this->labels['Add']    && $this->add_enabled();    }          function add_operation()    { return $this->operation == $this->labels['Add']    && $this->add_enabled();    }
         function change_operation() { return $this->operation == $this->labels['Change'] && $this->change_enabled(); }          function change_operation() { return $this->operation == $this->labels['Change'] && $this->change_enabled(); }
Line 213  class phpMyEdit
Line 216  class phpMyEdit
   
         function processed($k) /* {{{ */          function processed($k) /* {{{ */
         {          {
                   if ($this->virtual($k)) {
                           return false;
                   }
                 $options = @$this->fdd[$k]['options'];                  $options = @$this->fdd[$k]['options'];
                 if (! isset($options)) {                  if (! isset($options)) {
                         return true;                          return true;
Line 329  class phpMyEdit
Line 335  class phpMyEdit
   
         function set_values_from_table($field_num, $strict = false) /* {{{ */          function set_values_from_table($field_num, $strict = false) /* {{{ */
         {          {
                 if($this->fdd[$field_num]['values']['db']) {                  $db    = &$this->fdd[$field_num]['values']['db'];
                         $db = $this->fdd[$field_num]['values']['db'];  
                 } else {  
                         $db = $this->db;  
                 }  
                 $table = &$this->fdd[$field_num]['values']['table'];                  $table = &$this->fdd[$field_num]['values']['table'];
                 $key   = &$this->fdd[$field_num]['values']['column'];                  $key   = &$this->fdd[$field_num]['values']['column'];
                 $desc  = &$this->fdd[$field_num]['values']['description'];                  $desc  = &$this->fdd[$field_num]['values']['description'];
                   isset($db) || $db = $this->db;
                 $qparts['type'] = 'select';                  $qparts['type'] = 'select';
                 if ($table) {                  if ($table) {
                         $qparts['select'] = 'DISTINCT '.$key;                          $qparts['select'] = 'DISTINCT '.$table.'.'.$key;
                         if ($desc && is_array($desc) && is_array($desc['columns'])) {                          if ($desc && is_array($desc) && is_array($desc['columns'])) {
                                 $qparts['select'] .= ',CONCAT('; // )                                  $qparts['select'] .= ',CONCAT('; // )
                                 $num_cols = sizeof($desc['columns']);                                  $num_cols = sizeof($desc['columns']);
Line 362  class phpMyEdit
Line 365  class phpMyEdit
                         } else if ($desc && is_array($desc)) {                          } else if ($desc && is_array($desc)) {
                                 // TODO                                  // TODO
                         } else if ($desc) {                          } else if ($desc) {
                                 $qparts['select'] .= ','.$desc;                                  $qparts['select'] .= ','.$table.'.'.$desc;
                                 $qparts['orderby'] = $desc;                                  $qparts['orderby'] = $desc;
                         } else if ($key) {                          } else if ($key) {
                                 $qparts['orderby'] = $key;                                  $qparts['orderby'] = $key;
Line 374  class phpMyEdit
Line 377  class phpMyEdit
                                 $qparts['orderby'] = $this->fdd[$field_num]['values']['orderby'];                                  $qparts['orderby'] = $this->fdd[$field_num]['values']['orderby'];
                         }                          }
                 } else { /* simple value extraction */                  } else { /* simple value extraction */
                         $qparts['select'] = 'DISTINCT '.$this->fds[$field_num];                          $key = &$this->fds[$field_num];
                         $qparts['from']   = $this->db.'.'.$this->tb;                          $this->virtual($field_num) && $key = $this->fqn($field_num);
                           $qparts['select']  = 'DISTINCT '.$key.' AS PMEkey';
                           $qparts['orderby'] = 'PMEkey';
                           $qparts['from']    = $this->db.'.'.$this->tb;
                           $qparts['from']    = $this->db.'.'.$this->tb;
   
                 }                  }
                 $values = array();                  $values = array();
                 $res    = $this->myquery($this->query_make($qparts), __LINE__);                  $res    = $this->myquery($this->query_make($qparts), __LINE__);
Line 389  class phpMyEdit
Line 397  class phpMyEdit
         {          {
                 is_numeric($field) || $field = array_search($field, $this->fds);                  is_numeric($field) || $field = array_search($field, $this->fds);
                 // if read SQL expression exists use it                  // if read SQL expression exists use it
                 if (isset($this->fdd[$field]['sql']))                  if ($this->col_has_sql($field))
                         return $this->fdd[$field]['sql'];                          return $this->fdd[$field]['sql'];
                 // on copy/change always use simple key retrieving                  // on copy/change always use simple key retrieving
                 if ($this->add_operation()                  if ($this->add_operation()
Line 1761  function phpMyEdit_form_control(theForm)
Line 1769  function phpMyEdit_form_control(theForm)
                                 //$raw_sort_field = 'qf'.$field;                                  //$raw_sort_field = 'qf'.$field;
                                 $sort_field   = $this->fqn($field);                                  $sort_field   = $this->fqn($field);
                                 $sort_field_w = $this->fdd[$field]['name'];                                  $sort_field_w = $this->fdd[$field]['name'];
                                 $this->fdd[$field]['sql'] && $sort_field_w .= ' (sql)';                                  $this->col_has_sql($field) && $sort_field_w .= ' (sql)';
                                 if ($desc) {                                  if ($desc) {
                                         $sort_field   .= ' DESC';                                          $sort_field   .= ' DESC';
                                         $sort_field_w .= ' '.$this->labels['descending'];                                          $sort_field_w .= ' '.$this->labels['descending'];
Line 2180  function phpMyEdit_form_control(theForm)
Line 2188  function phpMyEdit_form_control(theForm)
                                         $fn = $this->get_cgi_var($this->fds[$k]);                                          $fn = $this->get_cgi_var($this->fds[$k]);
                                 }                                  }
                                 if ($fd == $this->key) {                                  if ($fd == $this->key) {
                                         $key_col_val = addslashes($fn);                                          $key_col_val = $fn;
                                 }                                  }
                                 if ($query == '') {                                  if ($query == '') {
                                         $query = 'INSERT INTO '.$this->tb.' ('.$fd; // )                                          $query = 'INSERT INTO '.$this->tb.' ('.$fd; // )
Line 2188  function phpMyEdit_form_control(theForm)
Line 2196  function phpMyEdit_form_control(theForm)
                                         $query .= ','.$fd;                                          $query .= ','.$fd;
                                 }                                  }
                                 $newvals[$this->fds[$k]] = is_array($fn) ? join(',',$fn) : $fn;                                  $newvals[$this->fds[$k]] = is_array($fn) ? join(',',$fn) : $fn;
                                 $vals_quoted[$k] = addslashes($newvals[$this->fds[$k]]);                                  if ($this->col_has_sqlw($k)) {
                                 $vals_quoted[$k] = "'".$vals_quoted[$k]."'";                                          $val     = $newvals[$this->fds[$k]];
                                           $val_as  = addslashes($val);
                                           $val_qas = '"'.addslashes($val).'"';
                                           $vals_quoted[$k] = stripslashes(eval('return "'.addslashes($this->fdd[$k]['sqlw']).'";'));
                                   } else {
                                           $vals_quoted[$k] = addslashes($newvals[$this->fds[$k]]);
                                           $vals_quoted[$k] = "'".$vals_quoted[$k]."'";
                                   }
                         }                          }
                 }                  }
                 // Creating array of changed keys ($changed)                  // Creating array of changed keys ($changed)
Line 2244  function phpMyEdit_form_control(theForm)
Line 2259  function phpMyEdit_form_control(theForm)
                         if ($this->processed($k) && !$this->readonly($k)) {                          if ($this->processed($k) && !$this->readonly($k)) {
                                 $fd = $this->fds[$k];                                  $fd = $this->fds[$k];
                                 $fn = $this->get_cgi_var($fd);                                  $fn = $this->get_cgi_var($fd);
                                 $newValue = $newvals[$this->fds[$k]] = is_array($fn) ? join(',',$fn) : $fn;                                  $newvals[$this->fds[$k]] = is_array($fn) ? join(',',$fn) : $fn;
                                 $newValue = addslashes($newValue);                                  if ($this->col_has_sqlw($k)) {
                                           $val      = $newvals[$this->fds[$k]];
                                           $val_as   = addslashes($val);
                                           $val_qas  = '"'.addslashes($val).'"';
                                           $newValue = stripslashes(eval('return "'.addslashes($this->fdd[$k]['sqlw']).'";'));
                                   } else {
                                           $newValue = $newvals[$this->fds[$k]];
                                           $newValue = "'".addslashes($newValue)."'";
                                   }
                                 if ($query_real == '') {                                  if ($query_real == '') {
                                         $query_real   = 'UPDATE '.$this->tb.' SET '.$fd.'=\''.$newValue.'\'';                                          $query_real   = 'UPDATE '.$this->tb.' SET '.$fd.'='.$newValue;
                                         $query_oldrec = 'SELECT '.$fd;                                          $query_oldrec = 'SELECT '.$fd;
                                 } else {                                  } else {
                                         $query_real   .= ','.$fd.'=\''.$newValue.'\'';                                          $query_real   .= ','.$fd.'='.$newValue;
                                         $query_oldrec .= ','.$fd;                                          $query_oldrec .= ','.$fd;
                                 }                                  }
                         }                          }
Line 2259  function phpMyEdit_form_control(theForm)
Line 2282  function phpMyEdit_form_control(theForm)
                 $query_real   .= $where_part;                  $query_real   .= $where_part;
                 $query_oldrec .= ' FROM ' . $this->tb . $where_part;                  $query_oldrec .= ' FROM ' . $this->tb . $where_part;
                 // Additional query (must go before real query)                  // Additional query (must go before real query)
                 $res_old = $this->myquery($query_oldrec, __LINE__);                  $res     = $this->myquery($query_oldrec, __LINE__);
                 $oldvals = @mysql_fetch_array($res_old, MYSQL_ASSOC);                  $oldvals = @mysql_fetch_array($res, MYSQL_ASSOC);
                 @mysql_free_result($res);                  @mysql_free_result($res);
                 // Creating array of changed keys ($changed)                  // Creating array of changed keys ($changed)
                 for ($k = 0; $k < $this->num_fds; $k++) {                  for ($k = 0; $k < $this->num_fds; $k++) {
Line 2283  function phpMyEdit_form_control(theForm)
Line 2306  function phpMyEdit_form_control(theForm)
                 if (! $res) {                  if (! $res) {
                         return false;                          return false;
                 }                  }
                   // Another additional query (must go after real query)
                   $res     = $this->myquery($query_oldrec, __LINE__);
                   $newvals = @mysql_fetch_array($res, MYSQL_ASSOC);
                   @mysql_free_result($res);
                   // Creating array of changed keys ($changed)
                   $changed = array();
                   for ($k = 0; $k < $this->num_fds; $k++) {
                           $key = $this->fds[$k];
                           if (! $this->processed($k) || $this->readonly($k) || $oldvals[$key] == $newvals[$key]) {
                                   continue;
                           }
                           $changed[] = $key;
                   }
                 // Notify list                  // Notify list
                 if (@$this->notify['update'] || @$this->notify['all']) {                  if (@$this->notify['update'] || @$this->notify['all']) {
                         if (count($changed) > 0) {                          if (count($changed) > 0) {

Legend:
Removed from v.1.95  
changed lines
  Added in v.1.96

Platon Group <platon@platon.org> http://platon.org/
Copyright © 2002-2006 Platon Group
Site powered by Metafox CMS
Go to Top