2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Displays add field form and handles it
10 * Get some core libraries
12 require_once 'libraries/common.inc.php';
14 $response = PMA_Response
::getInstance();
15 $header = $response->getHeader();
16 $scripts = $header->getScripts();
17 $scripts->addFile('tbl_structure.js');
20 PMA_Util
::checkParameters(array('db', 'table'));
24 * Defines the url to return to in case of error in a sql statement
26 $err_url = 'tbl_sql.php?' . PMA_URL_getCommon($db, $table);
29 * The form used to define the field to add has been submitted
33 // check number of fields to be created
34 if (isset($_REQUEST['submit_num_fields'])) {
35 if (isset($_REQUEST['orig_after_field'])) {
36 $_REQUEST['after_field'] = $_REQUEST['orig_after_field'];
38 if (isset($_REQUEST['orig_field_where'])) {
39 $_REQUEST['field_where'] = $_REQUEST['orig_field_where'];
41 $num_fields = $_REQUEST['orig_num_fields'] +
$_REQUEST['added_fields'];
43 } elseif (isset($_REQUEST['num_fields']) && intval($_REQUEST['num_fields']) > 0) {
44 $num_fields = (int) $_REQUEST['num_fields'];
49 if (isset($_REQUEST['do_save_data'])) {
50 //avoid an incorrect calling of PMA_updateColumns() via
51 //tbl_structure.php below
52 unset($_REQUEST['do_save_data']);
54 include_once 'libraries/create_addfield.lib.php';
56 list($result, $sql_query) = PMA_tryColumnCreationQuery($db, $table, $err_url);
58 if ($result === true) {
59 // If comments were sent, enable relation stuff
60 include_once 'libraries/transformations.lib.php';
62 // Update comment table for mime types [MIME]
63 if (isset($_REQUEST['field_mimetype'])
64 && is_array($_REQUEST['field_mimetype'])
67 foreach ($_REQUEST['field_mimetype'] as $fieldindex => $mimetype) {
68 if (isset($_REQUEST['field_name'][$fieldindex])
69 && strlen($_REQUEST['field_name'][$fieldindex])
73 $_REQUEST['field_name'][$fieldindex],
75 $_REQUEST['field_transformation'][$fieldindex],
76 $_REQUEST['field_transformation_options'][$fieldindex]
82 // Go back to the structure sub-page
83 $message = PMA_Message
::success(
84 __('Table %1$s has been altered successfully')
86 $message->addParam($table);
87 $response->addJSON('message', $message);
90 PMA_Util
::getMessage(null, $sql_query)
94 $error_message_html = PMA_Util
::mysqlDie('', '', '', $err_url, false);
95 $response->addHTML($error_message_html);
98 } // end do alter table
101 * Displays the form used to define the new field
103 if ($abort == false) {
105 * Gets tables informations
107 include_once 'libraries/tbl_common.inc.php';
108 include_once 'libraries/tbl_info.inc.php';
110 $active_page = 'tbl_structure.php';
114 $action = 'tbl_addfield.php';
115 include_once 'libraries/tbl_columns_definition_form.inc.php';