Issues (2811)

Dolibarr/Modules/EventOrganization.php (1 issue)

Labels
Severity
1
<?php
2
3
/* Copyright (C) 2021       Florian Henry           <[email protected]>
4
 * Copyright (C) 2024		MDW							<[email protected]>
5
 * Copyright (C) 2024       Rafael San José             <[email protected]>
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
21
/**
22
 *  \defgroup   eventorganization     Module EventOrganization
23
 *  \brief      EventOrganization module descriptor.
24
 *
25
 *  \file       htdocs/core/modules/modEventOrganization.class.php
26
 *  \ingroup    eventorganization
27
 *  \brief      Description and activation file for the EventOrganization
28
 */
29
30
namespace Dolibarr\Modules;
31
32
use Dolibarr\Code\Categories\Classes\Categorie;
33
use Dolibarr\Core\Base\DolibarrModules;
34
use DoliDB;
35
use FormMail;
36
use stdClass;
37
use User;
0 ignored issues
show
This use statement conflicts with another class in this namespace, Dolibarr\Modules\User. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
38
39
/**
40
 *  Description and activation class for module EventOrganization
41
 *  This module is base on this specification :
42
 *  https://wiki.dolibarr.org/index.php/Draft:Module_Event_Organization
43
 */
44
class EventOrganization extends DolibarrModules
45
{
46
    /**
47
     * Constructor. Define names, constants, directories, boxes, permissions
48
     *
49
     * @param DoliDB $db Database handler
50
     */
51
    public function __construct($db)
52
    {
53
        global $conf, $langs;
54
55
        $this->db = $db;
56
57
        $this->numero = 2450;
58
59
        $this->rights_class = 'eventorganization';
60
61
        $this->family = "projects";
62
63
        $this->module_position = '15';
64
65
        $this->name = preg_replace('/^mod/i', '', get_only_class($this));
66
67
        $this->description = "EventOrganizationDescription";
68
        $this->descriptionlong = "EventOrganizationDescriptionLong";
69
70
        $this->version = 'dolibarr';
71
72
73
        // Key used in llx_const table to save module status enabled/disabled (where EVENTORGANIZATION is value of property name of module in uppercase)
74
        $this->const_name = 'MAIN_MODULE_' . static::getNameOf($this->name); // strtoupper($this->name);
75
76
        $this->picto = 'conferenceorbooth';
77
78
        // Define some features supported by module (triggers, login, substitutions, menus, css, etc...)
79
        $this->module_parts = array(
80
            // Set this to 1 if module has its own trigger directory (core/triggers)
81
            'triggers' => 1,
82
            // Set this to 1 if module has its own login method file (core/login)
83
            'login' => 0,
84
            // Set this to 1 if module has its own substitution function file (core/substitutions)
85
            'substitutions' => 0,
86
            // Set this to 1 if module has its own menus handler directory (core/menus)
87
            'menus' => 0,
88
            // Set this to 1 if module overwrite template dir (core/tpl)
89
            'tpl' => 0,
90
            // Set this to 1 if module has its own barcode directory (core/modules/barcode)
91
            'barcode' => 0,
92
            // Set this to 1 if module has its own models directory (core/modules/xxx)
93
            'models' => 1,
94
            // Set this to 1 if module has its own printing directory (core/modules/printing)
95
            'printing' => 0,
96
            // Set this to 1 if module has its own theme directory (theme)
97
            'theme' => 0,
98
            // Set this to relative path of css file if module has its own css file
99
            'css' => array(//    '/eventorganization/css/eventorganization.css.php',
100
            ),
101
            // Set this to relative path of js file if module must load a js on all pages
102
            'js' => array(//   '/eventorganization/js/eventorganization.js.php',
103
            ),
104
            // 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'
105
            'hooks' => array(
106
                //   'data' => array(
107
                //       'hookcontext1',
108
                //       'hookcontext2',
109
                //   ),
110
                //   'entity' => '0',
111
            ),
112
            // Set this to 1 if features of module are opened to external users
113
            'moduleforexternal' => 0,
114
        );
115
116
        // Data directories to create when module is enabled.
117
        // Example: this->dirs = array("/eventorganization/temp","/eventorganization/subdir");
118
        $this->dirs = array("/eventorganization/temp");
119
120
        // Config pages. Put here list of php page, stored into eventorganization/admin directory, to use to setup module.
121
        $this->config_page_url = array("eventorganization.php");
122
123
        // Dependencies
124
        // A condition to hide module
125
        $this->hidden = false;
126
        // List of module class names as string that must be enabled if this module is enabled. Example: array('always'=>array('modModuleToEnable1','modModuleToEnable2'), 'FR'=>array('modModuleToEnableFR'...))
127
        $this->depends = array('modProjet', 'modCategorie', 'modAgenda');
128
        $this->requiredby = array(); // List of module class names as string to disable if this one is disabled. Example: array('modModuleToDisable1', ...)
129
        $this->conflictwith = array(); // List of module class names as string this module is in conflict with. Example: array('modModuleToDisable1', ...)
130
131
        // The language file dedicated to your module
132
        $this->langfiles = array("eventorganization");
133
134
        // Prerequisites
135
        $this->phpmin = array(7, 0); // Minimum version of PHP required by module
136
        $this->need_dolibarr_version = array(13, -3); // Minimum version of Dolibarr required by module
137
138
        // Messages at activation
139
        $this->warnings_activation = array(); // Warning to show when we activate module. array('always'='text') or array('FR'='textfr','ES'='textes'...)
140
        $this->warnings_activation_ext = array(); // Warning to show when we activate an external module. array('always'='text') or array('FR'='textfr','ES'='textes'...)
141
        //$this->automatic_activation = array('FR'=>'EventOrganizationWasAutomaticallyActivatedBecauseOfYourCountryChoice');
142
        //$this->always_enabled = true;                             // If true, can't be disabled
143
144
        // Constants
145
        // List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive)
146
        // Example: $this->const=array(1 => array('EVENTORGANIZATION_MYNEWCONST1', 'chaine', 'myvalue', 'This is a constant to add', 1),
147
        //                             2 => array('EVENTORGANIZATION_MYNEWCONST2', 'chaine', 'myvalue', 'This is another constant to add', 0, 'current', 1)
148
        // );
149
        $this->const = array(1 => array('EVENTORGANIZATION_TASK_LABEL', 'chaine', '', '', 0));
150
151
152
        // Some keys to add into the overwriting translation tables
153
        /*$this->overwrite_translation = array(
154
            'en_US:ParentCompany'=>'Parent company or reseller',
155
            'fr_FR:ParentCompany'=>'Maison mère ou revendeur'
156
        )*/
157
158
        if (!isset($conf->eventorganization) || !isset($conf->eventorganization->enabled)) {
159
            $conf->eventorganization = new stdClass();
160
            $conf->eventorganization->enabled = 0;
161
        }
162
163
        // Array to add new pages in new tabs
164
        $this->tabs = array();
165
        // Example:
166
        // $this->tabs[] = array('data'=>'objecttype:+tabname1:Title1:mylangfile@eventorganization:$user->rights->eventorganization->read:/eventorganization/mynewtab1.php?id=__ID__');                     // To add a new tab identified by code tabname1
167
        // $this->tabs[] = array('data'=>'objecttype:+tabname2:SUBSTITUTION_Title2:mylangfile@eventorganization:$user->rights->othermodule->read:/eventorganization/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.
168
        // $this->tabs[] = array('data'=>'objecttype:-tabname:NU:conditiontoremove');                                                                                           // To remove an existing tab identified by code tabname
169
        //
170
        // Where objecttype can be
171
        // 'categories_x'     to add a tab in category view (replace 'x' by type of category (0=product, 1=supplier, 2=customer, 3=member)
172
        // 'contact'          to add a tab in contact view
173
        // 'contract'         to add a tab in contract view
174
        // 'group'            to add a tab in group view
175
        // 'intervention'     to add a tab in intervention view
176
        // 'invoice'          to add a tab in customer invoice view
177
        // 'invoice_supplier' to add a tab in supplier invoice view
178
        // 'member'           to add a tab in foundation member view
179
        // 'opensurveypoll'   to add a tab in opensurvey poll view
180
        // 'order'            to add a tab in sales order view
181
        // 'order_supplier'   to add a tab in supplier order view
182
        // 'payment'          to add a tab in payment view
183
        // 'payment_supplier' to add a tab in supplier payment view
184
        // 'product'          to add a tab in product view
185
        // 'propal'           to add a tab in propal view
186
        // 'project'          to add a tab in project view
187
        // 'stock'            to add a tab in stock view
188
        // 'thirdparty'       to add a tab in third party view
189
        // 'user'             to add a tab in user view
190
191
        // Dictionaries
192
        $this->dictionaries = array();
193
194
        // Boxes/Widgets
195
        // Add here list of php file(s) stored in eventorganization/core/boxes that contains a class to show a widget.
196
        $this->boxes = array(
197
            //  0 => array(
198
            //      'file' => 'eventorganizationwidget1.php@eventorganization',
199
            //      'note' => 'Widget provided by EventOrganization',
200
            //      'enabledbydefaulton' => 'Home',
201
            //  ),
202
            //  ...
203
        );
204
205
        // Cronjobs (List of cron jobs entries to add when module is enabled)
206
        // unit_frequency must be 60 for minute, 3600 for hour, 86400 for day, 604800 for week
207
        $this->cronjobs = array();
208
209
210
        // Permissions provided by this module
211
        $this->rights = array();
212
        $r = 1;
213
214
        // Add here entries to declare new permissions
215
        /* BEGIN MODULEBUILDER PERMISSIONS */
216
        $this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used)
217
        $this->rights[$r][1] = 'Read objects of EventOrganization'; // Permission label
218
        $this->rights[$r][4] = 'read'; // In php code, permission will be checked by test if ($user->rights->eventorganization->level1)
219
        $r++;
220
        $this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used)
