2014-01-02 07:07:43 +01:00
< ? php
2015-05-31 12:25:33 +02:00
/* Copyright ( C ) 2013 - 2014 Jean - François Ferry < jfefe @ aternatik . fr >
2015-11-22 12:23:10 +01:00
* Copyright ( C ) 2015 Laurent Destailleur < eldy @ users . sourceforge . net >
2014-01-02 07:07:43 +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 />.
2015-05-31 02:05:39 +02:00
*
* Module to manage resources into Dolibarr ERP / CRM
2014-01-02 07:07:43 +01:00
*/
/**
2015-03-17 11:23:45 +01:00
* \defgroup resource Module resource
2014-01-02 07:07:43 +01:00
* \brief Resource module descriptor .
* \file core / modules / modResource . class . php
* \ingroup resource
* \brief Description and activation file for module Resource
*/
2020-04-10 10:59:32 +02:00
include_once DOL_DOCUMENT_ROOT . " /core/modules/DolibarrModules.class.php " ;
2014-01-02 07:07:43 +01:00
/**
* Description and activation class for module Resource
*/
class modResource extends DolibarrModules
{
/**
* Constructor . Define names , constants , directories , boxes , permissions
*
* @ param DoliDB $db Database handler
*/
public function __construct ( $db )
{
global $langs , $conf ;
$this -> db = $db ;
// Id for module (must be unique).
// Use a free id here
// (See in Home -> System information -> Dolibarr for list of used modules id).
2015-05-04 12:02:09 +02:00
$this -> numero = 63000 ;
2016-10-19 22:14:51 +02:00
2014-01-02 07:07:43 +01:00
// Key text used to identify module (for permissions, menus, etc...)
$this -> rights_class = 'resource' ;
// Family can be 'crm','financial','hr','projects','products','ecm','technic','other'
// It is used to group modules in module setup page
2015-05-31 12:25:33 +02:00
$this -> family = " projects " ;
2019-06-21 13:25:40 +02:00
$this -> module_position = '16' ;
2014-01-02 07:07:43 +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 ));
// Module description
// used if translation string 'ModuleXXXDesc' not found
// (where XXX is value of numeric property 'numero' of module)
2015-03-24 14:08:56 +01:00
$this -> description = " Manage resources (printers, cars, room, ...) you can then share into events " ;
2014-01-02 07:07:43 +01:00
// Possible values for version are: 'development', 'experimental' or version
2015-04-18 18:18:21 +02:00
$this -> version = 'dolibarr' ;
2014-01-02 07:07:43 +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)
2020-04-10 10:59:32 +02:00
$this -> const_name = 'MAIN_MODULE_' . strtoupper ( $this -> name );
2014-01-02 07:07:43 +01:00
// Name of image file used for this module.
// If file is in theme/yourtheme/img directory under name object_pictovalue.png
// use this->picto='pictovalue'
// If file is in module/img directory under name object_pictovalue.png
// use this->picto='pictovalue@module'
2014-03-15 21:24:37 +01:00
$this -> picto = 'resource' ; // mypicto@resource
2014-01-02 07:07:43 +01:00
// Defined all module parts (triggers, login, substitutions, menus, css, etc...)
// for default path (eg: /resource/core/xxxxx) (0=disable, 1=enable)
// for specific path of parts (eg: /resource/core/modules/barcode)
// for specific css file (eg: /resource/css/resource.css.php)
2018-05-01 12:40:42 +02:00
$this -> module_parts = array ();
2014-01-02 07:07:43 +01:00
// Data directories to create when module is enabled.
// Example: this->dirs = array("/resource/temp");
2014-03-15 08:50:17 +01:00
//$this->dirs = array("/resource");
2014-01-02 07:07:43 +01:00
// Config pages. Put here list of php pages
// stored into resource/admin directory, used to setup module.
2016-10-19 22:14:51 +02:00
$this -> config_page_url = array ( " resource.php " );
2014-01-02 07:07:43 +01:00
// Dependencies
// List of modules id that must be enabled if this module is enabled
$this -> depends = array ();
// List of modules id to disable if this one is disabled
$this -> requiredby = array ( 'modPlace' );
// Minimum version of PHP required by module
2018-07-10 09:32:55 +02:00
$this -> phpmin = array ( 5 , 4 );
2015-05-04 12:02:09 +02:00
2016-06-06 13:14:05 +02:00
$this -> langfiles = array ( " resource " ); // langfiles@resource
2014-01-02 07:07:43 +01:00
// Constants
// List of particular constants to add when module is enabled
// (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive)
// Example:
2014-03-23 19:42:01 +01:00
$this -> const = array ();
2014-01-02 07:07:43 +01:00
// Array to add new pages in new tabs
// Example:
$this -> tabs = array (
// // To add a new tab identified by code tabname1
// 'objecttype:+tabname1:Title1:langfile@resource:$user->rights->resource->read:/resource/mynewtab1.php?id=__ID__',
// // To add another new tab identified by code tabname2
// 'objecttype:+tabname2:Title2:langfile@resource:$user->rights->othermodule->read:/resource/mynewtab2.php?id=__ID__',
// // To remove an existing tab identified by code tabname
// 'objecttype:-tabname'
);
// where objecttype can be
// 'thirdparty' to add a tab in third party view
// 'intervention' to add a tab in intervention view
// 'order_supplier' to add a tab in supplier order view
// 'invoice_supplier' to add a tab in supplier invoice view
// 'invoice' to add a tab in customer invoice view
// 'order' to add a tab in customer order view
// 'product' to add a tab in product view
// 'stock' to add a tab in stock view
// 'propal' to add a tab in propal view
// 'member' to add a tab in fundation member view
// 'contract' to add a tab in contract view
// 'user' to add a tab in user view
// 'group' to add a tab in group view
// 'contact' to add a tab in contact view
// 'categories_x' to add a tab in category view
// (reresource 'x' by type of category (0=product, 1=supplier, 2=customer, 3=member)
// Boxes
// Add here list of php file(s) stored in core/boxes that contains class to show a box.
$this -> boxes = array (); // Boxes list
$r = 0 ;
// Example:
//$this->boxes[$r][1] = "MyBox@resource";
//$r ++;
/*
$this -> boxes [ $r ][ 1 ] = " myboxb.php " ;
$r ++ ;
*/
// Permissions
$this -> rights = array (); // Permission array used by this module
$r = 0 ;
2015-05-04 12:02:09 +02:00
$this -> rights [ $r ][ 0 ] = 63001 ;
$this -> rights [ $r ][ 1 ] = 'Read resources' ;
2014-01-02 07:07:43 +01:00
$this -> rights [ $r ][ 3 ] = 0 ;
$this -> rights [ $r ][ 4 ] = 'read' ;
$r ++ ;
2015-05-04 12:02:09 +02:00
$this -> rights [ $r ][ 0 ] = 63002 ;
$this -> rights [ $r ][ 1 ] = 'Create/Modify resources' ;
2014-01-02 07:07:43 +01:00
$this -> rights [ $r ][ 3 ] = 0 ;
$this -> rights [ $r ][ 4 ] = 'write' ;
$r ++ ;
2015-05-04 12:02:09 +02:00
$this -> rights [ $r ][ 0 ] = 63003 ;
2014-01-02 07:07:43 +01:00
$this -> rights [ $r ][ 1 ] = 'Delete resources' ;
$this -> rights [ $r ][ 3 ] = 0 ;
$this -> rights [ $r ][ 4 ] = 'delete' ;
$r ++ ;
2014-05-14 12:14:18 +02:00
2015-05-04 12:02:09 +02:00
$this -> rights [ $r ][ 0 ] = 63004 ;
2016-07-30 21:09:30 +02:00
$this -> rights [ $r ][ 1 ] = 'Link resources to agenda events' ;
2014-03-15 21:27:44 +01:00
$this -> rights [ $r ][ 3 ] = 0 ;
$this -> rights [ $r ][ 4 ] = 'link' ;
$r ++ ;
2014-01-02 07:07:43 +01:00
2016-09-30 13:02:13 +02:00
// Menus
//-------
2020-04-10 10:59:32 +02:00
$this -> menu = 1 ; // This module add menu entries. They are coded into menu manager.
2016-10-19 22:14:51 +02:00
2014-01-02 07:07:43 +01:00
// Main menu entries
$this -> menu = array (); // List of menus to add
$r = 0 ;
// Menus declaration
2020-04-10 10:59:32 +02:00
$this -> menu [ $r ] = array (
2014-01-02 07:07:43 +01:00
'fk_menu' => 'fk_mainmenu=tools' ,
'type' => 'left' ,
'titre' => 'MenuResourceIndex' ,
'mainmenu' => 'tools' ,
'leftmenu' => 'resource' ,
2014-05-14 12:14:18 +02:00
'url' => '/resource/list.php' ,
2014-03-15 21:27:44 +01:00
'langs' => 'resource' ,
2014-01-02 07:07:43 +01:00
'position' => 100 ,
'enabled' => '1' ,
'perms' => '$user->rights->resource->read' ,
'user' => 0
);
$r ++ ;
2014-05-14 12:14:18 +02:00
2020-04-10 10:59:32 +02:00
$this -> menu [ $r ++ ] = array (
2014-03-15 21:38:12 +01:00
'fk_menu' => 'fk_mainmenu=tools,fk_leftmenu=resource' , //On utilise les ancres définis dans le menu parent déclaré au dessus
'type' => 'left' , // Toujours un menu gauche
'titre' => 'MenuResourceAdd' ,
'mainmenu' => 'tools' ,
2017-10-24 09:58:32 +02:00
'leftmenu' => 'resource_add' ,
2017-11-21 11:45:37 +01:00
'url' => '/resource/card.php?action=create' ,
2014-03-15 21:38:12 +01:00
'langs' => 'resource' ,
'position' => 101 ,
'enabled' => '1' ,
2018-03-21 22:24:11 +01:00
'perms' => '$user->rights->resource->write' ,
2014-03-15 21:38:12 +01:00
'target' => '' ,
'user' => 0
);
2014-01-02 07:07:43 +01:00
2020-04-10 10:59:32 +02:00
$this -> menu [ $r ++ ] = array (
2015-11-22 12:23:10 +01:00
'fk_menu' => 'fk_mainmenu=tools,fk_leftmenu=resource' , //On utilise les ancres définis dans le menu parent déclaré au dessus
'type' => 'left' , // Toujours un menu gauche
'titre' => 'List' ,
'mainmenu' => 'tools' ,
2017-10-24 09:58:32 +02:00
'leftmenu' => 'resource_list' ,
2015-11-22 12:23:10 +01:00
'url' => '/resource/list.php' ,
'langs' => 'resource' ,
'position' => 102 ,
'enabled' => '1' ,
'perms' => '$user->rights->resource->read' ,
'target' => '' ,
'user' => 0
);
2016-10-19 22:14:51 +02:00
2014-01-02 07:07:43 +01:00
2017-04-18 15:25:04 +02:00
// Exports
//--------
2020-04-10 10:59:32 +02:00
$r = 0 ;
2017-10-24 09:58:32 +02:00
2017-04-18 15:25:04 +02:00
$r ++ ;
2020-04-10 10:59:32 +02:00
$this -> export_code [ $r ] = $this -> rights_class . '_' . $r ;
$this -> export_label [ $r ] = " ResourceSingular " ; // Translation key (used only if key ExportDataset_xxx_z not found)
$this -> export_permission [ $r ] = array ( array ( " resource " , " read " ));
2022-07-07 10:24:39 +02:00
$this -> export_fields_array [ $r ] = array ( 'r.rowid' => 'IdResource' , 'r.ref' => 'ResourceFormLabel_ref' , 'c.code' => 'ResourceTypeCode' , 'c.rowid' => 'ResourceType' , 'c.label' => 'ResourceTypeLabel' , 'r.description' => 'ResourceFormLabel_description' , 'r.note_private' => " NotePrivate " , 'r.note_public' => " NotePublic " , 'r.asset_number' => 'AssetNumber' , 'r.datec' => " DateCreation " , 'r.tms' => " DateLastModification " );
$this -> export_TypeFields_array [ $r ] = array ( 'r.rowid' => 'List:resource:ref' , 'r.ref' => 'Text' , 'r.asset_number' => 'Text' , 'r.description' => 'Text' , 'c.code' => 'Text' , 'c.rowid' => 'List:c_type_resource:label' , 'r.datec' => 'Date' , 'r.tms' => 'Date' , 'r.note_private' => 'Text' , 'r.note_public' => 'Text' );
$this -> export_entities_array [ $r ] = array ( 'r.rowid' => 'resource' , 'r.ref' => 'resource' , 'c.code' => 'resource' , 'c.rowid' => 'resource' , 'r.description' => 'resource' , 'r.note_private' => " resource " , 'r.resource' => " resource " , 'r.asset_number' => 'resource' , 'r.datec' => " resource " , 'r.tms' => " resource " );
2020-04-10 10:59:32 +02:00
$keyforselect = 'resource' ; $keyforelement = 'resource' ; $keyforaliasextra = 'extra' ;
2017-04-18 15:25:04 +02:00
include DOL_DOCUMENT_ROOT . '/core/extrafieldsinexport.inc.php' ;
2017-10-24 09:58:32 +02:00
2020-04-10 10:59:32 +02:00
$this -> export_dependencies_array [ $r ] = array ( 'resource' => array ( 'r.rowid' )); // We must keep this until the aggregate_array is used. To add unique key if we ask a field of a child to avoid the DISTINCT to discard them.
$this -> export_sql_start [ $r ] = 'SELECT DISTINCT ' ;
2020-11-12 14:11:59 +01:00
$this -> export_sql_end [ $r ] = ' FROM ' . MAIN_DB_PREFIX . 'resource as r' ;
2022-07-07 10:24:39 +02:00
$this -> export_sql_end [ $r ] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_type_resource as c ON c.code = r.fk_code_type_resource' ;
2020-11-12 14:11:59 +01:00
$this -> export_sql_end [ $r ] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'resource_extrafields as extra ON extra.fk_object = r.rowid' ;
2022-03-30 11:20:01 +02:00
$this -> export_sql_end [ $r ] .= ' WHERE r.entity IN (' . getEntity ( 'resource' ) . ')' ;
2017-10-24 09:58:32 +02:00
2017-04-18 15:25:04 +02:00
2022-07-07 10:24:39 +02:00
2017-04-18 15:25:04 +02:00
// Imports
//--------
2020-04-10 10:59:32 +02:00
$r = 0 ;
2017-10-24 09:58:32 +02:00
2017-04-18 15:25:04 +02:00
// Import list of third parties and attributes
$r ++ ;
2020-04-10 10:59:32 +02:00
$this -> import_code [ $r ] = $this -> rights_class . '_' . $r ;
$this -> import_label [ $r ] = 'ImportDataset_resource_1' ;
$this -> import_icon [ $r ] = 'resource' ;
$this -> import_entities_array [ $r ] = array (); // We define here only fields that use another icon that the one defined into import_icon
$this -> import_tables_array [ $r ] = array ( 'r' => MAIN_DB_PREFIX . 'resource' , 'extra' => MAIN_DB_PREFIX . 'resource_extrafields' ); // List of tables to insert into (insert done in same order)
$this -> import_fields_array [ $r ] = array ( 'r.ref' => " ResourceFormLabel_ref* " , 'r.fk_code_type_resource' => 'ResourceTypeCode' , 'r.description' => 'ResourceFormLabel_description' , 'r.note_private' => " NotePrivate " , 'r.note_public' => " NotePublic " , 'r.asset_number' => 'AssetNumber' , 'r.datec' => 'DateCreation' );
2017-04-18 15:25:04 +02:00
// Add extra fields
2021-10-31 14:33:44 +01:00
$sql = " SELECT name, label, fieldrequired FROM " . MAIN_DB_PREFIX . " extrafields WHERE type <> 'separate' AND elementtype = 'resource' AND entity IN (0, " . $conf -> entity . " ) " ;
2020-04-10 10:59:32 +02:00
$resql = $this -> db -> query ( $sql );
2017-04-18 15:25:04 +02:00
if ( $resql ) // This can fail when class is used on old database (during migration for example)
{
2020-04-10 10:59:32 +02:00
while ( $obj = $this -> db -> fetch_object ( $resql ))
2017-04-18 15:25:04 +02:00
{
2020-04-10 10:59:32 +02:00
$fieldname = 'extra.' . $obj -> name ;
$fieldlabel = ucfirst ( $obj -> label );
$this -> import_fields_array [ $r ][ $fieldname ] = $fieldlabel . ( $obj -> fieldrequired ? '*' : '' );
2017-04-18 15:25:04 +02:00
}
}
// End add extra fields
2020-04-10 10:59:32 +02:00
$this -> import_fieldshidden_array [ $r ] = array ( 'r.fk_user_author' => 'user->id' , 'extra.fk_object' => 'lastrowid-' . MAIN_DB_PREFIX . 'resource' ); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
$this -> import_convertvalue_array [ $r ] = array (
'r.fk_code_type_resource' => array ( 'rule' => 'fetchidfromcodeorlabel' , 'classfile' => '/core/class/ctyperesource.class.php' , 'class' => 'Ctyperesource' , 'method' => 'fetch' , 'dict' => 'DictionaryResourceType' ),
2017-04-18 15:25:04 +02:00
);
//$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t');
2020-04-10 10:59:32 +02:00
$this -> import_regex_array [ $r ] = array ( 's.datec' => '^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]( [0-9][0-9]:[0-9][0-9]:[0-9][0-9])?$' );
$this -> import_examplevalues_array [ $r ] = array ( 'r.ref' => " REF1 " , 'r.fk_code_type_resource' => " Code from dictionary resource type " , 'r.datec' => " 2017-01-01 or 2017-01-01 12:30:00 " );
$this -> import_updatekeys_array [ $r ] = array ( 'r.rf' => 'ResourceFormLabel_ref' );
2014-01-02 07:07:43 +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
*/
public function init ( $options = '' )
{
$sql = array ();
$result = $this -> loadTables ();
return $this -> _init ( $sql , $options );
}
/**
* Create tables , keys and data required by module
* Files llx_table1 . sql , llx_table1 . key . sql llx_data . sql with create table , create keys
* and create data commands must be stored in directory / resource / sql /
* This function is called by this -> init
*
* @ return int <= 0 if KO , > 0 if OK
*/
2019-08-05 13:41:25 +02:00
protected function loadTables ()
2014-01-02 07:07:43 +01:00
{
return $this -> _load_tables ( '/resource/sql/' );
}
}