interface_50_modAgenda_ActionsAuto.class.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. <?php
  2. /* Copyright (C) 2005-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2009-2011 Regis Houssin <regis.houssin@capnetworks.com>
  4. * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
  5. * Copyright (C) 2013 Cedric GROSS <c.gross@kreiz-it.fr>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php
  22. * \ingroup agenda
  23. * \brief Trigger file for agenda module
  24. */
  25. /**
  26. * Class of triggered functions for agenda module
  27. */
  28. class InterfaceActionsAuto
  29. {
  30. var $db;
  31. var $error;
  32. var $date;
  33. var $duree;
  34. var $texte;
  35. var $desc;
  36. /**
  37. * Constructor
  38. *
  39. * @param DoliDB $db Database handler
  40. */
  41. 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. $this->version = 'dolibarr'; // 'experimental' or 'dolibarr' or version
  48. $this->picto = 'action';
  49. }
  50. /**
  51. * Return name of trigger file
  52. *
  53. * @return string Name of trigger file
  54. */
  55. function getName()
  56. {
  57. return $this->name;
  58. }
  59. /**
  60. * Return description of trigger file
  61. *
  62. * @return string Description of trigger file
  63. */
  64. function getDesc()
  65. {
  66. return $this->description;
  67. }
  68. /**
  69. * Return version of trigger file
  70. *
  71. * @return string Version of trigger file
  72. */
  73. function getVersion()
  74. {
  75. global $langs;
  76. $langs->load("admin");
  77. if ($this->version == 'experimental') return $langs->trans("Experimental");
  78. elseif ($this->version == 'dolibarr') return DOL_VERSION;
  79. elseif ($this->version) return $this->version;
  80. else return $langs->trans("Unknown");
  81. }
  82. /**
  83. * Function called when a Dolibarrr business event is done.
  84. * All functions "run_trigger" are triggered if file is inside directory htdocs/core/triggers
  85. *
  86. * Following properties must be filled:
  87. * $object->actiontypecode (translation action code: AC_OTH, ...)
  88. * $object->actionmsg (note, long text)
  89. * $object->actionmsg2 (label, short text)
  90. * $object->sendtoid (id of contact)
  91. * $object->socid
  92. * Optionnal:
  93. * $object->fk_element
  94. * $object->elementtype
  95. *
  96. * @param string $action Event action code
  97. * @param Object $object Object
  98. * @param User $user Object user
  99. * @param Translate $langs Object langs
  100. * @param conf $conf Object conf
  101. * @return int <0 if KO, 0 if no triggered ran, >0 if OK
  102. */
  103. function run_trigger($action,$object,$user,$langs,$conf)
  104. {
  105. $key='MAIN_AGENDA_ACTIONAUTO_'.$action;
  106. //dol_syslog("xxxxxxxxxxx".$key);
  107. if (empty($conf->agenda->enabled)) return 0; // Module not active, we do nothing
  108. if (empty($conf->global->$key)) return 0; // Log events not enabled for this action
  109. $ok=0;
  110. // Actions
  111. if ($action == 'COMPANY_CREATE')
  112. {
  113. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  114. $langs->load("other");
  115. $langs->load("agenda");
  116. $object->actiontypecode='AC_OTH_AUTO';
  117. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("NewCompanyToDolibarr",$object->nom);
  118. $object->actionmsg=$langs->transnoentities("NewCompanyToDolibarr",$object->nom);
  119. if ($object->prefix) $object->actionmsg.=" (".$object->prefix.")";
  120. //$this->desc.="\n".$langs->transnoentities("Customer").': '.yn($object->client);
  121. //$this->desc.="\n".$langs->transnoentities("Supplier").': '.yn($object->fournisseur);
  122. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  123. $object->sendtoid=0;
  124. $object->socid=$object->id;
  125. $ok=1;
  126. }
  127. elseif ($action == 'CONTRACT_VALIDATE')
  128. {
  129. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  130. $langs->load("other");
  131. $langs->load("contracts");
  132. $langs->load("agenda");
  133. $object->actiontypecode='AC_OTH_AUTO';
  134. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ContractValidatedInDolibarr",$object->ref);
  135. $object->actionmsg=$langs->transnoentities("ContractValidatedInDolibarr",$object->ref);
  136. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  137. $object->sendtoid=0;
  138. $ok=1;
  139. }
  140. elseif ($action == 'PROPAL_VALIDATE')
  141. {
  142. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  143. $langs->load("propal");
  144. $langs->load("agenda");
  145. $object->actiontypecode='AC_OTH_AUTO';
  146. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("PropalValidatedInDolibarr",$object->ref);
  147. $object->actionmsg=$langs->transnoentities("PropalValidatedInDolibarr",$object->ref);
  148. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  149. $object->sendtoid=0;
  150. $ok=1;
  151. }
  152. elseif ($action == 'PROPAL_SENTBYMAIL')
  153. {
  154. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  155. $langs->load("propal");
  156. $langs->load("agenda");
  157. $object->actiontypecode='AC_OTH_AUTO';
  158. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ProposalSentByEMail",$object->ref);
  159. if (empty($object->actionmsg))
  160. {
  161. $object->actionmsg=$langs->transnoentities("ProposalSentByEMail",$object->ref);
  162. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  163. }
  164. // Parameters $object->sendtoid defined by caller
  165. //$object->sendtoid=0;
  166. $ok=1;
  167. }
  168. elseif ($action == 'PROPAL_CLOSE_SIGNED')
  169. {
  170. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  171. $langs->load("propal");
  172. $langs->load("agenda");
  173. $object->actiontypecode='AC_OTH_AUTO';
  174. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("PropalClosedSignedInDolibarr",$object->ref);
  175. $object->actionmsg=$langs->transnoentities("PropalClosedSignedInDolibarr",$object->ref);
  176. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  177. $object->sendtoid=0;
  178. $ok=1;
  179. }
  180. elseif ($action == 'PROPAL_CLOSE_REFUSED')
  181. {
  182. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  183. $langs->load("propal");
  184. $langs->load("agenda");
  185. $object->actiontypecode='AC_OTH_AUTO';
  186. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("PropalClosedRefusedInDolibarr",$object->ref);
  187. $object->actionmsg=$langs->transnoentities("PropalClosedRefusedInDolibarr",$object->ref);
  188. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  189. $object->sendtoid=0;
  190. $ok=1;
  191. }
  192. elseif ($action == 'ORDER_VALIDATE')
  193. {
  194. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  195. $langs->load("orders");
  196. $langs->load("agenda");
  197. $object->actiontypecode='AC_OTH_AUTO';
  198. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderValidatedInDolibarr",$object->ref);
  199. $object->actionmsg=$langs->transnoentities("OrderValidatedInDolibarr",$object->ref);
  200. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  201. $object->sendtoid=0;
  202. $ok=1;
  203. }
  204. elseif ($action == 'ORDER_SENTBYMAIL')
  205. {
  206. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  207. $langs->load("orders");
  208. $langs->load("agenda");
  209. $object->actiontypecode='AC_OTH_AUTO';
  210. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderSentByEMail",$object->ref);
  211. if (empty($object->actionmsg))
  212. {
  213. $object->actionmsg=$langs->transnoentities("OrderSentByEMail",$object->ref);
  214. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  215. }
  216. // Parameters $object->sendtoid defined by caller
  217. //$object->sendtoid=0;
  218. $ok=1;
  219. }
  220. elseif ($action == 'BILL_VALIDATE')
  221. {
  222. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  223. $langs->load("other");
  224. $langs->load("bills");
  225. $langs->load("agenda");
  226. $object->actiontypecode='AC_OTH_AUTO';
  227. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceValidatedInDolibarr",$object->ref);
  228. $object->actionmsg=$langs->transnoentities("InvoiceValidatedInDolibarr",$object->ref);
  229. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  230. $object->sendtoid=0;
  231. $ok=1;
  232. }
  233. elseif ($action == 'BILL_UNVALIDATE')
  234. {
  235. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  236. $langs->load("other");
  237. $langs->load("bills");
  238. $langs->load("agenda");
  239. $object->actiontypecode='AC_OTH_AUTO';
  240. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceBackToDraftInDolibarr",$object->ref);
  241. $object->actionmsg=$langs->transnoentities("InvoiceBackToDraftInDolibarr",$object->ref);
  242. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  243. $object->sendtoid=0;
  244. $ok=1;
  245. }
  246. elseif ($action == 'BILL_SENTBYMAIL')
  247. {
  248. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  249. $langs->load("other");
  250. $langs->load("bills");
  251. $langs->load("agenda");
  252. $object->actiontypecode='AC_OTH_AUTO';
  253. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceSentByEMail",$object->ref);
  254. if (empty($object->actionmsg))
  255. {
  256. $object->actionmsg=$langs->transnoentities("InvoiceSentByEMail",$object->ref);
  257. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  258. }
  259. // Parameters $object->sendtoid defined by caller
  260. //$object->sendtoid=0;
  261. $ok=1;
  262. }
  263. elseif ($action == 'BILL_PAYED')
  264. {
  265. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  266. $langs->load("other");
  267. $langs->load("bills");
  268. $langs->load("agenda");
  269. // Values for this action can't be defined by caller.
  270. $object->actiontypecode='AC_OTH_AUTO';
  271. $object->actionmsg2=$langs->transnoentities("InvoicePaidInDolibarr",$object->ref);
  272. $object->actionmsg=$langs->transnoentities("InvoicePaidInDolibarr",$object->ref);
  273. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  274. $object->sendtoid=0;
  275. $ok=1;
  276. }
  277. elseif ($action == 'BILL_CANCEL')
  278. {
  279. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  280. $langs->load("other");
  281. $langs->load("bills");
  282. $langs->load("agenda");
  283. $object->actiontypecode='AC_OTH_AUTO';
  284. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceCanceledInDolibarr",$object->ref);
  285. $object->actionmsg=$langs->transnoentities("InvoiceCanceledInDolibarr",$object->ref);
  286. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  287. $object->sendtoid=0;
  288. $ok=1;
  289. }
  290. elseif ($action == 'FICHINTER_VALIDATE')
  291. {
  292. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  293. $langs->load("other");
  294. $langs->load("interventions");
  295. $langs->load("agenda");
  296. $object->actiontypecode='AC_OTH_AUTO';
  297. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InterventionValidatedInDolibarr",$object->ref);
  298. $object->actionmsg=$langs->transnoentities("InterventionValidatedInDolibarr",$object->ref);
  299. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  300. $object->sendtoid=0;
  301. $object->fk_element=0;
  302. $object->elementtype='';
  303. $ok=1;
  304. }
  305. elseif ($action == 'FICHINTER_SENTBYMAIL')
  306. {
  307. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  308. $langs->load("other");
  309. $langs->load("interventions");
  310. $langs->load("agenda");
  311. $object->actiontypecode='AC_OTH_AUTO';
  312. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InterventionSentByEMail",$object->ref);
  313. $object->actionmsg=$langs->transnoentities("InterventionSentByEMail",$object->ref);
  314. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  315. // Parameters $object->sendotid defined by caller
  316. //$object->sendtoid=0;
  317. $ok=1;
  318. }
  319. elseif ($action == 'SHIPPING_SENTBYMAIL')
  320. {
  321. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  322. $langs->load("other");
  323. $langs->load("sendings");
  324. $langs->load("agenda");
  325. $object->actiontypecode='AC_OTH_AUTO';
  326. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ShippingSentByEMail",$object->ref);
  327. if (empty($object->actionmsg))
  328. {
  329. $object->actionmsg=$langs->transnoentities("ShippingSentByEMail",$object->ref);
  330. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  331. }
  332. // Parameters $object->sendtoid defined by caller
  333. //$object->sendtoid=0;
  334. $ok=1;
  335. }
  336. elseif ($action == 'ORDER_SUPPLIER_VALIDATE')
  337. {
  338. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  339. $langs->load("orders");
  340. $langs->load("agenda");
  341. $object->actiontypecode='AC_OTH_AUTO';
  342. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderValidatedInDolibarr",$object->ref);
  343. $object->actionmsg=$langs->transnoentities("OrderValidatedInDolibarr",$object->ref);
  344. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  345. $object->sendtoid=0;
  346. $ok=1;
  347. }
  348. elseif ($action == 'ORDER_SUPPLIER_SENTBYMAIL')
  349. {
  350. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  351. $langs->load("other");
  352. $langs->load("bills");
  353. $langs->load("agenda");
  354. $langs->load("orders");
  355. $object->actiontypecode='AC_OTH_AUTO';
  356. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("SupplierOrderSentByEMail",$object->ref);
  357. if (empty($object->actionmsg))
  358. {
  359. $object->actionmsg=$langs->transnoentities("SupplierOrderSentByEMail",$object->ref);
  360. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  361. }
  362. // Parameters $object->sendotid defined by caller
  363. //$object->sendtoid=0;
  364. $ok=1;
  365. }
  366. elseif ($action == 'BILL_SUPPLIER_VALIDATE')
  367. {
  368. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  369. $langs->load("other");
  370. $langs->load("bills");
  371. $langs->load("agenda");
  372. $object->actiontypecode='AC_OTH_AUTO';
  373. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceValidatedInDolibarr",$object->ref);
  374. $object->actionmsg=$langs->transnoentities("InvoiceValidatedInDolibarr",$object->ref);
  375. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  376. $object->sendtoid=0;
  377. $ok=1;
  378. }
  379. elseif ($action == 'BILL_SUPPLIER_SENTBYMAIL')
  380. {
  381. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  382. $langs->load("other");
  383. $langs->load("bills");
  384. $langs->load("agenda");
  385. $langs->load("orders");
  386. $object->actiontypecode='AC_OTH_AUTO';
  387. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("SupplierInvoiceSentByEMail",$object->ref);
  388. if (empty($object->actionmsg))
  389. {
  390. $object->actionmsg=$langs->transnoentities("SupplierInvoiceSentByEMail",$object->ref);
  391. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  392. }
  393. // Parameters $object->sendtoid defined by caller
  394. //$object->sendtoid=0;
  395. $ok=1;
  396. }
  397. elseif ($action == 'BILL_SUPPLIER_PAYED')
  398. {
  399. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  400. $langs->load("other");
  401. $langs->load("bills");
  402. $langs->load("agenda");
  403. $object->actiontypecode='AC_OTH_AUTO';
  404. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoicePaidInDolibarr",$object->ref);
  405. $object->actionmsg=$langs->transnoentities("InvoicePaidInDolibarr",$object->ref);
  406. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  407. $object->sendtoid=0;
  408. $ok=1;
  409. }
  410. elseif ($action == 'BILL_SUPPLIER_CANCELED')
  411. {
  412. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  413. $langs->load("other");
  414. $langs->load("bills");
  415. $langs->load("agenda");
  416. $object->actiontypecode='AC_OTH_AUTO';
  417. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceCanceledInDolibarr",$object->ref);
  418. $object->actionmsg=$langs->transnoentities("InvoiceCanceledInDolibarr",$object->ref);
  419. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  420. $object->sendtoid=0;
  421. $ok=1;
  422. }
  423. // Members
  424. elseif ($action == 'MEMBER_VALIDATE')
  425. {
  426. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  427. $langs->load("other");
  428. $langs->load("members");
  429. $langs->load("agenda");
  430. $object->actiontypecode='AC_OTH_AUTO';
  431. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("MemberValidatedInDolibarr",$object->ref);
  432. $object->actionmsg=$langs->transnoentities("MemberValidatedInDolibarr",$object->ref);
  433. $object->actionmsg.="\n".$langs->transnoentities("Member").': '.$object->getFullName($langs);
  434. $object->actionmsg.="\n".$langs->transnoentities("Type").': '.$object->type;
  435. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  436. $object->sendtoid=0;
  437. $ok=1;
  438. }
  439. elseif ($action == 'MEMBER_SUBSCRIPTION')
  440. {
  441. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  442. $langs->load("other");
  443. $langs->load("members");
  444. $langs->load("agenda");
  445. $object->actiontypecode='AC_OTH_AUTO';
  446. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("MemberSubscriptionAddedInDolibarr",$object->ref);
  447. $object->actionmsg=$langs->transnoentities("MemberSubscriptionAddedInDolibarr",$object->ref);
  448. $object->actionmsg.="\n".$langs->transnoentities("Member").': '.$object->getFullName($langs);
  449. $object->actionmsg.="\n".$langs->transnoentities("Type").': '.$object->type;
  450. $object->actionmsg.="\n".$langs->transnoentities("Amount").': '.$object->last_subscription_amount;
  451. $object->actionmsg.="\n".$langs->transnoentities("Period").': '.dol_print_date($object->last_subscription_date_start,'day').' - '.dol_print_date($object->last_subscription_date_end,'day');
  452. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  453. $object->sendtoid=0;
  454. $ok=1;
  455. }
  456. elseif ($action == 'MEMBER_MODIFY')
  457. {
  458. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  459. }
  460. elseif ($action == 'MEMBER_RESILIATE')
  461. {
  462. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  463. $langs->load("other");
  464. $langs->load("members");
  465. $langs->load("agenda");
  466. $object->actiontypecode='AC_OTH_AUTO';
  467. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("MemberResiliatedInDolibarr",$object->ref);
  468. $object->actionmsg=$langs->transnoentities("MemberResiliatedInDolibarr",$object->ref);
  469. $object->actionmsg.="\n".$langs->transnoentities("Member").': '.$object->getFullName($langs);
  470. $object->actionmsg.="\n".$langs->transnoentities("Type").': '.$object->type;
  471. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  472. $object->sendtoid=0;
  473. $ok=1;
  474. }
  475. elseif ($action == 'MEMBER_DELETE')
  476. {
  477. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  478. $langs->load("other");
  479. $langs->load("members");
  480. $langs->load("agenda");
  481. $object->actiontypecode='AC_OTH_AUTO';
  482. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("MemberDeletedInDolibarr",$object->ref);
  483. $object->actionmsg=$langs->transnoentities("MemberDeletedInDolibarr",$object->ref);
  484. $object->actionmsg.="\n".$langs->transnoentities("Member").': '.$object->getFullName($langs);
  485. $object->actionmsg.="\n".$langs->transnoentities("Type").': '.$object->type;
  486. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  487. $object->sendtoid=0;
  488. $ok=1;
  489. }
  490. // If not found
  491. /*
  492. else
  493. {
  494. dol_syslog("Trigger '".$this->name."' for action '$action' was ran by ".__FILE__." but no handler found for this action.");
  495. return 0;
  496. }
  497. */
  498. // Add entry in event table
  499. if ($ok)
  500. {
  501. $now=dol_now();
  502. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  503. require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  504. $contactforaction=new Contact($this->db);
  505. $societeforaction=new Societe($this->db);
  506. if ($object->sendtoid > 0) $contactforaction->fetch($object->sendtoid);
  507. if ($object->socid > 0) $societeforaction->fetch($object->socid);
  508. // Insertion action
  509. require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
  510. $actioncomm = new ActionComm($this->db);
  511. $actioncomm->type_code = $object->actiontypecode; // code of parent table llx_c_actioncomm (will be deprecated)
  512. $actioncomm->code='AC_'.$action;
  513. $actioncomm->label = $object->actionmsg2;
  514. $actioncomm->note = $object->actionmsg;
  515. $actioncomm->datep = $now;
  516. $actioncomm->datef = $now;
  517. $actioncomm->durationp = 0;
  518. $actioncomm->punctual = 1;
  519. $actioncomm->percentage = -1; // Not applicable
  520. $actioncomm->contact = $contactforaction;
  521. $actioncomm->societe = $societeforaction;
  522. $actioncomm->author = $user; // User saving action
  523. //$actioncomm->usertodo = $user; // User affected to action
  524. $actioncomm->userdone = $user; // User doing action
  525. $actioncomm->fk_element = $object->id;
  526. $actioncomm->elementtype = $object->element;
  527. $ret=$actioncomm->add($user); // User qui saisit l'action
  528. if ($ret > 0)
  529. {
  530. $_SESSION['LAST_ACTION_CREATED'] = $ret;
  531. return 1;
  532. }
  533. else
  534. {
  535. $error ="Failed to insert : ".$actioncomm->error." ";
  536. $this->error=$error;
  537. dol_syslog("interface_modAgenda_ActionsAuto.class.php: ".$this->error, LOG_ERR);
  538. return -1;
  539. }
  540. }
  541. return 0;
  542. }
  543. }
  544. ?>