aboutsummaryrefslogtreecommitdiff
path: root/srcs/phpmyadmin/tbl_row_action.php
blob: b26f1ecf89a22ef252f1ec2af174b8fc4d66ebec (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
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
 * handle row specific actions like edit, delete, export
 *
 * @package PhpMyAdmin
 */
declare(strict_types=1);

use PhpMyAdmin\Response;
use PhpMyAdmin\Sql;
use PhpMyAdmin\Url;

if (! defined('ROOT_PATH')) {
    define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR);
}

global $db, $pmaThemeImage, $sql_query, $table;

require_once ROOT_PATH . 'libraries/common.inc.php';

if (isset($_POST['submit_mult'])) {
    $submit_mult = $_POST['submit_mult'];
    // workaround for IE problem:
} elseif (isset($_POST['submit_mult_delete_x'])) {
    $submit_mult = 'row_delete';
} elseif (isset($_POST['submit_mult_change_x'])) {
    $submit_mult = 'row_edit';
} elseif (isset($_POST['submit_mult_export_x'])) {
    $submit_mult = 'row_export';
}

// If the 'Ask for confirmation' button was pressed, this can only come
// from 'delete' mode, so we set it straight away.
if (isset($_POST['mult_btn'])) {
    $submit_mult = 'row_delete';
}

if (! isset($submit_mult)) {
    $submit_mult = 'row_edit';
}

switch ($submit_mult) {
    case 'row_delete':
    case 'row_edit':
    case 'row_copy':
    case 'row_export':
        // leave as is
        break;

    case 'export':
        $submit_mult = 'row_export';
        break;

    case 'delete':
        $submit_mult = 'row_delete';
        break;

    case 'copy':
        $submit_mult = 'row_copy';
        break;

    case 'edit':
    default:
        $submit_mult = 'row_edit';
        break;
}

if (! empty($submit_mult)) {
    if (isset($_POST['goto'])
        && (! isset($_POST['rows_to_delete'])
        || ! is_array($_POST['rows_to_delete']))
    ) {
        $response = Response::getInstance();
        $response->setRequestStatus(false);
        $response->addJSON('message', __('No row selected.'));
    }

    switch ($submit_mult) {
    /** @noinspection PhpMissingBreakStatementInspection */
        case 'row_copy':
            $_POST['default_action'] = 'insert';
            // no break to allow for fallthough
        case 'row_edit':
            // As we got the rows to be edited from the
            // 'rows_to_delete' checkbox, we use the index of it as the
            // indicating WHERE clause. Then we build the array which is used
            // for the tbl_change.php script.
            $where_clause = [];
            if (isset($_POST['rows_to_delete'])
            && is_array($_POST['rows_to_delete'])
            ) {
                foreach ($_POST['rows_to_delete'] as $i => $i_where_clause) {
                    $where_clause[] = $i_where_clause;
                }
            }
            $active_page = 'tbl_change.php';
            include ROOT_PATH . 'tbl_change.php';
            break;

        case 'row_export':
            // Needed to allow SQL export
            $single_table = true;

            // As we got the rows to be exported from the
            // 'rows_to_delete' checkbox, we use the index of it as the
            // indicating WHERE clause. Then we build the array which is used
            // for the tbl_change.php script.
            $where_clause = [];
            if (isset($_POST['rows_to_delete'])
            && is_array($_POST['rows_to_delete'])
            ) {
                foreach ($_POST['rows_to_delete'] as $i => $i_where_clause) {
                    $where_clause[] = $i_where_clause;
                }
            }
            $active_page = 'tbl_export.php';
            include ROOT_PATH . 'tbl_export.php';
            break;

        case 'row_delete':
        default:
            $action = 'tbl_row_action.php';
            $err_url = 'tbl_row_action.php'
            . Url::getCommon($GLOBALS['url_params']);
            if (! isset($_POST['mult_btn'])) {
                $original_sql_query = $sql_query;
                if (! empty($url_query)) {
                    $original_url_query = $url_query;
                }
            }
            include ROOT_PATH . 'libraries/mult_submits.inc.php';
            $_url_params = $GLOBALS['url_params'];
            $_url_params['goto'] = 'tbl_sql.php';
            $url_query = Url::getCommon($_url_params);


            /**
         * Show result of multi submit operation
         */
            // sql_query is not set when user does not confirm multi-delete
            if ((! empty($submit_mult) || isset($_POST['mult_btn']))
            && ! empty($sql_query)
            ) {
                $disp_message = __('Your SQL query has been executed successfully.');
                $disp_query = $sql_query;
            }

            if (isset($original_sql_query)) {
                $sql_query = $original_sql_query;
            }

            if (isset($original_url_query)) {
                $url_query = $original_url_query;
            }

            $active_page = 'sql.php';
            $sql = new Sql();
            $sql->executeQueryAndSendQueryResponse(
                null, // analyzed_sql_results
                false, // is_gotofile
                $db, // db
                $table, // table
                null, // find_real_end
                null, // sql_query_for_bookmark
                null, // extra_data
                null, // message_to_show
                null, // message
                null, // sql_data
                $goto, // goto
                $pmaThemeImage, // pmaThemeImage
                null, // disp_query
                null, // disp_message
                null, // query_type
                $sql_query, // sql_query
                null, // selectedTables
                null // complete_query
            );
    }
}