Fix for issue #291
[openemr.git] / phpmyadmin / tbl_addfield.php
blob9bdc8bd3472bfcf852b5843adec4d42a390b4dcc
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_URL_getCommon(
27 array(
28 'db' => $db, 'table' => $table
32 /**
33 * The form used to define the field to add has been submitted
35 $abort = false;
37 // check number of fields to be created
38 if (isset($_REQUEST['submit_num_fields'])) {
39 if (isset($_REQUEST['orig_after_field'])) {
40 $_REQUEST['after_field'] = $_REQUEST['orig_after_field'];
42 if (isset($_REQUEST['orig_field_where'])) {
43 $_REQUEST['field_where'] = $_REQUEST['orig_field_where'];
45 $num_fields = $_REQUEST['orig_num_fields'] + $_REQUEST['added_fields'];
46 $regenerate = true;
47 } elseif (isset($_REQUEST['num_fields']) && intval($_REQUEST['num_fields']) > 0) {
48 $num_fields = (int) $_REQUEST['num_fields'];
49 } else {
50 $num_fields = 1;
53 if (isset($_REQUEST['do_save_data'])) {
54 //avoid an incorrect calling of PMA_updateColumns() via
55 //tbl_structure.php below
56 unset($_REQUEST['do_save_data']);
58 include_once 'libraries/create_addfield.lib.php';
60 list($result, $sql_query) = PMA_tryColumnCreationQuery($db, $table, $err_url);
62 if ($result === true) {
63 // If comments were sent, enable relation stuff
64 include_once 'libraries/transformations.lib.php';
66 // Update comment table for mime types [MIME]
67 if (isset($_REQUEST['field_mimetype'])
68 && is_array($_REQUEST['field_mimetype'])
69 && $cfg['BrowseMIME']
70 ) {
71 /** @var PMA_String $pmaString */
72 $pmaString = $GLOBALS['PMA_String'];
73 foreach ($_REQUEST['field_mimetype'] as $fieldindex => $mimetype) {
74 if (isset($_REQUEST['field_name'][$fieldindex])
75 && /*overload*/mb_strlen($_REQUEST['field_name'][$fieldindex])
76 ) {
77 PMA_setMIME(
78 $db, $table,
79 $_REQUEST['field_name'][$fieldindex],
80 $mimetype,
81 $_REQUEST['field_transformation'][$fieldindex],
82 $_REQUEST['field_transformation_options'][$fieldindex],
83 $_REQUEST['field_input_transformation'][$fieldindex],
84 $_REQUEST['field_input_transformation_options'][$fieldindex]
90 // Go back to the structure sub-page
91 $message = PMA_Message::success(
92 __('Table %1$s has been altered successfully.')
94 $message->addParam($table);
95 $response->addJSON(
96 'message', PMA_Util::getMessage($message, $sql_query, 'success')
98 exit;
99 } else {
100 $error_message_html = PMA_Util::mysqlDie('', '', false, $err_url, false);
101 $response->addHTML($error_message_html);
102 $response->isSuccess(false);
103 exit;
105 } // end do alter table
108 * Displays the form used to define the new field
110 if ($abort == false) {
112 * Gets tables information
114 include_once 'libraries/tbl_common.inc.php';
115 include_once 'libraries/tbl_info.inc.php';
117 $active_page = 'tbl_structure.php';
119 * Display the form
121 $action = 'tbl_addfield.php';
122 include_once 'libraries/tbl_columns_definition_form.inc.php';