dolibarr/htdocs/install/etape2.php

318 lines
7.2 KiB
PHP
Raw Normal View History

<?php
/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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$
*
*/
2004-01-30 12:55:53 +01:00
include("./inc.php");
pHeader("Cr<EFBFBD>ation des objets de la base","etape4");
2004-02-12 17:44:49 +01:00
2004-01-30 17:00:18 +01:00
$etape = 2;
2004-01-30 12:55:53 +01:00
2004-01-27 15:36:40 +01:00
$conf = "../conf/conf.php";
if (file_exists($conf))
{
include($conf);
}
if($dolibarr_main_db_type == "mysql")
{
2004-11-27 17:15:55 +01:00
require ($dolibarr_main_document_root . "/lib/mysql.lib.php");
$choix=1;
}
else
{
2004-11-27 17:15:55 +01:00
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");
2004-01-27 15:36:40 +01:00
if ($_POST["action"] == "set")
2004-01-27 15:36:40 +01:00
{
print '<h2>Base de donn<6E>e</h2>';
print '<table cellspacing="0" cellpadding="4" border="0" width="100%">';
$error=0;
print '<tr><td colspan="2">Test de connexion <20> la base de donn<6E>es</td></tr>';
$conf = new Conf();// on pourrait s'en passer
2004-01-27 15:36:40 +01:00
$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 "<tr><td>Connexion au serveur : $dolibarr_main_db_host</td><td>OK</td></tr>";
2004-02-12 17:44:49 +01:00
$ok = 1 ;
}
else
{
print "<tr><td>Erreur lors de la cr<63>ation de : $dolibarr_main_db_name</td><td>ERREUR</td></tr>";
}
/***************************************************************************************
*
*
*/
if ($ok)
{
2004-01-27 15:36:40 +01:00
if($db->database_selected == 1)
{
2004-02-12 17:44:49 +01:00
dolibarr_syslog("Connexion r<>ussie <20> la base : $dolibarr_main_db_name");
}
else
{
$ok = 0 ;
}
}
/***************************************************************************************
*
*
*/
if ($ok)
{
$ok = 0;
2004-11-27 17:15:55 +01:00
if ($choix == 1)
{
$dir = "../../mysql/tables/";
}
else
{
$dir = "../../pgsql/tables/";
}
2004-02-12 17:44:49 +01:00
$handle=opendir($dir);
$table_exists = 0;
while (($file = readdir($handle))!==false)
{
2004-11-27 17:15:55 +01:00
if (substr($file, strlen($file) - 4) == '.sql' && substr($file,0,4) == 'llx_' && substr($file, - 8) <> '.key.sql')
2004-01-30 17:00:18 +01:00
{
2004-02-12 17:44:49 +01:00
$name = substr($file, 0, strlen($file) - 4);
//print "<tr><td>Cr<43>ation de la table $name</td>";
$buffer = '';
$fp = fopen($dir.$file,"r");
2004-02-12 17:44:49 +01:00
if ($fp)
2004-01-27 15:36:40 +01:00
{
2004-02-12 17:44:49 +01:00
while (!feof ($fp))
2004-01-27 15:36:40 +01:00
{
2004-11-27 17:15:55 +01:00
$buf = fgets($fp, 4096);
if (substr($buf, 0, 2) <> '--')
{
$buffer .= $buf;
}
2004-01-30 17:00:18 +01:00
}
2004-02-12 17:44:49 +01:00
fclose($fp);
}
2004-11-27 17:15:55 +01:00
if ($db->query($buffer))
2004-02-12 17:44:49 +01:00
{
//print "<td>OK requete ==== $buffer</td></tr>";
2004-02-12 17:44:49 +01:00
}
else
{
if ($db->errno() == 1050)
2004-01-30 17:00:18 +01:00
{
2004-02-12 17:44:49 +01:00
//print "<td>D<>j<EFBFBD> existante</td></tr>";
$table_exists = 1;
2004-01-30 17:00:18 +01:00
}
else
{
2004-02-12 17:44:49 +01:00
print "<tr><td>Cr<43>ation de la table $name</td>";
print "<td>ERREUR ".$db->errno()." ".$db->error()."</td></tr>";
2004-01-30 17:00:18 +01:00
$error++;
}
}
}
2004-11-27 17:15:55 +01:00
2004-02-12 17:44:49 +01:00
}
2004-11-27 17:15:55 +01:00
//droit sur les tables
2004-11-27 17:15:55 +01:00
if ($db->query($grant_query))
{
print "<tr><td>Grant User '$nom' </td><td>OK</td></tr>";
}
2004-02-12 17:44:49 +01:00
closedir($handle);
2004-11-27 17:15:55 +01:00
2004-02-12 17:44:49 +01:00
if ($error == 0)
{
print '<tr><td>Cr<43>ation des tables et cl<63>s primaires</td><td>OK</td></tr>';
2004-02-12 17:44:49 +01:00
$ok = 1;
}
}
2004-02-12 17:44:49 +01:00
/***************************************************************************************
*
* Chargement fichier data.sql
2004-02-12 17:44:49 +01:00
*
***************************************************************************************/
if ($ok == 1)
{
//
// Donn<6E>es
//
2004-11-27 17:15:55 +01:00
if ($choix==1)
{
$dir = "../../mysql/data/";
$file = "data.sql";
$fp = fopen($dir.$file,"r");
if ($fp)
2004-01-30 17:00:18 +01:00
{
2004-11-27 17:15:55 +01:00
while (!feof ($fp))
{
$buffer = fgets($fp, 4096);
if (strlen(trim(ereg_replace("--","",$buffer))))
{
if ($db->query($buffer))
{
2004-11-27 17:15:55 +01:00
$ok = 1;
}
2004-11-27 17:15:55 +01:00
else
{
if ($db->errno() == 1062)
{
// print "<tr><td>Insertion ligne : $buffer</td><td>
}
else
{
$ok = 0;
print "Erreur SQL ".$db->errno()." sur requete '$buffer': ".$db->error()."<br>";
}
}
}
}
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() == 1062)
{
// print "<tr><td>Insertion ligne : $buffer</td><td>D<>ja existante</td></tr>";
}
else
{
$ok = 0;
print "Erreur SQL ".$db->errno()." sur requete '$buffer': ".$db->error()."<br>";
}
}
//}//while
fclose($fp);
}
}//else
2004-02-12 17:44:49 +01:00
print "<tr><td>Chargement des donn<6E>es de base</td>";
if ($ok)
{
print "<td>OK</td></tr>";
2004-01-27 15:36:40 +01:00
}
2004-01-30 17:00:18 +01:00
else
{
print "<td>ERREUR</td></tr>";
2004-02-12 17:44:49 +01:00
$ok = 1 ;
2004-01-30 17:00:18 +01:00
}
2004-02-12 17:44:49 +01:00
}
2004-01-30 17:00:18 +01:00
2004-02-12 17:44:49 +01:00
/***************************************************************************************
*
* Les variables qui ecrase le chemin par defaut sont red<EFBFBD>finies
2004-02-12 17:44:49 +01:00
*
***************************************************************************************/
if ($ok == 1)
{
2004-11-27 17:15:55 +01:00
$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';";
2004-11-27 17:15:55 +01:00
$result = 0;
2004-02-12 17:44:49 +01:00
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'");
}
}
2004-01-27 15:36:40 +01:00
}
2004-02-12 17:44:49 +01:00
/***************************************************************************************
*
*
*
*
***************************************************************************************/
2004-01-27 15:36:40 +01:00
print '</table>';
$db->close();
}
2004-02-12 17:44:49 +01:00
pFooter(!$ok);
2004-01-27 15:36:40 +01:00
?>