interface_50_modAgenda_ActionsAuto.class.php 50 KB

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