2017-03-09 15:16:45 +01:00
< ? php
2017-03-27 22:44:50 +02:00
/* Copyright ( C ) 2017 Laurent Destailleur < eldy @ users . sourcefore . net >
2017-03-09 15:16:45 +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 3 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
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2017-03-09 15:16:45 +01:00
*/
/**
2017-03-27 22:44:50 +02:00
* \defgroup blockedlog Module BlockedLog
2017-03-09 15:16:45 +01:00
* \brief Add a log into a block chain for some actions .
2017-03-27 22:44:50 +02:00
* \file htdocs / core / modules / modBlockedLog . class . php
* \ingroup blockedlog
* \brief Description and activation file for module BlockedLog
2017-03-09 15:16:45 +01:00
*/
2020-04-10 10:59:32 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/modules/DolibarrModules.class.php' ;
2017-03-09 15:16:45 +01:00
/**
2017-03-29 21:36:50 +02:00
* Class to describe a BlockedLog module
2017-03-09 15:16:45 +01:00
*/
2017-03-27 22:44:50 +02:00
class modBlockedLog extends DolibarrModules
2017-03-09 15:16:45 +01:00
{
/**
2019-02-25 20:35:59 +01:00
* Constructor . Define names , constants , directories , boxes , permissions
*
* @ param DoliDB $db Database handler
2017-03-09 15:16:45 +01:00
*/
2019-02-25 20:35:59 +01:00
public function __construct ( $db )
2017-03-09 15:16:45 +01:00
{
2019-02-25 20:35:59 +01:00
global $langs , $conf , $mysoc ;
2017-03-09 15:16:45 +01:00
$this -> db = $db ;
$this -> numero = 3200 ;
2017-12-15 15:15:14 +01:00
// Key text used to identify module (for permissions, menus, etc...)
$this -> rights_class = 'blockedlog' ;
2017-03-09 15:16:45 +01:00
2019-02-25 20:35:59 +01:00
// Family can be 'crm','financial','hr','projects','products','ecm','technic','other'
// It is used to group modules in module setup page
2017-06-16 11:51:33 +02:00
$this -> family = " base " ;
2018-01-25 17:53:02 +01:00
// Module position in the family on 2 digits ('01', '10', '20', ...)
2018-10-06 11:57:53 +02:00
$this -> module_position = '75' ;
2017-03-09 15:16:45 +01:00
// Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
2019-01-27 11:55:16 +01:00
$this -> name = preg_replace ( '/^mod/i' , '' , get_class ( $this ));
2017-06-16 11:51:33 +02:00
$this -> description = " Enable a log on some business events into a non reversible log. This module may be mandatory for some countries. " ;
2018-08-15 17:34:35 +02:00
// Possible values for version are: 'development', 'experimental', 'dolibarr' or version
2017-12-14 17:08:43 +01:00
$this -> version = 'dolibarr' ;
2017-03-09 15:16:45 +01:00
// Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase)
$this -> const_name = 'MAIN_MODULE_' . strtoupper ( $this -> name );
// Name of image file used for this module.
2020-04-10 10:59:32 +02:00
$this -> picto = 'technic' ;
2017-03-09 15:16:45 +01:00
// Data directories to create when module is enabled
$this -> dirs = array ();
// Config pages
//-------------
2017-12-16 21:50:58 +01:00
$this -> config_page_url = array ( 'blockedlog.php?withtab=1@blockedlog' );
2017-03-09 15:16:45 +01:00
// Dependancies
//-------------
2020-04-10 10:59:32 +02:00
$this -> hidden = false ; // A condition to disable module
$this -> depends = array ( 'always' => 'modFacture' ); // List of modules id that must be enabled if this module is enabled
$this -> requiredby = array (); // List of modules id to disable if this one is disabled
$this -> conflictwith = array (); // List of modules id this module is in conflict with
2017-12-05 11:34:07 +01:00
$this -> langfiles = array ( 'blockedlog' );
2017-03-09 15:16:45 +01:00
2020-04-10 10:59:32 +02:00
$this -> warnings_activation = array (); // Warning to show when we activate module. array('always'='text') or array('FR'='textfr','ES'='textes'...)
$this -> warnings_activation_ext = array (); // Warning to show when we activate an external module. array('always'='text') or array('FR'='textfr','ES'='textes'...)
2017-12-05 11:34:07 +01:00
$this -> warnings_unactivation = array ( 'FR' => 'BlockedLogAreRequiredByYourCountryLegislation' );
2017-12-08 16:15:41 +01:00
// Currently, activation is not automatic because only companies (in France) making invoices to non business customers must
// enable this module.
2017-12-15 15:15:14 +01:00
/* if ( ! empty ( $conf -> global -> BLOCKEDLOG_DISABLE_NOT_ALLOWED_FOR_COUNTRY ))
2017-12-08 16:15:41 +01:00
{
2019-02-25 20:35:59 +01:00
$tmp = explode ( ',' , $conf -> global -> BLOCKEDLOG_DISABLE_NOT_ALLOWED_FOR_COUNTRY );
$this -> automatic_activation = array ();
foreach ( $tmp as $key )
{
$this -> automatic_activation [ $key ] = 'BlockedLogActivatedBecauseRequiredByYourCountryLegislation' ;
}
2017-12-15 15:15:14 +01:00
} */
//var_dump($this->automatic_activation);
$this -> always_enabled = ( ! empty ( $conf -> blockedlog -> enabled )
2019-02-25 20:35:59 +01:00
&& ! empty ( $conf -> global -> BLOCKEDLOG_DISABLE_NOT_ALLOWED_FOR_COUNTRY )
&& in_array ( $mysoc -> country_code , explode ( ',' , $conf -> global -> BLOCKEDLOG_DISABLE_NOT_ALLOWED_FOR_COUNTRY ))
2019-09-08 21:21:33 +02:00
&& $this -> alreadyUsed ());
2017-12-08 16:15:41 +01:00
2017-03-09 15:16:45 +01:00
// Constants
//-----------
2017-12-15 15:15:14 +01:00
$this -> const = array (
2019-02-25 20:35:59 +01:00
1 => array ( 'BLOCKEDLOG_DISABLE_NOT_ALLOWED_FOR_COUNTRY' , 'chaine' , 'FR' , 'This is list of country code where the module may be mandatory' , 0 , 'current' , 0 )
2017-12-15 15:15:14 +01:00
);
2017-03-09 15:16:45 +01:00
// New pages on tabs
// -----------------
$this -> tabs = array ();
// Boxes
//------
$this -> boxes = array ();
2017-12-15 15:15:14 +01:00
// Permissions
2017-12-16 21:36:36 +01:00
// -----------------
2020-04-10 10:59:32 +02:00
$this -> rights = array (); // Permission array used by this module
2017-12-15 15:15:14 +01:00
2020-04-10 10:59:32 +02:00
$r = 0 ;
$this -> rights [ $r ][ 0 ] = $this -> numero + $r ; // Permission id (must not be already used)
$this -> rights [ $r ][ 1 ] = 'Read archived events and fingerprints' ; // Permission label
$this -> rights [ $r ][ 3 ] = 0 ; // Permission by default for new user (0/1)
$this -> rights [ $r ][ 4 ] = 'read' ; // In php code, permission will be checked by test if ($user->rights->mymodule->level1->level2)
2017-12-15 15:15:14 +01:00
$this -> rights [ $r ][ 5 ] = '' ;
2017-03-09 15:16:45 +01:00
// Main menu entries
2017-12-16 21:36:36 +01:00
// -----------------
2020-04-10 10:59:32 +02:00
$r = 0 ;
$this -> menu [ $r ] = array (
'fk_menu' => 'fk_mainmenu=tools' , // Use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
2017-12-16 21:36:36 +01:00
'mainmenu' => 'tools' ,
'leftmenu' => 'blockedlogbrowser' ,
2020-04-10 10:59:32 +02:00
'type' => 'left' , // This is a Left menu entry
2017-12-16 21:36:36 +01:00
'titre' => 'BrowseBlockedLog' ,
'url' => '/blockedlog/admin/blockedlog_list.php?mainmenu=tools&leftmenu=blockedlogbrowser' ,
2020-04-10 10:59:32 +02:00
'langs' => 'blockedlog' , // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
2017-12-16 21:36:36 +01:00
'position' => 200 ,
2020-04-10 10:59:32 +02:00
'enabled' => '$conf->blockedlog->enabled' , // Define condition to show or hide menu entry. Use '$conf->mymodule->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
'perms' => '$user->rights->blockedlog->read' , // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
2017-12-16 21:36:36 +01:00
'target' => '' ,
2020-04-10 10:59:32 +02:00
'user' => 2 ); // 0=Menu for internal users, 1=external users, 2=both
2017-12-16 21:36:36 +01:00
$r ++ ;
2017-03-09 15:16:45 +01:00
}
2017-12-08 16:15:41 +01:00
2017-12-15 15:15:14 +01:00
2017-12-05 11:34:07 +01:00
/**
2017-12-08 16:15:41 +01:00
* Check if module was already used before unactivation linked to warnings_unactivation property
2017-12-15 15:15:14 +01:00
*
* @ return boolean True if already used , otherwise False
2017-12-05 11:34:07 +01:00
*/
2019-02-26 21:13:07 +01:00
public function alreadyUsed ()
2018-08-15 17:34:35 +02:00
{
2019-02-25 20:35:59 +01:00
require_once DOL_DOCUMENT_ROOT . '/blockedlog/class/blockedlog.class.php' ;
2020-04-10 10:59:32 +02:00
$b = new BlockedLog ( $this -> db );
2019-02-25 20:35:59 +01:00
return $b -> alreadyUsed ( 1 );
2017-12-15 15:15:14 +01:00
}
/**
* Function called when module is enabled .
* The init function add constants , boxes , permissions and menus ( defined in constructor ) into Dolibarr database .
* It also creates data directories .
*
* @ param string $options Options when enabling module ( '' , 'noboxes' )
* @ return int 1 if OK , 0 if KO
*/
2019-02-26 21:13:07 +01:00
public function init ( $options = '' )
2017-12-15 15:15:14 +01:00
{
2019-02-25 20:35:59 +01:00
global $conf , $user ;
$sql = array ();
// If already used, we add an entry to show we enable module
require_once DOL_DOCUMENT_ROOT . '/blockedlog/class/blockedlog.class.php' ;
2020-04-10 10:59:32 +02:00
$object = new stdClass ();
2019-02-25 20:35:59 +01:00
$object -> id = 1 ;
$object -> element = 'module' ;
$object -> ref = 'systemevent' ;
$object -> entity = $conf -> entity ;
$object -> date = dol_now ();
2020-04-10 10:59:32 +02:00
$b = new BlockedLog ( $this -> db );
2019-02-25 20:35:59 +01:00
$result = $b -> setObjectData ( $object , 'MODULE_SET' , 0 );
if ( $result < 0 )
{
$this -> error = $b -> error ;
$this -> errors = $b -> erros ;
return 0 ;
}
$res = $b -> create ( $user );
2020-04-10 10:59:32 +02:00
if ( $res <= 0 ) {
2019-02-25 20:35:59 +01:00
$this -> error = $b -> error ;
$this -> errors = $b -> errors ;
return $res ;
}
return $this -> _init ( $sql , $options );
2017-12-05 11:34:07 +01:00
}
2017-12-08 16:15:41 +01:00
2017-12-05 11:34:07 +01:00
/**
2019-02-25 20:35:59 +01:00
* Function called when module is disabled .
* The remove function removes tabs , constants , boxes , permissions and menus from Dolibarr database .
* Data directories are not deleted
*
* @ param string $options Options when enabling module ( '' , 'noboxes' )
* @ return int 1 if OK , 0 if KO
*/
2019-02-26 21:13:07 +01:00
public function remove ( $options = '' )
2018-08-15 17:34:35 +02:00
{
2017-12-08 16:15:41 +01:00
2019-02-25 20:35:59 +01:00
global $conf , $user ;
$sql = array ();
// If already used, we add an entry to show we enable module
require_once DOL_DOCUMENT_ROOT . '/blockedlog/class/blockedlog.class.php' ;
2020-04-10 10:59:32 +02:00
$object = new stdClass ();
2019-02-25 20:35:59 +01:00
$object -> id = 1 ;
$object -> element = 'module' ;
$object -> ref = 'systemevent' ;
$object -> entity = $conf -> entity ;
$object -> date = dol_now ();
2020-04-10 10:59:32 +02:00
$b = new BlockedLog ( $this -> db );
2019-02-25 20:35:59 +01:00
$result = $b -> setObjectData ( $object , 'MODULE_RESET' , 0 );
if ( $result < 0 )
{
$this -> error = $b -> error ;
$this -> errors = $b -> erros ;
return 0 ;
}
if ( $b -> alreadyUsed ( 1 ))
{
2019-02-26 21:13:07 +01:00
$res = $b -> create ( $user , '0000000000' ); // If already used for something else than SET or UNSET, we log with error
2019-02-25 20:35:59 +01:00
}
else
{
$res = $b -> create ( $user );
}
2020-04-10 10:59:32 +02:00
if ( $res <= 0 ) {
2019-02-25 20:35:59 +01:00
$this -> error = $b -> error ;
$this -> errors = $b -> errors ;
return $res ;
}
return $this -> _remove ( $sql , $options );
2017-12-05 11:34:07 +01:00
}
2017-03-09 15:16:45 +01:00
}