~hexmode/+junk/main

« back to all changes in this revision

Viewing changes to install-files/apps/phpmyadmin2.10.1/libraries/display_tbl.lib.php

  • Committer: Mark A. Hershberger
  • Date: 2008-01-05 19:38:56 UTC
  • Revision ID: hershberger@spawn-xp-20080105193856-6rnzgwa4nehue3qj
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/* $Id: display_tbl.lib.php 10235 2007-03-31 13:07:59Z lem9 $ */
 
3
// vim: expandtab sw=4 ts=4 sts=4:
 
4
 
 
5
require_once './libraries/Table.class.php';
 
6
 
 
7
/**
 
8
 * Set of functions used to display the records returned by a sql query
 
9
 */
 
10
 
 
11
/**
 
12
 * Avoids undefined variables
 
13
 */
 
14
if (!isset($pos)) {
 
15
    $pos = 0;
 
16
} else {
 
17
    /* We need this to be a integer */
 
18
    $pos = (int)$pos;
 
19
}
 
20
 
 
21
/**
 
22
 * Defines the display mode to use for the results of a sql query
 
23
 *
 
24
 * It uses a synthetic string that contains all the required informations.
 
25
 * In this string:
 
26
 *   - the first two characters stand for the action to do while
 
27
 *     clicking on the "edit" link (eg 'ur' for update a row, 'nn' for no
 
28
 *     edit link...);
 
29
 *   - the next two characters stand for the action to do while
 
30
 *     clicking on the "delete" link (eg 'kp' for kill a process, 'nn' for
 
31
 *     no delete link...);
 
32
 *   - the next characters are boolean values (1/0) and respectively stand
 
33
 *     for sorting links, navigation bar, "insert a new row" link, the
 
34
 *     bookmark feature, the expand/collapse text/blob fields button and
 
35
 *     the "display printable view" option.
 
36
 *     Of course '0'/'1' means the feature won't/will be enabled.
 
37
 *
 
38
 * @param   string   the synthetic value for display_mode (see �1 a few
 
39
 *                   lines above for explanations)
 
40
 * @param   integer  the total number of rows returned by the sql query
 
41
 *                   without any programmatically appended "LIMIT" clause
 
42
 *                   (just a copy of $unlim_num_rows if it exists, else
 
43
 *                   computed inside this function)
 
44
 *
 
45
 * @return  array    an array with explicit indexes for all the display
 
46
 *                   elements
 
47
 *
 
48
 * @global  string   the database name
 
49
 * @global  string   the table name
 
50
 * @global  integer  the total number of rows returned by the sql query
 
51
 *                   without any programmatically appended "LIMIT" clause
 
52
 * @global  array    the properties of the fields returned by the query
 
53
 * @global  string   the url to return to in case of error in a sql
 
54
 *                   statement
 
55
 *
 
56
 * @access  private
 
57
 *
 
58
 * @see     PMA_displayTable()
 
59
 */
 
60
function PMA_setDisplayMode(&$the_disp_mode, &$the_total)
 
61
{
 
62
    global $db, $table;
 
63
    global $unlim_num_rows, $fields_meta;
 
64
    global $err_url;
 
65
 
 
66
    // 1. Initializes the $do_display array
 
67
    $do_display              = array();
 
68
    $do_display['edit_lnk']  = $the_disp_mode[0] . $the_disp_mode[1];
 
69
    $do_display['del_lnk']   = $the_disp_mode[2] . $the_disp_mode[3];
 
70
    $do_display['sort_lnk']  = (string) $the_disp_mode[4];
 
71
    $do_display['nav_bar']   = (string) $the_disp_mode[5];
 
72
    $do_display['ins_row']   = (string) $the_disp_mode[6];
 
73
    $do_display['bkm_form']  = (string) $the_disp_mode[7];
 
74
    $do_display['text_btn']  = (string) $the_disp_mode[8];
 
75
    $do_display['pview_lnk'] = (string) $the_disp_mode[9];
 
76
 
 
77
    // 2. Display mode is not "false for all elements" -> updates the
 
78
    // display mode
 
79
    if ($the_disp_mode != 'nnnn000000') {
 
80
        // 2.0 Print view -> set all elements to false!
 
81
        if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
 
82
            $do_display['edit_lnk']  = 'nn'; // no edit link
 
83
            $do_display['del_lnk']   = 'nn'; // no delete link
 
84
            $do_display['sort_lnk']  = (string) '0';
 
85
            $do_display['nav_bar']   = (string) '0';
 
86
            $do_display['ins_row']   = (string) '0';
 
87
            $do_display['bkm_form']  = (string) '0';
 
88
            $do_display['text_btn']  = (string) '0';
 
89
            $do_display['pview_lnk'] = (string) '0';
 
90
        }
 
91
        // 2.1 Statement is a "SELECT COUNT", a
 
92
        //     "CHECK/ANALYZE/REPAIR/OPTIMIZE", an "EXPLAIN" one or
 
93
        //     contains a "PROC ANALYSE" part
 
94
        elseif ($GLOBALS['is_count'] || $GLOBALS['is_analyse'] || $GLOBALS['is_maint'] || $GLOBALS['is_explain']) {
 
95
            $do_display['edit_lnk']  = 'nn'; // no edit link
 
96
            $do_display['del_lnk']   = 'nn'; // no delete link
 
97
            $do_display['sort_lnk']  = (string) '0';
 
98
            $do_display['nav_bar']   = (string) '0';
 
99
            $do_display['ins_row']   = (string) '0';
 
100
            $do_display['bkm_form']  = (string) '1';
 
101
            if ($GLOBALS['is_analyse']) {
 
102
                $do_display['text_btn']  = (string) '1';
 
103
            } else {
 
104
                $do_display['text_btn']  = (string) '0';
 
105
            }
 
106
            $do_display['pview_lnk'] = (string) '1';
 
107
        }
 
108
        // 2.2 Statement is a "SHOW..."
 
109
        elseif ($GLOBALS['is_show']) {
 
110
            /**
 
111
             * 2.2.1
 
112
             * @todo defines edit/delete links depending on show statement
 
113
             */
 
114
            $tmp = preg_match('@^SHOW[[:space:]]+(VARIABLES|(FULL[[:space:]]+)?PROCESSLIST|STATUS|TABLE|GRANTS|CREATE|LOGS|DATABASES|FIELDS)@i', $GLOBALS['sql_query'], $which);
 
115
            if (isset($which[1]) && strpos(' ' . strtoupper($which[1]), 'PROCESSLIST') > 0) {
 
116
                $do_display['edit_lnk'] = 'nn'; // no edit link
 
117
                $do_display['del_lnk']  = 'kp'; // "kill process" type edit link
 
118
            } else {
 
119
                // Default case -> no links
 
120
                $do_display['edit_lnk'] = 'nn'; // no edit link
 
121
                $do_display['del_lnk']  = 'nn'; // no delete link
 
122
            }
 
123
            // 2.2.2 Other settings
 
124
            $do_display['sort_lnk']  = (string) '0';
 
125
            $do_display['nav_bar']   = (string) '0';
 
126
            $do_display['ins_row']   = (string) '0';
 
127
            $do_display['bkm_form']  = (string) '1';
 
128
            $do_display['text_btn']  = (string) '1';
 
129
            $do_display['pview_lnk'] = (string) '1';
 
130
        }
 
131
        // 2.3 Other statements (ie "SELECT" ones) -> updates
 
132
        //     $do_display['edit_lnk'], $do_display['del_lnk'] and
 
133
        //     $do_display['text_btn'] (keeps other default values)
 
134
        else {
 
135
            $prev_table = $fields_meta[0]->table;
 
136
            $do_display['text_btn']  = (string) '1';
 
137
            for ($i = 0; $i < $GLOBALS['fields_cnt']; $i++) {
 
138
                $is_link = ($do_display['edit_lnk'] != 'nn'
 
139
                            || $do_display['del_lnk'] != 'nn'
 
140
                            || $do_display['sort_lnk'] != '0'
 
141
                            || $do_display['ins_row'] != '0');
 
142
                // 2.3.2 Displays edit/delete/sort/insert links?
 
143
                if ($is_link
 
144
                    && ($fields_meta[$i]->table == '' || $fields_meta[$i]->table != $prev_table)) {
 
145
                    $do_display['edit_lnk'] = 'nn'; // don't display links
 
146
                    $do_display['del_lnk']  = 'nn';
 
147
                    /**
 
148
                     * @todo May be problematic with same fields names in two joined table.
 
149
                     */
 
150
                    // $do_display['sort_lnk'] = (string) '0';
 
151
                    $do_display['ins_row']  = (string) '0';
 
152
                    if ($do_display['text_btn'] == '1') {
 
153
                        break;
 
154
                    }
 
155
                } // end if (2.3.2)
 
156
                // 2.3.3 Always display print view link
 
157
                $do_display['pview_lnk']    = (string) '1';
 
158
                $prev_table = $fields_meta[$i]->table;
 
159
            } // end for
 
160
        } // end if..elseif...else (2.1 -> 2.3)
 
161
    } // end if (2)
 
162
 
 
163
    // 3. Gets the total number of rows if it is unknown
 
164
    if (isset($unlim_num_rows) && $unlim_num_rows != '') {
 
165
        $the_total = $unlim_num_rows;
 
166
    } elseif (($do_display['nav_bar'] == '1' || $do_display['sort_lnk'] == '1')
 
167
             && (isset($db) && strlen($db) && !empty($table))) {
 
168
        $the_total   = PMA_Table::countRecords($db, $table, true);
 
169
    }
 
170
 
 
171
    // 4. If navigation bar or sorting fields names urls should be
 
172
    //    displayed but there is only one row, change these settings to
 
173
    //    false
 
174
    if ($do_display['nav_bar'] == '1' || $do_display['sort_lnk'] == '1') {
 
175
 
 
176
        if (isset($unlim_num_rows) && $unlim_num_rows < 2) {
 
177
            // garvin: force display of navbar for vertical/horizontal display-choice.
 
178
            // $do_display['nav_bar']  = (string) '0';
 
179
            $do_display['sort_lnk'] = (string) '0';
 
180
        }
 
181
 
 
182
    } // end if (3)
 
183
 
 
184
    // 5. Updates the synthetic var
 
185
    $the_disp_mode = join('', $do_display);
 
186
 
 
187
    return $do_display;
 
188
} // end of the 'PMA_setDisplayMode()' function
 
189
 
 
190
 
 
191
/**
 
192
 * Displays a navigation bar to browse among the results of a sql query
 
193
 *
 
194
 * @param   integer  the offset for the "next" page
 
195
 * @param   integer  the offset for the "previous" page
 
196
 * @param   string   the url-encoded query
 
197
 *
 
198
 * @global  string   $db             the database name
 
199
 * @global  string   $table          the table name
 
200
 * @global  string   $goto           the url to go back in case of errors
 
201
 * @global  boolean  $dontlimitchars whether to limit the number of displayed
 
202
 *                                   characters  of text type fields or not
 
203
 * @global  integer  $num_rows       the total number of rows returned by the
 
204
 *                                   sql query
 
205
 * @global  integer  $unlim_num_rows the total number of rows returned by the
 
206
 *                                   sql any programmatically appended "LIMIT" clause
 
207
 * @global  integer  $pos            the current position in results
 
208
 * @global  mixed    $session_max_rows the maximum number of rows per page
 
209
 *                                   ('all'  = no limit)
 
210
 * @global  string   $disp_direction the display mode
 
211
 *                                   (horizontal / vertical / horizontalflipped)
 
212
 * @global  integer  $repeat_cells   the number of row to display between two
 
213
 *                                   table headers
 
214
 * @global  boolean  $is_innodb      whether its InnoDB or not
 
215
 * @global  array    $showtable      table definitions
 
216
 *
 
217
 * @access  private
 
218
 *
 
219
 * @see     PMA_displayTable()
 
220
 */
 
221
function PMA_displayTableNavigation($pos_next, $pos_prev, $encoded_query)
 
