Exemplo n.º 1
0
/**
 * Handle remembered sorting order, only for single table query
 *
 * @param string $db                    database name
 * @param string $table                 table name
 * @param array  &$analyzed_sql_results the analyzed query results
 * @param string &$full_sql_query       SQL query
 *
 * @return void
 */
function PMA_handleSortOrder($db, $table, &$analyzed_sql_results, &$full_sql_query)
{
    $pmatable = new PMA_Table($table, $db);
    if (empty($analyzed_sql_results['order'])) {
        // Retrieving the name of the column we should sort after.
        $sortCol = $pmatable->getUiProp(PMA_Table::PROP_SORTED_COLUMN);
        if (empty($sortCol)) {
            return;
        }
        // Remove the name of the table from the retrieved field name.
        $sortCol = str_replace(PMA_Util::backquote($table) . '.', '', $sortCol);
        // Create the new query.
        $full_sql_query = SqlParser\Utils\Query::replaceClause($analyzed_sql_results['statement'], $analyzed_sql_results['parser']->list, 'ORDER BY ' . $sortCol);
        // TODO: Avoid reparsing the query.
        $analyzed_sql_results = SqlParser\Utils\Query::getAll($full_sql_query);
    } else {
        // Store the remembered table into session.
        $pmatable->setUiProp(PMA_Table::PROP_SORTED_COLUMN, SqlParser\Utils\Query::getClause($analyzed_sql_results['statement'], $analyzed_sql_results['parser']->list, 'ORDER BY'));
    }
}
Exemplo n.º 2
0
/**
 * Handle remembered sorting order, only for single table query
 *
 * @param string $db                    database name
 * @param string $table                 table name
 * @param array  &$analyzed_sql_results the analyzed query results
 * @param string &$full_sql_query       SQL query
 *
 * @return void
 */
function PMA_handleSortOrder($db, $table, &$analyzed_sql_results, &$full_sql_query)
{
    $pmatable = new PMA_Table($table, $db);
    if (empty($analyzed_sql_results['analyzed_sql'][0]['order_by_clause'])) {
        $sorted_col = $pmatable->getUiProp(PMA_Table::PROP_SORTED_COLUMN);
        if ($sorted_col) {
            //remove the tablename from retrieved preference
            //to get just the column name and the sort order
            $sorted_col = str_replace(PMA_Util::backquote($table) . '.', '', $sorted_col);
            // retrieve the remembered sorting order for current table
            $sql_order_to_append = ' ORDER BY ' . $sorted_col . ' ';
            $full_sql_query = $analyzed_sql_results['analyzed_sql'][0]['section_before_limit'] . $sql_order_to_append . $analyzed_sql_results['analyzed_sql'][0]['limit_clause'] . ' ' . $analyzed_sql_results['analyzed_sql'][0]['section_after_limit'];
            // update the $analyzed_sql
            $analyzed_sql_results['analyzed_sql'][0]['section_before_limit'] .= $sql_order_to_append;
            $analyzed_sql_results['analyzed_sql'][0]['order_by_clause'] = $sorted_col;
        }
    } else {
        // store the remembered table into session
        $pmatable->setUiProp(PMA_Table::PROP_SORTED_COLUMN, $analyzed_sql_results['analyzed_sql'][0]['order_by_clause']);
    }
}
Exemplo n.º 3
0
 /**
  * Get column order and column visibility
  *
  * @param array $analyzed_sql the analyzed query
  *
  * @return  array           2 element array - $col_order, $col_visib
  *
  * @access  private
  *
  * @see     _getTableBody()
  */
 private function _getColumnParams($analyzed_sql)
 {
     if ($this->_isSelect($analyzed_sql)) {
         $pmatable = new PMA_Table($this->__get('table'), $this->__get('db'));
         $col_order = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_ORDER);
         $col_visib = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_VISIB);
     } else {
         $col_order = false;
         $col_visib = false;
     }
     return array($col_order, $col_visib);
 }
