root/wp-dbmanager/trunk/database-run.php

Revision 52756, 4.2 kB (checked in by GamerZ, 5 days ago)

2.31

Line 
1 <?php
2 /*
3 +----------------------------------------------------------------+
4 |                                                                                            |
5 |    WordPress 2.5 Plugin: WP-DBManager 2.31                                |
6 |    Copyright (c) 2008 Lester "GaMerZ" Chan                                    |
7 |                                                                                            |
8 |    File Written By:                                                                    |
9 |    - Lester "GaMerZ" Chan                                                            |
10 |    - http://lesterchan.net                                                            |
11 |                                                                                            |
12 |    File Information:                                                                    |
13 |    - Database Run Query                                                            |
14 |    - wp-content/plugins/wp-dbmanager/database-run.php                |
15 |                                                                                            |
16 +----------------------------------------------------------------+
17 */
18
19
20 ### Check Whether User Can Manage Database
21 if(!current_user_can('manage_database')) {
22     die('Access Denied');
23 }
24
25
26 ### Variables Variables Variables
27 $base_name = plugin_basename('wp-dbmanager/database-manager.php');
28 $base_page = 'admin.php?page='.$base_name;
29 $backup = array();
30 $backup_options = get_option('dbmanager_options');
31 $backup['date'] = current_time('timestamp');
32 $backup['mysqldumppath'] = $backup_options['mysqldumppath'];
33 $backup['mysqlpath'] = $backup_options['mysqlpath'];
34 $backup['path'] = $backup_options['path'];
35
36
37 ### Form Processing
38 if($_POST['do']) {
39     // Decide What To Do
40     switch($_POST['do']) {
41         case __('Run', 'wp-dbmanager'):
42             $sql_queries2 = trim($_POST['sql_query']);
43             $totalquerycount = 0;
44             $successquery = 0;
45             if($sql_queries2) {
46                 $sql_queries = array();
47                 $sql_queries2 = explode("\n", $sql_queries2);
48                 foreach($sql_queries2 as $sql_query2) {
49                     $sql_query2 = trim(stripslashes($sql_query2));
50                     $sql_query2 = preg_replace("/[\r\n]+/", '', $sql_query2);
51                     if(!empty($sql_query2)) {
52                         $sql_queries[] = $sql_query2;
53                     }
54                 }
55                 if($sql_queries) {
56                     foreach($sql_queries as $sql_query) {           
57                         if (preg_match("/^\\s*(insert|update|replace|delete|create|alter) /i",$sql_query)) {
58                             $run_query = $wpdb->query($sql_query);
59                             if(!$run_query) {
60                                 $text .= "<font color=\"red\">$sql_query</font><br />";
61                             } else {
62                                 $successquery++;
63                                 $text .= "<font color=\"green\">$sql_query</font><br />";
64                             }
65                             $totalquerycount++;
66                         } elseif (preg_match("/^\\s*(select|drop|show|grant) /i",$sql_query)) {
67                             $text .= "<font color=\"red\">$sql_query</font><br />";
68                             $totalquerycount++;                       
69                         }
70                     }
71                     $text .= "<font color=\"blue\">$successquery/$totalquerycount ".__('Query(s) Executed Successfully', 'wp-dbmanager').'</font>';
72                 } else {
73                     $text = '<font color="red">'.__('Empty Query', 'wp-dbmanager').'</font>';
74                 }
75             } else {
76                 $text = '<font color="red">'.__('Empty Query', 'wp-dbmanager').'</font>';
77             }
78             break;
79     }
80 }
81 ?>
82 <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?>
83 <!-- Run SQL Query -->
84 <form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post">
85     <div class="wrap">
86         <h2><?php _e('Run SQL Query', 'wp-dbmanager'); ?></h2>
87         <br style="clear" />
88         <div>
89             <strong><?php _e('Seperate Multiple Queries With A New Line', 'wp-dbmanager'); ?></strong><br />
90             <font color="green"><?php _e('Use Only INSERT, UPDATE, REPLACE, DELETE, CREATE and ALTER statements.', 'wp-dbmanager'); ?></font>
91         </div>
92         <table class="form-table">
93             <tr>
94                 <td align="center"><textarea cols="120" rows="30" name="sql_query" style="width: 99%;"></textarea></td>
95             </tr>
96             <tr>
97                 <td align="center"><input type="submit" name="do" value="<?php _e('Run', 'wp-dbmanager'); ?>" class="button" />&nbsp;&nbsp;<input type="button" name="cancel" value="<?php _e('Cancel', 'wp-dbmanager'); ?>" class="button" onclick="javascript:history.go(-1)" /></td>
98             </tr>
99         </table>
100         <p>
101             <?php _e('1. CREATE statement will return an error, which is perfectly normal due to the database class. To confirm that your table has been created check the Manage Database page.', 'wp-dbmanager'); ?><br />
102             <?php _e('2. UPDATE statement may return an error sometimes due to the newly updated value being the same as the previous value.', 'wp-dbmanager'); ?><br />
103             <?php _e('3. ALTER statement will return an error because there is no value returned.', 'wp-dbmanager'); ?>
104         </p>
105     </div>
106 </form>
Note: See TracBrowser for help on using the browser.