222
{
 
223
    global $db, $table, $goto, $dontlimitchars;
 
224
    global $num_rows, $unlim_num_rows, $pos, $session_max_rows;
 
225
    global $disp_direction, $repeat_cells;
 
226
    global $is_innodb;
 
227
    global $showtable;
 
228
 
 
229
    /**
 
230
     * @todo move this to a central place
 
231
     * @todo for other future table types
 
232
     */
 
233
    $is_innodb = (isset($showtable['Type']) && $showtable['Type'] == 'InnoDB');
 
234
 
 
235
    ?>
 
236
 
 
237
<!-- Navigation bar -->
 
238
<table border="0" cellpadding="2" cellspacing="0">
 
239
<tr>
 
240
    <?php
 
241
    // Move to the beginning or to the previous page
 
242
    if ($pos > 0 && $session_max_rows != 'all') {
 
243
        // loic1: patch #474210 from Gosha Sakovich - part 1
 
244
        if ($GLOBALS['cfg']['NavigationBarIconic']) {
 
245
            $caption1 = '&lt;&lt;';
 
246
            $caption2 = ' &lt; ';
 
247
            $title1   = ' title="' . $GLOBALS['strPos1'] . '"';
 
248
            $title2   = ' title="' . $GLOBALS['strPrevious'] . '"';
 
249
        } else {
 
250
            $caption1 = $GLOBALS['strPos1'] . ' &lt;&lt;';
 
251
            $caption2 = $GLOBALS['strPrevious'] . ' &lt;';
 
252
            $title1   = '';
 
253
            $title2   = '';
 
254
        } // end if... else...
 
255
        ?>
 
256
<td>
 
257
    <form action="sql.php" method="post">
 
258
        <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
 
259
        <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
 
260
        <input type="hidden" name="pos" value="0" />
 
261
        <input type="hidden" name="session_max_rows" value="<?php echo $session_max_rows; ?>" />
 
262
        <input type="hidden" name="disp_direction" value="<?php echo $disp_direction; ?>" />
 
263
        <input type="hidden" name="repeat_cells" value="<?php echo $repeat_cells; ?>" />
 
264
        <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
 
265
        <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
 
266
        <input type="submit" name="navig" value="<?php echo $caption1; ?>"<?php echo $title1; ?> />
 
267
    </form>
 
268
</td>
 
269
<td>
 
270
    <form action="sql.php" method="post">
 
271
        <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
 
272
        <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
 
273
        <input type="hidden" name="pos" value="<?php echo $pos_prev; ?>" />
 
274
        <input type="hidden" name="session_max_rows" value="<?php echo $session_max_rows; ?>" />
 
275
        <input type="hidden" name="disp_direction" value="<?php echo $disp_direction; ?>" />
 
276
        <input type="hidden" name="repeat_cells" value="<?php echo $repeat_cells; ?>" />
 
277
        <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
 
278
        <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
 
279
        <input type="submit" name="navig" value="<?php echo $caption2; ?>"<?php echo $title2; ?> />
 
280
    </form>
 
281
</td>
 
282
        <?php
 
283
    } // end move back
 
284
    ?>
 
285
<td>
 
286
    &nbsp;&nbsp;&nbsp;
 
287
</td>
 
288
<td align="center">
 
289
    <form action="sql.php" method="post"
 
290
        onsubmit="return (checkFormElementInRange(this, 'session_max_rows', '<?php echo str_replace('\'', '\\\'', $GLOBALS['strInvalidRowNumber']); ?>', 1) &amp;&amp; checkFormElementInRange(this, 'pos', '<?php echo str_replace('\'', '\\\'', $GLOBALS['strInvalidRowNumber']); ?>', 0, <?php echo $unlim_num_rows - 1; ?>))">
 
291
        <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
 
292
        <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
 
293
        <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
 
294
        <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
 
295
        <input type="submit" name="navig" value="<?php echo $GLOBALS['strShow']; ?> :" />
 
296
        <input type="text" name="session_max_rows" size="3" value="<?php echo (($session_max_rows != 'all') ? $session_max_rows : $GLOBALS['cfg']['MaxRows']); ?>" class="textfield" onfocus="this.select()" />
 
297
        <?php echo $GLOBALS['strRowsFrom'] . "\n"; ?>
 
298
        <input type="text" name="pos" size="6" value="<?php echo (($pos_next >= $unlim_num_rows) ? 0 : $pos_next); ?>" class="textfield" onfocus="this.select()" />
 
299
        <br />
 
300
    <?php
 
301
    // Display mode (horizontal/vertical and repeat headers)
 
302
    $param1 = '            <select name="disp_direction">' . "\n"
 
303
            . '                <option value="horizontal"' . (($disp_direction == 'horizontal') ? ' selected="selected"': '') . '>' . $GLOBALS['strRowsModeHorizontal'] . '</option>' . "\n"
 
304
            . '                <option value="horizontalflipped"' . (($disp_direction == 'horizontalflipped') ? ' selected="selected"': '') . '>' . $GLOBALS['strRowsModeFlippedHorizontal'] . '</option>' . "\n"
 
305
            . '                <option value="vertical"' . (($disp_direction == 'vertical') ? ' selected="selected"': '') . '>' . $GLOBALS['strRowsModeVertical'] . '</option>' . "\n"
 
306
            . '            </select>' . "\n"
 
307
            . '           ';
 
308
    $param2 = '            <input type="text" size="3" name="repeat_cells" value="' . $repeat_cells . '" class="textfield" />' . "\n"
 
309
            . '           ';
 
310
    echo '    ' . sprintf($GLOBALS['strRowsModeOptions'], "\n" . $param1, "\n" . $param2) . "\n";
 
311
    ?>
 
312
    </form>
 
313
</td>
 
314
<td>
 
315
    &nbsp;&nbsp;&nbsp;
 
316
</td>
 
317
    <?php
 
318
    // Move to the next page or to the last one
 
319
    if (($pos + $session_max_rows < $unlim_num_rows) && $num_rows >= $session_max_rows
 
320
        && $session_max_rows != 'all') {
 
321
        // loic1: patch #474210 from Gosha Sakovich - part 2
 
322
        if ($GLOBALS['cfg']['NavigationBarIconic']) {
 
323
            $caption3 = ' &gt; ';
 
324
            $caption4 = '&gt;&gt;';
 
325
            $title3   = ' title="' . $GLOBALS['strNext'] . '"';
 
326
            $title4   = ' title="' . $GLOBALS['strEnd'] . '"';
 
327
        } else {
 
328
            $caption3 = '&gt; ' . $GLOBALS['strNext'];
 
329
            $caption4 = '&gt;&gt; ' . $GLOBALS['strEnd'];
 
330
            $title3   = '';
 
331
            $title4   = '';
 
332
        } // end if... else...
 
333
        echo "\n";
 
334
        ?>
 
335
<td>
 
336
    <form action="sql.php" method="post">
 
337
        <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
 
338
        <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
 
339
        <input type="hidden" name="pos" value="<?php echo $pos_next; ?>" />
 
340
        <input type="hidden" name="session_max_rows" value="<?php echo $session_max_rows; ?>" />
 
341
        <input type="hidden" name="disp_direction" value="<?php echo $disp_direction; ?>" />
 
342
        <input type="hidden" name="repeat_cells" value="<?php echo $repeat_cells; ?>" />
 
343
        <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
 
344
        <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
 
345
        <input type="submit" name="navig" value="<?php echo $caption3; ?>"<?php echo $title3; ?> />
 
346
    </form>
 
347
</td>
 
348
<td>
 
349
    <form action="sql.php" method="post"
 
350
        onsubmit="return <?php echo (($pos + $session_max_rows < $unlim_num_rows && $num_rows >= $session_max_rows) ? 'true' : 'false'); ?>">
 
351
        <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
 
352
        <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
 
353
        <input type="hidden" name="pos" value="<?php echo @((ceil($unlim_num_rows / $session_max_rows)- 1) * $session_max_rows); ?>" />
 
354
        <?php
 
355
        if ($is_innodb && $unlim_num_rows > $GLOBALS['cfg']['MaxExactCount']) {
 
356
            echo '<input type="hidden" name="find_real_end" value="1" />' . "\n";
 
357
            // no backquote around this message
 
358
            $onclick = ' onclick="return confirmAction(\'' . PMA_jsFormat($GLOBALS['strLongOperation'], false) . '\')"';
 
359
        }
 
360
        ?>
 
361
        <input type="hidden" name="session_max_rows" value="<?php echo $session_max_rows; ?>" />
 
362
        <input type="hidden" name="disp_direction" value="<?php echo $disp_direction; ?>" />
 
363
        <input type="hidden" name="repeat_cells" value="<?php echo $repeat_cells; ?>" />
 
364
        <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
 
365
        <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
 
366
        <input type="submit" name="navig" value="<?php echo $caption4; ?>"<?php echo $title4; ?> <?php echo (empty($onclick) ? '' : $onclick); ?>/>
 
367
    </form>
 
368
</td>
 
369
        <?php
 
370
    } // end move toward
 
371
 
 
372
 
 
373
    //page redirection
 
374
    $pageNow = @floor($pos / $session_max_rows) + 1;
 
375
    $nbTotalPage = @ceil($unlim_num_rows / $session_max_rows);
 
376
 
 
377
    if ($nbTotalPage > 1){ //if1
 
378
       ?>
 
379
   <td>
 
380
       &nbsp;&nbsp;&nbsp;
 
381
   </td>
 
382
   <td>
 
383
        <?php //<form> for keep the form alignment of button < and << ?>
 
384
        <form action="none">
 
385
        <?php echo PMA_pageselector(
 
386
                     'sql.php?sql_query='        . $encoded_query .
 
387
                        '&amp;session_max_rows=' . $session_max_rows .
 
388
                        '&amp;disp_direction='   . $disp_direction .
 
389
                        '&amp;repeat_cells='     . $repeat_cells .
 
390
                        '&amp;goto='             . $goto .
 
391
                        '&amp;dontlimitchars='   . $dontlimitchars .
 
392
                        '&amp;'                  . PMA_generate_common_url($db, $table) .
 
393
                        '&amp;',
 
394
                     $session_max_rows,
 
395
                     $pageNow,
 
396
                     $nbTotalPage
 
397
              );
 
398
        ?>
 
399
        </form>
 
400
    </td>
 
401
        <?php
 
402
    } //_if1
 
403
 
 
404
 
 
405
    // Show all the records if allowed
 
406
    if ($GLOBALS['cfg']['ShowAll'] && ($num_rows < $unlim_num_rows)) {
 
407
        echo "\n";
 
408
        ?>
 
409
<td>
 
410
    &nbsp;&nbsp;&nbsp;
 
411
</td>
 
412
<td>
 
413
    <form action="sql.php" method="post">
 
414
        <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
 
415
        <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
 
416
        <input type="hidden" name="pos" value="0" />
 
417
        <input type="hidden" name="session_max_rows" value="all" />
 
418
        <input type="hidden" name="disp_direction" value="<?php echo $disp_direction; ?>" />
 
419
        <input type="hidden" name="repeat_cells" value="<?php echo $repeat_cells; ?>" />
 
420
        <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
 
421
        <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
 
422
        <input type="submit" name="navig" value="<?php echo $GLOBALS['strShowAll']; ?>" />
 
423
    </form>
 
424
</td>
 
425
        <?php
 
426
    } // end show all
 
427
    echo "\n";
 
428
    ?>
 
429
</tr>
 
430
</table>
 
431
 
 
432
    <?php
 
433
} // end of the 'PMA_displayTableNavigation()' function
 
434
 
 
435
 
 
436
/**
 
437
 * Displays the headers of the results table
 
438
 *
 
439
 * @param   array    which elements to display
 
440
 * @param   array    the list of fields properties
 
441
 * @param   integer  the total number of fields returned by the sql query
 
442
 * @param   array    the analyzed query
 
443
 *
 
444
 * @return  boolean  always true
 
445
 *
 
446
 * @global  string   $db               the database name
 
447
 * @global  string   $table            the table name
 
448
 * @global  string   $goto             the url to go back in case of errors
 
449
 * @global  boolean  $dontlimitchars   whether to limit the number of displayed
 
450
 *                                     characters of text type fields or not
 
451
 * @global  string   $sql_query        the sql query
 
452
 * @global  integer  $num_rows         the total number of rows returned by the
 
453
 *                                     sql query
 
454
 * @global  integer  $pos              the current position in results
 
455
 * @global  integer  $session_max_rows the maximum number of rows per page
 
456
 * @global  array    $vertical_display informations used with vertical display
 
457
 *                                     mode
 
458
 * @global  string   $disp_direction   the display mode
 
459
 *                                     (horizontal/vertical/horizontalflipped)
 
460
 * @global  integer  $repeat_cellsthe  number of row to display between two
 
461
 *                                     table headers
 
462
 *
 
463
 * @access  private
 
464
 *
 
465
 * @see     PMA_displayTable()
 
466
 */
 
467
function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $analyzed_sql = '')
 
468
{
 
469
    global $db, $table, $goto, $dontlimitchars;
 
470
    global $sql_query, $num_rows, $pos, $session_max_rows;
 
471
    global $vertical_display, $disp_direction, $repeat_cells, $highlight_columns;
 
472
 
 
473
    if ($analyzed_sql == '') {
 
474
        $analyzed_sql = array();
 
475
    }
 
476
 
 
477
    // can the result be sorted?
 
478
    if ($is_display['sort_lnk'] == '1') {
 
479
 
 
480
        // Just as fallback
 
481
        $unsorted_sql_query     = $sql_query;
 
482
        if (isset($analyzed_sql[0]['unsorted_query'])) {
 
483
            $unsorted_sql_query = $analyzed_sql[0]['unsorted_query'];
 
484
        }
 
485
 
 
486
        // we need $sort_expression and $sort_expression_nodir
 
487
        // even if there are many table references
 
488
 
 
489
        $sort_expression = trim(str_replace('  ', ' ', $analyzed_sql[0]['order_by_clause']));
 
490
 
 
491
        /**
 
492
         * Get rid of ASC|DESC
 
493
         * @todo analyzer
 
494
         */
 
495
        preg_match('@(.*)([[:space:]]*(ASC|DESC))@si', $sort_expression, $matches);
 
496
        $sort_expression_nodir = isset($matches[1]) ? trim($matches[1]) : $sort_expression;
 
497
 
 
498
        // sorting by indexes, only if it makes sense (only one table ref)
 
499
        if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
 
500
            isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' &&
 
501
            isset($analyzed_sql[0]['table_ref']) && count($analyzed_sql[0]['table_ref']) == 1) {
 
502
 
 
503
            // grab indexes data:
 
504
            PMA_DBI_select_db($db);
 
505
            if (!defined('PMA_IDX_INCLUDED')) {
 
506
                $ret_keys = PMA_get_indexes($table);
 
507
            }
 
508
 
 
509
            $prev_index = '';
 
510
            foreach ($ret_keys as $row) {
 
511
 
 
512
                if ($row['Key_name'] != $prev_index){
 
513
                    $indexes[]  = $row['Key_name'];
 
514
                    $prev_index = $row['Key_name'];
 
515
                }
 
516
                $indexes_info[$row['Key_name']]['Sequences'][]     = $row['Seq_in_index'];
 
517
                $indexes_info[$row['Key_name']]['Non_unique']      = $row['Non_unique'];
 
518
                if (isset($row['Cardinality'])) {
 
519
                    $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
 
520
                }
 
521
            //    I don't know what does the following column mean....
 
522
            //    $indexes_info[$row['Key_name']]['Packed']          = $row['Packed'];
 
523
                $indexes_info[$row['Key_name']]['Comment']         = (isset($row['Comment']))
 
524
                                                                   ? $row['Comment']
 
525
                                                                   : '';
 
526
                $indexes_info[$row['Key_name']]['Index_type']      = (isset($row['Index_type']))
 
527
                                                                   ? $row['Index_type']
 
528
                                                                   : '';
 
529
 
 
530
                $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name']  = $row['Column_name'];
 
531
                if (isset($row['Sub_part'])) {
 
532
                    $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
 
533
                }
 
534
            } // end while
 
535
 
 
536
            // do we have any index?
 
537
            if (isset($indexes_data)) {
 
538
 
 
539
                if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
 
540
                    $span = $fields_cnt;
 
541
                    if ($is_display['edit_lnk'] != 'nn') {
 
542
                        $span++;
 
543
                    }
 
544
                    if ($is_display['del_lnk'] != 'nn') {
 
545
                        $span++;
 
546
                    }
 
547
                    if ($is_display['del_lnk'] != 'kp' && $is_display['del_lnk'] != 'nn') {
 
548
                        $span++;
 
549
                    }
 
550
                } else {
 
551
                    $span = $num_rows + floor($num_rows/$repeat_cells) + 1;
 
552
                }
 
553
 
 
554
                echo '<form action="sql.php" method="post">' . "\n";
 
555
                echo PMA_generate_common_hidden_inputs($db, $table, 5);
 
556
                echo '<input type="hidden" name="pos" value="' . $pos .  '" />' . "\n";
 
557
                echo '<input type="hidden" name="session_max_rows" value="' . $session_max_rows . '" />' . "\n";
 
558
                echo '<input type="hidden" name="disp_direction" value="' . $disp_direction . '" />' . "\n";
 
559
                echo '<input type="hidden" name="repeat_cells" value="' . $repeat_cells . '" />' . "\n";
 
560
                echo '<input type="hidden" name="dontlimitchars" value="' . $dontlimitchars . '" />' . "\n";
 
561
                echo $GLOBALS['strSortByKey'] . ': <select name="sql_query">' . "\n";
 
562
                $used_index = false;
 
563
                $local_order = (isset($sort_expression) ? $sort_expression : '');
 
564
                foreach ($indexes_data AS $key => $val) {
 
565
                    $asc_sort = '';
 
566
                    $desc_sort = '';
 
567
                    foreach ($val AS $key2 => $val2) {
 
568
                        $asc_sort .= PMA_backquote($val2['Column_name']) . ' ASC , ';
 
569
                        $desc_sort .= PMA_backquote($val2['Column_name']) . ' DESC , ';
 
570
                    }
 
571
                    $asc_sort = substr($asc_sort, 0, -3);
 
572
                    $desc_sort = substr($desc_sort, 0, -3);
 
573
                    $used_index = $used_index || $local_order == $asc_sort || $local_order == $desc_sort;
 
574
                    echo '<option value="' . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $asc_sort) . '"' . ($local_order == $asc_sort ? ' selected="selected"' : '') . '>' . htmlspecialchars($key) . ' (' . $GLOBALS['strAscending'] . ')</option>';
 
575
                    echo "\n";
 
576
                    echo '<option value="' . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $desc_sort) . '"' . ($local_order == $desc_sort ? ' selected="selected"' : '') . '>' . htmlspecialchars($key) . ' (' . $GLOBALS['strDescending'] . ')</option>';
 
577
                    echo "\n";
 
578
                }
 
