2015-01-26 16:21:35 +00:00
< ? php
/* Copyright ( C ) 2003 - 2004 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2015-03-09 20:20:56 +00:00
* Copyright ( C ) 2004 - 2015 Laurent Destailleur < eldy @ users . sourceforge . net >
2015-01-26 16:21:35 +00:00
* Copyright ( C ) 2004 Sebastien Di Cintio < sdicintio @ ressource - toi . org >
* Copyright ( C ) 2004 Benoit Mortier < benoit . mortier @ opensides . be >
2018-10-27 12:43:12 +00:00
* Copyright ( C ) 2005 - 2012 Regis Houssin < regis . houssin @ inodbox . com >
2015-01-26 16:21:35 +00:00
* Copyright ( C ) 2012 Juanjo Menent < jmenent @ 2 byte . es >
2026-04-12 09:59:56 +00:00
* Copyright ( C ) 2024 - 2026 Frédéric France < frederic . france @ free . fr >
2015-01-26 16:21:35 +00: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 19:55:30 +00:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2015-01-26 16:21:35 +00:00
*/
/**
2015-11-15 17:23:42 +00:00
* \defgroup supplier_proposal Module supplier_proposal
2015-03-09 20:20:56 +00:00
* \brief Module to request supplier price proposals
2016-01-25 12:31:43 +00:00
*
2015-11-15 17:23:42 +00:00
* \file htdocs / core / modules / modSupplierProposal . class . php
* \ingroup supplier_proposal
2021-03-20 12:55:43 +00:00
* \brief Description and activation file for the module supplier proposal
2015-01-26 16:21:35 +00:00
*/
2020-04-10 08:59:32 +00:00
include_once DOL_DOCUMENT_ROOT . '/core/modules/DolibarrModules.class.php' ;
2015-01-26 16:21:35 +00:00
/**
2018-07-01 21:57:54 +00:00
* Class to describe and enable module SupplierProposal
2015-01-26 16:21:35 +00:00
*/
2015-11-15 17:23:42 +00:00
class modSupplierProposal extends DolibarrModules
2015-01-26 16:21:35 +00:00
{
/**
* Constructor . Define names , constants , directories , boxes , permissions
*
* @ param DoliDB $db Database handler
*/
2019-02-25 19:35:59 +00:00
public function __construct ( $db )
2015-01-26 16:21:35 +00:00
{
global $conf ;
$this -> db = $db ;
2015-03-04 16:54:43 +00:00
$this -> numero = 1120 ;
2015-01-26 16:21:35 +00:00
2016-02-19 18:20:21 +00:00
$this -> family = " srm " ;
2026-04-07 12:30:17 +00:00
$this -> module_position = '11' ;
2019-01-27 10:55:16 +00:00
$this -> name = preg_replace ( '/^mod/i' , '' , get_class ( $this ));
2015-11-15 17:23:42 +00:00
$this -> description = " supplier_proposalDESC " ;
2015-01-26 16:21:35 +00:00
2016-01-25 11:33:38 +00:00
$this -> version = 'dolibarr' ;
2015-01-26 16:21:35 +00:00
$this -> const_name = 'MAIN_MODULE_' . strtoupper ( $this -> name );
2020-04-10 08:59:32 +00:00
$this -> picto = 'supplier_proposal' ;
2019-02-25 19:35:59 +00:00
2018-07-10 12:57:23 +00:00
// Data directories to create when module is enabled.
2026-04-12 09:59:56 +00:00
$this -> dirs = [];
2019-02-25 19:35:59 +00:00
2023-12-04 11:07:31 +00:00
// Config pages. Put here list of php page names stored in admin directory used to setup module.
2026-04-07 00:00:44 +00:00
$this -> config_page_url = array ( " supplier_proposal.php@supplier_proposal " );
2018-07-10 12:57:23 +00:00
// Dependencies
2020-04-10 08:59:32 +00:00
$this -> hidden = false ; // A condition to hide module
2026-04-07 12:30:17 +00:00
if ( getDolGlobalString ( 'MAIN_USE_NEW_SUPPLIERMOD' )) {
$this -> depends = array ( 'modSupplierOrder' ); // List of module class names as string that must be enabled if this module is enabled
} else {
$this -> depends = array ( 'modFournisseur' ); // List of module class names as string that must be enabled if this module is enabled
}
2026-04-12 09:59:56 +00:00
$this -> requiredby = []; // List of module ids to disable if this one is disabled
$this -> conflictwith = []; // List of module class names as string this module is in conflict with
2015-11-15 17:23:42 +00:00
$this -> langfiles = array ( " supplier_proposal " );
2015-01-26 16:21:35 +00:00
// Constants
2026-04-12 09:59:56 +00:00
$this -> const = [
[
" SUPPLIER_PROPOSAL_ADDON_PDF " ,
" chaine " ,
" aurore " ,
'Name of submodule to generate PDF for supplier quotation request' ,
0 ,
],
[
" SUPPLIER_PROPOSAL_ADDON " ,
" chaine " ,
" mod_supplier_proposal_marbre " ,
'Name of submodule to number supplier quotation request' ,
0 ,
],
[
" SUPPLIER_PROPOSAL_ADDON_PDF_ODT_PATH " ,
" chaine " ,
" DOL_DATA_ROOT " . ( $conf -> entity > 1 ? '/' . $conf -> entity : '' ) . " /doctemplates/supplier_proposals " ,
" " ,
0 ,
],
];
2015-01-26 16:21:35 +00:00
// Boxes
2026-04-12 09:59:56 +00:00
$this -> boxes = [];
2015-01-26 16:21:35 +00:00
// Permissions
2026-04-12 09:59:56 +00:00
$this -> rights = [];
2015-11-15 17:23:42 +00:00
$this -> rights_class = 'supplier_proposal' ;
2020-04-10 08:59:32 +00:00
$r = 0 ;
2015-01-26 16:21:35 +00:00
$r ++ ;
$this -> rights [ $r ][ 0 ] = $this -> numero + $r ; // id de la permission
2015-03-04 16:54:43 +00:00
$this -> rights [ $r ][ 1 ] = 'Read supplier proposals' ; // libelle de la permission
2024-01-13 18:48:20 +00:00
$this -> rights [ $r ][ 3 ] = 0 ; // La permission est-elle une permission par default
2015-01-27 15:53:27 +00:00
$this -> rights [ $r ][ 4 ] = 'lire' ;
2015-03-04 16:54:43 +00:00
2015-01-26 16:21:35 +00:00
$r ++ ;
$this -> rights [ $r ][ 0 ] = $this -> numero + $r ; // id de la permission
2015-03-04 16:54:43 +00:00
$this -> rights [ $r ][ 1 ] = 'Create/modify supplier proposals' ; // libelle de la permission
2024-01-13 18:48:20 +00:00
$this -> rights [ $r ][ 3 ] = 0 ; // La permission est-elle une permission par default
2015-01-27 15:53:27 +00:00
$this -> rights [ $r ][ 4 ] = 'creer' ;
2015-03-04 16:54:43 +00:00
2015-01-26 16:21:35 +00:00
$r ++ ;
$this -> rights [ $r ][ 0 ] = $this -> numero + $r ; // id de la permission
2015-03-04 16:54:43 +00:00
$this -> rights [ $r ][ 1 ] = 'Validate supplier proposals' ; // libelle de la permission
2024-01-13 18:48:20 +00:00
$this -> rights [ $r ][ 3 ] = 0 ; // La permission est-elle une permission par default
2016-01-25 11:33:38 +00:00
$this -> rights [ $r ][ 4 ] = 'validate_advance' ;
2015-03-04 16:54:43 +00:00
2015-01-26 16:21:35 +00:00
$r ++ ;
$this -> rights [ $r ][ 0 ] = $this -> numero + $r ; // id de la permission
2025-02-23 18:42:49 +00:00
$this -> rights [ $r ][ 1 ] = 'Send supplier proposals' ; // libelle de la permission
2024-01-13 18:48:20 +00:00
$this -> rights [ $r ][ 3 ] = 0 ; // La permission est-elle une permission par default
2020-10-31 13:32:18 +00:00
$this -> rights [ $r ][ 4 ] = 'send_advance' ;
2015-03-04 16:54:43 +00:00
2015-01-26 16:21:35 +00:00
$r ++ ;
$this -> rights [ $r ][ 0 ] = $this -> numero + $r ; // id de la permission
2015-03-04 16:54:43 +00:00
$this -> rights [ $r ][ 1 ] = 'Delete supplier proposals' ; // libelle de la permission
2024-01-13 18:48:20 +00:00
$this -> rights [ $r ][ 3 ] = 0 ; // La permission est-elle une permission par default
2015-01-27 15:53:27 +00:00
$this -> rights [ $r ][ 4 ] = 'supprimer' ;
2015-03-04 16:54:43 +00:00
2015-01-29 09:44:23 +00:00
$r ++ ;
$this -> rights [ $r ][ 0 ] = $this -> numero + $r ; // id de la permission
2015-03-04 16:54:43 +00:00
$this -> rights [ $r ][ 1 ] = 'Close supplier price requests' ; // libelle de la permission
2024-01-13 18:48:20 +00:00
$this -> rights [ $r ][ 3 ] = 0 ; // La permission est-elle une permission par default
2015-01-29 09:44:23 +00:00
$this -> rights [ $r ][ 4 ] = 'cloturer' ;
2015-03-04 16:54:43 +00:00
2021-02-23 21:03:23 +00:00
// Main menu entries
2026-04-12 09:59:56 +00:00
$this -> menu = []; // List of menus to add
2020-04-10 08:59:32 +00:00
$r = 0 ;
2015-01-26 16:21:35 +00: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
*
2020-10-31 13:32:18 +00:00
* @ param string $options Options when enabling module ( '' , 'noboxes' )
2015-01-26 16:21:35 +00:00
* @ return int 1 if OK , 0 if KO
*/
2020-10-31 13:32:18 +00:00
public function init ( $options = '' )
2015-01-26 16:21:35 +00:00
{
2020-04-10 08:59:32 +00:00
global $conf , $langs ;
2015-01-28 14:37:52 +00:00
// Remove permissions and default values
$this -> remove ( $options );
2026-04-12 09:59:56 +00:00
// ODT template
2020-04-10 08:59:32 +00:00
$src = DOL_DOCUMENT_ROOT . '/install/doctemplates/supplier_proposals/template_supplier_proposal.odt' ;
2025-02-13 17:20:47 +00:00
$dirodt = DOL_DATA_ROOT . ( $conf -> entity > 1 ? '/' . $conf -> entity : '' ) . '/doctemplates/supplier_proposals' ;
2020-04-10 08:59:32 +00:00
$dest = $dirodt . '/template_supplier_proposal.odt' ;
2015-01-28 14:37:52 +00:00
2021-02-23 21:03:23 +00:00
if ( file_exists ( $src ) && ! file_exists ( $dest )) {
2015-01-28 14:37:52 +00:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
dol_mkdir ( $dirodt );
2024-09-22 23:59:14 +00:00
$result = dol_copy ( $src , $dest , '0' , 0 );
2021-02-23 21:03:23 +00:00
if ( $result < 0 ) {
2015-01-28 14:37:52 +00:00
$langs -> load ( " errors " );
2020-04-10 08:59:32 +00:00
$this -> error = $langs -> trans ( 'ErrorFailToCopyFile' , $src , $dest );
2015-01-28 14:37:52 +00:00
return 0 ;
}
}
$sql = array (
2021-08-27 20:42:04 +00:00
" DELETE FROM " . MAIN_DB_PREFIX . " document_model WHERE nom = ' " . $this -> db -> escape ( $this -> const [ 0 ][ 2 ]) . " ' AND type = 'supplier_proposal' AND entity = " . (( int ) $conf -> entity ),
" INSERT INTO " . MAIN_DB_PREFIX . " document_model (nom, type, entity) VALUES(' " . $this -> db -> escape ( $this -> const [ 0 ][ 2 ]) . " ','supplier_proposal', " . (( int ) $conf -> entity ) . " ) " ,
2015-01-28 14:37:52 +00:00
);
2015-01-26 16:21:35 +00:00
return $this -> _init ( $sql , $options );
}
2018-02-25 09:55:02 +00:00
2015-11-15 17:23:42 +00:00
/**
* Function called when module is disabled .
* Remove from database constants , boxes and permissions from Dolibarr database .
* Data directories are not deleted
*
* @ param string $options Options when enabling module ( '' , 'noboxes' )
* @ return int 1 if OK , 0 if KO
*/
public function remove ( $options = '' )
{
2020-10-31 13:32:18 +00:00
$sql = array (
" DELETE FROM " . MAIN_DB_PREFIX . " rights_def WHERE module = 'askpricesupplier' " // To delete/clean deprecated entries
);
2018-02-25 09:55:02 +00:00
2020-10-31 13:32:18 +00:00
return $this -> _remove ( $sql , $options );
2018-02-25 09:55:02 +00:00
}
2019-02-03 14:21:21 +00:00
}