modAgenda.class.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. <?php
  2. /* Copyright (C) 2003,2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2003 Jean-Louis Bergamo <jlb@j1b.org>
  4. * Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
  6. * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
  7. * Copyright (C) 2009-2011 Regis Houssin <regis.houssin@capnetworks.com>
  8. * Copyright (C) 2013 Cedric Gross <c.gross@kreiz-it.fr>
  9. * Copyright (C) 2015 Bahfir Abbes <bafbes@gmail.com>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 3 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. */
  24. /**
  25. * \defgroup agenda Module agenda
  26. * \brief Module to manage agenda and events
  27. * \file htdocs/core/modules/modAgenda.class.php
  28. * \ingroup agenda
  29. * \brief File of class to describe and enable/disable module Agenda
  30. */
  31. include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php';
  32. /**
  33. * Class to describe and enable/disable module Agenda
  34. */
  35. class modAgenda extends DolibarrModules
  36. {
  37. /**
  38. * Constructor. Define names, constants, directories, boxes, permissions
  39. *
  40. * @param DoliDB $db Database handler
  41. */
  42. function __construct($db)
  43. {
  44. global $conf, $user;
  45. $this->db = $db;
  46. $this->numero = 2400;
  47. $this->family = "projects";
  48. $this->module_position = 15;
  49. // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
  50. $this->name = preg_replace('/^mod/i','',get_class($this));
  51. $this->description = "Follow events or rendez-vous. Record manual events into Agendas or let application record automatic events for log tracking.";
  52. $this->version = 'dolibarr'; // 'experimental' or 'dolibarr' or version
  53. // Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase)
  54. $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
  55. $this->special = 0;
  56. $this->picto='action';
  57. // Data directories to create when module is enabled
  58. $this->dirs = array("/agenda/temp");
  59. // Config pages
  60. //-------------
  61. $this->config_page_url = array("agenda_other.php");
  62. // Dependancies
  63. //-------------
  64. $this->depends = array();
  65. $this->requiredby = array();
  66. $this->langfiles = array("companies");
  67. // Constants
  68. //-----------
  69. $this->const = array();
  70. $sqlreadactions="SELECT code, label, description FROM ".MAIN_DB_PREFIX."c_action_trigger ORDER by rang";
  71. $resql = $this->db->query($sqlreadactions);
  72. if ($resql)
  73. {
  74. while ($obj = $this->db->fetch_object($sqlreadactions))
  75. {
  76. if (preg_match('/_CREATE$/',$obj->code) && ($obj->code != 'COMPANY_CREATE')) continue; // We don't track such events (*_CREATE) by default, we prefer validation (except thirdparty creation because there is no validation).
  77. if (preg_match('/^PROJECT_/',$obj->code)) continue; // We don't track such events by default.
  78. if (preg_match('/^TASK_/',$obj->code)) continue; // We don't track such events by default.
  79. $this->const[] = array('MAIN_AGENDA_ACTIONAUTO_'.$obj->code, "chaine", "1");
  80. }
  81. }
  82. else
  83. {
  84. dol_print_error($this->db->lasterror());
  85. }
  86. // New pages on tabs
  87. // -----------------
  88. $this->tabs = array();
  89. // Boxes
  90. //------
  91. $this->boxes = array(0=>array('file'=>'box_actions.php','enabledbydefaulton'=>'Home'));
  92. // Permissions
  93. //------------
  94. $this->rights = array();
  95. $this->rights_class = 'agenda';
  96. $r=0;
  97. // $this->rights[$r][0] Id permission (unique tous modules confondus)
  98. // $this->rights[$r][1] Libelle par defaut si traduction de cle "PermissionXXX" non trouvee (XXX = Id permission)
  99. // $this->rights[$r][2] Non utilise
  100. // $this->rights[$r][3] 1=Permis par defaut, 0=Non permis par defaut
  101. // $this->rights[$r][4] Niveau 1 pour nommer permission dans code
  102. // $this->rights[$r][5] Niveau 2 pour nommer permission dans code
  103. // $r++;
  104. $this->rights[$r][0] = 2401;
  105. $this->rights[$r][1] = 'Read actions/tasks linked to his account';
  106. $this->rights[$r][2] = 'r';
  107. $this->rights[$r][3] = 1;
  108. $this->rights[$r][4] = 'myactions';
  109. $this->rights[$r][5] = 'read';
  110. $r++;
  111. $this->rights[$r][0] = 2402;
  112. $this->rights[$r][1] = 'Create/modify actions/tasks linked to his account';
  113. $this->rights[$r][2] = 'w';
  114. $this->rights[$r][3] = 0;
  115. $this->rights[$r][4] = 'myactions';
  116. $this->rights[$r][5] = 'create';
  117. $r++;
  118. $this->rights[$r][0] = 2403;
  119. $this->rights[$r][1] = 'Delete actions/tasks linked to his account';
  120. $this->rights[$r][2] = 'w';
  121. $this->rights[$r][3] = 0;
  122. $this->rights[$r][4] = 'myactions';
  123. $this->rights[$r][5] = 'delete';
  124. $r++;
  125. $this->rights[$r][0] = 2411;
  126. $this->rights[$r][1] = 'Read actions/tasks of others';
  127. $this->rights[$r][2] = 'r';
  128. $this->rights[$r][3] = 0;
  129. $this->rights[$r][4] = 'allactions';
  130. $this->rights[$r][5] = 'read';
  131. $r++;
  132. $this->rights[$r][0] = 2412;
  133. $this->rights[$r][1] = 'Create/modify actions/tasks of others';
  134. $this->rights[$r][2] = 'w';
  135. $this->rights[$r][3] = 0;
  136. $this->rights[$r][4] = 'allactions';
  137. $this->rights[$r][5] = 'create';
  138. $r++;
  139. $this->rights[$r][0] = 2413;
  140. $this->rights[$r][1] = 'Delete actions/tasks of others';
  141. $this->rights[$r][2] = 'w';
  142. $this->rights[$r][3] = 0;
  143. $this->rights[$r][4] = 'allactions';
  144. $this->rights[$r][5] = 'delete';
  145. $r++;
  146. $this->rights[$r][0] = 2414;
  147. $this->rights[$r][1] = 'Export actions/tasks of others';
  148. $this->rights[$r][2] = 'w';
  149. $this->rights[$r][3] = 0;
  150. $this->rights[$r][4] = 'export';
  151. // Main menu entries
  152. $this->menu = array(); // List of menus to add
  153. $r=0;
  154. // Add here entries to declare new menus
  155. // Example to declare the Top Menu entry:
  156. // $this->menu[$r]=array( 'fk_menu'=>0, // Put 0 if this is a top menu
  157. // 'type'=>'top', // This is a Top menu entry
  158. // 'titre'=>'MyModule top menu',
  159. // 'mainmenu'=>'mymodule',
  160. // 'url'=>'/mymodule/pagetop.php',
  161. // 'langs'=>'mylangfile', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
  162. // 'position'=>100,
  163. // 'enabled'=>'1', // Define condition to show or hide menu entry. Use '$conf->mymodule->enabled' if entry must be visible if module is enabled.
  164. // 'perms'=>'1', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
  165. // 'target'=>'',
  166. // 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both
  167. // $r++;
  168. $this->menu[$r]=array('fk_menu'=>0,
  169. 'type'=>'top',
  170. 'titre'=>'Agenda',
  171. 'mainmenu'=>'agenda',
  172. 'url'=>'/comm/action/index.php',
  173. 'langs'=>'agenda',
  174. 'position'=>100,
  175. 'perms'=>'$user->rights->agenda->myactions->read',
  176. 'enabled'=>'$conf->agenda->enabled',
  177. 'target'=>'',
  178. 'user'=>2);
  179. $r++;
  180. $this->menu[$r]=array('fk_menu'=>'r=0',
  181. 'type'=>'left',
  182. 'titre'=>'Actions',
  183. 'mainmenu'=>'agenda',
  184. 'url'=>'/comm/action/index.php?mainmenu=agenda&amp;leftmenu=agenda',
  185. 'langs'=>'agenda',
  186. 'position'=>100,
  187. 'perms'=>'$user->rights->agenda->myactions->read',
  188. 'enabled'=>'$conf->agenda->enabled',
  189. 'target'=>'',
  190. 'user'=>2);
  191. $r++;
  192. $this->menu[$r]=array('fk_menu'=>'r=1',
  193. 'type'=>'left',
  194. 'titre'=>'NewAction',
  195. 'mainmenu'=>'agenda',
  196. 'url'=>'/comm/action/card.php?mainmenu=agenda&amp;leftmenu=agenda&amp;action=create',
  197. 'langs'=>'commercial',
  198. 'position'=>101,
  199. 'perms'=>'($user->rights->agenda->myactions->create||$user->rights->agenda->allactions->create)',
  200. 'enabled'=>'$conf->agenda->enabled',
  201. 'target'=>'',
  202. 'user'=>2);
  203. $r++;
  204. // Calendar
  205. $this->menu[$r]=array('fk_menu'=>'r=1',
  206. 'type'=>'left',
  207. 'titre'=>'Agenda',
  208. 'mainmenu'=>'agenda',
  209. 'url'=>'/comm/action/index.php?mainmenu=agenda&amp;leftmenu=agenda',
  210. 'langs'=>'agenda',
  211. 'position'=>102,
  212. 'perms'=>'$user->rights->agenda->myactions->read',
  213. 'enabled'=>'$conf->agenda->enabled',
  214. 'target'=>'',
  215. 'user'=>2);
  216. $r++;
  217. $this->menu[$r]=array('fk_menu'=>'r=3',
  218. 'type'=>'left',
  219. 'titre'=>'MenuToDoMyActions',
  220. 'mainmenu'=>'agenda',
  221. 'url'=>'/comm/action/index.php?mainmenu=agenda&amp;leftmenu=agenda&amp;status=todo&amp;filter=mine',
  222. 'langs'=>'agenda',
  223. 'position'=>103,
  224. 'perms'=>'$user->rights->agenda->myactions->read',
  225. 'enabled'=>'$conf->agenda->enabled',
  226. 'target'=>'',
  227. 'user'=>2);
  228. $r++;
  229. $this->menu[$r]=array('fk_menu'=>'r=3',
  230. 'type'=>'left',
  231. 'titre'=>'MenuDoneMyActions',
  232. 'mainmenu'=>'agenda',
  233. 'url'=>'/comm/action/index.php?mainmenu=agenda&amp;leftmenu=agenda&amp;status=done&amp;filter=mine',
  234. 'langs'=>'agenda',
  235. 'position'=>104,
  236. 'perms'=>'$user->rights->agenda->myactions->read',
  237. 'enabled'=>'$conf->agenda->enabled',
  238. 'target'=>'',
  239. 'user'=>2);
  240. $r++;
  241. $this->menu[$r]=array('fk_menu'=>'r=3',
  242. 'type'=>'left',
  243. 'titre'=>'MenuToDoActions',
  244. 'mainmenu'=>'agenda',
  245. 'url'=>'/comm/action/index.php?mainmenu=agenda&amp;leftmenu=agenda&amp;status=todo&amp;filtert=-1',
  246. 'langs'=>'agenda',
  247. 'position'=>105,
  248. 'perms'=>'$user->rights->agenda->allactions->read',
  249. 'enabled'=>'$user->rights->agenda->allactions->read',
  250. 'target'=>'',
  251. 'user'=>2);
  252. $r++;
  253. $this->menu[$r]=array('fk_menu'=>'r=3',
  254. 'type'=>'left',
  255. 'titre'=>'MenuDoneActions',
  256. 'mainmenu'=>'agenda',
  257. 'url'=>'/comm/action/index.php?mainmenu=agenda&amp;leftmenu=agenda&amp;status=done&amp;filtert=-1',
  258. 'langs'=>'agenda',
  259. 'position'=>106,
  260. 'perms'=>'$user->rights->agenda->allactions->read',
  261. 'enabled'=>'$user->rights->agenda->allactions->read',
  262. 'target'=>'',
  263. 'user'=>2);
  264. $r++;
  265. // List
  266. $this->menu[$r]=array('fk_menu'=>'r=1',
  267. 'type'=>'left',
  268. 'titre'=>'List',
  269. 'mainmenu'=>'agenda',
  270. 'url'=>'/comm/action/listactions.php?mainmenu=agenda&amp;leftmenu=agenda',
  271. 'langs'=>'agenda',
  272. 'position'=>112,
  273. 'perms'=>'$user->rights->agenda->myactions->read',
  274. 'enabled'=>'$conf->agenda->enabled',
  275. 'target'=>'',
  276. 'user'=>2);
  277. $r++;
  278. $this->menu[$r]=array('fk_menu'=>'r=8',
  279. 'type'=>'left',
  280. 'titre'=>'MenuToDoMyActions',
  281. 'mainmenu'=>'agenda',
  282. 'url'=>'/comm/action/listactions.php?mainmenu=agenda&amp;leftmenu=agenda&amp;status=todo&amp;filter=mine',
  283. 'langs'=>'agenda',
  284. 'position'=>113,
  285. 'perms'=>'$user->rights->agenda->myactions->read',
  286. 'enabled'=>'$conf->agenda->enabled',
  287. 'target'=>'',
  288. 'user'=>2);
  289. $r++;
  290. $this->menu[$r]=array('fk_menu'=>'r=8',
  291. 'type'=>'left',
  292. 'titre'=>'MenuDoneMyActions',
  293. 'mainmenu'=>'agenda',
  294. 'url'=>'/comm/action/listactions.php?mainmenu=agenda&amp;leftmenu=agenda&amp;status=done&amp;filter=mine',
  295. 'langs'=>'agenda',
  296. 'position'=>114,
  297. 'perms'=>'$user->rights->agenda->myactions->read',
  298. 'enabled'=>'$conf->agenda->enabled',
  299. 'target'=>'',
  300. 'user'=>2);
  301. $r++;
  302. $this->menu[$r]=array('fk_menu'=>'r=8',
  303. 'type'=>'left',
  304. 'titre'=>'MenuToDoActions',
  305. 'mainmenu'=>'agenda',
  306. 'url'=>'/comm/action/listactions.php?mainmenu=agenda&amp;leftmenu=agenda&amp;status=todo&amp;filtert=-1',
  307. 'langs'=>'agenda',
  308. 'position'=>115,
  309. 'perms'=>'$user->rights->agenda->allactions->read',
  310. 'enabled'=>'$user->rights->agenda->allactions->read',
  311. 'target'=>'',
  312. 'user'=>2);
  313. $r++;
  314. $this->menu[$r]=array('fk_menu'=>'r=8',
  315. 'type'=>'left',
  316. 'titre'=>'MenuDoneActions',
  317. 'mainmenu'=>'agenda',
  318. 'url'=>'/comm/action/listactions.php?mainmenu=agenda&amp;leftmenu=agenda&amp;status=done&amp;filtert=-1',
  319. 'langs'=>'agenda',
  320. 'position'=>116,
  321. 'perms'=>'$user->rights->agenda->allactions->read',
  322. 'enabled'=>'$user->rights->agenda->allactions->read',
  323. 'target'=>'',
  324. 'user'=>2);
  325. $r++;
  326. // Reports
  327. $this->menu[$r]=array('fk_menu'=>'r=1',
  328. 'type'=>'left',
  329. 'titre'=>'Reportings',
  330. 'mainmenu'=>'agenda',
  331. 'url'=>'/comm/action/rapport/index.php?mainmenu=agenda&amp;leftmenu=agenda',
  332. 'langs'=>'agenda',
  333. 'position'=>120,
  334. 'perms'=>'$user->rights->agenda->allactions->read',
  335. 'enabled'=>'$conf->agenda->enabled',
  336. 'target'=>'',
  337. 'user'=>2);
  338. $r++;
  339. // Exports
  340. //--------
  341. $r=0;
  342. $r++;
  343. $this->export_code[$r]=$this->rights_class.'_'.$r;
  344. $this->export_label[$r]="ExportDataset_event1";
  345. $this->export_permission[$r]=array(array("agenda","export"));
  346. $this->export_fields_array[$r]=array('ac.id'=>"IdAgenda",'ac.ref_ext'=>"ExternalRef",'ac.datec'=>"DateCreation",'ac.datep'=>"DateActionBegin",
  347. 'ac.datep2'=>"DateActionEnd",'ac.label'=>"Title",'ac.note'=>"Note",'ac.percent'=>"Percent",'ac.durationp'=>"Duration",
  348. 'cac.libelle'=>"ActionType",
  349. 's.rowid'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.zip'=>'Zip','s.town'=>'Town',
  350. 'co.code'=>'CountryCode','s.phone'=>'Phone','s.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','s.idprof5'=>'ProfId5','s.idprof6'=>'ProfId6',
  351. 's.code_compta'=>'CustomerAccountancyCode','s.code_compta_fournisseur'=>'SupplierAccountancyCode','s.tva_intra'=>'VATIntra');
  352. $this->export_TypeFields_array[$r]=array('ac.ref_ext'=>"Text",'ac.datec'=>"Date",'ac.datep'=>"Date",
  353. 'ac.datep2'=>"Date",'ac.label'=>"Text",'ac.note'=>"Text",'ac.percent'=>"Numeric",
  354. 'ac.durationp'=>"Duree",
  355. 'cac.libelle'=>"List:c_actioncomm:libelle:id",
  356. 's.nom'=>'Text','s.address'=>'Text','s.zip'=>'Text','s.town'=>'Text',
  357. 'co.code'=>'Text','s.phone'=>'Text','s.siren'=>'Text','s.siret'=>'Text','s.ape'=>'Text','s.idprof4'=>'Text','s.idprof5'=>'Text','s.idprof6'=>'Text',
  358. 's.code_compta'=>'Text','s.code_compta_fournisseur'=>'Text','s.tva_intra'=>'Text');
  359. $this->export_entities_array[$r]=array('ac.id'=>"action",'ac.ref_ext'=>"action",'ac.datec'=>"action",'ac.datep'=>"action",
  360. 'ac.datep2'=>"action",'ac.label'=>"action",'ac.note'=>"action",'ac.percent'=>"action",'ac.durationp'=>"action",
  361. 'cac.libelle'=>"action",
  362. 's.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.zip'=>'company','s.town'=>'company',
  363. 'co.code'=>'company','s.phone'=>'company','s.siren'=>'company','s.siret'=>'company','s.ape'=>'company','s.idprof4'=>'company','s.idprof5'=>'company','s.idprof6'=>'company',
  364. 's.code_compta'=>'company','s.code_compta_fournisseur'=>'company','s.tva_intra'=>'company',);
  365. $this->export_sql_start[$r]='SELECT DISTINCT ';
  366. $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'actioncomm as ac';
  367. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_actioncomm as cac on ac.fk_action = cac.id';
  368. if(!$user->rights->agenda->allactions->read) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'actioncomm_resources acr on ac.id = acr.fk_actioncomm';
  369. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'socpeople as sp on ac.fk_contact = sp.rowid';
  370. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s on ac.fk_soc = s.rowid';
  371. if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
  372. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as co on s.fk_pays = co.rowid';
  373. $this->export_sql_end[$r] .=' WHERE ac.entity IN ('.getEntity('agenda',1).')';
  374. if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' AND (sc.fk_user = '.$user->id.' OR ac.fk_soc IS NULL)';
  375. if(!$user->rights->agenda->allactions->read) $this->export_sql_end[$r] .=' AND acr.fk_element = '.$user->id;
  376. $this->export_sql_end[$r] .=' ORDER BY ac.datep';
  377. }
  378. }