221
        $this->rights[$r][1] = 'Create/Update objects of EventOrganization'; // Permission label
222
        $this->rights[$r][4] = 'write'; // In php code, permission will be checked by test if ($user->rights->eventorganization->level1)
223
        $r++;
224
        $this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used)
225
        $this->rights[$r][1] = 'Delete objects of EventOrganization'; // Permission label
226
        $this->rights[$r][4] = 'delete'; // In php code, permission will be checked by test if ($user->rights->eventorganization->level1)
227
        $r++;
228
        /* END MODULEBUILDER PERMISSIONS */
229
230
        // Main menu entries to add
231
        $this->menu = array();
232
        $r = 0;
233
        // Add here entries to declare new menus
234
        /* BEGIN MODULEBUILDER TOPMENU */
235
        /* END MODULEBUILDER TOPMENU */
236
        /* BEGIN MODULEBUILDER LEFTMENU CONFERENCEORBOOTH*/
237
        $this->menu[$r++] = array(
238
            'fk_menu' => 'fk_mainmenu=project',     // '' 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
239
            'type' => 'left',                           // This is a Left menu entry
240
            'titre' => 'EventOrganizationMenuLeft',
241
            'prefix' => img_picto('', 'eventorganization', 'class="paddingright pictofixedwidth"'),
242
            'mainmenu' => 'project',
243
            'leftmenu' => 'eventorganization',
244
            'url' => '',
245
            'langs' => 'eventorganization',         // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
246
            'position' => 1000 + $r,
247
            'enabled' => 'isModEnabled("eventorganization")',  // Define condition to show or hide menu entry. Use '$conf->eventorganization->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
248
            'perms' => '$user->hasRight("eventorganization", "read")',                          // Use 'perms'=>'$user->rights->eventorganization->level1->level2' if you want your menu with a permission rules
249
            'target' => '',
250
            'user' => 2,                                // 0=Menu for internal users, 1=external users, 2=both
251
        );
