WebPortal::remove()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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