Welcome to mirror list, hosted at ThFree Co, Russian Federation.

tbl_zoom_select.php - github.com/phpmyadmin/phpmyadmin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0e705ddf580a790cefa0b7117673a2c1be9c7dba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
 * Handles table zoom search tab
 *
 * display table zoom search form, create SQL queries from form data
 *
 * @package PhpMyAdmin
 */

/**
 * Gets some core libraries
 */
require_once './libraries/common.inc.php';
require_once './libraries/mysql_charsets.lib.php';
require_once './libraries/tbl_select.lib.php';
require_once './libraries/relation.lib.php';
require_once './libraries/tbl_info.inc.php';

$GLOBALS['js_include'][] = 'makegrid.js';
$GLOBALS['js_include'][] = 'sql.js';
$GLOBALS['js_include'][] = 'functions.js';
$GLOBALS['js_include'][] = 'date.js';
/* < IE 9 doesn't support canvas natively */
if (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER < 9) {
    $GLOBALS['js_include'][] = 'canvg/flashcanvas.js';
}

$GLOBALS['js_include'][] = 'jqplot/jquery.jqplot.js';
$GLOBALS['js_include'][] = 'jqplot/plugins/jqplot.canvasTextRenderer.js';
$GLOBALS['js_include'][] = 'jqplot/plugins/jqplot.canvasAxisLabelRenderer.js';
$GLOBALS['js_include'][] = 'jqplot/plugins/jqplot.dateAxisRenderer.js';
$GLOBALS['js_include'][] = 'jqplot/plugins/jqplot.highlighter.js';
$GLOBALS['js_include'][] = 'jqplot/plugins/jqplot.cursor.js';
$GLOBALS['js_include'][] = 'canvg/canvg.js';
$GLOBALS['js_include'][] = 'jquery/timepicker.js';
$GLOBALS['js_include'][] = 'tbl_zoom_plot_jqplot.js';

/**
 * Sets globals from $_POST
 */
$post_params = array(
    'collations',
    'dataLabel',
    'fields',
    'fields_null',
    'inputs',
    'maxPlotLimit',
    'types',
    'zoom_submit',
    'zoomFunc'
);
foreach ($post_params as $one_post_param) {
    if (isset($_POST[$one_post_param])) {
        $GLOBALS[$one_post_param] = $_POST[$one_post_param];
    }
}

/**
 * Handle AJAX request for data row on point select
 * @var post_params Object containing parameters for the POST request
 */

if (isset($_REQUEST['get_data_row']) && $_REQUEST['get_data_row'] == true) {
    $extra_data = array();
    $row_info_query = 'SELECT * FROM `' . $_REQUEST['db'] . '`.`'
        . $_REQUEST['table'] . '` WHERE ' .  $_REQUEST['where_clause'];
    $result = PMA_DBI_query($row_info_query . ";", null, PMA_DBI_QUERY_STORE);
    $fields_meta = PMA_DBI_get_fields_meta($result);
    while ($row = PMA_DBI_fetch_assoc($result)) {
        // for bit fields we need to convert them to printable form
        $i = 0;
        foreach ($row as $col => $val) {
            if ($fields_meta[$i]->type == 'bit') {
                $row[$col] = PMA_printableBitValue($val, $fields_meta[$i]->length);
            }
            $i++;
        }
        $extra_data['row_info'] = $row;
    }
    PMA_ajaxResponse(null, true, $extra_data);
}

/**
 * Handle AJAX request for changing field information
 * (value,collation,operators,field values) in input form
 * @var post_params Object containing parameters for the POST request
 */

if (isset($_REQUEST['change_tbl_info']) && $_REQUEST['change_tbl_info'] == true) {
    $extra_data = array();
    $field = $_REQUEST['field'];
    if ($field == 'pma_null') {
        $extra_data['field_type'] = '';
        $extra_data['field_collation'] = '';
        $extra_data['field_operators'] = '';
        PMA_ajaxResponse(null, true, $extra_data);
    }


    // Gets the list and number of fields
    list($fields_list, $fields_type, $fields_collation, $fields_null)
        = PMA_tbl_getFields($_REQUEST['db'], $_REQUEST['table']);

    $foreigners = PMA_getForeigners($db, $table);
    $titles['Browse'] = PMA_getIcon('b_browse.png', __('Browse foreign values'));
    $key = array_search($field, $fields_list);
    $extra_data['field_type'] = $fields_type[$key];
    $extra_data['field_collation'] = $fields_collation[$key];

    // HTML for operators
    $html = '<select name="zoomFunc[]">';
    $html .= $GLOBALS['PMA_Types']->getTypeOperatorsHtml(
        preg_replace('@\(.*@s', '', $fields_type[$key]),
        $fields_null[$key]
    );
    $html .= '</select>';
    $extra_data['field_operators'] = $html;

    // retrieve keys into foreign fields, if any
    // check also foreigners even if relwork is FALSE (to get
    // foreign keys from innodb)
    $foreignData = PMA_getForeignData($foreigners, $field, false, '', '');

    // HTML for field values
    $html = PMA_getForeignFields_Values(
        $foreigners,
        $foreignData,
        $field,
        array($_REQUEST['it'] => $fields_type[$key]),
        $_REQUEST['it'],
        $_REQUEST['db'],
        $_REQUEST['table'],
        $titles,
        $GLOBALS['cfg']['ForeignKeyMaxLimit'],
        ''
    );
    $extra_data['field_value'] = $html;
    PMA_ajaxResponse(null, true, $extra_data);
}