252
        $this->menu[$r++] = array(
253
            'fk_menu' => 'fk_mainmenu=project,fk_leftmenu=eventorganization',       // '' 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
254
            'type' => 'left',                           // This is a Left menu entry
255
            'titre' => 'New',
256
            'url' => '/projet/card.php?leftmenu=projects&action=create&usage_organize_event=1&usage_opportunity=0',
257
            'langs' => 'eventorganization@eventorganization',           // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
258
            'position' => 1000 + $r,
259
            'enabled' => 'isModEnabled("eventorganization")',  // Define condition to show or hide menu entry. Use '$conf->eventorganization->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
260
            'perms' => '$user->hasRight("eventorganization", "write")',                         // Use 'perms'=>'$user->rights->eventorganization->level1->level2' if you want your menu with a permission rules
261
            'target' => '',
262
            'user' => 2,                                // 0=Menu for internal users, 1=external users, 2=both
263
        );
264
        $this->menu[$r++] = array(
265
            'fk_menu' => 'fk_mainmenu=project,fk_leftmenu=eventorganization',       // '' 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
266
            'type' => 'left',                           // This is a Left menu entry
267
            'titre' => 'List',
268
            'url' => '/projet/list.php?search_usage_event_organization=1&search_status=99&mainmenu=project&contextpage=organizedevents',
269
            'langs' => 'eventorganization@eventorganization',           // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
270
            'position' => 1000 + $r,
271
            'enabled' => 'isModEnabled("eventorganization")',  // Define condition to show or hide menu entry. Use '$conf->eventorganization->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
272
            'perms' => '$user->hasRight("eventorganization", "write")',                         // Use 'perms'=>'$user->rights->eventorganization->level1->level2' if you want your menu with a permission rules
273
            'target' => '',
274
            'user' => 2,                                // 0=Menu for internal users, 1=external users, 2=both
275
        );
