PageRenderTime 89ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php

https://bitbucket.org/speedealing/speedealing
PHP | 601 lines | 431 code | 74 blank | 96 comment | 95 complexity | 11b981865d91e0815a4e9c04f843f6e6 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  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. *
  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 3 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_50_modAgenda_ActionsAuto.class.php
  21. * \ingroup agenda
  22. * \brief Trigger file for agenda module
  23. */
  24. /**
  25. * Class of triggered functions for agenda module
  26. */
  27. class InterfaceActionsAuto
  28. {
  29. var $db;
  30. var $error;
  31. var $date;
  32. var $duree;
  33. var $texte;
  34. var $desc;
  35. /**
  36. * Constructor
  37. *
  38. * @param DoliDB $db Database handler
  39. */
  40. function __construct($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. *
  52. * @return string Name of trigger file
  53. */
  54. function getName()
  55. {
  56. return $this->name;
  57. }
  58. /**
  59. * Return description of trigger file
  60. *
  61. * @return string Description of trigger file
  62. */
  63. function getDesc()
  64. {
  65. return $this->description;
  66. }
  67. /**
  68. * Return version of trigger file
  69. *
  70. * @return string Version of trigger file
  71. */
  72. function getVersion()
  73. {
  74. global $langs;
  75. $langs->load("admin");
  76. if ($this->version == 'experimental') return $langs->trans("Experimental");
  77. elseif ($this->version == 'dolibarr') return DOL_VERSION;
  78. elseif ($this->version) return $this->version;
  79. else return $langs->trans("Unknown");
  80. }
  81. /**
  82. * Function called when a Dolibarrr business event is done.
  83. * All functions "run_trigger" are triggered if file is inside directory htdocs/core/triggers
  84. *
  85. * Following properties must be filled:
  86. * $object->actiontypecode (translation action code: AC_OTH, ...)
  87. * $object->actionmsg (note, long text)
  88. * $object->actionmsg2 (label, short text)
  89. * $object->sendtoid (id of contact)
  90. * $object->socid
  91. * Optionnal:
  92. * $object->fk_element
  93. * $object->elementtype
  94. *
  95. * @param string $action Event action code
  96. * @param Object $object Object
  97. * @param User $user Object user
  98. * @param Translate $langs Object langs
  99. * @param conf $conf Object conf
  100. * @return int <0 if KO, 0 if no triggered ran, >0 if OK
  101. */
  102. function run_trigger($action,$object,$user,$langs,$conf)
  103. {
  104. $key='MAIN_AGENDA_ACTIONAUTO_'.$action;
  105. //dol_syslog("xxxxxxxxxxx".$key);
  106. if (empty($conf->agenda->enabled)) return 0; // Module not active, we do nothing
  107. if (empty($conf->global->$key)) return 0; // Log events not enabled for this action
  108. $ok=0;
  109. // Actions
  110. if ($action == 'COMPANY_CREATE')
  111. {
  112. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  113. $langs->load("other");
  114. $langs->load("agenda");
  115. $object->actiontypecode='AC_OTH';
  116. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("NewCompanyToSpeedealing",$object->nom);
  117. $object->actionmsg=$langs->transnoentities("NewCompanyToSpeedealing",$object->nom);
  118. if ($object->prefix) $object->actionmsg.=" (".$object->prefix.")";
  119. //$this->desc.="\n".$langs->transnoentities("Customer").': '.yn($object->client);
  120. //$this->desc.="\n".$langs->transnoentities("Supplier").': '.yn($object->fournisseur);
  121. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  122. $object->sendtoid=0;
  123. $object->socid=$object->id;
  124. $ok=1;
  125. }
  126. elseif ($action == 'CONTRACT_VALIDATE')
  127. {
  128. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  129. $langs->load("other");
  130. $langs->load("contracts");
  131. $langs->load("agenda");
  132. $object->actiontypecode='AC_OTH';
  133. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ContractValidatedInSpeedealing",$object->ref);
  134. $object->actionmsg=$langs->transnoentities("ContractValidatedInSpeedealing",$object->ref);
  135. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  136. $object->sendtoid=0;
  137. $ok=1;
  138. }
  139. elseif ($action == 'PROPAL_VALIDATE')
  140. {
  141. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  142. $langs->load("propal");
  143. $langs->load("agenda");
  144. $object->actiontypecode='AC_OTH';
  145. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("PropalValidatedInSpeedealing",$object->ref);
  146. $object->actionmsg=$langs->transnoentities("PropalValidatedInSpeedealing",$object->ref);
  147. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  148. $object->sendtoid=0;
  149. $ok=1;
  150. }
  151. elseif ($action == 'PROPAL_SENTBYMAIL')
  152. {
  153. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  154. $langs->load("propal");
  155. $langs->load("agenda");
  156. $object->actiontypecode='AC_EMAIL';
  157. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ProposalSentByEMail",$object->ref);
  158. if (empty($object->actionmsg))
  159. {
  160. $object->actionmsg=$langs->transnoentities("ProposalSentByEMail",$object->ref);
  161. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  162. }
  163. // Parameters $object->sendtoid defined by caller
  164. //$object->sendtoid=0;
  165. $ok=1;
  166. }
  167. elseif ($action == 'PROPAL_CLOSE_SIGNED')
  168. {
  169. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  170. $langs->load("propal");
  171. $langs->load("agenda");
  172. $object->actiontypecode='AC_OTH';
  173. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("PropalClosedSignedInSpeedealing",$object->ref);
  174. $object->actionmsg=$langs->transnoentities("PropalClosedSignedInSpeedealing",$object->ref);
  175. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  176. $object->sendtoid=0;
  177. $ok=1;
  178. }
  179. elseif ($action == 'PROPAL_CLOSE_REFUSED')
  180. {
  181. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  182. $langs->load("propal");
  183. $langs->load("agenda");
  184. $object->actiontypecode='AC_OTH';
  185. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("PropalClosedRefusedInSpeedealing",$object->ref);
  186. $object->actionmsg=$langs->transnoentities("PropalClosedRefusedInSpeedealing",$object->ref);
  187. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  188. $object->sendtoid=0;
  189. $ok=1;
  190. }
  191. elseif ($action == 'ORDER_VALIDATE')
  192. {
  193. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  194. $langs->load("orders");
  195. $langs->load("agenda");
  196. $object->actiontypecode='AC_OTH';
  197. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderValidatedInSpeedealing",$object->ref);
  198. $object->actionmsg=$langs->transnoentities("OrderValidatedInSpeedealing",$object->ref);
  199. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  200. $object->sendtoid=0;
  201. $ok=1;
  202. }
  203. elseif ($action == 'ORDER_SENTBYMAIL')
  204. {
  205. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  206. $langs->load("orders");
  207. $langs->load("agenda");
  208. $object->actiontypecode='AC_EMAIL';
  209. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderSentByEMail",$object->ref);
  210. if (empty($object->actionmsg))
  211. {
  212. $object->actionmsg=$langs->transnoentities("OrderSentByEMail",$object->ref);
  213. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  214. }
  215. // Parameters $object->sendtoid defined by caller
  216. //$object->sendtoid=0;
  217. $ok=1;
  218. }
  219. elseif ($action == 'BILL_VALIDATE')
  220. {
  221. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  222. $langs->load("other");
  223. $langs->load("bills");
  224. $langs->load("agenda");
  225. $object->actiontypecode='AC_OTH';
  226. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceValidatedInSpeedealing",$object->ref);
  227. $object->actionmsg=$langs->transnoentities("InvoiceValidatedInSpeedealing",$object->ref);
  228. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  229. $object->sendtoid=0;
  230. $ok=1;
  231. }
  232. elseif ($action == 'BILL_SENTBYMAIL')
  233. {
  234. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  235. $langs->load("other");
  236. $langs->load("bills");
  237. $langs->load("agenda");
  238. $object->actiontypecode='AC_EMAIL';
  239. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceSentByEMail",$object->ref);
  240. if (empty($object->actionmsg))
  241. {
  242. $object->actionmsg=$langs->transnoentities("InvoiceSentByEMail",$object->ref);
  243. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  244. }
  245. // Parameters $object->sendtoid defined by caller
  246. //$object->sendtoid=0;
  247. $ok=1;
  248. }
  249. elseif ($action == 'BILL_PAYED')
  250. {
  251. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  252. $langs->load("other");
  253. $langs->load("bills");
  254. $langs->load("agenda");
  255. $object->actiontypecode='AC_OTH';
  256. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoicePaidInSpeedealing",$object->ref);
  257. $object->actionmsg=$langs->transnoentities("InvoicePaidInSpeedealing",$object->ref);
  258. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  259. $object->sendtoid=0;
  260. $ok=1;
  261. }
  262. elseif ($action == 'BILL_CANCEL')
  263. {
  264. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  265. $langs->load("other");
  266. $langs->load("bills");
  267. $langs->load("agenda");
  268. $object->actiontypecode='AC_OTH';
  269. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceCanceledInSpeedealing",$object->ref);
  270. $object->actionmsg=$langs->transnoentities("InvoiceCanceledInSpeedealing",$object->ref);
  271. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  272. $object->sendtoid=0;
  273. $ok=1;
  274. }
  275. elseif ($action == 'FICHEINTER_VALIDATE')
  276. {
  277. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  278. $langs->load("other");
  279. $langs->load("interventions");
  280. $langs->load("agenda");
  281. $object->actiontypecode='AC_OTH';
  282. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InterventionValidatedInSpeedealing",$object->ref);
  283. $object->actionmsg=$langs->transnoentities("InterventionValidatedInSpeedealing",$object->ref);
  284. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  285. $object->sendtoid=0;
  286. $object->fk_element=0;
  287. $object->elementtype='';
  288. $ok=1;
  289. }
  290. elseif ($action == 'FICHEINTER_SENTBYMAIL')
  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_EMAIL';
  297. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InterventionSentByEMail",$object->ref);
  298. $object->actionmsg=$langs->transnoentities("InterventionSentByEMail",$object->ref);
  299. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  300. // Parameters $object->sendotid defined by caller
  301. //$object->sendtoid=0;
  302. $ok=1;
  303. }
  304. elseif ($action == 'SHIPPING_SENTBYMAIL')
  305. {
  306. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  307. $langs->load("other");
  308. $langs->load("sendings");
  309. $langs->load("agenda");
  310. $object->actiontypecode='AC_SHIP';
  311. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ShippingSentByEMail",$object->ref);
  312. if (empty($object->actionmsg))
  313. {
  314. $object->actionmsg=$langs->transnoentities("ShippingSentByEMail",$object->ref);
  315. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  316. }
  317. // Parameters $object->sendtoid defined by caller
  318. //$object->sendtoid=0;
  319. $ok=1;
  320. }
  321. elseif ($action == 'ORDER_SUPPLIER_VALIDATE')
  322. {
  323. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  324. $langs->load("orders");
  325. $langs->load("agenda");
  326. $object->actiontypecode='AC_OTH';
  327. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderValidatedInSpeedealing",$object->ref);
  328. $object->actionmsg=$langs->transnoentities("OrderValidatedInSpeedealing",$object->ref);
  329. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  330. $object->sendtoid=0;
  331. $ok=1;
  332. }
  333. elseif ($action == 'ORDER_SUPPLIER_SENTBYMAIL')
  334. {
  335. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  336. $langs->load("other");
  337. $langs->load("bills");
  338. $langs->load("agenda");
  339. $langs->load("orders");
  340. $object->actiontypecode='AC_EMAIL';
  341. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("SupplierOrderSentByEMail",$object->ref);
  342. if (empty($object->actionmsg))
  343. {
  344. $object->actionmsg=$langs->transnoentities("SupplierOrderSentByEMail",$object->ref);
  345. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  346. }
  347. // Parameters $object->sendotid defined by caller
  348. //$object->sendtoid=0;
  349. $ok=1;
  350. }
  351. elseif ($action == 'BILL_SUPPLIER_VALIDATE')
  352. {
  353. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  354. $langs->load("other");
  355. $langs->load("bills");
  356. $langs->load("agenda");
  357. $object->actiontypecode='AC_OTH';
  358. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceValidatedInSpeedealing",$object->ref);
  359. $object->actionmsg=$langs->transnoentities("InvoiceValidatedInSpeedealing",$object->ref);
  360. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  361. $object->sendtoid=0;
  362. $ok=1;
  363. }
  364. elseif ($action == 'BILL_SUPPLIER_SENTBYMAIL')
  365. {
  366. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  367. $langs->load("other");
  368. $langs->load("bills");
  369. $langs->load("agenda");
  370. $langs->load("orders");
  371. $object->actiontypecode='AC_EMAIL';
  372. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("SupplierInvoiceSentByEMail",$object->ref);
  373. if (empty($object->actionmsg))
  374. {
  375. $object->actionmsg=$langs->transnoentities("SupplierInvoiceSentByEMail",$object->ref);
  376. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  377. }
  378. // Parameters $object->sendtoid defined by caller
  379. //$object->sendtoid=0;
  380. $ok=1;
  381. }
  382. elseif ($action == 'BILL_SUPPLIER_PAYED')
  383. {
  384. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  385. $langs->load("other");
  386. $langs->load("bills");
  387. $langs->load("agenda");
  388. $object->actiontypecode='AC_OTH';
  389. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoicePaidInSpeedealing",$object->ref);
  390. $object->actionmsg=$langs->transnoentities("InvoicePaidInSpeedealing",$object->ref);
  391. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  392. $object->sendtoid=0;
  393. $ok=1;
  394. }
  395. elseif ($action == 'BILL_SUPPLIER_CANCELED')
  396. {
  397. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  398. $langs->load("other");
  399. $langs->load("bills");
  400. $langs->load("agenda");
  401. $object->actiontypecode='AC_OTH';
  402. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceCanceledInSpeedealing",$object->ref);
  403. $object->actionmsg=$langs->transnoentities("InvoiceCanceledInSpeedealing",$object->ref);
  404. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  405. $object->sendtoid=0;
  406. $ok=1;
  407. }
  408. // Members
  409. elseif ($action == 'MEMBER_VALIDATE')
  410. {
  411. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  412. $langs->load("other");
  413. $langs->load("members");
  414. $langs->load("agenda");
  415. $object->actiontypecode='AC_OTH';
  416. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("MemberValidatedInSpeedealing",$object->ref);
  417. $object->actionmsg=$langs->transnoentities("MemberValidatedInSpeedealing",$object->ref);
  418. $object->actionmsg.="\n".$langs->transnoentities("Member").': '.$object->getFullName($langs);
  419. $object->actionmsg.="\n".$langs->transnoentities("Type").': '.$object->type;
  420. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  421. $object->sendtoid=0;
  422. $ok=1;
  423. }
  424. elseif ($action == 'MEMBER_SUBSCRIPTION')
  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';
  431. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("MemberSubscriptionAddedInSpeedealing",$object->ref);
  432. $object->actionmsg=$langs->transnoentities("MemberSubscriptionAddedInSpeedealing",$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("Amount").': '.$object->last_subscription_amount;
  436. $object->actionmsg.="\n".$langs->transnoentities("Period").': '.dol_print_date($object->last_subscription_date_start,'day').' - '.dol_print_date($object->last_subscription_date_end,'day');
  437. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  438. $object->sendtoid=0;
  439. $ok=1;
  440. }
  441. elseif ($action == 'MEMBER_MODIFY')
  442. {
  443. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  444. }
  445. elseif ($action == 'MEMBER_RESILIATE')
  446. {
  447. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  448. $langs->load("other");
  449. $langs->load("members");
  450. $langs->load("agenda");
  451. $object->actiontypecode='AC_OTH';
  452. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("MemberResiliatedInSpeedealing",$object->ref);
  453. $object->actionmsg=$langs->transnoentities("MemberResiliatedInSpeedealing",$object->ref);
  454. $object->actionmsg.="\n".$langs->transnoentities("Member").': '.$object->getFullName($langs);
  455. $object->actionmsg.="\n".$langs->transnoentities("Type").': '.$object->type;
  456. $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
  457. $object->sendtoid=0;
  458. $ok=1;
  459. }
  460. elseif ($action == 'MEMBER_DELETE')
  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';
  467. if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("MemberDeletedInSpeedealing",$object->ref);
  468. $object->actionmsg=$langs->transnoentities("MemberDeletedInSpeedealing",$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. // If not found
  476. /*
  477. else
  478. {
  479. dol_syslog("Trigger '".$this->name."' for action '$action' was ran by ".__FILE__." but no handler found for this action.");
  480. return 0;
  481. }
  482. */
  483. // Add entry in event table
  484. if ($ok)
  485. {
  486. $now=dol_now();
  487. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  488. require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  489. $contactforaction=new Contact($this->db);
  490. $societeforaction=new Societe($this->db);
  491. if ($object->sendtoid > 0) $contactforaction->fetch($object->sendtoid);
  492. if ($object->socid > 0) $societeforaction->fetch($object->socid);
  493. // Insertion action
  494. require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
  495. $actioncomm = new ActionComm($this->db);
  496. $actioncomm->type_code = $object->actiontypecode;
  497. $actioncomm->label = $object->actionmsg2;
  498. $actioncomm->note = $object->actionmsg;
  499. $actioncomm->datep = $now;
  500. $actioncomm->datef = $now;
  501. $actioncomm->durationp = 0;
  502. $actioncomm->punctual = 1;
  503. $actioncomm->percentage = -1; // Not applicable
  504. $actioncomm->contact = $contactforaction;
  505. $actioncomm->societe = $societeforaction;
  506. $actioncomm->author = $user; // User saving action
  507. //$actioncomm->usertodo = $user; // User affected to action
  508. $actioncomm->userdone = $user; // User doing action
  509. $actioncomm->fk_element = $object->id;
  510. $actioncomm->elementtype = $object->element;
  511. $ret=$actioncomm->add($user); // User qui saisit l'action
  512. if ($ret > 0)
  513. {
  514. return 1;
  515. }
  516. else
  517. {
  518. $error ="Failed to insert : ".$actioncomm->error." ";
  519. $this->error=$error;
  520. dol_syslog("interface_modAgenda_ActionsAuto.class.php: ".$this->error, LOG_ERR);
  521. return -1;
  522. }
  523. }
  524. return 0;
  525. }
  526. }
  527. ?>