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