home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Plugins / wp-dbmanager / dbmanager / database-run.php < prev    next >
PHP Script  |  2008-02-19  |  4KB  |  98 lines

  1. <?php
  2. /*
  3. +----------------------------------------------------------------+
  4. |                                                                                            |
  5. |    WordPress 2.1 Plugin: WP-DBManager 2.20                                |
  6. |    Copyright (c) 2007 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/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('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. <div class="wrap">
  85.     <h2><?php _e('Run SQL Query', 'wp-dbmanager'); ?></h2>
  86.     <form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post">
  87.         <p>
  88.             <strong><?php _e('Seperate Multiple Queries With A New Line', 'wp-dbmanager'); ?></strong><br />
  89.             <font color="green"><?php _e('Use Only INSERT, UPDATE, REPLACE, DELETE, CREATE and ALTER statements.', 'wp-dbmanager'); ?></font>
  90.         </p>
  91.         <p align="center"><textarea cols="120" rows="30" name="sql_query"></textarea></p>
  92.         <p align="center"><input type="submit" name="do" value="<?php _e('Run', 'wp-dbmanager'); ?>" class="button" />  <input type="button" name="cancel" value="<?php _e('Cancel', 'wp-dbmanager'); ?>" class="button" onclick="javascript:history.go(-1)" /></p>
  93.         <p>
  94.             <?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 />
  95.             <?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 />
  96.             <?php _e('3. ALTER statement will return an error because there is no value returned.', 'wp-dbmanager'); ?></p>
  97.     </form>
  98. </div>