interface_modAgenda_ActionsAuto.class.php 25 KB

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