/**
  * Returns the singleton PMA_CommonFunctions object
  *
  * @return PMA_CommonFunctions object
  */
 public static function getInstance()
 {
     if (empty(self::$_instance)) {
         self::$_instance = new PMA_CommonFunctions();
     }
     return self::$_instance;
 }
 function testExtractValueFromFormattedSizeK()
 {
     $this->assertEquals(
         262144,
         PMA_CommonFunctions::getInstance()->extractValueFromFormattedSize("256K")
     );
 }
    /**
     * @dataProvider dataProvider
     */
    function testConvert_bit_default_value_test($bit, $val)
    {
        $this->assertEquals(
            $val, PMA_CommonFunctions::getInstance()->convertBitDefaultValue($bit)
        );

    }
Пример #4
0
 /**
  * Get CommmonFunctions
  * 
  * @return CommonFunctions object
  */
 public function getCommonFunctions()
 {
     if (is_null($this->_common_functions)) {
         $this->_common_functions = PMA_CommonFunctions::getInstance();
     }
     return $this->_common_functions;
 }
 function testNotSupportedDataTypes()
 {
     $no_support_types = array();
     $this->assertEquals(
         $no_support_types, PMA_CommonFunctions::getInstance()->unsupportedDatatypes()
     );
 }
/**
 * Cleanup database related relation stuff
 *
 * @param string $db
 */
function PMA_relationsCleanupDatabase($db)
{
    $common_functions = PMA_CommonFunctions::getInstance();
    $cfgRelation = PMA_getRelationsParam();
    if ($cfgRelation['commwork']) {
        $remove_query = 'DELETE FROM ' . $common_functions->backquote($cfgRelation['db']) . '.' . $common_functions->backquote($cfgRelation['column_info']) . ' WHERE db_name  = \'' . $common_functions->sqlAddSlashes($db) . '\'';
        PMA_queryAsControlUser($remove_query);
    }
    if ($cfgRelation['bookmarkwork']) {
        $remove_query = 'DELETE FROM ' . $common_functions->backquote($cfgRelation['db']) . '.' . $common_functions->backquote($cfgRelation['bookmark']) . ' WHERE dbase  = \'' . $common_functions->sqlAddSlashes($db) . '\'';
        PMA_queryAsControlUser($remove_query);
    }
    if ($cfgRelation['displaywork']) {
        $remove_query = 'DELETE FROM ' . $common_functions->backquote($cfgRelation['db']) . '.' . $common_functions->backquote($cfgRelation['table_info']) . ' WHERE db_name  = \'' . $common_functions->sqlAddSlashes($db) . '\'';
        PMA_queryAsControlUser($remove_query);
    }
    if ($cfgRelation['pdfwork']) {
        $remove_query = 'DELETE FROM ' . $common_functions->backquote($cfgRelation['db']) . '.' . $common_functions->backquote($cfgRelation['pdf_pages']) . ' WHERE db_name  = \'' . $common_functions->sqlAddSlashes($db) . '\'';
        PMA_queryAsControlUser($remove_query);
        $remove_query = 'DELETE FROM ' . $common_functions->backquote($cfgRelation['db']) . '.' . $common_functions->backquote($cfgRelation['table_coords']) . ' WHERE db_name  = \'' . $common_functions->sqlAddSlashes($db) . '\'';
        PMA_queryAsControlUser($remove_query);
    }
    if ($cfgRelation['designerwork']) {
        $remove_query = 'DELETE FROM ' . $common_functions->backquote($cfgRelation['db']) . '.' . $common_functions->backquote($cfgRelation['designer_coords']) . ' WHERE db_name  = \'' . $common_functions->sqlAddSlashes($db) . '\'';
        PMA_queryAsControlUser($remove_query);
    }
    if ($cfgRelation['relwork']) {
        $remove_query = 'DELETE FROM ' . $common_functions->backquote($cfgRelation['db']) . '.' . $common_functions->backquote($cfgRelation['relation']) . ' WHERE master_db  = \'' . $common_functions->sqlAddSlashes($db) . '\'';
        PMA_queryAsControlUser($remove_query);
        $remove_query = 'DELETE FROM ' . $common_functions->backquote($cfgRelation['db']) . '.' . $common_functions->backquote($cfgRelation['relation']) . ' WHERE foreign_db  = \'' . $common_functions->sqlAddSlashes($db) . '\'';
        PMA_queryAsControlUser($remove_query);
    }
}
    function testBuildActionTitles()
    {
        $titles = array();
        $common = PMA_CommonFunctions::getInstance();

        $titles['Browse']     = $common->getIcon('b_browse.png', __('Browse'));
        $titles['NoBrowse']   = $common->getIcon('bd_browse.png', __('Browse'));
        $titles['Search']     = $common->getIcon('b_select.png', __('Search'));
        $titles['NoSearch']   = $common->getIcon('bd_select.png', __('Search'));
        $titles['Insert']     = $common->getIcon('b_insrow.png', __('Insert'));
        $titles['NoInsert']   = $common->getIcon('bd_insrow.png', __('Insert'));
        $titles['Structure']  = $common->getIcon('b_props.png', __('Structure'));
        $titles['Drop']       = $common->getIcon('b_drop.png', __('Drop'));
        $titles['NoDrop']     = $common->getIcon('bd_drop.png', __('Drop'));
        $titles['Empty']      = $common->getIcon('b_empty.png', __('Empty'));
        $titles['NoEmpty']    = $common->getIcon('bd_empty.png', __('Empty'));
        $titles['Edit']       = $common->getIcon('b_edit.png', __('Edit'));
        $titles['NoEdit']     = $common->getIcon('bd_edit.png', __('Edit'));
        $titles['Export']     = $common->getIcon('b_export.png', __('Export'));
        $titles['NoExport']   = $common->getIcon('bd_export.png', __('Export'));
        $titles['Execute']    = $common->getIcon('b_nextpage.png', __('Execute'));
        $titles['NoExecute']  = $common->getIcon('bd_nextpage.png', __('Execute'));

        $this->assertEquals($titles, $common->buildActionTitles());

    }
