modAgenda.class.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  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-2008 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. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. */
  23. /**
  24. * \defgroup agenda Module agenda
  25. * \brief Module to manage agenda and events
  26. * \file htdocs/core/modules/modAgenda.class.php
  27. * \ingroup agenda
  28. * \brief File of class to describe and enable/disable module Agenda
  29. */
  30. include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php';
  31. /**
  32. * Class to describe and enable/disable module Agenda
  33. */
  34. class modAgenda extends DolibarrModules
  35. {
  36. /**
  37. * Constructor. Define names, constants, directories, boxes, permissions
  38. *
  39. * @param DoliDB $db Database handler
  40. */
  41. function __construct($db)
  42. {
  43. global $conf;
  44. $this->db = $db;
  45. $this->numero = 2400;
  46. $this->family = "projects";
  47. // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
  48. $this->name = preg_replace('/^mod/i','',get_class($this));
  49. $this->description = "Gestion de l'agenda et des actions";
  50. $this->version = 'dolibarr'; // 'experimental' or 'dolibarr' or version
  51. // Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase)
  52. $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
  53. $this->special = 0;
  54. $this->picto='action';
  55. // Data directories to create when module is enabled
  56. $this->dirs = array("/agenda/temp");
  57. // Config pages
  58. //-------------
  59. $this->config_page_url = array("agenda.php");
  60. // Dependancies
  61. //-------------
  62. $this->depends = array();
  63. $this->requiredby = array();
  64. $this->langfiles = array("companies");
  65. // Constantes
  66. //-----------
  67. $this->const = array();
  68. $this->const[15] = array("MAIN_AGENDA_ACTIONAUTO_COMPANY_SENTBYMAIL","chaine","1");
  69. $this->const[0] = array("MAIN_AGENDA_ACTIONAUTO_COMPANY_CREATE","chaine","1");
  70. $this->const[1] = array("MAIN_AGENDA_ACTIONAUTO_CONTRACT_VALIDATE","chaine","1");
  71. $this->const[2] = array("MAIN_AGENDA_ACTIONAUTO_PROPAL_VALIDATE","chaine","1");
  72. $this->const[3] = array("MAIN_AGENDA_ACTIONAUTO_PROPAL_SENTBYMAIL","chaine","1");
  73. $this->const[4] = array("MAIN_AGENDA_ACTIONAUTO_ORDER_VALIDATE","chaine","1");
  74. $this->const[5] = array("MAIN_AGENDA_ACTIONAUTO_ORDER_SENTBYMAIL","chaine","1");
  75. $this->const[6] = array("MAIN_AGENDA_ACTIONAUTO_BILL_VALIDATE","chaine","1");
  76. $this->const[7] = array("MAIN_AGENDA_ACTIONAUTO_BILL_PAYED","chaine","1");
  77. $this->const[8] = array("MAIN_AGENDA_ACTIONAUTO_BILL_CANCEL","chaine","1");
  78. $this->const[9] = array("MAIN_AGENDA_ACTIONAUTO_BILL_SENTBYMAIL","chaine","1");
  79. $this->const[10] = array("MAIN_AGENDA_ACTIONAUTO_ORDER_SUPPLIER_VALIDATE","chaine","1");
  80. $this->const[11] = array("MAIN_AGENDA_ACTIONAUTO_BILL_SUPPLIER_VALIDATE","chaine","1");
  81. $this->const[12] = array("MAIN_AGENDA_ACTIONAUTO_SHIPPING_VALIDATE","chaine","1");
  82. $this->const[13] = array("MAIN_AGENDA_ACTIONAUTO_SHIPPING_SENTBYMAIL","chaine","1");
  83. $this->const[14] = array("MAIN_AGENDA_ACTIONAUTO_BILL_UNVALIDATE","chaine","1");
  84. // New pages on tabs
  85. // -----------------
  86. $this->tabs = array();
  87. // Boxes
  88. //------
  89. $this->boxes = array(0=>array('file'=>'box_actions.php','enabledbydefaulton'=>'Home'));
  90. // Permissions
  91. //------------
  92. $this->rights = array();
  93. $this->rights_class = 'agenda';
  94. $r=0;
  95. // $this->rights[$r][0] Id permission (unique tous modules confondus)
  96. // $this->rights[$r][1] Libelle par defaut si traduction de cle "PermissionXXX" non trouvee (XXX = Id permission)
  97. // $this->rights[$r][2] Non utilise
  98. // $this->rights[$r][3] 1=Permis par defaut, 0=Non permis par defaut
  99. // $this->rights[$r][4] Niveau 1 pour nommer permission dans code
  100. // $this->rights[$r][5] Niveau 2 pour nommer permission dans code
  101. // $r++;
  102. $this->rights[$r][0] = 2401;
  103. $this->rights[$r][1] = 'Read actions/tasks linked to his account';
  104. $this->rights[$r][2] = 'r';
  105. $this->rights[$r][3] = 1;
  106. $this->rights[$r][4] = 'myactions';
  107. $this->rights[$r][5] = 'read';
  108. $r++;
  109. $this->rights[$r][0] = 2402;
  110. $this->rights[$r][1] = 'Create/modify actions/tasks linked to his account';
  111. $this->rights[$r][2] = 'w';
  112. $this->rights[$r][3] = 0;
  113. $this->rights[$r][4] = 'myactions';
  114. $this->rights[$r][5] = 'create';
  115. $r++;
  116. $this->rights[$r][0] = 2403;
  117. $this->rights[$r][1] = 'Delete actions/tasks linked to his account';
  118. $this->rights[$r][2] = 'w';
  119. $this->rights[$r][3] = 0;
  120. $this->rights[$r][4] = 'myactions';
  121. $this->rights[$r][5] = 'delete';
  122. $r++;
  123. $this->rights[$r][0] = 2411;
  124. $this->rights[$r][1] = 'Read actions/tasks of others';
  125. $this->rights[$r][2] = 'r';
  126. $this->rights[$r][3] = 0;
  127. $this->rights[$r][4] = 'allactions';
  128. $this->rights[$r][5] = 'read';
  129. $r++;
  130. $this->rights[$r][0] = 2412;
  131. $this->rights[$r][1] = 'Create/modify actions/tasks of others';
  132. $this->rights[$r][2] = 'w';
  133. $this->rights[$r][3] = 0;
  134. $this->rights[$r][4] = 'allactions';
  135. $this->rights[$r][5] = 'create';
  136. $r++;
  137. $this->rights[$r][0] = 2413;
  138. $this->rights[$r][1] = 'Delete actions/tasks of others';
  139. $this->rights[$r][2] = 'w';
  140. $this->rights[$r][3] = 0;
  141. $this->rights[$r][4] = 'allactions';
  142. $this->rights[$r][5] = 'delete';
  143. $r++;
  144. $this->rights[$r][0] = 2414;
  145. $this->rights[$r][1] = 'Export actions/tasks of others';
  146. $this->rights[$r][2] = 'w';
  147. $this->rights[$r][3] = 0;
  148. $this->rights[$r][4] = 'export';
  149. // Main menu entries
  150. $this->menu = array(); // List of menus to add
  151. $r=0;
  152. // Add here entries to declare new menus
  153. // Example to declare the Top Menu entry:
  154. // $this->menu[$r]=array( 'fk_menu'=>0, // Put 0 if this is a top menu
  155. // 'type'=>'top', // This is a Top menu entry
  156. // 'titre'=>'MyModule top menu',
  157. // 'mainmenu'=>'mymodule',
  158. // 'url'=>'/mymodule/pagetop.php',
  159. // 'langs'=>'mylangfile', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
  160. // 'position'=>100,
  161. // 'enabled'=>'1', // Define condition to show or hide menu entry. Use '$conf->mymodule->enabled' if entry must be visible if module is enabled.
  162. // 'perms'=>'1', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
  163. // 'target'=>'',
  164. // 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both
  165. // $r++;
  166. $this->menu[$r]=array('fk_menu'=>0,
  167. 'type'=>'top',
  168. 'titre'=>'Agenda',
  169. 'mainmenu'=>'agenda',
  170. 'url'=>'/comm/action/index.php',
  171. 'langs'=>'agenda',
  172. 'position'=>100,
  173. 'perms'=>'$user->rights->agenda->myactions->read',
  174. 'enabled'=>'$conf->agenda->enabled',
  175. 'target'=>'',
  176. 'user'=>2);
  177. $r++;
  178. $this->menu[$r]=array('fk_menu'=>'r=0',
  179. 'type'=>'left',
  180. 'titre'=>'Actions',
  181. 'mainmenu'=>'agenda',
  182. 'url'=>'/comm/action/index.php?mainmenu=agenda&amp;leftmenu=agenda',
  183. 'langs'=>'agenda',
  184. 'position'=>100,
  185. 'perms'=>'$user->rights->agenda->myactions->read',
  186. 'enabled'=>'$conf->agenda->enabled',
  187. 'target'=>'',
  188. 'user'=>2);
  189. $r++;
  190. $this->menu[$r]=array('fk_menu'=>'r=1',
  191. 'type'=>'left',
  192. 'titre'=>'NewAction',
  193. 'mainmenu'=>'agenda',
  194. 'url'=>'/comm/action/fiche.php?mainmenu=agenda&amp;leftmenu=agenda&amp;action=create',
  195. 'langs'=>'commercial',
  196. 'position'=>101,
  197. 'perms'=>'($user->rights->agenda->myactions->create||$user->rights->agenda->allactions->create)',
  198. 'enabled'=>'$conf->agenda->enabled',
  199. 'target'=>'',
  200. 'user'=>2);
  201. $r++;
  202. // Calendar
  203. $this->menu[$r]=array('fk_menu'=>'r=1',
  204. 'type'=>'left',
  205. 'titre'=>'Calendar',
  206. 'mainmenu'=>'agenda',
  207. 'url'=>'/comm/action/index.php?mainmenu=agenda&amp;leftmenu=agenda',
  208. 'langs'=>'agenda',
  209. 'position'=>102,
  210. 'perms'=>'$user->rights->agenda->myactions->read',
  211. 'enabled'=>'$conf->agenda->enabled',
  212. 'target'=>'',
  213. 'user'=>2);
  214. $r++;
  215. $this->menu[$r]=array('fk_menu'=>'r=3',
  216. 'type'=>'left',
  217. 'titre'=>'MenuToDoMyActions',
  218. 'mainmenu'=>'agenda',
  219. 'url'=>'/comm/action/index.php?mainmenu=agenda&amp;leftmenu=agenda&amp;status=todo&amp;filter=mine',
  220. 'langs'=>'agenda',
  221. 'position'=>103,
  222. 'perms'=>'$user->rights->agenda->myactions->read',
  223. 'enabled'=>'$conf->agenda->enabled',
  224. 'target'=>'',
  225. 'user'=>2);
  226. $r++;
  227. $this->menu[$r]=array('fk_menu'=>'r=3',
  228. 'type'=>'left',
  229. 'titre'=>'MenuDoneMyActions',
  230. 'mainmenu'=>'agenda',
  231. 'url'=>'/comm/action/index.php?mainmenu=agenda&amp;leftmenu=agenda&amp;status=done&amp;filter=mine',
  232. 'langs'=>'agenda',
  233. 'position'=>104,
  234. 'perms'=>'$user->rights->agenda->myactions->read',
  235. 'enabled'=>'$conf->agenda->enabled',
  236. 'target'=>'',
  237. 'user'=>2);
  238. $r++;
  239. $this->menu[$r]=array('fk_menu'=>'r=3',
  240. 'type'=>'left',
  241. 'titre'=>'MenuToDoActions',
  242. 'mainmenu'=>'agenda',
  243. 'url'=>'/comm/action/index.php?mainmenu=agenda&amp;leftmenu=agenda&amp;status=todo',
  244. 'langs'=>'agenda',
  245. 'position'=>105,
  246. 'perms'=>'$user->rights->agenda->allactions->read',
  247. 'enabled'=>'$user->rights->agenda->allactions->read',
  248. 'target'=>'',
  249. 'user'=>2);
  250. $r++;
  251. $this->menu[$r]=array('fk_menu'=>'r=3',
  252. 'type'=>'left',
  253. 'titre'=>'MenuDoneActions',
  254. 'mainmenu'=>'agenda',
  255. 'url'=>'/comm/action/index.php?mainmenu=agenda&amp;leftmenu=agenda&amp;status=done',
  256. 'langs'=>'agenda',
  257. 'position'=>106,
  258. 'perms'=>'$user->rights->agenda->allactions->read',
  259. 'enabled'=>'$user->rights->agenda->allactions->read',
  260. 'target'=>'',
  261. 'user'=>2);
  262. $r++;
  263. // List
  264. $this->menu[$r]=array('fk_menu'=>'r=1',
  265. 'type'=>'left',
  266. 'titre'=>'List',
  267. 'mainmenu'=>'agenda',
  268. 'url'=>'/comm/action/listactions.php?mainmenu=agenda&amp;leftmenu=agenda',
  269. 'langs'=>'agenda',
  270. 'position'=>112,
  271. 'perms'=>'$user->rights->agenda->myactions->read',
  272. 'enabled'=>'$conf->agenda->enabled',
  273. 'target'=>'',
  274. 'user'=>2);
  275. $r++;
  276. $this->menu[$r]=array('fk_menu'=>'r=8',
  277. 'type'=>'left',
  278. 'titre'=>'MenuToDoMyActions',
  279. 'mainmenu'=>'agenda',
  280. 'url'=>'/comm/action/listactions.php?mainmenu=agenda&amp;leftmenu=agenda&amp;status=todo&amp;filter=mine',
  281. 'langs'=>'agenda',
  282. 'position'=>113,
  283. 'perms'=>'$user->rights->agenda->myactions->read',
  284. 'enabled'=>'$conf->agenda->enabled',
  285. 'target'=>'',
  286. 'user'=>2);
  287. $r++;
  288. $this->menu[$r]=array('fk_menu'=>'r=8',
  289. 'type'=>'left',
  290. 'titre'=>'MenuDoneMyActions',
  291. 'mainmenu'=>'agenda',
  292. 'url'=>'/comm/action/listactions.php?mainmenu=agenda&amp;leftmenu=agenda&amp;status=done&amp;filter=mine',
  293. 'langs'=>'agenda',
  294. 'position'=>114,
  295. 'perms'=>'$user->rights->agenda->myactions->read',
  296. 'enabled'=>'$conf->agenda->enabled',
  297. 'target'=>'',
  298. 'user'=>2);
  299. $r++;
  300. $this->menu[$r]=array('fk_menu'=>'r=8',
  301. 'type'=>'left',
  302. 'titre'=>'MenuToDoActions',
  303. 'mainmenu'=>'agenda',
  304. 'url'=>'/comm/action/listactions.php?mainmenu=agenda&amp;leftmenu=agenda&amp;status=todo',
  305. 'langs'=>'agenda',
  306. 'position'=>115,
  307. 'perms'=>'$user->rights->agenda->allactions->read',
  308. 'enabled'=>'$user->rights->agenda->allactions->read',
  309. 'target'=>'',
  310. 'user'=>2);
  311. $r++;
  312. $this->menu[$r]=array('fk_menu'=>'r=8',
  313. 'type'=>'left',
  314. 'titre'=>'MenuDoneActions',
  315. 'mainmenu'=>'agenda',
  316. 'url'=>'/comm/action/listactions.php?mainmenu=agenda&amp;leftmenu=agenda&amp;status=done',
  317. 'langs'=>'agenda',
  318. 'position'=>116,
  319. 'perms'=>'$user->rights->agenda->allactions->read',
  320. 'enabled'=>'$user->rights->agenda->allactions->read',
  321. 'target'=>'',
  322. 'user'=>2);
  323. $r++;
  324. // Reports
  325. $this->menu[$r]=array('fk_menu'=>'r=1',
  326. 'type'=>'left',
  327. 'titre'=>'Reportings',
  328. 'mainmenu'=>'agenda',
  329. 'url'=>'/comm/action/rapport/index.php?mainmenu=agenda&amp;leftmenu=agenda',
  330. 'langs'=>'agenda',
  331. 'position'=>120,
  332. 'perms'=>'$user->rights->agenda->allactions->read',
  333. 'enabled'=>'$conf->agenda->enabled',
  334. 'target'=>'',
  335. 'user'=>2);
  336. $r++;
  337. // Exports
  338. //--------
  339. $r=0;
  340. $r++;
  341. $this->export_code[$r]=$this->rights_class.'_'.$r;
  342. $this->export_label[$r]="ExportDataset_event1";
  343. $this->export_permission[$r]=array(array("agenda","export"));
  344. $this->export_fields_array[$r]=array('ac.id'=>"ActionId",'ac.ref_ext'=>"ExternalRef",'ac.datec'=>"ActionDateCreation",'ac.datep'=>"DateActionBegin",
  345. 'ac.datep2'=>"DateActionEnd",'ac.label'=>"Title",'ac.note'=>"Note",'ac.percent'=>"Percent",'ac.durationp'=>"durationp",
  346. 'cac.libelle'=>"ActionType",
  347. 's.rowid'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.zip'=>'Zip','s.town'=>'Town',
  348. 'cp.code'=>'CountryCode','s.phone'=>'Phone','s.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4',
  349. 's.code_compta'=>'CustomerAccountancyCode','s.code_compta_fournisseur'=>'SupplierAccountancyCode','s.tva_intra'=>'VATIntra');
  350. $this->export_TypeFields_array[$r]=array('ac.ref_ext'=>"Text",'ac.datec'=>"Date",'ac.datep'=>"Date",
  351. 'ac.datep2'=>"Date",'ac.label'=>"Text",'ac.note'=>"Text",'ac.percent'=>"Number",
  352. 'ac.durationp'=>"Duree",
  353. 'cac.libelle'=>"List:c_actioncomm:libelle:rowid",
  354. 's.nom'=>'Text','s.address'=>'Text','s.zip'=>'Text','s.town'=>'Text',
  355. 'cp.code'=>'Text','s.phone'=>'Text','s.siren'=>'Text','s.siret'=>'Text','s.ape'=>'Text','s.idprof4'=>'Text',
  356. 's.code_compta'=>'Text','s.code_compta_fournisseur'=>'Text','s.tva_intra'=>'Text');
  357. $this->export_entities_array[$r]=array('ac.id'=>"action",'ac.ref_ext'=>"action",'ac.datec'=>"action",'ac.datep'=>"action",
  358. 'ac.datep2'=>"action",'ac.label'=>"action",'ac.note'=>"action",'ac.percent'=>"action",'ac.durationp'=>"action",
  359. 'cac.libelle'=>"action",
  360. 's.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.zip'=>'company','s.town'=>'company',
  361. 'cp.code'=>'company','s.phone'=>'company','s.siren'=>'company','s.siret'=>'company','s.ape'=>'company','s.idprof4'=>'company',
  362. 's.code_compta'=>'company','s.code_compta_fournisseur'=>'company','s.tva_intra'=>'company',);
  363. $this->export_sql_start[$r]='SELECT DISTINCT ';
  364. $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'actioncomm as ac';
  365. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_actioncomm as cac on ac.fk_action = cac.id';
  366. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'socpeople as sp on ac.fk_contact = sp.rowid';
  367. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s on ac.fk_soc = s.rowid';
  368. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_pays as cp on s.fk_pays = cp.rowid';
  369. $this->export_sql_end[$r] .=' Where ac.entity = '.$conf->entity;
  370. $this->export_sql_end[$r] .=' ORDER BY datep';
  371. }
  372. /**
  373. * Function called when module is enabled.
  374. * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
  375. * It also creates data directories
  376. *
  377. * @param string $options Options when enabling module ('', 'noboxes')
  378. * @return int 1 if OK, 0 if KO
  379. */
  380. function init($options='')
  381. {
  382. // Prevent pb of modules not correctly disabled
  383. //$this->remove($options);
  384. $sql = array();
  385. return $this->_init($sql,$options);
  386. }
  387. /**
  388. * Function called when module is disabled.
  389. * Remove from database constants, boxes and permissions from Dolibarr database.
  390. * Data directories are not deleted
  391. *
  392. * @param string $options Options when enabling module ('', 'noboxes')
  393. * @return int 1 if OK, 0 if KO
  394. */
  395. function remove($options='')
  396. {
  397. $sql = array();
  398. return $this->_remove($sql,$options);
  399. }
  400. }