$titles['Browse'] = PMA_getIcon('b_browse.png', __('Browse foreign values'));
/**
 * Not selection yet required -> displays the selection form
 */

// Gets some core libraries
require_once './libraries/tbl_common.inc.php';
$url_query .= '&amp;goto=tbl_select.php&amp;back=tbl_select.php';

/**
 * Gets tables informations
 */
require_once './libraries/tbl_info.inc.php';

if (! isset($goto)) {
    $goto = $GLOBALS['cfg']['DefaultTabTable'];
}
// Defines the url to return to in case of error in the next sql statement
$err_url   = $goto . '?' . PMA_generate_common_url($db, $table);

// Gets the list and number of fields

list($fields_list, $fields_type, $fields_collation, $fields_null)
    = PMA_tbl_getFields($db, $table);
$fields_cnt = count($fields_list);

// retrieve keys into foreign fields, if any
// check also foreigners even if relwork is FALSE (to get
// foreign keys from innodb)
$foreigners = PMA_getForeigners($db, $table);
$tbl_fields_type = $tbl_fields_collation = $tbl_fields_null = array();

if (! isset($zoom_submit) && ! isset($inputs)) {
    $dataLabel = PMA_getDisplayField($db, $table);
}
?>
<div id="sqlqueryresults"></div>
<fieldset id="fieldset_subtab">
<?php
$url_params = array();
$url_params['db']    = $db;
$url_params['table'] = $table;
echo PMA_generateHtmlTabs(PMA_tbl_getSubTabs(), $url_params, 'topmenu2');

/**
 *  Set the field name,type,collation and whether null on select of a coulmn
 */
if (isset($inputs) && ($inputs[0] != 'pma_null' || $inputs[1] != 'pma_null')) {
    for ($i = 0 ; $i < 4 ; $i++) {
        if ($inputs[$i] != 'pma_null') {
            $key = array_search($inputs[$i], $fields_list);
            $tbl_fields_type[$i] = $fields_type[$key];
            $tbl_fields_collation[$i] = $fields_collation[$key];
            $tbl_fields_func[$i] = '<select name="zoomFunc[]">';
            $tbl_fields_func[$i] .= $GLOBALS['PMA_Types']->getTypeOperatorsHtml(
                preg_replace('@\(.*@s', '', $fields_type[$key]),
                $fields_null[$key], $zoomFunc[$i]
            );
            $tbl_fields_func[$i] .= '</select>';
            $foreignData = PMA_getForeignData($foreigners, $inputs[$i], false, '', '');
            $tbl_fields_value[$i] =  PMA_getForeignFields_Values(
                $foreigners,
                $foreignData,
                $inputs[$i],
                $tbl_fields_type,
                $i,
                $db,
                $table,
                $titles,
                $GLOBALS['cfg']['ForeignKeyMaxLimit'],
                $fields
            );
        }
    }
}

/*
 * Form for input criteria
 */

?>
<form method="post" action="tbl_zoom_select.php" name="insertForm" id="zoom_search_form"
    <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? ' class="ajax"' : ''); ?>>
<?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
<input type="hidden" name="goto" value="<?php echo $goto; ?>" />
<input type="hidden" name="back" value="tbl_zoom_select.php" />

<fieldset id="inputSection">

<legend><?php echo __('Do a "query by example" (wildcard: "%") for two different columns') ?></legend>
<table class="data" id="tableFieldsId">
<?php echo PMA_tbl_setTableHeader();?>
<tbody>
<?php
    $odd_row = true;