Пример #8
0
/**
 * This function is called from one of the other functions in this file
 * and it completes the handling of the export functionality.
 *
 * @param string  $item_name    The name of the item that we are exporting
 * @param string  $export_data  The SQL query to create the requested item
 */
function PMA_RTE_handleExport($item_name, $export_data)
{
    global $db;
    $item_name = htmlspecialchars(PMA_CommonFunctions::getInstance()->backquote($_GET['item_name']));
    if ($export_data !== false) {
        $export_data = '<textarea cols="40" rows="15" style="width: 100%;">' . htmlspecialchars(trim($export_data)) . '</textarea>';
        $title = sprintf(PMA_RTE_getWord('export'), $item_name);
        if ($GLOBALS['is_ajax_request'] == true) {
            $response = PMA_Response::getInstance();
            $response->addJSON('message', $export_data);
            $response->addJSON('title', $title);
            exit;
        } else {
            echo "<fieldset>\n" . "<legend>{$title}</legend>\n" . $export_data . "</fieldset>\n";
        }
    } else {
        $_db = htmlspecialchars(PMA_CommonFunctions::getInstance()->backquote($db));
        $response = __('Error in Processing Request') . ' : ' . sprintf(PMA_RTE_getWord('not_found'), $item_name, $_db);
        $response = PMA_message::error($response);
        if ($GLOBALS['is_ajax_request'] == true) {
            $response = PMA_Response::getInstance();
            $response->isSuccess(false);
            $response->addJSON('message', $response);
            exit;
        } else {
            $response->display();
        }
    }
}
Пример #9
0
/**
 * Get SQL query for store new transformation details of a VIEW
 *
 * @param mysqli_result $pma_tranformation_data Result set of SQL execution
 * @param array         $column_map             Details of VIEW columns
 * @param string        $view_name              Name of the VIEW
 * @param string        $db                     Database name of the VIEW
 *
 * @return string $new_transformations_sql SQL query for new tranformations
 */