276
        $this->menu[$r++] = array(
277
            'fk_menu' => 'fk_mainmenu=project',     // '' 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
278
            'type' => 'left',                           // This is a Left menu entry
279
            'titre' => 'ConferenceOrBooth',
280
            'prefix' => img_picto('', 'conferenceorbooth', 'class="paddingright pictofixedwidth"'),
281
            'mainmenu' => 'project',
282
            'leftmenu' => 'eventorganizationconforbooth',
283
            'url' => '',
284
            'langs' => 'eventorganization',         // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
285
            'position' => 1000 + $r,
286
            'enabled' => 'isModEnabled("eventorganization")',  // Define condition to show or hide menu entry. Use '$conf->eventorganization->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
287
            'perms' => '$user->hasRight("eventorganization", "read")',                          // Use 'perms'=>'$user->rights->eventorganization->level1->level2' if you want your menu with a permission rules
288
            'target' => '',
289
            'user' => 2,                                // 0=Menu for internal users, 1=external users, 2=both
290
        );
291
        $this->menu[$r++] = array(
292
            'fk_menu' => 'fk_mainmenu=project,fk_leftmenu=eventorganizationconforbooth',        // '' 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' => 'left',                           // This is a Left menu entry
294
            'titre' => 'New',
295
            'url' => '/eventorganization/conferenceorbooth_card.php?leftmenu=projects&action=create',
296
            'langs' => 'eventorganization',         // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
297
            'position' => 1000 + $r,
298
            'enabled' => 'isModEnabled("eventorganization")',  // Define condition to show or hide menu entry. Use '$conf->eventorganization->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
299
            'perms' => '$user->hasRight("eventorganization", "write")',                         // Use 'perms'=>'$user->rights->eventorganization->level1->level2' if you want your menu with a permission rules
300
            'target' => '',
301
            'user' => 2,                                // 0=Menu for internal users, 1=external users, 2=both
302
        );
