* Copyright (C) 2004 Laurent Destailleur * * This program 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. * * This program 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Id$ * $Source$ * */ include_once("./inc.php"); $setuplang=isset($_POST["selectlang"])?$_POST["selectlang"]:(isset($_GET["selectlang"])?$_GET["selectlang"]:$langcode); $langs->defaultlang=$setuplang; $langs->load("admin"); $langs->load("install"); pHeader($langs->trans("CreateDatabaseObjects"),"etape4"); $etape = 2; if (file_exists($conffile)) { include_once($conffile); } if($dolibarr_main_db_type == "mysql") { require ($dolibarr_main_document_root . "/lib/mysql.lib.php"); $choix=1; } else { require ($dolibarr_main_document_root . "/lib/pgsql.lib.php"); require ($dolibarr_main_document_root . "/lib/grant.postgres.php"); $choix=2; } require ($dolibarr_main_document_root . "/conf/conf.class.php"); if ($_POST["action"] == "set") { print '

'.$langs->trans("Database").'

'; print ''; $error=0; $conf = new Conf();// on pourrait s'en passer $conf->db->host = $dolibarr_main_db_host; $conf->db->name = $dolibarr_main_db_name; $conf->db->user = $dolibarr_main_db_user; $conf->db->pass = $dolibarr_main_db_pass; $db = new DoliDb(); $ok = 0; if ($db->connected == 1) { print ""; $ok = 1 ; } else { print ""; } /*************************************************************************************** * * */ if ($ok) { if($db->database_selected == 1) { dolibarr_syslog("Connexion réussie à la base : $dolibarr_main_db_name"); } else { $ok = 0 ; } } /*************************************************************************************** * * */ if ($ok) { $ok = 0; if ($choix == 1) { $dir = "../../mysql/tables/"; } else { $dir = "../../pgsql/tables/"; } $handle=opendir($dir); $table_exists = 0; while (($file = readdir($handle))!==false) { if (substr($file, strlen($file) - 4) == '.sql' && substr($file,0,4) == 'llx_' && substr($file, - 8) <> '.key.sql') { $name = substr($file, 0, strlen($file) - 4); //print ""; $buffer = ''; $fp = fopen($dir.$file,"r"); if ($fp) { while (!feof ($fp)) { $buf = fgets($fp, 4096); if (substr($buf, 0, 2) <> '--') { $buffer .= $buf; } } fclose($fp); } if ($db->query($buffer)) { //print ""; } else { if ($db->errno() == DB_ERROR_TABLE_ALREADY_EXISTS) { //print ""; $table_exists = 1; } else { print ""; print ""; $error++; } } } } //droit sur les tables if ($db->query($grant_query)) { print ""; } closedir($handle); if ($error == 0) { print ''; $ok = 1; } } /*************************************************************************************** * * Chargement fichier data.sql * ***************************************************************************************/ if ($ok == 1) { // // Données // if ($choix==1) { $dir = "../../mysql/data/"; $file = "data.sql"; $fp = fopen($dir.$file,"r"); if ($fp) { while (!feof ($fp)) { $buffer = fgets($fp, 4096); if (strlen(trim(ereg_replace("--","",$buffer)))) { if ($db->query($buffer)) { $ok = 1; } else { if ($db->errno() == DB_ERROR_RECORD_ALREADY_EXISTS) { // print ""; } else { $ok = 0; print "Erreur SQL ".$db->errno()." sur requete '$buffer': ".$db->error()."
"; } } //}//while fclose($fp); } }//else print ""; if ($ok) { print ""; } else { print ""; $ok = 1 ; } } /*************************************************************************************** * * Les variables qui ecrase le chemin par defaut sont redéfinies * ***************************************************************************************/ if ($ok == 1) { $sql[0] = "UPDATE llx_const SET value = '".$dolibarr_main_data_root."/facture', type = 'chaine', visible = 0 where name ='FAC_OUTPUTDIR';" ; $sql[1] = "UPDATE llx_const SET value = '".$dolibarr_main_data_root."/propale', type = 'chaine', visible = 0 where name = 'PROPALE_OUTPUTDIR';" ; $sql[2] = "UPDATE llx_const SET value = '".$dolibarr_main_data_root."/ficheinter', type = 'chaine', visible = 0 where name = 'FICHEINTER_OUTPUTDIR';" ; $sql[3] = "UPDATE llx_const SET value='".$dolibarr_main_data_root."/societe', type = 'chaine', visible = 0 where name = 'SOCIETE_OUTPUTDIR';" ; $sql[4] = "DELETE from llx_const where name like '%_OUTPUT_URL';"; $sql[5] = "UPDATE llx_const SET value='".$langs->defaultlang."', type = 'chaine', visible = 0 where name = 'MAIN_LANG_DEFAULT';" ; $result = 0; for ($i=0; $i < sizeof($sql);$i++) { if ($db->query($sql[$i])) { $result++; } } if ($result == sizeof($sql)) { if ($error == 0) { $db->query("DELETE FROM llx_const WHERE name='MAIN_NOT_INSTALLED'"); } } } /*************************************************************************************** * * * * ***************************************************************************************/ print '
"; print $langs->trans("ServerConnection")." : $dolibarr_main_db_host".$langs->trans("OK")."
Erreur lors de la création de : $dolibarr_main_db_name".$langs->trans("Error")."
Création de la table $nameOK requete ==== $buffer
Déjà existante
Création de la table $name".$langs->trans("Error")." ".$db->errno()." ".$db->error()."
Grant User '$nom' ".$langs->trans("OK")."
'; print $langs->trans("TablesAndPrimaryKeyCreation").''.$langs->trans("OK").'
Insertion ligne : $buffer } else { $ok = 0; print "Erreur SQL ".$db->errno()." sur requete '$buffer': ".$db->error()."
"; } } } } fclose($fp); } }//choix==1 else { $dir = "../../pgsql/data/"; $file = "data.sql"; $fp = fopen($dir.$file,"r"); $buffer=''; if ($fp) { while (!feof ($fp)) { $buffer .= fgets($fp, 4096); } if ($db->query($buffer)) { $ok = 1; } else { if ($db->errno() == DB_ERROR_RECORD_ALREADY_EXISTS) { // print "
Insertion ligne : $bufferDéja existante
".$langs->trans("ReferenceDataLoading")."".$langs->trans("OK")."
".$langs->trans("Error")."
'; $db->close(); } pFooter(!$ok); ?>