for ($i = 0; $i < 4; $i++) {
    if ($i == 2) {
        echo "<tr><td>";
        echo __("Additional search criteria");
        echo "</td></tr>";
    }
    ?>
    <tr class="noclick <?php echo $odd_row ? 'odd' : 'even'; $odd_row = ! $odd_row; ?>">
        <th><select name="inputs[]" id="<?php echo 'tableid_' . $i; ?>" >
        <option value="<?php echo 'pma_null'; ?>"><?php echo __('None');  ?></option>
    <?php
    for ($j = 0 ; $j < $fields_cnt ; $j++) {
        if (isset($inputs[$i]) && $inputs[$i] == htmlspecialchars($fields_list[$j])) {?>
            <option value="<?php echo htmlspecialchars($fields_list[$j]);?>" selected="selected">
                <?php echo htmlspecialchars($fields_list[$j]);?></option>
        <?php
        } else { ?>
            <option value="<?php echo htmlspecialchars($fields_list[$j]);?>">
                <?php echo htmlspecialchars($fields_list[$j]);?></option>
        <?php
        }
    } ?>
        </select></th>
        <td><?php if (isset($tbl_fields_type[$i])) echo $tbl_fields_type[$i]; ?></td>
        <td><?php if (isset($tbl_fields_collation[$i])) echo $tbl_fields_collation[$i]; ?></td>
        <td><?php if (isset($tbl_fields_func[$i])) echo $tbl_fields_func[$i]; ?></td>
        <td><?php if (isset($tbl_fields_value[$i])) echo $tbl_fields_value[$i]; ?></td>
    </tr>
    <tr><td>
    <input type="hidden" name="types[<?php echo $i; ?>]" id="types_<?php echo $i; ?>"
    <?php
    if (isset($_POST['types'][$i])) {
        echo 'value="' . $_POST['types'][$i] . '"';
    }
    ?> />
      <input type="hidden" name="collations[<?php echo $i;?>]" id="collations_<?php echo $i; ?>" />
    </td></tr>
    <?php
}//end for
?>
    </tbody>
    </table>

<?php
/*
 * Other inputs like data label and mode go after selection of column criteria
 */

//Set default datalabel if not selected
if (isset($zoom_submit) && $inputs[0] != 'pma_null' && $inputs[1] != 'pma_null') {
    if ($dataLabel == '') {
        $dataLabel = PMA_getDisplayField($db, $table);
    }
}
?>
    <table class="data">
    <tr><td><label for="dataLabel"><?php echo __("Use this column to label each point"); ?></label></td>
    <td><select name="dataLabel" id='dataLabel' >
        <option value = ''> <?php echo __('None');  ?> </option>
<?php
for ($j = 0; $j < $fields_cnt; $j++) {
    if (isset($dataLabel) && $dataLabel == htmlspecialchars($fields_list[$j])) {
        ?>
        <option value="<?php echo htmlspecialchars($fields_list[$j]);?>" selected="selected">
            <?php echo htmlspecialchars($fields_list[$j]);?></option>
        <?php
    } else {
        ?>
        <option value="<?php echo htmlspecialchars($fields_list[$j]);?>" >
            <?php echo htmlspecialchars($fields_list[$j]);?></option>
        <?php
    }
}
?>
    </select>
    </td></tr>
    <tr><td><label for="maxRowPlotLimit"><?php echo __("Maximum rows to plot"); ?></label></td>
    <td>
<?php
echo '<input type="text" name="maxPlotLimit" id="maxRowPlotLimit" value="';
if (! empty($maxPlotLimit)) {
    echo htmlspecialchars($maxPlotLimit);
} else {
    echo $GLOBALS['cfg']['maxRowPlotLimit'];
}
echo '" /></td></tr>';
?>
    </table>

</fieldset>
<fieldset class="tblFooters">
    <input type="submit" name="zoom_submit" id="inputFormSubmitId" value="<?php echo __('Go'); ?>" />
</fieldset>
</form>
</fieldset>

<?php

/*
 * Handle the input criteria and generate the query result
 * Form for displaying query results
 */
