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