303
        $this->menu[$r++] = array(
304
            'fk_menu' => 'fk_mainmenu=project,fk_leftmenu=eventorganizationconforbooth',        // '' 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
305
            'type' => 'left',                           // This is a Left menu entry
306
            'titre' => 'List',
307
            'url' => '/eventorganization/conferenceorbooth_list.php?mainmenu=project',
308
            'langs' => 'eventorganization',         // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
309
            'position' => 1000 + $r,
310
            'enabled' => 'isModEnabled("eventorganization")',  // Define condition to show or hide menu entry. Use '$conf->eventorganization->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
311
            'perms' => '$user->hasRight("eventorganization", "read")',                          // Use 'perms'=>'$user->rights->eventorganization->level1->level2' if you want your menu with a permission rules
312
            'target' => '',
313
            'user' => 2,                                // 0=Menu for internal users, 1=external users, 2=both
314
        );
315
        /* END MODULEBUILDER LEFTMENU CONFERENCEORBOOTH */
316
317
        // Exports profiles provided by this module
318
        $r = 1;
319
320
        /* BEGIN MODULEBUILDER EXPORT CONFERENCEORBOOTHATTENDEES */
321
        $langs->load("eventorganization");
322
        $this->export_code[$r] = $this->rights_class . '_' . $r;
323
        $this->export_label[$r] = 'ListOfAttendeesOfEvent'; // Translation key (used only if key ExportDataset_xxx_z not found)
324
        $this->export_icon[$r] = $this->picto;
325
        // Define $this->export_fields_array, $this->export_TypeFields_array and $this->export_entities_array
326
        $keyforclass = 'ConferenceOrBoothAttendee';
327
        $keyforclassfile = '/eventorganization/class/conferenceorboothattendee.class.php';
328
        $keyforelement = 'conferenceorboothattendee';
329
        include DOL_DOCUMENT_ROOT . '/core/commonfieldsinexport.inc.php';
330
        $this->export_entities_array[$r]['t.fk_invoice'] = 'invoice';
331
        unset($this->export_fields_array[$r]['t.fk_project']);  // Remove field so we can add it at end just after
332
        unset($this->export_fields_array[$r]['t.fk_soc']);  // Remove field so we can add it at end just after
333
        $this->export_fields_array[$r]['t.fk_invoice'] = 'InvoiceId';
334
        $this->export_fields_array[$r]['t.fk_project'] = 'ProjectId';
335
        $this->export_fields_array[$r]['p.ref'] = 'ProjectRef';
336
        $this->export_fields_array[$r]['t.fk_soc'] = 'IdThirdParty';
337
        $this->export_entities_array[$r]['t.fk_project'] = 'project';
338
        $this->export_entities_array[$r]['p.ref'] = 'project';
339
        $this->export_entities_array[$r]['t.fk_soc'] = 'company';
340
        $this->export_TypeFields_array[$r]['t.fk_project'] = 'Numeric';
341
        $this->export_TypeFields_array[$r]['t.fk_invoice'] = 'Numeric';
342
        $this->export_TypeFields_array[$r]['p.ref'] = 'Text';
343
        $this->export_TypeFields_array[$r]['t.fk_soc'] = 'Numeric';
344
        //$this->export_fields_array[$r]['t.fieldtoadd']='FieldToAdd'; $this->export_TypeFields_array[$r]['t.fieldtoadd']='Text';
345
        //unset($this->export_fields_array[$r]['t.fieldtoremove']);
346
        $keyforselect = 'conferenceorboothattendee';
347
        $keyforaliasextra = 'extra';