Exemplo n.º 4
0
 /**
  * Test for setUiProp
  *
  * @return void
  */
 public function testSetUiProp()
 {
     $table_name = 'PMA_BookMark';
     $db = 'PMA';
     $table = new PMA_Table($table_name, $db);
     $property = PMA_Table::PROP_COLUMN_ORDER;
     $value = "UiProp_value";
     $table_create_time = null;
     $table->setUiProp($property, $value, $table_create_time);
     //set UI prop successfully
     $this->assertEquals($value, $table->uiprefs[$property]);
     //removeUiProp
     $table->removeUiProp($property);
     $is_define_property = isset($table->uiprefs[$property]) ? true : false;
     $this->assertEquals(false, $is_define_property);
     //getUiProp after removeUiProp
     $is_define_property = $table->getUiProp($property);
     $this->assertEquals(false, $is_define_property);
 }
Exemplo n.º 5
0
    $is_maint    = true;
}

// assign default full_sql_query
$full_sql_query = $sql_query;

// Handle remembered sorting order, only for single table query
if ($GLOBALS['cfg']['RememberSorting']
    && ! ($is_count || $is_export || $is_func || $is_analyse)
    && count($analyzed_sql[0]['select_expr']) == 0
    && isset($analyzed_sql[0]['queryflags']['select_from'])
    && count($analyzed_sql[0]['table_ref']) == 1
) {
    $pmatable = new PMA_Table($table, $db);
    if (empty($analyzed_sql[0]['order_by_clause'])) {
        $sorted_col = $pmatable->getUiProp(PMA_Table::PROP_SORTED_COLUMN);
        if ($sorted_col) {
            // retrieve the remembered sorting order for current table
            $sql_order_to_append = ' ORDER BY ' . $sorted_col . ' ';
            $full_sql_query = $analyzed_sql[0]['section_before_limit'] . $sql_order_to_append
                . $analyzed_sql[0]['limit_clause'] . ' ' . $analyzed_sql[0]['section_after_limit'];

            // update the $analyzed_sql
            $analyzed_sql[0]['section_before_limit'] .= $sql_order_to_append;
            $analyzed_sql[0]['order_by_clause'] = $sorted_col;
        }
    } else {
        // store the remembered table into session
        $pmatable->setUiProp(PMA_Table::PROP_SORTED_COLUMN, $analyzed_sql[0]['order_by_clause']);
    }
}
Exemplo n.º 6
0
/**
 * Update the table's structure based on $_REQUEST
 *
 * @param string $db    database name
 * @param string $table table name
 *
 * @return boolean $regenerate              true if error occurred
 *
 */
