Files
dolibarr/htdocs/install/etape5.php
Laurent Destailleur 6ee57fec28 Si on relance install, on peut créer un nouveau compte admin.
Si on est en mode crypté, le mot de passe est crypté pour ce nouveau compte.
2006-10-19 18:51:35 +00:00

221 lines
6.6 KiB
PHP
Raw Blame History

<?php
/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
* Copyright (C) 2004 Sebastien DiCintio <sdicintio@ressource-toi.org>
*
* 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$
*/
/**
\file htdocs/install/etape5.php
\brief Page de fin d'installation ou de migration
\version $Revision$
*/
include_once("./inc.php");
if (file_exists($conffile)) include_once($conffile);
if (! isset($dolibarr_main_db_prefix) || ! $dolibarr_main_db_prefix) $dolibarr_main_db_prefix='llx_';
define('MAIN_DB_PREFIX',$dolibarr_main_db_prefix);
require_once($dolibarr_main_document_root . "/lib/databases/".$dolibarr_main_db_type.".lib.php");
require_once($dolibarr_main_document_root . "/conf/conf.class.php");
$setuplang=isset($_POST["selectlang"])?$_POST["selectlang"]:(isset($_GET["selectlang"])?$_GET["selectlang"]:'auto');
$langs->setDefaultLang($setuplang);
$langs->load("admin");
$langs->load("install");
$success=0;
dolibarr_install_syslog("Entering etape5.php page");
if ($_POST["action"] == "set" || $_POST["action"] == "upgrade")
{
// If install, check pass and pass_verif used to create admin account
if ($_POST["action"] == "set")
{
if ($_POST["pass"] <> $_POST["pass_verif"])
{
Header("Location: etape4.php?error=1&selectlang=$setuplang");
exit;
}
if (strlen(trim($_POST["pass"])) == 0)
{
Header("Location: etape4.php?error=2&selectlang=$setuplang");
exit;
}
if (strlen(trim($_POST["login"])) == 0)
{
Header("Location: etape4.php?error=3&selectlang=$setuplang");
exit;
}
}
// If upgrade
if ($_POST["action"] == "upgrade")
{
}
pHeader($langs->trans("SetupEnd"),"etape5");
print '<table cellspacing="0" cellpadding="2" width="100%">';
$error=0;
$conf = new Conf();
$conf->db->type = $dolibarr_main_db_type;
$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($conf->db->type,$conf->db->host,$conf->db->user,$conf->db->pass,$conf->db->name);
$ok = 0;
// Active module user
$modName='modUser';
$file = $modName . ".class.php";
include_once("../includes/modules/$file");
$objMod = new $modName($db);
$objMod->init();
// If first install
if ($_POST["action"] == "set")
{
if ($db->connected == 1)
{
$conf->setValues($db);
$code=0;
// Recherche du code AD99 le plus <20>lev<65>.
$sql.= "select code from llx_user where code like 'AD%'";
$resql=$db->query($sql);
if ($resql)
{
$num = $db->num_rows($resql);
$i = 0;
while ($i < $num)
{
$obj = $db->fetch_object($resql);
$codefound=substr($obj->code,2);
if (is_numeric($codefound) && $codefound > $code) $code=$codefound;
//print "Found code=$code";
$i++;
}
}
$code++;
$code=sprintf("%02d",$code);
$sql = "INSERT INTO llx_user(datec,login,pass,admin,name,code) VALUES (now()";
$sql.= ",'".$_POST["login"]."'";
$sql.= ",'".($conf->global->DATABASE_PWD_ENCRYPTED?md5($_POST["pass"]):$_POST["pass"])."'";
$sql.= ",1,'Administrateur','AD".$code."')";
//print "sql=".$sql." ".mysql_errno($db->db);
$resql=$db->query($sql);
if ($resql)
{
print $langs->trans("AdminLoginCreatedSuccessfuly",$_POST["login"])."<br>";
$success = 1;
}
else
{
if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
{
print $langs->trans("AdminLoginAlreadyExists",$_POST["login"])."<br>";
$success = 1;
}
else
{
print $langs->trans("FailedToCreateAdminLogin")."<br>";
}
}
if ($success)
{
$db->query("DELETE FROM llx_const WHERE name='MAIN_NOT_INSTALLED'");
// Si install non Fran<61>ais, on configure pour fonctionner en mode internationnal
if ($langs->defaultlang != "fr_FR")
{
$db->query("UPDATE llx_const set value='eldy_backoffice.php' WHERE name='MAIN_MENU_BARRETOP';");
$db->query("UPDATE llx_const set value='eldy_backoffice.php' WHERE name='MAIN_MENU_BARRELEFT';");
$db->query("UPDATE llx_const set value='eldy_frontoffice.php' WHERE name='MAIN_MENUFRONT_BARRETOP';");
$db->query("UPDATE llx_const set value='eldy_frontoffice.php' WHERE name='MAIN_MENUFRONT_BARRELEFT';");
}
}
}
else
{
print $langs->trans("Error")."<br>";
}
}
$db->query("UPDATE llx_const set value='".$setuplang."' WHERE name='MAIN_LANG_DEFAULT';");
print '</table>';
$db->close();
}
print "<br>";
// If first install
if ($_POST["action"] == "set")
{
// Fin install
print $langs->trans("SystemIsInstalled")."<br>";
print '<div class="warning">'.$langs->trans("WarningRemoveInstallDir")."</div>";
print "<br>";
print $langs->trans("YouNeedToPersonalizeSetup")."<br><br>";
}
// If upgrade
if ($_POST["action"] == "upgrade")
{
// Fin install
print $langs->trans("SystemIsUpgraded")."<br>";
print '<div class="warning">'.$langs->trans("WarningRemoveInstallDir")."</div>";
print "<br>";
}
print '<a href="'.$dolibarr_main_url_root .'/admin/index.php?mainmenu=home&leftmenu=setup">';
print $langs->trans("GoToSetupArea");
print '</a>';
dolibarr_install_syslog("Dolibarr install/setup finished");
pFooter(1,$setuplang);
?>