interface_50_modAgenda_ActionsAuto.class.php 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584
  1. <?php
  2. /* Copyright (C) 2005-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2009-2017 Regis Houssin <regis.houssin@inodbox.com>
  4. * Copyright (C) 2011-2014 Juanjo Menent <jmenent@2byte.es>
  5. * Copyright (C) 2013 Cedric GROSS <c.gross@kreiz-it.fr>
  6. * Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
  7. * Copyright (C) 2015 Bahfir Abbes <bafbes@gmail.com>
  8. * Copyright (C) 2022 Ferran Marcet <fmarcet@2byte.es>
  9. * Copyright (C) 2023 William Mead <william.mead@manchenumerique.fr>
  10. * Copyright (C) 2023 Christian Foellmann <christian@foellmann.de>
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 3 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  24. */
  25. /**
  26. * \file htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php
  27. * \ingroup agenda
  28. * \brief Trigger file for agenda module
  29. */
  30. require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php';
  31. /**
  32. * Class of triggered functions for agenda module
  33. */
  34. class InterfaceActionsAuto extends DolibarrTriggers
  35. {
  36. /**
  37. * Constructor
  38. *
  39. * @param DoliDB $db Database handler
  40. */
  41. public function __construct($db)
  42. {
  43. $this->db = $db;
  44. $this->name = preg_replace('/^Interface/i', '', get_class($this));
  45. $this->family = "agenda";
  46. $this->description = "Triggers of this module add actions in agenda according to setup made in agenda setup.";
  47. // 'development', 'experimental', 'dolibarr' or version
  48. $this->version = self::VERSION_DOLIBARR;
  49. $this->picto = 'action';
  50. }
  51. /**
  52. * Function called when a Dolibarrr business event is done.
  53. * All functions "runTrigger" are triggered if file is inside directory htdocs/core/triggers or htdocs/module/code/triggers (and declared)
  54. *
  55. * Following properties may be set before calling trigger. The may be completed by this trigger to be used for writing the event into database:
  56. * $object->actiontypecode (translation action code: AC_OTH, ...)
  57. * $object->actionmsg (note, long text)
  58. * $object->actionmsg2 (label, short text)
  59. * $object->sendtoid (id of contact or array of ids of contacts)
  60. * $object->socid (id of thirdparty)
  61. * $object->fk_project
  62. * $object->fk_element (ID of object to link action event to)
  63. * $object->elementtype (->element of object to link action to)
  64. * $object->module (if defined, elementtype in llx_actioncomm will be elementtype@module)
  65. *
  66. * @param string $action Event action code ('CONTRACT_MODIFY', 'RECRUITMENTCANDIDATURE_MODIFIY', or example by external module: 'SENTBYSMS'...)
  67. * @param Object $object Object
  68. * @param User $user Object user
  69. * @param Translate $langs Object langs
  70. * @param conf $conf Object conf
  71. * @return int Return integer <0 if KO, 0 if no triggered ran, >0 if OK
  72. */
  73. public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
  74. {
  75. if (!isModEnabled('agenda')) {
  76. return 0; // Module not active, we do nothing
  77. }
  78. // Do not log events when trigger is for creating event (infinite loop)
  79. if (preg_match('/^ACTION_/', $action)) {
  80. return 0;
  81. }
  82. $key = 'MAIN_AGENDA_ACTIONAUTO_'.$action;
  83. //var_dump($action.' - '.$key.' - '.$conf->global->$key);exit;
  84. // Do not log events not enabled for this action
  85. // GUI allow to set this option only if entry exists into table llx_c_action_trigger
  86. if (!getDolGlobalString($key)) {
  87. return 0;
  88. }
  89. $langs->load("agenda");
  90. if (empty($object->actiontypecode)) {
  91. $object->actiontypecode = 'AC_OTH_AUTO';
  92. }
  93. // Actions
  94. if ($action == 'COMPANY_CREATE') {
  95. // Load translation files required by the page
  96. $langs->loadLangs(array("agenda", "other", "companies"));
  97. if (empty($object->actionmsg2)) {
  98. if (empty($object->context['actionmsg2'])) {
  99. $object->actionmsg2 = $langs->transnoentities("NewCompanyToDolibarr", $object->name);
  100. } else {
  101. $object->actionmsg2 = $object->context['actionmsg2'];
  102. }
  103. }
  104. if (empty($object->actionmsg)) {
  105. $object->actionmsg = $langs->transnoentities("NewCompanyToDolibarr", $object->name);
  106. }
  107. $object->sendtoid = 0;
  108. $object->socid = $object->id;
  109. } elseif ($action == 'COMPANY_MODIFY') {
  110. // Load translation files required by the page
  111. $langs->loadLangs(array("agenda", "other", "companies"));
  112. if (empty($object->actionmsg2)) {
  113. if (empty($object->context['actionmsg2'])) {
  114. $object->actionmsg2 = $langs->transnoentities("COMPANY_MODIFYInDolibarr", $object->name);
  115. } else {
  116. $object->actionmsg2 = $object->context['actionmsg2'];
  117. }
  118. }
  119. if (empty($object->actionmsg)) {
  120. $object->actionmsg = $langs->transnoentities("COMPANY_MODIFYInDolibarr", $object->name);
  121. }
  122. // For merge event, we add a mention
  123. if (!empty($object->context['mergefromname'])) {
  124. $object->actionmsg = dol_concatdesc($object->actionmsg, $langs->trans("DataFromWasMerged", $object->context['mergefromname'].' (id='.$object->context['mergefromname'].')'));
  125. }
  126. $object->sendtoid = 0;
  127. $object->socid = $object->id;
  128. } elseif ($action == 'COMPANY_SENTBYMAIL') {
  129. // Load translation files required by the page
  130. $langs->loadLangs(array("agenda", "other", "orders"));
  131. if (empty($object->actionmsg2)) {
  132. if (empty($object->context['actionmsg2'])) {
  133. dol_syslog('Trigger called with property actionmsg2 and context[actionmsg2] on object not defined', LOG_ERR);
  134. } else {
  135. $object->actionmsg2 = $object->context['actionmsg2'];
  136. }
  137. }
  138. // Parameters $object->sendtoid defined by caller
  139. //$object->sendtoid=0;
  140. } elseif ($action == 'CONTACT_CREATE') {
  141. // Load translation files required by the page
  142. $langs->loadLangs(array("agenda", "other", "companies"));
  143. if (empty($object->actionmsg2)) {
  144. if (empty($object->context['actionmsg2'])) {
  145. $object->actionmsg2 = $langs->transnoentities("CONTACT_CREATEInDolibarr", $object->getFullName($langs));
  146. } else {
  147. $object->actionmsg2 = $object->context['actionmsg2'];
  148. }
  149. }
  150. if (empty($object->actionmsg)) {
  151. $object->actionmsg = $langs->transnoentities("CONTACT_CREATEInDolibarr", $object->getFullName($langs));
  152. }
  153. $object->sendtoid = array($object->id => $object->id);
  154. $object->socid = $object->socid;
  155. } elseif ($action == 'CONTACT_MODIFY') {
  156. // Load translation files required by the page
  157. $langs->loadLangs(array("agenda", "other", "companies"));
  158. if (empty($object->actionmsg2)) {
  159. if (empty($object->context['actionmsg2'])) {
  160. $object->actionmsg2 = $langs->transnoentities("CONTACT_MODIFYInDolibarr", $object->name);
  161. } else {
  162. $object->actionmsg2 = $object->context['actionmsg2'];
  163. }
  164. }
  165. if (empty($object->actionmsg)) {
  166. $object->actionmsg = $langs->transnoentities("CONTACT_MODIFYInDolibarr", $object->name);
  167. }
  168. $object->sendtoid = array($object->id => $object->id);
  169. $object->socid = $object->socid;
  170. } elseif ($action == 'CONTRACT_VALIDATE') {
  171. // Load translation files required by the page
  172. $langs->loadLangs(array("agenda", "other", "contracts"));
  173. if (empty($object->actionmsg2)) {
  174. if (empty($object->context['actionmsg2'])) {
  175. $object->actionmsg2 = $langs->transnoentities("ContractValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
  176. } else {
  177. $object->actionmsg2 = $object->context['actionmsg2'];
  178. }
  179. }
  180. if (empty($object->actionmsg)) {
  181. $object->actionmsg = $langs->transnoentities("ContractValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
  182. }
  183. $object->sendtoid = 0;
  184. } elseif ($action == 'CONTRACT_SENTBYMAIL') {
  185. // Load translation files required by the page
  186. $langs->loadLangs(array("agenda", "other", "contracts"));
  187. if (empty($object->actionmsg2)) {
  188. if (empty($object->context['actionmsg2'])) {
  189. $object->actionmsg2 = $langs->transnoentities("ContractSentByEMail", $object->ref);
  190. } else {
  191. $object->actionmsg2 = $object->context['actionmsg2'];
  192. }
  193. }
  194. if (empty($object->actionmsg)) {
  195. $object->actionmsg = $langs->transnoentities("ContractSentByEMail", $object->ref);
  196. }
  197. // Parameters $object->sendtoid defined by caller
  198. //$object->sendtoid=0;
  199. } elseif ($action == 'PROPAL_VALIDATE') {
  200. // Load translation files required by the page
  201. $langs->loadLangs(array("agenda", "other", "propal"));
  202. if (empty($object->actionmsg2)) {
  203. if (empty($object->context['actionmsg2'])) {
  204. $object->actionmsg2 = $langs->transnoentities("PropalValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
  205. } else {
  206. $object->actionmsg2 = $object->context['actionmsg2'];
  207. }
  208. }
  209. if (empty($object->actionmsg)) {
  210. $object->actionmsg = $langs->transnoentities("PropalValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
  211. }
  212. $object->sendtoid = 0;
  213. } elseif ($action == 'PROPAL_MODIFY') {
  214. // Load translation files required by the page
  215. $langs->loadLangs(array("agenda", "other", "propal"));
  216. if (empty($object->actionmsg2)) {
  217. if (empty($object->context['actionmsg2'])) {
  218. $object->actionmsg2 = $langs->transnoentities("PropalBackToDraftInDolibarr", ($object->newref ? $object->newref : $object->ref));
  219. } else {
  220. $object->actionmsg2 = $object->context['actionmsg2'];
  221. }
  222. }
  223. if (empty($object->actionmsg)) {
  224. $object->actionmsg = $langs->transnoentities("PropalBackToDraftInDolibarr", ($object->newref ? $object->newref : $object->ref));
  225. }
  226. $object->sendtoid = 0;
  227. } elseif ($action == 'PROPAL_SENTBYMAIL') {
  228. // Load translation files required by the page
  229. $langs->loadLangs(array("agenda", "other", "propal"));
  230. if (empty($object->actionmsg2)) {
  231. if (empty($object->context['actionmsg2'])) {
  232. $object->actionmsg2 = $langs->transnoentities("ProposalSentByEMail", $object->ref);
  233. } else {
  234. $object->actionmsg2 = $object->context['actionmsg2'];
  235. }
  236. }
  237. if (empty($object->actionmsg)) {
  238. $object->actionmsg = $langs->transnoentities("ProposalSentByEMail", $object->ref);
  239. }
  240. // Parameters $object->sendtoid defined by caller
  241. //$object->sendtoid=0;
  242. } elseif ($action == 'PROPAL_CLOSE_SIGNED') {
  243. // Load translation files required by the page
  244. $langs->loadLangs(array("agenda", "other", "propal"));
  245. if (empty($object->actionmsg2)) {
  246. if (empty($object->context['actionmsg2'])) {
  247. $object->actionmsg2 = $langs->transnoentities("PropalClosedSignedInDolibarr", $object->ref);
  248. } else {
  249. $object->actionmsg2 = $object->context['actionmsg2'];
  250. }
  251. }
  252. if (empty($object->actionmsg)) {
  253. $object->actionmsg = $langs->transnoentities("PropalClosedSignedInDolibarr", $object->ref);
  254. }
  255. $object->sendtoid = 0;
  256. } elseif ($action == 'PROPAL_CLASSIFY_BILLED') {
  257. // Load translation files required by the page
  258. $langs->loadLangs(array("agenda", "other", "propal"));
  259. if (empty($object->actionmsg2)) {
  260. if (empty($object->context['actionmsg2'])) {
  261. $object->actionmsg2 = $langs->transnoentities("PropalClassifiedBilledInDolibarr", $object->ref);
  262. } else {
  263. $object->actionmsg2 = $object->context['actionmsg2'];
  264. }
  265. }
  266. if (empty($object->actionmsg)) {
  267. $object->actionmsg = $langs->transnoentities("PropalClassifiedBilledInDolibarr", $object->ref);
  268. }
  269. $object->sendtoid = 0;
  270. } elseif ($action == 'PROPAL_CLOSE_REFUSED') {
  271. // Load translation files required by the page
  272. $langs->loadLangs(array("agenda", "other", "propal"));
  273. if (empty($object->actionmsg2)) {
  274. if (empty($object->context['actionmsg2'])) {
  275. $object->actionmsg2 = $langs->transnoentities("PropalClosedRefusedInDolibarr", $object->ref);
  276. } else {
  277. $object->actionmsg2 = $object->context['actionmsg2'];
  278. }
  279. }
  280. if (empty($object->actionmsg)) {
  281. $object->actionmsg = $langs->transnoentities("PropalClosedRefusedInDolibarr", $object->ref);
  282. }
  283. $object->sendtoid = 0;
  284. } elseif ($action == 'ORDER_VALIDATE') {
  285. // Load translation files required by the page
  286. $langs->loadLangs(array("agenda", "orders"));
  287. if (empty($object->actionmsg2)) {
  288. if (empty($object->context['actionmsg2'])) {
  289. $object->actionmsg2 = $langs->transnoentities("OrderValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
  290. } else {
  291. $object->actionmsg2 = $object->context['actionmsg2'];
  292. }
  293. }
  294. if (empty($object->actionmsg)) {
  295. $object->actionmsg = $langs->transnoentities("OrderValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
  296. }
  297. $object->sendtoid = 0;
  298. } elseif ($action == 'ORDER_CLOSE') {
  299. // Load translation files required by the page
  300. $langs->loadLangs(array("agenda", "other", "orders"));
  301. if (empty($object->actionmsg2)) {
  302. if (empty($object->context['actionmsg2'])) {
  303. $object->actionmsg2 = $langs->transnoentities("OrderDeliveredInDolibarr", $object->ref);
  304. } else {
  305. $object->actionmsg2 = $object->context['actionmsg2'];
  306. }
  307. }
  308. if (empty($object->actionmsg)) {
  309. $object->actionmsg = $langs->transnoentities("OrderDeliveredInDolibarr", $object->ref);
  310. }
  311. $object->sendtoid = 0;
  312. } elseif ($action == 'ORDER_CLASSIFY_BILLED') {
  313. // Load translation files required by the page
  314. $langs->loadLangs(array("agenda", "other", "orders"));
  315. if (empty($object->actionmsg2)) {
  316. if (empty($object->context['actionmsg2'])) {
  317. $object->actionmsg2 = $langs->transnoentities("OrderBilledInDolibarr", $object->ref);
  318. } else {
  319. $object->actionmsg2 = $object->context['actionmsg2'];
  320. }
  321. }
  322. if (empty($object->actionmsg)) {
  323. $object->actionmsg = $langs->transnoentities("OrderBilledInDolibarr", $object->ref);
  324. }
  325. $object->sendtoid = 0;
  326. } elseif ($action == 'ORDER_CANCEL') {
  327. // Load translation files required by the page
  328. $langs->loadLangs(array("agenda", "other", "orders"));
  329. if (empty($object->actionmsg2)) {
  330. if (empty($object->context['actionmsg2'])) {
  331. $object->actionmsg2 = $langs->transnoentities("OrderCanceledInDolibarr", $object->ref);
  332. } else {
  333. $object->actionmsg2 = $object->context['actionmsg2'];
  334. }
  335. }
  336. if (empty($object->actionmsg)) {
  337. $object->actionmsg = $langs->transnoentities("OrderCanceledInDolibarr", $object->ref);
  338. }
  339. $object->sendtoid = 0;
  340. } elseif ($action == 'ORDER_SENTBYMAIL') {
  341. // Load translation files required by the page
  342. $langs->loadLangs(array("agenda", "other", "orders"));
  343. if (empty($object->actionmsg2)) {
  344. if (empty($object->context['actionmsg2'])) {
  345. $object->actionmsg2 = $langs->transnoentities("OrderSentByEMail", $object->ref);
  346. } else {
  347. $object->actionmsg2 = $object->context['actionmsg2'];
  348. }
  349. }
  350. if (empty($object->actionmsg)) {
  351. $object->actionmsg = $langs->transnoentities("OrderSentByEMail", $object->ref);
  352. }
  353. // Parameters $object->sendtoid defined by caller
  354. //$object->sendtoid=0;
  355. } elseif ($action == 'BILL_VALIDATE') {
  356. // Load translation files required by the page
  357. $langs->loadLangs(array("agenda", "other", "bills"));
  358. if (empty($object->actionmsg2)) {
  359. if (empty($object->context['actionmsg2'])) {
  360. $object->actionmsg2 = $langs->transnoentities("InvoiceValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
  361. } else {
  362. $object->actionmsg2 = $object->context['actionmsg2'];
  363. }
  364. }
  365. if (empty($object->actionmsg)) {
  366. $object->actionmsg = $langs->transnoentities("InvoiceValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
  367. }
  368. $object->sendtoid = 0;
  369. } elseif ($action == 'BILL_UNVALIDATE') {
  370. // Load translation files required by the page
  371. $langs->loadLangs(array("agenda", "other", "bills"));
  372. if (empty($object->actionmsg2)) {
  373. if (empty($object->context['actionmsg2'])) {
  374. $object->actionmsg2 = $langs->transnoentities("InvoiceBackToDraftInDolibarr", $object->ref);
  375. } else {
  376. $object->actionmsg2 = $object->context['actionmsg2'];
  377. }
  378. }
  379. if (empty($object->actionmsg)) {
  380. $object->actionmsg = $langs->transnoentities("InvoiceBackToDraftInDolibarr", $object->ref);
  381. }
  382. $object->sendtoid = 0;
  383. } elseif ($action == 'BILL_SENTBYMAIL') {
  384. // Load translation files required by the page
  385. $langs->loadLangs(array("agenda", "other", "bills"));
  386. if (empty($object->actionmsg2)) {
  387. if (empty($object->context['actionmsg2'])) {
  388. $object->actionmsg2 = $langs->transnoentities("InvoiceSentByEMail", $object->ref);
  389. } else {
  390. $object->actionmsg2 = $object->context['actionmsg2'];
  391. }
  392. }
  393. if (empty($object->actionmsg)) {
  394. $object->actionmsg = $langs->transnoentities("InvoiceSentByEMail", $object->ref);
  395. }
  396. // Parameters $object->sendtoid defined by caller
  397. //$object->sendtoid=0;
  398. } elseif ($action == 'BILL_PAYED') {
  399. // Load translation files required by the page
  400. $langs->loadLangs(array("agenda", "other", "bills"));
  401. // Values for this action can't be defined by caller.
  402. if (empty($object->actionmsg2)) {
  403. if (empty($object->context['actionmsg2'])) {
  404. $object->actionmsg2 = $langs->transnoentities("InvoicePaidInDolibarr", $object->ref);
  405. } else {
  406. $object->actionmsg2 = $object->context['actionmsg2'];
  407. }
  408. }
  409. if (empty($object->actionmsg)) {
  410. $object->actionmsg = $langs->transnoentities("InvoicePaidInDolibarr", $object->ref);
  411. }
  412. $object->sendtoid = 0;
  413. } elseif ($action == 'BILL_CANCEL') {
  414. // Load translation files required by the page
  415. $langs->loadLangs(array("agenda", "other", "bills"));
  416. if (empty($object->actionmsg2)) {
  417. if (empty($object->context['actionmsg2'])) {
  418. $object->actionmsg2 = $langs->transnoentities("InvoiceCanceledInDolibarr", $object->ref);
  419. } else {
  420. $object->actionmsg2 = $object->context['actionmsg2'];
  421. }
  422. }
  423. if (empty($object->actionmsg)) {
  424. $object->actionmsg = $langs->transnoentities("InvoiceCanceledInDolibarr", $object->ref);
  425. }
  426. $object->sendtoid = 0;
  427. } elseif ($action == 'FICHINTER_CREATE') {
  428. // Load translation files required by the page
  429. $langs->loadLangs(array("agenda", "other", "interventions"));
  430. if (empty($object->actionmsg2)) {
  431. if (empty($object->context['actionmsg2'])) {
  432. $object->actionmsg2 = $langs->transnoentities("InterventionCreatedInDolibarr", $object->ref);
  433. } else {
  434. $object->actionmsg2 = $object->context['actionmsg2'];
  435. }
  436. }
  437. if (empty($object->actionmsg)) {
  438. $object->actionmsg = $langs->transnoentities("InterventionCreatedInDolibarr", $object->ref);
  439. }
  440. $object->sendtoid = 0;
  441. $object->fk_element = 0;
  442. $object->elementtype = '';
  443. } elseif ($action == 'FICHINTER_VALIDATE') {
  444. // Load translation files required by the page
  445. $langs->loadLangs(array("agenda", "other", "interventions"));
  446. if (empty($object->actionmsg2)) {
  447. if (empty($object->context['actionmsg2'])) {
  448. $object->actionmsg2 = $langs->transnoentities("InterventionValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
  449. } else {
  450. $object->actionmsg2 = $object->context['actionmsg2'];
  451. }
  452. }
  453. if (empty($object->actionmsg)) {
  454. $object->actionmsg = $langs->transnoentities("InterventionValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
  455. }
  456. $object->sendtoid = 0;
  457. $object->fk_element = 0;
  458. $object->elementtype = '';
  459. } elseif ($action == 'FICHINTER_MODIFY') {
  460. // Load translation files required by the page
  461. $langs->loadLangs(array("agenda", "other", "interventions"));
  462. if (empty($object->actionmsg2)) {
  463. if (empty($object->context['actionmsg2'])) {
  464. $object->actionmsg2 = $langs->transnoentities("InterventionModifiedInDolibarr", $object->ref);
  465. } else {
  466. $object->actionmsg2 = $object->context['actionmsg2'];
  467. }
  468. }
  469. if (empty($object->actionmsg)) {
  470. $object->actionmsg = $langs->transnoentities("InterventionModifiedInDolibarr", $object->ref);
  471. }
  472. $object->sendtoid = 0;
  473. $object->fk_element = 0;
  474. $object->elementtype = '';
  475. } elseif ($action == 'FICHINTER_SENTBYMAIL') {
  476. // Load translation files required by the page
  477. $langs->loadLangs(array("agenda", "other", "interventions"));
  478. if (empty($object->actionmsg2)) {
  479. if (empty($object->context['actionmsg2'])) {
  480. $object->actionmsg2 = $langs->transnoentities("InterventionSentByEMail", $object->ref);
  481. } else {
  482. $object->actionmsg2 = $object->context['actionmsg2'];
  483. }
  484. }
  485. if (empty($object->actionmsg)) {
  486. $object->actionmsg = $langs->transnoentities("InterventionSentByEMail", $object->ref);
  487. }
  488. // Parameters $object->sendtoid defined by caller
  489. //$object->sendtoid=0;
  490. } elseif ($action == 'FICHINTER_CLASSIFY_BILLED') {
  491. // Load translation files required by the page
  492. $langs->loadLangs(array("agenda", "other", "interventions"));
  493. if (empty($object->actionmsg2)) {
  494. if (empty($object->context['actionmsg2'])) {
  495. $object->actionmsg2 = $langs->transnoentities("InterventionClassifiedBilledInDolibarr", $object->ref);
  496. } else {
  497. $object->actionmsg2 = $object->context['actionmsg2'];
  498. }
  499. }
  500. if (empty($object->actionmsg)) {
  501. $object->actionmsg = $langs->transnoentities("InterventionClassifiedBilledInDolibarr", $object->ref);
  502. }
  503. $object->sendtoid = 0;
  504. } elseif ($action == 'FICHINTER_CLASSIFY_UNBILLED') {
  505. // Load translation files required by the page
  506. $langs->loadLangs(array("agenda", "other", "interventions"));
  507. if (empty($object->actionmsg2)) {
  508. if (empty($object->context['actionmsg2'])) {
  509. $object->actionmsg2 = $langs->transnoentities("InterventionClassifiedUnbilledInDolibarr", $object->ref);
  510. } else {
  511. $object->actionmsg2 = $object->context['actionmsg2'];
  512. }
  513. }
  514. if (empty($object->actionmsg)) {
  515. $object->actionmsg = $langs->transnoentities("InterventionClassifiedUnbilledInDolibarr", $object->ref);
  516. }
  517. $object->sendtoid = 0;
  518. } elseif ($action == 'FICHINTER_CLOSE') {
  519. // Load translation files required by the page
  520. $langs->loadLangs(array("agenda", "other", "interventions"));
  521. if (empty($object->actionmsg2)) {
  522. if (empty($object->context['actionmsg2'])) {
  523. $object->actionmsg2 = $langs->transnoentities("InterventionClosedInDolibarr", $object->ref);
  524. } else {
  525. $object->actionmsg2 = $object->context['actionmsg2'];
  526. }
  527. }
  528. if (empty($object->actionmsg)) {
  529. $object->actionmsg = $langs->transnoentities("InterventionClosedInDolibarr", $object->ref);
  530. }
  531. $object->sendtoid = 0;
  532. $object->fk_element = 0;
  533. $object->elementtype = '';
  534. } elseif ($action == 'FICHINTER_DELETE') {
  535. // Load translation files required by the page
  536. $langs->loadLangs(array("agenda", "other", "interventions"));
  537. if (empty($object->actionmsg2)) {
  538. if (empty($object->context['actionmsg2'])) {
  539. $object->actionmsg2 = $langs->transnoentities("InterventionDeletedInDolibarr", $object->ref);
  540. } else {
  541. $object->actionmsg2 = $object->context['actionmsg2'];
  542. }
  543. }
  544. if (empty($object->actionmsg)) {
  545. $object->actionmsg = $langs->transnoentities("InterventionDeletedInDolibarr", $object->ref);
  546. }
  547. $object->sendtoid = 0;
  548. $object->fk_element = 0;
  549. $object->elementtype = '';
  550. } elseif ($action == 'SHIPPING_VALIDATE') {
  551. // Load translation files required by the page
  552. $langs->loadLangs(array("agenda", "other", "sendings"));
  553. if (empty($object->actionmsg2)) {
  554. if (empty($object->context['actionmsg2'])) {
  555. $object->actionmsg2 = $langs->transnoentities("ShippingValidated", ($object->newref ? $object->newref : $object->ref));
  556. } else {
  557. $object->actionmsg2 = $object->context['actionmsg2'];
  558. }
  559. }
  560. if (empty($object->actionmsg)) {
  561. $object->actionmsg = $langs->transnoentities("ShippingValidated", ($object->newref ? $object->newref : $object->ref));
  562. }
  563. // Parameters $object->sendtoid defined by caller
  564. //$object->sendtoid=0;
  565. } elseif ($action == 'SHIPPING_SENTBYMAIL') {
  566. // Load translation files required by the page
  567. $langs->loadLangs(array("agenda", "other", "sendings"));
  568. if (empty($object->actionmsg2)) {
  569. if (empty($object->context['actionmsg2'])) {
  570. $object->actionmsg2 = $langs->transnoentities("ShippingSentByEMail", $object->ref);
  571. } else {
  572. $object->actionmsg2 = $object->context['actionmsg2'];
  573. }
  574. }
  575. if (empty($object->actionmsg)) {
  576. $object->actionmsg = $langs->transnoentities("ShippingSentByEMail", $object->ref);
  577. }
  578. // Parameters $object->sendtoid defined by caller
  579. //$object->sendtoid=0;
  580. } elseif ($action == 'RECEPTION_VALIDATE') {
  581. $langs->load("agenda");
  582. $langs->load("other");
  583. $langs->load("receptions");
  584. if (empty($object->actionmsg2)) {
  585. if (empty($object->context['actionmsg2'])) {
  586. $object->actionmsg2 = $langs->transnoentities("ReceptionValidated", ($object->newref ? $object->newref : $object->ref));
  587. } else {
  588. $object->actionmsg2 = $object->context['actionmsg2'];
  589. }
  590. }
  591. if (empty($object->actionmsg)) {
  592. $object->actionmsg = $langs->transnoentities("ReceptionValidated", ($object->newref ? $object->newref : $object->ref));
  593. }
  594. // Parameters $object->sendtoid defined by caller
  595. //$object->sendtoid=0;
  596. } elseif ($action == 'RECEPTION_SENTBYMAIL') {
  597. $langs->load("agenda");
  598. $langs->load("other");
  599. $langs->load("receptions");
  600. if (empty($object->actionmsg2)) {
  601. if (empty($object->context['actionmsg2'])) {
  602. $object->actionmsg2 = $langs->transnoentities("ReceptionSentByEMail", $object->ref);
  603. } else {
  604. $object->actionmsg2 = $object->context['actionmsg2'];
  605. }
  606. }
  607. if (empty($object->actionmsg)) {
  608. $object->actionmsg = $langs->transnoentities("ReceptionSentByEMail", $object->ref);
  609. }
  610. // Parameters $object->sendtoid defined by caller
  611. //$object->sendtoid=0;
  612. } elseif ($action == 'PROPOSAL_SUPPLIER_VALIDATE') {
  613. // Load translation files required by the page
  614. $langs->loadLangs(array("agenda", "other", "propal"));
  615. if (empty($object->actionmsg2)) {
  616. if (empty($object->context['actionmsg2'])) {
  617. $object->actionmsg2 = $langs->transnoentities("PropalValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
  618. } else {
  619. $object->actionmsg2 = $object->context['actionmsg2'];
  620. }
  621. }
  622. if (empty($object->actionmsg)) {
  623. $object->actionmsg = $langs->transnoentities("PropalValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
  624. }
  625. $object->sendtoid = 0;
  626. } elseif ($action == 'PROPOSAL_SUPPLIER_SENTBYMAIL') {
  627. // Load translation files required by the page
  628. $langs->loadLangs(array("agenda", "other", "propal"));
  629. if (empty($object->actionmsg2)) {
  630. if (empty($object->context['actionmsg2'])) {
  631. $object->actionmsg2 = $langs->transnoentities("ProposalSentByEMail", $object->ref);
  632. } else {
  633. $object->actionmsg2 = $object->context['actionmsg2'];
  634. }
  635. }
  636. if (empty($object->actionmsg)) {
  637. $object->actionmsg = $langs->transnoentities("ProposalSentByEMail", $object->ref);
  638. }
  639. // Parameters $object->sendtoid defined by caller
  640. //$object->sendtoid=0;
  641. } elseif ($action == 'PROPOSAL_SUPPLIER_CLOSE_SIGNED') {
  642. // Load translation files required by the page
  643. $langs->loadLangs(array("agenda", "other", "propal"));
  644. if (empty($object->actionmsg2)) {
  645. if (empty($object->context['actionmsg2'])) {
  646. $object->actionmsg2 = $langs->transnoentities("PropalClosedSignedInDolibarr", $object->ref);
  647. } else {
  648. $object->actionmsg2 = $object->context['actionmsg2'];
  649. }
  650. }
  651. if (empty($object->actionmsg)) {
  652. $object->actionmsg = $langs->transnoentities("PropalClosedSignedInDolibarr", $object->ref);
  653. }
  654. $object->sendtoid = 0;
  655. } elseif ($action == 'PROPOSAL_SUPPLIER_CLOSE_REFUSED') {
  656. // Load translation files required by the page
  657. $langs->loadLangs(array("agenda", "other", "propal"));
  658. if (empty($object->actionmsg2)) {
  659. if (empty($object->context['actionmsg2'])) {
  660. $object->actionmsg2 = $langs->transnoentities("PropalClosedRefusedInDolibarr", $object->ref);
  661. } else {
  662. $object->actionmsg2 = $object->context['actionmsg2'];
  663. }
  664. }
  665. if (empty($object->actionmsg)) {
  666. $object->actionmsg = $langs->transnoentities("PropalClosedRefusedInDolibarr", $object->ref);
  667. }
  668. $object->sendtoid = 0;
  669. } elseif ($action == 'ORDER_SUPPLIER_CREATE') {
  670. // Load translation files required by the page
  671. $langs->loadLangs(array("agenda", "other", "orders"));
  672. if (empty($object->actionmsg2)) {
  673. if (empty($object->context['actionmsg2'])) {
  674. $object->actionmsg2 = $langs->transnoentities("OrderCreatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
  675. } else {
  676. $object->actionmsg2 = $object->context['actionmsg2'];
  677. }
  678. }
  679. if (empty($object->actionmsg)) {
  680. $object->actionmsg = $langs->transnoentities("OrderCreatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
  681. }
  682. $object->sendtoid = 0;
  683. } elseif ($action == 'ORDER_SUPPLIER_VALIDATE') {
  684. // Load translation files required by the page
  685. $langs->loadLangs(array("agenda", "other", "orders"));
  686. if (empty($object->actionmsg2)) {
  687. if (empty($object->context['actionmsg2'])) {
  688. $object->actionmsg2 = $langs->transnoentities("OrderValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
  689. } else {
  690. $object->actionmsg2 = $object->context['actionmsg2'];
  691. }
  692. }
  693. if (empty($object->actionmsg)) {
  694. $object->actionmsg = $langs->transnoentities("OrderValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
  695. }
  696. $object->sendtoid = 0;
  697. } elseif ($action == 'ORDER_SUPPLIER_APPROVE') {
  698. // Load translation files required by the page
  699. $langs->loadLangs(array("agenda", "other", "orders"));
  700. if (empty($object->actionmsg2)) {
  701. if (empty($object->context['actionmsg2'])) {
  702. $object->actionmsg2 = $langs->transnoentities("OrderApprovedInDolibarr", $object->ref);
  703. } else {
  704. $object->actionmsg2 = $object->context['actionmsg2'];
  705. }
  706. }
  707. if (empty($object->actionmsg)) {
  708. $object->actionmsg = $langs->transnoentities("OrderApprovedInDolibarr", $object->ref);
  709. }
  710. $object->sendtoid = 0;
  711. } elseif ($action == 'ORDER_SUPPLIER_REFUSE') {
  712. // Load translation files required by the page
  713. $langs->loadLangs(array("agenda", "other", "orders", "main"));
  714. if (empty($object->actionmsg2)) {
  715. if (empty($object->context['actionmsg2'])) {
  716. $object->actionmsg2 = $langs->transnoentities("OrderRefusedInDolibarr", $object->ref);
  717. } else {
  718. $object->actionmsg2 = $object->context['actionmsg2'];
  719. }
  720. }
  721. if (empty($object->actionmsg)) {
  722. $object->actionmsg = $langs->transnoentities("OrderRefusedInDolibarr", $object->ref);
  723. }
  724. if (!empty($object->refuse_note)) {
  725. $object->actionmsg .= '<br>';
  726. $object->actionmsg .= $langs->trans("Reason") . ': '.$object->refuse_note;
  727. }
  728. $object->sendtoid = 0;
  729. } elseif ($action == 'ORDER_SUPPLIER_CANCEL') {
  730. // Load translation files required by the page
  731. $langs->loadLangs(array("agenda", "other", "orders", "main"));
  732. if (empty($object->actionmsg2)) {
  733. if (empty($object->context['actionmsg2'])) {
  734. $object->actionmsg2 = $langs->transnoentities("OrderCanceledInDolibarr", $object->ref);
  735. } else {
  736. $object->actionmsg2 = $object->context['actionmsg2'];
  737. }
  738. }
  739. if (empty($object->actionmsg)) {
  740. $object->actionmsg = $langs->transnoentities("OrderCanceledInDolibarr", $object->ref);
  741. }
  742. if (!empty($object->cancel_note)) {
  743. $object->actionmsg .= '<br>';
  744. $object->actionmsg .= $langs->trans("Reason") . ': '.$object->cancel_note;
  745. }
  746. $object->sendtoid = 0;
  747. } elseif ($action == 'ORDER_SUPPLIER_SUBMIT') {
  748. // Load translation files required by the page
  749. $langs->loadLangs(array("agenda", "other", "orders"));
  750. if (empty($object->actionmsg2)) {
  751. if (empty($object->context['actionmsg2'])) {
  752. $object->actionmsg2 = $langs->transnoentities("SupplierOrderSubmitedInDolibarr", ($object->newref ? $object->newref : $object->ref));
  753. } else {
  754. $object->actionmsg2 = $object->context['actionmsg2'];
  755. }
  756. }
  757. if (empty($object->actionmsg)) {
  758. $object->actionmsg = $langs->transnoentities("SupplierOrderSubmitedInDolibarr", ($object->newref ? $object->newref : $object->ref));
  759. }
  760. if (!empty($object->context['comments'])) {
  761. $object->actionmsg .= '<br>';
  762. $object->actionmsg .= $langs->trans("Comment") . ': '.$object->context['comments'];
  763. }
  764. $object->sendtoid = 0;
  765. } elseif ($action == 'ORDER_SUPPLIER_RECEIVE') {
  766. // Load translation files required by the page
  767. $langs->loadLangs(array("agenda", "other", "orders"));
  768. if (empty($object->actionmsg2)) {
  769. if (empty($object->context['actionmsg2'])) {
  770. $object->actionmsg2 = $langs->transnoentities("SupplierOrderReceivedInDolibarr", ($object->newref ? $object->newref : $object->ref));
  771. } else {
  772. $object->actionmsg2 = $object->context['actionmsg2'];
  773. }
  774. }
  775. if (empty($object->actionmsg)) {
  776. $object->actionmsg = $langs->transnoentities("SupplierOrderReceivedInDolibarr", ($object->newref ? $object->newref : $object->ref));
  777. }
  778. $object->sendtoid = 0;
  779. } elseif ($action == 'ORDER_SUPPLIER_SENTBYMAIL') {
  780. // Load translation files required by the page
  781. $langs->loadLangs(array("agenda", "other", "bills", "orders"));
  782. if (empty($object->actionmsg2)) {
  783. if (empty($object->context['actionmsg2'])) {
  784. $object->actionmsg2 = $langs->transnoentities("SupplierOrderSentByEMail", $object->ref);
  785. } else {
  786. $object->actionmsg2 = $object->context['actionmsg2'];
  787. }
  788. }
  789. if (empty($object->actionmsg)) {
  790. $object->actionmsg = $langs->transnoentities("SupplierOrderSentByEMail", $object->ref);
  791. }
  792. // Parameters $object->sendtoid defined by caller
  793. //$object->sendtoid=0;
  794. } elseif ($action == 'ORDER_SUPPLIER_CLASSIFY_BILLED') {
  795. // Load translation files required by the page
  796. $langs->loadLangs(array("agenda", "other", "bills", "orders"));
  797. if (empty($object->actionmsg2)) {
  798. if (empty($object->context['actionmsg2'])) {
  799. $object->actionmsg2 = $langs->transnoentities("SupplierOrderClassifiedBilled", $object->ref);
  800. } else {
  801. $object->actionmsg2 = $object->context['actionmsg2'];
  802. }
  803. }
  804. if (empty($object->actionmsg)) {
  805. $object->actionmsg = $langs->transnoentities("SupplierOrderClassifiedBilled", $object->ref);
  806. }
  807. $object->sendtoid = 0;
  808. } elseif ($action == 'BILL_SUPPLIER_VALIDATE') {
  809. // Load translation files required by the page
  810. $langs->loadLangs(array("agenda", "other", "bills"));
  811. if (empty($object->actionmsg2)) {
  812. if (empty($object->context['actionmsg2'])) {
  813. $object->actionmsg2 = $langs->transnoentities("InvoiceValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
  814. } else {
  815. $object->actionmsg2 = $object->context['actionmsg2'];
  816. }
  817. }
  818. if (empty($object->actionmsg)) {
  819. $object->actionmsg = $langs->transnoentities("InvoiceValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref));
  820. }
  821. $object->sendtoid = 0;
  822. } elseif ($action == 'BILL_SUPPLIER_UNVALIDATE') {
  823. // Load translation files required by the page
  824. $langs->loadLangs(array("agenda", "other", "bills"));
  825. if (empty($object->actionmsg2)) {
  826. if (empty($object->context['actionmsg2'])) {
  827. $object->actionmsg2 = $langs->transnoentities("InvoiceBackToDraftInDolibarr", $object->ref);
  828. } else {
  829. $object->actionmsg2 = $object->context['actionmsg2'];
  830. }
  831. }
  832. if (empty($object->actionmsg)) {
  833. $object->actionmsg = $langs->transnoentities("InvoiceBackToDraftInDolibarr", $object->ref);
  834. }
  835. $object->sendtoid = 0;
  836. } elseif ($action == 'BILL_SUPPLIER_SENTBYMAIL') {
  837. // Load translation files required by the page
  838. $langs->loadLangs(array("agenda", "other", "bills", "orders"));
  839. if (empty($object->actionmsg2)) {
  840. if (empty($object->context['actionmsg2'])) {
  841. $object->actionmsg2 = $langs->transnoentities("SupplierInvoiceSentByEMail", $object->ref);
  842. } else {
  843. $object->actionmsg2 = $object->context['actionmsg2'];
  844. }
  845. }
  846. if (empty($object->actionmsg)) {
  847. $object->actionmsg = $langs->transnoentities("SupplierInvoiceSentByEMail", $object->ref);
  848. }
  849. // Parameters $object->sendtoid defined by caller
  850. //$object->sendtoid=0;
  851. } elseif ($action == 'BILL_SUPPLIER_PAYED') {
  852. // Load translation files required by the page
  853. $langs->loadLangs(array("agenda", "other", "bills"));
  854. if (empty($object->actionmsg2)) {
  855. if (empty($object->context['actionmsg2'])) {
  856. $object->actionmsg2 = $langs->transnoentities("InvoicePaidInDolibarr", $object->ref);
  857. } else {
  858. $object->actionmsg2 = $object->context['actionmsg2'];
  859. }
  860. }
  861. if (empty($object->actionmsg)) {
  862. $object->actionmsg = $langs->transnoentities("InvoicePaidInDolibarr", $object->ref);
  863. }
  864. $object->sendtoid = 0;
  865. } elseif ($action == 'BILL_SUPPLIER_CANCELED') {
  866. // Load translation files required by the page
  867. $langs->loadLangs(array("agenda", "other", "bills"));
  868. if (empty($object->actionmsg2)) {
  869. if (empty($object->context['actionmsg2'])) {
  870. $object->actionmsg2 = $langs->transnoentities("InvoiceCanceledInDolibarr", $object->ref);
  871. } else {
  872. $object->actionmsg2 = $object->context['actionmsg2'];
  873. }
  874. }
  875. if (empty($object->actionmsg)) {
  876. $object->actionmsg = $langs->transnoentities("InvoiceCanceledInDolibarr", $object->ref);
  877. }
  878. $object->sendtoid = 0;
  879. } elseif ($action == 'MEMBER_VALIDATE') {
  880. // Members
  881. // Load translation files required by the page
  882. $langs->loadLangs(array("agenda", "other", "members"));
  883. if (empty($object->actionmsg2)) {
  884. if (empty($object->context['actionmsg2'])) {
  885. $object->actionmsg2 = $langs->transnoentities("MemberValidatedInDolibarr", $object->getFullName($langs));
  886. } else {
  887. $object->actionmsg2 = $object->context['actionmsg2'];
  888. }
  889. }
  890. if (empty($object->actionmsg)) {
  891. $object->actionmsg = $langs->transnoentities("MemberValidatedInDolibarr", $object->getFullName($langs));
  892. $object->actionmsg .= "\n".$langs->transnoentities("Member").': '.$object->getFullName($langs);
  893. $object->actionmsg .= "\n".$langs->transnoentities("Type").': '.$object->type;
  894. }
  895. $object->sendtoid = 0;
  896. } elseif ($action == 'MEMBER_MODIFY') {
  897. // Load translation files required by the page
  898. $langs->loadLangs(array("agenda", "other", "members"));
  899. if (empty($object->actionmsg2)) {
  900. if (empty($object->context['actionmsg2'])) {
  901. $object->actionmsg2 = $langs->transnoentities("MemberModifiedInDolibarr", $object->getFullName($langs));
  902. } else {
  903. $object->actionmsg2 = $object->context['actionmsg2'];
  904. }
  905. }
  906. if (empty($object->actionmsg)) {
  907. $object->actionmsg = $langs->transnoentities("MemberModifiedInDolibarr", $object->getFullName($langs));
  908. $object->actionmsg .= "\n".$langs->transnoentities("Member").': '.$object->getFullName($langs);
  909. $object->actionmsg .= "\n".$langs->transnoentities("Type").': '.$object->type;
  910. }
  911. $object->sendtoid = 0;
  912. } elseif ($action == 'MEMBER_SUBSCRIPTION_CREATE') {
  913. // Load translation files required by the page
  914. $langs->loadLangs(array("agenda", "other", "members"));
  915. $member = (isset($object->context['member']) ? $object->context['member'] : null);
  916. if (!is_object($member)) { // This should not happen
  917. dol_syslog("Execute a trigger MEMBER_SUBSCRIPTION_CREATE with context key 'member' not an object");
  918. include_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  919. $member = new Adherent($this->db);
  920. $member->fetch($object->fk_adherent);
  921. }
  922. if (empty($object->actionmsg2)) {
  923. if (empty($object->context['actionmsg2'])) {
  924. $object->actionmsg2 = $langs->transnoentities("MemberSubscriptionAddedInDolibarr", $object->id, $member->getFullName($langs));
  925. } else {
  926. $object->actionmsg2 = $object->context['actionmsg2'];
  927. }
  928. }
  929. if (empty($object->actionmsg)) {
  930. $object->actionmsg = $langs->transnoentities("MemberSubscriptionAddedInDolibarr", $object->id, $member->getFullName($langs));
  931. $object->actionmsg .= "\n".$langs->transnoentities("Member").': '.$member->getFullName($langs);
  932. $object->actionmsg .= "\n".$langs->transnoentities("Type").': '.$object->fk_type;
  933. $object->actionmsg .= "\n".$langs->transnoentities("Amount").': '.$object->amount;
  934. $object->actionmsg .= "\n".$langs->transnoentities("Period").': '.dol_print_date($object->dateh, 'day').' - '.dol_print_date($object->datef, 'day');
  935. }
  936. $object->sendtoid = 0;
  937. if (isset($object->fk_soc) && $object->fk_soc > 0) {
  938. $object->socid = $object->fk_soc;
  939. }
  940. } elseif ($action == 'MEMBER_SUBSCRIPTION_MODIFY') {
  941. // Load translation files required by the page
  942. $langs->loadLangs(array("agenda", "other", "members"));
  943. $member = $object->context['member'];
  944. if (!is_object($member)) { // This should not happen
  945. include_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  946. $member = new Adherent($this->db);
  947. $member->fetch($object->fk_adherent);
  948. }
  949. if (empty($object->actionmsg2)) {
  950. if (empty($object->context['actionmsg2'])) {
  951. $object->actionmsg2 = $langs->transnoentities("MemberSubscriptionModifiedInDolibarr", $object->id, $member->getFullName($langs));
  952. } else {
  953. $object->actionmsg2 = $object->context['actionmsg2'];
  954. }
  955. }
  956. if (empty($object->actionmsg)) {
  957. $object->actionmsg = $langs->transnoentities("MemberSubscriptionModifiedInDolibarr", $object->id, $member->getFullName($langs));
  958. $object->actionmsg .= "\n".$langs->transnoentities("Member").': '.$member->getFullName($langs);
  959. $object->actionmsg .= "\n".$langs->transnoentities("Type").': '.$object->fk_type;
  960. $object->actionmsg .= "\n".$langs->transnoentities("Amount").': '.$object->amount;
  961. $object->actionmsg .= "\n".$langs->transnoentities("Period").': '.dol_print_date($object->dateh, 'day').' - '.dol_print_date($object->datef, 'day');
  962. }
  963. $object->sendtoid = 0;
  964. if ($object->fk_soc > 0) {
  965. $object->socid = $object->fk_soc;
  966. }
  967. } elseif ($action == 'MEMBER_SUBSCRIPTION_DELETE') {
  968. // Load translation files required by the page
  969. $langs->loadLangs(array("agenda", "other", "members"));
  970. $member = $object->context['member'];
  971. if (!is_object($member)) { // This should not happen but it happen when deleting a subscription from adherents/subscription/card.php
  972. dol_syslog("Execute a trigger MEMBER_SUBSCRIPTION_CREATE with context key 'member' not an object");
  973. include_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  974. $member = new Adherent($this->db);
  975. $member->fetch($object->fk_adherent);
  976. }
  977. if (empty($object->actionmsg2)) {
  978. if (empty($object->context['actionmsg2'])) {
  979. $object->actionmsg2 = $langs->transnoentities("MemberSubscriptionDeletedInDolibarr", $object->ref, $member->getFullName($langs));
  980. } else {
  981. $object->actionmsg2 = $object->context['actionmsg2'];
  982. }
  983. }
  984. if (empty($object->actionmsg)) {
  985. $object->actionmsg = $langs->transnoentities("MemberSubscriptionDeletedInDolibarr", $object->ref, $member->getFullName($langs));
  986. $object->actionmsg .= "\n".$langs->transnoentities("Member").': '.$member->getFullName($langs);
  987. $object->actionmsg .= "\n".$langs->transnoentities("Type").': '.$object->fk_type;
  988. $object->actionmsg .= "\n".$langs->transnoentities("Amount").': '.$object->amount;
  989. $object->actionmsg .= "\n".$langs->transnoentities("Period").': '.dol_print_date($object->dateh, 'day').' - '.dol_print_date($object->datef, 'day');
  990. }
  991. $object->sendtoid = 0;
  992. if (isset($object->fk_soc) && $object->fk_soc > 0) {
  993. $object->socid = $object->fk_soc;
  994. }
  995. } elseif ($action == 'MEMBER_RESILIATE') {
  996. // Load translation files required by the page
  997. $langs->loadLangs(array("agenda", "other", "members"));
  998. if (empty($object->actionmsg2)) {
  999. if (empty($object->context['actionmsg2'])) {
  1000. $object->actionmsg2 = $langs->transnoentities("MemberResiliatedInDolibarr", $object->getFullName($langs));
  1001. } else {
  1002. $object->actionmsg2 = $object->context['actionmsg2'];
  1003. }
  1004. }
  1005. if (empty($object->actionmsg)) {
  1006. $object->actionmsg = $langs->transnoentities("MemberResiliatedInDolibarr", $object->getFullName($langs));
  1007. $object->actionmsg .= "\n".$langs->transnoentities("Member").': '.$object->getFullName($langs);
  1008. $object->actionmsg .= "\n".$langs->transnoentities("Type").': '.$object->type;
  1009. }
  1010. $object->sendtoid = 0;
  1011. } elseif ($action == 'MEMBER_DELETE') {
  1012. // Load translation files required by the page
  1013. $langs->loadLangs(array("agenda", "other", "members"));
  1014. if (empty($object->actionmsg2)) {
  1015. if (empty($object->context['actionmsg2'])) {
  1016. $object->actionmsg2 = $langs->transnoentities("MemberDeletedInDolibarr", $object->getFullName($langs));
  1017. } else {
  1018. $object->actionmsg2 = $object->context['actionmsg2'];
  1019. }
  1020. }
  1021. if (empty($object->actionmsg)) {
  1022. $object->actionmsg = $langs->transnoentities("MemberDeletedInDolibarr", $object->getFullName($langs));
  1023. $object->actionmsg .= "\n".$langs->transnoentities("Member").': '.$object->getFullName($langs);
  1024. $object->actionmsg .= "\n".$langs->transnoentities("Type").': '.$object->type;
  1025. }
  1026. $object->sendtoid = 0;
  1027. } elseif ($action == 'MEMBER_EXCLUDE') {
  1028. // Load translation files required by the page
  1029. $langs->loadLangs(array("agenda", "other", "members"));
  1030. if (empty($object->actionmsg2)) {
  1031. if (empty($object->context['actionmsg2'])) {
  1032. $object->actionmsg2 = $langs->transnoentities("MemberExcludedInDolibarr", $object->getFullName($langs));
  1033. } else {
  1034. $object->actionmsg2 = $object->context['actionmsg2'];
  1035. }
  1036. }
  1037. if (empty($object->actionmsg)) {
  1038. $object->actionmsg = $langs->transnoentities("MemberExcludedInDolibarr", $object->getFullName($langs));
  1039. $object->actionmsg .= "\n".$langs->transnoentities("Member").': '.$object->getFullName($langs);
  1040. $object->actionmsg .= "\n".$langs->transnoentities("Type").': '.$object->type;
  1041. }
  1042. $object->sendtoid = 0;
  1043. } elseif ($action == 'PROJECT_CREATE') {
  1044. // Projects
  1045. // Load translation files required by the page
  1046. $langs->loadLangs(array("agenda", "other", "projects"));
  1047. if (empty($object->actionmsg2)) {
  1048. if (empty($object->context['actionmsg2'])) {
  1049. $object->actionmsg2 = $langs->transnoentities("ProjectCreatedInDolibarr", $object->ref);
  1050. } else {
  1051. $object->actionmsg2 = $object->context['actionmsg2'];
  1052. }
  1053. }
  1054. if (empty($object->actionmsg)) {
  1055. $object->actionmsg = $langs->transnoentities("ProjectCreatedInDolibarr", $object->ref);
  1056. $object->actionmsg .= "\n".$langs->transnoentities("Project").': '.$object->ref;
  1057. }
  1058. $object->sendtoid = 0;
  1059. } elseif ($action == 'PROJECT_VALIDATE') {
  1060. // Load translation files required by the page
  1061. $langs->loadLangs(array("agenda", "other", "projects"));
  1062. if (empty($object->actionmsg2)) {
  1063. if (empty($object->context['actionmsg2'])) {
  1064. $object->actionmsg2 = $langs->transnoentities("ProjectValidatedInDolibarr", $object->ref);
  1065. } else {
  1066. $object->actionmsg2 = $object->context['actionmsg2'];
  1067. }
  1068. }
  1069. if (empty($object->actionmsg)) {
  1070. $object->actionmsg = $langs->transnoentities("ProjectValidatedInDolibarr", $object->ref);
  1071. $object->actionmsg .= "\n".$langs->transnoentities("Project").': '.$object->ref;
  1072. }
  1073. $object->sendtoid = 0;
  1074. } elseif ($action == 'PROJECT_MODIFY') {
  1075. // Load translation files required by the page
  1076. $langs->loadLangs(array("agenda", "other", "projects"));
  1077. if (empty($object->actionmsg2)) {
  1078. if (empty($object->context['actionmsg2'])) {
  1079. $object->actionmsg2 = $langs->transnoentities("ProjectModifiedInDolibarr", $object->ref);
  1080. } else {
  1081. $object->actionmsg2 = $object->context['actionmsg2'];
  1082. }
  1083. }
  1084. if (empty($object->actionmsg)) {
  1085. $object->actionmsg = $langs->transnoentities("ProjectModifiedInDolibarr", $object->ref);
  1086. }
  1087. //$object->actionmsg .= "\n".$langs->transnoentities("Task").': ???';
  1088. if (!empty($object->usage_opportunity) && is_object($object->oldcopy) && $object->opp_status != $object->oldcopy->opp_status) {
  1089. $object->actionmsg .= "\n".$langs->transnoentitiesnoconv("OpportunityStatus").': '.$object->oldcopy->opp_status.' -> '.$object->opp_status;
  1090. }
  1091. $object->sendtoid = 0;
  1092. } elseif ($action == 'PROJECT_SENTBYMAIL') {
  1093. // Load translation files required by the page
  1094. $langs->loadLangs(array("agenda", "other", "projects"));
  1095. if (empty($object->actionmsg2)) {
  1096. if (empty($object->context['actionmsg2'])) {
  1097. $object->actionmsg2 = $langs->transnoentities("ProjectSentByEMail", $object->ref);
  1098. } else {
  1099. $object->actionmsg2 = $object->context['actionmsg2'];
  1100. }
  1101. }
  1102. if (empty($object->actionmsg)) {
  1103. $object->actionmsg = $langs->transnoentities("ProjectSentByEMail", $object->ref);
  1104. }
  1105. // Parameters $object->sendtoid defined by caller
  1106. //$object->sendtoid=0;
  1107. } elseif ($action == 'PROJECT_DELETE') {
  1108. // Load translation files required by the page
  1109. $langs->loadLangs(array("agenda", "other", "projects"));
  1110. if (empty($object->actionmsg2)) {
  1111. $object->actionmsg2 = $langs->transnoentities("ProjectDeletedInDolibarr", $object->ref);
  1112. }
  1113. $object->actionmsg = $langs->transnoentities("ProjectDeletedInDolibarr", $object->ref);
  1114. $object->sendtoid = 0;
  1115. } elseif ($action == 'PROJECT_CLOSE') {
  1116. // Load translation files required by the page
  1117. $langs->loadLangs(array("agenda", "other", "projects"));
  1118. if (empty($object->actionmsg2)) {
  1119. if (empty($object->context['actionmsg2'])) {
  1120. $object->actionmsg2 = $langs->transnoentities("ProjectClosedInDolibarr", $object->ref);
  1121. } else {
  1122. $object->actionmsg2 = $object->context['actionmsg2'];
  1123. }
  1124. }
  1125. if (empty($object->actionmsg)) {
  1126. $object->actionmsg = $langs->transnoentities("ProjectClosedInDolibarr", $object->ref);
  1127. }
  1128. $object->sendtoid = 0;
  1129. } elseif ($action == 'TASK_CREATE') {
  1130. // Project tasks
  1131. // Load translation files required by the page
  1132. $langs->loadLangs(array("agenda", "other", "projects"));
  1133. if (empty($object->actionmsg2)) {
  1134. if (empty($object->context['actionmsg2'])) {
  1135. $object->actionmsg2 = $langs->transnoentities("TaskCreatedInDolibarr", $object->ref);
  1136. } else {
  1137. $object->actionmsg2 = $object->context['actionmsg2'];
  1138. }
  1139. }
  1140. if (empty($object->actionmsg)) {
  1141. $object->actionmsg = $langs->transnoentities("TaskCreatedInDolibarr", $object->ref);
  1142. $object->actionmsg .= "\n".$langs->transnoentities("Task").': '.$object->ref;
  1143. }
  1144. $object->sendtoid = 0;
  1145. } elseif ($action == 'TASK_MODIFY') {
  1146. // Load translation files required by the page
  1147. $langs->loadLangs(array("agenda", "other", "projects"));
  1148. if (empty($object->actionmsg2)) {
  1149. if (empty($object->context['actionmsg2'])) {
  1150. $object->actionmsg2 = $langs->transnoentities("TaskModifiedInDolibarr", $object->ref);
  1151. } else {
  1152. $object->actionmsg2 = $object->context['actionmsg2'];
  1153. }
  1154. }
  1155. if (empty($object->actionmsg)) {
  1156. $object->actionmsg = $langs->transnoentities("TaskModifieddInDolibarr", $object->ref);
  1157. $object->actionmsg .= "\n".$langs->transnoentities("Task").': '.$object->ref;
  1158. }
  1159. $object->sendtoid = 0;
  1160. } elseif ($action == 'TASK_DELETE') {
  1161. // Load translation files required by the page
  1162. $langs->loadLangs(array("agenda", "other", "projects"));
  1163. if (empty($object->actionmsg2)) {
  1164. if (empty($object->context['actionmsg2'])) {
  1165. $object->actionmsg2 = $langs->transnoentities("TaskDeletedInDolibarr", $object->ref);
  1166. } else {
  1167. $object->actionmsg2 = $object->context['actionmsg2'];
  1168. }
  1169. }
  1170. if (empty($object->actionmsg)) {
  1171. $object->actionmsg = $langs->transnoentities("TaskDeletedInDolibarr", $object->ref);
  1172. $object->actionmsg .= "\n".$langs->transnoentities("Task").': '.$object->ref;
  1173. }
  1174. $object->sendtoid = 0;
  1175. } elseif ($action == 'TICKET_ASSIGNED') {
  1176. // Load translation files required by the page
  1177. $langs->loadLangs(array("agenda", "other", "projects"));
  1178. if (empty($object->actionmsg2)) {
  1179. if (empty($object->context['actionmsg2'])) {
  1180. $object->actionmsg2 = $langs->transnoentities("TICKET_ASSIGNEDInDolibarr", $object->ref);
  1181. } else {
  1182. $object->actionmsg2 = $object->context['actionmsg2'];
  1183. }
  1184. }
  1185. if (empty($object->actionmsg)) {
  1186. $object->actionmsg = $langs->transnoentities("TICKET_ASSIGNEDInDolibarr", $object->ref);
  1187. }
  1188. if ($object->oldcopy->fk_user_assign > 0) {
  1189. $tmpuser = new User($this->db);
  1190. $tmpuser->fetch($object->oldcopy->fk_user_assign);
  1191. $object->actionmsg .= "\n".$langs->transnoentities("OldUser").': '.$tmpuser->getFullName($langs);
  1192. } else {
  1193. $object->actionmsg .= "\n".$langs->transnoentities("OldUser").': '.$langs->trans("None");
  1194. }
  1195. if ($object->fk_user_assign > 0) {
  1196. $tmpuser = new User($this->db);
  1197. $tmpuser->fetch($object->fk_user_assign);
  1198. $object->actionmsg .= "\n".$langs->transnoentities("NewUser").': '.$tmpuser->getFullName($langs);
  1199. } else {
  1200. $object->actionmsg .= "\n".$langs->transnoentities("NewUser").': '.$langs->trans("None");
  1201. }
  1202. $object->sendtoid = 0;
  1203. } else {
  1204. // TODO Merge all previous cases into this generic one
  1205. // $action = PASSWORD, BILL_DELETE, TICKET_CREATE, TICKET_MODIFY, TICKET_DELETE, CONTACT_SENTBYMAIL, RECRUITMENTCANDIDATURE_MODIFY, ...
  1206. // Can also be a value defined by an external module like SENTBYSMS, COMPANY_SENTBYSMS, MEMBER_SENTBYSMS, ...
  1207. // Note: We are here only if $conf->global->MAIN_AGENDA_ACTIONAUTO_action is on (tested at begining of this function).
  1208. // Note that these key can be set in agenda setup, only if defined into llx_c_action_trigger
  1209. if (!empty($object->context['actionmsg']) && empty($object->actionmsg)) { // For description
  1210. $object->actionmsg = $object->context['actionmsg'];
  1211. }
  1212. if (!empty($object->context['actionmsg2']) && empty($object->actionmsg2)) { // For label
  1213. $object->actionmsg2 = $object->context['actionmsg2'];
  1214. }
  1215. if (empty($object->actionmsg2)) {
  1216. // Load translation files required by the page
  1217. $langs->loadLangs(array("agenda", "other"));
  1218. if ($langs->transnoentities($action."InDolibarr", (empty($object->newref) ? $object->ref : $object->newref)) != $action."InDolibarr") { // specific translation key
  1219. $object->actionmsg2 = $langs->transnoentities($action."InDolibarr", (empty($object->newref) ? $object->ref : $object->newref));
  1220. } else { // generic translation key
  1221. $tmp = explode('_', $action);
  1222. $object->actionmsg2 = $langs->transnoentities($tmp[count($tmp) - 1]."InDolibarr", (empty($object->newref) ? $object->ref : $object->newref));
  1223. }
  1224. }
  1225. if (empty($object->actionmsg)) {
  1226. // Load translation files required by the page
  1227. $langs->loadLangs(array("agenda", "other"));
  1228. if ($langs->transnoentities($action."InDolibarr", (empty($object->newref) ? $object->ref : $object->newref)) != $action."InDolibarr") { // specific translation key
  1229. $object->actionmsg = $langs->transnoentities($action."InDolibarr", (empty($object->newref) ? $object->ref : $object->newref));
  1230. } else { // generic translation key
  1231. $tmp = explode('_', $action);
  1232. $object->actionmsg = $langs->transnoentities($tmp[count($tmp) - 1]."InDolibarr", (empty($object->newref) ? $object->ref : $object->newref));
  1233. }
  1234. if (isModEnabled('multicompany') && property_exists($object, 'entity') && $object->entity > 1) {
  1235. $object->actionmsg .= ' ('.$langs->trans("Entity").' '.$object->entity.')';
  1236. }
  1237. }
  1238. if (!isset($object->sendtoid) || !is_array($object->sendtoid)) {
  1239. $object->sendtoid = 0;
  1240. }
  1241. }
  1242. // If trackid is not defined, we set it.
  1243. // Note that it should be set by caller. This is for compatibility purpose only.
  1244. if (empty($object->trackid)) {
  1245. // See also similar list into emailcollector.class.php
  1246. if (preg_match('/^COMPANY_/', $action)) {
  1247. $object->trackid = 'thi'.$object->id;
  1248. } elseif (preg_match('/^CONTACT_/', $action)) {
  1249. $object->trackid = 'ctc'.$object->id;
  1250. } elseif (preg_match('/^CONTRACT_/', $action)) {
  1251. $object->trackid = 'con'.$object->id;
  1252. } elseif (preg_match('/^PROPAL_/', $action)) {
  1253. $object->trackid = 'pro'.$object->id;
  1254. } elseif (preg_match('/^ORDER_/', $action)) {
  1255. $object->trackid = 'ord'.$object->id;
  1256. } elseif (preg_match('/^BILL_/', $action)) {
  1257. $object->trackid = 'inv'.$object->id;
  1258. } elseif (preg_match('/^FICHINTER_/', $action)) {
  1259. $object->trackid = 'int'.$object->id;
  1260. } elseif (preg_match('/^SHIPPING_/', $action)) {
  1261. $object->trackid = 'shi'.$object->id;
  1262. } elseif (preg_match('/^RECEPTION_/', $action)) {
  1263. $object->trackid = 'rec'.$object->id;
  1264. } elseif (preg_match('/^PROPOSAL_SUPPLIER/', $action)) {
  1265. $object->trackid = 'spr'.$object->id;
  1266. } elseif (preg_match('/^ORDER_SUPPLIER_/', $action)) {
  1267. $object->trackid = 'sor'.$object->id;
  1268. } elseif (preg_match('/^BILL_SUPPLIER_/', $action)) {
  1269. $object->trackid = 'sin'.$object->id;
  1270. } elseif (preg_match('/^MEMBER_SUBSCRIPTION_/', $action)) {
  1271. $object->trackid = 'sub'.$object->id;
  1272. } elseif (preg_match('/^MEMBER_/', $action)) {
  1273. $object->trackid = 'mem'.$object->id;
  1274. } elseif (preg_match('/^PARTNERSHIP_/', $action)) {
  1275. $object->trackid = 'pship'.$object->id;
  1276. } elseif (preg_match('/^PROJECT_/', $action)) {
  1277. $object->trackid = 'proj'.$object->id;
  1278. } elseif (preg_match('/^TASK_/', $action)) {
  1279. $object->trackid = 'tas'.$object->id;
  1280. } elseif (preg_match('/^TICKET_/', $action)) {
  1281. $object->trackid = 'tic'.$object->id;
  1282. } elseif (preg_match('/^USER_/', $action)) {
  1283. $object->trackid = 'use'.$object->id;
  1284. } else {
  1285. $object->trackid = '';
  1286. }
  1287. }
  1288. dol_syslog("Trigger '".$this->name."' for action '".$action."' launched by ".__FILE__.". id=".$object->id);
  1289. // Add entry in event table
  1290. $now = dol_now();
  1291. if (isset($_SESSION['listofnames-'.$object->trackid])) {
  1292. $attachs = $_SESSION['listofnames-'.$object->trackid];
  1293. if ($attachs && strpos($action, 'SENTBYMAIL')) {
  1294. $object->actionmsg = dol_concatdesc($object->actionmsg, "\n".$langs->transnoentities("AttachedFiles").': '.$attachs);
  1295. }
  1296. }
  1297. $societeforactionid = 0;
  1298. $contactforactionid = 0;
  1299. // Set $contactforactionid
  1300. if (is_array($object->sendtoid)) {
  1301. if (count($object->sendtoid) == 1) {
  1302. $contactforactionid = reset($object->sendtoid);
  1303. }
  1304. } else {
  1305. if ($object->sendtoid > 0) {
  1306. $contactforactionid = $object->sendtoid;
  1307. }
  1308. }
  1309. // Set $societeforactionid
  1310. if (isset($object->socid) && $object->socid > 0) {
  1311. $societeforactionid = $object->socid;
  1312. } elseif (isset($object->fk_soc) && $object->fk_soc > 0) {
  1313. $societeforactionid = $object->fk_soc;
  1314. } elseif (isset($object->thirdparty) && isset($object->thirdparty->id) && $object->thirdparty->id > 0) {
  1315. $societeforactionid = $object->thirdparty->id;
  1316. }
  1317. $projectid = isset($object->fk_project) ? $object->fk_project : 0;
  1318. if ($object->element == 'project') {
  1319. $projectid = $object->id;
  1320. }
  1321. $elementid = $object->id; // id of object
  1322. $elementtype = $object->element;
  1323. $elementmodule = (empty($object->module) ? '' : $object->module);
  1324. if ($object->element == 'subscription') {
  1325. $elementid = $object->fk_adherent;
  1326. $elementtype = 'member';
  1327. }
  1328. //var_dump($societeforaction);var_dump($contactforaction);var_dump($elementid);var_dump($elementtype);exit;
  1329. // Insertion action
  1330. require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
  1331. $actioncomm = new ActionComm($this->db);
  1332. $actioncomm->type_code = $object->actiontypecode; // Type of event ('AC_OTH', 'AC_OTH_AUTO', 'AC_XXX'...)
  1333. $actioncomm->code = 'AC_'.$action;
  1334. $actioncomm->label = $object->actionmsg2; // Label of event
  1335. $actioncomm->note_private = $object->actionmsg; // Description
  1336. $actioncomm->fk_project = $projectid;
  1337. $actioncomm->datep = $now;
  1338. $actioncomm->datef = $now;
  1339. $actioncomm->durationp = 0;
  1340. $actioncomm->percentage = -1; // Not applicable
  1341. $actioncomm->socid = $societeforactionid;
  1342. $actioncomm->contact_id = $contactforactionid; // deprecated, now managed by setting $actioncomm->socpeopleassigned later
  1343. $actioncomm->authorid = $user->id; // User saving action
  1344. $actioncomm->userownerid = $user->id; // Owner of action
  1345. // 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)
  1346. if (!property_exists($object, 'email_fields_no_propagate_in_actioncomm') || empty($object->email_fields_no_propagate_in_actioncomm)) {
  1347. $actioncomm->email_msgid = empty($object->email_msgid) ? null : $object->email_msgid;
  1348. $actioncomm->email_from = empty($object->email_from) ? null : $object->email_from;
  1349. $actioncomm->email_sender = empty($object->email_sender) ? null : $object->email_sender;
  1350. $actioncomm->email_to = empty($object->email_to) ? null : $object->email_to;
  1351. $actioncomm->email_tocc = empty($object->email_tocc) ? null : $object->email_tocc;
  1352. $actioncomm->email_tobcc = empty($object->email_tobcc) ? null : $object->email_tobcc;
  1353. $actioncomm->email_subject = empty($object->email_subject) ? null : $object->email_subject;
  1354. $actioncomm->errors_to = empty($object->errors_to) ? null : $object->errors_to;
  1355. }
  1356. // Object linked (if link is for thirdparty, contact or project, it is a recording error. We should not have links in link table
  1357. // for such objects because there is already a dedicated field into table llx_actioncomm or llx_actioncomm_resources.
  1358. if (!in_array($elementtype, array('societe', 'contact', 'project'))) {
  1359. $actioncomm->fk_element = $elementid;
  1360. $actioncomm->elementtype = $elementtype.($elementmodule ? '@'.$elementmodule : '');
  1361. }
  1362. if (property_exists($object, 'attachedfiles') && is_array($object->attachedfiles) && count($object->attachedfiles) > 0) {
  1363. $actioncomm->attachedfiles = $object->attachedfiles;
  1364. }
  1365. if (property_exists($object, 'sendtouserid') && is_array($object->sendtouserid) && count($object->sendtouserid) > 0) {
  1366. $actioncomm->userassigned = $object->sendtouserid;
  1367. }
  1368. if (property_exists($object, 'sendtoid') && is_array($object->sendtoid) && count($object->sendtoid) > 0) {
  1369. foreach ($object->sendtoid as $val) {
  1370. $actioncomm->socpeopleassigned[$val] = $val;
  1371. }
  1372. }
  1373. $ret = $actioncomm->create($user); // User creating action
  1374. if ($ret > 0 && getDolGlobalString('MAIN_COPY_FILE_IN_EVENT_AUTO')) {
  1375. if (property_exists($object, 'attachedfiles') && is_array($object->attachedfiles) && array_key_exists('paths', $object->attachedfiles) && count($object->attachedfiles['paths']) > 0) {
  1376. foreach ($object->attachedfiles['paths'] as $key => $filespath) {
  1377. $srcfile = $filespath;
  1378. $destdir = $conf->agenda->dir_output.'/'.$ret;
  1379. $destfile = $destdir.'/'.$object->attachedfiles['names'][$key];
  1380. if (dol_mkdir($destdir) >= 0) {
  1381. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  1382. dol_copy($srcfile, $destfile);
  1383. }
  1384. }
  1385. }
  1386. }
  1387. // Reset value set by caller
  1388. unset($object->context['actionmsg']);
  1389. unset($object->context['actionmsg2']);
  1390. unset($object->actionmsg);
  1391. unset($object->actionmsg2);
  1392. unset($object->actiontypecode); // When several action are called on same object, we must be sure to not reuse value of first action.
  1393. if ($ret > 0) {
  1394. $_SESSION['LAST_ACTION_CREATED'] = $ret;
  1395. return 1;
  1396. } else {
  1397. $this->error = "Failed to insert event : ".$actioncomm->error." ".join(',', $actioncomm->errors);
  1398. $this->errors = $actioncomm->errors;
  1399. dol_syslog("interface_modAgenda_ActionsAuto.class.php: ".$this->error, LOG_ERR);
  1400. return -1;
  1401. }
  1402. }
  1403. }