dolibarr 25.0.0-alpha
modMyModule.class.php
1<?php
2/* Copyright (C) 2004-2018 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2018-2019 Nicolas ZABOURI <info@inovea-conseil.com>
4 * Copyright (C) 2019-2024 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) ---Replace with your own copyright and developer email---
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
29include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
30require_once DOL_DOCUMENT_ROOT . '/core/lib/functions.lib.php';
31
32
37{
43 public function __construct($db)
44 {
45 global $conf, $langs;
46
47 $this->db = $db;
48
49 // Id for module (must be unique).
50 // Use here a free id (See in Home -> System information -> Dolibarr for list of used modules id).
51 $this->numero = 500000; // TODO Go on page https://wiki.dolibarr.org/index.php/List_of_modules_id to reserve an id number for your module
52
53 // Key text used to identify module (for permissions, menus, etc...)
54 $this->rights_class = 'mymodule';
55
56 // Family can be 'base' (core modules),'crm','financial','hr','projects','products','ecm','technic' (transverse modules),'interface' (link with external tools),'other','...'
57 // It is used to group modules by family in module setup page
58 $this->family = "other";
59
60 // Module position in the family on 2 digits ('01', '10', '20', ...)
61 $this->module_position = '90';
62
63 // Gives the possibility for the module, to provide his own family info and position of this family (Overwrite $this->family and $this->module_position. Avoid this)
64 //$this->familyinfo = array('myownfamily' => array('position' => '01', 'label' => $langs->trans("MyOwnFamily")));
65 // Module label (no space allowed), used if translation string 'ModuleMyModuleName' not found (MyModule is name of module).
66 $this->name = preg_replace('/^mod/i', '', get_class($this));
67
68 // DESCRIPTION_FLAG
69 // Module description, used if translation string 'ModuleMyModuleDesc' not found (MyModule is name of module).
70 $this->description = "MyModuleDescription";
71 // Used only if file README.md and README-LL.md not found.
72 $this->descriptionlong = "MyModuleDescription";
73
74 // Enables the module for all entities (Multicompany)
75 // Can be enabled / disabled only from the main company with superadmin account
76 // $this->core_enabled = 1;
77
78 // Author
79 $this->editor_name = 'Editor name';
80 $this->editor_url = 'https://www.example.com'; // Must be an external online web site
81 $this->editor_squarred_logo = ''; // Must be image filename into the module/img directory followed with @modulename. Example: 'myimage.png@mymodule'
82
83 // Possible values for version are: 'development', 'experimental', 'dolibarr', 'dolibarr_deprecated', 'experimental_deprecated' or a version string like 'x.y.z'
84 $this->version = '1.0';
85 // Url to the file with your last numberversion of this module
86 //$this->url_last_version = 'http://www.example.com/versionmodule.txt';
87
88 // Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase)
89 $this->const_name = 'MAIN_MODULE_'.dol_strtoupper($this->name);
90
91 // Name of image file used for this module.
92 // If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue'
93 // If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module'
94 // To use a supported fa-xxx css style of font awesome, use this->picto='xxx'
95 $this->picto = 'generic';
96
97 // Define some features supported by module (triggers, login, substitutions, menus, css, etc...)
98 // If your module use the parameter "core_enabled" and you would like to activate the parts in all entities (Multicompany):
99 // 'xxxxxx' => array(
100 // 'data' => 1 or '/mymodule/xxx/mymodule.xxx.php',
101 // 'entity' => '0'
102 // ),
103 // 'hooks' => array(
104 // 'data' => array(
105 // 'hookcontext1',
106 // 'hookcontext2',
107 // )
108 // 'entity' => '0'
109 // )
110 $this->module_parts = array(
111 // Set this to 1 if module has its own trigger directory (core/triggers)
112 'triggers' => 0,
113 // Set this to 1 if module has its own login method file (core/login)
114 'login' => 0,
115 // Set this to 1 if module has its own substitution function file (core/substitutions)
116 'substitutions' => 0,
117 // Set this to 1 if module has its own menus handler directory (core/menus)
118 'menus' => 0,
119 // Set this to 1 if module overwrite template dir (core/tpl)
120 'tpl' => 0,
121 // Set this to 1 if module has its own barcode directory (core/modules/barcode)
122 'barcode' => 0,
123 // Set this to 1 if module has its own models directory (core/modules/xxx)
124 'models' => 0,
125 // Set this to 1 if module has its own printing directory (core/modules/printing)
126 'printing' => 0,
127 // Set this to 1 if module has its own theme directory (theme)
128 'theme' => 0,
129 // Set this to relative path of css file if module has its own css file
130 'css' => array(
131 // '/mymodule/css/mymodule.css.php',
132 ),
133 // Set this to relative path of js file if module must load a js on all pages
134 'js' => array(
135 // '/mymodule/js/mymodule.js.php',
136 ),
137 // Set here all hooks context managed by module. To find available hook context, make a "grep -r '>initHooks(' *" on source code. You can also set hook context to 'all'
138 /* BEGIN MODULEBUILDER HOOKSCONTEXTS */
139 'hooks' => array(
140 // 'hookcontext1',
141 // 'hookcontext2',
142 ),
143 /* END MODULEBUILDER HOOKSCONTEXTS */
144 // Set this to 1 if features of module are opened to external users
145 'moduleforexternal' => 0,
146 // Set this to 1 if the module provides a website template into doctemplates/websites/website_template-mytemplate
147 'websitetemplates' => 0,
148 // Set this to 1 if the module provides a captcha driver
149 'captcha' => 0
150 );
151
152 // Data directories to create when module is enabled.
153 // Example: this->dirs = array("/mymodule/temp","/mymodule/subdir");
154 $this->dirs = array("/mymodule/temp");
155
156 // Config pages. Put here list of php page, stored into mymodule/admin directory, to use to setup module.
157 $this->config_page_url = array("setup.php@mymodule");
158
159 // Dependencies
160 // A condition to hide module
161 $this->hidden = getDolGlobalInt('MODULE_MYMODULE_DISABLED'); // A condition to disable module;
162 // List of module class names that must be enabled if this module is enabled. Example: array('always'=>array('modModuleToEnable1','modModuleToEnable2'), 'FR'=>array('modModuleToEnableFR')...)
163 $this->depends = array();
164 // List of module class names to disable if this one is disabled. Example: array('modModuleToDisable1', ...)
165 $this->requiredby = array();
166 // List of module class names this module is in conflict with. Example: array('modModuleToDisable1', ...)
167 $this->conflictwith = array();
168
169 // The language file dedicated to your module
170 $this->langfiles = array("mymodule@mymodule");
171
172 // Prerequisites
173 $this->phpmin = array(7, 2); // Minimum version of PHP required by module
174 // $this->phpmax = array(8, 0); // Maximum version of PHP required by module
175 $this->need_dolibarr_version = array(19, -3); // Minimum version of Dolibarr required by module
176 // $this->max_dolibarr_version = array(19, -3); // Maximum version of Dolibarr required by module
177 $this->need_javascript_ajax = 0;
178
179 // Messages at activation
180 $this->warnings_activation = array(); // Warning to show when we activate a module. Example: array('always'='text') or array('FR'='textfr','MX'='textmx'...)
181 $this->warnings_activation_ext = array(); // Warning to show when we activate a module if another module is on. Example: array('modOtherModule' => array('always'=>'text')) or array('always' => array('FR'=>'textfr','MX'=>'textmx'...))
182 //$this->automatic_activation = array('FR'=>'MyModuleWasAutomaticallyActivatedBecauseOfYourCountryChoice');
183 //$this->always_enabled = false; // If true, can't be disabled. Value true is reserved for core modules. Not allowed for external modules.
184
185 // Constants
186 // List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive)
187 // Example: $this->const=array(1 => array('MYMODULE_MYNEWCONST1', 'chaine', 'myvalue', 'This is a constant to add', 1),
188 // 2 => array('MYMODULE_MYNEWCONST2', 'chaine', 'myvalue', 'This is another constant to add', 0, 'current', 1)
189 // );
190 $this->const = array();
191
192 // Some keys to add into the overwriting translation tables
193 /*$this->overwrite_translation = array(
194 'en_US:ParentCompany'=>'Parent company or reseller',
195 'fr_FR:ParentCompany'=>'Maison mère ou revendeur'
196 )*/
197
198 if (!isModEnabled("mymodule")) {
199 $conf->mymodule = new stdClass();
200 $conf->mymodule->enabled = 0;
201 }
202
203 // Array to add new pages in new tabs
204 /* BEGIN MODULEBUILDER TABS */
205 // Don't forget to deactivate/reactivate your module to test your changes
206 $this->tabs = array();
207 /* END MODULEBUILDER TABS */
208 // Example:
209 // To add a new tab identified by code tabname1
210 // $this->tabs[] = array('data' => 'objecttype:+tabname1:Title1:mylangfile@mymodule:$user->hasRight('mymodule', 'myobject', 'read'):/mymodule/mynewtab1.php?id=__ID__');
211 // To add another new tab identified by code tabname2. Label will be result of calling all substitution functions on 'Title2' key.
212 // $this->tabs[] = array('data' => 'objecttype:+tabname2:SUBSTITUTION_Title2:mylangfile@mymodule:$user->hasRight('othermodule', 'otherobject', 'read'):/mymodule/mynewtab2.php?id=__ID__',
213 // To remove an existing tab identified by code tabname
214 // $this->tabs[] = array('data' => 'objecttype:-tabname:NU:conditiontoremove');
215 //
216 // Where objecttype can be
217 // 'categories_x' to add a tab in category view (replace 'x' by type of category (0=product, 1=supplier, 2=customer, 3=member)
218 // 'contact' to add a tab in contact view
219 // 'contract' to add a tab in contract view
220 // 'delivery' to add a tab in delivery view
221 // 'group' to add a tab in group view
222 // 'intervention' to add a tab in intervention view
223 // 'invoice' to add a tab in customer invoice view
224 // 'supplier_invoice' to add a tab in supplier invoice view
225 // 'member' to add a tab in foundation member view
226 // 'opensurveypoll' to add a tab in opensurvey poll view
227 // 'order' to add a tab in sale order view
228 // 'supplier_order' to add a tab in supplier order view
229 // 'payment' to add a tab in payment view
230 // 'supplier_payment' to add a tab in supplier payment view
231 // 'product' to add a tab in product view
232 // 'propal' to add a tab in propal view
233 // 'project' to add a tab in project view
234 // 'stock' to add a tab in stock view
235 // 'thirdparty' to add a tab in third party view
236 // 'user' to add a tab in user view
237
238
239 // Dictionaries
240 /* Example:
241 $this->dictionaries=array(
242 'langs' => 'mymodule@mymodule',
243 // List of tables we want to see into dictionary editor
244 'tabname' => array("table1", "table2", "table3"),
245 // Label of tables
246 'tablib' => array("Table1", "Table2", "Table3"),
247 // Request to select fields
248 'tabsql' => array('SELECT f.rowid as rowid, f.code, f.label, f.active FROM '.$this->db->prefix().'table1 as f', 'SELECT f.rowid as rowid, f.code, f.label, f.active FROM '.$this->db->prefix().'table2 as f', 'SELECT f.rowid as rowid, f.code, f.label, f.active FROM '.$this->db->prefix().'table3 as f'),
249 // Sort order
250 'tabsqlsort' => array("label ASC", "label ASC", "label ASC"),
251 // List of fields (result of select to show dictionary)
252 'tabfield' => array("code,label", "code,label", "code,label"),
253 // List of fields (list of fields to edit a record)
254 'tabfieldvalue' => array("code,label", "code,label", "code,label"),
255 // List of fields (list of fields for insert)
256 'tabfieldinsert' => array("code,label", "code,label", "code,label"),
257 // Name of columns with primary key (try to always name it 'rowid')
258 'tabrowid' => array("rowid", "rowid", "rowid"),
259 // Condition to show each dictionary
260 'tabcond' => array(isModEnabled('mymodule'), isModEnabled('mymodule'), isModEnabled('mymodule')),
261 // Tooltip for every fields of dictionaries: DO NOT PUT AN EMPTY ARRAY
262 'tabhelp' => array(array('code' => $langs->trans('CodeTooltipHelp'), 'field2' => 'field2tooltip'), array('code' => $langs->trans('CodeTooltipHelp'), 'field2' => 'field2tooltip'), ...),
263 );
264 */
265 /* BEGIN MODULEBUILDER DICTIONARIES */
266 $this->dictionaries = array();
267 /* END MODULEBUILDER DICTIONARIES */
268
269 // Boxes/Widgets
270 // Add here list of php file(s) stored in mymodule/core/boxes that contains a class to show a widget.
271 /* BEGIN MODULEBUILDER WIDGETS */
272 $this->boxes = array(
273 // 0 => array(
274 // 'file' => 'mymodulewidget1.php@mymodule',
275 // 'note' => 'Widget provided by MyModule',
276 // 'enabledbydefaulton' => 'Home',
277 // ),
278 // ...
279 );
280 /* END MODULEBUILDER WIDGETS */
281
282 // Cronjobs (List of cron jobs entries to add when module is enabled)
283 // unit_frequency must be 60 for minute, 3600 for hour, 86400 for day, 604800 for week
284 /* BEGIN MODULEBUILDER CRON */
285 $this->cronjobs = array(
286 // 0 => array(
287 // 'label' => 'MyJob label',
288 // 'jobtype' => 'method',
289 // 'class' => '/mymodule/class/myobject.class.php',
290 // 'objectname' => 'MyObject',
291 // 'method' => 'doScheduledJob',
292 // 'parameters' => '',
293 // 'comment' => 'Comment',
294 // 'frequency' => 2,
295 // 'unitfrequency' => 3600,
296 // 'status' => 0,
297 // 'test' => 'isModEnabled("mymodule")',
298 // 'priority' => 50,
299 // ),
300 );
301 /* END MODULEBUILDER CRON */
302 // Example: $this->cronjobs=array(
303 // 0=>array('label'=>'My label', 'jobtype'=>'method', 'class'=>'/dir/class/file.class.php', 'objectname'=>'MyClass', 'method'=>'myMethod', 'parameters'=>'param1, param2', 'comment'=>'Comment', 'frequency'=>2, 'unitfrequency'=>3600, 'status'=>0, 'test'=>'isModEnabled("mymodule")', 'priority'=>50),
304 // 1=>array('label'=>'My label', 'jobtype'=>'command', 'command'=>'', 'parameters'=>'param1, param2', 'comment'=>'Comment', 'frequency'=>1, 'unitfrequency'=>3600*24, 'status'=>0, 'test'=>'isModEnabled("mymodule")', 'priority'=>50)
305 // );
306
307 // Permissions provided by this module
308 $this->rights = array();
309 $r = 0;
310 // Add here entries to declare new permissions
311 /* BEGIN MODULEBUILDER PERMISSIONS */
312 /*
313 $o = 1;
314 $this->rights[$r][0] = $this->numero . sprintf("%02d", ($o * 10) + 1); // Permission id (must not be already used)
315 $this->rights[$r][1] = 'Read objects of MyModule'; // Permission label
316 $this->rights[$r][4] = 'myobject';
317 $this->rights[$r][5] = 'read'; // In php code, permission will be checked by test if ($user->hasRight('mymodule', 'myobject', 'read'))
318 $r++;
319 $this->rights[$r][0] = $this->numero . sprintf("%02d", ($o * 10) + 2); // Permission id (must not be already used)
320 $this->rights[$r][1] = 'Create/Update objects of MyModule'; // Permission label
321 $this->rights[$r][4] = 'myobject';
322 $this->rights[$r][5] = 'write'; // In php code, permission will be checked by test if ($user->hasRight('mymodule', 'myobject', 'write'))
323 $r++;
324 $this->rights[$r][0] = $this->numero . sprintf("%02d", ($o * 10) + 3); // Permission id (must not be already used)
325 $this->rights[$r][1] = 'Delete objects of MyModule'; // Permission label
326 $this->rights[$r][4] = 'myobject';
327 $this->rights[$r][5] = 'delete'; // In php code, permission will be checked by test if ($user->hasRight('mymodule', 'myobject', 'delete'))
328 $r++;
329 */
330 /* END MODULEBUILDER PERMISSIONS */
331
332
333 // Main menu entries to add
334 $this->menu = array();
335 $r = 0;
336 // Add here entries to declare new menus
337 /* BEGIN MODULEBUILDER TOPMENU */
338 $this->menu[$r++] = array(
339 'fk_menu' => '', // Will be stored into mainmenu + leftmenu. Use '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
340 'type' => 'top', // This is a Top menu entry
341 'titre' => 'ModuleMyModuleName',
342 'prefix' => img_picto('', $this->picto, 'class="pictofixedwidth valignmiddle"'),
343 'mainmenu' => 'mymodule',
344 'leftmenu' => '',
345 'url' => '/mymodule/mymoduleindex.php',
346 'langs' => 'mymodule@mymodule', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
347 'position' => 1000 + $r,
348 'enabled' => "isModEnabled('mymodule')", // Define condition to show or hide menu entry. Use "isModEnabled('mymodule')" if entry must be visible if module is enabled (those quote marks are importants).
349 'perms' => '1', // Use 'perms'=>'$user->hasRight("mymodule", "myobject", "read")' if you want your menu with a permission rules
350 'target' => '',
351 'user' => 2, // 0=Menu for internal users, 1=external users, 2=both
352 );
353 /* END MODULEBUILDER TOPMENU */
354
355 /* BEGIN MODULEBUILDER LEFTMENU MYOBJECT */
356 /*
357 $this->menu[$r++]=array(
358 'fk_menu' => 'fk_mainmenu=mymodule', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
359 'type' => 'left', // This is a Left menu entry
360 'titre' => 'MyObject',
361 'prefix' => img_picto('', $this->picto, 'class="pictofixedwidth valignmiddle paddingright"'),
362 'mainmenu' => 'mymodule',
363 'leftmenu' => 'myobject',
364 'url' => '/mymodule/mymoduleindex.php',
365 'langs' => 'mymodule@mymodule', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
366 'position' => 1000 + $r,
367 'enabled' => "isModEnabled('mymodule')", // Define condition to show or hide menu entry. Use isModEnabled("mymodule") if entry must be visible if module is enabled.
368 'perms' => '$user->hasRight("mymodule", "myobject", "read")',
369 'target' => '',
370 'user' => 2, // 0=Menu for internal users, 1=external users, 2=both
371 'object' => 'MyObject'
372 );
373 $this->menu[$r++]=array(
374 'fk_menu' => 'fk_mainmenu=mymodule,fk_leftmenu=myobject', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
375 'type' => 'left', // This is a Left menu entry
376 'titre' => 'New_MyObject',
377 'mainmenu' => 'mymodule',
378 'leftmenu' => 'mymodule_myobject_new',
379 'url' => '/mymodule/myobject_card.php?action=create',
380 'langs' => 'mymodule@mymodule', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
381 'position' => 1000 + $r,
382 'enabled' => "isModEnabled('mymodule')", // Define condition to show or hide menu entry. Use isModEnabled("mymodule") if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
383 'perms' => '$user->hasRight("mymodule", "myobject", "write")'
384 'target' => '',
385 'user' => 2, // 0=Menu for internal users, 1=external users, 2=both
386 'object' => 'MyObject'
387 );
388 $this->menu[$r++]=array(
389 'fk_menu' => 'fk_mainmenu=mymodule,fk_leftmenu=myobject', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
390 'type' => 'left', // This is a Left menu entry
391 'titre' => 'List_MyObject',
392 'mainmenu' => 'mymodule',
393 'leftmenu' => 'mymodule_myobject_list',
394 'url' => '/mymodule/myobject_list.php',
395 'langs' => 'mymodule@mymodule', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
396 'position' => 1000 + $r,
397 'enabled' => "isModEnabled('mymodule')", // Define condition to show or hide menu entry. Use isModEnabled("mymodule") if entry must be visible if module is enabled.
398 'perms' => '$user->hasRight("mymodule", "myobject", "read")'
399 'target' => '',
400 'user' => 2, // 0=Menu for internal users, 1=external users, 2=both
401 'object' => 'MyObject'
402 );
403 */
404 /* END MODULEBUILDER LEFTMENU MYOBJECT */
405
406
407 // Exports profiles provided by this module
408 $r = 0;
409 /* BEGIN MODULEBUILDER EXPORT MYOBJECT */
410 /*
411 $langs->load("mymodule@mymodule");
412 $this->export_code[$r] = $this->rights_class.'_'.$r;
413 $this->export_label[$r] = 'MyObjectLines'; // Translation key (used only if key ExportDataset_xxx_z not found)
414 $this->export_icon[$r] = $this->picto;
415 // Define $this->export_fields_array, $this->export_TypeFields_array and $this->export_entities_array
416 $keyforclass = 'MyObject'; $keyforclassfile='/mymodule/class/myobject.class.php'; $keyforelement='myobject@mymodule';
417 include DOL_DOCUMENT_ROOT.'/core/commonfieldsinexport.inc.php';
418 //$this->export_fields_array[$r]['t.fieldtoadd']='FieldToAdd'; $this->export_TypeFields_array[$r]['t.fieldtoadd']='Text';
419 //unset($this->export_fields_array[$r]['t.fieldtoremove']);
420 //$keyforclass = 'MyObjectLine'; $keyforclassfile='/mymodule/class/myobject.class.php'; $keyforelement='myobjectline@mymodule'; $keyforalias='tl';
421 //include DOL_DOCUMENT_ROOT.'/core/commonfieldsinexport.inc.php';
422 $keyforselect='myobject'; $keyforaliasextra='extra'; $keyforelement='myobject@mymodule';
423 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
424 //$keyforselect='myobjectline'; $keyforaliasextra='extraline'; $keyforelement='myobjectline@mymodule';
425 //include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
426 //$this->export_dependencies_array[$r] = array('myobjectline' => array('tl.rowid','tl.ref')); // To force to activate one or several fields if we select some fields that need same (like to select a unique key if we ask a field of a child to avoid the DISTINCT to discard them, or for computed field than need several other fields)
427 //$this->export_special_array[$r] = array('t.field' => '...');
428 //$this->export_examplevalues_array[$r] = array('t.field' => 'Example');
429 //$this->export_help_array[$r] = array('t.field' => 'FieldDescHelp');
430 $this->export_sql_start[$r]='SELECT DISTINCT ';
431 $this->export_sql_end[$r] =' FROM '.$this->db->prefix().'mymodule_myobject as t';
432 //$this->export_sql_end[$r] .=' LEFT JOIN '.$this->db->prefix().'mymodule_myobject_line as tl ON tl.fk_myobject = t.rowid';
433 $this->export_sql_end[$r] .=' WHERE 1 = 1';
434 $this->export_sql_end[$r] .=' AND t.entity IN ('.getEntity('myobject').')';
435 $r++; */
436 /* END MODULEBUILDER EXPORT MYOBJECT */
437
438 // Imports profiles provided by this module
439 $r = 0;
440 /* BEGIN MODULEBUILDER IMPORT MYOBJECT */
441 /*
442 $langs->load("mymodule@mymodule");
443 $this->import_code[$r] = $this->rights_class.'_'.$r;
444 $this->import_label[$r] = 'MyObjectLines'; // Translation key (used only if key ExportDataset_xxx_z not found)
445 $this->import_icon[$r] = $this->picto;
446 $this->import_tables_array[$r] = array('t' => $this->db->prefix().'mymodule_myobject', 'extra' => $this->db->prefix().'mymodule_myobject_extrafields');
447 $this->import_tables_creator_array[$r] = array('t' => 'fk_user_author'); // Fields to store import user id
448 $import_sample = array();
449 $keyforclass = 'MyObject'; $keyforclassfile='/mymodule/class/myobject.class.php'; $keyforelement='myobject@mymodule';
450 include DOL_DOCUMENT_ROOT.'/core/commonfieldsinimport.inc.php';
451 $import_extrafield_sample = array();
452 $keyforselect='myobject'; $keyforaliasextra='extra'; $keyforelement='myobject@mymodule';
453 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinimport.inc.php';
454 $this->import_fieldshidden_array[$r] = array('extra.fk_object' => 'lastrowid-'.$this->db->prefix().'mymodule_myobject');
455 $this->import_regex_array[$r] = array();
456 $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
457 $this->import_updatekeys_array[$r] = array('t.ref' => 'Ref');
458 $this->import_convertvalue_array[$r] = array(
459 't.ref' => array(
460 'rule'=>'getrefifauto',
461 'class'=>(!getDolGlobalString('MYMODULE_MYOBJECT_ADDON') ? 'mod_myobject_standard' : getDolGlobalString('MYMODULE_MYOBJECT_ADDON')),
462 'path'=>"/core/modules/mymodule/".(!getDolGlobalString('MYMODULE_MYOBJECT_ADDON') ? 'mod_myobject_standard' : getDolGlobalString('MYMODULE_MYOBJECT_ADDON')).'.php',
463 'classobject'=>'MyObject',
464 'pathobject'=>'/mymodule/class/myobject.class.php',
465 ),
466 't.fk_soc' => array('rule' => 'fetchidfromref', 'file' => '/societe/class/societe.class.php', 'class' => 'Societe', 'method' => 'fetch', 'element' => 'ThirdParty'),
467 't.fk_user_valid' => array('rule' => 'fetchidfromref', 'file' => '/user/class/user.class.php', 'class' => 'User', 'method' => 'fetch', 'element' => 'user'),
468 't.fk_mode_reglement' => array('rule' => 'fetchidfromcodeorlabel', 'file' => '/compta/paiement/class/cpaiement.class.php', 'class' => 'Cpaiement', 'method' => 'fetch', 'element' => 'cpayment'),
469 );
470 $this->import_run_sql_after_array[$r] = array();
471 $r++; */
472 /* END MODULEBUILDER IMPORT MYOBJECT */
473 }
474
483 public function init($options = '')
484 {
485 global $conf, $langs;
486
487 // Create tables of module at module activation
488 //$result = $this->_load_tables('/install/mysql/', 'mymodule');
489 $result = $this->_load_tables('/mymodule/sql/');
490 if ($result < 0) {
491 return -1; // Do not activate module if error 'not allowed' returned when loading module SQL queries (the _load_table run sql with run_sql with the error allowed parameter set to 'default')
492 }
493
494 // Create extrafields during init
495 //include_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
496 //$extrafields = new ExtraFields($this->db);
497 //$result0=$extrafields->addExtraField('mymodule_separator1', "Separator 1", 'separator', 1, 0, 'thirdparty', 0, 0, '', array('options'=>array(1=>1)), 1, '', 1, 0, '', '', 'mymodule@mymodule', 'isModEnabled("mymodule")');
498 //$result1=$extrafields->addExtraField('mymodule_myattr1', "New Attr 1 label", 'boolean', 1, 3, 'thirdparty', 0, 0, '', '', 1, '', -1, 0, '', '', 'mymodule@mymodule', 'isModEnabled("mymodule")');
499 //$result2=$extrafields->addExtraField('mymodule_myattr2', "New Attr 2 label", 'varchar', 1, 10, 'project', 0, 0, '', '', 1, '', -1, 0, '', '', 'mymodule@mymodule', 'isModEnabled("mymodule")');
500 //$result3=$extrafields->addExtraField('mymodule_myattr3', "New Attr 3 label", 'varchar', 1, 10, 'bank_account', 0, 0, '', '', 1, '', -1, 0, '', '', 'mymodule@mymodule', 'isModEnabled("mymodule")');
501 //$result4=$extrafields->addExtraField('mymodule_myattr4', "New Attr 4 label", 'select', 1, 3, 'thirdparty', 0, 1, '', array('options'=>array('code1'=>'Val1','code2'=>'Val2','code3'=>'Val3')), 1,'', -1, 0, '', '', 'mymodule@mymodule', 'isModEnabled("mymodule")');
502 //$result5=$extrafields->addExtraField('mymodule_myattr5', "New Attr 5 label", 'text', 1, 10, 'user', 0, 0, '', '', 1, '', -1, 0, '', '', 'mymodule@mymodule', 'isModEnabled("mymodule")');
503
504 // Permissions
505 $this->remove($options);
506
507 $sql = array();
508
509 // Document templates
510 $moduledir = dol_sanitizeFileName('mymodule');
511 $myTmpObjects = array();
512 $myTmpObjects['MyObject'] = array('includerefgeneration' => 0, 'includedocgeneration' => 0);
513
514 foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
515 if ($myTmpObjectArray['includerefgeneration']) {
516 $src = DOL_DOCUMENT_ROOT.'/install/doctemplates/'.$moduledir.'/template_myobjects.odt';
517 $dirodt = DOL_DATA_ROOT.($conf->entity > 1 ? '/'.$conf->entity : '').'/doctemplates/'.$moduledir;
518 $dest = $dirodt.'/template_myobjects.odt';
519
520 if (file_exists($src) && !file_exists($dest)) {
521 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
522 dol_mkdir($dirodt);
523 $result = dol_copy($src, $dest, '0', 0);
524 if ($result < 0) {
525 $langs->load("errors");
526 $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
527 return 0;
528 }
529 }
530
531 $sql = array_merge($sql, array(
532 "DELETE FROM ".$this->db->prefix()."document_model WHERE nom = 'standard_".$this->db->escape(dol_strtolower($myTmpObjectKey))."' AND type = '".$this->db->escape(dol_strtolower($myTmpObjectKey))."' AND entity = ".((int) $conf->entity),
533 "INSERT INTO ".$this->db->prefix()."document_model (nom, type, entity) VALUES('standard_".$this->db->escape(dol_strtolower($myTmpObjectKey))."', '".$this->db->escape(dol_strtolower($myTmpObjectKey))."', ".((int) $conf->entity).")",
534 "DELETE FROM ".$this->db->prefix()."document_model WHERE nom = 'generic_".$this->db->escape(dol_strtolower($myTmpObjectKey))."_odt' AND type = '".$this->db->escape(dol_strtolower($myTmpObjectKey))."' AND entity = ".((int) $conf->entity),
535 "INSERT INTO ".$this->db->prefix()."document_model (nom, type, entity) VALUES('generic_".$this->db->escape(dol_strtolower($myTmpObjectKey))."_odt', '".$this->db->escape(dol_strtolower($myTmpObjectKey))."', ".((int) $conf->entity).")"
536 ));
537 }
538 }
539
540 return $this->_init($sql, $options);
541 }
542
551 public function remove($options = '')
552 {
553 $sql = array();
554 return $this->_remove($sql, $options);
555 }
556}
Class DolibarrModules.
_init($array_sql, $options='')
Enables a module.
_remove($array_sql, $options='')
Disable function.
_load_tables($reldir, $onlywithsuffix='')
Create tables and keys required by module:
Description and activation class for module MyModule.
init($options='')
Function called when module is enabled.
__construct($db)
Constructor.
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.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dol_copy($srcfile, $destfile, $newmask='0', $overwriteifexists=1, $testvirus=0, $indexdatabase=0)
Copy a file to another file.
dol_strtolower($string, $encoding="UTF-8")
Convert a string to lower.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
$conf browser version
Definition main.inc.php:229
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:140