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