tbl_columns_definition_form.inc.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Display form for changing/adding table fields/columns.
  5. * Included by tbl_addfield.php and tbl_create.php
  6. *
  7. * @package PhpMyAdmin
  8. */
  9. if (! defined('PHPMYADMIN')) {
  10. exit;
  11. }
  12. /**
  13. * Check parameters
  14. */
  15. require_once './libraries/Util.class.php';
  16. PMA_Util::checkParameters(array('db', 'table', 'action', 'num_fields'));
  17. // Get available character sets and storage engines
  18. require_once './libraries/mysql_charsets.lib.php';
  19. require_once './libraries/StorageEngine.class.php';
  20. /**
  21. * Class for partition management
  22. */
  23. require_once './libraries/Partition.class.php';
  24. /**
  25. * We are in transition between old-style echo and new-style PMA_Response
  26. * so this script generates $html and at the bottom, either echos it
  27. * or uses addHTML on it.
  28. *
  29. * Initialize $html in case this variable was used by a caller
  30. * (yes, this script should be refactored into functions)
  31. */
  32. $html = '';
  33. $length_values_input_size = 8;
  34. $_form_params = array(
  35. 'db' => $db
  36. );
  37. if ($action == 'tbl_create.php') {
  38. $_form_params['reload'] = 1;
  39. } elseif ($action == 'tbl_addfield.php') {
  40. $_form_params['field_where'] = $_REQUEST['field_where'];
  41. $_form_params['after_field'] = $_REQUEST['after_field'];
  42. $_form_params['table'] = $table;
  43. } else {
  44. $_form_params['table'] = $table;
  45. }
  46. if (isset($num_fields)) {
  47. $_form_params['orig_num_fields'] = $num_fields;
  48. }
  49. if (isset($_REQUEST['field_where'])) {
  50. $_form_params['orig_field_where'] = $_REQUEST['field_where'];
  51. }
  52. if (isset($_REQUEST['after_field'])) {
  53. $_form_params['orig_after_field'] = $_REQUEST['after_field'];
  54. }
  55. if (isset($selected) && is_array($selected)) {
  56. foreach ($selected as $o_fld_nr => $o_fld_val) {
  57. $_form_params['selected[' . $o_fld_nr . ']'] = $o_fld_val;
  58. if (! isset($true_selected)) {
  59. $_form_params['true_selected[' . $o_fld_nr . ']'] = $o_fld_val;
  60. }
  61. }
  62. if (isset($true_selected) && is_array($true_selected)) {
  63. foreach ($true_selected as $o_fld_nr => $o_fld_val) {
  64. $_form_params['true_selected[' . $o_fld_nr . ']'] = $o_fld_val;
  65. }
  66. }
  67. } elseif (isset($_REQUEST['field'])) {
  68. $_form_params['orig_field'] = $_REQUEST['field'];
  69. if (isset($orig_field)) {
  70. $_form_params['true_selected[]'] = $orig_field;
  71. } else {
  72. $_form_params['true_selected[]'] = $_REQUEST['field'];
  73. }
  74. }
  75. $is_backup = ($action != 'tbl_create.php' && $action != 'tbl_addfield.php');
  76. $header_cells = array();
  77. $content_cells = array();
  78. $header_cells[] = __('Name');
  79. $header_cells[] = __('Type')
  80. . PMA_Util::showMySQLDocu('SQL-Syntax', 'data-types');
  81. $header_cells[] = __('Length/Values')
  82. . PMA_Util::showHint(
  83. __(
  84. 'If column type is "enum" or "set", please enter the values using'
  85. . ' this format: \'a\',\'b\',\'c\'…<br />If you ever need to put'
  86. . ' a backslash ("\") or a single quote ("\'") amongst those values,'
  87. . ' precede it with a backslash (for example \'\\\\xyz\' or \'a\\\'b\').'
  88. )
  89. );
  90. $header_cells[] = __('Default')
  91. . PMA_Util::showHint(
  92. __(
  93. 'For default values, please enter just a single value,'
  94. . ' without backslash escaping or quotes, using this format: a'
  95. )
  96. );
  97. $header_cells[] = __('Collation');
  98. $header_cells[] = __('Attributes');
  99. $header_cells[] = __('Null');
  100. // We could remove this 'if' and let the key information be shown and
  101. // editable. However, for this to work, structure.lib.php must be modified
  102. // to use the key fields, as tbl_addfield does.
  103. if (! $is_backup) {
  104. $header_cells[] = __('Index');
  105. }
  106. $header_cells[] = '<abbr title="AUTO_INCREMENT">A_I</abbr>';
  107. require_once './libraries/transformations.lib.php';
  108. $cfgRelation = PMA_getRelationsParam();
  109. $comments_map = array();
  110. $mime_map = array();
  111. $available_mime = array();
  112. $comments_map = PMA_getComments($db, $table);
  113. $header_cells[] = __('Comments');
  114. if (isset($fields_meta)) {
  115. // for moving, load all available column names
  116. $move_columns_sql_query = 'SELECT * FROM '
  117. . PMA_Util::backquote($db)
  118. . '.'
  119. . PMA_Util::backquote($table)
  120. . ' LIMIT 1';
  121. $move_columns_sql_result = PMA_DBI_try_query($move_columns_sql_query);
  122. $move_columns = PMA_DBI_get_fields_meta($move_columns_sql_result);
  123. unset($move_columns_sql_query, $move_columns_sql_result);
  124. $header_cells[] = __('Move column');
  125. }
  126. if ($cfgRelation['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {
  127. $mime_map = PMA_getMIME($db, $table);
  128. $available_mime = PMA_getAvailableMIMEtypes();
  129. $hint = '<br />'
  130. . sprintf(
  131. __(
  132. 'For a list of available transformation options and their MIME'
  133. . ' type transformations, click on %stransformation descriptions%s'
  134. ),
  135. '<a href="transformation_overview.php?'
  136. . PMA_generate_common_url($db, $table)
  137. . '" target="_blank">',
  138. '</a>'
  139. );
  140. $header_cells[] = __('MIME type');
  141. $header_cells[] = __('Browser transformation');
  142. $header_cells[] = __('Transformation options')
  143. . PMA_Util::showHint(
  144. __(
  145. 'Please enter the values for transformation options using this'
  146. . ' format: \'a\', 100, b,\'c\'…<br />If you ever need to put'
  147. . ' a backslash ("\") or a single quote ("\'") amongst those'
  148. . ' values, precede it with a backslash (for example \'\\\\xyz\''
  149. . ' or \'a\\\'b\').'
  150. )
  151. . $hint
  152. );
  153. }
  154. // workaround for field_fulltext, because its submitted indices contain
  155. // the index as a value, not a key. Inserted here for easier maintaineance
  156. // and less code to change in existing files.
  157. if (isset($field_fulltext) && is_array($field_fulltext)) {
  158. foreach ($field_fulltext as $fulltext_nr => $fulltext_indexkey) {
  159. $submit_fulltext[$fulltext_indexkey] = $fulltext_indexkey;
  160. }
  161. }
  162. for ($i = 0; $i < $num_fields; $i++) {
  163. if (! empty($regenerate)) {
  164. // An error happened with previous inputs, so we will restore the data
  165. // to embed it once again in this form.
  166. $row['Field'] = isset($_REQUEST['field_name'][$i])
  167. ? $_REQUEST['field_name'][$i]
  168. : false;
  169. $row['Type'] = isset($_REQUEST['field_type'][$i])
  170. ? $_REQUEST['field_type'][$i]
  171. : false;
  172. $row['Collation'] = isset($_REQUEST['field_collation'][$i])
  173. ? $_REQUEST['field_collation'][$i]
  174. : '';
  175. $row['Null'] = isset($_REQUEST['field_null'][$i])
  176. ? $_REQUEST['field_null'][$i]
  177. : '';
  178. if (isset($_REQUEST['field_key'][$i])
  179. && $_REQUEST['field_key'][$i] == 'primary_' . $i
  180. ) {
  181. $row['Key'] = 'PRI';
  182. } elseif (isset($_REQUEST['field_key'][$i])
  183. && $_REQUEST['field_key'][$i] == 'index_' . $i
  184. ) {
  185. $row['Key'] = 'MUL';
  186. } elseif (isset($_REQUEST['field_key'][$i])
  187. && $_REQUEST['field_key'][$i] == 'unique_' . $i
  188. ) {
  189. $row['Key'] = 'UNI';
  190. } elseif (isset($_REQUEST['field_key'][$i])
  191. && $_REQUEST['field_key'][$i] == 'fulltext_' . $i
  192. ) {
  193. $row['Key'] = 'FULLTEXT';
  194. } else {
  195. $row['Key'] = '';
  196. }
  197. // put None in the drop-down for Default, when someone adds a field
  198. $row['DefaultType'] = isset($_REQUEST['field_default_type'][$i])
  199. ? $_REQUEST['field_default_type'][$i]
  200. : 'NONE';
  201. $row['DefaultValue'] = isset($_REQUEST['field_default_value'][$i])
  202. ? $_REQUEST['field_default_value'][$i]
  203. : '';
  204. switch ($row['DefaultType']) {
  205. case 'NONE' :
  206. $row['Default'] = null;
  207. break;
  208. case 'USER_DEFINED' :
  209. $row['Default'] = $row['DefaultValue'];
  210. break;
  211. case 'NULL' :
  212. case 'CURRENT_TIMESTAMP' :
  213. $row['Default'] = $row['DefaultType'];
  214. break;
  215. }
  216. $row['Extra']
  217. = (isset($_REQUEST['field_extra'][$i])
  218. ? $_REQUEST['field_extra'][$i]
  219. : false);
  220. $row['Comment']
  221. = (isset($submit_fulltext[$i])
  222. && ($submit_fulltext[$i] == $i)
  223. ? 'FULLTEXT'
  224. : false);
  225. $submit_length
  226. = (isset($_REQUEST['field_length'][$i])
  227. ? $_REQUEST['field_length'][$i]
  228. : false);
  229. $submit_attribute
  230. = (isset($_REQUEST['field_attribute'][$i])
  231. ? $_REQUEST['field_attribute'][$i]
  232. : false);
  233. $submit_default_current_timestamp
  234. = (isset($_REQUEST['field_default_current_timestamp'][$i])
  235. ? true
  236. : false);
  237. if (isset($_REQUEST['field_comments'][$i])) {
  238. $comments_map[$row['Field']] = $_REQUEST['field_comments'][$i];
  239. }
  240. if (isset($_REQUEST['field_mimetype'][$i])) {
  241. $mime_map[$row['Field']]['mimetype'] = $_REQUEST['field_mimetype'][$i];
  242. }
  243. if (isset($_REQUEST['field_transformation'][$i])) {
  244. $mime_map[$row['Field']]['transformation']
  245. = $_REQUEST['field_transformation'][$i];
  246. }
  247. if (isset($_REQUEST['field_transformation_options'][$i])) {
  248. $mime_map[$row['Field']]['transformation_options']
  249. = $_REQUEST['field_transformation_options'][$i];
  250. }
  251. } elseif (isset($fields_meta[$i])) {
  252. $row = $fields_meta[$i];
  253. switch ($row['Default']) {
  254. case null:
  255. if ($row['Null'] == 'YES') {
  256. $row['DefaultType'] = 'NULL';
  257. $row['DefaultValue'] = '';
  258. // SHOW FULL COLUMNS does not report the case
  259. // when there is a DEFAULT value which is empty so we need to use the
  260. // results of SHOW CREATE TABLE
  261. } elseif (isset($row)
  262. && isset($analyzed_sql[0]['create_table_fields'][$row['Field']]
  263. ['default_value'])
  264. ) {
  265. $row['DefaultType'] = 'USER_DEFINED';
  266. $row['DefaultValue'] = $row['Default'];
  267. } else {
  268. $row['DefaultType'] = 'NONE';
  269. $row['DefaultValue'] = '';
  270. }
  271. break;
  272. case 'CURRENT_TIMESTAMP':
  273. $row['DefaultType'] = 'CURRENT_TIMESTAMP';
  274. $row['DefaultValue'] = '';
  275. break;
  276. default:
  277. $row['DefaultType'] = 'USER_DEFINED';
  278. $row['DefaultValue'] = $row['Default'];
  279. break;
  280. }
  281. }
  282. if (isset($row['Type'])) {
  283. $extracted_columnspec = PMA_Util::extractColumnSpec($row['Type']);
  284. if ($extracted_columnspec['type'] == 'bit') {
  285. $row['Default']
  286. = PMA_Util::convertBitDefaultValue($row['Default']);
  287. }
  288. }
  289. // Cell index: If certain fields get left out, the counter shouldn't change.
  290. $ci = 0;
  291. // Everytime a cell shall be left out the STRG-jumping feature, $ci_offset
  292. // has to be incremented ($ci_offset++)
  293. $ci_offset = -1;
  294. // old column name
  295. if ($is_backup) {
  296. if (! empty($true_selected[$i])) {
  297. $_form_params['field_orig[' . $i . ']'] = $true_selected[$i];
  298. } elseif (isset($row['Field'])) {
  299. $_form_params['field_orig[' . $i . ']'] = $row['Field'];
  300. } else {
  301. $_form_params['field_orig[' . $i . ']'] = '';
  302. }
  303. }
  304. // column name
  305. $content_cells[$i][$ci] = '<input id="field_' . $i . '_' . ($ci - $ci_offset)
  306. . '"' . ' type="text" name="field_name[' . $i . ']"'
  307. . ' maxlength="64" class="textfield" title="' . __('Column') . '"'
  308. . ' size="10"'
  309. . ' value="' . (isset($row['Field']) ? htmlspecialchars($row['Field']) : '')
  310. . '"' . ' />';
  311. $ci++;
  312. // column type
  313. $select_id = 'field_' . $i . '_' . ($ci - $ci_offset);
  314. $content_cells[$i][$ci] = '<select class="column_type" name="field_type[' .
  315. $i . ']"' .' id="' . $select_id . '">';
  316. if (empty($row['Type'])) {
  317. // creating a column
  318. $row['Type'] = '';
  319. $type = '';
  320. $length = '';
  321. } else {
  322. $type = $extracted_columnspec['type'];
  323. $length = $extracted_columnspec['spec_in_brackets'];
  324. }
  325. // some types, for example longtext, are reported as
  326. // "longtext character set latin7" when their charset and / or collation
  327. // differs from the ones of the corresponding database.
  328. $tmp = strpos($type, 'character set');
  329. if ($tmp) {
  330. $type = substr($type, 0, $tmp - 1);
  331. }
  332. if (isset($submit_length) && $submit_length != false) {
  333. $length = $submit_length;
  334. }
  335. // rtrim the type, for cases like "float unsigned"
  336. $type = rtrim($type);
  337. $type_upper = strtoupper($type);
  338. $content_cells[$i][$ci]
  339. .= PMA_Util::getSupportedDatatypes(true, $type_upper);
  340. $content_cells[$i][$ci] .= ' </select>';
  341. $ci++;
  342. // old column length
  343. if ($is_backup) {
  344. $_form_params['field_length_orig[' . $i . ']'] = $length;
  345. }
  346. // column length
  347. $length_to_display = $length;
  348. $content_cells[$i][$ci] = '<input id="field_' . $i . '_' . ($ci - $ci_offset)
  349. . '"' . ' type="text" name="field_length[' . $i . ']" size="'
  350. . $length_values_input_size . '"' . ' value="' . htmlspecialchars(
  351. $length_to_display
  352. )
  353. . '"'
  354. . ' class="textfield" />'
  355. . '<p class="enum_notice" id="enum_notice_' . $i . '_' . ($ci - $ci_offset)
  356. . '">';
  357. $content_cells[$i][$ci] .= __('ENUM or SET data too long?')
  358. . '<a href="#" class="open_enum_editor"> '
  359. . __('Get more editing space') . '</a>'
  360. . '</p>';
  361. $ci++;
  362. // column default
  363. // old column default
  364. if ($is_backup) {
  365. $_form_params['field_default_orig[' . $i . ']']
  366. = (isset($row['Default']) ? $row['Default'] : '');
  367. }
  368. // here we put 'NONE' as the default value of drop-down; otherwise
  369. // users would have problems if they forget to enter the default
  370. // value (example, for an INT)
  371. $default_options = array(
  372. 'NONE' => _pgettext('for default', 'None'),
  373. 'USER_DEFINED' => __('As defined:'),
  374. 'NULL' => 'NULL',
  375. 'CURRENT_TIMESTAMP' => 'CURRENT_TIMESTAMP',
  376. );
  377. // for a TIMESTAMP, do not show the string "CURRENT_TIMESTAMP" as a default value
  378. if ($type_upper == 'TIMESTAMP'
  379. && ! empty($default_current_timestamp)
  380. && isset($row['Default'])
  381. ) {
  382. $row['Default'] = '';
  383. }
  384. if ($type_upper == 'BIT') {
  385. $row['DefaultValue']
  386. = PMA_Util::convertBitDefaultValue($row['DefaultValue']);
  387. }
  388. $content_cells[$i][$ci] = '<select name="field_default_type[' . $i
  389. . ']" id="field_' . $i . '_' . ($ci - $ci_offset)
  390. . '" class="default_type">';
  391. foreach ($default_options as $key => $value) {
  392. $content_cells[$i][$ci] .= '<option value="' . $key . '"';
  393. // is only set when we go back to edit a field's structure
  394. if (isset($row['DefaultType']) && $row['DefaultType'] == $key) {
  395. $content_cells[$i][$ci] .= ' selected="selected"';
  396. }
  397. $content_cells[$i][$ci] .= ' >' . $value . '</option>';
  398. }
  399. $content_cells[$i][$ci] .= '</select>';
  400. $content_cells[$i][$ci] .= '<br />';
  401. $content_cells[$i][$ci] .= '<input type="text"'
  402. . ' name="field_default_value[' . $i . ']" size="12"'
  403. . ' value="' . (isset($row['DefaultValue'])
  404. ? htmlspecialchars($row['DefaultValue'])
  405. : '') . '"'
  406. . ' class="textfield default_value" />';
  407. $ci++;
  408. // column collation
  409. $tmp_collation = empty($row['Collation']) ? null : $row['Collation'];
  410. $content_cells[$i][$ci] = PMA_generateCharsetDropdownBox(
  411. PMA_CSDROPDOWN_COLLATION, 'field_collation[' . $i . ']',
  412. 'field_' . $i . '_' . ($ci - $ci_offset), $tmp_collation, false
  413. );
  414. unset($tmp_collation);
  415. $ci++;
  416. // column attribute
  417. $content_cells[$i][$ci] = '<select style="font-size: 70%;"'
  418. . ' name="field_attribute[' . $i . ']"'
  419. . ' id="field_' . $i . '_' . ($ci - $ci_offset) . '">';
  420. $attribute = '';
  421. if (isset($extracted_columnspec)) {
  422. $attribute = $extracted_columnspec['attribute'];
  423. }
  424. if (isset($row['Extra']) && $row['Extra'] == 'on update CURRENT_TIMESTAMP') {
  425. $attribute = 'on update CURRENT_TIMESTAMP';
  426. }
  427. if (isset($submit_attribute) && $submit_attribute != false) {
  428. $attribute = $submit_attribute;
  429. }
  430. // here, we have a TIMESTAMP that SHOW FULL COLUMNS reports as having the
  431. // NULL attribute, but SHOW CREATE TABLE says the contrary. Believe
  432. // the latter.
  433. if (PMA_MYSQL_INT_VERSION < 50025
  434. && isset($row['Field'])
  435. && isset($analyzed_sql[0]['create_table_fields'][$row['Field']]['type'])
  436. && $analyzed_sql[0]['create_table_fields'][$row['Field']]['type'] == 'TIMESTAMP'
  437. && $analyzed_sql[0]['create_table_fields'][$row['Field']]['timestamp_not_null'] == true
  438. ) {
  439. $row['Null'] = '';
  440. }
  441. // MySQL 4.1.2+ TIMESTAMP options
  442. // (if on_update_current_timestamp is set, then it's TRUE)
  443. if (isset($row['Field'])
  444. && isset($analyzed_sql[0]['create_table_fields'][$row['Field']]['on_update_current_timestamp'])
  445. ) {
  446. $attribute = 'on update CURRENT_TIMESTAMP';
  447. }
  448. if ((isset($row['Field'])
  449. && isset($analyzed_sql[0]['create_table_fields'][$row['Field']]['default_current_timestamp']))
  450. || (isset($submit_default_current_timestamp)
  451. && $submit_default_current_timestamp)
  452. ) {
  453. $default_current_timestamp = true;
  454. } else {
  455. $default_current_timestamp = false;
  456. }
  457. $attribute_types = $GLOBALS['PMA_Types']->getAttributes();
  458. $cnt_attribute_types = count($attribute_types);
  459. for ($j = 0; $j < $cnt_attribute_types; $j++) {
  460. $content_cells[$i][$ci]
  461. .= ' <option value="' . $attribute_types[$j] . '"';
  462. if (strtoupper($attribute) == strtoupper($attribute_types[$j])) {
  463. $content_cells[$i][$ci] .= ' selected="selected"';
  464. }
  465. $content_cells[$i][$ci] .= '>' . $attribute_types[$j] . '</option>';
  466. }
  467. $content_cells[$i][$ci] .= '</select>';
  468. $ci++;
  469. // column NULL
  470. $content_cells[$i][$ci] = '<input name="field_null[' . $i . ']"'
  471. . ' id="field_' . $i . '_' . ($ci - $ci_offset) . '"';
  472. if (! empty($row['Null'])
  473. && $row['Null'] != 'NO'
  474. && $row['Null'] != 'NOT NULL'
  475. ) {
  476. $content_cells[$i][$ci] .= ' checked="checked"';
  477. }
  478. $content_cells[$i][$ci] .= ' type="checkbox" value="NULL" class="allow_null"/>';
  479. $ci++;
  480. // column indexes
  481. // See my other comment about removing this 'if'.
  482. if (!$is_backup) {
  483. $content_cells[$i][$ci] = '<select name="field_key[' . $i . ']"'
  484. . ' id="field_' . $i . '_' . ($ci - $ci_offset) . '">';
  485. $content_cells[$i][$ci] .= '<option value="none_' . $i . '">---</option>';
  486. $content_cells[$i][$ci] .= '<option value="primary_' . $i . '" title="'
  487. . __('Primary') . '"';
  488. if (isset($row['Key']) && $row['Key'] == 'PRI') {
  489. $content_cells[$i][$ci] .= ' selected="selected"';
  490. }
  491. $content_cells[$i][$ci] .= '>PRIMARY</option>';
  492. $content_cells[$i][$ci] .= '<option value="unique_' . $i . '" title="'
  493. . __('Unique') . '"';
  494. if (isset($row['Key']) && $row['Key'] == 'UNI') {
  495. $content_cells[$i][$ci] .= ' selected="selected"';
  496. }
  497. $content_cells[$i][$ci] .= '>UNIQUE</option>';
  498. $content_cells[$i][$ci] .= '<option value="index_' . $i . '" title="'
  499. . __('Index') . '"';
  500. if (isset($row['Key']) && $row['Key'] == 'MUL') {
  501. $content_cells[$i][$ci] .= ' selected="selected"';
  502. }
  503. $content_cells[$i][$ci] .= '>INDEX</option>';
  504. if (!PMA_DRIZZLE) {
  505. $content_cells[$i][$ci] .= '<option value="fulltext_' . $i . '" title="'
  506. . __('Fulltext') . '"';
  507. if (isset($row['Key']) && $row['Key'] == 'FULLTEXT') {
  508. $content_cells[$i][$ci] .= ' selected="selected"';
  509. }
  510. $content_cells[$i][$ci] .= '>FULLTEXT</option>';
  511. }
  512. $content_cells[$i][$ci] .= '</select>';
  513. $ci++;
  514. } // end if ($action ==...)
  515. // column auto_increment
  516. $content_cells[$i][$ci] = '<input name="field_extra[' . $i . ']"'
  517. . ' id="field_' . $i . '_' . ($ci - $ci_offset) . '"';
  518. if (isset($row['Extra']) && strtolower($row['Extra']) == 'auto_increment') {
  519. $content_cells[$i][$ci] .= ' checked="checked"';
  520. }
  521. $content_cells[$i][$ci] .= ' type="checkbox" value="AUTO_INCREMENT" />';
  522. $ci++;
  523. // column comments
  524. $content_cells[$i][$ci] = '<input id="field_' . $i . '_' . ($ci - $ci_offset)
  525. . '"' . ' type="text" name="field_comments[' . $i . ']" size="12"'
  526. . ' value="' . (isset($row['Field'])
  527. && is_array($comments_map)
  528. && isset($comments_map[$row['Field']])
  529. ? htmlspecialchars($comments_map[$row['Field']])
  530. : '') . '"'
  531. . ' class="textfield" />';
  532. $ci++;
  533. // move column
  534. if (isset($fields_meta)) {
  535. $content_cells[$i][$ci] = '<select id="field_' . $i . '_'
  536. . ($ci - $ci_offset) . '"' . ' name="field_move_to[' . $i
  537. . ']" size="1" width="5em">'
  538. . '<option value="" selected="selected">&nbsp;</option>';
  539. // find index of current column
  540. $current_index = 0;
  541. for ($mi = 0, $cols = count($move_columns); $mi < $cols; $mi++) {
  542. if ($move_columns[$mi]->name == $row['Field']) {
  543. $current_index = $mi;
  544. break;
  545. }
  546. }
  547. $content_cells[$i][$ci] .= '<option value="-first"'
  548. . ($current_index == 0 ? ' disabled="disabled"' : '')
  549. . '>' . __('first') . '</option>';
  550. for ($mi = 0, $cols = count($move_columns); $mi < $cols; $mi++) {
  551. $content_cells[$i][$ci] .=
  552. '<option value="' . htmlspecialchars($move_columns[$mi]->name) . '"'
  553. . (($current_index == $mi || $current_index == $mi + 1)
  554. ? ' disabled="disabled"'
  555. : '')
  556. .'>'
  557. . sprintf(
  558. __('after %s'),
  559. PMA_Util::backquote(
  560. htmlspecialchars(
  561. $move_columns[$mi]->name
  562. )
  563. )
  564. )
  565. . '</option>';
  566. }
  567. $content_cells[$i][$ci] .= '</select>';
  568. $ci++;
  569. }
  570. // column MIME-types
  571. if ($cfgRelation['mimework']
  572. && $GLOBALS['cfg']['BrowseMIME']
  573. && $cfgRelation['commwork']
  574. ) {
  575. $content_cells[$i][$ci] = '<select id="field_' . $i . '_'
  576. . ($ci - $ci_offset) . '" size="1" name="field_mimetype[' . $i . ']">';
  577. $content_cells[$i][$ci] .= ' <option value="">&nbsp;</option>';
  578. if (is_array($available_mime['mimetype'])) {
  579. foreach ($available_mime['mimetype'] as $mimekey => $mimetype) {
  580. $checked = (isset($row['Field'])
  581. && isset($mime_map[$row['Field']]['mimetype'])
  582. && ($mime_map[$row['Field']]['mimetype']
  583. == str_replace('/', '_', $mimetype))
  584. ? 'selected '
  585. : '');
  586. $content_cells[$i][$ci] .= ' <option value="'
  587. . str_replace('/', '_', $mimetype) . '" ' . $checked . '>'
  588. . htmlspecialchars($mimetype) . '</option>';
  589. }
  590. }
  591. $content_cells[$i][$ci] .= '</select>';
  592. $ci++;
  593. $content_cells[$i][$ci] = '<select id="field_' . $i . '_'
  594. . ($ci - $ci_offset) . '" size="1" name="field_transformation['
  595. . $i . ']">';
  596. $content_cells[$i][$ci] .= ' <option value="" title="' . __('None')
  597. . '"></option>';
  598. if (is_array($available_mime['transformation'])) {
  599. foreach ($available_mime['transformation'] as $mimekey => $transform) {
  600. $checked = isset($row['Field'])
  601. && isset($mime_map[$row['Field']]['transformation'])
  602. && preg_match(
  603. '@' . preg_quote(
  604. $available_mime['transformation_file'][$mimekey], '@'
  605. ) . '3?@i',
  606. $mime_map[$row['Field']]['transformation']
  607. )
  608. ? 'selected '
  609. : '';
  610. $tooltip = PMA_getTransformationDescription(
  611. $available_mime['transformation_file'][$mimekey], false
  612. );
  613. $content_cells[$i][$ci] .= '<option value="'
  614. . $available_mime['transformation_file'][$mimekey] . '" '
  615. . $checked . ' title="' . htmlspecialchars($tooltip) . '">'
  616. . htmlspecialchars($transform) . '</option>';
  617. }
  618. }
  619. $content_cells[$i][$ci] .= '</select>';
  620. $ci++;
  621. $val = isset($row['Field'])
  622. && isset($mime_map[$row['Field']]['transformation_options'])
  623. ? htmlspecialchars($mime_map[$row['Field']]['transformation_options'])
  624. : '';
  625. $content_cells[$i][$ci] = '<input id="field_' . $i . '_'
  626. . ($ci - $ci_offset) . '"' . ' type="text" '
  627. . 'name="field_transformation_options[' . $i . ']"'
  628. . ' size="16" class="textfield"'
  629. . ' value="' . $val . '"'
  630. . ' />';
  631. //$ci++;
  632. }
  633. } // end for
  634. $html .= '<form method="post" action="' . $action . '" class="'
  635. . ($action == 'tbl_create.php' ? 'create_table' : 'append_fields')
  636. . '_form ajax">';
  637. $html .= PMA_generate_common_hidden_inputs($_form_params);
  638. unset($_form_params);
  639. if ($action == 'tbl_create.php') {
  640. $html .= '<table>'
  641. . '<tr class="vmiddle">'
  642. . '<td>' . __('Table name')
  643. . ':&nbsp;<input type="text" name="table" size="40" maxlength="80"'
  644. . ' value="'
  645. . (isset($_REQUEST['table']) ? htmlspecialchars($_REQUEST['table']) : '')
  646. . '" class="textfield" autofocus />'
  647. . '</td>'
  648. . '<td>';
  649. if ($action == 'tbl_create.php'
  650. || $action == 'tbl_addfield.php'
  651. ) {
  652. $html .= sprintf(
  653. __('Add %s column(s)'), '<input type="text" id="added_fields" '
  654. . 'name="added_fields" size="2" value="1" onfocus="this.select'
  655. . '()" />'
  656. );
  657. $html .= '<input type="submit" name="submit_num_fields"'
  658. . 'value="' . __('Go') . '"'
  659. . 'onclick="return'
  660. . ' checkFormElementInRange(this.form, \'added_fields\', \''
  661. . str_replace(
  662. '\'', '\\\'', __('You have to add at least one column.')
  663. ) . '\', 1)" />';
  664. }
  665. $html .= '</td>'
  666. . '</tr>'
  667. . '</table>';
  668. }
  669. if (is_array($content_cells) && is_array($header_cells)) {
  670. // last row is for javascript insert
  671. //$empty_row = array_pop($content_cells);
  672. $html .= '<table id="table_columns" class="noclick">';
  673. $html .= '<caption class="tblHeaders">' . __('Structure')
  674. . PMA_Util::showMySQLDocu('SQL-Syntax', 'CREATE_TABLE') . '</caption>';
  675. $html .= '<tr>';
  676. foreach ($header_cells as $header_val) {
  677. $html .= '<th>' . $header_val . '</th>';
  678. }
  679. $html .= '</tr>';
  680. $odd_row = true;
  681. foreach ($content_cells as $content_row) {
  682. $html .= '<tr class="' . ($odd_row ? 'odd' : 'even') . '">';
  683. $odd_row = ! $odd_row;
  684. if (is_array($content_row)) {
  685. foreach ($content_row as $content_row_val) {
  686. $html .= '<td class="center">' . $content_row_val . '</td>';
  687. }
  688. }
  689. $html .= '</tr>';
  690. }
  691. $html .= '</table>'
  692. . '<br />';
  693. }
  694. /**
  695. * needs to be finished
  696. *
  697. *
  698. if ($display_type == 'horizontal') {
  699. $new_field = '';
  700. foreach ($empty_row as $content_row_val) {
  701. $new_field .= '<td class="center">' . $content_row_val . '</td>';
  702. }
  703. ?>
  704. <script type="text/javascript">
  705. // <![CDATA[
  706. var odd_row = <?php echo $odd_row; ?>;
  707. function addField()
  708. {
  709. var new_fields = document.getElementById('added_fields').value;
  710. var new_field_container = document.getElementById('table_columns');
  711. var new_field = '<?php echo preg_replace('|\s+|', ' ', preg_replace('|\'|', '\\\'', $new_field)); ?>';
  712. var i = 0;
  713. for (i = 0; i < new_fields; i++) {
  714. if (odd_row) {
  715. new_field_container.innerHTML += '<tr class="odd">' + new_field + '</tr>';
  716. } else {
  717. new_field_container.innerHTML += '<tr class="even">' + new_field + '</tr>';
  718. }
  719. odd_row = ! odd_row;
  720. }
  721. return true;
  722. }
  723. // ]]>
  724. </script>
  725. <?php
  726. }
  727. */
  728. if ($action == 'tbl_create.php') {
  729. $html .= '<table>'
  730. . '<tr class="vtop">'
  731. . '<th>' . __('Table comments') . ':&nbsp;</th>'
  732. . '<td width="25">&nbsp;</td>'
  733. . '<th>' . __('Storage Engine') . ':'
  734. . PMA_Util::showMySQLDocu('Storage_engines', 'Storage_engines')
  735. . '</th>'
  736. . '<td width="25">&nbsp;</td>'
  737. . '<th>' . __('Collation') . ':&nbsp;</th>'
  738. . '</tr>'
  739. . '<tr><td><input type="text" name="comment" size="40" maxlength="80"'
  740. . 'value="'
  741. . (isset($_REQUEST['comment'])
  742. ? htmlspecialchars($_REQUEST['comment'])
  743. : '')
  744. . '" class="textfield" />'
  745. . '</td>'
  746. . '<td width="25">&nbsp;</td>'
  747. . '<td>'
  748. . PMA_StorageEngine::getHtmlSelect(
  749. 'tbl_storage_engine', null,
  750. (isset($_REQUEST['tbl_storage_engine'])
  751. ? $_REQUEST['tbl_storage_engine']
  752. : null
  753. )
  754. )
  755. . '</td>'
  756. . '<td width="25">&nbsp;</td>'
  757. . '<td>'
  758. . PMA_generateCharsetDropdownBox(
  759. PMA_CSDROPDOWN_COLLATION, 'tbl_collation', null,
  760. (isset($_REQUEST['tbl_collation'])
  761. ? $_REQUEST['tbl_collation']
  762. : null
  763. ),
  764. false, 3
  765. )
  766. . '</td>'
  767. . '</tr>';
  768. if (PMA_Partition::havePartitioning()) {
  769. $html .= '<tr class="vtop">'
  770. . '<th>' . __('PARTITION definition') . ':&nbsp;'
  771. . PMA_Util::showMySQLDocu('Partitioning', 'Partitioning')
  772. . '</th>'
  773. . '</tr>'
  774. . '<tr>'
  775. . '<td>'
  776. . '<textarea name="partition_definition" id="partitiondefinition"'
  777. . ' cols="' . $GLOBALS['cfg']['TextareaCols'] . '"'
  778. . ' rows="' . $GLOBALS['cfg']['TextareaRows'] . '"'
  779. . ' dir="' . $GLOBALS['text_dir'] . '">'
  780. . (isset($_REQUEST['partition_definition'])
  781. ? htmlspecialchars($_REQUEST['partition_definition'])
  782. : '')
  783. . '</textarea>'
  784. . '</td>'
  785. . '</tr>';
  786. }
  787. $html .= '</table>'
  788. . '<br />';
  789. } // end if ($action == 'tbl_create.php')
  790. $html .= '<fieldset class="tblFooters">'
  791. . '<input type="submit" name="do_save_data" value="' . __('Save') . '" />'
  792. . '</fieldset>'
  793. . '<div id="properties_message"></div>'
  794. . '</form>';
  795. $html .= '<div id="popup_background"></div>';
  796. PMA_Response::getInstance()->addHTML($html);
  797. ?>