2004-10-20 00:24:10 +02:00
< ? php
2007-04-10 14:08:44 +02:00
/* Copyright ( C ) 2003 - 2007 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
* Copyright ( C ) 2004 Sebastien Di Cintio < sdicintio @ ressource - toi . org >
* Copyright ( C ) 2004 Benoit Mortier < benoit . mortier @ opensides . be >
* Copyright ( C ) 2004 Eric Seigne < eric . seigne @ ryxeo . com >
2009-01-20 00:32:18 +01:00
* Copyright ( C ) 2005 - 2009 Laurent Destailleur < eldy @ users . sourceforge . net >
2009-04-17 09:45:00 +02:00
* Copyright ( C ) 2005 - 2009 Regis Houssin < regis @ dolibarr . fr >
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 .
*/
2005-04-09 17:52:07 +02:00
/**
2008-12-07 20:19:32 +01:00
* \file htdocs / includes / modules / DolibarrModules . class . php
* \brief Fichier de description et activation des modules Dolibarr
* \version $Id $
2008-10-06 09:39:52 +02:00
*/
2004-08-15 14:40:18 +02:00
2005-04-09 17:52:07 +02:00
/**
2008-12-07 20:19:32 +01:00
* \class DolibarrModules
* \brief Classe mere des classes de description et activation des modules Dolibarr
2008-10-06 09:39:52 +02:00
*/
2003-11-15 18:41:07 +01:00
class DolibarrModules
{
2008-10-06 09:39:52 +02:00
//! Database handler
var $db ;
//! Relative path to module style sheet
var $style_sheet = '' ;
//! Path to create when module activated
var $dirs = array ();
//! Tableau des boites
var $boxes ;
//! Tableau des constantes
var $const ;
//! Tableau des droits
var $rights ;
//! Tableau des menus
var $menu = array ();
//! Tableau des documents ???
var $docs ;
var $dbversion ;
/**
* \brief Constructeur
* \param DB handler d ' acces base
*/
function DolibarrModules ( $DB )
{
$this -> db = $DB ;
$this -> dbversion = " - " ;
}
2007-04-10 14:08:44 +02:00
2008-01-30 01:15:59 +01:00
/**
* \brief Fonction d ' activation . Insere en base les constantes et boites du module
* \param array_sql Tableau de requete sql a executer a l ' activation
2009-03-20 15:33:56 +01:00
* \param options Options when enabling module
* \return int 1 if OK , 0 if KO
2008-01-30 01:15:59 +01:00
*/
2009-03-20 15:33:56 +01:00
function _init ( $array_sql , $options = '' )
2008-01-30 01:15:59 +01:00
{
global $langs ;
$err = 0 ;
2008-10-06 09:39:52 +02:00
2008-01-30 01:15:59 +01:00
$this -> db -> begin ();
2008-10-06 09:39:52 +02:00
// Insert line in module table
2008-01-30 01:15:59 +01:00
if ( ! $err ) $err += $this -> _dbactive ();
2008-10-06 09:39:52 +02:00
// Insert activation module constant
2008-01-30 01:15:59 +01:00
if ( ! $err ) $err += $this -> _active ();
2008-10-06 09:39:52 +02:00
2008-03-31 00:25:39 +02:00
// Insere le nom de la feuille de style
if ( ! $err ) $err += $this -> insert_style_sheet ();
2008-12-07 20:19:32 +01:00
// Insert new pages for tabs into llx_const
if ( ! $err ) $err += $this -> insert_tabs ();
2008-01-30 01:15:59 +01:00
// Insere les constantes associees au module dans llx_const
if ( ! $err ) $err += $this -> insert_const ();
2008-10-06 09:39:52 +02:00
2008-01-30 01:15:59 +01:00
// Insere les boites dans llx_boxes_def
2009-03-20 15:33:56 +01:00
if ( ! $err && $options != 'noboxes' ) $err += $this -> insert_boxes ();
2008-10-06 09:39:52 +02:00
2008-01-30 01:15:59 +01:00
// Insere les permissions associees au module actif dans llx_rights_def
if ( ! $err ) $err += $this -> insert_permissions ();
2008-10-06 09:39:52 +02:00
2008-01-30 01:15:59 +01:00
// Insere les constantes associees au module dans llx_const
if ( ! $err ) $err += $this -> insert_menus ();
2009-04-29 22:17:31 +02:00
2009-04-29 22:37:20 +02:00
// Create module's directories
if ( ! $err ) $err += $this -> create_dirs ();
2008-10-06 09:39:52 +02:00
2008-01-30 01:15:59 +01:00
// Execute les requetes sql complementaires
2009-07-06 09:15:02 +02:00
if ( ! $err )
2008-01-30 01:15:59 +01:00
{
2009-07-06 09:15:02 +02:00
for ( $i = 0 ; $i < sizeof ( $array_sql ) ; $i ++ )
2008-01-30 01:15:59 +01:00
{
2009-07-06 09:15:02 +02:00
if ( ! $err )
2008-01-30 01:15:59 +01:00
{
2009-07-06 09:15:02 +02:00
$sql = $array_sql [ $i ];
dol_syslog ( " DolibarrModules::_init sql= " . $sql , LOG_DEBUG );
$result = $this -> db -> query ( $sql );
if ( ! $result )
{
$this -> error = $this -> db -> error ();
dol_syslog ( " DolibarrModules::_init Error " . $this -> error , LOG_ERR );
$err ++ ;
}
2008-01-30 01:15:59 +01:00
}
}
}
2008-10-06 09:39:52 +02:00
2009-03-20 15:33:56 +01:00
// Return code
2008-01-30 01:15:59 +01:00
if ( ! $err )
{
$this -> db -> commit ();
return 1 ;
}
else
{
$this -> db -> rollback ();
return 0 ;
}
}
2008-10-06 09:39:52 +02:00
/**
* \brief Fonction de desactivation . Supprime de la base les constantes et boites du module
* \param array_sql tableau de requete sql a executer a la desactivation
2009-03-20 15:33:56 +01:00
* \param options Options when disabling module
2008-10-06 09:39:52 +02:00
* \return int 1 if OK , 0 if KO
*/
2009-03-20 15:33:56 +01:00
function _remove ( $array_sql , $options = '' )
2008-10-06 09:39:52 +02:00
{
2009-03-20 15:33:56 +01:00
global $langs ;
$err = 0 ;
2008-10-06 09:39:52 +02:00
2009-03-20 15:33:56 +01:00
$this -> db -> begin ();
2009-04-16 20:46:26 +02:00
2008-10-06 09:39:52 +02:00
// Remove line in activation module
2009-03-20 15:33:56 +01:00
if ( ! $err ) $err += $this -> _dbunactive ();
2008-10-06 09:39:52 +02:00
// Remove activation module line
2009-03-20 15:33:56 +01:00
if ( ! $err ) $err += $this -> _unactive ();
2008-10-06 09:39:52 +02:00
2009-03-20 15:33:56 +01:00
// Remove activation of module's style sheet
if ( ! $err ) $err += $this -> delete_style_sheet ();
2008-10-06 09:39:52 +02:00
2009-03-20 15:33:56 +01:00
// Remove activation of module's new tabs
if ( ! $err ) $err += $this -> delete_tabs ();
2009-01-20 00:32:18 +01:00
2009-03-20 15:33:56 +01:00
// Remove list of module's available boxes
if ( ! $err && $options != 'noboxes' ) $err += $this -> delete_boxes ();
2008-10-06 09:39:52 +02:00
2009-03-20 15:33:56 +01:00
// Remove module's permissions from list of available permissions
if ( ! $err ) $err += $this -> delete_permissions ();
2008-10-06 09:39:52 +02:00
2009-04-28 15:04:35 +02:00
// Remove module's menus
2009-03-20 15:33:56 +01:00
if ( ! $err ) $err += $this -> delete_menus ();
2009-04-29 23:39:31 +02:00
2009-04-29 23:29:26 +02:00
// Remove module's directories
if ( ! $err ) $err += $this -> delete_dirs ();
2009-04-29 22:17:31 +02:00
2009-03-20 15:33:56 +01:00
// Run complementary sql requests
2008-10-06 09:39:52 +02:00
for ( $i = 0 ; $i < sizeof ( $array_sql ) ; $i ++ )
{
2009-04-16 20:46:26 +02:00
if ( ! $err )
2009-03-20 15:33:56 +01:00
{
2009-06-16 23:11:25 +02:00
dol_syslog ( " DolibarrModules::_remove sql= " . $array_sql [ $i ], LOG_DEBUG );
$result = $this -> db -> query ( $array_sql [ $i ]);
if ( ! $result )
2009-04-29 23:39:31 +02:00
{
2009-06-16 23:11:25 +02:00
$this -> error = $this -> db -> error ();
dol_syslog ( " DolibarrModules::_remove Error " . $this -> error , LOG_ERR );
2009-04-29 23:39:31 +02:00
$err ++ ;
}
2009-03-20 15:33:56 +01:00
}
2008-10-06 09:39:52 +02:00
}
2009-03-20 15:33:56 +01:00
// Return code
if ( ! $err )
{
$this -> db -> commit ();
return 1 ;
}
else
{
$this -> db -> rollback ();
return 0 ;
}
2008-10-06 09:39:52 +02:00
}
2007-04-10 14:08:44 +02:00
2008-02-19 22:04:23 +01:00
/**
2008-12-07 21:10:59 +01:00
* \brief Retourne le nom traduit du module si la traduction existe dans admin . lang ,
* sinon le nom defini par defaut dans le module .
* \return string Nom du module traduit
*/
2008-02-19 22:04:23 +01:00
function getName ()
{
global $langs ;
$langs -> load ( " admin " );
2008-10-06 09:39:52 +02:00
2008-02-19 22:04:23 +01:00
if ( $langs -> trans ( " Module " . $this -> numero . " Name " ) != ( " Module " . $this -> numero . " Name " ))
{
// Si traduction du nom du module existe
return $langs -> trans ( " Module " . $this -> numero . " Name " );
}
else
{
2008-10-01 21:10:17 +02:00
// If translation of module with its numero does not exists, we take its name
2008-02-19 22:04:23 +01:00
return $this -> name ;
}
}
2008-10-06 09:39:52 +02:00
2008-02-19 22:04:23 +01:00
/**
2008-12-07 21:10:59 +01:00
* \brief Retourne la description traduite du module si la traduction existe dans admin . lang ,
* sinon la description definie par defaut dans le module .
* \return string Nom du module traduit
*/
2008-02-19 22:04:23 +01:00
function getDesc ()
{
global $langs ;
$langs -> load ( " admin " );
2008-10-06 09:39:52 +02:00
2008-02-19 22:04:23 +01:00
if ( $langs -> trans ( " Module " . $this -> numero . " Desc " ) != ( " Module " . $this -> numero . " Desc " ))
{
// Si traduction de la description du module existe
return $langs -> trans ( " Module " . $this -> numero . " Desc " );
}
else
{
// Si traduction de la description du module n'existe pas, on prend definition en dur dans module
return $this -> description ;
}
}
2008-10-06 09:39:52 +02:00
2008-02-19 22:04:23 +01:00
/**
2008-12-07 21:10:59 +01:00
* \brief Retourne la version du module .
* Pour les modules a l 'etat ' experimental ', retourne la traduction de ' experimental '
* Pour les modules 'dolibarr' , retourne la version de Dolibarr
* Pour les autres modules , retourne la version du module
* \return string Version du module
*/
2008-02-19 22:04:23 +01:00
function getVersion ()
{
global $langs ;
$langs -> load ( " admin " );
2008-10-06 09:39:52 +02:00
2008-02-19 22:04:23 +01:00
if ( $this -> version == 'experimental' ) return $langs -> trans ( " VersionExperimental " );
elseif ( $this -> version == 'development' ) return $langs -> trans ( " VersionDevelopment " );
elseif ( $this -> version == 'dolibarr' ) return DOL_VERSION ;
elseif ( $this -> version ) return $this -> version ;
else return $langs -> trans ( " VersionUnknown " );
}
2008-10-06 09:39:52 +02:00
/**
2008-12-07 21:10:59 +01:00
* \brief Retourne la liste des fichiers lang en rapport avec le module
* \return array Tableau des fichier lang
2008-10-06 09:39:52 +02:00
*/
function getLangFilesArray ()
{
return $this -> langfiles ;
}
/**
2008-12-07 21:10:59 +01:00
* \brief Retourne le libelle d ' un lot de donnees exportable
* \return string Libelle du lot de donnees
2008-10-06 09:39:52 +02:00
*/
function getDatasetLabel ( $r )
{
global $langs ;
$langstring = " ExportDataset_ " . $this -> export_code [ $r ];
if ( $langs -> trans ( $langstring ) == $langstring )
{
// Traduction non trouvee
return $langs -> trans ( $this -> export_label [ $r ]);
}
else
{
// Traduction trouvee
return $langs -> trans ( $langstring );
}
}
/**
2009-03-20 15:33:56 +01:00
* \brief Insert line in dolibarr_modules table .
* \return int Nb of errors ( 0 if OK )
2009-04-16 20:46:26 +02:00
* \remarks Storage is made for information only , table is not required for Dolibarr usage .
2008-10-06 09:39:52 +02:00
*/
function _dbactive ()
{
2009-05-04 12:27:01 +02:00
global $conf ;
2009-05-08 03:11:04 +02:00
2008-10-06 09:39:52 +02:00
$err = 0 ;
2009-05-04 12:27:01 +02:00
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " dolibarr_modules " ;
$sql .= " WHERE numero = " . $this -> numero ;
$sql .= " AND entity = " . $conf -> entity ;
2009-05-08 03:11:04 +02:00
2009-02-20 23:53:15 +01:00
dol_syslog ( " DolibarrModules::_dbactive sql= " . $sql , LOG_DEBUG );
2009-01-20 00:32:18 +01:00
$this -> db -> query ( $sql );
2008-10-06 09:39:52 +02:00
2009-05-04 12:27:01 +02:00
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " dolibarr_modules ( " ;
$sql .= " numero " ;
$sql .= " , entity " ;
$sql .= " , active " ;
$sql .= " , active_date " ;
$sql .= " , active_version " ;
$sql .= " ) " ;
2009-01-20 00:32:18 +01:00
$sql .= " VALUES ( " ;
2009-05-04 12:27:01 +02:00
$sql .= $this -> numero ;
$sql .= " , " . $conf -> entity ;
$sql .= " , 1 " ;
2009-10-28 18:37:40 +01:00
$sql .= " , ' " . $this -> db -> idate ( gmmktime ()) . " ' " ;
2009-05-04 12:27:01 +02:00
$sql .= " , ' " . $this -> version . " ' " ;
$sql .= " ) " ;
2009-05-08 03:11:04 +02:00
2009-02-20 23:53:15 +01:00
dol_syslog ( " DolibarrModules::_dbactive sql= " . $sql , LOG_DEBUG );
2008-10-06 09:39:52 +02:00
$this -> db -> query ( $sql );
return $err ;
}
/**
2009-03-20 15:33:56 +01:00
* \brief Remove line in dolibarr_modules table
2008-10-06 09:39:52 +02:00
* \return int Nb of errors ( 0 if OK )
2009-04-16 20:46:26 +02:00
* \remarks Storage is made for information only , table is not required for Dolibarr usage .
2008-10-06 09:39:52 +02:00
*/
function _dbunactive ()
{
2009-05-04 12:27:01 +02:00
global $conf ;
2009-05-08 03:11:04 +02:00
2008-10-06 09:39:52 +02:00
$err = 0 ;
2009-05-04 12:27:01 +02:00
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " dolibarr_modules " ;
$sql .= " WHERE numero = " . $this -> numero ;
2009-07-08 15:51:17 +02:00
$sql .= " AND entity in (0, " . $conf -> entity . " ) " ;
2009-05-08 03:11:04 +02:00
2009-03-20 15:33:56 +01:00
dol_syslog ( " DolibarrModules::_dbunactive sql= " . $sql , LOG_DEBUG );
2009-01-20 00:32:18 +01:00
$this -> db -> query ( $sql );
2008-10-06 09:39:52 +02:00
return $err ;
}
/**
* \brief Insert constant to activate module
* \return int Nb of errors ( 0 if OK )
*/
function _active ()
{
2009-04-15 22:51:50 +02:00
global $conf ;
2008-10-06 09:39:52 +02:00
$err = 0 ;
2009-05-08 03:11:04 +02:00
2009-05-04 14:43:18 +02:00
// Common module
2009-07-08 15:51:17 +02:00
$entity = (( ! empty ( $this -> always_enabled ) || ! empty ( $this -> core_enabled )) ? 0 : $conf -> entity );
2009-04-16 20:46:26 +02:00
2009-04-20 17:39:36 +02:00
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " const " ;
2009-06-27 08:56:41 +02:00
$sql .= " WHERE " . $this -> db -> decrypt ( 'name' , $conf -> db -> dolibarr_main_db_encryption , $conf -> db -> dolibarr_main_db_cryptkey ) . " = ' " . $this -> const_name . " ' " ;
2009-07-08 15:51:17 +02:00
$sql .= " AND entity in (0, " . $entity . " ) " ;
2009-05-08 03:11:04 +02:00
2009-02-20 23:53:15 +01:00
dol_syslog ( " DolibarrModules::_active sql= " . $sql , LOG_DEBUG );
2009-01-20 00:32:18 +01:00
$this -> db -> query ( $sql );
2008-10-06 09:39:52 +02:00
2009-04-15 22:09:43 +02:00
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " const (name,value,visible,entity) VALUES " ;
2009-09-07 21:33:21 +02:00
$sql .= " ( " . $this -> db -> encrypt ( $this -> const_name , $conf -> db -> dolibarr_main_db_encryption , $conf -> db -> dolibarr_main_db_cryptkey , 1 );
$sql .= " , " . $this -> db -> encrypt ( '1' , $conf -> db -> dolibarr_main_db_encryption , $conf -> db -> dolibarr_main_db_cryptkey , 1 );
2009-06-28 01:28:25 +02:00
$sql .= " ,0, " . $entity . " ) " ;
2009-05-08 03:11:04 +02:00
2009-02-20 23:53:15 +01:00
dol_syslog ( " DolibarrModules::_active sql= " . $sql , LOG_DEBUG );
2008-10-06 09:39:52 +02:00
if ( ! $this -> db -> query ( $sql ))
{
$err ++ ;
}
return $err ;
}
/**
* \brief Remove activation line
* \return int Nb of errors ( 0 if OK )
**/
function _unactive ()
{
2009-04-15 22:51:50 +02:00
global $conf ;
2009-04-16 20:46:26 +02:00
2008-10-06 09:39:52 +02:00
$err = 0 ;
2009-05-08 03:11:04 +02:00
2009-05-04 15:13:01 +02:00
// Common module
2009-07-08 15:51:17 +02:00
$entity = (( ! empty ( $this -> always_enabled ) || ! empty ( $this -> core_enabled )) ? 0 : $conf -> entity );
2009-04-16 20:46:26 +02:00
2009-04-20 17:39:36 +02:00
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " const " ;
2009-06-27 08:56:41 +02:00
$sql .= " WHERE " . $this -> db -> decrypt ( 'name' , $conf -> db -> dolibarr_main_db_encryption , $conf -> db -> dolibarr_main_db_cryptkey ) . " = ' " . $this -> const_name . " ' " ;
2009-07-08 15:51:17 +02:00
$sql .= " AND entity in (0, " . $entity . " ) " ;
2009-05-08 03:11:04 +02:00
2009-02-20 23:53:15 +01:00
dol_syslog ( " DolibarrModules::_unactive sql= " . $sql );
2009-01-20 00:32:18 +01:00
$this -> db -> query ( $sql );
2008-10-06 09:39:52 +02:00
return $err ;
}
/**
2008-12-07 21:10:59 +01:00
* \brief Create tables and keys required by module
* Files module . sql and module . key . sql with create table and create keys
* commands must be stored in directory reldir = '/module/sql/'
* This function is called by this -> init .
* \return int <= 0 if KO , > 0 if OK
*/
function _load_tables ( $reldir )
{
global $db , $conf ;
include_once ( DOL_DOCUMENT_ROOT . " /lib/admin.lib.php " );
2009-01-20 00:32:18 +01:00
2008-12-07 21:10:59 +01:00
$ok = 1 ;
2009-05-08 03:11:04 +02:00
foreach ( $conf -> file -> dol_document_root as $dirroot )
2008-12-07 21:10:59 +01:00
{
if ( $ok )
{
$dir = $dirroot . $reldir ;
$ok = 0 ;
2009-01-20 00:32:18 +01:00
2008-12-07 21:10:59 +01:00
// Run llx_mytable.sql files
2009-02-12 00:46:49 +01:00
$handle =@ opendir ( $dir ); // Dir may not exists
2008-12-07 21:10:59 +01:00
if ( $handle )
{
while (( $file = readdir ( $handle )) !== false )
{
2009-10-22 17:09:04 +02:00
if ( preg_match ( '/\.sql$/i' , $file ) && ! preg_match ( '/\.key\.sql$/i' , $file ) && substr ( $file , 0 , 4 ) == 'llx_' && substr ( $file , 0 , 4 ) != 'data' )
2008-12-07 21:10:59 +01:00
{
$result = run_sql ( $dir . $file , 1 );
}
}
closedir ( $handle );
}
2009-01-20 00:32:18 +01:00
2008-12-07 21:10:59 +01:00
// Run llx_mytable.key.sql files
2009-02-12 00:46:49 +01:00
$handle =@ opendir ( $dir ); // Dir may not exist
2008-12-07 21:10:59 +01:00
if ( $handle )
{
while (( $file = readdir ( $handle )) !== false )
{
2009-10-22 17:09:04 +02:00
if ( preg_match ( '/\.key\.sql$/i' , $file ) && substr ( $file , 0 , 4 ) == 'llx_' && substr ( $file , 0 , 4 ) != 'data' )
2009-06-04 01:05:52 +02:00
{
$result = run_sql ( $dir . $file , 1 );
}
}
closedir ( $handle );
}
2009-10-07 20:17:55 +02:00
// Run .sql files
2009-06-04 01:05:52 +02:00
$handle =@ opendir ( $dir ); // Dir may not exist
if ( $handle )
{
while (( $file = readdir ( $handle )) !== false )
{
2009-10-22 17:09:04 +02:00
if ( preg_match ( '/\.sql$/i' , $file ) && ! preg_match ( '/\.key\.sql$/i' , $file ) && substr ( $file , 0 , 4 ) == 'data' )
2008-12-07 21:10:59 +01:00
{
$result = run_sql ( $dir . $file , 1 );
}
}
closedir ( $handle );
}
2009-01-20 00:32:18 +01:00
2008-12-07 21:10:59 +01:00
if ( $error == 0 )
{
$ok = 1 ;
}
}
}
return $ok ;
}
2009-01-20 00:32:18 +01:00
2008-12-07 21:10:59 +01:00
/**
* \brief Insere les boites associees au module dans llx_boxes_def
* \return int Nombre d ' erreurs ( 0 si ok )
2008-10-06 09:39:52 +02:00
*/
function insert_boxes ()
{
2009-04-27 22:37:50 +02:00
global $conf ;
2009-04-29 22:17:31 +02:00
2008-10-06 09:39:52 +02:00
$err = 0 ;
if ( is_array ( $this -> boxes ))
{
foreach ( $this -> boxes as $key => $value )
{
//$titre = $this->boxes[$key][0];
$file = isset ( $this -> boxes [ $key ][ 1 ]) ? $this -> boxes [ $key ][ 1 ] : '' ;
$note = isset ( $this -> boxes [ $key ][ 2 ]) ? $this -> boxes [ $key ][ 2 ] : '' ;
$sql = " SELECT count(*) FROM " . MAIN_DB_PREFIX . " boxes_def " ;
2009-04-27 22:37:50 +02:00
$sql .= " WHERE file = ' " . $file . " ' " ;
$sql .= " AND entity = " . $conf -> entity ;
2009-05-08 03:11:04 +02:00
2008-10-06 09:39:52 +02:00
if ( $note ) $sql .= " AND note =' " . addslashes ( $note ) . " ' " ;
$result = $this -> db -> query ( $sql );
if ( $result )
{
$row = $this -> db -> fetch_row ( $result );
if ( $row [ 0 ] == 0 )
{
2009-04-27 22:37:50 +02:00
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " boxes_def (file,entity,note) " ;
2008-10-06 09:39:52 +02:00
$sql .= " VALUES (' " . addslashes ( $file ) . " ', " ;
2009-04-27 22:37:50 +02:00
$sql .= $conf -> entity . " , " ;
2008-10-06 09:39:52 +02:00
$sql .= $note ? " ' " . addslashes ( $note ) . " ' " : " null " ;
$sql .= " ) " ;
2009-05-08 03:11:04 +02:00
2009-03-20 15:33:56 +01:00
dol_syslog ( " DolibarrModules::insert_boxes sql= " . $sql );
2008-10-06 09:39:52 +02:00
if ( ! $this -> db -> query ( $sql ))
{
$err ++ ;
}
}
}
else
{
2009-07-06 09:15:02 +02:00
$this -> error = $this -> db -> lasterror ();
dol_syslog ( " DolibarrModules::insert_boxes " . $this -> error , LOG_ERR );
2008-10-06 09:39:52 +02:00
$err ++ ;
}
}
}
return $err ;
}
2008-03-31 00:25:39 +02:00
/**
2008-12-07 21:10:59 +01:00
* \brief Supprime les boites
* \return int Nombre d ' erreurs ( 0 si ok )
*/
2008-03-31 00:25:39 +02:00
function delete_boxes ()
{
2009-04-27 22:37:50 +02:00
global $conf ;
2009-04-29 22:17:31 +02:00
2008-03-31 00:25:39 +02:00
$err = 0 ;
2008-10-06 09:39:52 +02:00
2008-03-31 00:25:39 +02:00
if ( is_array ( $this -> boxes ))
{
foreach ( $this -> boxes as $key => $value )
{
//$titre = $this->boxes[$key][0];
$file = $this -> boxes [ $key ][ 1 ];
//$note = $this->boxes[$key][2];
2008-10-06 09:39:52 +02:00
2008-03-31 00:25:39 +02:00
$sql = " DELETE " . MAIN_DB_PREFIX . " boxes " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " boxes, " . MAIN_DB_PREFIX . " boxes_def " ;
$sql .= " WHERE " . MAIN_DB_PREFIX . " boxes.box_id = " . MAIN_DB_PREFIX . " boxes_def.rowid " ;
$sql .= " AND " . MAIN_DB_PREFIX . " boxes_def.file = ' " . addslashes ( $file ) . " ' " ;
2009-04-27 22:37:50 +02:00
$sql .= " AND " . MAIN_DB_PREFIX . " boxes_def.entity = " . $conf -> entity ;
2009-05-08 03:11:04 +02:00
2009-02-20 23:53:15 +01:00
dol_syslog ( " DolibarrModules::delete_boxes sql= " . $sql );
2008-03-31 00:25:39 +02:00
$this -> db -> query ( $sql );
2008-10-06 09:39:52 +02:00
2008-03-31 00:25:39 +02:00
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " boxes_def " ;
$sql .= " WHERE file = ' " . addslashes ( $file ) . " ' " ;
2009-04-27 22:37:50 +02:00
$sql .= " AND entity = " . $conf -> entity ;
2009-05-08 03:11:04 +02:00
2009-02-20 23:53:15 +01:00
dol_syslog ( " DolibarrModules::delete_boxes sql= " . $sql );
2008-03-31 00:25:39 +02:00
if ( ! $this -> db -> query ( $sql ))
{
2009-05-04 13:06:49 +02:00
$this -> error = $this -> db -> lasterror ();
dol_syslog ( " DolibarrModules::delete_boxes " . $this -> error , LOG_ERR );
2008-03-31 00:25:39 +02:00
$err ++ ;
}
}
}
2008-10-06 09:39:52 +02:00
2008-03-31 00:25:39 +02:00
return $err ;
}
2008-10-06 09:39:52 +02:00
2008-03-31 00:25:39 +02:00
/**
2008-12-07 20:19:32 +01:00
* \brief Desactive feuille de style du module par suppression ligne dans llx_const
* \return int Nombre d ' erreurs ( 0 si ok )
*/
2008-03-31 00:25:39 +02:00
function delete_style_sheet ()
{
2009-04-27 22:37:50 +02:00
global $conf ;
2009-04-29 22:17:31 +02:00
2008-03-31 00:25:39 +02:00
$err = 0 ;
2008-10-06 09:39:52 +02:00
2008-03-31 00:25:39 +02:00
if ( $this -> style_sheet )
{
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " const " ;
2009-06-27 08:56:41 +02:00
$sql .= " WHERE " . $this -> db -> decrypt ( 'name' , $conf -> db -> dolibarr_main_db_encryption , $conf -> db -> dolibarr_main_db_cryptkey ) . " = ' " . $this -> const_name . " _CSS' " ;
2009-04-27 22:37:50 +02:00
$sql .= " AND entity = " . $conf -> entity ;
2009-05-08 03:11:04 +02:00
2009-02-20 23:53:15 +01:00
dol_syslog ( " DolibarrModules::delete_style_sheet sql= " . $sql );
2008-03-31 00:25:39 +02:00
if ( ! $this -> db -> query ( $sql ))
{
2009-05-04 13:06:49 +02:00
$this -> error = $this -> db -> lasterror ();
dol_syslog ( " DolibarrModules::delete_style_sheet " . $this -> error , LOG_ERR );
2008-03-31 00:25:39 +02:00
$err ++ ;
}
}
2008-10-06 09:39:52 +02:00
2008-03-31 00:25:39 +02:00
return $err ;
}
2008-10-06 09:39:52 +02:00
/**
2008-12-07 20:19:32 +01:00
* \brief Remove links to new module page present in llx_const
* \return int Nombre d ' erreurs ( 0 si ok )
*/
function delete_tabs ()
{
2009-04-27 22:37:50 +02:00
global $conf ;
2009-04-29 22:17:31 +02:00
2008-12-07 20:19:32 +01:00
$err = 0 ;
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " const " ;
2009-06-27 08:56:41 +02:00
$sql .= " WHERE " . $this -> db -> decrypt ( 'name' , $conf -> db -> dolibarr_main_db_encryption , $conf -> db -> dolibarr_main_db_cryptkey ) . " like ' " . $this -> const_name . " _TABS_%' " ;
2009-04-27 22:37:50 +02:00
$sql .= " AND entity = " . $conf -> entity ;
2009-05-08 03:11:04 +02:00
2009-02-20 23:53:15 +01:00
dol_syslog ( " DolibarrModules::delete_tabs sql= " . $sql );
2008-12-07 20:19:32 +01:00
if ( ! $this -> db -> query ( $sql ))
{
2009-05-04 13:06:49 +02:00
$this -> error = $this -> db -> lasterror ();
dol_syslog ( " DolibarrModules::delete_tabs " . $this -> error , LOG_ERR );
2008-12-07 20:19:32 +01:00
$err ++ ;
}
return $err ;
}
/**
* \brief Active la feuille de style associee au module par insertion ligne dans llx_const
* \return int Nombre d ' erreurs ( 0 si ok )
2008-10-06 09:39:52 +02:00
*/
function insert_style_sheet ()
{
2009-04-27 22:37:50 +02:00
global $conf ;
2009-04-29 22:17:31 +02:00
2008-10-06 09:39:52 +02:00
$err = 0 ;
2008-03-31 00:25:39 +02:00
2008-10-06 09:39:52 +02:00
if ( $this -> style_sheet )
2008-03-31 00:25:39 +02:00
{
2009-05-04 12:27:01 +02:00
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " const ( " ;
$sql .= " name " ;
$sql .= " , type " ;
$sql .= " , value " ;
$sql .= " , note " ;
$sql .= " , visible " ;
$sql .= " , entity " ;
$sql .= " ) " ;
$sql .= " VALUES ( " ;
2009-09-16 10:43:12 +02:00
$sql .= $this -> db -> encrypt ( $this -> const_name . " _CSS " , $conf -> db -> dolibarr_main_db_encryption , $conf -> db -> dolibarr_main_db_cryptkey , 1 );
2009-05-04 12:27:01 +02:00
$sql .= " , 'chaine' " ;
2009-09-16 10:43:12 +02:00
$sql .= " , " . $this -> db -> encrypt ( $this -> style_sheet , $conf -> db -> dolibarr_main_db_encryption , $conf -> db -> dolibarr_main_db_cryptkey , 1 );
2009-05-04 12:27:01 +02:00
$sql .= " , 'Style sheet for module " . $this -> name . " ' " ;
$sql .= " , '0' " ;
$sql .= " , " . $conf -> entity ;
$sql .= " ) " ;
2009-05-08 03:11:04 +02:00
2009-02-20 23:53:15 +01:00
dol_syslog ( " DolibarrModules::insert_style_sheet sql= " . $sql );
2008-03-31 00:25:39 +02:00
$resql = $this -> db -> query ( $sql );
/* Allow duplicate key
2008-10-06 09:39:52 +02:00
if ( ! $resql )
{
$err ++ ;
}
*/
}
return $err ;
}
/**
2008-12-07 20:19:32 +01:00
* \brief Add links of new pages from modules in llx_const
* \return int Number of errors ( 0 if ok )
*/
function insert_tabs ()
{
2009-04-27 22:37:50 +02:00
global $conf ;
2009-04-29 22:17:31 +02:00
2008-12-07 20:19:32 +01:00
$err = 0 ;
2009-01-20 00:32:18 +01:00
2008-12-07 20:19:32 +01:00
if ( ! empty ( $this -> tabs ))
{
$i = 0 ;
foreach ( $this -> tabs as $key => $value )
{
if ( $value )
{
2009-05-04 12:27:01 +02:00
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " const ( " ;
$sql .= " name " ;
$sql .= " , type " ;
$sql .= " , value " ;
$sql .= " , note " ;
$sql .= " , visible " ;
$sql .= " , entity " ;
$sql .= " ) " ;
$sql .= " VALUES ( " ;
2009-09-16 10:43:12 +02:00
$sql .= $this -> db -> encrypt ( $this -> const_name . " _TABS_ " . $i , $conf -> db -> dolibarr_main_db_encryption , $conf -> db -> dolibarr_main_db_cryptkey , 1 );
2009-05-04 12:27:01 +02:00
$sql .= " , 'chaine' " ;
2009-09-16 10:43:12 +02:00
$sql .= " , " . $this -> db -> encrypt ( $value , $conf -> db -> dolibarr_main_db_encryption , $conf -> db -> dolibarr_main_db_cryptkey , 1 );
2009-05-04 12:27:01 +02:00
$sql .= " , null " ;
$sql .= " , '0' " ;
$sql .= " , " . $conf -> entity ;
$sql .= " ) " ;
2009-05-08 03:11:04 +02:00
2009-02-20 23:53:15 +01:00
dol_syslog ( " DolibarrModules::insert_tabs sql= " . $sql );
2008-12-07 20:19:32 +01:00
$resql = $this -> db -> query ( $sql );
/* Allow duplicate key
if ( ! $resql )
{
$err ++ ;
2009-04-29 23:39:31 +02:00
}
*/
2008-12-07 20:19:32 +01:00
}
$i ++ ;
}
}
return $err ;
}
2009-01-20 00:32:18 +01:00
2008-12-07 20:19:32 +01:00
/**
* \brief Insere les constantes associees au module dans llx_const
* \return int Nombre d ' erreurs ( 0 si ok )
2008-10-06 09:39:52 +02:00
*/
function insert_const ()
{
2009-04-27 22:37:50 +02:00
global $conf ;
2009-04-29 22:17:31 +02:00
2008-10-06 09:39:52 +02:00
$err = 0 ;
foreach ( $this -> const as $key => $value )
{
$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 ];
2009-11-17 21:58:31 +01:00
$entity = isset ( $this -> const [ $key ][ 5 ]) ? $this -> const [ $key ][ 5 ] : 0 ;
2009-10-30 22:06:58 +01:00
$entity = (( ! empty ( $entity ) || $entity == '0' ) ? $entity : $conf -> entity );
2008-10-06 09:39:52 +02:00
2009-04-27 22:37:50 +02:00
$sql = " SELECT count(*) " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " const " ;
2009-06-28 01:28:25 +02:00
$sql .= " WHERE " . $this -> db -> decrypt ( 'name' , $conf -> db -> dolibarr_main_db_encryption , $conf -> db -> dolibarr_main_db_cryptkey ) . " = ' " . $name . " ' " ;
2009-10-29 16:42:36 +01:00
$sql .= " AND entity = " . $entity ;
2008-10-06 09:39:52 +02:00
$result = $this -> db -> query ( $sql );
if ( $result )
{
$row = $this -> db -> fetch_row ( $result );
2009-08-12 14:12:15 +02:00
if ( $row [ 0 ] == 0 ) // If not found
2008-10-06 09:39:52 +02:00
{
if ( ! $visible ) $visible = '0' ;
if ( strlen ( $note ))
{
2009-04-27 22:37:50 +02:00
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " const (name,type,value,note,visible,entity) " ;
2009-06-28 01:28:25 +02:00
$sql .= " VALUES ( " ;
2009-09-16 10:43:12 +02:00
$sql .= $this -> db -> encrypt ( $name , $conf -> db -> dolibarr_main_db_encryption , $conf -> db -> dolibarr_main_db_cryptkey , 1 );
2009-06-28 01:28:25 +02:00
$sql .= " ,' " . $type . " ' " ;
2009-09-16 10:43:12 +02:00
$sql .= " , " . $this -> db -> encrypt ( $val , $conf -> db -> dolibarr_main_db_encryption , $conf -> db -> dolibarr_main_db_cryptkey , 1 );
2009-11-26 23:40:28 +01:00
$sql .= " ,' " . addslashes ( $note ) . " ' " ;
2009-06-28 01:28:25 +02:00
$sql .= " ,' " . $visible . " ' " ;
2009-10-29 16:42:36 +01:00
$sql .= " , " . $entity ;
2009-06-28 01:28:25 +02:00
$sql .= " ) " ;
2008-10-06 09:39:52 +02:00
}
elseif ( strlen ( $val ))
{
2009-04-27 22:37:50 +02:00
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " const (name,type,value,visible,entity) " ;
2009-06-28 01:28:25 +02:00
$sql .= " VALUES ( " ;
2009-09-16 10:43:12 +02:00
$sql .= $this -> db -> encrypt ( $name , $conf -> db -> dolibarr_main_db_encryption , $conf -> db -> dolibarr_main_db_cryptkey , 1 );
2009-06-28 01:28:25 +02:00
$sql .= " ,' " . $type . " ' " ;
2009-09-16 10:43:12 +02:00
$sql .= " , " . $this -> db -> encrypt ( $val , $conf -> db -> dolibarr_main_db_encryption , $conf -> db -> dolibarr_main_db_cryptkey , 1 );
2009-06-28 01:28:25 +02:00
$sql .= " ,' " . $visible . " ' " ;
2009-10-29 16:42:36 +01:00
$sql .= " , " . $entity ;
2009-06-28 01:28:25 +02:00
$sql .= " ) " ;
2008-10-06 09:39:52 +02:00
}
else
{
2009-04-27 22:37:50 +02:00
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " const (name,type,visible,entity) " ;
2009-06-28 01:28:25 +02:00
$sql .= " VALUES ( " ;
2009-09-16 10:43:12 +02:00
$sql .= $this -> db -> encrypt ( $name , $conf -> db -> dolibarr_main_db_encryption , $conf -> db -> dolibarr_main_db_cryptkey , 1 );
2009-06-28 01:28:25 +02:00
$sql .= " ,' " . $type . " ' " ;
$sql .= " ,' " . $visible . " ' " ;
2009-10-29 16:42:36 +01:00
$sql .= " , " . $entity ;
2009-06-28 01:28:25 +02:00
$sql .= " ) " ;
2008-10-06 09:39:52 +02:00
}
2009-02-20 23:53:15 +01:00
dol_syslog ( " DolibarrModules::insert_const sql= " . $sql );
2008-10-06 09:39:52 +02:00
if ( ! $this -> db -> query ( $sql ) )
{
2009-02-20 23:53:15 +01:00
dol_syslog ( " DolibarrModules::insert_const " . $this -> db -> lasterror (), LOG_ERR );
2008-10-06 09:39:52 +02:00
$err ++ ;
}
}
2009-08-12 14:12:15 +02:00
else
{
2009-10-29 16:42:36 +01:00
dol_syslog ( " DolibarrModules::insert_const constant ' " . $name . " ' already exists " );
2009-08-12 14:12:15 +02:00
}
2008-10-06 09:39:52 +02:00
}
else
2008-03-31 00:25:39 +02:00
{
$err ++ ;
}
}
2008-10-06 09:39:52 +02:00
2008-03-31 00:25:39 +02:00
return $err ;
}
2005-04-09 17:52:07 +02:00
2008-10-06 09:39:52 +02:00
/**
2009-07-06 09:15:02 +02:00
* \brief Insert permissions related to module to activate into llx_rights_def
* \return int Number of error ( 0 if OK )
2008-10-06 09:39:52 +02:00
*/
function insert_permissions ()
{
2009-04-27 22:37:50 +02:00
global $conf ;
2009-04-29 22:17:31 +02:00
2008-10-06 09:39:52 +02:00
$err = 0 ;
//print $this->rights_class." ".sizeof($this->rights)."<br>";
// Test si module actif
2009-07-06 14:28:49 +02:00
$sql_del = " SELECT " . $this -> db -> decrypt ( 'value' , $conf -> db -> dolibarr_main_db_encryption , $conf -> db -> dolibarr_main_db_cryptkey ) . " as value " ;
2009-06-28 01:28:25 +02:00
$sql_del .= " FROM " . MAIN_DB_PREFIX . " const " ;
$sql_del .= " WHERE " . $this -> db -> decrypt ( 'name' , $conf -> db -> dolibarr_main_db_encryption , $conf -> db -> dolibarr_main_db_cryptkey ) . " = ' " . $this -> const_name . " ' " ;
2009-04-27 22:37:50 +02:00
$sql_del .= " AND entity IN (0, " . $conf -> entity . " ) " ;
2009-07-06 14:28:49 +02:00
2008-10-06 09:39:52 +02:00
$resql = $this -> db -> query ( $sql_del );
2009-07-06 09:15:02 +02:00
if ( $resql )
{
2008-10-06 09:39:52 +02:00
$obj = $this -> db -> fetch_object ( $resql );
2009-07-06 09:15:02 +02:00
if ( $obj -> value )
{
2008-10-06 09:39:52 +02:00
// Si module actif
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_perms = $this -> rights [ $key ][ 4 ];
2009-01-20 00:46:46 +01:00
$r_subperms = isset ( $this -> rights [ $key ][ 5 ]) ? $this -> rights [ $key ][ 5 ] : '' ;
2008-10-06 09:39:52 +02:00
$r_modul = $this -> rights_class ;
if ( empty ( $r_type )) $r_type = 'w' ;
if ( strlen ( $r_perms ) )
{
if ( strlen ( $r_subperms ) )
{
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " rights_def " ;
2009-04-27 22:37:50 +02:00
$sql .= " (id, entity, libelle, module, type, bydefault, perms, subperms) " ;
2008-10-06 09:39:52 +02:00
$sql .= " VALUES " ;
2009-04-27 22:37:50 +02:00
$sql .= " ( " . $r_id . " , " . $conf -> entity . " ,' " . addslashes ( $r_desc ) . " ',' " . $r_modul . " ',' " . $r_type . " ', " . $r_def . " ,' " . $r_perms . " ',' " . $r_subperms . " ') " ;
2008-10-06 09:39:52 +02:00
}
else
{
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " rights_def " ;
2009-04-27 22:37:50 +02:00
$sql .= " (id, entity, libelle, module, type, bydefault, perms) " ;
2008-10-06 09:39:52 +02:00
$sql .= " VALUES " ;
2009-04-27 22:37:50 +02:00
$sql .= " ( " . $r_id . " , " . $conf -> entity . " ,' " . addslashes ( $r_desc ) . " ',' " . $r_modul . " ',' " . $r_type . " ', " . $r_def . " ,' " . $r_perms . " ') " ;
2008-10-06 09:39:52 +02:00
}
}
else
{
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " rights_def " ;
2009-04-27 22:37:50 +02:00
$sql .= " (id, entity, libelle, module, type, bydefault) " ;
2008-10-06 09:39:52 +02:00
$sql .= " VALUES " ;
2009-04-27 22:37:50 +02:00
$sql .= " ( " . $r_id . " , " . $conf -> entity . " ,' " . addslashes ( $r_desc ) . " ',' " . $r_modul . " ',' " . $r_type . " ', " . $r_def . " ) " ;
2008-10-06 09:39:52 +02:00
}
2009-02-20 23:53:15 +01:00
dol_syslog ( " DolibarrModules::insert_permissions sql= " . $sql , LOG_DEBUG );
2008-10-06 09:39:52 +02:00
$resql = $this -> db -> query ( $sql );
if ( ! $resql )
{
if ( $this -> db -> errno () != " DB_ERROR_RECORD_ALREADY_EXISTS " ) {
2009-07-18 16:40:31 +02:00
$this -> error = $this -> db -> lasterror ();
dol_syslog ( " DolibarrModules::insert_permissions error " . $this -> error , LOG_ERR );
2008-10-06 09:39:52 +02:00
$err ++ ;
2009-07-18 17:01:45 +02:00
break ;
2008-10-06 09:39:52 +02:00
}
}
}
}
}
2009-07-06 09:15:02 +02:00
else
{
$this -> error = $this -> db -> lasterror ();
2009-07-18 16:40:31 +02:00
dol_syslog ( " DolibarrModules::insert_permissions " . $this -> error , LOG_ERR );
2009-07-06 09:15:02 +02:00
$err ++ ;
}
2008-10-06 09:39:52 +02:00
return $err ;
}
/**
\brief Supprime les permissions
\return int Nombre d ' erreurs ( 0 si ok )
*/
function delete_permissions ()
{
2009-04-27 22:37:50 +02:00
global $conf ;
2009-04-29 22:17:31 +02:00
2008-10-06 09:39:52 +02:00
$err = 0 ;
2009-04-27 22:37:50 +02:00
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " rights_def " ;
$sql .= " WHERE module = ' " . $this -> rights_class . " ' " ;
$sql .= " AND entity = " . $conf -> entity ;
2009-02-20 23:53:15 +01:00
dol_syslog ( " DolibarrModules::delete_permissions sql= " . $sql );
2009-05-04 13:06:49 +02:00
if ( ! $this -> db -> query ( $sql ))
2008-10-06 09:39:52 +02:00
{
2009-05-04 13:06:49 +02:00
$this -> error = $this -> db -> lasterror ();
dol_syslog ( " DolibarrModules::delete_dirs " . $this -> error , LOG_ERR );
2008-10-06 09:39:52 +02:00
$err ++ ;
}
return $err ;
}
/**
2008-12-02 15:16:18 +01:00
* \brief Insere les menus dans llx_menu *
* \return int Nombre d ' erreurs ( 0 si ok )
2008-10-06 09:39:52 +02:00
*/
function insert_menus ()
{
2008-01-14 02:41:10 +01:00
global $user ;
2009-01-20 00:32:18 +01:00
2008-04-20 06:24:00 +02:00
require_once ( DOL_DOCUMENT_ROOT . " /core/menubase.class.php " );
2008-01-14 02:26:15 +01:00
$err = 0 ;
2008-10-06 09:39:52 +02:00
2008-01-30 01:15:59 +01:00
$this -> db -> begin ();
2008-10-06 09:39:52 +02:00
2008-12-02 15:16:18 +01:00
//var_dump($this->menu); exit;
2008-10-06 09:39:52 +02:00
foreach ( $this -> menu as $key => $value )
{
$menu = new Menubase ( $this -> db );
$menu -> menu_handler = 'all' ;
2008-01-14 02:41:10 +01:00
$menu -> module = $this -> rights_class ;
2008-05-02 05:55:09 +02:00
if ( ! $this -> menu [ $key ][ 'fk_menu' ])
{
$menu -> fk_menu = 0 ;
2008-12-02 15:16:18 +01:00
//print 'aaa'.$this->menu[$key]['fk_menu'];
2008-05-02 05:55:09 +02:00
}
else
2008-01-30 01:15:59 +01:00
{
2008-12-02 15:16:18 +01:00
//print 'xxx'.$this->menu[$key]['fk_menu'];exit;
2008-01-30 01:15:59 +01:00
$numparent = $this -> menu [ $key ][ 'fk_menu' ];
2009-10-21 15:09:42 +02:00
$numparent = str_replace ( 'r=' , '' , $numparent );
2008-01-30 01:15:59 +01:00
if ( isset ( $this -> menu [ $numparent ][ 'rowid' ]))
{
$menu -> fk_menu = $this -> menu [ $numparent ][ 'rowid' ];
}
else
{
$this -> error = " BadDefinitionOfMenuArrayInModuleDescriptor " ;
2009-02-20 23:53:15 +01:00
dol_syslog ( " DolibarrModules::insert_menus " . $this -> error . " " . $this -> menu [ $key ][ 'fk_menu' ], LOG_ERR );
2008-01-30 01:15:59 +01:00
$err ++ ;
}
}
2008-01-14 02:26:15 +01:00
$menu -> type = $this -> menu [ $key ][ 'type' ];
2008-01-14 21:54:15 +01:00
$menu -> mainmenu = $this -> menu [ $key ][ 'mainmenu' ];
2008-01-14 02:26:15 +01:00
$menu -> titre = $this -> menu [ $key ][ 'titre' ];
$menu -> leftmenu = $this -> menu [ $key ][ 'leftmenu' ];
$menu -> url = $this -> menu [ $key ][ 'url' ];
$menu -> langs = $this -> menu [ $key ][ 'langs' ];
$menu -> position = $this -> menu [ $key ][ 'position' ];
$menu -> perms = $this -> menu [ $key ][ 'perms' ];
$menu -> target = $this -> menu [ $key ][ 'target' ];
$menu -> user = $this -> menu [ $key ][ 'user' ];
2009-04-27 22:37:50 +02:00
//$menu->constraint=$this->menu[$key]['constraint'];
$menu -> enabled = $this -> menu [ $key ][ 'enabled' ];
2008-01-30 01:15:59 +01:00
if ( ! $err )
{
$result = $menu -> create ( $user );
if ( $result > 0 )
2008-10-06 09:39:52 +02:00
{
$this -> menu [ $key ][ 'rowid' ] = $result ;
}
else
{
2008-01-30 01:15:59 +01:00
$this -> error = $menu -> error ;
2009-02-20 23:53:15 +01:00
dol_syslog ( 'DolibarrModules::insert_menus result=' . $result . " " . $this -> error , LOG_ERR );
2008-10-06 09:39:52 +02:00
$err ++ ;
2008-12-02 15:16:18 +01:00
break ;
2008-10-06 09:39:52 +02:00
}
2008-01-30 01:15:59 +01:00
}
2008-10-06 09:39:52 +02:00
}
if ( ! $err )
{
$this -> db -> commit ();
}
else
{
2009-02-20 23:53:15 +01:00
dol_syslog ( " DolibarrModules::insert_menus " . $this -> error , LOG_ERR );
2008-10-06 09:39:52 +02:00
$this -> db -> rollback ();
}
return $err ;
}
/**
2009-03-20 15:33:56 +01:00
* \brief Remove menus entries
* \return int Nombre d ' erreurs ( 0 si ok )
2008-10-06 09:39:52 +02:00
*/
function delete_menus ()
{
2009-04-27 22:37:50 +02:00
global $conf ;
2009-04-29 22:17:31 +02:00
2008-10-06 09:39:52 +02:00
$err = 0 ;
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " menu " ;
$sql .= " WHERE module = ' " . addslashes ( $this -> rights_class ) . " ' " ;
2009-04-27 22:37:50 +02:00
$sql .= " AND entity = " . $conf -> entity ;
2008-10-06 09:39:52 +02:00
2009-02-20 23:53:15 +01:00
dol_syslog ( " DolibarrModules::delete_menus sql= " . $sql );
2008-01-14 21:54:15 +01:00
$resql = $this -> db -> query ( $sql );
if ( ! $resql )
2008-10-06 09:39:52 +02:00
{
2009-05-04 13:06:49 +02:00
$this -> error = $this -> db -> lasterror ();
dol_syslog ( " DolibarrModules::delete_menus " . $this -> error , LOG_ERR );
2008-10-06 09:39:52 +02:00
$err ++ ;
}
return $err ;
}
2009-04-29 22:17:31 +02:00
2009-04-28 15:04:35 +02:00
/**
2009-04-29 22:17:31 +02:00
* \brief Create directories required by module
* \return int Number of errors ( 0 if OK )
2009-04-28 15:04:35 +02:00
*/
2009-04-29 22:37:20 +02:00
function create_dirs ()
2009-04-28 15:04:35 +02:00
{
2009-04-28 15:54:14 +02:00
global $langs , $conf ;
2009-04-29 22:17:31 +02:00
2009-04-28 15:04:35 +02:00
$err = 0 ;
2009-04-29 22:17:31 +02:00
2009-04-28 15:04:35 +02:00
if ( is_array ( $this -> dirs ))
{
foreach ( $this -> dirs as $key => $value )
{
2009-05-04 13:06:49 +02:00
$addtodatabase = 0 ;
if ( ! is_array ( $value )) $dir = $value ; // Default simple mode
else {
$constname = $this -> const_name . " _DIR_ " ;
$dir = $this -> dirs [ $key ][ 1 ];
$addtodatabase = empty ( $this -> dirs [ $key ][ 2 ]) ? '' : $this -> dirs [ $key ][ 2 ]; // Create constante in llx_const
$subname = empty ( $this -> dirs [ $key ][ 3 ]) ? '' : strtoupper ( $this -> dirs [ $key ][ 3 ]); // Add submodule name (ex: $conf->module->submodule->dir_output)
$forcename = empty ( $this -> dirs [ $key ][ 4 ]) ? '' : strtoupper ( $this -> dirs [ $key ][ 4 ]); // Change the module name if different
if ( $forcename ) $constname = 'MAIN_MODULE_' . $forcename . " _DIR_ " ;
if ( $subname ) $constname = $constname . $subname . " _ " ;
$name = $constname . strtoupper ( $this -> dirs [ $key ][ 0 ]);
}
2009-04-30 01:39:04 +02:00
2009-04-29 22:37:20 +02:00
// Define directory full path
2009-05-08 13:04:25 +02:00
if ( empty ( $conf -> global -> MAIN_MODULE_MULTICOMPANY ) || $conf -> entity == 1 ) $fulldir = DOL_DATA_ROOT . $dir ;
2009-04-29 23:29:26 +02:00
else $fulldir = DOL_DATA_ROOT . " / " . $conf -> entity . $dir ;
2009-04-29 22:37:20 +02:00
// Create dir if it does not exists
2009-04-29 23:29:26 +02:00
if ( $fulldir && ! file_exists ( $fulldir ))
2009-04-28 15:04:35 +02:00
{
2009-04-29 23:29:26 +02:00
if ( create_exdir ( $fulldir ) < 0 )
2009-04-28 15:04:35 +02:00
{
2009-04-29 23:29:26 +02:00
$this -> error = $langs -> trans ( " ErrorCanNotCreateDir " , $fulldir );
2009-04-29 22:37:20 +02:00
dol_syslog ( " DolibarrModules::_init " . $this -> error , LOG_ERR );
2009-04-28 15:04:35 +02:00
$err ++ ;
}
}
2009-05-04 13:06:49 +02:00
// Define the constant in database if requested (not the default mode)
if ( $addtodatabase )
2009-04-29 23:29:26 +02:00
{
$result = $this -> insert_dirs ( $name , $dir );
if ( $result ) $err ++ ;
}
2009-04-28 15:04:35 +02:00
}
}
2009-04-29 22:17:31 +02:00
2009-04-28 15:04:35 +02:00
return $err ;
2009-04-29 23:39:31 +02:00
}
/**
2009-04-29 23:29:26 +02:00
* \brief Insert directories in llx_const
* \return int Number of errors ( 0 if OK )
*/
function insert_dirs ( $name , $dir )
{
global $conf ;
2009-04-29 23:39:31 +02:00
2009-04-29 23:29:26 +02:00
$err = 0 ;
2009-04-29 23:39:31 +02:00
$sql = " SELECT count(*) " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " const " ;
2009-07-06 09:15:02 +02:00
$sql .= " WHERE " . $this -> db -> decrypt ( 'name' , $conf -> db -> dolibarr_main_db_encryption , $conf -> db -> dolibarr_main_db_cryptkey ) . " = ' " . $name . " ' " ;
2009-04-29 23:39:31 +02:00
$sql .= " AND entity = " . $conf -> entity ;
2009-07-06 09:15:02 +02:00
dol_syslog ( " DolibarrModules::insert_dirs sql= " . $sql );
2009-04-29 23:39:31 +02:00
$result = $this -> db -> query ( $sql );
if ( $result )
{
$row = $this -> db -> fetch_row ( $result );
if ( $row [ 0 ] == 0 )
{
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " const (name,type,value,note,visible,entity) " ;
2009-09-16 10:43:12 +02:00
$sql .= " VALUES ( " . $this -> db -> encrypt ( $name , $conf -> db -> dolibarr_main_db_encryption , $conf -> db -> dolibarr_main_db_cryptkey , 1 ) . " ,'chaine', " . $this -> db -> encrypt ( $dir , $conf -> db -> dolibarr_main_db_encryption , $conf -> db -> dolibarr_main_db_cryptkey , 1 ) . " ,'Directory for module " . $this -> name . " ','0', " . $conf -> entity . " ) " ;
2009-04-29 23:39:31 +02:00
2009-07-06 09:15:02 +02:00
dol_syslog ( " DolibarrModules::insert_dirs sql= " . $sql );
2009-04-29 23:39:31 +02:00
$resql = $this -> db -> query ( $sql );
}
}
else
{
2009-07-06 09:15:02 +02:00
$this -> error = $this -> db -> lasterror ();
dol_syslog ( " DolibarrModules::insert_dirs " . $this -> error , LOG_ERR );
2009-04-29 23:39:31 +02:00
$err ++ ;
}
return $err ;
2009-04-29 23:29:26 +02:00
}
2009-04-29 23:39:31 +02:00
/**
* \brief Remove directory entries
* \return int Number of errors ( 0 if OK )
2009-04-29 23:29:26 +02:00
*/
function delete_dirs ()
{
global $conf ;
2009-04-29 23:39:31 +02:00
2009-04-29 23:29:26 +02:00
$err = 0 ;
2009-04-29 23:39:31 +02:00
2009-04-29 23:29:26 +02:00
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " const " ;
2009-06-27 08:56:41 +02:00
$sql .= " WHERE " . $this -> db -> decrypt ( 'name' , $conf -> db -> dolibarr_main_db_encryption , $conf -> db -> dolibarr_main_db_cryptkey ) . " like ' " . $this -> const_name . " _DIR_%' " ;
2009-04-29 23:29:26 +02:00
$sql .= " AND entity = " . $conf -> entity ;
2009-04-29 23:39:31 +02:00
2009-05-04 13:06:49 +02:00
dol_syslog ( " DolibarrModules::delete_dirs sql= " . $sql );
2009-04-29 23:29:26 +02:00
if ( ! $this -> db -> query ( $sql ))
{
2009-05-04 13:06:49 +02:00
$this -> error = $this -> db -> lasterror ();
dol_syslog ( " DolibarrModules::delete_dirs " . $this -> error , LOG_ERR );
2009-04-29 23:29:26 +02:00
$err ++ ;
}
2009-04-29 23:39:31 +02:00
return $err ;
2009-04-29 23:29:26 +02:00
}
2009-04-29 23:39:31 +02:00
2003-11-15 18:41:07 +01:00
}
2009-04-29 23:39:31 +02:00
?>