579
                echo '<option value="' . htmlspecialchars($unsorted_sql_query) . '"' . ($used_index ? '' : ' selected="selected"') . '>' . $GLOBALS['strNone'] . '</option>';
 
580
                echo "\n";
 
581
                echo '</select>' . "\n";
 
582
                echo '<input type="submit" value="' . $GLOBALS['strGo'] . '" />';
 
583
                echo "\n";
 
584
                echo '</form>' . "\n";
 
585
            }
 
586
        }
 
587
    }
 
588
 
 
589
 
 
590
    $vertical_display['emptypre']   = 0;
 
591
    $vertical_display['emptyafter'] = 0;
 
592
    $vertical_display['textbtn']    = '';
 
593
 
 
594
 
 
595
    // Start of form for multi-rows delete
 
596
 
 
597
    if ($is_display['del_lnk'] == 'dr' || $is_display['del_lnk'] == 'kp') {
 
598
        echo '<form method="post" action="tbl_row_action.php" name="rowsDeleteForm" id="rowsDeleteForm">' . "\n";
 
599
        echo PMA_generate_common_hidden_inputs($db, $table, 1);
 
600
        echo '<input type="hidden" name="disp_direction"   value="' . $disp_direction . '" />' . "\n";
 
601
        echo '<input type="hidden" name="repeat_cells"     value="' . $repeat_cells   . '" />' . "\n";
 
602
        echo '<input type="hidden" name="dontlimitchars"   value="' . $dontlimitchars . '" />' . "\n";
 
603
        echo '<input type="hidden" name="pos"              value="' . $pos . '" />' . "\n";
 
604
        echo '<input type="hidden" name="session_max_rows" value="' . $session_max_rows . '" />' . "\n";
 
605
        echo '<input type="hidden" name="goto"             value="sql.php" />' . "\n";
 
606
    }
 
607
 
 
608
    echo '<table id="table_results" class="data">' . "\n";
 
609
    if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
 
610
        echo '<thead><tr>' . "\n";
 
611
    }
 
612
 
 
613
    // 1. Displays the full/partial text button (part 1)...
 
614
    if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
 
615
        $colspan  = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
 
616
                  ? ' colspan="3"'
 
617
                  : '';
 
618
    } else {
 
619
        $rowspan  = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
 
620
                  ? ' rowspan="3"'
 
621
                  : '';
 
622
    }
 
623
    $text_url = 'sql.php?'
 
624
              . PMA_generate_common_url($db, $table)
 
625
              . '&amp;sql_query=' . urlencode($sql_query)
 
626
              . '&amp;session_max_rows=' . $session_max_rows
 
627
              . '&amp;pos=' . $pos
 
628
              . '&amp;disp_direction=' . $disp_direction
 
629
              . '&amp;repeat_cells=' . $repeat_cells
 
630
              . '&amp;goto=' . $goto
 
631
              . '&amp;dontlimitchars=' . (($dontlimitchars) ? 0 : 1);
 
632
    $text_message = '<img class="fulltext" src="' . $GLOBALS['pmaThemeImage'] . 's_'.($dontlimitchars ? 'partialtext' : 'fulltext') . '.png" width="50" height="20" alt="' . ($dontlimitchars ? $GLOBALS['strPartialText'] : $GLOBALS['strFullText']) . '" title="' . ($dontlimitchars ? $GLOBALS['strPartialText'] : $GLOBALS['strFullText']) . '" />';
 
633
    $text_link = PMA_linkOrButton($text_url, $text_message, array(), false);
 
634
 
 
635
    //     ... before the result table
 
636
    if (($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
 
637
        && $is_display['text_btn'] == '1') {
 
638
        $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 0;
 
639
        if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
 
640
            ?>
 
641
    <th colspan="<?php echo $fields_cnt; ?>"><?php echo $text_link; ?></th>
 
642
</tr>
 
643
<tr>
 
644
            <?php
 
645
        } // end horizontal/horizontalflipped mode
 
646
        else {
 
647
            ?>
 
648
<tr>
 
649
    <th colspan="<?php echo $num_rows + floor($num_rows/$repeat_cells) + 1; ?>">
 
650
        <?php echo $text_link; ?></th>
 
651
</tr>
 
652
            <?php
 
653
        } // end vertical mode
 
654
    }
 
655
 
 
656
    //     ... at the left column of the result table header if possible
 
657
    //     and required
 
658
    elseif ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && $is_display['text_btn'] == '1') {
 
659
        $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 0;
 
660
        if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
 
661
            ?>
 
662
    <th <?php echo $colspan; ?>><?php echo $text_link; ?></th>
 
663
            <?php
 
664
        } // end horizontal/horizontalflipped mode
 
665
        else {
 
666
            $vertical_display['textbtn'] = '    <th ' . $rowspan . ' valign="middle">' . "\n"
 
667
                                         . '        ' . $text_link . "\n"
 
668
                                         . '    </th>' . "\n";
 
669
        } // end vertical mode
 
670
    }
 
671
 
 
672
    //     ... elseif no button, displays empty(ies) col(s) if required
 
673
    elseif ($GLOBALS['cfg']['ModifyDeleteAtLeft']
 
674
             && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')) {
 
675
        $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 0;
 
676
        if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
 
677
            ?>
 
678
    <td<?php echo $colspan; ?>></td>
 
679
            <?php
 
680
        } // end horizontal/horizontalfipped mode
 
681
        else {
 
682
            $vertical_display['textbtn'] = '    <td' . $rowspan . '></td>' . "\n";
 
683
        } // end vertical mode
 
684
    }
 
685
 
 
686
    // 2. Displays the fields' name
 
687
    // 2.0 If sorting links should be used, checks if the query is a "JOIN"
 
688
    //     statement (see 2.1.3)
 
689
 
 
690
    // 2.0.1 Prepare Display column comments if enabled ($GLOBALS['cfg']['ShowBrowseComments']).
 
691
    //       Do not show comments, if using horizontalflipped mode, because of space usage
 
692
    if ($GLOBALS['cfg']['ShowBrowseComments'] && ($GLOBALS['cfgRelation']['commwork'] || PMA_MYSQL_INT_VERSION >= 40100) && $disp_direction != 'horizontalflipped') {
 
693
        $comments_map = array();
 
694
        if (isset($analyzed_sql[0]) && is_array($analyzed_sql[0])) {
 
695
            foreach ($analyzed_sql[0]['table_ref'] as $tbl) {
 
696
                $tb = $tbl['table_true_name'];
 
697
                $comments_map[$tb] = PMA_getComments($db, $tb);
 
698
                unset($tb);
 
699
            }
 
700
        }
 
701
    }
 
702
 
 
703
    if ($GLOBALS['cfgRelation']['commwork'] && $GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {
 
704
        require_once './libraries/transformations.lib.php';
 
705
        $GLOBALS['mime_map'] = PMA_getMIME($db, $table);
 
706
    }
 
707
 
 
708
    if ($is_display['sort_lnk'] == '1') {
 
709
        //$is_join = preg_match('@(.*)[[:space:]]+FROM[[:space:]]+.*[[:space:]]+JOIN@im', $sql_query, $select_stt);
 
710
        $is_join = (isset($analyzed_sql[0]['queryflags']['join']) ? true : false);
 
711
        $select_expr = $analyzed_sql[0]['select_expr_clause'];
 
712
    } else {
 
713
        $is_join = false;
 
714
    }
 
715
 
 
716
    // garvin: See if we have to highlight any header fields of a WHERE query.
 
717
    //  Uses SQL-Parser results.
 
718
    $highlight_columns = array();
 
719
    if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
 
720
        isset($analyzed_sql[0]['where_clause_identifiers'])) {
 
721
 
 
722
        $wi = 0;
 
723
        if (isset($analyzed_sql[0]['where_clause_identifiers']) && is_array($analyzed_sql[0]['where_clause_identifiers'])) {
 
724
            foreach ($analyzed_sql[0]['where_clause_identifiers'] AS $wci_nr => $wci) {
 
725
                $highlight_columns[$wci] = 'true';
 
726
            }
 
727
        }
 
728
    }
 
