68@phan-var-force ?string $permissiontoread
69@phan-var-force ?string $permissiontodelete
70@phan-var-force ?string $permissiontoclose
71@phan-var-force ?string $permissiontoapprove
72@phan-var-force ?int[] $toselect
73@phan-var-force ?string $diroutputmassaction
74@phan-var-force ?string $objectlabel
75@phan-var-force ?string $option
76@phan-var-force ?string $deliveryreceipt
81if (empty($objectclass) || empty($uploaddir)) {
82 dol_print_error(
null,
'include of actions_massactions.inc.php is done but var $objectclass or $uploaddir was not defined');
85if (empty($massaction)) {
92@phan-var-force "CommonObject"|"CommandeFournisseur"|"ConferenceOrBoothAttendee"|"Contrat"|"Contact"|"Expedition"|"ExpenseReport"|"Facture"|"FactureFournisseur"|"Fichinter"|"Holiday"|"Partnership"|"Project"|"Propal"|"Societe"|"SupplierProposal" $objectclass
93@phan-var-force string $massaction
94@phan-var-force string $uploaddir
99if (!empty($permtoread) && empty($permissiontoread)) {
100 $permissiontoread = $permtoread;
102if (!empty($permtocreate) && empty($permissiontoadd)) {
103 $permissiontoadd = $permtocreate;
105if (!empty($permtodelete) && empty($permissiontodelete)) {
106 $permissiontodelete = $permtodelete;
110$maxformassaction = (!
getDolGlobalString(
'MAIN_LIMIT_FOR_MASS_ACTIONS') ? 1000 :
$conf->global->MAIN_LIMIT_FOR_MASS_ACTIONS);
111if ($massaction && is_array($toselect) && count($toselect) < 1) {
115if (!$error && isset($toselect) && is_array($toselect) && count($toselect) > $maxformassaction) {
116 setEventMessages($langs->trans(
'TooManyRecordForMassAction', $maxformassaction),
null,
'errors');
120if (!$error && $massaction ==
'confirm_presend' && !
GETPOST(
'sendmail')) {
121 $massaction =
'presend';
124if (!$error && $massaction ==
'confirm_presend') {
128 $langs->load(
"mails");
129 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
130 include_once DOL_DOCUMENT_ROOT.
'/core/lib/signature.lib.php';
132 $listofobjectid = array();
133 $listofobjectthirdparties = array();
134 $listofobjectcontacts = array();
135 $listofobjectref = array();
136 $contactidtosend = array();
137 $attachedfilesThirdpartyObj = array();
138 $oneemailperrecipient = (
GETPOSTINT(
'oneemailperrecipient') ? 1 : 0);
142 $objecttmp =
new $objectclass($db);
145 $thirdparty =
new Societe($db);
146 if ($objecttmp->element ==
'expensereport') {
147 $thirdparty =
new User($db);
148 } elseif ($objecttmp->element ==
'contact') {
149 $thirdparty =
new Contact($db);
150 } elseif ($objecttmp->element ==
'partnership' &&
getDolGlobalString(
'PARTNERSHIP_IS_MANAGED_FOR') ==
'member') {
152 } elseif ($objecttmp->element ==
'holiday') {
153 $thirdparty =
new User($db);
154 } elseif ($objecttmp->element ==
'conferenceorboothattendee') {
158 foreach ($toselect as $toselectid) {
159 $objecttmp =
new $objectclass($db);
160 '@phan-var-force CommonObject $objecttmp';
162 $result = $objecttmp->fetch($toselectid);
164 $listofobjectid[$toselectid] = $toselectid;
167 $tmpobjectid = ($objecttmp->fk_soc ? $objecttmp->fk_soc : $objecttmp->socid);
168 if ($objecttmp->element ==
'societe') {
169 '@phan-var-force Societe $objecttmp';
171 $tmpobjectid = $objecttmp->id;
172 } elseif ($objecttmp->element ==
'contact') {
173 '@phan-var-force Contact $objecttmp';
175 $tmpobjectid = $objecttmp->id;
176 } elseif ($objecttmp->element ==
'expensereport') {
177 '@phan-var-force ExpenseReport $objecttmp';
179 $tmpobjectid = $objecttmp->fk_user_author;
180 } elseif ($objecttmp->element ==
'partnership' &&
getDolGlobalString(
'PARTNERSHIP_IS_MANAGED_FOR') ==
'member') {
181 '@phan-var-force Partnership $objecttmp';
183 $tmpobjectid = $objecttmp->fk_member;
184 } elseif ($objecttmp->element ==
'holiday') {
185 '@phan-var-force Holiday $objecttmp';
187 $tmpobjectid = $objecttmp->fk_user;
188 } elseif ($objecttmp->element ==
'conferenceorboothattendee') {
189 '@phan-var-force ConferenceOrBoothAttendee $objecttmp';
191 $tmpobjectid = $objecttmp->id;
193 if (empty($tmpobjectid)) {
197 if ($objectclass ==
'Facture') {
198 '@phan-var-force Facture $objecttmp';
200 $tmparraycontact = array();
201 $tmparraycontact = $objecttmp->liste_contact(-1,
'external', 0,
'BILLING');
202 if (is_array($tmparraycontact) && count($tmparraycontact) > 0) {
203 foreach ($tmparraycontact as $data_email) {
204 $listofobjectcontacts[$toselectid][$data_email[
'id']] = $data_email[
'email'];
207 } elseif ($objectclass ==
'CommandeFournisseur') {
208 '@phan-var-force CommandeFournisseur $objecttmp';
210 $tmparraycontact = array();
211 $tmparraycontact = $objecttmp->liste_contact(-1,
'external', 0,
'CUSTOMER');
212 if (is_array($tmparraycontact) && count($tmparraycontact) > 0) {
213 foreach ($tmparraycontact as $data_email) {
214 $listofobjectcontacts[$toselectid][$data_email[
'id']] = $data_email[
'email'];
219 $listofobjectthirdparties[$tmpobjectid] = $tmpobjectid;
220 $listofobjectref[$tmpobjectid][$toselectid] = $objecttmp;
226 if (
GETPOST(
'fromtype',
'alpha') ===
'user' && empty($user->email)) {
229 $massaction =
'presend';
232 $receiver =
GETPOST(
'receiver',
'alphawithlgt');
233 if (!is_array($receiver)) {
234 if (empty($receiver) || $receiver ==
'-1') {
237 $receiver = array($receiver);
240 if (!trim(
GETPOST(
'sendto',
'alphawithlgt')) && count($receiver) == 0 && count($listofobjectthirdparties) == 1) {
242 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Recipient")),
null,
'warnings');
243 $massaction =
'presend';
246 if (!
GETPOST(
'subject',
'restricthtml')) {
248 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"MailTopic")),
null,
'warnings');
249 $massaction =
'presend';
254 foreach ($listofobjectthirdparties as $thirdpartyid) {
255 $result = $thirdparty->fetch($thirdpartyid);
268 if (trim(
GETPOST(
'sendto',
'alphawithlgt'))) {
270 $tmparray[] = trim(
GETPOST(
'sendto',
'alphawithlgt'));
272 if (count($receiver) > 0 && is_object($thirdparty)) {
273 foreach ($receiver as $key => $val) {
275 if ($val ==
'thirdparty') {
276 $tmparray[] = $thirdparty->name.
' <'.$thirdparty->email.
'>';
277 } elseif ($val && method_exists($thirdparty,
'contact_get_property')) {
278 $tmparray[] = $thirdparty->contact_get_property((
int) $val,
'email');
283 $sendto = implode(
',', $tmparray);
286 $receivercc =
GETPOST(
'receivercc',
'alphawithlgt');
287 if (!is_array($receivercc)) {
288 if ($receivercc ==
'-1') {
289 $receivercc = array();
291 $receivercc = array($receivercc);
295 if (trim(
GETPOST(
'sendtocc',
'alphawithlgt'))) {
296 $tmparray[] = trim(
GETPOST(
'sendtocc',
'alphawithlgt'));
298 if (count($receivercc) > 0) {
299 foreach ($receivercc as $key => $val) {
301 if ($val ==
'thirdparty') {
302 $tmparray[] = $thirdparty->name.
' <'.$thirdparty->email.
'>';
304 $tmparray[] = $thirdparty->contact_get_property((
int) $val,
'email');
309 $sendtocc = implode(
',', $tmparray);
312 $listofqualifiedobj = array();
313 $listofqualifiedref = array();
314 $thirdpartywithoutemail = array();
316 foreach ($listofobjectref[$thirdpartyid] as $objectid => $objectobj) {
319 $langs->load(
"errors");
321 $resaction .=
'<div class="error">'.$langs->trans(
'ErrorOnlyProposalNotDraftCanBeSentInMassAction', $objectobj->ref).
'</div><br>';
325 $langs->load(
"errors");
327 $resaction .=
'<div class="error">'.$langs->trans(
'ErrorOnlyOrderNotDraftCanBeSentInMassAction', $objectobj->ref).
'</div><br>';
331 $langs->load(
"errors");
333 $resaction .=
'<div class="error">'.$langs->trans(
'ErrorOnlyInvoiceValidatedCanBeSentInMassAction', $objectobj->ref).
'</div><br>';
338 if (empty($sendto)) {
339 if ($objectobj->element ==
'societe') {
340 $sendto = $objectobj->email;
341 } elseif ($objectobj->element ==
'expensereport') {
342 $fuser =
new User($db);
343 $fuser->fetch($objectobj->fk_user_author);
344 $sendto = $fuser->email;
345 } elseif ($objectobj->element ==
'contact') {
347 $fcontact->fetch($objectobj->id);
348 $sendto = $fcontact->email;
349 } elseif ($objectobj->element ==
'partnership' &&
getDolGlobalString(
'PARTNERSHIP_IS_MANAGED_FOR') ==
'member') {
351 $fadherent->fetch($objectobj->fk_member);
352 $sendto = $fadherent->email;
353 } elseif ($objectobj->element ==
'holiday') {
354 $fuser =
new User($db);
355 $fuser->fetch($objectobj->fk_user);
356 $sendto = $fuser->email;
357 } elseif ($objectobj->element ==
'facture' && !empty($listofobjectcontacts[$objectid])) {
358 $emails_to_sends = array();
359 $objectobj->fetch_thirdparty();
360 $contactidtosend = array();
361 foreach ($listofobjectcontacts[$objectid] as $contactemailid => $contactemailemail) {
362 $emails_to_sends[] = $objectobj->thirdparty->contact_get_property($contactemailid,
'email');
363 if (!in_array($contactemailid, $contactidtosend)) {
364 $contactidtosend[] = $contactemailid;
367 if (count($emails_to_sends) > 0) {
368 $sendto = implode(
',', $emails_to_sends);
370 } elseif ($objectobj->element ==
'order_supplier' && !empty($listofobjectcontacts[$objectid])) {
371 $emails_to_sends = array();
372 $objectobj->fetch_thirdparty();
373 $contactidtosend = array();
374 foreach ($listofobjectcontacts[$objectid] as $contactemailid => $contactemailemail) {
375 $emails_to_sends[] = $objectobj->thirdparty->contact_get_property($contactemailid,
'email');
376 if (!in_array($contactemailid, $contactidtosend)) {
377 $contactidtosend[] = $contactemailid;
380 if (count($emails_to_sends) > 0) {
381 $sendto = implode(
',', $emails_to_sends);
383 } elseif ($objectobj->element ==
'conferenceorboothattendee') {
384 $sendto = $objectobj->email;
386 $objectobj->fetch_thirdparty();
387 $sendto = $objectobj->thirdparty->email;
391 if (empty($sendto)) {
392 if ($objectobj->element ==
'societe') {
394 $objectobj->thirdparty = $objectobj;
399 if (empty($thirdpartywithoutemail[$objectobj->thirdparty->id])) {
400 $resaction .=
'<div class="error">'.$langs->trans(
'NoRecipientEmail', $objectobj->thirdparty->name).
'</div><br>';
402 dol_syslog(
'No recipient for thirdparty: '.$objectobj->thirdparty->name, LOG_WARNING);
403 $thirdpartywithoutemail[$objectobj->thirdparty->id] = 1;
407 if (
GETPOST(
'addmaindocfile')) {
414 $filedir = $uploaddir.
'/'.$subdir.dol_sanitizeFileName($objectobj->ref);
415 $filepath = $filedir.
'/'.$filename;
418 if ($objectobj->element ==
'invoice_supplier') {
419 $fileparams =
dol_most_recent_file($uploaddir.
'/'.
get_exdir($objectobj->id, 2, 0, 0, $objectobj, $objectobj->element).$objectobj->ref, preg_quote($objectobj->ref,
'/').
'([^\-])+');
420 $filepath = $fileparams[
'fullname'];
424 $filename_found =
'';
425 $filepath_found =
'';
426 $file_check_list = array();
427 $file_check_list[] = array(
431 if (
getDolGlobalString(
'MAIL_MASS_ACTION_ADD_LAST_IF_MAIN_DOC_NOT_FOUND') && !empty($objectobj->last_main_doc)) {
432 $file_check_list[] = array(
433 'name' => basename($objectobj->last_main_doc),
434 'path' => DOL_DATA_ROOT .
'/' . $objectobj->last_main_doc,
437 foreach ($file_check_list as $file_check_arr) {
439 $filename_found = $file_check_arr[
'name'];
440 $filepath_found = $file_check_arr[
'path'];
445 if ($filepath_found) {
447 $attachedfilesThirdpartyObj[$thirdpartyid][$objectid] = array(
448 'paths' => array($filepath_found),
449 'names' => array($filename_found),
454 $langs->load(
"errors");
455 foreach ($file_check_list as $file_check_arr) {
456 $resaction .=
'<div class="error">'.$langs->trans(
'ErrorCantReadFile', $file_check_arr[
'path']).
'</div><br>';
457 dol_syslog(
'Failed to read file: '.$file_check_arr[
'path'], LOG_WARNING);
464 $listofqualifiedobj[$objectid] = $objectobj;
465 $listofqualifiedref[$objectid] = $objectobj->ref;
472 if (count($listofqualifiedobj) > 0) {
473 $langs->load(
"commercial");
476 $fromtype =
GETPOST(
'fromtype');
477 if ($fromtype ===
'user') {
478 $from =
dol_string_nospecial($user->getFullName($langs),
' ', array(
",")).
' <'.$user->email.
'>';
479 } elseif ($fromtype ===
'company') {
481 } elseif (preg_match(
'/user_aliases_(\d+)/', $fromtype, $reg)) {
482 $tmp = explode(
',', $user->email_aliases);
483 $from = trim($tmp[((
int) $reg[1] - 1)]);
484 } elseif (preg_match(
'/global_aliases_(\d+)/', $fromtype, $reg)) {
486 $from = trim($tmp[((
int) $reg[1] - 1)]);
487 } elseif (preg_match(
'/senderprofile_(\d+)_(\d+)/', $fromtype, $reg)) {
488 $sql =
"SELECT rowid, label, email FROM ".MAIN_DB_PREFIX.
"c_email_senderprofile WHERE rowid = ".(int) $reg[1];
489 $resql = $db->query($sql);
490 $obj = $db->fetch_object($resql);
499 $subject =
GETPOST(
'subject',
'restricthtml');
500 $message =
GETPOST(
'message',
'restricthtml');
502 $sendtobcc =
GETPOST(
'sendtoccc');
503 if ($objectclass ==
'Propal') {
506 if ($objectclass ==
'Commande') {
509 if ($objectclass ==
'Facture') {
512 if ($objectclass ==
'SupplierProposal') {
513 $sendtobcc .= (!
getDolGlobalString(
'MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO') ?
'' : (($sendtobcc ?
", " :
"") .
getDolGlobalString(
'MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO')));
515 if ($objectclass ==
'CommandeFournisseur') {
518 if ($objectclass ==
'FactureFournisseur') {
521 if ($objectclass ==
'Project') {
527 $looparray = array();
528 if (!$oneemailperrecipient) {
529 $looparray = $listofqualifiedobj;
530 foreach ($looparray as $key => $objecttmp) {
531 $looparray[$key]->thirdparty = $thirdparty;
534 $objectforloop =
new $objectclass($db);
535 $objectforloop->thirdparty = $thirdparty;
536 $looparray[0] = $objectforloop;
539 dol_syslog(
"We have set an array of ".count($looparray).
" emails to send. oneemailperrecipient=".$oneemailperrecipient);
541 foreach ($looparray as $objectid => $objecttmp) {
543 if (isModEnabled(
'project') && method_exists($objecttmp,
'fetchProject') && is_null($objecttmp->project)) {
544 $objecttmp->fetchProject();
547 $substitutionarray[
'__ID__'] = ($oneemailperrecipient ? implode(
', ', array_keys($listofqualifiedobj)) : $objecttmp->id);
548 $substitutionarray[
'__REF__'] = ($oneemailperrecipient ? implode(
', ', $listofqualifiedref) : $objecttmp->
ref);
549 $substitutionarray[
'__EMAIL__'] = $thirdparty->email;
550 $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"/>';
552 if ($oneemailperrecipient) {
553 $substitutionarray[
'__ONLINE_PAYMENT_URL__'] =
'';
554 $substitutionarray[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
'';
557 $parameters = array(
'mode' =>
'formemail');
559 if (!empty($listofobjectthirdparties)) {
560 $parameters[
'listofobjectthirdparties'] = $listofobjectthirdparties;
562 if (!empty($listofobjectref)) {
563 $parameters[
'listofobjectref'] = $listofobjectref;
571 $attachedfiles = array(
'paths' => array(),
'names' => array(),
'mimes' => array());
572 if ($oneemailperrecipient) {
574 if (is_array($attachedfilesThirdpartyObj[$thirdparty->id]) && count($attachedfilesThirdpartyObj[$thirdparty->id])) {
575 foreach ($attachedfilesThirdpartyObj[$thirdparty->id] as $keyObjId => $objAttachedFiles) {
577 $attachedfiles = array(
578 'paths' => array_merge($attachedfiles[
'paths'], $objAttachedFiles[
'paths']),
579 'names' => array_merge($attachedfiles[
'names'], $objAttachedFiles[
'names']),
580 'mimes' => array_merge($attachedfiles[
'mimes'], $objAttachedFiles[
'mimes'])
584 } elseif (!empty($attachedfilesThirdpartyObj[$thirdparty->id][$objectid])) {
587 $attachedfiles = $attachedfilesThirdpartyObj[$thirdparty->id][$objectid];
590 $filepath = $attachedfiles[
'paths'];
591 $filename = $attachedfiles[
'names'];
592 $mimetype = $attachedfiles[
'mimes'];
595 if ($oneemailperrecipient) {
596 $trackid =
'thi'.$thirdparty->id;
597 if ($objecttmp->element ==
'expensereport') {
598 $trackid =
'use'.$thirdparty->id;
599 } elseif ($objecttmp->element ==
'contact') {
600 $trackid =
'ctc'.$thirdparty->id;
601 } elseif ($objecttmp->element ==
'holiday') {
602 $trackid =
'use'.$thirdparty->id;
605 $trackid = strtolower(get_class($objecttmp));
606 if (get_class($objecttmp) ==
'Contact') {
608 } elseif (get_class($objecttmp) ==
'Contrat') {
610 } elseif (get_class($objecttmp) ==
'Propal') {
612 } elseif (get_class($objecttmp) ==
'Commande') {
614 } elseif (get_class($objecttmp) ==
'Facture') {
616 } elseif (get_class($objecttmp) ==
'SupplierProposal') {
618 } elseif (get_class($objecttmp) ==
'CommandeFournisseur') {
620 } elseif (get_class($objecttmp) ==
'FactureFournisseur') {
624 $trackid .= $objecttmp->id;
630 if (empty($sendcontext)) {
631 $sendcontext =
'standard';
635 $vardir =
$conf->user->dir_output.
"/".$user->id;
636 $upload_dir_tmp = $vardir.
'/temp';
639 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
640 $mailfile =
new CMailFile($subjectreplaced, $sendto, $from, $messagereplaced, $filepath, $mimetype, $filename, $sendtocc, $sendtobcc, $deliveryreceipt, -1,
'',
'', $trackid,
'', $sendcontext,
'', $upload_dir_tmp);
641 if ($mailfile->error) {
642 $resaction .=
'<div class="error">'.$mailfile->error.
'</div>';
644 $result = $mailfile->sendfile();
646 $resaction .= $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($mailfile->addr_from, 2), $mailfile->getValidAddress($mailfile->addr_to, 2)).
'<br>';
651 foreach ($listofqualifiedobj as $objid2 => $objectobj2) {
652 if ((!$oneemailperrecipient) && $objid2 != $objectid) {
656 dol_syslog(
"Try to insert email event into agenda for objid=".$objid2.
" => objectobj=".get_class($objectobj2));
665 $actionmsg = $langs->transnoentities(
'MailSentByTo', $from, $sendto);
668 $actionmsg =
dol_concatdesc($actionmsg, $langs->transnoentities(
'Bcc').
": ".$sendtocc);
670 $actionmsg =
dol_concatdesc($actionmsg, $langs->transnoentities(
'MailTopic').
": ".$subjectreplaced);
671 $actionmsg =
dol_concatdesc($actionmsg, $langs->transnoentities(
'TextUsedInTheMessageBody').
":");
677 $objectobj2->sendtoid = (empty($contactidtosend) ? 0 : $contactidtosend);
678 $objectobj2->actionmsg = $actionmsg;
679 $objectobj2->actionmsg2 = $actionmsg2;
680 $objectobj2->fk_element = $objid2;
681 $objectobj2->elementtype = $objectobj2->element;
683 $objectobj2->actionmsg2 = $subjectreplaced;
686 $triggername = strtoupper(get_class($objectobj2)).
'_SENTBYMAIL';
687 if ($triggername ==
'SOCIETE_SENTBYMAIL') {
688 $triggername =
'COMPANY_SENTBYMAIL';
690 if ($triggername ==
'CONTRAT_SENTBYMAIL') {
691 $triggername =
'CONTRACT_SENTBYMAIL';
693 if ($triggername ==
'COMMANDE_SENTBYMAIL') {
694 $triggername =
'ORDER_SENTBYMAIL';
696 if ($triggername ==
'FACTURE_SENTBYMAIL') {
697 $triggername =
'BILL_SENTBYMAIL';
699 if ($triggername ==
'EXPEDITION_SENTBYMAIL') {
700 $triggername =
'SHIPPING_SENTBYMAIL';
702 if ($triggername ==
'COMMANDEFOURNISSEUR_SENTBYMAIL') {
703 $triggername =
'ORDER_SUPPLIER_SENTBYMAIL';
705 if ($triggername ==
'FACTUREFOURNISSEUR_SENTBYMAIL') {
706 $triggername =
'BILL_SUPPLIER_SENTBYMAIL';
708 if ($triggername ==
'SUPPLIERPROPOSAL_SENTBYMAIL') {
709 $triggername =
'PROPOSAL_SUPPLIER_SENTBYMAIL';
711 if ($triggername ==
'PROJET_SENTBYMAIL') {
712 $triggername =
'PROJECT_SENTBYMAIL';
715 if (!empty($triggername)) {
717 $result = $objectobj2->call_trigger($triggername, $user);
725 dol_syslog(
"Error in trigger ".$triggername.
' '.$db->lasterror(), LOG_ERR);
732 $langs->load(
"other");
733 if ($mailfile->error) {
734 $resaction .= $langs->trans(
'ErrorFailedToSendMail', $from, $sendto);
735 $resaction .=
'<br><div class="error">'.$mailfile->error.
'</div>';
737 $resaction .=
'<div class="warning">No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS</div>';
739 $resaction .= $langs->trans(
'ErrorFailedToSendMail', $from, $sendto) .
'<br><div class="error">(unhandled error)</div>';
747 $resaction .= ($resaction ?
'<br>' : $resaction);
748 $resaction .=
'<strong>'.$langs->trans(
"ResultOfMailSending").
':</strong><br>'.
"\n";
749 $resaction .= $langs->trans(
"NbSelected").
': '.count($toselect).
"\n<br>";
750 $resaction .= $langs->trans(
"NbIgnored").
': '.($nbignored ? $nbignored : 0).
"\n<br>";
751 $resaction .= $langs->trans(
"NbSent").
': '.($nbsent ? $nbsent : 0).
"\n<br>";
756 setEventMessages($langs->trans(
"EMailSentForNElements", $nbsent.
'/'.count($toselect)),
null,
'mesgs');
769if (!$error && $massaction ==
'cancelorders') {
774 $orders =
GETPOST(
'toselect',
'array');
775 foreach ($orders as $id_order) {
777 if ($cmd->fetch($id_order) <= 0) {
782 $langs->load(
'errors');
783 setEventMessages($langs->trans(
"ErrorObjectMustHaveStatusValidToBeCanceled", $cmd->ref),
null,
'errors');
788 $result = $cmd->cancel();
808if (!$error && $massaction ==
"builddoc" && $permissiontoread && !
GETPOST(
'button_search')) {
809 if (empty($diroutputmassaction)) {
810 dol_print_error(
null,
'include of actions_massactions.inc.php is done but var $diroutputmassaction was not defined');
814 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
815 require_once DOL_DOCUMENT_ROOT.
'/core/lib/pdf.lib.php';
816 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
818 $objecttmp =
new $objectclass($db);
819 $listofobjectid = array();
820 $listofobjectthirdparties = array();
821 $listofobjectref = array();
822 foreach ($toselect as $toselectid) {
823 $objecttmp =
new $objectclass($db);
824 $result = $objecttmp->fetch($toselectid);
826 $listofobjectid[$toselectid] = $toselectid;
827 $thirdpartyid = !empty($objecttmp->fk_soc) ? $objecttmp->fk_soc : $objecttmp->socid;
828 $listofobjectthirdparties[$thirdpartyid] = $thirdpartyid;
829 $listofobjectref[$toselectid] = $objecttmp->ref;
833 $arrayofinclusion = array();
834 foreach ($listofobjectref as $tmppdf) {
837 foreach ($listofobjectref as $tmppdf) {
838 $arrayofinclusion[] =
'^'.preg_quote(
dol_sanitizeFileName($tmppdf),
'/').
'_[a-zA-Z0-9\-\_\'\&\.]+\.pdf$';
840 $listoffiles =
dol_dir_list($uploaddir,
'all', 1, implode(
'|', $arrayofinclusion),
'\.meta$|\.png',
'date', SORT_DESC, 0, 1);
845 foreach ($listofobjectref as $basename) {
847 foreach ($listoffiles as $filefound) {
848 if (strstr($filefound[
"name"], $basename)) {
849 $files[] = $filefound[
'fullname'];
856 $outputlangs = $langs;
859 $newlang =
GETPOST(
'lang_id',
'aZ09');
864 if (!empty($newlang)) {
866 $outputlangs->setDefaultLang($newlang);
875 $filename = preg_replace(
'/\s/',
'_', $filename);
878 if (in_array($objecttmp->element, array(
'facture',
'invoice_supplier')) && $search_status ==
Facture::STATUS_VALIDATED) {
879 if ($option ==
'late') {
886 $filename .=
'_'.$year;
889 $filename .=
'_'.$month;
892 if (count($files) > 0) {
894 $file = $diroutputmassaction.
'/'.$filename.
'_'.
dol_print_date($now,
'dayhourlog').
'.pdf';
897 foreach ($files as $f) {
898 $input_files .=
' '.escapeshellarg($f);
901 $cmd =
'pdftk '.$input_files.
' cat output '.escapeshellarg($file);
905 if (file_exists($file)) {
908 $langs->load(
"exports");
911 setEventMessages($langs->trans(
'ErrorPDFTkOutputFileNotFound'),
null,
'errors');
914 setEventMessages($langs->trans(
'NoPDFAvailableForDocGenAmongChecked'),
null,
'errors');
919 $page_largeur = $formatarray[
'width'];
920 $page_hauteur = $formatarray[
'height'];
921 $format = array($page_largeur, $page_hauteur);
925 if (class_exists(
'TCPDF')) {
926 $pdf->setPrintHeader(
false);
927 $pdf->setPrintFooter(
false);
932 $pdf->SetCompression(
false);
937 foreach ($files as $file) {
939 $pagecount = $pdf->setSourceFile($file);
940 for ($i = 1; $i <= $pagecount; $i++) {
941 $tplidx = $pdf->importPage($i);
942 $s = $pdf->getTemplatesize($tplidx);
943 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
944 $pdf->useTemplate($tplidx);
953 $filename = preg_replace(
'/\s/',
'_', $filename);
957 if (in_array($objecttmp->element, array(
'facture',
'invoice_supplier')) && $search_status ==
Facture::STATUS_VALIDATED) {
958 if ($option ==
'late') {
965 $filename .=
'_'.$year;
968 $filename .=
'_'.$month;
972 $file = $diroutputmassaction.
'/'.$filename.
'_'.
dol_print_date($now,
'dayhourlog').
'.pdf';
973 $pdf->Output($file,
'F');
976 $langs->load(
"exports");
979 setEventMessages($langs->trans(
'NoPDFAvailableForDocGenAmongChecked'),
null,
'errors');
985if ($action ==
'remove_file') {
986 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
988 $langs->load(
"other");
989 $upload_dir = $diroutputmassaction;
990 $file = $upload_dir.
'/'.
GETPOST(
'file');
1002if (!$error && $massaction ==
'validate' && $permissiontoadd) {
1003 $objecttmp =
new $objectclass($db);
1005 if (($objecttmp->element ==
'facture' || $objecttmp->element ==
'invoice') && isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_BILL')) {
1006 $langs->load(
"errors");
1007 setEventMessages($langs->trans(
'ErrorMassValidationNotAllowedWhenStockIncreaseOnAction'),
null,
'errors');
1010 if ($objecttmp->element ==
'invoice_supplier' && isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_BILL')) {
1011 $langs->load(
"errors");
1012 setEventMessages($langs->trans(
'ErrorMassValidationNotAllowedWhenStockIncreaseOnAction'),
null,
'errors');
1015 if ($objecttmp->element ==
'facture') {
1018 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"facture";
1019 $sql .=
" WHERE rowid IN (".$db->sanitize(implode(
",", $toselect)).
")";
1020 $sql .=
" ORDER BY datef";
1022 $resql = $db->query($sql);
1025 while (!empty($arr = $db->fetch_row($resql))) {
1026 $toselectnew[] = $arr[0];
1028 $toselect = (empty($toselectnew)) ? $toselect : $toselectnew;
1039 foreach ($toselect as $toselectid) {
1040 $result = $objecttmp->fetch($toselectid);
1042 if (method_exists($objecttmp,
'validate')) {
1043 $result = $objecttmp->validate($user);
1044 } elseif (method_exists($objecttmp,
'setValid')) {
1045 $result = $objecttmp->setValid($user);
1047 $objecttmp->error =
'No method validate or setValid on this object';
1051 $langs->load(
"errors");
1052 setEventMessages($langs->trans(
"ErrorObjectMustHaveStatusDraftToBeValidated", $objecttmp->ref),
null,
'errors');
1055 } elseif ($result < 0) {
1063 $outputlangs = $langs;
1066 $newlang =
GETPOST(
'lang_id',
'aZ09');
1068 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && empty($newlang) && property_exists($objecttmp,
'thirdparty')) {
1069 if ((property_exists($objecttmp,
'socid') || property_exists($objecttmp,
'fk_soc')) && empty($objecttmp->thirdparty)) {
1070 $objecttmp->fetch_thirdparty();
1072 if (!empty($objecttmp->thirdparty)) {
1073 $newlang = $objecttmp->thirdparty->default_lang;
1076 if (!empty($newlang)) {
1078 $outputlangs->setDefaultLang($newlang);
1079 $outputlangs->load(
'products');
1081 $model = $objecttmp->model_pdf;
1082 $ret = $objecttmp->fetch($objecttmp->id);
1084 $hidedetails = !empty($hidedetails) ? $hidedetails : (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS') ? 1 : 0);
1085 $hidedesc = !empty($hidedesc) ? $hidedesc : (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_HIDE_DESC') ? 1 : 0);
1086 $hideref = !empty($hideref) ? $hideref : (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_HIDE_REF') ? 1 : 0);
1087 $moreparams = !empty($moreparams) ? $moreparams :
null;
1089 $result = $objecttmp->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1107 setEventMessages($langs->trans(
"RecordModifiedSuccessfully"),
null,
'mesgs');
1117if (!$error && ($massaction ==
'delete' || ($action ==
'delete' && $confirm ==
'yes')) && $permissiontodelete) {
1120 $objecttmp =
new $objectclass($db);
1126 $unique_arr = array_unique($toselect);
1127 foreach ($unique_arr as $toselectid) {
1128 $result = $objecttmp->fetch($toselectid);
1132 $langs->load(
"errors");
1134 $TMsg[] =
'<div class="error">'.$langs->trans(
'ErrorOnlyDraftStatusCanBeDeletedInMassAction', $objecttmp->ref).
'</div><br>';
1138 if (method_exists($objecttmp,
'is_erasable') && $objecttmp->is_erasable() <= 0) {
1139 $langs->load(
"errors");
1141 $TMsg[] =
'<div class="error">'.$langs->trans(
'ErrorRecordHasChildren').
' '.$objecttmp->ref.
'</div><br>';
1146 $langs->load(
"errors");
1148 $TMsg[] =
'<div class="error">'.$langs->trans(
'ErrorLeaveRequestMustBeDraftCanceledOrRefusedToBeDeleted', $objecttmp->ref).
'</div><br>';
1152 if ($objectclass ==
"Task" && $objecttmp->hasChildren() > 0) {
1153 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task SET fk_task_parent = 0 WHERE fk_task_parent = ".((int) $objecttmp->id);
1154 $res = $db->query($sql);
1162 if ($objecttmp->element ==
'societe') {
1164 '@phan-var-force Societe $objecttmp';
1166 $result = $objecttmp->delete($objecttmp->id, $user, 1);
1168 $result = $objecttmp->delete($user);
1171 if (empty($result)) {
1172 $TMsg = array_merge($objecttmp->errors, $TMsg);
1173 } elseif ($result < 0) {
1187 if (empty($error)) {
1191 } elseif ($nbok > 0) {
1198 if (!empty($TMsg)) {
1213if (!$error && $massaction ==
'generate_doc' && $permissiontoread) {
1216@phan-var-force
'Commande'|
'CommandeFournisseur'|
'Contrat'|
'Expedition'|
'ExpenseReport'|
'Facture'|
'FactureFournisseur'|
'Fichinter'|
'Project'|
'Propal'|
'SupplierProposal' $objectclass
1221 foreach ($toselect as $toselectid) {
1222 $objecttmp =
new $objectclass($db);
1223 $result = $objecttmp->fetch($toselectid);
1225 $outputlangs = $langs;
1229 $newlang =
GETPOST(
'lang_id',
'aZ09');
1231 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && empty($newlang) && isset($objecttmp->thirdparty->default_lang)) {
1232 $newlang = $objecttmp->thirdparty->default_lang;
1234 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && empty($newlang) && isset($objecttmp->default_lang)) {
1235 $newlang = $objecttmp->default_lang;
1237 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && empty($newlang) && empty($objecttmp->thirdparty)) {
1238 $objecttmp->fetch_thirdparty();
1239 $newlang = $objecttmp->thirdparty->default_lang;
1241 if (!empty($newlang)) {
1243 $outputlangs->setDefaultLang($newlang);
1247 if (empty($hidedetails)) {
1250 if (empty($hidedesc)) {
1253 if (empty($hideref)) {
1256 if (empty($moreparams)) {
1260 $result = $objecttmp->generateDocument($objecttmp->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1290if (!$error && ($action ==
'affecttag' && $confirm ==
'yes') && $permissiontoadd) {
1294 $affecttag_type =
GETPOST(
'affecttag_type',
'alpha');
1295 if (!empty($affecttag_type)) {
1296 $affecttag_type_array = explode(
',', $affecttag_type);
1300 if (!empty($affecttag_type_array)) {
1302 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1304 $to_affecttag_type_array = array();
1305 $categ_type_array = $categ->getMapList();
1306 foreach ($categ_type_array as $categdef) {
1307 if (in_array($categdef[
'code'], $affecttag_type_array)) {
1308 $to_affecttag_type_array[] = $categdef[
'code'];
1313 if (!empty($to_affecttag_type_array)) {
1314 foreach ($to_affecttag_type_array as $categ_type) {
1315 $contcats =
GETPOST(
'contcats_' . $categ_type,
'array');
1317 foreach ($toselect as $toselectid) {
1318 $result =
$object->fetch($toselectid);
1321 $result =
$object->setCategoriesCommon($contcats, $categ_type,
false);
1340 $toselect = array();
1346if (!$error && ($action ==
'updateprice' && $confirm ==
'yes') && $permissiontoadd) {
1347 '@phan-var-force Product|ProductCustomerPrice $obj';
1348 '@phan-var-force Product|ProductCustomerPrice $object';
1351 if (GETPOSTISSET(
'pricerate')) {
1353 if ($pricepercentage == 0) {
1356 foreach ($toselect as $toselectid) {
1357 $result =
$object->fetch($toselectid);
1360 if ($obj->price_base_type ==
'TTC') {
1361 $newprice =
$object->price_ttc * (100 + $pricepercentage) / 100;
1362 $minprice =
$object->price_min_ttc;
1364 $newprice =
$object->price * (100 + $pricepercentage) / 100;
1365 $minprice =
$object->price_min;
1367 $res =
$object->updatePrice($newprice, $obj->price_base_type, $user,
$object->tva_tx, $minprice, 0,
$object->tva_npr, 0, 0, array(),
$object->default_vat_code);
1387 $toselect = array();
1393if (!$error && ($action ==
'setsupervisor' && $confirm ==
'yes') && $permissiontoadd) {
1394 '@phan-var-force User $object';
1397 $supervisortoset =
GETPOSTINT(
'supervisortoset');
1398 if (!empty($supervisortoset)) {
1399 foreach ($toselect as $toselectid) {
1400 $result =
$object->fetch($toselectid);
1403 $object->fk_user = $supervisortoset;
1404 $res =
$object->update($user);
1424 $toselect = array();
1430if (!$error && ($action ==
'affectuser' && $confirm ==
'yes') && $permissiontoadd) {
1434 $usertoaffect =
GETPOST(
'usertoaffect');
1435 $projectrole =
GETPOST(
'projectrole');
1436 $tasksrole =
GETPOST(
'tasksrole');
1437 if (!empty($usertoaffect)) {
1438 foreach ($toselect as $toselectid) {
1439 $result =
$object->fetch($toselectid);
1442 $res =
$object->add_contact($usertoaffect, $projectrole,
'internal');
1444 $taskstatic =
new Task($db);
1445 $task_array = $taskstatic->getTasksArray(
null,
null,
$object->id, 0, 0);
1447 foreach ($task_array as $task) {
1448 $tasksToAffect =
new Task($db);
1449 $result = $tasksToAffect->fetch($task->id);
1451 $res = $tasksToAffect->add_contact($usertoaffect, $tasksrole,
'internal');
1475 $toselect = array();
1481if (!$error && ($massaction ==
'enable' || ($action ==
'enable' && $confirm ==
'yes')) && $permissiontoadd) {
1484 $objecttmp =
new $objectclass($db);
1486 foreach ($toselect as $toselectid) {
1487 $result = $objecttmp->fetch($toselectid);
1489 if (in_array($objecttmp->element, array(
'societe'))) {
1490 $result = $objecttmp->setStatut(1);
1518if (!$error && ($massaction ==
'disable' || ($action ==
'disable' && $confirm ==
'yes')) && $permissiontoadd) {
1521 $objecttmp =
new $objectclass($db);
1523 foreach ($toselect as $toselectid) {
1524 $result = $objecttmp->fetch($toselectid);
1526 if (in_array($objecttmp->element, array(
'societe'))) {
1527 $result = $objecttmp->setStatut(0);
1555if (!$error && $action ==
'confirm_edit_value_extrafields' && $confirm ==
'yes' && $permissiontoadd) {
1558 $objecttmp =
new $objectclass($db);
1560 $e->fetch_name_optionals_label($objecttmp->table_element);
1563 $extrafieldKeyToUpdate =
GETPOST(
'extrafield-key-to-update');
1566 foreach ($toselect as $toselectid) {
1568 $objecttmp =
new $objectclass($db);
1569 $result = $objecttmp->fetch($toselectid);
1572 $ret = $e->setOptionalsFromPost(
null, $objecttmp, $extrafieldKeyToUpdate);
1574 $objecttmp->insertExtraFields();
1598if (!$error && ($massaction ==
'affectcommercial' || ($action ==
'affectcommercial' && $confirm ==
'yes')) && $permissiontoadd) {
1601 $objecttmp =
new $objectclass($db);
1604 foreach ($toselect as $toselectid) {
1605 $result = $objecttmp->fetch($toselectid);
1607 if (in_array($objecttmp->element, array(
'societe'))) {
1608 $result = $objecttmp->setSalesRep(
GETPOST(
"commercial",
"alpha"));
1626 setEventMessages($langs->trans(
"CommercialsAffected", $nbok),
null,
'mesgs');
1636if (!$error && ($massaction ==
'unassigncommercial' || ($action ==
'unassigncommercial' && $confirm ==
'yes')) && $permissiontoadd) {
1639 $objecttmp =
new $objectclass($db);
1642 foreach ($toselect as $toselectid) {
1643 $result = $objecttmp->fetch($toselectid);
1645 if (in_array($objecttmp->element, array(
'societe'))) {
1646 $TCommercial =
GETPOST(
"commercial",
"alpha");
1647 if (is_array($TCommercial)) {
1648 foreach ($TCommercial as $commercial) {
1649 $result = $objecttmp->del_commercial($user, $commercial);
1669 setEventMessages($langs->trans(
"CommercialsDisaffected", $nbok),
null,
'mesgs');
1679if (!$error && ($massaction ==
'approveleave' || ($action ==
'approveleave' && $confirm ==
'yes')) && $permissiontoapprove) {
1682 $objecttmp =
new $objectclass($db);
1683 '@phan-var-force Holiday $objecttmp';
1685 foreach ($toselect as $toselectid) {
1686 $result = $objecttmp->fetch($toselectid);
1689 setEventMessages($langs->trans(
'StatusOfRefMustBe', $objecttmp->ref, $langs->transnoentitiesnoconv(
'Validated')),
null,
'warnings');
1692 if ($user->id == $objecttmp->fk_validator) {
1693 $objecttmp->oldcopy =
dol_clone($objecttmp, 2);
1695 $objecttmp->date_valid =
dol_now();
1696 $objecttmp->fk_user_valid = $user->id;
1698 $objecttmp->statut = $objecttmp->status;
1700 $verif = $objecttmp->approve($user);
1710 $nbopenedday =
num_open_day($objecttmp->date_debut_gmt, $objecttmp->date_fin_gmt, 0, 1, $objecttmp->halfday);
1711 $soldeActuel = $objecttmp->getCpforUser($objecttmp->fk_user, $objecttmp->fk_type);
1712 $newSolde = ($soldeActuel - $nbopenedday);
1715 $result = $objecttmp->addLogCP($user->id, $objecttmp->fk_user, $langs->transnoentitiesnoconv(
"Holidays"), $newSolde, $objecttmp->fk_type);
1722 $result = $objecttmp->updateSoldeCP($objecttmp->fk_user, $newSolde, $objecttmp->fk_type);
1731 $destinataire =
new User($db);
1732 $destinataire->fetch($objecttmp->fk_user);
1733 $emailTo = $destinataire->email;
1736 dol_syslog(
"User that request leave has no email, so we redirect directly to finished page without sending email");
1739 $expediteur =
new User($db);
1740 $expediteur->fetch($objecttmp->fk_validator);
1750 $subject = $societeName.
" - ".$langs->transnoentitiesnoconv(
"HolidaysValidated");
1753 $message = $langs->transnoentitiesnoconv(
"Hello").
" ".$destinataire->firstname.
",\n";
1756 $message .= $langs->transnoentities(
"HolidaysValidatedBody",
dol_print_date($objecttmp->date_debut,
'day'),
dol_print_date($objecttmp->date_fin,
'day')).
"\n";
1758 $message .=
"- ".$langs->transnoentitiesnoconv(
"ValidatedBy").
" : ".
dolGetFirstLastname($expediteur->firstname, $expediteur->lastname).
"\n";
1760 $message .=
"- ".$langs->transnoentitiesnoconv(
"Link").
" : ".$dolibarr_main_url_root.
"/holiday/card.php?id=".$objecttmp->id.
"\n\n";
1763 $trackid =
'leav'.$objecttmp->id;
1765 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
1766 $mail =
new CMailFile($subject, $emailTo, $emailFrom, $message, array(), array(), array(),
'',
'', 0, 0,
'',
'', $trackid);
1769 $result = $mail->sendfile();
1778 $langs->load(
"errors");
1779 setEventMessages($langs->trans(
'ErrorNotApproverForHoliday', $objecttmp->ref),
null,
'errors');
1791 } elseif ($nbok == 1) {
1800if (!$error && ($massaction ==
'increaseholiday' || ($action ==
'increaseholiday' && $confirm ==
'yes')) && $permissiontoapprove && is_array($toselect)) {
1801 '@phan-var-force Holiday $holiday';
1803 $objecttmp =
new $objectclass($db);
1805 $typeholiday =
GETPOST(
'typeholiday',
'alpha');
1808 if ($nbdaysholidays <= 0) {
1814 foreach ($toselect as $toselectid) {
1815 $balancecpuser = $objecttmp->getCPforUser($toselectid, $typeholiday);
1816 if (!empty($balancecpuser)) {
1817 $newnbdaysholidays = $nbdaysholidays + $balancecpuser;
1819 $newnbdaysholidays = $nbdaysholidays;
1821 $result = $holiday->addLogCP($user->id, $toselectid, $langs->transnoentitiesnoconv(
'ManualUpdate'), $newnbdaysholidays, $typeholiday);
1828 $objecttmp->updateSoldeCP($toselectid, $newnbdaysholidays, $typeholiday);
1841 setEventMessages($langs->trans(
"HolidayRecordsIncreased", $nbok),
null,
'mesgs');
1842 } elseif ($nbok == 1) {
1846 $toselect = array();
1853if (!$error && ($massaction ==
'clonetasks' || ($action ==
'clonetasks' && $confirm ==
'yes'))) {
1856 include_once DOL_DOCUMENT_ROOT.
'/projet/class/task.class.php';
1858 $origin_task =
new Task($db);
1859 $clone_task =
new Task($db);
1860 $newproject =
new Project($db);
1864 $iscontactofnewproject = 0;
1865 if (empty($newproject->public)) {
1866 $tmps = $newproject->getProjectsAuthorizedForUser($user, 0, 1, 0,
'(fk_statut:=:1)');
1867 $tmparray = explode(
',', $tmps);
1868 if (!in_array($newproject->id, $tmparray)) {
1869 $iscontactofnewproject = 1;
1874 $permisstiontoadd =
false;
1875 if ($user->hasRight(
'project',
'all',
'creer') || ($user->hasRight(
'project',
'creer') && ($newproject->public || $iscontactofnewproject))) {
1876 $permisstiontoadd =
true;
1879 if ($permisstiontoadd) {
1880 foreach (
GETPOST(
'selected') as $task) {
1881 $origin_task->fetch($task,
'', 0);
1886 require_once DOL_DOCUMENT_ROOT .
"/core/modules/project/task/" .
getDolGlobalString(
'PROJECT_TASK_ADDON') .
'.php';
1887 $modTask =
new $classnamemodtask();
1888 '@phan-var-force ModeleNumRefTask $modTask';
1889 $defaultref = $modTask->getNextValue(
null, $clone_task);
1893 $clone_task->fk_project =
GETPOSTINT(
'projectid');
1894 $clone_task->ref = $defaultref;
1895 $clone_task->label = $origin_task->label;
1896 $clone_task->description = $origin_task->description;
1897 $clone_task->planned_workload = $origin_task->planned_workload;
1898 $clone_task->fk_task_parent = $origin_task->fk_task_parent;
1899 $clone_task->date_c =
dol_now();
1900 $clone_task->date_start = $origin_task->date_start;
1901 $clone_task->date_end = $origin_task->date_end;
1902 $clone_task->progress = $origin_task->progress;
1905 $ret = $extrafields->setOptionalsFromPost(
null, $clone_task);
1907 $taskid = $clone_task->create($user);
1910 $result = $clone_task->add_contact(
GETPOSTINT(
"userid"),
'TASKEXECUTIVE',
'internal');
1913 if ($db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1914 $langs->load(
"projects");
1916 $duplicate_code_error =
true;
1927 setEventMessages($langs->trans(
'NumberOfTasksCloned', $num),
null,
'mesgs');
1928 header(
"Location: ".DOL_URL_ROOT.
'/projet/tasks.php?id='.
GETPOSTINT(
'projectid'));
1936if (empty($toselect)) {
1939$parameters[
'toselect'] = &$toselect;
1940$parameters[
'uploaddir'] = $uploaddir;
1941$parameters[
'massaction'] = $massaction;
1942$parameters[
'diroutputmassaction'] = isset($diroutputmassaction) ? $diroutputmassaction :
null;
1944$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.