PageRenderTime 48ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/pma/libraries/tbl_properties.inc.php

https://bitbucket.org/StasPiv/playzone
PHP | 765 lines | 559 code | 98 blank | 108 comment | 171 complexity | 02c97e94bb9c1febb9e606c8d537d7a2 MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause, GPL-2.0, LGPL-2.1
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Display form for changing/adding table fields/columns
  5. *
  6. * included by tbl_addfield.php, -_alter.php, -_create.php
  7. * @version $Id: tbl_properties.inc.php 12284 2009-03-03 16:41:41Z nijel $
  8. * @package phpMyAdmin
  9. */
  10. if (! defined('PHPMYADMIN')) {
  11. exit;
  12. }
  13. /**
  14. * Check parameters
  15. */
  16. require_once './libraries/common.inc.php';
  17. PMA_checkParameters(array('db', 'table', 'action', 'num_fields'));
  18. // Get available character sets and storage engines
  19. require_once './libraries/mysql_charsets.lib.php';
  20. require_once './libraries/StorageEngine.class.php';
  21. /**
  22. * Class for partition management
  23. */
  24. require_once './libraries/Partition.class.php';
  25. if (is_int($cfg['DefaultPropDisplay'])) {
  26. if ($num_fields <= $cfg['DefaultPropDisplay']) {
  27. $display_type = 'vertical';
  28. } else {
  29. $display_type = 'horizontal';
  30. }
  31. } else {
  32. $display_type = $cfg['DefaultPropDisplay'];
  33. }
  34. if ('horizontal' == $display_type) {
  35. $length_values_input_size = 8;
  36. } else {
  37. $length_values_input_size = 30;
  38. }
  39. $_form_params = array(
  40. 'db' => $db,
  41. 'table' => $table,
  42. );
  43. if ($action == 'tbl_create.php') {
  44. $_form_params['reload'] = 1;
  45. } elseif ($action == 'tbl_addfield.php') {
  46. $_form_params['field_where'] = $_REQUEST['field_where'];
  47. $_form_params['after_field'] = $_REQUEST['after_field'];
  48. }
  49. if (isset($num_fields)) {
  50. $_form_params['orig_num_fields'] = $num_fields;
  51. }
  52. if (isset($_REQUEST['field_where'])) {
  53. $_form_params['orig_field_where'] = $_REQUEST['field_where'];
  54. }
  55. if (isset($_REQUEST['after_field'])) {
  56. $_form_params['orig_after_field'] = $_REQUEST['after_field'];
  57. }
  58. if (isset($selected) && is_array($selected)) {
  59. foreach ($selected as $o_fld_nr => $o_fld_val) {
  60. $_form_params['selected[' . $o_fld_nr . ']'] = $o_fld_val;
  61. if (! isset($true_selected)) {
  62. $_form_params['true_selected[' . $o_fld_nr . ']'] = $o_fld_val;
  63. }
  64. }
  65. if (isset($true_selected) && is_array($true_selected)) {
  66. foreach ($true_selected as $o_fld_nr => $o_fld_val) {
  67. $_form_params['true_selected[' . $o_fld_nr . ']'] = $o_fld_val;
  68. }
  69. }
  70. } elseif (isset($_REQUEST['field'])) {
  71. $_form_params['orig_field'] = $_REQUEST['field'];
  72. if (isset($orig_field)) {
  73. $_form_params['true_selected[]'] = $orig_field;
  74. } else {
  75. $_form_params['true_selected[]'] = $_REQUEST['field'];
  76. }
  77. }
  78. $is_backup = ($action != 'tbl_create.php' && $action != 'tbl_addfield.php');
  79. $header_cells = array();
  80. $content_cells = array();
  81. $header_cells[] = $strField;
  82. $header_cells[] = $strType
  83. . ($GLOBALS['cfg']['ReplaceHelpImg']
  84. ? PMA_showMySQLDocu('SQL-Syntax', 'data-types')
  85. : '<br /><span style="font-weight: normal">' . PMA_showMySQLDocu('SQL-Syntax', 'data-types')
  86. . '</span>');
  87. $header_cells[] = $strLengthSet . PMA_showHint($strSetEnumVal);
  88. $header_cells[] = $strDefault . PMA_showHint($strDefaultValueHelp);
  89. $header_cells[] = $strCollation;
  90. $header_cells[] = $strAttr;
  91. $header_cells[] = $strNull;
  92. // lem9: We could remove this 'if' and let the key information be shown and
  93. // editable. However, for this to work, tbl_alter must be modified to use the
  94. // key fields, as tbl_addfield does.
  95. if (!$is_backup) {
  96. $header_cells[] = $strIndex;
  97. }
  98. $header_cells[] = '<abbr title="AUTO_INCREMENT">' . ($display_type == 'horizontal' ? 'A_I' : 'AUTO_INCREMENT') . '</abbr>';
  99. require_once './libraries/relation.lib.php';
  100. require_once './libraries/transformations.lib.php';
  101. $cfgRelation = PMA_getRelationsParam();
  102. $comments_map = array();
  103. $mime_map = array();
  104. $available_mime = array();
  105. $comments_map = PMA_getComments($db, $table);
  106. $header_cells[] = $strComments;
  107. if ($cfgRelation['mimework'] && $cfg['BrowseMIME']) {
  108. $mime_map = PMA_getMIME($db, $table);
  109. $available_mime = PMA_getAvailableMIMEtypes();
  110. $hint = '<br />' .
  111. sprintf($strMIME_transformation_note,
  112. '<a href="transformation_overview.php?'
  113. . PMA_generate_common_url($db, $table) . '" target="_blank">',
  114. '</a>');
  115. $header_cells[] = $strMIME_MIMEtype;
  116. $header_cells[] = $strMIME_transformation;
  117. $header_cells[] = $strMIME_transformation_options
  118. . PMA_showHint($strMIME_transformation_options_note . $hint);
  119. }
  120. // garvin: workaround for field_fulltext, because its submitted indizes contain
  121. // the index as a value, not a key. Inserted here for easier maintaineance
  122. // and less code to change in existing files.
  123. if (isset($field_fulltext) && is_array($field_fulltext)) {
  124. foreach ($field_fulltext as $fulltext_nr => $fulltext_indexkey) {
  125. $submit_fulltext[$fulltext_indexkey] = $fulltext_indexkey;
  126. }
  127. }
  128. for ($i = 0; $i < $num_fields; $i++) {
  129. if (! empty($regenerate)) {
  130. // An error happened with previous inputs, so we will restore the data
  131. // to embed it once again in this form.
  132. $row['Field'] = (isset($_REQUEST['field_name'][$i]) ? $_REQUEST['field_name'][$i] : false);
  133. $row['Type'] = (isset($_REQUEST['field_type'][$i]) ? $_REQUEST['field_type'][$i] : false);
  134. $row['Collation'] = (isset($_REQUEST['field_collation'][$i]) ? $_REQUEST['field_collation'][$i] : '');
  135. $row['Null'] = (isset($_REQUEST['field_null'][$i]) ? $_REQUEST['field_null'][$i] : '');
  136. if (isset($_REQUEST['field_key'][$i]) && $_REQUEST['field_key'][$i] == 'primary_' . $i) {
  137. $row['Key'] = 'PRI';
  138. } elseif (isset($_REQUEST['field_key'][$i]) && $_REQUEST['field_key'][$i] == 'index_' . $i) {
  139. $row['Key'] = 'MUL';
  140. } elseif (isset($_REQUEST['field_key'][$i]) && $_REQUEST['field_key'][$i] == 'unique_' . $i) {
  141. $row['Key'] = 'UNI';
  142. } elseif (isset($_REQUEST['field_key'][$i]) && $_REQUEST['field_key'][$i] == 'fulltext_' . $i) {
  143. $row['Key'] = 'FULLTEXT';
  144. } else {
  145. $row['Key'] = '';
  146. }
  147. // put None in the drop-down for Default, when someone adds a field
  148. $row['DefaultType'] = (isset($_REQUEST['field_default_type'][$i]) ? $_REQUEST['field_default_type'][$i] : 'NONE');
  149. $row['DefaultValue'] = (isset($_REQUEST['field_default_value'][$i]) ? $_REQUEST['field_default_value'][$i] : '');
  150. switch ($row['DefaultType']) {
  151. case 'NONE' :
  152. $row['Default'] = null;
  153. break;
  154. case 'USER_DEFINED' :
  155. $row['Default'] = $row['DefaultValue'];
  156. break;
  157. case 'NULL' :
  158. case 'CURRENT_TIMESTAMP' :
  159. $row['Default'] = $row['DefaultType'];
  160. break;
  161. }
  162. $row['Extra'] = (isset($_REQUEST['field_extra'][$i]) ? $_REQUEST['field_extra'][$i] : false);
  163. $row['Comment'] = (isset($submit_fulltext[$i]) && ($submit_fulltext[$i] == $i) ? 'FULLTEXT' : false);
  164. $submit_length = (isset($_REQUEST['field_length'][$i]) ? $_REQUEST['field_length'][$i] : false);
  165. $submit_attribute = (isset($_REQUEST['field_attribute'][$i]) ? $_REQUEST['field_attribute'][$i] : false);
  166. $submit_default_current_timestamp = (isset($_REQUEST['field_default_current_timestamp'][$i]) ? true : false);
  167. if (isset($_REQUEST['field_comments'][$i])) {
  168. $comments_map[$row['Field']] = $_REQUEST['field_comments'][$i];
  169. }
  170. if (isset($_REQUEST['field_mimetype'][$i])) {
  171. $mime_map[$row['Field']]['mimetype'] = $_REQUEST['field_mimetype'][$i];
  172. }
  173. if (isset($_REQUEST['field_transformation'][$i])) {
  174. $mime_map[$row['Field']]['transformation'] = $_REQUEST['field_transformation'][$i];
  175. }
  176. if (isset($_REQUEST['field_transformation_options'][$i])) {
  177. $mime_map[$row['Field']]['transformation_options'] = $_REQUEST['field_transformation_options'][$i];
  178. }
  179. } elseif (isset($fields_meta[$i])) {
  180. $row = $fields_meta[$i];
  181. switch ($row['Default']) {
  182. case null:
  183. if ($row['Null'] == 'YES') {
  184. $row['DefaultType'] = 'NULL';
  185. } else {
  186. $row['DefaultType'] = 'NONE';
  187. }
  188. $row['DefaultValue'] = '';
  189. break;
  190. case 'CURRENT_TIMESTAMP':
  191. $row['DefaultType'] = 'CURRENT_TIMESTAMP';
  192. $row['DefaultValue'] = '';
  193. break;
  194. default:
  195. $row['DefaultType'] = 'USER_DEFINED';
  196. $row['DefaultValue'] = $row['Default'];
  197. break;
  198. }
  199. }
  200. if (isset($row['Type'])) {
  201. $extracted_fieldspec = PMA_extractFieldSpec($row['Type']);
  202. if ($extracted_fieldspec['type'] == 'bit') {
  203. $row['Default'] = PMA_printable_bit_value($row['Default'], $extracted_fieldspec['spec_in_brackets']);
  204. }
  205. }
  206. // Cell index: If certain fields get left out, the counter shouldn't change.
  207. $ci = 0;
  208. // Everytime a cell shall be left out the STRG-jumping feature, $ci_offset
  209. // has to be incremented ($ci_offset++)
  210. $ci_offset = -1;
  211. // old column name
  212. if ($is_backup) {
  213. if (! empty($true_selected[$i])) {
  214. $_form_params['field_orig[' . $i . ']'] = $true_selected[$i];
  215. } elseif (isset($row['Field'])) {
  216. $_form_params['field_orig[' . $i . ']'] = $row['Field'];
  217. } else {
  218. $_form_params['field_orig[' . $i . ']'] = '';
  219. }
  220. }
  221. // column name
  222. $content_cells[$i][$ci] = '<input id="field_' . $i . '_' . ($ci - $ci_offset) . '"'
  223. . ' type="text" name="field_name[' . $i . ']"'
  224. . ' maxlength="64" class="textfield" title="' . $strField . '"'
  225. . ' size="' . ($GLOBALS['cfg']['DefaultPropDisplay'] == 'horizontal' ? '10' : '30') . '"'
  226. . ' value="' . (isset($row['Field']) ? htmlspecialchars($row['Field']) : '') . '"'
  227. . ' />';
  228. $ci++;
  229. // column type
  230. $content_cells[$i][$ci] = '<select name="field_type[' . $i . ']"'
  231. .' id="field_' . $i . '_' . ($ci - $ci_offset) . '" >';
  232. if (empty($row['Type'])) {
  233. // creating a column
  234. $row['Type'] = '';
  235. $type = '';
  236. } else {
  237. $type = $row['Type'];
  238. }
  239. if (! empty($row['Type'])) {
  240. $type = $extracted_fieldspec['type'];
  241. if ('set' == $extracted_fieldspec['type'] || 'enum' == $extracted_fieldspec['type']) {
  242. $length = $extracted_fieldspec['spec_in_brackets'];
  243. } else {
  244. // strip the "BINARY" attribute, except if we find "BINARY(" because
  245. // this would be a BINARY or VARBINARY field type
  246. $type = preg_replace('@BINARY([^\(])@i', '', $type);
  247. $type = preg_replace('@ZEROFILL@i', '', $type);
  248. $type = preg_replace('@UNSIGNED@i', '', $type);
  249. $length = $extracted_fieldspec['spec_in_brackets'];
  250. } // end if else
  251. } else {
  252. // creating a column
  253. $length = '';
  254. }
  255. // some types, for example longtext, are reported as
  256. // "longtext character set latin7" when their charset and / or collation
  257. // differs from the ones of the corresponding database.
  258. $tmp = strpos($type, 'character set');
  259. if ($tmp) {
  260. $type = substr($type, 0, $tmp - 1);
  261. }
  262. if (isset($submit_length) && $submit_length != false) {
  263. $length = $submit_length;
  264. }
  265. // rtrim the type, for cases like "float unsigned"
  266. $type = rtrim($type);
  267. $type_upper = strtoupper($type);
  268. foreach ($cfg['ColumnTypes'] as $col_goup => $column_type) {
  269. if (is_array($column_type)) {
  270. $content_cells[$i][$ci] .= '<optgroup label="' . htmlspecialchars($col_goup) . '">';
  271. foreach ($column_type as $col_group_type) {
  272. $content_cells[$i][$ci] .= '<option value="'. $col_group_type . '"';
  273. if ($type_upper == strtoupper($col_group_type)) {
  274. $content_cells[$i][$ci] .= ' selected="selected"';
  275. }
  276. $content_cells[$i][$ci] .= '>' . $col_group_type . '</option>';
  277. }
  278. $content_cells[$i][$ci] .= '</optgroup>';
  279. continue;
  280. }
  281. $content_cells[$i][$ci] .= '<option value="'. $column_type . '"';
  282. if ($type_upper == strtoupper($column_type)) {
  283. $content_cells[$i][$ci] .= ' selected="selected"';
  284. }
  285. $content_cells[$i][$ci] .= '>' . $column_type . '</option>';
  286. } // end for
  287. $content_cells[$i][$ci] .= ' </select>';
  288. $ci++;
  289. // old column length
  290. if ($is_backup) {
  291. $_form_params['field_length_orig[' . $i . ']'] = $length;
  292. }
  293. // column length
  294. if (isset($extracted_fieldspec) && ('set' == $extracted_fieldspec['type'] || 'enum' == $extracted_fieldspec['type'])) {
  295. $binary = 0;
  296. $unsigned = 0;
  297. $zerofill = 0;
  298. $length_to_display = htmlspecialchars($length);
  299. } else {
  300. $length_to_display = $length;
  301. $binary = false;
  302. $unsigned = stristr($row['Type'], 'unsigned');
  303. $zerofill = stristr($row['Type'], 'zerofill');
  304. }
  305. $content_cells[$i][$ci] = '<input id="field_' . $i . '_' . ($ci - $ci_offset) . '"'
  306. . ' type="text" name="field_length[' . $i . ']" size="' . $length_values_input_size . '"'
  307. . ' value="' . htmlspecialchars($length_to_display) . '"'
  308. . ' class="textfield" />';
  309. $ci++;
  310. // column default
  311. /**
  312. * having NULL enabled does not implicit having Default with NULL
  313. *
  314. if (isset($row)
  315. && !isset($row['Default']) && isset($row['Null']) && $row['Null'] == 'YES') {
  316. $row['Default'] = 'NULL';
  317. }
  318. */
  319. // old column default
  320. if ($is_backup) {
  321. $_form_params['field_default_orig[' . $i . ']'] =
  322. (isset($row['Default']) ? $row['Default'] : '');
  323. }
  324. // here we put 'NONE' as the default value of drop-down; otherwise
  325. // users would have problems if they forget to enter the default
  326. // value (example, for an INT)
  327. $default_options = array(
  328. 'NONE' => $strNoneDefault,
  329. 'USER_DEFINED' => $strAsDefined,
  330. 'NULL' => 'NULL',
  331. 'CURRENT_TIMESTAMP' => 'CURRENT_TIMESTAMP',
  332. );
  333. // for a TIMESTAMP, do not show CURRENT_TIMESTAMP as a default value
  334. if ($type_upper == 'TIMESTAMP'
  335. && $default_current_timestamp
  336. && isset($row['Default'])) {
  337. $row['Default'] = '';
  338. }
  339. $content_cells[$i][$ci] = '<select name="field_default_type[' . $i . ']">';
  340. foreach ($default_options as $key => $value) {
  341. $content_cells[$i][$ci] .= '<option value="' . $key . '"';
  342. // is only set when we go back to edit a field's structure
  343. if (isset($row['DefaultType']) && $row['DefaultType'] == $key) {
  344. $content_cells[$i][$ci] .= ' selected="selected"';
  345. }
  346. $content_cells[$i][$ci] .= ' >' . $value . '</option>';
  347. }
  348. $content_cells[$i][$ci] .= '</select>';
  349. $content_cells[$i][$ci] .= '<br />';
  350. $content_cells[$i][$ci] .= '<input id="field_' . $i . '_' . ($ci - $ci_offset) . '"'
  351. . ' type="text" name="field_default_value[' . $i . ']" size="12"'
  352. . ' value="' . (isset($row['DefaultValue']) ? htmlspecialchars($row['DefaultValue']) : '') . '"'
  353. . ' class="textfield" />';
  354. $ci++;
  355. // column collation
  356. $tmp_collation = empty($row['Collation']) ? null : $row['Collation'];
  357. $content_cells[$i][$ci] = PMA_generateCharsetDropdownBox(
  358. PMA_CSDROPDOWN_COLLATION, 'field_collation[' . $i . ']',
  359. 'field_' . $i . '_' . ($ci - $ci_offset), $tmp_collation, false);
  360. unset($tmp_collation);
  361. $ci++;
  362. // column attribute
  363. $content_cells[$i][$ci] = '<select style="font-size: 70%;"'
  364. . ' name="field_attribute[' . $i . ']"'
  365. . ' id="field_' . $i . '_' . ($ci - $ci_offset) . '">';
  366. $attribute = '';
  367. if ($binary) {
  368. $attribute = 'BINARY';
  369. }
  370. if ($unsigned) {
  371. $attribute = 'UNSIGNED';
  372. }
  373. if ($zerofill) {
  374. $attribute = 'UNSIGNED ZEROFILL';
  375. }
  376. if (isset($row['Extra']) && $row['Extra'] == 'on update CURRENT_TIMESTAMP') {
  377. $attribute = 'on update CURRENT_TIMESTAMP';
  378. }
  379. if (isset($submit_attribute) && $submit_attribute != false) {
  380. $attribute = $submit_attribute;
  381. }
  382. // here, we have a TIMESTAMP that SHOW FULL FIELDS reports as having the
  383. // NULL attribute, but SHOW CREATE TABLE says the contrary. Believe
  384. // the latter.
  385. if (PMA_MYSQL_INT_VERSION < 50025
  386. && isset($row['Field'])
  387. && isset($analyzed_sql[0]['create_table_fields'][$row['Field']]['type'])
  388. && $analyzed_sql[0]['create_table_fields'][$row['Field']]['type'] == 'TIMESTAMP'
  389. && $analyzed_sql[0]['create_table_fields'][$row['Field']]['timestamp_not_null'] == true) {
  390. $row['Null'] = '';
  391. }
  392. // MySQL 4.1.2+ TIMESTAMP options
  393. // (if on_update_current_timestamp is set, then it's TRUE)
  394. if (isset($row['Field'])
  395. && isset($analyzed_sql[0]['create_table_fields'][$row['Field']]['on_update_current_timestamp'])) {
  396. $attribute = 'on update CURRENT_TIMESTAMP';
  397. }
  398. if ((isset($row['Field'])
  399. && isset($analyzed_sql[0]['create_table_fields'][$row['Field']]['default_current_timestamp']))
  400. || (isset($submit_default_current_timestamp) && $submit_default_current_timestamp)) {
  401. $default_current_timestamp = true;
  402. } else {
  403. $default_current_timestamp = false;
  404. }
  405. $cnt_attribute_types = count($cfg['AttributeTypes']);
  406. for ($j = 0; $j < $cnt_attribute_types; $j++) {
  407. $content_cells[$i][$ci] .= ' <option value="'. $cfg['AttributeTypes'][$j] . '"';
  408. if (strtoupper($attribute) == strtoupper($cfg['AttributeTypes'][$j])) {
  409. $content_cells[$i][$ci] .= ' selected="selected"';
  410. }
  411. $content_cells[$i][$ci] .= '>' . $cfg['AttributeTypes'][$j] . '</option>';
  412. }
  413. $content_cells[$i][$ci] .= '</select>';
  414. $ci++;
  415. // column NULL
  416. $content_cells[$i][$ci] = '<input name="field_null[' . $i . ']"'
  417. . ' id="field_' . $i . '_' . ($ci - $ci_offset) . '"';
  418. if (! empty($row['Null']) && $row['Null'] != 'NO' && $row['Null'] != 'NOT NULL') {
  419. $content_cells[$i][$ci] .= ' checked="checked"';
  420. }
  421. $content_cells[$i][$ci] .= ' type="checkbox" value="NULL" />';
  422. $ci++;
  423. // column indexes
  424. // lem9: See my other comment about removing this 'if'.
  425. if (!$is_backup) {
  426. $content_cells[$i][$ci] = '<select name="field_key[' . $i . ']"'
  427. . ' id="field_' . $i . '_' . ($ci - $ci_offset) . '">';
  428. $content_cells[$i][$ci] .= '<option value="none_' . $i . '">---</option>';
  429. $content_cells[$i][$ci] .= '<option value="primary_' . $i . '" title="' . $strPrimary . '"';
  430. if (isset($row['Key']) && $row['Key'] == 'PRI') {
  431. $content_cells[$i][$ci] .= ' selected="selected"';
  432. }
  433. $content_cells[$i][$ci] .= '>PRIMARY</option>';
  434. $content_cells[$i][$ci] .= '<option value="unique_' . $i . '" title="' . $strUnique . '"';
  435. if (isset($row['Key']) && $row['Key'] == 'UNI') {
  436. $content_cells[$i][$ci] .= ' selected="selected"';
  437. }
  438. $content_cells[$i][$ci] .= '>UNIQUE</option>';
  439. $content_cells[$i][$ci] .= '<option value="index_' . $i . '" title="' . $strIndex . '"';
  440. if (isset($row['Key']) && $row['Key'] == 'MUL') {
  441. $content_cells[$i][$ci] .= ' selected="selected"';
  442. }
  443. $content_cells[$i][$ci] .= '>INDEX</option>';
  444. $content_cells[$i][$ci] .= '<option value="fulltext_' . $i . '" title="' . $strIdxFulltext . '"';
  445. if (isset($row['Key']) && $row['Key'] == 'FULLTEXT') {
  446. $content_cells[$i][$ci] .= ' selected="selected"';
  447. }
  448. $content_cells[$i][$ci] .= '>FULLTEXT</option>';
  449. $content_cells[$i][$ci] .= '</select>';
  450. $ci++;
  451. } // end if ($action ==...)
  452. // column auto_increment
  453. $content_cells[$i][$ci] = '<input name="field_extra[' . $i . ']"'
  454. . ' id="field_' . $i . '_' . ($ci - $ci_offset) . '"';
  455. if (isset($row['Extra']) && strtolower($row['Extra']) == 'auto_increment') {
  456. $content_cells[$i][$ci] .= ' checked="checked"';
  457. }
  458. $content_cells[$i][$ci] .= ' type="checkbox" value="AUTO_INCREMENT" />';
  459. $ci++;
  460. // column comments
  461. $content_cells[$i][$ci] = '<input id="field_' . $i . '_' . ($ci - $ci_offset) . '"'
  462. . ' type="text" name="field_comments[' . $i . ']" size="12"'
  463. . ' value="' . (isset($row['Field']) && is_array($comments_map) && isset($comments_map[$row['Field']]) ? htmlspecialchars($comments_map[$row['Field']]) : '') . '"'
  464. . ' class="textfield" />';
  465. $ci++;
  466. // column MIME-types
  467. if ($cfgRelation['mimework'] && $cfg['BrowseMIME'] && $cfgRelation['commwork']) {
  468. $content_cells[$i][$ci] = '<select id="field_' . $i . '_' . ($ci - $ci_offset) . '" size="1" name="field_mimetype[' . $i . ']">';
  469. $content_cells[$i][$ci] .= ' <option value="">&nbsp;</option>';
  470. if (is_array($available_mime['mimetype'])) {
  471. foreach ($available_mime['mimetype'] AS $mimekey => $mimetype) {
  472. $checked = (isset($row['Field']) && isset($mime_map[$row['Field']]['mimetype']) && ($mime_map[$row['Field']]['mimetype'] == str_replace('/', '_', $mimetype)) ? 'selected ' : '');
  473. $content_cells[$i][$ci] .= ' <option value="' . str_replace('/', '_', $mimetype) . '" ' . $checked . '>' . htmlspecialchars($mimetype) . '</option>';
  474. }
  475. }
  476. $content_cells[$i][$ci] .= '</select>';
  477. $ci++;
  478. $content_cells[$i][$ci] = '<select id="field_' . $i . '_' . ($ci - $ci_offset) . '" size="1" name="field_transformation[' . $i . ']">';
  479. $content_cells[$i][$ci] .= ' <option value="" title="' . $strNone . '"></option>';
  480. if (is_array($available_mime['transformation'])) {
  481. foreach ($available_mime['transformation'] AS $mimekey => $transform) {
  482. $checked = (isset($row['Field']) && isset($mime_map[$row['Field']]['transformation']) && (preg_match('@' . preg_quote($available_mime['transformation_file'][$mimekey]) . '3?@i', $mime_map[$row['Field']]['transformation'])) ? 'selected ' : '');
  483. $tooltip = 'strTransformation_' . strtolower(str_replace('.inc.php', '', $available_mime['transformation_file'][$mimekey]));
  484. $tooltip = isset($$tooltip) ? $$tooltip : sprintf(str_replace('<br />', ' ', $strMIME_nodescription), 'PMA_transformation_' . $tooltip . '()');
  485. $content_cells[$i][$ci] .= '<option value="' . $available_mime['transformation_file'][$mimekey] . '" ' . $checked . ' title="' . htmlspecialchars($tooltip) . '">' . htmlspecialchars($transform) . '</option>';
  486. }
  487. }
  488. $content_cells[$i][$ci] .= '</select>';
  489. $ci++;
  490. $content_cells[$i][$ci] = '<input id="field_' . $i . '_' . ($ci - $ci_offset) . '"'
  491. . ' type="text" name="field_transformation_options[' . $i . ']"'
  492. . ' size="16" class="textfield"'
  493. . ' value="' . (isset($row['Field']) && isset($mime_map[$row['Field']]['transformation_options']) ? htmlspecialchars($mime_map[$row['Field']]['transformation_options']) : '') . '"'
  494. . ' />';
  495. //$ci++;
  496. }
  497. } // end for
  498. if ($cfg['CtrlArrowsMoving']) {
  499. ?>
  500. <script src="./js/keyhandler.js" type="text/javascript"></script>
  501. <script type="text/javascript">
  502. // <![CDATA[
  503. var switch_movement = <?php echo $display_type == 'horizontal' ? '0' : '1'; ?>;
  504. document.onkeydown = onKeyDownArrowsHandler;
  505. // ]]>
  506. </script>
  507. <?php
  508. }
  509. ?>
  510. <form method="post" action="<?php echo $action; ?>">
  511. <?php
  512. echo PMA_generate_common_hidden_inputs($_form_params);
  513. unset($_form_params);
  514. if (is_array($content_cells) && is_array($header_cells)) {
  515. // last row is for javascript insert
  516. //$empty_row = array_pop($content_cells);
  517. echo '<table id="table_columns">';
  518. if ($display_type == 'horizontal') {
  519. ?>
  520. <tr>
  521. <?php foreach ($header_cells as $header_val) { ?>
  522. <th><?php echo $header_val; ?></th>
  523. <?php } ?>
  524. </tr>
  525. <?php
  526. $odd_row = true;
  527. foreach ($content_cells as $content_row) {
  528. echo '<tr class="' . ($odd_row ? 'odd' : 'even') . ' noclick">';
  529. $odd_row = ! $odd_row;
  530. if (is_array($content_row)) {
  531. foreach ($content_row as $content_row_val) {
  532. ?>
  533. <td align="center"><?php echo $content_row_val; ?></td>
  534. <?php
  535. }
  536. }
  537. echo '</tr>';
  538. }
  539. } else {
  540. $i = 0;
  541. $odd_row = true;
  542. foreach ($header_cells as $header_val) {
  543. echo '<tr class="' . ($odd_row ? 'odd' : 'even') . ' noclick">';
  544. $odd_row = ! $odd_row;
  545. ?>
  546. <th><?php echo $header_val; ?></th>
  547. <?php
  548. foreach ($content_cells as $content_cell) {
  549. if (isset($content_cell[$i]) && $content_cell[$i] != '') {
  550. ?>
  551. <td><?php echo $content_cell[$i]; ?></td>
  552. <?php
  553. }
  554. }
  555. echo '</tr>';
  556. $i++;
  557. }
  558. }
  559. ?>
  560. </table>
  561. <br />
  562. <?php
  563. }
  564. /**
  565. * needs to be finished
  566. *
  567. *
  568. if ($display_type == 'horizontal') {
  569. $new_field = '';
  570. foreach ($empty_row as $content_row_val) {
  571. $new_field .= '<td align="center">' . $content_row_val . '</td>';
  572. }
  573. ?>
  574. <script type="text/javascript">
  575. // <![CDATA[
  576. var odd_row = <?php echo $odd_row; ?>;
  577. function addField() {
  578. var new_fields = document.getElementById('added_fields').value;
  579. var new_field_container = document.getElementById('table_columns');
  580. var new_field = '<?php echo preg_replace('|\s+|', ' ', preg_replace('|\'|', '\\\'', $new_field)); ?>';
  581. var i = 0;
  582. for (i = 0; i < new_fields; i++) {
  583. if (odd_row) {
  584. new_field_container.innerHTML += '<tr class="odd">' + new_field + '</tr>';
  585. } else {
  586. new_field_container.innerHTML += '<tr class="even">' + new_field + '</tr>';
  587. }
  588. odd_row = ! odd_row;
  589. }
  590. return true;
  591. }
  592. // ]]>
  593. </script>
  594. <?php
  595. }
  596. */
  597. if ($action == 'tbl_create.php') {
  598. ?>
  599. <table>
  600. <tr valign="top">
  601. <th><?php echo $strTableComments; ?>:&nbsp;</th>
  602. <td width="25">&nbsp;</td>
  603. <th><?php echo $strStorageEngine; ?>:
  604. <?php echo PMA_showMySQLDocu('Storage_engines', 'Storage_engines'); ?>
  605. </th>
  606. <td width="25">&nbsp;</td>
  607. <th><?php echo $strCollation ;?>:&nbsp;</th>
  608. </tr>
  609. <tr><td><input type="text" name="comment" size="40" maxlength="80"
  610. value="<?php echo (isset($_REQUEST['comment']) ? htmlspecialchars($_REQUEST['comment']) : ''); ?>"
  611. class="textfield" />
  612. </td>
  613. <td width="25">&nbsp;</td>
  614. <td>
  615. <?php
  616. echo PMA_StorageEngine::getHtmlSelect('tbl_type', null,
  617. (isset($_REQUEST['tbl_type']) ? $_REQUEST['tbl_type'] : null));
  618. ?>
  619. </td>
  620. <td width="25">&nbsp;</td>
  621. <td>
  622. <?php
  623. echo PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION, 'tbl_collation',
  624. null, (isset($_REQUEST['tbl_collation']) ? $_REQUEST['tbl_collation'] : null), false, 3);
  625. ?>
  626. </td>
  627. </tr>
  628. <?php
  629. if (PMA_Partition::havePartitioning()) {
  630. ?>
  631. <tr valign="top">
  632. <th><?php echo $strPartitionDefinition; ?>:&nbsp;<?php echo PMA_showMySQLDocu('Partitioning', 'Partitioning'); ?>
  633. </th>
  634. </tr>
  635. <tr>
  636. <td>
  637. <textarea name="partition_definition" id="partitiondefinition"
  638. cols="<?php echo $GLOBALS['cfg']['TextareaCols'];?>"
  639. rows="<?php echo $GLOBALS['cfg']['TextareaRows'];?>"
  640. dir="<?php echo $GLOBALS['text_dir'];?>"><?php echo (isset($_REQUEST['partition_definition']) ? htmlspecialchars($_REQUEST['partition_definition']) : ''); ?></textarea>
  641. </td>
  642. </tr>
  643. <?php
  644. }
  645. ?>
  646. </table>
  647. <br />
  648. <?php
  649. } // end if ($action == 'tbl_create.php')
  650. ?>
  651. <fieldset class="tblFooters">
  652. <input type="submit" name="do_save_data" value="<?php echo $strSave; ?>"
  653. onclick="return checkTableEditForm(this.form, <?php echo $num_fields; ?>)" />
  654. <?php if ($action == 'tbl_create.php' || $action == 'tbl_addfield.php') { ?>
  655. <?php echo $GLOBALS['strOr']; ?>
  656. <?php echo sprintf($strAddFields, '<input type="text" id="added_fields" name="added_fields" size="2" value="1" onfocus="this.select()" />'); ?>
  657. <input type="submit" name="submit_num_fields"
  658. value="<?php echo $GLOBALS['strGo']; ?>"
  659. <?php /* onclick="if (addField()) return false;" */ ?>
  660. onclick="return checkFormElementInRange(this.form, 'added_fields', '<?php echo str_replace('\'', '\\\'', $GLOBALS['strInvalidFieldAddCount']); ?>', 1)"
  661. />
  662. <?php } ?>
  663. </fieldset>
  664. </form>
  665. <center><?php echo PMA_showMySQLDocu('SQL-Syntax', 'CREATE_TABLE'); ?></center>