348
        $keyforelement = 'conferenceorboothattendee';
349
        include DOL_DOCUMENT_ROOT . '/core/extrafieldsinexport.inc.php';
350
        //$this->export_dependencies_array[$r] = array('aaaline'=>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)
351
        //$this->export_special_array[$r] = array('t.field'=>'...');
352
        //$this->export_examplevalues_array[$r] = array('t.field'=>'Example');
353
        //$this->export_help_array[$r] = array('t.field'=>'FieldDescHelp');
354
        $this->export_sql_start[$r] = 'SELECT DISTINCT ';
355
        $this->export_sql_end[$r] = ' FROM ' . MAIN_DB_PREFIX . 'eventorganization_conferenceorboothattendee as t, ' . MAIN_DB_PREFIX . 'projet as p';
356
        $this->export_sql_end[$r] .= ' WHERE t.fk_project = p.rowid';
357
        $this->export_sql_end[$r] .= ' AND p.entity IN (' . getEntity('conferenceorboothattendee') . ')';
358
        $r++;
359
        /* END MODULEBUILDER EXPORT CONFERENCEORBOOTHATTENDEES */
360
361
        /* BEGIN MODULEBUILDER EXPORT CONFERENCEORBOOTH */
362
        $langs->load("eventorganization");
363
        $this->export_code[$r] = $this->rights_class . '_' . $r;
364
        $this->export_label[$r] = 'ListOfConfOrBoothOfEvent';   // Translation key (used only if key ExportDataset_xxx_z not found)
365
        $this->export_icon[$r] = 'conferenceorbooth';
366
        // Define $this->export_fields_array, $this->export_TypeFields_array and $this->export_entities_array
367
        $keyforclass = 'ConferenceOrBooth';
368
        $keyforclassfile = '/eventorganization/class/conferenceorbooth.class.php';
369
        $keyforelement = 'conferenceorbooth';
370
        include DOL_DOCUMENT_ROOT . '/core/commonfieldsinexport.inc.php';
371
        unset($this->export_fields_array[$r]['t.fk_action']);   // Remove field so we can add it at end just after
372
        unset($this->export_fields_array[$r]['t.fk_project']);  // Remove field so we can add it at end just after
373
        unset($this->export_fields_array[$r]['t.fk_soc']);  // Remove field so we can add it at end just after
374
        $this->export_fields_array[$r]['t.fk_action'] = 'ConferenceOrBoothFormatID';
375
        $this->export_fields_array[$r]['ca.code'] = 'ConferenceOrBoothFormatCode';
376
        $this->export_fields_array[$r]['ca.libelle'] = 'ConferenceOrBoothFormatLabel';
377
        $this->export_fields_array[$r]['t.fk_project'] = 'ProjectId';
378
        $this->export_fields_array[$r]['p.ref'] = 'ProjectRef';
379
        $this->export_fields_array[$r]['t.fk_soc'] = 'IdThirdParty';
380
        $this->export_fields_array[$r]['s.nom'] = 'ThirdPartyName';
381
        $this->export_entities_array[$r]['ca.code'] = 'conferenceorbooth';
382
        $this->export_entities_array[$r]['ca.libelle'] = 'conferenceorbooth';
383
        $this->export_entities_array[$r]['t.fk_project'] = 'project';
384
        $this->export_entities_array[$r]['p.ref'] = 'project';
385
        $this->export_entities_array[$r]['t.fk_soc'] = 'company';
386
        $this->export_entities_array[$r]['s.nom'] = 'company';
387
        $this->export_TypeFields_array[$r]['ca.code'] = 'Text';
388
        $this->export_TypeFields_array[$r]['ca.libelle'] = 'Text';
389
        $this->export_TypeFields_array[$r]['t.fk_project'] = 'Numeric';
390
        $this->export_TypeFields_array[$r]['p.ref'] = 'Text';
