69@phan-var-force ?string $permissiontoread
70@phan-var-force ?string $permissiontodelete
71@phan-var-force ?string $permissiontoclose
72@phan-var-force ?string $permissiontoapprove
73@phan-var-force ?int[] $toselect
74@phan-var-force ?string $diroutputmassaction
75@phan-var-force ?string $objectlabel
76@phan-var-force ?string $option
77@phan-var-force ?string $deliveryreceipt
82if (empty($objectclass) || empty($uploaddir)) {
83 dol_print_error(
null,
'include of actions_massactions.inc.php is done but var $objectclass or $uploaddir was not defined');
86if (empty($massaction)) {
93@phan-var-force "CommonObject"|"CommandeFournisseur"|"ConferenceOrBoothAttendee"|"Contrat"|"Contact"|"Expedition"|"ExpenseReport"|"Facture"|"FactureFournisseur"|"Fichinter"|"Holiday"|"Partnership"|"Project"|"Propal"|"Societe"|"SupplierProposal" $objectclass
94@phan-var-force string $massaction
95@phan-var-force string $uploaddir
100if (!empty($permtoread) && empty($permissiontoread)) {
101 $permissiontoread = $permtoread;
103if (!empty($permtocreate) && empty($permissiontoadd)) {
104 $permissiontoadd = $permtocreate;
106if (!empty($permtodelete) && empty($permissiontodelete)) {
107 $permissiontodelete = $permtodelete;
111$maxformassaction =
getDolGlobalInt(
'MAIN_LIMIT_FOR_MASS_ACTIONS', 1000);
112if ($massaction && is_array($toselect) && count($toselect) < 1) {
116if (!$error && isset($toselect) && is_array($toselect) && count($toselect) > $maxformassaction) {
117 setEventMessages($langs->trans(
'TooManyRecordForMassAction', $maxformassaction),
null,
'errors');
121if (!$error && $massaction ==
'confirm_presend' && !
GETPOST(
'sendmail')) {
122 $massaction =
'presend';
125if (!$error && $massaction ==
'confirm_presend') {
129 $langs->load(
"mails");
130 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
131 include_once DOL_DOCUMENT_ROOT.
'/core/lib/signature.lib.php';
133 $listofobjectid = array();
134 $listofobjectthirdparties = array();
135 $listofobjectcontacts = array();
136 $listofobjectref = array();
137 $contactidtosend = array();
138 $attachedfilesThirdpartyObj = array();
139 $oneemailperrecipient = (
GETPOSTINT(
'oneemailperrecipient') ? 1 : 0);
143 $objecttmp =
new $objectclass($db);
146 $thirdparty =
new Societe($db);
147 if ($objecttmp->element ==
'expensereport') {
148 $thirdparty =
new User($db);
149 } elseif ($objecttmp->element ==
'contact') {
150 $thirdparty =
new Contact($db);
151 } elseif ($objecttmp->element ==
'partnership' &&
getDolGlobalString(
'PARTNERSHIP_IS_MANAGED_FOR') ==
'member') {
153 } elseif ($objecttmp->element ==
'holiday') {
154 $thirdparty =
new User($db);
155 } elseif ($objecttmp->element ==
'conferenceorboothattendee') {
159 foreach ($toselect as $toselectid) {
160 $objecttmp =
new $objectclass($db);
161 '@phan-var-force CommonObject $objecttmp';
163 $result = $objecttmp->fetch($toselectid);
165 $listofobjectid[$toselectid] = $toselectid;
168 $tmpobjectid = ($objecttmp->fk_soc ? $objecttmp->fk_soc : $objecttmp->socid);
169 if ($objecttmp->element ==
'societe') {
170 '@phan-var-force Societe $objecttmp';
172 $tmpobjectid = $objecttmp->id;
173 } elseif ($objecttmp->element ==
'contact') {
174 '@phan-var-force Contact $objecttmp';
176 $tmpobjectid = $objecttmp->id;
177 } elseif ($objecttmp->element ==
'expensereport') {
178 '@phan-var-force ExpenseReport $objecttmp';
180 $tmpobjectid = $objecttmp->fk_user_author;
181 } elseif ($objecttmp->element ==
'partnership' &&
getDolGlobalString(
'PARTNERSHIP_IS_MANAGED_FOR') ==
'member') {
182 '@phan-var-force Partnership $objecttmp';
184 $tmpobjectid = $objecttmp->fk_member;
185 } elseif ($objecttmp->element ==
'holiday') {
186 '@phan-var-force Holiday $objecttmp';
188 $tmpobjectid = $objecttmp->fk_user;
189 } elseif ($objecttmp->element ==
'conferenceorboothattendee') {
190 '@phan-var-force ConferenceOrBoothAttendee $objecttmp';
192 $tmpobjectid = $objecttmp->id;
194 if (empty($tmpobjectid)) {
198 if ($objectclass ==
'Facture') {
199 '@phan-var-force Facture $objecttmp';
201 $tmparraycontact = array();
202 $tmparraycontact = $objecttmp->liste_contact(-1,
'external', 0,
'BILLING');
203 if (is_array($tmparraycontact) && count($tmparraycontact) > 0) {
204 foreach ($tmparraycontact as $data_email) {
205 $listofobjectcontacts[$toselectid][$data_email[
'id']] = $data_email[
'email'];
208 } elseif ($objectclass ==
'CommandeFournisseur') {
209 '@phan-var-force CommandeFournisseur $objecttmp';
211 $tmparraycontact = array();
212 $tmparraycontact = $objecttmp->liste_contact(-1,
'external', 0,
'CUSTOMER');
213 if (is_array($tmparraycontact) && count($tmparraycontact) > 0) {
214 foreach ($tmparraycontact as $data_email) {
215 $listofobjectcontacts[$toselectid][$data_email[
'id']] = $data_email[
'email'];
220 $listofobjectthirdparties[$tmpobjectid] = $tmpobjectid;
221 $listofobjectref[$tmpobjectid][$toselectid] = $objecttmp;
227 if (
GETPOST(
'fromtype',
'alpha') ===
'user' && empty($user->email)) {
230 $massaction =
'presend';
233 $receiver =
GETPOST(
'receiver',
'alphawithlgt');
234 if (!is_array($receiver)) {
235 if (empty($receiver) || $receiver ==
'-1') {
238 $receiver = array($receiver);
241 if (!trim(
GETPOST(
'sendto',
'alphawithlgt')) && count($receiver) == 0 && count($listofobjectthirdparties) == 1) {
243 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Recipient")),
null,
'warnings');
244 $massaction =
'presend';
247 if (!
GETPOST(
'subject',
'restricthtml')) {
249 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"MailTopic")),
null,
'warnings');
250 $massaction =
'presend';
255 foreach ($listofobjectthirdparties as $thirdpartyid) {
256 $result = $thirdparty->fetch($thirdpartyid);
269 if (trim(
GETPOST(
'sendto',
'alphawithlgt'))) {
271 $tmparray[] = trim(
GETPOST(
'sendto',
'alphawithlgt'));
273 if (count($receiver) > 0 && is_object($thirdparty)) {
274 foreach ($receiver as $key => $val) {
276 if ($val ==
'thirdparty') {
277 $tmparray[] = $thirdparty->name.
' <'.$thirdparty->email.
'>';
278 } elseif ($val && method_exists($thirdparty,
'contact_get_property')) {
279 $tmparray[] = $thirdparty->contact_get_property((
int) $val,
'email');
284 $sendto = implode(
',', $tmparray);
287 $receivercc =
GETPOST(
'receivercc',
'alphawithlgt');
288 if (!is_array($receivercc)) {
289 if ($receivercc ==
'-1') {
290 $receivercc = array();
292 $receivercc = array($receivercc);
296 if (trim(
GETPOST(
'sendtocc',
'alphawithlgt'))) {
297 $tmparray[] = trim(
GETPOST(
'sendtocc',
'alphawithlgt'));
299 if (count($receivercc) > 0) {
300 foreach ($receivercc as $key => $val) {
302 if ($val ==
'thirdparty') {
303 $tmparray[] = $thirdparty->name.
' <'.$thirdparty->email.
'>';
305 $tmparray[] = $thirdparty->contact_get_property((
int) $val,
'email');
310 $sendtocc = implode(
',', $tmparray);
313 $listofqualifiedobj = array();
314 $listofqualifiedref = array();
315 $thirdpartywithoutemail = array();
317 foreach ($listofobjectref[$thirdpartyid] as $objectid => $objectobj) {
320 $langs->load(
"errors");
322 $resaction .=
'<div class="error">'.$langs->trans(
'ErrorOnlyProposalNotDraftCanBeSentInMassAction', $objectobj->ref).
'</div><br>';
326 $langs->load(
"errors");
328 $resaction .=
'<div class="error">'.$langs->trans(
'ErrorOnlyOrderNotDraftCanBeSentInMassAction', $objectobj->ref).
'</div><br>';
332 $langs->load(
"errors");
334 $resaction .=
'<div class="error">'.$langs->trans(
'ErrorOnlyInvoiceValidatedCanBeSentInMassAction', $objectobj->ref).
'</div><br>';
339 if (empty($sendto)) {
340 if ($objectobj->element ==
'societe') {
341 $sendto = $objectobj->email;
342 } elseif ($objectobj->element ==
'expensereport') {
343 $fuser =
new User($db);
344 $fuser->fetch($objectobj->fk_user_author);
345 $sendto = $fuser->email;
346 } elseif ($objectobj->element ==
'contact') {
348 $fcontact->fetch($objectobj->id);
349 $sendto = $fcontact->email;
350 } elseif ($objectobj->element ==
'partnership' &&
getDolGlobalString(
'PARTNERSHIP_IS_MANAGED_FOR') ==
'member') {
352 $fadherent->fetch($objectobj->fk_member);
353 $sendto = $fadherent->email;
354 } elseif ($objectobj->element ==
'holiday') {
355 $fuser =
new User($db);
356 $fuser->fetch($objectobj->fk_user);
357 $sendto = $fuser->email;
358 } elseif ($objectobj->element ==
'facture' && !empty($listofobjectcontacts[$objectid])) {
359 $emails_to_sends = array();
360 $objectobj->fetch_thirdparty();
361 $contactidtosend = array();
362 foreach ($listofobjectcontacts[$objectid] as $contactemailid => $contactemailemail) {
363 $emails_to_sends[] = $objectobj->thirdparty->contact_get_property($contactemailid,
'email');
364 if (!in_array($contactemailid, $contactidtosend)) {
365 $contactidtosend[] = $contactemailid;
368 if (count($emails_to_sends) > 0) {
369 $sendto = implode(
',', $emails_to_sends);
371 } elseif ($objectobj->element ==
'order_supplier' && !empty($listofobjectcontacts[$objectid])) {
372 $emails_to_sends = array();
373 $objectobj->fetch_thirdparty();
374 $contactidtosend = array();
375 foreach ($listofobjectcontacts[$objectid] as $contactemailid => $contactemailemail) {
376 $emails_to_sends[] = $objectobj->thirdparty->contact_get_property($contactemailid,
'email');
377 if (!in_array($contactemailid, $contactidtosend)) {
378 $contactidtosend[] = $contactemailid;
381 if (count($emails_to_sends) > 0) {
382 $sendto = implode(
',', $emails_to_sends);
384 } elseif ($objectobj->element ==
'conferenceorboothattendee') {
385 $sendto = $objectobj->email;
387 $objectobj->fetch_thirdparty();
388 $sendto = $objectobj->thirdparty->email;
392 if (empty($sendto)) {
393 if ($objectobj->element ==
'societe') {
395 $objectobj->thirdparty = $objectobj;
400 if (empty($thirdpartywithoutemail[$objectobj->thirdparty->id])) {
401 $resaction .=
'<div class="error">'.$langs->trans(
'NoRecipientEmail', $objectobj->thirdparty->name).
'</div><br>';
403 dol_syslog(
'No recipient for thirdparty: '.$objectobj->thirdparty->name, LOG_WARNING);
404 $thirdpartywithoutemail[$objectobj->thirdparty->id] = 1;
408 if (
GETPOST(
'addmaindocfile')) {
415 $filedir = $uploaddir.
'/'.$subdir.dol_sanitizeFileName($objectobj->ref);
416 $filepath = $filedir.
'/'.$filename;
419 if ($objectobj->element ==
'invoice_supplier') {
420 $fileparams =
dol_most_recent_file($uploaddir.
'/'.
get_exdir($objectobj->id, 2, 0, 0, $objectobj, $objectobj->element).$objectobj->ref, preg_quote($objectobj->ref,
'/').
'([^\-])+');
421 $filepath = $fileparams[
'fullname'];
425 $filename_found =
'';
426 $filepath_found =
'';
427 $file_check_list = array();
428 $file_check_list[] = array(
432 if (
getDolGlobalString(
'MAIL_MASS_ACTION_ADD_LAST_IF_MAIN_DOC_NOT_FOUND') && !empty($objectobj->last_main_doc)) {
433 $file_check_list[] = array(
434 'name' => basename($objectobj->last_main_doc),
435 'path' => DOL_DATA_ROOT .
'/' . $objectobj->last_main_doc,
438 foreach ($file_check_list as $file_check_arr) {
440 $filename_found = $file_check_arr[
'name'];
441 $filepath_found = $file_check_arr[
'path'];
446 if ($filepath_found) {
448 $attachedfilesThirdpartyObj[$thirdpartyid][$objectid] = array(
449 'paths' => array($filepath_found),
450 'names' => array($filename_found),
455 $langs->load(
"errors");
456 foreach ($file_check_list as $file_check_arr) {
457 $resaction .=
'<div class="error">'.$langs->trans(
'ErrorCantReadFile', $file_check_arr[
'path']).
'</div><br>';
458 dol_syslog(
'Failed to read file: '.$file_check_arr[
'path'], LOG_WARNING);
465 $listofqualifiedobj[$objectid] = $objectobj;
466 $listofqualifiedref[$objectid] = $objectobj->ref;
473 if (count($listofqualifiedobj) > 0) {
474 $langs->load(
"commercial");
477 $fromtype =
GETPOST(
'fromtype');
478 if ($fromtype ===
'user') {
479 $from =
dol_string_nospecial($user->getFullName($langs),
' ', array(
",")).
' <'.$user->email.
'>';
480 } elseif ($fromtype ===
'company') {
482 } elseif (preg_match(
'/user_aliases_(\d+)/', $fromtype, $reg)) {
483 $tmp = explode(
',', $user->email_aliases);
484 $from = trim($tmp[((
int) $reg[1] - 1)]);
485 } elseif (preg_match(
'/global_aliases_(\d+)/', $fromtype, $reg)) {
487 $from = trim($tmp[((
int) $reg[1] - 1)]);
488 } elseif (preg_match(
'/senderprofile_(\d+)_(\d+)/', $fromtype, $reg)) {
489 $sql =
"SELECT rowid, label, email FROM ".MAIN_DB_PREFIX.
"c_email_senderprofile WHERE rowid = ".(int) $reg[1];
490 $resql = $db->query($sql);
491 $obj = $db->fetch_object($resql);
500 $subject =
GETPOST(
'subject',
'restricthtml');
501 $message =
GETPOST(
'message',
'restricthtml');
503 $sendtobcc =
GETPOST(
'sendtoccc');
504 if ($objectclass ==
'Propal') {
507 if ($objectclass ==
'Commande') {
510 if ($objectclass ==
'Facture') {
513 if ($objectclass ==
'SupplierProposal') {
514 $sendtobcc .= (!
getDolGlobalString(
'MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO') ?
'' : (($sendtobcc ?
", " :
"") .
getDolGlobalString(
'MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO')));
516 if ($objectclass ==
'CommandeFournisseur') {
519 if ($objectclass ==
'FactureFournisseur') {
522 if ($objectclass ==
'Project') {
528 $looparray = array();
529 if (!$oneemailperrecipient) {
530 $looparray = $listofqualifiedobj;
531 foreach ($looparray as $key => $objecttmp) {
532 $looparray[$key]->thirdparty = $thirdparty;
535 $objectforloop =
new $objectclass($db);
536 $objectforloop->thirdparty = $thirdparty;
537 $looparray[0] = $objectforloop;
540 dol_syslog(
"We have set an array of ".count($looparray).
" emails to send. oneemailperrecipient=".$oneemailperrecipient);
542 foreach ($looparray as $objectid => $objecttmp) {
544 if (isModEnabled(
'project') && method_exists($objecttmp,
'fetchProject') && is_null($objecttmp->project)) {
545 $objecttmp->fetchProject();
548 $substitutionarray[
'__ID__'] = ($oneemailperrecipient ? implode(
', ', array_keys($listofqualifiedobj)) : $objecttmp->id);
549 $substitutionarray[
'__REF__'] = ($oneemailperrecipient ? implode(
', ', $listofqualifiedref) : $objecttmp->
ref);
550 $substitutionarray[
'__EMAIL__'] = $thirdparty->email;
551 $substitutionarray[
'__CHECK_READ__'] =
'<img src="'.DOL_MAIN_URL_ROOT.
'/public/emailing/mailing-read.php?tag=undefined&securitykey='.
dol_hash(
getDolGlobalString(
'MAILING_EMAIL_UNSUBSCRIBE_KEY').
"-undefined",
'md5').
'" width="1" height="1" style="width:1px;height:1px" border="0"/>';
553 if ($oneemailperrecipient) {
554 $substitutionarray[
'__ONLINE_PAYMENT_URL__'] =
'';
555 $substitutionarray[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
'';
558 $parameters = array(
'mode' =>
'formemail');
560 if (!empty($listofobjectthirdparties)) {
561 $parameters[
'listofobjectthirdparties'] = $listofobjectthirdparties;
563 if (!empty($listofobjectref)) {
564 $parameters[
'listofobjectref'] = $listofobjectref;
572 $attachedfiles = array(
'paths' => array(),
'names' => array(),
'mimes' => array());
573 if ($oneemailperrecipient) {
575 if (is_array($attachedfilesThirdpartyObj[$thirdparty->id]) && count($attachedfilesThirdpartyObj[$thirdparty->id])) {
576 foreach ($attachedfilesThirdpartyObj[$thirdparty->id] as $keyObjId => $objAttachedFiles) {
578 $attachedfiles = array(
579 'paths' => array_merge($attachedfiles[
'paths'], $objAttachedFiles[
'paths']),
580 'names' => array_merge($attachedfiles[
'names'], $objAttachedFiles[
'names']),
581 'mimes' => array_merge($attachedfiles[
'mimes'], $objAttachedFiles[
'mimes'])
585 } elseif (!empty($attachedfilesThirdpartyObj[$thirdparty->id][$objectid])) {
588 $attachedfiles = $attachedfilesThirdpartyObj[$thirdparty->id][$objectid];
591 $filepath = $attachedfiles[
'paths'];
592 $filename = $attachedfiles[
'names'];
593 $mimetype = $attachedfiles[
'mimes'];
596 if ($oneemailperrecipient) {
597 $trackid =
'thi'.$thirdparty->id;
598 if ($objecttmp->element ==
'expensereport') {
599 $trackid =
'use'.$thirdparty->id;
600 } elseif ($objecttmp->element ==
'contact') {
601 $trackid =
'ctc'.$thirdparty->id;
602 } elseif ($objecttmp->element ==
'holiday') {
603 $trackid =
'use'.$thirdparty->id;
606 $trackid = strtolower(get_class($objecttmp));
607 if (get_class($objecttmp) ==
'Contact') {
609 } elseif (get_class($objecttmp) ==
'Contrat') {
611 } elseif (get_class($objecttmp) ==
'Propal') {
613 } elseif (get_class($objecttmp) ==
'Commande') {
615 } elseif (get_class($objecttmp) ==
'Facture') {
617 } elseif (get_class($objecttmp) ==
'SupplierProposal') {
619 } elseif (get_class($objecttmp) ==
'CommandeFournisseur') {
621 } elseif (get_class($objecttmp) ==
'FactureFournisseur') {
625 $trackid .= $objecttmp->id;
631 if (empty($sendcontext)) {
632 $sendcontext =
'standard';
636 $vardir =
$conf->user->dir_output.
"/".$user->id;
637 $upload_dir_tmp = $vardir.
'/temp';
640 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
641 $mailfile =
new CMailFile($subjectreplaced, $sendto, $from, $messagereplaced, $filepath, $mimetype, $filename, $sendtocc, $sendtobcc, $deliveryreceipt, -1,
'',
'', $trackid,
'', $sendcontext,
'', $upload_dir_tmp);
642 if ($mailfile->error) {
643 $resaction .=
'<div class="error">'.$mailfile->error.
'</div>';
645 $result = $mailfile->sendfile();
647 $resaction .= $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($mailfile->addr_from, 2), $mailfile->getValidAddress($mailfile->addr_to, 2)).
'<br>';
652 foreach ($listofqualifiedobj as $objid2 => $objectobj2) {
653 if ((!$oneemailperrecipient) && $objid2 != $objectid) {
657 dol_syslog(
"Try to insert email event into agenda for objid=".$objid2.
" => objectobj=".get_class($objectobj2));
666 $actionmsg = $langs->transnoentities(
'MailSentByTo', $from, $sendto);
669 $actionmsg =
dol_concatdesc($actionmsg, $langs->transnoentities(
'Bcc').
": ".$sendtocc);
671 $actionmsg =
dol_concatdesc($actionmsg, $langs->transnoentities(
'MailTopic').
": ".$subjectreplaced);
672 $actionmsg =
dol_concatdesc($actionmsg, $langs->transnoentities(
'TextUsedInTheMessageBody').
":");
678 $objectobj2->sendtoid = (empty($contactidtosend) ? 0 : $contactidtosend);
679 $objectobj2->actionmsg = $actionmsg;
680 $objectobj2->actionmsg2 = $actionmsg2;
681 $objectobj2->fk_element = $objid2;
682 $objectobj2->elementtype = $objectobj2->element;
684 $objectobj2->actionmsg2 = $subjectreplaced;
687 $triggername = strtoupper(get_class($objectobj2)).
'_SENTBYMAIL';
688 if ($triggername ==
'SOCIETE_SENTBYMAIL') {
689 $triggername =
'COMPANY_SENTBYMAIL';
691 if ($triggername ==
'CONTRAT_SENTBYMAIL') {
692 $triggername =
'CONTRACT_SENTBYMAIL';
694 if ($triggername ==
'COMMANDE_SENTBYMAIL') {
695 $triggername =
'ORDER_SENTBYMAIL';
697 if ($triggername ==
'FACTURE_SENTBYMAIL') {
698 $triggername =
'BILL_SENTBYMAIL';
700 if ($triggername ==
'EXPEDITION_SENTBYMAIL') {
701 $triggername =
'SHIPPING_SENTBYMAIL';
703 if ($triggername ==
'COMMANDEFOURNISSEUR_SENTBYMAIL') {
704 $triggername =
'ORDER_SUPPLIER_SENTBYMAIL';
706 if ($triggername ==
'FACTUREFOURNISSEUR_SENTBYMAIL') {
707 $triggername =
'BILL_SUPPLIER_SENTBYMAIL';
709 if ($triggername ==
'SUPPLIERPROPOSAL_SENTBYMAIL') {
710 $triggername =
'PROPOSAL_SUPPLIER_SENTBYMAIL';
712 if ($triggername ==
'PROJET_SENTBYMAIL') {
713 $triggername =
'PROJECT_SENTBYMAIL';
716 if (!empty($triggername)) {
718 $result = $objectobj2->call_trigger($triggername, $user);
726 dol_syslog(
"Error in trigger ".$triggername.
' '.$db->lasterror(), LOG_ERR);
733 $langs->load(
"other");
734 if ($mailfile->error) {
735 $resaction .= $langs->trans(
'ErrorFailedToSendMail', $from, $sendto);
736 $resaction .=
'<br><div class="error">'.$mailfile->error.
'</div>';
738 $resaction .=
'<div class="warning">No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS</div>';
740 $resaction .= $langs->trans(
'ErrorFailedToSendMail', $from, $sendto) .
'<br><div class="error">(unhandled error)</div>';
748 $resaction .= ($resaction ?
'<br>' : $resaction);
749 $resaction .=
'<strong>'.$langs->trans(
"ResultOfMailSending").
':</strong><br>'.
"\n";
750 $resaction .= $langs->trans(
"NbSelected").
': '.count($toselect).
"\n<br>";
751 $resaction .= $langs->trans(
"NbIgnored").
': '.($nbignored ? $nbignored : 0).
"\n<br>";
752 $resaction .= $langs->trans(
"NbSent").
': '.($nbsent ? $nbsent : 0).
"\n<br>";
757 setEventMessages($langs->trans(
"EMailSentForNElements", $nbsent.
'/'.count($toselect)),
null,
'mesgs');
770if (!$error && $massaction ==
'cancelorders') {
775 $orders =
GETPOST(
'toselect',
'array');
776 foreach ($orders as $id_order) {
778 if ($cmd->fetch($id_order) <= 0) {
783 $langs->load(
'errors');
784 setEventMessages($langs->trans(
"ErrorObjectMustHaveStatusValidToBeCanceled", $cmd->ref),
null,
'errors');
789 $result = $cmd->cancel();
809if (!$error && $massaction ==
"builddoc" && $permissiontoread && !
GETPOST(
'button_search')) {
810 if (empty($diroutputmassaction)) {
811 dol_print_error(
null,
'include of actions_massactions.inc.php is done but var $diroutputmassaction was not defined');
815 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
816 require_once DOL_DOCUMENT_ROOT.
'/core/lib/pdf.lib.php';
817 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
819 $objecttmp =
new $objectclass($db);
820 $listofobjectid = array();
821 $listofobjectthirdparties = array();
822 $listofobjectref = array();
823 foreach ($toselect as $toselectid) {
824 $objecttmp =
new $objectclass($db);
825 $result = $objecttmp->fetch($toselectid);
827 $listofobjectid[$toselectid] = $toselectid;
828 $thirdpartyid = !empty($objecttmp->fk_soc) ? $objecttmp->fk_soc : $objecttmp->socid;
829 $listofobjectthirdparties[$thirdpartyid] = $thirdpartyid;
830 $listofobjectref[$toselectid] = $objecttmp->ref;
834 $arrayofinclusion = array();
835 foreach ($listofobjectref as $tmppdf) {
838 foreach ($listofobjectref as $tmppdf) {
839 $arrayofinclusion[] =
'^'.preg_quote(
dol_sanitizeFileName($tmppdf),
'/').
'_[a-zA-Z0-9\-\_\'\&\.]+\.pdf$';
841 $listoffiles =
dol_dir_list($uploaddir,
'all', 1, implode(
'|', $arrayofinclusion),
'\.meta$|\.png',
'date', SORT_DESC, 0, 1);
846 foreach ($listofobjectref as $basename) {
848 foreach ($listoffiles as $filefound) {
849 if (strstr($filefound[
"name"], $basename)) {
850 $files[] = $filefound[
'fullname'];
857 $outputlangs = $langs;
860 $newlang =
GETPOST(
'lang_id',
'aZ09');
865 if (!empty($newlang)) {
867 $outputlangs->setDefaultLang($newlang);
876 $filename = preg_replace(
'/\s/',
'_', $filename);
879 if (in_array($objecttmp->element, array(
'facture',
'invoice_supplier')) && $search_status ==
Facture::STATUS_VALIDATED) {
880 if ($option ==
'late') {
887 $filename .=
'_'.$year;
890 $filename .=
'_'.$month;
893 if (count($files) > 0) {
895 $file = $diroutputmassaction.
'/'.$filename.
'_'.
dol_print_date($now,
'dayhourlog').
'.pdf';
898 foreach ($files as $f) {
899 $input_files .=
' '.escapeshellarg($f);
902 $cmd =
'pdftk '.$input_files.
' cat output '.escapeshellarg($file);
906 if (file_exists($file)) {
909 $langs->load(
"exports");
912 setEventMessages($langs->trans(
'ErrorPDFTkOutputFileNotFound'),
null,
'errors');
915 setEventMessages($langs->trans(
'NoPDFAvailableForDocGenAmongChecked'),
null,
'errors');
920 $page_largeur = $formatarray[
'width'];
921 $page_hauteur = $formatarray[
'height'];
922 $format = array($page_largeur, $page_hauteur);
926 if (class_exists(
'TCPDF')) {
927 $pdf->setPrintHeader(
false);
928 $pdf->setPrintFooter(
false);
933 $pdf->SetCompression(
false);
938 foreach ($files as $file) {
940 $pagecount = $pdf->setSourceFile($file);
941 for ($i = 1; $i <= $pagecount; $i++) {
942 $tplidx = $pdf->importPage($i);
943 $s = $pdf->getTemplatesize($tplidx);
944 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
945 $pdf->useTemplate($tplidx);
954 $filename = preg_replace(
'/\s/',
'_', $filename);
958 if (in_array($objecttmp->element, array(
'facture',
'invoice_supplier')) && $search_status ==
Facture::STATUS_VALIDATED) {
959 if ($option ==
'late') {
966 $filename .=
'_'.$year;
968 if (!empty($month)) {
969 $filename .=
'_'.$month;
973 $file = $diroutputmassaction.
'/'.$filename.
'_'.
dol_print_date($now,
'dayhourlog').
'.pdf';
974 $pdf->Output($file,
'F');
977 $langs->load(
"exports");
980 setEventMessages($langs->trans(
'NoPDFAvailableForDocGenAmongChecked'),
null,
'errors');
986if ($action ==
'remove_file') {
987 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
989 $langs->load(
"other");
990 $upload_dir = $diroutputmassaction;
991 $file = $upload_dir.
'/'.
GETPOST(
'file');
1003if (!$error && $massaction ==
'validate' && $permissiontoadd) {
1004 $objecttmp =
new $objectclass($db);
1006 if (($objecttmp->element ==
'facture' || $objecttmp->element ==
'invoice') && isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_BILL')) {
1007 $langs->load(
"errors");
1008 setEventMessages($langs->trans(
'ErrorMassValidationNotAllowedWhenStockIncreaseOnAction'),
null,
'errors');
1011 if ($objecttmp->element ==
'invoice_supplier' && isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_BILL')) {
1012 $langs->load(
"errors");
1013 setEventMessages($langs->trans(
'ErrorMassValidationNotAllowedWhenStockIncreaseOnAction'),
null,
'errors');
1016 if ($objecttmp->element ==
'facture') {
1019 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"facture";
1020 $sql .=
" WHERE rowid IN (".$db->sanitize(implode(
",", $toselect)).
")";
1021 $sql .=
" ORDER BY datef";
1023 $resql = $db->query($sql);
1026 while (!empty($arr = $db->fetch_row($resql))) {
1027 $toselectnew[] = $arr[0];
1029 $toselect = (empty($toselectnew)) ? $toselect : $toselectnew;
1040 foreach ($toselect as $toselectid) {
1041 $result = $objecttmp->fetch($toselectid);
1043 if (method_exists($objecttmp,
'validate')) {
1044 $result = $objecttmp->validate($user);
1045 } elseif (method_exists($objecttmp,
'setValid')) {
1046 $result = $objecttmp->setValid($user);
1048 $objecttmp->error =
'No method validate or setValid on this object';
1052 $langs->load(
"errors");
1053 setEventMessages($langs->trans(
"ErrorObjectMustHaveStatusDraftToBeValidated", $objecttmp->ref),
null,
'errors');
1056 } elseif ($result < 0) {
1064 $outputlangs = $langs;
1067 $newlang =
GETPOST(
'lang_id',
'aZ09');
1069 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && empty($newlang) && property_exists($objecttmp,
'thirdparty')) {
1070 if ((property_exists($objecttmp,
'socid') || property_exists($objecttmp,
'fk_soc')) && empty($objecttmp->thirdparty)) {
1071 $objecttmp->fetch_thirdparty();
1073 if (!empty($objecttmp->thirdparty)) {
1074 $newlang = $objecttmp->thirdparty->default_lang;
1077 if (!empty($newlang)) {
1079 $outputlangs->setDefaultLang($newlang);
1080 $outputlangs->load(
'products');
1082 $model = $objecttmp->model_pdf;
1083 $ret = $objecttmp->fetch($objecttmp->id);
1086 $hidedetails = isset($hidedetails) ? $hidedetails : (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS') ? 1 : 0);
1087 $hidedesc = isset($hidedesc) ? $hidedesc : (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_HIDE_DESC') ? 1 : 0);
1088 $hideref = isset($hideref) ? $hideref : (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_HIDE_REF') ? 1 : 0);
1089 $moreparams = isset($moreparams) ? $moreparams :
null;
1091 $result = $objecttmp->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1109 setEventMessages($langs->trans(
"RecordModifiedSuccessfully"),
null,
'mesgs');
1119if (!$error && ($massaction ==
'delete' || ($action ==
'delete' && $confirm ==
'yes')) && $permissiontodelete) {
1122 $objecttmp =
new $objectclass($db);
1128 $unique_arr = array_unique($toselect);
1129 foreach ($unique_arr as $toselectid) {
1130 $result = $objecttmp->fetch($toselectid);
1134 $langs->load(
"errors");
1136 $TMsg[] =
'<div class="error">'.$langs->trans(
'ErrorOnlyDraftStatusCanBeDeletedInMassAction', $objecttmp->ref).
'</div><br>';
1140 if (method_exists($objecttmp,
'is_erasable') && $objecttmp->is_erasable() <= 0) {
1141 $langs->load(
"errors");
1143 $TMsg[] =
'<div class="error">'.$langs->trans(
'ErrorRecordHasChildren').
' '.$objecttmp->ref.
'</div><br>';
1148 $langs->load(
"errors");
1150 $TMsg[] =
'<div class="error">'.$langs->trans(
'ErrorLeaveRequestMustBeDraftCanceledOrRefusedToBeDeleted', $objecttmp->ref).
'</div><br>';
1154 if ($objectclass ==
"Task" && $objecttmp->hasChildren() > 0) {
1155 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task SET fk_task_parent = 0 WHERE fk_task_parent = ".((int) $objecttmp->id);
1156 $res = $db->query($sql);
1164 if ($objecttmp->element ==
'societe') {
1166 '@phan-var-force Societe $objecttmp';
1168 $result = $objecttmp->delete($objecttmp->id, $user, 1);
1170 $result = $objecttmp->delete($user);
1173 if (empty($result)) {
1174 $TMsg = array_merge($objecttmp->errors, $TMsg);
1175 } elseif ($result < 0) {
1189 if (empty($error)) {
1193 } elseif ($nbok > 0) {
1200 if (!empty($TMsg)) {
1215if (!$error && $massaction ==
'generate_doc' && $permissiontoread) {
1218@phan-var-force
'Commande'|
'CommandeFournisseur'|
'Contrat'|
'Expedition'|
'ExpenseReport'|
'Facture'|
'FactureFournisseur'|
'Fichinter'|
'Project'|
'Propal'|
'SupplierProposal' $objectclass
1223 foreach ($toselect as $toselectid) {
1224 $objecttmp =
new $objectclass($db);
1225 $result = $objecttmp->fetch($toselectid);
1227 $outputlangs = $langs;
1231 $newlang =
GETPOST(
'lang_id',
'aZ09');
1233 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && empty($newlang) && isset($objecttmp->thirdparty->default_lang)) {
1234 $newlang = $objecttmp->thirdparty->default_lang;
1236 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && empty($newlang) && isset($objecttmp->default_lang)) {
1237 $newlang = $objecttmp->default_lang;
1239 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && empty($newlang) && empty($objecttmp->thirdparty)) {
1240 $objecttmp->fetch_thirdparty();
1241 $newlang = $objecttmp->thirdparty->default_lang;
1243 if (!empty($newlang)) {
1245 $outputlangs->setDefaultLang($newlang);
1249 $hidedetails = isset($hidedetails) ? $hidedetails : (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS') ? 1 : 0);
1250 $hidedesc = isset($hidedesc) ? $hidedesc : (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_HIDE_DESC') ? 1 : 0);
1251 $hideref = isset($hideref) ? $hideref : (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_HIDE_REF') ? 1 : 0);
1252 $moreparams = isset($moreparams) ? $moreparams :
null;
1254 $result = $objecttmp->generateDocument($objecttmp->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1284if (!$error && ($action ==
'affecttag' && $confirm ==
'yes') && $permissiontoadd) {
1288 $affecttag_type =
GETPOST(
'affecttag_type',
'alpha');
1289 if (!empty($affecttag_type)) {
1290 $affecttag_type_array = explode(
',', $affecttag_type);
1294 if (!empty($affecttag_type_array)) {
1296 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1298 $to_affecttag_type_array = array();
1299 $categ_type_array = $categ->getMapList();
1300 foreach ($categ_type_array as $categdef) {
1301 if (in_array($categdef[
'code'], $affecttag_type_array)) {
1302 $to_affecttag_type_array[] = $categdef[
'code'];
1307 if (!empty($to_affecttag_type_array)) {
1308 foreach ($to_affecttag_type_array as $categ_type) {
1309 $contcats =
GETPOST(
'contcats_' . $categ_type,
'array');
1311 foreach ($toselect as $toselectid) {
1312 $result =
$object->fetch($toselectid);
1315 $result =
$object->setCategoriesCommon($contcats, $categ_type,
false);
1334 $toselect = array();
1340if (!$error && ($action ==
'updateprice' && $confirm ==
'yes') && $permissiontoadd) {
1341 '@phan-var-force Product|ProductCustomerPrice $obj';
1342 '@phan-var-force Product|ProductCustomerPrice $object';
1345 if (GETPOSTISSET(
'pricerate')) {
1347 if ($pricepercentage == 0) {
1350 foreach ($toselect as $toselectid) {
1351 $result =
$object->fetch($toselectid);
1356 if (
$object->price_base_type ==
'TTC') {
1357 $newprice =
$object->price_ttc * (100 + $pricepercentage) / 100;
1358 $minprice =
$object->price_min_ttc;
1360 $newprice =
$object->price * (100 + $pricepercentage) / 100;
1361 $minprice =
$object->price_min;
1363 $res =
$object->updatePrice($newprice,
$object->price_base_type, $user,
$object->tva_tx, $minprice, 0,
$object->tva_npr, 0, 0, array(),
$object->default_vat_code);
1371 for ($level = 1; $level <= $maxlevel; $level++) {
1372 if (
$object->price_base_type ==
'TTC') {
1373 $newprice =
$object->multiprices_ttc[$level] * (100 + $pricepercentage) / 100;
1374 $minprice =
$object->multiprices_min_ttc[$level];
1376 $newprice =
$object->multiprices[$level] * (100 + $pricepercentage) / 100;
1377 $minprice =
$object->multiprices_min[$level];
1379 $res =
$object->updatePrice($newprice,
$object->price_base_type, $user,
$object->tva_tx, $minprice, $level,
$object->tva_npr, 0, 0, array(),
$object->default_vat_code);
1399 $toselect = array();
1405if (!$error && ($action ==
'setsupervisor' && $confirm ==
'yes') && $permissiontoadd) {
1406 '@phan-var-force User $object';
1409 $supervisortoset =
GETPOSTINT(
'supervisortoset');
1410 if (!empty($supervisortoset)) {
1411 foreach ($toselect as $toselectid) {
1412 $result =
$object->fetch($toselectid);
1415 $object->fk_user = $supervisortoset;
1416 $res =
$object->update($user);
1436 $toselect = array();
1442if (!$error && ($action ==
'affectuser' && $confirm ==
'yes') && $permissiontoadd) {
1446 $usertoaffect =
GETPOST(
'usertoaffect');
1447 $projectrole =
GETPOST(
'projectrole');
1448 $tasksrole =
GETPOST(
'tasksrole');
1449 if (!empty($usertoaffect)) {
1450 foreach ($toselect as $toselectid) {
1451 $result =
$object->fetch($toselectid);
1454 $res =
$object->add_contact($usertoaffect, $projectrole,
'internal');
1456 $taskstatic =
new Task($db);
1457 $task_array = $taskstatic->getTasksArray(
null,
null,
$object->id, 0, 0);
1459 foreach ($task_array as $task) {
1460 $tasksToAffect =
new Task($db);
1461 $result = $tasksToAffect->fetch($task->id);
1463 $res = $tasksToAffect->add_contact($usertoaffect, $tasksrole,
'internal');
1487 $toselect = array();
1493if (!$error && ($massaction ==
'enable' || ($action ==
'enable' && $confirm ==
'yes')) && $permissiontoadd) {
1496 $objecttmp =
new $objectclass($db);
1498 foreach ($toselect as $toselectid) {
1499 $result = $objecttmp->fetch($toselectid);
1501 if (in_array($objecttmp->element, array(
'societe'))) {
1502 $result = $objecttmp->setStatut(1);
1530if (!$error && ($massaction ==
'disable' || ($action ==
'disable' && $confirm ==
'yes')) && $permissiontoadd) {
1533 $objecttmp =
new $objectclass($db);
1535 foreach ($toselect as $toselectid) {
1536 $result = $objecttmp->fetch($toselectid);
1538 if (in_array($objecttmp->element, array(
'societe'))) {
1539 $result = $objecttmp->setStatut(0);
1567if (!$error && $action ==
'confirm_edit_value_extrafields' && $confirm ==
'yes' && $permissiontoadd) {
1570 $objecttmp =
new $objectclass($db);
1572 $e->fetch_name_optionals_label($objecttmp->table_element);
1575 $extrafieldKeyToUpdate =
GETPOST(
'extrafield-key-to-update');
1578 foreach ($toselect as $toselectid) {
1580 $objecttmp =
new $objectclass($db);
1581 $result = $objecttmp->fetch($toselectid);
1584 $ret = $e->setOptionalsFromPost(
null, $objecttmp, $extrafieldKeyToUpdate);
1586 $objecttmp->insertExtraFields();
1610if (!$error && ($massaction ==
'assignsalerepresentative' || ($action ==
'assignsalerepresentative' && $confirm ==
'yes')) && $permissiontoadd) {
1613 $objecttmp =
new $objectclass($db);
1616 foreach ($toselect as $toselectid) {
1617 $result = $objecttmp->fetch($toselectid);
1619 if (in_array($objecttmp->element, array(
'societe'))) {
1620 $result = $objecttmp->setSalesRep(
GETPOST(
"commercial",
"alpha"));
1638 setEventMessages($langs->trans(
"CommercialsAffected", $nbok),
null,
'mesgs');
1648if (!$error && ($massaction ==
'unassigncommercial' || ($action ==
'unassigncommercial' && $confirm ==
'yes')) && $permissiontoadd) {
1651 $objecttmp =
new $objectclass($db);
1654 foreach ($toselect as $toselectid) {
1655 $result = $objecttmp->fetch($toselectid);
1657 if (in_array($objecttmp->element, array(
'societe'))) {
1658 $TCommercial =
GETPOST(
"commercial",
"alpha");
1659 if (is_array($TCommercial)) {
1660 foreach ($TCommercial as $commercial) {
1661 $result = $objecttmp->del_commercial($user, $commercial);
1681 setEventMessages($langs->trans(
"CommercialsDisaffected", $nbok),
null,
'mesgs');
1691if (!$error && ($massaction ==
'approveleave' || ($action ==
'approveleave' && $confirm ==
'yes')) && $permissiontoapprove) {
1694 $objecttmp =
new $objectclass($db);
1695 '@phan-var-force Holiday $objecttmp';
1697 foreach ($toselect as $toselectid) {
1698 $result = $objecttmp->fetch($toselectid);
1701 setEventMessages($langs->trans(
'StatusOfRefMustBe', $objecttmp->ref, $langs->transnoentitiesnoconv(
'Validated')),
null,
'warnings');
1704 if ($user->id == $objecttmp->fk_validator) {
1705 $objecttmp->oldcopy =
dol_clone($objecttmp, 2);
1707 $objecttmp->date_valid =
dol_now();
1708 $objecttmp->fk_user_valid = $user->id;
1709 $objecttmp->date_approval =
dol_now();
1710 $objecttmp->fk_user_approve = $user->id;
1712 $objecttmp->statut = $objecttmp->status;
1714 $verif = $objecttmp->approve($user);
1724 $nbopenedday =
num_open_day($objecttmp->date_debut_gmt, $objecttmp->date_fin_gmt, 0, 1, $objecttmp->halfday);
1725 $soldeActuel = $objecttmp->getCpforUser($objecttmp->fk_user, $objecttmp->fk_type);
1726 $newSolde = ($soldeActuel - $nbopenedday);
1729 $result = $objecttmp->addLogCP($user->id, $objecttmp->fk_user, $langs->transnoentitiesnoconv(
"Holidays"), $newSolde, $objecttmp->fk_type);
1736 $result = $objecttmp->updateSoldeCP($objecttmp->fk_user, $newSolde, $objecttmp->fk_type);
1745 $destinataire =
new User($db);
1746 $destinataire->fetch($objecttmp->fk_user);
1747 $emailTo = $destinataire->email;
1750 dol_syslog(
"User that request leave has no email, so we redirect directly to finished page without sending email");
1753 $expediteur =
new User($db);
1754 $expediteur->fetch($objecttmp->fk_validator);
1764 $subject = $societeName.
" - ".$langs->transnoentitiesnoconv(
"HolidaysValidated");
1767 $message = $langs->transnoentitiesnoconv(
"Hello").
" ".$destinataire->firstname.
",\n";
1770 $message .= $langs->transnoentities(
"HolidaysValidatedBody",
dol_print_date($objecttmp->date_debut,
'day'),
dol_print_date($objecttmp->date_fin,
'day')).
"\n";
1772 $message .=
"- ".$langs->transnoentitiesnoconv(
"ValidatedBy").
" : ".
dolGetFirstLastname($expediteur->firstname, $expediteur->lastname).
"\n";
1774 $message .=
"- ".$langs->transnoentitiesnoconv(
"Link").
" : ".$dolibarr_main_url_root.
"/holiday/card.php?id=".$objecttmp->id.
"\n\n";
1777 $trackid =
'leav'.$objecttmp->id;
1779 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
1780 $mail =
new CMailFile($subject, $emailTo, $emailFrom, $message, array(), array(), array(),
'',
'', 0, 0,
'',
'', $trackid);
1783 $result = $mail->sendfile();
1792 $langs->load(
"errors");
1793 setEventMessages($langs->trans(
'ErrorNotApproverForHoliday', $objecttmp->ref),
null,
'errors');
1805 } elseif ($nbok == 1) {
1814if (!$error && ($massaction ==
'increaseholiday' || ($action ==
'increaseholiday' && $confirm ==
'yes')) && $permissiontoapprove && is_array($toselect)) {
1815 '@phan-var-force Holiday $holiday';
1817 $objecttmp =
new $objectclass($db);
1819 $typeholiday =
GETPOST(
'typeholiday',
'alpha');
1822 if ($nbdaysholidays <= 0) {
1828 foreach ($toselect as $toselectid) {
1829 $balancecpuser = $objecttmp->getCPforUser($toselectid, $typeholiday);
1830 if (!empty($balancecpuser)) {
1831 $newnbdaysholidays = $nbdaysholidays + $balancecpuser;
1833 $newnbdaysholidays = $nbdaysholidays;
1835 $result = $holiday->addLogCP($user->id, $toselectid, $langs->transnoentitiesnoconv(
'ManualUpdate'), $newnbdaysholidays, $typeholiday);
1842 $objecttmp->updateSoldeCP($toselectid, $newnbdaysholidays, $typeholiday);
1855 setEventMessages($langs->trans(
"HolidayRecordsIncreased", $nbok),
null,
'mesgs');
1856 } elseif ($nbok == 1) {
1860 $toselect = array();
1867if (!$error && ($massaction ==
'clonetasks' || ($action ==
'clonetasks' && $confirm ==
'yes'))) {
1870 include_once DOL_DOCUMENT_ROOT.
'/projet/class/task.class.php';
1872 $origin_task =
new Task($db);
1873 $clone_task =
new Task($db);
1874 $newproject =
new Project($db);
1878 $iscontactofnewproject = 0;
1879 if (empty($newproject->public)) {
1880 $tmps = $newproject->getProjectsAuthorizedForUser($user, 0, 1, 0,
'(fk_statut:=:1)');
1881 $tmparray = explode(
',', $tmps);
1882 if (!in_array($newproject->id, $tmparray)) {
1883 $iscontactofnewproject = 1;
1888 $permisstiontoadd =
false;
1889 if ($user->hasRight(
'project',
'all',
'creer') || ($user->hasRight(
'project',
'creer') && ($newproject->public || $iscontactofnewproject))) {
1890 $permisstiontoadd =
true;
1893 if ($permisstiontoadd) {
1894 foreach (
GETPOST(
'selected') as $task) {
1895 $origin_task->fetch($task,
'', 0);
1900 require_once DOL_DOCUMENT_ROOT .
"/core/modules/project/task/" .
getDolGlobalString(
'PROJECT_TASK_ADDON') .
'.php';
1901 $modTask =
new $classnamemodtask();
1902 '@phan-var-force ModeleNumRefTask $modTask';
1903 $defaultref = $modTask->getNextValue(
null, $clone_task);
1907 $clone_task->fk_project =
GETPOSTINT(
'projectid');
1908 $clone_task->ref = $defaultref;
1909 $clone_task->label = $origin_task->label;
1910 $clone_task->description = $origin_task->description;
1911 $clone_task->planned_workload = $origin_task->planned_workload;
1912 $clone_task->fk_task_parent = $origin_task->fk_task_parent;
1913 $clone_task->date_c =
dol_now();
1914 $clone_task->date_start = $origin_task->date_start;
1915 $clone_task->date_end = $origin_task->date_end;
1916 $clone_task->progress = $origin_task->progress;
1919 $ret = $extrafields->setOptionalsFromPost(
null, $clone_task);
1921 $taskid = $clone_task->create($user);
1924 $result = $clone_task->add_contact(
GETPOSTINT(
"userid"),
'TASKEXECUTIVE',
'internal');
1927 if ($db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1928 $langs->load(
"projects");
1930 $duplicate_code_error =
true;
1941 setEventMessages($langs->trans(
'NumberOfTasksCloned', $num),
null,
'mesgs');
1942 header(
"Location: ".DOL_URL_ROOT.
'/projet/tasks.php?id='.
GETPOSTINT(
'projectid'));
1950if (empty($toselect)) {
1953$parameters[
'toselect'] = &$toselect;
1954$parameters[
'uploaddir'] = $uploaddir;
1955$parameters[
'massaction'] = $massaction;
1956$parameters[
'diroutputmassaction'] = isset($diroutputmassaction) ? $diroutputmassaction :
null;
1958$reshook = $hookmanager->executeHooks(
'doMassActions', $parameters,
$object, $action);
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Class to manage members of a foundation.
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
Class to manage categories.
Class to manage customers orders.
const STATUS_DRAFT
Draft status.
const STATUS_VALIDATED
Validated status.
Class for ConferenceOrBoothAttendee.
const STATUS_DRAFT
Draft status.
const STATUS_VALIDATED
Validated (need to be paid)
const STATUS_VALIDATED
Validated status.
const STATUS_DRAFT
Draft status.
const STATUS_REFUSED
Refused.
const STATUS_CANCELED
Canceled.
const STATUS_APPROVED
Approved.
Class to manage projects.
const STATUS_DRAFT
Draft status.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
Class to manage Dolibarr users.
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)
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.
dol_is_file($pathoffile)
Return if path is a file.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
dol_most_recent_file($dir, $regexfilter='', $excludefilter=array('(\.meta|_preview.*\.png) $', '^\.'), $nohook=0, $mode=0)
Return file(s) into a directory (by default most recent)
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
dol_mimetype($file, $default='application/octet-stream', $mode=0)
Return MIME type of a file from its name with extension.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_string_nospecial($str, $newstr='_', $badcharstoreplace='', $badcharstoremove='', $keepspaces=0)
Clean a string from all punctuation characters to use it as a ref or login.
setEventMessage($mesgs, $style='mesgs', $noduplicate=0, $attop=0)
Set event message in dol_events session object.
dolChmod($filepath, $newmask='')
Change mod of a file.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
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...
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...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
GETPOSTFLOAT($paramname, $rounding='')
Return the value of a $_GET or $_POST supervariable, converted into float.
dol_clone($object, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null, $include=null)
Return array of possible common substitutions.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
pdf_getFormat($outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
dol_hash($chain, $type='0', $nosalt=0, $mode=0)
Returns a hash (non reversible encryption) of a string.