';
} elseif ($GLOBALS['cfg']['RowActionLinks'] == self::POSITION_NONE) {
// ... elseif display an empty column if the actions links are
// disabled to match the rest of the table
$button_html .= '
';
}
$this->__set('display_params', $display_params);
return [
$colspan,
$button_html,
];
}
/**
* Get table comments as array
*
* @param array $analyzed_sql_results analyzed sql results
*
* @return array table comments
*
* @access private
*
* @see _getTableHeaders()
*/
private function _getTableCommentsArray(array $analyzed_sql_results)
{
if (! $GLOBALS['cfg']['ShowBrowseComments']
|| empty($analyzed_sql_results['statement']->from)
) {
return [];
}
$ret = [];
foreach ($analyzed_sql_results['statement']->from as $field) {
if (empty($field->table)) {
continue;
}
$ret[$field->table] = $this->relation->getComments(
empty($field->database) ? $this->__get('db') : $field->database,
$field->table
);
}
return $ret;
}
/**
* Set global array for store highlighted header fields
*
* @param array $analyzed_sql_results analyzed sql results
*
* @return void
*
* @access private
*
* @see _getTableHeaders()
*/
private function _setHighlightedColumnGlobalField(array $analyzed_sql_results)
{
$highlight_columns = [];
if (! empty($analyzed_sql_results['statement']->where)) {
foreach ($analyzed_sql_results['statement']->where as $expr) {
foreach ($expr->identifiers as $identifier) {
$highlight_columns[$identifier] = 'true';
}
}
}
$this->__set('highlight_columns', $highlight_columns);
}
/**
* Prepare data for column restoring and show/hide
*
* @param array $analyzedSqlResults analyzed sql results
*
* @return string html content
*
* @access private
*
* @see _getTableHeaders()
*/
private function _getDataForResettingColumnOrder(array $analyzedSqlResults): string
{
if (! $this->_isSelect($analyzedSqlResults)) {
return '';
}
list($columnOrder, $columnVisibility) = $this->_getColumnParams(
$analyzedSqlResults
);
$tableCreateTime = '';
$table = new Table($this->__get('table'), $this->__get('db'));
if (! $table->isView()) {
$tableCreateTime = $GLOBALS['dbi']->getTable(
$this->__get('db'),
$this->__get('table')
)->getStatusInfo('Create_time');
}
return $this->template->render('display/results/data_for_resetting_column_order', [
'column_order' => $columnOrder,
'column_visibility' => $columnVisibility,
'is_view' => $table->isView(),
'table_create_time' => $tableCreateTime,
]);
}
/**
* Prepare option fields block
*
* @return string html content
*
* @access private
*
* @see _getTableHeaders()
*/
private function _getOptionsBlock()
{
if (isset($_SESSION['tmpval']['possible_as_geometry']) && $_SESSION['tmpval']['possible_as_geometry'] == false) {
if ($_SESSION['tmpval']['geoOption'] == self::GEOMETRY_DISP_GEOM) {
$_SESSION['tmpval']['geoOption'] = self::GEOMETRY_DISP_WKT;
}
}
return $this->template->render('display/results/options_block', [
'unique_id' => $this->__get('unique_id'),
'geo_option' => $_SESSION['tmpval']['geoOption'],
'hide_transformation' => $_SESSION['tmpval']['hide_transformation'],
'display_blob' => $_SESSION['tmpval']['display_blob'],
'display_binary' => $_SESSION['tmpval']['display_binary'],
'relational_display' => $_SESSION['tmpval']['relational_display'],
'displaywork' => $GLOBALS['cfgRelation']['displaywork'],
'relwork' => $GLOBALS['cfgRelation']['relwork'],
'possible_as_geometry' => $_SESSION['tmpval']['possible_as_geometry'],
'pftext' => $_SESSION['tmpval']['pftext'],
'db' => $this->__get('db'),
'table' => $this->__get('table'),
'sql_query' => $this->__get('sql_query'),
'goto' => $this->__get('goto'),
'default_sliders_state' => $GLOBALS['cfg']['InitialSlidersState'],
]);
}
/**
* Get full/partial text button or link
*
* @return string html content
*
* @access private
*
* @see _getTableHeaders()
*/
private function _getFullOrPartialTextButtonOrLink()
{
$url_params_full_text = [
'db' => $this->__get('db'),
'table' => $this->__get('table'),
'sql_query' => $this->__get('sql_query'),
'goto' => $this->__get('goto'),
'full_text_button' => 1,
];
if ($_SESSION['tmpval']['pftext'] == self::DISPLAY_FULL_TEXT) {
// currently in fulltext mode so show the opposite link
$tmp_image_file = $this->__get('pma_theme_image') . 's_partialtext.png';
$tmp_txt = __('Partial texts');
$url_params_full_text['pftext'] = self::DISPLAY_PARTIAL_TEXT;
} else {
$tmp_image_file = $this->__get('pma_theme_image') . 's_fulltext.png';
$tmp_txt = __('Full texts');
$url_params_full_text['pftext'] = self::DISPLAY_FULL_TEXT;
}
$tmp_image = '';
$tmp_url = 'sql.php' . Url::getCommon($url_params_full_text);
return Util::linkOrButton($tmp_url, $tmp_image);
}
/**
* Get comment for row
*
* @param array $commentsMap comments array
* @param array $fieldsMeta set of field properties
*
* @return string html content
*
* @access private
*
* @see _getTableHeaders()
*/
private function _getCommentForRow(array $commentsMap, $fieldsMeta)
{
return $this->template->render('display/results/comment_for_row', [
'comments_map' => $commentsMap,
'fields_meta' => $fieldsMeta,
'limit_chars' => $GLOBALS['cfg']['LimitChars'],
]);
}
/**
* Prepare parameters and html for sorted table header fields
*
* @param stdClass $fields_meta set of field properties
* @param array $sort_expression sort expression
* @param array $sort_expression_nodirection sort expression without direction
* @param integer $column_index the index of the column
* @param string $unsorted_sql_query the unsorted sql query
* @param integer $session_max_rows maximum rows resulted by sql
* @param string $comments comment for row
* @param array $sort_direction sort direction
* @param boolean $col_visib column is visible(false)
* array column isn't visible(string array)
* @param string $col_visib_j element of $col_visib array
*
* @return array 2 element array - $order_link, $sorted_header_html
*
* @access private
*
* @see _getTableHeaders()
*/
private function _getOrderLinkAndSortedHeaderHtml(
$fields_meta,
array $sort_expression,
array $sort_expression_nodirection,
$column_index,
$unsorted_sql_query,
$session_max_rows,
$comments,
array $sort_direction,
$col_visib,
$col_visib_j
) {
$sorted_header_html = '';
// Checks if the table name is required; it's the case
// for a query with a "JOIN" statement and if the column
// isn't aliased, or in queries like
// SELECT `1`.`master_field` , `2`.`master_field`
// FROM `PMA_relation` AS `1` , `PMA_relation` AS `2`
$sort_tbl = isset($fields_meta->table)
&& strlen($fields_meta->table) > 0
&& $fields_meta->orgname == $fields_meta->name
? Util::backquote(
$fields_meta->table
) . '.'
: '';
$name_to_use_in_sort = $fields_meta->name;
// Generates the orderby clause part of the query which is part
// of URL
list($single_sort_order, $multi_sort_order, $order_img)
= $this->_getSingleAndMultiSortUrls(
$sort_expression,
$sort_expression_nodirection,
$sort_tbl,
$name_to_use_in_sort,
$sort_direction,
$fields_meta
);
if (preg_match(
'@(.*)([[:space:]](LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|'
. 'LOCK IN SHARE MODE))@is',
$unsorted_sql_query,
$regs3
)) {
$single_sorted_sql_query = $regs3[1] . $single_sort_order . $regs3[2];
$multi_sorted_sql_query = $regs3[1] . $multi_sort_order . $regs3[2];
} else {
$single_sorted_sql_query = $unsorted_sql_query . $single_sort_order;
$multi_sorted_sql_query = $unsorted_sql_query . $multi_sort_order;
}
$_single_url_params = [
'db' => $this->__get('db'),
'table' => $this->__get('table'),
'sql_query' => $single_sorted_sql_query,
'sql_signature' => Core::signSqlQuery($single_sorted_sql_query),
'session_max_rows' => $session_max_rows,
'is_browse_distinct' => $this->__get('is_browse_distinct'),
];
$_multi_url_params = [
'db' => $this->__get('db'),
'table' => $this->__get('table'),
'sql_query' => $multi_sorted_sql_query,
'sql_signature' => Core::signSqlQuery($multi_sorted_sql_query),
'session_max_rows' => $session_max_rows,
'is_browse_distinct' => $this->__get('is_browse_distinct'),
];
$single_order_url = 'sql.php' . Url::getCommon($_single_url_params);
$multi_order_url = 'sql.php' . Url::getCommon($_multi_url_params);
// Displays the sorting URL
// enable sort order swapping for image
$order_link = $this->_getSortOrderLink(
$order_img,
$fields_meta,
$single_order_url,
$multi_order_url
);
$sorted_header_html .= $this->_getDraggableClassForSortableColumns(
$col_visib,
$col_visib_j,
$fields_meta,
$order_link,
$comments
);
return [
$order_link,
$sorted_header_html,
];
}
/**
* Prepare parameters and html for sorted table header fields
*
* @param array $sort_expression sort expression
* @param array $sort_expression_nodirection sort expression without direction
* @param string $sort_tbl The name of the table to which
* the current column belongs to
* @param string $name_to_use_in_sort The current column under
* consideration
* @param array $sort_direction sort direction
* @param stdClass $fields_meta set of field properties
*
* @return array 3 element array - $single_sort_order, $sort_order, $order_img
*
* @access private
*
* @see _getOrderLinkAndSortedHeaderHtml()
*/
private function _getSingleAndMultiSortUrls(
array $sort_expression,
array $sort_expression_nodirection,
$sort_tbl,
$name_to_use_in_sort,
array $sort_direction,
$fields_meta
) {
$sort_order = "";
// Check if the current column is in the order by clause
$is_in_sort = $this->_isInSorted(
$sort_expression,
$sort_expression_nodirection,
$sort_tbl,
$name_to_use_in_sort
);
$current_name = $name_to_use_in_sort;
if ($sort_expression_nodirection[0] == '' || ! $is_in_sort) {
$special_index = $sort_expression_nodirection[0] == ''
? 0
: count($sort_expression_nodirection);
$sort_expression_nodirection[$special_index]
= Util::backquote(
$current_name
);
$sort_direction[$special_index] = preg_match(
'@time|date@i',
$fields_meta->type ?? ''
) ? self::DESCENDING_SORT_DIR : self::ASCENDING_SORT_DIR;
}
$sort_expression_nodirection = array_filter($sort_expression_nodirection);
$single_sort_order = null;
foreach ($sort_expression_nodirection as $index => $expression) {
// check if this is the first clause,
// if it is then we have to add "order by"
$is_first_clause = ($index == 0);
$name_to_use_in_sort = $expression;
$sort_tbl_new = $sort_tbl;
// Test to detect if the column name is a standard name
// Standard name has the table name prefixed to the column name
if (mb_strpos($name_to_use_in_sort, '.') !== false) {
$matches = explode('.', $name_to_use_in_sort);
// Matches[0] has the table name
// Matches[1] has the column name
$name_to_use_in_sort = $matches[1];
$sort_tbl_new = $matches[0];
}
// $name_to_use_in_sort might contain a space due to
// formatting of function expressions like "COUNT(name )"
// so we remove the space in this situation
$name_to_use_in_sort = str_replace([' )', '``'], [')', '`'], $name_to_use_in_sort);
$name_to_use_in_sort = trim($name_to_use_in_sort, '`');
// If this the first column name in the order by clause add
// order by clause to the column name
$query_head = $is_first_clause ? "\nORDER BY " : "";
// Again a check to see if the given column is a aggregate column
if (mb_strpos($name_to_use_in_sort, '(') !== false) {
$sort_order .= $query_head . $name_to_use_in_sort . ' ' ;
} else {
if (strlen($sort_tbl_new) > 0) {
$sort_tbl_new .= ".";
}
$sort_order .= $query_head . $sort_tbl_new
. Util::backquote(
$name_to_use_in_sort
) . ' ' ;
}
// For a special case where the code generates two dots between
// column name and table name.
$sort_order = preg_replace("/\.\./", ".", $sort_order);
// Incase this is the current column save $single_sort_order
if ($current_name == $name_to_use_in_sort) {
if (mb_strpos($current_name, '(') !== false) {
$single_sort_order = "\n" . 'ORDER BY ' . Util::backquote($current_name) . ' ';
} else {
$single_sort_order = "\n" . 'ORDER BY ' . $sort_tbl
. Util::backquote(
$current_name
) . ' ';
}
if ($is_in_sort) {
list($single_sort_order, $order_img)
= $this->_getSortingUrlParams(
$sort_direction,
$single_sort_order,
$index
);
} else {
$single_sort_order .= strtoupper($sort_direction[$index]);
}
}
if ($current_name == $name_to_use_in_sort && $is_in_sort) {
// We need to generate the arrow button and related html
list($sort_order, $order_img) = $this->_getSortingUrlParams(
$sort_direction,
$sort_order,
$index
);
$order_img .= " " . ($index + 1) . "";
} else {
$sort_order .= strtoupper($sort_direction[$index]);
}
// Separate columns by a comma
$sort_order .= ", ";
}
// remove the comma from the last column name in the newly
// constructed clause
$sort_order = mb_substr(
$sort_order,
0,
mb_strlen($sort_order) - 2
);
if (empty($order_img)) {
$order_img = '';
}
return [
$single_sort_order,
$sort_order,
$order_img,
];
}
/**
* Check whether the column is sorted
*
* @param array $sort_expression sort expression
* @param array $sort_expression_nodirection sort expression without direction
* @param string $sort_tbl the table name
* @param string $name_to_use_in_sort the sorting column name
*
* @return boolean the column sorted or not
*
* @access private
*
* @see _getTableHeaders()
*/
private function _isInSorted(
array $sort_expression,
array $sort_expression_nodirection,
$sort_tbl,
$name_to_use_in_sort
) {
$index_in_expression = 0;
foreach ($sort_expression_nodirection as $index => $clause) {
if (mb_strpos($clause, '.') !== false) {
$fragments = explode('.', $clause);
$clause2 = $fragments[0] . "." . str_replace('`', '', $fragments[1]);
} else {
$clause2 = $sort_tbl . str_replace('`', '', $clause);
}
if ($clause2 === $sort_tbl . $name_to_use_in_sort) {
$index_in_expression = $index;
break;
}
}
if (empty($sort_expression[$index_in_expression])) {
$is_in_sort = false;
} else {
// Field name may be preceded by a space, or any number
// of characters followed by a dot (tablename.fieldname)
// so do a direct comparison for the sort expression;
// this avoids problems with queries like
// "SELECT id, count(id)..." and clicking to sort
// on id or on count(id).
// Another query to test this:
// SELECT p.*, FROM_UNIXTIME(p.temps) FROM mytable AS p
// (and try clicking on each column's header twice)
$noSortTable = empty($sort_tbl) || mb_strpos(
$sort_expression_nodirection[$index_in_expression],
$sort_tbl
) === false;
$noOpenParenthesis = mb_strpos(
$sort_expression_nodirection[$index_in_expression],
'('
) === false;
if (! empty($sort_tbl) && $noSortTable && $noOpenParenthesis) {
$new_sort_expression_nodirection = $sort_tbl
. $sort_expression_nodirection[$index_in_expression];
} else {
$new_sort_expression_nodirection
= $sort_expression_nodirection[$index_in_expression];
}
//Back quotes are removed in next comparison, so remove them from value
//to compare.
$name_to_use_in_sort = str_replace('`', '', $name_to_use_in_sort);
$is_in_sort = false;
$sort_name = str_replace('`', '', $sort_tbl) . $name_to_use_in_sort;
if ($sort_name == str_replace('`', '', $new_sort_expression_nodirection)
|| $sort_name == str_replace('`', '', $sort_expression_nodirection[$index_in_expression])
) {
$is_in_sort = true;
}
}
return $is_in_sort;
}
/**
* Get sort url parameters - sort order and order image
*
* @param array $sort_direction the sort direction
* @param string $sort_order the sorting order
* @param integer $index the index of sort direction array.
*
* @return array 2 element array - $sort_order, $order_img
*
* @access private
*
* @see _getSingleAndMultiSortUrls()
*/
private function _getSortingUrlParams(array $sort_direction, $sort_order, $index)
{
if (strtoupper(trim($sort_direction[$index])) == self::DESCENDING_SORT_DIR) {
$sort_order .= ' ASC';
$order_img = ' ' . Util::getImage(
's_desc',
__('Descending'),
[
'class' => "soimg",
'title' => '',
]
);
$order_img .= ' ' . Util::getImage(
's_asc',
__('Ascending'),
[
'class' => "soimg hide",
'title' => '',
]
);
} else {
$sort_order .= ' DESC';
$order_img = ' ' . Util::getImage(
's_asc',
__('Ascending'),
[
'class' => "soimg",
'title' => '',
]
);
$order_img .= ' ' . Util::getImage(
's_desc',
__('Descending'),
[
'class' => "soimg hide",
'title' => '',
]
);
}
return [
$sort_order,
$order_img,
];
}
/**
* Get sort order link
*
* @param string $order_img the sort order image
* @param stdClass $fields_meta set of field properties
* @param string $order_url the url for sort
* @param string $multi_order_url the url for sort
*
* @return string the sort order link
*
* @access private
*
* @see _getTableHeaders()
*/
private function _getSortOrderLink(
$order_img,
$fields_meta,
$order_url,
$multi_order_url
) {
$order_link_params = [
'class' => 'sortlink',
];
$order_link_content = htmlspecialchars($fields_meta->name);
$inner_link_content = $order_link_content . $order_img
. '';
return Util::linkOrButton(
$order_url,
$inner_link_content,
$order_link_params
);
}
/**
* Check if the column contains numeric data. If yes, then set the
* column header's alignment right
*
* @param stdClass $fields_meta set of field properties
* @param array $th_class array containing classes
*
* @return void
*
* @see _getDraggableClassForSortableColumns()
*/
private function _getClassForNumericColumnType($fields_meta, array &$th_class)
{
if (preg_match(
'@int|decimal|float|double|real|bit|boolean|serial@i',
(string) $fields_meta->type
)) {
$th_class[] = 'right';
}
}
/**
* Prepare columns to draggable effect for sortable columns
*
* @param boolean $col_visib the column is visible (false)
* array the column is not visible (string array)
* @param string $col_visib_j element of $col_visib array
* @param stdClass $fields_meta set of field properties
* @param string $order_link the order link
* @param string $comments the comment for the column
*
* @return string html content
*
* @access private
*
* @see _getTableHeaders()
*/
private function _getDraggableClassForSortableColumns(
$col_visib,
$col_visib_j,
$fields_meta,
$order_link,
$comments
) {
$draggable_html = '
';
return $draggable_html;
}
/**
* Prepare columns to draggable effect for non sortable columns
*
* @param boolean $col_visib the column is visible (false)
* array the column is not visible (string array)
* @param string $col_visib_j element of $col_visib array
* @param boolean $condition_field whether to add CSS class condition
* @param stdClass $fields_meta set of field properties
* @param string $comments the comment for the column
*
* @return string html content
*
* @access private
*
* @see _getTableHeaders()
*/
private function _getDraggableClassForNonSortableColumns(
$col_visib,
$col_visib_j,
$condition_field,
$fields_meta,
$comments
) {
$draggable_html = '
';
}
$this->__set('display_params', $display_params);
return $right_column_html;
}
/**
* Prepares the display for a value
*
* @param string $class class of table cell
* @param bool $conditionField whether to add CSS class condition
* @param string $value value to display
*
* @return string the td
*
* @access private
*
* @see _getDataCellForGeometryColumns(),
* _getDataCellForNonNumericColumns()
*/
private function _buildValueDisplay($class, $conditionField, $value)
{
return $this->template->render('display/results/value_display', [
'class' => $class,
'condition_field' => $conditionField,
'value' => $value,
]);
}
/**
* Prepares the display for a null value
*
* @param string $class class of table cell
* @param bool $conditionField whether to add CSS class condition
* @param stdClass $meta the meta-information about this field
* @param string $align cell alignment
*
* @return string the td
*
* @access private
*
* @see _getDataCellForNumericColumns(),
* _getDataCellForGeometryColumns(),
* _getDataCellForNonNumericColumns()
*/
private function _buildNullDisplay($class, $conditionField, $meta, $align = '')
{
$classes = $this->_addClass($class, $conditionField, $meta, '');
return $this->template->render('display/results/null_display', [
'align' => $align,
'meta' => $meta,
'classes' => $classes,
]);
}
/**
* Prepares the display for an empty value
*
* @param string $class class of table cell
* @param bool $conditionField whether to add CSS class condition
* @param stdClass $meta the meta-information about this field
* @param string $align cell alignment
*
* @return string the td
*
* @access private
*
* @see _getDataCellForNumericColumns(),
* _getDataCellForGeometryColumns(),
* _getDataCellForNonNumericColumns()
*/
private function _buildEmptyDisplay($class, $conditionField, $meta, $align = '')
{
$classes = $this->_addClass($class, $conditionField, $meta, 'nowrap');
return $this->template->render('display/results/empty_display', [
'align' => $align,
'classes' => $classes,
]);
}
/**
* Adds the relevant classes.
*
* @param string $class class of table cell
* @param bool $condition_field whether to add CSS class
* condition
* @param stdClass $meta the meta-information about the
* field
* @param string $nowrap avoid wrapping
* @param bool $is_field_truncated is field truncated (display ...)
* @param TransformationsPlugin|string $transformation_plugin transformation plugin.
* Can also be the default function:
* Core::mimeDefaultFunction
* @param string $default_function default transformation function
*
* @return string the list of classes
*
* @access private
*
* @see _buildNullDisplay(), _getRowData()
*/
private function _addClass(
$class,
$condition_field,
$meta,
$nowrap,
$is_field_truncated = false,
$transformation_plugin = '',
$default_function = ''
) {
$classes = [
$class,
$nowrap,
];
if (isset($meta->mimetype)) {
$classes[] = preg_replace('/\//', '_', $meta->mimetype);
}
if ($condition_field) {
$classes[] = 'condition';
}
if ($is_field_truncated) {
$classes[] = 'truncated';
}
$mime_map = $this->__get('mime_map');
$orgFullColName = $this->__get('db') . '.' . $meta->orgtable
. '.' . $meta->orgname;
if ($transformation_plugin != $default_function
|| ! empty($mime_map[$orgFullColName]['input_transformation'])
) {
$classes[] = 'transformed';
}
// Define classes to be added to this data field based on the type of data
$matches = [
'enum' => 'enum',
'set' => 'set',
'binary' => 'hex',
];
foreach ($matches as $key => $value) {
if (mb_strpos($meta->flags, $key) !== false) {
$classes[] = $value;
}
}
if (mb_strpos($meta->type, 'bit') !== false) {
$classes[] = 'bit';
}
return implode(' ', $classes);
}
/**
* Prepare the body of the results table
*
* @param integer $dt_result the link id associated to the query
* which results have to be displayed
* @param array $displayParts which elements to display
* @param array $map the list of relations
* @param array $analyzed_sql_results analyzed sql results
* @param boolean $is_limited_display with limited operations or not
*
* @return string html content
*
* @global array $row current row data
*
* @access private
*
* @see getTable()
*/
private function _getTableBody(
&$dt_result,
array &$displayParts,
array $map,
array $analyzed_sql_results,
$is_limited_display = false
) {
global $row; // mostly because of browser transformations,
// to make the row-data accessible in a plugin
$table_body_html = '';
// query without conditions to shorten URLs when needed, 200 is just
// guess, it should depend on remaining URL length
$url_sql_query = $this->_getUrlSqlQuery($analyzed_sql_results);
$display_params = $this->__get('display_params');
if (! is_array($map)) {
$map = [];
}
$row_no = 0;
$display_params['edit'] = [];
$display_params['copy'] = [];
$display_params['delete'] = [];
$display_params['data'] = [];
$display_params['row_delete'] = [];
$this->__set('display_params', $display_params);
// name of the class added to all grid editable elements;
// if we don't have all the columns of a unique key in the result set,
// do not permit grid editing
if ($is_limited_display || ! $this->__get('editable')) {
$grid_edit_class = '';
} else {
switch ($GLOBALS['cfg']['GridEditing']) {
case 'double-click':
// trying to reduce generated HTML by using shorter
// classes like click1 and click2
$grid_edit_class = 'grid_edit click2';
break;
case 'click':
$grid_edit_class = 'grid_edit click1';
break;
default: // 'disabled'
$grid_edit_class = '';
break;
}
}
// prepare to get the column order, if available
list($col_order, $col_visib) = $this->_getColumnParams(
$analyzed_sql_results
);
// Correction University of Virginia 19991216 in the while below
// Previous code assumed that all tables have keys, specifically that
// the phpMyAdmin GUI should support row delete/edit only for such
// tables.
// Although always using keys is arguably the prescribed way of
// defining a relational table, it is not required. This will in
// particular be violated by the novice.
// We want to encourage phpMyAdmin usage by such novices. So the code
// below has been changed to conditionally work as before when the
// table being displayed has one or more keys; but to display
// delete/edit options correctly for tables without keys.
$whereClauseMap = $this->__get('whereClauseMap');
while ($row = $GLOBALS['dbi']->fetchRow($dt_result)) {
// add repeating headers
if (($row_no != 0) && ($_SESSION['tmpval']['repeat_cells'] != 0)
&& ! ($row_no % $_SESSION['tmpval']['repeat_cells'])
) {
$table_body_html .= $this->_getRepeatingHeaders(
$display_params
);
}
$tr_class = [];
if ($GLOBALS['cfg']['BrowsePointerEnable'] != true) {
$tr_class[] = 'nopointer';
}
if ($GLOBALS['cfg']['BrowseMarkerEnable'] != true) {
$tr_class[] = 'nomarker';
}
// pointer code part
$classes = (empty($tr_class) ? ' ' : 'class="' . implode(' ', $tr_class) . '"');
$table_body_html .= '
';
// 1. Prepares the row
// In print view these variable needs to be initialized
$del_url = $del_str = $edit_anchor_class
= $edit_str = $js_conf = $copy_url = $copy_str = $edit_url = null;
// 1.2 Defines the URLs for the modify/delete link(s)
if (($displayParts['edit_lnk'] != self::NO_EDIT_OR_DELETE)
|| ($displayParts['del_lnk'] != self::NO_EDIT_OR_DELETE)
) {
// Results from a "SELECT" statement -> builds the
// WHERE clause to use in links (a unique key if possible)
/**
* @todo $where_clause could be empty, for example a table
* with only one field and it's a BLOB; in this case,
* avoid to display the delete and edit links
*/
list($where_clause, $clause_is_unique, $condition_array)
= Util::getUniqueCondition(
$dt_result, // handle
$this->__get('fields_cnt'), // fields_cnt
$this->__get('fields_meta'), // fields_meta
$row, // row
false, // force_unique
$this->__get('table'), // restrict_to_table
$analyzed_sql_results // analyzed_sql_results
);
$whereClauseMap[$row_no][$this->__get('table')] = $where_clause;
$this->__set('whereClauseMap', $whereClauseMap);
$where_clause_html = htmlspecialchars($where_clause);
// 1.2.1 Modify link(s) - update row case
if ($displayParts['edit_lnk'] == self::UPDATE_ROW) {
list($edit_url, $copy_url, $edit_str, $copy_str,
$edit_anchor_class)
= $this->_getModifiedLinks(
$where_clause,
$clause_is_unique,
$url_sql_query
);
} // end if (1.2.1)
// 1.2.2 Delete/Kill link(s)
list($del_url, $del_str, $js_conf)
= $this->_getDeleteAndKillLinks(
$where_clause,
$clause_is_unique,
$url_sql_query,
$displayParts['del_lnk'],
$row
);
// 1.3 Displays the links at left if required
if (($GLOBALS['cfg']['RowActionLinks'] == self::POSITION_LEFT)
|| ($GLOBALS['cfg']['RowActionLinks'] == self::POSITION_BOTH)
) {
$table_body_html .= $this->_getPlacedLinks(
self::POSITION_LEFT,
$del_url,
$displayParts,
$row_no,
$where_clause,
$where_clause_html,
$condition_array,
$edit_url,
$copy_url,
$edit_anchor_class,
$edit_str,
$copy_str,
$del_str,
$js_conf
);
} elseif ($GLOBALS['cfg']['RowActionLinks'] == self::POSITION_NONE) {
$table_body_html .= $this->_getPlacedLinks(
self::POSITION_NONE,
$del_url,
$displayParts,
$row_no,
$where_clause,
$where_clause_html,
$condition_array,
$edit_url,
$copy_url,
$edit_anchor_class,
$edit_str,
$copy_str,
$del_str,
$js_conf
);
} // end if (1.3)
} // end if (1)
// 2. Displays the rows' values
if ($this->__get('mime_map') === null) {
$this->_setMimeMap();
}
$table_body_html .= $this->_getRowValues(
$dt_result,
$row,
$row_no,
$col_order,
$map,
$grid_edit_class,
$col_visib,
$url_sql_query,
$analyzed_sql_results
);
// 3. Displays the modify/delete links on the right if required
if (($displayParts['edit_lnk'] != self::NO_EDIT_OR_DELETE)
|| ($displayParts['del_lnk'] != self::NO_EDIT_OR_DELETE)
) {
if (($GLOBALS['cfg']['RowActionLinks'] == self::POSITION_RIGHT)
|| ($GLOBALS['cfg']['RowActionLinks'] == self::POSITION_BOTH)
) {
$table_body_html .= $this->_getPlacedLinks(
self::POSITION_RIGHT,
$del_url,
$displayParts,
$row_no,
$where_clause,
$where_clause_html,
$condition_array,
$edit_url,
$copy_url,
$edit_anchor_class,
$edit_str,
$copy_str,
$del_str,
$js_conf
);
}
} // end if (3)
$table_body_html .= '
';
$table_body_html .= "\n";
$row_no++;
} // end while
return $table_body_html;
}
/**
* Sets the MIME details of the columns in the results set
*
* @return void
*/
private function _setMimeMap()
{
$fields_meta = $this->__get('fields_meta');
$mimeMap = [];
$added = [];
for ($currentColumn = 0; $currentColumn < $this->__get('fields_cnt'); ++$currentColumn) {
$meta = $fields_meta[$currentColumn];
$orgFullTableName = $this->__get('db') . '.' . $meta->orgtable;
if ($GLOBALS['cfgRelation']['commwork']
&& $GLOBALS['cfgRelation']['mimework']
&& $GLOBALS['cfg']['BrowseMIME']
&& ! $_SESSION['tmpval']['hide_transformation']
&& empty($added[$orgFullTableName])
) {
$mimeMap = array_merge(
$mimeMap,
$this->transformations->getMime($this->__get('db'), $meta->orgtable, false, true)
);
$added[$orgFullTableName] = true;
}
}
// special browser transformation for some SHOW statements
if ($this->__get('is_show')
&& ! $_SESSION['tmpval']['hide_transformation']
) {
preg_match(
'@^SHOW[[:space:]]+(VARIABLES|(FULL[[:space:]]+)?'
. 'PROCESSLIST|STATUS|TABLE|GRANTS|CREATE|LOGS|DATABASES|FIELDS'
. ')@i',
$this->__get('sql_query'),
$which
);
if (isset($which[1])) {
$str = ' ' . strtoupper($which[1]);
$isShowProcessList = strpos($str, 'PROCESSLIST') > 0;
if ($isShowProcessList) {
$mimeMap['..Info'] = [
'mimetype' => 'Text_Plain',
'transformation' => 'output/Text_Plain_Sql.php',
];
}
$isShowCreateTable = preg_match(
'@CREATE[[:space:]]+TABLE@i',
$this->__get('sql_query')
);
if ($isShowCreateTable) {
$mimeMap['..Create Table'] = [
'mimetype' => 'Text_Plain',
'transformation' => 'output/Text_Plain_Sql.php',
];
}
}
}
$this->__set('mime_map', $mimeMap);
}
/**
* Get the values for one data row
*
* @param integer $dt_result the link id associated to
* the query which results
* have to be displayed
* @param array $row current row data
* @param integer $row_no the index of current row
* @param array|boolean $col_order the column order false when
* a property not found false
* when a property not found
* @param array $map the list of relations
* @param string $grid_edit_class the class for all editable
* columns
* @param boolean|array|string $col_visib column is visible(false);
* column isn't visible(string
* array)
* @param string $url_sql_query the analyzed sql query
* @param array $analyzed_sql_results analyzed sql results
*
* @return string html content
*
* @access private
*
* @see _getTableBody()
*/
private function _getRowValues(
&$dt_result,
array $row,
$row_no,
$col_order,
array $map,
$grid_edit_class,
$col_visib,
$url_sql_query,
array $analyzed_sql_results
) {
$row_values_html = '';
// Following variable are needed for use in isset/empty or
// use with array indexes/safe use in foreach
$sql_query = $this->__get('sql_query');
$fields_meta = $this->__get('fields_meta');
$highlight_columns = $this->__get('highlight_columns');
$mime_map = $this->__get('mime_map');
$row_info = $this->_getRowInfoForSpecialLinks($row, $col_order);
$whereClauseMap = $this->__get('whereClauseMap');
$columnCount = $this->__get('fields_cnt');
for ($currentColumn = 0; $currentColumn < $columnCount; ++$currentColumn) {
// assign $i with appropriate column order
$i = $col_order ? $col_order[$currentColumn] : $currentColumn;
$meta = $fields_meta[$i];
$orgFullColName
= $this->__get('db') . '.' . $meta->orgtable . '.' . $meta->orgname;
$not_null_class = $meta->not_null ? 'not_null' : '';
$relation_class = isset($map[$meta->name]) ? 'relation' : '';
$hide_class = $col_visib && isset($col_visib[$currentColumn]) && ! $col_visib[$currentColumn]
? 'hide'
: '';
$grid_edit = $meta->orgtable != '' ? $grid_edit_class : '';
// handle datetime-related class, for grid editing
$field_type_class
= $this->_getClassForDateTimeRelatedFields($meta->type);
$is_field_truncated = false;
// combine all the classes applicable to this column's value
$class = $this->_getClassesForColumn(
$grid_edit,
$not_null_class,
$relation_class,
$hide_class,
$field_type_class
);
// See if this column should get highlight because it's used in the
// where-query.
$condition_field = isset($highlight_columns)
&& (isset($highlight_columns[$meta->name])
|| isset($highlight_columns[Util::backquote($meta->name)]))
? true
: false;
// Wrap MIME-transformations. [MIME]
$default_function = [
Core::class,
'mimeDefaultFunction',
]; // default_function
$transformation_plugin = $default_function;
$transform_options = [];
if ($GLOBALS['cfgRelation']['mimework']
&& $GLOBALS['cfg']['BrowseMIME']
) {
if (isset($mime_map[$orgFullColName]['mimetype'])
&& ! empty($mime_map[$orgFullColName]['transformation'])
) {
$file = $mime_map[$orgFullColName]['transformation'];
$include_file = 'libraries/classes/Plugins/Transformations/' . $file;
if (@file_exists($include_file)) {
$class_name = $this->transformations->getClassName($include_file);
if (class_exists($class_name)) {
// todo add $plugin_manager
$plugin_manager = null;
$transformation_plugin = new $class_name(
$plugin_manager
);
$transform_options = $this->transformations->getOptions(
isset(
$mime_map[$orgFullColName]['transformation_options']
)
? $mime_map[$orgFullColName]['transformation_options']
: ''
);
$meta->mimetype = str_replace(
'_',
'/',
$mime_map[$orgFullColName]['mimetype']
);
}
} // end if file_exists
} // end if transformation is set
} // end if mime/transformation works.
// Check whether the field needs to display with syntax highlighting
$dbLower = mb_strtolower($this->__get('db'));
$tblLower = mb_strtolower($meta->orgtable);
$nameLower = mb_strtolower($meta->orgname);
if (! empty($this->transformation_info[$dbLower][$tblLower][$nameLower])
&& isset($row[$i])
&& (trim($row[$i]) != '')
&& ! $_SESSION['tmpval']['hide_transformation']
) {
include_once $this->transformation_info[$dbLower][$tblLower][$nameLower][0];
$transformation_plugin = new $this->transformation_info[$dbLower][$tblLower][$nameLower][1](null);
$transform_options = $this->transformations->getOptions(
isset($mime_map[$orgFullColName]['transformation_options'])
? $mime_map[$orgFullColName]['transformation_options']
: ''
);
$meta->mimetype = str_replace(
'_',
'/',
$this->transformation_info[$dbLower][mb_strtolower($meta->orgtable)][mb_strtolower($meta->orgname)][2]
);
}
// Check for the predefined fields need to show as link in schemas
$specialSchemaLinks = SpecialSchemaLinks::get();
if (! empty($specialSchemaLinks[$dbLower][$tblLower][$nameLower])) {
$linking_url = $this->_getSpecialLinkUrl(
$specialSchemaLinks,
$row[$i],
$row_info,
mb_strtolower($meta->orgname)
);
$transformation_plugin = new Text_Plain_Link();
$transform_options = [
0 => $linking_url,
2 => true,
];
$meta->mimetype = str_replace(
'_',
'/',
'Text/Plain'
);
}
/*
* The result set can have columns from more than one table,
* this is why we have to check for the unique conditions
* related to this table; however getUniqueCondition() is
* costly and does not need to be called if we already know
* the conditions for the current table.
*/
if (! isset($whereClauseMap[$row_no][$meta->orgtable])) {
$unique_conditions = Util::getUniqueCondition(
$dt_result, // handle
$this->__get('fields_cnt'), // fields_cnt
$this->__get('fields_meta'), // fields_meta
$row, // row
false, // force_unique
$meta->orgtable, // restrict_to_table
$analyzed_sql_results // analyzed_sql_results
);
$whereClauseMap[$row_no][$meta->orgtable] = $unique_conditions[0];
}
$_url_params = [
'db' => $this->__get('db'),
'table' => $meta->orgtable,
'where_clause_sign' => Core::signSqlQuery($whereClauseMap[$row_no][$meta->orgtable]),
'where_clause' => $whereClauseMap[$row_no][$meta->orgtable],
'transform_key' => $meta->orgname,
];
if (! empty($sql_query)) {
$_url_params['sql_query'] = $url_sql_query;
}
$transform_options['wrapper_link'] = Url::getCommon($_url_params);
$display_params = $this->__get('display_params');
// in some situations (issue 11406), numeric returns 1
// even for a string type
// for decimal numeric is returning 1
// have to improve logic
if (($meta->numeric == 1 && $meta->type != 'string') || $meta->type == 'real') {
// n u m e r i c
$display_params['data'][$row_no][$i]
= $this->_getDataCellForNumericColumns(
$row[$i] === null ? null : (string) $row[$i],
$class,
$condition_field,
$meta,
$map,
$is_field_truncated,
$analyzed_sql_results,
$transformation_plugin,
$default_function,
$transform_options
);
} elseif ($meta->type == self::GEOMETRY_FIELD) {
// g e o m e t r y
// Remove 'grid_edit' from $class as we do not allow to
// inline-edit geometry data.
$class = str_replace('grid_edit', '', $class);
$display_params['data'][$row_no][$i]
= $this->_getDataCellForGeometryColumns(
$row[$i],
$class,
$meta,
$map,
$_url_params,
$condition_field,
$transformation_plugin,
$default_function,
$transform_options,
$analyzed_sql_results
);
} else {
// n o t n u m e r i c
$display_params['data'][$row_no][$i]
= $this->_getDataCellForNonNumericColumns(
$row[$i],
$class,
$meta,
$map,
$_url_params,
$condition_field,
$transformation_plugin,
$default_function,
$transform_options,
$is_field_truncated,
$analyzed_sql_results,
$dt_result,
$i
);
}
// output stored cell
$row_values_html .= $display_params['data'][$row_no][$i];
if (isset($display_params['rowdata'][$i][$row_no])) {
$display_params['rowdata'][$i][$row_no]
.= $display_params['data'][$row_no][$i];
} else {
$display_params['rowdata'][$i][$row_no]
= $display_params['data'][$row_no][$i];
}
$this->__set('display_params', $display_params);
} // end for
return $row_values_html;
}
/**
* Get link for display special schema links
*
* @param array $specialSchemaLinks special schema links
* @param string $column_value column value
* @param array $row_info information about row
* @param string $field_name column name
*
* @return string generated link
*/
private function _getSpecialLinkUrl(
array $specialSchemaLinks,
$column_value,
array $row_info,
$field_name
) {
$linking_url_params = [];
$link_relations = $specialSchemaLinks[mb_strtolower($this->__get('db'))][mb_strtolower($this->__get('table'))][$field_name];
if (! is_array($link_relations['link_param'])) {
$linking_url_params[$link_relations['link_param']] = $column_value;
} else {
// Consider only the case of creating link for column field
// sql query that needs to be passed as url param
$sql = 'SELECT `' . $column_value . '` FROM `'
. $row_info[$link_relations['link_param'][1]] . '`.`'
. $row_info[$link_relations['link_param'][2]] . '`';
$linking_url_params[$link_relations['link_param'][0]] = $sql;
}
$divider = strpos($link_relations['default_page'], '?') ? '&' : '?';
if (empty($link_relations['link_dependancy_params'])) {
return $link_relations['default_page']
. Url::getCommonRaw($linking_url_params, $divider);
}
foreach ($link_relations['link_dependancy_params'] as $new_param) {
// If param_info is an array, set the key and value
// from that array
if (is_array($new_param['param_info'])) {
$linking_url_params[$new_param['param_info'][0]]
= $new_param['param_info'][1];
continue;
}
$linking_url_params[$new_param['param_info']]
= $row_info[mb_strtolower($new_param['column_name'])];
// Special case 1 - when executing routines, according
// to the type of the routine, url param changes
if (empty($row_info['routine_type'])) {
continue;
}
}
return $link_relations['default_page']
. Url::getCommonRaw($linking_url_params, $divider);
}
/**
* Prepare row information for display special links
*
* @param array $row current row data
* @param array|boolean $col_order the column order
*
* @return array associative array with column nama -> value
*/
private function _getRowInfoForSpecialLinks(array $row, $col_order)
{
$row_info = [];
$fields_meta = $this->__get('fields_meta');
for ($n = 0; $n < $this->__get('fields_cnt'); ++$n) {
$m = $col_order ? $col_order[$n] : $n;
$row_info[mb_strtolower($fields_meta[$m]->orgname)]
= $row[$m];
}
return $row_info;
}
/**
* Get url sql query without conditions to shorten URLs
*
* @param array $analyzed_sql_results analyzed sql results
*
* @return string analyzed sql query
*
* @access private
*
* @see _getTableBody()
*/
private function _getUrlSqlQuery(array $analyzed_sql_results)
{
if (($analyzed_sql_results['querytype'] != 'SELECT')
|| (mb_strlen($this->__get('sql_query')) < 200)
) {
return $this->__get('sql_query');
}
$query = 'SELECT ' . Query::getClause(
$analyzed_sql_results['statement'],
$analyzed_sql_results['parser']->list,
'SELECT'
);
$from_clause = Query::getClause(
$analyzed_sql_results['statement'],
$analyzed_sql_results['parser']->list,
'FROM'
);
if (! empty($from_clause)) {
$query .= ' FROM ' . $from_clause;
}
return $query;
}
/**
* Get column order and column visibility
*
* @param array $analyzed_sql_results analyzed sql results
*
* @return array 2 element array - $col_order, $col_visib
*
* @access private
*
* @see _getTableBody()
*/
private function _getColumnParams(array $analyzed_sql_results)
{
if ($this->_isSelect($analyzed_sql_results)) {
$pmatable = new Table($this->__get('table'), $this->__get('db'));
$col_order = $pmatable->getUiProp(Table::PROP_COLUMN_ORDER);
/* Validate the value */
if ($col_order !== false) {
$fields_cnt = $this->__get('fields_cnt');
foreach ($col_order as $value) {
if ($value >= $fields_cnt) {
$pmatable->removeUiProp(Table::PROP_COLUMN_ORDER);
$fields_cnt = false;
}
}
}
$col_visib = $pmatable->getUiProp(Table::PROP_COLUMN_VISIB);
} else {
$col_order = false;
$col_visib = false;
}
return [
$col_order,
$col_visib,
];
}
/**
* Get HTML for repeating headers
*
* @param array $display_params holds various display info
*
* @return string html content
*
* @access private
*
* @see _getTableBody()
*/
private function _getRepeatingHeaders(
array $display_params
) {
$header_html = '
\n";
$links_html .= ''
. "\n";
if (! empty($url_query)) {
$links_html .= '' . "\n";
}
// fetch last row of the result set
$GLOBALS['dbi']->dataSeek($dt_result, $this->__get('num_rows') - 1);
$row = $GLOBALS['dbi']->fetchRow($dt_result);
// @see DbiMysqi::fetchRow & DatabaseInterface::fetchRow
if (! is_array($row)) {
$row = [];
}
// $clause_is_unique is needed by getTable() to generate the proper param
// in the multi-edit and multi-delete form
list($where_clause, $clause_is_unique, $condition_array)
= Util::getUniqueCondition(
$dt_result, // handle
$this->__get('fields_cnt'), // fields_cnt
$this->__get('fields_meta'), // fields_meta
$row, // row
false, // force_unique
false, // restrict_to_table
$analyzed_sql_results // analyzed_sql_results
);
unset($where_clause, $condition_array);
// reset to first row for the loop in _getTableBody()
$GLOBALS['dbi']->dataSeek($dt_result, 0);
$links_html .= '' . "\n";
$links_html .= '' . "\n";
return $links_html;
}
/**
* Generates HTML to display the Create view in span tag
*
* @param array $analyzed_sql_results analyzed sql results
* @param string $url_query String with URL Parameters
*
* @return string
*
* @access private
*
* @see _getResultsOperations()
*/
private function _getLinkForCreateView(array $analyzed_sql_results, $url_query)
{
$results_operations_html = '';
if (empty($analyzed_sql_results['procedure'])) {
$results_operations_html .= ''
. Util::linkOrButton(
'view_create.php' . $url_query,
Util::getIcon(
'b_view_add',
__('Create view'),
true
),
['class' => 'create_view ajax btn']
)
. '' . "\n";
}
return $results_operations_html;
}
/**
* Calls the _getResultsOperations with $only_view as true
*
* @param array $analyzed_sql_results analyzed sql results
*
* @return string
*
* @access public
*
*/
public function getCreateViewQueryResultOp(array $analyzed_sql_results)
{
$results_operations_html = '';
//calling to _getResultOperations with a fake $displayParts
//and setting only_view parameter to be true to generate just view
$results_operations_html .= $this->_getResultsOperations(
[],
$analyzed_sql_results,
true
);
return $results_operations_html;
}
/**
* Get copy to clipboard links for results operations
*
* @return string
*
* @access private
*/
private function _getCopytoclipboardLinks()
{
return Util::linkOrButton(
'#',
Util::getIcon(
'b_insrow',
__('Copy to clipboard'),
true
),
[
'id' => 'copyToClipBoard' ,
'class' => 'btn',
]
);
}
/**
* Get printview links for results operations
*
* @return string
*
* @access private
*/
private function _getPrintviewLinks()
{
return Util::linkOrButton(
'#',
Util::getIcon(
'b_print',
__('Print'),
true
),
[
'id' => 'printView' ,
'class' => 'btn',
],
'print_view'
);
}
/**
* Get operations that are available on results.
*
* @param array $displayParts the parts to display
* @param array $analyzed_sql_results analyzed sql results
* @param boolean $only_view Whether to show only view
*
* @return string html content
*
* @access private
*
* @see getTable()
*/
private function _getResultsOperations(
array $displayParts,
array $analyzed_sql_results,
$only_view = false
) {
global $printview;
$results_operations_html = '';
$fields_meta = $this->__get('fields_meta'); // To safe use in foreach
$header_shown = false;
$header = ' ';
}
return $results_operations_html;
}
// Displays "printable view" link if required
if ($displayParts['pview_lnk'] == '1') {
$results_operations_html .= $this->_getPrintviewLinks();
$results_operations_html .= $this->_getCopytoclipboardLinks();
} // end displays "printable view"
// Export link
// (the url_query has extra parameters that won't be used to export)
// (the single_table parameter is used in \PhpMyAdmin\Export->getDisplay()
// to hide the SQL and the structure export dialogs)
// If the parser found a PROCEDURE clause
// (most probably PROCEDURE ANALYSE()) it makes no sense to
// display the Export link).
if (($analyzed_sql_results['querytype'] == self::QUERY_TYPE_SELECT)
&& ! isset($printview)
&& empty($analyzed_sql_results['procedure'])
) {
if (count($analyzed_sql_results['select_tables']) === 1) {
$_url_params['single_table'] = 'true';
}
if (! $header_shown) {
$results_operations_html .= $header;
$header_shown = true;
}
$_url_params['unlim_num_rows'] = $this->__get('unlim_num_rows');
/**
* At this point we don't know the table name; this can happen
* for example with a query like
* SELECT bike_code FROM (SELECT bike_code FROM bikes) tmp
* As a workaround we set in the table parameter the name of the
* first table of this database, so that tbl_export.php and
* the script it calls do not fail
*/
if (empty($_url_params['table']) && ! empty($_url_params['db'])) {
$_url_params['table'] = $GLOBALS['dbi']->fetchValue("SHOW TABLES");
/* No result (probably no database selected) */
if ($_url_params['table'] === false) {
unset($_url_params['table']);
}
}
$results_operations_html .= Util::linkOrButton(
'tbl_export.php' . Url::getCommon($_url_params),
Util::getIcon(
'b_tblexport',
__('Export'),
true
),
['class' => 'btn']
);
// prepare chart
$results_operations_html .= Util::linkOrButton(
'tbl_chart.php' . Url::getCommon($_url_params),
Util::getIcon(
'b_chart',
__('Display chart'),
true
),
['class' => 'btn']
);
// prepare GIS chart
$geometry_found = false;
// If at least one geometry field is found
foreach ($fields_meta as $meta) {
if ($meta->type == self::GEOMETRY_FIELD) {
$geometry_found = true;
break;
}
}
if ($geometry_found) {
$results_operations_html
.= Util::linkOrButton(
'tbl_gis_visualization.php'
. Url::getCommon($_url_params),
Util::getIcon(
'b_globe',
__('Visualize GIS data'),
true
),
['class' => 'btn']
);
}
}
// CREATE VIEW
/**
*
* @todo detect privileges to create a view
* (but see 2006-01-19 note in PhpMyAdmin\Display\CreateTable,
* I think we cannot detect db-specific privileges reliably)
* Note: we don't display a Create view link if we found a PROCEDURE clause
*/
if (! $header_shown) {
$results_operations_html .= $header;
$header_shown = true;
}
$results_operations_html .= $this->_getLinkForCreateView(
$analyzed_sql_results,
$url_query
);
if ($header_shown) {
$results_operations_html .= ' ';
}
return $results_operations_html;
}
/**
* Verifies what to do with non-printable contents (binary or BLOB)
* in Browse mode.
*
* @param string $category BLOB|BINARY|GEOMETRY
* @param string|null $content the binary content
* @param mixed $transformation_plugin transformation plugin.
* Can also be the
* default function:
* Core::mimeDefaultFunction
* @param string $transform_options transformation parameters
* @param string $default_function default transformation function
* @param stdClass $meta the meta-information about the field
* @param array $url_params parameters that should go to the
* download link
* @param boolean $is_truncated the result is truncated or not
*
* @return mixed string or float
*
* @access private
*
* @see _getDataCellForGeometryColumns(),
* _getDataCellForNonNumericColumns(),
* _getSortedColumnMessage()
*/
private function _handleNonPrintableContents(
$category,
?string $content,
$transformation_plugin,
$transform_options,
$default_function,
$meta,
array $url_params = [],
&$is_truncated = null
) {
$is_truncated = false;
$result = '[' . $category;
if ($content !== null) {
$size = strlen($content);
$display_size = Util::formatByteDown($size, 3, 1);
$result .= ' - ' . $display_size[0] . ' ' . $display_size[1];
} else {
$result .= ' - NULL';
$size = 0;
$content = '';
}
$result .= ']';
// if we want to use a text transformation on a BLOB column
if (gettype($transformation_plugin) === "object") {
$posMimeOctetstream = strpos(
$transformation_plugin->getMIMESubtype(),
'Octetstream'
);
$posMimeText = strpos($transformation_plugin->getMIMEtype(), 'Text');
if ($posMimeOctetstream
|| $posMimeText !== false
) {
// Applying Transformations on hex string of binary data
// seems more appropriate
$result = pack("H*", bin2hex($content));
}
}
if ($size <= 0) {
return $result;
}
if ($default_function != $transformation_plugin) {
$result = $transformation_plugin->applyTransformation(
$result,
$transform_options,
$meta
);
return $result;
}
$result = $default_function($result, [], $meta);
if (($_SESSION['tmpval']['display_binary']
&& $meta->type === self::STRING_FIELD)
|| ($_SESSION['tmpval']['display_blob']
&& false !== stripos($meta->type, self::BLOB_FIELD))
) {
// in this case, restart from the original $content
if (mb_check_encoding($content, 'utf-8')
&& ! preg_match('/[\x00-\x08\x0B\x0C\x0E-\x1F\x80-\x9F]/u', $content)
) {
// show as text if it's valid utf-8
$result = htmlspecialchars($content);
} else {
$result = '0x' . bin2hex($content);
}
list(
$is_truncated,
$result,
// skip 3rd param
) = $this->_getPartialText($result);
}
/* Create link to download */
// in PHP < 5.5, empty() only checks variables
$tmpdb = $this->__get('db');
if (count($url_params) > 0
&& (! empty($tmpdb) && ! empty($meta->orgtable))
) {
$url_params['where_clause_sign'] = Core::signSqlQuery($url_params['where_clause']);
$result = ''
. $result . '';
}
return $result;
}
/**
* Retrieves the associated foreign key info for a data cell
*
* @param array $map the list of relations
* @param stdClass $meta the meta-information about the field
* @param string $where_comparison data for the where clause
*
* @return string|null formatted data
*
* @access private
*
*/
private function _getFromForeign(array $map, $meta, $where_comparison)
{
$dispsql = 'SELECT '
. Util::backquote($map[$meta->name][2])
. ' FROM '
. Util::backquote($map[$meta->name][3])
. '.'
. Util::backquote($map[$meta->name][0])
. ' WHERE '
. Util::backquote($map[$meta->name][1])
. $where_comparison;
$dispresult = $GLOBALS['dbi']->tryQuery(
$dispsql,
DatabaseInterface::CONNECT_USER,
DatabaseInterface::QUERY_STORE
);
if ($dispresult && $GLOBALS['dbi']->numRows($dispresult) > 0) {
list($dispval) = $GLOBALS['dbi']->fetchRow($dispresult, 0);
} else {
$dispval = __('Link not found!');
}
$GLOBALS['dbi']->freeResult($dispresult);
return $dispval;
}
/**
* Prepares the displayable content of a data cell in Browse mode,
* taking into account foreign key description field and transformations
*
* @param string $class css classes for the td element
* @param bool $condition_field whether the column is a part of
* the where clause
* @param array $analyzed_sql_results the analyzed query
* @param stdClass $meta the meta-information about the
* field
* @param array $map the list of relations
* @param string $data data
* @param string $displayedData data that will be displayed (maybe be chunked)
* @param TransformationsPlugin $transformation_plugin transformation plugin.
* Can also be the default function:
* Core::mimeDefaultFunction
* @param string $default_function default function
* @param string $nowrap 'nowrap' if the content should
* not be wrapped
* @param string $where_comparison data for the where clause
* @param array $transform_options options for transformation
* @param bool $is_field_truncated whether the field is truncated
* @param string $original_length of a truncated column, or ''
*
* @return string formatted data
*
* @access private
*
* @see _getDataCellForNumericColumns(), _getDataCellForGeometryColumns(),
* _getDataCellForNonNumericColumns(),
*
*/
private function _getRowData(
$class,
$condition_field,
array $analyzed_sql_results,
$meta,
array $map,
$data,
$displayedData,
$transformation_plugin,
$default_function,
$nowrap,
$where_comparison,
array $transform_options,
$is_field_truncated,
$original_length = ''
) {
$relational_display = $_SESSION['tmpval']['relational_display'];
$printview = $this->__get('printview');
$decimals = isset($meta->decimals) ? $meta->decimals : '-1';
$result = '
_addClass(
$class,
$condition_field,
$meta,
$nowrap,
$is_field_truncated,
$transformation_plugin,
$default_function
)
. '">';
if (! empty($analyzed_sql_results['statement']->expr)) {
foreach ($analyzed_sql_results['statement']->expr as $expr) {
if (empty($expr->alias) || empty($expr->column)) {
continue;
}
if (strcasecmp($meta->name, $expr->alias) == 0) {
$meta->name = $expr->column;
}
}
}
if (isset($map[$meta->name])) {
// Field to display from the foreign table?
if (isset($map[$meta->name][2])
&& strlen((string) $map[$meta->name][2]) > 0
) {
$dispval = $this->_getFromForeign(
$map,
$meta,
$where_comparison
);
} else {
$dispval = '';
} // end if... else...
if (isset($printview) && ($printview == '1')) {
$result .= ($transformation_plugin != $default_function
? $transformation_plugin->applyTransformation(
$data,
$transform_options,
$meta
)
: $default_function($data)
)
. ' [->' . $dispval . ']';
} else {
if ($relational_display == self::RELATIONAL_KEY) {
// user chose "relational key" in the display options, so
// the title contains the display field
$title = ! empty($dispval)
? htmlspecialchars($dispval)
: '';
} else {
$title = htmlspecialchars($data);
}
$sqlQuery = 'SELECT * FROM '
. Util::backquote($map[$meta->name][3]) . '.'
. Util::backquote($map[$meta->name][0])
. ' WHERE '
. Util::backquote($map[$meta->name][1])
. $where_comparison;
$_url_params = [
'db' => $map[$meta->name][3],
'table' => $map[$meta->name][0],
'pos' => '0',
'sql_signature' => Core::signSqlQuery($sqlQuery),
'sql_query' => $sqlQuery,
];
if ($transformation_plugin != $default_function) {
// always apply a transformation on the real data,
// not on the display field
$displayedData = $transformation_plugin->applyTransformation(
$data,
$transform_options,
$meta
);
} else {
if ($relational_display == self::RELATIONAL_DISPLAY_COLUMN
&& ! empty($map[$meta->name][2])
) {
// user chose "relational display field" in the
// display options, so show display field in the cell
$displayedData = $dispval === null ? 'NULL' : $default_function($dispval);
} else {
// otherwise display data in the cell
$displayedData = $default_function($displayedData);
}
}
$tag_params = ['title' => $title];
if (strpos($class, 'grid_edit') !== false) {
$tag_params['class'] = 'ajax';
}
$result .= Util::linkOrButton(
'sql.php' . Url::getCommon($_url_params),
$displayedData,
$tag_params
);
}
} else {
$result .= ($transformation_plugin != $default_function
? $transformation_plugin->applyTransformation(
$data,
$transform_options,
$meta
)
: $default_function($data)
);
}
$result .= '
' . "\n";
return $result;
}
/**
* Prepares a checkbox for multi-row submits
*
* @param string $del_url delete url
* @param array $displayParts array with explicit indexes for all
* the display elements
* @param string $row_no the row number
* @param string $where_clause_html url encoded where clause
* @param array $condition_array array of conditions in the where clause
* @param string $id_suffix suffix for the id
* @param string $class css classes for the td element
*
* @return string the generated HTML
*
* @access private
*
* @see _getTableBody(), _getCheckboxAndLinks()
*/
private function _getCheckboxForMultiRowSubmissions(
$del_url,
array $displayParts,
$row_no,
$where_clause_html,
array $condition_array,
$id_suffix,
$class
) {
$ret = '';
if (! empty($del_url) && $displayParts['del_lnk'] != self::KILL_PROCESS) {
$ret .= '
'
. ''
. '
';
}
return $ret;
}
/**
* Prepares an Edit link
*
* @param string $edit_url edit url
* @param string $class css classes for td element
* @param string $edit_str text for the edit link
* @param string $where_clause where clause
* @param string $where_clause_html url encoded where clause
*
* @return string the generated HTML
*
* @access private
*
* @see _getTableBody(), _getCheckboxAndLinks()
*/
private function _getEditLink(
$edit_url,
$class,
$edit_str,
$where_clause,
$where_clause_html
) {
$ret = '';
if (! empty($edit_url)) {
$ret .= '
'
. ''
. Util::linkOrButton($edit_url, $edit_str);
/*
* Where clause for selecting this row uniquely is provided as
* a hidden input. Used by jQuery scripts for handling grid editing
*/
if (! empty($where_clause)) {
$ret .= '';
}
$ret .= '
';
}
return $ret;
}
/**
* Prepares an Copy link
*
* @param string $copy_url copy url
* @param string $copy_str text for the copy link
* @param string $where_clause where clause
* @param string $where_clause_html url encoded where clause
* @param string $class css classes for the td element
*
* @return string the generated HTML
*
* @access private
*
* @see _getTableBody(), _getCheckboxAndLinks()
*/
private function _getCopyLink(
$copy_url,
$copy_str,
$where_clause,
$where_clause_html,
$class
) {
$ret = '';
if (! empty($copy_url)) {
$ret .= '
'
. Util::linkOrButton($copy_url, $copy_str);
/*
* Where clause for selecting this row uniquely is provided as
* a hidden input. Used by jQuery scripts for handling grid editing
*/
if (! empty($where_clause)) {
$ret .= '';
}
$ret .= '
';
}
return $ret;
}
/**
* Prepares a Delete link
*
* @param string $del_url delete url
* @param string $del_str text for the delete link
* @param string $js_conf text for the JS confirmation
* @param string $class css classes for the td element
*
* @return string the generated HTML
*
* @access private
*
* @see _getTableBody(), _getCheckboxAndLinks()
*/
private function _getDeleteLink($del_url, $del_str, $js_conf, $class)
{
$ret = '';
if (empty($del_url)) {
return $ret;
}
$ret .= '