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