dolibarr 21.0.0-alpha
modWebPortal.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2023-2024 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2023-2024 Lionel Vessiller <lvessiller@easya.solutions>
4 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
28include_once DOL_DOCUMENT_ROOT . '/core/modules/DolibarrModules.class.php';
29
34{
40 public function __construct($db)
41 {
42 global $conf;
43 $this->db = $db;
44
45 // Id for module (must be unique).
46 // Use here a free id (See in Home -> System information -> Dolibarr for list of used modules id).
47 $this->numero = 11000; // TODO Go on page https://wiki.dolibarr.org/index.php/List_of_modules_id to reserve an id number for your module
48
49 // Key text used to identify module (for permissions, menus, etc...)
50 $this->rights_class = 'webportal';
51
52 // Family can be 'base' (core modules),'crm','financial','hr','projects','products','ecm','technic' (transverse modules),'interface' (link with external tools),'other','...'
53 // It is used to group modules by family in module setup page
54 $this->family = "portal";
55
56 // Module position in the family on 2 digits ('01', '10', '20', ...)
57 $this->module_position = '47';
58
59 // 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)
60 //$this->familyinfo = array('myownfamily' => array('position' => '01', 'label' => $langs->trans("MyOwnFamily")));
61 // Module label (no space allowed), used if translation string 'ModuleWebPortalName' not found (WebPortal is name of module).
62 $this->name = preg_replace('/^mod/i', '', get_class($this));
63
64 // Module description, used if translation string 'ModuleWebPortalDesc' not found (WebPortal is name of module).
65 $this->description = "WebPortalDescription";
66 // Used only if file README.md and README-LL.md not found.
67 $this->descriptionlong = "WebPortalDescription";
68
69 // Author
70 //$this->editor_name = 'Dolibarr';
71 //$this->editor_url = 'dolibarr.org';
72
73 // Possible values for version are: 'development', 'experimental', 'dolibarr', 'dolibarr_deprecated', 'experimental_deprecated' or a version string like 'x.y.z'
74 $this->version = 'experimental';
75 // Url to the file with your last numberversion of this module
76 //$this->url_last_version = 'http://www.example.com/versionmodule.txt';
77
78 // Key used in llx_const table to save module status enabled/disabled (where WEBPORTAL is value of property name of module in uppercase)
79 $this->const_name = 'MAIN_MODULE_' . strtoupper($this->name);
80
81 // Name of image file used for this module.
82 // If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue'
83 // If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module'
84 // To use a supported fa-xxx css style of font awesome, use this->picto='xxx'
85 $this->picto = 'fa-door-open';
86
87 // Define some features supported by module (triggers, login, substitutions, menus, css, etc...)
88 $this->module_parts = array(
89 // Set this to 1 if module has its own trigger directory (core/triggers)
90 'triggers' => 0,
91 // Set this to 1 if module has its own login method file (core/login)
92 'login' => 0,
93 // Set this to 1 if module has its own substitution function file (core/substitutions)
94 'substitutions' => 0,
95 // Set this to 1 if module has its own menus handler directory (core/menus)
96 'menus' => 0,
97 // Set this to 1 if module overwrite template dir (core/tpl)
98 'tpl' => 0,
99 // Set this to 1 if module has its own barcode directory (core/modules/barcode)
100 'barcode' => 0,
101 // Set this to 1 if module has its own models directory (core/modules/xxx)
102 'models' => 0,
103 // Set this to 1 if module has its own printing directory (core/modules/printing)
104 'printing' => 0,
105 // Set this to 1 if module has its own theme directory (theme)
106 'theme' => 0,
107 // Set this to relative path of css file if module has its own css file
108 'css' => array(// '/webportal/css/webportal.css.php',
109 ),
110 // Set this to relative path of js file if module must load a js on all pages
111 'js' => array(// '/webportal/js/webportal.js.php',
112 ),
113 // 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'
114 'hooks' => array(
115 // 'data' => array(
116 // 'hookcontext1',
117 // 'hookcontext2',
118 // ),
119 // 'entity' => '0',
120 ),
121 // Set this to 1 if features of module are opened to external users
122 'moduleforexternal' => 0,
123 );
124
125 // Data directories to create when module is enabled.
126 // Example: this->dirs = array("/webportal/temp","/webportal/subdir");
127 $this->dirs = array("/webportal/temp");
128
129 // Config pages. Put here list of php page, stored into webportal/admin directory, to use to setup module.
130 $this->config_page_url = array("setup.php@webportal");
131
132 // Dependencies
133 // A condition to hide module
134 $this->hidden = false;
135 // List of module class names that must be enabled if this module is enabled. Example: array('always'=>array('modModuleToEnable1','modModuleToEnable2'), 'FR'=>array('modModuleToEnableFR')...)
136 $this->depends = array();
137 // List of module class names to disable if this one is disabled. Example: array('modModuleToDisable1', ...)
138 $this->requiredby = array();
139 // List of module class names this module is in conflict with. Example: array('modModuleToDisable1', ...)
140 $this->conflictwith = array();
141
142 // The language file dedicated to your module
143 $this->langfiles = array("website");
144
145 // Prerequisites
146 $this->phpmin = array(7, 0); // Minimum version of PHP required by module
147 //$this->need_dolibarr_version = array(11, -3); // Minimum version of Dolibarr required by module
148 //$this->need_javascript_ajax = 0;
149
150 // Messages at activation
151 $this->warnings_activation = array(); // Warning to show when we activate module. array('always'='text') or array('FR'='textfr','MX'='textmx'...)
152 $this->warnings_activation_ext = array(); // Warning to show when we activate an external module. array('always'='text') or array('FR'='textfr','MX'='textmx'...)
153 //$this->automatic_activation = array('FR'=>'WebPortalWasAutomaticallyActivatedBecauseOfYourCountryChoice');
154 //$this->always_enabled = true; // If true, can't be disabled
155
156 // Constants
157 // List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive)
158 // Example: $this->const=array(1 => array('WEBPORTAL_MYNEWCONST1', 'chaine', 'myvalue', 'This is a constant to add', 1),
159 // 2 => array('WEBPORTAL_MYNEWCONST2', 'chaine', 'myvalue', 'This is another constant to add', 0, 'current', 1)
160 // );
161 $this->const = array();
162
163 // Some keys to add into the overwriting translation tables
164 /*$this->overwrite_translation = array(
165 'en_US:ParentCompany'=>'Parent company or reseller',
166 'fr_FR:ParentCompany'=>'Maison mère ou revendeur'
167 )*/
168
169 // To avoid warnings
170 if (isModEnabled('webportal')) {
171 $conf->webportal = new stdClass();
172 $conf->webportal->enabled = 0;
173 }
174
175 // Array to add new pages in new tabs
176 $this->tabs = array();
177 // Example:
178 // $this->tabs[] = array('data'=>'objecttype:+tabname1:Title1:mylangfile@webportal:$user->rights->webportal->read:/webportal/mynewtab1.php?id=__ID__'); // To add a new tab identified by code tabname1
179 // $this->tabs[] = array('data'=>'objecttype:+tabname2:SUBSTITUTION_Title2:mylangfile@webportal:$user->rights->othermodule->read:/webportal/mynewtab2.php?id=__ID__', // To add another new tab identified by code tabname2. Label will be result of calling all substitution functions on 'Title2' key.
180 // $this->tabs[] = array('data'=>'objecttype:-tabname:NU:conditiontoremove'); // To remove an existing tab identified by code tabname
181 //
182 // Where objecttype can be
183 // 'categories_x' to add a tab in category view (replace 'x' by type of category (0=product, 1=supplier, 2=customer, 3=member)
184 // 'contact' to add a tab in contact view
185 // 'contract' to add a tab in contract view
186 // 'group' to add a tab in group view
187 // 'intervention' to add a tab in intervention view
188 // 'invoice' to add a tab in customer invoice view
189 // 'invoice_supplier' to add a tab in supplier invoice view
190 // 'member' to add a tab in foundation member view
191 // 'opensurveypoll' to add a tab in opensurvey poll view
192 // 'order' to add a tab in sale order view
193 // 'order_supplier' to add a tab in supplier order view
194 // 'payment' to add a tab in payment view
195 // 'payment_supplier' to add a tab in supplier payment view
196 // 'product' to add a tab in product view
197 // 'propal' to add a tab in propal view
198 // 'project' to add a tab in project view
199 // 'stock' to add a tab in stock view
200 // 'thirdparty' to add a tab in third party view
201 // 'user' to add a tab in user view
202
203 // Dictionaries
204 $this->dictionaries = array();
205 /* Example:
206 $this->dictionaries=array(
207 'langs'=>'website',
208 // List of tables we want to see into dictionary editor
209 'tabname'=>array("table1", "table2", "table3"),
210 // Label of tables
211 'tablib'=>array("Table1", "Table2", "Table3"),
212 // Request to select fields
213 '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'),
214 // Sort order
215 'tabsqlsort'=>array("label ASC", "label ASC", "label ASC"),
216 // List of fields (result of select to show dictionary)
217 'tabfield'=>array("code,label", "code,label", "code,label"),
218 // List of fields (list of fields to edit a record)
219 'tabfieldvalue'=>array("code,label", "code,label", "code,label"),
220 // List of fields (list of fields for insert)
221 'tabfieldinsert'=>array("code,label", "code,label", "code,label"),
222 // Name of columns with primary key (try to always name it 'rowid')
223 'tabrowid'=>array("rowid", "rowid", "rowid"),
224 // Condition to show each dictionary
225 'tabcond'=>array(isModEnabled('webportal'), isModEnabled('webportal'), isModEnabled('webportal')),
226 // Tooltip for every fields of dictionaries: DO NOT PUT AN EMPTY ARRAY
227 'tabhelp'=>array(array('code'=>$langs->trans('CodeTooltipHelp'), 'field2' => 'field2tooltip'), array('code'=>$langs->trans('CodeTooltipHelp'), 'field2' => 'field2tooltip'), ...),
228 );
229 */
230
231 // Boxes/Widgets
232 // Add here list of php file(s) stored in webportal/core/boxes that contains a class to show a widget.
233 $this->boxes = array(
234 // 0 => array(
235 // 'file' => 'webportalwidget1.php@webportal',
236 // 'note' => 'Widget provided by WebPortal',
237 // 'enabledbydefaulton' => 'Home',
238 // ),
239 // ...
240 );
241
242 // Cronjobs (List of cron jobs entries to add when module is enabled)
243 // unit_frequency must be 60 for minute, 3600 for hour, 86400 for day, 604800 for week
244 $this->cronjobs = array(
245 // 0 => array(
246 // 'label' => 'MyJob label',
247 // 'jobtype' => 'method',
248 // 'class' => '/webportal/class/webportalpropal.class.php',
249 // 'objectname' => 'WebPortalPropal',
250 // 'method' => 'doScheduledJob',
251 // 'parameters' => '',
252 // 'comment' => 'Comment',
253 // 'frequency' => 2,
254 // 'unitfrequency' => 3600,
255 // 'status' => 0,
256 // 'test' => 'isModEnabled("webportal")',
257 // 'priority' => 50,
258 // ),
259 );
260 // Example: $this->cronjobs=array(
261 // 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("webportal")', 'priority'=>50),
262 // 1=>array('label'=>'My label', 'jobtype'=>'command', 'command'=>'', 'parameters'=>'param1, param2', 'comment'=>'Comment', 'frequency'=>1, 'unitfrequency'=>3600*24, 'status'=>0, 'test'=>'isModEnabled("webportal")', 'priority'=>50)
263 // );
264
265 // Permissions provided by this module
266 $this->rights = array();
267 $r = 0;
268 // Add here entries to declare new permissions
269 $this->rights[$r][0] = $this->numero . sprintf("%02d", $r + 1); // Permission id (must not be already used)
270 $this->rights[$r][1] = 'Administer users of the customer/partner webportal module'; // Permission label
271 $this->rights[$r][3] = 0;
272 $this->rights[$r][4] = 'write';
273 //$r++;
274 //$this->rights[$r][0] = $this->numero . sprintf("%02d", $r + 1); // Permission id (must not be already used)
275 //$this->rights[$r][1] = 'Delete objects of WebPortal'; // Permission label
276 //$this->rights[$r][3] = 0;
277 //$this->rights[$r][4] = 'delete';
278 //$r++;
279
280 // Main menu entries to add
281 $this->menu = array();
282 $r = 0;
283 // Add here entries to declare new menus
284 /*
285 $this->menu[$r++] = array(
286 '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
287 'type' => 'top', // This is a Top menu entry
288 'titre' => 'ModuleWebPortalName',
289 'prefix' => img_picto('', $this->picto, 'class="paddingright pictofixedwidth valignmiddle"'),
290 'mainmenu' => 'webportal',
291 'leftmenu' => '',
292 'url' => getDolGlobalString('WEBPORTAL_ROOT_URL', '/public/webportal/index.php'),
293 'langs' => 'website', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
294 'position' => 1000 + $r,
295 'enabled' => 'isModEnabled("webportal")', // Define condition to show or hide menu entry. Use 'isModEnabled("webportal")' if entry must be visible if module is enabled.
296 'perms' => '1', // Use 'perms'=>'$user->hasRight("webportal", "webportalpropal", "read")' if you want your menu with a permission rules
297 'target' => '',
298 'user' => 2, // 0=Menu for internal users, 1=external users, 2=both
299 );
300 */
301 /*$this->menu[$r++]=array(
302 'fk_menu'=>'fk_mainmenu=webportal', // '' 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
303 'type'=>'left', // This is a Left menu entry
304 'titre'=>'WebPortalPropal',
305 'prefix' => img_picto('', $this->picto, 'class="paddingright pictofixedwidth valignmiddle"'),
306 'mainmenu'=>'webportal',
307 'leftmenu'=>'webportalpropal',
308 'url'=>'/webportal/webportalindex.php',
309 'langs'=>'website', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
310 'position'=>1000+$r,
311 'enabled'=>'isModEnabled("webportal")', // Define condition to show or hide menu entry. Use 'isModEnabled("webportal")' if entry must be visible if module is enabled.
312 'perms'=>'$user->hasRight("webportal", "webportalpropal", "read")',
313 'target'=>'',
314 'user'=>2, // 0=Menu for internal users, 1=external users, 2=both
315 );
316 $this->menu[$r++]=array(
317 'fk_menu'=>'fk_mainmenu=webportal,fk_leftmenu=webportalpropal', // '' 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
318 'type'=>'left', // This is a Left menu entry
319 'titre'=>'List_WebPortalPropal',
320 'mainmenu'=>'webportal',
321 'leftmenu'=>'webportal_webportalpropal_list',
322 'url'=>'/webportal/webportalpropal_list.php',
323 'langs'=>'website', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
324 'position'=>1000+$r,
325 'enabled'=>'isModEnabled("webportal")', // Define condition to show or hide menu entry. Use 'isModEnabled("webportal")' if entry must be visible if module is enabled.
326 'perms'=>'$user->hasRight("webportal", "webportalpropal", "read")'
327 'target'=>'',
328 'user'=>2, // 0=Menu for internal users, 1=external users, 2=both
329 );
330 $this->menu[$r++]=array(
331 'fk_menu'=>'fk_mainmenu=webportal,fk_leftmenu=webportalpropal', // '' 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
332 'type'=>'left', // This is a Left menu entry
333 'titre'=>'New_WebPortalPropal',
334 'mainmenu'=>'webportal',
335 'leftmenu'=>'webportal_webportalpropal_new',
336 'url'=>'/webportal/webportalpropal_card.php?action=create',
337 'langs'=>'website', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
338 'position'=>1000+$r,
339 'enabled'=>'isModEnabled("webportal")', // Define condition to show or hide menu entry. Use 'isModEnabled("webportal")' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
340 'perms'=>'$user->hasRight("webportal", "webportalpropal", "write")'
341 'target'=>'',
342 'user'=>2, // 0=Menu for internal users, 1=external users, 2=both
343 );*/
344 }
345
354 public function init($options = '')
355 {
356 // Permissions
357 $this->remove($options);
358
359 $sql = array();
360
361 return $this->_init($sql, $options);
362 }
363
372 public function remove($options = '')
373 {
374 $sql = array();
375 return $this->_remove($sql, $options);
376 }
377}
Class DolibarrModules.
_init($array_sql, $options='')
Enables a module.
_remove($array_sql, $options='')
Disable function.
Description and activation class for module WebPortal.
__construct($db)
Constructor.
init($options='')
Function called when module is enabled.
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.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:140