actions_massactions.inc.php 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514
  1. <?php
  2. /* Copyright (C) 2015-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2018-2021 Nicolas ZABOURI <info@inovea-conseil.com>
  4. * Copyright (C) 2018 Juanjo Menent <jmenent@2byte.es>
  5. * Copyright (C) 2019 Ferran Marcet <fmarcet@2byte.es>
  6. * Copyright (C) 2019-2021 Frédéric France <frederic.france@netlogic.fr>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. * or see https://www.gnu.org/
  21. */
  22. /**
  23. * \file htdocs/core/actions_massactions.inc.php
  24. * \brief Code for actions done with massaction button (send by email, merge pdf, delete, ...)
  25. */
  26. // $massaction must be defined
  27. // $objectclass and $objectlabel must be defined
  28. // $parameters, $object, $action must be defined for the hook.
  29. // $permissiontoread, $permissiontoadd, $permissiontodelete, $permissiontoclose may be defined
  30. // $uploaddir may be defined (example to $conf->projet->dir_output."/";)
  31. // $toselect may be defined
  32. // $diroutputmassaction may be defined
  33. // Protection
  34. if (empty($objectclass) || empty($uploaddir)) {
  35. dol_print_error(null, 'include of actions_massactions.inc.php is done but var $objectclass or $uploaddir was not defined');
  36. exit;
  37. }
  38. // For backward compatibility
  39. if (!empty($permtoread) && empty($permissiontoread)) {
  40. $permissiontoread = $permtoread;
  41. }
  42. if (!empty($permtocreate) && empty($permissiontoadd)) {
  43. $permissiontoadd = $permtocreate;
  44. }
  45. if (!empty($permtodelete) && empty($permissiontodelete)) {
  46. $permissiontodelete = $permtodelete;
  47. }
  48. // Mass actions. Controls on number of lines checked.
  49. $maxformassaction = (empty($conf->global->MAIN_LIMIT_FOR_MASS_ACTIONS) ? 1000 : $conf->global->MAIN_LIMIT_FOR_MASS_ACTIONS);
  50. if (!empty($massaction) && is_array($toselect) && count($toselect) < 1) {
  51. $error++;
  52. setEventMessages($langs->trans("NoRecordSelected"), null, "warnings");
  53. }
  54. if (!$error && is_array($toselect) && count($toselect) > $maxformassaction) {
  55. setEventMessages($langs->trans('TooManyRecordForMassAction', $maxformassaction), null, 'errors');
  56. $error++;
  57. }
  58. if (!$error && $massaction == 'confirm_presend' && !GETPOST('sendmail')) { // If we do not choose button send (for example when we change template or limit), we must not send email, but keep on send email form
  59. $massaction = 'presend';
  60. }
  61. if (!$error && $massaction == 'confirm_presend') {
  62. $resaction = '';
  63. $nbsent = 0;
  64. $nbignored = 0;
  65. $langs->load("mails");
  66. include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  67. $listofobjectid = array();
  68. $listofobjectthirdparties = array();
  69. $listofobjectcontacts = array();
  70. $listofobjectref = array();
  71. $contactidtosend = array();
  72. $attachedfilesThirdpartyObj = array();
  73. $oneemailperrecipient = (GETPOST('oneemailperrecipient', 'int') ? 1 : 0);
  74. if (!$error) {
  75. $thirdparty = new Societe($db);
  76. $objecttmp = new $objectclass($db);
  77. if ($objecttmp->element == 'expensereport') {
  78. $thirdparty = new User($db);
  79. }
  80. if ($objecttmp->element == 'partnership' && getDolGlobalString('PARTNERSHIP_IS_MANAGED_FOR') == 'member') {
  81. $thirdparty = new Adherent($db);
  82. }
  83. if ($objecttmp->element == 'holiday') {
  84. $thirdparty = new User($db);
  85. }
  86. foreach ($toselect as $toselectid) {
  87. $objecttmp = new $objectclass($db); // we must create new instance because instance is saved into $listofobjectref array for future use
  88. $result = $objecttmp->fetch($toselectid);
  89. if ($result > 0) {
  90. $listofobjectid[$toselectid] = $toselectid;
  91. $thirdpartyid = ($objecttmp->fk_soc ? $objecttmp->fk_soc : $objecttmp->socid);
  92. if ($objecttmp->element == 'societe') {
  93. $thirdpartyid = $objecttmp->id;
  94. }
  95. if ($objecttmp->element == 'expensereport') {
  96. $thirdpartyid = $objecttmp->fk_user_author;
  97. }
  98. if ($objecttmp->element == 'partnership' && getDolGlobalString('PARTNERSHIP_IS_MANAGED_FOR') == 'member') {
  99. $thirdpartyid = $objecttmp->fk_member;
  100. }
  101. if ($objecttmp->element == 'holiday') {
  102. $thirdpartyid = $objecttmp->fk_user;
  103. }
  104. if (empty($thirdpartyid)) {
  105. $thirdpartyid = 0;
  106. }
  107. if ($objectclass == 'Facture') {
  108. $tmparraycontact = array();
  109. $tmparraycontact = $objecttmp->liste_contact(-1, 'external', 0, 'BILLING');
  110. if (is_array($tmparraycontact) && count($tmparraycontact) > 0) {
  111. foreach ($tmparraycontact as $data_email) {
  112. $listofobjectcontacts[$toselectid][$data_email['id']] = $data_email['email'];
  113. }
  114. }
  115. } elseif ($objectclass == 'CommandeFournisseur') {
  116. $tmparraycontact = array();
  117. $tmparraycontact = $objecttmp->liste_contact(-1, 'external', 0, 'CUSTOMER');
  118. if (is_array($tmparraycontact) && count($tmparraycontact) > 0) {
  119. foreach ($tmparraycontact as $data_email) {
  120. $listofobjectcontacts[$toselectid][$data_email['id']] = $data_email['email'];
  121. }
  122. }
  123. }
  124. $listofobjectthirdparties[$thirdpartyid] = $thirdpartyid;
  125. $listofobjectref[$thirdpartyid][$toselectid] = $objecttmp;
  126. }
  127. }
  128. }
  129. // Check mandatory parameters
  130. if (GETPOST('fromtype', 'alpha') === 'user' && empty($user->email)) {
  131. $error++;
  132. setEventMessages($langs->trans("NoSenderEmailDefined"), null, 'warnings');
  133. $massaction = 'presend';
  134. }
  135. $receiver = GETPOST('receiver', 'alphawithlgt');
  136. if (!is_array($receiver)) {
  137. if (empty($receiver) || $receiver == '-1') {
  138. $receiver = array();
  139. } else {
  140. $receiver = array($receiver);
  141. }
  142. }
  143. if (!trim($_POST['sendto']) && count($receiver) == 0 && count($listofobjectthirdparties) == 1) { // if only one recipient, receiver is mandatory
  144. $error++;
  145. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Recipient")), null, 'warnings');
  146. $massaction = 'presend';
  147. }
  148. if (!GETPOST('subject', 'restricthtml')) {
  149. $error++;
  150. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("MailTopic")), null, 'warnings');
  151. $massaction = 'presend';
  152. }
  153. // Loop on each recipient/thirdparty
  154. if (!$error) {
  155. foreach ($listofobjectthirdparties as $thirdpartyid) {
  156. $result = $thirdparty->fetch($thirdpartyid);
  157. if ($result < 0) {
  158. dol_print_error($db);
  159. exit;
  160. }
  161. $sendto = '';
  162. $sendtocc = '';
  163. $sendtobcc = '';
  164. $sendtoid = array();
  165. // Define $sendto
  166. $tmparray = array();
  167. if (trim($_POST['sendto'])) {
  168. // Recipients are provided into free text
  169. $tmparray[] = trim(GETPOST('sendto', 'alphawithlgt'));
  170. }
  171. if (count($receiver) > 0) {
  172. foreach ($receiver as $key => $val) {
  173. // Recipient was provided from combo list
  174. if ($val == 'thirdparty') { // Id of third party or user
  175. $tmparray[] = $thirdparty->name.' <'.$thirdparty->email.'>';
  176. } elseif ($val && method_exists($thirdparty, 'contact_get_property')) { // Id of contact
  177. $tmparray[] = $thirdparty->contact_get_property((int) $val, 'email');
  178. $sendtoid[] = $val;
  179. }
  180. }
  181. }
  182. $sendto = implode(',', $tmparray);
  183. // Define $sendtocc
  184. $receivercc = GETPOST('receivercc', 'alphawithlgt');
  185. if (!is_array($receivercc)) {
  186. if ($receivercc == '-1') {
  187. $receivercc = array();
  188. } else {
  189. $receivercc = array($receivercc);
  190. }
  191. }
  192. $tmparray = array();
  193. if (trim($_POST['sendtocc'])) {
  194. $tmparray[] = trim(GETPOST('sendtocc', 'alphawithlgt'));
  195. }
  196. if (count($receivercc) > 0) {
  197. foreach ($receivercc as $key => $val) {
  198. // Recipient was provided from combo list
  199. if ($val == 'thirdparty') { // Id of third party
  200. $tmparray[] = $thirdparty->name.' <'.$thirdparty->email.'>';
  201. } elseif ($val) { // Id du contact
  202. $tmparray[] = $thirdparty->contact_get_property((int) $val, 'email');
  203. //$sendtoid[] = $val; TODO Add also id of contact in CC ?
  204. }
  205. }
  206. }
  207. $sendtocc = implode(',', $tmparray);
  208. //var_dump($listofobjectref);exit;
  209. $listofqualifiedobj = array();
  210. $listofqualifiedref = array();
  211. $thirdpartywithoutemail = array();
  212. foreach ($listofobjectref[$thirdpartyid] as $objectid => $objectobj) {
  213. //var_dump($thirdpartyid.' - '.$objectid.' - '.$objectobj->statut);
  214. if ($objectclass == 'Propal' && $objectobj->statut == Propal::STATUS_DRAFT) {
  215. $langs->load("errors");
  216. $nbignored++;
  217. $resaction .= '<div class="error">'.$langs->trans('ErrorOnlyProposalNotDraftCanBeSentInMassAction', $objectobj->ref).'</div><br>';
  218. continue; // Payment done or started or canceled
  219. }
  220. if ($objectclass == 'Commande' && $objectobj->statut == Commande::STATUS_DRAFT) {
  221. $langs->load("errors");
  222. $nbignored++;
  223. $resaction .= '<div class="error">'.$langs->trans('ErrorOnlyOrderNotDraftCanBeSentInMassAction', $objectobj->ref).'</div><br>';
  224. continue;
  225. }
  226. if ($objectclass == 'Facture' && $objectobj->statut == Facture::STATUS_DRAFT) {
  227. $langs->load("errors");
  228. $nbignored++;
  229. $resaction .= '<div class="error">'.$langs->trans('ErrorOnlyInvoiceValidatedCanBeSentInMassAction', $objectobj->ref).'</div><br>';
  230. continue; // Payment done or started or canceled
  231. }
  232. // Test recipient
  233. if (empty($sendto)) { // For the case, no recipient were set (multi thirdparties send)
  234. if ($objectobj->element == 'societe') {
  235. $sendto = $objectobj->email;
  236. } elseif ($objectobj->element == 'expensereport') {
  237. $fuser = new User($db);
  238. $fuser->fetch($objectobj->fk_user_author);
  239. $sendto = $fuser->email;
  240. } elseif ($objectobj->element == 'partnership' && getDolGlobalString('PARTNERSHIP_IS_MANAGED_FOR') == 'member') {
  241. $fadherent = new Adherent($db);
  242. $fadherent->fetch($objectobj->fk_member);
  243. $sendto = $fadherent->email;
  244. } elseif ($objectobj->element == 'holiday') {
  245. $fuser = new User($db);
  246. $fuser->fetch($objectobj->fk_user);
  247. $sendto = $fuser->email;
  248. } elseif ($objectobj->element == 'facture' && !empty($listofobjectcontacts[$objectid])) {
  249. $emails_to_sends = array();
  250. $objectobj->fetch_thirdparty();
  251. $contactidtosend = array();
  252. foreach ($listofobjectcontacts[$objectid] as $contactemailid => $contactemailemail) {
  253. $emails_to_sends[] = $objectobj->thirdparty->contact_get_property($contactemailid, 'email');
  254. if (!in_array($contactemailid, $contactidtosend)) {
  255. $contactidtosend[] = $contactemailid;
  256. }
  257. }
  258. if (count($emails_to_sends) > 0) {
  259. $sendto = implode(',', $emails_to_sends);
  260. }
  261. } elseif ($objectobj->element == 'order_supplier' && !empty($listofobjectcontacts[$objectid])) {
  262. $emails_to_sends = array();
  263. $objectobj->fetch_thirdparty();
  264. $contactidtosend = array();
  265. foreach ($listofobjectcontacts[$objectid] as $contactemailid => $contactemailemail) {
  266. $emails_to_sends[] = $objectobj->thirdparty->contact_get_property($contactemailid, 'email');
  267. if (!in_array($contactemailid, $contactidtosend)) {
  268. $contactidtosend[] = $contactemailid;
  269. }
  270. }
  271. if (count($emails_to_sends) > 0) {
  272. $sendto = implode(',', $emails_to_sends);
  273. }
  274. } else {
  275. $objectobj->fetch_thirdparty();
  276. $sendto = $objectobj->thirdparty->email;
  277. }
  278. }
  279. if (empty($sendto)) {
  280. if ($objectobj->element == 'societe') {
  281. $objectobj->thirdparty = $objectobj; // Hack so following code is comaptible when objectobj is a thirdparty
  282. }
  283. //print "No recipient for thirdparty ".$objectobj->thirdparty->name;
  284. $nbignored++;
  285. if (empty($thirdpartywithoutemail[$objectobj->thirdparty->id])) {
  286. $resaction .= '<div class="error">'.$langs->trans('NoRecipientEmail', $objectobj->thirdparty->name).'</div><br>';
  287. }
  288. dol_syslog('No recipient for thirdparty: '.$objectobj->thirdparty->name, LOG_WARNING);
  289. $thirdpartywithoutemail[$objectobj->thirdparty->id] = 1;
  290. continue;
  291. }
  292. if (GETPOST('addmaindocfile')) {
  293. // TODO Use future field $objectobj->fullpathdoc to know where is stored default file
  294. // TODO If not defined, use $objectobj->model_pdf (or defaut invoice config) to know what is template to use to regenerate doc.
  295. $filename = dol_sanitizeFileName($objectobj->ref).'.pdf';
  296. $subdir = '';
  297. // TODO Set subdir to be compatible with multi levels dir trees
  298. // $subdir = get_exdir($objectobj->id, 2, 0, 0, $objectobj, $objectobj->element)
  299. $filedir = $uploaddir.'/'.$subdir.dol_sanitizeFileName($objectobj->ref);
  300. $filepath = $filedir.'/'.$filename;
  301. // For supplier invoices, we use the file provided by supplier, not the one we generate
  302. if ($objectobj->element == 'invoice_supplier') {
  303. $fileparams = dol_most_recent_file($uploaddir.'/'.get_exdir($objectobj->id, 2, 0, 0, $objectobj, $objectobj->element).$objectobj->ref, preg_quote($objectobj->ref, '/').'([^\-])+');
  304. $filepath = $fileparams['fullname'];
  305. }
  306. // try to find other files generated for this object (last_main_doc)
  307. $filename_found = '';
  308. $filepath_found = '';
  309. $file_check_list = array();
  310. $file_check_list[] = array(
  311. 'name' => $filename,
  312. 'path' => $filepath,
  313. );
  314. if (!empty($conf->global->MAIL_MASS_ACTION_ADD_LAST_IF_MAIN_DOC_NOT_FOUND) && !empty($objectobj->last_main_doc)) {
  315. $file_check_list[] = array(
  316. 'name' => basename($objectobj->last_main_doc),
  317. 'path' => DOL_DATA_ROOT . '/' . $objectobj->last_main_doc,
  318. );
  319. }
  320. foreach ($file_check_list as $file_check_arr) {
  321. if (dol_is_file($file_check_arr['path'])) {
  322. $filename_found = $file_check_arr['name'];
  323. $filepath_found = $file_check_arr['path'];
  324. break;
  325. }
  326. }
  327. if ($filepath_found) {
  328. // Create form object
  329. $attachedfilesThirdpartyObj[$thirdpartyid][$objectid] = array(
  330. 'paths'=>array($filepath_found),
  331. 'names'=>array($filename_found),
  332. 'mimes'=>array(dol_mimetype($filepath_found))
  333. );
  334. } else {
  335. $nbignored++;
  336. $langs->load("errors");
  337. foreach ($file_check_list as $file_check_arr) {
  338. $resaction .= '<div class="error">'.$langs->trans('ErrorCantReadFile', $file_check_arr['path']).'</div><br>';
  339. dol_syslog('Failed to read file: '.$file_check_arr['path'], LOG_WARNING);
  340. }
  341. continue;
  342. }
  343. }
  344. // Object of thirdparty qualified, we add it
  345. $listofqualifiedobj[$objectid] = $objectobj;
  346. $listofqualifiedref[$objectid] = $objectobj->ref;
  347. //var_dump($listofqualifiedref);
  348. }
  349. // Send email if there is at least one qualified object for current thirdparty
  350. if (count($listofqualifiedobj) > 0) {
  351. $langs->load("commercial");
  352. $reg = array();
  353. $fromtype = GETPOST('fromtype');
  354. if ($fromtype === 'user') {
  355. $from = dol_string_nospecial($user->getFullName($langs), ' ', array(",")).' <'.$user->email.'>';
  356. } elseif ($fromtype === 'company') {
  357. $from = $conf->global->MAIN_INFO_SOCIETE_NOM.' <'.$conf->global->MAIN_INFO_SOCIETE_MAIL.'>';
  358. } elseif (preg_match('/user_aliases_(\d+)/', $fromtype, $reg)) {
  359. $tmp = explode(',', $user->email_aliases);
  360. $from = trim($tmp[($reg[1] - 1)]);
  361. } elseif (preg_match('/global_aliases_(\d+)/', $fromtype, $reg)) {
  362. $tmp = explode(',', $conf->global->MAIN_INFO_SOCIETE_MAIL_ALIASES);
  363. $from = trim($tmp[($reg[1] - 1)]);
  364. } elseif (preg_match('/senderprofile_(\d+)_(\d+)/', $fromtype, $reg)) {
  365. $sql = "SELECT rowid, label, email FROM ".MAIN_DB_PREFIX."c_email_senderprofile WHERE rowid = ".(int) $reg[1];
  366. $resql = $db->query($sql);
  367. $obj = $db->fetch_object($resql);
  368. if ($obj) {
  369. $from = dol_string_nospecial($obj->label, ' ', array(",")).' <'.$obj->email.'>';
  370. }
  371. } else {
  372. $from = GETPOST('fromname').' <'.GETPOST('frommail').'>';
  373. }
  374. $replyto = $from;
  375. $subject = GETPOST('subject', 'restricthtml');
  376. $message = GETPOST('message', 'restricthtml');
  377. $sendtobcc = GETPOST('sendtoccc');
  378. if ($objectclass == 'Propal') {
  379. $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO) ? '' : (($sendtobcc ? ", " : "").$conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO));
  380. }
  381. if ($objectclass == 'Commande') {
  382. $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_ORDER_TO) ? '' : (($sendtobcc ? ", " : "").$conf->global->MAIN_MAIL_AUTOCOPY_ORDER_TO));
  383. }
  384. if ($objectclass == 'Facture') {
  385. $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO) ? '' : (($sendtobcc ? ", " : "").$conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO));
  386. }
  387. if ($objectclass == 'Supplier_Proposal') {
  388. $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO) ? '' : (($sendtobcc ? ", " : "").$conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO));
  389. }
  390. if ($objectclass == 'CommandeFournisseur') {
  391. $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO) ? '' : (($sendtobcc ? ", " : "").$conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO));
  392. }
  393. if ($objectclass == 'FactureFournisseur') {
  394. $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO) ? '' : (($sendtobcc ? ", " : "").$conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO));
  395. }
  396. if ($objectclass == 'Project') {
  397. $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_PROJECT_TO) ? '' : (($sendtobcc ? ", " : "").$conf->global->MAIN_MAIL_AUTOCOPY_PROJECT_TO));
  398. }
  399. // $listofqualifiedobj is array with key = object id and value is instance of qualified objects, for the current thirdparty (but thirdparty property is not loaded yet)
  400. // $looparray will be an array with number of email to send for the current thirdparty (so 1 or n if n object for same thirdparty)
  401. $looparray = array();
  402. if (!$oneemailperrecipient) {
  403. $looparray = $listofqualifiedobj;
  404. foreach ($looparray as $key => $objecttmp) {
  405. $looparray[$key]->thirdparty = $thirdparty; // Force thirdparty on object
  406. }
  407. } else {
  408. $objectforloop = new $objectclass($db);
  409. $objectforloop->thirdparty = $thirdparty; // Force thirdparty on object (even if object was not loaded)
  410. $looparray[0] = $objectforloop;
  411. }
  412. //var_dump($looparray);exit;
  413. dol_syslog("We have set an array of ".count($looparray)." emails to send. oneemailperrecipient=".$oneemailperrecipient);
  414. //var_dump($oneemailperrecipient); var_dump($listofqualifiedobj); var_dump($listofqualifiedref);
  415. foreach ($looparray as $objectid => $objecttmp) { // $objecttmp is a real object or an empty object if we choose to send one email per thirdparty instead of one per object
  416. // Make substitution in email content
  417. if (!empty($conf->projet->enabled) && method_exists($objecttmp, 'fetch_projet') && is_null($objecttmp->project)) {
  418. $objecttmp->fetch_projet();
  419. }
  420. $substitutionarray = getCommonSubstitutionArray($langs, 0, null, $objecttmp);
  421. $substitutionarray['__ID__'] = ($oneemailperrecipient ? join(', ', array_keys($listofqualifiedobj)) : $objecttmp->id);
  422. $substitutionarray['__REF__'] = ($oneemailperrecipient ? join(', ', $listofqualifiedref) : $objecttmp->ref);
  423. $substitutionarray['__EMAIL__'] = $thirdparty->email;
  424. $substitutionarray['__CHECK_READ__'] = '<img src="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-read.php?tag='.urlencode($thirdparty->tag).'&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).'" width="1" height="1" style="width:1px;height:1px" border="0"/>';
  425. $parameters = array('mode'=>'formemail');
  426. if (!empty($listofobjectthirdparties)) {
  427. $parameters['listofobjectthirdparties'] = $listofobjectthirdparties;
  428. }
  429. if (!empty($listofobjectref)) {
  430. $parameters['listofobjectref'] = $listofobjectref;
  431. }
  432. complete_substitutions_array($substitutionarray, $langs, $objecttmp, $parameters);
  433. $subjectreplaced = make_substitutions($subject, $substitutionarray);
  434. $messagereplaced = make_substitutions($message, $substitutionarray);
  435. $attachedfiles = array('paths'=>array(), 'names'=>array(), 'mimes'=>array());
  436. if ($oneemailperrecipient) {
  437. // if "one email per recipient" is check we must collate $attachedfiles by thirdparty
  438. if (is_array($attachedfilesThirdpartyObj[$thirdparty->id]) && count($attachedfilesThirdpartyObj[$thirdparty->id])) {
  439. foreach ($attachedfilesThirdpartyObj[$thirdparty->id] as $keyObjId => $objAttachedFiles) {
  440. // Create form object
  441. $attachedfiles = array(
  442. 'paths'=>array_merge($attachedfiles['paths'], $objAttachedFiles['paths']),
  443. 'names'=>array_merge($attachedfiles['names'], $objAttachedFiles['names']),
  444. 'mimes'=>array_merge($attachedfiles['mimes'], $objAttachedFiles['mimes'])
  445. );
  446. }
  447. }
  448. } elseif (!empty($attachedfilesThirdpartyObj[$thirdparty->id][$objectid])) {
  449. // Create form object
  450. // if "one email per recipient" isn't check we must separate $attachedfiles by object
  451. $attachedfiles = $attachedfilesThirdpartyObj[$thirdparty->id][$objectid];
  452. }
  453. $filepath = $attachedfiles['paths'];
  454. $filename = $attachedfiles['names'];
  455. $mimetype = $attachedfiles['mimes'];
  456. // Define the trackid when emails sent from the mass action
  457. if ($oneemailperrecipient) {
  458. $trackid = 'thi'.$thirdparty->id;
  459. if ($objecttmp->element == 'expensereport') {
  460. $trackid = 'use'.$thirdparty->id;
  461. }
  462. if ($objecttmp->element == 'holiday') {
  463. $trackid = 'use'.$thirdparty->id;
  464. }
  465. } else {
  466. $trackid = strtolower(get_class($objecttmp));
  467. if (get_class($objecttmp) == 'Contrat') {
  468. $trackid = 'con';
  469. }
  470. if (get_class($objecttmp) == 'Propal') {
  471. $trackid = 'pro';
  472. }
  473. if (get_class($objecttmp) == 'Commande') {
  474. $trackid = 'ord';
  475. }
  476. if (get_class($objecttmp) == 'Facture') {
  477. $trackid = 'inv';
  478. }
  479. if (get_class($objecttmp) == 'Supplier_Proposal') {
  480. $trackid = 'spr';
  481. }
  482. if (get_class($objecttmp) == 'CommandeFournisseur') {
  483. $trackid = 'sor';
  484. }
  485. if (get_class($objecttmp) == 'FactureFournisseur') {
  486. $trackid = 'sin';
  487. }
  488. $trackid .= $objecttmp->id;
  489. }
  490. //var_dump($filepath);
  491. //var_dump($trackid);exit;
  492. //var_dump($subjectreplaced);
  493. if (empty($sendcontext)) {
  494. $sendcontext = 'standard';
  495. }
  496. // Send mail (substitutionarray must be done just before this)
  497. require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
  498. $mailfile = new CMailFile($subjectreplaced, $sendto, $from, $messagereplaced, $filepath, $mimetype, $filename, $sendtocc, $sendtobcc, $deliveryreceipt, -1, '', '', $trackid, '', $sendcontext);
  499. if ($mailfile->error) {
  500. $resaction .= '<div class="error">'.$mailfile->error.'</div>';
  501. } else {
  502. $result = $mailfile->sendfile();
  503. if ($result) {
  504. $resaction .= $langs->trans('MailSuccessfulySent', $mailfile->getValidAddress($from, 2), $mailfile->getValidAddress($sendto, 2)).'<br>'; // Must not contain "
  505. $error = 0;
  506. // Insert logs into agenda
  507. foreach ($listofqualifiedobj as $objid2 => $objectobj2) {
  508. if ((!$oneemailperrecipient) && $objid2 != $objectid) {
  509. continue; // We discard this pass to avoid duplicate with other pass in looparray at higher level
  510. }
  511. dol_syslog("Try to insert email event into agenda for objid=".$objid2." => objectobj=".get_class($objectobj2));
  512. /*if ($objectclass == 'Propale') $actiontypecode='AC_PROP';
  513. if ($objectclass == 'Commande') $actiontypecode='AC_COM';
  514. if ($objectclass == 'Facture') $actiontypecode='AC_FAC';
  515. if ($objectclass == 'Supplier_Proposal') $actiontypecode='AC_SUP_PRO';
  516. if ($objectclass == 'CommandeFournisseur') $actiontypecode='AC_SUP_ORD';
  517. if ($objectclass == 'FactureFournisseur') $actiontypecode='AC_SUP_INV';*/
  518. $actionmsg = $langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto;
  519. if ($message) {
  520. if ($sendtocc) {
  521. $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc').": ".$sendtocc);
  522. }
  523. $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic').": ".$subjectreplaced);
  524. $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody').":");
  525. $actionmsg = dol_concatdesc($actionmsg, $messagereplaced);
  526. }
  527. $actionmsg2 = '';
  528. // Initialisation donnees
  529. $objectobj2->sendtoid = (empty($contactidtosend) ? 0 : $contactidtosend);
  530. $objectobj2->actionmsg = $actionmsg; // Long text
  531. $objectobj2->actionmsg2 = $actionmsg2; // Short text
  532. $objectobj2->fk_element = $objid2;
  533. $objectobj2->elementtype = $objectobj2->element;
  534. $triggername = strtoupper(get_class($objectobj2)).'_SENTBYMAIL';
  535. if ($triggername == 'SOCIETE_SENTBYMAIL') {
  536. $triggername = 'COMPANY_SENTBYMAIL';
  537. }
  538. if ($triggername == 'CONTRAT_SENTBYMAIL') {
  539. $triggername = 'CONTRACT_SENTBYMAIL';
  540. }
  541. if ($triggername == 'COMMANDE_SENTBYMAIL') {
  542. $triggername = 'ORDER_SENTBYMAIL';
  543. }
  544. if ($triggername == 'FACTURE_SENTBYMAIL') {
  545. $triggername = 'BILL_SENTBYMAIL';
  546. }
  547. if ($triggername == 'EXPEDITION_SENTBYMAIL') {
  548. $triggername = 'SHIPPING_SENTBYMAIL';
  549. }
  550. if ($triggername == 'COMMANDEFOURNISSEUR_SENTBYMAIL') {
  551. $triggername = 'ORDER_SUPPLIER_SENTBYMAIL';
  552. }
  553. if ($triggername == 'FACTUREFOURNISSEUR_SENTBYMAIL') {
  554. $triggername = 'BILL_SUPPLIER_SENTBYMAIL';
  555. }
  556. if ($triggername == 'SUPPLIERPROPOSAL_SENTBYMAIL') {
  557. $triggername = 'PROPOSAL_SUPPLIER_SENTBYMAIL';
  558. }
  559. if (!empty($triggername)) {
  560. // Call trigger
  561. $result = $objectobj2->call_trigger($triggername, $user);
  562. if ($result < 0) {
  563. $error++;
  564. }
  565. // End call triggers
  566. if ($error) {
  567. setEventMessages($db->lasterror(), $errors, 'errors');
  568. dol_syslog("Error in trigger ".$triggername.' '.$db->lasterror(), LOG_ERR);
  569. }
  570. }
  571. $nbsent++; // Nb of object sent
  572. }
  573. } else {
  574. $langs->load("other");
  575. if ($mailfile->error) {
  576. $resaction .= $langs->trans('ErrorFailedToSendMail', $from, $sendto);
  577. $resaction .= '<br><div class="error">'.$mailfile->error.'</div>';
  578. } elseif (!empty($conf->global->MAIN_DISABLE_ALL_MAILS)) {
  579. $resaction .= '<div class="warning">No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS</div>';
  580. } else {
  581. $resaction .= $langs->trans('ErrorFailedToSendMail', $from, $sendto) . '<br><div class="error">(unhandled error)</div>';
  582. }
  583. }
  584. }
  585. }
  586. }
  587. }
  588. $resaction .= ($resaction ? '<br>' : $resaction);
  589. $resaction .= '<strong>'.$langs->trans("ResultOfMailSending").':</strong><br>'."\n";
  590. $resaction .= $langs->trans("NbSelected").': '.count($toselect)."\n<br>";
  591. $resaction .= $langs->trans("NbIgnored").': '.($nbignored ? $nbignored : 0)."\n<br>";
  592. $resaction .= $langs->trans("NbSent").': '.($nbsent ? $nbsent : 0)."\n<br>";
  593. if ($nbsent) {
  594. $action = ''; // Do not show form post if there was at least one successfull sent
  595. //setEventMessages($langs->trans("EMailSentToNRecipients", $nbsent.'/'.count($toselect)), null, 'mesgs');
  596. setEventMessages($langs->trans("EMailSentForNElements", $nbsent.'/'.count($toselect)), null, 'mesgs');
  597. setEventMessages($resaction, null, 'mesgs');
  598. } else {
  599. //setEventMessages($langs->trans("EMailSentToNRecipients", 0), null, 'warnings'); // May be object has no generated PDF file
  600. setEventMessages($resaction, null, 'warnings');
  601. }
  602. $action = 'list';
  603. $massaction = '';
  604. }
  605. }
  606. if (!$error && $massaction == 'cancelorders') {
  607. $db->begin();
  608. $nbok = 0;
  609. $orders = GETPOST('toselect', 'array');
  610. foreach ($orders as $id_order) {
  611. $cmd = new Commande($db);
  612. if ($cmd->fetch($id_order) <= 0) {
  613. continue;
  614. }
  615. if ($cmd->statut != Commande::STATUS_VALIDATED) {
  616. $langs->load('errors');
  617. setEventMessages($langs->trans("ErrorObjectMustHaveStatusValidToBeCanceled", $cmd->ref), null, 'errors');
  618. $error++;
  619. break;
  620. } else {
  621. // TODO We do not provide warehouse so no stock change here for the moment.
  622. $result = $cmd->cancel();
  623. }
  624. if ($result < 0) {
  625. setEventMessages($cmd->error, $cmd->errors, 'errors');
  626. $error++;
  627. break;
  628. } else {
  629. $nbok++;
  630. }
  631. }
  632. if (!$error) {
  633. if ($nbok > 1) {
  634. setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
  635. } else {
  636. setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
  637. }
  638. $db->commit();
  639. } else {
  640. $db->rollback();
  641. }
  642. }
  643. if (!$error && $massaction == "builddoc" && $permissiontoread && !GETPOST('button_search')) {
  644. if (empty($diroutputmassaction)) {
  645. dol_print_error(null, 'include of actions_massactions.inc.php is done but var $diroutputmassaction was not defined');
  646. exit;
  647. }
  648. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  649. require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
  650. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  651. $objecttmp = new $objectclass($db);
  652. $listofobjectid = array();
  653. $listofobjectthirdparties = array();
  654. $listofobjectref = array();
  655. foreach ($toselect as $toselectid) {
  656. $objecttmp = new $objectclass($db); // must create new instance because instance is saved into $listofobjectref array for future use
  657. $result = $objecttmp->fetch($toselectid);
  658. if ($result > 0) {
  659. $listofobjectid[$toselectid] = $toselectid;
  660. $thirdpartyid = $objecttmp->fk_soc ? $objecttmp->fk_soc : $objecttmp->socid;
  661. $listofobjectthirdparties[$thirdpartyid] = $thirdpartyid;
  662. $listofobjectref[$toselectid] = $objecttmp->ref;
  663. }
  664. }
  665. $arrayofinclusion = array();
  666. foreach ($listofobjectref as $tmppdf) {
  667. $arrayofinclusion[] = '^'.preg_quote(dol_sanitizeFileName($tmppdf), '/').'\.pdf$';
  668. }
  669. foreach ($listofobjectref as $tmppdf) {
  670. $arrayofinclusion[] = '^'.preg_quote(dol_sanitizeFileName($tmppdf), '/').'_[a-zA-Z0-9-_]+\.pdf$'; // To include PDF generated from ODX files
  671. }
  672. $listoffiles = dol_dir_list($uploaddir, 'all', 1, implode('|', $arrayofinclusion), '\.meta$|\.png', 'date', SORT_DESC, 0, true);
  673. // build list of files with full path
  674. $files = array();
  675. foreach ($listofobjectref as $basename) {
  676. $basename = dol_sanitizeFileName($basename);
  677. foreach ($listoffiles as $filefound) {
  678. if (strstr($filefound["name"], $basename)) {
  679. $files[] = $uploaddir.'/'.$basename.'/'.$filefound["name"];
  680. break;
  681. }
  682. }
  683. }
  684. // Define output language (Here it is not used because we do only merging existing PDF)
  685. $outputlangs = $langs;
  686. $newlang = '';
  687. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
  688. $newlang = GETPOST('lang_id', 'aZ09');
  689. }
  690. //elseif ($conf->global->MAIN_MULTILANGS && empty($newlang) && is_object($objecttmp->thirdparty)) { // On massaction, we can have several values for $objecttmp->thirdparty
  691. // $newlang = $objecttmp->thirdparty->default_lang;
  692. //}
  693. if (!empty($newlang)) {
  694. $outputlangs = new Translate("", $conf);
  695. $outputlangs->setDefaultLang($newlang);
  696. }
  697. if (!empty($conf->global->USE_PDFTK_FOR_PDF_CONCAT)) {
  698. // Create output dir if not exists
  699. dol_mkdir($diroutputmassaction);
  700. // Defined name of merged file
  701. $filename = strtolower(dol_sanitizeFileName($langs->transnoentities($objectlabel)));
  702. $filename = preg_replace('/\s/', '_', $filename);
  703. // Save merged file
  704. if (in_array($objecttmp->element, array('facture', 'facture_fournisseur')) && $search_status == Facture::STATUS_VALIDATED) {
  705. if ($option == 'late') {
  706. $filename .= '_'.strtolower(dol_sanitizeFileName($langs->transnoentities("Unpaid"))).'_'.strtolower(dol_sanitizeFileName($langs->transnoentities("Late")));
  707. } else {
  708. $filename .= '_'.strtolower(dol_sanitizeFileName($langs->transnoentities("Unpaid")));
  709. }
  710. }
  711. if ($year) {
  712. $filename .= '_'.$year;
  713. }
  714. if ($month) {
  715. $filename .= '_'.$month;
  716. }
  717. if (count($files) > 0) {
  718. $now = dol_now();
  719. $file = $diroutputmassaction.'/'.$filename.'_'.dol_print_date($now, 'dayhourlog').'.pdf';
  720. $input_files = '';
  721. foreach ($files as $f) {
  722. $input_files .= ' '.escapeshellarg($f);
  723. }
  724. $cmd = 'pdftk '.$input_files.' cat output '.escapeshellarg($file);
  725. exec($cmd);
  726. // check if pdftk is installed
  727. if (file_exists($file)) {
  728. if (!empty($conf->global->MAIN_UMASK)) {
  729. @chmod($file, octdec($conf->global->MAIN_UMASK));
  730. }
  731. $langs->load("exports");
  732. setEventMessages($langs->trans('FileSuccessfullyBuilt', $filename.'_'.dol_print_date($now, 'dayhourlog')), null, 'mesgs');
  733. } else {
  734. setEventMessages($langs->trans('ErrorPDFTkOutputFileNotFound'), null, 'errors');
  735. }
  736. } else {
  737. setEventMessages($langs->trans('NoPDFAvailableForDocGenAmongChecked'), null, 'errors');
  738. }
  739. } else {
  740. // Create empty PDF
  741. $formatarray = pdf_getFormat();
  742. $page_largeur = $formatarray['width'];
  743. $page_hauteur = $formatarray['height'];
  744. $format = array($page_largeur, $page_hauteur);
  745. $pdf = pdf_getInstance($format);
  746. if (class_exists('TCPDF')) {
  747. $pdf->setPrintHeader(false);
  748. $pdf->setPrintFooter(false);
  749. }
  750. $pdf->SetFont(pdf_getPDFFont($outputlangs));
  751. if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) {
  752. $pdf->SetCompression(false);
  753. }
  754. // Add all others
  755. foreach ($files as $file) {
  756. // Charge un document PDF depuis un fichier.
  757. $pagecount = $pdf->setSourceFile($file);
  758. for ($i = 1; $i <= $pagecount; $i++) {
  759. $tplidx = $pdf->importPage($i);
  760. $s = $pdf->getTemplatesize($tplidx);
  761. $pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L');
  762. $pdf->useTemplate($tplidx);
  763. }
  764. }
  765. // Create output dir if not exists
  766. dol_mkdir($diroutputmassaction);
  767. // Defined name of merged file
  768. $filename = strtolower(dol_sanitizeFileName($langs->transnoentities($objectlabel)));
  769. $filename = preg_replace('/\s/', '_', $filename);
  770. // Save merged file
  771. if (in_array($objecttmp->element, array('facture', 'facture_fournisseur')) && $search_status == Facture::STATUS_VALIDATED) {
  772. if ($option == 'late') {
  773. $filename .= '_'.strtolower(dol_sanitizeFileName($langs->transnoentities("Unpaid"))).'_'.strtolower(dol_sanitizeFileName($langs->transnoentities("Late")));
  774. } else {
  775. $filename .= '_'.strtolower(dol_sanitizeFileName($langs->transnoentities("Unpaid")));
  776. }
  777. }
  778. if ($year) {
  779. $filename .= '_'.$year;
  780. }
  781. if ($month) {
  782. $filename .= '_'.$month;
  783. }
  784. if ($pagecount) {
  785. $now = dol_now();
  786. $file = $diroutputmassaction.'/'.$filename.'_'.dol_print_date($now, 'dayhourlog').'.pdf';
  787. $pdf->Output($file, 'F');
  788. if (!empty($conf->global->MAIN_UMASK)) {
  789. @chmod($file, octdec($conf->global->MAIN_UMASK));
  790. }
  791. $langs->load("exports");
  792. setEventMessages($langs->trans('FileSuccessfullyBuilt', $filename.'_'.dol_print_date($now, 'dayhourlog')), null, 'mesgs');
  793. } else {
  794. setEventMessages($langs->trans('NoPDFAvailableForDocGenAmongChecked'), null, 'errors');
  795. }
  796. }
  797. }
  798. // Remove a file from massaction area
  799. if ($action == 'remove_file') {
  800. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  801. $langs->load("other");
  802. $upload_dir = $diroutputmassaction;
  803. $file = $upload_dir.'/'.GETPOST('file');
  804. $ret = dol_delete_file($file);
  805. if ($ret) {
  806. setEventMessages($langs->trans("FileWasRemoved", GETPOST('file')), null, 'mesgs');
  807. } else {
  808. setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('file')), null, 'errors');
  809. }
  810. $action = '';
  811. }
  812. // Validate records
  813. if (!$error && $massaction == 'validate' && $permissiontoadd) {
  814. $objecttmp = new $objectclass($db);
  815. if (($objecttmp->element == 'facture' || $objecttmp->element == 'invoice') && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_BILL)) {
  816. $langs->load("errors");
  817. setEventMessages($langs->trans('ErrorMassValidationNotAllowedWhenStockIncreaseOnAction'), null, 'errors');
  818. $error++;
  819. }
  820. if ($objecttmp->element == 'invoice_supplier' && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL)) {
  821. $langs->load("errors");
  822. setEventMessages($langs->trans('ErrorMassValidationNotAllowedWhenStockIncreaseOnAction'), null, 'errors');
  823. $error++;
  824. }
  825. if ($objecttmp->element == 'facture') {
  826. if (!empty($toselect) && !empty($conf->global->INVOICE_CHECK_POSTERIOR_DATE)) {
  827. // order $toselect by date
  828. $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."facture";
  829. $sql .= " WHERE rowid IN (".$db->sanitize(implode(",", $toselect)).")";
  830. $sql .= " ORDER BY datef";
  831. $resql = $db->query($sql);
  832. if ($resql) {
  833. $toselectnew = [];
  834. while ( !empty($arr = $db->fetch_row($resql))) {
  835. $toselectnew[] = $arr[0];
  836. }
  837. $toselect = (empty($toselectnew)) ? $toselect : $toselectnew;
  838. } else {
  839. dol_print_error($db);
  840. $error++;
  841. }
  842. }
  843. }
  844. if (!$error) {
  845. $db->begin();
  846. $nbok = 0;
  847. foreach ($toselect as $toselectid) {
  848. $result = $objecttmp->fetch($toselectid);
  849. if ($result > 0) {
  850. $result = $objecttmp->validate($user);
  851. if ($result == 0) {
  852. $langs->load("errors");
  853. setEventMessages($langs->trans("ErrorObjectMustHaveStatusDraftToBeValidated", $objecttmp->ref), null, 'errors');
  854. $error++;
  855. break;
  856. } elseif ($result < 0) {
  857. setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
  858. $error++;
  859. break;
  860. } else {
  861. // validate() rename pdf but do not regenerate
  862. // Define output language
  863. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
  864. $outputlangs = $langs;
  865. $newlang = '';
  866. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
  867. $newlang = GETPOST('lang_id', 'aZ09');
  868. }
  869. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
  870. $newlang = $objecttmp->thirdparty->default_lang;
  871. }
  872. if (!empty($newlang)) {
  873. $outputlangs = new Translate("", $conf);
  874. $outputlangs->setDefaultLang($newlang);
  875. $outputlangs->load('products');
  876. }
  877. $model = $objecttmp->model_pdf;
  878. $ret = $objecttmp->fetch($objecttmp->id); // Reload to get new records
  879. // To be sure vars is defined
  880. $hidedetails = !empty($hidedetails) ? $hidedetails : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0);
  881. $hidedesc = !empty($hidedesc) ? $hidedesc : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0);
  882. $hideref = !empty($hideref) ? $hideref : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0);
  883. $moreparams = !empty($moreparams) ? $moreparams : null;
  884. $result = $objecttmp->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
  885. if ($result < 0) {
  886. setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
  887. }
  888. }
  889. $nbok++;
  890. }
  891. } else {
  892. setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
  893. $error++;
  894. break;
  895. }
  896. }
  897. if (!$error) {
  898. if ($nbok > 1) {
  899. setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
  900. } else {
  901. setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs');
  902. }
  903. $db->commit();
  904. } else {
  905. $db->rollback();
  906. }
  907. //var_dump($listofobjectthirdparties);exit;
  908. }
  909. }
  910. //var_dump($_POST);var_dump($massaction);exit;
  911. // Delete record from mass action (massaction = 'delete' for direct delete, action/confirm='delete'/'yes' with a confirmation step before)
  912. if (!$error && ($massaction == 'delete' || ($action == 'delete' && $confirm == 'yes')) && $permissiontodelete) {
  913. $db->begin();
  914. $objecttmp = new $objectclass($db);
  915. $nbok = 0;
  916. $TMsg = array();
  917. foreach ($toselect as $toselectid) {
  918. $result = $objecttmp->fetch($toselectid);
  919. if ($result > 0) {
  920. // Refuse deletion for some objects/status
  921. if ($objectclass == 'Facture' && empty($conf->global->INVOICE_CAN_ALWAYS_BE_REMOVED) && $objecttmp->status != Facture::STATUS_DRAFT) {
  922. $langs->load("errors");
  923. $nbignored++;
  924. $TMsg[] = '<div class="error">'.$langs->trans('ErrorOnlyDraftStatusCanBeDeletedInMassAction', $objecttmp->ref).'</div><br>';
  925. continue;
  926. }
  927. if (method_exists($objecttmp, 'is_erasable') && $objecttmp->is_erasable() <= 0) {
  928. $langs->load("errors");
  929. $nbignored++;
  930. $TMsg[] = '<div class="error">'.$langs->trans('ErrorRecordHasChildren').' '.$objecttmp->ref.'</div><br>';
  931. continue;
  932. }
  933. if ($objectclass == 'Holiday' && ! in_array($objecttmp->statut, array(Holiday::STATUS_DRAFT, Holiday::STATUS_CANCELED, Holiday::STATUS_REFUSED))) {
  934. $nbignored++;
  935. $resaction .= '<div class="error">'.$langs->trans('ErrorLeaveRequestMustBeDraftCanceledOrRefusedToBeDeleted', $objecttmp->ref).'</div><br>';
  936. continue;
  937. }
  938. if ($objectclass == "Task" && $objecttmp->hasChildren() > 0) {
  939. $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task SET fk_task_parent = 0 WHERE fk_task_parent = ".((int) $objecttmp->id);
  940. $res = $db->query($sql);
  941. if (!$res) {
  942. setEventMessage('ErrorRecordParentingNotModified', 'errors');
  943. $error++;
  944. }
  945. }
  946. if (in_array($objecttmp->element, array('societe', 'member'))) {
  947. $result = $objecttmp->delete($objecttmp->id, $user, 1);
  948. } else {
  949. $result = $objecttmp->delete($user);
  950. }
  951. if (empty($result)) { // if delete returns 0, there is at least one object linked
  952. $TMsg = array_merge($objecttmp->errors, $TMsg);
  953. } elseif ($result < 0) { // if delete returns is < 0, there is an error, we break and rollback later
  954. setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
  955. $error++;
  956. break;
  957. } else {
  958. $nbok++;
  959. }
  960. } else {
  961. setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
  962. $error++;
  963. break;
  964. }
  965. }
  966. if (empty($error)) {
  967. // Message for elements well deleted
  968. if ($nbok > 1) {
  969. setEventMessages($langs->trans("RecordsDeleted", $nbok), null, 'mesgs');
  970. } elseif ($nbok > 0) {
  971. setEventMessages($langs->trans("RecordDeleted", $nbok), null, 'mesgs');
  972. } else {
  973. setEventMessages($langs->trans("NoRecordDeleted"), null, 'mesgs');
  974. }
  975. // Message for elements which can't be deleted
  976. if (!empty($TMsg)) {
  977. sort($TMsg);
  978. setEventMessages('', array_unique($TMsg), 'warnings');
  979. }
  980. $db->commit();
  981. } else {
  982. $db->rollback();
  983. }
  984. //var_dump($listofobjectthirdparties);exit;
  985. }
  986. // Generate document foreach object according to model linked to object
  987. // @todo : propose model selection
  988. if (!$error && $massaction == 'generate_doc' && $permissiontoread) {
  989. $db->begin();
  990. $objecttmp = new $objectclass($db);
  991. $nbok = 0;
  992. foreach ($toselect as $toselectid) {
  993. $result = $objecttmp->fetch($toselectid);
  994. if ($result > 0) {
  995. $outputlangs = $langs;
  996. $newlang = '';
  997. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
  998. $newlang = GETPOST('lang_id', 'aZ09');
  999. }
  1000. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && isset($objecttmp->thirdparty->default_lang)) {
  1001. $newlang = $objecttmp->thirdparty->default_lang; // for proposal, order, invoice, ...
  1002. }
  1003. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && isset($objecttmp->default_lang)) {
  1004. $newlang = $objecttmp->default_lang; // for thirdparty
  1005. }
  1006. if (!empty($newlang)) {
  1007. $outputlangs = new Translate("", $conf);
  1008. $outputlangs->setDefaultLang($newlang);
  1009. }
  1010. // To be sure vars is defined
  1011. if (empty($hidedetails)) {
  1012. $hidedetails = (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0);
  1013. }
  1014. if (empty($hidedesc)) {
  1015. $hidedesc = (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0);
  1016. }
  1017. if (empty($hideref)) {
  1018. $hideref = (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0);
  1019. }
  1020. if (empty($moreparams)) {
  1021. $moreparams = null;
  1022. }
  1023. $result = $objecttmp->generateDocument($objecttmp->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
  1024. if ($result <= 0) {
  1025. setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
  1026. $error++;
  1027. break;
  1028. } else {
  1029. $nbok++;
  1030. }
  1031. } else {
  1032. setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
  1033. $error++;
  1034. break;
  1035. }
  1036. }
  1037. if (!$error) {
  1038. if ($nbok > 1) {
  1039. setEventMessages($langs->trans("RecordsGenerated", $nbok), null, 'mesgs');
  1040. } else {
  1041. setEventMessages($langs->trans("RecordGenerated", $nbok), null, 'mesgs');
  1042. }
  1043. $db->commit();
  1044. } else {
  1045. $db->rollback();
  1046. }
  1047. }
  1048. if (!$error && ($action == 'affecttag' && $confirm == 'yes') && $permissiontoadd) {
  1049. $db->begin();
  1050. $affecttag_type=GETPOST('affecttag_type', 'alpha');
  1051. if (!empty($affecttag_type)) {
  1052. $affecttag_type_array=explode(',', $affecttag_type);
  1053. } else {
  1054. setEventMessage('CategTypeNotFound', 'errors');
  1055. }
  1056. if (!empty($affecttag_type_array)) {
  1057. //check if tag type submited exists into Tag Map categorie class
  1058. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  1059. $categ = new Categorie($db);
  1060. $to_affecttag_type_array=array();
  1061. $categ_type_array=$categ->getMapList();
  1062. foreach ($categ_type_array as $categdef) {
  1063. if (in_array($categdef['code'], $affecttag_type_array)) {
  1064. $to_affecttag_type_array[] = $categdef['code'];
  1065. }
  1066. }
  1067. //For each valid categ type set common categ
  1068. $nbok = 0;
  1069. if (!empty($to_affecttag_type_array)) {
  1070. foreach ($to_affecttag_type_array as $categ_type) {
  1071. $contcats = GETPOST('contcats_' . $categ_type, 'array');
  1072. //var_dump($toselect);exit;
  1073. foreach ($toselect as $toselectid) {
  1074. $result = $object->fetch($toselectid);
  1075. //var_dump($contcats);exit;
  1076. if ($result > 0) {
  1077. $result = $object->setCategoriesCommon($contcats, $categ_type, false);
  1078. if ($result > 0) {
  1079. $nbok++;
  1080. } else {
  1081. setEventMessages($object->error, $object->errors, 'errors');
  1082. }
  1083. } else {
  1084. setEventMessages($object->error, $object->errors, 'errors');
  1085. $error++;
  1086. break;
  1087. }
  1088. }
  1089. }
  1090. }
  1091. }
  1092. if (!$error) {
  1093. if ($nbok > 1) {
  1094. setEventMessages($langs->trans("RecordsModified", $nbok), null);
  1095. } else {
  1096. setEventMessages($langs->trans("RecordsModified", $nbok), null);
  1097. }
  1098. $db->commit();
  1099. $toselect=array();
  1100. } else {
  1101. $db->rollback();
  1102. }
  1103. }
  1104. if (!$error && ($massaction == 'enable' || ($action == 'enable' && $confirm == 'yes')) && $permissiontoadd) {
  1105. $db->begin();
  1106. $objecttmp = new $objectclass($db);
  1107. $nbok = 0;
  1108. foreach ($toselect as $toselectid) {
  1109. $result = $objecttmp->fetch($toselectid);
  1110. if ($result>0) {
  1111. if (in_array($objecttmp->element, array('societe'))) {
  1112. $result =$objecttmp->setStatut(1);
  1113. }
  1114. if ($result <= 0) {
  1115. setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
  1116. $error++;
  1117. break;
  1118. } else {
  1119. $nbok++;
  1120. }
  1121. } else {
  1122. setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
  1123. $error++;
  1124. break;
  1125. }
  1126. }
  1127. if (!$error) {
  1128. if ($nbok > 1) {
  1129. setEventMessages($langs->trans("RecordsEnabled", $nbok), null, 'mesgs');
  1130. } else {
  1131. setEventMessages($langs->trans("RecordEnabled"), null, 'mesgs');
  1132. }
  1133. $db->commit();
  1134. } else {
  1135. $db->rollback();
  1136. }
  1137. }
  1138. if (!$error && ($massaction == 'disable' || ($action == 'disable' && $confirm == 'yes')) && $permissiontoadd) {
  1139. $db->begin();
  1140. $objecttmp = new $objectclass($db);
  1141. $nbok = 0;
  1142. foreach ($toselect as $toselectid) {
  1143. $result = $objecttmp->fetch($toselectid);
  1144. if ($result>0) {
  1145. if (in_array($objecttmp->element, array('societe'))) {
  1146. $result =$objecttmp->setStatut(0);
  1147. }
  1148. if ($result <= 0) {
  1149. setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
  1150. $error++;
  1151. break;
  1152. } else {
  1153. $nbok++;
  1154. }
  1155. } else {
  1156. setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
  1157. $error++;
  1158. break;
  1159. }
  1160. }
  1161. if (!$error) {
  1162. if ($nbok > 1) {
  1163. setEventMessages($langs->trans("RecordsDisabled", $nbok), null, 'mesgs');
  1164. } else {
  1165. setEventMessages($langs->trans("RecordDisabled"), null, 'mesgs');
  1166. }
  1167. $db->commit();
  1168. } else {
  1169. $db->rollback();
  1170. }
  1171. }
  1172. if (!$error && $action == 'confirm_edit_value_extrafields' && $confirm == 'yes' && $permissiontoadd) {
  1173. $db->begin();
  1174. $objecttmp = new $objectclass($db);
  1175. $e = new ExtraFields($db);// fetch optionals attributes and labels
  1176. $e->fetch_name_optionals_label($objecttmp->table_element);
  1177. $nbok = 0;
  1178. $extrafieldKeyToUpdate = GETPOST('extrafield-key-to-update');
  1179. foreach ($toselect as $toselectid) {
  1180. /** @var CommonObject $objecttmp */
  1181. $objecttmp = new $objectclass($db); // to avoid ghost data
  1182. $result = $objecttmp->fetch($toselectid);
  1183. if ($result>0) {
  1184. // Fill array 'array_options' with data from add form
  1185. $ret = $e->setOptionalsFromPost(null, $objecttmp, $extrafieldKeyToUpdate);
  1186. if ($ret > 0) {
  1187. $objecttmp->insertExtraFields();
  1188. } else {
  1189. $error++;
  1190. setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
  1191. }
  1192. } else {
  1193. setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
  1194. $error++;
  1195. break;
  1196. }
  1197. }
  1198. if (!$error) {
  1199. if ($nbok > 1) {
  1200. setEventMessages($langs->trans("RecordsDisabled", $nbok), null, 'mesgs');
  1201. } else {
  1202. setEventMessages($langs->trans("save"), null, 'mesgs');
  1203. }
  1204. $db->commit();
  1205. } else {
  1206. $db->rollback();
  1207. }
  1208. }
  1209. if (!$error && ($massaction == 'affectcommercial' || ($action == 'affectcommercial' && $confirm == 'yes')) && $permissiontoadd) {
  1210. $db->begin();
  1211. $objecttmp = new $objectclass($db);
  1212. $nbok = 0;
  1213. foreach ($toselect as $toselectid) {
  1214. $result = $objecttmp->fetch($toselectid);
  1215. if ($result>0) {
  1216. if (in_array($objecttmp->element, array('societe'))) {
  1217. $result = $objecttmp->setSalesRep(GETPOST("commercial", "alpha"));
  1218. }
  1219. if ($result <= 0) {
  1220. setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
  1221. $error++;
  1222. break;
  1223. } else {
  1224. $nbok++;
  1225. }
  1226. } else {
  1227. setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
  1228. $error++;
  1229. break;
  1230. }
  1231. }
  1232. if (!$error) {
  1233. if ($nbok > 1) {
  1234. setEventMessages($langs->trans("CommercialsAffected", $nbok), null, 'mesgs');
  1235. } else {
  1236. setEventMessages($langs->trans("CommercialAffected"), null, 'mesgs');
  1237. }
  1238. $db->commit();
  1239. } else {
  1240. $db->rollback();
  1241. }
  1242. }
  1243. // Approve for leave only
  1244. if (!$error && ($massaction == 'approveleave' || ($action == 'approveleave' && $confirm == 'yes')) && $permissiontoapprove) {
  1245. $db->begin();
  1246. $objecttmp = new $objectclass($db);
  1247. $nbok = 0;
  1248. foreach ($toselect as $toselectid) {
  1249. $result = $objecttmp->fetch($toselectid);
  1250. if ($result > 0) {
  1251. if ($objecttmp->statut != Holiday::STATUS_VALIDATED) {
  1252. setEventMessages($langs->trans('StatusOfRefMustBe', $objecttmp->ref, $langs->transnoentitiesnoconv('Validated')), null, 'warnings');
  1253. continue;
  1254. }
  1255. if ($user->id == $objecttmp->fk_validator) {
  1256. $objecttmp->oldcopy = dol_clone($objecttmp);
  1257. $objecttmp->date_valid = dol_now();
  1258. $objecttmp->fk_user_valid = $user->id;
  1259. $objecttmp->statut = Holiday::STATUS_APPROVED;
  1260. $verif = $objecttmp->approve($user);
  1261. if ($verif <= 0) {
  1262. setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
  1263. $error++;
  1264. }
  1265. // If no SQL error, we redirect to the request form
  1266. if (!$error) {
  1267. // Calculcate number of days consummed
  1268. $nbopenedday = num_open_day($objecttmp->date_debut_gmt, $objecttmp->date_fin_gmt, 0, 1, $objecttmp->halfday);
  1269. $soldeActuel = $objecttmp->getCpforUser($objecttmp->fk_user, $objecttmp->fk_type);
  1270. $newSolde = ($soldeActuel - $nbopenedday);
  1271. // The modification is added to the LOG
  1272. $result = $objecttmp->addLogCP($user->id, $objecttmp->fk_user, $langs->transnoentitiesnoconv("Holidays"), $newSolde, $objecttmp->fk_type);
  1273. if ($result < 0) {
  1274. $error++;
  1275. setEventMessages(null, $objecttmp->errors, 'errors');
  1276. }
  1277. // Update balance
  1278. $result = $objecttmp->updateSoldeCP($objecttmp->fk_user, $newSolde, $objecttmp->fk_type);
  1279. if ($result < 0) {
  1280. $error++;
  1281. setEventMessages(null, $objecttmp->errors, 'errors');
  1282. }
  1283. }
  1284. if (!$error) {
  1285. // To
  1286. $destinataire = new User($db);
  1287. $destinataire->fetch($objecttmp->fk_user);
  1288. $emailTo = $destinataire->email;
  1289. if (!$emailTo) {
  1290. dol_syslog("User that request leave has no email, so we redirect directly to finished page without sending email");
  1291. } else {
  1292. // From
  1293. $expediteur = new User($db);
  1294. $expediteur->fetch($objecttmp->fk_validator);
  1295. //$emailFrom = $expediteur->email; Email of user can be an email into another company. Sending will fails, we must use the generic email.
  1296. $emailFrom = $conf->global->MAIN_MAIL_EMAIL_FROM;
  1297. // Subject
  1298. $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM;
  1299. if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
  1300. $societeName = $conf->global->MAIN_APPLICATION_TITLE;
  1301. }
  1302. $subject = $societeName." - ".$langs->transnoentitiesnoconv("HolidaysValidated");
  1303. // Content
  1304. $message = $langs->transnoentitiesnoconv("Hello")." ".$destinataire->firstname.",\n";
  1305. $message .= "\n";
  1306. $message .= $langs->transnoentities("HolidaysValidatedBody", dol_print_date($objecttmp->date_debut, 'day'), dol_print_date($objecttmp->date_fin, 'day'))."\n";
  1307. $message .= "- ".$langs->transnoentitiesnoconv("ValidatedBy")." : ".dolGetFirstLastname($expediteur->firstname, $expediteur->lastname)."\n";
  1308. $message .= "- ".$langs->transnoentitiesnoconv("Link")." : ".$dolibarr_main_url_root."/holiday/card.php?id=".$objecttmp->id."\n\n";
  1309. $message .= "\n";
  1310. $trackid = 'leav'.$objecttmp->id;
  1311. require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
  1312. $mail = new CMailFile($subject, $emailTo, $emailFrom, $message, array(), array(), array(), '', '', 0, 0, '', '', $trackid);
  1313. // Sending email
  1314. $result = $mail->sendfile();
  1315. if (!$result) {
  1316. setEventMessages($mail->error, $mail->errors, 'warnings'); // Show error, but do no make rollback, so $error is not set to 1
  1317. $action = '';
  1318. }
  1319. }
  1320. }
  1321. } else {
  1322. $langs->load("errors");
  1323. setEventMessages($langs->trans('ErrorNotApproverForHoliday', $objecttmp->ref), null, 'errors');
  1324. }
  1325. } else {
  1326. setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
  1327. $error++;
  1328. break;
  1329. }
  1330. }
  1331. if (!$error) {
  1332. if ($nbok > 1) {
  1333. setEventMessages($langs->trans("RecordsApproved", $nbok), null, 'mesgs');
  1334. } elseif ($nbok == 1) {
  1335. setEventMessages($langs->trans("RecordAproved"), null, 'mesgs');
  1336. }
  1337. $db->commit();
  1338. } else {
  1339. $db->rollback();
  1340. }
  1341. }
  1342. $parameters['toselect'] = $toselect;
  1343. $parameters['uploaddir'] = $uploaddir;
  1344. $parameters['massaction'] = $massaction;
  1345. $parameters['diroutputmassaction'] = isset($diroutputmassaction) ? $diroutputmassaction : null;
  1346. $reshook = $hookmanager->executeHooks('doMassActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  1347. if ($reshook < 0) {
  1348. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  1349. }