729
 
 
730
    for ($i = 0; $i < $fields_cnt; $i++) {
 
731
        // garvin: See if this column should get highlight because it's used in the
 
732
        //  where-query.
 
733
        if (isset($highlight_columns[$fields_meta[$i]->name]) || isset($highlight_columns[PMA_backquote($fields_meta[$i]->name)])) {
 
734
            $condition_field = true;
 
735
        } else {
 
736
            $condition_field = false;
 
737
        }
 
738
 
 
739
        // 2.0 Prepare comment-HTML-wrappers for each row, if defined/enabled.
 
740
        if (isset($comments_map) &&
 
741
                isset($comments_map[$fields_meta[$i]->table]) &&
 
742
                isset($comments_map[$fields_meta[$i]->table][$fields_meta[$i]->name])) {
 
743
            $comments = '<span class="tblcomment">' . htmlspecialchars($comments_map[$fields_meta[$i]->table][$fields_meta[$i]->name]) . '</span>';
 
744
        } else {
 
745
            $comments = '';
 
746
        }
 
747
 
 
748
        // 2.1 Results can be sorted
 
749
        if ($is_display['sort_lnk'] == '1') {
 
750
 
 
751
            // 2.1.1 Checks if the table name is required; it's the case
 
752
            //       for a query with a "JOIN" statement and if the column
 
753
            //       isn't aliased, or in queries like
 
754
            //       SELECT `1`.`master_field` , `2`.`master_field`
 
755
            //       FROM `PMA_relation` AS `1` , `PMA_relation` AS `2`
 
756
            /**
 
757
             * we prefer always using table if existing
 
758
             * and second this code does not correctly check $fields_meta[$i]->table
 
759
            if (($is_join
 
760
                && !preg_match('~([^[:space:],]|`[^`]`)[[:space:]]+(as[[:space:]]+)?' . strtr($fields_meta[$i]->name, array('[' => '\\[', '~' => '\\~', '\\' => '\\\\')) . '~i', $select_expr, $parts))
 
761
               || (isset($analyzed_sql[0]['select_expr'][$i]['expr'])
 
762
                   && isset($analyzed_sql[0]['select_expr'][$i]['column'])
 
763
                   && $analyzed_sql[0]['select_expr'][$i]['expr'] !=
 
764
                   $analyzed_sql[0]['select_expr'][$i]['column']
 
765
                  && isset($fields_meta[$i]->table) && strlen($fields_meta[$i]->table))) {
 
766
            */
 
767
            if (isset($fields_meta[$i]->table) && strlen($fields_meta[$i]->table)) {
 
768
                $sort_tbl = PMA_backquote($fields_meta[$i]->table) . '.';
 
769
            } else {
 
770
                $sort_tbl = '';
 
771
            }
 
772
 
 
773
            // 2.1.2 Checks if the current column is used to sort the
 
774
            //       results
 
775
            if (empty($sort_expression)) {
 
776
                $is_in_sort = false;
 
777
            } else {
 
778
                // field name may be preceded by a space, or any number
 
779
                // of characters followed by a dot (tablename.fieldname)
 
780
                // so do a direct comparison
 
781
                // for the sort expression (avoids problems with queries
 
782
                // like "SELECT id, count(id)..." and clicking to sort
 
783
                // on id or on count(id))
 
784
                $is_in_sort = ($sort_tbl . PMA_backquote($fields_meta[$i]->name) == $sort_expression_nodir ? true : false);
 
785
            }
 
786
            // 2.1.3 Check the field name for backquotes.
 
787
            //       If it contains some, it's probably a function column
 
788
            //       like 'COUNT(`field`)'
 
789
            if (strpos($fields_meta[$i]->name, '`') !== false) {
 
790
                $sort_order = ' ORDER BY ' . PMA_backquote($fields_meta[$i]->name) . ' ';
 
791
            } else {
 
792
                $sort_order = ' ORDER BY ' . $sort_tbl . PMA_backquote($fields_meta[$i]->name) . ' ';
 
793
            }
 
794
 
 
795
            // 2.1.4 Do define the sorting url
 
796
            if (! $is_in_sort) {
 
797
                // loic1: patch #455484 ("Smart" order)
 
798
                $GLOBALS['cfg']['Order'] = strtoupper($GLOBALS['cfg']['Order']);
 
799
                if ($GLOBALS['cfg']['Order'] === 'SMART') {
 
800
                    $sort_order .= (preg_match('@time|date@i', $fields_meta[$i]->type)) ? 'DESC' : 'ASC';
 
801
                } else {
 
802
                    $sort_order .= $GLOBALS['cfg']['Order'];
 
803
                }
 
804
                $order_img   = '';
 
805
            } elseif (preg_match('@[[:space:]]DESC$@i', $sort_expression)) {
 
806
                $sort_order .= ' ASC';
 
807
                $order_img   = ' <img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 's_desc.png" width="11" height="9" alt="'. $GLOBALS['strDescending'] . '" title="'. $GLOBALS['strDescending'] . '" id="soimg' . $i . '" />';
 
808
            } else {
 
809
                $sort_order .= ' DESC';
 
810
                $order_img   = ' <img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 's_asc.png" width="11" height="9" alt="'. $GLOBALS['strAscending'] . '" title="'. $GLOBALS['strAscending'] . '" id="soimg' . $i . '" />';
 
811
            }
 
812
 
 
813
            if (preg_match('@(.*)([[:space:]](LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|LOCK IN SHARE MODE))@i', $unsorted_sql_query, $regs3)) {
 
814
                $sorted_sql_query = $regs3[1] . $sort_order . $regs3[2];
 
815
            } else {
 
816
                $sorted_sql_query = $unsorted_sql_query . $sort_order;
 
817
            }
 
818
            $url_query = PMA_generate_common_url($db, $table)
 
819
                       . '&amp;pos=' . $pos
 
820
                       . '&amp;session_max_rows=' . $session_max_rows
 
821
                       . '&amp;disp_direction=' . $disp_direction
 
822
                       . '&amp;repeat_cells=' . $repeat_cells
 
823
                       . '&amp;dontlimitchars=' . $dontlimitchars
 
824
                       . '&amp;sql_query=' . urlencode($sorted_sql_query);
 
825
            $order_url  = 'sql.php?' . $url_query;
 
826
 
 
827
            // 2.1.5 Displays the sorting url
 
828
            // added 20004-06-09: Michael Keck <mail@michaelkeck.de>
 
829
            //                    enable sord order swapping for image
 
830
            $order_link_params = array();
 
831
            if (isset($order_img) && $order_img!='') {
 
832
                if (strstr($order_img, 'asc')) {
 
833
                    $order_link_params['onmouseover'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_desc.png\'; }';
 
834
                    $order_link_params['onmouseout']  = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_asc.png\'; }';
 
835
                } elseif (strstr($order_img, 'desc')) {
 
836
                    $order_link_params['onmouseover'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_asc.png\'; }';
 
837
                    $order_link_params['onmouseout']  = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_desc.png\'; }';
 
838
                }
 
839
            }
 
840
            if ($disp_direction == 'horizontalflipped'
 
841
              && $GLOBALS['cfg']['HeaderFlipType'] == 'css') {
 
842
                $order_link_params['style'] = 'direction: ltr; writing-mode: tb-rl;';
 
843
            }
 
844
            $order_link_params['title'] = $GLOBALS['strSort'];
 
845
            $order_link_content = ($disp_direction == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'fake' ? PMA_flipstring(htmlspecialchars($fields_meta[$i]->name), "<br />\n") : htmlspecialchars($fields_meta[$i]->name));
 
846
            $order_link = PMA_linkOrButton($order_url, $order_link_content . $order_img, $order_link_params, false, true);
 
847
 
 
848
            if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
 
849
                echo '<th';
 
850
                if ($condition_field) {
 
851
                    echo ' class="condition"';
 
852
                }
 
853
                if ($disp_direction == 'horizontalflipped') {
 
854
                    echo ' valign="bottom"';
 
855
                }
 
856
                echo '>' . $order_link . $comments . '</th>';
 
857
            }
 
858
            $vertical_display['desc'][] = '    <th '
 
859
                . ($condition_field ? ' class="condition"' : '') . '>' . "\n"
 
860
                . $order_link . $comments . '    </th>' . "\n";
 
861
        } // end if (2.1)
 
862
 
 
863
        // 2.2 Results can't be sorted
 
864
        else {
 
865
            if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
 
866
                echo '<th';
 
867
                if ($condition_field) {
 
868
                    echo ' class="condition"';
 
869
                }
 
870
                if ($disp_direction == 'horizontalflipped') {
 
871
                    echo ' valign="bottom"';
 
872
                }
 
873
                if ($disp_direction == 'horizontalflipped'
 
874
                 && $GLOBALS['cfg']['HeaderFlipType'] == 'css') {
 
875
                    echo ' style="direction: ltr; writing-mode: tb-rl;"';
 
876
                }
 
877
                echo '>';
 
878
                if ($disp_direction == 'horizontalflipped'
 
879
                 && $GLOBALS['cfg']['HeaderFlipType'] == 'fake') {
 
880
                    echo PMA_flipstring(htmlspecialchars($fields_meta[$i]->name), '<br />');
 
881
                } else {
 
882
                    echo htmlspecialchars($fields_meta[$i]->name);
 
883
                }
 
884
                echo "\n" . $comments . '</th>';
 
885
            }
 
886
            $vertical_display['desc'][] = '    <th '
 
887
                . ($condition_field ? ' class="condition"' : '') . '>' . "\n"
 
888
                . '        ' . htmlspecialchars($fields_meta[$i]->name) . "\n"
 
889
                . $comments . '    </th>';
 
890
        } // end else (2.2)
 
891
    } // end for
 
892
 
 
893
    // 3. Displays the full/partial text button (part 2) at the right
 
894
    //    column of the result table header if possible and required...
 
895
    if ($GLOBALS['cfg']['ModifyDeleteAtRight']
 
896
        && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')
 
897
        && $is_display['text_btn'] == '1') {
 
898
        $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 1;
 
899
        if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
 
900
            echo "\n";
 
901
            ?>
 
902
<th <?php echo $colspan; ?>>
 
903
    <?php echo $text_link; ?>
 
904
</th>
 
905
            <?php
 
906
        } // end horizontal/horizontalflipped mode
 
907
        else {
 
908
            $vertical_display['textbtn'] = '    <th ' . $rowspan . ' valign="middle">' . "\n"
 
909
                                         . '        ' . $text_link . "\n"
 
910
                                         . '    </th>' . "\n";
 
911
        } // end vertical mode
 
912
    }
 
913
 
 
914
    //     ... elseif no button, displays empty cols if required
 
915
    // (unless coming from Browse mode print view)
 
916
    elseif ($GLOBALS['cfg']['ModifyDeleteAtRight']
 
917
             && ($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
 
918
             && (!$GLOBALS['is_header_sent'])) {
 
919
        $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 1;
 
920
        if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
 
921
            echo "\n";
 
922
            ?>
 
923
<td<?php echo $colspan; ?>></td>
 
924
            <?php
 
925
        } // end horizontal/horizontalflipped mode
 
926
        else {
 
927
            $vertical_display['textbtn'] = '    <td' . $rowspan . '></td>' . "\n";
 
928
        } // end vertical mode
 
929
    }
 
930
 
 
931
    if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
 
932
        ?>
 
933
</tr>
 
934
</thead>
 
935
        <?php
 
936
    }
 
937
 
 
938
    return true;
 
939
} // end of the 'PMA_displayTableHeaders()' function
 
940
 
 
941
 
 
942
 
 
943
/**
 
944
 * Displays the body of the results table
 
945
 *
 
946
 * @param   integer  the link id associated to the query which results have
 
947
 *                   to be displayed
 
948
 * @param   array    which elements to display
 
949
 * @param   array    the list of relations
 
950
 * @param   array    the analyzed query
 
951
 *
 
952
 * @return  boolean  always true
 
953
 *
 
954
 * @global  string   $db                the database name
 
955
 * @global  string   $table             the table name
 
956
 * @global  string   $goto              the url to go back in case of errors
 
957
 * @global  boolean  $dontlimitchars    whether to limit the number of displayed
 
958
 *                                      characters of text type fields or not
 
959
 * @global  string   $sql_query         the sql query
 
960
 * @global  integer  $pos               the current position in results
 
961
 * @global  integer  $session_max_rows  the maximum number of rows per page
 
962
 * @global  array    $fields_meta       the list of fields properties
 
963
 * @global  integer  $fields_cnt        the total number of fields returned by
 
964
 *                                      the sql query
 
965
 * @global  array    $vertical_display  informations used with vertical display
 
966
 *                                      mode
 
967
 * @global  string   $disp_direction    the display mode
 
968
 *                                      (horizontal/vertical/horizontalflipped)
 
969
 * @global  integer  $repeat_cells      the number of row to display between two
 
970
 *                                      table headers
 
971
 * @global  array    $highlight_columns collumn names to highlight
 
972
 * @gloabl  array    $row               current row data
 
973
 *
 
974
 * @access  private
 
975
 *
 
976
 * @see     PMA_displayTable()
 
977
 */
 
978
function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) {
 
979
    global $db, $table, $goto, $dontlimitchars;
 
980
    global $sql_query, $pos, $session_max_rows, $fields_meta, $fields_cnt;
 
981
    global $vertical_display, $disp_direction, $repeat_cells, $highlight_columns;
 
982
    global $row; // mostly because of browser transformations, to make the row-data accessible in a plugin
 
983
 
 
984
    $url_sql_query          = $sql_query;
 
985
 
 
986
    // query without conditions to shorten urls when needed, 200 is just
 
987
    // guess, it should depend on remaining url length
 
988
 
 
989
    if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
 
990
        isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' &&
 
991
        strlen($sql_query) > 200) {
 
992
 
 
993
        $url_sql_query = 'SELECT ';
 
994
        if (isset($analyzed_sql[0]['queryflags']['distinct'])) {
 
995
            $url_sql_query .= ' DISTINCT ';
 
996
        }
 
997
        $url_sql_query .= $analyzed_sql[0]['select_expr_clause'];
 
998
        if (!empty($analyzed_sql[0]['from_clause'])) {
 
999
            $url_sql_query .= ' FROM ' . $analyzed_sql[0]['from_clause'];
 
1000
        }
 
1001
    }
 
1002
 
 
1003
    if (!is_array($map)) {
 
1004
        $map = array();
 
1005
    }
 
1006
    $row_no                         = 0;
 
1007
    $vertical_display['edit']       = array();
 
1008
    $vertical_display['delete']     = array();
 
1009
    $vertical_display['data']       = array();
 
1010
    $vertical_display['row_delete'] = array();
 
1011
 
 
1012
    // Correction University of Virginia 19991216 in the while below
 
1013
    // Previous code assumed that all tables have keys, specifically that
 
1014
    // the phpMyAdmin GUI should support row delete/edit only for such
 
1015
    // tables.
 
1016
    // Although always using keys is arguably the prescribed way of
 
1017
    // defining a relational table, it is not required. This will in
 
1018
    // particular be violated by the novice.
 
1019
    // We want to encourage phpMyAdmin usage by such novices. So the code
 
1020
    // below has been changed to conditionally work as before when the
 
1021
    // table being displayed has one or more keys; but to display
 
1022
    // delete/edit options correctly for tables without keys.
 
1023
 
 
1024
    // loic1: use 'PMA_mysql_fetch_array' rather than 'PMA_mysql_fetch_row'
 
1025
    //        to get the NULL values
 
1026
 
 
1027
    // rabus: This function needs a little rework.
 
1028
    //        Using MYSQL_BOTH just pollutes the memory!
 
1029
 
 
1030
    // ne0x:  Use function PMA_DBI_fetch_array() due to mysqli
 
1031
    //        compatibility. Now this function is wrapped.
 
1032
 
 
1033
    $odd_row = true;
 
1034
    while ($row = PMA_DBI_fetch_row($dt_result)) {
 
1035
        // lem9: "vertical display" mode stuff
 
1036
        if ($row_no != 0 && $repeat_cells != 0 && !($row_no % $repeat_cells)
 
1037
          && ($disp_direction == 'horizontal'
 
1038
            || $disp_direction == 'horizontalflipped'))
 
1039
        {
 
1040
            echo '<tr>' . "\n";
 
1041
            if ($vertical_display['emptypre'] > 0) {
 
1042
                echo '    <th colspan="' . $vertical_display['emptypre'] . '">' . "\n"
 
1043
                    .'        &nbsp;</th>' . "\n";
 
1044
            }
 
1045
 
 
1046
            foreach ($vertical_display['desc'] as $val) {
 
1047
                echo $val;
 
1048
            }
 
1049
 
 
1050
            if ($vertical_display['emptyafter'] > 0) {
 
1051
                echo '    <th colspan="' . $vertical_display['emptyafter'] . '">' . "\n"
 
1052
                    .'        &nbsp;</th>' . "\n";
 
1053
            }
 
1054
            echo '</tr>' . "\n";
 
1055
        } // end if
 
1056
 
 
1057
        $class = $odd_row ? 'odd' : 'even';
 
1058
        $odd_row = ! $odd_row;
 
1059
        if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
 
1060
            // loic1: pointer code part
 
1061
            echo '    <tr class="' . $class . '">' . "\n";
 
1062
            $class = '';
 
1063
        }
 
1064
 
 
1065
 
 
1066
        // 1. Prepares the row (gets primary keys to use)
 
1067
        // 1.1 Results from a "SELECT" statement -> builds the
 
1068
        //     "primary" key to use in links
 
1069
        /**
 
1070
         * @todo $unique_condition could be empty, for example a table
 
1071
         *       with only one field and it's a BLOB; in this case,
 
1072
         *       avoid to display the delete and edit links
 
1073
         */
 
1074
 
 
1075
        $unique_condition     = urlencode(PMA_getUniqueCondition($dt_result, $fields_cnt, $fields_meta, $row));
 
1076
 
 
1077
        // 1.2 Defines the urls for the modify/delete link(s)
 
