/html/ops/phpMyAdmin-3.2.4-all-languages/libraries/tbl_replace_fields.inc.php

https://github.com/jackygrahamez/DrugDiscovery-Home · PHP · 134 lines · 65 code · 14 blank · 55 comment · 24 complexity · 3b0c00e73c09278d836474a7aeca1b69 MD5 · raw file

  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 12245 2009-02-23 08:36:34Z 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. * @package phpMyAdmin
  32. */
  33. if (! defined('PHPMYADMIN')) {
  34. exit;
  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. $file_to_insert = new PMA_File();
  48. $file_to_insert->checkTblChangeForm($key, $rowcount);
  49. $possibly_uploaded_val = $file_to_insert->getContent();
  50. if ($file_to_insert->isError()) {
  51. $message .= $file_to_insert->getError();
  52. }
  53. $file_to_insert->cleanUp();
  54. if (false !== $possibly_uploaded_val) {
  55. $val = $possibly_uploaded_val;
  56. } else {
  57. // f i e l d v a l u e i n t h e f o r m
  58. if (isset($me_fields_type[$key])) {
  59. $type = $me_fields_type[$key];
  60. } else {
  61. $type = '';
  62. }
  63. // $key contains the md5() of the fieldname
  64. $f = 'field_' . $key;
  65. if (0 === strlen($val)) {
  66. // default
  67. $val = "''";
  68. switch ($type) {
  69. case 'enum':
  70. // if we have an enum, then construct the value
  71. case 'set':
  72. // if we have a set, then construct the value
  73. case 'foreign':
  74. // if we have a foreign key, then construct the value
  75. if (! empty($_REQUEST[$f]['multi_edit'][$rowcount])) {
  76. $val = implode(',', $_REQUEST[$f]['multi_edit'][$rowcount]);
  77. $val = "'" . PMA_sqlAddslashes($val) . "'";
  78. }
  79. break;
  80. case 'protected':
  81. // here we are in protected mode (asked in the config)
  82. // so tbl_change has put this special value in the
  83. // fields array, so we do not change the field value
  84. // but we can still handle field upload
  85. // garvin: when in UPDATE mode, do not alter field's contents. When in INSERT
  86. // mode, insert empty field because no values were submitted. If protected
  87. // blobs where set, insert original fields content.
  88. if (! empty($prot_row[$me_fields_name[$key]])) {
  89. $val = '0x' . bin2hex($prot_row[$me_fields_name[$key]]);
  90. } else {
  91. $val = '';
  92. }
  93. break;
  94. default:
  95. // best way to avoid problems in strict mode (works also in non-strict mode)
  96. if (isset($me_auto_increment) && isset($me_auto_increment[$key])) {
  97. $val = 'NULL';
  98. }
  99. break;
  100. }
  101. } elseif ($type == 'bit') {
  102. $val = preg_replace('/[^01]/', '0', $val);
  103. $val = "b'" . PMA_sqlAddslashes($val) . "'";
  104. } elseif (! ($type == 'timestamp' && $val == 'CURRENT_TIMESTAMP')) {
  105. $val = "'" . PMA_sqlAddslashes($val) . "'";
  106. }
  107. // Was the Null checkbox checked for this field?
  108. // (if there is a value, we ignore the Null checkbox: this could
  109. // be possible if Javascript is disabled in the browser)
  110. if (isset($me_fields_null[$key])
  111. && $val == "''") {
  112. $val = 'NULL';
  113. }
  114. // The Null checkbox was unchecked for this field
  115. if (empty($val) && isset($me_fields_null_prev[$key]) && ! isset($me_fields_null[$key])) {
  116. $val = "''";
  117. }
  118. } // end else (field value in the form)
  119. unset($type, $f);
  120. ?>