function PMA_updateColumns($db, $table)
{
    $err_url = 'tbl_structure.php' . PMA_URL_getCommon(array('db' => $db, 'table' => $table));
    $regenerate = false;
    $field_cnt = count($_REQUEST['field_name']);
    $changes = array();
    $pmatable = new PMA_Table($table, $db);
    for ($i = 0; $i < $field_cnt; $i++) {
        if (PMA_columnNeedsAlterTable($i)) {
            $changes[] = 'CHANGE ' . PMA_Table::generateAlter(isset($_REQUEST['field_orig'][$i]) ? $_REQUEST['field_orig'][$i] : '', $_REQUEST['field_name'][$i], $_REQUEST['field_type'][$i], $_REQUEST['field_length'][$i], $_REQUEST['field_attribute'][$i], isset($_REQUEST['field_collation'][$i]) ? $_REQUEST['field_collation'][$i] : '', isset($_REQUEST['field_null'][$i]) ? $_REQUEST['field_null'][$i] : 'NOT NULL', $_REQUEST['field_default_type'][$i], $_REQUEST['field_default_value'][$i], isset($_REQUEST['field_extra'][$i]) ? $_REQUEST['field_extra'][$i] : false, isset($_REQUEST['field_comments'][$i]) ? $_REQUEST['field_comments'][$i] : '', isset($_REQUEST['field_move_to'][$i]) ? $_REQUEST['field_move_to'][$i] : '');
            // find the remembered sort expression
            $sorted_col = $pmatable->getUiProp(PMA_Table::PROP_SORTED_COLUMN);
            // if the old column name is part of the remembered sort expression
            if (mb_strpos($sorted_col, PMA_Util::backquote($_REQUEST['field_orig'][$i])) !== false) {
                // delete the whole remembered sort expression
                $pmatable->removeUiProp(PMA_Table::PROP_SORTED_COLUMN);
            }
        }
    }
    // end for
    $response = PMA_Response::getInstance();
    if (count($changes) > 0 || isset($_REQUEST['preview_sql'])) {
        // Builds the primary keys statements and updates the table
        $key_query = '';
        /**
         * this is a little bit more complex
         *
         * @todo if someone selects A_I when altering a column we need to check:
         *  - no other column with A_I
         *  - the column has an index, if not create one
         *
         */
        // To allow replication, we first select the db to use
        // and then run queries on this db.
        if (!$GLOBALS['dbi']->selectDb($db)) {
            PMA_Util::mysqlDie($GLOBALS['dbi']->getError(), 'USE ' . PMA_Util::backquote($db) . ';', false, $err_url);
        }
        $sql_query = 'ALTER TABLE ' . PMA_Util::backquote($table) . ' ';
        $sql_query .= implode(', ', $changes) . $key_query;
        $sql_query .= ';';
        // If there is a request for SQL previewing.
        if (isset($_REQUEST['preview_sql'])) {
            PMA_previewSQL(count($changes) > 0 ? $sql_query : '');
        }
        $result = $GLOBALS['dbi']->tryQuery($sql_query);
        if ($result !== false) {
            $message = PMA_Message::success(__('Table %1$s has been altered successfully.'));
            $message->addParam($table);
            $response->addHTML(PMA_Util::getMessage($message, $sql_query, 'success'));
        } else {
            // An error happened while inserting/updating a table definition
            $response->isSuccess(false);
            $response->addJSON('message', PMA_Message::rawError(__('Query error') . ':<br />' . $GLOBALS['dbi']->getError()));
            $regenerate = true;
        }
    }
    include_once 'libraries/transformations.lib.php';
    // update field names in relation
    if (isset($_REQUEST['field_orig']) && is_array($_REQUEST['field_orig'])) {
        foreach ($_REQUEST['field_orig'] as $fieldindex => $fieldcontent) {
            if ($_REQUEST['field_name'][$fieldindex] != $fieldcontent) {
                PMA_REL_renameField($db, $table, $fieldcontent, $_REQUEST['field_name'][$fieldindex]);
            }
        }
    }
    // update mime types
    if (isset($_REQUEST['field_mimetype']) && is_array($_REQUEST['field_mimetype']) && $GLOBALS['cfg']['BrowseMIME']) {
        foreach ($_REQUEST['field_mimetype'] as $fieldindex => $mimetype) {
            if (isset($_REQUEST['field_name'][$fieldindex]) && mb_strlen($_REQUEST['field_name'][$fieldindex])) {
                PMA_setMIME($db, $table, $_REQUEST['field_name'][$fieldindex], $mimetype, $_REQUEST['field_transformation'][$fieldindex], $_REQUEST['field_transformation_options'][$fieldindex], $_REQUEST['field_input_transformation'][$fieldindex], $_REQUEST['field_input_transformation_options'][$fieldindex]);
            }
        }
    }
    return $regenerate;
}
Exemplo n.º 7
0
/**
 * Handle remembered sorting order, only for single table query
 *
 * @param string $db              database name
 * @param string $table           table name
 * @param array  &$analyzed_sql   the analyzed query
 * @param string &$full_sql_query SQL query
 *
 * @return void
 */