1078
        $url_query  = PMA_generate_common_url($db, $table)
 
1079
                    . '&amp;pos=' . $pos
 
1080
                    . '&amp;session_max_rows=' . $session_max_rows
 
1081
                    . '&amp;disp_direction=' . $disp_direction
 
1082
                    . '&amp;repeat_cells=' . $repeat_cells
 
1083
                    . '&amp;dontlimitchars=' . $dontlimitchars;
 
1084
 
 
1085
        if ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn') {
 
1086
            // We need to copy the value or else the == 'both' check will always return true
 
1087
 
 
1088
            if ($GLOBALS['cfg']['PropertiesIconic'] === 'both') {
 
1089
                $iconic_spacer = '<div class="nowrap">';
 
1090
            } else {
 
1091
                $iconic_spacer = '';
 
1092
            }
 
1093
 
 
1094
            // 1.2.1 Modify link(s)
 
1095
            if ($is_display['edit_lnk'] == 'ur') { // update row case
 
1096
                $lnk_goto = 'sql.php';
 
1097
 
 
1098
                $edit_url = 'tbl_change.php'
 
1099
                          . '?' . $url_query
 
1100
                          . '&amp;primary_key=' . $unique_condition
 
1101
                          . '&amp;sql_query=' . urlencode($url_sql_query)
 
1102
                          . '&amp;goto=' . urlencode($lnk_goto);
 
1103
                if ($GLOBALS['cfg']['PropertiesIconic'] === false) {
 
1104
                    $edit_str = $GLOBALS['strEdit'];
 
1105
                } else {
 
1106
                    $edit_str = $iconic_spacer . '<img class="icon" width="16" height="16" src="' . $GLOBALS['pmaThemeImage'] . 'b_edit.png" alt="' . $GLOBALS['strEdit'] . '" title="' . $GLOBALS['strEdit'] . '" />';
 
1107
                    if ($GLOBALS['cfg']['PropertiesIconic'] === 'both') {
 
1108
                        $edit_str .= ' ' . $GLOBALS['strEdit'] . '</div>';
 
1109
                    }
 
1110
                }
 
1111
            } // end if (1.2.1)
 
1112
 
 
1113
            if (isset($GLOBALS['cfg']['Bookmark']['table']) && isset($GLOBALS['cfg']['Bookmark']['db']) && $table == $GLOBALS['cfg']['Bookmark']['table'] && $db == $GLOBALS['cfg']['Bookmark']['db'] && isset($row[1]) && isset($row[0])) {
 
1114
                $bookmark_go = '<a href="import.php?'
 
1115
                                . PMA_generate_common_url($row[1], '')
 
1116
                                . '&amp;id_bookmark=' . $row[0]
 
1117
                                . '&amp;action_bookmark=0'
 
1118
                                . '&amp;action_bookmark_all=1'
 
1119
                                . '&amp;SQL=' . $GLOBALS['strExecuteBookmarked']
 
1120
                                .' " title="' . $GLOBALS['strExecuteBookmarked'] . '">';
 
1121
 
 
1122
                if ($GLOBALS['cfg']['PropertiesIconic'] === false) {
 
1123
                    $bookmark_go .= $GLOBALS['strExecuteBookmarked'];
 
1124
                } else {
 
1125
                    $bookmark_go .= $iconic_spacer . '<img class="icon" width="16" height="16" src="' . $GLOBALS['pmaThemeImage'] . 'b_bookmark.png" alt="' . $GLOBALS['strExecuteBookmarked'] . '" title="' . $GLOBALS['strExecuteBookmarked'] . '" />';
 
1126
                    if ($GLOBALS['cfg']['PropertiesIconic'] === 'both') {
 
1127
                        $bookmark_go .= ' ' . $GLOBALS['strExecuteBookmarked'] . '</div>';
 
1128
                    }
 
1129
                }
 
1130
 
 
1131
                $bookmark_go .= '</a>';
 
1132
            } else {
 
1133
                $bookmark_go = '';
 
1134
            }
 
1135
 
 
1136
            // 1.2.2 Delete/Kill link(s)
 
1137
            if ($is_display['del_lnk'] == 'dr') { // delete row case
 
1138
                $lnk_goto = 'sql.php'
 
1139
                          . '?' . str_replace('&amp;', '&', $url_query)
 
1140
                          . '&sql_query=' . urlencode($url_sql_query)
 
1141
                          . '&zero_rows=' . urlencode(htmlspecialchars($GLOBALS['strDeleted']))
 
1142
                          . '&goto=' . (empty($goto) ? 'tbl_sql.php' : $goto);
 
1143
                $del_query = urlencode('DELETE FROM ' . PMA_backquote($table) . ' WHERE') . $unique_condition . '+LIMIT+1';
 
1144
                $del_url  = 'sql.php'
 
1145
                          . '?' . $url_query
 
1146
                          . '&amp;sql_query=' . $del_query
 
1147
                          . '&amp;zero_rows=' . urlencode(htmlspecialchars($GLOBALS['strDeleted']))
 
1148
                          . '&amp;goto=' . urlencode($lnk_goto);
 
1149
                $js_conf  = 'DELETE FROM ' . PMA_jsFormat($table)
 
1150
                          . ' WHERE ' . trim(PMA_jsFormat(urldecode($unique_condition), false))
 
1151
                          . ' LIMIT 1';
 
1152
                if ($GLOBALS['cfg']['PropertiesIconic'] === false) {
 
1153
                    $del_str = $GLOBALS['strDelete'];
 
1154
                } else {
 
1155
                    $del_str = $iconic_spacer . '<img class="icon" width="16" height="16" src="' . $GLOBALS['pmaThemeImage'] . 'b_drop.png" alt="' . $GLOBALS['strDelete'] . '" title="' . $GLOBALS['strDelete'] . '" />';
 
1156
                    if ($GLOBALS['cfg']['PropertiesIconic'] === 'both') {
 
1157
                        $del_str .= ' ' . $GLOBALS['strDelete'] . '</div>';
 
1158
                    }
 
1159
                }
 
1160
            } elseif ($is_display['del_lnk'] == 'kp') { // kill process case
 
1161
                $lnk_goto = 'sql.php'
 
1162
                          . '?' . str_replace('&amp;', '&', $url_query)
 
1163
                          . '&sql_query=' . urlencode($url_sql_query)
 
1164
                          . '&goto=main.php';
 
1165
                $del_url  = 'sql.php?'
 
1166
                          . PMA_generate_common_url('mysql')
 
1167
                          . '&amp;sql_query=' . urlencode('KILL ' . $row[0])
 
1168
                          . '&amp;goto=' . urlencode($lnk_goto);
 
1169
                $del_query = urlencode('KILL ' . $row[0]);
 
1170
                $js_conf  = 'KILL ' . $row[0];
 
1171
                if ($GLOBALS['cfg']['PropertiesIconic'] === false) {
 
1172
                    $del_str = $GLOBALS['strKill'];
 
1173
                } else {
 
1174
                    $del_str = $iconic_spacer . '<img class="icon" width="16" height="16" src="' . $GLOBALS['pmaThemeImage'] . 'b_drop.png" alt="' . $GLOBALS['strKill'] . '" title="' . $GLOBALS['strKill'] . '" />';
 
1175
                    if ($GLOBALS['cfg']['PropertiesIconic'] === 'both') {
 
1176
                        $del_str .= ' ' . $GLOBALS['strKill'] . '</div>';
 
1177
                    }
 
1178
                }
 
1179
            } // end if (1.2.2)
 
1180
 
 
1181
            // 1.3 Displays the links at left if required
 
1182
            if ($GLOBALS['cfg']['ModifyDeleteAtLeft']
 
1183
                && ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped')) {
 
1184
                $doWriteModifyAt = 'left';
 
1185
                require './libraries/display_tbl_links.lib.php';
 
1186
            } // end if (1.3)
 
1187
        } // end if (1)
 
1188
 
 
1189
        // 2. Displays the rows' values
 
1190
        for ($i = 0; $i < $fields_cnt; ++$i) {
 
1191
            $meta    = $fields_meta[$i];
 
1192
            // loic1: To fix bug #474943 under php4, the row pointer will
 
1193
            //        depend on whether the "is_null" php4 function is
 
1194
            //        available or not
 
1195
            $pointer = (function_exists('is_null') ? $i : $meta->name);
 
1196
            // garvin: See if this column should get highlight because it's used in the
 
1197
            //  where-query.
 
1198
            if (isset($highlight_columns) && (isset($highlight_columns[$meta->name]) || isset($highlight_columns[PMA_backquote($meta->name)]))) {
 
1199
                $condition_field = true;
 
1200
            } else {
 
1201
                $condition_field = false;
 
1202
            }
 
1203
 
 
1204
            $mouse_events = '';
 
1205
            if ($disp_direction == 'vertical' && (!isset($GLOBALS['printview']) || ($GLOBALS['printview'] != '1'))) {
 
1206
                if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
 
1207
                    $mouse_events .= ' onmouseover="setVerticalPointer(this, ' . $row_no . ', \'over\', \'odd\', \'even\', \'hover\', \'marked\');"'
 
1208
                              . ' onmouseout="setVerticalPointer(this, ' . $row_no . ', \'out\', \'odd\', \'even\', \'hover\', \'marked\');" ';
 
1209
                }
 
1210
                if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
 
1211
                    $mouse_events .= ' onmousedown="setVerticalPointer(this, ' . $row_no . ', \'click\', \'odd\', \'even\', \'hover\', \'marked\'); setCheckboxColumn(\'id_rows_to_delete' . $row_no . '\');" ';
 
1212
                } else {
 
1213
                    $mouse_events .= ' onmousedown="setCheckboxColumn(\'id_rows_to_delete' . $row_no . '\');" ';
 
1214
                }
 
1215
            }// end if
 
1216
 
 
1217
            // garvin: Wrap MIME-transformations. [MIME]
 
1218
            $default_function = 'default_function'; // default_function
 
1219
            $transform_function = $default_function;
 
1220
            $transform_options = array();
 
1221
 
 
1222
            if ($GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {
 
1223
 
 
1224
                if (isset($GLOBALS['mime_map'][$meta->name]['mimetype']) && isset($GLOBALS['mime_map'][$meta->name]['transformation']) && !empty($GLOBALS['mime_map'][$meta->name]['transformation'])) {
 
1225
                    $include_file = PMA_sanitizeTransformationFile($GLOBALS['mime_map'][$meta->name]['transformation']);
 
1226
 
 
1227
                    if (file_exists('./libraries/transformations/' . $include_file)) {
 
1228
                        $transformfunction_name = preg_replace('@(\.inc\.php3?)$@i', '', $GLOBALS['mime_map'][$meta->name]['transformation']);
 
1229
 
 
1230
                        require_once './libraries/transformations/' . $include_file;
 
1231
 
 
1232
                        if (function_exists('PMA_transformation_' . $transformfunction_name)) {
 
1233
                            $transform_function = 'PMA_transformation_' . $transformfunction_name;
 
1234
                            $transform_options  = PMA_transformation_getOptions((isset($GLOBALS['mime_map'][$meta->name]['transformation_options']) ? $GLOBALS['mime_map'][$meta->name]['transformation_options'] : ''));
 
1235
                            $meta->mimetype     = str_replace('_', '/', $GLOBALS['mime_map'][$meta->name]['mimetype']);
 
1236
                        }
 
1237
                    } // end if file_exists
 
1238
                } // end if transformation is set
 
1239
            } // end if mime/transformation works.
 
1240
 
 
1241
            $transform_options['wrapper_link'] = '?'
 
1242
                                                . (isset($url_query) ? $url_query : '')
 
1243
                                                . '&amp;primary_key=' . (isset($unique_condition) ? $unique_condition : '')
 
1244
                                                . '&amp;sql_query=' . (isset($sql_query) ? urlencode($url_sql_query) : '')
 
1245
                                                . '&amp;goto=' . (isset($sql_goto) ? urlencode($lnk_goto) : '')
 
1246
                                                . '&amp;transform_key=' . urlencode($meta->name);
 
1247
 
 
1248
 
 
1249
            // n u m e r i c
 
1250
            if ($meta->numeric == 1) {
 
1251
 
 
1252
 
 
1253
            // lem9: if two fields have the same name (this is possible
 
1254
            //       with self-join queries, for example), using $meta->name
 
1255
            //       will show both fields NULL even if only one is NULL,
 
1256
            //       so use the $pointer
 
1257
            //      (works only if function_exists('is_null')
 
1258
            // PS:   why not always work with the number ($i), since
 
1259
            //       the default second parameter of
 
1260
            //       mysql_fetch_array() is MYSQL_BOTH, so we always get
 
1261
            //       associative and numeric indices?
 
1262
 
 
1263
                //if (!isset($row[$meta->name])
 
1264
                if (!isset($row[$i]) || is_null($row[$i])) {
 
1265
                    $vertical_display['data'][$row_no][$i]     = '    <td align="right"' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '"><i>NULL</i></td>' . "\n";
 
1266
                } elseif ($row[$i] != '') {
 
1267
                    $vertical_display['data'][$row_no][$i]     = '    <td align="right"' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . ' nowrap">';
 
1268
 
 
1269
                    if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) {
 
1270
                        foreach ($analyzed_sql[0]['select_expr'] AS $select_expr_position => $select_expr) {
 
1271
                            $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
 
1272
                            if (isset($alias) && strlen($alias)) {
 
1273
                                $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
 
1274
                                if ($alias == $meta->name) {
 
1275
                                    $meta->name = $true_column;
 
1276
                                } // end if
 
1277
                            } // end if
 
1278
                        } // end while
 
1279
                    }
 
1280
 
 
1281
                    if (isset($map[$meta->name])) {
 
1282
                        // Field to display from the foreign table?
 
1283
                        if (isset($map[$meta->name][2]) && strlen($map[$meta->name][2])) {
 
1284
                            $dispsql     = 'SELECT ' . PMA_backquote($map[$meta->name][2])
 
1285
                                         . ' FROM ' . PMA_backquote($map[$meta->name][3]) . '.' . PMA_backquote($map[$meta->name][0])
 
1286
                                         . ' WHERE ' . PMA_backquote($map[$meta->name][1])
 
1287
                                         . ' = ' . $row[$i];
 
1288
                            $dispresult  = PMA_DBI_try_query($dispsql, null, PMA_DBI_QUERY_STORE);
 
1289
                            if ($dispresult && PMA_DBI_num_rows($dispresult) > 0) {
 
1290
                                list($dispval) = PMA_DBI_fetch_row($dispresult, 0);
 
1291
                            } else {
 
1292
                                $dispval = $GLOBALS['strLinkNotFound'];
 
1293
                            }
 
1294
                            @PMA_DBI_free_result($dispresult);
 
1295
                        } else {
 
1296
                            $dispval     = '';
 
1297
                        } // end if... else...
 
1298
 
 
1299
                        if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
 
1300
                            $vertical_display['data'][$row_no][$i] .= ($transform_function != $default_function ? $transform_function($row[$i], $transform_options, $meta) : $transform_function($row[$i], array(), $meta)) . ' <code>[-&gt;' . $dispval . ']</code>';
 
1301
                        } else {
 
1302
                            $title = (!empty($dispval))? ' title="' . htmlspecialchars($dispval) . '"' : '';
 
1303
 
 
1304
                            $vertical_display['data'][$row_no][$i] .= '<a href="sql.php?'
 
1305
                                                                   .  PMA_generate_common_url($map[$meta->name][3], $map[$meta->name][0])
 
1306
                                                                   .  '&amp;pos=0&amp;session_max_rows=' . $session_max_rows . '&amp;dontlimitchars=' . $dontlimitchars
 
1307
                                                                   .  '&amp;sql_query=' . urlencode('SELECT * FROM ' . PMA_backquote($map[$meta->name][0]) . ' WHERE ' . PMA_backquote($map[$meta->name][1]) . ' = ' . $row[$i]) . '"' . $title . '>'
 
1308
                                                                   .  ($transform_function != $default_function ? $transform_function($row[$i], $transform_options, $meta) : $transform_function($row[$i], array(), $meta)) . '</a>';
 
1309
                        }
 
1310
                    } else {
 
1311
                        $vertical_display['data'][$row_no][$i] .= ($transform_function != $default_function ? $transform_function($row[$i], $transform_options, $meta) : $transform_function($row[$i], array(), $meta));
 
1312
                    }
 
1313
                    $vertical_display['data'][$row_no][$i]     .= '</td>' . "\n";
 
1314
                } else {
 
1315
                    $vertical_display['data'][$row_no][$i]     = '    <td align="right"' . $mouse_events . ' class="' . $class . ' nowrap' . ($condition_field ? ' condition' : '') . '">&nbsp;</td>' . "\n";
 
1316
                }
 
