tbl_columns_definition_form.lib.php 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * set of functions used by tbl_columns_definitions_form.inc.php
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. if (!defined('PHPMYADMIN')) {
  9. exit;
  10. }
  11. /**
  12. * Function to get form parameters
  13. *
  14. * @param string $db database
  15. * @param string $table table
  16. * @param string $action action
  17. * @param int $num_fields number of fields
  18. * @param bool $selected selected
  19. *
  20. * @return array $form_params form parameters
  21. */
  22. function PMA_getFormsParameters($db, $table, $action, $num_fields, $selected)
  23. {
  24. $form_params = array(
  25. 'db' => $db
  26. );
  27. if ($action == 'tbl_create.php') {
  28. $form_params['reload'] = 1;
  29. } elseif ($action == 'tbl_addfield.php') {
  30. $form_params['field_where'] = $_REQUEST['field_where'];
  31. $form_params['after_field'] = $_REQUEST['after_field'];
  32. $form_params['table'] = $table;
  33. } else {
  34. $form_params['table'] = $table;
  35. }
  36. if (isset($num_fields)) {
  37. $form_params['orig_num_fields'] = $num_fields;
  38. }
  39. if (isset($_REQUEST['field_where'])) {
  40. $form_params['orig_field_where'] = $_REQUEST['field_where'];
  41. }
  42. if (isset($_REQUEST['after_field'])) {
  43. $form_params['orig_after_field'] = $_REQUEST['after_field'];
  44. }
  45. if (isset($selected) && is_array($selected)) {
  46. foreach ($selected as $o_fld_nr => $o_fld_val) {
  47. $form_params['selected[' . $o_fld_nr . ']'] = $o_fld_val;
  48. }
  49. }
  50. return $form_params;
  51. }
  52. /**
  53. * Function to get html for table comments, storage engine, collation and
  54. * partition definition
  55. *
  56. * @return string
  57. */
  58. function PMA_getHtmlForTableConfigurations()
  59. {
  60. $html = '<table>'
  61. . '<tr class="vtop">'
  62. . '<th>' . __('Table comments:') . '</th>'
  63. . '<td width="25">&nbsp;</td>'
  64. . '<th>' . __('Storage Engine:')
  65. . PMA_Util::showMySQLDocu('Storage_engines')
  66. . '</th>'
  67. . '<td width="25">&nbsp;</td>'
  68. . '<th>' . __('Collation:') . '</th>'
  69. . '</tr>'
  70. . '<tr><td><input type="text" name="comment" size="40" maxlength="80"'
  71. . ' value="'
  72. . (isset($_REQUEST['comment'])
  73. ? htmlspecialchars($_REQUEST['comment'])
  74. : '')
  75. . '" class="textfield" />'
  76. . '</td>'
  77. . '<td width="25">&nbsp;</td>'
  78. . '<td>'
  79. . PMA_StorageEngine::getHtmlSelect(
  80. 'tbl_storage_engine', null,
  81. (isset($_REQUEST['tbl_storage_engine'])
  82. ? $_REQUEST['tbl_storage_engine']
  83. : null
  84. )
  85. )
  86. . '</td>'
  87. . '<td width="25">&nbsp;</td>'
  88. . '<td>'
  89. . PMA_generateCharsetDropdownBox(
  90. PMA_CSDROPDOWN_COLLATION, 'tbl_collation', null,
  91. (isset($_REQUEST['tbl_collation'])
  92. ? $_REQUEST['tbl_collation']
  93. : null
  94. ),
  95. false, 3
  96. )
  97. . '</td>'
  98. . '</tr>';
  99. if (PMA_Partition::havePartitioning()) {
  100. $html .= '<tr class="vtop">'
  101. . '<th>' . __('PARTITION definition:') . '&nbsp;'
  102. . PMA_Util::showMySQLDocu('Partitioning')
  103. . '</th>'
  104. . '</tr>'
  105. . '<tr>'
  106. . '<td>'
  107. . '<textarea name="partition_definition" id="partitiondefinition"'
  108. . ' cols="' . $GLOBALS['cfg']['TextareaCols'] . '"'
  109. . ' rows="' . $GLOBALS['cfg']['TextareaRows'] . '"'
  110. . ' dir="' . $GLOBALS['text_dir'] . '">'
  111. . (isset($_REQUEST['partition_definition'])
  112. ? htmlspecialchars($_REQUEST['partition_definition'])
  113. : '')
  114. . '</textarea>'
  115. . '</td>'
  116. . '</tr>';
  117. }
  118. $html .= '</table>'
  119. . '<br />';
  120. return $html;
  121. }
  122. /**
  123. * Function to get html for the footer
  124. *
  125. * @return string
  126. */
  127. function PMA_getHtmlForFooter()
  128. {
  129. $html = '<fieldset class="tblFooters">'
  130. . '<input type="submit" name="do_save_data" value="' . __('Save') . '" />'
  131. . '</fieldset>'
  132. . '<div id="properties_message"></div>'
  133. . '</form>';
  134. $html .= '<div id="popup_background"></div>';
  135. return $html;
  136. }
  137. /**
  138. * Function to get html for table create table name and number of fields
  139. *
  140. * @return string
  141. */
  142. function PMA_getHtmlForTableNameAndNoOfColumns()
  143. {
  144. $html = '<table>'
  145. . '<tr class="vmiddle">'
  146. . '<td>' . __('Table name')
  147. . ':&nbsp;<input type="text" name="table" size="40" maxlength="80"'
  148. . ' value="'
  149. . (isset($_REQUEST['table']) ? htmlspecialchars($_REQUEST['table']) : '')
  150. . '" class="textfield" autofocus required />'
  151. . '</td>'
  152. . '<td>';
  153. $html .= sprintf(
  154. __('Add %s column(s)'), '<input type="text" id="added_fields" '
  155. . 'name="added_fields" size="2" value="1" onfocus="this.select'
  156. . '()" />'
  157. );
  158. $html .= '<input type="submit" name="submit_num_fields"'
  159. . 'value="' . __('Go') . '"'
  160. . ' onclick="return'
  161. . ' checkFormElementInRange(this.form, \'added_fields\', \''
  162. . str_replace(
  163. '\'', '\\\'', __('You have to add at least one column.')
  164. ) . '\', 1)" />';
  165. $html .= '</td>'
  166. . '</tr>'
  167. . '</table>';
  168. return $html;
  169. }
  170. /**
  171. * Function to get html for table field definitions
  172. *
  173. * @param array $header_cells header cells
  174. * @param array $content_cells content cells
  175. *
  176. * @return string
  177. */
  178. function PMA_getHtmlForTableFieldDefinitions($header_cells, $content_cells)
  179. {
  180. $html = '<table id="table_columns" class="noclick">';
  181. $html .= '<caption class="tblHeaders">' . __('Structure')
  182. . PMA_Util::showMySQLDocu('CREATE_TABLE') . '</caption>';
  183. $html .= '<tr>';
  184. foreach ($header_cells as $header_val) {
  185. $html .= '<th>' . $header_val . '</th>';
  186. }
  187. $html .= '</tr>';
  188. $odd_row = true;
  189. foreach ($content_cells as $content_row) {
  190. $html .= '<tr class="' . ($odd_row ? 'odd' : 'even') . '">';
  191. $odd_row = ! $odd_row;
  192. if (is_array($content_row)) {
  193. foreach ($content_row as $content_row_val) {
  194. $html .= '<td class="center">' . $content_row_val . '</td>';
  195. }
  196. }
  197. $html .= '</tr>';
  198. }
  199. $html .= '</table>'
  200. . '<br />';
  201. return $html;
  202. }
  203. /**
  204. * Function to get html for the create table or field add view
  205. *
  206. * @param string $action action
  207. * @param array $form_params forms parameters
  208. * @param array $content_cells content cells
  209. * @param array $header_cells header cells
  210. *
  211. * @return string
  212. */
  213. function PMA_getHtmlForTableCreateOrAddField($action, $form_params, $content_cells,
  214. $header_cells
  215. ) {
  216. $html = '<form method="post" action="' . $action . '" class="'
  217. . ($action == 'tbl_create.php' ? 'create_table' : 'append_fields')
  218. . '_form ajax">';
  219. $html .= PMA_URL_getHiddenInputs($form_params);
  220. if ($action == 'tbl_create.php') {
  221. $html .= PMA_getHtmlForTableNameAndNoOfColumns();
  222. }
  223. if (is_array($content_cells) && is_array($header_cells)) {
  224. $html .= PMA_getHtmlForTableFieldDefinitions($header_cells, $content_cells);
  225. }
  226. if ($action == 'tbl_create.php') {
  227. $html .= PMA_getHtmlForTableConfigurations();
  228. }
  229. $html .= PMA_getHtmlForFooter();
  230. return $html;
  231. }
  232. /**
  233. * Function to get header cells
  234. *
  235. * @param bool $is_backup whether backup or not
  236. * @param array $columnMeta column meta data
  237. * @param bool $mimework whether mimework or not
  238. * @param string $db current database
  239. * @param string $table current table
  240. *
  241. * @return array
  242. */
  243. function PMA_getHeaderCells($is_backup, $columnMeta, $mimework, $db, $table)
  244. {
  245. $header_cells = array();
  246. $header_cells[] = __('Name');
  247. $header_cells[] = __('Type')
  248. . PMA_Util::showMySQLDocu('data-types');
  249. $header_cells[] = __('Length/Values')
  250. . PMA_Util::showHint(
  251. __(
  252. 'If column type is "enum" or "set", please enter the values using'
  253. . ' this format: \'a\',\'b\',\'c\'…<br />If you ever need to put'
  254. . ' a backslash ("\") or a single quote ("\'") amongst those'
  255. . ' values, precede it with a backslash (for example \'\\\\xyz\''
  256. . ' or \'a\\\'b\').'
  257. )
  258. );
  259. $header_cells[] = __('Default')
  260. . PMA_Util::showHint(
  261. __(
  262. 'For default values, please enter just a single value,'
  263. . ' without backslash escaping or quotes, using this format: a'
  264. )
  265. );
  266. $header_cells[] = __('Collation');
  267. $header_cells[] = __('Attributes');
  268. $header_cells[] = __('Null');
  269. // We could remove this 'if' and let the key information be shown and
  270. // editable. However, for this to work, structure.lib.php must be modified
  271. // to use the key fields, as tbl_addfield does.
  272. if (! $is_backup) {
  273. $header_cells[] = __('Index');
  274. }
  275. $header_cells[] = '<abbr title="AUTO_INCREMENT">A_I</abbr>';
  276. $header_cells[] = __('Comments');
  277. if (isset($columnMeta)) {
  278. $header_cells[] = __('Move column');
  279. }
  280. if ($mimework && $GLOBALS['cfg']['BrowseMIME']) {
  281. $header_cells[] = __('MIME type');
  282. $header_cells[] = '<a href="transformation_overview.php?'
  283. . PMA_URL_getCommon($db, $table)
  284. . '" title="' . __(
  285. 'List of available transformations and their options'
  286. )
  287. . '" target="_blank">'
  288. . __('Browser transformation')
  289. . '</a>';
  290. $header_cells[] = __('Transformation options')
  291. . PMA_Util::showHint(
  292. __(
  293. 'Please enter the values for transformation options using this'
  294. . ' format: \'a\', 100, b,\'c\'…<br />If you ever need to put'
  295. . ' a backslash ("\") or a single quote ("\'") amongst those'
  296. . ' values, precede it with a backslash (for example \'\\\\xyz\''
  297. . ' or \'a\\\'b\').'
  298. )
  299. );
  300. }
  301. return $header_cells;
  302. }
  303. /**
  304. * Function for moving, load all available column names
  305. *
  306. * @param string $db current database
  307. * @param string $table current table
  308. *
  309. * @return array
  310. */
  311. function PMA_getMoveColumns($db, $table)
  312. {
  313. $move_columns_sql_query = 'SELECT * FROM '
  314. . PMA_Util::backquote($db)
  315. . '.'
  316. . PMA_Util::backquote($table)
  317. . ' LIMIT 1';
  318. $move_columns_sql_result = $GLOBALS['dbi']->tryQuery($move_columns_sql_query);
  319. $move_columns = $GLOBALS['dbi']->getFieldsMeta($move_columns_sql_result);
  320. return $move_columns;
  321. }
  322. /**
  323. * Function to get row data for regenerating previous when error occurred.
  324. *
  325. * @param int $columnNumber column number
  326. * @param array $submit_fulltext submit full text
  327. *
  328. * @return array
  329. */
  330. function PMA_getRowDataForRegeneration($columnNumber, $submit_fulltext)
  331. {
  332. $columnMeta = array();
  333. $columnMeta['Field'] = isset($_REQUEST['field_name'][$columnNumber])
  334. ? $_REQUEST['field_name'][$columnNumber]
  335. : false;
  336. $columnMeta['Type'] = isset($_REQUEST['field_type'][$columnNumber])
  337. ? $_REQUEST['field_type'][$columnNumber]
  338. : false;
  339. $columnMeta['Collation'] = isset($_REQUEST['field_collation'][$columnNumber])
  340. ? $_REQUEST['field_collation'][$columnNumber]
  341. : '';
  342. $columnMeta['Null'] = isset($_REQUEST['field_null'][$columnNumber])
  343. ? $_REQUEST['field_null'][$columnNumber]
  344. : '';
  345. $columnMeta['Key'] = '';
  346. if (isset($_REQUEST['field_key'][$columnNumber])) {
  347. $parts = explode('_', $_REQUEST['field_key'][$columnNumber], 2);
  348. if (count($parts) == 2 && $parts[1] == $columnNumber) {
  349. switch ($parts[0]) {
  350. case 'primary':
  351. $columnMeta['Key'] = 'PRI';
  352. break;
  353. case 'index':
  354. $columnMeta['Key'] = 'MUL';
  355. break;
  356. case 'unique':
  357. $columnMeta['Key'] = 'UNI';
  358. break;
  359. case 'fulltext':
  360. $columnMeta['Key'] = 'FULLTEXT';
  361. break;
  362. }
  363. }
  364. }
  365. // put None in the drop-down for Default, when someone adds a field
  366. $columnMeta['DefaultType']
  367. = isset($_REQUEST['field_default_type'][$columnNumber])
  368. ? $_REQUEST['field_default_type'][$columnNumber]
  369. : 'NONE';
  370. $columnMeta['DefaultValue']
  371. = isset($_REQUEST['field_default_value'][$columnNumber])
  372. ? $_REQUEST['field_default_value'][$columnNumber]
  373. : '';
  374. switch ($columnMeta['DefaultType']) {
  375. case 'NONE' :
  376. $columnMeta['Default'] = null;
  377. break;
  378. case 'USER_DEFINED' :
  379. $columnMeta['Default'] = $columnMeta['DefaultValue'];
  380. break;
  381. case 'NULL' :
  382. case 'CURRENT_TIMESTAMP' :
  383. $columnMeta['Default'] = $columnMeta['DefaultType'];
  384. break;
  385. }
  386. $columnMeta['Extra']
  387. = (isset($_REQUEST['field_extra'][$columnNumber])
  388. ? $_REQUEST['field_extra'][$columnNumber]
  389. : false);
  390. $columnMeta['Comment']
  391. = (isset($submit_fulltext[$columnNumber])
  392. && ($submit_fulltext[$columnNumber] == $columnNumber)
  393. ? 'FULLTEXT'
  394. : false);
  395. return $columnMeta;
  396. }
  397. /**
  398. * Function to get submit properties for regenerating previous when error occurred.
  399. *
  400. * @param int $columnNumber column number
  401. *
  402. * @return array
  403. */
  404. function PMA_getSubmitPropertiesForRegeneration($columnNumber)
  405. {
  406. $submit_length
  407. = (isset($_REQUEST['field_length'][$columnNumber])
  408. ? $_REQUEST['field_length'][$columnNumber]
  409. : false);
  410. $submit_attribute
  411. = (isset($_REQUEST['field_attribute'][$columnNumber])
  412. ? $_REQUEST['field_attribute'][$columnNumber]
  413. : false);
  414. $submit_default_current_timestamp
  415. = (isset($_REQUEST['field_default_current_timestamp'][$columnNumber])
  416. ? true
  417. : false);
  418. return array(
  419. $submit_length, $submit_attribute, $submit_default_current_timestamp
  420. );
  421. }
  422. /**
  423. * An error happened with previous inputs, so we will restore the data
  424. * to embed it once again in this form.
  425. *
  426. * @param int $columnNumber column number
  427. * @param array $submit_fulltext submit full text
  428. * @param array $comments_map comments map
  429. * @param array $mime_map mime map
  430. *
  431. * @return array
  432. */
  433. function PMA_handleRegeneration($columnNumber, $submit_fulltext, $comments_map,
  434. $mime_map
  435. ) {
  436. $columnMeta = PMA_getRowDataForRegeneration(
  437. $columnNumber, isset($submit_fulltext) ? $submit_fulltext : null
  438. );
  439. list($submit_length, $submit_attribute, $submit_default_current_timestamp)
  440. = PMA_getSubmitPropertiesForRegeneration($columnNumber);
  441. if (isset($_REQUEST['field_comments'][$columnNumber])) {
  442. $comments_map[$columnMeta['Field']]
  443. = $_REQUEST['field_comments'][$columnNumber];
  444. }
  445. if (isset($_REQUEST['field_mimetype'][$columnNumber])) {
  446. $mime_map[$columnMeta['Field']]['mimetype']
  447. = $_REQUEST['field_mimetype'][$columnNumber];
  448. }
  449. if (isset($_REQUEST['field_transformation'][$columnNumber])) {
  450. $mime_map[$columnMeta['Field']]['transformation']
  451. = $_REQUEST['field_transformation'][$columnNumber];
  452. }
  453. if (isset($_REQUEST['field_transformation_options'][$columnNumber])) {
  454. $mime_map[$columnMeta['Field']]['transformation_options']
  455. = $_REQUEST['field_transformation_options'][$columnNumber];
  456. }
  457. return array(
  458. $columnMeta, $submit_length, $submit_attribute,
  459. $submit_default_current_timestamp, $comments_map, $mime_map
  460. );
  461. }
  462. /**
  463. * Function to update default value info in $columnMeta and get this array
  464. *
  465. * @param array $columnMeta column meta
  466. * @param bool $isDefault whether the row value is default
  467. *
  468. * @return array
  469. */
  470. function PMA_getColumnMetaForDefault($columnMeta, $isDefault)
  471. {
  472. switch ($columnMeta['Default']) {
  473. case null:
  474. if ($columnMeta['Null'] == 'YES') {
  475. $columnMeta['DefaultType'] = 'NULL';
  476. $columnMeta['DefaultValue'] = '';
  477. // SHOW FULL COLUMNS does not report the case
  478. // when there is a DEFAULT value which is empty so we need to use the
  479. // results of SHOW CREATE TABLE
  480. } elseif ($isDefault) {
  481. $columnMeta['DefaultType'] = 'USER_DEFINED';
  482. $columnMeta['DefaultValue'] = $columnMeta['Default'];
  483. } else {
  484. $columnMeta['DefaultType'] = 'NONE';
  485. $columnMeta['DefaultValue'] = '';
  486. }
  487. break;
  488. case 'CURRENT_TIMESTAMP':
  489. $columnMeta['DefaultType'] = 'CURRENT_TIMESTAMP';
  490. $columnMeta['DefaultValue'] = '';
  491. break;
  492. default:
  493. $columnMeta['DefaultType'] = 'USER_DEFINED';
  494. $columnMeta['DefaultValue'] = $columnMeta['Default'];
  495. break;
  496. }
  497. return $columnMeta;
  498. }
  499. /**
  500. * Function to get html for the column name
  501. *
  502. * @param int $columnNumber column number
  503. * @param int $ci cell index
  504. * @param int $ci_offset cell index offset
  505. * @param array $columnMeta column meta
  506. *
  507. * @return string
  508. */
  509. function PMA_getHtmlForColumnName($columnNumber, $ci, $ci_offset, $columnMeta)
  510. {
  511. $title = '';
  512. if (isset($columnMeta['column_status'])) {
  513. if ($columnMeta['column_status']['isReferenced']) {
  514. $title .= sprintf(
  515. __('Referenced by %s.'),
  516. implode(",", $columnMeta['column_status']['references'])
  517. );
  518. }
  519. if ($columnMeta['column_status']['isForeignKey']) {
  520. if (!empty($title)) {
  521. $title .= "\n";
  522. }
  523. $title .= __('Is a foreign key.');
  524. }
  525. }
  526. if (empty($title)) {
  527. $title = __('Column');
  528. }
  529. $html = '<input' . (isset($columnMeta['column_status'])
  530. && !$columnMeta['column_status']['isEditable']?' disabled="disabled" ':' ')
  531. . 'id="field_' . $columnNumber . '_' . ($ci - $ci_offset)
  532. . '"' . ' type="text" name="field_name[' . $columnNumber . ']"'
  533. . ' maxlength="64" class="textfield" title="' . $title . '"'
  534. . ' size="10"'
  535. . ' value="'
  536. . (isset($columnMeta['Field'])
  537. ? htmlspecialchars($columnMeta['Field']) : '')
  538. . '"' . ' />';
  539. return $html;
  540. }
  541. /**
  542. * Function to get html for the column type
  543. *
  544. * @param int $columnNumber column number
  545. * @param int $ci cell index
  546. * @param int $ci_offset cell index offset
  547. * @param string $type_upper type inuppercase
  548. * @param array $columnMeta meta data
  549. *
  550. * @return string
  551. */
  552. function PMA_getHtmlForColumnType($columnNumber, $ci, $ci_offset,
  553. $type_upper, $columnMeta
  554. ) {
  555. $select_id = 'field_' . $columnNumber . '_' . ($ci - $ci_offset);
  556. $html = '<select' . (isset($columnMeta['column_status'])
  557. && !$columnMeta['column_status']['isEditable']?' disabled="disabled" ':' ')
  558. . 'class="column_type" name="field_type['
  559. . $columnNumber . ']"' . ' id="' . $select_id . '">';
  560. $html .= PMA_Util::getSupportedDatatypes(true, $type_upper);
  561. $html .= ' </select>';
  562. return $html;
  563. }
  564. /**
  565. * Function to get html for transformation option
  566. *
  567. * @param int $columnNumber column number
  568. * @param int $ci cell index
  569. * @param int $ci_offset cell index offset
  570. * @param array $columnMeta column meta
  571. * @param array $mime_map mime map
  572. *
  573. * @return string
  574. */
  575. function PMA_getHtmlForTransformationOption($columnNumber, $ci, $ci_offset,
  576. $columnMeta, $mime_map
  577. ) {
  578. $val = isset($columnMeta['Field'])
  579. && isset($mime_map[$columnMeta['Field']]['transformation_options'])
  580. ? htmlspecialchars(
  581. $mime_map[$columnMeta['Field']]
  582. ['transformation_options']
  583. )
  584. : '';
  585. $html = '<input id="field_' . $columnNumber . '_'
  586. . ($ci - $ci_offset) . '"' . ' type="text" '
  587. . 'name="field_transformation_options[' . $columnNumber . ']"'
  588. . ' size="16" class="textfield"'
  589. . ' value="' . $val . '"'
  590. . ' />';
  591. return $html;
  592. }
  593. /**
  594. * Function to get html for mime type
  595. *
  596. * @param int $columnNumber column number
  597. * @param int $ci cell index
  598. * @param int $ci_offset cell index offset
  599. * @param array $available_mime available mime
  600. * @param array $columnMeta column meta
  601. * @param array $mime_map mime map
  602. *
  603. * @return string
  604. */
  605. function PMA_getHtmlForMimeType($columnNumber, $ci, $ci_offset,
  606. $available_mime, $columnMeta, $mime_map
  607. ) {
  608. $html = '<select id="field_' . $columnNumber . '_'
  609. . ($ci - $ci_offset)
  610. . '" size="1" name="field_mimetype[' . $columnNumber . ']">';
  611. $html .= ' <option value="">&nbsp;</option>';
  612. if (is_array($available_mime['mimetype'])) {
  613. foreach ($available_mime['mimetype'] as $mimetype) {
  614. $checked = (isset($columnMeta['Field'])
  615. && isset($mime_map[$columnMeta['Field']]['mimetype'])
  616. && ($mime_map[$columnMeta['Field']]['mimetype']
  617. == str_replace('/', '_', $mimetype))
  618. ? 'selected '
  619. : '');
  620. $html .= ' <option value="'
  621. . str_replace('/', '_', $mimetype) . '" ' . $checked . '>'
  622. . htmlspecialchars($mimetype) . '</option>';
  623. }
  624. }
  625. $html .= '</select>';
  626. return $html;
  627. }
  628. /**
  629. * Function to get html for browser transformation
  630. *
  631. * @param int $columnNumber column number
  632. * @param int $ci cell index
  633. * @param int $ci_offset cell index offset
  634. * @param array $available_mime available mime
  635. * @param array $columnMeta column meta
  636. * @param array $mime_map mime map
  637. *
  638. * @return string
  639. */
  640. function PMA_getHtmlForBrowserTransformation($columnNumber, $ci, $ci_offset,
  641. $available_mime, $columnMeta, $mime_map
  642. ) {
  643. $html = '<select id="field_' . $columnNumber . '_'
  644. . ($ci - $ci_offset) . '" size="1" name="field_transformation['
  645. . $columnNumber . ']">';
  646. $html .= ' <option value="" title="' . __('None')
  647. . '"></option>';
  648. if (is_array($available_mime['transformation'])) {
  649. foreach ($available_mime['transformation'] as $mimekey => $transform) {
  650. $checked = isset($columnMeta['Field'])
  651. && isset($mime_map[$columnMeta['Field']]['transformation'])
  652. && preg_match(
  653. '@' . preg_quote(
  654. $available_mime['transformation_file'][$mimekey]
  655. ) . '3?@i',
  656. $mime_map[$columnMeta['Field']]['transformation']
  657. )
  658. ? 'selected '
  659. : '';
  660. $tooltip = PMA_getTransformationDescription(
  661. $available_mime['transformation_file'][$mimekey], false
  662. );
  663. $html .= '<option value="'
  664. . $available_mime['transformation_file'][$mimekey] . '" '
  665. . $checked . ' title="' . htmlspecialchars($tooltip) . '">'
  666. . htmlspecialchars($transform) . '</option>';
  667. }
  668. }
  669. $html .= '</select>';
  670. return $html;
  671. }
  672. /**
  673. * Function to get html for move column
  674. *
  675. * @param int $columnNumber column number
  676. * @param int $ci cell index
  677. * @param int $ci_offset cell index offset
  678. * @param array $move_columns move columns
  679. * @param array $columnMeta column meta
  680. *
  681. * @return string
  682. */
  683. function PMA_getHtmlForMoveColumn($columnNumber, $ci, $ci_offset, $move_columns,
  684. $columnMeta
  685. ) {
  686. $html = '<select id="field_' . $columnNumber . '_'
  687. . ($ci - $ci_offset) . '"' . ' name="field_move_to[' . $columnNumber
  688. . ']" size="1" width="5em">'
  689. . '<option value="" selected="selected">&nbsp;</option>';
  690. // find index of current column
  691. $current_index = 0;
  692. for ($mi = 0, $cols = count($move_columns); $mi < $cols; $mi++) {
  693. if ($move_columns[$mi]->name == $columnMeta['Field']) {
  694. $current_index = $mi;
  695. break;
  696. }
  697. }
  698. $html .= '<option value="-first"'
  699. . ($current_index == 0 ? ' disabled="disabled"' : '')
  700. . '>' . __('first') . '</option>';
  701. for ($mi = 0, $cols = count($move_columns); $mi < $cols; $mi++) {
  702. $html .=
  703. '<option value="' . htmlspecialchars($move_columns[$mi]->name) . '"'
  704. . (($current_index == $mi || $current_index == $mi + 1)
  705. ? ' disabled="disabled"'
  706. : '')
  707. . '>'
  708. . sprintf(
  709. __('after %s'),
  710. PMA_Util::backquote(
  711. htmlspecialchars(
  712. $move_columns[$mi]->name
  713. )
  714. )
  715. )
  716. . '</option>';
  717. }
  718. $html .= '</select>';
  719. return $html;
  720. }
  721. /**
  722. * Function to get html for column comment
  723. *
  724. * @param int $columnNumber column number
  725. * @param int $ci cell index
  726. * @param int $ci_offset cell index offset
  727. * @param array $columnMeta column meta
  728. * @param array $comments_map comments map
  729. *
  730. * @return string
  731. */
  732. function PMA_getHtmlForColumnComment($columnNumber, $ci, $ci_offset, $columnMeta,
  733. $comments_map
  734. ) {
  735. $html = '<input id="field_' . $columnNumber . '_' . ($ci - $ci_offset)
  736. . '"' . ' type="text" name="field_comments[' . $columnNumber
  737. . ']" size="12"'
  738. . ' value="' . (isset($columnMeta['Field'])
  739. && is_array($comments_map)
  740. && isset($comments_map[$columnMeta['Field']])
  741. ? htmlspecialchars($comments_map[$columnMeta['Field']])
  742. : '') . '"'
  743. . ' class="textfield" />';
  744. return $html;
  745. }
  746. /**
  747. * Function get html for column auto increment
  748. *
  749. * @param int $columnNumber column number
  750. * @param int $ci cell index
  751. * @param int $ci_offset cell index offset
  752. * @param array $columnMeta column meta
  753. *
  754. * @return string
  755. */
  756. function PMA_getHtmlForColumnAutoIncrement($columnNumber, $ci, $ci_offset,
  757. $columnMeta
  758. ) {
  759. $html = '<input name="field_extra[' . $columnNumber . ']"'
  760. . ' id="field_' . $columnNumber . '_' . ($ci - $ci_offset) . '"';
  761. if (isset($columnMeta['Extra'])
  762. && strtolower($columnMeta['Extra']) == 'auto_increment'
  763. ) {
  764. $html .= ' checked="checked"';
  765. }
  766. $html .= ' type="checkbox" value="AUTO_INCREMENT" />';
  767. return $html;
  768. }
  769. /**
  770. * Function to get html for the column indexes
  771. *
  772. * @param int $columnNumber column number
  773. * @param int $ci cell index
  774. * @param int $ci_offset cell index offset
  775. * @param array $columnMeta column meta
  776. *
  777. * @return string
  778. */
  779. function PMA_getHtmlForColumnIndexes($columnNumber, $ci, $ci_offset, $columnMeta)
  780. {
  781. $html = '<select name="field_key[' . $columnNumber . ']"'
  782. . ' id="field_' . $columnNumber . '_' . ($ci - $ci_offset) . '">';
  783. $html .= '<option value="none_' . $columnNumber . '">---</option>';
  784. $html .= PMA_getHtmlForIndexTypeOption(
  785. $columnNumber, $columnMeta, 'Primary', 'PRI'
  786. );
  787. $html .= PMA_getHtmlForIndexTypeOption(
  788. $columnNumber, $columnMeta, 'Unique', 'UNI'
  789. );
  790. $html .= PMA_getHtmlForIndexTypeOption(
  791. $columnNumber, $columnMeta, 'Index', 'MUL'
  792. );
  793. if (!PMA_DRIZZLE) {
  794. $html .= PMA_getHtmlForIndexTypeOption(
  795. $columnNumber, $columnMeta, 'Fulltext', 'FULLTEXT'
  796. );
  797. }
  798. $html .= '</select>';
  799. return $html;
  800. }
  801. /**
  802. * Function to get html for the index options
  803. *
  804. * @param int $columnNumber column number
  805. * @param array $columnMeta column meta
  806. * @param string $type index type
  807. * @param string $key column meta key
  808. *
  809. * @return string
  810. */
  811. function PMA_getHtmlForIndexTypeOption($columnNumber, $columnMeta, $type, $key)
  812. {
  813. $html = '<option value="' . strtolower($type) . '_' . $columnNumber
  814. . '" title="'
  815. . __($type) . '"';
  816. if (isset($columnMeta['Key']) && $columnMeta['Key'] == $key) {
  817. $html .= ' selected="selected"';
  818. }
  819. $html .= '>' . strtoupper($type) . '</option>';
  820. return $html;
  821. }
  822. /**
  823. * Function to get html for column null
  824. *
  825. * @param int $columnNumber column number
  826. * @param int $ci cell index
  827. * @param int $ci_offset cell index offset
  828. * @param array $columnMeta column meta
  829. *
  830. * @return string
  831. */
  832. function PMA_getHtmlForColumnNull($columnNumber, $ci, $ci_offset, $columnMeta)
  833. {
  834. $html = '<input name="field_null[' . $columnNumber . ']"'
  835. . ' id="field_' . $columnNumber . '_' . ($ci - $ci_offset) . '"';
  836. if (! empty($columnMeta['Null'])
  837. && $columnMeta['Null'] != 'NO'
  838. && $columnMeta['Null'] != 'NOT NULL'
  839. ) {
  840. $html .= ' checked="checked"';
  841. }
  842. $html .= ' type="checkbox" value="NULL" class="allow_null"/>';
  843. return $html;
  844. }
  845. /**
  846. * Function to get html for column attribute
  847. *
  848. * @param int $columnNumber column number
  849. * @param int $ci cell index
  850. * @param int $ci_offset cell index offset
  851. * @param array $extracted_columnspec extracted column
  852. * @param array $columnMeta column meta
  853. * @param bool $submit_attribute submit attribute
  854. * @param array $analyzed_sql analyzed sql
  855. * @param bool $submit_default_current_timestamp submit default current time stamp
  856. *
  857. * @return string
  858. */
  859. function PMA_getHtmlForColumnAttribute($columnNumber, $ci, $ci_offset,
  860. $extracted_columnspec, $columnMeta, $submit_attribute, $analyzed_sql,
  861. $submit_default_current_timestamp
  862. ) {
  863. $html = '<select style="font-size: 70%;"'
  864. . ' name="field_attribute[' . $columnNumber . ']"'
  865. . ' id="field_' . $columnNumber . '_' . ($ci - $ci_offset) . '">';
  866. $attribute = '';
  867. if (isset($extracted_columnspec['attribute'])) {
  868. $attribute = $extracted_columnspec['attribute'];
  869. }
  870. if (isset($columnMeta['Extra'])
  871. && $columnMeta['Extra'] == 'on update CURRENT_TIMESTAMP'
  872. ) {
  873. $attribute = 'on update CURRENT_TIMESTAMP';
  874. }
  875. if (isset($submit_attribute) && $submit_attribute != false) {
  876. $attribute = $submit_attribute;
  877. }
  878. // here, we have a TIMESTAMP that SHOW FULL COLUMNS reports as having the
  879. // NULL attribute, but SHOW CREATE TABLE says the contrary. Believe
  880. // the latter.
  881. $create_table_fields = $analyzed_sql[0]['create_table_fields'];
  882. if (PMA_MYSQL_INT_VERSION < 50025
  883. && isset($columnMeta['Field'])
  884. && isset($create_table_fields[$columnMeta['Field']]['type'])
  885. && $create_table_fields[$columnMeta['Field']]['type'] == 'TIMESTAMP'
  886. && $create_table_fields[$columnMeta['Field']]['timestamp_not_null'] == true
  887. ) {
  888. $columnMeta['Null'] = '';
  889. }
  890. // MySQL 4.1.2+ TIMESTAMP options
  891. // (if on_update_current_timestamp is set, then it's TRUE)
  892. if (isset($columnMeta['Field'])) {
  893. $field = $create_table_fields[$columnMeta['Field']];
  894. }
  895. if (isset($field)
  896. && isset($field['on_update_current_timestamp'])
  897. ) {
  898. $attribute = 'on update CURRENT_TIMESTAMP';
  899. }
  900. if ((isset($columnMeta['Field'])
  901. && isset($field['default_current_timestamp']))
  902. || (isset($submit_default_current_timestamp)
  903. && $submit_default_current_timestamp)
  904. ) {
  905. $default_current_timestamp = true;
  906. } else {
  907. $default_current_timestamp = false;
  908. }
  909. $attribute_types = $GLOBALS['PMA_Types']->getAttributes();
  910. $cnt_attribute_types = count($attribute_types);
  911. for ($j = 0; $j < $cnt_attribute_types; $j++) {
  912. $html
  913. .= ' <option value="' . $attribute_types[$j] . '"';
  914. if (strtoupper($attribute) == strtoupper($attribute_types[$j])) {
  915. $html .= ' selected="selected"';
  916. }
  917. $html .= '>' . $attribute_types[$j] . '</option>';
  918. }
  919. $html .= '</select>';
  920. return $html;
  921. }
  922. /**
  923. * Function to get html for column collation
  924. *
  925. * @param int $columnNumber column number
  926. * @param int $ci cell index
  927. * @param int $ci_offset cell index offset
  928. * @param array $columnMeta column meta
  929. *
  930. * @return string
  931. */
  932. function PMA_getHtmlForColumnCollation($columnNumber, $ci, $ci_offset, $columnMeta)
  933. {
  934. $tmp_collation
  935. = empty($columnMeta['Collation']) ? null : $columnMeta['Collation'];
  936. $html = PMA_generateCharsetDropdownBox(
  937. PMA_CSDROPDOWN_COLLATION, 'field_collation[' . $columnNumber . ']',
  938. 'field_' . $columnNumber . '_' . ($ci - $ci_offset), $tmp_collation, false
  939. );
  940. return $html;
  941. }
  942. /**
  943. * Function get html for column length
  944. *
  945. * @param int $columnNumber column number
  946. * @param int $ci cell index
  947. * @param int $ci_offset cell index offset
  948. * @param int $length_values_input_size length values input size
  949. * @param int $length_to_display length to disply
  950. *
  951. * @return string
  952. */
  953. function PMA_getHtmlForColumnLength($columnNumber, $ci, $ci_offset,
  954. $length_values_input_size, $length_to_display
  955. ) {
  956. $html = '<input id="field_' . $columnNumber . '_' . ($ci - $ci_offset)
  957. . '"' . ' type="text" name="field_length[' . $columnNumber . ']" size="'
  958. . $length_values_input_size . '"' . ' value="' . htmlspecialchars(
  959. $length_to_display
  960. )
  961. . '"'
  962. . ' class="textfield" />'
  963. . '<p class="enum_notice" id="enum_notice_' . $columnNumber . '_'
  964. . ($ci - $ci_offset)
  965. . '">';
  966. $html .= '<a href="#" class="open_enum_editor"> '
  967. . __('Edit ENUM/SET values') . '</a>'
  968. . '</p>';
  969. return $html;
  970. }
  971. /**
  972. * Function to get html for the default column
  973. *
  974. * @param int $columnNumber column number
  975. * @param int $ci cell index
  976. * @param int $ci_offset cell index offset
  977. * @param string $type_upper type upper
  978. * @param string $default_current_timestamp default current timestamp
  979. * @param array $columnMeta column meta
  980. *
  981. * @return string
  982. */
  983. function PMA_getHtmlForColumnDefault($columnNumber, $ci, $ci_offset, $type_upper,
  984. $default_current_timestamp, $columnMeta
  985. ) {
  986. // here we put 'NONE' as the default value of drop-down; otherwise
  987. // users would have problems if they forget to enter the default
  988. // value (example, for an INT)
  989. $default_options = array(
  990. 'NONE' => _pgettext('for default', 'None'),
  991. 'USER_DEFINED' => __('As defined:'),
  992. 'NULL' => 'NULL',
  993. 'CURRENT_TIMESTAMP' => 'CURRENT_TIMESTAMP',
  994. );
  995. // for a TIMESTAMP, do not show the string "CURRENT_TIMESTAMP" as a default
  996. // value
  997. if ($type_upper == 'TIMESTAMP'
  998. && ! empty($default_current_timestamp)
  999. && isset($columnMeta['Default'])
  1000. ) {
  1001. $columnMeta['Default'] = '';
  1002. }
  1003. if ($type_upper == 'BIT') {
  1004. $columnMeta['DefaultValue']
  1005. = PMA_Util::convertBitDefaultValue($columnMeta['DefaultValue']);
  1006. }
  1007. $html = '<select name="field_default_type[' . $columnNumber
  1008. . ']" id="field_' . $columnNumber . '_' . ($ci - $ci_offset)
  1009. . '" class="default_type">';
  1010. foreach ($default_options as $key => $value) {
  1011. $html .= '<option value="' . $key . '"';
  1012. // is only set when we go back to edit a field's structure
  1013. if (isset($columnMeta['DefaultType'])
  1014. && $columnMeta['DefaultType'] == $key
  1015. ) {
  1016. $html .= ' selected="selected"';
  1017. }
  1018. $html .= ' >' . $value . '</option>';
  1019. }
  1020. $html .= '</select>';
  1021. $html .= '<br />';
  1022. $value = isset($columnMeta['DefaultValue'])
  1023. ? htmlspecialchars($columnMeta['DefaultValue'])
  1024. : '';
  1025. if ($GLOBALS['cfg']['CharEditing'] == 'textarea') {
  1026. $html .= '<textarea'
  1027. . ' name="field_default_value[' . $columnNumber . ']" cols="15"'
  1028. . ' class="textfield default_value">'
  1029. . $value
  1030. . '</textarea>';
  1031. } else {
  1032. $html .= '<input type="text"'
  1033. . ' name="field_default_value[' . $columnNumber . ']" size="12"'
  1034. . ' value="' . $value . '"'
  1035. . ' class="textfield default_value" />';
  1036. }
  1037. return $html;
  1038. }
  1039. /**
  1040. * Function to get html for column attributes
  1041. *
  1042. * @param int $columnNumber column number
  1043. * @param array $columnMeta column meta
  1044. * @param string $type_upper type upper
  1045. * @param int $length_values_input_size length values input size
  1046. * @param int $length length
  1047. * @param string $default_current_timestamp default current time stamp
  1048. * @param array $extracted_columnspec extracted column spec
  1049. * @param string $submit_attribute submit attribute
  1050. * @param array $analyzed_sql analyzed sql
  1051. * @param string $submit_default_current_timestamp submit default current time stamp
  1052. * @param array $comments_map comments map
  1053. * @param array $fields_meta fields map
  1054. * @param bool $is_backup is backup
  1055. * @param array $move_columns move columns
  1056. * @param array $cfgRelation configuration relation
  1057. * @param array $available_mime available mime
  1058. * @param array $mime_map mime map
  1059. *
  1060. * @return array
  1061. */
  1062. function PMA_getHtmlForColumnAttributes($columnNumber, $columnMeta, $type_upper,
  1063. $length_values_input_size, $length, $default_current_timestamp,
  1064. $extracted_columnspec, $submit_attribute, $analyzed_sql,
  1065. $submit_default_current_timestamp, $comments_map, $fields_meta, $is_backup,
  1066. $move_columns, $cfgRelation, $available_mime, $mime_map
  1067. ) {
  1068. // Cell index: If certain fields get left out, the counter shouldn't change.
  1069. $ci = 0;
  1070. // Everytime a cell shall be left out the STRG-jumping feature, $ci_offset
  1071. // has to be incremented ($ci_offset++)
  1072. $ci_offset = -1;
  1073. $content_cell = array();
  1074. // column name
  1075. $content_cell[$ci] = PMA_getHtmlForColumnName(
  1076. $columnNumber, $ci, $ci_offset, isset($columnMeta) ? $columnMeta : null
  1077. );
  1078. $ci++;
  1079. // column type
  1080. $content_cell[$ci] = PMA_getHtmlForColumnType(
  1081. $columnNumber, $ci, $ci_offset, $type_upper, isset($columnMeta) ? $columnMeta : null
  1082. );
  1083. $ci++;
  1084. // column length
  1085. $content_cell[$ci] = PMA_getHtmlForColumnLength(
  1086. $columnNumber, $ci, $ci_offset, $length_values_input_size, $length
  1087. );
  1088. $ci++;
  1089. // column default
  1090. $content_cell[$ci] = PMA_getHtmlForColumnDefault(
  1091. $columnNumber, $ci, $ci_offset,
  1092. isset($type_upper) ? $type_upper : null,
  1093. isset($default_current_timestamp) ? $default_current_timestamp : null,
  1094. isset($columnMeta) ? $columnMeta : null
  1095. );
  1096. $ci++;
  1097. // column collation
  1098. $content_cell[$ci] = PMA_getHtmlForColumnCollation(
  1099. $columnNumber, $ci, $ci_offset, $columnMeta
  1100. );
  1101. $ci++;
  1102. // column attribute
  1103. $content_cell[$ci] = PMA_getHtmlForColumnAttribute(
  1104. $columnNumber, $ci, $ci_offset,
  1105. isset($extracted_columnspec) ? $extracted_columnspec : null,
  1106. isset($columnMeta) ? $columnMeta : null,
  1107. isset($submit_attribute) ? $submit_attribute : null,
  1108. isset($analyzed_sql) ? $analyzed_sql : null,
  1109. isset($submit_default_current_timestamp)
  1110. ? $submit_default_current_timestamp : null
  1111. );
  1112. $ci++;
  1113. // column NULL
  1114. $content_cell[$ci] = PMA_getHtmlForColumnNull(
  1115. $columnNumber, $ci, $ci_offset, isset($columnMeta) ? $columnMeta : null
  1116. );
  1117. $ci++;
  1118. // column indexes
  1119. // See my other comment about this 'if'.
  1120. if (!$is_backup) {
  1121. $content_cell[$ci] = PMA_getHtmlForColumnIndexes(
  1122. $columnNumber, $ci, $ci_offset, $columnMeta
  1123. );
  1124. $ci++;
  1125. } // end if ($action ==...)
  1126. // column auto_increment
  1127. $content_cell[$ci] = PMA_getHtmlForColumnAutoIncrement(
  1128. $columnNumber, $ci, $ci_offset, $columnMeta
  1129. );
  1130. $ci++;
  1131. // column comments
  1132. $content_cell[$ci] = PMA_getHtmlForColumnComment(
  1133. $columnNumber, $ci, $ci_offset, isset($columnMeta) ? $columnMeta : null,
  1134. $comments_map
  1135. );
  1136. $ci++;
  1137. // move column
  1138. if (isset($fields_meta)) {
  1139. $content_cell[$ci] = PMA_getHtmlForMoveColumn(
  1140. $columnNumber, $ci, $ci_offset, $move_columns, $columnMeta
  1141. );
  1142. $ci++;
  1143. }
  1144. if ($cfgRelation['mimework']
  1145. && $GLOBALS['cfg']['BrowseMIME']
  1146. && $cfgRelation['commwork']
  1147. ) {
  1148. // Column Mime-type
  1149. $content_cell[$ci] = PMA_getHtmlForMimeType(
  1150. $columnNumber, $ci, $ci_offset, $available_mime, $columnMeta, $mime_map
  1151. );
  1152. $ci++;
  1153. // Column Browser transformation
  1154. $content_cell[$ci] = PMA_getHtmlForBrowserTransformation(
  1155. $columnNumber, $ci, $ci_offset, $available_mime, $columnMeta, $mime_map
  1156. );
  1157. $ci++;
  1158. // column Transformation options
  1159. $content_cell[$ci] = PMA_getHtmlForTransformationOption(
  1160. $columnNumber, $ci, $ci_offset, isset($columnMeta) ? $columnMeta : null,
  1161. isset($mime_map) ? $mime_map : null
  1162. );
  1163. }
  1164. return $content_cell;
  1165. }
  1166. /**
  1167. * Function to get form parameters for old column
  1168. *
  1169. * @param array $columnMeta column meta
  1170. * @param int $length length
  1171. * @param array $form_params form parameters
  1172. * @param int $columnNumber column/field number
  1173. * @param string $type type in lowercase without the length
  1174. * @param array $extracted_columnspec details about the column spec
  1175. *
  1176. * @return array
  1177. */
  1178. function PMA_getFormParamsForOldColumn(
  1179. $columnMeta, $length, $form_params, $columnNumber, $type,
  1180. $extracted_columnspec
  1181. ) {
  1182. // old column name
  1183. if (isset($columnMeta['Field'])) {
  1184. $form_params['field_orig[' . $columnNumber . ']']
  1185. = $columnMeta['Field'];
  1186. if (isset($columnMeta['column_status'])
  1187. && !$columnMeta['column_status']['isEditable']
  1188. ) {
  1189. $form_params['field_name[' . $columnNumber . ']']
  1190. = $columnMeta['Field'];
  1191. }
  1192. } else {
  1193. $form_params['field_orig[' . $columnNumber . ']'] = '';
  1194. }
  1195. // old column type
  1196. if (isset($columnMeta['Type'])) {
  1197. // keep in uppercase because the new type will be in uppercase
  1198. $form_params['field_type_orig[' . $columnNumber . ']']
  1199. = strtoupper($type);
  1200. if (isset($columnMeta['column_status'])
  1201. && !$columnMeta['column_status']['isEditable']
  1202. ) {
  1203. $form_params['field_type[' . $columnNumber . ']']
  1204. = strtoupper($type);
  1205. }
  1206. } else {
  1207. $form_params['field_type_orig[' . $columnNumber . ']'] = '';
  1208. }
  1209. // old column length
  1210. $form_params['field_length_orig[' . $columnNumber . ']'] = $length;
  1211. // old column default
  1212. $form_params['field_default_value_orig[' . $columnNumber . ']']
  1213. = (isset($columnMeta['Default']) ? $columnMeta['Default'] : '');
  1214. $form_params['field_default_type_orig[' . $columnNumber . ']']
  1215. = (isset($columnMeta['DefaultType']) ? $columnMeta['DefaultType'] : '');
  1216. // old column collation
  1217. if (isset($columnMeta['Collation'])) {
  1218. $form_params['field_collation_orig[' . $columnNumber . ']']
  1219. = $columnMeta['Collation'];
  1220. } else {
  1221. $form_params['field_collation_orig[' . $columnNumber . ']'] = '';
  1222. }
  1223. // old column attribute
  1224. if (isset($extracted_columnspec['attribute'])) {
  1225. $form_params['field_attribute_orig[' . $columnNumber . ']']
  1226. = trim($extracted_columnspec['attribute']);
  1227. } else {
  1228. $form_params['field_attribute_orig[' . $columnNumber . ']'] = '';
  1229. }
  1230. // old column null
  1231. if (isset($columnMeta['Null'])) {
  1232. $form_params['field_null_orig[' . $columnNumber . ']']
  1233. = $columnMeta['Null'];
  1234. } else {
  1235. $form_params['field_null_orig[' . $columnNumber . ']'] = '';
  1236. }
  1237. // old column extra (for auto_increment)
  1238. if (isset($columnMeta['Extra'])) {
  1239. $form_params['field_extra_orig[' . $columnNumber . ']']
  1240. = $columnMeta['Extra'];
  1241. } else {
  1242. $form_params['field_extra_orig[' . $columnNumber . ']'] = '';
  1243. }
  1244. // old column comment
  1245. if (isset($columnMeta['Comment'])) {
  1246. $form_params['field_comments_orig[' . $columnNumber . ']']
  1247. = $columnMeta['Comment'];
  1248. } else {
  1249. $form_params['field_comment_orig[' . $columnNumber . ']'] = '';
  1250. }
  1251. return $form_params;
  1252. }
  1253. ?>