dolibarr 25.0.0-alpha
modSubtotals.class.php
1<?php
2/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2010 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2011 Dimitri Mouillard <dmouillard@teclib.com>
6 * Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
7 * Copyright (C) 2018 Charlene Benke <charlie@patas-monkey.com>
8 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
9 * Copyright (C) 2026 Frédéric France <frederic.france@free.fr>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 * or see https://www.gnu.org/
24 */
25
34include_once DOL_DOCUMENT_ROOT."/core/modules/DolibarrModules.class.php";
35require_once DOL_DOCUMENT_ROOT.'/subtotals/class/commonsubtotal.class.php';
36
37if (!defined('SUBTOTALS_SPECIAL_CODE')) {
38 define('SUBTOTALS_SPECIAL_CODE', 81);
39}
40
45{
51 public function __construct($db)
52 {
53 $this->db = $db;
54
55 // Id for module (must be unique).
56 // Use here a free id (See in Home -> System information -> Dolibarr for list of used modules id).
57 $this->numero = SUBTOTALS_SPECIAL_CODE;
58 // Key text used to identify module (for permissions, menus, etc...)
59 $this->rights_class = 'subtotals';
60
61 // Family can be 'crm','financial','hr','projects','products','ecm','technic','other'
62 // It is used to group modules in module setup page
63 $this->family = "technic";
64 $this->module_position = '42';
65 // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
66 $this->name = preg_replace('/^mod/i', '', get_class($this));
67 // Module description, used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module)
68 $this->description = "SubTotalModuleDesc";
69 // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
70 $this->version = 'dolibarr';
71 // Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase)
72 $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
73 // Name of image file used for this module.
74 // If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue'
75 // If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module'
76 $this->picto = 'donation';
77
78 // Data directories to create when module is enabled.
79 // Example: this->dirs = array("/mymodule/temp");
80 $this->dirs = array("/subtotals/temp");
81
82 // Config pages
83 $this->config_page_url = array("subtotals.php");
84
85 // Dependencies
86 $this->hidden = false; // A condition to hide module
87 $this->depends = array(); // List of module class names as string that must be enabled if this module is enabled
88 $this->requiredby = array(); // List of module ids to disable if this one is disabled
89 $this->conflictwith = array(); // List of module class names as string this module is in conflict with
90 $this->phpmin = array(7, 0); // Minimum version of PHP required by module
91 $this->need_dolibarr_version = array(3, 0); // Minimum version of Dolibarr required by module
92 $this->langfiles = array("subtotals");
93
94 // Constants
95 // Example: $this->const=array(0=>array('MYMODULE_MYNEWCONST1','chaine','myvalue','This is a constant to add',0),
96 // 1=>array('MYMODULE_MYNEWCONST2','chaine','myvalue','This is another constant to add',0) );
97 $this->const = array(); // List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 0 or 'allentities')
98
99 // Dictionaries
100 $this->dictionaries = array(
101 'langs' => 'subtotals',
102 'tabname' => array("c_subtotals_titles", "c_subtotals_texts"),
103 'tablib' => array("SubtotalsPredefinedTitles", "SubtotalsPredefinedTexts"),
104 'tabsql' => array(
105 'SELECT rowid, code, label, active, entity FROM '.MAIN_DB_PREFIX.'c_subtotals_titles WHERE entity IN ('.getEntity('c_subtotals_titles').')',
106 'SELECT rowid, code, label, content, active, entity FROM '.MAIN_DB_PREFIX.'c_subtotals_texts WHERE entity IN ('.getEntity('c_subtotals_texts').')',
107 ),
108 'tabsqlsort' => array("label ASC", "label ASC"),
109 'tabfield' => array("code,label", "code,label,content"),
110 'tabfieldvalue' => array("code,label", "code,label,content"),
111 'tabfieldinsert' => array("code,label,entity", "code,label,content,entity"),
112 'tabrowid' => array("rowid", "rowid"),
113 'tabcond' => array(isModEnabled('subtotals'), isModEnabled('subtotals')),
114 'tabhelp' => array(array(), array()),
115 );
116
117 // Array to add new pages in new tabs
118 //$this->tabs[] = array('data'=>'user:+paidholidays:CPTitreMenu:holiday:$user->rights->holiday->read:/holiday/list.php?mainmenu=hrm&id=__ID__'); // We avoid to get one tab for each module. RH data are already in RH tab.
119 $this->tabs[] = array(); // To add a new tab identified by code tabname1
120
121 // Boxes
122 $this->boxes = array(); // List of boxes
123
124 // Permissions
125 $this->rights = array(); // Permission array used by this module
126
127 // Menus
128 //-------
129 $this->menu = 1; // This module add menu entries. They are coded into menu manager.
130
131 $this->module_parts = array('substitutions' => 1);
132 }
133
142 public function init($options = '')
143 {
144 $result = $this->_load_tables('/install/mysql/', 'subtotals');
145 if ($result < 0) {
146 return -1; // Do not activate module if error occurred while loading module SQL queries
147 }
148
149 // Permissions
150 $this->remove($options);
151
152 $sql = array(
153 // "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[0][2])."' AND type = 'holiday' AND entity = ".((int) $conf->entity),
154 // "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[0][2])."','holiday',".((int) $conf->entity).")"
155 );
156
157 return $this->_init($sql, $options);
158 }
159}
Class DolibarrModules.
_init($array_sql, $options='')
Enables a module.
_load_tables($reldir, $onlywithsuffix='')
Create tables and keys required by module:
Description and activation class for module subtotals.
__construct($db)
Constructor.
init($options='')
Function called when module is enabled.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
isModEnabled($module)
Is Dolibarr module enabled.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:133