1317
 
 
1318
            //  b l o b
 
1319
 
 
1320
            } elseif ($GLOBALS['cfg']['ShowBlob'] == false && stristr($meta->type, 'BLOB')) {
 
1321
                // loic1 : PMA_mysql_fetch_fields returns BLOB in place of
 
1322
                // TEXT fields type, however TEXT fields must be displayed
 
1323
                // even if $GLOBALS['cfg']['ShowBlob'] is false -> get the true type
 
1324
                // of the fields.
 
1325
                $field_flags = PMA_DBI_field_flags($dt_result, $i);
 
1326
                if (stristr($field_flags, 'BINARY')) {
 
1327
                    $blobtext = '[BLOB';
 
1328
                    if (!isset($row[$i]) || is_null($row[$i])) {
 
1329
                        $blobtext .= ' - NULL';
 
1330
                        $blob_size = 0;
 
1331
                    } elseif (isset($row[$i])) {
 
1332
                        $blob_size = strlen($row[$i]);
 
1333
                        $display_blob_size = PMA_formatByteDown($blob_size, 3, 1);
 
1334
                        $blobtext .= ' - '. $display_blob_size[0] . ' ' . $display_blob_size[1];
 
1335
                        unset($display_blob_size);
 
1336
                    }
 
1337
 
 
1338
                    $blobtext .= ']';
 
1339
                    if (strpos($transform_function, 'octetstream')) {
 
1340
                        $blobtext = $row[$i];
 
1341
                    }
 
1342
                    if ($blob_size > 0) {
 
1343
                        $blobtext = ($default_function != $transform_function ? $transform_function($blobtext, $transform_options, $meta) : $default_function($blobtext, array(), $meta));
 
1344
                    }
 
1345
                    unset($blob_size);
 
1346
 
 
1347
                    $vertical_display['data'][$row_no][$i]      = '    <td align="left"' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '">' . $blobtext . '</td>';
 
1348
                } else {
 
1349
                    if (!isset($row[$i]) || is_null($row[$i])) {
 
1350
                        $vertical_display['data'][$row_no][$i] = '    <td' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '"><i>NULL</i></td>' . "\n";
 
1351
                    } elseif ($row[$i] != '') {
 
1352
                        // garvin: if a transform function for blob is set, none of these replacements will be made
 
1353
                        if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && ($dontlimitchars != 1)) {
 
1354
                            $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...';
 
1355
                        }
 
1356
                        // loic1: displays all space characters, 4 space
 
1357
                        // characters for tabulations and <cr>/<lf>
 
1358
                        $row[$i]     = ($default_function != $transform_function ? $transform_function($row[$i], $transform_options, $meta) : $default_function($row[$i], array(), $meta));
 
1359
 
 
1360
                        $vertical_display['data'][$row_no][$i] = '    <td' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '">' . $row[$i] . '</td>' . "\n";
 
1361
                    } else {
 
1362
                        $vertical_display['data'][$row_no][$i] = '    <td' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '">&nbsp;</td>' . "\n";
 
1363
                    }
 
1364
                }
 
1365
            } else {
 
1366
                if (!isset($row[$i]) || is_null($row[$i])) {
 
1367
                    $vertical_display['data'][$row_no][$i]     = '    <td' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '"><i>NULL</i></td>' . "\n";
 
1368
                } elseif ($row[$i] != '') {
 
1369
                    // loic1: support blanks in the key
 
1370
                    $relation_id = $row[$i];
 
1371
 
 
1372
                    // nijel: Cut all fields to $GLOBALS['cfg']['LimitChars']
 
1373
                    // lem9: (unless it's a link-type transformation)
 
1374
                    if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && ($dontlimitchars != 1) && !strpos($transform_function, 'link') === true) {
 
1375
                        $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...';
 
1376
                    }
 
1377
 
 
1378
                    // loic1: displays special characters from binaries
 
1379
                    $field_flags = PMA_DBI_field_flags($dt_result, $i);
 
1380
                    if (stristr($field_flags, 'BINARY')) {
 
1381
                        $row[$i]     = str_replace("\x00", '\0', $row[$i]);
 
1382
                        $row[$i]     = str_replace("\x08", '\b', $row[$i]);
 
1383
                        $row[$i]     = str_replace("\x0a", '\n', $row[$i]);
 
1384
                        $row[$i]     = str_replace("\x0d", '\r', $row[$i]);
 
1385
                        $row[$i]     = str_replace("\x1a", '\Z', $row[$i]);
 
1386
                        $row[$i]     = ($default_function != $transform_function ? $transform_function($row[$i], $transform_options, $meta) : $default_function($row[$i], array(), $meta));
 
1387
                    }
 
1388
                    // loic1: displays all space characters, 4 space
 
1389
                    // characters for tabulations and <cr>/<lf>
 
1390
                    else {
 
1391
                        $row[$i]     = ($default_function != $transform_function ? $transform_function($row[$i], $transform_options, $meta) : $default_function($row[$i], array(), $meta));
 
1392
                    }
 
1393
 
 
1394
                    // garvin: transform functions may enable nowrapping:
 
1395
                    $function_nowrap = $transform_function . '_nowrap';
 
1396
                    $bool_nowrap = (($default_function != $transform_function && function_exists($function_nowrap)) ? $function_nowrap($transform_options) : false);
 
1397
 
 
1398
                    // loic1: do not wrap if date field type
 
1399
                    $nowrap = ((preg_match('@DATE|TIME@i', $meta->type) || $bool_nowrap) ? ' nowrap' : '');
 
1400
                    $vertical_display['data'][$row_no][$i]     = '    <td' . $mouse_events . ' class="' . $class . $nowrap . ($condition_field ? ' condition' : '') . '">';
 
1401
 
 
1402
                    if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) {
 
1403
                        foreach ($analyzed_sql[0]['select_expr'] AS $select_expr_position => $select_expr) {
 
1404
                            $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
 
1405
                            if (isset($alias) && strlen($alias)) {
 
1406
                                $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
 
1407
                                if ($alias == $meta->name) {
 
1408
                                    $meta->name = $true_column;
 
1409
                                } // end if
 
1410
                            } // end if
 
1411
                        } // end while
 
1412
                    }
 
1413
 
 
1414
                    if (isset($map[$meta->name])) {
 
1415
                        // Field to display from the foreign table?
 
1416
                        if (isset($map[$meta->name][2]) && strlen($map[$meta->name][2])) {
 
1417
                            $dispsql     = 'SELECT ' . PMA_backquote($map[$meta->name][2])
 
1418
                                         . ' FROM ' . PMA_backquote($map[$meta->name][3]) . '.' . PMA_backquote($map[$meta->name][0])
 
1419
                                         . ' WHERE ' . PMA_backquote($map[$meta->name][1])
 
1420
                                         . ' = \'' . PMA_sqlAddslashes($row[$i]) . '\'';
 
1421
                            $dispresult  = PMA_DBI_try_query($dispsql, null, PMA_DBI_QUERY_STORE);
 
1422
                            if ($dispresult && PMA_DBI_num_rows($dispresult) > 0) {
 
1423
                                list($dispval) = PMA_DBI_fetch_row($dispresult);
 
1424
                                @PMA_DBI_free_result($dispresult);
 
1425
                            } else {
 
1426
                                $dispval = $GLOBALS['strLinkNotFound'];
 
1427
                            }
 
1428
                        } else {
 
1429
                            $dispval = '';
 
1430
                        }
 
1431
                        $title = (!empty($dispval))? ' title="' . htmlspecialchars($dispval) . '"' : '';
 
1432
 
 
1433
                        $vertical_display['data'][$row_no][$i] .= '<a href="sql.php?'
 
1434
                                                               .  PMA_generate_common_url($map[$meta->name][3], $map[$meta->name][0])
 
1435
                                                               .  '&amp;pos=0&amp;session_max_rows=' . $session_max_rows . '&amp;dontlimitchars=' . $dontlimitchars
 
1436
                                                               .  '&amp;sql_query=' . urlencode('SELECT * FROM ' . PMA_backquote($map[$meta->name][0]) . ' WHERE ' . PMA_backquote($map[$meta->name][1]) . ' = \'' . PMA_sqlAddslashes($relation_id) . '\'') . '"' . $title . '>'
 
1437
                                                               .  $row[$i] . '</a>';
 
1438
                    } else {
 
1439
                        $vertical_display['data'][$row_no][$i] .= $row[$i];
 
1440
                    }
 
1441
                    $vertical_display['data'][$row_no][$i]     .= '</td>' . "\n";
 
1442
                } else {
 
1443
                    $vertical_display['data'][$row_no][$i]     = '    <td' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '">&nbsp;</td>' . "\n";
 
1444
                }
 
1445
            }
 
1446
 
 
1447
            // lem9: output stored cell
 
1448
            if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
 
1449
                echo $vertical_display['data'][$row_no][$i];
 
1450
            }
 
1451
 
 
1452
            if (isset($vertical_display['rowdata'][$i][$row_no])) {
 
1453
                $vertical_display['rowdata'][$i][$row_no] .= $vertical_display['data'][$row_no][$i];
 
1454
            } else {
 
1455
                $vertical_display['rowdata'][$i][$row_no] = $vertical_display['data'][$row_no][$i];
 
1456
            }
 
1457
        } // end for (2)
 
1458
 
 
1459
        // 3. Displays the modify/delete links on the right if required
 
1460
        if ($GLOBALS['cfg']['ModifyDeleteAtRight']
 
1461
            && ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped')) {
 
1462
                $doWriteModifyAt = 'right';
 
1463
                require './libraries/display_tbl_links.lib.php';
 
1464
        } // end if (3)
 
1465
 
 
1466
        if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
 
1467
            ?>
 
1468
</tr>
 
1469
            <?php
 
1470
        } // end if
 
1471
 
 
1472
        // 4. Gather links of del_urls and edit_urls in an array for later
 
1473
        //    output
 
1474
        if (!isset($vertical_display['edit'][$row_no])) {
 
1475
            $vertical_display['edit'][$row_no]       = '';
 
1476
            $vertical_display['delete'][$row_no]     = '';
 
1477
            $vertical_display['row_delete'][$row_no] = '';
 
1478
        }
 
1479
 
 
1480
        $column_style_vertical = '';
 
1481
        if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
 
1482
            $column_style_vertical .= ' onmouseover="setVerticalPointer(this, ' . $row_no . ', \'over\', \'odd\', \'even\', \'hover\', \'marked\');"'
 
1483
                         . ' onmouseout="setVerticalPointer(this, ' . $row_no . ', \'out\', \'odd\', \'even\', \'hover\', \'marked\');"';
 
1484
        }
 
1485
        $column_marker_vertical = '';
 
1486
        if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
 
1487
            $column_marker_vertical .= 'setVerticalPointer(this, ' . $row_no . ', \'click\', \'odd\', \'even\', \'hover\', \'marked\');';
 
1488
        }
 
1489
 
 
1490
        if (!empty($del_url) && $is_display['del_lnk'] != 'kp') {
 
1491
            $vertical_display['row_delete'][$row_no] .= '    <td align="center" class="' . $class . '" ' . $column_style_vertical . '>' . "\n"
 
1492
                                                     .  '        <input type="checkbox" id="id_rows_to_delete' . $row_no . '[%_PMA_CHECKBOX_DIR_%]" name="rows_to_delete[' . $unique_condition . ']"'
 
1493
                                                     .  ' onclick="' . $column_marker_vertical . 'copyCheckboxesRange(\'rowsDeleteForm\', \'id_rows_to_delete' . $row_no . '\',\'[%_PMA_CHECKBOX_DIR_%]\');"'
 
1494
                                                     .  ' value="' . $del_query . '" ' . (isset($GLOBALS['checkall']) ? 'checked="checked"' : '') . ' />' . "\n"
 
1495
                                                     .  '    </td>' . "\n";
 
1496
        } else {
 
1497
            unset($vertical_display['row_delete'][$row_no]);
 
1498
        }
 
