| [ Index ] |
|
Code source de Dolibarr 2.0.1 |
1 <?php 2 /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org> 3 * Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net> 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 * 19 * $Id: etape2.php,v 1.35.2.2 2006/01/21 15:06:20 eldy Exp $ 20 * $Source: /cvsroot/dolibarr/dolibarr/htdocs/install/etape2.php,v $ 21 */ 22 23 /** 24 \file htdocs/install/etape2.php 25 \brief Crée les tables, clés primaires, clés étrangères, index et fonctions en base puis charge les données de référence 26 \version $Revision: 1.35.2.2 $ 27 */ 28 29 include_once ("./inc.php"); 30 31 $etape = 2; 32 $ok = 0; 33 34 35 // Cette page peut etre longue. On augmente le délai par défaut de 30 à 60. 36 // Ne fonctionne que si on est pas en safe_mode. 37 $err=error_reporting(); 38 error_reporting(0); 39 set_time_limit(90); 40 error_reporting($err); 41 42 $setuplang=isset($_POST["selectlang"])?$_POST["selectlang"]:(isset($_GET["selectlang"])?$_GET["selectlang"]:'auto'); 43 $langs->setDefaultLang($setuplang); 44 45 $langs->load("admin"); 46 $langs->load("install"); 47 48 49 pHeader($langs->trans("CreateDatabaseObjects"),"etape4"); 50 51 52 if (file_exists($conffile)) 53 { 54 include_once($conffile); 55 } 56 57 if($dolibarr_main_db_type == "mysql") 58 { 59 require_once($dolibarr_main_document_root . "/lib/mysql.lib.php"); 60 $choix=1; 61 } 62 else 63 { 64 require_once($dolibarr_main_document_root . "/lib/pgsql.lib.php"); 65 $choix=2; 66 } 67 68 require_once($dolibarr_main_document_root . "/conf/conf.class.php"); 69 70 71 if ($_POST["action"] == "set") 72 { 73 print '<h2>'.$langs->trans("Database").'</h2>'; 74 75 print '<table cellspacing="0" cellpadding="4" border="0" width="100%">'; 76 $error=0; 77 78 $conf = new Conf();// on pourrait s'en passer 79 $conf->db->type = $dolibarr_main_db_type; 80 $conf->db->host = $dolibarr_main_db_host; 81 $conf->db->name = $dolibarr_main_db_name; 82 $conf->db->user = $dolibarr_main_db_user; 83 $conf->db->pass = $dolibarr_main_db_pass; 84 85 $db = new DoliDb($conf->db->type,$conf->db->host,$conf->db->user,$conf->db->pass,$conf->db->name); 86 if ($db->connected == 1) 87 { 88 print "<tr><td>"; 89 print $langs->trans("ServerConnection")." : $dolibarr_main_db_host</td><td>".$langs->trans("OK")."</td></tr>"; 90 $ok = 1 ; 91 } 92 else 93 { 94 print "<tr><td>Erreur lors de la création de : $dolibarr_main_db_name</td><td>".$langs->trans("Error")."</td></tr>"; 95 } 96 97 if ($ok) 98 { 99 if($db->database_selected == 1) 100 { 101 102 dolibarr_syslog("Connexion réussie à la base : $dolibarr_main_db_name"); 103 } 104 else 105 { 106 $ok = 0 ; 107 } 108 } 109 110 111 // Affiche version 112 if ($ok) 113 { 114 $version=$db->getVersion(); 115 print '<tr><td>'; 116 print $langs->trans("DatabaseVersion").'</td><td>'.$version.'</td></tr>'; 117 } 118 119 /************************************************************************************** 120 * 121 * Chargement fichiers tables/*.sql (non *.key.sql) 122 * A faire avant les fichiers *.key.sql 123 * 124 ***************************************************************************************/ 125 if ($ok) 126 { 127 if ($choix==1) $dir = "../../mysql/tables/"; 128 else $dir = "../../pgsql/tables/"; 129 130 $ok = 0; 131 $handle=opendir($dir); 132 $table_exists = 0; 133 while (($file = readdir($handle))!==false) 134 { 135 if (substr($file, strlen($file) - 4) == '.sql' && substr($file,0,4) == 'llx_' && substr($file, -8) <> '.key.sql') 136 { 137 $name = substr($file, 0, strlen($file) - 4); 138 $buffer = ''; 139 $fp = fopen($dir.$file,"r"); 140 if ($fp) 141 { 142 while (!feof ($fp)) 143 { 144 $buf = fgets($fp, 4096); 145 if (substr($buf, 0, 2) <> '--') 146 { 147 $buffer .= $buf; 148 } 149 } 150 fclose($fp); 151 } 152 153 //print "<tr><td>Création de la table $name/td>"; 154 155 if ($db->query($buffer)) 156 { 157 //print "<td>OK requete ==== $buffer</td></tr>"; 158 } 159 else 160 { 161 if ($db->errno() == 'DB_ERROR_TABLE_ALREADY_EXISTS') 162 { 163 //print "<td>Déjà existante</td></tr>"; 164 $table_exists = 1; 165 } 166 else 167 { 168 print "<tr><td>".$langs->trans("CreateTableAndPrimaryKey",$name)."</td>"; 169 print "<td>".$langs->trans("Error")." ".$db->errno()." ".$db->error()."</td></tr>"; 170 $error++; 171 } 172 } 173 } 174 175 } 176 closedir($handle); 177 178 if ($error == 0) 179 { 180 print '<tr><td>'; 181 print $langs->trans("TablesAndPrimaryKeysCreation").'</td><td>'.$langs->trans("OK").'</td></tr>'; 182 $ok = 1; 183 } 184 } 185 186 187 /*************************************************************************************** 188 * 189 * Chargement fichiers tables/*.key.sql 190 * A faire après les fichiers *.sql 191 * 192 ***************************************************************************************/ 193 if ($ok) 194 { 195 if ($choix==1) $dir = "../../mysql/tables/"; 196 else $dir = "../../pgsql/tables/"; 197 198 $okkeys = 0; 199 $handle=opendir($dir); 200 $table_exists = 0; 201 while (($file = readdir($handle))!==false) 202 { 203 if (substr($file, strlen($file) - 4) == '.sql' && substr($file,0,4) == 'llx_' && substr($file, -8) == '.key.sql') 204 { 205 $name = substr($file, 0, strlen($file) - 4); 206 //print "<tr><td>Création de la table $name</td>"; 207 $buffer = ''; 208 $fp = fopen($dir.$file,"r"); 209 if ($fp) 210 { 211 while (!feof ($fp)) 212 { 213 $buf = fgets($fp, 4096); 214 215 // Cas special de lignes autorisees pour certaines versions uniquement 216 if (eregi('^-- V([0-9]+)',$buf,$reg)) 217 { 218 if ($reg[1] && $reg[1] <= $version) 219 { 220 $buf=eregi_replace('^-- V([0-9]+)','',$buf); 221 //print $buf.'<br>'; 222 } 223 } 224 225 // Ajout ligne si non commentaire 226 if (! eregi('^--',$buf)) $buffer .= $buf; 227 } 228 fclose($fp); 229 } 230 231 // Si plusieurs requetes, on boucle sur chaque 232 $listesql=split(';',$buffer); 233 foreach ($listesql as $buffer) { 234 if (trim($buffer)) { 235 //print "<tr><td>Création des clés et index de la table $name: '$buffer'</td>"; 236 if ($db->query(trim($buffer))) 237 { 238 //print "<td>OK requete ==== $buffer</td></tr>"; 239 } 240 else 241 { 242 if ($db->errno() == 'DB_ERROR_KEY_NAME_ALREADY_EXISTS' || 243 $db->errno() == 'DB_ERROR_CANNOT_CREATE' || 244 eregi('duplicate key name',$db->error())) 245 { 246 //print "<td>Déjà existante</td></tr>"; 247 $key_exists = 1; 248 } 249 else 250 { 251 print "<tr><td>".$langs->trans("CreateOtherKeysForTable",$name)."</td>"; 252 print "<td>".$langs->trans("Error")." ".$db->errno()." ".$db->error()."</td></tr>"; 253 $error++; 254 } 255 } 256 } 257 } 258 } 259 260 } 261 closedir($handle); 262 263 if ($error == 0) 264 { 265 print '<tr><td>'; 266 print $langs->trans("OtherKeysCreation").'</td><td>'.$langs->trans("OK").'</td></tr>'; 267 $okkeys = 1; 268 } 269 } 270 271 272 /*************************************************************************************** 273 * 274 * Positionnement des droits 275 * 276 ***************************************************************************************/ 277 if ($ok) 278 { 279 // Droits sur les tables 280 $grant_query=$db->getGrantForUserQuery($dolibarr_main_db_user); 281 282 if ($grant_query) // Seules les bases qui en ont besoin le definisse 283 { 284 if ($db->query($grant_query)) 285 { 286 print "<tr><td>Grant User</td><td>".$langs->trans("OK")."</td></tr>"; 287 } 288 } 289 } 290 291 292 /*************************************************************************************** 293 * 294 * Chargement fichier functions.sql 295 * 296 ***************************************************************************************/ 297 if ($ok) 298 { 299 if ($choix==1) $dir = "../../mysql/functions/"; 300 else $dir = "../../pgsql/functions/"; 301 302 // Création données 303 $file = "functions.sql"; 304 if (file_exists($dir.$file)) { 305 $fp = fopen($dir.$file,"r"); 306 if ($fp) 307 { 308 while (!feof ($fp)) 309 { 310 $buffer = fgets($fp, 4096); 311 if (substr($buf, 0, 2) <> '--') 312 { 313 $buffer .= $buf; 314 } 315 } 316 fclose($fp); 317 } 318 319 // Si plusieurs requetes, on boucle sur chaque 320 $listesql=split('§',eregi_replace(";';",";'§",$buffer)); 321 foreach ($listesql as $buffer) { 322 if (trim($buffer)) { 323 324 if ($db->query(trim($buffer))) 325 { 326 $ok = 1; 327 } 328 else 329 { 330 if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') 331 { 332 // print "<tr><td>Insertion ligne : $buffer</td><td> 333 } 334 else 335 { 336 $ok = 0; 337 print $langs->trans("ErrorSQL")." : ".$db->errno()." - '$buffer' - ".$db->error()."<br>"; 338 } 339 } 340 } 341 } 342 343 print "<tr><td>".$langs->trans("FunctionsCreation")."</td>"; 344 if ($ok) 345 { 346 print "<td>".$langs->trans("OK")."</td></tr>"; 347 } 348 else 349 { 350 print "<td>".$langs->trans("Error")."</td></tr>"; 351 $ok = 1 ; 352 } 353 354 } 355 } 356 357 358 /*************************************************************************************** 359 * 360 * Chargement fichier data.sql 361 * 362 ***************************************************************************************/ 363 if ($ok) 364 { 365 if ($choix==1) $dir = "../../mysql/data/"; 366 else $dir = "../../pgsql/data/"; 367 368 // Création données 369 $file = "data.sql"; 370 $fp = fopen($dir.$file,"r"); 371 if ($fp) 372 { 373 while (!feof ($fp)) 374 { 375 $buffer = fgets($fp, 4096); 376 377 if (strlen(trim(ereg_replace("--","",$buffer)))) 378 { 379 if ($db->query($buffer)) 380 { 381 $ok = 1; 382 } 383 else 384 { 385 if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') 386 { 387 // print "<tr><td>Insertion ligne : $buffer</td><td> 388 } 389 else 390 { 391 $ok = 0; 392 print $langs->trans("ErrorSQL")." : ".$db->errno()." - '$buffer' - ".$db->error()."<br>"; 393 } 394 } 395 } 396 } 397 fclose($fp); 398 } 399 400 print "<tr><td>".$langs->trans("ReferenceDataLoading")."</td>"; 401 if ($ok) 402 { 403 print "<td>".$langs->trans("OK")."</td></tr>"; 404 } 405 else 406 { 407 print "<td>".$langs->trans("Error")."</td></tr>"; 408 $ok = 1 ; 409 } 410 } 411 412 413 /*************************************************************************************** 414 * 415 * Les variables qui ecrase le chemin par defaut sont redéfinies 416 * 417 ***************************************************************************************/ 418 if ($ok == 1) 419 { 420 $sql[0] = "UPDATE llx_const SET value = '".$dolibarr_main_data_root."/facture', 421 type = 'chaine', 422 visible = 0 423 where name ='FAC_OUTPUTDIR';" ; 424 425 $sql[1] = "UPDATE llx_const SET value = '".$dolibarr_main_data_root."/propale', 426 type = 'chaine', 427 visible = 0 428 where name = 'PROPALE_OUTPUTDIR';" ; 429 430 $sql[2] = "UPDATE llx_const SET value = '".$dolibarr_main_data_root."/ficheinter', 431 type = 'chaine', 432 visible = 0 433 where name = 'FICHEINTER_OUTPUTDIR';" ; 434 435 $sql[3] = "UPDATE llx_const SET value='".$dolibarr_main_data_root."/societe', 436 type = 'chaine', 437 visible = 0 438 where name = 'SOCIETE_OUTPUTDIR';" ; 439 440 $sql[4] = "DELETE from llx_const where name like '%_OUTPUT_URL';"; 441 442 443 $sql[5] = "UPDATE llx_const SET value='".$langs->defaultlang."', 444 type = 'chaine', 445 visible = 0 446 where name = 'MAIN_LANG_DEFAULT';" ; 447 448 $result = 0; 449 450 for ($i=0; $i < sizeof($sql);$i++) 451 { 452 if ($db->query($sql[$i])) 453 { 454 $result++; 455 } 456 } 457 458 } 459 460 print '</table>'; 461 462 $db->close(); 463 } 464 465 pFooter(!$ok,$setuplang); 466 467 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Mon Nov 26 12:29:37 2007 | par Balluche grâce à PHPXref 0.7 |
|