db_qbe.php

来自「phpMyAdmin图形界面化操作,我已经配置好了,只要把解要压缩后的文件放到站」· PHP 代码 · 共 945 行 · 第 1/2 页

PHP
945
字号
<?php/* vim: set expandtab sw=4 ts=4 sts=4: *//** * query by example the whole database * * @version $Id: db_qbe.php 11498 2008-08-21 16:32:39Z lem9 $ *//** * requirements */require_once './libraries/common.inc.php';require_once './libraries/Table.class.php';require_once './libraries/relation.lib.php';/** * Gets the relation settings */$cfgRelation = PMA_getRelationsParam();/** * A query has been submitted -> execute it, else display the headers */if (isset($_REQUEST['submit_sql']) && ! empty($sql_query)) {    $goto      = 'db_sql.php';    $zero_rows = htmlspecialchars($GLOBALS['strSuccess']);    require './sql.php';    exit;} else {    $sub_part  = '_qbe';    require './libraries/db_common.inc.php';    $url_query .= '&amp;goto=db_qbe.php';    $url_params['goto'] = 'db_qbe.php';    require './libraries/db_info.inc.php';}if (isset($_REQUEST['submit_sql']) && ! preg_match('@^SELECT@i', $sql_query)) {    PMA_Message::warning('strHaveToShow')->display();}/** * Initialize some variables */$col_cnt = PMA_ifSetOr($_REQUEST['col_cnt'], 3, 'numeric');$add_col = PMA_ifSetOr($_REQUEST['add_col'], 0, 'numeric');$add_row = PMA_ifSetOr($_REQUEST['add_row'], 0, 'numeric');$rows    = PMA_ifSetOr($_REQUEST['rows'],    0, 'numeric');$ins_col = PMA_ifSetOr($_REQUEST['ins_col'], null, 'array');$del_col = PMA_ifSetOr($_REQUEST['del_col'], null, 'array');$prev_criteria = isset($_REQUEST['prev_criteria'])    ? $_REQUEST['prev_criteria']    : array();$criteria = isset($_REQUEST['criteria'])    ? $_REQUEST['criteria']    : array_fill(0, $col_cnt, '');$ins_row = isset($_REQUEST['ins_row'])    ? $_REQUEST['ins_row']    : array_fill(0, $col_cnt, '');$del_row = isset($_REQUEST['del_row'])    ? $_REQUEST['del_row']    : array_fill(0, $col_cnt, '');$and_or_row = isset($_REQUEST['and_or_row'])    ? $_REQUEST['and_or_row']    : array_fill(0, $col_cnt, '');$and_or_col = isset($_REQUEST['and_or_col'])    ? $_REQUEST['and_or_col']    : array_fill(0, $col_cnt, '');// minimum width$form_column_width = 12;$col = max($col_cnt + $add_col, 0);$row = max($rows + $add_row, 0);// The tables list sent by a previously submitted formif (PMA_isValid($_REQUEST['TableList'], 'array')) {    foreach ($_REQUEST['TableList'] as $each_table) {        $tbl_names[$each_table] = ' selected="selected"';    }} // end if// this was a work in progress, deactivated for now//$columns = PMA_DBI_get_columns_full($GLOBALS['db']);//$tables  = PMA_DBI_get_columns_full($GLOBALS['db']);/** * Prepares the form */$tbl_result     = PMA_DBI_query('SHOW TABLES FROM ' . PMA_backquote($db) . ';', null, PMA_DBI_QUERY_STORE);$tbl_result_cnt = PMA_DBI_num_rows($tbl_result);if (0 == $tbl_result_cnt) {    PMA_Message::error('strNoTablesFound')->display();    require_once './libraries/footer.inc.php';    exit;}// The tables list gets from MySQLwhile (list($tbl) = PMA_DBI_fetch_row($tbl_result)) {    $fld_results = PMA_DBI_get_fields($db, $tbl);    if (empty($tbl_names[$tbl]) && !empty($_REQUEST['TableList'])) {        $tbl_names[$tbl] = '';    } else {        $tbl_names[$tbl] = ' selected="selected"';    } //  end if    // The fields list per selected tables    if ($tbl_names[$tbl] == ' selected="selected"') {        $each_table = PMA_backquote($tbl);        $fld[]  = $each_table . '.*';        foreach ($fld_results as $each_field) {            $each_field = $each_table . '.' . PMA_backquote($each_field['Field']);            $fld[] = $each_field;            // increase the width if necessary            $form_column_width = max(strlen($each_field), $form_column_width);        } // end foreach    } // end if} // end whilePMA_DBI_free_result($tbl_result);// largest width found$realwidth = $form_column_width . 'ex';/** * Displays the Query by example form *//** * Enter description here... * * @param array     $columns * @param numeric   $column_number * @param string    $selected */function showColumnSelectCell($columns, $column_number, $selected = ''){    ?>    <td align="center">        <select name="Field[<?php echo $column_number; ?>]" size="1">            <option value="">&nbsp;</option>    <?php    foreach ($columns as $column) {        if ($column === $selected) {            $sel = ' selected="selected"';        } else {            $sel = '';        }        echo '<option value="' . htmlspecialchars($column) . '"' . $sel . '>'            . str_replace(' ', '&nbsp;', htmlspecialchars($column)) . '</option>' . "\n";    }    ?>        </select>    </td>    <?php}?><fieldset><form action="db_qbe.php" method="post"><table class="data" style="width: 100%;"><tr class="odd noclick">    <th><?php echo $strField; ?>:</th><?php$z = 0;for ($x = 0; $x < $col; $x++) {    if (isset($ins_col[$x]) && $ins_col[$x] == 'on') {        showColumnSelectCell($fld, $z);        $z++;    }    if (! empty($del_col) && isset($del_col[$x]) && $del_col[$x] == 'on') {        continue;    }    $selected = '';    if (isset($Field[$x])) {        $selected = $Field[$x];        $curField[$z] = $Field[$x];    }    showColumnSelectCell($fld, $z, $selected);    $z++;} // end for?></tr><!-- Sort row --><tr class="even noclick">    <th><?php echo $strSort; ?>:</th><?php$z = 0;for ($x = 0; $x < $col; $x++) {    if (!empty($ins_col) && isset($ins_col[$x]) && $ins_col[$x] == 'on') {        ?>    <td align="center">        <select style="width: <?php echo $realwidth; ?>" name="Sort[<?php echo $z; ?>]" size="1">            <option value="">&nbsp;</option>            <option value="ASC"><?php echo $strAscending; ?></option>            <option value="DESC"><?php echo $strDescending; ?></option>        </select>    </td>        <?php        $z++;    } // end if    echo "\n";    if (!empty($del_col) && isset($del_col[$x]) && $del_col[$x] == 'on') {        continue;    }    ?>    <td align="center">        <select style="width: <?php echo $realwidth; ?>" name="Sort[<?php echo $z; ?>]" size="1">            <option value="">&nbsp;</option>    <?php    echo "\n";    // If they have chosen all fields using the * selector,    // then sorting is not available    // Robbat2 - Fix for Bug #570698    if (isset($Sort[$x]) && isset($Field[$x])     && substr($Field[$x], -2) == '.*') {        $Sort[$x] = '';    } //end if    if (isset($Sort[$x]) && $Sort[$x] == 'ASC') {        $curSort[$z] = $Sort[$x];        $sel         = ' selected="selected"';    } else {        $sel         = '';    } // end if    echo '                ';    echo '<option value="ASC"' . $sel . '>' . $strAscending . '</option>' . "\n";    if (isset($Sort[$x]) && $Sort[$x] == 'DESC') {        $curSort[$z] = $Sort[$x];        $sel         = ' selected="selected"';    } else {        $sel         = '';    } // end if    echo '                ';    echo '<option value="DESC"' . $sel . '>' . $strDescending . '</option>' . "\n";    ?>        </select>    </td>    <?php    $z++;    echo "\n";} // end for?></tr><!-- Show row --><tr class="odd noclick">    <th><?php echo $strShow; ?>:</th><?php$z = 0;for ($x = 0; $x < $col; $x++) {    if (!empty($ins_col) && isset($ins_col[$x]) && $ins_col[$x] == 'on') {        ?>    <td align="center">        <input type="checkbox" name="Show[<?php echo $z; ?>]" />    </td>        <?php        $z++;    } // end if    echo "\n";    if (!empty($del_col) && isset($del_col[$x]) && $del_col[$x] == 'on') {        continue;    }    if (isset($Show[$x])) {        $checked     = ' checked="checked"';        $curShow[$z] = $Show[$x];    } else {        $checked     =  '';    }    ?>    <td align="center">        <input type="checkbox" name="Show[<?php echo $z; ?>]"<?php echo $checked; ?> />    </td>    <?php    $z++;    echo "\n";} // end for?></tr><!-- Criteria row --><tr class="even noclick">    <th><?php echo $strCriteria; ?>:</th><?php$z = 0;for ($x = 0; $x < $col; $x++) {    if (!empty($ins_col) && isset($ins_col[$x]) && $ins_col[$x] == 'on') {        ?>    <td align="center">        <input type="text" name="criteria[<?php echo $z; ?>]" value="" class="textfield" style="width: <?php echo $realwidth; ?>" size="20" />    </td>        <?php        $z++;    } // end if    echo "\n";    if (!empty($del_col) && isset($del_col[$x]) && $del_col[$x] == 'on') {        continue;    }    if (isset($criteria[$x])) {        $stripped_Criteria = $criteria[$x];    }    if ((empty($prev_criteria) || !isset($prev_criteria[$x]))        || $prev_criteria[$x] != htmlspecialchars($stripped_Criteria)) {        $curCriteria[$z]   = $stripped_Criteria;    } else {        $curCriteria[$z]   = $prev_criteria[$x];    }    ?>    <td align="center">        <input type="hidden" name="prev_criteria[<?php echo $z; ?>]" value="<?php echo htmlspecialchars($curCriteria[$z]); ?>" />        <input type="text" name="criteria[<?php echo $z; ?>]" value="<?php echo htmlspecialchars($stripped_Criteria); ?>" class="textfield" style="width: <?php echo $realwidth; ?>" size="20" />    </td>    <?php    $z++;    echo "\n";} // end for?></tr><!-- And/Or columns and rows --><?php$w = 0;$odd_row = true;for ($y = 0; $y <= $row; $y++) {    if (isset($ins_row[$y]) && $ins_row[$y] == 'on') {        $chk['or']  = ' checked="checked"';        $chk['and'] = '';        ?><tr class="<?php echo $odd_row ? 'odd' : 'even'; ?> noclick">    <td align="<?php echo $cell_align_right; ?>" nowrap="nowrap">        <!-- Row controls -->        <table cellpadding="0" cellspacing="0" border="0">        <tr>            <td align="<?php echo $cell_align_right; ?>" nowrap="nowrap">                <small><?php echo $strQBEIns; ?>:</small>                <input type="checkbox" name="ins_row[<?php echo $w; ?>]" />            </td>            <td align="<?php echo $cell_align_right; ?>">                <strong><?php echo $strAnd; ?>:</strong>            </td>            <td>                <input type="radio" name="and_or_row[<?php echo $w; ?>]" value="and"<?php echo $chk['and']; ?> />                &nbsp;            </td>        </tr>        <tr>            <td align="<?php echo $cell_align_right; ?>" nowrap="nowrap">                <small><?php echo $strQBEDel; ?>:</small>                <input type="checkbox" name="del_row[<?php echo $w; ?>]" />            </td>            <td align="<?php echo $cell_align_right; ?>">                <strong><?php echo $strOr; ?>:</strong>            </td>            <td>                <input type="radio" name="and_or_row[<?php echo $w; ?>]" value="or"<?php echo $chk['or']; ?> />                &nbsp;            </td>        </tr>        </table>    </td>        <?php        $z = 0;        for ($x = 0; $x < $col; $x++) {            if (isset($ins_col[$x]) && $ins_col[$x] == 'on') {                echo "\n";                $or = 'Or' . $w . '[' . $z . ']';                ?>    <td align="center">        <textarea cols="20" rows="2" style="width: <?php echo $realwidth; ?>" name="<?php echo $or; ?>" dir="<?php echo $text_dir; ?>"></textarea>    </td>                <?php                $z++;            } // end if            if (isset($del_col[$x]) && $del_col[$x] == 'on') {                continue;            }            echo "\n";            $or = 'Or' . $w . '[' . $z . ']';            ?>    <td align="center">        <textarea cols="20" rows="2" style="width: <?php echo $realwidth; ?>" name="<?php echo $or; ?>" dir="<?php echo $text_dir; ?>"></textarea>    </td>            <?php            $z++;        } // end for        $w++;        echo "\n";        ?></tr>        <?php        $odd_row =! $odd_row;    } // end if    if (isset($del_row[$y]) && $del_row[$y] == 'on') {        continue;    }    if (isset($and_or_row[$y])) {        $curAndOrRow[$w] = $and_or_row[$y];    }    if (isset($and_or_row[$y]) && $and_or_row[$y] == 'and') {        $chk['and'] =  ' checked="checked"';        $chk['or']  =  '';    } else {        $chk['or']  =  ' checked="checked"';        $chk['and'] =  '';    }    echo "\n";    ?><tr class="<?php echo $odd_row ? 'odd' : 'even'; ?> noclick">    <td align="<?php echo $cell_align_right; ?>" nowrap="nowrap">        <!-- Row controls -->        <table border="0" cellpadding="0" cellspacing="0">        <tr>            <td align="<?php echo $cell_align_right; ?>" nowrap="nowrap">                <small><?php echo $strQBEIns; ?>:</small>                <input type="checkbox" name="ins_row[<?php echo $w; ?>]" />            </td>            <td align="<?php echo $cell_align_right; ?>">                <strong><?php echo $strAnd; ?>:</strong>            </td>            <td>                <input type="radio" name="and_or_row[<?php echo $w; ?>]" value="and"<?php echo $chk['and']; ?> />            </td>        </tr>        <tr>            <td align="<?php echo $cell_align_right; ?>" nowrap="nowrap">                <small><?php echo $strQBEDel; ?>:</small>                <input type="checkbox" name="del_row[<?php echo $w; ?>]" />            </td>            <td align="<?php echo $cell_align_right; ?>">                <strong><?php echo $strOr; ?>:</strong>            </td>            <td>                <input type="radio" name="and_or_row[<?php echo $w; ?>]" value="or"<?php echo $chk['or']; ?> />            </td>        </tr>        </table>    </td>    <?php    $z = 0;    for ($x = 0; $x < $col; $x++) {        if (!empty($ins_col) && isset($ins_col[$x]) && $ins_col[$x] == 'on') {            echo "\n";            $or = 'Or' . $w . '[' . $z . ']';            ?>    <td align="center">        <textarea cols="20" rows="2" style="width: <?php echo $realwidth; ?>" name="<?php echo $or; ?>" dir="<?php echo $text_dir; ?>"></textarea>    </td>            <?php            $z++;        } // end if        if (!empty($del_col) && isset($del_col[$x]) && $del_col[$x] == 'on') {            continue;        }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?