1499
 
 
1500
        if (isset($edit_url)) {
 
1501
            $vertical_display['edit'][$row_no]   .= '    <td align="center" class="' . $class . '" ' . $column_style_vertical . '>' . "\n"
 
1502
                                                 . PMA_linkOrButton($edit_url, $edit_str, array(), false)
 
1503
                                                 . $bookmark_go
 
1504
                                                 .  '    </td>' . "\n";
 
1505
        } else {
 
1506
            unset($vertical_display['edit'][$row_no]);
 
1507
        }
 
1508
 
 
1509
        if (isset($del_url)) {
 
1510
            $vertical_display['delete'][$row_no] .= '    <td align="center" class="' . $class . '" ' . $column_style_vertical . '>' . "\n"
 
1511
                                                 . PMA_linkOrButton($del_url, $del_str, (isset($js_conf) ? $js_conf : ''), false)
 
1512
                                                 .  '    </td>' . "\n";
 
1513
        } else {
 
1514
            unset($vertical_display['delete'][$row_no]);
 
1515
        }
 
1516
 
 
1517
        echo (($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') ? "\n" : '');
 
1518
        $row_no++;
 
1519
    } // end while
 
1520
 
 
1521
    if (isset($url_query)) {
 
1522
        $GLOBALS['url_query'] = $url_query;
 
1523
    }
 
1524
 
 
1525
    return true;
 
1526
} // end of the 'PMA_displayTableBody()' function
 
1527
 
 
1528
 
 
1529
/**
 
1530
 * Do display the result table with the vertical direction mode.
 
1531
 * Credits for this feature goes to Garvin Hicking <hicking@faktor-e.de>.
 
1532
 *
 
1533
 * @return  boolean  always true
 
1534
 *
 
1535
 * @global  array    $vertical_display the information to display
 
1536
 * @global  integer  $repeat_cells     the number of row to display between two
 
1537
 *                                     table headers
 
1538
 *
 
1539
 * @access  private
 
1540
 *
 
1541
 * @see     PMA_displayTable()
 
1542
 */
 
1543
function PMA_displayVerticalTable()
 
1544
{
 
1545
    global $vertical_display, $repeat_cells;
 
1546
 
 
1547
    // Displays "multi row delete" link at top if required
 
1548
    if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['row_delete']) && (count($vertical_display['row_delete']) > 0 || !empty($vertical_display['textbtn']))) {
 
1549
        echo '<tr>' . "\n";
 
1550
        echo $vertical_display['textbtn'];
 
1551
        $foo_counter = 0;
 
1552
        foreach ($vertical_display['row_delete'] as $val) {
 
1553
            if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
 
1554
                echo '<th>&nbsp;</th>' . "\n";
 
1555
            }
 
1556
 
 
1557
            echo str_replace('[%_PMA_CHECKBOX_DIR_%]', '', $val);
 
1558
            $foo_counter++;
 
1559
        } // end while
 
1560
        echo '</tr>' . "\n";
 
1561
    } // end if
 
1562
 
 
1563
    // Displays "edit" link at top if required
 
1564
    if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['edit']) && (count($vertical_display['edit']) > 0 || !empty($vertical_display['textbtn']))) {
 
1565
        echo '<tr>' . "\n";
 
1566
        if (!is_array($vertical_display['row_delete'])) {
 
1567
            echo $vertical_display['textbtn'];
 
1568
        }
 
1569
        $foo_counter = 0;
 
1570
        foreach ($vertical_display['edit'] as $val) {
 
1571
            if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
 
1572
                echo '    <th>&nbsp;</th>' . "\n";
 
1573
            }
 
1574
 
 
1575
            echo $val;
 
1576
            $foo_counter++;
 
1577
        } // end while
 
1578
        echo '</tr>' . "\n";
 
1579
    } // end if
 
1580
 
 
1581
    // Displays "delete" link at top if required
 
1582
    if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['delete']) && (count($vertical_display['delete']) > 0 || !empty($vertical_display['textbtn']))) {
 
1583
        echo '<tr>' . "\n";
 
1584
        if (!is_array($vertical_display['edit']) && !is_array($vertical_display['row_delete'])) {
 
1585
            echo $vertical_display['textbtn'];
 
1586
        }
 
1587
        $foo_counter = 0;
 
1588
        foreach ($vertical_display['delete'] as $val) {
 
1589
            if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
 
1590
                echo '<th>&nbsp;</th>' . "\n";
 
1591
            }
 
1592
 
 
1593
            echo $val;
 
1594
            $foo_counter++;
 
1595
        } // end while
 
1596
        echo '</tr>' . "\n";
 
1597
    } // end if
 
1598
 
 
1599
    // Displays data
 
1600
    foreach ($vertical_display['desc'] AS $key => $val) {
 
1601
 
 
1602
        echo '<tr>' . "\n";
 
1603
        echo $val;
 
1604
 
 
1605
        $foo_counter = 0;
 
1606
        foreach ($vertical_display['rowdata'][$key] as $subval) {
 
1607
            if (($foo_counter != 0) && ($repeat_cells != 0) and !($foo_counter % $repeat_cells)) {
 
1608
                echo $val;
 
1609
            }
 
1610
 
 
1611
            echo $subval;
 
1612
            $foo_counter++;
 
1613
        } // end while
 
1614
 
 
1615
        echo '</tr>' . "\n";
 
1616
    } // end while
 
1617
 
 
1618
    // Displays "multi row delete" link at bottom if required
 
1619
    if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['row_delete']) && (count($vertical_display['row_delete']) > 0 || !empty($vertical_display['textbtn']))) {
 
1620
        echo '<tr>' . "\n";
 
1621
        echo $vertical_display['textbtn'];
 
1622
        $foo_counter = 0;
 
1623
        foreach ($vertical_display['row_delete'] as $val) {
 
1624
            if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
 
1625
                echo '<th>&nbsp;</th>' . "\n";
 
1626
            }
 
1627
 
 
1628
            echo str_replace('[%_PMA_CHECKBOX_DIR_%]', 'r', $val);
 
1629
            $foo_counter++;
 
1630
        } // end while
 
1631
        echo '</tr>' . "\n";
 
1632
    } // end if
 
1633
 
 
1634
    // Displays "edit" link at bottom if required
 
1635
    if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['edit']) && (count($vertical_display['edit']) > 0 || !empty($vertical_display['textbtn']))) {
 
1636
        echo '<tr>' . "\n";
 
1637
        if (!is_array($vertical_display['row_delete'])) {
 
1638
            echo $vertical_display['textbtn'];
 
1639
        }
 
1640
        $foo_counter = 0;
 
1641
        foreach ($vertical_display['edit'] as $val) {
 
1642
            if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
 
1643
                echo '<th>&nbsp;</th>' . "\n";
 
1644
            }
 
1645
 
 
1646
            echo $val;
 
1647
            $foo_counter++;
 
1648
        } // end while
 
1649
        echo '</tr>' . "\n";
 
1650
    } // end if
 
1651
 
 
1652
    // Displays "delete" link at bottom if required
 
1653
    if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['delete']) && (count($vertical_display['delete']) > 0 || !empty($vertical_display['textbtn']))) {
 
1654
        echo '<tr>' . "\n";
 
1655
        if (!is_array($vertical_display['edit']) && !is_array($vertical_display['row_delete'])) {
 
1656
            echo $vertical_display['textbtn'];
 
1657
        }
 
1658
        $foo_counter = 0;
 
1659
        foreach ($vertical_display['delete'] as $val) {
 
1660
            if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
 
1661
                echo '<th>&nbsp;</th>' . "\n";
 
1662
            }
 
1663
 
 
1664
            echo $val;
 
1665
            $foo_counter++;
 
1666
        } // end while
 
1667
        echo '</tr>' . "\n";
 
1668
    }
 
1669
 
 
1670
    return true;
 
1671
} // end of the 'PMA_displayVerticalTable' function
 
1672
 
 
1673
 
 
1674
/**
 
1675
 * Displays a table of results returned by a sql query.
 
1676
 * This function is called by the "sql.php" script.
 
1677
 *
 
1678
 * @param   integer the link id associated to the query which results have
 
1679
 *                  to be displayed
 
1680
 * @param   array   the display mode
 
1681
 * @param   array   the analyzed query
 
1682
 *
 
1683
 * @global  string   $db                the database name
 
1684
 * @global  string   $table             the table name
 
1685
 * @global  string   $goto              the url to go back in case of errors
 
1686
 * @global  boolean  $dontlimitchars    whether to limit the number of displayed
 
1687
 *                                      characters of text type fields or not
 
1688
 * @global  string   $sql_query         the current sql query
 
1689
 * @global  integer  $num_rows          the total number of rows returned by the
 
1690
 *                                      sql query
 
1691
 * @global  integer  $unlim_num_rows    the total number of rows returned by the
 
1692
 *                                      sql query without any programmatically
 
1693
 *                                      appended "LIMIT" clause
 
1694
 * @global  integer  $pos               the current postion of the first record
 
1695
 *                                      to be displayed
 
1696
 * @global  array    $fields_meta       the list of fields properties
 
1697
 * @global  integer  $fields_cnt        the total number of fields returned by
 
1698
 *                                      the sql query
 
1699
 * @global  array    $vertical_display  informations used with vertical display
 
1700
 *                                      mode
 
1701
 * @global  string   $disp_direction    the display mode
 
1702
 *                                      (horizontal/vertical/horizontalflipped)
 
1703
 * @global  integer  $repeat_cells      the number of row to display between two
 
1704
 *                                      table headers
 
1705
 * @global  array    $highlight_columns collumn names to highlight
 
1706
 * @global  array    $cfgRelation       the relation settings
 
1707
 *
 
1708
 * @access  private
 
1709
 *
 
1710
 * @see     PMA_showMessage(), PMA_setDisplayMode(),
 
1711
 *          PMA_displayTableNavigation(), PMA_displayTableHeaders(),
 
1712
 *          PMA_displayTableBody(), PMA_displayResultsOperations()
 
1713
 */
 
1714
function PMA_displayTable(&$dt_result, &$the_disp_mode, $analyzed_sql)
 