391
        $this->export_TypeFields_array[$r]['t.fk_soc'] = 'Numeric';
392
        $this->export_TypeFields_array[$r]['s.nom'] = 'Text';
393
        //$this->export_fields_array[$r]['t.fieldtoadd']='FieldToAdd'; $this->export_TypeFields_array[$r]['t.fieldtoadd']='Text';
394
        //unset($this->export_fields_array[$r]['t.fieldtoremove']);
395
        $keyforselect = 'conferenceorbooth';
396
        $keyforaliasextra = 'extra';
397
        $keyforelement = 'conferenceorbooth';
398
        include DOL_DOCUMENT_ROOT . '/core/extrafieldsinexport.inc.php';
399
        //$this->export_dependencies_array[$r] = array('aaaline'=>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)
400
        //$this->export_special_array[$r] = array('t.field'=>'...');
401
        //$this->export_examplevalues_array[$r] = array('t.field'=>'Example');
402
        //$this->export_help_array[$r] = array('t.field'=>'FieldDescHelp');
403
        $this->export_sql_start[$r] = 'SELECT DISTINCT ';
404
        $this->export_sql_end[$r] = ' FROM ' . MAIN_DB_PREFIX . 'actioncomm as t';
405
        $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe as s ON t.fk_soc = s.rowid,';
406
        $this->export_sql_end[$r] .= ' ' . MAIN_DB_PREFIX . 'projet as p,';
407
        $this->export_sql_end[$r] .= ' ' . MAIN_DB_PREFIX . 'c_actioncomm as ca';
408
        $this->export_sql_end[$r] .= ' WHERE t.fk_project = p.rowid';
409
        $this->export_sql_end[$r] .= ' AND ca.id = t.fk_action';
410
        $this->export_sql_end[$r] .= " AND t.code LIKE 'AC_EO_%'";
411
        $this->export_sql_end[$r] .= ' AND p.usage_organize_event = 1';
412
        $this->export_sql_end[$r] .= ' AND p.entity IN (' . getEntity('conferenceorboothattendee') . ')';
413
        $r++;
414
        /* END MODULEBUILDER EXPORT CONFERENCEORBOOTH */
415
416
417
        // Imports profiles provided by this module
418
        $r = 1;
419
        /* BEGIN MODULEBUILDER IMPORT CONFERENCEORBOOTH */
420
        /* END MODULEBUILDER IMPORT CONFERENCEORBOOTH */
421
    }
422
423
    /**
424
     *  Function called when module is enabled.
425
     *  The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
426
     *  It also creates data directories
427
     *
428
     * @param string $options Options when enabling module ('', 'noboxes')
429
     * @return     int                 1 if OK, 0 if KO
430
     */
431
    public function init($options = '')
