Translated using Weblate (Bulgarian)
[phpmyadmin.git] / tbl_addfield.php
blob499cb21ef05ce092c911a487973585b473d19963
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Displays add field form and handles it
6 * @package PhpMyAdmin
7 */
9 /**
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');
19 // Check parameters
20 PMA_Util::checkParameters(array('db', 'table'));
23 /**
24 * Defines the url to return to in case of error in a sql statement
26 $err_url = 'tbl_sql.php?' . PMA_generate_common_url($db, $table);
28 /**
29 * The form used to define the field to add has been submitted
31 $abort = false;
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'];
42 $regenerate = true;
43 } elseif (isset($_REQUEST['num_fields']) && intval($_REQUEST['num_fields']) > 0) {
44 $num_fields = (int) $_REQUEST['num_fields'];
45 } else {
46 $num_fields = 1;
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';
55 // get column addition statements
56 $sql_statement = PMA_getColumnCreationStatements(false);
58 // To allow replication, we first select the db to use and then run queries
59 // on this db.
60 $GLOBALS['dbi']->selectDb($db)
61 or PMA_Util::mysqlDie(
62 $GLOBALS['dbi']->getError(), 'USE ' . PMA_Util::backquote($db), '', $err_url
64 $sql_query = 'ALTER TABLE ' .
65 PMA_Util::backquote($table) . ' ' . $sql_statement . ';';
66 $result = $GLOBALS['dbi']->tryQuery($sql_query);
68 if ($result === true) {
69 // If comments were sent, enable relation stuff
70 include_once 'libraries/transformations.lib.php';
72 // Update comment table for mime types [MIME]
73 if (isset($_REQUEST['field_mimetype'])
74 && is_array($_REQUEST['field_mimetype'])
75 && $cfg['BrowseMIME']
76 ) {
77 foreach ($_REQUEST['field_mimetype'] as $fieldindex => $mimetype) {
78 if (isset($_REQUEST['field_name'][$fieldindex])
79 && strlen($_REQUEST['field_name'][$fieldindex])
80 ) {
81 PMA_setMIME(
82 $db, $table,
83 $_REQUEST['field_name'][$fieldindex],
84 $mimetype,
85 $_REQUEST['field_transformation'][$fieldindex],
86 $_REQUEST['field_transformation_options'][$fieldindex]
92 // Go back to the structure sub-page
93 $message = PMA_Message::success(
94 __('Table %1$s has been altered successfully')
96 $message->addParam($table);
98 if ($GLOBALS['is_ajax_request'] == true) {
99 $response->addJSON('message', $message);
100 $response->addJSON(
101 'sql_query',
102 PMA_Util::getMessage(null, $sql_query)
104 exit;
107 $active_page = 'tbl_structure.php';
108 $abort = true;
109 include 'tbl_structure.php';
110 } else {
111 $error_message_html = PMA_Util::mysqlDie('', '', '', $err_url, false);
112 $response->addHTML($error_message_html);
113 if ($GLOBALS['is_ajax_request'] == true) {
114 exit;
116 // An error happened while inserting/updating a table definition.
117 // to prevent total loss of that data, we embed the form once again.
118 // The variable $regenerate will be used to restore data in libraries/
119 // tbl_columns_definition_form.inc.php
120 $num_fields = $_REQUEST['orig_num_fields'];
121 if (isset($_REQUEST['orig_after_field'])) {
122 $_REQUEST['after_field'] = $_REQUEST['orig_after_field'];
124 if (isset($_REQUEST['orig_field_where'])) {
125 $_REQUEST['field_where'] = $_REQUEST['orig_field_where'];
127 $regenerate = true;
129 } // end do alter table
132 * Displays the form used to define the new field
134 if ($abort == false) {
136 * Gets tables informations
138 include_once 'libraries/tbl_common.inc.php';
139 include_once 'libraries/tbl_info.inc.php';
141 $active_page = 'tbl_structure.php';
143 * Display the form
145 $action = 'tbl_addfield.php';
146 include_once 'libraries/tbl_columns_definition_form.inc.php';