1715
{
 
1716
    global $db, $table, $goto, $dontlimitchars;
 
1717
    global $sql_query, $num_rows, $unlim_num_rows, $pos, $fields_meta, $fields_cnt;
 
1718
    global $vertical_display, $disp_direction, $repeat_cells, $highlight_columns;
 
1719
    global $cfgRelation;
 
1720
 
 
1721
    // 1. ----- Prepares the work -----
 
1722
 
 
1723
    // 1.1 Gets the informations about which functionnalities should be
 
1724
    //     displayed
 
1725
    $total      = '';
 
1726
    $is_display = PMA_setDisplayMode($the_disp_mode, $total);
 
1727
    if ($total == '') {
 
1728
        unset($total);
 
1729
    }
 
1730
 
 
1731
    // 1.2 Defines offsets for the next and previous pages
 
1732
    if ($is_display['nav_bar'] == '1') {
 
1733
        if (!isset($pos)) {
 
1734
            $pos          = 0;
 
1735
        }
 
1736
        if ($GLOBALS['session_max_rows'] == 'all') {
 
1737
            $pos_next     = 0;
 
1738
            $pos_prev     = 0;
 
1739
        } else {
 
1740
            $pos_next     = $pos + $GLOBALS['cfg']['MaxRows'];
 
1741
            $pos_prev     = $pos - $GLOBALS['cfg']['MaxRows'];
 
1742
            if ($pos_prev < 0) {
 
1743
                $pos_prev = 0;
 
1744
            }
 
1745
        }
 
1746
    } // end if
 
1747
 
 
1748
    // 1.3 Urlencodes the query to use in input form fields
 
1749
    $encoded_sql_query = urlencode($sql_query);
 
1750
 
 
1751
    // 2. ----- Displays the top of the page -----
 
1752
 
 
1753
    // 2.1 Displays a messages with position informations
 
1754
    if ($is_display['nav_bar'] == '1' && isset($pos_next)) {
 
1755
        if (isset($unlim_num_rows) && $unlim_num_rows != $total) {
 
1756
            $selectstring = ', ' . $unlim_num_rows . ' ' . $GLOBALS['strSelectNumRows'];
 
1757
        } else {
 
1758
            $selectstring = '';
 
1759
        }
 
1760
        $last_shown_rec = ($GLOBALS['session_max_rows'] == 'all' || $pos_next > $total)
 
1761
                        ? $total - 1
 
1762
                        : $pos_next - 1;
 
1763
        PMA_showMessage($GLOBALS['strShowingRecords'] . " $pos - $last_shown_rec (" . PMA_formatNumber($total, 0) . ' ' . $GLOBALS['strTotal'] . $selectstring . ', ' . sprintf($GLOBALS['strQueryTime'], $GLOBALS['querytime']) . ')');
 
1764
        if (isset($table) && PMA_Table::isView($db, $table) && $total ==  $GLOBALS['cfg']['MaxExactCount']) {
 
1765
            echo '<div class="notice">' . "\n";
 
1766
            echo PMA_sanitize(sprintf($GLOBALS['strViewMaxExactCount'], PMA_formatNumber($GLOBALS['cfg']['MaxExactCount'], 0), '[a@./Documentation.html#cfg_MaxExactCount@_blank]', '[/a]')) . "\n";
 
1767
            echo '</div>' . "\n";
 
1768
        }
 
1769
 
 
1770
    } elseif (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
 
1771
        PMA_showMessage($GLOBALS['strSQLQuery']);
 
1772
    }
 
1773
 
 
1774
    // 2.3 Displays the navigation bars
 
1775
    if (!isset($table) || strlen(trim($table)) == 0) {
 
1776
        if (isset($analyzed_sql[0]['query_type'])
 
1777
           && $analyzed_sql[0]['query_type'] == 'SELECT') {
 
1778
            // table does not always contain a real table name,
 
1779
            // for example in MySQL 5.0.x, the query SHOW STATUS
 
1780
            // returns STATUS as a table name
 
1781
            $table = $fields_meta[0]->table;
 
1782
        } else {
 
1783
            $table = '';
 
1784
        }
 
1785
    }
 
1786
    if (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
 
1787
        PMA_displayResultsOperations($the_disp_mode, $analyzed_sql);
 
1788
    }
 
1789
    if ($is_display['nav_bar'] == '1') {
 
1790
        PMA_displayTableNavigation($pos_next, $pos_prev, $encoded_sql_query);
 
1791
        echo "\n";
 
1792
    } elseif (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
 
1793
        echo "\n" . '<br /><br />' . "\n";
 
1794
    }
 
1795
 
 
1796
    // 2b ----- Get field references from Database -----
 
1797
    // (see the 'relation' config variable)
 
1798
    // loic1, 2002-03-02: extended to php3
 
1799
 
 
1800
    // init map
 
1801
    $map = array();
 
1802
 
 
1803
    // find tables
 
1804
    $target=array();
 
1805
    if (isset($analyzed_sql[0]['table_ref']) && is_array($analyzed_sql[0]['table_ref'])) {
 
1806
        foreach ($analyzed_sql[0]['table_ref'] AS $table_ref_position => $table_ref) {
 
1807
           $target[] = $analyzed_sql[0]['table_ref'][$table_ref_position]['table_true_name'];
 
1808
        }
 
1809
    }
 
1810
    $tabs    = '(\'' . join('\',\'', $target) . '\')';
 
1811
 
 
1812
    if ($cfgRelation['displaywork']) {
 
1813
        if (! isset($table) || ! strlen($table)) {
 
1814
            $exist_rel = false;
 
1815
        } else {
 
1816
            $exist_rel = PMA_getForeigners($db, $table, '', 'both');
 
1817
            if ($exist_rel) {
 
1818
                foreach ($exist_rel AS $master_field => $rel) {
 
1819
                    $display_field = PMA_getDisplayField($rel['foreign_db'], $rel['foreign_table']);
 
1820
                    $map[$master_field] = array($rel['foreign_table'],
 
1821
                                          $rel['foreign_field'],
 
1822
                                          $display_field,
 
1823
                                          $rel['foreign_db']);
 
1824
                } // end while
 
1825
            } // end if
 
1826
        } // end if
 
1827
    } // end if
 
1828
    // end 2b
 
1829
 
 
1830
    // 3. ----- Displays the results table -----
 
1831
    PMA_displayTableHeaders($is_display, $fields_meta, $fields_cnt, $analyzed_sql);
 
1832
    $url_query='';
 
1833
    echo '<tbody>' . "\n";
 
1834
    PMA_displayTableBody($dt_result, $is_display, $map, $analyzed_sql);
 
1835
    echo '</tbody>' . "\n";
 
1836
    // vertical output case
 
1837
    if ($disp_direction == 'vertical') {
 
1838
        PMA_displayVerticalTable();
 
1839
    } // end if
 
1840
    unset($vertical_display);
 
1841
    ?>
 
1842
</table>
 
1843
 
 
1844
    <?php
 
1845
    // 4. ----- Displays the link for multi-fields delete
 
1846
 
 
1847
    if ($is_display['del_lnk'] == 'dr' && $is_display['del_lnk'] != 'kp') {
 
1848
 
 
1849
        $delete_text = $is_display['del_lnk'] == 'dr' ? $GLOBALS['strDelete'] : $GLOBALS['strKill'];
 
1850
 
 
1851
        $uncheckall_url = 'sql.php?'
 
1852
                  . PMA_generate_common_url($db, $table)
 
1853
                  . '&amp;sql_query=' . urlencode($sql_query)
 
1854
                  . '&amp;pos=' . $pos
 
1855
                  . '&amp;session_max_rows=' . $GLOBALS['session_max_rows']
 
1856
                  . '&amp;pos=' . $pos
 
1857
                  . '&amp;disp_direction=' . $disp_direction
 
1858
                  . '&amp;repeat_cells=' . $repeat_cells
 
1859
                  . '&amp;goto=' . $goto
 
1860
                  . '&amp;dontlimitchars=' . $dontlimitchars;
 
1861
        $checkall_url = $uncheckall_url . '&amp;checkall=1';
 
1862
 
 
1863
        if ($disp_direction == 'vertical') {
 
1864
            $checkall_params['onclick'] = 'if (setCheckboxes(\'rowsDeleteForm\', true)) return false;';
 
1865
            $uncheckall_params['onclick'] = 'if (setCheckboxes(\'rowsDeleteForm\', false)) return false;';
 
1866
        } else {
 
1867
            $checkall_params['onclick'] = 'if (markAllRows(\'rowsDeleteForm\')) return false;';
 
1868
            $uncheckall_params['onclick'] = 'if (unMarkAllRows(\'rowsDeleteForm\')) return false;';
 
1869
        }
 
1870
        $checkall_link = PMA_linkOrButton($checkall_url, $GLOBALS['strCheckAll'], $checkall_params, false);
 
1871
        $uncheckall_link = PMA_linkOrButton($uncheckall_url, $GLOBALS['strUncheckAll'], $uncheckall_params, false);
 
1872
        if ($disp_direction != 'vertical') {
 
1873
            echo '<img class="selectallarrow" width="38" height="22"'
 
1874
                .' src="' . $GLOBALS['pmaThemeImage'] . 'arrow_' . $GLOBALS['text_dir'] . '.png' . '"'
 
1875
                .' alt="' . $GLOBALS['strWithChecked'] . '" />';
 
1876
        }
 
1877
        echo $checkall_link . "\n"
 
1878
            .' / ' . "\n"
 
1879
            .$uncheckall_link . "\n"
 
1880
            .'<i>' . $GLOBALS['strWithChecked'] . '</i>' . "\n";
 
1881
 
 
1882
        if ($GLOBALS['cfg']['PropertiesIconic']) {
 
1883
            PMA_buttonOrImage('submit_mult', 'mult_submit',
 
1884
                'submit_mult_change', $GLOBALS['strChange'], 'b_edit.png');
 
1885
            PMA_buttonOrImage('submit_mult', 'mult_submit',
 
1886
                'submit_mult_delete', $delete_text, 'b_drop.png');
 
1887
            if ($analyzed_sql[0]['querytype'] == 'SELECT') {
 
1888
                PMA_buttonOrImage('submit_mult', 'mult_submit',
 
1889
                    'submit_mult_export', $GLOBALS['strExport'],
 
1890
                    'b_tblexport.png');
 
1891
            }
 
1892
            echo "\n";
 
1893
        } else {
 
1894
            echo ' <input type="submit" name="submit_mult"'
 
1895
                .' value="' . htmlspecialchars($GLOBALS['strEdit']) . '"'
 
1896
                .' title="' . $GLOBALS['strEdit'] . '" />' . "\n";
 
1897
            echo ' <input type="submit" name="submit_mult"'
 
1898
                .' value="' . htmlspecialchars($delete_text) . '"'
 
1899
                .' title="' . $delete_text . '" />' . "\n";
 
1900
            if ($analyzed_sql[0]['querytype'] == 'SELECT') {
 
1901
                echo ' <input type="submit" name="submit_mult"'
 
1902
                    .' value="' . htmlspecialchars($GLOBALS['strExport']) . '"'
 
1903
                    .' title="' . $GLOBALS['strExport'] . '" />' . "\n";
 
1904
            }
 
1905
        }
 
1906
        echo '<input type="hidden" name="sql_query"'
 
1907
            .' value="' . htmlspecialchars($sql_query) . '" />' . "\n";
 
1908
        echo '<input type="hidden" name="pos" value="' . $pos . '" />' . "\n";
 
1909
        echo '<input type="hidden" name="url_query"'
 
1910
            .' value="' . $GLOBALS['url_query'] . '" />' . "\n";
 
1911
        echo '</form>' . "\n";
 
1912
    }
 
1913
 
 
1914
    // 5. ----- Displays the navigation bar at the bottom if required -----
 
1915
 
 
1916
    if ($is_display['nav_bar'] == '1') {
 
1917
        echo '<br />' . "\n";
 
1918
        PMA_displayTableNavigation($pos_next, $pos_prev, $encoded_sql_query);
 
1919
    } elseif (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
 
1920
        echo "\n" . '<br /><br />' . "\n";
 
1921
    }
 
1922
} // end of the 'PMA_displayTable()' function
 
1923
 
 
1924
function default_function($buffer) {
 
1925
    $buffer = htmlspecialchars($buffer);
 
1926
    $buffer = str_replace("\011", ' &nbsp;&nbsp;&nbsp;',
 
1927
        str_replace('  ', ' &nbsp;', $buffer));
 
1928
    $buffer = preg_replace("@((\015\012)|(\015)|(\012))@", '<br />', $buffer);
 
1929
 
 
1930
    return $buffer;
 
1931
}
 
1932
 
 
1933
/**
 
1934
 * Displays operations that are available on results.
 
1935
 *
 
1936
 * @param   array   the display mode
 
1937
 * @param   array   the analyzed query
 
1938
 *
 
1939
 * @global  string   $db                the database name
 
1940
 * @global  string   $table             the table name
 
1941
 * @global  boolean  $dontlimitchars    whether to limit the number of displayed
 
1942
 *                                      characters of text type fields or not
 
1943
 * @global  integer  $pos               the current postion of the first record
 
1944
 *                                      to be displayed
 
1945
 * @global  string   $sql_query         the current sql query
 
1946
 * @global  integer  $unlim_num_rows    the total number of rows returned by the
 
1947
 *                                      sql query without any programmatically
 
1948
 *                                      appended "LIMIT" clause
 
1949
 * @global  string   $disp_direction    the display mode
 
1950
 *                                      (horizontal/vertical/horizontalflipped)
 
1951
 * @global  integer  $repeat_cells      the number of row to display between two
 
1952
 *                                      table headers
 
1953
 *
 
1954
 * @access  private
 
1955
 *
 
1956
 * @see     PMA_showMessage(), PMA_setDisplayMode(),
 
1957
 *          PMA_displayTableNavigation(), PMA_displayTableHeaders(),
 
1958
 *          PMA_displayTableBody(), PMA_displayResultsOperations()
 
1959
 */
 
1960
function PMA_displayResultsOperations($the_disp_mode, $analyzed_sql) {
 
1961
    global $db, $table, $dontlimitchars, $pos, $sql_query, $unlim_num_rows, $disp_direction, $repeat_cells;
 
1962
 
 
1963
    $header_shown = FALSE;
 
1964
    $header = '<fieldset><legend>' . $GLOBALS['strQueryResultsOperations'] . '</legend>';
 
1965
 
 
1966
    if ($the_disp_mode[6] == '1' || $the_disp_mode[9] == '1') {
 
1967
        // Displays "printable view" link if required
 
1968
        if ($the_disp_mode[9] == '1') {
 
1969
 
 
1970
            if (!$header_shown) {
 
1971
                echo $header;
 
1972
                $header_shown = TRUE;
 
1973
            }
 
1974
 
 
1975
            $url_query = '?'
 
1976
                       . PMA_generate_common_url($db, $table)
 
1977
                       . '&amp;pos=' . $pos
 
1978
                       . '&amp;session_max_rows=' . $GLOBALS['session_max_rows']
 
1979
                       . '&amp;disp_direction=' . $disp_direction
 
1980
                       . '&amp;repeat_cells=' . $repeat_cells
 
1981
                       . '&amp;printview=1'
 
1982
                       . '&amp;sql_query=' . urlencode($sql_query);
 
1983
            echo '    <!-- Print view -->' . "\n";
 
1984
            echo PMA_linkOrButton(
 
1985
                'sql.php' . $url_query . ((isset($dontlimitchars) && $dontlimitchars == '1') ? '&amp;dontlimitchars=1' : ''),
 
1986
                ($GLOBALS['cfg']['PropertiesIconic'] ? '<img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 'b_print.png" height="16" width="16" alt="' . $GLOBALS['strPrintView'] . '"/>' : '') . $GLOBALS['strPrintView'],
 
1987
                '', true, true, 'print_view') . "\n";
 
1988
 
 
1989
            if (!$dontlimitchars) {
 
1990
                echo   '    &nbsp;&nbsp;' . "\n";
 
1991
                echo PMA_linkOrButton(
 
1992
                    'sql.php' . $url_query . '&amp;dontlimitchars=1',
 
1993
                    ($GLOBALS['cfg']['PropertiesIconic'] ? '<img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 'b_print.png" height="16" width="16" alt="' . $GLOBALS['strPrintViewFull'] . '"/>' : '') . $GLOBALS['strPrintViewFull'],
 
1994
                    '', true, true, 'print_view') . "\n";
 
1995
            }
 
1996
        } // end displays "printable view"
 
1997
 
 
1998
        echo "\n";
 
1999
    }
 
2000
 
 
2001
    // Export link
 
2002
    // (the url_query has extra parameters that won't be used to export)
 
2003
    // (the single_table parameter is used in display_export.lib.php
 
2004
    //  to hide the SQL and the structure export dialogs)
 
2005
    if (isset($analyzed_sql[0]) && $analyzed_sql[0]['querytype'] == 'SELECT' && !isset($printview)) {
 
2006
        if (isset($analyzed_sql[0]['table_ref'][0]['table_true_name']) && !isset($analyzed_sql[0]['table_ref'][1]['table_true_name'])) {
 
2007
            $single_table   = '&amp;single_table=true';
 
2008
        } else {
 
2009
            $single_table   = '';
 
2010
        }
 
2011
        if (!$header_shown) {
 
2012
            echo $header;
 
2013
            $header_shown = TRUE;
 
2014
        }
 
2015
        echo '    <!-- Export -->' . "\n";
 
2016
        echo   '    &nbsp;&nbsp;' . "\n";
 
2017
        echo PMA_linkOrButton(
 
2018
            'tbl_export.php' . $url_query . '&amp;unlim_num_rows=' . $unlim_num_rows . $single_table,
 
2019
            ($GLOBALS['cfg']['PropertiesIconic'] ? '<img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 'b_tblexport.png" height="16" width="16" alt="' . $GLOBALS['strExport'] . '" />' : '') . $GLOBALS['strExport'],
 
2020
            '', true, true, '') . "\n";
 
2021
    }
 
2022
    if ($header_shown) {
 
2023
        echo '</fieldset><br />';
 
2024
    }
 
2025
}
 
2026
?>