Пример #1
0
 /**
  * Test for PMA_Bookmark_getParams
  *
  * @return void
  */
 public function testPMA_Bookmark_getParams()
 {
     $this->assertEquals(
         false,
         PMA_Bookmark_getParams()
     );
 }
/**
 * Deletes a bookmark
 *
 * @uses    PMA_backquote()
 * @uses    PMA_sqlAddslashes()
 * @uses    PMA_DBI_try_query()
 * @uses    PMA_Bookmark_getParams()
 * @global  resource  the controluser db connection handle
 *
 * @param   string   the current database name
 * @param   integer  the id of the bookmark to get
 *
 * @access  public
 */
function PMA_Bookmark_delete($db, $id)
{
    global $controllink;
    $cfgBookmark = PMA_Bookmark_getParams();
    if (empty($cfgBookmark)) {
        return false;
    }
    $query = 'DELETE FROM ' . PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table']) . ' WHERE (user = \'' . PMA_sqlAddslashes($cfgBookmark['user']) . '\'' . '        OR user = \'\')' . ' AND id = ' . $id;
    return PMA_DBI_try_query($query, $controllink);
}
Пример #3
0
/**
 * Function to display results when the executed query returns non empty results
 *
 * @param array      $result               executed query results
 * @param array      $analyzed_sql_results analysed sql results
 * @param string     $db                   current database
 * @param string     $table                current table
 * @param string     $disp_mode            display mode
 * @param string     $message              message to show
 * @param array      $sql_data             sql data
 * @param object     $displayResultsObject Instance of DisplayResults.class
 * @param string     $goto                 goto page url
 * @param string     $pmaThemeImage        uri of the theme image
 * @param string     $sql_limit_to_append  sql limit to append
 * @param int        $unlim_num_rows       unlimited number of rows
 * @param int        $num_rows             number of rows
 * @param string     $full_sql_query       full sql query
 * @param string     $disp_query           display query
 * @param string     $disp_message         display message
 * @param array      $profiling_results    profiling results
 * @param string     $query_type           query type
 * @param array|null $selectedTables       array of table names selected from
 *                                         the database structure page, for an
 *                                         action like check table, optimize
 *                                         table, analyze table or repair table
 * @param string     $sql_query            sql query
 * @param string     $complete_query       complete sql query
 *
 * @return void
 */
function PMA_sendQueryResponseForResultsReturned($result, $analyzed_sql_results, $db, $table, $disp_mode, $message, $sql_data, $displayResultsObject, $goto, $pmaThemeImage, $sql_limit_to_append, $unlim_num_rows, $num_rows, $full_sql_query, $disp_query, $disp_message, $profiling_results, $query_type, $selectedTables, $sql_query, $complete_query)
{
    // If we are retrieving the full value of a truncated field or the original
    // value of a transformed field, show it here
    if (isset($_REQUEST['grid_edit']) && $_REQUEST['grid_edit'] == true) {
        PMA_sendResponseForGridEdit($result);
        // script has exited at this point
    }
    // Gets the list of fields properties
    if (isset($result) && $result) {
        $fields_meta = $GLOBALS['dbi']->getFieldsMeta($result);
    }
    // Should be initialized these parameters before parsing
    $showtable = isset($showtable) ? $showtable : null;
    $url_query = isset($url_query) ? $url_query : null;
    $response = PMA_Response::getInstance();
    $header = $response->getHeader();
    $scripts = $header->getScripts();
    // hide edit and delete links:
    // - for information_schema
    // - if the result set does not contain all the columns of a unique key
    //   (unless this is an updatable view)
    $sele_exp_cls = $analyzed_sql_results['analyzed_sql'][0]['select_expr_clause'];
    $updatableView = trim($sele_exp_cls) == '*' && PMA_Table::isUpdatableView($db, $table);
    $has_unique = PMA_resultSetContainsUniqueKey($db, $table, $fields_meta);
    $just_one_table = PMA_resultSetHasJustOneTable($fields_meta);
    $editable = ($has_unique || $updatableView) && $just_one_table;
    // Displays the results in a table
    if (empty($disp_mode)) {
        // see the "PMA_setDisplayMode()" function in
        // libraries/DisplayResults.class.php
        $disp_mode = 'urdr111101';
    }
    if (!empty($table) && ($GLOBALS['dbi']->isSystemSchema($db) || !$editable)) {
        $disp_mode = 'nnnn110111';
    }
    if (isset($_REQUEST['printview']) && $_REQUEST['printview'] == '1') {
        $disp_mode = 'nnnn000000';
    }
    if (isset($_REQUEST['table_maintenance'])) {
        $scripts->addFile('makegrid.js');
        $scripts->addFile('sql.js');
        $table_maintenance_html = '';
        if (isset($message)) {
            $message = PMA_Message::success($message);
            $table_maintenance_html = PMA_Util::getMessage($message, $GLOBALS['sql_query'], 'success');
        }
        $table_maintenance_html .= PMA_getHtmlForSqlQueryResultsTable(isset($sql_data) ? $sql_data : null, $displayResultsObject, $db, $goto, $pmaThemeImage, $url_query, $disp_mode, $sql_limit_to_append, false, $unlim_num_rows, $num_rows, $showtable, $result, $analyzed_sql_results);
        if (empty($sql_data) || ($sql_data['valid_queries'] = 1)) {
            $response->addHTML($table_maintenance_html);
            exit;
        }
    }
    if (!isset($_REQUEST['printview']) || $_REQUEST['printview'] != '1') {
        $scripts->addFile('makegrid.js');
        $scripts->addFile('sql.js');
        unset($GLOBALS['message']);
        //we don't need to buffer the output in getMessage here.
        //set a global variable and check against it in the function
        $GLOBALS['buffer_message'] = false;
    }
    $print_view_header_html = PMA_getHtmlForPrintViewHeader($db, $full_sql_query, $num_rows);
    $previous_update_query_html = PMA_getHtmlForPreviousUpdateQuery(isset($disp_query) ? $disp_query : null, $GLOBALS['cfg']['ShowSQL'], isset($sql_data) ? $sql_data : null, isset($disp_message) ? $disp_message : null);
    $profiling_chart_html = PMA_getHtmlForProfilingChart($disp_mode, $db, isset($profiling_results) ? $profiling_results : null);
    $missing_unique_column_msg = PMA_getMessageIfMissingColumnIndex($table, $db, $editable);
    $bookmark_created_msg = PMA_getBookmarkCreatedMessage();
    $table_html = PMA_getHtmlForSqlQueryResultsTable(isset($sql_data) ? $sql_data : null, $displayResultsObject, $db, $goto, $pmaThemeImage, $url_query, $disp_mode, $sql_limit_to_append, $editable, $unlim_num_rows, $num_rows, $showtable, $result, $analyzed_sql_results);
    $indexes_problems_html = PMA_getHtmlForIndexesProblems(isset($query_type) ? $query_type : null, isset($selectedTables) ? $selectedTables : null, $db);
    $cfgBookmark = PMA_Bookmark_getParams();
    if ($cfgBookmark) {
        $bookmark_support_html = PMA_getHtmlForBookmark($disp_mode, $cfgBookmark, $sql_query, $db, $table, isset($complete_query) ? $complete_query : $sql_query, $cfgBookmark['user']);
    } else {
        $bookmark_support_html = '';
    }
    $print_button_html = PMA_getHtmlForPrintButton();
    $html_output = isset($table_maintenance_html) ? $table_maintenance_html : '';
    $html_output .= isset($print_view_header_html) ? $print_view_header_html : '';
    $html_output .= PMA_getHtmlForSqlQueryResults($previous_update_query_html, $profiling_chart_html, $missing_unique_column_msg, $bookmark_created_msg, $table_html, $indexes_problems_html, $bookmark_support_html, $print_button_html);
    $response->addHTML($html_output);
    exit;
}
/**
 * return HTML for Sql Query Form Insert
 *
 * @param string $query     query to display in the textarea
 * @param string $delimiter default delimiter to use
 *
 * @return string
 *
 * @usedby  PMA_getHtmlForSqlQueryForm()
 */
function PMA_getHtmlForSqlQueryFormInsert($query = '', $delimiter = ';')
{
    // enable auto select text in textarea
    if ($GLOBALS['cfg']['TextareaAutoSelect']) {
        $auto_sel = ' onclick="selectContent(this, sql_box_locked, true);"';
    } else {
        $auto_sel = '';
    }
    $locking = '';
    $height = $GLOBALS['cfg']['TextareaRows'] * 2;
    $table = '';
    $db = '';
    $fields_list = array();
    if (!mb_strlen($GLOBALS['db'])) {
        // prepare for server related
        $legend = sprintf(__('Run SQL query/queries on server %s'), '"' . htmlspecialchars(!empty($GLOBALS['cfg']['Servers'][$GLOBALS['server']]['verbose']) ? $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['verbose'] : $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['host']) . '"');
    } elseif (!mb_strlen($GLOBALS['table'])) {
        // prepare for db related
        $db = $GLOBALS['db'];
        // if you want navigation:
        $tmp_db_link = '<a href="' . $GLOBALS['cfg']['DefaultTabDatabase'] . PMA_URL_getCommon(array('db' => $db)) . '"';
        $tmp_db_link .= '>' . htmlspecialchars($db) . '</a>';
        // else use
        // $tmp_db_link = htmlspecialchars($db);
        $legend = sprintf(__('Run SQL query/queries on database %s'), $tmp_db_link);
        if (empty($query)) {
            $query = PMA_Util::expandUserString($GLOBALS['cfg']['DefaultQueryDatabase'], 'backquote');
        }
    } else {
        $table = $GLOBALS['table'];
        $db = $GLOBALS['db'];
        // Get the list and number of fields
        // we do a try_query here, because we could be in the query window,
        // trying to synchronize and the table has not yet been created
        $fields_list = $GLOBALS['dbi']->getColumns($db, $GLOBALS['table'], null, true);
        $tmp_db_link = '<a href="' . $GLOBALS['cfg']['DefaultTabDatabase'] . PMA_URL_getCommon(array('db' => $db)) . '"';
        $tmp_db_link .= '>' . htmlspecialchars($db) . '</a>';
        // else use
        // $tmp_db_link = htmlspecialchars($db);
        $legend = sprintf(__('Run SQL query/queries on database %s'), $tmp_db_link);
        if (empty($query)) {
            $query = PMA_Util::expandUserString($GLOBALS['cfg']['DefaultQueryTable'], 'backquote');
        }
    }
    $legend .= ': ' . PMA_Util::showMySQLDocu('SELECT');
    if (count($fields_list)) {
        $sqlquerycontainer_id = 'sqlquerycontainer';
    } else {
        $sqlquerycontainer_id = 'sqlquerycontainerfull';
    }
    $html = '<a id="querybox"></a>' . '<div id="queryboxcontainer">' . '<fieldset id="queryboxf">';
    $html .= '<legend>' . $legend . '</legend>';
    $html .= '<div id="queryfieldscontainer">';
    $html .= '<div id="' . $sqlquerycontainer_id . '">' . '<textarea tabindex="100" name="sql_query" id="sqlquery"' . '  cols="' . $GLOBALS['cfg']['TextareaCols'] . '"' . '  rows="' . $height . '"' . '  dir="' . $GLOBALS['text_dir'] . '"' . $auto_sel . $locking . '>' . htmlspecialchars($query) . '</textarea>';
    // Add buttons to generate query easily for
    // select all, single select, insert, update and delete
    if (count($fields_list)) {
        $html .= '<input type="button" value="SELECT *" id="selectall"' . ' class="button sqlbutton" />';
        $html .= '<input type="button" value="SELECT" id="select"' . ' class="button sqlbutton" />';
        $html .= '<input type="button" value="INSERT" id="insert"' . ' class="button sqlbutton" />';
        $html .= '<input type="button" value="UPDATE" id="update"' . ' class="button sqlbutton" />';
        $html .= '<input type="button" value="DELETE" id="delete"' . ' class="button sqlbutton" />';
    }
    $html .= '<input type="button" value="' . __('Clear') . '" id="clear"' . ' class="button sqlbutton" />';
    $html .= '</div>' . "\n";
    if (count($fields_list)) {
        $html .= '<div id="tablefieldscontainer">' . '<label>' . __('Columns') . '</label>' . '<select id="tablefields" name="dummy" ' . 'size="' . ($GLOBALS['cfg']['TextareaRows'] - 2) . '" ' . 'multiple="multiple" ondblclick="insertValueQuery()">';
        foreach ($fields_list as $field) {
            $html .= '<option value="' . PMA_Util::backquote(htmlspecialchars($field['Field'])) . '"';
            if (isset($field['Field']) && mb_strlen($field['Field']) && isset($field['Comment'])) {
                $html .= ' title="' . htmlspecialchars($field['Comment']) . '"';
            }
            $html .= '>' . htmlspecialchars($field['Field']) . '</option>' . "\n";
        }
        $html .= '</select>' . '<div id="tablefieldinsertbuttoncontainer">';
        if (PMA_Util::showIcons('ActionLinksMode')) {
            $html .= '<input type="button" class="button" name="insert"' . ' value="&lt;&lt;" onclick="insertValueQuery()"' . ' title="' . __('Insert') . '" />';
        } else {
            $html .= '<input type="button" class="button" name="insert"' . ' value="' . __('Insert') . '"' . ' onclick="insertValueQuery()" />';
        }
        $html .= '</div>' . "\n" . '</div>' . "\n";
    }
    $html .= '<div class="clearfloat"></div>' . "\n";
    $html .= '</div>' . "\n";
    $cfgBookmark = PMA_Bookmark_getParams();
    if ($cfgBookmark) {
        $html .= '<div id="bookmarkoptions">';
        $html .= '<div class="formelement">';
        $html .= '<label for="bkm_label">' . __('Bookmark this SQL query:') . '</label>';
        $html .= '<input type="text" name="bkm_label" id="bkm_label"' . ' tabindex="110" value="" />';
        $html .= '</div>';
        $html .= '<div class="formelement">';
        $html .= '<input type="checkbox" name="bkm_all_users" tabindex="111"' . ' id="id_bkm_all_users" value="true" />';
        $html .= '<label for="id_bkm_all_users">' . __('Let every user access this bookmark') . '</label>';
        $html .= '</div>';
        $html .= '<div class="formelement">';
        $html .= '<input type="checkbox" name="bkm_replace" tabindex="112"' . ' id="id_bkm_replace" value="true" />';
        $html .= '<label for="id_bkm_replace">' . __('Replace existing bookmark of same name') . '</label>';
        $html .= '</div>';
        $html .= '</div>';
    }
    $html .= '<div class="clearfloat"></div>' . "\n";
    $html .= '</fieldset>' . "\n" . '</div>' . "\n";
    $html .= '<fieldset id="queryboxfooter" class="tblFooters">' . "\n";
    $html .= '<div class="formelement">' . "\n";
    $html .= '</div>' . "\n";
    $html .= '<div class="formelement">' . "\n";
    $html .= '<label for="id_sql_delimiter">[ ' . __('Delimiter') . '</label>' . "\n";
    $html .= '<input type="text" name="sql_delimiter" tabindex="131" size="3" ' . 'value="' . $delimiter . '" ' . 'id="id_sql_delimiter" /> ]';
    $html .= '<input type="checkbox" name="show_query" value="1" ' . 'id="checkbox_show_query" tabindex="132" checked="checked" />' . '<label for="checkbox_show_query">' . __('Show this query here again') . '</label>';
    $html .= '<input type="checkbox" name="retain_query_box" value="1" ' . 'id="retain_query_box" tabindex="133" ' . ($GLOBALS['cfg']['RetainQueryBox'] === false ? '' : ' checked="checked"') . ' />' . '<label for="retain_query_box">' . __('Retain query box') . '</label>';
    $html .= '<input type="checkbox" name="rollback_query" value="1" ' . 'id="rollback_query" tabindex="134" />' . '<label for="rollback_query">' . __('Rollback when finished') . '</label>';
    $html .= '</div>' . "\n";
    $html .= '<input type="submit" id="button_submit_query" name="SQL"';
    $html .= ' tabindex="200" value="' . __('Go') . '" />' . "\n";
    $html .= '<div class="clearfloat"></div>' . "\n";
    $html .= '</fieldset>' . "\n";
    return $html;
}
Пример #5
0
/**
 * Deletes a bookmark
 *
 * @param integer $id the id of the bookmark to delete
 *
 * @return bool true if successful
 *
 * @access  public
 *
 * @global  resource $controllink the controluser db connection handle
 */
function PMA_Bookmark_delete($id)
{
    global $controllink;
    $cfgBookmark = PMA_Bookmark_getParams();
    if (empty($cfgBookmark)) {
        return false;
    }
    $query = 'DELETE FROM ' . PMA_Util::backquote($cfgBookmark['db']) . '.' . PMA_Util::backquote($cfgBookmark['table']) . ' WHERE (user = \'' . PMA_Util::sqlAddSlashes($cfgBookmark['user']) . '\'' . '        OR user = \'\')' . ' AND id = ' . $id;
    return $GLOBALS['dbi']->tryQuery($query, $controllink);
}
/**
 * return HTML for Sql Query Form Insert
 *
 * @param string $query     query to display in the textarea
 * @param string $delimiter default delimiter to use
 *
 * @return string
 *
 * @usedby  PMA_getHtmlForSqlQueryForm()
 */
function PMA_getHtmlForSqlQueryFormInsert($query = '', $delimiter = ';')
{
    // enable auto select text in textarea
    if ($GLOBALS['cfg']['TextareaAutoSelect']) {
        $auto_sel = ' onclick="selectContent(this, sql_box_locked, true);"';
    } else {
        $auto_sel = '';
    }
    $locking = '';
    $height = $GLOBALS['cfg']['TextareaRows'] * 2;
    list($legend, $query, $columns_list) = PMA_initQueryForm($query);
    if (!empty($columns_list)) {
        $sqlquerycontainer_id = 'sqlquerycontainer';
    } else {
        $sqlquerycontainer_id = 'sqlquerycontainerfull';
    }
    $html = '<a id="querybox"></a>' . '<div id="queryboxcontainer">' . '<fieldset id="queryboxf">';
    $html .= '<legend>' . $legend . '</legend>';
    $html .= '<div id="queryfieldscontainer">';
    $html .= '<div id="' . $sqlquerycontainer_id . '">' . '<textarea tabindex="100" name="sql_query" id="sqlquery"' . '  cols="' . $GLOBALS['cfg']['TextareaCols'] . '"' . '  rows="' . $height . '"' . '  dir="' . $GLOBALS['text_dir'] . '"' . $auto_sel . $locking . '>' . htmlspecialchars($query) . '</textarea>';
    $html .= '<div id="querymessage"></div>';
    // Add buttons to generate query easily for
    // select all, single select, insert, update and delete
    if (!empty($columns_list)) {
        $html .= '<input type="button" value="SELECT *" id="selectall"' . ' class="button sqlbutton" />';
        $html .= '<input type="button" value="SELECT" id="select"' . ' class="button sqlbutton" />';
        $html .= '<input type="button" value="INSERT" id="insert"' . ' class="button sqlbutton" />';
        $html .= '<input type="button" value="UPDATE" id="update"' . ' class="button sqlbutton" />';
        $html .= '<input type="button" value="DELETE" id="delete"' . ' class="button sqlbutton" />';
    }
    $html .= '<input type="button" value="' . __('Clear') . '" id="clear"' . ' class="button sqlbutton" />';
    if ($GLOBALS['cfg']['CodemirrorEnable']) {
        $html .= '<input type="button" value="' . __('Format') . '" id="format"' . ' class="button sqlbutton" />';
    }
    $html .= '<input type="button" value="' . __('Get auto-saved query') . '" id="saved"' . ' class="button sqlbutton" />';
    // Disable/Enable foreign key checks
    $html .= '<div>';
    $html .= PMA_Util::getFKCheckbox();
    $html .= '</div>';
    // parameter binding
    $html .= '<div>';
    $html .= '<input type="checkbox" name="parameterized" id="parameterized" />';
    $html .= '<label for="parameterized">' . __('Bind parameters') . '</label>';
    $html .= '<div id="parametersDiv"></div>';
    $html .= '</div>';
    $html .= '</div>' . "\n";
    if (!empty($columns_list)) {
        $html .= '<div id="tablefieldscontainer">' . '<label>' . __('Columns') . '</label>' . '<select id="tablefields" name="dummy" ' . 'size="' . ($GLOBALS['cfg']['TextareaRows'] - 2) . '" ' . 'multiple="multiple" ondblclick="insertValueQuery()">';
        foreach ($columns_list as $field) {
            $html .= '<option value="' . PMA_Util::backquote(htmlspecialchars($field['Field'])) . '"';
            if (isset($field['Field']) && mb_strlen($field['Field']) && isset($field['Comment'])) {
                $html .= ' title="' . htmlspecialchars($field['Comment']) . '"';
            }
            $html .= '>' . htmlspecialchars($field['Field']) . '</option>' . "\n";
        }
        $html .= '</select>' . '<div id="tablefieldinsertbuttoncontainer">';
        if (PMA_Util::showIcons('ActionLinksMode')) {
            $html .= '<input type="button" class="button" name="insert"' . ' value="&lt;&lt;" onclick="insertValueQuery()"' . ' title="' . __('Insert') . '" />';
        } else {
            $html .= '<input type="button" class="button" name="insert"' . ' value="' . __('Insert') . '"' . ' onclick="insertValueQuery()" />';
        }
        $html .= '</div>' . "\n" . '</div>' . "\n";
    }
    $html .= '<div class="clearfloat"></div>' . "\n";
    $html .= '</div>' . "\n";
    $cfgBookmark = PMA_Bookmark_getParams();
    if ($cfgBookmark) {
        $html .= '<div id="bookmarkoptions">';
        $html .= '<div class="formelement">';
        $html .= '<label for="bkm_label">' . __('Bookmark this SQL query:') . '</label>';
        $html .= '<input type="text" name="bkm_label" id="bkm_label"' . ' tabindex="110" value="" />';
        $html .= '</div>';
        $html .= '<div class="formelement">';
        $html .= '<input type="checkbox" name="bkm_all_users" tabindex="111"' . ' id="id_bkm_all_users" value="true" />';
        $html .= '<label for="id_bkm_all_users">' . __('Let every user access this bookmark') . '</label>';
        $html .= '</div>';
        $html .= '<div class="formelement">';
        $html .= '<input type="checkbox" name="bkm_replace" tabindex="112"' . ' id="id_bkm_replace" value="true" />';
        $html .= '<label for="id_bkm_replace">' . __('Replace existing bookmark of same name') . '</label>';
        $html .= '</div>';
        $html .= '</div>';
    }
    $html .= '<div class="clearfloat"></div>' . "\n";
    $html .= '</fieldset>' . "\n" . '</div>' . "\n";
    $html .= '<fieldset id="queryboxfooter" class="tblFooters">' . "\n";
    $html .= '<div class="formelement">' . "\n";
    $html .= '</div>' . "\n";
    $html .= '<div class="formelement">' . "\n";
    $html .= '<label for="id_sql_delimiter">[ ' . __('Delimiter') . '</label>' . "\n";
    $html .= '<input type="text" name="sql_delimiter" tabindex="131" size="3" ' . 'value="' . $delimiter . '" ' . 'id="id_sql_delimiter" /> ]';
    $html .= '<input type="checkbox" name="show_query" value="1" ' . 'id="checkbox_show_query" tabindex="132" checked="checked" />' . '<label for="checkbox_show_query">' . __('Show this query here again') . '</label>';
    $html .= '<input type="checkbox" name="retain_query_box" value="1" ' . 'id="retain_query_box" tabindex="133" ' . ($GLOBALS['cfg']['RetainQueryBox'] === false ? '' : ' checked="checked"') . ' />' . '<label for="retain_query_box">' . __('Retain query box') . '</label>';
    $html .= '<input type="checkbox" name="rollback_query" value="1" ' . 'id="rollback_query" tabindex="134" />' . '<label for="rollback_query">' . __('Rollback when finished') . '</label>';
    $html .= '</div>' . "\n";
    $html .= '<input type="submit" id="button_submit_query" name="SQL"';
    $html .= ' tabindex="200" value="' . __('Go') . '" />' . "\n";
    $html .= '<div class="clearfloat"></div>' . "\n";
    $html .= '</fieldset>' . "\n";
    return $html;
}
Пример #7
0
/**
 * Function to display results when the executed query returns non empty results
 *
 * @param object         $result               executed query results
 * @param array          $analyzed_sql_results analysed sql results
 * @param string         $db                   current database
 * @param string         $table                current table
 * @param string         $message              message to show
 * @param array          $sql_data             sql data
 * @param DisplayResults $displayResultsObject Instance of DisplayResults
 * @param string         $pmaThemeImage        uri of the theme image
 * @param int            $unlim_num_rows       unlimited number of rows
 * @param int            $num_rows             number of rows
 * @param string         $disp_query           display query
 * @param string         $disp_message         display message
 * @param array          $profiling_results    profiling results
 * @param string         $query_type           query type
 * @param array|null     $selectedTables       array of table names selected
 *                                             from the database structure page, for
 *                                             an action like check table,
 *                                             optimize table, analyze table or
 *                                             repair table
 * @param string         $sql_query            sql query
 * @param string         $complete_query       complete sql query
 *
 * @return string html
 */
function PMA_getQueryResponseForResultsReturned($result, $analyzed_sql_results, $db, $table, $message, $sql_data, $displayResultsObject, $pmaThemeImage, $unlim_num_rows, $num_rows, $disp_query, $disp_message, $profiling_results, $query_type, $selectedTables, $sql_query, $complete_query)
{
    // If we are retrieving the full value of a truncated field or the original
    // value of a transformed field, show it here
    if (isset($_REQUEST['grid_edit']) && $_REQUEST['grid_edit'] == true) {
        PMA_sendResponseForGridEdit($result);
        // script has exited at this point
    }
    // Gets the list of fields properties
    if (isset($result) && $result) {
        $fields_meta = $GLOBALS['dbi']->getFieldsMeta($result);
    }
    // Should be initialized these parameters before parsing
    $showtable = isset($showtable) ? $showtable : null;
    $url_query = isset($url_query) ? $url_query : null;
    $response = PMA\libraries\Response::getInstance();
    $header = $response->getHeader();
    $scripts = $header->getScripts();
    // hide edit and delete links:
    // - for information_schema
    // - if the result set does not contain all the columns of a unique key
    //   (unless this is an updatable view)
    $updatableView = false;
    $statement = $analyzed_sql_results['statement'];
    if ($statement instanceof SqlParser\Statements\SelectStatement) {
        if (!empty($statement->expr)) {
            if ($statement->expr[0]->expr === '*') {
                $_table = new Table($table, $db);
                $updatableView = $_table->isUpdatableView();
            }
        }
    }
    $has_unique = PMA_resultSetContainsUniqueKey($db, $table, $fields_meta);
    $just_one_table = PMA_resultSetHasJustOneTable($fields_meta);
    $editable = ($has_unique || $GLOBALS['cfg']['RowActionLinksWithoutUnique'] || $updatableView) && $just_one_table;
    $displayParts = array('edit_lnk' => $displayResultsObject::UPDATE_ROW, 'del_lnk' => $displayResultsObject::DELETE_ROW, 'sort_lnk' => '1', 'nav_bar' => '1', 'bkm_form' => '1', 'text_btn' => '0', 'pview_lnk' => '1');
    if (!empty($table) && ($GLOBALS['dbi']->isSystemSchema($db) || !$editable)) {
        $displayParts = array('edit_lnk' => $displayResultsObject::NO_EDIT_OR_DELETE, 'del_lnk' => $displayResultsObject::NO_EDIT_OR_DELETE, 'sort_lnk' => '1', 'nav_bar' => '1', 'bkm_form' => '1', 'text_btn' => '1', 'pview_lnk' => '1');
    }
    if (isset($_REQUEST['printview']) && $_REQUEST['printview'] == '1') {
        $displayParts = array('edit_lnk' => $displayResultsObject::NO_EDIT_OR_DELETE, 'del_lnk' => $displayResultsObject::NO_EDIT_OR_DELETE, 'sort_lnk' => '0', 'nav_bar' => '0', 'bkm_form' => '0', 'text_btn' => '0', 'pview_lnk' => '0');
    }
    if (isset($_REQUEST['table_maintenance'])) {
        $scripts->addFile('makegrid.js');
        $scripts->addFile('sql.js');
        $table_maintenance_html = '';
        if (isset($message)) {
            $message = Message::success($message);
            $table_maintenance_html = PMA\libraries\Util::getMessage($message, $GLOBALS['sql_query'], 'success');
        }
        $table_maintenance_html .= PMA_getHtmlForSqlQueryResultsTable($displayResultsObject, $pmaThemeImage, $url_query, $displayParts, false, $unlim_num_rows, $num_rows, $showtable, $result, $analyzed_sql_results);
        if (empty($sql_data) || ($sql_data['valid_queries'] = 1)) {
            $response->addHTML($table_maintenance_html);
            exit;
        }
    }
    if (!isset($_REQUEST['printview']) || $_REQUEST['printview'] != '1') {
        $scripts->addFile('makegrid.js');
        $scripts->addFile('sql.js');
        unset($GLOBALS['message']);
        //we don't need to buffer the output in getMessage here.
        //set a global variable and check against it in the function
        $GLOBALS['buffer_message'] = false;
    }
    $previous_update_query_html = PMA_getHtmlForPreviousUpdateQuery(isset($disp_query) ? $disp_query : null, $GLOBALS['cfg']['ShowSQL'], isset($sql_data) ? $sql_data : null, isset($disp_message) ? $disp_message : null);
    $profiling_chart_html = PMA_getHtmlForProfilingChart($url_query, $db, isset($profiling_results) ? $profiling_results : array());
    $missing_unique_column_msg = PMA_getMessageIfMissingColumnIndex($table, $db, $editable, $has_unique);
    $bookmark_created_msg = PMA_getBookmarkCreatedMessage();
    $table_html = PMA_getHtmlForSqlQueryResultsTable($displayResultsObject, $pmaThemeImage, $url_query, $displayParts, $editable, $unlim_num_rows, $num_rows, $showtable, $result, $analyzed_sql_results);
    $indexes_problems_html = PMA_getHtmlForIndexesProblems(isset($query_type) ? $query_type : null, isset($selectedTables) ? $selectedTables : null, $db);
    $cfgBookmark = PMA_Bookmark_getParams();
    if ($cfgBookmark) {
        $bookmark_support_html = PMA_getHtmlForBookmark($displayParts, $cfgBookmark, $sql_query, $db, $table, isset($complete_query) ? $complete_query : $sql_query, $cfgBookmark['user']);
    } else {
        $bookmark_support_html = '';
    }
    $html_output = isset($table_maintenance_html) ? $table_maintenance_html : '';
    $html_output .= PMA_getHtmlForSqlQueryResults($previous_update_query_html, $profiling_chart_html, $missing_unique_column_msg, $bookmark_created_msg, $table_html, $indexes_problems_html, $bookmark_support_html);
    return $html_output;
}
Пример #8
0
    }
    if (!isset($ajax_reload)) {
        $ajax_reload = array();
    }
    if (isset($table)) {
        $ajax_reload['table_name'] = $table;
    }
    $response = PMA_Response::getInstance();
    $response->addJSON('ajax_reload', $ajax_reload);
    $response->addHTML($html_output);
    exit;
} else {
    if ($result) {
        // Save a Bookmark with more than one queries (if Bookmark label given).
        if (!empty($_POST['bkm_label']) && !empty($import_text)) {
            $cfgBookmark = PMA_Bookmark_getParams();
            PMA_storeTheQueryAsBookmark($db, $cfgBookmark['user'], $_REQUEST['sql_query'], $_POST['bkm_label'], isset($_POST['bkm_replace']) ? $_POST['bkm_replace'] : null);
        }
        $response = PMA_Response::getInstance();
        $response->isSuccess(true);
        $response->addJSON('message', PMA_Message::success($msg));
        $response->addJSON('sql_query', PMA_Util::getMessage($msg, $sql_query, 'success'));
    } else {
        if ($result == false) {
            $response = PMA_Response::getInstance();
            $response->isSuccess(false);
            $response->addJSON('message', PMA_Message::error($msg));
        } else {
            $active_page = $goto;
            include '' . $goto;
        }
Пример #9
0
 /**
  * Renders the console
  *
  * @access public
  * @return string
  */
 public function getDisplay()
 {
     $output = '';
     if (!$this->_isAjax && $this->_isEnabled) {
         $cfgBookmark = PMA_Bookmark_getParams();
         $output .= '<div id="pma_console_container"><div id="pma_console">';
         // The templates, use sprintf() to output them
         // There're white space at the end of every <span>,
         // for double-click selection
         $tpl_query_actions = '<span class="action collapse">' . __('Collapse') . '</span> ' . '<span class="action expand">' . __('Expand') . '</span> ' . '<span class="action requery">' . __('Requery') . '</span> ' . '<span class="action edit">' . __('Edit') . '</span> ' . '<span class="action explain">' . __('Explain') . '</span> ' . '<span class="action profiling">' . __('Profiling') . '</span> ' . ($cfgBookmark ? '<span class="action bookmark">' . __('Bookmark') . '</span> ' : '') . '<span class="text failed">' . __('Query failed') . '</span> ' . '<span class="text targetdb">' . __('Database') . ': <span>%s</span></span> ' . '<span class="text query_time">' . __('Queried time') . ': <span>%s</span></span> ';
         // Console toolbar
         $output .= '<div class="toolbar collapsed">';
         $output .= '<div class="switch_button console_switch">';
         $output .= PMA_Util::getImage('console.png', __('SQL Query Console'));
         $output .= '<span>' . __('Console') . '</span></div>';
         $output .= '<div class="button clear"><span>' . __('Clear') . '</span></div>';
         $output .= '<div class="button history"><span>' . __('History') . '</span></div>';
         $output .= '<div class="button options"><span>' . __('Options') . '</span></div>';
         if ($cfgBookmark) {
             $output .= '<div class="button bookmarks"><span>' . __('Bookmarks') . '</span></div>';
         }
         $output .= '<div class="button debug hide"><span>' . __('Debug SQL') . '</span></div>';
         $output .= '</div>';
         // Toolbar end
         // Console messages
         $output .= '<div class="content">';
         $output .= '<div class="console_message_container">' . '<div class="message welcome"><span>' . '<span id="instructions-0">' . __('Press Ctrl+Enter to execute query') . '</span>' . '<span class="hide" id="instructions-1">' . __('Press Enter to execute query') . '</span>' . '</span></div>';
         $output .= $this->_getHistory($tpl_query_actions);
         $output .= '</div>';
         // .console_message_container
         $output .= '<div class="query_input">' . '<span class="console_query_input"></span>' . '</div>';
         $output .= '</div>';
         // Messages end
         // Dark the console while other cards cover it
         $output .= '<div class="mid_layer"></div>';
         // Debug SQL card
         $output .= '<div class="card" id="debug_console">';
         $output .= '<div class="toolbar">' . '<div class="button order order_asc">' . '<span>' . __('ascending') . '</span>' . '</div>' . '<div class="button order order_desc">' . '<span>' . __('descending') . '</span>' . '</div>' . '<div class="text">' . '<span>' . __('Order:') . '</span>' . '</div>' . '<div class="switch_button">' . '<span>' . __('Debug SQL') . '</span>' . '</div>' . '<div class="button order_by sort_count">' . '<span>' . __('Count') . '</span>' . '</div>' . '<div class="button order_by sort_exec">' . '<span>' . __('Execution order') . '</span>' . '</div>' . '<div class="button order_by sort_time">' . '<span>' . __('Time taken') . '</span>' . '</div>' . '<div class="text">' . '<span>' . __('Order by:') . '</span>' . '</div>' . '<div class="button group_queries">' . '<span>' . __('Group queries') . '</span>' . '</div>' . '<div class="button ungroup_queries">' . '<span>' . __('Ungroup queries') . '</span>' . '</div>' . '</div>';
         // Toolbar
         $output .= '<div class="content debug">';
         $output .= '<div class="message welcome"></div>';
         $output .= '<div class="debugLog"></div>';
         $output .= '</div>';
         // Content
         $output .= '<div class="templates">' . '<div class="debug_query action_content">' . '<span class="action collapse">' . __('Collapse') . '</span> ' . '<span class="action expand">' . __('Expand') . '</span> ' . '<span class="action dbg_show_trace">' . __('Show trace') . '</span> ' . '<span class="action dbg_hide_trace">' . __('Hide trace') . '</span> ' . '<span class="text count hide">' . __('Count:') . ' <span></span></span>' . '<span class="text time">' . __('Time taken:') . ' <span></span></span>' . '</div>' . '</div>';
         // Template
         $output .= '</div>';
         // Debug SQL card
         // Bookmarks card:
         if ($cfgBookmark) {
             $output .= '<div class="card" id="pma_bookmarks">';
             $output .= '<div class="toolbar">' . '<div class="switch_button"><span>' . __('Bookmarks') . '</span></div>';
             $output .= '<div class="button refresh"><span>' . __('Refresh') . '</span></div>';
             $output .= '<div class="button add"><span>' . __('Add') . '</span></div>';
             $output .= '</div><div class="content bookmark">';
             $output .= $this->getBookmarkContent();
             $output .= '</div>';
             $output .= '<div class="mid_layer"></div>';
             $output .= '<div class="card add">';
             $output .= '<div class="toolbar">' . '<div class="switch_button"><span>' . __('Add bookmark') . '</span></div>';
             $output .= '</div><div class="content add_bookmark">' . '<div class="options">' . '<label>' . __('Label') . ': <input type="text" name="label"></label> ' . '<label>' . __('Target database') . ': <input type="text" name="targetdb"></label> ' . '<label><input type="checkbox" name="shared">' . __('Share this bookmark') . '</label>' . '<button type="submit" name="submit">Ok</button>' . '</div>' . '<div class="query_input">' . '<span class="bookmark_add_input"></span></div>';
             $output .= '</div>';
             $output .= '</div>';
             // Add bookmark card
             $output .= '</div>';
             // Bookmarks card
         }
         // Options card:
         $output .= '<div class="card" id="pma_console_options">';
         $output .= '<div class="toolbar">' . '<div class="switch_button"><span>' . __('Options') . '</span></div>';
         $output .= '<div class="button default"><span>' . __('Set default') . '</span></div>';
         $output .= '</div><div class="content">' . '<label><input type="checkbox" name="always_expand">' . __('Always expand query messages') . '</label><br>' . '<label><input type="checkbox" name="start_history">' . __('Show query history at start') . '</label><br>' . '<label><input type="checkbox" name="current_query">' . __('Show current browsing query') . '</label><br>' . '<label><input type="checkbox" name="enter_executes">' . __('Execute queries on Enter and insert new line with Shift + ' . 'Enter. To make this permanent, view settings.') . '</label><br>' . '<label><input type="checkbox" name="dark_theme">' . __('Switch to dark theme') . '</label><br>' . '</div>';
         $output .= '</div>';
         // Options card
         $output .= '<div class="templates">' . '<div class="query_actions">' . sprintf($tpl_query_actions, '', '') . '</div>' . '</div>';
         $output .= '</div></div>';
         // #console and #pma_console_container ends
     }
     return $output;
 }
 /**
  * Renders the console
  *
  * @access public
  * @return string
  */
 public function getDisplay()
 {
     $output = '';
     if (!$this->_isAjax && $this->_isEnabled) {
         $cfgBookmark = PMA_Bookmark_getParams();
         $output .= '<div id="pma_console_container"><div id="pma_console">';
         // The templates, use sprintf() to output them
         // There're white space at the end of every <span>,
         // for double-click selection
         $tpl_query_actions = '<span class="action collapse">' . __('Collapse') . '</span> ' . '<span class="action expand">' . __('Expand') . '</span> ' . '<span class="action requery">' . __('Requery') . '</span> ' . '<span class="action edit">' . __('Edit') . '</span> ' . '<span class="action explain">' . __('Explain') . '</span> ' . '<span class="action profiling">' . __('Profiling') . '</span> ' . ($cfgBookmark ? '<span class="action bookmark">' . __('Bookmark') . '</span> ' : '') . '<span class="text failed">' . __('Query failed') . '</span> ' . '<span class="text targetdb">' . __('Database') . ': <span>%s</span></span> ' . '<span class="text query_time">' . __('Queried time') . ': <span>%s</span></span> ';
         // Console toolbar
         $output .= '<div class="toolbar collapsed">';
         $output .= '<div class="switch_button console_switch">';
         $output .= PMA_Util::getImage('console.png', __('SQL Query Console'));
         $output .= '<span>' . __('Console') . '</span></div>';
         $output .= '<div class="button clear"><span>' . __('Clear') . '</span></div>';
         $output .= '<div class="button history"><span>' . __('History') . '</span></div>';
         $output .= '<div class="button options"><span>' . __('Options') . '</span></div>';
         if ($cfgBookmark) {
             $output .= '<div class="button bookmarks"><span>' . __('Bookmarks') . '</span></div>';
         }
         $output .= '</div>';
         // Toolbar end
         // Console messages
         $output .= '<div class="content">';
         $output .= '<div class="console_message_container">' . '<div class="message welcome"><span>' . '<span id="instructions-0">' . __('Press Ctrl+Enter to execute query') . '</span>' . '<span class="hide" id="instructions-1">' . __('Press Enter to execute query') . '</span>' . '</span></div>';
         // History support
         $_sql_history = PMA_getHistory($GLOBALS['cfg']['Server']['user']);
         if ($_sql_history) {
             foreach (array_reverse($_sql_history) as $record) {
                 $isSelect = preg_match('@^SELECT[[:space:]]+@i', $record['sqlquery']);
                 $output .= '<div class="message history collapsed hide' . ($isSelect ? ' select' : '') . '" targetdb="' . htmlspecialchars($record['db']) . '" targettable="' . htmlspecialchars($record['table']) . '"><div class="action_content">' . sprintf($tpl_query_actions, htmlspecialchars($record['db']), isset($record['timevalue']) ? $record['timevalue'] : __('During current session')) . '</div><span class="query">' . htmlspecialchars($record['sqlquery']) . '</span></div>';
             }
         }
         $output .= '</div>';
         // .console_message_container
         $output .= '<div class="query_input">' . '<span class="console_query_input"></span>' . '</div>';
         $output .= '</div>';
         // Messages end
         // Dark the console while other cards cover it
         $output .= '<div class="mid_layer"></div>';
         // Bookmarks card:
         if ($cfgBookmark) {
             $output .= '<div class="card" id="pma_bookmarks">';
             $output .= '<div class="toolbar">' . '<div class="switch_button"><span>' . __('Bookmarks') . '</span></div>';
             $output .= '<div class="button refresh"><span>' . __('Refresh') . '</span></div>';
             $output .= '<div class="button add"><span>' . __('Add') . '</span></div>';
             $output .= '</div><div class="content bookmark">';
             $output .= $this->getBookmarkContent();
             $output .= '</div>';
             $output .= '<div class="mid_layer"></div>';
             $output .= '<div class="card add">';
             $output .= '<div class="toolbar">' . '<div class="switch_button"><span>' . __('Add bookmark') . '</span></div>';
             $output .= '</div><div class="content add_bookmark">' . '<div class="options">' . '<label>' . __('Label') . ': <input type="text" name="label"></label> ' . '<label>' . __('Target database') . ': <input type="text" name="targetdb"></label> ' . '<label><input type="checkbox" name="shared">' . __('Share this bookmark') . '</label>' . '<button type="submit" name="submit">Ok</button>' . '</div>' . '<div class="query_input">' . '<span class="bookmark_add_input"></span></div>';
             $output .= '</div>';
             $output .= '</div>';
             // Add bookmark card
             $output .= '</div>';
             // Bookmarks card
         }
         // Options card:
         $output .= '<div class="card" id="pma_console_options">';
         $output .= '<div class="toolbar">' . '<div class="switch_button"><span>' . __('Options') . '</span></div>';
         $output .= '<div class="button default"><span>' . __('Set default') . '</span></div>';
         $output .= '</div><div class="content">' . '<label><input type="checkbox" name="always_expand">' . __('Always expand query messages') . '</label><br>' . '<label><input type="checkbox" name="start_history">' . __('Show query history at start') . '</label><br>' . '<label><input type="checkbox" name="current_query">' . __('Show current browsing query') . '</label><br>' . '<label><input type="checkbox" name="enter_executes">' . __('Execute queries on Enter and insert new line with Shift + Enter. ' . 'To make this permanent, view settings.') . '</label><br>' . '<label><input type="checkbox" name="dark_theme">' . __('Switch to dark theme') . '</label><br>' . '</div>';
         $output .= '</div>';
         // Options card
         $output .= '<div class="templates">' . '<div class="query_actions">' . sprintf($tpl_query_actions, '', '') . '</div>' . '</div>';
         $output .= '</div></div>';
         // #console and #pma_console_container ends
     }
     return $output;
 }