65@phan-var-force ?string $permissiontoread
66@phan-var-force ?string $permissiontodelete
67@phan-var-force ?string $permissiontoclose
68@phan-var-force ?string $permissiontoapprove
69@phan-var-force ?int[] $toselect
70@phan-var-force ?string $diroutputmassaction
71@phan-var-force ?string $objectlabel
72@phan-var-force ?string $option
73@phan-var-force ?string $deliveryreceipt
78if (empty($objectclass) || empty($uploaddir)) {
79 dol_print_error(
null,
'include of actions_massactions.inc.php is done but var $objectclass or $uploaddir was not defined');
82if (empty($massaction)) {
89@phan-var-force "CommonObject"|"CommandeFournisseur"|"ConferenceOrBoothAttendee"|"Contrat"|"Contact"|"Expedition"|"ExpenseReport"|"Facture"|"FactureFournisseur"|"Fichinter"|"Holiday"|"Partnership"|"Project"|"Propal"|"Societe"|"SupplierProposal" $objectclass
90@phan-var-force string $massaction
91@phan-var-force string $uploaddir
96if (!empty($permtoread) && empty($permissiontoread)) {
97 $permissiontoread = $permtoread;
99if (!empty($permtocreate) && empty($permissiontoadd)) {
100 $permissiontoadd = $permtocreate;
102if (!empty($permtodelete) && empty($permissiontodelete)) {
103 $permissiontodelete = $permtodelete;
107$maxformassaction = (!
getDolGlobalString(
'MAIN_LIMIT_FOR_MASS_ACTIONS') ? 1000 :
$conf->global->MAIN_LIMIT_FOR_MASS_ACTIONS);
108if ($massaction && is_array($toselect) && count($toselect) < 1) {
112if (!$error && isset($toselect) && is_array($toselect) && count($toselect) > $maxformassaction) {
113 setEventMessages($langs->trans(
'TooManyRecordForMassAction', $maxformassaction),
null,
'errors');
117if (!$error && $massaction ==
'confirm_presend' && !
GETPOST(
'sendmail')) {
118 $massaction =
'presend';
121if (!$error && $massaction ==
'confirm_presend') {
125 $langs->load(
"mails");
126 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
127 include_once DOL_DOCUMENT_ROOT.
'/core/lib/signature.lib.php';
129 $listofobjectid = array();
130 $listofobjectthirdparties = array();
131 $listofobjectcontacts = array();
132 $listofobjectref = array();
133 $contactidtosend = array();
134 $attachedfilesThirdpartyObj = array();
135 $oneemailperrecipient = (
GETPOSTINT(
'oneemailperrecipient') ? 1 : 0);
139 $objecttmp =
new $objectclass($db);
142 $thirdparty =
new Societe($db);
143 if ($objecttmp->element ==
'expensereport') {
144 $thirdparty =
new User($db);
145 } elseif ($objecttmp->element ==
'contact') {
146 $thirdparty =
new Contact($db);
147 } elseif ($objecttmp->element ==
'partnership' &&
getDolGlobalString(
'PARTNERSHIP_IS_MANAGED_FOR') ==
'member') {
149 } elseif ($objecttmp->element ==
'holiday') {
150 $thirdparty =
new User($db);
151 } elseif ($objecttmp->element ==
'conferenceorboothattendee') {
155 foreach ($toselect as $toselectid) {
156 $objecttmp =
new $objectclass($db);
157 '@phan-var-force CommonObject $objecttmp';
159 $result = $objecttmp->fetch($toselectid);
161 $listofobjectid[$toselectid] = $toselectid;
164 $tmpobjectid = ($objecttmp->fk_soc ? $objecttmp->fk_soc : $objecttmp->socid);
165 if ($objecttmp->element ==
'societe') {
166 '@phan-var-force Societe $objecttmp';
168 $tmpobjectid = $objecttmp->id;
169 } elseif ($objecttmp->element ==
'contact') {
170 '@phan-var-force Contact $objecttmp';
172 $tmpobjectid = $objecttmp->id;
173 } elseif ($objecttmp->element ==
'expensereport') {
174 '@phan-var-force ExpenseReport $objecttmp';
176 $tmpobjectid = $objecttmp->fk_user_author;
177 } elseif ($objecttmp->element ==
'partnership' &&
getDolGlobalString(
'PARTNERSHIP_IS_MANAGED_FOR') ==
'member') {
178 '@phan-var-force Partnership $objecttmp';
180 $tmpobjectid = $objecttmp->fk_member;
181 } elseif ($objecttmp->element ==
'holiday') {
182 '@phan-var-force Holiday $objecttmp';
184 $tmpobjectid = $objecttmp->fk_user;
185 } elseif ($objecttmp->element ==
'conferenceorboothattendee') {
186 '@phan-var-force ConferenceOrBoothAttendee $objecttmp';
188 $tmpobjectid = $objecttmp->id;
190 if (empty($tmpobjectid)) {
194 if ($objectclass ==
'Facture') {
195 '@phan-var-force Facture $objecttmp';
197 $tmparraycontact = array();
198 $tmparraycontact = $objecttmp->liste_contact(-1,
'external', 0,
'BILLING');
199 if (is_array($tmparraycontact) && count($tmparraycontact) > 0) {
200 foreach ($tmparraycontact as $data_email) {
201 $listofobjectcontacts[$toselectid][$data_email[
'id']] = $data_email[
'email'];
204 } elseif ($objectclass ==
'CommandeFournisseur') {
205 '@phan-var-force CommandeFournisseur $objecttmp';
207 $tmparraycontact = array();
208 $tmparraycontact = $objecttmp->liste_contact(-1,
'external', 0,
'CUSTOMER');
209 if (is_array($tmparraycontact) && count($tmparraycontact) > 0) {
210 foreach ($tmparraycontact as $data_email) {
211 $listofobjectcontacts[$toselectid][$data_email[
'id']] = $data_email[
'email'];
216 $listofobjectthirdparties[$tmpobjectid] = $tmpobjectid;
217 $listofobjectref[$tmpobjectid][$toselectid] = $objecttmp;
223 if (
GETPOST(
'fromtype',
'alpha') ===
'user' && empty($user->email)) {
226 $massaction =
'presend';
229 $receiver =
GETPOST(
'receiver',
'alphawithlgt');
230 if (!is_array($receiver)) {
231 if (empty($receiver) || $receiver ==
'-1') {
234 $receiver = array($receiver);
237 if (!trim(
GETPOST(
'sendto',
'alphawithlgt')) && count($receiver) == 0 && count($listofobjectthirdparties) == 1) {
239 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Recipient")),
null,
'warnings');
240 $massaction =
'presend';
243 if (!
GETPOST(
'subject',
'restricthtml')) {
245 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"MailTopic")),
null,
'warnings');
246 $massaction =
'presend';
251 foreach ($listofobjectthirdparties as $thirdpartyid) {
252 $result = $thirdparty->fetch($thirdpartyid);
265 if (trim(
GETPOST(
'sendto',
'alphawithlgt'))) {
267 $tmparray[] = trim(
GETPOST(
'sendto',
'alphawithlgt'));
269 if (count($receiver) > 0 && is_object($thirdparty)) {
270 foreach ($receiver as $key => $val) {
272 if ($val ==
'thirdparty') {
273 $tmparray[] = $thirdparty->name.
' <'.$thirdparty->email.
'>';
274 } elseif ($val && method_exists($thirdparty,
'contact_get_property')) {
275 $tmparray[] = $thirdparty->contact_get_property((
int) $val,
'email');
280 $sendto = implode(
',', $tmparray);
283 $receivercc =
GETPOST(
'receivercc',
'alphawithlgt');
284 if (!is_array($receivercc)) {
285 if ($receivercc ==
'-1') {
286 $receivercc = array();
288 $receivercc = array($receivercc);
292 if (trim(
GETPOST(
'sendtocc',
'alphawithlgt'))) {
293 $tmparray[] = trim(
GETPOST(
'sendtocc',
'alphawithlgt'));
295 if (count($receivercc) > 0) {
296 foreach ($receivercc as $key => $val) {
298 if ($val ==
'thirdparty') {
299 $tmparray[] = $thirdparty->name.
' <'.$thirdparty->email.
'>';
301 $tmparray[] = $thirdparty->contact_get_property((
int) $val,
'email');
306 $sendtocc = implode(
',', $tmparray);
309 $listofqualifiedobj = array();
310 $listofqualifiedref = array();
311 $thirdpartywithoutemail = array();
313 foreach ($listofobjectref[$thirdpartyid] as $objectid => $objectobj) {
316 $langs->load(
"errors");
318 $resaction .=
'<div class="error">'.$langs->trans(
'ErrorOnlyProposalNotDraftCanBeSentInMassAction', $objectobj->ref).
'</div><br>';
322 $langs->load(
"errors");
324 $resaction .=
'<div class="error">'.$langs->trans(
'ErrorOnlyOrderNotDraftCanBeSentInMassAction', $objectobj->ref).
'</div><br>';
328 $langs->load(
"errors");
330 $resaction .=
'<div class="error">'.$langs->trans(
'ErrorOnlyInvoiceValidatedCanBeSentInMassAction', $objectobj->ref).
'</div><br>';
335 if (empty($sendto)) {
336 if ($objectobj->element ==
'societe') {
337 $sendto = $objectobj->email;
338 } elseif ($objectobj->element ==
'expensereport') {
339 $fuser =
new User($db);
340 $fuser->fetch($objectobj->fk_user_author);
341 $sendto = $fuser->email;
342 } elseif ($objectobj->element ==
'contact') {
344 $fcontact->fetch($objectobj->id);
345 $sendto = $fcontact->email;
346 } elseif ($objectobj->element ==
'partnership' &&
getDolGlobalString(
'PARTNERSHIP_IS_MANAGED_FOR') ==
'member') {
348 $fadherent->fetch($objectobj->fk_member);
349 $sendto = $fadherent->email;
350 } elseif ($objectobj->element ==
'holiday') {
351 $fuser =
new User($db);
352 $fuser->fetch($objectobj->fk_user);
353 $sendto = $fuser->email;
354 } elseif ($objectobj->element ==
'facture' && !empty($listofobjectcontacts[$objectid])) {
355 $emails_to_sends = array();
356 $objectobj->fetch_thirdparty();
357 $contactidtosend = array();
358 foreach ($listofobjectcontacts[$objectid] as $contactemailid => $contactemailemail) {
359 $emails_to_sends[] = $objectobj->thirdparty->contact_get_property($contactemailid,
'email');
360 if (!in_array($contactemailid, $contactidtosend)) {
361 $contactidtosend[] = $contactemailid;
364 if (count($emails_to_sends) > 0) {
365 $sendto = implode(
',', $emails_to_sends);
367 } elseif ($objectobj->element ==
'order_supplier' && !empty($listofobjectcontacts[$objectid])) {
368 $emails_to_sends = array();
369 $objectobj->fetch_thirdparty();
370 $contactidtosend = array();
371 foreach ($listofobjectcontacts[$objectid] as $contactemailid => $contactemailemail) {
372 $emails_to_sends[] = $objectobj->thirdparty->contact_get_property($contactemailid,
'email');
373 if (!in_array($contactemailid, $contactidtosend)) {
374 $contactidtosend[] = $contactemailid;
377 if (count($emails_to_sends) > 0) {
378 $sendto = implode(
',', $emails_to_sends);
380 } elseif ($objectobj->element ==
'conferenceorboothattendee') {
381 $sendto = $objectobj->email;
383 $objectobj->fetch_thirdparty();
384 $sendto = $objectobj->thirdparty->email;
388 if (empty($sendto)) {
389 if ($objectobj->element ==
'societe') {
391 $objectobj->thirdparty = $objectobj;
396 if (empty($thirdpartywithoutemail[$objectobj->thirdparty->id])) {
397 $resaction .=
'<div class="error">'.$langs->trans(
'NoRecipientEmail', $objectobj->thirdparty->name).
'</div><br>';
399 dol_syslog(
'No recipient for thirdparty: '.$objectobj->thirdparty->name, LOG_WARNING);
400 $thirdpartywithoutemail[$objectobj->thirdparty->id] = 1;
404 if (
GETPOST(
'addmaindocfile')) {
411 $filedir = $uploaddir.
'/'.$subdir.dol_sanitizeFileName($objectobj->ref);
412 $filepath = $filedir.
'/'.$filename;
415 if ($objectobj->element ==
'invoice_supplier') {
416 $fileparams =
dol_most_recent_file($uploaddir.
'/'.
get_exdir($objectobj->id, 2, 0, 0, $objectobj, $objectobj->element).$objectobj->ref, preg_quote($objectobj->ref,
'/').
'([^\-])+');
417 $filepath = $fileparams[
'fullname'];
421 $filename_found =
'';
422 $filepath_found =
'';
423 $file_check_list = array();
424 $file_check_list[] = array(
428 if (
getDolGlobalString(
'MAIL_MASS_ACTION_ADD_LAST_IF_MAIN_DOC_NOT_FOUND') && !empty($objectobj->last_main_doc)) {
429 $file_check_list[] = array(
430 'name' => basename($objectobj->last_main_doc),
431 'path' => DOL_DATA_ROOT .
'/' . $objectobj->last_main_doc,
434 foreach ($file_check_list as $file_check_arr) {
436 $filename_found = $file_check_arr[
'name'];
437 $filepath_found = $file_check_arr[
'path'];
442 if ($filepath_found) {
444 $attachedfilesThirdpartyObj[$thirdpartyid][$objectid] = array(
445 'paths' => array($filepath_found),
446 'names' => array($filename_found),
451 $langs->load(
"errors");
452 foreach ($file_check_list as $file_check_arr) {
453 $resaction .=
'<div class="error">'.$langs->trans(
'ErrorCantReadFile', $file_check_arr[
'path']).
'</div><br>';
454 dol_syslog(
'Failed to read file: '.$file_check_arr[
'path'], LOG_WARNING);
461 $listofqualifiedobj[$objectid] = $objectobj;
462 $listofqualifiedref[$objectid] = $objectobj->ref;
469 if (count($listofqualifiedobj) > 0) {
470 $langs->load(
"commercial");
473 $fromtype =
GETPOST(
'fromtype');
474 if ($fromtype ===
'user') {
475 $from =
dol_string_nospecial($user->getFullName($langs),
' ', array(
",")).
' <'.$user->email.
'>';
476 } elseif ($fromtype ===
'company') {
478 } elseif (preg_match(
'/user_aliases_(\d+)/', $fromtype, $reg)) {
479 $tmp = explode(
',', $user->email_aliases);
480 $from = trim($tmp[((
int) $reg[1] - 1)]);
481 } elseif (preg_match(
'/global_aliases_(\d+)/', $fromtype, $reg)) {
483 $from = trim($tmp[((
int) $reg[1] - 1)]);
484 } elseif (preg_match(
'/senderprofile_(\d+)_(\d+)/', $fromtype, $reg)) {
485 $sql =
"SELECT rowid, label, email FROM ".MAIN_DB_PREFIX.
"c_email_senderprofile WHERE rowid = ".(int) $reg[1];
486 $resql = $db->query($sql);
487 $obj = $db->fetch_object($resql);
496 $subject =
GETPOST(
'subject',
'restricthtml');
497 $message =
GETPOST(
'message',
'restricthtml');
499 $sendtobcc =
GETPOST(
'sendtoccc');
500 if ($objectclass ==
'Propal') {
503 if ($objectclass ==
'Commande') {
506 if ($objectclass ==
'Facture') {
509 if ($objectclass ==
'SupplierProposal') {
510 $sendtobcc .= (!
getDolGlobalString(
'MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO') ?
'' : (($sendtobcc ?
", " :
"") .
getDolGlobalString(
'MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO')));
512 if ($objectclass ==
'CommandeFournisseur') {
515 if ($objectclass ==
'FactureFournisseur') {
518 if ($objectclass ==
'Project') {
524 $looparray = array();
525 if (!$oneemailperrecipient) {
526 $looparray = $listofqualifiedobj;
527 foreach ($looparray as $key => $objecttmp) {
528 $looparray[$key]->thirdparty = $thirdparty;
531 $objectforloop =
new $objectclass($db);
532 $objectforloop->thirdparty = $thirdparty;
533 $looparray[0] = $objectforloop;
536 dol_syslog(
"We have set an array of ".count($looparray).
" emails to send. oneemailperrecipient=".$oneemailperrecipient);
538 foreach ($looparray as $objectid => $objecttmp) {
540 if (isModEnabled(
'project') && method_exists($objecttmp,
'fetchProject') && is_null($objecttmp->project)) {
541 $objecttmp->fetchProject();
544 $substitutionarray[
'__ID__'] = ($oneemailperrecipient ? implode(
', ', array_keys($listofqualifiedobj)) : $objecttmp->id);
545 $substitutionarray[
'__REF__'] = ($oneemailperrecipient ? implode(
', ', $listofqualifiedref) : $objecttmp->
ref);
546 $substitutionarray[
'__EMAIL__'] = $thirdparty->email;
547 $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"/>';
549 if ($oneemailperrecipient) {
550 $substitutionarray[
'__ONLINE_PAYMENT_URL__'] =
'';
551 $substitutionarray[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
'';
554 $parameters = array(
'mode' =>
'formemail');
556 if (!empty($listofobjectthirdparties)) {
557 $parameters[
'listofobjectthirdparties'] = $listofobjectthirdparties;
559 if (!empty($listofobjectref)) {
560 $parameters[
'listofobjectref'] = $listofobjectref;
568 $attachedfiles = array(
'paths' => array(),
'names' => array(),
'mimes' => array());
569 if ($oneemailperrecipient) {
571 if (is_array($attachedfilesThirdpartyObj[$thirdparty->id]) && count($attachedfilesThirdpartyObj[$thirdparty->id])) {
572 foreach ($attachedfilesThirdpartyObj[$thirdparty->id] as $keyObjId => $objAttachedFiles) {
574 $attachedfiles = array(
575 'paths' => array_merge($attachedfiles[
'paths'], $objAttachedFiles[
'paths']),
576 'names' => array_merge($attachedfiles[
'names'], $objAttachedFiles[
'names']),
577 'mimes' => array_merge($attachedfiles[
'mimes'], $objAttachedFiles[
'mimes'])
581 } elseif (!empty($attachedfilesThirdpartyObj[$thirdparty->id][$objectid])) {
584 $attachedfiles = $attachedfilesThirdpartyObj[$thirdparty->id][$objectid];
587 $filepath = $attachedfiles[
'paths'];
588 $filename = $attachedfiles[
'names'];
589 $mimetype = $attachedfiles[
'mimes'];
592 if ($oneemailperrecipient) {
593 $trackid =
'thi'.$thirdparty->id;
594 if ($objecttmp->element ==
'expensereport') {
595 $trackid =
'use'.$thirdparty->id;
596 } elseif ($objecttmp->element ==
'contact') {
597 $trackid =
'ctc'.$thirdparty->id;
598 } elseif ($objecttmp->element ==
'holiday') {
599 $trackid =
'use'.$thirdparty->id;
602 $trackid = strtolower(get_class($objecttmp));
603 if (get_class($objecttmp) ==
'Contact') {
605 } elseif (get_class($objecttmp) ==
'Contrat') {
607 } elseif (get_class($objecttmp) ==
'Propal') {
609 } elseif (get_class($objecttmp) ==
'Commande') {
611 } elseif (get_class($objecttmp) ==
'Facture') {
613 } elseif (get_class($objecttmp) ==
'SupplierProposal') {
615 } elseif (get_class($objecttmp) ==
'CommandeFournisseur') {
617 } elseif (get_class($objecttmp) ==
'FactureFournisseur') {
621 $trackid .= $objecttmp->id;
627 if (empty($sendcontext)) {
628 $sendcontext =
'standard';
632 $vardir =
$conf->user->dir_output.
"/".$user->id;
633 $upload_dir_tmp = $vardir.
'/temp';
636 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
637 $mailfile =
new CMailFile($subjectreplaced, $sendto, $from, $messagereplaced, $filepath, $mimetype, $filename, $sendtocc, $sendtobcc, $deliveryreceipt, -1,
'',
'', $trackid,
'', $sendcontext,
'', $upload_dir_tmp);
638 if ($mailfile->error) {
639 $resaction .=
'<div class="error">'.$mailfile->error.
'</div>';
641 $result = $mailfile->sendfile();
643 $resaction .= $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($mailfile->addr_from, 2), $mailfile->getValidAddress($mailfile->addr_to, 2)).
'<br>';
648 foreach ($listofqualifiedobj as $objid2 => $objectobj2) {
649 if ((!$oneemailperrecipient) && $objid2 != $objectid) {
653 dol_syslog(
"Try to insert email event into agenda for objid=".$objid2.
" => objectobj=".get_class($objectobj2));
662 $actionmsg = $langs->transnoentities(
'MailSentByTo', $from, $sendto);
665 $actionmsg =
dol_concatdesc($actionmsg, $langs->transnoentities(
'Bcc').
": ".$sendtocc);
667 $actionmsg =
dol_concatdesc($actionmsg, $langs->transnoentities(
'MailTopic').
": ".$subjectreplaced);
668 $actionmsg =
dol_concatdesc($actionmsg, $langs->transnoentities(
'TextUsedInTheMessageBody').
":");
674 $objectobj2->sendtoid = (empty($contactidtosend) ? 0 : $contactidtosend);
675 $objectobj2->actionmsg = $actionmsg;
676 $objectobj2->actionmsg2 = $actionmsg2;
677 $objectobj2->fk_element = $objid2;
678 $objectobj2->elementtype = $objectobj2->element;
680 $objectobj2->actionmsg2 = $subjectreplaced;
683 $triggername = strtoupper(get_class($objectobj2)).
'_SENTBYMAIL';
684 if ($triggername ==
'SOCIETE_SENTBYMAIL') {
685 $triggername =
'COMPANY_SENTBYMAIL';
687 if ($triggername ==
'CONTRAT_SENTBYMAIL') {
688 $triggername =
'CONTRACT_SENTBYMAIL';
690 if ($triggername ==
'COMMANDE_SENTBYMAIL') {
691 $triggername =
'ORDER_SENTBYMAIL';
693 if ($triggername ==
'FACTURE_SENTBYMAIL') {
694 $triggername =
'BILL_SENTBYMAIL';
696 if ($triggername ==
'EXPEDITION_SENTBYMAIL') {
697 $triggername =
'SHIPPING_SENTBYMAIL';
699 if ($triggername ==
'COMMANDEFOURNISSEUR_SENTBYMAIL') {
700 $triggername =
'ORDER_SUPPLIER_SENTBYMAIL';
702 if ($triggername ==
'FACTUREFOURNISSEUR_SENTBYMAIL') {
703 $triggername =
'BILL_SUPPLIER_SENTBYMAIL';
705 if ($triggername ==
'SUPPLIERPROPOSAL_SENTBYMAIL') {
706 $triggername =
'PROPOSAL_SUPPLIER_SENTBYMAIL';
708 if ($triggername ==
'PROJET_SENTBYMAIL') {
709 $triggername =
'PROJECT_SENTBYMAIL';
712 if (!empty($triggername)) {
714 $result = $objectobj2->call_trigger($triggername, $user);
722 dol_syslog(
"Error in trigger ".$triggername.
' '.$db->lasterror(), LOG_ERR);
729 $langs->load(
"other");
730 if ($mailfile->error) {
731 $resaction .= $langs->trans(
'ErrorFailedToSendMail', $from, $sendto);
732 $resaction .=
'<br><div class="error">'.$mailfile->error.
'</div>';
734 $resaction .=
'<div class="warning">No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS</div>';
736 $resaction .= $langs->trans(
'ErrorFailedToSendMail', $from, $sendto) .
'<br><div class="error">(unhandled error)</div>';
744 $resaction .= ($resaction ?
'<br>' : $resaction);
745 $resaction .=
'<strong>'.$langs->trans(
"ResultOfMailSending").
':</strong><br>'.
"\n";
746 $resaction .= $langs->trans(
"NbSelected").
': '.count($toselect).
"\n<br>";
747 $resaction .= $langs->trans(
"NbIgnored").
': '.($nbignored ? $nbignored : 0).
"\n<br>";
748 $resaction .= $langs->trans(
"NbSent").
': '.($nbsent ? $nbsent : 0).
"\n<br>";
753 setEventMessages($langs->trans(
"EMailSentForNElements", $nbsent.
'/'.count($toselect)),
null,
'mesgs');
766if (!$error && $massaction ==
'cancelorders') {
771 $orders =
GETPOST(
'toselect',
'array');
772 foreach ($orders as $id_order) {
774 if ($cmd->fetch($id_order) <= 0) {
779 $langs->load(
'errors');
780 setEventMessages($langs->trans(
"ErrorObjectMustHaveStatusValidToBeCanceled", $cmd->ref),
null,
'errors');
785 $result = $cmd->cancel();
805if (!$error && $massaction ==
"builddoc" && $permissiontoread && !
GETPOST(
'button_search')) {
806 if (empty($diroutputmassaction)) {
807 dol_print_error(
null,
'include of actions_massactions.inc.php is done but var $diroutputmassaction was not defined');
811 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
812 require_once DOL_DOCUMENT_ROOT.
'/core/lib/pdf.lib.php';
813 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
815 $objecttmp =
new $objectclass($db);
816 $listofobjectid = array();
817 $listofobjectthirdparties = array();
818 $listofobjectref = array();
819 foreach ($toselect as $toselectid) {
820 $objecttmp =
new $objectclass($db);
821 $result = $objecttmp->fetch($toselectid);
823 $listofobjectid[$toselectid] = $toselectid;
824 $thirdpartyid = !empty($objecttmp->fk_soc) ? $objecttmp->fk_soc : $objecttmp->socid;
825 $listofobjectthirdparties[$thirdpartyid] = $thirdpartyid;
826 $listofobjectref[$toselectid] = $objecttmp->ref;
830 $arrayofinclusion = array();
831 foreach ($listofobjectref as $tmppdf) {
834 foreach ($listofobjectref as $tmppdf) {
835 $arrayofinclusion[] =
'^'.preg_quote(
dol_sanitizeFileName($tmppdf),
'/').
'_[a-zA-Z0-9\-\_\'\&\.]+\.pdf$';
837 $listoffiles =
dol_dir_list($uploaddir,
'all', 1, implode(
'|', $arrayofinclusion),
'\.meta$|\.png',
'date', SORT_DESC, 0, 1);
842 foreach ($listofobjectref as $basename) {
844 foreach ($listoffiles as $filefound) {
845 if (strstr($filefound[
"name"], $basename)) {
846 $files[] = $filefound[
'fullname'];
853 $outputlangs = $langs;
856 $newlang =
GETPOST(
'lang_id',
'aZ09');
861 if (!empty($newlang)) {
863 $outputlangs->setDefaultLang($newlang);
872 $filename = preg_replace(
'/\s/',
'_', $filename);
875 if (in_array($objecttmp->element, array(
'facture',
'invoice_supplier')) && $search_status ==
Facture::STATUS_VALIDATED) {
876 if ($option ==
'late') {
883 $filename .=
'_'.$year;
886 $filename .=
'_'.$month;
889 if (count($files) > 0) {
891 $file = $diroutputmassaction.
'/'.$filename.
'_'.
dol_print_date($now,
'dayhourlog').
'.pdf';
894 foreach ($files as $f) {
895 $input_files .=
' '.escapeshellarg($f);
898 $cmd =
'pdftk '.$input_files.
' cat output '.escapeshellarg($file);
902 if (file_exists($file)) {
905 $langs->load(
"exports");
908 setEventMessages($langs->trans(
'ErrorPDFTkOutputFileNotFound'),
null,
'errors');
911 setEventMessages($langs->trans(
'NoPDFAvailableForDocGenAmongChecked'),
null,
'errors');
916 $page_largeur = $formatarray[
'width'];
917 $page_hauteur = $formatarray[
'height'];
918 $format = array($page_largeur, $page_hauteur);
922 if (class_exists(
'TCPDF')) {
923 $pdf->setPrintHeader(
false);
924 $pdf->setPrintFooter(
false);
929 $pdf->SetCompression(
false);
934 foreach ($files as $file) {
936 $pagecount = $pdf->setSourceFile($file);
937 for ($i = 1; $i <= $pagecount; $i++) {
938 $tplidx = $pdf->importPage($i);
939 $s = $pdf->getTemplatesize($tplidx);
940 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
941 $pdf->useTemplate($tplidx);
950 $filename = preg_replace(
'/\s/',
'_', $filename);
954 if (in_array($objecttmp->element, array(
'facture',
'invoice_supplier')) && $search_status ==
Facture::STATUS_VALIDATED) {
955 if ($option ==
'late') {
962 $filename .=
'_'.$year;
965 $filename .=
'_'.$month;
969 $file = $diroutputmassaction.
'/'.$filename.
'_'.
dol_print_date($now,
'dayhourlog').
'.pdf';
970 $pdf->Output($file,
'F');
973 $langs->load(
"exports");
976 setEventMessages($langs->trans(
'NoPDFAvailableForDocGenAmongChecked'),
null,
'errors');
982if ($action ==
'remove_file') {
983 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
985 $langs->load(
"other");
986 $upload_dir = $diroutputmassaction;
987 $file = $upload_dir.
'/'.
GETPOST(
'file');
999if (!$error && $massaction ==
'validate' && $permissiontoadd) {
1000 $objecttmp =
new $objectclass($db);
1002 if (($objecttmp->element ==
'facture' || $objecttmp->element ==
'invoice') && isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_BILL')) {
1003 $langs->load(
"errors");
1004 setEventMessages($langs->trans(
'ErrorMassValidationNotAllowedWhenStockIncreaseOnAction'),
null,
'errors');
1007 if ($objecttmp->element ==
'invoice_supplier' && isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_BILL')) {
1008 $langs->load(
"errors");
1009 setEventMessages($langs->trans(
'ErrorMassValidationNotAllowedWhenStockIncreaseOnAction'),
null,
'errors');
1012 if ($objecttmp->element ==
'facture') {
1015 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"facture";
1016 $sql .=
" WHERE rowid IN (".$db->sanitize(implode(
",", $toselect)).
")";
1017 $sql .=
" ORDER BY datef";
1019 $resql = $db->query($sql);
1022 while (!empty($arr = $db->fetch_row($resql))) {
1023 $toselectnew[] = $arr[0];
1025 $toselect = (empty($toselectnew)) ? $toselect : $toselectnew;
1036 foreach ($toselect as $toselectid) {
1037 $result = $objecttmp->fetch($toselectid);
1039 if (method_exists($objecttmp,
'validate')) {
1040 $result = $objecttmp->validate($user);
1041 } elseif (method_exists($objecttmp,
'setValid')) {
1042 $result = $objecttmp->setValid($user);
1044 $objecttmp->error =
'No method validate or setValid on this object';
1048 $langs->load(
"errors");
1049 setEventMessages($langs->trans(
"ErrorObjectMustHaveStatusDraftToBeValidated", $objecttmp->ref),
null,
'errors');
1052 } elseif ($result < 0) {
1060 $outputlangs = $langs;
1063 $newlang =
GETPOST(
'lang_id',
'aZ09');
1065 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && empty($newlang) && property_exists($objecttmp,
'thirdparty')) {
1066 if ((property_exists($objecttmp,
'socid') || property_exists($objecttmp,
'fk_soc')) && empty($objecttmp->thirdparty)) {
1067 $objecttmp->fetch_thirdparty();
1069 if (!empty($objecttmp->thirdparty)) {
1070 $newlang = $objecttmp->thirdparty->default_lang;
1073 if (!empty($newlang)) {
1075 $outputlangs->setDefaultLang($newlang);
1076 $outputlangs->load(
'products');
1078 $model = $objecttmp->model_pdf;
1079 $ret = $objecttmp->fetch($objecttmp->id);
1081 $hidedetails = !empty($hidedetails) ? $hidedetails : (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS') ? 1 : 0);
1082 $hidedesc = !empty($hidedesc) ? $hidedesc : (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_HIDE_DESC') ? 1 : 0);
1083 $hideref = !empty($hideref) ? $hideref : (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_HIDE_REF') ? 1 : 0);
1084 $moreparams = !empty($moreparams) ? $moreparams :
null;
1086 $result = $objecttmp->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1104 setEventMessages($langs->trans(
"RecordModifiedSuccessfully"),
null,
'mesgs');
1114if (!$error && ($massaction ==
'delete' || ($action ==
'delete' && $confirm ==
'yes')) && $permissiontodelete) {
1117 $objecttmp =
new $objectclass($db);
1123 $unique_arr = array_unique($toselect);
1124 foreach ($unique_arr as $toselectid) {
1125 $result = $objecttmp->fetch($toselectid);
1129 $langs->load(
"errors");
1131 $TMsg[] =
'<div class="error">'.$langs->trans(
'ErrorOnlyDraftStatusCanBeDeletedInMassAction', $objecttmp->ref).
'</div><br>';
1135 if (method_exists($objecttmp,
'is_erasable') && $objecttmp->is_erasable() <= 0) {
1136 $langs->load(
"errors");
1138 $TMsg[] =
'<div class="error">'.$langs->trans(
'ErrorRecordHasChildren').
' '.$objecttmp->ref.
'</div><br>';
1143 $langs->load(
"errors");
1145 $TMsg[] =
'<div class="error">'.$langs->trans(
'ErrorLeaveRequestMustBeDraftCanceledOrRefusedToBeDeleted', $objecttmp->ref).
'</div><br>';
1149 if ($objectclass ==
"Task" && $objecttmp->hasChildren() > 0) {
1150 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task SET fk_task_parent = 0 WHERE fk_task_parent = ".((int) $objecttmp->id);
1151 $res = $db->query($sql);
1159 if ($objecttmp->element ==
'societe') {
1161 '@phan-var-force Societe $objecttmp';
1163 $result = $objecttmp->delete($objecttmp->id, $user, 1);
1165 $result = $objecttmp->delete($user);
1168 if (empty($result)) {
1169 $TMsg = array_merge($objecttmp->errors, $TMsg);
1170 } elseif ($result < 0) {
1184 if (empty($error)) {
1188 } elseif ($nbok > 0) {
1195 if (!empty($TMsg)) {
1210if (!$error && $massaction ==
'generate_doc' && $permissiontoread) {
1213@phan-var-force
'Commande'|
'CommandeFournisseur'|
'Contrat'|
'Expedition'|
'ExpenseReport'|
'Facture'|
'FactureFournisseur'|
'Fichinter'|
'Project'|
'Propal'|
'SupplierProposal' $objectclass
1218 foreach ($toselect as $toselectid) {
1219 $objecttmp =
new $objectclass($db);
1220 $result = $objecttmp->fetch($toselectid);
1222 $outputlangs = $langs;
1226 $newlang =
GETPOST(
'lang_id',
'aZ09');
1228 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && empty($newlang) && isset($objecttmp->thirdparty->default_lang)) {
1229 $newlang = $objecttmp->thirdparty->default_lang;
1231 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && empty($newlang) && isset($objecttmp->default_lang)) {
1232 $newlang = $objecttmp->default_lang;
1234 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && empty($newlang) && empty($objecttmp->thirdparty)) {
1235 $objecttmp->fetch_thirdparty();
1236 $newlang = $objecttmp->thirdparty->default_lang;
1238 if (!empty($newlang)) {
1240 $outputlangs->setDefaultLang($newlang);
1244 if (empty($hidedetails)) {
1247 if (empty($hidedesc)) {
1250 if (empty($hideref)) {
1253 if (empty($moreparams)) {
1257 $result = $objecttmp->generateDocument($objecttmp->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1287if (!$error && ($action ==
'affecttag' && $confirm ==
'yes') && $permissiontoadd) {
1291 $affecttag_type =
GETPOST(
'affecttag_type',
'alpha');
1292 if (!empty($affecttag_type)) {
1293 $affecttag_type_array = explode(
',', $affecttag_type);
1297 if (!empty($affecttag_type_array)) {
1299 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1301 $to_affecttag_type_array = array();
1302 $categ_type_array = $categ->getMapList();
1303 foreach ($categ_type_array as $categdef) {
1304 if (in_array($categdef[
'code'], $affecttag_type_array)) {
1305 $to_affecttag_type_array[] = $categdef[
'code'];
1310 if (!empty($to_affecttag_type_array)) {
1311 foreach ($to_affecttag_type_array as $categ_type) {
1312 $contcats =
GETPOST(
'contcats_' . $categ_type,
'array');
1314 foreach ($toselect as $toselectid) {
1315 $result =
$object->fetch($toselectid);
1318 $result =
$object->setCategoriesCommon($contcats, $categ_type,
false);
1337 $toselect = array();
1343if (!$error && ($action ==
'updateprice' && $confirm ==
'yes') && $permissiontoadd) {
1344 '@phan-var-force Product|ProductCustomerPrice $obj';
1345 '@phan-var-force Product|ProductCustomerPrice $object';
1348 if (GETPOSTISSET(
'pricerate')) {
1350 if ($pricepercentage == 0) {
1353 foreach ($toselect as $toselectid) {
1354 $result =
$object->fetch($toselectid);
1357 if ($obj->price_base_type ==
'TTC') {
1358 $newprice =
$object->price_ttc * (100 + $pricepercentage) / 100;
1359 $minprice =
$object->price_min_ttc;
1361 $newprice =
$object->price * (100 + $pricepercentage) / 100;
1362 $minprice =
$object->price_min;
1364 $res =
$object->updatePrice($newprice, $obj->price_base_type, $user,
$object->tva_tx, $minprice, 0,
$object->tva_npr, 0, 0, array(),
$object->default_vat_code);
1384 $toselect = array();
1390if (!$error && ($action ==
'setsupervisor' && $confirm ==
'yes') && $permissiontoadd) {
1391 '@phan-var-force User $object';
1394 $supervisortoset =
GETPOSTINT(
'supervisortoset');
1395 if (!empty($supervisortoset)) {
1396 foreach ($toselect as $toselectid) {
1397 $result =
$object->fetch($toselectid);
1400 $object->fk_user = $supervisortoset;
1401 $res =
$object->update($user);
1421 $toselect = array();
1427if (!$error && ($action ==
'affectuser' && $confirm ==
'yes') && $permissiontoadd) {
1431 $usertoaffect =
GETPOST(
'usertoaffect');
1432 $projectrole =
GETPOST(
'projectrole');
1433 $tasksrole =
GETPOST(
'tasksrole');
1434 if (!empty($usertoaffect)) {
1435 foreach ($toselect as $toselectid) {
1436 $result =
$object->fetch($toselectid);
1439 $res =
$object->add_contact($usertoaffect, $projectrole,
'internal');
1441 $taskstatic =
new Task($db);
1442 $task_array = $taskstatic->getTasksArray(
null,
null,
$object->id, 0, 0);
1444 foreach ($task_array as $task) {
1445 $tasksToAffect =
new Task($db);
1446 $result = $tasksToAffect->fetch($task->id);
1448 $res = $tasksToAffect->add_contact($usertoaffect, $tasksrole,
'internal');
1472 $toselect = array();
1478if (!$error && ($massaction ==
'enable' || ($action ==
'enable' && $confirm ==
'yes')) && $permissiontoadd) {
1481 $objecttmp =
new $objectclass($db);
1483 foreach ($toselect as $toselectid) {
1484 $result = $objecttmp->fetch($toselectid);
1486 if (in_array($objecttmp->element, array(
'societe'))) {
1487 $result = $objecttmp->setStatut(1);
1515if (!$error && ($massaction ==
'disable' || ($action ==
'disable' && $confirm ==
'yes')) && $permissiontoadd) {
1518 $objecttmp =
new $objectclass($db);
1520 foreach ($toselect as $toselectid) {
1521 $result = $objecttmp->fetch($toselectid);
1523 if (in_array($objecttmp->element, array(
'societe'))) {
1524 $result = $objecttmp->setStatut(0);
1552if (!$error && $action ==
'confirm_edit_value_extrafields' && $confirm ==
'yes' && $permissiontoadd) {
1555 $objecttmp =
new $objectclass($db);
1557 $e->fetch_name_optionals_label($objecttmp->table_element);
1560 $extrafieldKeyToUpdate =
GETPOST(
'extrafield-key-to-update');
1563 foreach ($toselect as $toselectid) {
1565 $objecttmp =
new $objectclass($db);
1566 $result = $objecttmp->fetch($toselectid);
1569 $ret = $e->setOptionalsFromPost(
null, $objecttmp, $extrafieldKeyToUpdate);
1571 $objecttmp->insertExtraFields();
1595if (!$error && ($massaction ==
'affectcommercial' || ($action ==
'affectcommercial' && $confirm ==
'yes')) && $permissiontoadd) {
1598 $objecttmp =
new $objectclass($db);
1601 foreach ($toselect as $toselectid) {
1602 $result = $objecttmp->fetch($toselectid);
1604 if (in_array($objecttmp->element, array(
'societe'))) {
1605 $result = $objecttmp->setSalesRep(
GETPOST(
"commercial",
"alpha"));
1623 setEventMessages($langs->trans(
"CommercialsAffected", $nbok),
null,
'mesgs');
1633if (!$error && ($massaction ==
'unassigncommercial' || ($action ==
'unassigncommercial' && $confirm ==
'yes')) && $permissiontoadd) {
1636 $objecttmp =
new $objectclass($db);
1639 foreach ($toselect as $toselectid) {
1640 $result = $objecttmp->fetch($toselectid);
1642 if (in_array($objecttmp->element, array(
'societe'))) {
1643 $TCommercial =
GETPOST(
"commercial",
"alpha");
1644 if (is_array($TCommercial)) {
1645 foreach ($TCommercial as $commercial) {
1646 $result = $objecttmp->del_commercial($user, $commercial);
1666 setEventMessages($langs->trans(
"CommercialsDisaffected", $nbok),
null,
'mesgs');
1676if (!$error && ($massaction ==
'approveleave' || ($action ==
'approveleave' && $confirm ==
'yes')) && $permissiontoapprove) {
1679 $objecttmp =
new $objectclass($db);
1680 '@phan-var-force Holiday $objecttmp';
1682 foreach ($toselect as $toselectid) {
1683 $result = $objecttmp->fetch($toselectid);
1686 setEventMessages($langs->trans(
'StatusOfRefMustBe', $objecttmp->ref, $langs->transnoentitiesnoconv(
'Validated')),
null,
'warnings');
1689 if ($user->id == $objecttmp->fk_validator) {
1690 $objecttmp->oldcopy =
dol_clone($objecttmp, 2);
1692 $objecttmp->date_valid =
dol_now();
1693 $objecttmp->fk_user_valid = $user->id;
1695 $objecttmp->statut = $objecttmp->status;
1697 $verif = $objecttmp->approve($user);
1707 $nbopenedday =
num_open_day($objecttmp->date_debut_gmt, $objecttmp->date_fin_gmt, 0, 1, $objecttmp->halfday);
1708 $soldeActuel = $objecttmp->getCpforUser($objecttmp->fk_user, $objecttmp->fk_type);
1709 $newSolde = ($soldeActuel - $nbopenedday);
1712 $result = $objecttmp->addLogCP($user->id, $objecttmp->fk_user, $langs->transnoentitiesnoconv(
"Holidays"), $newSolde, $objecttmp->fk_type);
1719 $result = $objecttmp->updateSoldeCP($objecttmp->fk_user, $newSolde, $objecttmp->fk_type);
1728 $destinataire =
new User($db);
1729 $destinataire->fetch($objecttmp->fk_user);
1730 $emailTo = $destinataire->email;
1733 dol_syslog(
"User that request leave has no email, so we redirect directly to finished page without sending email");
1736 $expediteur =
new User($db);
1737 $expediteur->fetch($objecttmp->fk_validator);
1747 $subject = $societeName.
" - ".$langs->transnoentitiesnoconv(
"HolidaysValidated");
1750 $message = $langs->transnoentitiesnoconv(
"Hello").
" ".$destinataire->firstname.
",\n";
1753 $message .= $langs->transnoentities(
"HolidaysValidatedBody",
dol_print_date($objecttmp->date_debut,
'day'),
dol_print_date($objecttmp->date_fin,
'day')).
"\n";
1755 $message .=
"- ".$langs->transnoentitiesnoconv(
"ValidatedBy").
" : ".
dolGetFirstLastname($expediteur->firstname, $expediteur->lastname).
"\n";
1757 $message .=
"- ".$langs->transnoentitiesnoconv(
"Link").
" : ".$dolibarr_main_url_root.
"/holiday/card.php?id=".$objecttmp->id.
"\n\n";
1760 $trackid =
'leav'.$objecttmp->id;
1762 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
1763 $mail =
new CMailFile($subject, $emailTo, $emailFrom, $message, array(), array(), array(),
'',
'', 0, 0,
'',
'', $trackid);
1766 $result = $mail->sendfile();
1775 $langs->load(
"errors");
1776 setEventMessages($langs->trans(
'ErrorNotApproverForHoliday', $objecttmp->ref),
null,
'errors');
1788 } elseif ($nbok == 1) {
1797if (!$error && ($massaction ==
'increaseholiday' || ($action ==
'increaseholiday' && $confirm ==
'yes')) && $permissiontoapprove && is_array($toselect)) {
1798 '@phan-var-force Holiday $holiday';
1800 $objecttmp =
new $objectclass($db);
1802 $typeholiday =
GETPOST(
'typeholiday',
'alpha');
1805 if ($nbdaysholidays <= 0) {
1811 foreach ($toselect as $toselectid) {
1812 $balancecpuser = $objecttmp->getCPforUser($toselectid, $typeholiday);
1813 if (!empty($balancecpuser)) {
1814 $newnbdaysholidays = $nbdaysholidays + $balancecpuser;
1816 $newnbdaysholidays = $nbdaysholidays;
1818 $result = $holiday->addLogCP($user->id, $toselectid, $langs->transnoentitiesnoconv(
'ManualUpdate'), $newnbdaysholidays, $typeholiday);
1825 $objecttmp->updateSoldeCP($toselectid, $newnbdaysholidays, $typeholiday);
1838 setEventMessages($langs->trans(
"HolidayRecordsIncreased", $nbok),
null,
'mesgs');
1839 } elseif ($nbok == 1) {
1843 $toselect = array();
1850if (!$error && ($massaction ==
'clonetasks' || ($action ==
'clonetasks' && $confirm ==
'yes'))) {
1853 include_once DOL_DOCUMENT_ROOT.
'/projet/class/task.class.php';
1855 $origin_task =
new Task($db);
1856 $clone_task =
new Task($db);
1857 $newproject =
new Project($db);
1861 $iscontactofnewproject = 0;
1862 if (empty($newproject->public)) {
1863 $tmps = $newproject->getProjectsAuthorizedForUser($user, 0, 1, 0,
'(fk_statut:=:1)');
1864 $tmparray = explode(
',', $tmps);
1865 if (!in_array($newproject->id, $tmparray)) {
1866 $iscontactofnewproject = 1;
1871 $permisstiontoadd =
false;
1872 if ($user->hasRight(
'project',
'all',
'creer') || ($user->hasRight(
'project',
'creer') && ($newproject->public || $iscontactofnewproject))) {
1873 $permisstiontoadd =
true;
1876 if ($permisstiontoadd) {
1877 foreach (
GETPOST(
'selected') as $task) {
1878 $origin_task->fetch($task,
'', 0);
1883 require_once DOL_DOCUMENT_ROOT .
"/core/modules/project/task/" .
getDolGlobalString(
'PROJECT_TASK_ADDON') .
'.php';
1884 $modTask =
new $classnamemodtask();
1885 '@phan-var-force ModeleNumRefTask $modTask';
1886 $defaultref = $modTask->getNextValue(
null, $clone_task);
1890 $clone_task->fk_project =
GETPOSTINT(
'projectid');
1891 $clone_task->ref = $defaultref;
1892 $clone_task->label = $origin_task->label;
1893 $clone_task->description = $origin_task->description;
1894 $clone_task->planned_workload = $origin_task->planned_workload;
1895 $clone_task->fk_task_parent = $origin_task->fk_task_parent;
1896 $clone_task->date_c =
dol_now();
1897 $clone_task->date_start = $origin_task->date_start;
1898 $clone_task->date_end = $origin_task->date_end;
1899 $clone_task->progress = $origin_task->progress;
1902 $ret = $extrafields->setOptionalsFromPost(
null, $clone_task);
1904 $taskid = $clone_task->create($user);
1907 $result = $clone_task->add_contact(
GETPOSTINT(
"userid"),
'TASKEXECUTIVE',
'internal');
1910 if ($db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1911 $langs->load(
"projects");
1913 $duplicate_code_error =
true;
1924 setEventMessages($langs->trans(
'NumberOfTasksCloned', $num),
null,
'mesgs');
1925 header(
"Location: ".DOL_URL_ROOT.
'/projet/tasks.php?id='.
GETPOSTINT(
'projectid'));
1933if (empty($toselect)) {
1936$parameters[
'toselect'] = &$toselect;
1937$parameters[
'uploaddir'] = $uploaddir;
1938$parameters[
'massaction'] = $massaction;
1939$parameters[
'diroutputmassaction'] = isset($diroutputmassaction) ? $diroutputmassaction :
null;
1941$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_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
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.
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)
Returns a hash (non reversible encryption) of a string.