2004-10-20 00:24:10 +02:00
|
|
|
|
<?php
|
2003-11-15 18:41:07 +01:00
|
|
|
|
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
2004-09-11 00:23:40 +02:00
|
|
|
|
* Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
|
|
|
|
|
|
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
|
2003-11-15 18:41:07 +01:00
|
|
|
|
*
|
|
|
|
|
|
* 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-08-15 15:46:45 +02:00
|
|
|
|
/*! \file htdocs/includes/modules/DolibarrModules.class.php
|
2004-10-20 00:24:10 +02:00
|
|
|
|
\brief Fichier de description et activation des modules Dolibarr
|
2004-08-15 14:40:18 +02:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*! \class DolibarrModules
|
2004-10-20 00:24:10 +02:00
|
|
|
|
\brief Classe m<EFBFBD>re des classes de description et activation des modules Dolibarr
|
2004-08-15 14:40:18 +02:00
|
|
|
|
*/
|
2003-11-15 18:41:07 +01:00
|
|
|
|
class DolibarrModules
|
|
|
|
|
|
{
|
2004-08-15 14:40:18 +02:00
|
|
|
|
var $db; // Handler d'acc<63>s aux base
|
|
|
|
|
|
var $boxes; // Tableau des boites
|
|
|
|
|
|
var $const; // Tableau des constantes
|
2003-11-15 18:41:07 +01:00
|
|
|
|
|
|
|
|
|
|
|
2004-08-15 14:40:18 +02:00
|
|
|
|
/*! \brief Constructeur
|
|
|
|
|
|
* \param DB handler d'acc<EFBFBD>s base
|
|
|
|
|
|
*/
|
2004-08-07 19:14:42 +02:00
|
|
|
|
function DolibarrModules($DB)
|
2003-11-15 18:41:07 +01:00
|
|
|
|
{
|
|
|
|
|
|
$this->db = $DB ;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-08-15 14:40:18 +02:00
|
|
|
|
|
|
|
|
|
|
/*! \brief Fonction d'activation. Ins<EFBFBD>re en base les constantes et boites du module
|
|
|
|
|
|
* \param array_sql tableau de requete sql a ex<EFBFBD>cuter <EFBFBD> l'activation
|
|
|
|
|
|
*/
|
2004-08-07 19:14:42 +02:00
|
|
|
|
function _init($array_sql)
|
2003-11-15 18:41:07 +01:00
|
|
|
|
{
|
2004-08-15 14:40:18 +02:00
|
|
|
|
// Ins<6E>re les constantes
|
2003-11-15 18:41:07 +01:00
|
|
|
|
$err = 0;
|
2004-09-11 00:23:40 +02:00
|
|
|
|
$sql_del = "DELETE FROM ".MAIN_DB_PREFIX."const WHERE name = '".$this->const_name."';";
|
2004-09-06 22:10:57 +02:00
|
|
|
|
$this->db->query($sql_del);
|
2004-09-11 00:23:40 +02:00
|
|
|
|
$sql ="INSERT INTO ".MAIN_DB_PREFIX."const (name,value,visible) VALUES
|
2004-09-06 22:10:57 +02:00
|
|
|
|
('".$this->const_name."','1',0);";
|
2003-11-15 18:41:07 +01:00
|
|
|
|
|
|
|
|
|
|
if (!$this->db->query($sql))
|
|
|
|
|
|
{
|
|
|
|
|
|
$err++;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-08-15 14:40:18 +02:00
|
|
|
|
// Ins<6E>re les boxes dans llx_boxes_def
|
2003-11-15 18:41:07 +01:00
|
|
|
|
foreach ($this->boxes as $key => $value)
|
|
|
|
|
|
{
|
|
|
|
|
|
$titre = $this->boxes[$key][0];
|
|
|
|
|
|
$file = $this->boxes[$key][1];
|
|
|
|
|
|
|
2004-02-01 02:19:35 +01:00
|
|
|
|
$sql = "SELECT count(*) FROM ".MAIN_DB_PREFIX."boxes_def WHERE name ='".$titre."'";
|
2003-11-15 18:41:07 +01:00
|
|
|
|
|
|
|
|
|
|
if ( $this->db->query($sql) )
|
|
|
|
|
|
{
|
|
|
|
|
|
$row = $this->db->fetch_row($sql);
|
|
|
|
|
|
if ($row[0] == 0)
|
|
|
|
|
|
{
|
2004-09-11 00:23:40 +02:00
|
|
|
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."boxes_def (name, file) VALUES ('".$titre."','".$file."')";
|
2003-11-15 18:41:07 +01:00
|
|
|
|
if (! $this->db->query($sql) )
|
|
|
|
|
|
{
|
|
|
|
|
|
$err++;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
$err++;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2004-11-22 10:56:35 +01:00
|
|
|
|
/*
|
|
|
|
|
|
* D<EFBFBD>finit les constantes associ<EFBFBD>es
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
2003-11-15 18:41:07 +01:00
|
|
|
|
|
|
|
|
|
|
foreach ($this->const as $key => $value)
|
|
|
|
|
|
{
|
2004-06-09 03:30:26 +02:00
|
|
|
|
$name = $this->const[$key][0];
|
|
|
|
|
|
$type = $this->const[$key][1];
|
|
|
|
|
|
$val = $this->const[$key][2];
|
|
|
|
|
|
$note = $this->const[$key][3];
|
|
|
|
|
|
$visible= $this->const[$key][4]||'0';
|
2003-11-15 18:41:07 +01:00
|
|
|
|
|
2004-02-01 02:19:35 +01:00
|
|
|
|
$sql = "SELECT count(*) FROM ".MAIN_DB_PREFIX."const WHERE name ='".$name."'";
|
2003-11-15 18:41:07 +01:00
|
|
|
|
|
|
|
|
|
|
if ( $this->db->query($sql) )
|
|
|
|
|
|
{
|
|
|
|
|
|
$row = $this->db->fetch_row($sql);
|
|
|
|
|
|
|
|
|
|
|
|
if ($row[0] == 0)
|
|
|
|
|
|
{
|
2004-09-06 22:10:57 +02:00
|
|
|
|
// Si non trouve // '$visible'
|
2004-06-09 03:30:26 +02:00
|
|
|
|
if (strlen($note)){
|
2004-09-06 22:10:57 +02:00
|
|
|
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."const (name,type,value,note,visible) VALUES ('$name','$type','$val','$note',0);";
|
2004-06-09 03:30:26 +02:00
|
|
|
|
}elseif (strlen($val))
|
|
|
|
|
|
{
|
2004-09-06 22:10:57 +02:00
|
|
|
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."const (name,type,value,visible) VALUES ('$name','$type','$val',0);";
|
2004-06-09 03:30:26 +02:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2004-09-06 22:10:57 +02:00
|
|
|
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."const (name,type,visible) VALUES ('$name','$type',0);";
|
2004-06-09 03:30:26 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (! $this->db->query($sql) )
|
|
|
|
|
|
{
|
|
|
|
|
|
$err++;
|
|
|
|
|
|
}
|
2003-11-15 18:41:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
$err++;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2004-11-24 10:27:58 +01:00
|
|
|
|
/*
|
|
|
|
|
|
* D<EFBFBD>finit les permissions associ<EFBFBD>es au module activ<EFBFBD>
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
|
|
|
|
|
if (is_array($this->rights))
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach ($this->rights as $key => $value)
|
|
|
|
|
|
{
|
|
|
|
|
|
$r_id = $this->rights[$key][0];
|
|
|
|
|
|
$r_desc = $this->rights[$key][1];
|
|
|
|
|
|
$r_type = $this->rights[$key][2];
|
|
|
|
|
|
$r_def = $this->rights[$key][3];
|
|
|
|
|
|
$r_modul = $this->rights_class;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."rights_def ";
|
|
|
|
|
|
$sql .= " (id, libelle, module, type, bydefault)";
|
|
|
|
|
|
$sql .= " VALUES ";
|
|
|
|
|
|
$sql .= "(".$r_id.",'".$r_desc."','".$r_modul."','".$r_type."',".$r_def.");";
|
|
|
|
|
|
|
|
|
|
|
|
if ( $this->db->query($sql) )
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2003-11-15 18:41:07 +01:00
|
|
|
|
|
2004-11-22 10:56:35 +01:00
|
|
|
|
/*
|
|
|
|
|
|
* Cr<EFBFBD><EFBFBD> les r<EFBFBD>pertoires
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
|
|
|
|
|
if (is_array($this->dirs))
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach ($this->dirs as $key => $value)
|
|
|
|
|
|
{
|
|
|
|
|
|
$dir = $value;
|
|
|
|
|
|
|
|
|
|
|
|
if (! file_exists($dir))
|
|
|
|
|
|
{
|
|
|
|
|
|
umask(0);
|
|
|
|
|
|
if (! @mkdir($dir, 0755))
|
|
|
|
|
|
{
|
|
|
|
|
|
$this->error = "Erreur: Le r<>pertoire '$dir' n'existe pas et Dolibarr n'a pu le cr<63>er.";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2003-11-15 18:41:07 +01:00
|
|
|
|
/*
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
for ($i = 0 ; $i < sizeof($array_sql) ; $i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (! $this->db->query($array_sql[$i]))
|
|
|
|
|
|
{
|
|
|
|
|
|
$err++;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ($err > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2004-08-15 14:40:18 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*! \brief Fonction de d<EFBFBD>sactivation. Supprime de la base les constantes et boites du module
|
|
|
|
|
|
* \param array_sql tableau de requete sql a ex<EFBFBD>cuter <EFBFBD> la d<EFBFBD>sactivation
|
|
|
|
|
|
*/
|
2004-08-07 19:14:42 +02:00
|
|
|
|
function _remove($array_sql)
|
2003-11-15 18:41:07 +01:00
|
|
|
|
{
|
|
|
|
|
|
$err = 0;
|
|
|
|
|
|
|
2004-02-01 02:19:35 +01:00
|
|
|
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."const WHERE name = '".$this->const_name."'";
|
2003-11-15 18:41:07 +01:00
|
|
|
|
|
|
|
|
|
|
if (!$this->db->query($sql))
|
|
|
|
|
|
{
|
|
|
|
|
|
$err++;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for ($i = 0 ; $i < sizeof($array_sql) ; $i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
if (!$this->db->query($array_sql[$i]))
|
|
|
|
|
|
{
|
|
|
|
|
|
$err++;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* Boites
|
|
|
|
|
|
*/
|
|
|
|
|
|
foreach ($this->boxes as $key => $value)
|
|
|
|
|
|
{
|
|
|
|
|
|
$titre = $this->boxes[$key][0];
|
|
|
|
|
|
$file = $this->boxes[$key][1];
|
|
|
|
|
|
|
2004-02-01 02:19:35 +01:00
|
|
|
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."boxes_def WHERE file = '".$file."'";
|
2003-11-15 18:41:07 +01:00
|
|
|
|
if (! $this->db->query($sql) )
|
|
|
|
|
|
{
|
|
|
|
|
|
$err++;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ($err > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
?>
|