[ PHPXref.com ] [ Generated: Sun Jul 20 17:59:13 2008 ] [ GLPI 0.65 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/ -> update_content.php (source)

   1  <?php
   2  /*
   3   * @version $Id: update_content.php,v 1.32 2006/03/15 13:47:36 moyo Exp $
   4   ----------------------------------------------------------------------
   5   GLPI - Gestionnaire Libre de Parc Informatique
   6   Copyright (C) 2003-2006 by the INDEPNET Development Team.
   7   
   8   http://indepnet.net/   http://glpi.indepnet.org
   9   ----------------------------------------------------------------------
  10  
  11   LICENSE
  12  
  13      This file is part of GLPI.
  14  
  15      GLPI is free software; you can redistribute it and/or modify
  16      it under the terms of the GNU General Public License as published by
  17      the Free Software Foundation; either version 2 of the License, or
  18      (at your option) any later version.
  19  
  20      GLPI is distributed in the hope that it will be useful,
  21      but WITHOUT ANY WARRANTY; without even the implied warranty of
  22      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  23      GNU General Public License for more details.
  24  
  25      You should have received a copy of the GNU General Public License
  26      along with GLPI; if not, write to the Free Software
  27      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  28   ------------------------------------------------------------------------
  29  */
  30  
  31  // ----------------------------------------------------------------------
  32  // Original Author of file: Julien Dombre & Bazile Lebeau
  33  // Purpose of file:
  34  // ----------------------------------------------------------------------
  35  
  36  //#################### INCLUDE & SESSIONS ############################
  37  include  ("_relpos.php");
  38  include  ($phproot . "/glpi/common/classes.php");
  39  include  ($phproot . "/glpi/common/functions.php");
  40  include  ($phproot . "/glpi/common/functions_display.php");
  41  include  ($phproot . "/glpi/common/functions_db.php");
  42  include  ($phproot . "/glpi/config/based_config.php");
  43  include($cfg_glpi["config_dir"] . "/config_db.php");
  44  
  45  if(!session_id()){@session_start();}
  46  
  47  // Init debug variable
  48  $cfg_glpi["debug"]=0;
  49  
  50  
  51  //################################ Functions ################################
  52  
  53  function loadLang() {
  54              unset($lang);
  55              global $lang;
  56              include  ("_relpos.php");
  57              $file = $phproot ."/glpi/dicts/".$_SESSION["dict"].".php";
  58              include($file);
  59  }
  60  
  61  $max_time=min(get_cfg_var("max_execution_time"),get_cfg_var("max_input_time"));
  62  if ($max_time>5) {$defaulttimeout=$max_time-2;$defaultrowlimit=1;}
  63  else {$defaulttimeout=1;$defaultrowlimit=1;}
  64  
  65  $db=new DB;
  66  
  67  function init_time() 
  68  {
  69      global $TPSDEB,$TPSCOUR;
  70      
  71      
  72      list ($usec,$sec)=explode(" ",microtime());
  73      $TPSDEB=$sec;
  74      $TPSCOUR=0;
  75  
  76  }
  77  
  78  function current_time() 
  79  {
  80      global $TPSDEB,$TPSCOUR;
  81      list ($usec,$sec)=explode(" ",microtime());
  82      $TPSFIN=$sec;
  83      if (round($TPSFIN-$TPSDEB,1)>=$TPSCOUR+1) //une seconde de plus
  84      {
  85      $TPSCOUR=round($TPSFIN-$TPSDEB,1);
  86      }
  87  
  88  }
  89  
  90  function test_content_ok(){
  91      global $db;
  92      
  93      $query1="SELECT ID FROM glpi_computers WHERE  comments LIKE '%\\\\\\%';";
  94      $query2="SELECT ID FROM glpi_printers WHERE  comments LIKE '%\\\\\\%';";    
  95      $query3="SELECT ID FROM glpi_tracking WHERE  contents LIKE '%\\\\\\%';";    
  96      $query4="SELECT ID FROM glpi_followups WHERE  contents LIKE '%\\\\\\%';";    
  97      
  98      $result1=$db->query($query1);
  99      if ($db->numrows($result1)>0)
 100          return false;
 101      $result4=$db->query($query4);
 102      if ($db->numrows($result4)>0)
 103          return false;    
 104      $result3=$db->query($query3);
 105      if ($db->numrows($result3)>0)
 106          return false;
 107      $result2=$db->query($query2);
 108      if ($db->numrows($result2)>0)
 109          return false;
 110      return true;        
 111      }
 112  
 113  function seems_utf8($Str) {
 114   for ($i=0; $i<strlen($Str); $i++) {
 115    if (ord($Str[$i]) < 0x80) continue; # 0bbbbbbb
 116    elseif ((ord($Str[$i]) & 0xE0) == 0xC0) $n=1; # 110bbbbb
 117    elseif ((ord($Str[$i]) & 0xF0) == 0xE0) $n=2; # 1110bbbb
 118    elseif ((ord($Str[$i]) & 0xF8) == 0xF0) $n=3; # 11110bbb
 119    elseif ((ord($Str[$i]) & 0xFC) == 0xF8) $n=4; # 111110bb
 120    elseif ((ord($Str[$i]) & 0xFE) == 0xFC) $n=5; # 1111110b
 121    else return false; # Does not match any model
 122    for ($j=0; $j<$n; $j++) { # n bytes matching 10bbbbbb follow ?
 123     if ((++$i == strlen($Str)) || ((ord($Str[$i]) & 0xC0) != 0x80))
 124     return false;
 125    }
 126   }
 127   return true;
 128  }
 129  
 130  function get_update_content($db, $table,$from,$limit,$conv_utf8)
 131  {
 132       $content="";
 133       $result = $db->query("SELECT * FROM $table LIMIT $from,$limit");
 134       
 135       if($result)
 136       while($row = $db->fetch_assoc($result)) {
 137           if (isset($row["ID"])) {
 138               if (get_magic_quotes_runtime()) $row=stripslashes_deep($row);
 139               $row=stripslashes_deep($row);
 140               $insert = "UPDATE $table SET ";
 141               foreach ($row as $key => $val) {
 142                   $insert.=" ".$key."=";
 143                   
 144                  if(!isset($val)) $insert .= "NULL,";
 145                  else if($val != "") {
 146                      if ($conv_utf8) {
 147              // Gestion users AD qui sont déjà en UTF8
 148              if ($table!="glpi_users"||!seems_utf8($val))
 149                  $val=utf8_encode($val);
 150              }
 151                      $insert .= "'".addslashes($val)."',";
 152                      }
 153                  else $insert .= "'',";
 154               }
 155               $insert = ereg_replace(",$","",$insert);
 156               $insert.=" WHERE ID = '".$row["ID"]."' ";
 157               $insert .= ";\n";
 158               $content .= $insert;
 159          }
 160       }
 161       //if ($table=="glpi_dropdown_locations") echo $content;
 162       return $content;
 163  }
 164  
 165  
 166  function UpdateContent($db, $duree,$rowlimit,$conv_utf8)
 167  {
 168  // $dumpFile, fichier source
 169  // $database, nom de la base de données cible
 170  // $mysqlUser, login pouyr la connexion au serveur MySql
 171  // $mysqlPassword, mot de passe
 172  // $histMySql, nom de la machine serveur MySQl
 173  // $duree=timeout pour changement de page (-1 = aucun)
 174  
 175  
 176  global $TPSCOUR,$offsettable,$offsetrow,$cpt;
 177  if ($db->error)
 178  {
 179       echo "Connexion impossible à $hostMySql pour $mysqlUser";
 180       return FALSE;
 181  }
 182  
 183  $result=$db->list_tables();
 184  $numtab=0;
 185  while ($t=$db->fetch_array($result)){
 186      if (ereg("glpi_",$t[0])){
 187      $tables[$numtab]=$t[0];
 188  $numtab++;
 189  }
 190  }
 191  
 192  
 193  for (;$offsettable<$numtab;$offsettable++){
 194  // Dump de la strucutre table
 195  if ($offsetrow==-1){
 196      $offsetrow++;
 197      $cpt++;
 198      }
 199      current_time();
 200      if ($duree>0 and $TPSCOUR>=$duree) //on atteint la fin du temps imparti
 201          return TRUE;
 202  
 203      $fin=0;
 204      while (!$fin){
 205      $todump=get_update_content($db,$tables[$offsettable],$offsetrow,$rowlimit,$conv_utf8);
 206  //    echo $todump."<br>";
 207      $rowtodump=substr_count($todump, "UPDATE ");
 208      if ($rowtodump>0){
 209  //    echo $todump;
 210      $result = $db->query($todump);
 211  //    if (!$result) echo "ECHEC ".$todump;
 212      
 213      $cpt+=$rowtodump;
 214      $offsetrow+=$rowlimit;
 215      if ($rowtodump<$rowlimit) $fin=1;
 216      current_time();
 217      if ($duree>0 and $TPSCOUR>=$duree) //on atteint la fin du temps imparti
 218          return TRUE;
 219  
 220      }
 221      else {$fin=1;$offsetrow=-1;}
 222      }
 223      if ($fin) $offsetrow=-1;
 224      current_time();
 225      if ($duree>0 and $TPSCOUR>=$duree) //on atteint la fin du temps imparti
 226          return TRUE;
 227      
 228  }
 229  if ($db->error())
 230       echo "<hr>ERREUR à partir de [$formattedQuery]<br>".$db->error()."<hr>";
 231  $offsettable=-1;
 232  return TRUE;
 233  }
 234  
 235  //########################### Script start ################################
 236  
 237  loadLang();
 238  
 239          // Send UTF8 Headers
 240          header("Content-Type: text/html; charset=UTF-8");
 241  
 242  //style and co
 243      echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">";
 244          echo "<html>";
 245          echo "<head>";
 246          echo " <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">";
 247          echo "<meta http-equiv=\"Content-Script-Type\" content=\"text/javascript\"> ";
 248          echo "<meta http-equiv=\"Content-Style-Type\" content=\"text/css\"> ";
 249          echo "<meta http-equiv=\"Content-Language\" content=\"fr\"> ";
 250          echo "<meta name=\"generator\" content=\"\">";
 251          echo "<meta name=\"DC.Language\" content=\"fr\" scheme=\"RFC1766\">";
 252          echo "<title>Setup GLPI</title>";
 253         
 254          echo "<style type=\"text/css\">";
 255          echo "<!--
 256  
 257          /*  ... Definition des styles ... */
 258  
 259          body {
 260          background-color:#C5DAC8;
 261          color:#000000; }
 262          
 263         .principal {
 264          background-color: #ffffff;
 265          font-family: Verdana;font-size:12px;
 266          text-align: justify ; 
 267          -moz-border-radius: 4px;
 268      border: 1px solid #FFC65D;
 269           margin: 40px; 
 270           padding: 40px 40px 10px 40px;
 271         }
 272  
 273         table {
 274         text-align:center;
 275         border: 0;
 276         margin: 20px;
 277         margin-left: auto;
 278         margin-right: auto;
 279         width: 90%;}
 280  
 281         .red { color:red;}
 282         .green {color:green;}
 283         
 284         h2 {
 285          color:#FFC65D;
 286          text-align:center;}
 287  
 288         h3 {
 289          text-align:center;}
 290  
 291          input {border: 1px solid #ccc;}
 292  
 293          fieldset {
 294          padding: 20px;
 295            border: 1px dotted #ccc;
 296          font-size: 12px;
 297          font-weight:200;}
 298  
 299          .submit { text-align:center;}
 300         
 301          input.submit {
 302          border:1px solid #000000;
 303          background-color:#eeeeee;
 304          }
 305          
 306          input.submit:hover {
 307          border:1px solid #cccccc;
 308         background-color:#ffffff;
 309          }
 310  
 311      .button {
 312          font-weight:200;
 313      color:#000000;
 314      padding:5px;
 315      text-decoration:none;
 316      border:1px solid #009966;
 317          background-color:#eeeeee;
 318          }
 319  
 320          .button:hover{
 321            font-weight:200;
 322        color:#000000;
 323       padding:5px;
 324      text-decoration:none;
 325      border:1px solid #009966;
 326         background-color:#ffffff;
 327          }
 328      
 329          -->  ";
 330          echo "</style>";
 331           echo "</head>";
 332          echo "<body>";
 333      echo "<div class=\"principal\">";
 334  //end style and co
 335  /*if (!isset($_POST["oui"])&&!isset($_POST["non"])&&!isset($_GET["dump"]))
 336  if (test_content_ok()) {
 337      echo "<div align=\"center\">";
 338      echo $lang["update"]["108"];
 339      echo $lang["update"]["109"];
 340      echo "<form action=\"update_content.php\" method=\"post\">";
 341      echo "<input type=\"submit\" class='submit' name=\"oui\" value=\"Oui\" />&nbsp;&nbsp;";
 342      echo "<input type=\"submit\" class='submit' name=\"non\" value=\"Non\" />";
 343      echo "</form></div>";
 344  }
 345  else {
 346      echo "<div align=\"center\">";
 347      echo $lang["update"]["110"];
 348      echo $lang["update"]["109"];
 349      echo "<form action=\"update_content.php\" method=\"post\">";
 350      echo "<input type=\"submit\" class='submit' name=\"oui\" value=\"Oui\" />&nbsp;&nbsp;";
 351      echo "<input type=\"submit\" class='submit' name=\"non\" value=\"Non\" />";
 352      echo "</form></div>";
 353  
 354  }
 355  */
 356  // #################" UPDATE CONTENT #################################
 357  
 358      $time_file=date("Y-m-d-h-i");
 359      $cur_time=date("Y-m-d H:i");
 360  
 361  init_time(); //initialise le temps
 362  //début de fichier
 363  if (!isset($_GET["offsettable"])) $offsettable=0; 
 364  else $offsettable=$_GET["offsettable"]; 
 365  //début de fichier
 366  if (!isset($_GET["offsetrow"])) $offsetrow=-1; 
 367  else $offsetrow=$_GET["offsetrow"];
 368  //timeout de 5 secondes par défaut, -1 pour utiliser sans timeout
 369  if (!isset($_GET["duree"])) $duree=$defaulttimeout; 
 370  else $duree=$_GET["duree"];
 371  //Limite de lignes à dumper à chaque fois
 372  if (!isset($_GET["rowlimit"])) $rowlimit=$defaultrowlimit; 
 373  else  $rowlimit=$_GET["rowlimit"];
 374  
 375  $tab=$db->list_tables();
 376  $tot=$db->numrows($tab);
 377  if(isset($offsettable)){
 378  if ($offsettable>=0)
 379  $percent=min(100,round(100*$offsettable/$tot,0));
 380  else $percent=100;
 381  }
 382  else $percent=0;
 383  if ($percent >= 0) {
 384   
 385  displayProgressBar(400,$percent);
 386  
 387  }
 388  $conv_utf8=false;
 389  if(!FieldExists("glpi_config","utf8_conv")) {
 390  $conv_utf8=true;
 391  }
 392  
 393  if ($offsettable>=0){
 394      if (UpdateContent($db,$duree,$rowlimit,$conv_utf8))
 395      {
 396      echo "<br>Redirection automatique sinon cliquez <a href=\"update_content.php?dump=1&amp;duree=$duree&amp;rowlimit=$rowlimit&amp;offsetrow=$offsetrow&amp;offsettable=$offsettable&amp;cpt=$cpt\">ici</a>";
 397      echo "<script language=\"javascript\" type=\"text/javascript\">window.location=\"update_content.php?dump=1&duree=$duree&rowlimit=$rowlimit&offsetrow=$offsetrow&offsettable=$offsettable&cpt=$cpt\";</script>";
 398  echo "</div>";
 399  
 400      glpi_flush();    
 401      exit;
 402      }
 403  }
 404  else  { 
 405  //echo "<div align='center'><p>Terminé. Nombre de requêtes totales traitées : $cpt</p></div>";
 406      echo "<p class='submit'> <a href=\"index.php\"><span class='button'>".$lang["install"][64]."</span></a></p>";
 407  echo "</div>";
 408  
 409  }
 410  
 411  if ($conv_utf8){
 412      $query = "ALTER TABLE `glpi_config` ADD `utf8_conv` INT( 11 ) DEFAULT '0' NOT NULL";
 413      $db->query($query) or die(" 0.6 add utf8_conv to glpi_config".$lang["update"][90].$db->error());
 414  }
 415  
 416  ?>


[ Powered by PHPXref - Served by Debian GNU/Linux ]