interface_50_modAgenda_ActionsAuto.class.php 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105
  1. <?php
  2. /* Copyright (C) 2005-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2009-2017 Regis Houssin <regis.houssin@inodbox.com>
  4. * Copyright (C) 2011-2014 Juanjo Menent <jmenent@2byte.es>
  5. * Copyright (C) 2013 Cedric GROSS <c.gross@kreiz-it.fr>
  6. * Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
  7. * Copyright (C) 2015 Bahfir Abbes <bafbes@gmail.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php
  24. * \ingroup agenda
  25. * \brief Trigger file for agenda module
  26. */
  27. require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php';
  28. /**
  29. * Class of triggered functions for agenda module
  30. */
  31. class InterfaceActionsAuto extends DolibarrTriggers
  32. {
  33. /**
  34. * Constructor
  35. *
  36. * @param DoliDB $db Database handler
  37. */
  38. public function __construct($db)
  39. {
  40. $this->db = $db;
  41. $this->name = preg_replace('/^Interface/i', '', get_class($this));
  42. $this->family = "agenda";
  43. $this->description = "Triggers of this module add actions in agenda according to setup made in agenda setup.";
  44. // 'development', 'experimental', 'dolibarr' or version
  45. $this->version = self::VERSION_DOLIBARR;
  46. $this->picto = 'action';
  47. }
  48. /**
  49. * Function called when a Dolibarrr business event is done.
  50. * All functions "runTrigger" are triggered if file is inside directory htdocs/core/triggers or htdocs/module/code/triggers (and declared)
  51. *
  52. * Following properties may be set before calling trigger. The may be completed by this trigger to be used for writing the event into database:
  53. * $object->actiontypecode (translation action code: AC_OTH, ...)
  54. * $object->actionmsg (note, long text)
  55. * $object->actionmsg2 (label, short text)
  56. * $object->sendtoid (id of contact or array of ids of contacts)
  57. * $object->socid (id of thirdparty)
  58. * $object->fk_project
  59. * $object->fk_element (ID of object to link action event to)
  60. * $object->elementtype (->element of object to link action to)
  61. * $object->module (if defined, elementtype in llx_actioncomm will be elementtype@module)
  62. *
  63. * @param string $action Event action code ('CONTRACT_MODIFY', 'RECRUITMENTCANDIDATURE_MODIFIY', or example by external module: 'SENTBYSMS'...)
  64. * @param Object $object Object
  65. * @param User $user Object user
  66. * @param Translate $langs Object langs
  67. * @param conf $conf Object conf
  68. * @return int <0 if KO, 0 if no triggered ran, >0 if OK
  69. */
  70. public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
  71. {
  72. if (empty($conf->agenda) || empty($conf->agenda->enabled)) {
  73. return 0; // Module not active, we do nothing
  74. }
  75. // Do not log events when trigger is for creating event (infinite loop)
  76. if (preg_match('/^ACTION_/', $action)) {
  77. return 0;
  78. }
  79. $key = 'MAIN_AGENDA_ACTIONAUTO_'.$action;
  80. //var_dump($action.' - '.$conf->global->$key);exit;
  81. // Do not log events not enabled for this action
  82. // GUI allow to set this option only if entry exists into table llx_c_action_trigger
  83. if (empty($conf->global->$key)) {
  84. return 0;
  85. }
  86. $langs->load("agenda");
  87. if (empty($object->actiontypecode)) {
  88. $object->actiontypecode = 'AC_OTH_AUTO';
  89. }
  90. // Actions
  91. if ($action == 'COMPANY_CREATE') {
  92. // Load translation files required by the page
  93. $langs->loadLangs(array("agenda", "other", "companies"));
  94. if (empty($object->actionmsg2)) {
  95. $object->actionmsg2 = $langs->transnoentities("NewCompanyToDolibarr", $object->name);
  96. }
  97. $object->actionmsg = $langs->transnoentities("NewCompanyToDolibarr", $object->name);
  98. $object->sendtoid = 0;
  99. $object->socid = $object->id;
  100. } elseif ($action == 'COMPANY_MODIFY') {
  101. // Load translation files required by the page
  102. $langs->loadLangs(array("agenda", "other", "companies"));
  103. if (empty($object->actionmsg2)) {
  104. $object->actionmsg2 = $langs->transnoentities("COMPANY_MODIFYInDolibarr", $object->name);
  105. }
  106. $object->actionmsg = $langs->transnoentities("COMPANY_MODIFYInDolibarr", $object->name);
  107. $object->sendtoid = 0;
  108. $object->socid = $object->id;
  109. } elseif ($action == 'COMPANY_SENTBYMAIL') {
  110. // Load translation files required by the page
  111. $langs->loadLangs(array("agenda", "other", "orders"));
  112. if (empty($object->actionmsg2)) {
  113. dol_syslog('Trigger called with property actionmsg2 on object not defined', LOG_ERR);
  114. }
  115. // Parameters $object->sendtoid defined by caller
  116. //$object->sendtoid=0;
  117. } elseif ($action == 'CONTACT_CREATE') {
  118. // Load translation files required by the page
  119. $langs->loadLangs(array("agenda", "other", "companies"));
  120. if (empty($object->actionmsg2)) {
  121. $object->actionmsg2 = $langs->transnoentities("CONTACT_CREATEInDolibarr", $object->getFullName($langs));
  122. }
  123. $object->actionmsg = $langs->transnoentities("CONTACT_CREATEInDolibarr", $object->getFullName($langs));
  124. $object->sendtoid = array($object->id => $object->id);
  125. $object->socid = $object->socid;
  126. } elseif ($action == 'CONTACT_MODIFY') {
  127. // Load translation files required by the page
  128. $langs->loadLangs(array("agenda", "other", "companies"));
  129. if (empty($object->actionmsg2)) {
  130. $object->actionmsg2 = $langs->transnoentities("CONTACT_MODIFYInDolibarr", $object->name);
  131. }
  132. $object->actionmsg = $langs->transnoentities("CONTACT_MODIFYInDolibarr", $object->name);
  133. $object->sendtoid = array($object->id => $object->id);
  134. $object->socid = $object->socid;
  135. } elseif ($action == 'CONTRACT_VALIDATE') {
  136. // Load translation files required by the page
  137. $langs->loadLangs(array("agenda", "other", "contracts"));
  138. if (empty($object->actionmsg2)) {
  139. $object->actionmsg2 = $langs->transnoentities("ContractValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
  140. }
  141. $object->actionmsg = $langs->transnoentities("ContractValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
  142. $object->sendtoid = 0;
  143. } elseif ($action == 'CONTRACT_SENTBYMAIL') {
  144. // Load translation files required by the page
  145. $langs->loadLangs(array("agenda", "other", "contracts"));
  146. if (empty($object->actionmsg2)) {
  147. $object->actionmsg2 = $langs->transnoentities("ContractSentByEMail", $object->ref);
  148. }
  149. if (empty($object->actionmsg)) {
  150. $object->actionmsg = $langs->transnoentities("ContractSentByEMail", $object->ref);
  151. }
  152. // Parameters $object->sendtoid defined by caller
  153. //$object->sendtoid=0;
  154. } elseif ($action == 'PROPAL_VALIDATE') {
  155. // Load translation files required by the page
  156. $langs->loadLangs(array("agenda", "other", "propal"));
  157. if (empty($object->actionmsg2)) {
  158. $object->actionmsg2 = $langs->transnoentities("PropalValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
  159. }
  160. $object->actionmsg = $langs->transnoentities("PropalValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
  161. $object->sendtoid = 0;
  162. } elseif ($action == 'PROPAL_MODIFY') {
  163. // Load translation files required by the page
  164. $langs->loadLangs(array("agenda", "other", "propal"));
  165. if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("PropalBackToDraftInDolibarr", ($object->newref ? $object->newref : $object->ref));
  166. $object->actionmsg = $langs->transnoentities("PropalBackToDraftInDolibarr", ($object->newref ? $object->newref : $object->ref));
  167. $object->sendtoid = 0;
  168. } elseif ($action == 'PROPAL_SENTBYMAIL') {
  169. // Load translation files required by the page
  170. $langs->loadLangs(array("agenda", "other", "propal"));
  171. if (empty($object->actionmsg2)) {
  172. $object->actionmsg2 = $langs->transnoentities("ProposalSentByEMail", $object->ref);
  173. }
  174. if (empty($object->actionmsg)) {
  175. $object->actionmsg = $langs->transnoentities("ProposalSentByEMail", $object->ref);
  176. }
  177. // Parameters $object->sendtoid defined by caller
  178. //$object->sendtoid=0;
  179. } elseif ($action == 'PROPAL_CLOSE_SIGNED') {
  180. // Load translation files required by the page
  181. $langs->loadLangs(array("agenda", "other", "propal"));
  182. if (empty($object->actionmsg2)) {
  183. $object->actionmsg2 = $langs->transnoentities("PropalClosedSignedInDolibarr", $object->ref);
  184. }
  185. $object->actionmsg = $langs->transnoentities("PropalClosedSignedInDolibarr", $object->ref);
  186. $object->sendtoid = 0;
  187. } elseif ($action == 'PROPAL_CLASSIFY_BILLED') {
  188. // Load translation files required by the page
  189. $langs->loadLangs(array("agenda", "other", "propal"));
  190. if (empty($object->actionmsg2)) {
  191. $object->actionmsg2 = $langs->transnoentities("PropalClassifiedBilledInDolibarr", $object->ref);
  192. }
  193. $object->actionmsg = $langs->transnoentities("PropalClassifiedBilledInDolibarr", $object->ref);
  194. $object->sendtoid = 0;
  195. } elseif ($action == 'PROPAL_CLOSE_REFUSED') {
  196. // Load translation files required by the page
  197. $langs->loadLangs(array("agenda", "other", "propal"));
  198. if (empty($object->actionmsg2)) {
  199. $object->actionmsg2 = $langs->transnoentities("PropalClosedRefusedInDolibarr", $object->ref);
  200. }
  201. $object->actionmsg = $langs->transnoentities("PropalClosedRefusedInDolibarr", $object->ref);
  202. $object->sendtoid = 0;
  203. } elseif ($action == 'ORDER_VALIDATE') {
  204. // Load translation files required by the page
  205. $langs->loadLangs(array("agenda", "orders"));
  206. if (empty($object->actionmsg2)) {
  207. $object->actionmsg2 = $langs->transnoentities("OrderValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
  208. }
  209. $object->actionmsg = $langs->transnoentities("OrderValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
  210. $object->sendtoid = 0;
  211. } elseif ($action == 'ORDER_CLOSE') {
  212. // Load translation files required by the page
  213. $langs->loadLangs(array("agenda", "other", "orders"));
  214. if (empty($object->actionmsg2)) {
  215. $object->actionmsg2 = $langs->transnoentities("OrderDeliveredInDolibarr", $object->ref);
  216. }
  217. $object->actionmsg = $langs->transnoentities("OrderDeliveredInDolibarr", $object->ref);
  218. $object->sendtoid = 0;
  219. } elseif ($action == 'ORDER_CLASSIFY_BILLED') {
  220. // Load translation files required by the page
  221. $langs->loadLangs(array("agenda", "other", "orders"));
  222. if (empty($object->actionmsg2)) {
  223. $object->actionmsg2 = $langs->transnoentities("OrderBilledInDolibarr", $object->ref);
  224. }
  225. $object->actionmsg = $langs->transnoentities("OrderBilledInDolibarr", $object->ref);
  226. $object->sendtoid = 0;
  227. } elseif ($action == 'ORDER_CANCEL') {
  228. // Load translation files required by the page
  229. $langs->loadLangs(array("agenda", "other", "orders"));
  230. if (empty($object->actionmsg2)) {
  231. $object->actionmsg2 = $langs->transnoentities("OrderCanceledInDolibarr", $object->ref);
  232. }
  233. $object->actionmsg = $langs->transnoentities("OrderCanceledInDolibarr", $object->ref);
  234. $object->sendtoid = 0;
  235. } elseif ($action == 'ORDER_SENTBYMAIL') {
  236. // Load translation files required by the page
  237. $langs->loadLangs(array("agenda", "other", "orders"));
  238. if (empty($object->actionmsg2)) {
  239. $object->actionmsg2 = $langs->transnoentities("OrderSentByEMail", $object->ref);
  240. }
  241. if (empty($object->actionmsg)) {
  242. $object->actionmsg = $langs->transnoentities("OrderSentByEMail", $object->ref);
  243. }
  244. // Parameters $object->sendtoid defined by caller
  245. //$object->sendtoid=0;
  246. } elseif ($action == 'BILL_VALIDATE') {
  247. // Load translation files required by the page
  248. $langs->loadLangs(array("agenda", "other", "bills"));
  249. if (empty($object->actionmsg2)) {
  250. $object->actionmsg2 = $langs->transnoentities("InvoiceValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
  251. }
  252. $object->actionmsg = $langs->transnoentities("InvoiceValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
  253. $object->sendtoid = 0;
  254. } elseif ($action == 'BILL_UNVALIDATE') {
  255. // Load translation files required by the page
  256. $langs->loadLangs(array("agenda", "other", "bills"));
  257. if (empty($object->actionmsg2)) {
  258. $object->actionmsg2 = $langs->transnoentities("InvoiceBackToDraftInDolibarr", $object->ref);
  259. }
  260. $object->actionmsg = $langs->transnoentities("InvoiceBackToDraftInDolibarr", $object->ref);
  261. $object->sendtoid = 0;
  262. } elseif ($action == 'BILL_SENTBYMAIL') {
  263. // Load translation files required by the page
  264. $langs->loadLangs(array("agenda", "other", "bills"));
  265. if (empty($object->actionmsg2)) {
  266. $object->actionmsg2 = $langs->transnoentities("InvoiceSentByEMail", $object->ref);
  267. }
  268. if (empty($object->actionmsg)) {
  269. $object->actionmsg = $langs->transnoentities("InvoiceSentByEMail", $object->ref);
  270. }
  271. // Parameters $object->sendtoid defined by caller
  272. //$object->sendtoid=0;
  273. } elseif ($action == 'BILL_PAYED') {
  274. // Load translation files required by the page
  275. $langs->loadLangs(array("agenda", "other", "bills"));
  276. // Values for this action can't be defined by caller.
  277. $object->actionmsg2 = $langs->transnoentities("InvoicePaidInDolibarr", $object->ref);
  278. $object->actionmsg = $langs->transnoentities("InvoicePaidInDolibarr", $object->ref);
  279. $object->sendtoid = 0;
  280. } elseif ($action == 'BILL_CANCEL') {
  281. // Load translation files required by the page
  282. $langs->loadLangs(array("agenda", "other", "bills"));
  283. if (empty($object->actionmsg2)) {
  284. $object->actionmsg2 = $langs->transnoentities("InvoiceCanceledInDolibarr", $object->ref);
  285. }
  286. $object->actionmsg = $langs->transnoentities("InvoiceCanceledInDolibarr", $object->ref);
  287. $object->sendtoid = 0;
  288. } elseif ($action == 'FICHINTER_CREATE') {
  289. // Load translation files required by the page
  290. $langs->loadLangs(array("agenda", "other", "interventions"));
  291. if (empty($object->actionmsg2)) {
  292. $object->actionmsg2 = $langs->transnoentities("InterventionCreatedInDolibarr", $object->ref);
  293. }
  294. $object->actionmsg = $langs->transnoentities("InterventionCreatedInDolibarr", $object->ref);
  295. $object->sendtoid = 0;
  296. $object->fk_element = 0;
  297. $object->elementtype = '';
  298. } elseif ($action == 'FICHINTER_VALIDATE') {
  299. // Load translation files required by the page
  300. $langs->loadLangs(array("agenda", "other", "interventions"));
  301. if (empty($object->actionmsg2)) {
  302. $object->actionmsg2 = $langs->transnoentities("InterventionValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
  303. }
  304. $object->actionmsg = $langs->transnoentities("InterventionValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
  305. $object->sendtoid = 0;
  306. $object->fk_element = 0;
  307. $object->elementtype = '';
  308. } elseif ($action == 'FICHINTER_MODIFY') {
  309. // Load translation files required by the page
  310. $langs->loadLangs(array("agenda", "other", "interventions"));
  311. if (empty($object->actionmsg2)) {
  312. $object->actionmsg2 = $langs->transnoentities("InterventionModifiedInDolibarr", $object->ref);
  313. }
  314. $object->actionmsg = $langs->transnoentities("InterventionModifiedInDolibarr", $object->ref);
  315. $object->sendtoid = 0;
  316. $object->fk_element = 0;
  317. $object->elementtype = '';
  318. } elseif ($action == 'FICHINTER_SENTBYMAIL') {
  319. // Load translation files required by the page
  320. $langs->loadLangs(array("agenda", "other", "interventions"));
  321. if (empty($object->actionmsg2)) {
  322. $object->actionmsg2 = $langs->transnoentities("InterventionSentByEMail", $object->ref);
  323. }
  324. if (empty($object->actionmsg)) {
  325. $object->actionmsg = $langs->transnoentities("InterventionSentByEMail", $object->ref);
  326. }
  327. // Parameters $object->sendtoid defined by caller
  328. //$object->sendtoid=0;
  329. } elseif ($action == 'FICHINTER_CLASSIFY_BILLED') {
  330. // Load translation files required by the page
  331. $langs->loadLangs(array("agenda", "other", "interventions"));
  332. if (empty($object->actionmsg2)) {
  333. $object->actionmsg2 = $langs->transnoentities("InterventionClassifiedBilledInDolibarr", $object->ref);
  334. }
  335. $object->actionmsg = $langs->transnoentities("InterventionClassifiedBilledInDolibarr", $object->ref);
  336. $object->sendtoid = 0;
  337. } elseif ($action == 'FICHINTER_CLASSIFY_UNBILLED') {
  338. // Load translation files required by the page
  339. $langs->loadLangs(array("agenda", "other", "interventions"));
  340. if (empty($object->actionmsg2)) {
  341. $object->actionmsg2 = $langs->transnoentities("InterventionClassifiedUnbilledInDolibarr", $object->ref);
  342. }
  343. $object->actionmsg = $langs->transnoentities("InterventionClassifiedUnbilledInDolibarr", $object->ref);
  344. $object->sendtoid = 0;
  345. } elseif ($action == 'FICHINTER_DELETE') {
  346. // Load translation files required by the page
  347. $langs->loadLangs(array("agenda", "other", "interventions"));
  348. if (empty($object->actionmsg2)) {
  349. $object->actionmsg2 = $langs->transnoentities("InterventionDeletedInDolibarr", $object->ref);
  350. }
  351. $object->actionmsg = $langs->transnoentities("InterventionDeletedInDolibarr", $object->ref);
  352. $object->sendtoid = 0;
  353. $object->fk_element = 0;
  354. $object->elementtype = '';
  355. } elseif ($action == 'SHIPPING_VALIDATE') {
  356. // Load translation files required by the page
  357. $langs->loadLangs(array("agenda", "other", "sendings"));
  358. if (empty($object->actionmsg2)) {
  359. $object->actionmsg2 = $langs->transnoentities("ShippingValidated", ($object->newref ? $object->newref : $object->ref));
  360. }
  361. if (empty($object->actionmsg)) {
  362. $object->actionmsg = $langs->transnoentities("ShippingValidated", ($object->newref ? $object->newref : $object->ref));
  363. }
  364. // Parameters $object->sendtoid defined by caller
  365. //$object->sendtoid=0;
  366. } elseif ($action == 'SHIPPING_SENTBYMAIL') {
  367. // Load translation files required by the page
  368. $langs->loadLangs(array("agenda", "other", "sendings"));
  369. if (empty($object->actionmsg2)) {
  370. $object->actionmsg2 = $langs->transnoentities("ShippingSentByEMail", $object->ref);
  371. }
  372. if (empty($object->actionmsg)) {
  373. $object->actionmsg = $langs->transnoentities("ShippingSentByEMail", $object->ref);
  374. }
  375. // Parameters $object->sendtoid defined by caller
  376. //$object->sendtoid=0;
  377. } elseif ($action == 'RECEPTION_VALIDATE') {
  378. $langs->load("agenda");
  379. $langs->load("other");
  380. $langs->load("receptions");
  381. if (empty($object->actionmsg2)) {
  382. $object->actionmsg2 = $langs->transnoentities("ReceptionValidated", ($object->newref ? $object->newref : $object->ref));
  383. }
  384. if (empty($object->actionmsg)) {
  385. $object->actionmsg = $langs->transnoentities("ReceptionValidated", ($object->newref ? $object->newref : $object->ref));
  386. }
  387. // Parameters $object->sendtoid defined by caller
  388. //$object->sendtoid=0;
  389. } elseif ($action == 'RECEPTION_SENTBYMAIL') {
  390. $langs->load("agenda");
  391. $langs->load("other");
  392. $langs->load("receptions");
  393. if (empty($object->actionmsg2)) {
  394. $object->actionmsg2 = $langs->transnoentities("ReceptionSentByEMail", $object->ref);
  395. }
  396. if (empty($object->actionmsg)) {
  397. $object->actionmsg = $langs->transnoentities("ReceptionSentByEMail", $object->ref);
  398. }
  399. // Parameters $object->sendtoid defined by caller
  400. //$object->sendtoid=0;
  401. } elseif ($action == 'PROPOSAL_SUPPLIER_VALIDATE') {
  402. // Load translation files required by the page
  403. $langs->loadLangs(array("agenda", "other", "propal"));
  404. if (empty($object->actionmsg2)) {
  405. $object->actionmsg2 = $langs->transnoentities("PropalValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
  406. }
  407. $object->actionmsg = $langs->transnoentities("PropalValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
  408. $object->sendtoid = 0;
  409. } elseif ($action == 'PROPOSAL_SUPPLIER_SENTBYMAIL') {
  410. // Load translation files required by the page
  411. $langs->loadLangs(array("agenda", "other", "propal"));
  412. if (empty($object->actionmsg2)) {
  413. $object->actionmsg2 = $langs->transnoentities("ProposalSentByEMail", $object->ref);
  414. }
  415. if (empty($object->actionmsg)) {
  416. $object->actionmsg = $langs->transnoentities("ProposalSentByEMail", $object->ref);
  417. }
  418. // Parameters $object->sendtoid defined by caller
  419. //$object->sendtoid=0;
  420. } elseif ($action == 'PROPOSAL_SUPPLIER_CLOSE_SIGNED') {
  421. // Load translation files required by the page
  422. $langs->loadLangs(array("agenda", "other", "propal"));
  423. if (empty($object->actionmsg2)) {
  424. $object->actionmsg2 = $langs->transnoentities("PropalClosedSignedInDolibarr", $object->ref);
  425. }
  426. $object->actionmsg = $langs->transnoentities("PropalClosedSignedInDolibarr", $object->ref);
  427. $object->sendtoid = 0;
  428. } elseif ($action == 'PROPOSAL_SUPPLIER_CLOSE_REFUSED') {
  429. // Load translation files required by the page
  430. $langs->loadLangs(array("agenda", "other", "propal"));
  431. if (empty($object->actionmsg2)) {
  432. $object->actionmsg2 = $langs->transnoentities("PropalClosedRefusedInDolibarr", $object->ref);
  433. }
  434. $object->actionmsg = $langs->transnoentities("PropalClosedRefusedInDolibarr", $object->ref);
  435. $object->sendtoid = 0;
  436. } elseif ($action == 'ORDER_SUPPLIER_CREATE') {
  437. // Load translation files required by the page
  438. $langs->loadLangs(array("agenda", "other", "orders"));
  439. if (empty($object->actionmsg2)) {
  440. $object->actionmsg2 = $langs->transnoentities("OrderCreatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
  441. }
  442. $object->actionmsg = $langs->transnoentities("OrderCreatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
  443. $object->sendtoid = 0;
  444. } elseif ($action == 'ORDER_SUPPLIER_VALIDATE') {
  445. // Load translation files required by the page
  446. $langs->loadLangs(array("agenda", "other", "orders"));
  447. if (empty($object->actionmsg2)) {
  448. $object->actionmsg2 = $langs->transnoentities("OrderValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
  449. }
  450. $object->actionmsg = $langs->transnoentities("OrderValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
  451. $object->sendtoid = 0;
  452. } elseif ($action == 'ORDER_SUPPLIER_APPROVE') {
  453. // Load translation files required by the page
  454. $langs->loadLangs(array("agenda", "other", "orders"));
  455. if (empty($object->actionmsg2)) {
  456. $object->actionmsg2 = $langs->transnoentities("OrderApprovedInDolibarr", $object->ref);
  457. }
  458. $object->actionmsg = $langs->transnoentities("OrderApprovedInDolibarr", $object->ref);
  459. $object->sendtoid = 0;
  460. } elseif ($action == 'ORDER_SUPPLIER_REFUSE') {
  461. // Load translation files required by the page
  462. $langs->loadLangs(array("agenda", "other", "orders", "main"));
  463. if (empty($object->actionmsg2)) {
  464. $object->actionmsg2 = $langs->transnoentities("OrderRefusedInDolibarr", $object->ref);
  465. }
  466. $object->actionmsg = $langs->transnoentities("OrderRefusedInDolibarr", $object->ref);
  467. if (!empty($object->refuse_note)) {
  468. $object->actionmsg .= '<br>';
  469. $object->actionmsg .= $langs->trans("Reason") . ': '.$object->refuse_note;
  470. }
  471. $object->sendtoid = 0;
  472. } elseif ($action == 'ORDER_SUPPLIER_CANCEL') {
  473. // Load translation files required by the page
  474. $langs->loadLangs(array("agenda", "other", "orders", "main"));
  475. if (empty($object->actionmsg2)) {
  476. $object->actionmsg2 = $langs->transnoentities("OrderCanceledInDolibarr", $object->ref);
  477. }
  478. $object->actionmsg = $langs->transnoentities("OrderCanceledInDolibarr", $object->ref);
  479. if (!empty($object->cancel_note)) {
  480. $object->actionmsg .= '<br>';
  481. $object->actionmsg .= $langs->trans("Reason") . ': '.$object->cancel_note;
  482. }
  483. $object->sendtoid = 0;
  484. } elseif ($action == 'ORDER_SUPPLIER_SUBMIT') {
  485. // Load translation files required by the page
  486. $langs->loadLangs(array("agenda", "other", "orders"));
  487. if (empty($object->actionmsg2)) {
  488. $object->actionmsg2 = $langs->transnoentities("SupplierOrderSubmitedInDolibarr", ($object->newref ? $object->newref : $object->ref));
  489. }
  490. $object->actionmsg = $langs->transnoentities("SupplierOrderSubmitedInDolibarr", ($object->newref ? $object->newref : $object->ref));
  491. if (!empty($object->context['comments'])) {
  492. $object->actionmsg .= '<br>';
  493. $object->actionmsg .= $langs->trans("Comment") . ': '.$object->context['comments'];
  494. }
  495. $object->sendtoid = 0;
  496. } elseif ($action == 'ORDER_SUPPLIER_RECEIVE') {
  497. // Load translation files required by the page
  498. $langs->loadLangs(array("agenda", "other", "orders"));
  499. if (empty($object->actionmsg2)) {
  500. $object->actionmsg2 = $langs->transnoentities("SupplierOrderReceivedInDolibarr", ($object->newref ? $object->newref : $object->ref));
  501. }
  502. $object->actionmsg = $langs->transnoentities("SupplierOrderReceivedInDolibarr", ($object->newref ? $object->newref : $object->ref));
  503. $object->sendtoid = 0;
  504. } elseif ($action == 'ORDER_SUPPLIER_SENTBYMAIL') {
  505. // Load translation files required by the page
  506. $langs->loadLangs(array("agenda", "other", "bills", "orders"));
  507. if (empty($object->actionmsg2)) {
  508. $object->actionmsg2 = $langs->transnoentities("SupplierOrderSentByEMail", $object->ref);
  509. }
  510. if (empty($object->actionmsg)) {
  511. $object->actionmsg = $langs->transnoentities("SupplierOrderSentByEMail", $object->ref);
  512. }
  513. // Parameters $object->sendtoid defined by caller
  514. //$object->sendtoid=0;
  515. } elseif ($action == 'ORDER_SUPPLIER_CLASSIFY_BILLED') {
  516. // Load translation files required by the page
  517. $langs->loadLangs(array("agenda", "other", "bills", "orders"));
  518. if (empty($object->actionmsg2)) {
  519. $object->actionmsg2 = $langs->transnoentities("SupplierOrderClassifiedBilled", $object->ref);
  520. }
  521. if (empty($object->actionmsg)) {
  522. $object->actionmsg = $langs->transnoentities("SupplierOrderClassifiedBilled", $object->ref);
  523. }
  524. $object->sendtoid = 0;
  525. } elseif ($action == 'BILL_SUPPLIER_VALIDATE') {
  526. // Load translation files required by the page
  527. $langs->loadLangs(array("agenda", "other", "bills"));
  528. if (empty($object->actionmsg2)) {
  529. $object->actionmsg2 = $langs->transnoentities("InvoiceValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
  530. }
  531. $object->actionmsg = $langs->transnoentities("InvoiceValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
  532. $object->sendtoid = 0;
  533. } elseif ($action == 'BILL_SUPPLIER_UNVALIDATE') {
  534. // Load translation files required by the page
  535. $langs->loadLangs(array("agenda", "other", "bills"));
  536. if (empty($object->actionmsg2)) {
  537. $object->actionmsg2 = $langs->transnoentities("InvoiceBackToDraftInDolibarr", $object->ref);
  538. }
  539. $object->actionmsg = $langs->transnoentities("InvoiceBackToDraftInDolibarr", $object->ref);
  540. $object->sendtoid = 0;
  541. } elseif ($action == 'BILL_SUPPLIER_SENTBYMAIL') {
  542. // Load translation files required by the page
  543. $langs->loadLangs(array("agenda", "other", "bills", "orders"));
  544. if (empty($object->actionmsg2)) {
  545. $object->actionmsg2 = $langs->transnoentities("SupplierInvoiceSentByEMail", $object->ref);
  546. }
  547. if (empty($object->actionmsg)) {
  548. $object->actionmsg = $langs->transnoentities("SupplierInvoiceSentByEMail", $object->ref);
  549. }
  550. // Parameters $object->sendtoid defined by caller
  551. //$object->sendtoid=0;
  552. } elseif ($action == 'BILL_SUPPLIER_PAYED') {
  553. // Load translation files required by the page
  554. $langs->loadLangs(array("agenda", "other", "bills"));
  555. if (empty($object->actionmsg2)) {
  556. $object->actionmsg2 = $langs->transnoentities("InvoicePaidInDolibarr", $object->ref);
  557. }
  558. $object->actionmsg = $langs->transnoentities("InvoicePaidInDolibarr", $object->ref);
  559. $object->sendtoid = 0;
  560. } elseif ($action == 'BILL_SUPPLIER_CANCELED') {
  561. // Load translation files required by the page
  562. $langs->loadLangs(array("agenda", "other", "bills"));
  563. if (empty($object->actionmsg2)) {
  564. $object->actionmsg2 = $langs->transnoentities("InvoiceCanceledInDolibarr", $object->ref);
  565. }
  566. $object->actionmsg = $langs->transnoentities("InvoiceCanceledInDolibarr", $object->ref);
  567. $object->sendtoid = 0;
  568. } elseif ($action == 'MEMBER_VALIDATE') {
  569. // Members
  570. // Load translation files required by the page
  571. $langs->loadLangs(array("agenda", "other", "members"));
  572. if (empty($object->actionmsg2)) {
  573. $object->actionmsg2 = $langs->transnoentities("MemberValidatedInDolibarr", $object->getFullName($langs));
  574. }
  575. $object->actionmsg = $langs->transnoentities("MemberValidatedInDolibarr", $object->getFullName($langs));
  576. $object->actionmsg .= "\n".$langs->transnoentities("Member").': '.$object->getFullName($langs);
  577. $object->actionmsg .= "\n".$langs->transnoentities("Type").': '.$object->type;
  578. $object->sendtoid = 0;
  579. } elseif ($action == 'MEMBER_MODIFY') {
  580. // Load translation files required by the page
  581. $langs->loadLangs(array("agenda", "other", "members"));
  582. if (empty($object->actionmsg2)) {
  583. $object->actionmsg2 = $langs->transnoentities("MemberModifiedInDolibarr", $object->getFullName($langs));
  584. }
  585. $object->actionmsg = $langs->transnoentities("MemberModifiedInDolibarr", $object->getFullName($langs));
  586. $object->actionmsg .= "\n".$langs->transnoentities("Member").': '.$object->getFullName($langs);
  587. $object->actionmsg .= "\n".$langs->transnoentities("Type").': '.$object->type;
  588. $object->sendtoid = 0;
  589. } elseif ($action == 'MEMBER_SUBSCRIPTION_CREATE') {
  590. // Load translation files required by the page
  591. $langs->loadLangs(array("agenda", "other", "members"));
  592. $member = $this->context['member'];
  593. if (!is_object($member)) { // This should not happen
  594. dol_syslog("Execute a trigger MEMBER_SUBSCRIPTION_CREATE with context key 'member' not an object");
  595. include_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  596. $member = new Adherent($this->db);
  597. $member->fetch($object->fk_adherent);
  598. }
  599. if (empty($object->actionmsg2)) {
  600. $object->actionmsg2 = $langs->transnoentities("MemberSubscriptionAddedInDolibarr", $object->id, $member->getFullName($langs));
  601. }
  602. $object->actionmsg = $langs->transnoentities("MemberSubscriptionAddedInDolibarr", $object->id, $member->getFullName($langs));
  603. $object->actionmsg .= "\n".$langs->transnoentities("Member").': '.$member->getFullName($langs);
  604. $object->actionmsg .= "\n".$langs->transnoentities("Type").': '.$object->fk_type;
  605. $object->actionmsg .= "\n".$langs->transnoentities("Amount").': '.$object->amount;
  606. $object->actionmsg .= "\n".$langs->transnoentities("Period").': '.dol_print_date($object->dateh, 'day').' - '.dol_print_date($object->datef, 'day');
  607. $object->sendtoid = 0;
  608. if ($object->fk_soc > 0) {
  609. $object->socid = $object->fk_soc;
  610. }
  611. } elseif ($action == 'MEMBER_SUBSCRIPTION_MODIFY') {
  612. // Load translation files required by the page
  613. $langs->loadLangs(array("agenda", "other", "members"));
  614. $member = $this->context['member'];
  615. if (!is_object($member)) { // This should not happen
  616. include_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  617. $member = new Adherent($this->db);
  618. $member->fetch($this->fk_adherent);
  619. }
  620. if (empty($object->actionmsg2)) {
  621. $object->actionmsg2 = $langs->transnoentities("MemberSubscriptionModifiedInDolibarr", $object->id, $member->getFullName($langs));
  622. }
  623. $object->actionmsg = $langs->transnoentities("MemberSubscriptionModifiedInDolibarr", $object->id, $member->getFullName($langs));
  624. $object->actionmsg .= "\n".$langs->transnoentities("Member").': '.$member->getFullName($langs);
  625. $object->actionmsg .= "\n".$langs->transnoentities("Type").': '.$object->fk_type;
  626. $object->actionmsg .= "\n".$langs->transnoentities("Amount").': '.$object->amount;
  627. $object->actionmsg .= "\n".$langs->transnoentities("Period").': '.dol_print_date($object->dateh, 'day').' - '.dol_print_date($object->datef, 'day');
  628. $object->sendtoid = 0;
  629. if ($object->fk_soc > 0) {
  630. $object->socid = $object->fk_soc;
  631. }
  632. } elseif ($action == 'MEMBER_SUBSCRIPTION_DELETE') {
  633. // Load translation files required by the page
  634. $langs->loadLangs(array("agenda", "other", "members"));
  635. if (empty($object->actionmsg2)) {
  636. $object->actionmsg2 = $langs->transnoentities("MemberSubscriptionDeletedInDolibarr", $object->ref, $object->getFullName($langs));
  637. }
  638. $object->actionmsg = $langs->transnoentities("MemberSubscriptionDeletedInDolibarr", $object->ref, $object->getFullName($langs));
  639. $object->actionmsg .= "\n".$langs->transnoentities("Member").': '.$object->getFullName($langs);
  640. $object->actionmsg .= "\n".$langs->transnoentities("Type").': '.$object->type;
  641. $object->actionmsg .= "\n".$langs->transnoentities("Amount").': '.$object->last_subscription_amount;
  642. $object->actionmsg .= "\n".$langs->transnoentities("Period").': '.dol_print_date($object->last_subscription_date_start, 'day').' - '.dol_print_date($object->last_subscription_date_end, 'day');
  643. $object->sendtoid = 0;
  644. if ($object->fk_soc > 0) {
  645. $object->socid = $object->fk_soc;
  646. }
  647. } elseif ($action == 'MEMBER_RESILIATE') {
  648. // Load translation files required by the page
  649. $langs->loadLangs(array("agenda", "other", "members"));
  650. if (empty($object->actionmsg2)) {
  651. $object->actionmsg2 = $langs->transnoentities("MemberResiliatedInDolibarr", $object->getFullName($langs));
  652. }
  653. $object->actionmsg = $langs->transnoentities("MemberResiliatedInDolibarr", $object->getFullName($langs));
  654. $object->actionmsg .= "\n".$langs->transnoentities("Member").': '.$object->getFullName($langs);
  655. $object->actionmsg .= "\n".$langs->transnoentities("Type").': '.$object->type;
  656. $object->sendtoid = 0;
  657. } elseif ($action == 'MEMBER_DELETE') {
  658. // Load translation files required by the page
  659. $langs->loadLangs(array("agenda", "other", "members"));
  660. if (empty($object->actionmsg2)) {
  661. $object->actionmsg2 = $langs->transnoentities("MemberDeletedInDolibarr", $object->getFullName($langs));
  662. }
  663. $object->actionmsg = $langs->transnoentities("MemberDeletedInDolibarr", $object->getFullName($langs));
  664. $object->actionmsg .= "\n".$langs->transnoentities("Member").': '.$object->getFullName($langs);
  665. $object->actionmsg .= "\n".$langs->transnoentities("Type").': '.$object->type;
  666. $object->sendtoid = 0;
  667. } elseif ($action == 'PROJECT_CREATE') {
  668. // Projects
  669. // Load translation files required by the page
  670. $langs->loadLangs(array("agenda", "other", "projects"));
  671. if (empty($object->actionmsg2)) {
  672. $object->actionmsg2 = $langs->transnoentities("ProjectCreatedInDolibarr", $object->ref);
  673. }
  674. $object->actionmsg = $langs->transnoentities("ProjectCreatedInDolibarr", $object->ref);
  675. $object->actionmsg .= "\n".$langs->transnoentities("Project").': '.$object->ref;
  676. $object->sendtoid = 0;
  677. } elseif ($action == 'PROJECT_VALIDATE') {
  678. // Load translation files required by the page
  679. $langs->loadLangs(array("agenda", "other", "projects"));
  680. if (empty($object->actionmsg2)) {
  681. $object->actionmsg2 = $langs->transnoentities("ProjectValidatedInDolibarr", $object->ref);
  682. }
  683. $object->actionmsg = $langs->transnoentities("ProjectValidatedInDolibarr", $object->ref);
  684. $object->actionmsg .= "\n".$langs->transnoentities("Project").': '.$object->ref;
  685. $object->sendtoid = 0;
  686. } elseif ($action == 'PROJECT_MODIFY') {
  687. // Load translation files required by the page
  688. $langs->loadLangs(array("agenda", "other", "projects"));
  689. if (empty($object->actionmsg2)) {
  690. $object->actionmsg2 = $langs->transnoentities("ProjectModifiedInDolibarr", $object->ref);
  691. }
  692. $object->actionmsg = $langs->transnoentities("ProjectModifiedInDolibarr", $object->ref);
  693. //$object->actionmsg .= "\n".$langs->transnoentities("Task").': ???';
  694. if (!empty($object->usage_opportunity) && is_object($object->oldcopy) && $object->opp_status != $object->oldcopy->opp_status) {
  695. $object->actionmsg .= "\n".$langs->transnoentitiesnoconv("OpportunityStatus").': '.$object->oldcopy->opp_status.' -> '.$object->opp_status;
  696. }
  697. $object->sendtoid = 0;
  698. } elseif ($action == 'TASK_CREATE') {
  699. // Project tasks
  700. // Load translation files required by the page
  701. $langs->loadLangs(array("agenda", "other", "projects"));
  702. if (empty($object->actionmsg2)) {
  703. $object->actionmsg2 = $langs->transnoentities("TaskCreatedInDolibarr", $object->ref);
  704. }
  705. $object->actionmsg = $langs->transnoentities("TaskCreatedInDolibarr", $object->ref);
  706. $object->actionmsg .= "\n".$langs->transnoentities("Task").': '.$object->ref;
  707. $object->sendtoid = 0;
  708. } elseif ($action == 'TASK_MODIFY') {
  709. // Load translation files required by the page
  710. $langs->loadLangs(array("agenda", "other", "projects"));
  711. if (empty($object->actionmsg2)) {
  712. $object->actionmsg2 = $langs->transnoentities("TaskModifiedInDolibarr", $object->ref);
  713. }
  714. $object->actionmsg = $langs->transnoentities("TaskModifieddInDolibarr", $object->ref);
  715. $object->actionmsg .= "\n".$langs->transnoentities("Task").': '.$object->ref;
  716. $object->sendtoid = 0;
  717. } elseif ($action == 'TASK_DELETE') {
  718. // Load translation files required by the page
  719. $langs->loadLangs(array("agenda", "other", "projects"));
  720. if (empty($object->actionmsg2)) {
  721. $object->actionmsg2 = $langs->transnoentities("TaskDeletedInDolibarr", $object->ref);
  722. }
  723. $object->actionmsg = $langs->transnoentities("TaskDeletedInDolibarr", $object->ref);
  724. $object->actionmsg .= "\n".$langs->transnoentities("Task").': '.$object->ref;
  725. $object->sendtoid = 0;
  726. } elseif ($action == 'TICKET_ASSIGNED') {
  727. // Load translation files required by the page
  728. $langs->loadLangs(array("agenda", "other", "projects"));
  729. if (empty($object->actionmsg2)) {
  730. $object->actionmsg2 = $langs->transnoentities("TICKET_ASSIGNEDInDolibarr", $object->ref);
  731. }
  732. $object->actionmsg = $langs->transnoentities("TICKET_ASSIGNEDInDolibarr", $object->ref);
  733. if ($object->oldcopy->fk_user_assign > 0) {
  734. $tmpuser = new User($this->db);
  735. $tmpuser->fetch($object->oldcopy->fk_user_assign);
  736. $object->actionmsg .= "\n".$langs->transnoentities("OldUser").': '.$tmpuser->getFullName($langs);
  737. } else {
  738. $object->actionmsg .= "\n".$langs->transnoentities("OldUser").': '.$langs->trans("None");
  739. }
  740. if ($object->fk_user_assign > 0) {
  741. $tmpuser = new User($this->db);
  742. $tmpuser->fetch($object->fk_user_assign);
  743. $object->actionmsg .= "\n".$langs->transnoentities("NewUser").': '.$tmpuser->getFullName($langs);
  744. } else {
  745. $object->actionmsg .= "\n".$langs->transnoentities("NewUser").': '.$langs->trans("None");
  746. }
  747. $object->sendtoid = 0;
  748. } else {
  749. // TODO Merge all previous cases into this generic one
  750. // $action = BILL_DELETE, TICKET_CREATE, TICKET_MODIFY, TICKET_DELETE, CONTACT_SENTBYMAIL, RECRUITMENTCANDIDATURE_MODIFY, ...
  751. // Can also be a value defined by an external module like SENTBYSMS, COMPANY_SENTBYSMS, MEMBER_SENTBYSMS, ...
  752. // Note: We are here only if $conf->global->MAIN_AGENDA_ACTIONAUTO_action is on (tested at begining of this function).
  753. // Note that these key can be set in agenda setup, only if defined into llx_c_action_trigger
  754. // Load translation files required by the page
  755. if (empty($object->actionmsg2)) {
  756. $langs->loadLangs(array("agenda", "other"));
  757. if ($langs->transnoentities($action."InDolibarr", (empty($object->newref) ? $object->ref : $object->newref)) != $action."InDolibarr") { // specific translation key
  758. $object->actionmsg2 = $langs->transnoentities($action."InDolibarr", (empty($object->newref) ? $object->ref : $object->newref));
  759. } else { // generic translation key
  760. $tmp = explode('_', $action);
  761. $object->actionmsg2 = $langs->transnoentities($tmp[count($tmp) - 1]."InDolibarr", (empty($object->newref) ? $object->ref : $object->newref));
  762. }
  763. }
  764. if (empty($object->actionmsg)) {
  765. $langs->loadLangs(array("agenda", "other"));
  766. if ($langs->transnoentities($action."InDolibarr", (empty($object->newref) ? $object->ref : $object->newref)) != $action."InDolibarr") { // specific translation key
  767. $object->actionmsg = $langs->transnoentities($action."InDolibarr", (empty($object->newref) ? $object->ref : $object->newref));
  768. } else { // generic translation key
  769. $tmp = explode('_', $action);
  770. $object->actionmsg = $langs->transnoentities($tmp[count($tmp) - 1]."InDolibarr", (empty($object->newref) ? $object->ref : $object->newref));
  771. }
  772. }
  773. if (!isset($object->sendtoid) || !is_array($object->sendtoid)) {
  774. $object->sendtoid = 0;
  775. }
  776. }
  777. // If trackid is not defined, we set it.
  778. // Note that it should be set by caller. This is for compatibility purpose only.
  779. if (empty($object->trackid)) {
  780. // See also similar list into emailcollector.class.php
  781. if (preg_match('/^COMPANY_/', $action)) {
  782. $object->trackid = 'thi'.$object->id;
  783. } elseif (preg_match('/^CONTACT_/', $action)) {
  784. $object->trackid = 'ctc'.$object->id;
  785. } elseif (preg_match('/^CONTRACT_/', $action)) {
  786. $object->trackid = 'con'.$object->id;
  787. } elseif (preg_match('/^PROPAL_/', $action)) {
  788. $object->trackid = 'pro'.$object->id;
  789. } elseif (preg_match('/^ORDER_/', $action)) {
  790. $object->trackid = 'ord'.$object->id;
  791. } elseif (preg_match('/^BILL_/', $action)) {
  792. $object->trackid = 'inv'.$object->id;
  793. } elseif (preg_match('/^FICHINTER_/', $action)) {
  794. $object->trackid = 'int'.$object->id;
  795. } elseif (preg_match('/^SHIPPING_/', $action)) {
  796. $object->trackid = 'shi'.$object->id;
  797. } elseif (preg_match('/^RECEPTION_/', $action)) {
  798. $object->trackid = 'rec'.$object->id;
  799. } elseif (preg_match('/^PROPOSAL_SUPPLIER/', $action)) {
  800. $object->trackid = 'spr'.$object->id;
  801. } elseif (preg_match('/^ORDER_SUPPLIER_/', $action)) {
  802. $object->trackid = 'sor'.$object->id;
  803. } elseif (preg_match('/^BILL_SUPPLIER_/', $action)) {
  804. $object->trackid = 'sin'.$object->id;
  805. } elseif (preg_match('/^MEMBER_SUBSCRIPTION_/', $action)) {
  806. $object->trackid = 'sub'.$object->id;
  807. } elseif (preg_match('/^MEMBER_/', $action)) {
  808. $object->trackid = 'mem'.$object->id;
  809. } elseif (preg_match('/^PROJECT_/', $action)) {
  810. $object->trackid = 'proj'.$object->id;
  811. } elseif (preg_match('/^TASK_/', $action)) {
  812. $object->trackid = 'tas'.$object->id;
  813. } elseif (preg_match('/^TICKET_/', $action)) {
  814. $object->trackid = 'tic'.$object->id;
  815. } else {
  816. $object->trackid = '';
  817. }
  818. }
  819. /* Seems no more required: We have the data in dedicated field now.
  820. if (!empty($user->login)) {
  821. $object->actionmsg = dol_concatdesc($langs->transnoentities("Author").': '.$user->login, $object->actionmsg);
  822. } elseif (isset($object->origin_email)) {
  823. $object->actionmsg = dol_concatdesc($langs->transnoentities("Author").': '.$object->origin_email, $object->actionmsg);
  824. }
  825. */
  826. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  827. // Add entry in event table
  828. $now = dol_now();
  829. if (isset($_SESSION['listofnames-'.$object->trackid])) {
  830. $attachs = $_SESSION['listofnames-'.$object->trackid];
  831. if ($attachs && strpos($action, 'SENTBYMAIL')) {
  832. $object->actionmsg = dol_concatdesc($object->actionmsg, "\n".$langs->transnoentities("AttachedFiles").': '.$attachs);
  833. }
  834. }
  835. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  836. require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  837. $contactforaction = new Contact($this->db);
  838. $societeforaction = new Societe($this->db);
  839. // Set contactforaction if there is only 1 contact.
  840. if (is_array($object->sendtoid)) {
  841. if (count($object->sendtoid) == 1) {
  842. $contactforaction->fetch(reset($object->sendtoid));
  843. }
  844. } else {
  845. if ($object->sendtoid > 0) {
  846. $contactforaction->fetch($object->sendtoid);
  847. }
  848. }
  849. // Set societeforaction.
  850. if (isset($object->socid) && $object->socid > 0) {
  851. $societeforaction->fetch($object->socid);
  852. } elseif (isset($object->fk_soc) && $object->fk_soc > 0) {
  853. $societeforaction->fetch($object->fk_soc);
  854. } elseif (isset($object->thirdparty) && isset($object->thirdparty->id) && $object->thirdparty->id > 0) {
  855. $societeforaction = $object->thirdparty;
  856. }
  857. $projectid = isset($object->fk_project) ? $object->fk_project : 0;
  858. if ($object->element == 'project') {
  859. $projectid = $object->id;
  860. }
  861. $elementid = $object->id; // id of object
  862. $elementtype = $object->element;
  863. $elementmodule = (empty($object->module) ? '' : $object->module);
  864. if ($object->element == 'subscription') {
  865. $elementid = $object->fk_adherent;
  866. $elementtype = 'member';
  867. }
  868. //var_dump($societeforaction);var_dump($contactforaction);var_dump($elementid);var_dump($elementtype);exit;
  869. // Insertion action
  870. require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
  871. $actioncomm = new ActionComm($this->db);
  872. $actioncomm->type_code = $object->actiontypecode; // Type of event ('AC_OTH', 'AC_OTH_AUTO', 'AC_XXX'...)
  873. $actioncomm->code = 'AC_'.$action;
  874. $actioncomm->label = $object->actionmsg2;
  875. $actioncomm->note_private = $object->actionmsg;
  876. $actioncomm->fk_project = $projectid;
  877. $actioncomm->datep = $now;
  878. $actioncomm->datef = $now;
  879. $actioncomm->durationp = 0;
  880. $actioncomm->percentage = -1; // Not applicable
  881. $actioncomm->socid = $societeforaction->id;
  882. $actioncomm->contact_id = $contactforaction->id; // deprecated, use ->socpeopleassigned instead
  883. $actioncomm->authorid = $user->id; // User saving action
  884. $actioncomm->userownerid = $user->id; // Owner of action
  885. // Fields defined when action is an email (content should be into object->actionmsg to be added into event note, subject should be into object->actionms2 to be added into event label)
  886. if (!property_exists($object, 'email_fields_no_propagate_in_actioncomm') || empty($object->email_fields_no_propagate_in_actioncomm)) {
  887. $actioncomm->email_msgid = empty($object->email_msgid) ? null : $object->email_msgid;
  888. $actioncomm->email_from = empty($object->email_from) ? null : $object->email_from;
  889. $actioncomm->email_sender = empty($object->email_sender) ? null : $object->email_sender;
  890. $actioncomm->email_to = empty($object->email_to) ? null : $object->email_to;
  891. $actioncomm->email_tocc = empty($object->email_tocc) ? null : $object->email_tocc;
  892. $actioncomm->email_tobcc = empty($object->email_tobcc) ? null : $object->email_tobcc;
  893. $actioncomm->email_subject = empty($object->email_subject) ? null : $object->email_subject;
  894. $actioncomm->errors_to = empty($object->errors_to) ? null : $object->errors_to;
  895. }
  896. // Object linked (if link is for thirdparty, contact, project it is a recording error. We should not have links in link table
  897. // for such objects because there is already a dedicated field into table llx_actioncomm or llx_actioncomm_resources.
  898. if (!in_array($elementtype, array('societe', 'contact', 'project'))) {
  899. $actioncomm->fk_element = $elementid;
  900. $actioncomm->elementtype = $elementtype.($elementmodule ? '@'.$elementmodule : '');
  901. }
  902. if (property_exists($object, 'attachedfiles') && is_array($object->attachedfiles) && count($object->attachedfiles) > 0) {
  903. $actioncomm->attachedfiles = $object->attachedfiles;
  904. }
  905. if (property_exists($object, 'sendtouserid') && is_array($object->sendtouserid) && count($object->sendtouserid) > 0) {
  906. $actioncomm->userassigned = $object->sendtouserid;
  907. }
  908. if (property_exists($object, 'sendtoid') && is_array($object->sendtoid) && count($object->sendtoid) > 0) {
  909. foreach ($object->sendtoid as $val) {
  910. $actioncomm->socpeopleassigned[$val] = $val;
  911. }
  912. }
  913. $ret = $actioncomm->create($user); // User creating action
  914. if ($ret > 0 && !empty($conf->global->MAIN_COPY_FILE_IN_EVENT_AUTO)) {
  915. if (is_array($object->attachedfiles) && array_key_exists('paths', $object->attachedfiles) && count($object->attachedfiles['paths']) > 0) {
  916. foreach ($object->attachedfiles['paths'] as $key => $filespath) {
  917. $srcfile = $filespath;
  918. $destdir = $conf->agenda->dir_output.'/'.$ret;
  919. $destfile = $destdir.'/'.$object->attachedfiles['names'][$key];
  920. if (dol_mkdir($destdir) >= 0) {
  921. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  922. dol_copy($srcfile, $destfile);
  923. }
  924. }
  925. }
  926. }
  927. unset($object->actionmsg);
  928. unset($object->actionmsg2);
  929. unset($object->actiontypecode); // When several action are called on same object, we must be sure to not reuse value of first action.
  930. if ($ret > 0) {
  931. $_SESSION['LAST_ACTION_CREATED'] = $ret;
  932. return 1;
  933. } else {
  934. $this->error = "Failed to insert event : ".$actioncomm->error." ".join(',', $actioncomm->errors);
  935. $this->errors = $actioncomm->errors;
  936. dol_syslog("interface_modAgenda_ActionsAuto.class.php: ".$this->error, LOG_ERR);
  937. return -1;
  938. }
  939. }
  940. }