interface_50_modAgenda_ActionsAuto.class.php 49 KB

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