[ Index ]
 

Code source de e107 0.7.8

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/e107_admin/ -> db_verify.php (source)

   1  <?php
   2  /*
   3  + ----------------------------------------------------------------------------+
   4  |     e107 website system
   5  |
   6  |     ©Steve Dunstan 2001-2002
   7  |     http://e107.org
   8  |     jalist@e107.org
   9  |
  10  |     Released under the terms and conditions of the
  11  |     GNU General Public License (http://gnu.org).
  12  |
  13  |     $Source: /cvsroot/e107/e107_0.7/e107_admin/db_verify.php,v $
  14  |     $Revision: 1.23 $
  15  |     $Date: 2006/10/29 01:00:20 $
  16  |     $Author: e107coders $
  17  +----------------------------------------------------------------------------+
  18  */
  19  require_once ("../class2.php");
  20  $e_sub_cat = 'database';
  21  require_once ("auth.php");
  22  
  23  
  24  $filename = "sql/core_sql.php";
  25  $fd = fopen ($filename, "r");
  26  $sql_data = @fread($fd, filesize($filename));
  27  fclose ($fd);
  28  
  29  if (!$sql_data) {
  30      echo DBLAN_1."<br /><br />";
  31      exit;
  32  }
  33  
  34   $tables["core"] = $sql_data;
  35  
  36  if (!getperms("0")) {
  37      header("location:".e_BASE."index.php");
  38      exit;
  39  }
  40  
  41  //Get any plugin _sql.php files
  42  
  43      foreach($pref['e_sql_list'] as $path => $file)
  44      {
  45          $filename = e_PLUGIN.$path."/".$file.".php";
  46          if(is_readable($filename)){
  47              $fd = fopen($filename, "r");
  48              $sql_data = fread($fd, filesize($filename));
  49              fclose ($fd);
  50              $id = str_replace("_sql","",$file);
  51              $tables[$id] = $sql_data;
  52          }else{
  53              echo $filename." is not readable<br />";
  54          }
  55      }
  56  
  57  
  58  
  59  function read_tables($tab) {
  60      global $tablines;
  61      global $table_list;
  62      global $tables,$sql,$pref;
  63  
  64      $file = split("\n", $tables[$tab]);
  65      foreach($file as $line) {
  66          $line = ltrim(stripslashes($line));
  67          if (preg_match("/CREATE TABLE (.*) /", $line, $match)) {
  68              if($match[1] != "user_extended"){
  69                  $table_list[$match[1]]  = 1;
  70                  $current_table = $match[1];
  71                  $x = 0;
  72                  $cnt = 0;
  73              }
  74          }
  75  
  76          if (strpos($line, "TYPE=") !== FALSE) {
  77              $current_table = "";
  78          }
  79  
  80          if ($current_table && $x) {
  81              $tablines[$current_table][$cnt++] = $line;
  82  
  83          }
  84  
  85          $x = 1;
  86      }
  87  
  88  // Get multi-language tables as well
  89      if($pref['multilanguage']){
  90          $langs = table_list();
  91          foreach($table_list as $name=>$stuff){
  92              if($langs[$name]){
  93                  $ltab = $langs[$name];
  94                  $table_list[$ltab] = 1;
  95                  $tablines[$ltab] = $tablines[$name];
  96              }
  97          }
  98      }
  99  
 100  }
 101  
 102  function get_current($tab, $prefix = "") {
 103      if (!$prefix) {
 104          $prefix = MPREFIX;
 105      }
 106      $result = mysql_query('SET SQL_QUOTE_SHOW_CREATE = 1');
 107      $qry = 'SHOW CREATE TABLE `'.$prefix.$tab."`";
 108      $z = mysql_query($qry);
 109      if ($z) {
 110          $row = mysql_fetch_row($z);
 111          return str_replace("`", "", stripslashes($row[1]));
 112      } else {
 113  
 114          return FALSE;
 115      }
 116  }
 117  
 118  function check_tables($what) {
 119      global $tablines;
 120      global $table_list;
 121      global $ns;
 122      $cur=0;
 123      $table_list = "";
 124      read_tables($what);
 125  
 126      $text = "<form method='post' action='".e_SELF."' id='checktab'>
 127          <div style='text-align:center'>
 128          <table style='".ADMIN_WIDTH."' class='fborder'>
 129          <tr>
 130          <td class='fcaption' style='text-align:center'>".DBLAN_4."</td>
 131          <td class='fcaption' style='text-align:center'>".DBLAN_5."</td>
 132          <td class='fcaption' style='text-align:center'>".DBLAN_6."</td>
 133          <td class='fcaption' style='text-align:center'>".DBLAN_7."</td>
 134          </tr>";
 135      foreach(array_keys($table_list) as $k) {
 136  
 137          $prefix = MPREFIX;
 138          $current_tab = get_current($k, $prefix);
 139          unset($fields);
 140          unset($xfields);
 141          if ($current_tab) {
 142              $lines = split("\n", $current_tab);
 143              $fieldnum = 0;
 144              foreach($tablines[$k] as $x) {
 145                  $fieldnum++;
 146                  $ffound = 0;
 147                  list($fname, $fparams) = split(" ", $x, 2);
 148                  if ($fname == "KEY") {
 149                      list($key, $keyname, $keyparms) = split(" ", $x, 3);
 150                      $fname = $key." ".$keyname;
 151                      $fparams = $keyparms;
 152                  }
 153                  $fields[$fname] = 1;
 154                  $fparams = ltrim(rtrim($fparams));
 155                  $fparams = preg_replace("/\r?\n$|\r[^\n]$|,$/", "", $fparams);
 156  
 157              if(stristr($k, "lan_") !== FALSE && $cur != 1){
 158                  $text .= "<tr><td colspan='6' class='fcaption'>".ADLAN_132."</td></tr>";
 159                  $cur = 1;
 160              };
 161  
 162  
 163  
 164                  $text .= "<tr><td class='forumheader3'>$k</td><td class='forumheader3'>$fname";
 165                  if (strpos($fparams, "KEY") !== FALSE) {
 166                      $text .= " $fparams";
 167                  }
 168                  $text .= "</td>";
 169                  $s = 0;
 170                  $xfieldnum = -1;
 171                  foreach($lines as $l) {
 172                      $xfieldnum++;
 173                      list($xl, $tmp) = split("\n", $l, 2);
 174                      $xl = ltrim(rtrim(stripslashes($xl)));
 175                      $xl = preg_replace("/\r?\n$|\r[^\n]$/", "", $xl);
 176                      list($xfname, $xfparams) = split(" ", $xl, 2);
 177  
 178                      if ($xfname == "KEY") {
 179                          list($key, $keyname, $keyparms) = split(" ", $xl, 3);
 180                          $xfname = $key." ".$keyname;
 181                          $xfparams = $keyparms;
 182                      }
 183  
 184                      if ($xfname != "CREATE" && $xfname != ")") {
 185                          $xfields[$xfname] = 1;
 186                      }
 187                      $xfparams = preg_replace("/,$/", "", $xfparams);
 188                      $fparams = preg_replace("/,$/", "", $fparams);
 189                      if ($xfname == $fname) {
 190                          $ffound = 1;
 191                          if (strcasecmp($fparams, $xfparams) != 0) {
 192                              $text .= "<td class='forumheader' style='text-align:center'>".DBLAN_8."</td>";
 193                              $text .= "<td class='forumheader3' style='text-align:center'>".DBLAN_9."<div class='indent'>".$xfparams."</div><b>".DBLAN_10."</b><div class='indent'>".$fparams." <br />".fix_form($k,$fname,$fparams,"alter")."</div></td>";
 194                              $fix_active = TRUE;
 195                          } elseif($fieldnum != $xfieldnum) {
 196                              $text .= "<td class='fcaption' style='text-align:center'>".DBLAN_5." ".DBLAN_8."</td>
 197                                  <td class='forumheader3' style='text-align:center'>".DBLAN_9." #{$xfieldnum}<br />".DBLAN_10." #{$fieldnum}</td>";
 198                          } else {
 199                              $text .= "<td class='forumheader3' style='text-align:center;'>OK</td>
 200                                  <td class='forumheader3' style='text-align:center'>&nbsp;</td>";
 201                          }
 202                      }
 203                  }
 204  
 205                  if ($ffound == 0) {
 206                      $text .= "<td class='forumheader' style='text-align:center'><strong><em>".DBLAN_11."</em></strong></td>
 207                          <td class='forumheader3' style='text-align:center'><b>".DBLAN_10." [$fparams]</b><br />".fix_form($k,$fname,$fparams,"insert",$prev_fname)."<br /></td>";
 208                      $fix_active = TRUE;
 209                  }
 210                  $prev_fname = $fname;
 211                  $text .= "</tr>\n";
 212              }
 213              foreach(array_keys($xfields) as $tf) {
 214                  if (!$fields[$tf] && $k != "user_extended") {
 215                      $fix_active = TRUE;
 216                      $text .= "<tr><td class='forumheader3' style='text-align:center'>$k</td><td class='forumheader3' style='text-align:center'>$tf</td><td class='forumheader3' style='text-align:center'><strong><em>".DBLAN_12."</em></strong></td><td class='forumheader3' style='text-align:center'>&nbsp;".fix_form($k,$tf,$fparams,"drop")."</td></tr>";
 217                  }
 218              }
 219          } else {    // Table Missing.
 220              $text .= "<tr><td class='forumheader3' style='text-align:center'>$k</td><td class='forumheader3' style='text-align:center'>&nbsp;</td><td class='forumheader' style='text-align:center'>".DBLAN_13."<br /><td class='forumheader3' style='text-align:center'>&nbsp;".fix_form($k,$tf,$tablines[$k],"create")."</td></tr>";
 221              $fix_active = TRUE;
 222          }
 223      }
 224      $text .= "</table></div>";
 225  
 226      if($fix_active){
 227          $text .= "<div style='".ADMIN_WIDTH.";text-align:right'>
 228          <input class='button' type='submit' name='do_fix' value='".DBLAN_21."' /></div>\n";
 229      }
 230  
 231      foreach(array_keys($_POST) as $j) {
 232          if (preg_match("/table_(.*)/", $j, $mitch)) {
 233              $lx = $mitch[1];
 234              $text .= "<input type='hidden' name='table_{$lx}' value='1' />\n";
 235          }
 236      }
 237      $text .= "</form>";
 238  
 239      return $text;
 240  }
 241  
 242  global $table_list;
 243  
 244  // -------------------- Table Fixing ------------------------------
 245  
 246  if(isset($_POST['do_fix'])){
 247      $text = "<div><table class='fborder' style='".ADMIN_WIDTH."'>";
 248      foreach( $_POST['fix_active'] as $key=>$val){
 249  
 250          if (MAGIC_QUOTES_GPC == TRUE) {
 251              $table = stripslashes($_POST['fix_table'][$key][0]);
 252              $newval = stripslashes($_POST['fix_newval'][$key][0]);
 253              $mode = stripslashes($_POST['fix_mode'][$key][0]);
 254              $after = stripslashes($_POST['fix_after'][$key][0]);
 255          } else {
 256              $table = $_POST['fix_table'][$key][0];
 257              $newval = $_POST['fix_newval'][$key][0];
 258              $mode = $_POST['fix_mode'][$key][0];
 259              $after = $_POST['fix_after'][$key][0];
 260          }
 261  
 262  
 263          $field= $key;
 264  
 265          if($mode == "alter"){
 266              $query = "ALTER TABLE `".MPREFIX.$table."` CHANGE `$field` `$field` $newval";
 267          }
 268  
 269          if($mode == "insert"){
 270              $query = "ALTER TABLE `".MPREFIX.$table."` ADD `$field` $newval AFTER $after";
 271          }
 272  
 273          if($mode == "drop"){
 274              $query = "ALTER TABLE `".MPREFIX.$table."` DROP `$field` ";
 275          }
 276  
 277          if($mode == "index"){
 278              $query = "ALTER TABLE `".MPREFIX.$table."` ADD INDEX `$field` (`$newval`)";
 279          }
 280  
 281          if($mode == "indexdrop"){
 282              $query = "ALTER TABLE `".MPREFIX.$table."` DROP INDEX `$field`";
 283          }
 284  
 285          if($mode == "create"){
 286              $query = "CREATE TABLE ".MPREFIX.$table." ($newval) TYPE=MyISAM;";
 287          }
 288  
 289  
 290          $text .= "<tr><td class='forumheader3' style='vertical-align:top;width:70%'>".$query."</td><td class='forumheader3' style='vertical-align:top;width:30%'>";
 291          $text .= (mysql_query($query)) ? " - <b>".LAN_UPDATED."</b>" : " - <b>".LAN_UPDATED_FAILED."</b>";
 292          $text .= "</td></tr>";
 293  
 294  
 295      }
 296          $text .= "</table></div>";
 297          $text .="<div style='text-align:center'><br />
 298                  <form method='post' action='db.php'>
 299                  <input class='button' type='submit' name='back' value='".DBLAN_17."' />
 300                  </form>
 301                  </div>";
 302  
 303      $ns -> tablerender(DBLAN_20, $text);
 304  }
 305  
 306  
 307  
 308  // ---------------------- Main Form and Submit. ------------------------
 309  if (!$_POST['db_verify'] && !$_POST['do_fix']) {
 310      $text = "
 311          <form method='post' action='".e_SELF."'>
 312          <table border=0 align='center'>
 313          <tr><td>".DBLAN_14."<br /><br />";
 314      foreach(array_keys($tables) as $x) {
 315          $text .= "<input type='checkbox' name='table_".$x."' />".$x."<br />";
 316      }
 317      $text .= "
 318          <br /><input class='button' name='db_verify' type='submit' value='".DBLAN_15."' />
 319          </td></tr></table></form>";
 320      $ns->tablerender(DBLAN_16, $text);
 321  } else {
 322      foreach(array_keys($_POST) as $k) {
 323          if (preg_match("/table_(.*)/", $k, $match)) {
 324              $xx = $match[1];
 325              $str = "<br />
 326                  <div style='text-align:center'>
 327                  <form method='post' action='db.php'>
 328                  <input class='button' type='submit' name='back' value='".DBLAN_17."' />
 329                  </form>
 330                  </div>";
 331              $ns->tablerender(DBLAN_16." - $xx ".DBLAN_18, check_tables($xx).$str);
 332          }
 333      }
 334  }
 335  
 336  
 337  
 338  // --------------------------------------------------------------
 339  function fix_form($table,$field, $newvalue,$mode,$after =''){
 340  
 341      if(stristr($field, "KEY ") !== FALSE){
 342          $field = chop(str_replace("KEY ","",$field));
 343          $mode = ($mode == "drop") ? "indexdrop" : "index";
 344          $search = array("(",")");
 345          $newvalue = str_replace($search,"",$newvalue);
 346      }
 347  
 348      if($mode == "create"){
 349          $newvalue = implode("\n",$newvalue);
 350      }
 351  
 352      $text .= "<input type='checkbox'  name=\"fix_active[$field][]\" value='1' /> ".DBLAN_19."\n"; // 'attempt to fix'
 353      $text .= "<input type='hidden' name=\"fix_newval[$field][]\" value=\"$newvalue\" />\n";
 354      $text .= "<input type='hidden'  name=\"fix_table[$field][]\" value=\"$table\" />\n";
 355      $text .= "<input type='hidden'  name=\"fix_mode[$field][]\" value=\"$mode\" />\n";
 356      $text .= ($after) ? "<input type='hidden'  name=\"fix_after[$field][]\" value=\"$after\" />\n" : "";
 357  
 358      return $text;
 359  }
 360  
 361  function table_list() {
 362      // grab default language lists.
 363      global $mySQLdefaultdb;
 364  
 365      $exclude[] = "banlist";        $exclude[] = "banner";
 366      $exclude[] = "cache";        $exclude[] = "core";
 367      $exclude[] = "online";        $exclude[] = "parser";
 368      $exclude[] = "plugin";        $exclude[] = "user";
 369      $exclude[] = "upload";        $exclude[] = "userclass_classes";
 370      $exclude[] = "rbinary";        $exclude[] = "session";
 371      $exclude[] = "tmp";             $exclude[] = "flood";
 372      $exclude[] = "stat_info";    $exclude[] = "stat_last";
 373      $exclude[] = "submit_news";    $exclude[] = "rate";
 374      $exclude[] = "stat_counter";$exclude[] = "user_extended";
 375      $exclude[] = "user_extended_struc";
 376      $exclude[] = "pm_messages";
 377      $exclude[] = "pm_blocks";
 378  
 379      //   print_r($search);
 380  
 381      $tables = mysql_list_tables($mySQLdefaultdb);
 382      while (list($temp) = mysql_fetch_array($tables)){
 383          $prefix = MPREFIX."lan_";
 384  
 385          if(preg_match("/^".$prefix."(.*)/", $temp, $match)){
 386              $e107tab = str_replace(MPREFIX, "", $temp);
 387              $pos = strrpos($match[1],"_")+1;
 388              $core = substr(str_replace("lan_","",$e107tab),$pos);
 389              if (str_replace($exclude, "", $e107tab)){
 390                  $tabs[$core] = $e107tab;
 391              }
 392          }
 393      }
 394  
 395      return $tabs;
 396  }
 397  
 398  
 399  
 400  
 401  require_once(e_ADMIN."footer.php");
 402  ?>


Généré le : Sun Apr 1 01:23:32 2007 par Balluche grâce à PHPXref 0.7