interface_50_modAgenda_ActionsAuto.class.php 51 KB

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