devilbox/.devilbox/www/htdocs/vendor/phpmyadmin-4.9.3/tbl_addfield.php

134 lines
3.7 KiB
PHP
Raw Normal View History

2016-10-22 14:57:10 +00:00
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Displays add field form and handles it
*
* @package PhpMyAdmin
*/
2018-04-14 09:18:00 +00:00
use PhpMyAdmin\CreateAddField;
use PhpMyAdmin\Message;
use PhpMyAdmin\Response;
use PhpMyAdmin\Transformations;
use PhpMyAdmin\Url;
use PhpMyAdmin\Util;
2016-10-22 14:57:10 +00:00
/**
* Get some core libraries
*/
require_once 'libraries/common.inc.php';
$response = Response::getInstance();
2016-10-22 14:57:10 +00:00
$header = $response->getHeader();
$scripts = $header->getScripts();
$scripts->addFile('tbl_structure.js');
// Check parameters
2018-04-14 09:18:00 +00:00
Util::checkParameters(array('db', 'table'));
2016-10-22 14:57:10 +00:00
/**
* Defines the url to return to in case of error in a sql statement
*/
2018-04-14 09:18:00 +00:00
$err_url = 'tbl_sql.php' . Url::getCommon(
2016-10-22 14:57:10 +00:00
array(
'db' => $db, 'table' => $table
)
);
/**
* The form used to define the field to add has been submitted
*/
$abort = false;
// check number of fields to be created
2018-12-16 14:31:03 +00:00
if (isset($_POST['submit_num_fields'])) {
if (isset($_POST['orig_after_field'])) {
$_POST['after_field'] = $_POST['orig_after_field'];
2016-10-22 14:57:10 +00:00
}
2018-12-16 14:31:03 +00:00
if (isset($_POST['orig_field_where'])) {
$_POST['field_where'] = $_POST['orig_field_where'];
2016-10-22 14:57:10 +00:00
}
$num_fields = min(
2018-12-16 14:31:03 +00:00
intval($_POST['orig_num_fields']) + intval($_POST['added_fields']),
2016-10-22 14:57:10 +00:00
4096
);
$regenerate = true;
2018-12-16 14:31:03 +00:00
} elseif (isset($_POST['num_fields']) && intval($_POST['num_fields']) > 0) {
$num_fields = min(4096, intval($_POST['num_fields']));
2016-10-22 14:57:10 +00:00
} else {
$num_fields = 1;
}
2018-12-16 14:31:03 +00:00
if (isset($_POST['do_save_data'])) {
2016-10-22 14:57:10 +00:00
//avoid an incorrect calling of PMA_updateColumns() via
//tbl_structure.php below
2018-12-16 14:31:03 +00:00
unset($_POST['do_save_data']);
2016-10-22 14:57:10 +00:00
2018-04-14 09:18:00 +00:00
$createAddField = new CreateAddField($GLOBALS['dbi']);
2016-10-22 14:57:10 +00:00
2018-04-14 09:18:00 +00:00
list($result, $sql_query) = $createAddField->tryColumnCreationQuery($db, $table, $err_url);
2016-10-22 14:57:10 +00:00
if ($result === true) {
// Update comment table for mime types [MIME]
2018-12-16 14:31:03 +00:00
if (isset($_POST['field_mimetype'])
&& is_array($_POST['field_mimetype'])
2016-10-22 14:57:10 +00:00
&& $cfg['BrowseMIME']
) {
2018-12-16 14:31:03 +00:00
foreach ($_POST['field_mimetype'] as $fieldindex => $mimetype) {
if (isset($_POST['field_name'][$fieldindex])
&& strlen($_POST['field_name'][$fieldindex]) > 0
2016-10-22 14:57:10 +00:00
) {
2018-04-14 09:18:00 +00:00
Transformations::setMIME(
2016-10-22 14:57:10 +00:00
$db, $table,
2018-12-16 14:31:03 +00:00
$_POST['field_name'][$fieldindex],
2016-10-22 14:57:10 +00:00
$mimetype,
2018-12-16 14:31:03 +00:00
$_POST['field_transformation'][$fieldindex],
$_POST['field_transformation_options'][$fieldindex],
$_POST['field_input_transformation'][$fieldindex],
$_POST['field_input_transformation_options'][$fieldindex]
2016-10-22 14:57:10 +00:00
);
}
}
}
// Go back to the structure sub-page
2018-04-14 09:18:00 +00:00
$message = Message::success(
2016-10-22 14:57:10 +00:00
__('Table %1$s has been altered successfully.')
);
$message->addParam($table);
$response->addJSON(
'message',
2018-04-14 09:18:00 +00:00
Util::getMessage($message, $sql_query, 'success')
2016-10-22 14:57:10 +00:00
);
exit;
} else {
2018-04-14 09:18:00 +00:00
$error_message_html = Util::mysqlDie(
2016-10-22 14:57:10 +00:00
'',
'',
false,
$err_url,
false
);
$response->addHTML($error_message_html);
$response->setRequestStatus(false);
exit;
}
} // end do alter table
/**
* Displays the form used to define the new field
*/
if ($abort == false) {
/**
* Gets tables information
*/
include_once 'libraries/tbl_common.inc.php';
$active_page = 'tbl_structure.php';
/**
* Display the form
*/
$action = 'tbl_addfield.php';
include_once 'libraries/tbl_columns_definition_form.inc.php';
}