function PMA_handleSortOrder($db, $table, &$analyzed_sql, &$full_sql_query)
{
    $pmatable = new PMA_Table($table, $db);
    if (empty($analyzed_sql[0]['order_by_clause'])) {
        $sorted_col = $pmatable->getUiProp(PMA_Table::PROP_SORTED_COLUMN);
        if ($sorted_col) {
            // retrieve the remembered sorting order for current table
            $sql_order_to_append = ' ORDER BY ' . $sorted_col . ' ';
            $full_sql_query = $analyzed_sql[0]['section_before_limit'] . $sql_order_to_append . $analyzed_sql[0]['limit_clause'] . ' ' . $analyzed_sql[0]['section_after_limit'];
            // update the $analyzed_sql
            $analyzed_sql[0]['section_before_limit'] .= $sql_order_to_append;
            $analyzed_sql[0]['order_by_clause'] = $sorted_col;
        }
    } else {
        // store the remembered table into session
        $pmatable->setUiProp(PMA_Table::PROP_SORTED_COLUMN, $analyzed_sql[0]['order_by_clause']);
    }
}
Exemplo n.º 8
0
/**
 * Do display the result table with the vertical direction mode.
 *
 * @return  boolean  always true
 *
 * @global  array    $vertical_display the information to display
 *
 * @access  private
 *
 * @see     PMA_displayTable()
 */