function PMA_getNewTransformationDataSql($pma_tranformation_data, $column_map, $view_name, $db)
{
    $common_functions = PMA_CommonFunctions::getInstance();
    $cfgRelation = PMA_getRelationsParam();
    // Need to store new transformation details for VIEW
    $new_transformations_sql = 'INSERT INTO ' . $common_functions->backquote($cfgRelation['db']) . '.' . $common_functions->backquote($cfgRelation['column_info']) . ' (`db_name`, `table_name`, `column_name`, `comment`, ' . '`mimetype`, `transformation`, `transformation_options`)' . ' VALUES ';
    $column_count = 0;
    $add_comma = false;
    while ($data_row = PMA_DBI_fetch_assoc($pma_tranformation_data)) {
        foreach ($column_map as $column) {
            if ($data_row['table_name'] == $column['table_name'] && $data_row['column_name'] == $column['refering_column']) {
                $new_transformations_sql .= $add_comma ? ', ' : '';
                $new_transformations_sql .= '(' . '\'' . $db . '\', ' . '\'' . $view_name . '\', ' . '\'';
                $new_transformations_sql .= isset($column['real_column']) ? $column['real_column'] : $column['refering_column'];
                $new_transformations_sql .= '\', ' . '\'' . $data_row['comment'] . '\', ' . '\'' . $data_row['mimetype'] . '\', ' . '\'' . $data_row['transformation'] . '\', ' . '\'' . $common_functions->sqlAddSlashes($data_row['transformation_options']) . '\')';
                $add_comma = true;
                $column_count++;
                break;
            }
        }
        if ($column_count == count($column_map)) {
            break;
        }
    }
    return $column_count > 0 ? $new_transformations_sql : '';
}
/**
* Prints details about the current Git commit revision
*
* @return void
*/
function PMA_printGitRevision()
{
    $common_functions = PMA_CommonFunctions::getInstance();
    if (!$GLOBALS['PMA_Config']->get('PMA_VERSION_GIT')) {
        $response = PMA_Response::getInstance();
        $response->isSuccess(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'), $common_functions->localisedDate(strtotime($committer['date'])), '<a href="' . PMA_linkURL('mailto:' . $committer['email']) . '">' . htmlspecialchars($committer['name']) . '</a>') . ($author != $committer ? ', <br />' . sprintf(__('authored on %1$s by %2$s'), $common_functions->localisedDate(strtotime($author['date'])), '<a href="' . PMA_linkURL('mailto:' . $author['email']) . '">' . htmlspecialchars($author['name']) . '</a>') : ''), 'li_pma_version_git', null, null, null);
}
    /**
     * @dataProvider dataProvider
     * @return void
     */
    function testMaximumUploadSize($size, $unit, $res)
    {
        $this->assertEquals(
            "(" . __('Max: '). $res . $unit .")",
            PMA_CommonFunctions::getInstance()->getFormattedMaximumUploadSize($size)
        );

    }
Пример #12
0
 /**
  * returns the pbxt engine specific handling for
  * PMA_ENGINE_DETAILS_TYPE_SIZE variables.
  *
  * @param string $formatted_size the size expression (for example 8MB)
  *
  * @return string the formatted value and its unit
  */
 function resolveTypeSize($formatted_size)
 {
     $common_functions = PMA_CommonFunctions::getInstance();
     if (preg_match('/^[0-9]+[a-zA-Z]+$/', $formatted_size)) {
         $value = $common_functions->extractValueFromFormattedSize($formatted_size);
     } else {
         $value = $formatted_size;
     }
     return $common_functions->formatByteDown($value);
 }
    function testGetCheckboxCheckedOnclick()
    {
        $name = "test_display_html_checkbox";
        $label = "text_label_for_checkbox";

        $this->assertEquals(
            PMA_CommonFunctions::getInstance()->getCheckbox($name, $label, true, true),
            '<input type="checkbox" name="' . $name . '" id="' . $name . '" checked="checked" class="autosubmit" /><label for="' . $name . '">' . $label . '</label>'
        );
    }
 /**
  * Test case for expanding strings with escaping
  *
  * @param string $in  string to evaluate
  * @param string $out expected output
  *
  * @return void
  *
  * @dataProvider provider
  */
 public function testExpandEscape($in, $out)
 {
     $out = str_replace('PMA_VERSION', PMA_VERSION, $out);
     $this->assertEquals(
         htmlspecialchars($out),
         PMA_CommonFunctions::getInstance()->expandUserString(
             $in, 'htmlspecialchars'
         )
     );
 }
Пример #15
0
/**
 * 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)
{
    if (is_string($a_string)) {
        $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_CommonFunctions::getInstance()->backquote($a_string) : $a_string;
}
/**
 * Saves user preferences
 *
 * @param array $config_array configuration array
 *
 * @return true|PMA_Message
 */
function PMA_save_userprefs(array $config_array)
{
    
    $common_functions = PMA_CommonFunctions::getInstance();
    $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 = $common_functions->backquote($cfgRelation['db']) . '.'
        . $common_functions->backquote($cfgRelation['userconfig']);
    $query = '
        SELECT `username`
        FROM ' . $query_table . '
          WHERE `username` = \'' . $common_functions->sqlAddSlashes($cfgRelation['user']) . '\'';

    $has_config = PMA_DBI_fetch_value($query, 0, 0, $GLOBALS['controllink']);
    $config_data = json_encode($config_array);
    if ($has_config) {
        $query = '
            UPDATE ' . $query_table . '
            SET `config_data` = \'' . $common_functions->sqlAddSlashes($config_data) . '\'
            WHERE `username` = \'' . $common_functions->sqlAddSlashes($cfgRelation['user']) . '\'';
    } else {
        $query = '
            INSERT INTO ' . $query_table . ' (`username`, `config_data`)
            VALUES (\'' . $common_functions->sqlAddSlashes($cfgRelation['user']) . '\',
                \'' . $common_functions->sqlAddSlashes($config_data) . '\')';
    }
    if (isset($_SESSION['cache'][$cache_key]['userprefs'])) {
        unset($_SESSION['cache'][$cache_key]['userprefs']);
    }
    if (!PMA_DBI_try_query($query, $GLOBALS['controllink'])) {
        $message = PMA_Message::error(__('Could not save configuration'));
        $message->addMessage('<br /><br />');
        $message->addMessage(
            PMA_Message::rawError(PMA_DBI_getError($GLOBALS['controllink']))
        );
        return $message;
    }
    return true;
}
Пример #17
0
    function testGetIconWithForceText()
    {
        $GLOBALS['cfg']['PropertiesIconic'] = true;
        $alternate_text = 'alt_str';

        $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_CommonFunctions::getInstance()->getIcon('b_comment.png', $alternate_text, true)
        );

    }
Пример #18
0
    function testShowDocu()
    {
        $anchor = "relation";
        $expected = '<a href="Documentation.html#' . $anchor . '" target="documentation">'
                  . '<img src="themes/dot.gif" title="' . __('Documentation') . '" '
                  . 'alt="' . __('Documentation') . '" class="icon ic_b_help" /></a>';

        $this->assertEquals(
            $expected, PMA_CommonFunctions::getInstance()->showDocu($anchor)
        );

    }
 /**
  * @dataProvider dataProvider
  * @return void
  */
 function testBrowseUploadFile($size, $unit, $res)
 {
     $this->assertEquals(
         PMA_CommonFunctions::getInstance()->getBrowseUploadFileBlock($size),
         '<label for="input_import_file">' . __("Browse your computer:") . '</label>'
         . '<div id="upload_form_status" style="display: none;"></div>'
         . '<div id="upload_form_status_info" style="display: none;"></div>'
         . '<input type="file" name="import_file" id="input_import_file" />'
         . "(" . __('Max: '). $res . $unit .")" . "\n"
         . '<input type="hidden" name="MAX_FILE_SIZE" value="' .$size . '" />' . "\n"
     );        
 }
/**
 * Displays for for language selection
 *
 * @access  public
 */
function PMA_select_language($use_fieldset = false, $show_doc = true)
{
    if (count($GLOBALS['available_languages']) == 1) {
        // no use in switching languages, there is only one available
        return;
    }
    global $cfg, $lang;
    ?>

<form method="post" action="index.php" target="_parent">
    <?php 
    $_form_params = array('db' => $GLOBALS['db'], 'table' => $GLOBALS['table']);
    echo PMA_generate_common_hidden_inputs($_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_CommonFunctions::getInstance()->showDocu('faq7_2');
    }
    if ($use_fieldset) {
        echo '<fieldset><legend lang="en" dir="ltr">' . $language_title . '</legend>';
    } else {
        echo '<bdo lang="en" dir="ltr"><label for="sel-lang">' . $language_title . ':</label></bdo>';
    }
    ?>

    <select name="lang" class="autosubmit" lang="en" dir="ltr" id="sel-lang">
    <?php 
    uasort($GLOBALS['available_languages'], 'PMA_language_cmp');
    foreach ($GLOBALS['available_languages'] as $id => $tmplang) {
        $lang_name = PMA_langName($tmplang);
        //Is current one active?
        if ($lang == $id) {
            $selected = ' selected="selected"';
        } else {
            $selected = '';
        }
        echo '        ';
        echo '<option value="' . $id . '"' . $selected . '>' . $lang_name . '</option>' . "\n";
    }
    ?>

    </select>
    <?php 
    if ($use_fieldset) {
        echo '</fieldset>';
    }
    ?>
</form>
    <?php 
}
    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 . '&amp;server=99&amp;lang=en&amp;token=token'
            . '" target="documentation"><img src="themes/dot.gif" title="'
            . __('Documentation') . '" alt="' . __('Documentation') . '" class="icon ic_b_help" /></a>';

        $this->assertEquals(
            $expected, PMA_CommonFunctions::getInstance()->showPHPDocu($target)
        );
    }
Пример #22
0
 function testGetDbLinkWithSpecialChars()
 {
     global $cfg;
     $database = 'test&data\'base';
     $this->assertEquals(
         '<a href="' . $cfg['DefaultTabDatabase'] . '?db='
         . htmlspecialchars(urlencode($database))
         . '&amp;server=99&amp;lang=en&amp;token=token" title="Jump to database &quot;'
         . htmlspecialchars($database) . '&quot;.">'
         . htmlspecialchars($database) . '</a>',
         PMA_CommonFunctions::getInstance()->getDbLink($database)
     );
 }
    function testGetDivForSliderEffectTestDisabled()
    {
        global $cfg;
        $cfg['InitialSlidersState'] = 'disabled';

        $id = "test_id";
        $message = "test_message";

        $this->assertEquals(
            PMA_CommonFunctions::getInstance()->getDivForSliderEffect($id, $message),
            '<div id="' . $id . '">'
        );
    }
Пример #24
0
 /**
  * This function must be named "Footer" to work with the TCPDF library
  */
 function Footer()
 {
     // Check if footer for this page already exists
     if (!isset($this->footerset[$this->page])) {
         $this->SetY(-15);
         $this->SetFont(PMA_PDF_FONT, '', 14);
         $this->Cell(0, 6, __('Page number:') . ' ' . $this->getAliasNumPage() . '/' . $this->getAliasNbPages(), 'T', 0, 'C');
         $this->Cell(0, 6, PMA_CommonFunctions::getInstance()->localisedDate(), 0, 1, 'R');
         $this->SetY(20);
         // set footerset
         $this->footerset[$this->page] = 1;
     }
 }
    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_CommonFunctions::getInstance()->checkParameters(
            array('db', 'table', 'field', 'sql_query')
        );
    }