if (isset($zoom_submit)
    && $inputs[0] != 'pma_null'
    && $inputs[1] != 'pma_null'
    && $inputs[0] != $inputs[1]
) {

    /*
     * Query generation part
     */
    $w = $data = array();
    $sql_query = 'SELECT *';

    //Add the table
    $sql_query .= ' FROM ' . PMA_backquote($table);
    for ($i = 0; $i < 4; $i++) {
        if ($inputs[$i] == 'pma_null') {
            continue;
        }
        $tmp = array();
        // The where clause
        $charsets = array();
        $cnt_func = count($zoomFunc[$i]);
        $func_type = $zoomFunc[$i];
        list($charsets[$i]) = explode('_', $collations[$i]);
        $unaryFlag = $GLOBALS['PMA_Types']->isUnaryOperator($func_type);
        $whereClause = PMA_tbl_search_getWhereClause(
            $fields[$i], $inputs[$i], $types[$i],
            $collations[$i], $func_type, $unaryFlag
        );
        if ($whereClause) {
            $w[] = $whereClause;
        }
    } // end for
    if ($w) {
        $sql_query .= ' WHERE ' . implode(' AND ', $w);
    }
    $sql_query .= ' LIMIT ' . $maxPlotLimit;

    /*
     * Query execution part
     */
    $result = PMA_DBI_query($sql_query . ";", null, PMA_DBI_QUERY_STORE);
    $fields_meta = PMA_DBI_get_fields_meta($result);
    while ($row = PMA_DBI_fetch_assoc($result)) {
        //Need a row with indexes as 0,1,2 for the PMA_getUniqueCondition
        // hence using a temporary array
        $tmpRow = array();
        foreach ($row as $val) {
            $tmpRow[] = $val;
        }
        //Get unique conditon on each row (will be needed for row update)
        $uniqueCondition = PMA_getUniqueCondition(
            $result, $fields_cnt, $fields_meta, $tmpRow, true
        );

        //Append it to row array as where_clause
        $row['where_clause'] = $uniqueCondition[0];
        if ($dataLabel == $inputs[0] || $dataLabel == $inputs[1]) {
            $data[] = array(
                $inputs[0]     => $row[$inputs[0]],
                $inputs[1]     => $row[$inputs[1]],
                'where_clause' => $uniqueCondition[0]
            );
        } elseif ($dataLabel) {
            $data[] = array(
                $inputs[0]     => $row[$inputs[0]],
                $inputs[1]     => $row[$inputs[1]],
                $dataLabel     => $row[$dataLabel],
                'where_clause' => $uniqueCondition[0]
            );
        } else {
            $data[] = array(
                $inputs[0]     => $row[$inputs[0]],
                $inputs[1]     => $row[$inputs[1]],
                $dataLabel     => '',
                'where_clause' => $uniqueCondition[0]
            );
        }
    }
    /*
     * Form for displaying point data and also the scatter plot
     */
    ?>
    <form method="post" action="tbl_zoom_select.php" name="displayResultForm" id="zoom_display_form"
        <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? ' class="ajax"' : ''); ?>>
    <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
    <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
    <input type="hidden" name="back" value="tbl_zoom_select.php" />

    <fieldset id="displaySection">
      <legend><?php echo __('Browse/Edit the points') ?></legend>
      <center>
    <?php
    //JSON encode the data(query result)
    if (isset($zoom_submit) && ! empty($data)) {
        ?>
        <div id="resizer">
          <center><a href="#" onclick="displayHelp();"><?php echo __('How to use'); ?></a></center>
          <div id="querydata" style="display:none">
        <?php
        echo json_encode($data);
        ?>
          </div>
          <div id="querychart"></div>
          <button class="button-reset"><?php echo __('Reset zoom'); ?></button>
        </div>
        <?php
    }
    ?>
      </center>
      <div id='dataDisplay' style="display:none">
        <table>
          <thead>
            <tr>
              <th> <?php echo __('Column'); ?> </th>
              <th> <?php echo __('Null'); ?> </th>
              <th> <?php echo __('Value'); ?> </th>
            </tr>
          </thead>
          <tbody>
    <?php
    $odd_row = true;
    for ($i = 4; $i < $fields_cnt + 4; $i++) {
        $tbl_fields_type[$i] = $fields_type[$i - 4];
        $fieldpopup = $fields_list[$i - 4];
        $foreignData = PMA_getForeignData($foreigners, $fieldpopup, false, '', '');
        ?>
            <tr class="noclick <?php echo $odd_row ? 'odd' : 'even'; $odd_row = ! $odd_row; ?>">
              <th><?php echo htmlspecialchars($fields_list[$i - 4]); ?></th>
              <th><?php echo ($fields_null[$i - 4] == 'YES')
                  ? '<input type="checkbox" class="checkbox_null" name="fields_null[ '
                      . $i . ' ]" id="fields_null_id_' . $i . '" />'
                  : ''; ?>
              </th>
              <th> <?php
              echo PMA_getForeignFields_Values(
                  $foreigners, $foreignData, $fieldpopup, $tbl_fields_type,
                  $i, $db, $table, $titles,
                  $GLOBALS['cfg']['ForeignKeyMaxLimit'], '', false, true
              ); ?>
              </th>
            </tr>
        <?php
    }
    ?>
          </tbody>
        </table>
    </div>
    <input type="hidden" id="queryID" name="sql_query" />
    </form>
    <?php
}
require './libraries/footer.inc.php';
?>