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