diff --git a/htdocs/install/etape2.php b/htdocs/install/etape2.php index fb488610828..26309b921b6 100644 --- a/htdocs/install/etape2.php +++ b/htdocs/install/etape2.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004 Laurent Destailleur +/* Copyright (C) 2004 Rodolphe Quiedeville + * Copyright (C) 2004-2005 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 @@ -20,6 +20,7 @@ * $Source$ * */ + include_once("./inc.php"); $setuplang=isset($_POST["selectlang"])?$_POST["selectlang"]:(isset($_GET["selectlang"])?$_GET["selectlang"]:$langcode); @@ -33,296 +34,408 @@ $etape = 2; if (file_exists($conffile)) { - include_once($conffile); + include_once($conffile); } if($dolibarr_main_db_type == "mysql") { - require ($dolibarr_main_document_root . "/lib/mysql.lib.php"); - $choix=1; + 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 . "/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 '

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

'; - print ''; - $error=0; + 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) + $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 ; + print ""; + $ok = 1 ; } - else + 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; - } + print ""; } - /*************************************************************************************** - * - * Chargement fichier data.sql - * - ***************************************************************************************/ - if ($ok == 1) + if ($ok) { - // - // 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 ; - } + if($db->database_selected == 1) + { + + dolibarr_syslog("Connexion réussie à la base : $dolibarr_main_db_name"); + } + else + { + $ok = 0 ; + } } - /*************************************************************************************** - * - * Les variables qui ecrase le chemin par defaut sont redéfinies - * - ***************************************************************************************/ - if ($ok == 1) + /*************************************************************************************** + * + * Chargement fichiers tables/*.sql (non *.key.sql) + * A faire avant les fichiers *.key.sql + * + ***************************************************************************************/ + if ($ok) { - $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';"; + if ($choix==1) $dir = "../../mysql/tables/"; + else $dir = "../../pgsql/tables/"; + $ok = 0; + $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); + $buffer = ''; + $fp = fopen($dir.$file,"r"); + if ($fp) + { + while (!feof ($fp)) + { + $buf = fgets($fp, 4096); + if (substr($buf, 0, 2) <> '--') + { + $buffer .= $buf; + } + } + fclose($fp); + } - $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 ""; + } + else + { + if ($db->errno() == DB_ERROR_TABLE_ALREADY_EXISTS) + { + //print ""; + $table_exists = 1; + } + else + { + print ""; + print ""; + $error++; + } + } + } + + } + closedir($handle); + + if ($error == 0) + { + print ''; + $ok = 1; + } } - /*************************************************************************************** - * - * - * - * - ***************************************************************************************/ + /*************************************************************************************** + * + * Chargement fichiers tables/*.key.sql + * A faire après les fichiers *.sql + * + ***************************************************************************************/ + if ($ok) + { + if ($choix==1) $dir = "../../mysql/tables/"; + else $dir = "../../pgsql/tables/"; + + $okkeys = 0; + $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); + } + + // Si plusieurs requetes, on boucle sur chaque + $listesql=split(';',$buffer); + foreach ($listesql as $buffer) { + if (trim($buffer)) { + //print ""; + if ($db->query(trim($buffer))) + { + //print ""; + } + else + { + if ($db->errno() == DB_ERROR_CANNOT_CREATE || eregi('duplicate key name',$db->error())) + { + //print ""; + $key_exists = 1; + } + else + { + print ""; + print ""; + $error++; + } + } + } + } + } + + } + closedir($handle); + + if ($error == 0) + { + print ''; + $okkeys = 1; + } + } + + + /*************************************************************************************** + * + * Positionnement des droits + * + ***************************************************************************************/ + if ($ok) + { + // Droits sur les tables + if ($grant_query) { + if ($db->query($grant_query)) + { + print ""; + } + } + } - print '
"; - print $langs->trans("ServerConnection")." : $dolibarr_main_db_host".$langs->trans("OK")."
"; + 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").'
Erreur lors de la création de : $dolibarr_main_db_name".$langs->trans("Error")."
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")."
Création de la table $name/td>"; + + if ($db->query($buffer)) + { + //print "OK requete ==== $buffer
Déjà existante
".$langs->trans("CreateTableAndPrimaryKey",$name)."".$langs->trans("Error")." ".$db->errno()." ".$db->error()."
'; + print $langs->trans("TablesAndPrimaryKeysCreation").''.$langs->trans("OK").'
Création de la table $name
Création des clés et index de la table $name: '$buffer'OK requete ==== $buffer
Déjà existante
".$langs->trans("CreateOtherKeysForTable",$name)."".$langs->trans("Error")." ".$db->errno()." ".$db->error()."
'; + print $langs->trans("OtherKeysCreation").''.$langs->trans("OK").'
Grant User".$langs->trans("OK")."
'; + /*************************************************************************************** + * + * Chargement fichier functions.sql + * + ***************************************************************************************/ + if ($ok) + { + if ($choix==1) $dir = "../../mysql/functions/"; + else $dir = "../../pgsql/functions/"; - $db->close(); + // Création données + $file = "functions.sql"; + if (file_exists($dir.$file)) { + $fp = fopen($dir.$file,"r"); + if ($fp) + { + while (!feof ($fp)) + { + $buffer = fgets($fp, 4096); + if (substr($buf, 0, 2) <> '--') + { + $buffer .= $buf; + } + } + fclose($fp); + } + + // Si plusieurs requetes, on boucle sur chaque + $listesql=split('§',eregi_replace(";';",";'§",$buffer)); + foreach ($listesql as $buffer) { + if (trim($buffer)) { + + if ($db->query(trim($buffer))) + { + $ok = 1; + } + else + { + if ($db->errno() == DB_ERROR_RECORD_ALREADY_EXISTS) + { + // print "Insertion ligne : $buffer + } + else + { + $ok = 0; + print "Erreur SQL ".$db->errno()." sur requete '$buffer': ".$db->error()."
"; + } + } + } + } + + print "".$langs->trans("FunctionsCreation").""; + if ($ok) + { + print "".$langs->trans("OK").""; + } + else + { + print "".$langs->trans("Error").""; + $ok = 1 ; + } + + } + } + + + /*************************************************************************************** + * + * Chargement fichier data.sql + * + ***************************************************************************************/ + if ($ok) + { + if ($choix==1) $dir = "../../mysql/data/"; + else $dir = "../../pgsql/data/"; + + // Création données + $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 "Insertion ligne : $buffer + } + else + { + $ok = 0; + print "Erreur SQL ".$db->errno()." sur requete '$buffer': ".$db->error()."
"; + } + } + } + } + fclose($fp); + } + + print "".$langs->trans("ReferenceDataLoading").""; + if ($ok) + { + print "".$langs->trans("OK").""; + } + else + { + print "".$langs->trans("Error").""; + $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 ''; + + $db->close(); } pFooter(!$ok); ?> diff --git a/pgsql/functions/functions.sql b/pgsql/functions/functions.sql index 35679e004d9..c32702a5e58 100644 --- a/pgsql/functions/functions.sql +++ b/pgsql/functions/functions.sql @@ -36,4 +36,4 @@ CREATE OR REPLACE FUNCTION FROM_UNIXTIME(BIGINT, VARCHAR) RETURNS TIMESTAMP WITH TIME ZONE LANGUAGE SQL IMMUTABLE STRICT -AS 'SELECT TIMESTAMP WITH TIME ZONE \'epoch\' + $1 * interval \'1 second\';'; \ No newline at end of file +AS 'SELECT TIMESTAMP WITH TIME ZONE \'epoch\' + $1 * interval \'1 second\' ;'; \ No newline at end of file