function PMA_displayVerticalTable()
{
    global $vertical_display;
    // Displays "multi row delete" link at top if required
    if ($GLOBALS['cfg']['RowActionLinks'] != 'right' && is_array($vertical_display['row_delete']) && (count($vertical_display['row_delete']) > 0 || !empty($vertical_display['textbtn']))) {
        echo '<tr>' . "\n";
        if ($GLOBALS['cfg']['RowActionLinks'] == 'none') {
            // if we are not showing the RowActionLinks, then we need to show the Multi-Row-Action checkboxes
            echo '<th></th>' . "\n";
        }
        echo $vertical_display['textbtn'];
        $cell_displayed = 0;
        foreach ($vertical_display['row_delete'] as $val) {
            if ($cell_displayed != 0 && $_SESSION['tmp_user_values']['repeat_cells'] != 0 && !($cell_displayed % $_SESSION['tmp_user_values']['repeat_cells'])) {
                echo '<th' . ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn' ? ' rowspan="4"' : '') . '></th>' . "\n";
            }
            echo str_replace('[%_PMA_CHECKBOX_DIR_%]', '_left', $val);
            $cell_displayed++;
        }
        // end while
        echo '</tr>' . "\n";
    }
    // end if
    // Displays "edit" link at top if required
    if (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both') && is_array($vertical_display['edit']) && (count($vertical_display['edit']) > 0 || !empty($vertical_display['textbtn']))) {
        echo '<tr>' . "\n";
        if (!is_array($vertical_display['row_delete'])) {
            echo $vertical_display['textbtn'];
        }
        foreach ($vertical_display['edit'] as $val) {
            echo $val;
        }
        // end while
        echo '</tr>' . "\n";
    }
    // end if
    // Displays "copy" link at top if required
    if (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both') && is_array($vertical_display['copy']) && (count($vertical_display['copy']) > 0 || !empty($vertical_display['textbtn']))) {
        echo '<tr>' . "\n";
        if (!is_array($vertical_display['row_delete'])) {
            echo $vertical_display['textbtn'];
        }
        foreach ($vertical_display['copy'] as $val) {
            echo $val;
        }
        // end while
        echo '</tr>' . "\n";
    }
    // end if
    // Displays "delete" link at top if required
    if (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both') && is_array($vertical_display['delete']) && (count($vertical_display['delete']) > 0 || !empty($vertical_display['textbtn']))) {
        echo '<tr>' . "\n";
        if (!is_array($vertical_display['edit']) && !is_array($vertical_display['row_delete'])) {
            echo $vertical_display['textbtn'];
        }
        foreach ($vertical_display['delete'] as $val) {
            echo $val;
        }
        // end while
        echo '</tr>' . "\n";
    }
    // end if
    if (PMA_isSelect()) {
        // prepare to get the column order, if available
        $pmatable = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
        $col_order = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_ORDER);
        $col_visib = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_VISIB);
    } else {
        $col_order = false;
        $col_visib = false;
    }
    // Displays data
    foreach ($vertical_display['desc'] as $j => $val) {
        // assign appropriate key with current column order
        $key = $col_order ? $col_order[$j] : $j;
        echo '<tr' . ($col_visib && !$col_visib[$j] ? ' class="hide"' : '') . '>' . "\n";
        echo $val;
        $cell_displayed = 0;
        foreach ($vertical_display['rowdata'][$key] as $subval) {
            if ($cell_displayed != 0 && $_SESSION['tmp_user_values']['repeat_cells'] != 0 and !($cell_displayed % $_SESSION['tmp_user_values']['repeat_cells'])) {
                echo $val;
            }
            echo $subval;
            $cell_displayed++;
        }
        // end while
        echo '</tr>' . "\n";
    }
    // end while
    // Displays "multi row delete" link at bottom if required
    if (($GLOBALS['cfg']['RowActionLinks'] == 'right' || $GLOBALS['cfg']['RowActionLinks'] == 'both') && is_array($vertical_display['row_delete']) && (count($vertical_display['row_delete']) > 0 || !empty($vertical_display['textbtn']))) {
        echo '<tr>' . "\n";
        echo $vertical_display['textbtn'];
        $cell_displayed = 0;
        foreach ($vertical_display['row_delete'] as $val) {
            if ($cell_displayed != 0 && $_SESSION['tmp_user_values']['repeat_cells'] != 0 && !($cell_displayed % $_SESSION['tmp_user_values']['repeat_cells'])) {
                echo '<th' . ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn' ? ' rowspan="4"' : '') . '></th>' . "\n";
            }
            echo str_replace('[%_PMA_CHECKBOX_DIR_%]', '_right', $val);
            $cell_displayed++;
        }
        // end while
        echo '</tr>' . "\n";
    }
    // end if
    // Displays "edit" link at bottom if required
    if (($GLOBALS['cfg']['RowActionLinks'] == 'right' || $GLOBALS['cfg']['RowActionLinks'] == 'both') && is_array($vertical_display['edit']) && (count($vertical_display['edit']) > 0 || !empty($vertical_display['textbtn']))) {
        echo '<tr>' . "\n";
        if (!is_array($vertical_display['row_delete'])) {
            echo $vertical_display['textbtn'];
        }
        foreach ($vertical_display['edit'] as $val) {
            echo $val;
        }
        // end while
        echo '</tr>' . "\n";
    }
    // end if
    // Displays "copy" link at bottom if required
    if (($GLOBALS['cfg']['RowActionLinks'] == 'right' || $GLOBALS['cfg']['RowActionLinks'] == 'both') && is_array($vertical_display['copy']) && (count($vertical_display['copy']) > 0 || !empty($vertical_display['textbtn']))) {
        echo '<tr>' . "\n";
        if (!is_array($vertical_display['row_delete'])) {
            echo $vertical_display['textbtn'];
        }
        foreach ($vertical_display['copy'] as $val) {
            echo $val;
        }
        // end while
        echo '</tr>' . "\n";
    }
    // end if
    // Displays "delete" link at bottom if required
    if (($GLOBALS['cfg']['RowActionLinks'] == 'right' || $GLOBALS['cfg']['RowActionLinks'] == 'both') && is_array($vertical_display['delete']) && (count($vertical_display['delete']) > 0 || !empty($vertical_display['textbtn']))) {
        echo '<tr>' . "\n";
        if (!is_array($vertical_display['edit']) && !is_array($vertical_display['row_delete'])) {
            echo $vertical_display['textbtn'];
        }
        foreach ($vertical_display['delete'] as $val) {
            echo $val;
        }
        // end while
        echo '</tr>' . "\n";
    }
    return true;
}