modEventOrganization.class.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  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. /**
  18. * \defgroup eventorganization Module EventOrganization
  19. * \brief EventOrganization module descriptor.
  20. *
  21. * \file htdocs/core/modules/modEventOrganization.class.php
  22. * \ingroup eventorganization
  23. * \brief Description and activation file for the EventOrganization
  24. */
  25. include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  27. /**
  28. * Description and activation class for module EventOrganization
  29. * This module is base on this specification :
  30. * https://wiki.dolibarr.org/index.php/Draft:Module_Event_Organization
  31. */
  32. class modEventOrganization extends DolibarrModules
  33. {
  34. /**
  35. * Constructor. Define names, constants, directories, boxes, permissions
  36. *
  37. * @param DoliDB $db Database handler
  38. */
  39. public function __construct($db)
  40. {
  41. global $langs, $conf;
  42. $this->db = $db;
  43. $this->numero = 2450;
  44. $this->rights_class = 'eventorganization';
  45. $this->family = "projects";
  46. $this->module_position = '20';
  47. $this->name = preg_replace('/^mod/i', '', get_class($this));
  48. $this->description = "EventOrganizationDescription";
  49. $this->descriptionlong = "EventOrganizationDescriptionLong";
  50. $this->version = 'dolibarr';
  51. // Key used in llx_const table to save module status enabled/disabled (where EVENTORGANIZATION is value of property name of module in uppercase)
  52. $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
  53. $this->picto = 'action';
  54. // Define some features supported by module (triggers, login, substitutions, menus, css, etc...)
  55. $this->module_parts = array(
  56. // Set this to 1 if module has its own trigger directory (core/triggers)
  57. 'triggers' => 1,
  58. // Set this to 1 if module has its own login method file (core/login)
  59. 'login' => 0,
  60. // Set this to 1 if module has its own substitution function file (core/substitutions)
  61. 'substitutions' => 0,
  62. // Set this to 1 if module has its own menus handler directory (core/menus)
  63. 'menus' => 0,
  64. // Set this to 1 if module overwrite template dir (core/tpl)
  65. 'tpl' => 0,
  66. // Set this to 1 if module has its own barcode directory (core/modules/barcode)
  67. 'barcode' => 0,
  68. // Set this to 1 if module has its own models directory (core/modules/xxx)
  69. 'models' => 1,
  70. // Set this to 1 if module has its own printing directory (core/modules/printing)
  71. 'printing' => 0,
  72. // Set this to 1 if module has its own theme directory (theme)
  73. 'theme' => 0,
  74. // Set this to relative path of css file if module has its own css file
  75. 'css' => array(
  76. // '/eventorganization/css/eventorganization.css.php',
  77. ),
  78. // Set this to relative path of js file if module must load a js on all pages
  79. 'js' => array(
  80. // '/eventorganization/js/eventorganization.js.php',
  81. ),
  82. // 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'
  83. 'hooks' => array(
  84. // 'data' => array(
  85. // 'hookcontext1',
  86. // 'hookcontext2',
  87. // ),
  88. // 'entity' => '0',
  89. ),
  90. // Set this to 1 if features of module are opened to external users
  91. 'moduleforexternal' => 0,
  92. );
  93. // Data directories to create when module is enabled.
  94. // Example: this->dirs = array("/eventorganization/temp","/eventorganization/subdir");
  95. $this->dirs = array("/eventorganization/temp");
  96. // Config pages. Put here list of php page, stored into eventorganization/admin directory, to use to setup module.
  97. $this->config_page_url = array("eventorganization.php");
  98. // Dependencies
  99. // A condition to hide module
  100. $this->hidden = false;
  101. // List of module class names as string that must be enabled if this module is enabled. Example: array('always1'=>'modModuleToEnable1','always2'=>'modModuleToEnable2', 'FR1'=>'modModuleToEnableFR'...)
  102. $this->depends = array('modProjet','modCategorie');
  103. $this->requiredby = array(); // List of module class names as string to disable if this one is disabled. Example: array('modModuleToDisable1', ...)
  104. $this->conflictwith = array(); // List of module class names as string this module is in conflict with. Example: array('modModuleToDisable1', ...)
  105. // The language file dedicated to your module
  106. $this->langfiles = array("eventorganization");
  107. // Prerequisites
  108. $this->phpmin = array(5, 6); // Minimum version of PHP required by module
  109. $this->need_dolibarr_version = array(13, -3); // Minimum version of Dolibarr required by module
  110. // Messages at activation
  111. $this->warnings_activation = array(); // Warning to show when we activate module. array('always'='text') or array('FR'='textfr','ES'='textes'...)
  112. $this->warnings_activation_ext = array(); // Warning to show when we activate an external module. array('always'='text') or array('FR'='textfr','ES'='textes'...)
  113. //$this->automatic_activation = array('FR'=>'EventOrganizationWasAutomaticallyActivatedBecauseOfYourCountryChoice');
  114. //$this->always_enabled = true; // If true, can't be disabled
  115. // Constants
  116. // List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive)
  117. // Example: $this->const=array(1 => array('EVENTORGANIZATION_MYNEWCONST1', 'chaine', 'myvalue', 'This is a constant to add', 1),
  118. // 2 => array('EVENTORGANIZATION_MYNEWCONST2', 'chaine', 'myvalue', 'This is another constant to add', 0, 'current', 1)
  119. // );
  120. $this->const = array(1 => array('EVENTORGANIZATION_TASK_LABEL', 'chaine', '', '', 0));
  121. // Some keys to add into the overwriting translation tables
  122. /*$this->overwrite_translation = array(
  123. 'en_US:ParentCompany'=>'Parent company or reseller',
  124. 'fr_FR:ParentCompany'=>'Maison mère ou revendeur'
  125. )*/
  126. if (!isset($conf->eventorganization) || !isset($conf->eventorganization->enabled)) {
  127. $conf->eventorganization = new stdClass();
  128. $conf->eventorganization->enabled = 0;
  129. }
  130. // Array to add new pages in new tabs
  131. $this->tabs = array();
  132. // Example:
  133. // $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
  134. // $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.
  135. // $this->tabs[] = array('data'=>'objecttype:-tabname:NU:conditiontoremove'); // To remove an existing tab identified by code tabname
  136. //
  137. // Where objecttype can be
  138. // 'categories_x' to add a tab in category view (replace 'x' by type of category (0=product, 1=supplier, 2=customer, 3=member)
  139. // 'contact' to add a tab in contact view
  140. // 'contract' to add a tab in contract view
  141. // 'group' to add a tab in group view
  142. // 'intervention' to add a tab in intervention view
  143. // 'invoice' to add a tab in customer invoice view
  144. // 'invoice_supplier' to add a tab in supplier invoice view
  145. // 'member' to add a tab in fundation member view
  146. // 'opensurveypoll' to add a tab in opensurvey poll view
  147. // 'order' to add a tab in customer order view
  148. // 'order_supplier' to add a tab in supplier order view
  149. // 'payment' to add a tab in payment view
  150. // 'payment_supplier' to add a tab in supplier payment view
  151. // 'product' to add a tab in product view
  152. // 'propal' to add a tab in propal view
  153. // 'project' to add a tab in project view
  154. // 'stock' to add a tab in stock view
  155. // 'thirdparty' to add a tab in third party view
  156. // 'user' to add a tab in user view
  157. // Dictionaries
  158. $this->dictionaries = array();
  159. // Boxes/Widgets
  160. // Add here list of php file(s) stored in eventorganization/core/boxes that contains a class to show a widget.
  161. $this->boxes = array(
  162. // 0 => array(
  163. // 'file' => 'eventorganizationwidget1.php@eventorganization',
  164. // 'note' => 'Widget provided by EventOrganization',
  165. // 'enabledbydefaulton' => 'Home',
  166. // ),
  167. // ...
  168. );
  169. // Cronjobs (List of cron jobs entries to add when module is enabled)
  170. // unit_frequency must be 60 for minute, 3600 for hour, 86400 for day, 604800 for week
  171. $this->cronjobs = array(
  172. );
  173. // Permissions provided by this module
  174. $this->rights = array();
  175. $r = 1;
  176. // Add here entries to declare new permissions
  177. /* BEGIN MODULEBUILDER PERMISSIONS */
  178. $this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used)
  179. $this->rights[$r][1] = 'Read objects of EventOrganization'; // Permission label
  180. $this->rights[$r][4] = 'read'; // In php code, permission will be checked by test if ($user->rights->eventorganization->level1)
  181. $r++;
  182. $this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used)
  183. $this->rights[$r][1] = 'Create/Update objects of EventOrganization'; // Permission label
  184. $this->rights[$r][4] = 'write'; // In php code, permission will be checked by test if ($user->rights->eventorganization->level1)
  185. $r++;
  186. $this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used)
  187. $this->rights[$r][1] = 'Delete objects of EventOrganization'; // Permission label
  188. $this->rights[$r][4] = 'delete'; // In php code, permission will be checked by test if ($user->rights->eventorganization->level1)
  189. $r++;
  190. /* END MODULEBUILDER PERMISSIONS */
  191. // Main menu entries to add
  192. $this->menu = array();
  193. $r = 0;
  194. // Add here entries to declare new menus
  195. /* BEGIN MODULEBUILDER TOPMENU */
  196. /* END MODULEBUILDER TOPMENU */
  197. /* BEGIN MODULEBUILDER LEFTMENU CONFERENCEORBOOTH*/
  198. $this->menu[$r++]=array(
  199. '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
  200. 'type'=>'left', // This is a Left menu entry
  201. 'titre'=>'EventOrganizationMenuLeft',
  202. 'prefix' => img_picto('', 'eventorganization', 'class="paddingright pictofixedwidth"'),
  203. 'mainmenu'=>'project',
  204. 'leftmenu'=>'eventorganization',
  205. 'url'=>'',
  206. 'langs'=>'eventorganization', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
  207. 'position'=>1000+$r,
  208. '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.
  209. 'perms'=>'$user->rights->eventorganization->read', // Use 'perms'=>'$user->rights->eventorganization->level1->level2' if you want your menu with a permission rules
  210. 'target'=>'',
  211. 'user'=>2, // 0=Menu for internal users, 1=external users, 2=both
  212. );
  213. $this->menu[$r++]=array(
  214. '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
  215. 'type'=>'left', // This is a Left menu entry
  216. 'titre'=>'List',
  217. 'url'=>'/projet/list.php?search_usage_event_organization=1&search_status=99&mainmenu=project&contextpage=organizedevents',
  218. 'langs'=>'eventorganization@eventorganization', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
  219. 'position'=>1000+$r,
  220. '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.
  221. 'perms'=>'$user->rights->eventorganization->read', // Use 'perms'=>'$user->rights->eventorganization->level1->level2' if you want your menu with a permission rules
  222. 'target'=>'',
  223. 'user'=>2, // 0=Menu for internal users, 1=external users, 2=both
  224. );
  225. $this->menu[$r++]=array(
  226. '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
  227. 'type'=>'left', // This is a Left menu entry
  228. 'titre'=>'New',
  229. 'url'=>'/projet/card.php?leftmenu=projects&action=create&usage_organize_event=1&usage_opportunity=0',
  230. 'langs'=>'eventorganization@eventorganization', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
  231. 'position'=>1000+$r,
  232. '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.
  233. 'perms'=>'$user->rights->eventorganization->write', // Use 'perms'=>'$user->rights->eventorganization->level1->level2' if you want your menu with a permission rules
  234. 'target'=>'',
  235. 'user'=>2, // 0=Menu for internal users, 1=external users, 2=both
  236. );
  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'=>'ConferenceOrBooth',
  241. 'prefix' => img_picto('', 'conferenceorbooth', 'class="paddingright pictofixedwidth"'),
  242. 'mainmenu'=>'project',
  243. 'leftmenu'=>'eventorganizationconforbooth',
  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'=>'$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.
  248. 'perms'=>'$user->rights->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=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
  254. 'type'=>'left', // This is a Left menu entry
  255. 'titre'=>'List',
  256. 'url'=>'/eventorganization/conferenceorbooth_list.php?mainmenu=project',
  257. 'langs'=>'eventorganization', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
  258. 'position'=>1000+$r,
  259. '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.
  260. 'perms'=>'$user->rights->eventorganization->read', // 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=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
  266. 'type'=>'left', // This is a Left menu entry
  267. 'titre'=>'New',
  268. 'url'=>'/eventorganization/conferenceorbooth_card.php?leftmenu=projects&action=create',
  269. 'langs'=>'eventorganization', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
  270. 'position'=>1000+$r,
  271. '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.
  272. 'perms'=>'$user->rights->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. /* END MODULEBUILDER LEFTMENU CONFERENCEORBOOTH */
  277. // Exports profiles provided by this module
  278. $r = 1;
  279. /* BEGIN MODULEBUILDER EXPORT CONFERENCEORBOOTH */
  280. /* END MODULEBUILDER EXPORT CONFERENCEORBOOTH */
  281. // Imports profiles provided by this module
  282. $r = 1;
  283. /* BEGIN MODULEBUILDER IMPORT CONFERENCEORBOOTH */
  284. /* END MODULEBUILDER IMPORT CONFERENCEORBOOTH */
  285. }
  286. /**
  287. * Function called when module is enabled.
  288. * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
  289. * It also creates data directories
  290. *
  291. * @param string $options Options when enabling module ('', 'noboxes')
  292. * @return int 1 if OK, 0 if KO
  293. */
  294. public function init($options = '')
  295. {
  296. global $conf, $langs;
  297. // Permissions
  298. $this->remove($options);
  299. $sql = array();
  300. // Document templates
  301. $moduledir = 'eventorganization';
  302. $myTmpObjects = array();
  303. $myTmpObjects['ConferenceOrBooth'] = array('includerefgeneration'=>0, 'includedocgeneration'=>0);
  304. foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
  305. if ($myTmpObjectKey == 'ConferenceOrBooth') {
  306. continue;
  307. }
  308. if ($myTmpObjectArray['includerefgeneration']) {
  309. $src = DOL_DOCUMENT_ROOT.'/install/doctemplates/eventorganization/template_conferenceorbooths.odt';
  310. $dirodt = DOL_DATA_ROOT.'/doctemplates/eventorganization';
  311. $dest = $dirodt.'/template_conferenceorbooths.odt';
  312. if (file_exists($src) && !file_exists($dest)) {
  313. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  314. dol_mkdir($dirodt);
  315. $result = dol_copy($src, $dest, 0, 0);
  316. if ($result < 0) {
  317. $langs->load("errors");
  318. $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
  319. return 0;
  320. }
  321. }
  322. $sql = array_merge($sql, array(
  323. "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = 'standard_".strtolower($myTmpObjectKey)."' AND type = '".$this->db->escape(strtolower($myTmpObjectKey))."' AND entity = ".((int) $conf->entity),
  324. "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('standard_".strtolower($myTmpObjectKey)."','".$this->db->escape(strtolower($myTmpObjectKey))."',".((int) $conf->entity).")",
  325. "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),
  326. "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('generic_".strtolower($myTmpObjectKey)."_odt', '".$this->db->escape(strtolower($myTmpObjectKey))."', ".((int) $conf->entity).")"
  327. ));
  328. }
  329. }
  330. $init = $this->_init($sql, $options);
  331. return $init;
  332. }
  333. /**
  334. * Function called when module is disabled.
  335. * Remove from database constants, boxes and permissions from Dolibarr database.
  336. * Data directories are not deleted
  337. *
  338. * @param string $options Options when enabling module ('', 'noboxes')
  339. * @return int 1 if OK, 0 if KO
  340. */
  341. public function remove($options = '')
  342. {
  343. $sql = array();
  344. return $this->_remove($sql, $options);
  345. }
  346. }