modAgenda.class.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  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@inodbox.com>
  8. * Copyright (C) 2013 Cedric Gross <c.gross@kreiz-it.fr>
  9. * Copyright (C) 2015 Bahfir Abbes <bafbes@gmail.com>
  10. * Copyright (C) 2017 Juanjo Menent <jmenent@2byte.es>
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 3 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  24. */
  25. /**
  26. * \defgroup agenda Module agenda
  27. * \brief Module to manage agenda and events
  28. * \file htdocs/core/modules/modAgenda.class.php
  29. * \ingroup agenda
  30. * \brief Description and activation file for the module agenda
  31. */
  32. include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
  33. /**
  34. * Class to describe and enable/disable module Agenda
  35. */
  36. class modAgenda extends DolibarrModules
  37. {
  38. /**
  39. * Constructor. Define names, constants, directories, boxes, permissions
  40. *
  41. * @param DoliDB $db Database handler
  42. */
  43. public function __construct($db)
  44. {
  45. global $conf, $user;
  46. $this->db = $db;
  47. $this->numero = 2400;
  48. $this->family = "projects";
  49. $this->module_position = '16';
  50. // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
  51. $this->name = preg_replace('/^mod/i', '', get_class($this));
  52. $this->description = "Follow events or rendez-vous. Record manual events into Agendas or let application record automatic events for log tracking.";
  53. // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
  54. $this->version = 'dolibarr';
  55. // Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase)
  56. $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
  57. $this->picto = 'action';
  58. // Data directories to create when module is enabled
  59. $this->dirs = array("/agenda/temp");
  60. // Config pages
  61. $this->config_page_url = array("agenda_other.php");
  62. // Dependencies
  63. $this->hidden = false; // A condition to hide module
  64. $this->depends = array(); // List of module class names as string that must be enabled if this module is enabled
  65. $this->requiredby = array(); // List of module ids to disable if this one is disabled
  66. $this->conflictwith = array(); // List of module class names as string this module is in conflict with
  67. $this->langfiles = array("companies");
  68. $this->phpmin = array(7, 0); // Minimum version of PHP required by module
  69. // Module parts
  70. $this->module_parts = array();
  71. // Constants
  72. //-----------
  73. // List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive)
  74. // Example: $this->const=array(0=>array('MYMODULE_MYNEWCONST1','chaine','myvalue','This is a constant to add',1),
  75. // 1=>array('MYMODULE_MYNEWCONST2','chaine','myvalue','This is another constant to add',0, 'current', 1)
  76. // );
  77. $this->const = array();
  78. //$this->const[] = array('AGENDA_DEFAULT_FILTER_TYPE', 'chaine', 'AC_NON_AUTO', 'Default filter for type of event on agenda', 0, 'current');
  79. $sqlreadactions = "SELECT code, label, description FROM ".MAIN_DB_PREFIX."c_action_trigger ORDER by rang";
  80. $resql = $this->db->query($sqlreadactions);
  81. if ($resql) {
  82. while ($obj = $this->db->fetch_object($resql)) {
  83. //if (preg_match('/_CREATE$/',$obj->code) && (! in_array($obj->code, array('COMPANY_CREATE','PRODUCT_CREATE','TASK_CREATE')))) continue; // We don't track such events (*_CREATE) by default, we prefer validation (except thirdparty/product/task creation because there is no validation).
  84. if (preg_match('/^TASK_/', $obj->code)) {
  85. continue; // We don't track such events by default.
  86. }
  87. //if (preg_match('/^_MODIFY/',$obj->code)) continue; // We don't track such events by default.
  88. $this->const[] = array('MAIN_AGENDA_ACTIONAUTO_'.$obj->code, "chaine", "1", '', 0, 'current');
  89. }
  90. } else {
  91. dol_print_error($this->db->lasterror());
  92. }
  93. // New pages on tabs
  94. // -----------------
  95. $this->tabs = array();
  96. // Boxes
  97. //------
  98. $this->boxes = array(
  99. 0=>array('file'=>'box_actions.php', 'enabledbydefaulton'=>'Home'),
  100. 1=>array('file'=>'box_actions_future.php', 'enabledbydefaulton'=>'Home')
  101. );
  102. // Cronjobs
  103. //------------
  104. $datestart = dol_now();
  105. $this->cronjobs = array(
  106. 0=>array('label'=>'SendEmailsReminders', 'jobtype'=>'method', 'class'=>'comm/action/class/actioncomm.class.php', 'objectname'=>'ActionComm', 'method'=>'sendEmailsReminder', 'parameters'=>'', 'comment'=>'SendEMailsReminder', 'frequency'=>5, 'unitfrequency'=>60, 'priority'=>10, 'status'=>1, 'test'=>'isModEnabled("agenda")', 'datestart'=>$datestart),
  107. );
  108. // Permissions
  109. //------------
  110. $this->rights = array();
  111. $this->rights_class = 'agenda';
  112. $r = 0;
  113. // $this->rights[$r][0] Id permission (unique tous modules confondus)
  114. // $this->rights[$r][1] Libelle par defaut si traduction de cle "PermissionXXX" non trouvee (XXX = Id permission)
  115. // $this->rights[$r][2] Non utilise
  116. // $this->rights[$r][3] 1=Permis par defaut, 0=Non permis par defaut
  117. // $this->rights[$r][4] Niveau 1 pour nommer permission dans code
  118. // $this->rights[$r][5] Niveau 2 pour nommer permission dans code
  119. // $r++;
  120. $this->rights[$r][0] = 2401;
  121. $this->rights[$r][1] = 'Read actions/tasks linked to his account';
  122. $this->rights[$r][2] = 'r';
  123. $this->rights[$r][3] = 0;
  124. $this->rights[$r][4] = 'myactions';
  125. $this->rights[$r][5] = 'read';
  126. $r++;
  127. $this->rights[$r][0] = 2402;
  128. $this->rights[$r][1] = 'Create/modify actions/tasks linked to his account';
  129. $this->rights[$r][2] = 'w';
  130. $this->rights[$r][3] = 0;
  131. $this->rights[$r][4] = 'myactions';
  132. $this->rights[$r][5] = 'create';
  133. $r++;
  134. $this->rights[$r][0] = 2403;
  135. $this->rights[$r][1] = 'Delete actions/tasks linked to his account';
  136. $this->rights[$r][2] = 'w';
  137. $this->rights[$r][3] = 0;
  138. $this->rights[$r][4] = 'myactions';
  139. $this->rights[$r][5] = 'delete';
  140. $r++;
  141. $this->rights[$r][0] = 2411;
  142. $this->rights[$r][1] = 'Read actions/tasks of others';
  143. $this->rights[$r][2] = 'r';
  144. $this->rights[$r][3] = 0;
  145. $this->rights[$r][4] = 'allactions';
  146. $this->rights[$r][5] = 'read';
  147. $r++;
  148. $this->rights[$r][0] = 2412;
  149. $this->rights[$r][1] = 'Create/modify actions/tasks of others';
  150. $this->rights[$r][2] = 'w';
  151. $this->rights[$r][3] = 0;
  152. $this->rights[$r][4] = 'allactions';
  153. $this->rights[$r][5] = 'create';
  154. $r++;
  155. $this->rights[$r][0] = 2413;
  156. $this->rights[$r][1] = 'Delete actions/tasks of others';
  157. $this->rights[$r][2] = 'w';
  158. $this->rights[$r][3] = 0;
  159. $this->rights[$r][4] = 'allactions';
  160. $this->rights[$r][5] = 'delete';
  161. $r++;
  162. $this->rights[$r][0] = 2414;
  163. $this->rights[$r][1] = 'Export actions/tasks of others';
  164. $this->rights[$r][2] = 'w';
  165. $this->rights[$r][3] = 0;
  166. $this->rights[$r][4] = 'export';
  167. // Main menu entries
  168. $this->menu = array(); // List of menus to add
  169. $r = 0;
  170. // Add here entries to declare new menus
  171. // Example to declare the Top Menu entry:
  172. // $this->menu[$r]=array( 'fk_menu'=>0, // Put 0 if this is a top menu
  173. // 'type'=>'top', // This is a Top menu entry
  174. // 'titre'=>'MyModule top menu',
  175. // 'mainmenu'=>'mymodule',
  176. // 'url'=>'/mymodule/pagetop.php',
  177. // 'langs'=>'mylangfile', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
  178. // 'position'=>100,
  179. // 'enabled'=>'1', // Define condition to show or hide menu entry. Use '$conf->mymodule->enabled' if entry must be visible if module is enabled.
  180. // 'perms'=>'1', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
  181. // 'target'=>'',
  182. // 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both
  183. // $r++;
  184. $this->menu[$r] = array(
  185. 'fk_menu'=>0,
  186. 'type'=>'top',
  187. 'titre'=>'TMenuAgenda',
  188. 'prefix' => img_picto('', $this->picto, 'class="pictofixedwidth"'),
  189. 'mainmenu'=>'agenda',
  190. 'url'=>'/comm/action/index.php',
  191. 'langs'=>'agenda',
  192. 'position'=>86,
  193. 'perms'=>'$user->hasRight("agenda", "myactions", "read") || $user->hasRight("resource", "read")',
  194. 'enabled'=>'isModEnabled("agenda") || isModEnabled("resource")',
  195. 'target'=>'',
  196. 'user'=>2,
  197. );
  198. $r++;
  199. $this->menu[$r] = array(
  200. 'fk_menu'=>'r=0',
  201. 'type'=>'left',
  202. 'titre'=>'Actions',
  203. 'prefix' => img_picto('', $this->picto, 'class="paddingright pictofixedwidth"'),
  204. 'mainmenu'=>'agenda',
  205. 'url'=>'/comm/action/index.php?mainmenu=agenda&amp;leftmenu=agenda',
  206. 'langs'=>'agenda',
  207. 'position'=>100,
  208. 'perms'=>'$user->hasRight("agenda", "myactions", "read")',
  209. 'enabled'=>'isModEnabled("agenda")',
  210. 'target'=>'',
  211. 'user'=>2,
  212. );
  213. $r++;
  214. $this->menu[$r] = array(
  215. 'fk_menu'=>'r=1',
  216. 'type'=>'left',
  217. 'titre'=>'NewAction',
  218. 'mainmenu'=>'agenda',
  219. 'url'=>'/comm/action/card.php?mainmenu=agenda&amp;leftmenu=agenda&amp;action=create',
  220. 'langs'=>'commercial',
  221. 'position'=>101,
  222. 'perms'=>'($user->hasRight("agenda", "myactions", "create") || $user->hasRight("agenda", "allactions", "create"))',
  223. 'enabled'=>'isModEnabled("agenda")',
  224. 'target'=>'',
  225. 'user'=>2
  226. );
  227. $r++;
  228. // Calendar
  229. $this->menu[$r] = array(
  230. 'fk_menu'=>'r=1',
  231. 'type'=>'left',
  232. 'titre'=>'Calendar',
  233. 'mainmenu'=>'agenda',
  234. 'url'=>'/comm/action/index.php?action=default&amp;mainmenu=agenda&amp;leftmenu=agenda',
  235. 'langs'=>'agenda',
  236. 'position'=>140,
  237. 'perms'=>'$user->hasRight("agenda", "myactions", "read")',
  238. 'enabled'=>'isModEnabled("agenda")',
  239. 'target'=>'',
  240. 'user'=>2
  241. );
  242. $r++;
  243. $this->menu[$r] = array(
  244. 'fk_menu'=>'r=3',
  245. 'type'=>'left',
  246. 'titre'=>'MenuToDoMyActions',
  247. 'mainmenu'=>'agenda',
  248. 'url'=>'/comm/action/index.php?action=default&amp;mainmenu=agenda&amp;leftmenu=agenda&amp;status=todo&amp;filter=mine',
  249. 'langs'=>'agenda',
  250. 'position'=>141,
  251. 'perms'=>'$user->hasRight("agenda", "myactions", "read")',
  252. 'enabled'=>'isModEnabled("agenda")',
  253. 'target'=>'',
  254. 'user'=>2
  255. );
  256. $r++;
  257. $this->menu[$r] = array(
  258. 'fk_menu'=>'r=3',
  259. 'type'=>'left',
  260. 'titre'=>'MenuDoneMyActions',
  261. 'mainmenu'=>'agenda',
  262. 'url'=>'/comm/action/index.php?action=default&amp;mainmenu=agenda&amp;leftmenu=agenda&amp;status=done&amp;filter=mine',
  263. 'langs'=>'agenda',
  264. 'position'=>142,
  265. 'perms'=>'$user->hasRight("agenda", "myactions", "read")',
  266. 'enabled'=>'isModEnabled("agenda")',
  267. 'target'=>'',
  268. 'user'=>2
  269. );
  270. $r++;
  271. $this->menu[$r] = array(
  272. 'fk_menu'=>'r=3',
  273. 'type'=>'left',
  274. 'titre'=>'MenuToDoActions',
  275. 'mainmenu'=>'agenda',
  276. 'url'=>'/comm/action/index.php?action=default&amp;mainmenu=agenda&amp;leftmenu=agenda&amp;status=todo&amp;filtert=-1',
  277. 'langs'=>'agenda',
  278. 'position'=>143,
  279. 'perms'=>'$user->hasRight("agenda", "allactions", "read")',
  280. 'enabled'=>'isModEnabled("agenda")',
  281. 'target'=>'',
  282. 'user'=>2
  283. );
  284. $r++;
  285. $this->menu[$r] = array(
  286. 'fk_menu'=>'r=3',
  287. 'type'=>'left',
  288. 'titre'=>'MenuDoneActions',
  289. 'mainmenu'=>'agenda',
  290. 'url'=>'/comm/action/index.php?action=default&amp;mainmenu=agenda&amp;leftmenu=agenda&amp;status=done&amp;filtert=-1',
  291. 'langs'=>'agenda',
  292. 'position'=>144,
  293. 'perms'=>'$user->hasRight("agenda", "allactions", "read")',
  294. 'enabled'=>'isModEnabled("agenda")',
  295. 'target'=>'',
  296. 'user'=>2
  297. );
  298. // List
  299. $r++;
  300. $this->menu[$r] = array(
  301. 'fk_menu'=>'r=1',
  302. 'type'=>'left',
  303. 'titre'=>'List',
  304. 'mainmenu'=>'agenda',
  305. 'url'=>'/comm/action/list.php?mode=show_list&amp;mainmenu=agenda&amp;leftmenu=agenda',
  306. 'langs'=>'agenda',
  307. 'position'=>110,
  308. 'perms'=>'$user->hasRight("agenda", "myactions", "read")',
  309. 'enabled'=>'isModEnabled("agenda")',
  310. 'target'=>'',
  311. 'user'=>2
  312. );
  313. $r++;
  314. $this->menu[$r] = array(
  315. 'fk_menu'=>'r=8',
  316. 'type'=>'left',
  317. 'titre'=>'MenuToDoMyActions',
  318. 'mainmenu'=>'agenda',
  319. 'url'=>'/comm/action/list.php?mode=show_list&amp;mainmenu=agenda&amp;leftmenu=agenda&amp;status=todo&amp;filter=mine',
  320. 'langs'=>'agenda',
  321. 'position'=>111,
  322. 'perms'=>'$user->hasRight("agenda", "myactions", "read")',
  323. 'enabled'=>'isModEnabled("agenda")',
  324. 'target'=>'',
  325. 'user'=>2
  326. );
  327. $r++;
  328. $this->menu[$r] = array(
  329. 'fk_menu'=>'r=8',
  330. 'type'=>'left',
  331. 'titre'=>'MenuDoneMyActions',
  332. 'mainmenu'=>'agenda',
  333. 'url'=>'/comm/action/list.php?mode=show_list&amp;mainmenu=agenda&amp;leftmenu=agenda&amp;status=done&amp;filter=mine',
  334. 'langs'=>'agenda',
  335. 'position'=>112,
  336. 'perms'=>'$user->hasRight("agenda", "myactions", "read")',
  337. 'enabled'=>'isModEnabled("agenda")',
  338. 'target'=>'',
  339. 'user'=>2
  340. );
  341. $r++;
  342. $this->menu[$r] = array(
  343. 'fk_menu'=>'r=8',
  344. 'type'=>'left',
  345. 'titre'=>'MenuToDoActions',
  346. 'mainmenu'=>'agenda',
  347. 'url'=>'/comm/action/list.php?mode=show_list&amp;mainmenu=agenda&amp;leftmenu=agenda&amp;status=todo&amp;filtert=-1',
  348. 'langs'=>'agenda',
  349. 'position'=>113,
  350. 'perms'=>'$user->hasRight("agenda", "allactions", "read")',
  351. 'enabled'=>'isModEnabled("agenda")',
  352. 'target'=>'',
  353. 'user'=>2
  354. );
  355. $r++;
  356. $this->menu[$r] = array(
  357. 'fk_menu'=>'r=8',
  358. 'type'=>'left',
  359. 'titre'=>'MenuDoneActions',
  360. 'mainmenu'=>'agenda',
  361. 'url'=>'/comm/action/list.php?mode=show_list&amp;mainmenu=agenda&amp;leftmenu=agenda&amp;status=done&amp;filtert=-1',
  362. 'langs'=>'agenda',
  363. 'position'=>114,
  364. 'perms'=>'$user->hasRight("agenda", "allactions", "read")',
  365. 'enabled'=>'isModEnabled("agenda")',
  366. 'target'=>'',
  367. 'user'=>2
  368. );
  369. $r++;
  370. // Reports
  371. $this->menu[$r] = array(
  372. 'fk_menu'=>'r=1',
  373. 'type'=>'left',
  374. 'titre'=>'Reportings',
  375. 'mainmenu'=>'agenda',
  376. 'url'=>'/comm/action/rapport/index.php?mainmenu=agenda&amp;leftmenu=agenda',
  377. 'langs'=>'agenda',
  378. 'position'=>160,
  379. 'perms'=>'$user->hasRight("agenda", "allactions", "read")',
  380. 'enabled'=>'isModEnabled("agenda")',
  381. 'target'=>'',
  382. 'user'=>2
  383. );
  384. $r++;
  385. // Categories
  386. $this->menu[$r] = array(
  387. 'fk_menu' => 'r=1',
  388. 'type' => 'left',
  389. 'titre' => 'Categories',
  390. 'mainmenu' => 'agenda',
  391. 'url'=>'/categories/index.php?mainmenu=agenda&amp;leftmenu=agenda&type=10',
  392. 'langs' => 'agenda',
  393. 'position' => 170,
  394. 'perms' => '$user->hasRight("agenda", "allactions", "read")',
  395. 'enabled' => 'isModEnabled("categorie")',
  396. 'target' => '',
  397. 'user' => 2
  398. );
  399. $r++;
  400. // Exports
  401. //--------
  402. $r = 0;
  403. $r++;
  404. $this->export_code[$r] = $this->rights_class.'_'.$r;
  405. $this->export_label[$r] = "ExportDataset_event1";
  406. $this->export_permission[$r] = array(array("agenda", "export"));
  407. $this->export_fields_array[$r] = array('ac.id'=>"IdAgenda", 'ac.ref_ext'=>"ExternalRef", 'ac.datec'=>"DateCreation", 'ac.datep'=>"DateActionBegin",
  408. 'ac.datep2'=>"DateActionEnd", 'ac.label'=>"Title", 'ac.note'=>"Note", 'ac.percent'=>"Percent", 'ac.durationp'=>"Duration",
  409. 'cac.libelle'=>"ActionType",
  410. 's.rowid'=>"IdCompany", 's.nom'=>'CompanyName', 's.address'=>'Address', 's.zip'=>'Zip', 's.town'=>'Town',
  411. 'co.code'=>'CountryCode', 's.phone'=>'Phone', 's.siren'=>'ProfId1', 's.siret'=>'ProfId2', 's.ape'=>'ProfId3', 's.idprof4'=>'ProfId4', 's.idprof5'=>'ProfId5', 's.idprof6'=>'ProfId6',
  412. 's.code_compta'=>'CustomerAccountancyCode', 's.code_compta_fournisseur'=>'SupplierAccountancyCode', 's.tva_intra'=>'VATIntra',
  413. 'p.ref' => 'ProjectRef',
  414. );
  415. $this->export_TypeFields_array[$r] = array('ac.ref_ext'=>"Text", 'ac.datec'=>"Date", 'ac.datep'=>"Date",
  416. 'ac.datep2'=>"Date", 'ac.label'=>"Text", 'ac.note'=>"Text", 'ac.percent'=>"Numeric",
  417. 'ac.durationp'=>"Duree",
  418. 'cac.libelle'=>"List:c_actioncomm:libelle:libelle",
  419. 's.nom'=>'Text', 's.address'=>'Text', 's.zip'=>'Text', 's.town'=>'Text',
  420. 'co.code'=>'Text', 's.phone'=>'Text', 's.siren'=>'Text', 's.siret'=>'Text', 's.ape'=>'Text', 's.idprof4'=>'Text', 's.idprof5'=>'Text', 's.idprof6'=>'Text',
  421. 's.code_compta'=>'Text', 's.code_compta_fournisseur'=>'Text', 's.tva_intra'=>'Text',
  422. 'p.ref' => 'Text',
  423. );
  424. $this->export_entities_array[$r] = array('ac.id'=>"action", 'ac.ref_ext'=>"action", 'ac.datec'=>"action", 'ac.datep'=>"action",
  425. 'ac.datep2'=>"action", 'ac.label'=>"action", 'ac.note'=>"action", 'ac.percent'=>"action", 'ac.durationp'=>"action",
  426. 'cac.libelle'=>"action",
  427. 's.rowid'=>"company", 's.nom'=>'company', 's.address'=>'company', 's.zip'=>'company', 's.town'=>'company',
  428. 'co.code'=>'company', 's.phone'=>'company', 's.siren'=>'company', 's.siret'=>'company', 's.ape'=>'company', 's.idprof4'=>'company', 's.idprof5'=>'company', 's.idprof6'=>'company',
  429. 's.code_compta'=>'company', 's.code_compta_fournisseur'=>'company', 's.tva_intra'=>'company',
  430. 'p.ref' => 'project',
  431. );
  432. $keyforselect = 'actioncomm';
  433. $keyforelement = 'action';
  434. $keyforaliasextra = 'extra';
  435. include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
  436. $this->export_sql_start[$r] = 'SELECT DISTINCT ';
  437. $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'actioncomm as ac';
  438. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'actioncomm_extrafields as extra ON ac.id = extra.fk_object';
  439. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_actioncomm as cac on ac.fk_action = cac.id';
  440. if (!empty($user) && !$user->hasRight('agenda', 'allactions', 'read')) {
  441. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'actioncomm_resources acr on ac.id = acr.fk_actioncomm';
  442. }
  443. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'socpeople as sp on ac.fk_contact = sp.rowid';
  444. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s on ac.fk_soc = s.rowid';
  445. if (!empty($user) && !$user->hasRight('societe', 'client', 'voir')) {
  446. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
  447. }
  448. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as co on s.fk_pays = co.rowid';
  449. $this->export_sql_end[$r] .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON p.rowid = ac.fk_project";
  450. $this->export_sql_end[$r] .= ' WHERE ac.entity IN ('.getEntity('agenda').')';
  451. if (!empty($user) && !$user->hasRight('societe', 'client', 'voir')) {
  452. $this->export_sql_end[$r] .= ' AND (sc.fk_user = '.(empty($user) ? 0 : $user->id).' OR ac.fk_soc IS NULL)';
  453. }
  454. if (!empty($user) && !$user->hasRight('agenda', 'allactions', 'read')) {
  455. $this->export_sql_end[$r] .= ' AND acr.fk_element = '.(empty($user) ? 0 : $user->id);
  456. }
  457. $this->export_sql_order[$r] = ' ORDER BY ac.datep';
  458. }
  459. }