432
    {
433
        global $conf, $langs, $user;
434
435
        /*$result = run_sql(DOL_DOCUMENT_ROOT.'/install/mysql/data/llx_c_email_templates.sql', 1, '', 1);
436
        if ($result <= 0) {
437
            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')
438
        }
439
        TODO Instead use the array merge of the sql found into llx_c_email_templates for this module
440
        */
441
442
        // Permissions
443
        $this->remove($options);
444
445
        $sql = array();
446
447
        // Document templates
448
        $moduledir = 'eventorganization';
449
        $myTmpObjects = array();
450
        $myTmpObjects['ConferenceOrBooth'] = array('includerefgeneration' => 0, 'includedocgeneration' => 0);
451
452
        foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
453
            if ($myTmpObjectKey == 'ConferenceOrBooth') {
454
                continue;
455
            }
456
            if ($myTmpObjectArray['includerefgeneration']) {
457
                $src = DOL_DOCUMENT_ROOT . '/install/doctemplates/eventorganization/template_conferenceorbooths.odt';
458
                $dirodt = DOL_DATA_ROOT . '/doctemplates/eventorganization';
459
                $dest = $dirodt . '/template_conferenceorbooths.odt';
460
461
                if (file_exists($src) && !file_exists($dest)) {
462
                    require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/files.lib.php';
463
                    dol_mkdir($dirodt);
464
                    $result = dol_copy($src, $dest, 0, 0);
465
                    if ($result < 0) {
466
                        $langs->load("errors");
467
                        $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
468
                        return 0;
469
                    }
470
                }
471
472
                $sql = array_merge($sql, array(
473
                    "DELETE FROM " . MAIN_DB_PREFIX . "document_model WHERE nom = 'standard_" . strtolower($myTmpObjectKey) . "' AND type = '" . $this->db->escape(strtolower($myTmpObjectKey)) . "' AND entity = " . ((int)$conf->entity),
474
                    "INSERT INTO " . MAIN_DB_PREFIX . "document_model (nom, type, entity) VALUES('standard_" . strtolower($myTmpObjectKey) . "','" . $this->db->escape(strtolower($myTmpObjectKey)) . "'," . ((int)$conf->entity) . ")",
475
                    "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),
476
                    "INSERT INTO " . MAIN_DB_PREFIX . "document_model (nom, type, entity) VALUES('generic_" . strtolower($myTmpObjectKey) . "_odt', '" . $this->db->escape(strtolower($myTmpObjectKey)) . "', " . ((int)$conf->entity) . ")"
477
                ));
478
            }
479
        }
480
481
        $init = $this->_init($sql, $options);
482
483
484
        // Insert some vars
485
        $formmail = new FormMail($this->db);
486
487
        if (!is_object($user)) {
488
            $user = new User($this->db); // To avoid error during migration
489
        }
490
491
        $template = $formmail->getEMailTemplate($this->db, 'conferenceorbooth', $user, $langs, 0, 1, '(EventOrganizationEmailAskConf)');
492
        if ($template->id > 0) {
493
            dolibarr_set_const($this->db, 'EVENTORGANIZATION_TEMPLATE_EMAIL_ASK_CONF', $template->id, 'chaine', 0, '', $conf->entity);
494
        }
495
        $template = $formmail->getEMailTemplate($this->db, 'conferenceorbooth', $user, $langs, 0, 1, '(EventOrganizationEmailAskBooth)');
496
        if ($template->id > 0) {
497
            dolibarr_set_const($this->db, 'EVENTORGANIZATION_TEMPLATE_EMAIL_ASK_BOOTH', $template->id, 'chaine', 0, '', $conf->entity);
498
        }
499
        $template = $formmail->getEMailTemplate($this->db, 'conferenceorbooth', $user, $langs, 0, 1, '(EventOrganizationEmailBoothPayment)');
500
        if ($template->id > 0) {
501
            dolibarr_set_const($this->db, 'EVENTORGANIZATION_TEMPLATE_EMAIL_AFT_SUBS_BOOTH', $template->id, 'chaine', 0, '', $conf->entity);
502
        }
503
        $template = $formmail->getEMailTemplate($this->db, 'conferenceorbooth', $user, $langs, 0, 1, '(EventOrganizationEmailRegistrationPayment)');
504
        if ($template->id > 0) {
505
            dolibarr_set_const($this->db, 'EVENTORGANIZATION_TEMPLATE_EMAIL_AFT_SUBS_EVENT', $template->id, 'chaine', 0, '', $conf->entity);
506
        }
507
508
        return $init;
509
    }
510
511
    /**
512
     *  Function called when module is disabled.
513
     *  Remove from database constants, boxes and permissions from Dolibarr database.
514
     *  Data directories are not deleted
515
     *
516
     * @param string $options Options when enabling module ('', 'noboxes')
517
     * @return     int                 1 if OK, 0 if KO
518
     */
519
    public function remove($options = '')
520
    {
521
        $sql = array();
522
        return $this->_remove($sql, $options);
523
    }
524
}
525