/** * Returns html with PMA\libraries\Advisor * * @return string */ function PMA_getHtmlForAdvisor() { $output = '<a href="#openAdvisorInstructions">'; $output .= PMA\libraries\Util::getIcon('b_help.png', __('Instructions')); $output .= '</a>'; $output .= '<div id="statustabs_advisor"></div>'; $output .= '<div id="advisorInstructionsDialog" style="display:none;">'; $output .= '<p>'; $output .= __('The Advisor system can provide recommendations ' . 'on server variables by analyzing the server status variables.'); $output .= '</p>'; $output .= '<p>'; $output .= __('Do note however that this system provides recommendations ' . 'based on simple calculations and by rule of thumb which may ' . 'not necessarily apply to your system.'); $output .= '</p>'; $output .= '<p>'; $output .= __('Prior to changing any of the configuration, be sure to know ' . 'what you are changing (by reading the documentation) and how ' . 'to undo the change. Wrong tuning can have a very negative ' . 'effect on performance.'); $output .= '</p>'; $output .= '<p>'; $output .= __('The best way to tune your system would be to change only one ' . 'setting at a time, observe or benchmark your database, and undo ' . 'the change if there was no clearly measurable improvement.'); $output .= '</p>'; $output .= '</div>'; $output .= '<div id="advisorData" style="display:none;">'; $advisor = new PMA\libraries\Advisor(); $output .= htmlspecialchars(json_encode($advisor->run())); $output .= '</div>'; return $output; }
/** * Get HTML for the Change password dialog * * @param string $username username * @param string $hostname hostname * * @return string html snippet */ function PMA_getHtmlForChangePassword($username, $hostname) { /** * autocomplete feature of IE kills the "onchange" event handler and it * must be replaced by the "onpropertychange" one in this case */ $chg_evt_handler = PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER >= 5 && PMA_USR_BROWSER_VER < 7 ? 'onpropertychange' : 'onchange'; $is_privileges = basename($_SERVER['SCRIPT_NAME']) === 'server_privileges.php'; $html = '<form method="post" id="change_password_form" ' . 'action="' . basename($GLOBALS['PMA_PHP_SELF']) . '" ' . 'name="chgPassword" ' . 'class="' . ($is_privileges ? 'submenu-item' : '') . '">'; $html .= PMA_URL_getHiddenInputs(); if (strpos($GLOBALS['PMA_PHP_SELF'], 'server_privileges') !== false) { $html .= '<input type="hidden" name="username" ' . 'value="' . htmlspecialchars($username) . '" />' . '<input type="hidden" name="hostname" ' . 'value="' . htmlspecialchars($hostname) . '" />'; } $html .= '<fieldset id="fieldset_change_password">' . '<legend' . ($is_privileges ? ' data-submenu-label="' . __('Change password') . '"' : '') . '>' . __('Change password') . '</legend>' . '<table class="data noclick">' . '<tr class="odd">' . '<td colspan="2">' . '<input type="radio" name="nopass" value="1" id="nopass_1" ' . 'onclick="pma_pw.value = \'\'; pma_pw2.value = \'\'; ' . 'this.checked = true" />' . '<label for="nopass_1">' . __('No Password') . '</label>' . '</td>' . '</tr>' . '<tr class="even vmiddle">' . '<td>' . '<input type="radio" name="nopass" value="0" id="nopass_0" ' . 'onclick="document.getElementById(\'text_pma_pw\').focus();" ' . 'checked="checked" />' . '<label for="nopass_0">' . __('Password:'******' </label>' . '</td>' . '<td>' . '<input type="password" name="pma_pw" id="text_pma_pw" size="10" ' . 'class="textfield"' . $chg_evt_handler . '="nopass[1].checked = true" />' . ' ' . __('Re-type:') . ' ' . '<input type="password" name="pma_pw2" id="text_pma_pw2" size="10" ' . 'class="textfield"' . $chg_evt_handler . '="nopass[1].checked = true" />' . '</td>' . '</tr>'; $html .= '<tr class="vmiddle">' . '<td>' . __('Password Hashing:') . '</td><td>'; $serverType = PMA\libraries\Util::getServerType(); $orig_auth_plugin = PMA_getCurrentAuthenticationPlugin('change', $username, $hostname); if ($serverType == 'MySQL' && PMA_MYSQL_INT_VERSION >= 50507 || $serverType == 'MariaDB' && PMA_MYSQL_INT_VERSION >= 50200) { $auth_plugin_dropdown = PMA_getHtmlForAuthPluginsDropdown($username, $hostname, $orig_auth_plugin, 'change_pw', 'new'); $html .= $auth_plugin_dropdown; $html .= '</td></tr>'; $html .= '<tr id="tr_element_before_generate_password"></tr>'; $html .= '</table>'; $html .= '<div ' . ($orig_auth_plugin != 'sha256_password' ? 'style="display:none"' : '') . ' id="ssl_reqd_warning_cp">' . Message::notice(__('This method requires using an \'<i>SSL connection</i>\' ' . 'or an \'<i>unencrypted connection that encrypts the password ' . 'using RSA</i>\'; while connecting to the server.') . PMA\libraries\Util::showMySQLDocu('sha256-authentication-plugin'))->getDisplay() . '</div>'; $html .= '<div ' . ($orig_auth_plugin != 'sha256_password' ? 'style="display:none"' : '') . ' id="ssl_reqd_warning_cp">' . Message::notice(__('This method requires using an \'<i>SSL connection</i>\' ' . 'or an \'<i>unencrypted connection that encrypts the password ' . 'using RSA</i>\'; while connecting to the server.') . PMA\libraries\Util::showMySQLDocu('sha256-authentication-plugin'))->getDisplay() . '</div>'; } else { $auth_plugin_dropdown = PMA_getHtmlForAuthPluginsDropdown($username, $hostname, $orig_auth_plugin, 'change_pw', 'old'); $html .= $auth_plugin_dropdown . '</td></tr>' . '<tr id="tr_element_before_generate_password"></tr>' . '</table>'; } $html .= '</fieldset>' . '<fieldset id="fieldset_change_password_footer" class="tblFooters">' . '<input type="hidden" name="change_pw" value="1" />' . '<input type="submit" value="' . __('Go') . '" />' . '</fieldset>' . '</form>'; return $html; }
/** * Test for showPHPDocu * * @return void */ function testShowPHPDocu() { $target = "docu"; $lang = _pgettext('PHP documentation language', 'en'); $expected = '<a href="./url.php?url=http%3A%2F%2Fphp.net%2Fmanual%2F' . $lang . '%2F' . $target . '" target="documentation">' . '<img src="themes/dot.gif" title="' . __('Documentation') . '" alt="' . __('Documentation') . '" class="icon ic_b_help" /></a>'; $this->assertEquals($expected, PMA\libraries\Util::showPHPDocu($target)); }
/** * This function is called from one of the other functions in this file * and it completes the handling of the export functionality. * * @param string $export_data The SQL query to create the requested item * * @return void */ function PMA_RTE_handleExport($export_data) { global $db; $item_name = htmlspecialchars(PMA\libraries\Util::backquote($_GET['item_name'])); if ($export_data !== false) { $export_data = htmlspecialchars(trim($export_data)); $title = sprintf(PMA_RTE_getWord('export'), $item_name); if ($GLOBALS['is_ajax_request'] == true) { $response = PMA\libraries\Response::getInstance(); $response->addJSON('message', $export_data); $response->addJSON('title', $title); exit; } else { $export_data = '<textarea cols="40" rows="15" style="width: 100%;">' . $export_data . '</textarea>'; echo "<fieldset>\n" . "<legend>{$title}</legend>\n" . $export_data . "</fieldset>\n"; } } else { $_db = htmlspecialchars(PMA\libraries\Util::backquote($db)); $message = __('Error in processing request:') . ' ' . sprintf(PMA_RTE_getWord('not_found'), $item_name, $_db); $response = Message::error($message); if ($GLOBALS['is_ajax_request'] == true) { $response = PMA\libraries\Response::getInstance(); $response->setRequestStatus(false); $response->addJSON('message', $message); exit; } else { $response->display(); } } }
/** * Returns the html for the sub-page heading * * @param string $type Sub page type * @param string $link Link to the official MySQL documentation * @param bool $is_image Display image or icon, true: image, false: icon * * @return string */ function PMA_getHtmlForSubPageHeader($type, $link = '', $is_image = true) { //array contains Sub page icon and text $header = array(); $header['variables']['image'] = 's_vars.png'; $header['variables']['text'] = __('Server variables and settings'); $header['engines']['image'] = 'b_engine.png'; $header['engines']['text'] = __('Storage Engines'); $header['plugins']['image'] = 'b_engine.png'; $header['plugins']['text'] = __('Plugins'); $header['binlog']['image'] = 's_tbl.png'; $header['binlog']['text'] = __('Binary log'); $header['collations']['image'] = 's_asci.png'; $header['collations']['text'] = __('Character Sets and Collations'); $header['replication']['image'] = 's_replication.png'; $header['replication']['text'] = __('Replication'); $header['database_statistics']['image'] = 's_db.png'; $header['database_statistics']['text'] = __('Databases statistics'); $header['databases']['image'] = 's_db.png'; $header['databases']['text'] = __('Databases'); $header['privileges']['image'] = 'b_usrlist.png'; $header['privileges']['text'] = __('Privileges'); if ($is_image) { $html = '<h2>' . "\n" . PMA\libraries\Util::getImage($header[$type]['image']) . ' ' . $header[$type]['text'] . "\n" . $link . '</h2>' . "\n"; } else { $html = '<h2>' . "\n" . PMA\libraries\Util::getIcon($header[$type]['image']) . ' ' . $header[$type]['text'] . "\n" . $link . '</h2>' . "\n"; } return $html; }
/** * Prints details about the current Git commit revision * * @return void */ function PMA_printGitRevision() { if (!$GLOBALS['PMA_Config']->get('PMA_VERSION_GIT')) { $response = PMA\libraries\Response::getInstance(); $response->setRequestStatus(false); return; } // load revision data from repo $GLOBALS['PMA_Config']->checkGitRevision(); // if using a remote commit fast-forwarded, link to GitHub $commit_hash = substr($GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_COMMITHASH'), 0, 7); $commit_hash = '<strong title="' . htmlspecialchars($GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_MESSAGE')) . '">' . $commit_hash . '</strong>'; if ($GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_ISREMOTECOMMIT')) { $commit_hash = '<a href="' . PMA_linkURL('https://github.com/phpmyadmin/phpmyadmin/commit/' . $GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_COMMITHASH')) . '" target="_blank">' . $commit_hash . '</a>'; } $branch = $GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_BRANCH'); if ($GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_ISREMOTEBRANCH')) { $branch = '<a href="' . PMA_linkURL('https://github.com/phpmyadmin/phpmyadmin/tree/' . $GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_BRANCH')) . '" target="_blank">' . $branch . '</a>'; } if ($branch !== false) { $branch = sprintf(__('%1$s from %2$s branch'), $commit_hash, $branch); } else { $branch = $commit_hash . ' (' . __('no branch') . ')'; } $committer = $GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_COMMITTER'); $author = $GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_AUTHOR'); PMA_printListItem(__('Git revision:') . ' ' . $branch . ',<br /> ' . sprintf(__('committed on %1$s by %2$s'), PMA\libraries\Util::localisedDate(strtotime($committer['date'])), '<a href="' . PMA_linkURL('mailto:' . htmlspecialchars($committer['email'])) . '">' . htmlspecialchars($committer['name']) . '</a>') . ($author != $committer ? ', <br />' . sprintf(__('authored on %1$s by %2$s'), PMA\libraries\Util::localisedDate(strtotime($author['date'])), '<a href="' . PMA_linkURL('mailto:' . htmlspecialchars($author['email'])) . '">' . htmlspecialchars($author['name']) . '</a>') : ''), 'li_pma_version_git', null, null, null); }
/** * Send TRI or EVN editor via ajax or by echoing. * * @param string $type TRI or EVN * @param string $mode Editor mode 'add' or 'edit' * @param array $item Data necessary to create the editor * @param string $title Title of the editor * @param string $db Database * @param string $operation Operation 'change' or '' * * @return void */ function PMA_RTE_sendEditor($type, $mode, $item, $title, $db, $operation = null) { if ($item !== false) { // Show form if ($type == 'TRI') { $editor = PMA_TRI_getEditorForm($mode, $item); } else { // EVN $editor = PMA_EVN_getEditorForm($mode, $operation, $item); } if ($GLOBALS['is_ajax_request']) { $response = PMA\libraries\Response::getInstance(); $response->addJSON('message', $editor); $response->addJSON('title', $title); } else { echo "\n\n<h2>{$title}</h2>\n\n{$editor}"; unset($_POST); } exit; } else { $message = __('Error in processing request:') . ' '; $message .= sprintf(PMA_RTE_getWord('not_found'), htmlspecialchars(PMA\libraries\Util::backquote($_REQUEST['item_name'])), htmlspecialchars(PMA\libraries\Util::backquote($db))); $message = Message::error($message); if ($GLOBALS['is_ajax_request']) { $response = PMA\libraries\Response::getInstance(); $response->setRequestStatus(false); $response->addJSON('message', $message); exit; } else { $message->display(); } } }
/** * Saves user preferences * * @param array $config_array configuration array * * @return true|PMA\libraries\Message */ function PMA_saveUserprefs(array $config_array) { $cfgRelation = PMA_getRelationsParam(); $server = isset($GLOBALS['server']) ? $GLOBALS['server'] : $GLOBALS['cfg']['ServerDefault']; $cache_key = 'server_' . $server; if (!$cfgRelation['userconfigwork']) { // no pmadb table, use session storage $_SESSION['userconfig'] = array('db' => $config_array, 'ts' => time()); if (isset($_SESSION['cache'][$cache_key]['userprefs'])) { unset($_SESSION['cache'][$cache_key]['userprefs']); } return true; } // save configuration to pmadb $query_table = PMA\libraries\Util::backquote($cfgRelation['db']) . '.' . PMA\libraries\Util::backquote($cfgRelation['userconfig']); $query = 'SELECT `username` FROM ' . $query_table . ' WHERE `username` = \'' . $GLOBALS['dbi']->escapeString($cfgRelation['user']) . '\''; $has_config = $GLOBALS['dbi']->fetchValue($query, 0, 0, $GLOBALS['controllink']); $config_data = json_encode($config_array); if ($has_config) { $query = 'UPDATE ' . $query_table . ' SET `timevalue` = NOW(), `config_data` = \'' . $GLOBALS['dbi']->escapeString($config_data) . '\'' . ' WHERE `username` = \'' . $GLOBALS['dbi']->escapeString($cfgRelation['user']) . '\''; } else { $query = 'INSERT INTO ' . $query_table . ' (`username`, `timevalue`,`config_data`) ' . 'VALUES (\'' . $GLOBALS['dbi']->escapeString($cfgRelation['user']) . '\', NOW(), ' . '\'' . $GLOBALS['dbi']->escapeString($config_data) . '\')'; } if (isset($_SESSION['cache'][$cache_key]['userprefs'])) { unset($_SESSION['cache'][$cache_key]['userprefs']); } if (!$GLOBALS['dbi']->tryQuery($query, $GLOBALS['controllink'])) { $message = Message::error(__('Could not save configuration')); $message->addMessage('<br /><br />'); $message->addMessage(Message::rawError($GLOBALS['dbi']->getError($GLOBALS['controllink']))); return $message; } return true; }
/** * Test for PMA_selectServer * * @return void */ public function testPMASelectServer() { $not_only_options = false; $omit_fieldset = false; $GLOBALS['cfg']['DefaultTabServer'] = "welcome"; $GLOBALS['cfg']['Servers'] = array('0' => array('host' => 'host0', 'port' => 'port0', 'only_db' => 'only_db0', 'user' => 'user0', 'auth_type' => 'config'), '1' => array('host' => 'host1', 'port' => 'port1', 'only_db' => 'only_db1', 'user' => 'user1', 'auth_type' => 'config')); //$not_only_options=false & $omit_fieldset=false $html = PMA_selectServer($not_only_options, $omit_fieldset); $server = $GLOBALS['cfg']['Servers']['0']; //server items $this->assertContains($server['host'], $html); $this->assertContains($server['port'], $html); $this->assertContains($server['only_db'], $html); $this->assertContains($server['user'], $html); $not_only_options = true; $omit_fieldset = true; $GLOBALS['cfg']['DisplayServersList'] = null; //$not_only_options=true & $omit_fieldset=true $html = PMA_selectServer($not_only_options, $omit_fieldset); //$GLOBALS['cfg']['DefaultTabServer'] $this->assertContains(PMA\libraries\Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabServer'], 'server'), $html); //labels $this->assertContains(__('Current server:'), $html); $this->assertContains('(' . __('Servers') . ')', $html); //server items $server = $GLOBALS['cfg']['Servers']['0']; $this->assertContains($server['host'], $html); $this->assertContains($server['port'], $html); $this->assertContains($server['only_db'], $html); $this->assertContains($server['user'], $html); }
/** * Test for isForeignKeySupported * * @return void */ public function testIsForeignKeySupported() { $GLOBALS['server'] = 1; $this->assertTrue(PMA\libraries\Util::isForeignKeySupported('innodb')); $this->assertFalse(PMA\libraries\Util::isForeignKeySupported('myisam')); $this->assertTrue(PMA\libraries\Util::isForeignKeySupported('ndb')); }
/** * Test for getMessage * * @return void */ function testShowMessageNotAjax() { global $cfg; $cfg['Server']['DisableIS'] = false; $GLOBALS['table'] = 'tbl'; $GLOBALS['db'] = 'db'; $GLOBALS['sql_query'] = "SELECT * FROM tblPatient "; $this->expectOutputString( "<div class=\"result_query\" align=\"\"> <div class=\"notice\">msg</div><code class=\"sql\"><span class=\"syntax\"><span class=\"inner_sql\"><a href=\"./url.php?url=http%3A%2F%2Fdev.mysql.com%2Fdoc%2Frefman%2F5.0%2Fen%2Fselect.html&server=server&lang=en\" target=\"mysql_doc\"><span class=\"syntax_alpha syntax_alpha_reservedWord\">SELECT</span></a> <span class=\"syntax_punct\">*</span> <br /><span class=\"syntax_alpha syntax_alpha_reservedWord\">FROM</span> <span class=\"syntax_alpha syntax_alpha_identifier\">tblPatient</span></span></span></code><div class=\"tools\"><form action=\"sql.php\" method=\"post\"><input type=\"hidden\" name=\"db\" value=\"db\" /><input type=\"hidden\" name=\"table\" value=\"tbl\" /><input type=\"hidden\" name=\"server\" value=\"server\" /><input type=\"hidden\" name=\"lang\" value=\"en\" /><input type=\"hidden\" name=\"token\" value=\"647a62ad301bf9025e3b13bc7caa02cb\" /><input type=\"hidden\" name=\"sql_query\" value=\"SELECT * FROM tblPatient \" /></form><script type=\"text/javascript\"> //<![CDATA[ $('.tools form').last().after('[<a href=\"#\" title=\"Inline edit of this query\" class=\"inline_edit_sql\">Inline</a>]'); //]]> </script> [ <a href=\"tbl_sql.php?db=db&table=tbl&sql_query=SELECT+%2A+FROM+tblPatient+&show_query=1&server=server&lang=en#querybox\" >Edit</a> ] [ <a href=\"import.php?db=db&table=tbl&sql_query=EXPLAIN+SELECT+%2A+FROM+tblPatient+&server=server&lang=en\" >Explain SQL</a> ] [ <a href=\"import.php?db=db&table=tbl&sql_query=SELECT+%2A+FROM+tblPatient+&show_query=1&show_as_php=1&server=server&lang=en\" >Create PHP code</a> ] [ <a href=\"import.php?db=db&table=tbl&sql_query=SELECT+%2A+FROM+tblPatient+&show_query=1&server=server&lang=en\" >Refresh</a> ]</div></div>" ); echo PMA\libraries\Util::getMessage("msg"); //$this->assertEquals("", PMA\libraries\Util::getMessage("msg")); $this->assertTrue(true); }
/** * Tests for _getHtmlForServerEngine() method * * @return void */ public function testGetHtmlForServerEngine() { $_REQUEST['engine'] = "Pbxt"; $_REQUEST['page'] = "page"; //Mock DBI $dbi = $this->getMockBuilder('PMA\\libraries\\DatabaseInterface')->disableOriginalConstructor()->getMock(); $GLOBALS['dbi'] = $dbi; $class = new ReflectionClass('\\PMA\\libraries\\controllers\\server\\ServerEnginesController'); $method = $class->getMethod('_getHtmlForServerEngine'); $method->setAccessible(true); $engine_plugin = StorageEngine::getEngine("Pbxt"); $ctrl = new ServerEnginesController(); $html = $method->invoke($ctrl, $engine_plugin); //validate 1: Engine title $this->assertContains(htmlspecialchars($engine_plugin->getTitle()), $html); //validate 2: Engine Mysql Help Page $this->assertContains(PMA\libraries\Util::showMySQLDocu($engine_plugin->getMysqlHelpPage()), $html); //validate 3: Engine Comment $this->assertContains(htmlspecialchars($engine_plugin->getComment()), $html); //validate 4: Engine Info Pages $this->assertContains(__('Variables'), $html); $this->assertContains(URL::getCommon(array('engine' => $_REQUEST['engine'], 'page' => "Documentation")), $html); //validate 5: other items $this->assertContains(URL::getCommon(array('engine' => $_REQUEST['engine'])), $html); $this->assertContains($engine_plugin->getSupportInformationMessage(), $html); $this->assertContains('There is no detailed status information available for this ' . 'storage engine.', $html); }
/** * Test for getDivForSliderEffect * * @return void */ function testGetDivForSliderEffectTestDisabled() { global $cfg; $cfg['InitialSlidersState'] = 'disabled'; $id = "test_id"; $message = "test_message"; $this->assertEquals(PMA\libraries\Util::getDivForSliderEffect($id, $message), '<div id="' . $id . '">'); }
/** * Test for getIcon * * @return void */ function testGetIconWithForceText() { $GLOBALS['cfg']['ActionLinksMode'] = 'icons'; $alternate_text = 'alt_str'; // Here we are checking for an icon embedded inside a span (i.e not a menu // bar icon $this->assertEquals('<span class="nowrap"><img src="themes/dot.gif" title="' . $alternate_text . '" alt="' . $alternate_text . '" class="icon ic_b_comment" /> ' . $alternate_text . '</span>', PMA\libraries\Util::getIcon('b_comment.png', $alternate_text, true, false)); }
/** * Test for getDivForSliderEffect * * @return void */ function testGetDivForSliderEffectTestDisabled() { global $cfg; $cfg['InitialSlidersState'] = 'disabled'; $id = "test_id"; $message = "test_message"; $this->assertXmlStringEqualsXmlString("<root>" . PMA\libraries\Util::getDivForSliderEffect($id, $message) . "</div></root>", "<root><div id=\"{$id}\">\n</div></root>"); }
/** * Format a string so it can be a string inside JavaScript code inside an * eventhandler (onclick, onchange, on..., ). * This function is used to displays a javascript confirmation box for * "DROP/DELETE/ALTER" queries. * * @param string $a_string the string to format * @param boolean $add_backquotes whether to add backquotes to the string or not * * @return string the formatted string * * @access public */ function PMA_jsFormat($a_string = '', $add_backquotes = true) { $a_string = htmlspecialchars($a_string); $a_string = PMA_escapeJsString($a_string); // Needed for inline javascript to prevent some browsers // treating it as a anchor $a_string = str_replace('#', '\\#', $a_string); return $add_backquotes ? PMA\libraries\Util::backquote($a_string) : $a_string; }
/** * Test for isForeignKeyCheck * * @return void */ public function testIsForeignKeyCheck() { $GLOBALS['server'] = 1; $GLOBALS['cfg']['DefaultForeignKeyChecks'] = 'enable'; $this->assertEquals(true, PMA\libraries\Util::isForeignKeyCheck()); $GLOBALS['cfg']['DefaultForeignKeyChecks'] = 'disable'; $this->assertEquals(false, PMA\libraries\Util::isForeignKeyCheck()); $GLOBALS['cfg']['DefaultForeignKeyChecks'] = 'default'; $this->assertEquals(true, PMA\libraries\Util::isForeignKeyCheck()); }
/** * Test for checkParameters * * @return void */ function testCheckParameter() { $GLOBALS['PMA_PHP_SELF'] = PMA_getenv('PHP_SELF'); $GLOBALS['pmaThemePath'] = $_SESSION['PMA_Theme']->getPath(); $GLOBALS['db'] = "dbDatabase"; $GLOBALS['table'] = "tblTable"; $GLOBALS['field'] = "test_field"; $GLOBALS['sql_query'] = "SELECT * FROM tblTable;"; $this->expectOutputString(""); PMA\libraries\Util::checkParameters(array('db', 'table', 'field', 'sql_query')); }
/** * Callback function for replacing [doc@anchor] links in bb code. * * @param array $found Array of preg matches * * @return string Replaced string */ function PMA_replaceDocLink($found) { $anchor = $found[1]; if (strncmp('faq', $anchor, 3) == 0) { $page = 'faq'; } else { if (strncmp('cfg', $anchor, 3) == 0) { $page = 'cfg'; } else { /* Guess */ $page = 'setup'; } } $link = PMA\libraries\Util::getDocuLink($page, $anchor); return '<a href="' . $link . '" target="documentation">'; }
/** * Get HTML for display indexes * * @return string $html_output */ function PMA_getHtmlForDisplayIndexes() { $html_output = '<div id="index_div" class="ajax'; if ($GLOBALS['cfg']['InitialSlidersState'] != 'disabled') { $html_output .= ' print_ignore'; } $html_output .= '" >'; $html_output .= PMA\libraries\Util::getDivForSliderEffect('indexes', __('Indexes')); $html_output .= PMA\libraries\Index::getHtmlForIndexes($GLOBALS['table'], $GLOBALS['db']); $html_output .= '<fieldset class="tblFooters print_ignore" style="text-align: ' . 'left;"><form action="tbl_indexes.php" method="post">'; $html_output .= URL::getHiddenInputs($GLOBALS['db'], $GLOBALS['table']); $html_output .= sprintf(__('Create an index on %s columns'), '<input type="number" name="added_fields" value="1" ' . 'min="1" required="required" />'); $html_output .= '<input type="hidden" name="create_index" value="1" />' . '<input class="add_index ajax"' . ' type="submit" value="' . __('Go') . '" />'; $html_output .= '</form>' . '</fieldset>' . '</div>' . '</div>'; return $html_output; }
/** * Test for getDropdown * * @return void */ function testGetDropdownWithActive() { $name = "&test_dropdown_name"; $choices = array("value_1" => "label_1", "value&_2\"" => "label_2"); $active_choice = "value&_2\""; $id = "test_<dropdown>_name"; $result = '<select name="' . htmlspecialchars($name) . '" id="' . htmlspecialchars($id) . '">'; foreach ($choices as $one_choice_value => $one_choice_label) { $result .= '<option value="' . htmlspecialchars($one_choice_value) . '"'; if ($one_choice_value == $active_choice) { $result .= ' selected="selected"'; } $result .= '>' . htmlspecialchars($one_choice_label) . '</option>'; } $result .= '</select>'; $this->assertEquals($result, PMA\libraries\Util::getDropdown($name, $choices, $active_choice, $id)); }
/** * Test for PMA_getHtmlForCreateTable * * @return void */ public function testPMAGetHtmlForCreateTable() { $db = "pma_db"; //Call the test function $html = PMA_getHtmlForCreateTable($db); //getImage $this->assertContains(PMA\libraries\Util::getImage('b_table_add.png'), $html); //__('Create table') $this->assertContains(__('Create table'), $html); //PMA_URL_getHiddenInputs $this->assertContains(PMA_URL_getHiddenInputs($db), $html); //label $this->assertContains(__('Name'), $html); $this->assertContains(__('Number of columns'), $html); //button $this->assertContains(__('Go'), $html); }
/** * Returns HTML code for the language selector * * @param boolean $use_fieldset whether to use fieldset for selection * @param boolean $show_doc whether to show documentation links * * @return string * * @access public */ function PMA_getLanguageSelectorHtml($use_fieldset = false, $show_doc = true) { global $lang; $retval = ''; // Display language selection only if there // is more than one language to choose from if (count($GLOBALS['available_languages']) > 1) { $retval .= '<form method="get" action="index.php" class="disableAjax">'; $_form_params = array('db' => $GLOBALS['db'], 'table' => $GLOBALS['table']); $retval .= PMA_URL_getHiddenInputs($_form_params); // For non-English, display "Language" with emphasis because it's // not a proper word in the current language; we show it to help // people recognize the dialog $language_title = __('Language') . (__('Language') != 'Language' ? ' - <em>Language</em>' : ''); if ($show_doc) { $language_title .= PMA\libraries\Util::showDocu('faq', 'faq7-2'); } if ($use_fieldset) { $retval .= '<fieldset><legend lang="en" dir="ltr">' . $language_title . '</legend>'; } else { $retval .= '<bdo lang="en" dir="ltr"><label for="sel-lang">' . $language_title . ': </label></bdo>'; } $retval .= '<select name="lang" class="autosubmit" lang="en"' . ' dir="ltr" id="sel-lang">'; uasort($GLOBALS['available_languages'], 'PMA_languageCmp'); foreach ($GLOBALS['available_languages'] as $id => $tmplang) { $lang_name = PMA_languageName($tmplang); //Is current one active? if ($lang == $id) { $selected = ' selected="selected"'; } else { $selected = ''; } $retval .= '<option value="' . $id . '"' . $selected . '>'; $retval .= $lang_name; $retval .= '</option>'; } $retval .= '</select>'; if ($use_fieldset) { $retval .= '</fieldset>'; } $retval .= '</form>'; } return $retval; }
/** * Test for PMA_getHtmlForQueryStatistics * * @return void */ public function testPMAGetHtmlForQueryStatistics() { //Call the test function $html = PMA_getHtmlForQueryStatistics($this->ServerStatusData); $hour_factor = 3600 / $this->ServerStatusData->status['Uptime']; $used_queries = $this->ServerStatusData->used_queries; $total_queries = array_sum($used_queries); $questions_from_start = sprintf(__('Questions since startup: %s'), PMA\libraries\Util::formatNumber($total_queries, 0)); //validate 1: PMA_getHtmlForQueryStatistics $this->assertContains('<h3 id="serverstatusqueries">', $html); $this->assertContains($questions_from_start, $html); //validate 2: per hour $this->assertContains(__('per hour:'), $html); $this->assertContains(PMA\libraries\Util::formatNumber($total_queries * $hour_factor, 0), $html); //validate 3:per minute $value_per_minute = PMA\libraries\Util::formatNumber($total_queries * 60 / $this->ServerStatusData->status['Uptime'], 0); $this->assertContains(__('per minute:'), $html); $this->assertContains($value_per_minute, $html); }
/** * setup HTML for a given Storage Engine * * @return string */ function PMA_getHtmlForSpecifiedServerEngines() { /** * Displays details about a given Storage Engine */ $html = ''; $engine_plugin = StorageEngine::getEngine($_REQUEST['engine']); $html .= '<h2>' . "\n" . PMA\libraries\Util::getImage('b_engine.png') . ' ' . htmlspecialchars($engine_plugin->getTitle()) . "\n" . ' ' . PMA\libraries\Util::showMySQLDocu($engine_plugin->getMysqlHelpPage()) . "\n" . '</h2>' . "\n\n"; $html .= '<p>' . "\n" . ' <em>' . "\n" . ' ' . htmlspecialchars($engine_plugin->getComment()) . "\n" . ' </em>' . "\n" . '</p>' . "\n\n"; $infoPages = $engine_plugin->getInfoPages(); if (!empty($infoPages) && is_array($infoPages)) { $html .= '<p>' . "\n" . ' <strong>[</strong>' . "\n"; if (empty($_REQUEST['page'])) { $html .= ' <strong>' . __('Variables') . '</strong>' . "\n"; } else { $html .= ' <a href="server_engines.php' . PMA_URL_getCommon(array('engine' => $_REQUEST['engine'])) . '">' . __('Variables') . '</a>' . "\n"; } foreach ($infoPages as $current => $label) { $html .= ' <strong>|</strong>' . "\n"; if (isset($_REQUEST['page']) && $_REQUEST['page'] == $current) { $html .= ' <strong>' . $label . '</strong>' . "\n"; } else { $html .= ' <a href="server_engines.php' . PMA_URL_getCommon(array('engine' => $_REQUEST['engine'], 'page' => $current)) . '">' . htmlspecialchars($label) . '</a>' . "\n"; } } unset($current, $label); $html .= ' <strong>]</strong>' . "\n" . '</p>' . "\n\n"; } unset($infoPages, $page_output); if (!empty($_REQUEST['page'])) { $page_output = $engine_plugin->getPage($_REQUEST['page']); } if (!empty($page_output)) { $html .= $page_output; } else { $html .= '<p> ' . $engine_plugin->getSupportInformationMessage() . "\n" . '</p>' . "\n" . $engine_plugin->getHtmlVariables(); } return $html; }
/** * Test for PMA_getHtmlForSqlQueryFormInsert * * @return void */ public function testPMAGetHtmlForSqlQueryFormInsert() { //Call the test function $query = "select * from PMA"; $html = PMA_getHtmlForSqlQueryFormInsert($query); //validate 1: query $this->assertContains(htmlspecialchars($query), $html); //validate 2: enable auto select text in textarea $auto_sel = ' onclick="selectContent(this, sql_box_locked, true);"'; $this->assertContains($auto_sel, $html); //validate 3: showMySQLDocu $this->assertContains(PMA\libraries\Util::showMySQLDocu('SELECT'), $html); //validate 4: $fields_list $this->assertContains('<input type="button" value="DELETE" id="delete"', $html); $this->assertContains('<input type="button" value="UPDATE" id="update"', $html); $this->assertContains('<input type="button" value="INSERT" id="insert"', $html); $this->assertContains('<input type="button" value="SELECT" id="select"', $html); $this->assertContains('<input type="button" value="SELECT *" id="selectall"', $html); //validate 5: Clear button $this->assertContains('<input type="button" value="DELETE" id="delete"', $html); $this->assertContains(__('Clear'), $html); }
/** * Test for whichCrlf * * @return void * * @using runkit pecl extension * if not define PMA_USR_OS, then define it as Win * if installed runkit, then constant will not change */ public function testWhichCrlf() { if (PMA_HAS_RUNKIT && defined('PMA_USR_OS')) { $pma_usr_os = PMA_USR_OS; } if (defined('PMA_USR_OS') && !PMA_HAS_RUNKIT) { if (PMA_USR_OS == 'Win') { $this->assertEquals("\r\n", PMA\libraries\Util::whichCrlf()); } else { $this->assertEquals("\n", PMA\libraries\Util::whichCrlf()); } $this->markTestIncomplete('Cannot redefine constant'); } else { if (PMA_HAS_RUNKIT) { if (!defined('PMA_USR_OS')) { define('PMA_USR_OS', 'Linux'); } else { runkit_constant_redefine('PMA_USR_OS', 'Linux'); } $this->assertEquals("\n", PMA\libraries\Util::whichCrlf()); } if (PMA_HAS_RUNKIT) { runkit_constant_redefine('PMA_USR_OS', 'Win'); } else { define('PMA_USR_OS', 'Win'); } $this->assertEquals("\r\n", PMA\libraries\Util::whichCrlf()); } if (PMA_HAS_RUNKIT) { if (isset($pma_usr_os)) { runkit_constant_redefine('PMA_USR_OS', 'Win'); } else { runkit_constant_remove('PMA_USR_OS'); } } }
/** * Test for buildActionTitles * * @return void */ function testBuildActionTitles() { $titles = array(); $titles['Browse'] = PMA\libraries\Util::getIcon('b_browse.png', __('Browse')); $titles['NoBrowse'] = PMA\libraries\Util::getIcon('bd_browse.png', __('Browse')); $titles['Search'] = PMA\libraries\Util::getIcon('b_select.png', __('Search')); $titles['NoSearch'] = PMA\libraries\Util::getIcon('bd_select.png', __('Search')); $titles['Insert'] = PMA\libraries\Util::getIcon('b_insrow.png', __('Insert')); $titles['NoInsert'] = PMA\libraries\Util::getIcon('bd_insrow.png', __('Insert')); $titles['Structure'] = PMA\libraries\Util::getIcon('b_props.png', __('Structure')); $titles['Drop'] = PMA\libraries\Util::getIcon('b_drop.png', __('Drop')); $titles['NoDrop'] = PMA\libraries\Util::getIcon('bd_drop.png', __('Drop')); $titles['Empty'] = PMA\libraries\Util::getIcon('b_empty.png', __('Empty')); $titles['NoEmpty'] = PMA\libraries\Util::getIcon('bd_empty.png', __('Empty')); $titles['Edit'] = PMA\libraries\Util::getIcon('b_edit.png', __('Edit')); $titles['NoEdit'] = PMA\libraries\Util::getIcon('bd_edit.png', __('Edit')); $titles['Export'] = PMA\libraries\Util::getIcon('b_export.png', __('Export')); $titles['NoExport'] = PMA\libraries\Util::getIcon('bd_export.png', __('Export')); $titles['Execute'] = PMA\libraries\Util::getIcon('b_nextpage.png', __('Execute')); $titles['NoExecute'] = PMA\libraries\Util::getIcon('bd_nextpage.png', __('Execute')); $titles['Favorite'] = PMA\libraries\Util::getIcon('b_favorite.png', ''); $titles['NoFavorite'] = PMA\libraries\Util::getIcon('b_no_favorite.png', ''); $this->assertEquals($titles, PMA\libraries\Util::buildActionTitles()); }
/** * Test for PMA_getAddUserHtmlFieldset * * @return void */ public function testPMAGetAddUserHtmlFieldset() { $html = PMA_getAddUserHtmlFieldset(); $this->assertContains(PMA_URL_getCommon(array('adduser' => 1)), $html); $this->assertContains(PMA\libraries\Util::getIcon('b_usradd.png'), $html); $this->assertContains(__('Add user'), $html); }
PMA_printListItem(__('Show PHP information'), 'li_phpinfo', 'phpinfo.php' . $common_url_query, null, '_blank'); } echo ' </ul>'; echo ' </div>'; } echo '<div class="group pmagroup">'; echo '<h2>phpMyAdmin</h2>'; echo '<ul>'; $class = null; // We rely on CSP to allow access to http://www.phpmyadmin.net, but IE lacks // support here and does not allow request to http once using https. if ($GLOBALS['cfg']['VersionCheck'] && (!$GLOBALS['PMA_Config']->get('is_https') || PMA_USR_BROWSER_AGENT != 'IE')) { $class = 'jsversioncheck'; } PMA_printListItem(__('Version information:') . ' <span class="version">' . PMA_VERSION . '</span>', 'li_pma_version', null, null, null, null, $class); PMA_printListItem(__('Documentation'), 'li_pma_docs', PMA\libraries\Util::getDocuLink('index'), null, '_blank'); PMA_printListItem(__('Wiki'), 'li_pma_wiki', PMA_linkURL('http://wiki.phpmyadmin.net/'), null, '_blank'); // does not work if no target specified, don't know why PMA_printListItem(__('Official Homepage'), 'li_pma_homepage', PMA_linkURL('http://www.phpMyAdmin.net/'), null, '_blank'); PMA_printListItem(__('Contribute'), 'li_pma_contribute', PMA_linkURL('https://www.phpmyadmin.net/contribute/'), null, '_blank'); PMA_printListItem(__('Get support'), 'li_pma_support', PMA_linkURL('https://www.phpmyadmin.net/support/'), null, '_blank'); PMA_printListItem(__('List of changes'), 'li_pma_changes', 'changelog.php' . PMA_URL_getCommon(), null, '_blank'); PMA_printListItem(__('License'), 'li_pma_license', 'license.php' . PMA_URL_getCommon(), null, '_blank'); echo ' </ul>'; echo ' </div>'; echo '</div>'; echo '</div>'; /** * As we try to handle charsets by ourself, mbstring overloads just * break it, see bug 1063821. */