PageRenderTime 56ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/pma/tbl_change.php

https://bitbucket.org/StasPiv/playzone
PHP | 1181 lines | 893 code | 100 blank | 188 comment | 199 complexity | a14c1082c934d534ca62727da2ead545 MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause, GPL-2.0, LGPL-2.1

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Displays form for editing and inserting new table rows
  5. *
  6. * register_globals_save (mark this file save for disabling register globals)
  7. *
  8. * @version $Id: tbl_change.php 12390 2009-05-04 16:05:24Z lem9 $
  9. * @package phpMyAdmin
  10. */
  11. /**
  12. * Gets the variables sent or posted to this script and displays the header
  13. */
  14. require_once './libraries/common.inc.php';
  15. /**
  16. * Ensures db and table are valid, else moves to the "parent" script
  17. */
  18. require_once './libraries/db_table_exists.lib.php';
  19. /**
  20. * Sets global variables.
  21. * Here it's better to use a if, instead of the '?' operator
  22. * to avoid setting a variable to '' when it's not present in $_REQUEST
  23. */
  24. /**
  25. * @todo this one is badly named, it's really a WHERE condition
  26. * and exists even for tables not having a primary key or unique key
  27. */
  28. if (isset($_REQUEST['primary_key'])) {
  29. $primary_key = $_REQUEST['primary_key'];
  30. }
  31. if (isset($_SESSION['edit_next'])) {
  32. $primary_key = $_SESSION['edit_next'];
  33. unset($_SESSION['edit_next']);
  34. $after_insert = 'edit_next';
  35. }
  36. if (isset($_REQUEST['sql_query'])) {
  37. $sql_query = $_REQUEST['sql_query'];
  38. }
  39. if (isset($_REQUEST['ShowFunctionFields'])) {
  40. $cfg['ShowFunctionFields'] = $_REQUEST['ShowFunctionFields'];
  41. }
  42. /**
  43. * load relation data, foreign keys
  44. */
  45. require_once './libraries/relation.lib.php';
  46. /**
  47. * file listing
  48. */
  49. require_once './libraries/file_listing.php';
  50. /**
  51. * Defines the url to return to in case of error in a sql statement
  52. * (at this point, $GLOBALS['goto'] will be set but could be empty)
  53. */
  54. if (empty($GLOBALS['goto'])) {
  55. if (strlen($table)) {
  56. // avoid a problem (see bug #2202709)
  57. $GLOBALS['goto'] = 'tbl_sql.php';
  58. } else {
  59. $GLOBALS['goto'] = 'db_sql.php';
  60. }
  61. }
  62. /**
  63. * @todo check if we could replace by "db_|tbl_" - please clarify!?
  64. */
  65. $_url_params = array(
  66. 'db' => $db,
  67. 'sql_query' => $sql_query
  68. );
  69. if (preg_match('@^tbl_@', $GLOBALS['goto'])) {
  70. $_url_params['table'] = $table;
  71. }
  72. $err_url = $GLOBALS['goto'] . PMA_generate_common_url($_url_params);
  73. unset($_url_params);
  74. /**
  75. * Sets parameters for links
  76. * where is this variable used?
  77. * replace by PMA_generate_common_url($url_params);
  78. */
  79. $url_query = PMA_generate_common_url($url_params, 'html', '');
  80. /**
  81. * get table information
  82. * @todo should be done by a Table object
  83. */
  84. require_once './libraries/tbl_info.inc.php';
  85. /**
  86. * Get comments for table fileds/columns
  87. */
  88. $comments_map = array();
  89. if ($GLOBALS['cfg']['ShowPropertyComments']) {
  90. $comments_map = PMA_getComments($db, $table);
  91. }
  92. /**
  93. * START REGULAR OUTPUT
  94. */
  95. /**
  96. * used in ./libraries/header.inc.php to load JavaScript library file
  97. */
  98. $GLOBALS['js_include'][] = 'tbl_change.js';
  99. /**
  100. * HTTP and HTML headers
  101. */
  102. require_once './libraries/header.inc.php';
  103. /**
  104. * Displays the query submitted and its result
  105. *
  106. * @todo where does $disp_message and $disp_query come from???
  107. */
  108. if (! empty($disp_message)) {
  109. if (! isset($disp_query)) {
  110. $disp_query = null;
  111. }
  112. PMA_showMessage($disp_message, $disp_query);
  113. }
  114. /**
  115. * Displays top menu links
  116. */
  117. require_once './libraries/tbl_links.inc.php';
  118. /**
  119. * Get the analysis of SHOW CREATE TABLE for this table
  120. * @todo should be handled by class Table
  121. */
  122. $show_create_table = PMA_DBI_fetch_value(
  123. 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
  124. 0, 1);
  125. $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
  126. unset($show_create_table);
  127. /**
  128. * Get the list of the fields of the current table
  129. */
  130. PMA_DBI_select_db($db);
  131. $table_fields = PMA_DBI_fetch_result('SHOW FIELDS FROM ' . PMA_backquote($table) . ';',
  132. null, null, null, PMA_DBI_QUERY_STORE);
  133. $rows = array();
  134. if (isset($primary_key)) {
  135. // when in edit mode load all selected rows from table
  136. $insert_mode = false;
  137. if (is_array($primary_key)) {
  138. $primary_key_array = $primary_key;
  139. } else {
  140. $primary_key_array = array(0 => $primary_key);
  141. }
  142. $result = array();
  143. $found_unique_key = false;
  144. foreach ($primary_key_array as $key_id => $primary_key) {
  145. $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' WHERE ' . $primary_key . ';';
  146. $result[$key_id] = PMA_DBI_query($local_query, null, PMA_DBI_QUERY_STORE);
  147. $rows[$key_id] = PMA_DBI_fetch_assoc($result[$key_id]);
  148. $primary_keys[$key_id] = str_replace('\\', '\\\\', $primary_key);
  149. // No row returned
  150. if (! $rows[$key_id]) {
  151. unset($rows[$key_id], $primary_key_array[$key_id]);
  152. PMA_showMessage($strEmptyResultSet, $local_query);
  153. echo "\n";
  154. require_once './libraries/footer.inc.php';
  155. } else { // end if (no record returned)
  156. $meta = PMA_DBI_get_fields_meta($result[$key_id]);
  157. if ($tmp = PMA_getUniqueCondition($result[$key_id], count($meta), $meta, $rows[$key_id], true)) {
  158. $found_unique_key = true;
  159. }
  160. unset($tmp);
  161. }
  162. }
  163. } else {
  164. // no primary key given, just load first row - but what happens if tbale is empty?
  165. $insert_mode = true;
  166. $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' LIMIT 1;', null, PMA_DBI_QUERY_STORE);
  167. $rows = array_fill(0, $cfg['InsertRows'], false);
  168. }
  169. // <markus@noga.de>
  170. // retrieve keys into foreign fields, if any
  171. $foreigners = PMA_getForeigners($db, $table);
  172. /**
  173. * Displays the form
  174. */
  175. // loic1: autocomplete feature of IE kills the "onchange" event handler and it
  176. // must be replaced by the "onpropertychange" one in this case
  177. $chg_evt_handler = (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER >= 5 && PMA_USR_BROWSER_VER < 7)
  178. ? 'onpropertychange'
  179. : 'onchange';
  180. // Had to put the URI because when hosted on an https server,
  181. // some browsers send wrongly this form to the http server.
  182. if ($cfg['CtrlArrowsMoving']) {
  183. ?>
  184. <!-- Set on key handler for moving using by Ctrl+arrows -->
  185. <script src="./js/keyhandler.js" type="text/javascript"></script>
  186. <script type="text/javascript">
  187. //<![CDATA[
  188. var switch_movement = 0;
  189. document.onkeydown = onKeyDownArrowsHandler;
  190. //]]>
  191. </script>
  192. <?php
  193. }
  194. $_form_params = array(
  195. 'db' => $db,
  196. 'table' => $table,
  197. 'goto' => $GLOBALS['goto'],
  198. 'err_url' => $err_url,
  199. 'sql_query' => $sql_query,
  200. );
  201. if (isset($primary_keys)) {
  202. foreach ($primary_key_array as $key_id => $primary_key) {
  203. $_form_params['primary_key[' . $key_id . ']'] = trim($primary_key);
  204. }
  205. }
  206. ?>
  207. <!-- Insert/Edit form -->
  208. <form method="post" action="tbl_replace.php" name="insertForm" <?php if ($is_upload) { echo ' enctype="multipart/form-data"'; } ?>>
  209. <?php
  210. echo PMA_generate_common_hidden_inputs($_form_params);
  211. $titles['Browse'] = PMA_getIcon('b_browse.png', $strBrowseForeignValues);
  212. // Set if we passed the first timestamp field
  213. $timestamp_seen = 0;
  214. $fields_cnt = count($table_fields);
  215. $tabindex = 0;
  216. $tabindex_for_function = +3000;
  217. $tabindex_for_null = +6000;
  218. $tabindex_for_value = 0;
  219. $o_rows = 0;
  220. $biggest_max_file_size = 0;
  221. // user can toggle the display of Function column
  222. // (currently does not work for multi-edits)
  223. $url_params['db'] = $db;
  224. $url_params['table'] = $table;
  225. if (isset($primary_key)) {
  226. $url_params['primary_key'] = trim($primary_key);
  227. }
  228. if (! empty($sql_query)) {
  229. $url_params['sql_query'] = $sql_query;
  230. }
  231. if (! $cfg['ShowFunctionFields']) {
  232. $this_url_params = array_merge($url_params,
  233. array('ShowFunctionFields' => 1));
  234. echo $strShow . ' : <a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '">' . $strFunction . '</a>' . "\n";
  235. }
  236. foreach ($rows as $row_id => $vrow) {
  237. if ($vrow === false) {
  238. unset($vrow);
  239. }
  240. $jsvkey = $row_id;
  241. $browse_foreigners_uri = '&amp;pk=' . $row_id;
  242. $vkey = '[multi_edit][' . $jsvkey . ']';
  243. $vresult = (isset($result) && is_array($result) && isset($result[$row_id]) ? $result[$row_id] : $result);
  244. if ($insert_mode && $row_id > 0) {
  245. echo '<input type="checkbox" checked="checked" name="insert_ignore_' . $row_id . '" id="insert_ignore_check_' . $row_id . '" />';
  246. echo '<label for="insert_ignore_check_' . $row_id . '">' . $strIgnore . '</label><br />' . "\n";
  247. }
  248. ?>
  249. <table>
  250. <thead>
  251. <tr>
  252. <th><?php echo $strField; ?></th>
  253. <th><?php echo $strType; ?></th>
  254. <?php
  255. if ($cfg['ShowFunctionFields']) {
  256. $this_url_params = array_merge($url_params,
  257. array('ShowFunctionFields' => 0));
  258. echo ' <th><a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '" title="' . $strHide . '">' . $strFunction . '</a></th>' . "\n";
  259. }
  260. ?>
  261. <th><?php echo $strNull; ?></th>
  262. <th><?php echo $strValue; ?></th>
  263. </tr>
  264. </thead>
  265. <tfoot>
  266. <tr>
  267. <th colspan="5" align="right" class="tblFooters">
  268. <input type="submit" value="<?php echo $strGo; ?>" />
  269. </th>
  270. </tr>
  271. </tfoot>
  272. <tbody>
  273. <?php
  274. // Sets a multiplier used for input-field counts (as zero cannot be used, advance the counter plus one)
  275. $m_rows = $o_rows + 1;
  276. $odd_row = true;
  277. for ($i = 0; $i < $fields_cnt; $i++) {
  278. if (! isset($table_fields[$i]['processed'])) {
  279. $table_fields[$i]['Field_html'] = htmlspecialchars($table_fields[$i]['Field']);
  280. $table_fields[$i]['Field_md5'] = md5($table_fields[$i]['Field']);
  281. // True_Type contains only the type (stops at first bracket)
  282. $table_fields[$i]['True_Type'] = preg_replace('@\(.*@s', '', $table_fields[$i]['Type']);
  283. // d a t e t i m e
  284. //
  285. // loic1: current date should not be set as default if the field is NULL
  286. // for the current row
  287. // lem9: but do not put here the current datetime if there is a default
  288. // value (the real default value will be set in the
  289. // Default value logic below)
  290. // Note: (tested in MySQL 4.0.16): when lang is some UTF-8,
  291. // $field['Default'] is not set if it contains NULL:
  292. // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Extra] => [True_Type] => datetime)
  293. // but, look what we get if we switch to iso: (Default is NULL)
  294. // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Default] => [Extra] => [True_Type] => datetime)
  295. // so I force a NULL into it (I don't think it's possible
  296. // to have an empty default value for DATETIME)
  297. // then, the "if" after this one will work
  298. if ($table_fields[$i]['Type'] == 'datetime'
  299. && ! isset($table_fields[$i]['Default'])
  300. && isset($table_fields[$i]['Null'])
  301. && $table_fields[$i]['Null'] == 'YES') {
  302. $table_fields[$i]['Default'] = null;
  303. }
  304. $table_fields[$i]['len'] =
  305. preg_match('@float|double@', $table_fields[$i]['Type']) ? 100 : -1;
  306. if (isset($comments_map[$table_fields[$i]['Field']])) {
  307. $table_fields[$i]['Field_title'] = '<span style="border-bottom: 1px dashed black;" title="'
  308. . htmlspecialchars($comments_map[$table_fields[$i]['Field']]) . '">'
  309. . $table_fields[$i]['Field_html'] . '</span>';
  310. } else {
  311. $table_fields[$i]['Field_title'] = $table_fields[$i]['Field_html'];
  312. }
  313. // The type column
  314. $table_fields[$i]['is_binary'] = stristr($table_fields[$i]['Type'], 'binary');
  315. $table_fields[$i]['is_blob'] = stristr($table_fields[$i]['Type'], 'blob');
  316. $table_fields[$i]['is_char'] = stristr($table_fields[$i]['Type'], 'char');
  317. $table_fields[$i]['first_timestamp'] = false;
  318. switch ($table_fields[$i]['True_Type']) {
  319. case 'set':
  320. $table_fields[$i]['pma_type'] = 'set';
  321. $table_fields[$i]['wrap'] = '';
  322. break;
  323. case 'enum':
  324. $table_fields[$i]['pma_type'] = 'enum';
  325. $table_fields[$i]['wrap'] = '';
  326. break;
  327. case 'timestamp':
  328. if (!$timestamp_seen) { // can only occur once per table
  329. $timestamp_seen = 1;
  330. $table_fields[$i]['first_timestamp'] = true;
  331. }
  332. $table_fields[$i]['pma_type'] = $table_fields[$i]['Type'];
  333. $table_fields[$i]['wrap'] = ' nowrap="nowrap"';
  334. break;
  335. default:
  336. $table_fields[$i]['pma_type'] = $table_fields[$i]['Type'];
  337. $table_fields[$i]['wrap'] = ' nowrap="nowrap"';
  338. break;
  339. }
  340. }
  341. $field = $table_fields[$i];
  342. $extracted_fieldspec = PMA_extractFieldSpec($field['Type']);
  343. if (-1 === $field['len']) {
  344. $field['len'] = PMA_DBI_field_len($vresult, $i);
  345. }
  346. $unnullify_trigger = $chg_evt_handler . "=\"return unNullify('"
  347. . PMA_escapeJsString($field['Field_md5']) . "', '"
  348. . PMA_escapeJsString($jsvkey) . "')\"";
  349. // Use an MD5 as an array index to avoid having special characters in the name atttibute (see bug #1746964 )
  350. $field_name_appendix = $vkey . '[' . $field['Field_md5'] . ']';
  351. $field_name_appendix_md5 = $field['Field_md5'] . $vkey . '[]';
  352. if ($field['Type'] == 'datetime'
  353. && ! isset($field['Default'])
  354. && ! is_null($field['Default'])
  355. && ($insert_mode || ! isset($vrow[$field['Field']]))) {
  356. // INSERT case or
  357. // UPDATE case with an NULL value
  358. $vrow[$field['Field']] = date('Y-m-d H:i:s', time());
  359. }
  360. ?>
  361. <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
  362. <td <?php echo ($cfg['LongtextDoubleTextarea'] && strstr($field['True_Type'], 'longtext') ? 'rowspan="2"' : ''); ?> align="center">
  363. <?php echo $field['Field_title']; ?>
  364. <input type="hidden" name="fields_name<?php echo $field_name_appendix; ?>" value="<?php echo $field['Field_html']; ?>"/>
  365. </td>
  366. <td align="center"<?php echo $field['wrap']; ?>>
  367. <?php echo $field['pma_type']; ?>
  368. </td>
  369. <?php
  370. // Prepares the field value
  371. $real_null_value = FALSE;
  372. $special_chars_encoded = '';
  373. if (isset($vrow)) {
  374. // On a BLOB that can have a NULL value, the is_null() returns
  375. // true if it has no content but for me this is different than
  376. // having been set explicitely to NULL so I put an exception here
  377. if (! $field['is_blob'] && is_null($vrow[$field['Field']])) {
  378. $real_null_value = TRUE;
  379. $vrow[$field['Field']] = '';
  380. $special_chars = '';
  381. $data = $vrow[$field['Field']];
  382. } elseif ($field['True_Type'] == 'bit') {
  383. $special_chars = PMA_printable_bit_value($vrow[$field['Field']], $extracted_fieldspec['spec_in_brackets']);
  384. } else {
  385. // loic1: special binary "characters"
  386. if ($field['is_binary'] || $field['is_blob']) {
  387. $vrow[$field['Field']] = PMA_replace_binary_contents($vrow[$field['Field']]);
  388. } // end if
  389. $special_chars = htmlspecialchars($vrow[$field['Field']]);
  390. //We need to duplicate the first \n or otherwise we will lose the first newline entered in a VARCHAR or TEXT column
  391. $special_chars_encoded = PMA_duplicateFirstNewline($special_chars);
  392. $data = $vrow[$field['Field']];
  393. } // end if... else...
  394. // loic1: if a timestamp field value is not included in an update
  395. // statement MySQL auto-update it to the current timestamp
  396. // lem9: however, things have changed since MySQL 4.1, so
  397. // it's better to set a fields_prev in this situation
  398. $backup_field = '<input type="hidden" name="fields_prev'
  399. . $field_name_appendix . '" value="'
  400. . htmlspecialchars($vrow[$field['Field']]) . '" />';
  401. } else {
  402. // loic1: display default values
  403. if (!isset($field['Default'])) {
  404. $field['Default'] = '';
  405. $real_null_value = TRUE;
  406. $data = '';
  407. } else {
  408. $data = $field['Default'];
  409. }
  410. if ($field['True_Type'] == 'bit') {
  411. $special_chars = PMA_printable_bit_value($field['Default'], $extracted_fieldspec['spec_in_brackets']);
  412. } else {
  413. $special_chars = htmlspecialchars($field['Default']);
  414. }
  415. $backup_field = '';
  416. $special_chars_encoded = PMA_duplicateFirstNewline($special_chars);
  417. }
  418. $idindex = ($o_rows * $fields_cnt) + $i + 1;
  419. $tabindex = (($idindex - 1) * 3) + 1;
  420. // The function column
  421. // -------------------
  422. // Change by Bernard M. Piller <bernard@bmpsystems.com>
  423. // We don't want binary data to be destroyed
  424. // Note: from the MySQL manual: "BINARY doesn't affect how the column is
  425. // stored or retrieved" so it does not mean that the contents is
  426. // binary
  427. if ($cfg['ShowFunctionFields']) {
  428. if (($cfg['ProtectBinary'] && $field['is_blob'] && !$is_upload)
  429. || ($cfg['ProtectBinary'] == 'all' && $field['is_binary'])) {
  430. echo ' <td align="center">' . $strBinary . '</td>' . "\n";
  431. } elseif (strstr($field['True_Type'], 'enum') || strstr($field['True_Type'], 'set')) {
  432. echo ' <td align="center">--</td>' . "\n";
  433. } else {
  434. ?>
  435. <td>
  436. <select name="funcs<?php echo $field_name_appendix; ?>" <?php echo $unnullify_trigger; ?> tabindex="<?php echo ($tabindex + $tabindex_for_function); ?>" id="field_<?php echo $idindex; ?>_1">
  437. <option></option>
  438. <?php
  439. $selected = '';
  440. // garvin: Find the current type in the RestrictColumnTypes. Will result in 'FUNC_CHAR'
  441. // or something similar. Then directly look up the entry in the RestrictFunctions array,
  442. // which will then reveal the available dropdown options
  443. if (isset($cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])])
  444. && isset($cfg['RestrictFunctions'][$cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])]])) {
  445. $current_func_type = $cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])];
  446. $dropdown = $cfg['RestrictFunctions'][$current_func_type];
  447. $default_function = $cfg['DefaultFunctions'][$current_func_type];
  448. } else {
  449. $dropdown = array();
  450. $default_function = '';
  451. }
  452. $dropdown_built = array();
  453. $op_spacing_needed = FALSE;
  454. // what function defined as default?
  455. // for the first timestamp we don't set the default function
  456. // if there is a default value for the timestamp
  457. // (not including CURRENT_TIMESTAMP)
  458. // and the column does not have the
  459. // ON UPDATE DEFAULT TIMESTAMP attribute.
  460. if ($field['True_Type'] == 'timestamp'
  461. && empty($field['Default'])
  462. && ! isset($analyzed_sql[0]['create_table_fields'][$field['Field']]['on_update_current_timestamp'])) {
  463. $default_function = $cfg['DefaultFunctions']['first_timestamp'];
  464. }
  465. if ($field['Key'] == 'PRI'
  466. && ($field['Type'] == 'char(36)' || $field['Type'] == 'varchar(36)')) {
  467. $default_function = $cfg['DefaultFunctions']['pk_char36'];
  468. }
  469. // garvin: loop on the dropdown array and print all available options for that field.
  470. foreach ($dropdown as $each_dropdown){
  471. echo '<option';
  472. if ($default_function === $each_dropdown) {
  473. echo ' selected="selected"';
  474. }
  475. echo '>' . $each_dropdown . '</option>' . "\n";
  476. $dropdown_built[$each_dropdown] = 'TRUE';
  477. $op_spacing_needed = TRUE;
  478. }
  479. // garvin: For compatibility's sake, do not let out all other functions. Instead
  480. // print a separator (blank) and then show ALL functions which weren't shown
  481. // yet.
  482. $cnt_functions = count($cfg['Functions']);
  483. for ($j = 0; $j < $cnt_functions; $j++) {
  484. if (!isset($dropdown_built[$cfg['Functions'][$j]]) || $dropdown_built[$cfg['Functions'][$j]] != 'TRUE') {
  485. // Is current function defined as default?
  486. $selected = ($field['first_timestamp'] && $cfg['Functions'][$j] == $cfg['DefaultFunctions']['first_timestamp'])
  487. || (!$field['first_timestamp'] && $cfg['Functions'][$j] == $default_function)
  488. ? ' selected="selected"'
  489. : '';
  490. if ($op_spacing_needed == TRUE) {
  491. echo ' ';
  492. echo '<option value="">--------</option>' . "\n";
  493. $op_spacing_needed = FALSE;
  494. }
  495. echo ' ';
  496. echo '<option' . $selected . '>' . $cfg['Functions'][$j] . '</option>' . "\n";
  497. }
  498. } // end for
  499. unset($selected);
  500. ?>
  501. </select>
  502. </td>
  503. <?php
  504. }
  505. } // end if ($cfg['ShowFunctionFields'])
  506. // The null column
  507. // ---------------
  508. $foreignData = PMA_getForeignData($foreigners, $field['Field'], false, '', '');
  509. echo ' <td>' . "\n";
  510. if ($field['Null'] == 'YES') {
  511. echo ' <input type="hidden" name="fields_null_prev' . $field_name_appendix . '"';
  512. if ($real_null_value && !$field['first_timestamp']) {
  513. echo ' value="on"';
  514. }
  515. echo ' />' . "\n";
  516. if (!(($cfg['ProtectBinary'] && $field['is_blob']) || ($cfg['ProtectBinary'] == 'all' && $field['is_binary']))) {
  517. echo ' <input type="checkbox" tabindex="' . ($tabindex + $tabindex_for_null) . '"'
  518. . ' name="fields_null' . $field_name_appendix . '"';
  519. if ($real_null_value && !$field['first_timestamp']) {
  520. echo ' checked="checked"';
  521. }
  522. echo ' id="field_' . ($idindex) . '_2"';
  523. $onclick = ' onclick="if (this.checked) {nullify(';
  524. if (strstr($field['True_Type'], 'enum')) {
  525. if (strlen($field['Type']) > 20) {
  526. $onclick .= '1, ';
  527. } else {
  528. $onclick .= '2, ';
  529. }
  530. } elseif (strstr($field['True_Type'], 'set')) {
  531. $onclick .= '3, ';
  532. } elseif ($foreigners && isset($foreigners[$field['Field']]) && $foreignData['foreign_link'] == false) {
  533. // foreign key in a drop-down
  534. $onclick .= '4, ';
  535. } elseif ($foreigners && isset($foreigners[$field['Field']]) && $foreignData['foreign_link'] == true) {
  536. // foreign key with a browsing icon
  537. $onclick .= '6, ';
  538. } else {
  539. $onclick .= '5, ';
  540. }
  541. $onclick .= '\'' . PMA_escapeJsString($field['Field_html']) . '\', \'' . $field['Field_md5'] . '\', \'' . PMA_escapeJsString($vkey) . '\'); this.checked = true}; return true" />' . "\n";
  542. echo $onclick;
  543. } else {
  544. echo ' <input type="hidden" name="fields_null' . $field_name_appendix . '"';
  545. if ($real_null_value && !$field['first_timestamp']) {
  546. echo ' value="on"';
  547. }
  548. echo ' />' . "\n";
  549. }
  550. }
  551. echo ' </td>' . "\n";
  552. // The value column (depends on type)
  553. // ----------------
  554. // See bug #1667887 for the reason why we don't use the maxlength
  555. // HTML attribute
  556. echo ' <td>' . "\n";
  557. if ($foreignData['foreign_link'] == true) {
  558. echo $backup_field . "\n";
  559. ?>
  560. <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>"
  561. value="foreign" />
  562. <input type="hidden" name="fields<?php echo $field_name_appendix; ?>"
  563. value="" id="field_<?php echo ($idindex); ?>_3A" />
  564. <input type="text" name="field_<?php echo $field_name_appendix_md5; ?>"
  565. class="textfield" <?php echo $unnullify_trigger; ?>
  566. tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
  567. id="field_<?php echo ($idindex); ?>_3"
  568. value="<?php echo htmlspecialchars($data); ?>" />
  569. <script type="text/javascript">
  570. //<![CDATA[
  571. document.writeln('<a target="_blank" onclick="window.open(this.href, \'foreigners\', \'width=640,height=240,scrollbars=yes,resizable=yes\'); return false"');
  572. document.write(' href="browse_foreigners.php?');
  573. document.write('<?php echo PMA_generate_common_url($db, $table); ?>');
  574. document.writeln('&amp;field=<?php echo PMA_escapeJsString(urlencode($field['Field']) . $browse_foreigners_uri); ?>">');
  575. document.writeln('<?php echo str_replace("'", "\'", $titles['Browse']); ?></a>');
  576. //]]>
  577. </script>
  578. <?php
  579. } elseif (is_array($foreignData['disp_row'])) {
  580. echo $backup_field . "\n";
  581. ?>
  582. <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>"
  583. value="foreign" />
  584. <input type="hidden" name="fields<?php echo $field_name_appendix; ?>"
  585. value="" id="field_<?php echo $idindex; ?>_3A" />
  586. <select name="field_<?php echo $field_name_appendix_md5; ?>"
  587. <?php echo $unnullify_trigger; ?>
  588. tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
  589. id="field_<?php echo ($idindex); ?>_3">
  590. <?php echo PMA_foreignDropdown($foreignData['disp_row'], $foreignData['foreign_field'], $foreignData['foreign_display'], $data, $cfg['ForeignKeyMaxLimit']); ?>
  591. </select>
  592. <?php
  593. // still needed? :
  594. unset($foreignData['disp_row']);
  595. } elseif ($cfg['LongtextDoubleTextarea'] && strstr($field['pma_type'], 'longtext')) {
  596. ?>
  597. &nbsp;</td>
  598. </tr>
  599. <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
  600. <td colspan="5" align="right">
  601. <?php echo $backup_field . "\n"; ?>
  602. <textarea name="fields<?php echo $field_name_appendix; ?>"
  603. rows="<?php echo ($cfg['TextareaRows']*2); ?>"
  604. cols="<?php echo ($cfg['TextareaCols']*2); ?>"
  605. dir="<?php echo $text_dir; ?>"
  606. id="field_<?php echo ($idindex); ?>_3"
  607. <?php echo $unnullify_trigger; ?>
  608. tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
  609. ><?php echo $special_chars_encoded; ?></textarea>
  610. <?php
  611. } elseif (strstr($field['pma_type'], 'text')) {
  612. echo $backup_field . "\n";
  613. ?>
  614. <textarea name="fields<?php echo $field_name_appendix; ?>"
  615. rows="<?php echo $cfg['TextareaRows']; ?>"
  616. cols="<?php echo $cfg['TextareaCols']; ?>"
  617. dir="<?php echo $text_dir; ?>"
  618. id="field_<?php echo ($idindex); ?>_3"
  619. <?php echo $unnullify_trigger; ?>
  620. tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
  621. ><?php echo $special_chars_encoded; ?></textarea>
  622. <?php
  623. echo "\n";
  624. if (strlen($special_chars) > 32000) {
  625. echo " </td>\n";
  626. echo ' <td>' . $strTextAreaLength;
  627. }
  628. } elseif ($field['pma_type'] == 'enum') {
  629. if (! isset($table_fields[$i]['values'])) {
  630. $table_fields[$i]['values'] = array();
  631. foreach ($extracted_fieldspec['enum_set_values'] as $val) {
  632. // Removes automatic MySQL escape format
  633. $val = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $val));
  634. $table_fields[$i]['values'][] = array(
  635. 'plain' => $val,
  636. 'html' => htmlspecialchars($val),
  637. );
  638. }
  639. }
  640. $field_enum_values = $table_fields[$i]['values'];
  641. ?>
  642. <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="enum" />
  643. <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
  644. <?php
  645. echo "\n" . ' ' . $backup_field . "\n";
  646. // show dropdown or radio depend on length
  647. if (strlen($field['Type']) > 20) {
  648. ?>
  649. <select name="field_<?php echo $field_name_appendix_md5; ?>"
  650. <?php echo $unnullify_trigger; ?>
  651. tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
  652. id="field_<?php echo ($idindex); ?>_3">
  653. <option value="">&nbsp;</option>
  654. <?php
  655. echo "\n";
  656. foreach ($field_enum_values as $enum_value) {
  657. echo ' ';
  658. echo '<option value="' . $enum_value['html'] . '"';
  659. if ($data == $enum_value['plain']
  660. || ($data == ''
  661. && (! isset($primary_key) || $field['Null'] != 'YES')
  662. && isset($field['Default'])
  663. && $enum_value['plain'] == $field['Default'])) {
  664. echo ' selected="selected"';
  665. }
  666. echo '>' . $enum_value['html'] . '</option>' . "\n";
  667. } // end for
  668. ?>
  669. </select>
  670. <?php
  671. } else {
  672. $j = 0;
  673. foreach ($field_enum_values as $enum_value) {
  674. echo ' ';
  675. echo '<input type="radio" name="field_' . $field_name_appendix_md5 . '"';
  676. echo ' value="' . $enum_value['html'] . '"';
  677. echo ' id="field_' . ($idindex) . '_3_' . $j . '"';
  678. echo ' onclick="';
  679. echo "if (typeof(document.forms['insertForm'].elements['fields_null"
  680. . $field_name_appendix . "']) != 'undefined') {document.forms['insertForm'].elements['fields_null"
  681. . $field_name_appendix . "'].checked = false}";
  682. echo '"';
  683. if ($data == $enum_value['plain']
  684. || ($data == ''
  685. && (! isset($primary_key) || $field['Null'] != 'YES')
  686. && isset($field['Default'])
  687. && $enum_value['plain'] == $field['Default'])) {
  688. echo ' checked="checked"';
  689. }
  690. echo ' tabindex="' . ($tabindex + $tabindex_for_value) . '" />';
  691. echo '<label for="field_' . $idindex . '_3_' . $j . '">'
  692. . $enum_value['html'] . '</label>' . "\n";
  693. $j++;
  694. } // end for
  695. } // end else
  696. } elseif ($field['pma_type'] == 'set') {
  697. if (! isset($table_fields[$i]['values'])) {
  698. $table_fields[$i]['values'] = array();
  699. foreach ($extracted_fieldspec['enum_set_values'] as $val) {
  700. $table_fields[$i]['values'][] = array(
  701. 'plain' => $val,
  702. 'html' => htmlspecialchars($val),
  703. );
  704. }
  705. $table_fields[$i]['select_size'] = min(4, count($table_fields[$i]['values']));
  706. }
  707. $field_set_values = $table_fields[$i]['values'];
  708. $select_size = $table_fields[$i]['select_size'];
  709. $vset = array_flip(explode(',', $data));
  710. echo $backup_field . "\n";
  711. ?>
  712. <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="set" />
  713. <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
  714. <select name="field_<?php echo $field_name_appendix_md5; ?>"
  715. size="<?php echo $select_size; ?>"
  716. multiple="multiple" <?php echo $unnullify_trigger; ?>
  717. tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
  718. id="field_<?php echo ($idindex); ?>_3">
  719. <?php
  720. foreach ($field_set_values as $field_set_value) {
  721. echo ' ';
  722. echo '<option value="' . $field_set_value['html'] . '"';
  723. if (isset($vset[$field_set_value['plain']])) {
  724. echo ' selected="selected"';
  725. }
  726. echo '>' . $field_set_value['html'] . '</option>' . "\n";
  727. } // end for
  728. ?>
  729. </select>
  730. <?php
  731. }
  732. // Change by Bernard M. Piller <bernard@bmpsystems.com>
  733. // We don't want binary data destroyed
  734. elseif ($field['is_binary'] || $field['is_blob']) {
  735. if (($cfg['ProtectBinary'] && $field['is_blob'])
  736. || ($cfg['ProtectBinary'] == 'all' && $field['is_binary'])) {
  737. echo "\n";
  738. // rajk - for blobstreaming
  739. $bs_reference_exists = FALSE;
  740. if (isset ($tbl_type) && strlen ($tbl_type) > 0)
  741. {
  742. // load PMA_Config
  743. $PMA_Config = $_SESSION['PMA_Config'];
  744. if (!empty($PMA_Config))
  745. {
  746. $requiredTblType = $PMA_Config->get('PBXT_NAME');
  747. if ($requiredTblType == strtolower ($tbl_type))
  748. {
  749. $pluginsExist = $PMA_Config->get('BLOBSTREAMING_PLUGINS_EXIST');
  750. // check if blobstreaming plugins exist
  751. if ($pluginsExist)
  752. {
  753. $bs_tables = $PMA_Config->get('BLOBSTREAMABLE_DATABASES');
  754. if (!empty($bs_tables) && strlen($db) > 0)
  755. {
  756. $bs_tables = $bs_tables[$db];
  757. if (isset($bs_tables))
  758. {
  759. $allBSTablesExist = TRUE;
  760. foreach ($bs_tables as $table_key=>$bs_tbl)
  761. if (!$bs_tables[$table_key]['Exists'])
  762. {
  763. $allBSTablesExist = FALSE;
  764. break;
  765. }
  766. if ($allBSTablesExist)
  767. $bs_reference_exists = PMA_BS_ReferenceExists($data, $db);
  768. } // end if (isset($bs_tables))
  769. } // end if (!empty($bs_tables) && strlen($db) > 0)
  770. } // end if ($pluginsExist)
  771. } // end if ($requiredTblType == strtolower ($tbl_type))
  772. } // end if (!empty($PMA_Config))
  773. } // end if (isset ($tbl_type) && strlen ($tbl_type) > 0)
  774. if ($bs_reference_exists)
  775. {
  776. echo '<input type="hidden" name="remove_blob_ref_' . $field['Field_md5'] . $vkey . '" value="' . $data . '" />';
  777. echo '<input type="checkbox" name="remove_blob_repo_' . $field['Field_md5'] . $vkey . '" /> ' . $strBLOBRepositoryRemove . "<br />";
  778. echo PMA_BS_CreateReferenceLink($data, $db);
  779. echo "<br />";
  780. }
  781. else
  782. {
  783. echo $strBinaryDoNotEdit;
  784. if (isset($data)) {
  785. $data_size = PMA_formatByteDown(strlen(stripslashes($data)), 3, 1);
  786. echo ' ('. $data_size [0] . ' ' . $data_size[1] . ')';
  787. unset($data_size);
  788. }
  789. echo "\n";
  790. } // end if ($bs_reference_exists)
  791. ?>
  792. <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="protected" />
  793. <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
  794. <?php
  795. } elseif ($field['is_blob']) {
  796. echo "\n";
  797. echo $backup_field . "\n";
  798. ?>
  799. <textarea name="fields<?php echo $field_name_appendix; ?>"
  800. rows="<?php echo $cfg['TextareaRows']; ?>"
  801. cols="<?php echo $cfg['TextareaCols']; ?>"
  802. dir="<?php echo $text_dir; ?>"
  803. id="field_<?php echo ($idindex); ?>_3"
  804. <?php echo $unnullify_trigger; ?>
  805. tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
  806. ><?php echo $special_chars_encoded; ?></textarea>
  807. <?php
  808. } else {
  809. // field size should be at least 4 and max 40
  810. $fieldsize = min(max($field['len'], 4), 40);
  811. echo "\n";
  812. echo $backup_field . "\n";
  813. ?>
  814. <input type="text" name="fields<?php echo $field_name_appendix; ?>"
  815. value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>"
  816. class="textfield" <?php echo $unnullify_trigger; ?>
  817. tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
  818. id="field_<?php echo ($idindex); ?>_3" />
  819. <?php
  820. } // end if...elseif...else
  821. // Upload choice (only for BLOBs because the binary
  822. // attribute does not imply binary contents)
  823. // (displayed whatever value the ProtectBinary has)
  824. if ($is_upload && $field['is_blob']) {
  825. // added by rajk
  826. // check if field type is of longblob
  827. if ($field['pma_type'] == "longblob")
  828. {
  829. if (isset ($tbl_type) && strlen ($tbl_type) > 0)
  830. {
  831. // load PMA Config
  832. $PMA_Config = $_SESSION['PMA_Config'];
  833. // is PMA_Config's data loaded? continue only if it is
  834. if (!empty($PMA_Config))
  835. {
  836. $requiredTblType = $PMA_Config->get('PBXT_NAME');
  837. if ($requiredTblType == strtolower ($tbl_type))
  838. {
  839. $pluginsExist = $PMA_Config->get('BLOBSTREAMING_PLUGINS_EXIST');
  840. // check if blobstreaming plugins exist
  841. if ($pluginsExist)
  842. {
  843. $curlExists = $PMA_Config->get('CURL_EXISTS');
  844. // check if CURL exists
  845. if ($curlExists)
  846. {
  847. $bs_tables = $PMA_Config->get('BLOBSTREAMABLE_DATABASES');
  848. // check for BLOBStreamable databases and if current database name is provided
  849. if (!empty($bs_tables) && strlen($db) > 0)
  850. {
  851. $bs_tables = $bs_tables[$db];
  852. // check if reference to BLOBStreaming tables exists
  853. if (isset($bs_tables))
  854. {
  855. $allBSTablesExist = TRUE;
  856. foreach ($bs_tables as $table_key=>$bs_tbl)
  857. if (!$bs_tables[$table_key]['Exists'])
  858. {
  859. $allBSTablesExist = FALSE;
  860. break;
  861. }
  862. // check if necessary BLOBStreaming tables exist
  863. if ($allBSTablesExist)
  864. {
  865. echo '<br />';
  866. echo '<input type="checkbox" name="upload_blob_repo_' . $field['Field_md5'] . $vkey . '" /> ' . $strBLOBRepositoryUpload;
  867. } // end if ($allBSTablesExist)
  868. } // end if (isset($bs_tables)
  869. } // end if (!empty($bs_tables) && strlen ($db) > 0)
  870. } // end if ($curlExists)
  871. } // end if ($pluginsExist)
  872. } // end if ($requiredTblType == strtolower ($tbl_type))
  873. } // end if (!empty($PMA_Config))
  874. } // end if (isset ($tbl_type) && strlen ($tbl_type) > 0)
  875. }
  876. echo '<br />';
  877. echo '<input type="file" name="fields_upload_' . $field['Field_md5'] . $vkey . '" class="textfield" id="field_' . $idindex . '_3" size="10" />&nbsp;';
  878. // find maximum upload size, based on field type
  879. /**
  880. * @todo with functions this is not so easy, as you can basically
  881. * process any data with function like MD5
  882. */
  883. $max_field_sizes = array(
  884. 'tinyblob' => '256',
  885. 'blob' => '65536',
  886. 'mediumblob' => '16777216',
  887. 'longblob' => '4294967296'); // yeah, really
  888. $this_field_max_size = $max_upload_size; // from PHP max
  889. if ($this_field_max_size > $max_field_sizes[$field['pma_type']]) {
  890. $this_field_max_size = $max_field_sizes[$field['pma_type']];
  891. }
  892. echo PMA_displayMaximumUploadSize($this_field_max_size) . "\n";
  893. // do not generate here the MAX_FILE_SIZE, because we should
  894. // put only one in the form to accommodate the biggest field
  895. if ($this_field_max_size > $biggest_max_file_size) {
  896. $biggest_max_file_size = $this_field_max_size;
  897. }
  898. }
  899. if (!empty($cfg['UploadDir'])) {
  900. $files = PMA_getFileSelectOptions(PMA_userDir($cfg['UploadDir']));
  901. if ($files === FALSE) {
  902. echo ' <font color="red">' . $strError . '</font><br />' . "\n";
  903. echo ' ' . $strWebServerUploadDirectoryError . "\n";
  904. } elseif (!empty($files)) {
  905. echo "<br />\n";
  906. echo ' <i>' . $strOr . '</i>' . ' ' . $strWebServerUploadDirectory . ':<br />' . "\n";
  907. echo ' <select size="1" name="fields_uploadlocal_' . $field['Field_md5'] . $vkey . '">' . "\n";
  908. echo ' <option value="" selected="selected"></option>' . "\n";
  909. echo $files;
  910. echo ' </select>' . "\n";
  911. }
  912. } // end if (web-server upload directory)
  913. } // end elseif (binary or blob)
  914. else {
  915. // field size should be at least 4 and max 40
  916. $fieldsize = min(max($field['len'], 4), 40);
  917. echo $backup_field . "\n";
  918. if ($field['is_char'] && ($cfg['CharEditing'] == 'textarea' || strpos($data, "\n") !== FALSE)) {
  919. echo "\n";
  920. ?>
  921. <textarea name="fields<?php echo $field_name_appendix; ?>"
  922. rows="<?php echo $cfg['CharTextareaRows']; ?>"
  923. cols="<?php echo $cfg['CharTextareaCols']; ?>"
  924. dir="<?php echo $text_dir; ?>"
  925. id="field_<?php echo ($idindex); ?>_3"
  926. <?php echo $unnullify_trigger; ?>
  927. tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
  928. ><?php echo $special_chars_encoded; ?></textarea>
  929. <?php
  930. } else {
  931. ?>
  932. <input type="text" name="fields<?php echo $field_name_appendix; ?>"
  933. value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>"
  934. class="textfield" <?php echo $unnullify_trigger; ?>
  935. tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
  936. id="field_<?php echo ($idindex); ?>_3" />
  937. <?php
  938. if ($field['Extra'] == 'auto_increment') {
  939. ?>
  940. <input type="hidden" name="auto_increment<?php echo $field_name_appendix; ?>" value="1" />
  941. <?php
  942. } // end if
  943. if (substr($field['pma_type'], 0, 9) == 'timestamp') {
  944. ?>
  945. <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="timestamp" />
  946. <?php
  947. }
  948. if ($field['True_Type'] == 'bit') {
  949. ?>
  950. <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="bit" />
  951. <?php
  952. }
  953. if ($field['pma_type'] == 'date' || $field['pma_type'] == 'datetime' || substr($field['pma_type'], 0, 9) == 'timestamp') {
  954. // the _3 suffix points to the date field
  955. // the _2 suffix points to the corresponding NULL checkbox
  956. ?>
  957. <script type="text/javascript">
  958. //<![CDATA[
  959. document.write('<a title="<?php echo $strCalendar;?>"');
  960. document.write(' href="javascript:openCalendar(\'<?php echo PMA_generate_common_url();?>\', \'insertForm\', \'field_<?php echo ($idindex); ?>_3\', \'<?php echo (substr($field['pma_type'], 0, 9) == 'timestamp') ? 'datetime' : substr($field['pma_type'], 0, 9); ?>\', \'field_<?php echo ($idindex); ?>_2\')">');
  961. document.write('<img class="calendar"');
  962. document.write(' src="<?php echo $pmaThemeImage; ?>b_calendar.png"');
  963. document.write(' alt="<?php echo $strCalendar; ?>"/></a>');
  964. //]]>
  965. </script>
  966. <?php
  967. }
  968. }
  969. }
  970. ?>
  971. </td>
  972. </tr>
  973. <?php
  974. $odd_row = !$odd_row;
  975. } // end for
  976. $o_rows++;
  977. echo ' </tbody></table><br />';
  978. } // end foreach on multi-edit
  979. ?>
  980. <br />
  981. <fieldset>
  982. <table border="0" cellpadding="5" cellspacing="0">
  983. <tr>
  984. <td valign="middle" nowrap="nowrap">
  985. <select name="submit_type" tabindex="<?php echo ($tabindex + $tabindex_for_value + 1); ?>">
  986. <?php
  987. if (isset($primary_key)) {
  988. ?>
  989. <option value="<?php echo $strSave; ?>"><?php echo $strSave; ?></option>
  990. <?php
  991. }
  992. ?>
  993. <option value="<?php echo $strInsertAsNewRow; ?>"><?php echo $strInsertAsNewRow; ?></option>
  994. </select>
  995. <?php
  996. echo "\n";
  997. if (!isset($after_insert)) {
  998. $after_insert = 'back';
  999. }
  1000. ?>
  1001. </td>
  1002. <td valign="middle">
  1003. &nbsp;&nbsp;&nbsp;<strong><?php echo $strAndT

Large files files are truncated, but you can click here to view the full file