Пример #26
0
    /**
     * @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()
    {
        $runkit = function_exists('runkit_constant_redefine');
        if ($runkit && defined('PMA_USR_OS')) {
            $pma_usr_os = PMA_USR_OS;
        }

        if (defined('PMA_USR_OS') && !$runkit) {

            if (PMA_USR_OS == 'Win') {
                $this->assertEquals(
                    "\r\n", PMA_CommonFunctions::getInstance()->whichCrlf()
                );
            } else {
                $this->assertEquals(
                    "\n", PMA_CommonFunctions::getInstance()->whichCrlf()
                );
            }

            $this->markTestIncomplete('Cannot redefine constant');

        } else {

            if ($runkit) {
                define('PMA_USR_OS', 'Linux');
                $this->assertEquals(
                    "\n", PMA_CommonFunctions::getInstance()->whichCrlf()
                );
            }

            if ($runkit) {
                runkit_constant_redefine('PMA_USR_OS', 'Win');
            } else {
                define('PMA_USR_OS', 'Win');
            }
            $this->assertEquals(
                "\r\n", PMA_CommonFunctions::getInstance()->whichCrlf()
            );

        }

        if ($runkit) {
            if (isset($pma_usr_os)) {
                runkit_constant_redefine('PMA_USR_OS', 'Win');
            } else {
                runkit_constant_remove('PMA_USR_OS');
            }
        }
    }
Пример #27
0
/**
 * Based on IP Pattern Matcher
 * Originally by J.Adams <*****@*****.**>
 * Found on <http://www.php.net/manual/en/function.ip2long.php>
 * Modified for phpMyAdmin
 *
 * Matches:
 * xxx.xxx.xxx.xxx        (exact)
 * xxx.xxx.xxx.[yyy-zzz]  (range)
 * xxx.xxx.xxx.xxx/nn     (CIDR)
 *
 * Does not match:
 * xxx.xxx.xxx.xx[yyy-zzz]  (range, partial octets not supported)
 *
 * @param string $testRange string of IP range to match
 * @param string $ipToTest  string of IP to test against range
 *
 * @return boolean    always true
 *
 * @access  public
 */
