';
- /* Preparation integration SMARTY */
- fputs($fp, '$dolibarr_smarty_libs_dir="";');
- fputs($fp,"\n");
-
- fputs($fp, '$dolibarr_smarty_compile="";');
- fputs($fp,"\n");
+ // Verification validite parametre main_dir
+ if (! $error)
+ {
+ if (! is_dir($main_dir))
+ {
+ dolibarr_syslog ("Repertoire '".$main_dir."' inexistant ou non accessible");
+
+ print "";
+ print $langs->trans("ErrorDirDoesNotExists",$main_dir).' ';
+ print $langs->trans("ErrorWrongValueForParameter",$langs->trans("WebPagesDirectory")).' ';
+ print $langs->trans("ErrorGoBackAndCorrectParameters").'
';
+ print ' | ';
+ print $langs->trans("Error");
+ print " |
";
+ $error++;
+ }
+ }
- fputs($fp, '$dolibarr_smarty_cache="";');
- fputs($fp,"\n");
- /* Fin Smarty*/
-
- fputs($fp, '?>');
- fclose($fp);
-
- if (file_exists("$conffile"))
- {
- include("$conffile"); // On force rechargement. Ne pas mettre include_once !
- print "| ".$langs->trans("ConfigurationSaving")." | ".$langs->trans("OK")." | ";
- }
- else
- {
- $error++;
- }
- }
-
- if($dolibarr_main_db_type == "mysql")
- {
- $choix=1;
- }
- else
- {
- $choix=2;
- }
-
- // Chargement driver acces bases
- require_once($dolibarr_main_document_root."/lib/databases/".$dolibarr_main_db_type.".lib.php");
-
- }
-
- /***************************************************************************
- *
- * Creation des répertoires
- *
- ***************************************************************************/
-
- // Creation des sous-répertoires main_data_dir
- if (! $error)
- {
- dolibarr_syslog ("Le dossier '".$main_dir."' existe");
-
- // Répertoire des documents
- if (! is_dir($main_data_dir))
- {
- create_exdir($main_data_dir);
- }
-
- if (! is_dir($main_data_dir))
- {
- print "
| ".$langs->trans("ErrorDirDoesNotExists",$main_data_dir);
- print $langs->trans("YouMustCreateItAndAllowServerToWrite");
- print ' | ';
- print $langs->trans("Error");
- print " |
";
- $error++;
- }
- else
- {
- // Les documents sont en dehors de htdocs car ne doivent pas pouvoir etre téléchargés en passant outre l'authentification
- $dir[0] = "$main_data_dir/facture";
- $dir[1] = "$main_data_dir/users";
- $dir[2] = "$main_data_dir/propale";
- $dir[3] = "$main_data_dir/societe";
- $dir[4] = "$main_data_dir/ficheinter";
- $dir[5] = "$main_data_dir/produit";
- $dir[6] = "$main_data_dir/rapport";
- $dir[7] = "$main_data_dir/rss";
- $dir[8] = "$main_data_dir/logo";
-
- // Boucle sur chaque répertoire de dir[] pour les créer s'ils nexistent pas
- for ($i = 0 ; $i < sizeof($dir) ; $i++)
- {
- if (is_dir($dir[$i]))
- {
- dolibarr_syslog ("Directory '".$dir[$i]."' exists");
- }
- else
- {
- if (create_exdir($dir[$i]) < 0)
- {
- print "| ";
- print "Failed to create directory: ".$dir[$i];
- print ' | ';
- print $langs->trans("Error");
- print " |
";
- $error++;
- }
- else
- {
- dolibarr_syslog("Directory '".$dir[$i]."' created");
- }
- }
- }
- }
- }
-
- /*
- * Base de données
- *
- */
- if (! $error)
- {
- include_once($dolibarr_main_document_root . "/conf/conf.class.php");
-
- $conf = new Conf();
- $conf->db->type = trim($dolibarr_main_db_type);
- $conf->db->host = trim($dolibarr_main_db_host);
- $conf->db->name = trim($dolibarr_main_db_name);
- $conf->db->user = trim($dolibarr_main_db_user);
- $conf->db->pass = trim($dolibarr_main_db_pass);
-
- $userroot=isset($_POST["db_user_root"])?$_POST["db_user_root"]:"";
- $passroot=isset($_POST["db_pass_root"])?$_POST["db_pass_root"]:"";
-
-
- /*
- * Si creation utilisateur admin demandée, on le crée
- */
- if (isset($_POST["db_create_user"]) && $_POST["db_create_user"] == "on")
- {
- dolibarr_syslog("Creation de l'utilisateur: ".$dolibarr_main_db_user." choix base: ".$choix);
-
- if ($choix == 1) //choix 1=mysql
- {
- //print $conf->db->host." , ".$conf->db->name." , ".$conf->db->user." , ".$conf->db->pass;
-
- // Creation handler de base, verification du support et connexion
- $db = new DoliDb($conf->db->type,$conf->db->host,$userroot,$passroot,'mysql');
- if ($db->error)
- {
- print $langs->trans("ThisPHPDoesNotSupportTypeBase",'mysql');
- $error++;
- }
-
- if (! $error)
- {
- if ($db->connected)
- {
- $sql = "INSERT INTO user ";
- $sql.= "(Host,User,password,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv,Index_Priv,Alter_priv)";
- $sql.= " VALUES ('$dolibarr_main_db_host','$dolibarr_main_db_user',password('$dolibarr_main_db_pass')";
- $sql.= ",'Y','Y','Y','Y','Y','Y','Y','Y');";
-
- //print "$sql
\n";
-
- $db->query($sql);
-
- $sql = "INSERT INTO db ";
- $sql.= "(Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv,Index_Priv,Alter_priv)";
- $sql.= " VALUES ('$dolibarr_main_db_host','$dolibarr_main_db_name','$dolibarr_main_db_user'";
- $sql.= ",'Y','Y','Y','Y','Y','Y','Y','Y');";
-
- //print "$sql
\n";
-
- $resql=$db->query($sql);
- if ($resql)
- {
- dolibarr_syslog("flush privileges");
- $db->query("FLUSH Privileges;");
-
- print '| ';
- print $langs->trans("UserCreation").' : ';
- print $dolibarr_main_db_user;
- print ' | ';
- print ''.$langs->trans("OK").' |
';
- }
- else
- {
- if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
- {
- dolibarr_syslog("User already exists");
- print '| ';
- print $langs->trans("UserCreation").' : ';
- print $dolibarr_main_db_user;
- print ' | ';
- print ''.$langs->trans("LoginAlreadyExists").' |
';
- }
- else
- {
- dolibarr_syslog("Failed to create user");
- print '| ';
- print $langs->trans("UserCreation").' : ';
- print $dolibarr_main_db_user;
- print ' | ';
- print ''.$langs->trans("Error").' '.$db->error()." |
";
- }
- }
-
- $db->close();
- }
- else
- {
- print '| ';
- print $langs->trans("UserCreation").' : ';
- print $dolibarr_main_db_user;
- print ' | ';
- print ''.$langs->trans("Error").' | ';
- print '
';
-
- // Affiche aide diagnostique
- print ' ';
- print 'Vous avez demandé la création du login Dolibarr "'.$dolibarr_main_db_user.'", mais pour cela, ';
- print 'Dolibarr doit se connecter sur le serveur "'.$dolibarr_main_db_host.'" via le super utilisateur "'.$userroot.'". ';
- print 'La connexion ayant échoué, les paramètres du serveur ou du super utilisateur sont peut-etre incorrects. ';
- print $langs->trans("ErrorGoBackAndCorrectParameters").'
';
- print ' |
';
-
- $error++;
- }
- }
- }
- else //choix 2=postgresql
- {
- //print $conf->db->host." , ".$conf->db->name." , ".$conf->db->user." , ".$conf->db->pass;
-
- // Creation handler de base, verification du support et connexion
- $db = new DoliDb($conf->db->type,$conf->db->host,$userroot,$passroot,$conf->db->name);
- if ($db->error)
- {
- print $langs->trans("ThisPHPDoesNotSupportTypeBase",'mysql');
- $error++;
- }
-
- if (! $error)
- {
- if ($db->connected)
- {
- $nom = $dolibarr_main_db_user;
- $sql = "create user \"".$nom."\" with password '".$dolibarr_main_db_pass."';";
- //print $query_str;
- $resql = $db->query($sql);
- if ($resql)
- {
- print '| ';
- print $langs->trans("UserCreation").' : ';
- print $dolibarr_main_db_user;
- print ' | ';
- print ''.$langs->trans("OK").' | ';
- print '
';
- }
- else
- {
- if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
- {
- dolibarr_syslog("User already exists");
- print '| ';
- print $langs->trans("UserCreation").' : ';
- print $dolibarr_main_db_user;
- print ' | ';
- print ''.$langs->trans("LoginAlreadyExists").' |
';
- }
- else
- {
- dolibarr_syslog("Failed to create user");
- print '| ';
- print $langs->trans("UserCreation").' : ';
- print $dolibarr_main_db_user;
- print ' | ';
- print ''.$langs->trans("Error").' '.$db->error()." |
";
- }
- }
- }
- else
- {
- print '| ';
- print $langs->trans("UserCreation").' : ';
- print $dolibarr_main_db_user;
- print ' | ';
- print ''.$langs->trans("Error").' | ';
- print '
';
-
- // Affiche aide diagnostique
- print ' ';
- print 'Vous avez demandé la création du login Dolibarr "'.$dolibarr_main_db_user.'", mais pour cela, ';
- print 'Dolibarr doit se connecter sur le serveur "'.$dolibarr_main_db_host.'" via le super utilisateur "'.$userroot.'". ';
- print 'La connexion ayant échoué, les paramètres du serveur ou du super utilisateur sont peut-etre incorrects. ';
- print $langs->trans("ErrorGoBackAndCorrectParameters").'
';
- print ' |
';
-
- $error++;
- }
- }
- }
-
- } // Fin si "creation utilisateur"
-
-
- /*
- * Si creation database demandée, on la crée
- */
- if (! $error && (isset($_POST["db_create_database"]) && $_POST["db_create_database"] == "on"))
- {
- dolibarr_syslog ("Creation de la base : ".$dolibarr_main_db_name);
+ // Sauvegarde fichier configuration
+ if (! $error)
+ {
+ $fp = fopen("$conffile", "w");
+
+ if($fp)
+ {
+ clearstatcache();
+
+ fputs($fp, 'db->type,$conf->db->host,$userroot,$passroot);
+ /* Preparation integration SMARTY */
+ fputs($fp, '$dolibarr_smarty_libs_dir="";');
+ fputs($fp,"\n");
+
+ fputs($fp, '$dolibarr_smarty_compile="";');
+ fputs($fp,"\n");
- if ($db->connected)
- {
- if ($db->DDLCreateDb($dolibarr_main_db_name))
- {
- print '| ';
- print $langs->trans("DatabaseCreation").' : ';
- print $dolibarr_main_db_name;
- print ' | ';
- print "".$langs->trans("OK")." |
";
- }
- else
- {
- print '| ';
- print $langs->trans("DatabaseCreation").' : ';
- print $dolibarr_main_db_name;
- print ' | ';
- print ''.$langs->trans("Error").' '.$db->errno().' |
';
-
- // Affiche aide diagnostique
- print ' ';
- print $langs->trans("ErrorFailedToCreateDatabase",$dolibarr_main_db_name).' ';
- print $langs->trans("IfDatabaseExistsGoBackAndCheckCreate");
- print ' ';
- print ' |
';
-
- $error++;
- }
- $db->close();
- }
- else {
- print '| ';
- print $langs->trans("DatabaseCreation").' : ';
- print $dolibarr_main_db_name;
- print ' | ';
- print ''.$langs->trans("Error").' | ';
- print '
';
-
- // Affiche aide diagnostique
- print ' Vous avez demandé la création de la base Dolibarr "'.$dolibarr_main_db_name.'", mais pour cela, ';
- print 'Dolibarr doit se connecter sur le serveur "'.$dolibarr_main_db_host.'" via le super utilisateur "'.$userroot.'". ';
- print 'La connexion ayant échoué, les paramètres du serveur ou du super utilisateur sont peut-etre incorrects. ';
- print $langs->trans("ErrorGoBackAndCorrectParameters").'
';
- print ' |
';
-
- $error++;
- }
- } // Fin si "creation database"
+ fputs($fp, '$dolibarr_smarty_cache="";');
+ fputs($fp,"\n");
+ /* Fin Smarty*/
+
+ fputs($fp, '?>');
+ fclose($fp);
+
+ if (file_exists("$conffile"))
+ {
+ include("$conffile"); // On force rechargement. Ne pas mettre include_once !
+ print "| ".$langs->trans("ConfigurationSaving")." | ".$langs->trans("OK")." | ";
+ }
+ else
+ {
+ $error++;
+ }
+ }
+
+ if($dolibarr_main_db_type == "mysql")
+ {
+ $choix=1;
+ }
+ else
+ {
+ $choix=2;
+ }
+
+ // Chargement driver acces bases
+ require_once($dolibarr_main_document_root."/lib/databases/".$dolibarr_main_db_type.".lib.php");
+
+ }
- /*
- * On test maintenant l'accès par le user admin dolibarr
- */
- if (! $error)
- {
- dolibarr_syslog("connexion de type=".$conf->db->type." sur host=".$conf->db->host." user=".$conf->db->user." name=".$conf->db->name);
- //print "connexion de type=".$conf->db->type." sur host=".$conf->db->host." user=".$conf->db->user." name=".$conf->db->name;
+ /***************************************************************************
+ * Creation des répertoires
+ ***************************************************************************/
- $db = new DoliDb($conf->db->type,$conf->db->host,$conf->db->user,$conf->db->pass,$conf->db->name);
+ // Creation des sous-répertoires main_data_dir
+ if (! $error)
+ {
+ dolibarr_syslog ("Le dossier '".$main_dir."' existe");
+
+ // Répertoire des documents
+ if (! is_dir($main_data_dir))
+ {
+ create_exdir($main_data_dir);
+ }
+
+ if (! is_dir($main_data_dir))
+ {
+ print "
| ".$langs->trans("ErrorDirDoesNotExists",$main_data_dir);
+ print $langs->trans("YouMustCreateItAndAllowServerToWrite");
+ print ' | ';
+ print $langs->trans("Error");
+ print " |
";
+ $error++;
+ }
+ else
+ {
+ // Les documents sont en dehors de htdocs car ne doivent pas pouvoir etre téléchargés en passant outre l'authentification
+ $dir[0] = "$main_data_dir/facture";
+ $dir[1] = "$main_data_dir/users";
+ $dir[2] = "$main_data_dir/propale";
+ $dir[3] = "$main_data_dir/societe";
+ $dir[4] = "$main_data_dir/ficheinter";
+ $dir[5] = "$main_data_dir/produit";
+ $dir[6] = "$main_data_dir/rapport";
+ $dir[7] = "$main_data_dir/rss";
+ $dir[8] = "$main_data_dir/logo";
+
+ // Boucle sur chaque répertoire de dir[] pour les créer s'ils nexistent pas
+ for ($i = 0 ; $i < sizeof($dir) ; $i++)
+ {
+ if (is_dir($dir[$i]))
+ {
+ dolibarr_syslog ("Directory '".$dir[$i]."' exists");
+ }
+ else
+ {
+ if (create_exdir($dir[$i]) < 0)
+ {
+ print "| ";
+ print "Failed to create directory: ".$dir[$i];
+ print ' | ';
+ print $langs->trans("Error");
+ print " |
";
+ $error++;
+ }
+ else
+ {
+ dolibarr_syslog("Directory '".$dir[$i]."' created");
+ }
+ }
+ }
+ }
+ }
- if ($db->connected == 1)
- {
- // si accès serveur ok et accès base ok, tout est ok, on ne va pas plus loin, on a même pas utilisé le compte root.
- if ($db->database_selected == 1)
- {
- dolibarr_syslog("la connexion au serveur par le user ".$conf->db->user." est reussie");
- print "| ";
- print $langs->trans("ServerConnection")." : ";
- print $dolibarr_main_db_host;
- print " | ";
- print $langs->trans("OK");
- print " |
";
+ /**
+ * Création des Bases de données
+ */
+ if (! $error)
+ {
+ include_once($dolibarr_main_document_root . "/conf/conf.class.php");
+
+ $conf = new Conf();
+ $conf->db->type = trim($dolibarr_main_db_type);
+ $conf->db->host = trim($dolibarr_main_db_host);
+ $conf->db->name = trim($dolibarr_main_db_name);
+ $conf->db->user = trim($dolibarr_main_db_user);
+ $conf->db->pass = trim($dolibarr_main_db_pass);
+
+ $userroot=isset($_POST["db_user_root"])?$_POST["db_user_root"]:"";
+ $passroot=isset($_POST["db_pass_root"])?$_POST["db_pass_root"]:"";
- dolibarr_syslog("la connexion a la base : ".$conf->db->name.",par le user : ".$conf->db->user." est reussie");
- print "| ";
- print $langs->trans("DatabaseConnection")." : ";
- print $dolibarr_main_db_name;
- print " | ";
- print $langs->trans("OK");
- print " |
";
- $error = 0;
- }
- else
- {
- dolibarr_syslog("la connection au serveur par le user ".$conf->db->user." est reussie");
- print "| ";
- print $langs->trans("ServerConnection")." : ";
- print $dolibarr_main_db_host;
- print " | ";
- print $langs->trans("OK");
- print " |
";
+ /**
+ * Si creation utilisateur admin demandée, on le crée
+ */
+ if (isset($_POST["db_create_user"]) && $_POST["db_create_user"] == "on")
+ {
+ dolibarr_syslog("Creation de l'utilisateur: ".$dolibarr_main_db_user." choix base: ".$choix);
- dolibarr_syslog("la connexion a la base ".$conf->db->name.",par le user ".$conf->db->user." a échoué");
- print "| ";
- print $langs->trans("DatabaseConnection")." : ";
- print $dolibarr_main_db_name;
- print ' | ';
- print $langs->trans("Error");
- print " |
";
+ //print $conf->db->host." , ".$conf->db->name." , ".$conf->db->user." , ".$conf->db->pass;
+
+ // Creation handler de base, verification du support et connexion
+ $db = new DoliDb($conf->db->type,$conf->db->host,$userroot,$passroot,'mysql');
+ if ($db->error)
+ {
+ print $langs->trans("ThisPHPDoesNotSupportTypeBase",'mysql');
+ $error++;
+ }
+
+ if (! $error)
+ {
+ if ($db->connected)
+ {
+ $result=$db->DDLCreateUser($dolibarr_main_db_host,$dolibarr_main_db_user,$dolibarr_main_db_pass);
- // Affiche aide diagnostique
- print ' Vérifier que le nom de base "'.$dolibarr_main_db_name.'" est correct. ';
- print 'Si ce nom est correct et que cette base n\'existe pas déjà, vous devez cocher l\'option "Créer la base de donnée". ';
- print $langs->trans("ErrorGoBackAndCorrectParameters").'
';
- print ' |
';
+ if ($result > 0)
+ {
+
+ print '| ';
+ print $langs->trans("UserCreation").' : ';
+ print $dolibarr_main_db_user;
+ print ' | ';
+ print ''.$langs->trans("OK").' |
';
+ }
+ else
+ {
+ if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
+ {
+ dolibarr_syslog("User already exists");
+ print '| ';
+ print $langs->trans("UserCreation").' : ';
+ print $dolibarr_main_db_user;
+ print ' | ';
+ print ''.$langs->trans("LoginAlreadyExists").' |
';
+ }
+ else
+ {
+ dolibarr_syslog("Failed to create user");
+ print '| ';
+ print $langs->trans("UserCreation").' : ';
+ print $dolibarr_main_db_user;
+ print ' | ';
+ print ''.$langs->trans("Error").' '.$db->error()." |
";
+ }
+ }
+
+ $db->close();
+ }
+ else
+ {
+ print '| ';
+ print $langs->trans("UserCreation").' : ';
+ print $dolibarr_main_db_user;
+ print ' | ';
+ print ''.$langs->trans("Error").' | ';
+ print '
';
+
+ // Affiche aide diagnostique
+ print ' ';
+ print 'Vous avez demandé la création du login Dolibarr "'.$dolibarr_main_db_user.'", mais pour cela, ';
+ print 'Dolibarr doit se connecter sur le serveur "'.$dolibarr_main_db_host.'" via le super utilisateur "'.$userroot.'". ';
+ print 'La connexion ayant échoué, les paramètres du serveur ou du super utilisateur sont peut-etre incorrects. ';
+ print $langs->trans("ErrorGoBackAndCorrectParameters").'
';
+ print ' |
';
+
+ $error++;
+ }
+ }
+ } // Fin si "creation utilisateur"
+
+
+ /*
+ * Si creation database demandée, on la crée
+ */
+ if (! $error && (isset($_POST["db_create_database"]) && $_POST["db_create_database"] == "on"))
+ {
+ dolibarr_syslog ("Creation de la base : ".$dolibarr_main_db_name);
- $error++;
- }
- }
- else
- {
- dolibarr_syslog("la connection au serveur par le user ".$conf->db->user." est rate");
- print "| ";
- print $langs->trans("ServerConnection")." : ";
- print $dolibarr_main_db_host;
- print ' | ';
- print ''.$db->error.'';
- print " |
";
+ $db = new DoliDb($conf->db->type,$conf->db->host,$userroot,$passroot);
- // Affiche aide diagnostique
- print ' Le serveur "'.$conf->db->host.'", nom de base "'.$conf->db->name.'", login "'.$conf->db->user.'", ou mot de passe "'.$conf->db->pass.'" de la base de donnée est peut-être incorrect ou la version du client PHP trop ancienne par rapport à la version de la base de donnée. ';
- print 'Si le login n\'existe pas encore, vous devez cocher l\'option "Créer l\'utilisateur". ';
- print $langs->trans("ErrorGoBackAndCorrectParameters").'
';
- print ' |
';
+ if ($db->connected)
+ {
+ if ($db->DDLCreateDb($dolibarr_main_db_name))
+ {
+ print '| ';
+ print $langs->trans("DatabaseCreation").' : ';
+ print $dolibarr_main_db_name;
+ print ' | ';
+ print "".$langs->trans("OK")." |
";
+ }
+ else
+ {
+ print '| ';
+ print $langs->trans("DatabaseCreation").' : ';
+ print $dolibarr_main_db_name;
+ print ' | ';
+ print ''.$langs->trans("Error").' '.$db->errno().' |
';
- $error++;
- }
- }
- }
+ // Affiche aide diagnostique
+ print ' ';
+ print $langs->trans("ErrorFailedToCreateDatabase",$dolibarr_main_db_name).' ';
+ print $langs->trans("IfDatabaseExistsGoBackAndCheckCreate");
+ print ' ';
+ print ' |
';
+
+ $error++;
+ }
+ $db->close();
+ }
+ else {
+ print '| ';
+ print $langs->trans("DatabaseCreation").' : ';
+ print $dolibarr_main_db_name;
+ print ' | ';
+ print ''.$langs->trans("Error").' | ';
+ print '
';
+
+ // Affiche aide diagnostique
+ print ' Vous avez demandé la création de la base Dolibarr "'.$dolibarr_main_db_name.'", mais pour cela, ';
+ print 'Dolibarr doit se connecter sur le serveur "'.$dolibarr_main_db_host.'" via le super utilisateur "'.$userroot.'". ';
+ print 'La connexion ayant échoué, les paramètres du serveur ou du super utilisateur sont peut-etre incorrects. ';
+ print $langs->trans("ErrorGoBackAndCorrectParameters").'
';
+ print ' |
';
+
+ $error++;
+ }
+ } // Fin si "creation database"
+
+
+ /*
+ * On test maintenant l'accès par le user admin dolibarr
+ */
+ if (! $error)
+ {
+ dolibarr_syslog("connexion de type=".$conf->db->type." sur host=".$conf->db->host." user=".$conf->db->user." name=".$conf->db->name);
+ //print "connexion de type=".$conf->db->type." sur host=".$conf->db->host." user=".$conf->db->user." name=".$conf->db->name;
+
+ $db = new DoliDb($conf->db->type,$conf->db->host,$conf->db->user,$conf->db->pass,$conf->db->name);
+
+ if ($db->connected == 1)
+ {
+ // si accès serveur ok et accès base ok, tout est ok, on ne va pas plus loin, on a même pas utilisé le compte root.
+ if ($db->database_selected == 1)
+ {
+ dolibarr_syslog("la connexion au serveur par le user ".$conf->db->user." est reussie");
+ print "| ";
+ print $langs->trans("ServerConnection")." : ";
+ print $dolibarr_main_db_host;
+ print " | ";
+ print $langs->trans("OK");
+ print " |
";
+
+ dolibarr_syslog("la connexion a la base : ".$conf->db->name.",par le user : ".$conf->db->user." est reussie");
+ print "| ";
+ print $langs->trans("DatabaseConnection")." : ";
+ print $dolibarr_main_db_name;
+ print " | ";
+ print $langs->trans("OK");
+ print " |
";
+
+ $error = 0;
+ }
+ else
+ {
+ dolibarr_syslog("la connection au serveur par le user ".$conf->db->user." est reussie");
+ print "| ";
+ print $langs->trans("ServerConnection")." : ";
+ print $dolibarr_main_db_host;
+ print " | ";
+ print $langs->trans("OK");
+ print " |
";
+
+ dolibarr_syslog("la connexion a la base ".$conf->db->name.",par le user ".$conf->db->user." a échoué");
+ print "| ";
+ print $langs->trans("DatabaseConnection")." : ";
+ print $dolibarr_main_db_name;
+ print ' | ';
+ print $langs->trans("Error");
+ print " |
";
+
+ // Affiche aide diagnostique
+ print ' Vérifier que le nom de base "'.$dolibarr_main_db_name.'" est correct. ';
+ print 'Si ce nom est correct et que cette base n\'existe pas déjà, vous devez cocher l\'option "Créer la base de donnée". ';
+ print $langs->trans("ErrorGoBackAndCorrectParameters").'
';
+ print ' |
';
+
+ $error++;
+ }
+ }
+ else
+ {
+ dolibarr_syslog("la connection au serveur par le user ".$conf->db->user." est rate");
+ print "| ";
+ print $langs->trans("ServerConnection")." : ";
+ print $dolibarr_main_db_host;
+ print ' | ';
+ print ''.$db->error.'';
+ print " |
";
+
+ // Affiche aide diagnostique
+ print ' Le serveur "'.$conf->db->host.'", nom de base "'.$conf->db->name.'", login "'.$conf->db->user.'", ou mot de passe "'.$conf->db->pass.'" de la base de donnée est peut-être incorrect ou la version du client PHP trop ancienne par rapport à la version de la base de donnée. ';
+ print 'Si le login n\'existe pas encore, vous devez cocher l\'option "Créer l\'utilisateur". ';
+ print $langs->trans("ErrorGoBackAndCorrectParameters").'
';
+ print ' |
';
+
+ $error++;
+ }
+ }
+ }
print '
';
}
diff --git a/htdocs/lib/databases/mysql.lib.php b/htdocs/lib/databases/mysql.lib.php
index faf9d32f1bf..9de17af84a2 100644
--- a/htdocs/lib/databases/mysql.lib.php
+++ b/htdocs/lib/databases/mysql.lib.php
@@ -779,6 +779,48 @@ class DoliDb
else
return 1;
}
+
+ /**
+ \brief Crée un utilisateur
+ \param dolibarr_main_db_host Ip serveur
+ \param dolibarr_main_db_user Nom user à créer
+ \param dolibarr_main_db_pass Mot de passe user à créer
+ \return int <0 si KO, >=0 si OK
+ */
+ function DDLCreateUser($dolibarr_main_db_host,$dolibarr_main_db_user,$dolibarr_main_db_pass)
+ {
+ $sql = "INSERT INTO user ";
+ $sql.= "(Host,User,password,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv,Index_Priv,Alter_priv)";
+ $sql.= " VALUES ('$dolibarr_main_db_host','$dolibarr_main_db_user',password('$dolibarr_main_db_pass')";
+ $sql.= ",'Y','Y','Y','Y','Y','Y','Y','Y');";
+
+ dolibarr_syslog("mysql.lib::DDLCreateUser sql=".$sql);
+ $resql=$this->query($sql);
+ if (! $resql)
+ {
+ return -1;
+ }
+
+ $sql = "INSERT INTO db ";
+ $sql.= "(Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv,Index_Priv,Alter_priv)";
+ $sql.= " VALUES ('$dolibarr_main_db_host','$dolibarr_main_db_name','$dolibarr_main_db_user'";
+ $sql.= ",'Y','Y','Y','Y','Y','Y','Y','Y');";
+
+ dolibarr_syslog("mysql.lib::DDLCreateUser sql=".$sql);
+ $resql=$this->query($sql);
+ if (! $resql)
+ {
+ return -1;
+ }
+
+ $sql="FLUSH Privileges";
+
+ dolibarr_syslog("mysql.lib::DDLCreateUser sql=".$sql);
+ $resql=$this->query($sql);
+
+ return 1;
+ }
+
}
?>
diff --git a/htdocs/lib/databases/mysqli.lib.php b/htdocs/lib/databases/mysqli.lib.php
index 6d00844a5f9..0b36e20465c 100644
--- a/htdocs/lib/databases/mysqli.lib.php
+++ b/htdocs/lib/databases/mysqli.lib.php
@@ -785,6 +785,46 @@ class DoliDb
return 1;
}
+ /**
+ \brief Crée un utilisateur
+ \param dolibarr_main_db_host Ip serveur
+ \param dolibarr_main_db_user Nom user à créer
+ \param dolibarr_main_db_pass Mot de passe user à créer
+ \return int <0 si KO, >=0 si OK
+ */
+ function DDLCreateUser($dolibarr_main_db_host,$dolibarr_main_db_user,$dolibarr_main_db_pass)
+ {
+ $sql = "INSERT INTO user ";
+ $sql.= "(Host,User,password,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv,Index_Priv,Alter_priv)";
+ $sql.= " VALUES ('$dolibarr_main_db_host','$dolibarr_main_db_user',password('$dolibarr_main_db_pass')";
+ $sql.= ",'Y','Y','Y','Y','Y','Y','Y','Y');";
+
+ dolibarr_syslog("mysql.lib::DDLCreateUser sql=".$sql);
+ $resql=$this->query($sql);
+ if (! $resql)
+ {
+ return -1;
+ }
+
+ $sql = "INSERT INTO db ";
+ $sql.= "(Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv,Index_Priv,Alter_priv)";
+ $sql.= " VALUES ('$dolibarr_main_db_host','$dolibarr_main_db_name','$dolibarr_main_db_user'";
+ $sql.= ",'Y','Y','Y','Y','Y','Y','Y','Y');";
+
+ dolibarr_syslog("mysql.lib::DDLCreateUser sql=".$sql);
+ $resql=$this->query($sql);
+ if (! $resql)
+ {
+ return -1;
+ }
+
+ $sql="FLUSH Privileges";
+
+ dolibarr_syslog("mysql.lib::DDLCreateUser sql=".$sql);
+ $resql=$this->query($sql);
+
+ return 1;
+ }
}
?>
diff --git a/htdocs/lib/databases/pgsql.lib.php b/htdocs/lib/databases/pgsql.lib.php
index a0581aacfae..a1898a30275 100644
--- a/htdocs/lib/databases/pgsql.lib.php
+++ b/htdocs/lib/databases/pgsql.lib.php
@@ -609,6 +609,27 @@ class DoliDb
return $this->results;
}
+
+ /**
+ \brief Crée un utilisateur
+ \param dolibarr_main_db_host Ip serveur
+ \param dolibarr_main_db_user Nom user à créer
+ \param dolibarr_main_db_pass Mot de passe user à créer
+ \return int <0 si KO, >=0 si OK
+ */
+ function DDLCreateUser($dolibarr_main_db_host,$dolibarr_main_db_user,$dolibarr_main_db_pass)
+ {
+ $sql = "create user \"".$dolibarr_main_db_user."\" with password '".$dolibarr_main_db_pass."'";
+
+ dolibarr_syslog("mysql.lib::DDLCreateUser sql=".$sql);
+ $resql=$this->query($sql);
+ if (! $resql)
+ {
+ return -1;
+ }
+
+ return 1;
+ }
}
?>