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