actions_massactions.inc.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. <?php
  2. /* Copyright (C) 2015 Laurent Destailleur <eldy@users.sourceforge.net>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. * or see http://www.gnu.org/
  17. */
  18. /**
  19. * \file htdocs/core/actions_massactions.inc.php
  20. * \brief Code for actions done with massaction button (send by email, merge pdf, delete, ...)
  21. */
  22. // $massaction must be defined
  23. // $objectclass and $$objectlabel must be defined
  24. // $uploaddir (example $conf->projet->dir_output . "/";)
  25. // $toselect may be defined
  26. // Protection
  27. if (empty($objectclass) || empty($uploaddir))
  28. {
  29. dol_print_error(null, 'include of actions_massactions.inc.php is done but var $massaction or $objectclass or $uploaddir was not defined');
  30. exit;
  31. }
  32. // Mass actions. Controls on number of lines checked
  33. $maxformassaction=1000;
  34. if (! empty($massaction) && count($toselect) < 1)
  35. {
  36. $error++;
  37. setEventMessages($langs->trans("NoRecordSelected"), null, "warnings");
  38. }
  39. if (! $error && count($toselect) > $maxformassaction)
  40. {
  41. setEventMessages($langs->trans('TooManyRecordForMassAction',$maxformassaction), null, 'errors');
  42. $error++;
  43. }
  44. if (! $error && $massaction == 'confirm_presend' && GETPOST('modelselected')) // If we change the template, we must not send email, but keep on send email form
  45. {
  46. $massaction='presend';
  47. }
  48. if (! $error && $massaction == 'confirm_presend')
  49. {
  50. $resaction = '';
  51. $nbsent = 0;
  52. $nbignored = 0;
  53. $langs->load("mails");
  54. include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  55. if (!$error && !isset($user->email))
  56. {
  57. $error++;
  58. setEventMessages($langs->trans("NoSenderEmailDefined"), null, 'warnings');
  59. }
  60. if (! $error)
  61. {
  62. $thirdparty=new Societe($db);
  63. $objecttmp=new $objectclass($db);
  64. $listofobjectid=array();
  65. $listofobjectthirdparties=array();
  66. $listofobjectref=array();
  67. foreach($toselect as $toselectid)
  68. {
  69. $objecttmp=new $objectclass($db); // must create new instance because instance is saved into $listofobjectref array for future use
  70. $result=$objecttmp->fetch($toselectid);
  71. if ($result > 0)
  72. {
  73. $listoinvoicesid[$toselectid]=$toselectid;
  74. $thirdpartyid=$objecttmp->fk_soc?$objecttmp->fk_soc:$objecttmp->socid;
  75. $listofobjectthirdparties[$thirdpartyid]=$thirdpartyid;
  76. $listofobjectref[$thirdpartyid][$toselectid]=$objecttmp;
  77. }
  78. }
  79. //var_dump($listofobjectthirdparties);exit;
  80. foreach ($listofobjectthirdparties as $thirdpartyid)
  81. {
  82. $result = $thirdparty->fetch($thirdpartyid);
  83. if ($result < 0)
  84. {
  85. dol_print_error($db);
  86. exit;
  87. }
  88. // Define recipient $sendto and $sendtocc
  89. if (trim($_POST['sendto']))
  90. {
  91. // Recipient is provided into free text
  92. $sendto = trim($_POST['sendto']);
  93. $sendtoid = 0;
  94. }
  95. elseif ($_POST['receiver'] != '-1')
  96. {
  97. // Recipient was provided from combo list
  98. if ($_POST['receiver'] == 'thirdparty') // Id of third party
  99. {
  100. $sendto = $thirdparty->email;
  101. $sendtoid = 0;
  102. }
  103. else // Id du contact
  104. {
  105. $sendto = $thirdparty->contact_get_property((int) $_POST['receiver'],'email');
  106. $sendtoid = $_POST['receiver'];
  107. }
  108. }
  109. if (trim($_POST['sendtocc']))
  110. {
  111. $sendtocc = trim($_POST['sendtocc']);
  112. }
  113. elseif ($_POST['receivercc'] != '-1')
  114. {
  115. // Recipient was provided from combo list
  116. if ($_POST['receivercc'] == 'thirdparty') // Id of third party
  117. {
  118. $sendtocc = $thirdparty->email;
  119. }
  120. else // Id du contact
  121. {
  122. $sendtocc = $thirdparty->contact_get_property((int) $_POST['receivercc'],'email');
  123. }
  124. }
  125. //var_dump($listofobjectref[$thirdpartyid]); // Array of invoice for this thirdparty
  126. $attachedfiles=array('paths'=>array(), 'names'=>array(), 'mimes'=>array());
  127. $listofqualifiedinvoice=array();
  128. $listofqualifiedref=array();
  129. foreach($listofobjectref[$thirdpartyid] as $objectid => $object)
  130. {
  131. //var_dump($object);
  132. //var_dump($thirdpartyid.' - '.$objectid.' - '.$object->statut);
  133. if ($objectclass == 'Facture' && $object->statut != Facture::STATUS_VALIDATED)
  134. {
  135. $nbignored++;
  136. $resaction.='<div class="error">'.$langs->trans('ErrorOnlyInvoiceValidatedCanBeSentInMassAction',$object->ref).'</div><br>';
  137. continue; // Payment done or started or canceled
  138. }
  139. if ($objectclass == 'Commande' && $object->statut == Commande::STATUS_DRAFT)
  140. {
  141. $nbignored++;
  142. $resaction.='<div class="error">'.$langs->trans('ErrorOnlyOrderNotDraftCanBeSentInMassAction',$object->ref).'</div><br>';
  143. continue;
  144. }
  145. // Read document
  146. // TODO Use future field $object->fullpathdoc to know where is stored default file
  147. // TODO If not defined, use $object->modelpdf (or defaut invoice config) to know what is template to use to regenerate doc.
  148. $filename=dol_sanitizeFileName($object->ref).'.pdf';
  149. $filedir=$uploaddir . '/' . dol_sanitizeFileName($object->ref);
  150. $file = $filedir . '/' . $filename;
  151. $mime = dol_mimetype($file);
  152. if (dol_is_file($file))
  153. {
  154. if (empty($sendto)) // For the case, no recipient were set (multi thirdparties send)
  155. {
  156. $object->fetch_thirdparty();
  157. $sendto = $object->thirdparty->email;
  158. }
  159. if (empty($sendto))
  160. {
  161. //print "No recipient for thirdparty ".$object->thirdparty->name;
  162. $nbignored++;
  163. continue;
  164. }
  165. if (dol_strlen($sendto))
  166. {
  167. // Create form object
  168. $attachedfiles=array(
  169. 'paths'=>array_merge($attachedfiles['paths'],array($file)),
  170. 'names'=>array_merge($attachedfiles['names'],array($filename)),
  171. 'mimes'=>array_merge($attachedfiles['mimes'],array($mime))
  172. );
  173. }
  174. $listofqualifiedinvoice[$objectid]=$object;
  175. $listofqualifiedref[$objectid]=$object->ref;
  176. }
  177. else
  178. {
  179. $nbignored++;
  180. $langs->load("errors");
  181. $resaction.='<div class="error">'.$langs->trans('ErrorCantReadFile',$file).'</div><br>';
  182. dol_syslog('Failed to read file: '.$file, LOG_WARNING);
  183. continue;
  184. }
  185. //var_dump($listofqualifiedref);
  186. }
  187. if (count($listofqualifiedinvoice) > 0)
  188. {
  189. $langs->load("commercial");
  190. $fromtype = GETPOST('fromtype');
  191. if ($fromtype === 'user') {
  192. $from = $user->getFullName($langs) .' <'.$user->email.'>';
  193. }
  194. elseif ($fromtype === 'company') {
  195. $from = $conf->global->MAIN_INFO_SOCIETE_NOM .' <'.$conf->global->MAIN_INFO_SOCIETE_MAIL.'>';
  196. }
  197. elseif (preg_match('/user_aliases_(\d+)/', $fromtype, $reg)) {
  198. $tmp=explode(',', $user->email_aliases);
  199. $from = trim($tmp[($reg[1] - 1)]);
  200. }
  201. elseif (preg_match('/global_aliases_(\d+)/', $fromtype, $reg)) {
  202. $tmp=explode(',', $conf->global->MAIN_INFO_SOCIETE_MAIL_ALIASES);
  203. $from = trim($tmp[($reg[1] - 1)]);
  204. }
  205. else {
  206. $from = $_POST['fromname'] . ' <' . $_POST['frommail'] .'>';
  207. }
  208. $replyto = $from;
  209. $subject = GETPOST('subject');
  210. $message = GETPOST('message');
  211. $sendtocc = GETPOST('sentocc');
  212. $sendtobcc = (empty($conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO)?'':$conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO);
  213. $substitutionarray=array(
  214. '__ID__' => join(', ',array_keys($listofqualifiedinvoice)),
  215. '__EMAIL__' => $thirdparty->email,
  216. '__CHECK_READ__' => '<img src="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-read.php?tag='.$thirdparty->tag.'&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).'" width="1" height="1" style="width:1px;height:1px" border="0"/>',
  217. '__FACREF__' => join(', ',$listofqualifiedref), // For backward compatibility
  218. '__ORDERREF__' => join(', ',$listofqualifiedref), // For backward compatibility
  219. '__PROPREF__' => join(', ',$listofqualifiedref), // For backward compatibility
  220. '__REF__' => join(', ',$listofqualifiedref),
  221. '__REFCLIENT__' => $thirdparty->name
  222. );
  223. $subject=make_substitutions($subject, $substitutionarray);
  224. $message=make_substitutions($message, $substitutionarray);
  225. $filepath = $attachedfiles['paths'];
  226. $filename = $attachedfiles['names'];
  227. $mimetype = $attachedfiles['mimes'];
  228. //var_dump($filepath);
  229. // Send mail
  230. require_once(DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php');
  231. $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,$sendtobcc,$deliveryreceipt,-1);
  232. if ($mailfile->error)
  233. {
  234. $resaction.='<div class="error">'.$mailfile->error.'</div>';
  235. }
  236. else
  237. {
  238. $result=$mailfile->sendfile();
  239. if ($result)
  240. {
  241. $resaction.=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($from,2),$mailfile->getValidAddress($sendto,2)).'<br>'; // Must not contain "
  242. $error=0;
  243. // Insert logs into agenda
  244. foreach($listofqualifiedinvoice as $invid => $object)
  245. {
  246. /*if ($objectclass == 'Propale') $actiontypecode='AC_PROP';
  247. if ($objectclass == 'Commande') $actiontypecode='AC_COM';
  248. if ($objectclass == 'Facture') $actiontypecode='AC_FAC';
  249. if ($objectclass == 'Supplier_Proposal') $actiontypecode='AC_SUP_PRO';
  250. if ($objectclass == 'CommandeFournisseur') $actiontypecode='AC_SUP_ORD';
  251. if ($objectclass == 'FactureFournisseur') $actiontypecode='AC_SUP_INV';*/
  252. $actionmsg=$langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto;
  253. if ($message)
  254. {
  255. if ($sendtocc) $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc') . ": " . $sendtocc);
  256. $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic') . ": " . $subject);
  257. $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody') . ":");
  258. $actionmsg = dol_concatdesc($actionmsg, $message);
  259. }
  260. $actionmsg2='';
  261. // Initialisation donnees
  262. $object->sendtoid = 0;
  263. $object->actionmsg = $actionmsg; // Long text
  264. $object->actionmsg2 = $actionmsg2; // Short text
  265. $object->fk_element = $invid;
  266. $object->elementtype = $object->element;
  267. // Appel des triggers
  268. include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
  269. $interface=new Interfaces($db);
  270. $result=$interface->run_triggers('BILL_SENTBYMAIL',$object,$user,$langs,$conf);
  271. if ($result < 0) { $error++; $errors=$interface->errors; }
  272. // Fin appel triggers
  273. if ($error)
  274. {
  275. setEventMessages($db->lasterror(), $errors, 'errors');
  276. dol_syslog("Error in trigger BILL_SENTBYMAIL ".$db->lasterror(), LOG_ERR);
  277. }
  278. $nbsent++;
  279. }
  280. }
  281. else
  282. {
  283. $langs->load("other");
  284. if ($mailfile->error)
  285. {
  286. $resaction.=$langs->trans('ErrorFailedToSendMail',$from,$sendto);
  287. $resaction.='<br><div class="error">'.$mailfile->error.'</div>';
  288. }
  289. else
  290. {
  291. $resaction.='<div class="warning">No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS</div>';
  292. }
  293. }
  294. }
  295. }
  296. }
  297. $resaction.=($resaction?'<br>':$resaction);
  298. $resaction.='<strong>'.$langs->trans("ResultOfMailSending").':</strong><br>'."\n";
  299. $resaction.=$langs->trans("NbSelected").': '.count($toselect)."\n<br>";
  300. $resaction.=$langs->trans("NbIgnored").': '.($nbignored?$nbignored:0)."\n<br>";
  301. $resaction.=$langs->trans("NbSent").': '.($nbsent?$nbsent:0)."\n<br>";
  302. if ($nbsent)
  303. {
  304. $action=''; // Do not show form post if there was at least one successfull sent
  305. //setEventMessages($langs->trans("EMailSentToNRecipients", $nbsent.'/'.count($toselect)), null, 'mesgs');
  306. setEventMessages($langs->trans("EMailSentForNElements", $nbsent.'/'.count($toselect)), null, 'mesgs');
  307. setEventMessages($resaction, null, 'mesgs');
  308. }
  309. else
  310. {
  311. //setEventMessages($langs->trans("EMailSentToNRecipients", 0), null, 'warnings'); // May be object has no generated PDF file
  312. setEventMessages($resaction, null, 'warnings');
  313. }
  314. }
  315. $action='list';
  316. $massaction='';
  317. }
  318. if (! $error && $massaction == "builddoc" && $permtoread && ! GETPOST('button_search'))
  319. {
  320. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  321. require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
  322. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  323. $objecttmp=new $objectclass($db);
  324. $listofobjectid=array();
  325. $listofobjectthirdparties=array();
  326. $listofobjectref=array();
  327. foreach($toselect as $toselectid)
  328. {
  329. $objecttmp=new $objectclass($db); // must create new instance because instance is saved into $listofobjectref array for future use
  330. $result=$objecttmp->fetch($toselectid);
  331. if ($result > 0)
  332. {
  333. $listoinvoicesid[$toselectid]=$toselectid;
  334. $thirdpartyid=$objecttmp->fk_soc?$objecttmp->fk_soc:$objecttmp->socid;
  335. $listofobjectthirdparties[$thirdpartyid]=$thirdpartyid;
  336. $listofobjectref[$toselectid]=$objecttmp->ref;
  337. }
  338. }
  339. $arrayofinclusion=array();
  340. foreach($listofobjectref as $tmppdf) $arrayofinclusion[]=preg_quote($tmppdf.'.pdf','/');
  341. $listoffiles = dol_dir_list($uploaddir,'all',1,implode('|',$arrayofinclusion),'\.meta$|\.png','date',SORT_DESC,0,true);
  342. // build list of files with full path
  343. $files = array();
  344. foreach($listofobjectref as $basename)
  345. {
  346. foreach($listoffiles as $filefound)
  347. {
  348. if (strstr($filefound["name"],$basename))
  349. {
  350. $files[] = $uploaddir.'/'.$basename.'/'.$filefound["name"];
  351. break;
  352. }
  353. }
  354. }
  355. // Define output language (Here it is not used because we do only merging existing PDF)
  356. $outputlangs = $langs;
  357. $newlang='';
  358. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id');
  359. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->thirdparty->default_lang;
  360. if (! empty($newlang))
  361. {
  362. $outputlangs = new Translate("",$conf);
  363. $outputlangs->setDefaultLang($newlang);
  364. }
  365. if(!empty($conf->global->USE_PDFTK_FOR_PDF_CONCAT)) {
  366. // Create output dir if not exists
  367. dol_mkdir($diroutputmassaction);
  368. // Defined name of merged file
  369. $filename=strtolower(dol_sanitizeFileName($langs->transnoentities($objectlabel)));
  370. $filename=preg_replace('/\s/','_',$filename);
  371. // Save merged file
  372. if ($filter=='paye:0')
  373. {
  374. if ($option=='late') $filename.='_'.strtolower(dol_sanitizeFileName($langs->transnoentities("Unpaid"))).'_'.strtolower(dol_sanitizeFileName($langs->transnoentities("Late")));
  375. else $filename.='_'.strtolower(dol_sanitizeFileName($langs->transnoentities("Unpaid")));
  376. }
  377. if ($year) $filename.='_'.$year;
  378. if ($month) $filename.='_'.$month;
  379. if (count($files)>0)
  380. {
  381. $now=dol_now();
  382. $file=$diroutputmassaction.'/'.$filename.'_'.dol_print_date($now,'dayhourlog').'.pdf';
  383. $input_files = '';
  384. foreach($files as $f) {
  385. $input_files.=' '.escapeshellarg($f);
  386. }
  387. $cmd = 'pdftk '.$input_files.' cat output '.escapeshellarg($file);
  388. exec($cmd);
  389. if (! empty($conf->global->MAIN_UMASK))
  390. @chmod($file, octdec($conf->global->MAIN_UMASK));
  391. $langs->load("exports");
  392. setEventMessages($langs->trans('FileSuccessfullyBuilt',$filename.'_'.dol_print_date($now,'dayhourlog')), null, 'mesgs');
  393. }
  394. else
  395. {
  396. setEventMessages($langs->trans('NoPDFAvailableForDocGenAmongChecked'), null, 'errors');
  397. }
  398. }
  399. else {
  400. // Create empty PDF
  401. $pdf=pdf_getInstance();
  402. if (class_exists('TCPDF'))
  403. {
  404. $pdf->setPrintHeader(false);
  405. $pdf->setPrintFooter(false);
  406. }
  407. $pdf->SetFont(pdf_getPDFFont($outputlangs));
  408. if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
  409. // Add all others
  410. foreach($files as $file)
  411. {
  412. // Charge un document PDF depuis un fichier.
  413. $pagecount = $pdf->setSourceFile($file);
  414. for ($i = 1; $i <= $pagecount; $i++)
  415. {
  416. $tplidx = $pdf->importPage($i);
  417. $s = $pdf->getTemplatesize($tplidx);
  418. $pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L');
  419. $pdf->useTemplate($tplidx);
  420. }
  421. }
  422. // Create output dir if not exists
  423. dol_mkdir($diroutputmassaction);
  424. // Defined name of merged file
  425. $filename=strtolower(dol_sanitizeFileName($langs->transnoentities($objectlabel)));
  426. $filename=preg_replace('/\s/','_',$filename);
  427. // Save merged file
  428. if ($filter=='paye:0')
  429. {
  430. if ($option=='late') $filename.='_'.strtolower(dol_sanitizeFileName($langs->transnoentities("Unpaid"))).'_'.strtolower(dol_sanitizeFileName($langs->transnoentities("Late")));
  431. else $filename.='_'.strtolower(dol_sanitizeFileName($langs->transnoentities("Unpaid")));
  432. }
  433. if ($year) $filename.='_'.$year;
  434. if ($month) $filename.='_'.$month;
  435. if ($pagecount)
  436. {
  437. $now=dol_now();
  438. $file=$diroutputmassaction.'/'.$filename.'_'.dol_print_date($now,'dayhourlog').'.pdf';
  439. $pdf->Output($file,'F');
  440. if (! empty($conf->global->MAIN_UMASK))
  441. @chmod($file, octdec($conf->global->MAIN_UMASK));
  442. $langs->load("exports");
  443. setEventMessages($langs->trans('FileSuccessfullyBuilt',$filename.'_'.dol_print_date($now,'dayhourlog')), null, 'mesgs');
  444. }
  445. else
  446. {
  447. setEventMessages($langs->trans('NoPDFAvailableForDocGenAmongChecked'), null, 'errors');
  448. }
  449. }
  450. }
  451. // Remove a file from massaction area
  452. if ($action == 'remove_file')
  453. {
  454. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  455. $langs->load("other");
  456. $upload_dir = $diroutputmassaction;
  457. $file = $upload_dir . '/' . GETPOST('file');
  458. $ret=dol_delete_file($file);
  459. if ($ret) setEventMessages($langs->trans("FileWasRemoved", GETPOST('file')), null, 'mesgs');
  460. else setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('file')), null, 'errors');
  461. $action='';
  462. }
  463. // Delete records
  464. if (! $error && $massaction == 'delete' && $permtodelete)
  465. {
  466. $db->begin();
  467. $objecttmp=new $objectclass($db);
  468. $nbok = 0;
  469. foreach($toselect as $toselectid)
  470. {
  471. $result=$objecttmp->fetch($toselectid);
  472. if ($result > 0)
  473. {
  474. if ($objecttmp->element == 'societe') $result = $objecttmp->delete($objecttmp->id, $user, 1);
  475. else $result = $objecttmp->delete($user);
  476. if ($result <= 0)
  477. {
  478. setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
  479. $error++;
  480. break;
  481. }
  482. else $nbok++;
  483. }
  484. else
  485. {
  486. setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
  487. $error++;
  488. break;
  489. }
  490. }
  491. if (! $error)
  492. {
  493. if ($nbok > 1) setEventMessages($langs->trans("RecordsDeleted", $nbok), null, 'mesgs');
  494. else setEventMessages($langs->trans("RecordDeleted", $nbok), null, 'mesgs');
  495. $db->commit();
  496. }
  497. else
  498. {
  499. $db->rollback();
  500. }
  501. //var_dump($listofobjectthirdparties);exit;
  502. }