/** * getDisplay test */ public function testGetDisplay() { $this->object->setMessage('Test Message'); $this->assertEquals( '<div class="notice">Test Message</div>', $this->object->getDisplay() ); }
/** * Get HTML snippet for display user overview page * * @param string $pmaThemeImage a image source link * @param string $text_dir text directory * * @return string $html_output */ function PMA_getHtmlForUserOverview($pmaThemeImage, $text_dir) { $html_output = '<h2>' . "\n" . PMA_Util::getIcon('b_usrlist.png') . __('Users overview') . "\n" . '</h2>' . "\n"; $password_column = 'Password'; if (PMA_Util::getServerType() == 'MySQL' && PMA_MYSQL_INT_VERSION >= 50706) { $password_column = 'authentication_string'; } // $sql_query is for the initial-filtered, // $sql_query_all is for counting the total no. of users $sql_query = $sql_query_all = 'SELECT *,' . " IF(`" . $password_column . "` = _latin1 '', 'N', 'Y') AS 'Password'" . ' FROM `mysql`.`user`'; $sql_query .= isset($_REQUEST['initial']) ? PMA_rangeOfUsers($_REQUEST['initial']) : ''; $sql_query .= ' ORDER BY `User` ASC, `Host` ASC;'; $sql_query_all .= ' ;'; $res = $GLOBALS['dbi']->tryQuery($sql_query, null, PMA_DatabaseInterface::QUERY_STORE); $res_all = $GLOBALS['dbi']->tryQuery($sql_query_all, null, PMA_DatabaseInterface::QUERY_STORE); if (!$res) { // the query failed! This may have two reasons: // - the user does not have enough privileges // - the privilege tables use a structure of an earlier version. // so let's try a more simple query $GLOBALS['dbi']->freeResult($res); $GLOBALS['dbi']->freeResult($res_all); $sql_query = 'SELECT * FROM `mysql`.`user`'; $res = $GLOBALS['dbi']->tryQuery($sql_query, null, PMA_DatabaseInterface::QUERY_STORE); if (!$res) { $html_output .= PMA_getHtmlForViewUsersError(); $html_output .= PMA_getAddUserHtmlFieldset(); } else { // This message is hardcoded because I will replace it by // a automatic repair feature soon. $raw = 'Your privilege table structure seems to be older than' . ' this MySQL version!<br />' . 'Please run the <code>mysql_upgrade</code> command' . '(<code>mysql_fix_privilege_tables</code> on older systems)' . ' that should be included in your MySQL server distribution' . ' to solve this problem!'; $html_output .= PMA_Message::rawError($raw)->getDisplay(); } $GLOBALS['dbi']->freeResult($res); } else { $db_rights = PMA_getDbRightsForUserOverview(); // for all initials, even non A-Z $array_initials = array(); /** * Displays the initials * Also not necessary if there is less than 20 privileges */ if ($GLOBALS['dbi']->numRows($res_all) > 20) { $html_output .= PMA_getHtmlForInitials($array_initials); } /** * Display the user overview * (if less than 50 users, display them immediately) */ if (isset($_REQUEST['initial']) || isset($_REQUEST['showall']) || $GLOBALS['dbi']->numRows($res) < 50) { $html_output .= PMA_getUsersOverview($res, $db_rights, $pmaThemeImage, $text_dir); } else { $html_output .= PMA_getAddUserHtmlFieldset(); } // end if (display overview) if (!$GLOBALS['is_ajax_request'] || !empty($_REQUEST['ajax_page_request'])) { $flushnote = new PMA_Message(__('Note: phpMyAdmin gets the users\' privileges directly ' . 'from MySQL\'s privilege tables. The content of these tables ' . 'may differ from the privileges the server uses, ' . 'if they have been changed manually. In this case, ' . 'you should %sreload the privileges%s before you continue.'), PMA_Message::NOTICE); $flushLink = '<a href="server_privileges.php' . PMA_URL_getCommon(array('flush_privileges' => 1)) . '" id="reload_privileges_anchor">'; $flushnote->addParam($flushLink, false); $flushnote->addParam('</a>', false); $html_output .= $flushnote->getDisplay(); } } return $html_output; }
/** * function that generates a json output for an ajax request and ends script * execution * * @param PMA_Message|string $message message string containing the * html of the message * @param bool $success success whether the ajax request * was successfull * @param array $extra_data extra data optional - * any other data as part of the json request * * @return nothing */ function PMA_ajaxResponse($message, $success = true, $extra_data = array()) { $response = array(); if ($success == true) { $response['success'] = true; if ($message instanceof PMA_Message) { $response['message'] = $message->getDisplay(); } else { $response['message'] = $message; } } else { $response['success'] = false; if ($message instanceof PMA_Message) { $response['error'] = $message->getDisplay(); } else { $response['error'] = $message; } } // If extra_data has been provided, append it to the response array if (!empty($extra_data) && count($extra_data) > 0) { $response = array_merge($response, $extra_data); } // Set the Content-Type header to JSON so that jQuery parses the // response correctly. // // At this point, other headers might have been sent; // even if $GLOBALS['is_header_sent'] is true, // we have to send these additional headers. header('Cache-Control: no-cache'); header("Content-Type: application/json"); echo json_encode($response); if (!defined('TESTSUITE')) { exit; } }
/** * Get HTML snippet for display user overview page * * @param string $link_edit standard link to edit privileges * @param string $pmaThemeImage a image source link * @param string $text_dir text directory * @param string $conditional_class if ajaxable 'Ajax' otherwise '' * @param string $link_export standard link to export privileges * * @return string $html_output */ function PMA_getHtmlForDisplayUserOverviewPage($link_edit, $pmaThemeImage, $text_dir, $conditional_class, $link_export) { $html_output = '<h2>' . "\n" . PMA_Util::getIcon('b_usrlist.png') . __('Users overview') . "\n" . '</h2>' . "\n"; $sql_query = 'SELECT *,' . " IF(`Password` = _latin1 '', 'N', 'Y') AS 'Password'" . ' FROM `mysql`.`user`'; $sql_query .= isset($_REQUEST['initial']) ? PMA_rangeOfUsers($_REQUEST['initial']) : ''; $sql_query .= ' ORDER BY `User` ASC, `Host` ASC;'; $res = PMA_DBI_try_query($sql_query, null, PMA_DBI_QUERY_STORE); if (!$res) { // the query failed! This may have two reasons: // - the user does not have enough privileges // - the privilege tables use a structure of an earlier version. // so let's try a more simple query $sql_query = 'SELECT * FROM `mysql`.`user`'; $res = PMA_DBI_try_query($sql_query, null, PMA_DBI_QUERY_STORE); if (!$res) { $html_output .= PMA_Message::error(__('No Privileges'))->getDisplay(); PMA_DBI_free_result($res); unset($res); } else { // This message is hardcoded because I will replace it by // a automatic repair feature soon. $raw = 'Your privilege table structure seems to be older than' . ' this MySQL version!<br />' . 'Please run the <code>mysql_upgrade</code> command' . '(<code>mysql_fix_privilege_tables</code> on older systems)' . ' that should be included in your MySQL server distribution' . ' to solve this problem!'; $html_output .= PMA_Message::rawError($raw)->getDisplay(); } } else { $db_rights = PMA_getDbRightsForUserOverview(); // for all initials, even non A-Z $array_initials = array(); /** * Displays the initials * Also not necassary if there is less than 20 privileges */ if (PMA_DBI_num_rows($res) > 20) { $html_output .= PMA_getHtmlForDisplayTheInitials($array_initials, $conditional_class); } /** * Display the user overview * (if less than 50 users, display them immediately) */ if (isset($_REQUEST['initial']) || isset($_REQUEST['showall']) || PMA_DBI_num_rows($res) < 50) { $html_output .= PMA_getUsersOverview($res, $db_rights, $link_edit, $pmaThemeImage, $text_dir, $conditional_class, $link_export); } else { $html_output .= PMA_getAddUserHtmlFieldset($conditional_class); } // end if (display overview) if (!$GLOBALS['is_ajax_request'] || !empty($_REQUEST['ajax_page_request'])) { $flushnote = new PMA_Message(__('Note: phpMyAdmin gets the users\' privileges directly from MySQL\'s privilege tables. The content of these tables may differ from the privileges the server uses, if they have been changed manually. In this case, you should %sreload the privileges%s before you continue.'), PMA_Message::NOTICE); $flushLink = '<a href="server_privileges.php?' . $GLOBALS['url_query'] . '&' . 'flush_privileges=1" id="reload_privileges_anchor" ' . 'class="' . $conditional_class . '">'; $flushnote->addParam($flushLink, false); $flushnote->addParam('</a>', false); $html_output .= $flushnote->getDisplay(); } return $html_output; } }
/** * Prepare the message and the query * usually the message is the result of the query executed * * @param PMA_Message|string $message the message to display * @param string $sql_query the query to display * @param string $type the type (level) of the message * * @return string * * @access public */ public static function getMessage($message, $sql_query = null, $type = 'notice') { global $cfg; $retval = ''; if (null === $sql_query) { if (!empty($GLOBALS['display_query'])) { $sql_query = $GLOBALS['display_query']; } elseif (!empty($GLOBALS['unparsed_sql'])) { $sql_query = $GLOBALS['unparsed_sql']; } elseif (!empty($GLOBALS['sql_query'])) { $sql_query = $GLOBALS['sql_query']; } else { $sql_query = ''; } } if (isset($GLOBALS['using_bookmark_message'])) { $retval .= $GLOBALS['using_bookmark_message']->getDisplay(); unset($GLOBALS['using_bookmark_message']); } // In an Ajax request, $GLOBALS['cell_align_left'] may not be defined. Hence, // check for it's presence before using it $retval .= '<div class="result_query"' . (isset($GLOBALS['cell_align_left']) ? ' style="text-align: ' . $GLOBALS['cell_align_left'] . '"' : '') . '>' . "\n"; if ($message instanceof PMA_Message) { if (isset($GLOBALS['special_message'])) { $message->addMessage($GLOBALS['special_message']); unset($GLOBALS['special_message']); } $retval .= $message->getDisplay(); } else { $retval .= '<div class="' . $type . '">'; $retval .= PMA_sanitize($message); if (isset($GLOBALS['special_message'])) { $retval .= PMA_sanitize($GLOBALS['special_message']); unset($GLOBALS['special_message']); } $retval .= '</div>'; } if ($cfg['ShowSQL'] == true && !empty($sql_query) && $sql_query !== ';') { // Html format the query to be displayed // If we want to show some sql code it is easiest to create it here /* SQL-Parser-Analyzer */ if (!empty($GLOBALS['show_as_php'])) { $new_line = '\\n"<br />' . "\n" . ' . "'; $query_base = htmlspecialchars(addslashes($sql_query)); $query_base = preg_replace('/((\\015\\012)|(\\015)|(\\012))/', $new_line, $query_base); } else { $query_base = $sql_query; } $query_too_big = false; $queryLength = mb_strlen($query_base); if ($queryLength > $cfg['MaxCharactersInDisplayedSQL']) { // when the query is large (for example an INSERT of binary // data), the parser chokes; so avoid parsing the query $query_too_big = true; $shortened_query_base = nl2br(htmlspecialchars(mb_substr($sql_query, 0, $cfg['MaxCharactersInDisplayedSQL']) . '[...]')); } if (!empty($GLOBALS['show_as_php'])) { $query_base = '$sql = "' . $query_base; } elseif (isset($query_base)) { $query_base = self::formatSql($query_base); } // Prepares links that may be displayed to edit/explain the query // (don't go to default pages, we must go to the page // where the query box is available) // Basic url query part $url_params = array(); if (!isset($GLOBALS['db'])) { $GLOBALS['db'] = ''; } if (mb_strlen($GLOBALS['db'])) { $url_params['db'] = $GLOBALS['db']; if (mb_strlen($GLOBALS['table'])) { $url_params['table'] = $GLOBALS['table']; $edit_link = 'tbl_sql.php'; } else { $edit_link = 'db_sql.php'; } } else { $edit_link = 'server_sql.php'; } // Want to have the query explained // but only explain a SELECT (that has not been explained) /* SQL-Parser-Analyzer */ $explain_link = ''; $is_select = preg_match('@^SELECT[[:space:]]+@i', $sql_query); if (!empty($cfg['SQLQuery']['Explain']) && !$query_too_big) { $explain_params = $url_params; if ($is_select) { $explain_params['sql_query'] = 'EXPLAIN ' . $sql_query; $explain_link = ' [' . self::linkOrButton('import.php' . PMA_URL_getCommon($explain_params), __('Explain SQL')) . ']'; } elseif (preg_match('@^EXPLAIN[[:space:]]+SELECT[[:space:]]+@i', $sql_query)) { $explain_params['sql_query'] = mb_substr($sql_query, 8); $explain_link = ' [' . self::linkOrButton('import.php' . PMA_URL_getCommon($explain_params), __('Skip Explain SQL')) . ']'; $url = 'https://mariadb.org/explain_analyzer/analyze/' . '?client=phpMyAdmin&raw_explain=' . urlencode(self::_generateRowQueryOutput($sql_query)); $explain_link .= ' [' . self::linkOrButton('url.php?url=' . urlencode($url), sprintf(__('Analyze Explain at %s'), 'mariadb.org'), array(), true, false, '_blank') . ']'; } } //show explain $url_params['sql_query'] = $sql_query; $url_params['show_query'] = 1; // even if the query is big and was truncated, offer the chance // to edit it (unless it's enormous, see linkOrButton() ) if (!empty($cfg['SQLQuery']['Edit'])) { $edit_link .= PMA_URL_getCommon($url_params) . '#querybox'; $edit_link = ' [' . self::linkOrButton($edit_link, __('Edit')) . ']'; } else { $edit_link = ''; } // Also we would like to get the SQL formed in some nice // php-code if (!empty($cfg['SQLQuery']['ShowAsPHP']) && !$query_too_big) { $php_params = $url_params; if (!empty($GLOBALS['show_as_php'])) { $_message = __('Without PHP Code'); } else { $php_params['show_as_php'] = 1; $_message = __('Create PHP code'); } $php_link = 'import.php' . PMA_URL_getCommon($php_params); $php_link = ' [' . self::linkOrButton($php_link, $_message) . ']'; if (isset($GLOBALS['show_as_php'])) { $runquery_link = 'import.php' . PMA_URL_getCommon($url_params); $php_link .= ' [' . self::linkOrButton($runquery_link, __('Submit Query')) . ']'; } } else { $php_link = ''; } //show as php // Refresh query if (!empty($cfg['SQLQuery']['Refresh']) && !isset($GLOBALS['show_as_php']) && preg_match('@^(SELECT|SHOW)[[:space:]]+@i', $sql_query)) { $refresh_link = 'import.php' . PMA_URL_getCommon($url_params); $refresh_link = ' [' . self::linkOrButton($refresh_link, __('Refresh')) . ']'; } else { $refresh_link = ''; } //refresh $retval .= '<div class="sqlOuter">'; if ($query_too_big) { $retval .= $shortened_query_base; } else { $retval .= $query_base; } //Clean up the end of the PHP if (!empty($GLOBALS['show_as_php'])) { $retval .= '";'; } $retval .= '</div>'; $retval .= '<div class="tools print_ignore">'; $retval .= '<form action="sql.php" method="post">'; $retval .= PMA_URL_getHiddenInputs($GLOBALS['db'], $GLOBALS['table']); $retval .= '<input type="hidden" name="sql_query" value="' . htmlspecialchars($sql_query) . '" />'; // avoid displaying a Profiling checkbox that could // be checked, which would reexecute an INSERT, for example if (!empty($refresh_link) && self::profilingSupported()) { $retval .= '<input type="hidden" name="profiling_form" value="1" />'; $retval .= self::getCheckbox('profiling', __('Profiling'), isset($_SESSION['profiling']), true); } $retval .= '</form>'; /** * TODO: Should we have $cfg['SQLQuery']['InlineEdit']? */ if (!empty($cfg['SQLQuery']['Edit']) && !$query_too_big) { $inline_edit_link = ' [' . self::linkOrButton('#', _pgettext('Inline edit query', 'Edit inline'), array('class' => 'inline_edit_sql')) . ']'; } else { $inline_edit_link = ''; } $retval .= $inline_edit_link . $edit_link . $explain_link . $php_link . $refresh_link; $retval .= '</div>'; } $retval .= '</div>'; if ($GLOBALS['is_ajax_request'] === false) { $retval .= '<br class="clearfloat" />'; } return $retval; }
/** * Stops the import on (mostly upload/file related) error * * @param PMA_Message $error_message The error message * * @return void * @access public * */ function PMA_stopImport(PMA_Message $error_message) { global $import_handle, $file_to_unlink; // Close open handles if ($import_handle !== false && $import_handle !== null) { fclose($import_handle); } // Delete temporary file if ($file_to_unlink != '') { unlink($file_to_unlink); } $msg = $error_message->getDisplay(); $_SESSION['Import_message']['message'] = $msg; $response = PMA_Response::getInstance(); $response->isSuccess(false); $response->addJSON('message', PMA_Message::error($msg)); exit; }
/** * Function to get html for the sql query results div * * @param string $previous_update_query_html html for the previously * executed query * @param string $profiling_chart_html html for profiling * @param PMA_Message $missing_unique_column_msg message for the missing * unique column * @param PMA_Message $bookmark_created_msg message for bookmark creation * @param string $table_html html for the table for * displaying sql results * @param string $indexes_problems_html html for displaying errors * in indexes * @param string $bookmark_support_html html for displaying bookmark form * * @return string $html_output */ function PMA_getHtmlForSqlQueryResults($previous_update_query_html, $profiling_chart_html, $missing_unique_column_msg, $bookmark_created_msg, $table_html, $indexes_problems_html, $bookmark_support_html) { //begin the sqlqueryresults div here. container div $html_output = '<div class="sqlqueryresults ajax">'; $html_output .= isset($previous_update_query_html) ? $previous_update_query_html : ''; $html_output .= isset($profiling_chart_html) ? $profiling_chart_html : ''; $html_output .= isset($missing_unique_column_msg) ? $missing_unique_column_msg->getDisplay() : ''; $html_output .= isset($bookmark_created_msg) ? $bookmark_created_msg->getDisplay() : ''; $html_output .= $table_html; $html_output .= isset($indexes_problems_html) ? $indexes_problems_html : ''; $html_output .= isset($bookmark_support_html) ? $bookmark_support_html : ''; $html_output .= '</div>'; // end sqlqueryresults div return $html_output; }
/** * getDisplay test * * @return void */ public function testGetDisplay() { $this->object->setMessage('Test Message'); $this->assertEquals('<div class="notice"><img src="theme/s_notice.png" title="" alt="" /> ' . 'Test Message</div>', $this->object->getDisplay()); }