function PMA_ipMaskTest($testRange, $ipToTest)
{
    $result = true;
    $match = preg_match('|([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)/([0-9]+)|', $testRange, $regs);
    if ($match) {
        // performs a mask match
        $ipl = ip2long($ipToTest);
        $rangel = ip2long($regs[1] . '.' . $regs[2] . '.' . $regs[3] . '.' . $regs[4]);
        $maskl = 0;
        for ($i = 0; $i < 31; $i++) {
            if ($i < $regs[5] - 1) {
                $maskl = $maskl + PMA_CommonFunctions::getInstance()->pow(2, 30 - $i);
            }
            // end if
        }
        // end for
        if (($maskl & $rangel) == ($maskl & $ipl)) {
            return true;
        } else {
            return false;
        }
    } else {
        // range based
        $maskocts = explode('.', $testRange);
        $ipocts = explode('.', $ipToTest);
        // perform a range match
        for ($i = 0; $i < 4; $i++) {
            if (preg_match('|\\[([0-9]+)\\-([0-9]+)\\]|', $maskocts[$i], $regs)) {
                if ($ipocts[$i] > $regs[2] || $ipocts[$i] < $regs[1]) {
                    $result = false;
                }
                // end if
            } else {
                if ($maskocts[$i] != $ipocts[$i]) {
                    $result = false;
                }
                // end if
            }
            // end if/else
        }
        //end for
    }
    //end if/else
    return $result;
}
Пример #28
0
 /**
  * returns html tables with stats over inno db buffer pool
  *
  * @return string  html table with stats
  */
 function getPageBufferpool()
 {
     $common_functions = PMA_CommonFunctions::getInstance();
     // The following query is only possible because we know
     // that we are on MySQL 5 here (checked above)!
     // side note: I love MySQL 5 for this. :-)
     $sql = '
          SHOW STATUS
         WHERE Variable_name LIKE \'Innodb\\_buffer\\_pool\\_%\'
            OR Variable_name = \'Innodb_page_size\';';
     $status = PMA_DBI_fetch_result($sql, 0, 1);
     $output = '<table class="data" id="table_innodb_bufferpool_usage">' . "\n" . '    <caption class="tblHeaders">' . "\n" . '        ' . __('Buffer Pool Usage') . "\n" . '    </caption>' . "\n" . '    <tfoot>' . "\n" . '        <tr>' . "\n" . '            <th colspan="2">' . "\n" . '                ' . __('Total') . "\n" . '                : ' . $common_functions->formatNumber($status['Innodb_buffer_pool_pages_total'], 0) . '&nbsp;' . __('pages') . ' / ' . join('&nbsp;', $common_functions->formatByteDown($status['Innodb_buffer_pool_pages_total'] * $status['Innodb_page_size'])) . "\n" . '            </th>' . "\n" . '        </tr>' . "\n" . '    </tfoot>' . "\n" . '    <tbody>' . "\n" . '        <tr class="odd">' . "\n" . '            <th>' . __('Free pages') . '</th>' . "\n" . '            <td class="value">' . $common_functions->formatNumber($status['Innodb_buffer_pool_pages_free'], 0) . '</td>' . "\n" . '        </tr>' . "\n" . '        <tr class="even">' . "\n" . '            <th>' . __('Dirty pages') . '</th>' . "\n" . '            <td class="value">' . $common_functions->formatNumber($status['Innodb_buffer_pool_pages_dirty'], 0) . '</td>' . "\n" . '        </tr>' . "\n" . '        <tr class="odd">' . "\n" . '            <th>' . __('Pages containing data') . '</th>' . "\n" . '            <td class="value">' . $common_functions->formatNumber($status['Innodb_buffer_pool_pages_data'], 0) . "\n" . '</td>' . "\n" . '        </tr>' . "\n" . '        <tr class="even">' . "\n" . '            <th>' . __('Pages to be flushed') . '</th>' . "\n" . '            <td class="value">' . $common_functions->formatNumber($status['Innodb_buffer_pool_pages_flushed'], 0) . "\n" . '</td>' . "\n" . '        </tr>' . "\n" . '        <tr class="odd">' . "\n" . '            <th>' . __('Busy pages') . '</th>' . "\n" . '            <td class="value">' . $common_functions->formatNumber($status['Innodb_buffer_pool_pages_misc'], 0) . "\n" . '</td>' . "\n" . '        </tr>';
     // not present at least since MySQL 5.1.40
     if (isset($status['Innodb_buffer_pool_pages_latched'])) {
         $output .= '        <tr class="even">' . '            <th>' . __('Latched pages') . '</th>' . '            <td class="value">' . $common_functions->formatNumber($status['Innodb_buffer_pool_pages_latched'], 0) . '</td>' . '        </tr>';
     }
     $output .= '    </tbody>' . "\n" . '</table>' . "\n\n" . '<table class="data" id="table_innodb_bufferpool_activity">' . "\n" . '    <caption class="tblHeaders">' . "\n" . '        ' . __('Buffer Pool Activity') . "\n" . '    </caption>' . "\n" . '    <tbody>' . "\n" . '        <tr class="odd">' . "\n" . '            <th>' . __('Read requests') . '</th>' . "\n" . '            <td class="value">' . $common_functions->formatNumber($status['Innodb_buffer_pool_read_requests'], 0) . "\n" . '</td>' . "\n" . '        </tr>' . "\n" . '        <tr class="even">' . "\n" . '            <th>' . __('Write requests') . '</th>' . "\n" . '            <td class="value">' . $common_functions->formatNumber($status['Innodb_buffer_pool_write_requests'], 0) . "\n" . '</td>' . "\n" . '        </tr>' . "\n" . '        <tr class="odd">' . "\n" . '            <th>' . __('Read misses') . '</th>' . "\n" . '            <td class="value">' . $common_functions->formatNumber($status['Innodb_buffer_pool_reads'], 0) . "\n" . '</td>' . "\n" . '        </tr>' . "\n" . '        <tr class="even">' . "\n" . '            <th>' . __('Write waits') . '</th>' . "\n" . '            <td class="value">' . $common_functions->formatNumber($status['Innodb_buffer_pool_wait_free'], 0) . "\n" . '</td>' . "\n" . '        </tr>' . "\n" . '        <tr class="odd">' . "\n" . '            <th>' . __('Read misses in %') . '</th>' . "\n" . '            <td class="value">' . ($status['Innodb_buffer_pool_read_requests'] == 0 ? '---' : htmlspecialchars($common_functions->formatNumber($status['Innodb_buffer_pool_reads'] * 100 / $status['Innodb_buffer_pool_read_requests'], 3, 2)) . ' %') . "\n" . '</td>' . "\n" . '        </tr>' . "\n" . '        <tr class="even">' . "\n" . '            <th>' . __('Write waits in %') . '</th>' . "\n" . '            <td class="value">' . ($status['Innodb_buffer_pool_write_requests'] == 0 ? '---' : htmlspecialchars($common_functions->formatNumber($status['Innodb_buffer_pool_wait_free'] * 100 / $status['Innodb_buffer_pool_write_requests'], 3, 2)) . ' %') . "\n" . '</td>' . "\n" . '        </tr>' . "\n" . '    </tbody>' . "\n" . '</table>' . "\n";
     return $output;
 }
    function testShowMessageNotAjax()
    {
        global $cfg;

        $GLOBALS['is_ajax_request'] = true;
        $cfg['Server']['DisableIS'] = false;
        $GLOBALS['table'] = 'tbl';
        $GLOBALS['db'] = 'db';

        $_SESSION[' PMA_token '] = md5(uniqid(rand(), true));

        $GLOBALS['sql_query'] = "SELECT * FROM tblPatient ";

        $this->expectOutputString(
        "<script type=\"text/javascript\">
        //<![CDATA[
        if (window.parent.updateTableTitle) window.parent.updateTableTitle('db.tbl', ' ()');
        //]]>
        </script>
        <div id=\"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&amp;server=server&amp;lang=en&amp;token=647a62ad301bf9025e3b13bc7caa02cb\" 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&amp;table=tbl&amp;sql_query=SELECT+%2A+FROM+tblPatient+&amp;show_query=1&amp;server=server&amp;lang=en&amp;token=647a62ad301bf9025e3b13bc7caa02cb#querybox\" onclick=\"window.parent.focus_querywindow('SELECT * FROM tblPatient '); return false;\">Edit</a>
        ] [
        <a href=\"import.php?db=db&amp;table=tbl&amp;sql_query=EXPLAIN+SELECT+%2A+FROM+tblPatient+&amp;server=server&amp;lang=en&amp;token=647a62ad301bf9025e3b13bc7caa02cb\" >Explain SQL</a>
        ] [
        <a href=\"import.php?db=db&amp;table=tbl&amp;sql_query=SELECT+%2A+FROM+tblPatient+&amp;show_query=1&amp;show_as_php=1&amp;server=server&amp;lang=en&amp;token=647a62ad301bf9025e3b13bc7caa02cb\" >Create PHP Code</a>
        ] [
        <a href=\"import.php?db=db&amp;table=tbl&amp;sql_query=SELECT+%2A+FROM+tblPatient+&amp;show_query=1&amp;server=server&amp;lang=en&amp;token=647a62ad301bf9025e3b13bc7caa02cb\" >Refresh</a>
        ]</div></div>"
        );

        echo PMA_CommonFunctions::getInstance()->getMessage("msg");

        //$this->assertEquals("", PMA_CommonFunctions::getInstance()->getMessage("msg"));
        $this->assertTrue(true);
    }
