home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / phpMyAdmin / libraries / tbl_replace_fields.inc.php < prev    next >
Encoding:
PHP Script  |  2008-06-23  |  4.4 KB  |  133 lines

  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4.  * handle field values (possibly uploaded from a file)
  5.  *
  6.  * garvin: original if-clause checked, whether input was stored in a possible
  7.  * fields_upload_XX var. Now check, if the field is set. If it is empty or a
  8.  * malicious file, do not alter fields contents. If an empty or invalid file is
  9.  * specified, the binary data gets deleter. Maybe a nice new text-variable is
  10.  * appropriate to document this behaviour.
  11.  *
  12.  * garvin: security cautions! You could trick the form and submit any file the
  13.  * webserver has access to for upload to a binary field. Shouldn't be that easy! ;)
  14.  *
  15.  * garvin: default is to advance to the field-value parsing. Will only be set to
  16.  * true when a binary file is uploaded, thus bypassing further manipulation of $val.
  17.  *
  18.  * note: grab_globals has extracted the fields from _FILES or HTTP_POST_FILES
  19.  *
  20.  * @version $Id: tbl_replace_fields.inc.php 11326 2008-06-17 21:32:48Z lem9 $
  21.  *
  22.  * @uses $_REQUEST
  23.  * @uses defined()
  24.  * @uses define()
  25.  * @uses bin2hex()
  26.  * @uses strlen()
  27.  * @uses md5()
  28.  * @uses implode()
  29.  * @uses PMA_NO_VARIABLES_IMPORT
  30.  * @uses PMA_sqlAddslashes()
  31.  */
  32. if (! defined('PHPMYADMIN')) {
  33.     exit;
  34. }
  35.  
  36. /**
  37.  * do not import request variable into global scope
  38.  */
  39. if (! defined('PMA_NO_VARIABLES_IMPORT')) {
  40.     define('PMA_NO_VARIABLES_IMPORT', true);
  41. }
  42. /**
  43.  * Gets some core libraries
  44.  */
  45. require_once './libraries/common.inc.php';
  46. require_once './libraries/File.class.php';
  47.  
  48. $file_to_insert = new PMA_File();
  49. $file_to_insert->checkTblChangeForm($key, $rowcount);
  50.  
  51. $possibly_uploaded_val = $file_to_insert->getContent();
  52.  
  53. if ($file_to_insert->isError()) {
  54.     $message .= $file_to_insert->getError();
  55. }
  56. $file_to_insert->cleanUp();
  57.  
  58. if (false !== $possibly_uploaded_val) {
  59.     $val = $possibly_uploaded_val;
  60. } else {
  61.  
  62.     // f i e l d    v a l u e    i n    t h e    f o r m
  63.  
  64.     if (isset($me_fields_type[$key])) {
  65.         $type = $me_fields_type[$key];
  66.     } else {
  67.         $type = '';
  68.     }
  69.  
  70.     $f = 'field_' . md5($key);
  71.  
  72.     if (0 === strlen($val)) {
  73.         // default
  74.         $val = "''";
  75.  
  76.         switch ($type) {
  77.             case 'enum':
  78.                 // if we have an enum, then construct the value
  79.             case 'set':
  80.                 // if we have a set, then construct the value
  81.             case 'foreign':
  82.                 // if we have a foreign key, then construct the value
  83.                 if (! empty($_REQUEST[$f]['multi_edit'][$rowcount])) {
  84.                     $val = implode(',', $_REQUEST[$f]['multi_edit'][$rowcount]);
  85.                     $val = "'" . PMA_sqlAddslashes($val) . "'";
  86.                 }
  87.                 break;
  88.             case 'protected':
  89.                 // here we are in protected mode (asked in the config)
  90.                 // so tbl_change has put this special value in the
  91.                 // fields array, so we do not change the field value
  92.                 // but we can still handle field upload
  93.  
  94.                 // garvin: when in UPDATE mode, do not alter field's contents. When in INSERT
  95.                 // mode, insert empty field because no values were submitted. If protected
  96.                 // blobs where set, insert original fields content.
  97.                 if (! empty($prot_row[$key])) {
  98.                     $val = '0x' . bin2hex($prot_row[$key]);
  99.                 } else {
  100.                     $val = '';
  101.                 }
  102.  
  103.                 break;
  104.             default:
  105.                 // best way to avoid problems in strict mode (works also in non-strict mode)
  106.                 if (isset($me_auto_increment)  && isset($me_auto_increment[$key])) {
  107.                     $val = 'NULL';
  108.                 }
  109.                 break;
  110.         }
  111.     } elseif ($type == 'bit') {
  112.         $val = preg_replace('/[^01]/', '0', $val);
  113.         $val = "b'" . PMA_sqlAddslashes($val) . "'";
  114.     } elseif (! ($type == 'timestamp' && $val == 'CURRENT_TIMESTAMP')) {
  115.         $val = "'" . PMA_sqlAddslashes($val) . "'";
  116.     }
  117.  
  118.     // Was the Null checkbox checked for this field?
  119.     // (if there is a value, we ignore the Null checkbox: this could
  120.     // be possible if Javascript is disabled in the browser)
  121.     if (isset($me_fields_null[$key])
  122.      && $val == "''") {
  123.         $val = 'NULL';
  124.     }
  125.  
  126.     // The Null checkbox was unchecked for this field
  127.     if (empty($val) && isset($me_fields_null_prev[$key]) && ! isset($me_fields_null[$key])) {
  128.         $val = "''";
  129.     }
  130. }  // end else (field value in the form)
  131. unset($type, $f);
  132. ?>
  133.