dolibarr  16.0.5
modEventOrganization.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2021 Florian Henry <florian.henry@scopen.fr>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <https://www.gnu.org/licenses/>.
16  */
17 
26 include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
27 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
28 
35 {
41  public function __construct($db)
42  {
43  global $langs, $conf;
44  $this->db = $db;
45 
46  $this->numero = 2450;
47 
48  $this->rights_class = 'eventorganization';
49 
50  $this->family = "projects";
51 
52  $this->module_position = '20';
53 
54  $this->name = preg_replace('/^mod/i', '', get_class($this));
55 
56  $this->description = "EventOrganizationDescription";
57  $this->descriptionlong = "EventOrganizationDescriptionLong";
58 
59  $this->version = 'dolibarr';
60 
61 
62  // Key used in llx_const table to save module status enabled/disabled (where EVENTORGANIZATION is value of property name of module in uppercase)
63  $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
64 
65  $this->picto = 'action';
66 
67  // Define some features supported by module (triggers, login, substitutions, menus, css, etc...)
68  $this->module_parts = array(
69  // Set this to 1 if module has its own trigger directory (core/triggers)
70  'triggers' => 1,
71  // Set this to 1 if module has its own login method file (core/login)
72  'login' => 0,
73  // Set this to 1 if module has its own substitution function file (core/substitutions)
74  'substitutions' => 0,
75  // Set this to 1 if module has its own menus handler directory (core/menus)
76  'menus' => 0,
77  // Set this to 1 if module overwrite template dir (core/tpl)
78  'tpl' => 0,
79  // Set this to 1 if module has its own barcode directory (core/modules/barcode)
80  'barcode' => 0,
81  // Set this to 1 if module has its own models directory (core/modules/xxx)
82  'models' => 1,
83  // Set this to 1 if module has its own printing directory (core/modules/printing)
84  'printing' => 0,
85  // Set this to 1 if module has its own theme directory (theme)
86  'theme' => 0,
87  // Set this to relative path of css file if module has its own css file
88  'css' => array(
89  // '/eventorganization/css/eventorganization.css.php',
90  ),
91  // Set this to relative path of js file if module must load a js on all pages
92  'js' => array(
93  // '/eventorganization/js/eventorganization.js.php',
94  ),
95  // 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'
96  'hooks' => array(
97  // 'data' => array(
98  // 'hookcontext1',
99  // 'hookcontext2',
100  // ),
101  // 'entity' => '0',
102  ),
103  // Set this to 1 if features of module are opened to external users
104  'moduleforexternal' => 0,
105  );
106 
107  // Data directories to create when module is enabled.
108  // Example: this->dirs = array("/eventorganization/temp","/eventorganization/subdir");
109  $this->dirs = array("/eventorganization/temp");
110 
111  // Config pages. Put here list of php page, stored into eventorganization/admin directory, to use to setup module.
112  $this->config_page_url = array("eventorganization.php");
113 
114  // Dependencies
115  // A condition to hide module
116  $this->hidden = false;
117  // List of module class names as string that must be enabled if this module is enabled. Example: array('always1'=>'modModuleToEnable1','always2'=>'modModuleToEnable2', 'FR1'=>'modModuleToEnableFR'...)
118  $this->depends = array('modProjet','modCategorie');
119  $this->requiredby = array(); // List of module class names as string to disable if this one is disabled. Example: array('modModuleToDisable1', ...)
120  $this->conflictwith = array(); // List of module class names as string this module is in conflict with. Example: array('modModuleToDisable1', ...)
121 
122  // The language file dedicated to your module
123  $this->langfiles = array("eventorganization");
124 
125  // Prerequisites
126  $this->phpmin = array(5, 6); // Minimum version of PHP required by module
127  $this->need_dolibarr_version = array(13, -3); // Minimum version of Dolibarr required by module
128 
129  // Messages at activation
130  $this->warnings_activation = array(); // Warning to show when we activate module. array('always'='text') or array('FR'='textfr','ES'='textes'...)
131  $this->warnings_activation_ext = array(); // Warning to show when we activate an external module. array('always'='text') or array('FR'='textfr','ES'='textes'...)
132  //$this->automatic_activation = array('FR'=>'EventOrganizationWasAutomaticallyActivatedBecauseOfYourCountryChoice');
133  //$this->always_enabled = true; // If true, can't be disabled
134 
135  // Constants
136  // List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive)
137  // Example: $this->const=array(1 => array('EVENTORGANIZATION_MYNEWCONST1', 'chaine', 'myvalue', 'This is a constant to add', 1),
138  // 2 => array('EVENTORGANIZATION_MYNEWCONST2', 'chaine', 'myvalue', 'This is another constant to add', 0, 'current', 1)
139  // );
140  $this->const = array(1 => array('EVENTORGANIZATION_TASK_LABEL', 'chaine', '', '', 0));
141 
142 
143 
144  // Some keys to add into the overwriting translation tables
145  /*$this->overwrite_translation = array(
146  'en_US:ParentCompany'=>'Parent company or reseller',
147  'fr_FR:ParentCompany'=>'Maison mère ou revendeur'
148  )*/
149 
150  if (!isset($conf->eventorganization) || !isset($conf->eventorganization->enabled)) {
151  $conf->eventorganization = new stdClass();
152  $conf->eventorganization->enabled = 0;
153  }
154 
155  // Array to add new pages in new tabs
156  $this->tabs = array();
157  // Example:
158  // $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
159  // $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.
160  // $this->tabs[] = array('data'=>'objecttype:-tabname:NU:conditiontoremove'); // To remove an existing tab identified by code tabname
161  //
162  // Where objecttype can be
163  // 'categories_x' to add a tab in category view (replace 'x' by type of category (0=product, 1=supplier, 2=customer, 3=member)
164  // 'contact' to add a tab in contact view
165  // 'contract' to add a tab in contract view
166  // 'group' to add a tab in group view
167  // 'intervention' to add a tab in intervention view
168  // 'invoice' to add a tab in customer invoice view
169  // 'invoice_supplier' to add a tab in supplier invoice view
170  // 'member' to add a tab in fundation member view
171  // 'opensurveypoll' to add a tab in opensurvey poll view
172  // 'order' to add a tab in customer order view
173  // 'order_supplier' to add a tab in supplier order view
174  // 'payment' to add a tab in payment view
175  // 'payment_supplier' to add a tab in supplier payment view
176  // 'product' to add a tab in product view
177  // 'propal' to add a tab in propal view
178  // 'project' to add a tab in project view
179  // 'stock' to add a tab in stock view
180  // 'thirdparty' to add a tab in third party view
181  // 'user' to add a tab in user view
182 
183  // Dictionaries
184  $this->dictionaries = array();
185 
186  // Boxes/Widgets
187  // Add here list of php file(s) stored in eventorganization/core/boxes that contains a class to show a widget.
188  $this->boxes = array(
189  // 0 => array(
190  // 'file' => 'eventorganizationwidget1.php@eventorganization',
191  // 'note' => 'Widget provided by EventOrganization',
192  // 'enabledbydefaulton' => 'Home',
193  // ),
194  // ...
195  );
196 
197  // Cronjobs (List of cron jobs entries to add when module is enabled)
198  // unit_frequency must be 60 for minute, 3600 for hour, 86400 for day, 604800 for week
199  $this->cronjobs = array(
200  );
201 
202 
203  // Permissions provided by this module
204  $this->rights = array();
205  $r = 1;
206 
207  // Add here entries to declare new permissions
208  /* BEGIN MODULEBUILDER PERMISSIONS */
209  $this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used)
210  $this->rights[$r][1] = 'Read objects of EventOrganization'; // Permission label
211  $this->rights[$r][4] = 'read'; // In php code, permission will be checked by test if ($user->rights->eventorganization->level1)
212  $r++;
213  $this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used)
214  $this->rights[$r][1] = 'Create/Update objects of EventOrganization'; // Permission label
215  $this->rights[$r][4] = 'write'; // In php code, permission will be checked by test if ($user->rights->eventorganization->level1)
216  $r++;
217  $this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used)
218  $this->rights[$r][1] = 'Delete objects of EventOrganization'; // Permission label
219  $this->rights[$r][4] = 'delete'; // In php code, permission will be checked by test if ($user->rights->eventorganization->level1)
220  $r++;
221  /* END MODULEBUILDER PERMISSIONS */
222 
223  // Main menu entries to add
224  $this->menu = array();
225  $r = 0;
226  // Add here entries to declare new menus
227  /* BEGIN MODULEBUILDER TOPMENU */
228  /* END MODULEBUILDER TOPMENU */
229  /* BEGIN MODULEBUILDER LEFTMENU CONFERENCEORBOOTH*/
230  $this->menu[$r++]=array(
231  '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
232  'type'=>'left', // This is a Left menu entry
233  'titre'=>'EventOrganizationMenuLeft',
234  'prefix' => img_picto('', 'eventorganization', 'class="paddingright pictofixedwidth"'),
235  'mainmenu'=>'project',
236  'leftmenu'=>'eventorganization',
237  'url'=>'',
238  'langs'=>'eventorganization', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
239  'position'=>1000+$r,
240  'enabled'=>'$conf->eventorganization->enabled', // 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.
241  'perms'=>'$user->rights->eventorganization->read', // Use 'perms'=>'$user->rights->eventorganization->level1->level2' if you want your menu with a permission rules
242  'target'=>'',
243  'user'=>2, // 0=Menu for internal users, 1=external users, 2=both
244  );
245  $this->menu[$r++]=array(
246  '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
247  'type'=>'left', // This is a Left menu entry
248  'titre'=>'List',
249  'url'=>'/projet/list.php?search_usage_event_organization=1&search_status=99&mainmenu=project&contextpage=organizedevents',
250  'langs'=>'eventorganization@eventorganization', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
251  'position'=>1000+$r,
252  'enabled'=>'$conf->eventorganization->enabled', // 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.
253  'perms'=>'$user->rights->eventorganization->read', // Use 'perms'=>'$user->rights->eventorganization->level1->level2' if you want your menu with a permission rules
254  'target'=>'',
255  'user'=>2, // 0=Menu for internal users, 1=external users, 2=both
256  );
257  $this->menu[$r++]=array(
258  '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
259  'type'=>'left', // This is a Left menu entry
260  'titre'=>'New',
261  'url'=>'/projet/card.php?leftmenu=projects&action=create&usage_organize_event=1&usage_opportunity=0',
262  'langs'=>'eventorganization@eventorganization', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
263  'position'=>1000+$r,
264  'enabled'=>'$conf->eventorganization->enabled', // 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.
265  'perms'=>'$user->rights->eventorganization->write', // Use 'perms'=>'$user->rights->eventorganization->level1->level2' if you want your menu with a permission rules
266  'target'=>'',
267  'user'=>2, // 0=Menu for internal users, 1=external users, 2=both
268  );
269  $this->menu[$r++]=array(
270  '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
271  'type'=>'left', // This is a Left menu entry
272  'titre'=>'ConferenceOrBooth',
273  'prefix' => img_picto('', 'conferenceorbooth', 'class="paddingright pictofixedwidth"'),
274  'mainmenu'=>'project',
275  'leftmenu'=>'eventorganizationconforbooth',
276  'url'=>'',
277  'langs'=>'eventorganization', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
278  'position'=>1000+$r,
279  'enabled'=>'$conf->eventorganization->enabled', // 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.
280  'perms'=>'$user->rights->eventorganization->read', // Use 'perms'=>'$user->rights->eventorganization->level1->level2' if you want your menu with a permission rules
281  'target'=>'',
282  'user'=>2, // 0=Menu for internal users, 1=external users, 2=both
283  );
284  $this->menu[$r++]=array(
285  '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
286  'type'=>'left', // This is a Left menu entry
287  'titre'=>'List',
288  'url'=>'/eventorganization/conferenceorbooth_list.php?mainmenu=project',
289  'langs'=>'eventorganization', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
290  'position'=>1000+$r,
291  'enabled'=>'$conf->eventorganization->enabled', // 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.
292  'perms'=>'$user->rights->eventorganization->read', // Use 'perms'=>'$user->rights->eventorganization->level1->level2' if you want your menu with a permission rules
293  'target'=>'',
294  'user'=>2, // 0=Menu for internal users, 1=external users, 2=both
295  );
296  $this->menu[$r++]=array(
297  '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
298  'type'=>'left', // This is a Left menu entry
299  'titre'=>'New',
300  'url'=>'/eventorganization/conferenceorbooth_card.php?leftmenu=projects&action=create',
301  'langs'=>'eventorganization', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
302  'position'=>1000+$r,
303  'enabled'=>'$conf->eventorganization->enabled', // 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.
304  'perms'=>'$user->rights->eventorganization->write', // Use 'perms'=>'$user->rights->eventorganization->level1->level2' if you want your menu with a permission rules
305  'target'=>'',
306  'user'=>2, // 0=Menu for internal users, 1=external users, 2=both
307  );
308  /* END MODULEBUILDER LEFTMENU CONFERENCEORBOOTH */
309  // Exports profiles provided by this module
310  $r = 1;
311  /* BEGIN MODULEBUILDER EXPORT CONFERENCEORBOOTH */
312  /* END MODULEBUILDER EXPORT CONFERENCEORBOOTH */
313 
314  // Imports profiles provided by this module
315  $r = 1;
316  /* BEGIN MODULEBUILDER IMPORT CONFERENCEORBOOTH */
317  /* END MODULEBUILDER IMPORT CONFERENCEORBOOTH */
318  }
319 
328  public function init($options = '')
329  {
330  global $conf, $langs;
331 
332  // Permissions
333  $this->remove($options);
334 
335  $sql = array();
336 
337  // Document templates
338  $moduledir = 'eventorganization';
339  $myTmpObjects = array();
340  $myTmpObjects['ConferenceOrBooth'] = array('includerefgeneration'=>0, 'includedocgeneration'=>0);
341 
342  foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
343  if ($myTmpObjectKey == 'ConferenceOrBooth') {
344  continue;
345  }
346  if ($myTmpObjectArray['includerefgeneration']) {
347  $src = DOL_DOCUMENT_ROOT.'/install/doctemplates/eventorganization/template_conferenceorbooths.odt';
348  $dirodt = DOL_DATA_ROOT.'/doctemplates/eventorganization';
349  $dest = $dirodt.'/template_conferenceorbooths.odt';
350 
351  if (file_exists($src) && !file_exists($dest)) {
352  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
353  dol_mkdir($dirodt);
354  $result = dol_copy($src, $dest, 0, 0);
355  if ($result < 0) {
356  $langs->load("errors");
357  $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
358  return 0;
359  }
360  }
361 
362  $sql = array_merge($sql, array(
363  "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = 'standard_".strtolower($myTmpObjectKey)."' AND type = '".$this->db->escape(strtolower($myTmpObjectKey))."' AND entity = ".((int) $conf->entity),
364  "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('standard_".strtolower($myTmpObjectKey)."','".$this->db->escape(strtolower($myTmpObjectKey))."',".((int) $conf->entity).")",
365  "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),
366  "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('generic_".strtolower($myTmpObjectKey)."_odt', '".$this->db->escape(strtolower($myTmpObjectKey))."', ".((int) $conf->entity).")"
367  ));
368  }
369  }
370 
371  $init = $this->_init($sql, $options);
372 
373  return $init;
374  }
375 
384  public function remove($options = '')
385  {
386  $sql = array();
387  return $this->_remove($sql, $options);
388  }
389 }
db
$conf db
API class for accounts.
Definition: inc.php:41
description
print *****$script_file(".$version.") pid cd cd cd description as description
Definition: email_expire_services_to_customers.php:83
modEventOrganization
Description and activation class for module EventOrganization This module is base on this specificati...
Definition: modEventOrganization.class.php:34
name
$conf db name
Definition: repair.php:122
DolibarrModules\_remove
_remove($array_sql, $options='')
Disable function.
Definition: DolibarrModules.class.php:482
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
modEventOrganization\__construct
__construct($db)
Constructor.
Definition: modEventOrganization.class.php:41
dol_copy
dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1)
Copy a file to another file.
Definition: files.lib.php:703
modEventOrganization\init
init($options='')
Function called when module is enabled.
Definition: modEventOrganization.class.php:328
DolibarrModules\_init
_init($array_sql, $options='')
Enables a module.
Definition: DolibarrModules.class.php:383
dol_mkdir
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
Definition: functions.lib.php:6603
DolibarrModules
Class DolibarrModules.
Definition: DolibarrModules.class.php:37