Merge branch 'MAINT_3_4_0' into QA_3_4
[phpmyadmin/crack.git] / libraries / tbl_replace_fields.inc.php
blob824d5bc063ac5e940f8b88ec9a714615887156e6
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * handle field values (possibly uploaded from a file)
6 * 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.
12 * 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! ;)
15 * 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.
18 * note: grab_globals has extracted the fields from _FILES or HTTP_POST_FILES
21 * @uses $_REQUEST
22 * @uses defined()
23 * @uses define()
24 * @uses bin2hex()
25 * @uses strlen()
26 * @uses md5()
27 * @uses implode()
28 * @uses PMA_NO_VARIABLES_IMPORT
29 * @uses PMA_sqlAddslashes()
30 * @package phpMyAdmin
32 if (! defined('PHPMYADMIN')) {
33 exit;
36 /**
37 * do not import request variable into global scope
39 if (! defined('PMA_NO_VARIABLES_IMPORT')) {
40 define('PMA_NO_VARIABLES_IMPORT', true);
42 /**
43 * Gets some core libraries
45 require_once './libraries/common.inc.php';
46 require_once './libraries/File.class.php';
48 $file_to_insert = new PMA_File();
49 $file_to_insert->checkTblChangeForm($key, $rowcount);
51 $possibly_uploaded_val = $file_to_insert->getContent();
53 if ($file_to_insert->isError()) {
54 $message .= $file_to_insert->getError();
56 $file_to_insert->cleanUp();
58 if (false !== $possibly_uploaded_val) {
59 $val = $possibly_uploaded_val;
60 } else {
62 // f i e l d v a l u e i n t h e f o r m
64 if (isset($me_fields_type[$key])) {
65 $type = $me_fields_type[$key];
66 } else {
67 $type = '';
70 // $key contains the md5() of the fieldname
71 $f = 'field_' . $key;
73 if (0 === strlen($val)) {
74 // default
75 $val = "''";
77 switch ($type) {
78 case 'enum':
79 // if we have an enum, then construct the value
80 case 'set':
81 // if we have a set, then construct the value
82 case 'foreign':
83 // if we have a foreign key, then construct the value
84 if (! empty($_REQUEST[$f]['multi_edit'][$rowcount])) {
85 $val = implode(',', $_REQUEST[$f]['multi_edit'][$rowcount]);
86 $val = "'" . PMA_sqlAddslashes($val) . "'";
88 break;
89 case 'protected':
90 // here we are in protected mode (asked in the config)
91 // so tbl_change has put this special value in the
92 // fields array, so we do not change the field value
93 // but we can still handle field upload
95 // when in UPDATE mode, do not alter field's contents. When in INSERT
96 // mode, insert empty field because no values were submitted. If protected
97 // blobs where set, insert original fields content.
98 if (! empty($prot_row[$me_fields_name[$key]])) {
99 $val = '0x' . bin2hex($prot_row[$me_fields_name[$key]]);
100 } else {
101 $val = '';
104 break;
105 default:
106 // best way to avoid problems in strict mode (works also in non-strict mode)
107 if (isset($me_auto_increment) && isset($me_auto_increment[$key])) {
108 $val = 'NULL';
110 break;
112 } elseif ($type == 'bit') {
113 $val = preg_replace('/[^01]/', '0', $val);
114 $val = "b'" . PMA_sqlAddslashes($val) . "'";
115 } elseif (! (($type == 'datetime' || $type == 'timestamp') && $val == 'CURRENT_TIMESTAMP')) {
116 $val = "'" . PMA_sqlAddslashes($val) . "'";
119 // Was the Null checkbox checked for this field?
120 // (if there is a value, we ignore the Null checkbox: this could
121 // be possible if Javascript is disabled in the browser)
122 if (isset($me_fields_null[$key])
123 && ($val == "''" || $val == '')) {
124 $val = 'NULL';
127 // The Null checkbox was unchecked for this field
128 if (empty($val) && isset($me_fields_null_prev[$key]) && ! isset($me_fields_null[$key])) {
129 $val = "''";
131 } // end else (field value in the form)
132 unset($type, $f);