interface_50_modAgenda_ActionsAuto.class.php 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829
  1. <?php
  2. /* Copyright (C) 2005-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2009-2011 Regis Houssin <regis.houssin@capnetworks.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 <http://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. public $family = 'agenda';
  34. public $description = "Triggers of this module add actions in agenda according to setup made in agenda setup.";
  35. public $version = self::VERSION_DOLIBARR;
  36. public $picto = 'action';
  37. /**
  38. * Function called when a Dolibarrr business event is done.
  39. * All functions "runTrigger" are triggered if file is inside directory htdocs/core/triggers or htdocs/module/code/triggers (and declared)
  40. *
  41. * Following properties may be set before calling trigger. The may be completed by this trigger to be used for writing the event into database:
  42. * $object->actiontypecode (translation action code: AC_OTH, ...)
  43. * $object->actionmsg (note, long text)
  44. * $object->actionmsg2 (label, short text)
  45. * $object->sendtoid (id of contact)
  46. * $object->socid
  47. * $object->fk_project
  48. * $object->fk_element
  49. * $object->elementtype
  50. *
  51. * @param string $action Event action code
  52. * @param Object $object Object
  53. * @param User $user Object user
  54. * @param Translate $langs Object langs
  55. * @param conf $conf Object conf
  56. * @return int <0 if KO, 0 if no triggered ran, >0 if OK
  57. */
  58. public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
  59. {
  60. // Module not active, we do nothing
  61. if (empty($conf->agenda->enabled)) {
  62. return 0;
  63. }
  64. $key = 'MAIN_AGENDA_ACTIONAUTO_'.$action;
  65. // Do not log events not enabled for this action
  66. if (empty($conf->global->$key)) {
  67. return 0;
  68. }
  69. $langs->load("agenda");
  70. // Actions
  71. if ($action == 'COMPANY_CREATE')
  72. {
  73. $langs->load("other");
  74. $langs->load("companies");
  75. $object->actiontypecode='AC_OTH_AUTO';
  76. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("NewCompanyToDolibarr",$object->name);
  77. $object->actionmsg=$langs->transnoentities("NewCompanyToDolibarr",$object->name);
  78. if (! empty($object->prefix)) $object->actionmsg.=" (".$object->prefix.")";
  79. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  80. $object->sendtoid=0;
  81. $object->socid=$object->id;
  82. }
  83. elseif ($action == 'COMPANY_SENTBYMAIL')
  84. {
  85. $langs->load("other");
  86. $langs->load("orders");
  87. if (empty($object->actiontypecode)) $object->actiontypecode='AC_OTH_AUTO';
  88. if (empty($object->actionmsg2)) dol_syslog('Trigger called with property actionmsg2 on object not defined', LOG_ERR);
  89. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  90. // Parameters $object->sendtoid defined by caller
  91. //$object->sendtoid=0;
  92. }
  93. elseif ($action == 'CONTRACT_VALIDATE')
  94. {
  95. $langs->load("other");
  96. $langs->load("contracts");
  97. $object->actiontypecode='AC_OTH_AUTO';
  98. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ContractValidatedInDolibarr",($object->newref?$object->newref:$object->ref));
  99. $object->actionmsg=$langs->transnoentities("ContractValidatedInDolibarr",($object->newref?$object->newref:$object->ref));
  100. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  101. $object->sendtoid=0;
  102. }
  103. elseif ($action == 'PROPAL_VALIDATE')
  104. {
  105. $langs->load("other");
  106. $langs->load("propal");
  107. $object->actiontypecode='AC_OTH_AUTO';
  108. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("PropalValidatedInDolibarr",($object->newref?$object->newref:$object->ref));
  109. $object->actionmsg=$langs->transnoentities("PropalValidatedInDolibarr",($object->newref?$object->newref:$object->ref));
  110. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  111. $object->sendtoid=0;
  112. }
  113. elseif ($action == 'PROPAL_SENTBYMAIL')
  114. {
  115. $langs->load("other");
  116. $langs->load("propal");
  117. $object->actiontypecode='AC_OTH_AUTO';
  118. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ProposalSentByEMail",$object->ref);
  119. if (empty($object->actionmsg))
  120. {
  121. $object->actionmsg=$langs->transnoentities("ProposalSentByEMail",$object->ref);
  122. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  123. }
  124. // Parameters $object->sendtoid defined by caller
  125. //$object->sendtoid=0;
  126. }
  127. elseif ($action == 'PROPAL_CLOSE_SIGNED')
  128. {
  129. $langs->load("other");
  130. $langs->load("propal");
  131. $object->actiontypecode='AC_OTH_AUTO';
  132. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("PropalClosedSignedInDolibarr",$object->ref);
  133. $object->actionmsg=$langs->transnoentities("PropalClosedSignedInDolibarr",$object->ref);
  134. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  135. $object->sendtoid=0;
  136. }
  137. elseif ($action == 'PROPAL_CLASSIFY_BILLED')
  138. {
  139. $langs->load("other");
  140. $langs->load("propal");
  141. $object->actiontypecode='AC_OTH_AUTO';
  142. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("PropalClassifiedBilledInDolibarr",$object->ref);
  143. $object->actionmsg=$langs->transnoentities("PropalClassifiedBilledInDolibarr",$object->ref);
  144. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  145. $object->sendtoid=0;
  146. }
  147. elseif ($action == 'PROPAL_CLOSE_REFUSED')
  148. {
  149. $langs->load("other");
  150. $langs->load("propal");
  151. $object->actiontypecode='AC_OTH_AUTO';
  152. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("PropalClosedRefusedInDolibarr",$object->ref);
  153. $object->actionmsg=$langs->transnoentities("PropalClosedRefusedInDolibarr",$object->ref);
  154. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  155. $object->sendtoid=0;
  156. }
  157. elseif ($action == 'ORDER_VALIDATE')
  158. {
  159. $langs->load("orders");
  160. $object->actiontypecode='AC_OTH_AUTO';
  161. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderValidatedInDolibarr",($object->newref?$object->newref:$object->ref));
  162. $object->actionmsg=$langs->transnoentities("OrderValidatedInDolibarr",($object->newref?$object->newref:$object->ref));
  163. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  164. $object->sendtoid=0;
  165. }
  166. elseif ($action == 'ORDER_CLOSE')
  167. {
  168. $langs->load("other");
  169. $langs->load("orders");
  170. $object->actiontypecode='AC_OTH_AUTO';
  171. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderDeliveredInDolibarr",$object->ref);
  172. $object->actionmsg=$langs->transnoentities("OrderDeliveredInDolibarr",$object->ref);
  173. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  174. $object->sendtoid=0;
  175. }
  176. elseif ($action == 'ORDER_CLASSIFY_BILLED')
  177. {
  178. $langs->load("other");
  179. $langs->load("orders");
  180. $object->actiontypecode='AC_OTH_AUTO';
  181. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderBilledInDolibarr",$object->ref);
  182. $object->actionmsg=$langs->transnoentities("OrderBilledInDolibarr",$object->ref);
  183. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  184. $object->sendtoid=0;
  185. }
  186. elseif ($action == 'ORDER_CANCEL')
  187. {
  188. $langs->load("other");
  189. $langs->load("orders");
  190. $object->actiontypecode='AC_OTH_AUTO';
  191. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderCanceledInDolibarr",$object->ref);
  192. $object->actionmsg=$langs->transnoentities("OrderCanceledInDolibarr",$object->ref);
  193. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  194. $object->sendtoid=0;
  195. }
  196. elseif ($action == 'ORDER_SENTBYMAIL')
  197. {
  198. $langs->load("other");
  199. $langs->load("orders");
  200. $object->actiontypecode='AC_OTH_AUTO';
  201. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderSentByEMail",$object->ref);
  202. if (empty($object->actionmsg))
  203. {
  204. $object->actionmsg=$langs->transnoentities("OrderSentByEMail",$object->ref);
  205. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  206. }
  207. // Parameters $object->sendtoid defined by caller
  208. //$object->sendtoid=0;
  209. }
  210. elseif ($action == 'BILL_VALIDATE')
  211. {
  212. $langs->load("other");
  213. $langs->load("bills");
  214. $object->actiontypecode='AC_OTH_AUTO';
  215. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceValidatedInDolibarr",($object->newref?$object->newref:$object->ref));
  216. $object->actionmsg=$langs->transnoentities("InvoiceValidatedInDolibarr",($object->newref?$object->newref:$object->ref));
  217. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  218. $object->sendtoid=0;
  219. }
  220. elseif ($action == 'BILL_UNVALIDATE')
  221. {
  222. $langs->load("other");
  223. $langs->load("bills");
  224. $object->actiontypecode='AC_OTH_AUTO';
  225. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceBackToDraftInDolibarr",$object->ref);
  226. $object->actionmsg=$langs->transnoentities("InvoiceBackToDraftInDolibarr",$object->ref);
  227. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  228. $object->sendtoid=0;
  229. }
  230. elseif ($action == 'BILL_SENTBYMAIL')
  231. {
  232. $langs->load("other");
  233. $langs->load("bills");
  234. $object->actiontypecode='AC_OTH_AUTO';
  235. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceSentByEMail",$object->ref);
  236. if (empty($object->actionmsg))
  237. {
  238. $object->actionmsg=$langs->transnoentities("InvoiceSentByEMail",$object->ref);
  239. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  240. }
  241. // Parameters $object->sendtoid defined by caller
  242. //$object->sendtoid=0;
  243. }
  244. elseif ($action == 'BILL_PAYED')
  245. {
  246. $langs->load("other");
  247. $langs->load("bills");
  248. // Values for this action can't be defined by caller.
  249. $object->actiontypecode='AC_OTH_AUTO';
  250. $object->actionmsg2=$langs->transnoentities("InvoicePaidInDolibarr",$object->ref);
  251. $object->actionmsg=$langs->transnoentities("InvoicePaidInDolibarr",$object->ref);
  252. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  253. $object->sendtoid=0;
  254. }
  255. elseif ($action == 'BILL_CANCEL')
  256. {
  257. $langs->load("other");
  258. $langs->load("bills");
  259. $object->actiontypecode='AC_OTH_AUTO';
  260. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceCanceledInDolibarr",$object->ref);
  261. $object->actionmsg=$langs->transnoentities("InvoiceCanceledInDolibarr",$object->ref);
  262. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  263. $object->sendtoid=0;
  264. }
  265. elseif ($action == 'FICHINTER_CREATE')
  266. {
  267. $langs->load("other");
  268. $langs->load("interventions");
  269. $object->actiontypecode='AC_OTH_AUTO';
  270. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InterventionCreatedInDolibarr",$object->ref);
  271. $object->actionmsg=$langs->transnoentities("InterventionCreatedInDolibarr",$object->ref);
  272. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  273. $object->sendtoid=0;
  274. $object->fk_element=0;
  275. $object->elementtype='';
  276. }
  277. elseif ($action == 'FICHINTER_VALIDATE')
  278. {
  279. $langs->load("other");
  280. $langs->load("interventions");
  281. $object->actiontypecode='AC_OTH_AUTO';
  282. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InterventionValidatedInDolibarr",($object->newref?$object->newref:$object->ref));
  283. $object->actionmsg=$langs->transnoentities("InterventionValidatedInDolibarr",($object->newref?$object->newref:$object->ref));
  284. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  285. $object->sendtoid=0;
  286. $object->fk_element=0;
  287. $object->elementtype='';
  288. }
  289. elseif ($action == 'FICHINTER_MODIFY')
  290. {
  291. $langs->load("other");
  292. $langs->load("interventions");
  293. $object->actiontypecode='AC_OTH_AUTO';
  294. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InterventionModifiedInDolibarr",$object->ref);
  295. $object->actionmsg=$langs->transnoentities("InterventionModifiedInDolibarr",$object->ref);
  296. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  297. $object->sendtoid=0;
  298. $object->fk_element=0;
  299. $object->elementtype='';
  300. }
  301. elseif ($action == 'FICHINTER_SENTBYMAIL')
  302. {
  303. $langs->load("other");
  304. $langs->load("interventions");
  305. $object->actiontypecode='AC_OTH_AUTO';
  306. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InterventionSentByEMail",$object->ref);
  307. $object->actionmsg=$langs->transnoentities("InterventionSentByEMail",$object->ref);
  308. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  309. // Parameters $object->sendtoid defined by caller
  310. //$object->sendtoid=0;
  311. }
  312. elseif ($action == 'FICHINTER_CLASSIFY_BILLED')
  313. {
  314. $langs->load("other");
  315. $langs->load("interventions");
  316. $object->actiontypecode='AC_OTH_AUTO';
  317. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InterventionClassifiedBilledInDolibarr",$object->ref);
  318. $object->actionmsg=$langs->transnoentities("InterventionClassifiedBilledInDolibarr",$object->ref);
  319. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  320. $object->sendtoid=0;
  321. }
  322. elseif ($action == 'FICHINTER_CLASSIFY_UNBILLED')
  323. {
  324. $langs->load("other");
  325. $langs->load("interventions");
  326. $object->actiontypecode='AC_OTH_AUTO';
  327. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InterventionClassifiedUnbilledInDolibarr",$object->ref);
  328. $object->actionmsg=$langs->transnoentities("InterventionClassifiedUnbilledInDolibarr",$object->ref);
  329. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  330. $object->sendtoid=0;
  331. }
  332. elseif ($action == 'FICHINTER_DELETE')
  333. {
  334. $langs->load("other");
  335. $langs->load("interventions");
  336. $object->actiontypecode='AC_OTH_AUTO';
  337. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InterventionDeletedInDolibarr",$object->ref);
  338. $object->actionmsg=$langs->transnoentities("InterventionDeletedInDolibarr",$object->ref);
  339. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  340. $object->sendtoid=0;
  341. $object->fk_element=0;
  342. $object->elementtype='';
  343. }
  344. elseif ($action == 'SHIPPING_VALIDATE')
  345. {
  346. $langs->load("other");
  347. $langs->load("sendings");
  348. $object->actiontypecode='AC_OTH_AUTO';
  349. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ShippingValidated",($object->newref?$object->newref:$object->ref));
  350. if (empty($object->actionmsg))
  351. {
  352. $object->actionmsg=$langs->transnoentities("ShippingValidated",($object->newref?$object->newref:$object->ref));
  353. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  354. }
  355. // Parameters $object->sendtoid defined by caller
  356. //$object->sendtoid=0;
  357. }
  358. elseif ($action == 'SHIPPING_SENTBYMAIL')
  359. {
  360. $langs->load("other");
  361. $langs->load("sendings");
  362. $object->actiontypecode='AC_OTH_AUTO';
  363. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ShippingSentByEMail",$object->ref);
  364. if (empty($object->actionmsg))
  365. {
  366. $object->actionmsg=$langs->transnoentities("ShippingSentByEMail",$object->ref);
  367. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  368. }
  369. // Parameters $object->sendtoid defined by caller
  370. //$object->sendtoid=0;
  371. }
  372. elseif ($action == 'ORDER_SUPPLIER_CREATE')
  373. {
  374. $langs->load("other");
  375. $langs->load("orders");
  376. $object->actiontypecode='AC_OTH_AUTO';
  377. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderCreatedInDolibarr",($object->newref?$object->newref:$object->ref));
  378. $object->actionmsg=$langs->transnoentities("OrderCreatedInDolibarr",($object->newref?$object->newref:$object->ref));
  379. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  380. $object->sendtoid=0;
  381. }
  382. elseif ($action == 'ORDER_SUPPLIER_VALIDATE')
  383. {
  384. $langs->load("other");
  385. $langs->load("orders");
  386. $object->actiontypecode='AC_OTH_AUTO';
  387. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderValidatedInDolibarr",($object->newref?$object->newref:$object->ref));
  388. $object->actionmsg=$langs->transnoentities("OrderValidatedInDolibarr",($object->newref?$object->newref:$object->ref));
  389. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  390. $object->sendtoid=0;
  391. }
  392. elseif ($action == 'ORDER_SUPPLIER_APPROVE')
  393. {
  394. $langs->load("other");
  395. $langs->load("orders");
  396. $object->actiontypecode='AC_OTH_AUTO';
  397. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderApprovedInDolibarr",$object->ref);
  398. $object->actionmsg=$langs->transnoentities("OrderApprovedInDolibarr",$object->ref);
  399. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  400. $object->sendtoid=0;
  401. }
  402. elseif ($action == 'ORDER_SUPPLIER_REFUSE')
  403. {
  404. $langs->load("other");
  405. $langs->load("orders");
  406. $object->actiontypecode='AC_OTH_AUTO';
  407. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderRefusedInDolibarr",$object->ref);
  408. $object->actionmsg=$langs->transnoentities("OrderRefusedInDolibarr",$object->ref);
  409. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  410. $object->sendtoid=0;
  411. }
  412. elseif ($action == 'ORDER_SUPPLIER_SUBMIT')
  413. {
  414. $langs->load("other");
  415. $langs->load("orders");
  416. $object->actiontypecode='AC_OTH_AUTO';
  417. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("SupplierOrderSubmitedInDolibarr",($object->newref?$object->newref:$object->ref));
  418. $object->actionmsg=$langs->transnoentities("SupplierOrderSubmitedInDolibarr",($object->newref?$object->newref:$object->ref));
  419. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  420. $object->sendtoid=0;
  421. }
  422. elseif ($action == 'ORDER_SUPPLIER_RECEIVE')
  423. {
  424. $langs->load("other");
  425. $langs->load("orders");
  426. $object->actiontypecode='AC_OTH_AUTO';
  427. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("SupplierOrderReceivedInDolibarr",($object->newref?$object->newref:$object->ref));
  428. $object->actionmsg=$langs->transnoentities("SupplierOrderReceivedInDolibarr",($object->newref?$object->newref:$object->ref));
  429. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  430. $object->sendtoid=0;
  431. }
  432. elseif ($action == 'ORDER_SUPPLIER_SENTBYMAIL')
  433. {
  434. $langs->load("other");
  435. $langs->load("bills");
  436. $langs->load("orders");
  437. $object->actiontypecode='AC_OTH_AUTO';
  438. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("SupplierOrderSentByEMail",$object->ref);
  439. if (empty($object->actionmsg))
  440. {
  441. $object->actionmsg=$langs->transnoentities("SupplierOrderSentByEMail",$object->ref);
  442. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  443. }
  444. // Parameters $object->sendtoid defined by caller
  445. //$object->sendtoid=0;
  446. }
  447. elseif ($action == 'ORDER_SUPPLIER_CLASSIFY_BILLED')
  448. {
  449. $langs->load("other");
  450. $langs->load("bills");
  451. $langs->load("orders");
  452. $object->actiontypecode='AC_OTH_AUTO';
  453. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("SupplierOrderClassifiedBilled",$object->ref);
  454. if (empty($object->actionmsg))
  455. {
  456. $object->actionmsg=$langs->transnoentities("SupplierOrderClassifiedBilled",$object->ref);
  457. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  458. }
  459. $object->sendtoid=0;
  460. }
  461. elseif ($action == 'BILL_SUPPLIER_VALIDATE')
  462. {
  463. $langs->load("other");
  464. $langs->load("bills");
  465. $object->actiontypecode='AC_OTH_AUTO';
  466. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceValidatedInDolibarr",($object->newref?$object->newref:$object->ref));
  467. $object->actionmsg=$langs->transnoentities("InvoiceValidatedInDolibarr",($object->newref?$object->newref:$object->ref));
  468. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  469. $object->sendtoid=0;
  470. }
  471. elseif ($action == 'BILL_SUPPLIER_UNVALIDATE')
  472. {
  473. $langs->load("other");
  474. $langs->load("bills");
  475. $object->actiontypecode='AC_OTH_AUTO';
  476. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceBackToDraftInDolibarr",$object->ref);
  477. $object->actionmsg=$langs->transnoentities("InvoiceBackToDraftInDolibarr",$object->ref);
  478. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  479. $object->sendtoid=0;
  480. }
  481. elseif ($action == 'BILL_SUPPLIER_SENTBYMAIL')
  482. {
  483. $langs->load("other");
  484. $langs->load("bills");
  485. $langs->load("orders");
  486. $object->actiontypecode='AC_OTH_AUTO';
  487. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("SupplierInvoiceSentByEMail",$object->ref);
  488. if (empty($object->actionmsg))
  489. {
  490. $object->actionmsg=$langs->transnoentities("SupplierInvoiceSentByEMail",$object->ref);
  491. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  492. }
  493. // Parameters $object->sendtoid defined by caller
  494. //$object->sendtoid=0;
  495. }
  496. elseif ($action == 'BILL_SUPPLIER_PAYED')
  497. {
  498. $langs->load("other");
  499. $langs->load("bills");
  500. $object->actiontypecode='AC_OTH_AUTO';
  501. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoicePaidInDolibarr",$object->ref);
  502. $object->actionmsg=$langs->transnoentities("InvoicePaidInDolibarr",$object->ref);
  503. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  504. $object->sendtoid=0;
  505. }
  506. elseif ($action == 'BILL_SUPPLIER_CANCELED')
  507. {
  508. $langs->load("other");
  509. $langs->load("bills");
  510. $object->actiontypecode='AC_OTH_AUTO';
  511. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceCanceledInDolibarr",$object->ref);
  512. $object->actionmsg=$langs->transnoentities("InvoiceCanceledInDolibarr",$object->ref);
  513. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  514. $object->sendtoid=0;
  515. }
  516. // Members
  517. elseif ($action == 'MEMBER_VALIDATE')
  518. {
  519. $langs->load("other");
  520. $langs->load("members");
  521. $object->actiontypecode='AC_OTH_AUTO';
  522. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("MemberValidatedInDolibarr",($object->newref?$object->newref:$object->ref));
  523. $object->actionmsg=$langs->transnoentities("MemberValidatedInDolibarr",($object->newref?$object->newref:$object->ref));
  524. $object->actionmsg.="\n".$langs->transnoentities("Member").': '.$object->getFullName($langs);
  525. $object->actionmsg.="\n".$langs->transnoentities("Type").': '.$object->type;
  526. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  527. $object->sendtoid=0;
  528. }
  529. elseif ($action == 'MEMBER_SUBSCRIPTION')
  530. {
  531. $langs->load("other");
  532. $langs->load("members");
  533. $object->actiontypecode='AC_OTH_AUTO';
  534. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("MemberSubscriptionAddedInDolibarr",$object->ref);
  535. $object->actionmsg=$langs->transnoentities("MemberSubscriptionAddedInDolibarr",$object->ref);
  536. $object->actionmsg.="\n".$langs->transnoentities("Member").': '.$object->getFullName($langs);
  537. $object->actionmsg.="\n".$langs->transnoentities("Type").': '.$object->type;
  538. $object->actionmsg.="\n".$langs->transnoentities("Amount").': '.$object->last_subscription_amount;
  539. $object->actionmsg.="\n".$langs->transnoentities("Period").': '.dol_print_date($object->last_subscription_date_start,'day').' - '.dol_print_date($object->last_subscription_date_end,'day');
  540. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  541. $object->sendtoid=0;
  542. }
  543. elseif ($action == 'MEMBER_RESILIATE')
  544. {
  545. $langs->load("other");
  546. $langs->load("members");
  547. $object->actiontypecode='AC_OTH_AUTO';
  548. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("MemberResiliatedInDolibarr",$object->ref);
  549. $object->actionmsg=$langs->transnoentities("MemberResiliatedInDolibarr",$object->ref);
  550. $object->actionmsg.="\n".$langs->transnoentities("Member").': '.$object->getFullName($langs);
  551. $object->actionmsg.="\n".$langs->transnoentities("Type").': '.$object->type;
  552. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  553. $object->sendtoid=0;
  554. }
  555. elseif ($action == 'MEMBER_DELETE')
  556. {
  557. $langs->load("other");
  558. $langs->load("members");
  559. $object->actiontypecode='AC_OTH_AUTO';
  560. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("MemberDeletedInDolibarr",$object->ref);
  561. $object->actionmsg=$langs->transnoentities("MemberDeletedInDolibarr",$object->ref);
  562. $object->actionmsg.="\n".$langs->transnoentities("Member").': '.$object->getFullName($langs);
  563. $object->actionmsg.="\n".$langs->transnoentities("Type").': '.$object->type;
  564. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  565. $object->sendtoid=0;
  566. }
  567. // Projects
  568. elseif ($action == 'PROJECT_CREATE')
  569. {
  570. $langs->load("other");
  571. $langs->load("projects");
  572. $object->actiontypecode='AC_OTH_AUTO';
  573. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ProjectCreatedInDolibarr",$object->ref);
  574. $object->actionmsg=$langs->transnoentities("ProjectCreatedInDolibarr",$object->ref);
  575. $object->actionmsg.="\n".$langs->transnoentities("Project").': '.$object->ref;
  576. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  577. $object->sendtoid=0;
  578. }
  579. elseif($action == 'PROJECT_CREATE') {
  580. $langs->load("other");
  581. $langs->load("projects");
  582. $object->actiontypecode='AC_OTH_AUTO';
  583. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ProjectCreatedInDolibarr",$object->ref);
  584. $object->actionmsg=$langs->transnoentities("ProjectCreatedInDolibarr",$object->ref);
  585. $object->actionmsg.="\n".$langs->transnoentities("Task").': '.$object->ref;
  586. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  587. $object->sendtoid=0;
  588. }
  589. elseif($action == 'PROJECT_MODIFY') {
  590. $langs->load("other");
  591. $langs->load("projects");
  592. $object->actiontypecode='AC_OTH_AUTO';
  593. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ProjectModifiedInDolibarr",$object->ref);
  594. $object->actionmsg=$langs->transnoentities("ProjectModifieddInDolibarr",$object->ref);
  595. $object->actionmsg.="\n".$langs->transnoentities("Task").': '.$object->ref;
  596. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  597. $object->sendtoid=0;
  598. }
  599. // Project tasks
  600. elseif($action == 'TASK_CREATE') {
  601. $langs->load("other");
  602. $langs->load("projects");
  603. $object->actiontypecode='AC_OTH_AUTO';
  604. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("TaskCreatedInDolibarr",$object->ref);
  605. $object->actionmsg=$langs->transnoentities("TaskCreatedInDolibarr",$object->ref);
  606. $object->actionmsg.="\n".$langs->transnoentities("Task").': '.$object->ref;
  607. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  608. $object->sendtoid=0;
  609. }
  610. elseif($action == 'TASK_MODIFY') {
  611. $langs->load("other");
  612. $langs->load("projects");
  613. $object->actiontypecode='AC_OTH_AUTO';
  614. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("TaskModifiedInDolibarr",$object->ref);
  615. $object->actionmsg=$langs->transnoentities("TaskModifieddInDolibarr",$object->ref);
  616. $object->actionmsg.="\n".$langs->transnoentities("Task").': '.$object->ref;
  617. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  618. $object->sendtoid=0;
  619. }
  620. elseif($action == 'TASK_DELETE') {
  621. $langs->load("other");
  622. $langs->load("projects");
  623. $object->actiontypecode='AC_OTH_AUTO';
  624. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("TaskDeletedInDolibarr",$object->ref);
  625. $object->actionmsg=$langs->transnoentities("TaskDeletedInDolibarr",$object->ref);
  626. $object->actionmsg.="\n".$langs->transnoentities("Task").': '.$object->ref;
  627. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  628. $object->sendtoid=0;
  629. }
  630. // The trigger was enabled but we are missing the implementation, let the log know
  631. else
  632. {
  633. dol_syslog("Trigger '".$this->name."' for action '$action' was ran by ".__FILE__." but no handler found for this action.", LOG_WARNING);
  634. return 0;
  635. }
  636. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  637. // Add entry in event table
  638. $now=dol_now();
  639. if (isset($_SESSION['listofnames']))
  640. {
  641. $attachs=$_SESSION['listofnames'];
  642. if ($attachs && strpos($action,'SENTBYMAIL'))
  643. {
  644. $object->actionmsg=dol_concatdesc($object->actionmsg, "\n".$langs->transnoentities("AttachedFiles").': '.$attachs);
  645. }
  646. }
  647. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  648. require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  649. $contactforaction=new Contact($this->db);
  650. $societeforaction=new Societe($this->db);
  651. if ($object->sendtoid > 0) $contactforaction->fetch($object->sendtoid);
  652. if ($object->socid > 0) $societeforaction->fetch($object->socid);
  653. // Insertion action
  654. require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
  655. $actioncomm = new ActionComm($this->db);
  656. $actioncomm->type_code = $object->actiontypecode; // code of parent table llx_c_actioncomm (will be deprecated)
  657. $actioncomm->code = 'AC_'.$action;
  658. $actioncomm->label = $object->actionmsg2;
  659. $actioncomm->note = $object->actionmsg; // TODO Replace with $actioncomm->email_msgid ? $object->email_content : $object->actionmsg
  660. $actioncomm->fk_project = isset($object->fk_project)?$object->fk_project:0;
  661. $actioncomm->datep = $now;
  662. $actioncomm->datef = $now;
  663. $actioncomm->durationp = 0;
  664. $actioncomm->punctual = 1;
  665. $actioncomm->percentage = -1; // Not applicable
  666. $actioncomm->societe = $societeforaction;
  667. $actioncomm->contact = $contactforaction;
  668. $actioncomm->socid = $societeforaction->id;
  669. $actioncomm->contactid = $contactforaction->id;
  670. $actioncomm->authorid = $user->id; // User saving action
  671. $actioncomm->userownerid = $user->id; // Owner of action
  672. // Fields when action is en email (content should be added into note)
  673. $actioncomm->email_msgid = $object->email_msgid;
  674. $actioncomm->email_from = $object->email_from;
  675. $actioncomm->email_sender= $object->email_sender;
  676. $actioncomm->email_to = $object->email_to;
  677. $actioncomm->email_tocc = $object->email_tocc;
  678. $actioncomm->email_tobcc = $object->email_tobcc;
  679. $actioncomm->email_subject = $object->email_subject;
  680. $actioncomm->errors_to = $object->errors_to;
  681. $actioncomm->fk_element = $object->id;
  682. $actioncomm->elementtype = $object->element;
  683. $ret=$actioncomm->create($user); // User creating action
  684. unset($object->actionmsg); unset($object->actionmsg2); unset($object->actiontypecode); // When several action are called on same object, we must be sure to not reuse value of first action.
  685. if ($ret > 0)
  686. {
  687. $_SESSION['LAST_ACTION_CREATED'] = $ret;
  688. return 1;
  689. }
  690. else
  691. {
  692. $error ="Failed to insert event : ".$actioncomm->error." ".join(',',$actioncomm->errors);
  693. $this->error=$error;
  694. $this->errors=$actioncomm->errors;
  695. dol_syslog("interface_modAgenda_ActionsAuto.class.php: ".$this->error, LOG_ERR);
  696. return -1;
  697. }
  698. return 0;
  699. }
  700. }