Пример #30
0
/**
 * fills given tooltip arrays
 *
 * @param array &$tooltip_truename  tooltip data
 * @param array &$tooltip_aliasname tooltip data
 * @param array $table              tabledata
 *
 * @return void
 */
function PMA_fillTooltip(&$tooltip_truename, &$tooltip_aliasname, $table)
{
    $common_functions = PMA_CommonFunctions::getInstance();
    if (strstr($table['Comment'], '; InnoDB free') === false) {
        if (!strstr($table['Comment'], 'InnoDB free') === false) {
            // here we have just InnoDB generated part
            $table['Comment'] = '';
        }
    } else {
        // remove InnoDB comment from end, just the minimal part (*? is non greedy)
        $table['Comment'] = preg_replace('@; InnoDB free:.*?$@', '', $table['Comment']);
    }
    // views have VIEW as comment so it's not a real comment put by a user
    if ('VIEW' == $table['Comment']) {
        $table['Comment'] = '';
    }
    if (empty($table['Comment'])) {
        $table['Comment'] = $table['Name'];
    } else {
        // why?
        $table['Comment'] .= ' ';
    }
    if ($GLOBALS['cfg']['ShowTooltipAliasTB'] && $GLOBALS['cfg']['ShowTooltipAliasTB'] !== 'nested') {
        $tooltip_truename[$table['Name']] = $table['Comment'];
        $tooltip_aliasname[$table['Name']] = $table['Name'];
    } else {
        $tooltip_truename[$table['Name']] = $table['Name'];
        $tooltip_aliasname[$table['Name']] = $table['Comment'];
    }
    if (isset($table['Create_time']) && !empty($table['Create_time'])) {
        $tooltip_aliasname[$table['Name']] .= ', ' . __('Creation') . ': ' . $common_functions->localisedDate(strtotime($table['Create_time']));
    }
    if (!empty($table['Update_time'])) {
        $tooltip_aliasname[$table['Name']] .= ', ' . __('Last update') . ': ' . $common_functions->localisedDate(strtotime($table['Update_time']));
    }
    if (!empty($table['Check_time'])) {
        $tooltip_aliasname[$table['Name']] .= ', ' . __('Last check') . ': ' . $common_functions->localisedDate(strtotime($table['Check_time']));
    }
}