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