modAgenda.class.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  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 = '15';
  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(0=>array('file'=>'box_actions.php', 'enabledbydefaulton'=>'Home'));
  99. // Cronjobs
  100. //------------
  101. $datestart = dol_now();
  102. $this->cronjobs = array(
  103. 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'=>'$conf->agenda->enabled', 'datestart'=>$datestart),
  104. );
  105. // Permissions
  106. //------------
  107. $this->rights = array();
  108. $this->rights_class = 'agenda';
  109. $r = 0;
  110. // $this->rights[$r][0] Id permission (unique tous modules confondus)
  111. // $this->rights[$r][1] Libelle par defaut si traduction de cle "PermissionXXX" non trouvee (XXX = Id permission)
  112. // $this->rights[$r][2] Non utilise
  113. // $this->rights[$r][3] 1=Permis par defaut, 0=Non permis par defaut
  114. // $this->rights[$r][4] Niveau 1 pour nommer permission dans code
  115. // $this->rights[$r][5] Niveau 2 pour nommer permission dans code
  116. // $r++;
  117. $this->rights[$r][0] = 2401;
  118. $this->rights[$r][1] = 'Read actions/tasks linked to his account';
  119. $this->rights[$r][2] = 'r';
  120. $this->rights[$r][3] = 0;
  121. $this->rights[$r][4] = 'myactions';
  122. $this->rights[$r][5] = 'read';
  123. $r++;
  124. $this->rights[$r][0] = 2402;
  125. $this->rights[$r][1] = 'Create/modify actions/tasks linked to his account';
  126. $this->rights[$r][2] = 'w';
  127. $this->rights[$r][3] = 0;
  128. $this->rights[$r][4] = 'myactions';
  129. $this->rights[$r][5] = 'create';
  130. $r++;
  131. $this->rights[$r][0] = 2403;
  132. $this->rights[$r][1] = 'Delete actions/tasks linked to his account';
  133. $this->rights[$r][2] = 'w';
  134. $this->rights[$r][3] = 0;
  135. $this->rights[$r][4] = 'myactions';
  136. $this->rights[$r][5] = 'delete';
  137. $r++;
  138. $this->rights[$r][0] = 2411;
  139. $this->rights[$r][1] = 'Read actions/tasks of others';
  140. $this->rights[$r][2] = 'r';
  141. $this->rights[$r][3] = 0;
  142. $this->rights[$r][4] = 'allactions';
  143. $this->rights[$r][5] = 'read';
  144. $r++;
  145. $this->rights[$r][0] = 2412;
  146. $this->rights[$r][1] = 'Create/modify actions/tasks of others';
  147. $this->rights[$r][2] = 'w';
  148. $this->rights[$r][3] = 0;
  149. $this->rights[$r][4] = 'allactions';
  150. $this->rights[$r][5] = 'create';
  151. $r++;
  152. $this->rights[$r][0] = 2413;
  153. $this->rights[$r][1] = 'Delete actions/tasks of others';
  154. $this->rights[$r][2] = 'w';
  155. $this->rights[$r][3] = 0;
  156. $this->rights[$r][4] = 'allactions';
  157. $this->rights[$r][5] = 'delete';
  158. $r++;
  159. $this->rights[$r][0] = 2414;
  160. $this->rights[$r][1] = 'Export actions/tasks of others';
  161. $this->rights[$r][2] = 'w';
  162. $this->rights[$r][3] = 0;
  163. $this->rights[$r][4] = 'export';
  164. // Main menu entries
  165. $this->menu = array(); // List of menus to add
  166. $r = 0;
  167. // Add here entries to declare new menus
  168. // Example to declare the Top Menu entry:
  169. // $this->menu[$r]=array( 'fk_menu'=>0, // Put 0 if this is a top menu
  170. // 'type'=>'top', // This is a Top menu entry
  171. // 'titre'=>'MyModule top menu',
  172. // 'mainmenu'=>'mymodule',
  173. // 'url'=>'/mymodule/pagetop.php',
  174. // 'langs'=>'mylangfile', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
  175. // 'position'=>100,
  176. // 'enabled'=>'1', // Define condition to show or hide menu entry. Use '$conf->mymodule->enabled' if entry must be visible if module is enabled.
  177. // 'perms'=>'1', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
  178. // 'target'=>'',
  179. // 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both
  180. // $r++;
  181. $this->menu[$r] = array(
  182. 'fk_menu'=>0,
  183. 'type'=>'top',
  184. 'titre'=>'TMenuAgenda',
  185. 'prefix' => img_picto('', $this->picto, 'class="paddingright pictofixedwidth"'),
  186. 'mainmenu'=>'agenda',
  187. 'url'=>'/comm/action/index.php',
  188. 'langs'=>'agenda',
  189. 'position'=>86,
  190. 'perms'=>'$user->rights->agenda->myactions->read || $user->rights->resource->read',
  191. 'enabled'=>'$conf->agenda->enabled || $conf->resource->enabled',
  192. 'target'=>'',
  193. 'user'=>2,
  194. );
  195. $r++;
  196. $this->menu[$r] = array(
  197. 'fk_menu'=>'r=0',
  198. 'type'=>'left',
  199. 'titre'=>'Actions',
  200. 'prefix' => img_picto('', $this->picto, 'class="paddingright pictofixedwidth"'),
  201. 'mainmenu'=>'agenda',
  202. 'url'=>'/comm/action/index.php?mainmenu=agenda&amp;leftmenu=agenda',
  203. 'langs'=>'agenda',
  204. 'position'=>100,
  205. 'perms'=>'$user->rights->agenda->myactions->read',
  206. 'enabled'=>'$conf->agenda->enabled',
  207. 'target'=>'',
  208. 'user'=>2,
  209. );
  210. $r++;
  211. $this->menu[$r] = array(
  212. 'fk_menu'=>'r=1',
  213. 'type'=>'left',
  214. 'titre'=>'NewAction',
  215. 'mainmenu'=>'agenda',
  216. 'url'=>'/comm/action/card.php?mainmenu=agenda&amp;leftmenu=agenda&amp;action=create',
  217. 'langs'=>'commercial',
  218. 'position'=>101,
  219. 'perms'=>'($user->rights->agenda->myactions->create||$user->rights->agenda->allactions->create)',
  220. 'enabled'=>'$conf->agenda->enabled',
  221. 'target'=>'',
  222. 'user'=>2
  223. );
  224. $r++;
  225. // Calendar
  226. $this->menu[$r] = array(
  227. 'fk_menu'=>'r=1',
  228. 'type'=>'left',
  229. 'titre'=>'Calendar',
  230. 'mainmenu'=>'agenda',
  231. 'url'=>'/comm/action/index.php?action=default&amp;mainmenu=agenda&amp;leftmenu=agenda',
  232. 'langs'=>'agenda',
  233. 'position'=>140,
  234. 'perms'=>'$user->rights->agenda->myactions->read',
  235. 'enabled'=>'$conf->agenda->enabled',
  236. 'target'=>'',
  237. 'user'=>2
  238. );
  239. $r++;
  240. /* $this->menu[$r] = array(
  241. 'fk_menu'=>'r=3',
  242. 'type'=>'left',
  243. 'titre'=>'MenuToDoMyActions',
  244. 'mainmenu'=>'agenda',
  245. 'url'=>'/comm/action/index.php?action=default&amp;mainmenu=agenda&amp;leftmenu=agenda&amp;status=todo&amp;filter=mine',
  246. 'langs'=>'agenda',
  247. 'position'=>141,
  248. 'perms'=>'$user->rights->agenda->myactions->read',
  249. 'enabled'=>'$conf->agenda->enabled',
  250. 'target'=>'',
  251. 'user'=>2
  252. );
  253. $r++;
  254. $this->menu[$r] = array(
  255. 'fk_menu'=>'r=3',
  256. 'type'=>'left',
  257. 'titre'=>'MenuDoneMyActions',
  258. 'mainmenu'=>'agenda',
  259. 'url'=>'/comm/action/index.php?action=default&amp;mainmenu=agenda&amp;leftmenu=agenda&amp;status=done&amp;filter=mine',
  260. 'langs'=>'agenda',
  261. 'position'=>142,
  262. 'perms'=>'$user->rights->agenda->myactions->read',
  263. 'enabled'=>'$conf->agenda->enabled',
  264. 'target'=>'',
  265. 'user'=>2
  266. );
  267. $r++;
  268. $this->menu[$r] = array(
  269. 'fk_menu'=>'r=3',
  270. 'type'=>'left',
  271. 'titre'=>'MenuToDoActions',
  272. 'mainmenu'=>'agenda',
  273. 'url'=>'/comm/action/index.php?action=default&amp;mainmenu=agenda&amp;leftmenu=agenda&amp;status=todo&amp;filtert=-1',
  274. 'langs'=>'agenda',
  275. 'position'=>143,
  276. 'perms'=>'$user->rights->agenda->allactions->read',
  277. 'enabled'=>'$user->rights->agenda->allactions->read',
  278. 'target'=>'',
  279. 'user'=>2
  280. );
  281. $r++;
  282. $this->menu[$r] = array(
  283. 'fk_menu'=>'r=3',
  284. 'type'=>'left',
  285. 'titre'=>'MenuDoneActions',
  286. 'mainmenu'=>'agenda',
  287. 'url'=>'/comm/action/index.php?action=default&amp;mainmenu=agenda&amp;leftmenu=agenda&amp;status=done&amp;filtert=-1',
  288. 'langs'=>'agenda',
  289. 'position'=>144,
  290. 'perms'=>'$user->rights->agenda->allactions->read',
  291. 'enabled'=>'$user->rights->agenda->allactions->read',
  292. 'target'=>'',
  293. 'user'=>2
  294. ); */
  295. // List
  296. //$r++;
  297. $this->menu[$r] = array(
  298. 'fk_menu'=>'r=1',
  299. 'type'=>'left',
  300. 'titre'=>'List',
  301. 'mainmenu'=>'agenda',
  302. 'url'=>'/comm/action/list.php?mode=show_list&amp;mainmenu=agenda&amp;leftmenu=agenda',
  303. 'langs'=>'agenda',
  304. 'position'=>110,
  305. 'perms'=>'$user->rights->agenda->myactions->read',
  306. 'enabled'=>'$conf->agenda->enabled',
  307. 'target'=>'',
  308. 'user'=>2
  309. );
  310. $r++;
  311. /* $this->menu[$r] = array(
  312. 'fk_menu'=>'r=8',
  313. 'type'=>'left',
  314. 'titre'=>'MenuToDoMyActions',
  315. 'mainmenu'=>'agenda',
  316. 'url'=>'/comm/action/list.php?mode=show_list&amp;mainmenu=agenda&amp;leftmenu=agenda&amp;status=todo&amp;filter=mine',
  317. 'langs'=>'agenda',
  318. 'position'=>111,
  319. 'perms'=>'$user->rights->agenda->myactions->read',
  320. 'enabled'=>'$conf->agenda->enabled',
  321. 'target'=>'',
  322. 'user'=>2
  323. );
  324. $r++;
  325. $this->menu[$r] = array(
  326. 'fk_menu'=>'r=8',
  327. 'type'=>'left',
  328. 'titre'=>'MenuDoneMyActions',
  329. 'mainmenu'=>'agenda',
  330. 'url'=>'/comm/action/list.php?mode=show_list&amp;mainmenu=agenda&amp;leftmenu=agenda&amp;status=done&amp;filter=mine',
  331. 'langs'=>'agenda',
  332. 'position'=>112,
  333. 'perms'=>'$user->rights->agenda->myactions->read',
  334. 'enabled'=>'$conf->agenda->enabled',
  335. 'target'=>'',
  336. 'user'=>2
  337. );
  338. $r++;
  339. $this->menu[$r] = array(
  340. 'fk_menu'=>'r=8',
  341. 'type'=>'left',
  342. 'titre'=>'MenuToDoActions',
  343. 'mainmenu'=>'agenda',
  344. 'url'=>'/comm/action/list.php?mode=show_list&amp;mainmenu=agenda&amp;leftmenu=agenda&amp;status=todo&amp;filtert=-1',
  345. 'langs'=>'agenda',
  346. 'position'=>113,
  347. 'perms'=>'$user->rights->agenda->allactions->read',
  348. 'enabled'=>'$user->rights->agenda->allactions->read',
  349. 'target'=>'',
  350. 'user'=>2
  351. );
  352. $r++;
  353. $this->menu[$r] = array(
  354. 'fk_menu'=>'r=8',
  355. 'type'=>'left',
  356. 'titre'=>'MenuDoneActions',
  357. 'mainmenu'=>'agenda',
  358. 'url'=>'/comm/action/list.php?mode=show_list&amp;mainmenu=agenda&amp;leftmenu=agenda&amp;status=done&amp;filtert=-1',
  359. 'langs'=>'agenda',
  360. 'position'=>114,
  361. 'perms'=>'$user->rights->agenda->allactions->read',
  362. 'enabled'=>'$user->rights->agenda->allactions->read',
  363. 'target'=>'',
  364. 'user'=>2
  365. );
  366. $r++; */
  367. // Reports
  368. $this->menu[$r] = array(
  369. 'fk_menu'=>'r=1',
  370. 'type'=>'left',
  371. 'titre'=>'Reportings',
  372. 'mainmenu'=>'agenda',
  373. 'url'=>'/comm/action/rapport/index.php?mainmenu=agenda&amp;leftmenu=agenda',
  374. 'langs'=>'agenda',
  375. 'position'=>160,
  376. 'perms'=>'$user->rights->agenda->allactions->read',
  377. 'enabled'=>'$conf->agenda->enabled',
  378. 'target'=>'',
  379. 'user'=>2
  380. );
  381. $r++;
  382. // Categories
  383. $this->menu[$r] = array(
  384. 'fk_menu' => 'r=1',
  385. 'type' => 'left',
  386. 'titre' => 'Categories',
  387. 'mainmenu' => 'agenda',
  388. 'url'=>'/categories/index.php?mainmenu=agenda&amp;leftmenu=agenda&type=10',
  389. 'langs' => 'agenda',
  390. 'position' => 170,
  391. 'perms' => '$user->rights->agenda->allactions->read',
  392. 'enabled' => '$conf->categorie->enabled',
  393. 'target' => '',
  394. 'user' => 2
  395. );
  396. $r++;
  397. // Exports
  398. //--------
  399. $r = 0;
  400. $r++;
  401. $this->export_code[$r] = $this->rights_class.'_'.$r;
  402. $this->export_label[$r] = "ExportDataset_event1";
  403. $this->export_permission[$r] = array(array("agenda", "export"));
  404. $this->export_fields_array[$r] = array('ac.id'=>"IdAgenda", 'ac.ref_ext'=>"ExternalRef", 'ac.datec'=>"DateCreation", 'ac.datep'=>"DateActionBegin",
  405. 'ac.datep2'=>"DateActionEnd", 'ac.label'=>"Title", 'ac.note'=>"Note", 'ac.percent'=>"Percent", 'ac.durationp'=>"Duration",
  406. 'cac.libelle'=>"ActionType",
  407. 's.rowid'=>"IdCompany", 's.nom'=>'CompanyName', 's.address'=>'Address', 's.zip'=>'Zip', 's.town'=>'Town',
  408. 'co.code'=>'CountryCode', 's.phone'=>'Phone', 's.siren'=>'ProfId1', 's.siret'=>'ProfId2', 's.ape'=>'ProfId3', 's.idprof4'=>'ProfId4', 's.idprof5'=>'ProfId5', 's.idprof6'=>'ProfId6',
  409. 's.code_compta'=>'CustomerAccountancyCode', 's.code_compta_fournisseur'=>'SupplierAccountancyCode', 's.tva_intra'=>'VATIntra',
  410. 'p.ref' => 'ProjectRef',
  411. );
  412. $this->export_TypeFields_array[$r] = array('ac.ref_ext'=>"Text", 'ac.datec'=>"Date", 'ac.datep'=>"Date",
  413. 'ac.datep2'=>"Date", 'ac.label'=>"Text", 'ac.note'=>"Text", 'ac.percent'=>"Numeric",
  414. 'ac.durationp'=>"Duree",
  415. 'cac.libelle'=>"List:c_actioncomm:libelle:libelle",
  416. 's.nom'=>'Text', 's.address'=>'Text', 's.zip'=>'Text', 's.town'=>'Text',
  417. 'co.code'=>'Text', 's.phone'=>'Text', 's.siren'=>'Text', 's.siret'=>'Text', 's.ape'=>'Text', 's.idprof4'=>'Text', 's.idprof5'=>'Text', 's.idprof6'=>'Text',
  418. 's.code_compta'=>'Text', 's.code_compta_fournisseur'=>'Text', 's.tva_intra'=>'Text',
  419. 'p.ref' => 'Text',
  420. );
  421. $this->export_entities_array[$r] = array('ac.id'=>"action", 'ac.ref_ext'=>"action", 'ac.datec'=>"action", 'ac.datep'=>"action",
  422. 'ac.datep2'=>"action", 'ac.label'=>"action", 'ac.note'=>"action", 'ac.percent'=>"action", 'ac.durationp'=>"action",
  423. 'cac.libelle'=>"action",
  424. 's.rowid'=>"company", 's.nom'=>'company', 's.address'=>'company', 's.zip'=>'company', 's.town'=>'company',
  425. 'co.code'=>'company', 's.phone'=>'company', 's.siren'=>'company', 's.siret'=>'company', 's.ape'=>'company', 's.idprof4'=>'company', 's.idprof5'=>'company', 's.idprof6'=>'company',
  426. 's.code_compta'=>'company', 's.code_compta_fournisseur'=>'company', 's.tva_intra'=>'company',
  427. 'p.ref' => 'project',
  428. );
  429. $keyforselect = 'actioncomm'; $keyforelement = 'action'; $keyforaliasextra = 'extra';
  430. include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
  431. $this->export_sql_start[$r] = 'SELECT DISTINCT ';
  432. $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'actioncomm as ac';
  433. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'actioncomm_extrafields as extra ON ac.id = extra.fk_object';
  434. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_actioncomm as cac on ac.fk_action = cac.id';
  435. if (!empty($user) && empty($user->rights->agenda->allactions->read)) {
  436. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'actioncomm_resources acr on ac.id = acr.fk_actioncomm';
  437. }
  438. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'socpeople as sp on ac.fk_contact = sp.rowid';
  439. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s on ac.fk_soc = s.rowid';
  440. if (!empty($user) && empty($user->rights->societe->client->voir)) {
  441. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
  442. }
  443. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as co on s.fk_pays = co.rowid';
  444. $this->export_sql_end[$r] .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON p.rowid = ac.fk_project";
  445. $this->export_sql_end[$r] .= ' WHERE ac.entity IN ('.getEntity('agenda').')';
  446. if (empty($user->rights->societe->client->voir)) {
  447. $this->export_sql_end[$r] .= ' AND (sc.fk_user = '.(empty($user) ? 0 : $user->id).' OR ac.fk_soc IS NULL)';
  448. }
  449. if (empty($user->rights->agenda->allactions->read)) {
  450. $this->export_sql_end[$r] .= ' AND acr.fk_element = '.(empty($user) ? 0 : $user->id);
  451. }
  452. $this->export_sql_order[$r] = ' ORDER BY ac.datep';
  453. }
  454. }