This is not a know pseudoclass.
[phpmyadmin/crack.git] / libraries / mult_submits.inc.php
blob89bb4f6ac07ab034503a4e9b07281f461a938143
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @version $Id$
6 */
7 if (! defined('PHPMYADMIN')) {
8 exit;
11 /**
12 * Prepares the work and runs some other scripts if required
14 if (! empty($submit_mult)
15 && $submit_mult != $strWithChecked
16 && (! empty($selected_db)
17 || ! empty($selected_tbl)
18 || ! empty($selected_fld)
19 || ! empty($rows_to_delete))) {
20 define('PMA_SUBMIT_MULT', 1);
21 if (isset($selected_db) && !empty($selected_db)) {
22 // coming from server database view - do something with selected databases
23 $selected = $selected_db;
24 $what = 'drop_db';
25 } elseif (isset($selected_tbl) && !empty($selected_tbl)) {
26 // coming from database structure view - do something with selected tables
27 if ($submit_mult == $strPrintView) {
28 require './tbl_printview.php';
29 } else {
30 $selected = $selected_tbl;
31 switch ($submit_mult) {
32 case 'drop_db':
33 $what = 'drop_db';
34 break;
35 case $strDrop:
36 $what = 'drop_tbl';
37 break;
38 case $strEmpty:
39 $what = 'empty_tbl';
40 break;
41 case $strCheckTable:
42 unset($submit_mult);
43 $query_type = 'check_tbl';
44 $mult_btn = $strYes;
45 break;
46 case $strOptimizeTable:
47 unset($submit_mult);
48 $query_type = 'optimize_tbl';
49 $mult_btn = $strYes;
50 break;
51 case $strRepairTable:
52 unset($submit_mult);
53 $query_type = 'repair_tbl';
54 $mult_btn = $strYes;
55 break;
56 case $strAnalyzeTable:
57 unset($submit_mult);
58 $query_type = 'analyze_tbl';
59 $mult_btn = $strYes;
60 break;
61 } // end switch
63 } elseif (isset($selected_fld) && !empty($selected_fld)) {
64 // coming from table structure view - do something with selected columns/fileds
65 $selected = $selected_fld;
66 switch ($submit_mult) {
67 case $strDrop:
68 $what = 'drop_fld';
69 break;
70 case $strPrimary:
71 // Gets table primary key
72 PMA_DBI_select_db($db);
73 $result = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';');
74 $primary = '';
75 while ($row = PMA_DBI_fetch_assoc($result)) {
76 // Backups the list of primary keys
77 if ($row['Key_name'] == 'PRIMARY') {
78 $primary .= $row['Column_name'] . ', ';
80 } // end while
81 PMA_DBI_free_result($result);
82 if (empty($primary)) {
83 // no primary key, so we can safely create new
84 unset($submit_mult);
85 $query_type = 'primary_fld';
86 $mult_btn = $strYes;
87 } else {
88 // primary key exists, so lets as user
89 $what = 'primary_fld';
91 break;
92 case $strIndex:
93 unset($submit_mult);
94 $query_type = 'index_fld';
95 $mult_btn = $strYes;
96 break;
97 case $strUnique:
98 unset($submit_mult);
99 $query_type = 'unique_fld';
100 $mult_btn = $strYes;
101 break;
102 case $strIdxFulltext:
103 unset($submit_mult);
104 $query_type = 'fulltext_fld';
105 $mult_btn = $strYes;
106 break;
107 case $strChange:
108 require './tbl_alter.php';
109 break;
110 case $strBrowse:
111 // this should already be handled by tbl_structure.php
113 } else {
114 // coming from borwsing - do something with selected rows
115 $what = 'row_delete';
116 $selected = $rows_to_delete;
118 } // end if
122 * Displays the confirmation form if required
124 if (!empty($submit_mult) && !empty($what)) {
125 $GLOBALS['js_include'][] = 'functions.js';
126 unset($message);
128 require_once './libraries/header.inc.php';
129 if (strlen($table)) {
130 require './libraries/tbl_common.php';
131 $url_query .= '&amp;goto=tbl_sql.php&amp;back=tbl_sql.php';
132 require './libraries/tbl_info.inc.php';
133 require_once './libraries/tbl_links.inc.php';
134 } elseif (strlen($db)) {
135 require './libraries/db_common.inc.php';
136 require './libraries/db_info.inc.php';
137 } else {
138 require_once './libraries/server_common.inc.php';
139 require_once './libraries/server_links.inc.php';
142 // Builds the query
143 $full_query = '';
144 if ($what == 'drop_tbl') {
145 $full_query_views = '';
147 $selected_cnt = count($selected);
148 $i = 0;
149 foreach ($selected AS $idx => $sval) {
150 switch ($what) {
151 case 'row_delete':
152 $full_query .= htmlspecialchars($sval)
153 . ';<br />';
154 break;
155 case 'drop_db':
156 $full_query .= 'DROP DATABASE '
157 . PMA_backquote(htmlspecialchars($sval))
158 . ';<br />';
159 $reload = 1;
160 break;
162 case 'drop_tbl':
163 $current = $sval;
164 if (!empty($views) && in_array($current, $views)) {
165 $full_query_views .= (empty($full_query_views) ? 'DROP VIEW ' : ', ')
166 . PMA_backquote(htmlspecialchars($current));
167 } else {
168 $full_query .= (empty($full_query) ? 'DROP TABLE ' : ', ')
169 . PMA_backquote(htmlspecialchars($current));
171 break;
173 case 'empty_tbl':
174 $full_query .= 'TRUNCATE ';
175 $full_query .= PMA_backquote(htmlspecialchars($sval))
176 . ';<br />';
177 break;
179 case 'primary_fld':
180 if ($full_query == '') {
181 $full_query .= 'ALTER TABLE '
182 . PMA_backquote(htmlspecialchars($table))
183 . '<br />&nbsp;&nbsp;DROP PRIMARY KEY,'
184 . '<br />&nbsp;&nbsp; ADD PRIMARY KEY('
185 . '<br />&nbsp;&nbsp;&nbsp;&nbsp; '
186 . PMA_backquote(htmlspecialchars($sval))
187 . ',';
188 } else {
189 $full_query .= '<br />&nbsp;&nbsp;&nbsp;&nbsp; '
190 . PMA_backquote(htmlspecialchars($sval))
191 . ',';
193 if ($i == $selected_cnt-1) {
194 $full_query = preg_replace('@,$@', ');<br />', $full_query);
196 break;
198 case 'drop_fld':
199 if ($full_query == '') {
200 $full_query .= 'ALTER TABLE '
201 . PMA_backquote(htmlspecialchars($table));
203 $full_query .= '<br />&nbsp;&nbsp;DROP '
204 . PMA_backquote(htmlspecialchars($sval))
205 . ',';
206 if ($i == $selected_cnt - 1) {
207 $full_query = preg_replace('@,$@', ';<br />', $full_query);
209 break;
210 } // end switch
211 $i++;
213 if ($what == 'drop_tbl') {
214 if (!empty($full_query)) {
215 $full_query .= ';<br />' . "\n";
217 if (!empty($full_query_views)) {
218 $full_query .= $full_query_views . ';<br />' . "\n";
220 unset($full_query_views);
223 // Displays the confirmation form
224 $_url_params = array(
225 'query_type' => $what,
226 'reload' => (! empty($reload) ? 1 : 0),
228 if (strpos(' ' . $action, 'db_') == 1) {
229 $_url_params['db']= $db;
230 } elseif (strpos(' ' . $action, 'tbl_') == 1 || $what == 'row_delete') {
231 $_url_params['db']= $db;
232 $_url_params['table']= $table;
234 foreach ($selected as $idx => $sval) {
235 $_url_params['selected'][] = $sval;
237 if ($what == 'drop_tbl' && !empty($views)) {
238 foreach ($views as $current) {
239 $_url_params['views'][] = $current;
242 if ($what == 'row_delete') {
243 $_url_params['original_sql_query'] = $original_sql_query;
244 $_url_params['original_url_query'] = $original_url_query;
247 <form action="<?php echo $action; ?>" method="post">
248 <?php
249 echo PMA_generate_common_hidden_inputs($_url_params);
251 <fieldset class="confirmation">
252 <legend><?php echo ($what == 'drop_db' ? $strDropDatabaseStrongWarning . '&nbsp;' : '') . $strDoYouReally; ?>:</legend>
253 <tt><?php echo $full_query; ?></tt>
254 </fieldset>
255 <fieldset class="tblFooters">
256 <input type="submit" name="mult_btn" value="<?php echo $strYes; ?>" id="buttonYes" />
257 <input type="submit" name="mult_btn" value="<?php echo $strNo; ?>" id="buttonNo" />
258 </fieldset>
259 <?php
260 require_once './libraries/footer.inc.php';
261 } // end if
265 * Executes the query - dropping rows, columns/fields, tables or dbs
267 elseif ($mult_btn == $strYes) {
269 if ($query_type == 'drop_db' || $query_type == 'drop_tbl' || $query_type == 'drop_fld') {
270 require_once './libraries/relation_cleanup.lib.php';
273 $sql_query = '';
274 if ($query_type == 'drop_tbl') {
275 $sql_query_views = '';
277 $selected_cnt = count($selected);
278 $run_parts = FALSE; // whether to run query after each pass
279 $use_sql = FALSE; // whether to include sql.php at the end (to display results)
281 if ($query_type == 'primary_fld') {
282 // Gets table primary key
283 PMA_DBI_select_db($db);
284 $result = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';');
285 $primary = '';
286 while ($row = PMA_DBI_fetch_assoc($result)) {
287 // Backups the list of primary keys
288 if ($row['Key_name'] == 'PRIMARY') {
289 $primary .= $row['Column_name'] . ', ';
291 } // end while
292 PMA_DBI_free_result($result);
295 $rebuild_database_list = false;
297 for ($i = 0; $i < $selected_cnt; $i++) {
298 switch ($query_type) {
299 case 'row_delete':
300 $a_query = $selected[$i];
301 $run_parts = TRUE;
302 break;
304 case 'drop_db':
305 PMA_relationsCleanupDatabase($selected[$i]);
306 $a_query = 'DROP DATABASE '
307 . PMA_backquote($selected[$i]);
308 $reload = 1;
309 $run_parts = TRUE;
310 $rebuild_database_list = true;
311 break;
313 case 'drop_tbl':
314 PMA_relationsCleanupTable($db, $selected[$i]);
315 $current = $selected[$i];
316 if (!empty($views) && in_array($current, $views)) {
317 $sql_query_views .= (empty($sql_query_views) ? 'DROP VIEW ' : ', ')
318 . PMA_backquote($current);
319 } else {
320 $sql_query .= (empty($sql_query) ? 'DROP TABLE ' : ', ')
321 . PMA_backquote($current);
323 $reload = 1;
324 break;
326 case 'check_tbl':
327 $sql_query .= (empty($sql_query) ? 'CHECK TABLE ' : ', ')
328 . PMA_backquote($selected[$i]);
329 $use_sql = TRUE;
330 break;
332 case 'optimize_tbl':
333 $sql_query .= (empty($sql_query) ? 'OPTIMIZE TABLE ' : ', ')
334 . PMA_backquote($selected[$i]);
335 $use_sql = TRUE;
336 break;
338 case 'analyze_tbl':
339 $sql_query .= (empty($sql_query) ? 'ANALYZE TABLE ' : ', ')
340 . PMA_backquote($selected[$i]);
341 $use_sql = TRUE;
342 break;
344 case 'repair_tbl':
345 $sql_query .= (empty($sql_query) ? 'REPAIR TABLE ' : ', ')
346 . PMA_backquote($selected[$i]);
347 $use_sql = TRUE;
348 break;
350 case 'empty_tbl':
351 $a_query = 'TRUNCATE ';
352 $a_query .= PMA_backquote(htmlspecialchars($selected[$i]));
353 $run_parts = TRUE;
354 break;
356 case 'drop_fld':
357 PMA_relationsCleanupColumn($db, $table, $selected[$i]);
358 $sql_query .= (empty($sql_query) ? 'ALTER TABLE ' . PMA_backquote($table) : ',')
359 . ' DROP ' . PMA_backquote($selected[$i])
360 . (($i == $selected_cnt-1) ? ';' : '');
361 break;
363 case 'primary_fld':
364 $sql_query .= (empty($sql_query) ? 'ALTER TABLE ' . PMA_backquote($table) . (empty($primary) ? '' : ' DROP PRIMARY KEY,') . ' ADD PRIMARY KEY( ' : ', ')
365 . PMA_backquote($selected[$i])
366 . (($i == $selected_cnt-1) ? ');' : '');
367 break;
369 case 'index_fld':
370 $sql_query .= (empty($sql_query) ? 'ALTER TABLE ' . PMA_backquote($table) . ' ADD INDEX( ' : ', ')
371 . PMA_backquote($selected[$i])
372 . (($i == $selected_cnt-1) ? ');' : '');
373 break;
375 case 'unique_fld':
376 $sql_query .= (empty($sql_query) ? 'ALTER TABLE ' . PMA_backquote($table) . ' ADD UNIQUE( ' : ', ')
377 . PMA_backquote($selected[$i])
378 . (($i == $selected_cnt-1) ? ');' : '');
379 break;
381 case 'fulltext_fld':
382 $sql_query .= (empty($sql_query) ? 'ALTER TABLE ' . PMA_backquote($table) . ' ADD FULLTEXT( ' : ', ')
383 . PMA_backquote($selected[$i])
384 . (($i == $selected_cnt-1) ? ');' : '');
385 break;
386 } // end switch
388 // All "DROP TABLE", "DROP FIELD", "OPTIMIZE TABLE" and "REPAIR TABLE"
389 // statements will be run at once below
390 if ($run_parts) {
391 $sql_query .= $a_query . ';' . "\n";
392 if ($query_type != 'drop_db') {
393 PMA_DBI_select_db($db);
395 $result = PMA_DBI_query($a_query);
396 } // end if
397 } // end for
399 if ($query_type == 'drop_tbl') {
400 if (!empty($sql_query)) {
401 $sql_query .= ';';
402 } elseif (!empty($sql_query_views)) {
403 $sql_query = $sql_query_views . ';';
404 unset($sql_query_views);
408 if ($use_sql) {
409 require './sql.php';
410 } elseif (!$run_parts) {
411 PMA_DBI_select_db($db);
412 $result = PMA_DBI_try_query($sql_query);
413 if ($result && !empty($sql_query_views)) {
414 $sql_query .= ' ' . $sql_query_views . ';';
415 $result = PMA_DBI_try_query($sql_query_views);
416 unset($sql_query_views);
419 if (! $result) {
420 $message = PMA_Message::error(PMA_DBI_getError());
423 if ($rebuild_database_list) {
424 // avoid a problem with the database list navigator
425 // when dropping a db from server_databases
426 $GLOBALS['pma']->databases->build();
428 } else {
429 $message = PMA_Message::success('strNoModification');