Merge pull request #1233 from smita786/gsoc_central_columns_list
add user defined column to central list
This commit is contained in:
commit
ebd19293c6
@ -10,22 +10,32 @@
|
||||
* Gets some core libraries
|
||||
*/
|
||||
require_once 'libraries/common.inc.php';
|
||||
require_once 'libraries/tbl_columns_definition_form.lib.php';
|
||||
require_once 'libraries/central_columns.lib.php';
|
||||
|
||||
if (isset($_POST['edit_save'])) {
|
||||
if (isset($_POST['edit_save']) || isset($_POST['add_new_column'])) {
|
||||
$col_name = $_POST['col_name'];
|
||||
$orig_col_name = $_POST['orig_col_name'];
|
||||
if (isset($_POST['edit_save'])) {
|
||||
$orig_col_name = $_POST['orig_col_name'];
|
||||
}
|
||||
$col_default = $_POST['col_default'];
|
||||
$col_extra = $_POST['col_extra'];
|
||||
$col_isNull = isset($_POST['col_isNull'])?1:0;
|
||||
$col_length = $_POST['col_length'];
|
||||
$col_type = $_POST['col_type'];
|
||||
$collation = $_POST['collation'];
|
||||
echo PMA_updateOneColumn(
|
||||
$db, $orig_col_name, $col_name, $col_type,
|
||||
$col_length, $col_isNull, $collation, $col_extra, $col_default
|
||||
);
|
||||
exit;
|
||||
if (isset($orig_col_name) && $orig_col_name) {
|
||||
echo PMA_updateOneColumn(
|
||||
$db, $orig_col_name, $col_name, $col_type,
|
||||
$col_length, $col_isNull, $collation, $col_extra, $col_default
|
||||
);
|
||||
exit;
|
||||
} else {
|
||||
$tmp_msg = PMA_updateOneColumn(
|
||||
$db, "", $col_name, $col_type,
|
||||
$col_length, $col_isNull, $collation, $col_extra, $col_default
|
||||
);
|
||||
}
|
||||
}
|
||||
if (isset($_POST['populateColumns'])) {
|
||||
$selected_tbl = $_POST['selectedTable'];
|
||||
@ -60,18 +70,21 @@ if (isset($_POST['delete_save'])) {
|
||||
if (isset($_REQUEST['total_rows']) && $_REQUEST['total_rows']) {
|
||||
$total_rows = $_REQUEST['total_rows'];
|
||||
} else {
|
||||
$result = PMA_getColumnsList($db, 0, 0);
|
||||
$total_rows = count($result);
|
||||
$total_rows = PMA_getCentralColumnsCount($db);
|
||||
}
|
||||
if (isset($_REQUEST['pos'])) {
|
||||
$pos = $_REQUEST['pos'];
|
||||
} else {
|
||||
$pos = 0;
|
||||
}
|
||||
$addNewColumn = PMA_getHTMLforAddNewColumn($db);
|
||||
$response->addHTML($addNewColumn);
|
||||
if ($total_rows <= 0) {
|
||||
$response->addHTML(
|
||||
'<fieldset>There are no columns in central list to display for the '
|
||||
. 'current database.</fieldset>'
|
||||
'<fieldset>' . __(
|
||||
'There are no columns in central list to display for the current '
|
||||
. 'database.'
|
||||
) . '</fieldset>'
|
||||
);
|
||||
$columnAdd = PMA_getHTMLforAddCentralColumn($total_rows, $pos, $db);
|
||||
$response->addHTML($columnAdd);
|
||||
@ -93,7 +106,9 @@ $table_struct = '<div id="tableslistcontainer">'
|
||||
. '<table id="table_columns" class="tablesorter" '
|
||||
. 'style="min-width:100%" class="data">';
|
||||
$response->addHTML($table_struct);
|
||||
$tableheader = PMA_getCentralColumnsTableHeader();
|
||||
$tableheader = PMA_getCentralColumnsTableHeader(
|
||||
'column_heading', __('Click to sort'), 2
|
||||
);
|
||||
$response->addHTML($tableheader);
|
||||
$result = PMA_getColumnsList($db, $pos, $max_rows);
|
||||
$odd_row = false;
|
||||
@ -110,7 +125,7 @@ $response->addHTML('</table></div>');
|
||||
$message = PMA_Message::success(
|
||||
sprintf(__('Showing row(s) %1$s - %2$s'), ($pos + 1), ($pos + count($result)))
|
||||
);
|
||||
if (isset($tmp_msg) && $tmp_msg != true) {
|
||||
$message->addMessage($tmp_msg);
|
||||
if (isset($tmp_msg) && $tmp_msg !== true) {
|
||||
$message = $tmp_msg;
|
||||
}
|
||||
?>
|
||||
|
||||
@ -25,13 +25,27 @@ AJAX.registerTeardown('db_central_columns.js', function () {
|
||||
$('.column_heading').unbind('hover');
|
||||
$('#table-select').unbind('change');
|
||||
$('#column-select').unbind('change');
|
||||
$("#add_col_div>a").unbind('click');
|
||||
$('#add_new').unbind('submit');
|
||||
$("select.default_type").unbind('change');
|
||||
});
|
||||
|
||||
AJAX.registerOnload('db_central_columns.js', function () {
|
||||
$('#tableslistcontainer input,#tableslistcontainer select').hide();
|
||||
$('#tableslistcontainer input,#tableslistcontainer select,.default_value,.open_enum_editor').hide();
|
||||
if ($('#table_columns tbody tr').length > 0) {
|
||||
$("#table_columns").tablesorter();
|
||||
}
|
||||
$('#add_new td').each(function(){
|
||||
if ($(this).attr('name') !== 'undefined') {
|
||||
$(this).find('input,select:first').attr('name', $(this).attr('name'));
|
||||
}
|
||||
});
|
||||
$("#add_new #field_0_0").attr('required','required');
|
||||
$('#add_new input[type="text"], #add_new input[type="number"], #add_new select')
|
||||
.css({
|
||||
'width' : '10em',
|
||||
'-moz-box-sizing' : 'border-box'
|
||||
});
|
||||
$('.column_heading').hover(function(){
|
||||
$(this).css("cursor","move");
|
||||
PMA_tooltip(
|
||||
@ -40,6 +54,7 @@ AJAX.registerOnload('db_central_columns.js', function () {
|
||||
PMA_messages.strSortHint
|
||||
);
|
||||
});
|
||||
window.scrollTo(0, 0);
|
||||
$(".filter_rows").live("keyup", function () {
|
||||
var cols = ["Name", "Type", "Length/Values", "Collation", "Null", "Extra", "Default"];
|
||||
$.uiTableFilter($("#table_columns"), $(this).val(), cols, null, "td span");
|
||||
@ -49,13 +64,18 @@ AJAX.registerOnload('db_central_columns.js', function () {
|
||||
$('#save_'+rownum).show();
|
||||
$(this).hide();
|
||||
$('#f_'+rownum+' td span').hide();
|
||||
$('#f_'+rownum +' input, #f_'+rownum+' select').show();
|
||||
$('#f_'+rownum +' input, #f_'+rownum+' select, #f_'+rownum+' .open_enum_editor').show();
|
||||
var extra_val = $('#f_'+rownum +' td[name=col_extra] span').html();
|
||||
$('#f_'+rownum+' select[name=col_extra] option[value="'+extra_val+'"]').attr("selected","selected");
|
||||
if($('#f_'+rownum+' .default_type').val() === 'USER_DEFINED') {
|
||||
$('#f_'+rownum+' .default_type').siblings('.default_value').show();
|
||||
} else {
|
||||
$('#f_'+rownum+' .default_type').siblings('.default_value').hide();
|
||||
}
|
||||
});
|
||||
$(".del_row").click(function() {
|
||||
//alert('del')
|
||||
rownum = $(this).data('rownum');
|
||||
//alert($('#f_'+rownum +' input[name=col_name]').val());
|
||||
$("#del_col_name").val($('#f_'+rownum +' input[name=col_name]').val());
|
||||
$("#del_col_name").val($('#f_'+rownum +' td[name=col_name] span').html());
|
||||
$("#del_form").submit();
|
||||
});
|
||||
$('.edit_cancel_form').click(function(event) {
|
||||
@ -65,13 +85,24 @@ AJAX.registerOnload('db_central_columns.js', function () {
|
||||
$('#save_'+rownum).hide();
|
||||
$('#edit_'+rownum).show();
|
||||
$('#f_'+rownum+' td span').show();
|
||||
$('#f_'+rownum +' input, #f_'+rownum+' select').hide();
|
||||
$('#f_'+rownum +' input, #f_'+rownum+' select,#f_'+rownum+' .default_value, #f_'+rownum+' .open_enum_editor').hide();
|
||||
});
|
||||
$('.edit_save_form').click(function(event) {
|
||||
//alert(1);
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
rownum = $(this).data('rownum');
|
||||
$('#f_'+rownum+' td').each(function() {
|
||||
if ($(this).attr('name') !== 'undefined') {
|
||||
$(this).find(':input[type!="hidden"],select:first')
|
||||
.attr('name', $(this).attr('name'));
|
||||
}
|
||||
});
|
||||
if($('#f_'+rownum+' .default_type').val() === 'USER_DEFINED') {
|
||||
$('#f_'+rownum+' .default_type').attr('name','col_default_sel');
|
||||
} else {
|
||||
$('#f_'+rownum+' .default_value').attr('name','col_default_val');
|
||||
}
|
||||
// alert(rownum);
|
||||
var datastring = $('#f_'+rownum+' :input').serialize();
|
||||
//console.log(datastring);
|
||||
@ -94,14 +125,13 @@ AJAX.registerOnload('db_central_columns.js', function () {
|
||||
$('#f_'+rownum +' td[name=col_length] span').text($('#f_'+rownum +' input[name=col_length]').val()).html();
|
||||
$('#f_'+rownum +' td[name=collation] span').text($('#f_'+rownum +' select[name=collation]').val()).html();
|
||||
$('#f_'+rownum +' td[name=col_isNull] span').text($('#f_'+rownum +' input[name=col_isNull]').val()).html();
|
||||
$('#f_'+rownum +' td[name=col_extra] span').text($('#f_'+rownum +' input[name=col_extra]').val()).html();
|
||||
$('#f_'+rownum +' td[name=col_default] span').text($('#f_'+rownum +' input[name=col_default]').val()).html();
|
||||
$('#f_'+rownum +' td[name=col_extra] span').text($('#f_'+rownum +' select[name=col_extra]').val()).html();
|
||||
$('#f_'+rownum +' td[name=col_default] span').text($('#f_'+rownum +' :input[name=col_default]').val()).html();
|
||||
}
|
||||
|
||||
$('#save_'+rownum).hide();
|
||||
$('#edit_'+rownum).show();
|
||||
$('#f_'+rownum+' td span').show();
|
||||
$('#f_'+rownum +' input, #f_'+rownum+' select').hide();
|
||||
$('#f_'+rownum +' input, #f_'+rownum+' select,#f_'+rownum+' .default_value, #f_'+rownum+' .open_enum_editor').hide();
|
||||
},
|
||||
error: function() {
|
||||
PMA_ajaxShowMessage(
|
||||
@ -138,4 +168,24 @@ AJAX.registerOnload('db_central_columns.js', function () {
|
||||
$("#add_column").submit();
|
||||
}
|
||||
});
|
||||
$("#add_col_div>a").click(function(event){
|
||||
$('#add_new').slideToggle("slow");
|
||||
if($("#add_col_div>a span").html() === '+') {
|
||||
$("#add_col_div>a span").html('-');
|
||||
} else {
|
||||
$("#add_col_div>a span").html('+');
|
||||
}
|
||||
});
|
||||
$('#add_new').submit(function(event){
|
||||
$('#add_new').toggle();
|
||||
});
|
||||
$("select.default_type").change(function () {
|
||||
if ($(this).val() === 'USER_DEFINED') {
|
||||
$(this).siblings('.default_value').attr('name','col_default');
|
||||
$(this).attr('name','col_default_sel');
|
||||
} else {
|
||||
$(this).attr('name','col_default');
|
||||
$(this).siblings('.default_value').attr('name','col_default_val');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@ -73,17 +73,28 @@ function PMA_getColumnsList($db, $from=0, $num=25)
|
||||
return $has_list;
|
||||
}
|
||||
|
||||
/* to do block, need to complete
|
||||
/**
|
||||
* get the number of columns present in central list for given db
|
||||
*
|
||||
* @param string $db current database
|
||||
*
|
||||
* @return int number of columns in central list of columns for $db
|
||||
*/
|
||||
function PMA_getCentralColumnsCount($db)
|
||||
{
|
||||
$pmadb = $GLOBALS['cfg']['Server']['pmadb'];
|
||||
$cfgCentralColumns = PMA_centralColumnsGetParams();
|
||||
if (empty($cfgCentralColumns)) {
|
||||
return 0;
|
||||
}
|
||||
$pmadb = $cfgCentralColumns['db'];
|
||||
$GLOBALS['dbi']->selectDb($pmadb);
|
||||
$central_list_table = $GLOBALS['cfg']['Server']['central_columns'];
|
||||
$central_list_table = $cfgCentralColumns['table'];
|
||||
$query = 'SELECT count(db_name) FROM ' .
|
||||
* PMA_Util::backquote($central_list_table) . ' '
|
||||
PMA_Util::backquote($central_list_table) . ' '
|
||||
. 'WHERE db_name = \'' . $db . '\';';
|
||||
return $GLOBALS['dbi']->fetchResult($query);
|
||||
}*/
|
||||
$res = $GLOBALS['dbi']->fetchResult($query);
|
||||
return $res[0];
|
||||
}
|
||||
/**
|
||||
* return the existing columns in central list among the given list of columns
|
||||
*
|
||||
@ -489,6 +500,18 @@ function PMA_updateOneColumn($db, $orig_col_name, $col_name, $col_type,
|
||||
}
|
||||
$centralTable = $cfgCentralColumns['table'];
|
||||
$GLOBALS['dbi']->selectDb($cfgCentralColumns['db'], $GLOBALS['controllink']);
|
||||
if ($orig_col_name == "") {
|
||||
$def = array();
|
||||
$def['Type'] = $col_type;
|
||||
if ($col_length) {
|
||||
$def['Type'] .= '(' . $col_length . ')';
|
||||
}
|
||||
$def['Collation'] = $collation;
|
||||
$def['Null'] = $col_isNull?__('YES'):__('NO');
|
||||
$def['Extra'] = $col_extra;
|
||||
$def['Default'] = $col_default;
|
||||
$query = PMA_getInsertQuery($col_name, $def, $db, $centralTable);
|
||||
} else {
|
||||
$query = 'UPDATE ' . PMA_Util::backquote($centralTable)
|
||||
. ' SET col_type = \'' . PMA_Util::sqlAddSlashes($col_type) . '\''
|
||||
. ',col_name = \'' . PMA_Util::sqlAddSlashes($col_name) . '\''
|
||||
@ -500,6 +523,7 @@ function PMA_updateOneColumn($db, $orig_col_name, $col_name, $col_type,
|
||||
. ' WHERE db_name = \'' . PMA_Util::sqlAddSlashes($db) . '\' '
|
||||
. 'AND col_name = \'' . PMA_Util::sqlAddSlashes($orig_col_name)
|
||||
. '\'';
|
||||
}
|
||||
if (!$GLOBALS['dbi']->tryQuery($query, $GLOBALS['controllink'])) {
|
||||
return PMA_Message::error(
|
||||
$GLOBALS['dbi']->getError($GLOBALS['controllink'])
|
||||
@ -522,7 +546,7 @@ function PMA_getHTMLforTableNavigation($total_rows, $pos, $db)
|
||||
$max_rows = $GLOBALS['cfg']['MaxRows'];
|
||||
$pageNow = ($pos / $max_rows) + 1;
|
||||
$nbTotalPage = ceil($total_rows / $max_rows);
|
||||
$table_navigation_html = '<table style="display:inline-block" '
|
||||
$table_navigation_html = '<table style="display:inline-block;max-width:49%" '
|
||||
. 'class="navigation nospacing nopadding">'
|
||||
. '<tr>'
|
||||
. '<td class="navigation_separator"></td>';
|
||||
@ -586,27 +610,35 @@ function PMA_getHTMLforTableNavigation($total_rows, $pos, $db)
|
||||
/**
|
||||
* function generate and return the table header for central columns page
|
||||
*
|
||||
* @param string $class styling class of 'th' elements
|
||||
* @param string $title title of the 'th' elements
|
||||
* @param integer $actionCount number of actions
|
||||
*
|
||||
* @return html for table header in central columns view/edit page
|
||||
*/
|
||||
function PMA_getCentralColumnsTableHeader()
|
||||
function PMA_getCentralColumnsTableHeader($class='', $title='', $actionCount=0)
|
||||
{
|
||||
$action = '';
|
||||
if ($actionCount > 0) {
|
||||
$action .= '<th colspan="' . $actionCount . '">' . __('Action') . '</th>';
|
||||
}
|
||||
$tableheader = '<thead>';
|
||||
$tableheader .= '<tr>'
|
||||
. '<th colspan="2">' . __('Action') . '</th>'
|
||||
. $action
|
||||
. '<th class="" style="display:none"></th>'
|
||||
. '<th class="column_heading" title="Click to sort" data-column="name">'
|
||||
. '<th class="' . $class . '" title="' . $title . '" data-column="name">'
|
||||
. __('Name') . '</th>'
|
||||
. '<th class="column_heading" title="Click to sort" data-column="type">'
|
||||
. '<th class="' . $class . '" title="' . $title . '" data-column="type">'
|
||||
. __('Type') . '</th>'
|
||||
. '<th class="column_heading" title="Click to sort" data-column="length">'
|
||||
. '<th class="' . $class . '" title="' . $title . '" data-column="length">'
|
||||
. __('Length/Values') . '</th>'
|
||||
. '<th class="column_heading" title="Click to sort" data-column="collation">'
|
||||
. __('Collation') . '</th>'
|
||||
. '<th class="column_heading" title="Click to sort" data-column="isnull">'
|
||||
. '<th class="' . $class . '" title="' . $title . '" data-column="collation"'
|
||||
. '>' . __('Collation') . '</th>'
|
||||
. '<th class="' . $class . '" title="' . $title . '" data-column="isnull">'
|
||||
. __('Null') . '</th>'
|
||||
. '<th class="column_heading" title="Click to sort" data-column="extra">'
|
||||
. '<th class="' . $class . '" title="' . $title . '" data-column="extra">'
|
||||
. __('Extra') . '</th>'
|
||||
. '<th class="column_heading" title="Click to sort" data-column="default">'
|
||||
. '<th class="' . $class . '" title="' . $title . '" data-column="default">'
|
||||
. __('Default') . '</th>'
|
||||
. '</tr>';
|
||||
$tableheader .= '</thead>';
|
||||
@ -673,7 +705,7 @@ function PMA_getHTMLforColumnDropdown($db, $selected_tbl)
|
||||
*/
|
||||
function PMA_getHTMLforAddCentralColumn($total_rows, $pos, $db)
|
||||
{
|
||||
$columnAdd = '<table style="display:inline-block;margin-left:2%;width:50%" '
|
||||
$columnAdd = '<table style="display:inline-block;margin-left:1%;max-width:50%" '
|
||||
. 'class="navigation nospacing nopadding">'
|
||||
. '<tr>'
|
||||
. '<td class="navigation_separator"></td>'
|
||||
@ -736,50 +768,67 @@ function PMA_getHTMLforCentralColumnsTableRow($row, $odd_row, $row_num, $db)
|
||||
. '<span>' . htmlspecialchars($row['col_name']) . '</span>'
|
||||
. '<input name="orig_col_name" type="hidden" '
|
||||
. 'value="' . htmlspecialchars($row['col_name']) . '">'
|
||||
. '<input class="edit_box" name="col_name" type="text" '
|
||||
. 'value="' . htmlspecialchars($row['col_name']) . '"></td>';
|
||||
. PMA_getHtmlForColumnName(
|
||||
$row_num, 0, 0, array('Field'=>$row['col_name']),
|
||||
array('central_columnswork'=>false)
|
||||
)
|
||||
. '</td>';
|
||||
$tableHtml .=
|
||||
'<td name = "col_type" class="nowrap"><span>'
|
||||
. htmlspecialchars($row['col_type']) . '</span>'
|
||||
. '<select name="col_type">' .
|
||||
PMA_Util::getSupportedDatatypes(true, strtoupper($row['col_type']))
|
||||
. '</select></td>';
|
||||
. PMA_getHtmlForColumnType(
|
||||
$row_num, 1, 0, strtoupper($row['col_type']), array()
|
||||
)
|
||||
. '</td>';
|
||||
$tableHtml .=
|
||||
'<td class="nowrap" name="col_length">'
|
||||
. '<span>' . ($row['col_length']?htmlspecialchars($row['col_length']):"")
|
||||
. '</span>'
|
||||
. '<input class="edit_box" type="number" name="col_length" '
|
||||
. 'value="' . ($row['col_length']?htmlspecialchars($row['col_length']):"")
|
||||
. '">'
|
||||
. PMA_getHtmlForColumnLength($row_num, 2, 0, 8, $row['col_length'])
|
||||
. '</td>';
|
||||
|
||||
$tableHtml .=
|
||||
'<td name="collation" class="nowrap">'
|
||||
. '<span>' . htmlspecialchars($row['col_collation']) . '</span>'
|
||||
. PMA_generateCharsetDropdownBox(
|
||||
PMA_CSDROPDOWN_COLLATION, null,
|
||||
null, $row['col_collation']
|
||||
. PMA_getHtmlForColumnCollation(
|
||||
$row_num, 3, 0, array('Collation'=>$row['col_collation'])
|
||||
)
|
||||
. '</td>';
|
||||
$tableHtml .=
|
||||
'<td class="nowrap" name="col_isNull">'
|
||||
. '<span>' . ($row['col_isNull'] ? __('Yes') : __('No'))
|
||||
. '</span><input type="checkbox" name="col_isNull" '
|
||||
. '' . ($row['col_isNull'] ?"checked" : "") . '/>'
|
||||
. '</span>'
|
||||
. PMA_getHtmlForColumnNull($row_num, 4, 0, array('Null'=>$row['col_isNull']))
|
||||
. '</td>';
|
||||
|
||||
$tableHtml .=
|
||||
'<td class="nowrap" name="col_extra"><span>'
|
||||
. htmlspecialchars($row['col_extra']) . '</span>'
|
||||
. '<input type="text" name="col_extra" value="'
|
||||
. htmlspecialchars($row['col_extra']) . '"/>'
|
||||
. '<select name="col_extra"><option value=""></option>'
|
||||
. '<option value="auto_increment">' . __('auto_increment') . '</option>'
|
||||
. '<option value="on update CURRENT_TIMESTAMP">'
|
||||
. __('on update CURRENT_TIMESTAMP') . '</option></select>'
|
||||
. '</td>';
|
||||
|
||||
$meta = array();
|
||||
if (!isset($row['col_default']) || $row['col_default'] == '') {
|
||||
$meta['DefaultType'] = 'NONE';
|
||||
} else {
|
||||
if ($row['col_default'] == 'CURRENT_TIMESTAMP'
|
||||
|| $row['col_default'] == 'NULL'
|
||||
) {
|
||||
$meta['DefaultType'] = $row['col_default'];
|
||||
} else {
|
||||
$meta['DefaultType'] = 'USER_DEFINED';
|
||||
$meta['DefaultValue'] = $row['col_default'];
|
||||
}
|
||||
}
|
||||
$tableHtml .=
|
||||
'<td class="nowrap" name="col_default"><span>' . (isset($row['col_default'])
|
||||
? htmlspecialchars($row['col_default']) : 'None')
|
||||
. '</span><input type="text" name="col_default" '
|
||||
. 'value="' . htmlspecialchars($row['col_default']) . '"/>'
|
||||
. '</span>'
|
||||
. PMA_getHtmlForColumnDefault(
|
||||
$row_num, 5, 0, strtoupper($row['col_type']), '', $meta
|
||||
)
|
||||
. '</td>';
|
||||
$tableHtml .= '</tr>';
|
||||
return $tableHtml;
|
||||
@ -825,4 +874,59 @@ function PMA_getCentralColumnsListRaw($db, $table)
|
||||
return json_encode($columns_list);
|
||||
}
|
||||
|
||||
/**
|
||||
* build html for adding a new user defined column to central list
|
||||
*
|
||||
* @param string $db current database
|
||||
*
|
||||
* @return html of the form to let user add a new user defined column to the list
|
||||
*/
|
||||
function PMA_getHTMLforAddNewColumn($db)
|
||||
{
|
||||
$addNewColumn = '<div id="add_col_div"><a href="#">'
|
||||
. '<span>+</span> ' . __('Add new column') . '</a>'
|
||||
. '<form id="add_new" style="min-width:100%;display:none" '
|
||||
. 'method="post" action="db_central_columns.php">'
|
||||
. PMA_URL_getHiddenInputs(
|
||||
$db
|
||||
)
|
||||
. '<input type="hidden" name="add_new_column" value="add_new_column">'
|
||||
. '<table>';
|
||||
$addNewColumn .= PMA_getCentralColumnsTableHeader();
|
||||
$addNewColumn .= '<tr>'
|
||||
. '<td name="col_name" class="nowrap">'
|
||||
. PMA_getHtmlForColumnName(
|
||||
0, 0, 0, array(), array('central_columnswork'=>false)
|
||||
)
|
||||
. '</td>'
|
||||
. '<td name = "col_type" class="nowrap">'
|
||||
. PMA_getHtmlForColumnType(0, 1, 0, '', array())
|
||||
. '</td>'
|
||||
. '<td class="nowrap" name="col_length">'
|
||||
. PMA_getHtmlForColumnLength(0, 2, 0, 8, '')
|
||||
. '</td>'
|
||||
. '<td name="collation" class="nowrap">'
|
||||
. PMA_getHtmlForColumnCollation(
|
||||
0, 3, 0, array()
|
||||
)
|
||||
. '</td>'
|
||||
. '<td class="nowrap" name="col_isNull">'
|
||||
. PMA_getHtmlForColumnNull(0, 4, 0, array())
|
||||
. '</td>'
|
||||
. '<td class="nowrap" name="col_extra">'
|
||||
. '<select name="col_extra"><option value="">'
|
||||
. '<option value="auto_increment">' . __('auto_increment') . '</option>'
|
||||
. '<option value="on update CURRENT_TIMESTAMP">'
|
||||
. __('on update CURRENT_TIMESTAMP') . '</option></select>'
|
||||
. '</td>'
|
||||
. '<td class="nowrap" name="col_default">'
|
||||
. PMA_getHtmlForColumnDefault(0, 5, 0, '', '', array())
|
||||
. '</td>'
|
||||
. ' <td>'
|
||||
. '<input id="add_column_save" type="submit" '
|
||||
. ' value="Save"/></td>'
|
||||
. '</tr>';
|
||||
$addNewColumn .= '</table></form></div>';
|
||||
return $addNewColumn;
|
||||
}
|
||||
?>
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
$GLOBALS['server'] = 1;
|
||||
require_once 'libraries/Util.class.php';
|
||||
require_once 'libraries/php-gettext/gettext.inc';
|
||||
require_once 'libraries/database_interface.inc.php';
|
||||
@ -17,6 +18,9 @@ require_once 'libraries/relation.lib.php';
|
||||
require_once 'libraries/Message.class.php';
|
||||
require_once 'libraries/url_generating.lib.php';
|
||||
require_once 'libraries/Theme.class.php';
|
||||
require_once 'libraries/tbl_columns_definition_form.lib.php';
|
||||
require_once 'libraries/Types.class.php';
|
||||
require_once 'libraries/mysql_charsets.inc.php';
|
||||
require_once 'libraries/central_columns.lib.php';
|
||||
|
||||
/**
|
||||
@ -33,6 +37,7 @@ class PMA_Central_Columns_Test extends PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
$GLOBALS['PMA_Types'] = new PMA_Types_MySQL();
|
||||
$GLOBALS['cfg']['Server']['user'] = 'pma_user';
|
||||
$GLOBALS['cfg']['Server']['pmadb'] = 'phpmyadmin';
|
||||
$GLOBALS['cfg']['Server']['central_columns'] = 'pma_central_columns';
|
||||
@ -40,6 +45,7 @@ class PMA_Central_Columns_Test extends PHPUnit_Framework_TestCase
|
||||
$GLOBALS['cfg']['ServerDefault'] = "PMA_server";
|
||||
$GLOBALS['cfg']['ActionLinksMode'] = 'icons';
|
||||
$GLOBALS['pmaThemeImage'] = 'image';
|
||||
$GLOBALS['cfg']['CharEditing'] = '';
|
||||
|
||||
//$_SESSION
|
||||
$GLOBALS['server'] = 1;
|
||||
@ -72,6 +78,19 @@ class PMA_Central_Columns_Test extends PHPUnit_Framework_TestCase
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA_getCentralColumnsCount
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testPMAGetCentralColumnsCount()
|
||||
{
|
||||
$this->assertEquals(
|
||||
0,
|
||||
PMA_getCentralColumnsCount('phpmyadmin')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA_syncUniqueColumns
|
||||
*
|
||||
@ -138,9 +157,40 @@ class PMA_Central_Columns_Test extends PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testPMAGetHTMLforTableNavigation()
|
||||
{
|
||||
$result = PMA_getHTMLforTableNavigation(0, 0, 'phpmyadmin');
|
||||
$this->assertTag(
|
||||
array('tag' => 'table'),
|
||||
PMA_getHTMLforTableNavigation(1, 0, 'phpmyadmin')
|
||||
$result
|
||||
);
|
||||
$this->assertContains(
|
||||
__('Search this table'),
|
||||
$result
|
||||
);
|
||||
$result_1 = PMA_getHTMLforTableNavigation(25, 10, 'phpmyadmin');
|
||||
$this->assertContains(
|
||||
'<form action="db_central_columns.php" method="post">'
|
||||
. PMA_URL_getHiddenInputs(
|
||||
'phpmyadmin'
|
||||
),
|
||||
$result_1
|
||||
);
|
||||
$this->assertContains(
|
||||
'<input type="submit" name="navig"'
|
||||
. ' class="ajax" '
|
||||
. 'value="<" />',
|
||||
$result_1
|
||||
);
|
||||
$this->assertContains(
|
||||
PMA_Util::pageselector(
|
||||
'pos', 10, 2, 3
|
||||
),
|
||||
$result_1
|
||||
);
|
||||
$this->assertContains(
|
||||
'<input type="submit" name="navig"'
|
||||
. ' class="ajax" '
|
||||
. 'value=">" />',
|
||||
$result_1
|
||||
);
|
||||
}
|
||||
|
||||
@ -152,7 +202,70 @@ class PMA_Central_Columns_Test extends PHPUnit_Framework_TestCase
|
||||
public function testPMAGetCentralColumnsTableHeader()
|
||||
{
|
||||
$this->assertTag(
|
||||
array('tag' => 'thead'), PMA_getCentralColumnsTableHeader()
|
||||
array('tag' => 'thead'), PMA_getCentralColumnsTableHeader(
|
||||
'column_heading', __('Click to sort'), 2
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA_getHTMLforCentralColumnsTableRow
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testPMAGetHTMLforCentralColumnsTableRow()
|
||||
{
|
||||
$row = array(
|
||||
'col_name'=>'col_test',
|
||||
'col_type'=>'int',
|
||||
'col_length'=>12,
|
||||
'col_collation'=>'utf8_general_ci',
|
||||
'col_isNull'=>1,
|
||||
'col_extra'=>''
|
||||
);
|
||||
$result = PMA_getHTMLforCentralColumnsTableRow($row, false, 1, 'phpmyadmin');
|
||||
$this->assertTag(
|
||||
array('tag' => 'tr'), $result
|
||||
);
|
||||
$this->assertContains(
|
||||
PMA_URL_getHiddenInputs('phpmyadmin'),
|
||||
$result
|
||||
);
|
||||
$this->assertTag(
|
||||
array('tag' => 'span', 'content'=>'col_test'), $result
|
||||
);
|
||||
$this->assertContains(
|
||||
__('on update CURRENT_TIMESTAMP'),
|
||||
$result
|
||||
);
|
||||
$this->assertContains(
|
||||
PMA_getHtmlForColumnDefault(
|
||||
1, 5, 0, strtoupper($row['col_type']), '',
|
||||
array('DefaultType'=>'NONE')
|
||||
),
|
||||
$result
|
||||
);
|
||||
$row['col_default'] = 100;
|
||||
$result_1 = PMA_getHTMLforCentralColumnsTableRow(
|
||||
$row, false, 1, 'phpmyadmin'
|
||||
);
|
||||
$this->assertContains(
|
||||
PMA_getHtmlForColumnDefault(
|
||||
1, 5, 0, strtoupper($row['col_type']), '',
|
||||
array('DefaultType'=>'USER_DEFINED', 'DefaultValue'=>100)
|
||||
),
|
||||
$result_1
|
||||
);
|
||||
$row['col_default'] = 'CURRENT_TIMESTAMP';
|
||||
$result_2 = PMA_getHTMLforCentralColumnsTableRow(
|
||||
$row, false, 1, 'phpmyadmin'
|
||||
);
|
||||
$this->assertContains(
|
||||
PMA_getHtmlForColumnDefault(
|
||||
1, 5, 0, strtoupper($row['col_type']), '',
|
||||
array('DefaultType'=>'CURRENT_TIMESTAMP')
|
||||
),
|
||||
$result_2
|
||||
);
|
||||
}
|
||||
|
||||
@ -169,4 +282,24 @@ class PMA_Central_Columns_Test extends PHPUnit_Framework_TestCase
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA_getHTMLforAddNewColumn
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testPMAGetHTMLforAddNewColumn()
|
||||
{
|
||||
$result = PMA_getHTMLforAddNewColumn('phpmyadmin');
|
||||
$this->assertTag(
|
||||
array('tag' => 'form','tag'=>'table'), $result
|
||||
);
|
||||
$this->assertContains(
|
||||
__('Add new column'),
|
||||
$result
|
||||
);
|
||||
$this->assertContains(
|
||||
PMA_URL_getHiddenInputs('phpmyadmin'),
|
||||
$result
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user