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.12 and 1.13

version 1.12, 2002/09/29 17:11:30 version 1.13, 2002/10/12 10:59:35
Line 144  class phpMyEdit
Line 144  class phpMyEdit
         var $logtable;   // name of optional logtable          var $logtable;   // name of optional logtable
         var $navigation; // navigation style          var $navigation; // navigation style
   
         function myquery($qry, $line = 0) /* {{{ */          function myquery($qry, $line = 0, $debug = 0) /* {{{ */
         {          {
                 global $debug_query;                  global $debug_query;
                 if ($debug_query) {                  if ($debug_query || $debug) {
                         $line = intval($line);                          $line = intval($line);
                         echo '<h4>qry at '.$line.': '.htmlspecialchars($qry).'</h4><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);
Line 223  class phpMyEdit
Line 223  class phpMyEdit
   
         function set_values_from_table($field_num, $prepend = '') /* {{{ */          function set_values_from_table($field_num, $prepend = '') /* {{{ */
         {          {
                 //echo $field_num;                  /*
                 //echo '<pre>';                     echo "$field_num, ";
                 //var_dump($this->fdd);                     var_dump($prepend);
                 //echo '</pre>';                     echo '<pre>';
                      var_dump($this->fdd);
                      echo '</pre>';
                    */
                 if($this->fdd[$field_num]['values']['db']) {                  if($this->fdd[$field_num]['values']['db']) {
                         $db = $this->fdd[$field_num]['values']['db'];                          $db = $this->fdd[$field_num]['values']['db'];
                 } else {                  } else {
Line 236  class phpMyEdit
Line 239  class phpMyEdit
                 $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'];
                 $qparts['type']   = 'select';                  $qparts['type']   = 'select';
                 $qparts['select'] = 'DISTINCT '.$key;                  if ($table) {
                 if ($desc) {                          $qparts['select'] = 'DISTINCT '.$key;
                         //- $qparts['select'] .= ','.$desc;                          if ($desc) {
                         //- $qparts['orderby'] = $desc;                                  //- $qparts['select'] .= ','.$desc;
                         //      Changes 08/08/02 Shaun Johnston                                  //- $qparts['orderby'] = $desc;
                         if (is_array($desc)) {                                  //      Changes 08/08/02 Shaun Johnston
                                 $qparts['select'] .= ',CONCAT('; // )                                  if (is_array($desc)) {
                                 $num_cols = sizeof($desc['columns']);                                          $qparts['select'] .= ',CONCAT('; // )
                                 for ($i = 0; $i <= $num_cols; $i++) {                                          $num_cols = sizeof($desc['columns']);
                                         $qparts['select'] .= $desc['columns'][$i];                                          for ($i = 0; $i <= $num_cols; $i++) {
                                         if ($desc['divs'][$i]) {                                                  $qparts['select'] .= $desc['columns'][$i];
                                                 $qparts['select'] .= ',"'.$desc['divs'][$i].'"';                                                  if ($desc['divs'][$i]) {
                                         }                                                          $qparts['select'] .= ',"'.$desc['divs'][$i].'"';
                                         if ($i < ($num_cols - 1)) {                                                  }
                                                 $qparts['select'] .= ',';                                                  if ($i < ($num_cols - 1)) {
                                                           $qparts['select'] .= ',';
                                                   }
                                         }                                          }
                                           $qparts['select'] .= ') AS select_alias_'.$field_num;
                                           $qparts['orderby'] = $desc['orderby'];
                                   } else {
                                           $qparts['select'] .= ','.$desc;
                                           $qparts['orderby'] = $desc;
                                 }                                  }
                                 $qparts['select'] .= ') AS select_alias_'.$field_num;  
                                 $qparts['orderby'] = $desc['orderby'];  
                         } else {                          } else {
                                 $qparts['select'] .= ','.$desc;                                  if ($key) {
                                 $qparts['orderby'] = $desc;                                          $qparts['orderby'] = $key;
                                   }
                         }                          }
                 } else {                          //$qparts['from'] = "$db.$table.$sel;
                         $qparts['orderby'] = $key;                          $qparts['from'] = "$db.$table";
                 }                          $qparts['where'] = $this->fdd[$field_num]['values']['filters'];
                 //$qparts['from'] = "$db.$table.$sel;                          if ($this->fdd[$field_num]['values']['orderby']) {
                 $qparts['from'] = "$db.$table";                                  $qparts['orderby'] = $this->fdd[$field_num]['values']['orderby'];
                 $qparts['where'] = $this->fdd[$field_num]['values']['filters'];                          }
                 if ($this->fdd[$field_num]['values']['orderby']) {                  } else { /* simple value extraction */
                         $qparts['orderby'] = $this->fdd[$field_num]['values']['orderby'];                          $qparts['select'] = 'DISTINCT '.$this->fds[$field_num];
                           $qparts['from']   = $this->db.'.'.$this->tb;
                 }                  }
                 $res = $this->myquery($this->query_make($qparts),__LINE__);  
                 $values = array();                  $values = array();
                 if ($prepend != '') {                  $res    = $this->myquery($this->query_make($qparts), __LINE__);
                         $values[$prepend[0]] = $prepend[1];  
                 }  
                 while ($row = mysql_fetch_row($res)) {                  while ($row = mysql_fetch_row($res)) {
                         if ($desc) {                          if ($desc) {
                                 $values[$row[0]] = $row[1];                                  $values[$row[0]] = $row[1];
Line 280  class phpMyEdit
Line 287  class phpMyEdit
                                 $values[$row[0]] = $row[0];                                  $values[$row[0]] = $row[0];
                         }                          }
                 }                  }
                   if (is_array($prepend)) {
                           // old wrong prepending -- REMOVE ME at December 2002
                           //$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) /* {{{ */          function fqn($field, $use_qfx = false, $dont_desc = false) /* {{{ */
         {          {
                 if (is_string($field)) {                  if (is_string($field)) {
                         $field = array_search($field,$this->fds);                          $field = array_search($field,$this->fds);
Line 300  class phpMyEdit
Line 312  class phpMyEdit
                 } else {                  } else {
                         if (isset($this->fdd[$field]['expression'])) {                          if (isset($this->fdd[$field]['expression'])) {
                                 $ret = $this->fdd[$field]['expression'];                                  $ret = $this->fdd[$field]['expression'];
                         } elseif ($this->fdd[$this->fds[$field]]['values']['description']) {                          } elseif ($this->fdd[$this->fds[$field]]['values']['description'] && ! $dont_desc) {
                                 //      Changed 06/08/02 Shaun Johnston                                  //      Changed 06/08/02 Shaun Johnston
                                 $desc = $this->fdd[$this->fds[$field]]['values']['description'];                                  $desc = $this->fdd[$this->fds[$field]]['values']['description'];
                                 if (is_array($desc)) {                                  if (is_array($desc)) {
Line 475  class phpMyEdit
Line 487  class phpMyEdit
                 }                  }
   
                 if (isset($var)) {                  if (isset($var)) {
                         $var = stripslashes($var);                          if (is_array($var)) {
                                   foreach (array_keys($var) as $key) {
                                           $var[$key] = stripslashes($var[$key]);
                                   }
                           } else {
                                   $var = stripslashes($var);
                           }
                 } else {                  } else {
                         $var = $default_value;                          $var = $default_value;
                 }                  }
Line 517  class phpMyEdit
Line 535  class phpMyEdit
                         if ($m != '') {                          if ($m != '') {
                                 if (is_array($m)) { // multiple selection has been used                                  if (is_array($m)) { // multiple selection has been used
                                         if (!in_array('*',$m))  { // one '*' in a multiple selection is all you need                                          if (!in_array('*',$m))  { // one '*' in a multiple selection is all you need
                                                 for ($n=0; $n<count($m); $n++) {                                                  $qf_op = '';
                                                         if ($n==0) {                                                  foreach (array_keys($m) as $key) {
                                                                 $qf_op = 'IN';                                                          if ($qf_op == '') {
                                                                 $qf_val = "'".addslashes($m[$n])."'";                                                                  $qf_op   = 'IN';
                                                                 $afilter=" IN ('".addslashes($m[$n])."'";                                                                  $qf_val  = "'".addslashes($m[$key])."'";
                                                                   $afilter =" IN ('".addslashes($m[$key])."'";
                                                         } else {                                                          } else {
                                                                 $afilter=$afilter.",'".addslashes($m[$n])."'";                                                                  $afilter =$afilter.",'".addslashes($m[$key])."'";
                                                                 $qf_val .= ",'".addslashes($m[$n])."'";                                                                  $qf_val .= ",'".addslashes($m[$key])."'";
                                                         }                                                          }
                                                 }                                                  }
                                                 $afilter = $afilter.')';                                                  $afilter = $afilter.')';
                                                 $qo[$this->fqn($k)] =                                                  // XXX: nasty $dont_desc hack
                                                   $dont_desc = isset($this->fdd[$k]['values']['description']);
                                                   $qo[$this->fqn($k, false, $dont_desc)] =
                                                         array( 'oper'  => $qf_op, 'value' => '('.$qf_val.')');                                                          array( 'oper'  => $qf_op, 'value' => '('.$qf_val.')');
                                         }                                          }
                                 } else {                                  } else {
                                         $afilter = $m;                                          $afilter = $m;
                                         if ($afilter != '*') {                                          if ($afilter != '*') {
                                                   /* XXX: This is ugly fqn() hack. We must pass third
                                                      $dont_desc parameter to fqn() method, as far as we
                                                      want to return not description column, but ID one. */
                                                 if ($this->fdd[$k]['values']['description']) {                                                  if ($this->fdd[$k]['values']['description']) {
                                                         $qo[$this->fqn($k)] =                                                          // DEBUG
                                                                 array( 'oper'  => '=', 'value' => "'".$afilter."'");                                                          // echo htmlspecialchars(' k = '.$k.' | fqn($k) = '.$this->fqn($k, false, true));
                                                           $qo[$this->fqn($k, false, true)] =
                                                                   array('oper'  => '=', 'value' => "'".$afilter."'");
                                                 } elseif ($this->fdd[$k]['values']['column']) {                                                  } elseif ($this->fdd[$k]['values']['column']) {
                                                         $qo[$this->fqn($k)] =                                                          $qo[$this->fqn($k)] =
                                                                 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
                                                         if (($afilter != '') AND ($afilter != '*')) {                                                          if (($afilter != '') AND ($afilter != '*')) {
                                                                 $afilter = addslashes(addslashes('%'                                                                  $afilter = addslashes(addslashes('%'
                                                                                         .str_replace ('*', '%', $afilter).'%'));                                                                                          .str_replace('*', '%', $afilter).'%'));
                                                                 $qo[$this->fqn($k)] =                                                                  $qo[$this->fqn($k)] =
                                                                         array('oper'  => 'like', 'value' => "'".$afilter."'");                                                                          array('oper'  => 'like', 'value' => "'".$afilter."'");
                                                         }                                                          }
Line 1034  return true;
Line 1060  return true;
                         .'" value="'.htmlspecialchars($value).'">'."\n";                          .'" value="'.htmlspecialchars($value).'">'."\n";
         } /* }}} */          } /* }}} */
   
         function htmlSelect($var, $kv_array, $selected, $multiple = false, $nat_sort = false) /* {{{ */          /**
            * Creates HTML select element (tag)
            *
            * @param       name            element name
            * @param       kv_array        key => value array
            * @param       selected        selected key (it can be single string, array of
            *                                              keys or multiple values separated by comma
            * @param       multiple        bool for mulptiple selection
            * @param       nat_sort        bool for natural sorting
            */
           function htmlSelect($name, $kv_array, $selected, $multiple = false, $nat_sort = false) /* {{{ */
         {          {
                 $ret  = '<select name="'.htmlspecialchars($var);                  $ret = '<select name="'.htmlspecialchars($name);
                 if ($multiple) {                  if ($multiple) {
                         $ret  .= '[]" multiple size="'.$this->multiple;                          $ret  .= '[]" multiple size="'.$this->multiple;
                         $selected = explode(',', $selected);                          !is_array($selected) && $selected = explode(',', $selected);
                 }                  }
                 $ret .= '">'."\n";                  $ret .= '">'."\n";
   
Line 1080  return true;
Line 1116  return true;
         {          {
                 if (isset($x)) {                  if (isset($x)) {
                         if (is_array($x)) {                          if (is_array($x)) {
                                 for ($n=0; $n<count($x); $n++) {                                  foreach (array_keys($x) as $key) {
                                         $x[$n] = $this->web2plain($x[$n]);                                          $x[$key] = rawurldecode($x[$key]);
                                 }                                  }
                         } else {                          } else {
                                 $x = rawurldecode($x);                                  $x = rawurldecode($x);
Line 1417  return true;
Line 1453  return true;
                                 $m   = $this->web2plain($$l);  // get the field name and value                                  $m   = $this->web2plain($$l);  // get the field name and value
                                 $mc  = $this->web2plain($$lc); // get the comparison operator for numeric/date types                                  $mc  = $this->web2plain($$lc); // get the comparison operator for numeric/date types
   
                                 if (isset ($m)) {                                  if (isset($m)) {
                                         if (is_array($m)) { // multiple selection has been used                                          if (is_array($m)) { // multiple selection has been used
                                                 if (!in_array('*',$m)) {// one '*' in a multiple selection is all you need                                                  if (!in_array('*',$m)) {// one '*' in a multiple selection is all you need
                                                         for ($n=0; $n<count($m); $n++) {                                                          for ($n=0; $n<count($m); $n++) {
Line 1595  return true;
Line 1631  return true;
                                 $qparts['select'] .= ','.$this->fqn($this->key);                                  $qparts['select'] .= ','.$this->fqn($this->key);
                         }                          }
                 }                  }
                 $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 (
Line 1698  return true;
Line 1734  return true;
                                         $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;
                                 }                                  }
Line 1715  return true;
Line 1751  return true;
                                         !isset ($this->fdd[$fd]['options'])                                          !isset ($this->fdd[$fd]['options'])
                                 )                                  )
                                 */                                  */
                                 if (                                  if ($this->displayed($k)) {
                                         $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';
                                                 $selected = '';                                                  $selected = '';
                                                 if ($m != '') {                                                  if ($m != '') {
                                                         $selected = $m;                                                          $selected = $m;
Line 1730  return true;
Line 1765  return true;
                                                         $x = $this->set_values_from_table($k, array('*' => '*'));                                                          $x = $this->set_values_from_table($k, array('*' => '*'));
                                                 } elseif ($this->fdd[$k]['values']) {                                                  } elseif ($this->fdd[$k]['values']) {
                                                         $x = array('*' => '*') + $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
                                                 if (                                                  if (! $this->password($k) && ! $this->hidden($k)) {
                                                         ! $this->password($k) &&  
                                                         ! $this->hidden($k)  
                                                 ) {  
                                                         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.'"';
Line 1795  return true;
Line 1830  return true;
   
                                                 // if it's int or real and if not password or hidden, display aggr options                                                  // if it's int or real and if not password or hidden, display aggr options
                                                 /* XXX Disabled until we have time to work on this                                                  /* XXX Disabled until we have time to work on this
                                                 if (  
                                                         (                                                  if ((! $this->password($k) && ! $this->hidden($k))
                                                                 ! $this->password($k) &&                                                  && (($this->col_is_number($k)) && (! isset($this->fdd[$k]['values'])))) {
                                                                 ! $this->hidden($k)  
                                                         ) && (  
                                                                 (  
                                                                         $this->col_is_number($k)  
                                                                 ) && (  
                                                                         ! isset($this->fdd[$k]['values'])  
                                                                 )  
                                                         )  
                                                 ) {  
                                                         $var_to_total = 'qf'.$k.'_aggr';                                                          $var_to_total = 'qf'.$k.'_aggr';
                                                         global $$var_to_total;                                                          global $$var_to_total;
                                                         $aggr_function = $$var_to_total;                                                          $aggr_function = $$var_to_total;
Line 1856  return true;
Line 1883  return true;
                 /*                  /*
                  * Each row of the HTML table is one record from the SQL Query                   * Each row of the HTML table is one record from the SQL Query
                  */                   */
                 //echo "<h4>".$this->query_make($qparts)."</h4>\n";  
                 $res      = $this->myquery($this->query_make($qparts),__LINE__);                  $res      = $this->myquery($this->query_make($qparts),__LINE__);
                 $first    = true;                  $first    = true;
                 $rowCount = 0;                  $rowCount = 0;
Line 2003  return true;
Line 2029  return true;
                                                 echo '      <td'.$colattrs.'>';                                                  echo '      <td'.$colattrs.'>';
                                                 if (! $this->hidden($k) && ! $this->password($k)) {                                                  if (! $this->hidden($k) && ! $this->password($k)) {
                                                         // displayable                                                          // displayable
                                                         if (isset($this->fdd[$k]['URL'])) {                                                          if (isset($this->fdd[$k]['URL'])
                                                                 // it's an URL                                                                          || isset($this->fdd[$k]['URLprefix'])
                                                                           || 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
                                                                      to be able to use in the URL string. */
                                                                 $key      = $row[$this->key_num];                                                                  $key      = $row[$this->key_num];
                                                                 $name     = $this->fds[$k];                                                                  $name     = $this->fds[$k];
                                                                 $value    = $row[$k];                                                                  $value    = $row[$k];
                                                                 $page     = $this->page_name;                                                                  $page     = $this->page_name;
                                                                 $urlquery = $urlqueryproto."&rec=$key";                                                                  $urlstr   = $urlqueryproto.'&rec='.$key;
                                                                 // remember that $row is a mysql_fetch_array, so it contains all fields                                                                  $urllink = isset($this->fdd[$k]['URL'])
                                                                 //debug_var('URL',$this->fdd[$k]);                                                                          ? eval('return "'.$this->fdd[$k]['URL'].'";')
                                                                 //debug_var('urlquery',$urlquery);                                                                          : $value;
                                                                 // it's built, now eval it  
                                                                 $urlstr = eval('return "'.$urlquery.'";');  
                                                                 //debug_var('urlstr',$urlstr);  
                                                                 $urllink = eval('return "'.$this->fdd[$k]['URL'].'";');  
                                                                 // TODO: document this, is is undocumented  
                                                                 $urldisp = isset($this->fdd[$k]['URLdisp'])                                                                  $urldisp = isset($this->fdd[$k]['URLdisp'])
                                                                         ? eval('return "'.$this->fdd[$k]['URLdisp'].'";')                                                                          ? eval('return "'.$this->fdd[$k]['URLdisp'].'";')
                                                                         : $value;                                                                          : $value;
                                                                 $target = isset($this->fdd[$k]['URLtarget'])                                                                  $target = isset($this->fdd[$k]['URLtarget'])
                                                                         ? 'target="'.htmlspecialchars($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'];
                                                                 $urllink = htmlspecialchars($urllink);                                                                  $urllink = htmlspecialchars($urllink);
                                                                 $urldisp = htmlspecialchars($urldisp);                                                                  $urldisp = htmlspecialchars($urldisp);
                                                                 echo '<a '.$target.'class="pme_a_u" href="'.$urllink.'">'.$urldisp.'</a>';                                                                  echo '<a '.$target.'class="pme_a_u" href="'.$urllink.'">'.$urldisp.'</a>';
Line 2195  return true;
Line 2219  return true;
                         $$lc  = $this->get_cgi_var($lc);                          $$lc  = $this->get_cgi_var($lc);
                         $m    = $this->web2plain($$l);  // get the field name and value                          $m    = $this->web2plain($$l);  // get the field name and value
                         $mc   = $this->web2plain($$lc); // get the comparison operator for numeric/date types                          $mc   = $this->web2plain($$lc); // get the comparison operator for numeric/date types
                         if (isset ($m)) {                          if (isset($m)) {
                                 if (is_array($m)) { // multiple selection has been used                                  if (is_array($m)) { // multiple selection has been used
                                         if (!in_array('*',$m)) {        // one '*' in a multiple selection is all you need                                          if (!in_array('*',$m)) {        // one '*' in a multiple selection is all you need
                                                 for ($n=0; $n<count($m); $n++) {                                                  for ($n=0; $n<count($m); $n++) {

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.13

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