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
* along with this program . If not , see < http :// www . gnu . org / licenses />.
*/
/**
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
*/
include_once DOL_DOCUMENT_ROOT . '/core/modules/DolibarrModules.class.php' ;
/**
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
{
/**
* Constructor . Define names , constants , directories , boxes , permissions
*
* @ param DoliDB $db Database handler
*/
function __construct ( $db )
{
2017-12-05 18:30:48 +01:00
global $langs , $conf , $mysoc ;
2017-03-09 15:16:45 +01:00
$this -> db = $db ;
$this -> numero = 3200 ;
// 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 " ;
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)
$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. " ;
2017-08-22 18:34:58 +02:00
// Possible values for version are: 'development', 'experimental', 'dolibarr' or version
2017-12-01 13:41:37 +01:00
$this -> version = 'experimental' ;
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 );
// Where to store the module in setup page (0=common,1=interface,2=others,3=very specific)
2017-06-16 11:51:33 +02:00
$this -> special = 2 ;
2017-03-09 15:16:45 +01:00
// Name of image file used for this module.
2017-03-27 22:44:50 +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-06-10 09:25:32 +02:00
$this -> config_page_url = array ( 'blockedlog.php@blockedlog' );
2017-03-09 15:16:45 +01:00
// Dependancies
//-------------
$this -> hidden = false ; // A condition to disable module
2017-06-17 11:43:00 +02:00
$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
2017-12-08 16:15:41 +01: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.
// It is automatic only if $conf->global->BLOCKEDLOG_DISABLE_NOT_ALLOWED_FOR_COUNTRY is on.
if ( ! empty ( $conf -> global -> BLOCKEDLOG_DISABLE_NOT_ALLOWED_FOR_COUNTRY ))
{
$this -> automatic_activation = array ( 'FR' => 'BlockedLogActivatedBecauseRequiredByYourCountryLegislation' );
}
$this -> always_enabled = ! empty ( $conf -> blockedlog -> enabled ) && ! empty ( $conf -> global -> BLOCKEDLOG_DISABLE_NOT_ALLOWED_FOR_COUNTRY ) && in_array ( $mysoc -> country_code , explode ( ',' , $conf -> global -> BLOCKEDLOG_DISABLE_NOT_ALLOWED_FOR_COUNTRY ));
2017-03-09 15:16:45 +01:00
// Constants
//-----------
2017-12-08 16:15:41 +01:00
$this -> const = array ();
2017-03-09 15:16:45 +01:00
// New pages on tabs
// -----------------
$this -> tabs = array ();
// Boxes
//------
$this -> boxes = array ();
// Main menu entries
//------------------
$this -> menu = array ();
}
2017-12-08 16:15:41 +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-05 11:34:07 +01:00
*/
function alreadyUsed () {
2017-12-08 16:15:41 +01:00
2017-12-05 11:34:07 +01:00
$res = $this -> db -> query ( " SELECT count(*) as nb FROM " . MAIN_DB_PREFIX . " blockedlog " );
if ( $res !== false ) {
$obj = $this -> db -> fetch_object ( $res );
return ( $obj -> nb > 0 );
}
2017-12-08 16:15:41 +01:00
2017-12-05 11:34:07 +01:00
return false ;
}
2017-12-08 16:15:41 +01:00
2017-12-05 11:34:07 +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
*/
function remove ( $options = '' ) {
2017-12-08 16:15:41 +01:00
2017-12-05 11:34:07 +01:00
global $user ;
2017-12-08 16:15:41 +01:00
2017-12-05 11:34:07 +01:00
require_once DOL_DOCUMENT_ROOT . '/blockedlog/class/blockedlog.class.php' ;
2017-12-08 16:15:41 +01:00
2017-12-05 11:34:07 +01:00
$object = new stdClass ;
$object -> id = 1 ;
$object -> element = 'module' ;
$object -> ref = 'module' ;
$object -> date = time ();
2017-12-08 16:15:41 +01:00
2017-12-05 11:34:07 +01:00
$b = new BlockedLog ( $this -> db );
$b -> setObjectData ( $object , 'MODULE_RESET' , - 1 );
2017-12-08 16:15:41 +01:00
2017-12-05 11:34:07 +01:00
$res = $b -> create ( $user );
if ( $res <= 0 ) {
$this -> error = $b -> error ;
return $res ;
}
2017-12-08 16:15:41 +01:00
2017-12-05 11:34:07 +01:00
return $this -> _remove ( array (), $options );
2017-12-08 16:15:41 +01:00
2017-12-05 11:34:07 +01:00
}
2017-03-09 15:16:45 +01:00
}