43if (empty($objectclass) || empty($uploaddir)) {
44 dol_print_error(
null,
'include of actions_massactions.inc.php is done but var $objectclass or $uploaddir was not defined');
47if (empty($massaction)) {
53if (!empty($permtoread) && empty($permissiontoread)) {
54 $permissiontoread = $permtoread;
56if (!empty($permtocreate) && empty($permissiontoadd)) {
57 $permissiontoadd = $permtocreate;
59if (!empty($permtodelete) && empty($permissiontodelete)) {
60 $permissiontodelete = $permtodelete;
64$maxformassaction = (!
getDolGlobalString(
'MAIN_LIMIT_FOR_MASS_ACTIONS') ? 1000 : $conf->global->MAIN_LIMIT_FOR_MASS_ACTIONS);
65if ($massaction && is_array($toselect) && count($toselect) < 1) {
69if (!$error && isset($toselect) && is_array($toselect) && count($toselect) > $maxformassaction) {
70 setEventMessages($langs->trans(
'TooManyRecordForMassAction', $maxformassaction),
null,
'errors');
74if (!$error && $massaction ==
'confirm_presend' && !
GETPOST(
'sendmail')) {
75 $massaction =
'presend';
78if (!$error && $massaction ==
'confirm_presend') {
82 $langs->load(
"mails");
83 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
84 include_once DOL_DOCUMENT_ROOT.
'/core/lib/signature.lib.php';
86 $listofobjectid = array();
87 $listofobjectthirdparties = array();
88 $listofobjectcontacts = array();
89 $listofobjectref = array();
90 $contactidtosend = array();
91 $attachedfilesThirdpartyObj = array();
92 $oneemailperrecipient = (
GETPOSTINT(
'oneemailperrecipient') ? 1 : 0);
95 $objecttmp =
new $objectclass($db);
99 if ($objecttmp->element ==
'expensereport') {
100 $thirdparty =
new User($db);
101 } elseif ($objecttmp->element ==
'contact') {
102 $thirdparty =
new Contact($db);
103 } elseif ($objecttmp->element ==
'partnership' &&
getDolGlobalString(
'PARTNERSHIP_IS_MANAGED_FOR') ==
'member') {
105 } elseif ($objecttmp->element ==
'holiday') {
106 $thirdparty =
new User($db);
107 } elseif ($objecttmp->element ==
'conferenceorboothattendee') {
111 foreach ($toselect as $toselectid) {
112 $objecttmp =
new $objectclass($db);
113 $result = $objecttmp->fetch($toselectid);
115 $listofobjectid[$toselectid] = $toselectid;
116 $tmpobjectid = ($objecttmp->fk_soc ? $objecttmp->fk_soc : $objecttmp->socid);
117 if ($objecttmp->element ==
'societe') {
118 $tmpobjectid = $objecttmp->id;
119 } elseif ($objecttmp->element ==
'contact') {
120 $tmpobjectid = $objecttmp->id;
121 } elseif ($objecttmp->element ==
'expensereport') {
122 $tmpobjectid = $objecttmp->fk_user_author;
123 } elseif ($objecttmp->element ==
'partnership' &&
getDolGlobalString(
'PARTNERSHIP_IS_MANAGED_FOR') ==
'member') {
124 $tmpobjectid = $objecttmp->fk_member;
125 } elseif ($objecttmp->element ==
'holiday') {
126 $tmpobjectid = $objecttmp->fk_user;
127 } elseif ($objecttmp->element ==
'conferenceorboothattendee') {
128 $tmpobjectid = $objecttmp->id;
130 if (empty($tmpobjectid)) {
134 if ($objectclass ==
'Facture') {
135 $tmparraycontact = array();
136 $tmparraycontact = $objecttmp->liste_contact(-1,
'external', 0,
'BILLING');
137 if (is_array($tmparraycontact) && count($tmparraycontact) > 0) {
138 foreach ($tmparraycontact as $data_email) {
139 $listofobjectcontacts[$toselectid][$data_email[
'id']] = $data_email[
'email'];
142 } elseif ($objectclass ==
'CommandeFournisseur') {
143 $tmparraycontact = array();
144 $tmparraycontact = $objecttmp->liste_contact(-1,
'external', 0,
'CUSTOMER');
145 if (is_array($tmparraycontact) && count($tmparraycontact) > 0) {
146 foreach ($tmparraycontact as $data_email) {
147 $listofobjectcontacts[$toselectid][$data_email[
'id']] = $data_email[
'email'];
152 $listofobjectthirdparties[$tmpobjectid] = $tmpobjectid;
153 $listofobjectref[$tmpobjectid][$toselectid] = $objecttmp;
159 if (
GETPOST(
'fromtype',
'alpha') ===
'user' && empty($user->email)) {
162 $massaction =
'presend';
165 $receiver =
GETPOST(
'receiver',
'alphawithlgt');
166 if (!is_array($receiver)) {
167 if (empty($receiver) || $receiver ==
'-1') {
170 $receiver = array($receiver);
173 if (!trim(
GETPOST(
'sendto',
'alphawithlgt')) && count($receiver) == 0 && count($listofobjectthirdparties) == 1) {
175 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Recipient")),
null,
'warnings');
176 $massaction =
'presend';
179 if (!
GETPOST(
'subject',
'restricthtml')) {
181 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"MailTopic")),
null,
'warnings');
182 $massaction =
'presend';
187 foreach ($listofobjectthirdparties as $thirdpartyid) {
188 $result = $thirdparty->fetch($thirdpartyid);
201 if (trim(
GETPOST(
'sendto',
'alphawithlgt'))) {
203 $tmparray[] = trim(
GETPOST(
'sendto',
'alphawithlgt'));
205 if (count($receiver) > 0) {
206 foreach ($receiver as $key => $val) {
208 if ($val ==
'thirdparty') {
209 $tmparray[] = $thirdparty->name.
' <'.$thirdparty->email.
'>';
210 } elseif ($val && method_exists($thirdparty,
'contact_get_property')) {
211 $tmparray[] = $thirdparty->contact_get_property((
int) $val,
'email');
216 $sendto = implode(
',', $tmparray);
219 $receivercc =
GETPOST(
'receivercc',
'alphawithlgt');
220 if (!is_array($receivercc)) {
221 if ($receivercc ==
'-1') {
222 $receivercc = array();
224 $receivercc = array($receivercc);
228 if (trim(
GETPOST(
'sendtocc',
'alphawithlgt'))) {
229 $tmparray[] = trim(
GETPOST(
'sendtocc',
'alphawithlgt'));
231 if (count($receivercc) > 0) {
232 foreach ($receivercc as $key => $val) {
234 if ($val ==
'thirdparty') {
235 $tmparray[] = $thirdparty->name.
' <'.$thirdparty->email.
'>';
237 $tmparray[] = $thirdparty->contact_get_property((
int) $val,
'email');
242 $sendtocc = implode(
',', $tmparray);
245 $listofqualifiedobj = array();
246 $listofqualifiedref = array();
247 $thirdpartywithoutemail = array();
249 foreach ($listofobjectref[$thirdpartyid] as $objectid => $objectobj) {
252 $langs->load(
"errors");
254 $resaction .=
'<div class="error">'.$langs->trans(
'ErrorOnlyProposalNotDraftCanBeSentInMassAction', $objectobj->ref).
'</div><br>';
258 $langs->load(
"errors");
260 $resaction .=
'<div class="error">'.$langs->trans(
'ErrorOnlyOrderNotDraftCanBeSentInMassAction', $objectobj->ref).
'</div><br>';
264 $langs->load(
"errors");
266 $resaction .=
'<div class="error">'.$langs->trans(
'ErrorOnlyInvoiceValidatedCanBeSentInMassAction', $objectobj->ref).
'</div><br>';
271 if (empty($sendto)) {
272 if ($objectobj->element ==
'societe') {
273 $sendto = $objectobj->email;
274 } elseif ($objectobj->element ==
'expensereport') {
275 $fuser =
new User($db);
276 $fuser->fetch($objectobj->fk_user_author);
277 $sendto = $fuser->email;
278 } elseif ($objectobj->element ==
'contact') {
280 $fcontact->fetch($objectobj->id);
281 $sendto = $fcontact->email;
282 } elseif ($objectobj->element ==
'partnership' &&
getDolGlobalString(
'PARTNERSHIP_IS_MANAGED_FOR') ==
'member') {
284 $fadherent->fetch($objectobj->fk_member);
285 $sendto = $fadherent->email;
286 } elseif ($objectobj->element ==
'holiday') {
287 $fuser =
new User($db);
288 $fuser->fetch($objectobj->fk_user);
289 $sendto = $fuser->email;
290 } elseif ($objectobj->element ==
'facture' && !empty($listofobjectcontacts[$objectid])) {
291 $emails_to_sends = array();
292 $objectobj->fetch_thirdparty();
293 $contactidtosend = array();
294 foreach ($listofobjectcontacts[$objectid] as $contactemailid => $contactemailemail) {
295 $emails_to_sends[] = $objectobj->thirdparty->contact_get_property($contactemailid,
'email');
296 if (!in_array($contactemailid, $contactidtosend)) {
297 $contactidtosend[] = $contactemailid;
300 if (count($emails_to_sends) > 0) {
301 $sendto = implode(
',', $emails_to_sends);
303 } elseif ($objectobj->element ==
'order_supplier' && !empty($listofobjectcontacts[$objectid])) {
304 $emails_to_sends = array();
305 $objectobj->fetch_thirdparty();
306 $contactidtosend = array();
307 foreach ($listofobjectcontacts[$objectid] as $contactemailid => $contactemailemail) {
308 $emails_to_sends[] = $objectobj->thirdparty->contact_get_property($contactemailid,
'email');
309 if (!in_array($contactemailid, $contactidtosend)) {
310 $contactidtosend[] = $contactemailid;
313 if (count($emails_to_sends) > 0) {
314 $sendto = implode(
',', $emails_to_sends);
316 } elseif ($objectobj->element ==
'conferenceorboothattendee') {
317 $sendto = $objectobj->email;
319 $objectobj->fetch_thirdparty();
320 $sendto = $objectobj->thirdparty->email;
324 if (empty($sendto)) {
325 if ($objectobj->element ==
'societe') {
326 $objectobj->thirdparty = $objectobj;
331 if (empty($thirdpartywithoutemail[$objectobj->thirdparty->id])) {
332 $resaction .=
'<div class="error">'.$langs->trans(
'NoRecipientEmail', $objectobj->thirdparty->name).
'</div><br>';
334 dol_syslog(
'No recipient for thirdparty: '.$objectobj->thirdparty->name, LOG_WARNING);
335 $thirdpartywithoutemail[$objectobj->thirdparty->id] = 1;
339 if (
GETPOST(
'addmaindocfile')) {
346 $filedir = $uploaddir.
'/'.$subdir.dol_sanitizeFileName($objectobj->ref);
347 $filepath = $filedir.
'/'.$filename;
350 if ($objectobj->element ==
'invoice_supplier') {
351 $fileparams =
dol_most_recent_file($uploaddir.
'/'.
get_exdir($objectobj->id, 2, 0, 0, $objectobj, $objectobj->element).$objectobj->ref, preg_quote($objectobj->ref,
'/').
'([^\-])+');
352 $filepath = $fileparams[
'fullname'];
356 $filename_found =
'';
357 $filepath_found =
'';
358 $file_check_list = array();
359 $file_check_list[] = array(
363 if (
getDolGlobalString(
'MAIL_MASS_ACTION_ADD_LAST_IF_MAIN_DOC_NOT_FOUND') && !empty($objectobj->last_main_doc)) {
364 $file_check_list[] = array(
365 'name' => basename($objectobj->last_main_doc),
366 'path' => DOL_DATA_ROOT .
'/' . $objectobj->last_main_doc,
369 foreach ($file_check_list as $file_check_arr) {
371 $filename_found = $file_check_arr[
'name'];
372 $filepath_found = $file_check_arr[
'path'];
377 if ($filepath_found) {
379 $attachedfilesThirdpartyObj[$thirdpartyid][$objectid] = array(
380 'paths' => array($filepath_found),
381 'names' => array($filename_found),
386 $langs->load(
"errors");
387 foreach ($file_check_list as $file_check_arr) {
388 $resaction .=
'<div class="error">'.$langs->trans(
'ErrorCantReadFile', $file_check_arr[
'path']).
'</div><br>';
389 dol_syslog(
'Failed to read file: '.$file_check_arr[
'path'], LOG_WARNING);
396 $listofqualifiedobj[$objectid] = $objectobj;
397 $listofqualifiedref[$objectid] = $objectobj->ref;
404 if (count($listofqualifiedobj) > 0) {
405 $langs->load(
"commercial");
408 $fromtype =
GETPOST(
'fromtype');
409 if ($fromtype ===
'user') {
410 $from =
dol_string_nospecial($user->getFullName($langs),
' ', array(
",")).
' <'.$user->email.
'>';
411 } elseif ($fromtype ===
'company') {
413 } elseif (preg_match(
'/user_aliases_(\d+)/', $fromtype, $reg)) {
414 $tmp = explode(
',', $user->email_aliases);
415 $from = trim($tmp[($reg[1] - 1)]);
416 } elseif (preg_match(
'/global_aliases_(\d+)/', $fromtype, $reg)) {
418 $from = trim($tmp[($reg[1] - 1)]);
419 } elseif (preg_match(
'/senderprofile_(\d+)_(\d+)/', $fromtype, $reg)) {
420 $sql =
"SELECT rowid, label, email FROM ".MAIN_DB_PREFIX.
"c_email_senderprofile WHERE rowid = ".(int) $reg[1];
421 $resql = $db->query($sql);
422 $obj = $db->fetch_object($resql);
431 $subject =
GETPOST(
'subject',
'restricthtml');
432 $message =
GETPOST(
'message',
'restricthtml');
434 $sendtobcc =
GETPOST(
'sendtoccc');
435 if ($objectclass ==
'Propal') {
438 if ($objectclass ==
'Commande') {
441 if ($objectclass ==
'Facture') {
444 if ($objectclass ==
'SupplierProposal') {
445 $sendtobcc .= (!
getDolGlobalString(
'MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO') ?
'' : (($sendtobcc ?
", " :
"") .
getDolGlobalString(
'MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO')));
447 if ($objectclass ==
'CommandeFournisseur') {
450 if ($objectclass ==
'FactureFournisseur') {
453 if ($objectclass ==
'Project') {
459 $looparray = array();
460 if (!$oneemailperrecipient) {
461 $looparray = $listofqualifiedobj;
462 foreach ($looparray as $key => $objecttmp) {
463 $looparray[$key]->thirdparty = $thirdparty;
466 $objectforloop =
new $objectclass($db);
467 $objectforloop->thirdparty = $thirdparty;
468 $looparray[0] = $objectforloop;
471 dol_syslog(
"We have set an array of ".count($looparray).
" emails to send. oneemailperrecipient=".$oneemailperrecipient);
473 foreach ($looparray as $objectid => $objecttmp) {
475 if (isModEnabled(
'project') && method_exists($objecttmp,
'fetch_projet') && is_null($objecttmp->project)) {
476 $objecttmp->fetch_projet();
479 $substitutionarray[
'__ID__'] = ($oneemailperrecipient ? implode(
', ', array_keys($listofqualifiedobj)) : $objecttmp->id);
480 $substitutionarray[
'__REF__'] = ($oneemailperrecipient ? implode(
', ', $listofqualifiedref) : $objecttmp->
ref);
481 $substitutionarray[
'__EMAIL__'] = $thirdparty->email;
482 $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"/>';
484 if ($oneemailperrecipient) {
485 $substitutionarray[
'__ONLINE_PAYMENT_URL__'] =
'';
486 $substitutionarray[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
'';
489 $parameters = array(
'mode' =>
'formemail');
491 if (!empty($listofobjectthirdparties)) {
492 $parameters[
'listofobjectthirdparties'] = $listofobjectthirdparties;
494 if (!empty($listofobjectref)) {
495 $parameters[
'listofobjectref'] = $listofobjectref;
503 $attachedfiles = array(
'paths' => array(),
'names' => array(),
'mimes' => array());
504 if ($oneemailperrecipient) {
506 if (is_array($attachedfilesThirdpartyObj[$thirdparty->id]) && count($attachedfilesThirdpartyObj[$thirdparty->id])) {
507 foreach ($attachedfilesThirdpartyObj[$thirdparty->id] as $keyObjId => $objAttachedFiles) {
509 $attachedfiles = array(
510 'paths' => array_merge($attachedfiles[
'paths'], $objAttachedFiles[
'paths']),
511 'names' => array_merge($attachedfiles[
'names'], $objAttachedFiles[
'names']),
512 'mimes' => array_merge($attachedfiles[
'mimes'], $objAttachedFiles[
'mimes'])
516 } elseif (!empty($attachedfilesThirdpartyObj[$thirdparty->id][$objectid])) {
519 $attachedfiles = $attachedfilesThirdpartyObj[$thirdparty->id][$objectid];
522 $filepath = $attachedfiles[
'paths'];
523 $filename = $attachedfiles[
'names'];
524 $mimetype = $attachedfiles[
'mimes'];
527 if ($oneemailperrecipient) {
528 $trackid =
'thi'.$thirdparty->id;
529 if ($objecttmp->element ==
'expensereport') {
530 $trackid =
'use'.$thirdparty->id;
531 } elseif ($objecttmp->element ==
'contact') {
532 $trackid =
'ctc'.$thirdparty->id;
533 } elseif ($objecttmp->element ==
'holiday') {
534 $trackid =
'use'.$thirdparty->id;
537 $trackid = strtolower(get_class($objecttmp));
538 if (get_class($objecttmp) ==
'Contact') {
540 } elseif (get_class($objecttmp) ==
'Contrat') {
542 } elseif (get_class($objecttmp) ==
'Propal') {
544 } elseif (get_class($objecttmp) ==
'Commande') {
546 } elseif (get_class($objecttmp) ==
'Facture') {
548 } elseif (get_class($objecttmp) ==
'SupplierProposal') {
550 } elseif (get_class($objecttmp) ==
'CommandeFournisseur') {
552 } elseif (get_class($objecttmp) ==
'FactureFournisseur') {
556 $trackid .= $objecttmp->id;
562 if (empty($sendcontext)) {
563 $sendcontext =
'standard';
567 $vardir = $conf->user->dir_output.
"/".$user->id;
568 $upload_dir_tmp = $vardir.
'/temp';
571 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
572 $mailfile =
new CMailFile($subjectreplaced, $sendto, $from, $messagereplaced, $filepath, $mimetype, $filename, $sendtocc, $sendtobcc, $deliveryreceipt, -1,
'',
'', $trackid,
'', $sendcontext,
'', $upload_dir_tmp);
573 if ($mailfile->error) {
574 $resaction .=
'<div class="error">'.$mailfile->error.
'</div>';
576 $result = $mailfile->sendfile();
578 $resaction .= $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($mailfile->addr_from, 2), $mailfile->getValidAddress($mailfile->addr_to, 2)).
'<br>';
583 foreach ($listofqualifiedobj as $objid2 => $objectobj2) {
584 if ((!$oneemailperrecipient) && $objid2 != $objectid) {
588 dol_syslog(
"Try to insert email event into agenda for objid=".$objid2.
" => objectobj=".get_class($objectobj2));
597 $actionmsg = $langs->transnoentities(
'MailSentByTo', $from, $sendto);
600 $actionmsg =
dol_concatdesc($actionmsg, $langs->transnoentities(
'Bcc').
": ".$sendtocc);
602 $actionmsg =
dol_concatdesc($actionmsg, $langs->transnoentities(
'MailTopic').
": ".$subjectreplaced);
603 $actionmsg =
dol_concatdesc($actionmsg, $langs->transnoentities(
'TextUsedInTheMessageBody').
":");
609 $objectobj2->sendtoid = (empty($contactidtosend) ? 0 : $contactidtosend);
610 $objectobj2->actionmsg = $actionmsg;
611 $objectobj2->actionmsg2 = $actionmsg2;
612 $objectobj2->fk_element = $objid2;
613 $objectobj2->elementtype = $objectobj2->element;
615 $objectobj2->actionmsg2 = $subjectreplaced;
618 $triggername = strtoupper(get_class($objectobj2)).
'_SENTBYMAIL';
619 if ($triggername ==
'SOCIETE_SENTBYMAIL') {
620 $triggername =
'COMPANY_SENTBYMAIL';
622 if ($triggername ==
'CONTRAT_SENTBYMAIL') {
623 $triggername =
'CONTRACT_SENTBYMAIL';
625 if ($triggername ==
'COMMANDE_SENTBYMAIL') {
626 $triggername =
'ORDER_SENTBYMAIL';
628 if ($triggername ==
'FACTURE_SENTBYMAIL') {
629 $triggername =
'BILL_SENTBYMAIL';
631 if ($triggername ==
'EXPEDITION_SENTBYMAIL') {
632 $triggername =
'SHIPPING_SENTBYMAIL';
634 if ($triggername ==
'COMMANDEFOURNISSEUR_SENTBYMAIL') {
635 $triggername =
'ORDER_SUPPLIER_SENTBYMAIL';
637 if ($triggername ==
'FACTUREFOURNISSEUR_SENTBYMAIL') {
638 $triggername =
'BILL_SUPPLIER_SENTBYMAIL';
640 if ($triggername ==
'SUPPLIERPROPOSAL_SENTBYMAIL') {
641 $triggername =
'PROPOSAL_SUPPLIER_SENTBYMAIL';
643 if ($triggername ==
'PROJET_SENTBYMAIL') {
644 $triggername =
'PROJECT_SENTBYMAIL';
647 if (!empty($triggername)) {
649 $result = $objectobj2->call_trigger($triggername, $user);
657 dol_syslog(
"Error in trigger ".$triggername.
' '.$db->lasterror(), LOG_ERR);
664 $langs->load(
"other");
665 if ($mailfile->error) {
666 $resaction .= $langs->trans(
'ErrorFailedToSendMail', $from, $sendto);
667 $resaction .=
'<br><div class="error">'.$mailfile->error.
'</div>';
669 $resaction .=
'<div class="warning">No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS</div>';
671 $resaction .= $langs->trans(
'ErrorFailedToSendMail', $from, $sendto) .
'<br><div class="error">(unhandled error)</div>';
679 $resaction .= ($resaction ?
'<br>' : $resaction);
680 $resaction .=
'<strong>'.$langs->trans(
"ResultOfMailSending").
':</strong><br>'.
"\n";
681 $resaction .= $langs->trans(
"NbSelected").
': '.count($toselect).
"\n<br>";
682 $resaction .= $langs->trans(
"NbIgnored").
': '.($nbignored ? $nbignored : 0).
"\n<br>";
683 $resaction .= $langs->trans(
"NbSent").
': '.($nbsent ? $nbsent : 0).
"\n<br>";
688 setEventMessages($langs->trans(
"EMailSentForNElements", $nbsent.
'/'.count($toselect)),
null,
'mesgs');
701if (!$error && $massaction ==
'cancelorders') {
706 $orders =
GETPOST(
'toselect',
'array');
707 foreach ($orders as $id_order) {
709 if ($cmd->fetch($id_order) <= 0) {
714 $langs->load(
'errors');
715 setEventMessages($langs->trans(
"ErrorObjectMustHaveStatusValidToBeCanceled", $cmd->ref),
null,
'errors');
720 $result = $cmd->cancel();
740if (!$error && $massaction ==
"builddoc" && $permissiontoread && !
GETPOST(
'button_search')) {
741 if (empty($diroutputmassaction)) {
742 dol_print_error(
null,
'include of actions_massactions.inc.php is done but var $diroutputmassaction was not defined');
746 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
747 require_once DOL_DOCUMENT_ROOT.
'/core/lib/pdf.lib.php';
748 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
750 $objecttmp =
new $objectclass($db);
751 $listofobjectid = array();
752 $listofobjectthirdparties = array();
753 $listofobjectref = array();
754 foreach ($toselect as $toselectid) {
755 $objecttmp =
new $objectclass($db);
756 $result = $objecttmp->fetch($toselectid);
758 $listofobjectid[$toselectid] = $toselectid;
759 $thirdpartyid = !empty($objecttmp->fk_soc) ? $objecttmp->fk_soc : $objecttmp->socid;
760 $listofobjectthirdparties[$thirdpartyid] = $thirdpartyid;
761 $listofobjectref[$toselectid] = $objecttmp->ref;
765 $arrayofinclusion = array();
766 foreach ($listofobjectref as $tmppdf) {
769 foreach ($listofobjectref as $tmppdf) {
770 $arrayofinclusion[] =
'^'.preg_quote(
dol_sanitizeFileName($tmppdf),
'/').
'_[a-zA-Z0-9\-\_\'\&\.]+\.pdf$';
772 $listoffiles =
dol_dir_list($uploaddir,
'all', 1, implode(
'|', $arrayofinclusion),
'\.meta$|\.png',
'date', SORT_DESC, 0,
true);
777 foreach ($listofobjectref as $basename) {
779 foreach ($listoffiles as $filefound) {
780 if (strstr($filefound[
"name"], $basename)) {
781 $files[] = $filefound[
'fullname'];
788 $outputlangs = $langs;
791 $newlang =
GETPOST(
'lang_id',
'aZ09');
796 if (!empty($newlang)) {
798 $outputlangs->setDefaultLang($newlang);
807 $filename = preg_replace(
'/\s/',
'_', $filename);
810 if (in_array($objecttmp->element, array(
'facture',
'invoice_supplier')) && $search_status ==
Facture::STATUS_VALIDATED) {
811 if ($option ==
'late') {
818 $filename .=
'_'.$year;
821 $filename .=
'_'.$month;
824 if (count($files) > 0) {
826 $file = $diroutputmassaction.
'/'.$filename.
'_'.
dol_print_date($now,
'dayhourlog').
'.pdf';
829 foreach ($files as $f) {
830 $input_files .=
' '.escapeshellarg($f);
833 $cmd =
'pdftk '.$input_files.
' cat output '.escapeshellarg($file);
837 if (file_exists($file)) {
840 $langs->load(
"exports");
843 setEventMessages($langs->trans(
'ErrorPDFTkOutputFileNotFound'),
null,
'errors');
846 setEventMessages($langs->trans(
'NoPDFAvailableForDocGenAmongChecked'),
null,
'errors');
851 $page_largeur = $formatarray[
'width'];
852 $page_hauteur = $formatarray[
'height'];
853 $format = array($page_largeur, $page_hauteur);
857 if (class_exists(
'TCPDF')) {
858 $pdf->setPrintHeader(
false);
859 $pdf->setPrintFooter(
false);
864 $pdf->SetCompression(
false);
868 foreach ($files as $file) {
870 $pagecount = $pdf->setSourceFile($file);
871 for ($i = 1; $i <= $pagecount; $i++) {
872 $tplidx = $pdf->importPage($i);
873 $s = $pdf->getTemplatesize($tplidx);
874 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
875 $pdf->useTemplate($tplidx);
884 $filename = preg_replace(
'/\s/',
'_', $filename);
888 if (in_array($objecttmp->element, array(
'facture',
'invoice_supplier')) && $search_status ==
Facture::STATUS_VALIDATED) {
889 if ($option ==
'late') {
896 $filename .=
'_'.$year;
899 $filename .=
'_'.$month;
903 $file = $diroutputmassaction.
'/'.$filename.
'_'.
dol_print_date($now,
'dayhourlog').
'.pdf';
904 $pdf->Output($file,
'F');
907 $langs->load(
"exports");
910 setEventMessages($langs->trans(
'NoPDFAvailableForDocGenAmongChecked'),
null,
'errors');
916if ($action ==
'remove_file') {
917 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
919 $langs->load(
"other");
920 $upload_dir = $diroutputmassaction;
921 $file = $upload_dir.
'/'.
GETPOST(
'file');
933if (!$error && $massaction ==
'validate' && $permissiontoadd) {
934 $objecttmp =
new $objectclass($db);
936 if (($objecttmp->element ==
'facture' || $objecttmp->element ==
'invoice') && isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_BILL')) {
937 $langs->load(
"errors");
938 setEventMessages($langs->trans(
'ErrorMassValidationNotAllowedWhenStockIncreaseOnAction'),
null,
'errors');
941 if ($objecttmp->element ==
'invoice_supplier' && isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_BILL')) {
942 $langs->load(
"errors");
943 setEventMessages($langs->trans(
'ErrorMassValidationNotAllowedWhenStockIncreaseOnAction'),
null,
'errors');
946 if ($objecttmp->element ==
'facture') {
949 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"facture";
950 $sql .=
" WHERE rowid IN (".$db->sanitize(implode(
",", $toselect)).
")";
951 $sql .=
" ORDER BY datef";
953 $resql = $db->query($sql);
956 while (!empty($arr = $db->fetch_row($resql))) {
957 $toselectnew[] = $arr[0];
959 $toselect = (empty($toselectnew)) ? $toselect : $toselectnew;
970 foreach ($toselect as $toselectid) {
971 $result = $objecttmp->fetch($toselectid);
973 if (method_exists($objecttmp,
'validate')) {
974 $result = $objecttmp->validate($user);
975 } elseif (method_exists($objecttmp,
'setValid')) {
976 $result = $objecttmp->setValid($user);
978 $objecttmp->error =
'No method validate or setValid on this object';
982 $langs->load(
"errors");
983 setEventMessages($langs->trans(
"ErrorObjectMustHaveStatusDraftToBeValidated", $objecttmp->ref),
null,
'errors');
986 } elseif ($result < 0) {
994 $outputlangs = $langs;
997 $newlang =
GETPOST(
'lang_id',
'aZ09');
999 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && empty($newlang) && property_exists($objecttmp,
'thirdparty')) {
1000 if ((property_exists($objecttmp,
'socid') || property_exists($objecttmp,
'fk_soc')) && empty($objecttmp->thirdparty)) {
1001 $objecttmp->fetch_thirdparty();
1003 if (!empty($objecttmp->thirdparty)) {
1004 $newlang = $objecttmp->thirdparty->default_lang;
1007 if (!empty($newlang)) {
1008 $outputlangs =
new Translate(
"", $conf);
1009 $outputlangs->setDefaultLang($newlang);
1010 $outputlangs->load(
'products');
1012 $model = $objecttmp->model_pdf;
1013 $ret = $objecttmp->fetch($objecttmp->id);
1016 $hidedetails = isset($hidedetails) ? $hidedetails : (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS') ? 1 : 0);
1017 $hidedesc = isset($hidedesc) ? $hidedesc : (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_HIDE_DESC') ? 1 : 0);
1018 $hideref = isset($hideref) ? $hideref : (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_HIDE_REF') ? 1 : 0);
1019 $moreparams = isset($moreparams) ? $moreparams :
null;
1021 $result = $objecttmp->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1039 setEventMessages($langs->trans(
"RecordModifiedSuccessfully"),
null,
'mesgs');
1049if (!$error && ($massaction ==
'delete' || ($action ==
'delete' && $confirm ==
'yes')) && $permissiontodelete) {
1052 $objecttmp =
new $objectclass($db);
1058 $unique_arr = array_unique($toselect);
1059 foreach ($unique_arr as $toselectid) {
1060 $result = $objecttmp->fetch($toselectid);
1064 $langs->load(
"errors");
1066 $TMsg[] =
'<div class="error">'.$langs->trans(
'ErrorOnlyDraftStatusCanBeDeletedInMassAction', $objecttmp->ref).
'</div><br>';
1070 if (method_exists($objecttmp,
'is_erasable') && $objecttmp->is_erasable() <= 0) {
1071 $langs->load(
"errors");
1073 $TMsg[] =
'<div class="error">'.$langs->trans(
'ErrorRecordHasChildren').
' '.$objecttmp->ref.
'</div><br>';
1078 $langs->load(
"errors");
1080 $TMsg[] =
'<div class="error">'.$langs->trans(
'ErrorLeaveRequestMustBeDraftCanceledOrRefusedToBeDeleted', $objecttmp->ref).
'</div><br>';
1084 if ($objectclass ==
"Task" && $objecttmp->hasChildren() > 0) {
1085 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task SET fk_task_parent = 0 WHERE fk_task_parent = ".((int) $objecttmp->id);
1086 $res = $db->query($sql);
1094 if ($objecttmp->element ==
'societe') {
1096 '@phan-var-force Societe $objecttmp';
1098 $result = $objecttmp->delete($objecttmp->id, $user, 1);
1100 $result = $objecttmp->delete($user);
1103 if (empty($result)) {
1104 $TMsg = array_merge($objecttmp->errors, $TMsg);
1105 } elseif ($result < 0) {
1119 if (empty($error)) {
1123 } elseif ($nbok > 0) {
1130 if (!empty($TMsg)) {
1145if (!$error && $massaction ==
'generate_doc' && $permissiontoread) {
1147 $objecttmp =
new $objectclass($db);
1149 foreach ($toselect as $toselectid) {
1150 $result = $objecttmp->fetch($toselectid);
1152 $outputlangs = $langs;
1156 $newlang =
GETPOST(
'lang_id',
'aZ09');
1158 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && empty($newlang) && isset($objecttmp->thirdparty->default_lang)) {
1159 $newlang = $objecttmp->thirdparty->default_lang;
1161 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && empty($newlang) && isset($objecttmp->default_lang)) {
1162 $newlang = $objecttmp->default_lang;
1164 if ($conf->global->MAIN_MULTILANGS && empty($newlang) && empty($objecttmp->thirdparty)) {
1165 $objecttmp->fetch_thirdparty();
1166 $newlang = $objecttmp->thirdparty->default_lang;
1168 if (!empty($newlang)) {
1169 $outputlangs =
new Translate(
"", $conf);
1170 $outputlangs->setDefaultLang($newlang);
1174 $hidedetails = isset($hidedetails) ? $hidedetails : (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS') ? 1 : 0);
1175 $hidedesc = isset($hidedesc) ? $hidedesc : (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_HIDE_DESC') ? 1 : 0);
1176 $hideref = isset($hideref) ? $hideref : (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_HIDE_REF') ? 1 : 0);
1177 $moreparams = isset($moreparams) ? $moreparams :
null;
1179 $result = $objecttmp->generateDocument($objecttmp->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1207if (!$error && ($action ==
'affecttag' && $confirm ==
'yes') && $permissiontoadd) {
1211 $affecttag_type =
GETPOST(
'affecttag_type',
'alpha');
1212 if (!empty($affecttag_type)) {
1213 $affecttag_type_array = explode(
',', $affecttag_type);
1217 if (!empty($affecttag_type_array)) {
1219 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1221 $to_affecttag_type_array = array();
1222 $categ_type_array = $categ->getMapList();
1223 foreach ($categ_type_array as $categdef) {
1224 if (in_array($categdef[
'code'], $affecttag_type_array)) {
1225 $to_affecttag_type_array[] = $categdef[
'code'];
1230 if (!empty($to_affecttag_type_array)) {
1231 foreach ($to_affecttag_type_array as $categ_type) {
1232 $contcats =
GETPOST(
'contcats_' . $categ_type,
'array');
1234 foreach ($toselect as $toselectid) {
1235 $result =
$object->fetch($toselectid);
1238 $result =
$object->setCategoriesCommon($contcats, $categ_type,
false);
1257 $toselect = array();
1263if (!$error && ($action ==
'updateprice' && $confirm ==
'yes') && $permissiontoadd) {
1266 if (GETPOSTISSET(
'pricerate')) {
1268 if ($pricepercentage == 0) {
1271 foreach ($toselect as $toselectid) {
1272 $result =
$object->fetch($toselectid);
1277 if (
$object->price_base_type ==
'TTC') {
1278 $newprice =
$object->price_ttc * (100 + $pricepercentage) / 100;
1279 $minprice =
$object->price_min_ttc;
1281 $newprice =
$object->price * (100 + $pricepercentage) / 100;
1282 $minprice =
$object->price_min;
1284 $res =
$object->updatePrice($newprice,
$object->price_base_type, $user,
$object->tva_tx, $minprice, 0,
$object->tva_npr, 0, 0, array(),
$object->default_vat_code);
1292 for ($level = 1; $level <= $maxlevel; $level++) {
1293 if (
$object->price_base_type ==
'TTC') {
1294 $newprice =
$object->multiprices_ttc[$level] * (100 + $pricepercentage) / 100;
1295 $minprice =
$object->multiprices_min_ttc[$level];
1297 $newprice =
$object->multiprices[$level] * (100 + $pricepercentage) / 100;
1298 $minprice =
$object->multiprices_min[$level];
1300 $res =
$object->updatePrice($newprice,
$object->price_base_type, $user,
$object->tva_tx, $minprice, $level,
$object->tva_npr, 0, 0, array(),
$object->default_vat_code);
1320 $toselect = array();
1326if (!$error && ($action ==
'setsupervisor' && $confirm ==
'yes') && $permissiontoadd) {
1329 $supervisortoset =
GETPOST(
'supervisortoset');
1330 if (!empty($supervisortoset)) {
1331 foreach ($toselect as $toselectid) {
1332 $result =
$object->fetch($toselectid);
1335 $object->fk_user = $supervisortoset;
1336 $res =
$object->update($user);
1356 $toselect = array();
1362if (!$error && ($action ==
'affectuser' && $confirm ==
'yes') && $permissiontoadd) {
1366 $usertoaffect =
GETPOST(
'usertoaffect');
1367 $projectrole =
GETPOST(
'projectrole');
1368 $tasksrole =
GETPOST(
'tasksrole');
1369 if (!empty($usertoaffect)) {
1370 foreach ($toselect as $toselectid) {
1371 $result =
$object->fetch($toselectid);
1374 $res =
$object->add_contact($usertoaffect, $projectrole,
'internal');
1376 $taskstatic =
new Task($db);
1377 $task_array = $taskstatic->getTasksArray(0, 0,
$object->id, 0, 0);
1379 foreach ($task_array as $task) {
1380 $tasksToAffect =
new Task($db);
1381 $result = $tasksToAffect->fetch($task->id);
1383 $res = $tasksToAffect->add_contact($usertoaffect, $tasksrole,
'internal');
1407 $toselect = array();
1413if (!$error && ($massaction ==
'enable' || ($action ==
'enable' && $confirm ==
'yes')) && $permissiontoadd) {
1416 $objecttmp =
new $objectclass($db);
1418 foreach ($toselect as $toselectid) {
1419 $result = $objecttmp->fetch($toselectid);
1421 if (in_array($objecttmp->element, array(
'societe'))) {
1422 $result = $objecttmp->setStatut(1);
1450if (!$error && ($massaction ==
'disable' || ($action ==
'disable' && $confirm ==
'yes')) && $permissiontoadd) {
1453 $objecttmp =
new $objectclass($db);
1455 foreach ($toselect as $toselectid) {
1456 $result = $objecttmp->fetch($toselectid);
1458 if (in_array($objecttmp->element, array(
'societe'))) {
1459 $result = $objecttmp->setStatut(0);
1487if (!$error && $action ==
'confirm_edit_value_extrafields' && $confirm ==
'yes' && $permissiontoadd) {
1490 $objecttmp =
new $objectclass($db);
1492 $e->fetch_name_optionals_label($objecttmp->table_element);
1495 $extrafieldKeyToUpdate =
GETPOST(
'extrafield-key-to-update');
1498 foreach ($toselect as $toselectid) {
1500 $objecttmp =
new $objectclass($db);
1501 $result = $objecttmp->fetch($toselectid);
1504 $ret = $e->setOptionalsFromPost(
null, $objecttmp, $extrafieldKeyToUpdate);
1506 $objecttmp->insertExtraFields();
1530if (!$error && ($massaction ==
'affectcommercial' || ($action ==
'affectcommercial' && $confirm ==
'yes')) && $permissiontoadd) {
1533 $objecttmp =
new $objectclass($db);
1536 foreach ($toselect as $toselectid) {
1537 $result = $objecttmp->fetch($toselectid);
1539 if (in_array($objecttmp->element, array(
'societe'))) {
1540 $result = $objecttmp->setSalesRep(
GETPOST(
"commercial",
"alpha"));
1558 setEventMessages($langs->trans(
"CommercialsAffected", $nbok),
null,
'mesgs');
1568if (!$error && ($massaction ==
'unassigncommercial' || ($action ==
'unassigncommercial' && $confirm ==
'yes')) && $permissiontoadd) {
1571 $objecttmp =
new $objectclass($db);
1574 foreach ($toselect as $toselectid) {
1575 $result = $objecttmp->fetch($toselectid);
1577 if (in_array($objecttmp->element, array(
'societe'))) {
1578 $TCommercial =
GETPOST(
"commercial",
"alpha");
1579 if (is_array($TCommercial)) {
1580 foreach ($TCommercial as $commercial) {
1581 $result = $objecttmp->del_commercial($user, $commercial);
1601 setEventMessages($langs->trans(
"CommercialsDisaffected", $nbok),
null,
'mesgs');
1611if (!$error && ($massaction ==
'approveleave' || ($action ==
'approveleave' && $confirm ==
'yes')) && $permissiontoapprove) {
1614 $objecttmp =
new $objectclass($db);
1616 foreach ($toselect as $toselectid) {
1617 $result = $objecttmp->fetch($toselectid);
1620 setEventMessages($langs->trans(
'StatusOfRefMustBe', $objecttmp->ref, $langs->transnoentitiesnoconv(
'Validated')),
null,
'warnings');
1623 if ($user->id == $objecttmp->fk_validator) {
1624 $objecttmp->oldcopy =
dol_clone($objecttmp, 2);
1626 $objecttmp->date_valid =
dol_now();
1627 $objecttmp->fk_user_valid = $user->id;
1628 $objecttmp->date_approval =
dol_now();
1629 $objecttmp->fk_user_approve = $user->id;
1631 $objecttmp->statut = $objecttmp->status;
1633 $verif = $objecttmp->approve($user);
1643 $nbopenedday =
num_open_day($objecttmp->date_debut_gmt, $objecttmp->date_fin_gmt, 0, 1, $objecttmp->halfday);
1644 $soldeActuel = $objecttmp->getCpforUser($objecttmp->fk_user, $objecttmp->fk_type);
1645 $newSolde = ($soldeActuel - $nbopenedday);
1648 $result = $objecttmp->addLogCP($user->id, $objecttmp->fk_user, $langs->transnoentitiesnoconv(
"Holidays"), $newSolde, $objecttmp->fk_type);
1655 $result = $objecttmp->updateSoldeCP($objecttmp->fk_user, $newSolde, $objecttmp->fk_type);
1664 $destinataire =
new User($db);
1665 $destinataire->fetch($objecttmp->fk_user);
1666 $emailTo = $destinataire->email;
1669 dol_syslog(
"User that request leave has no email, so we redirect directly to finished page without sending email");
1672 $expediteur =
new User($db);
1673 $expediteur->fetch($objecttmp->fk_validator);
1683 $subject = $societeName.
" - ".$langs->transnoentitiesnoconv(
"HolidaysValidated");
1686 $message = $langs->transnoentitiesnoconv(
"Hello").
" ".$destinataire->firstname.
",\n";
1689 $message .= $langs->transnoentities(
"HolidaysValidatedBody",
dol_print_date($objecttmp->date_debut,
'day'),
dol_print_date($objecttmp->date_fin,
'day')).
"\n";
1691 $message .=
"- ".$langs->transnoentitiesnoconv(
"ValidatedBy").
" : ".
dolGetFirstLastname($expediteur->firstname, $expediteur->lastname).
"\n";
1693 $message .=
"- ".$langs->transnoentitiesnoconv(
"Link").
" : ".$dolibarr_main_url_root.
"/holiday/card.php?id=".$objecttmp->id.
"\n\n";
1696 $trackid =
'leav'.$objecttmp->id;
1698 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
1699 $mail =
new CMailFile($subject, $emailTo, $emailFrom, $message, array(), array(), array(),
'',
'', 0, 0,
'',
'', $trackid);
1702 $result = $mail->sendfile();
1711 $langs->load(
"errors");
1712 setEventMessages($langs->trans(
'ErrorNotApproverForHoliday', $objecttmp->ref),
null,
'errors');
1724 } elseif ($nbok == 1) {
1733if (!$error && ($massaction ==
'increaseholiday' || ($action ==
'increaseholiday' && $confirm ==
'yes')) && $permissiontoapprove) {
1735 $objecttmp =
new $objectclass($db);
1737 $typeholiday =
GETPOST(
'typeholiday',
'alpha');
1740 if ($nbdaysholidays <= 0) {
1746 foreach ($toselect as $toselectid) {
1747 $balancecpuser = $objecttmp->getCPforUser($toselectid, $typeholiday);
1748 if (!empty($balancecpuser)) {
1749 $newnbdaysholidays = $nbdaysholidays + $balancecpuser;
1751 $newnbdaysholidays = $nbdaysholidays;
1753 $result = $holiday->addLogCP($user->id, $toselectid, $langs->transnoentitiesnoconv(
'ManualUpdate'), $newnbdaysholidays, $typeholiday);
1760 $objecttmp->updateSoldeCP($toselectid, $newnbdaysholidays, $typeholiday);
1773 setEventMessages($langs->trans(
"HolidayRecordsIncreased", $nbok),
null,
'mesgs');
1774 } elseif ($nbok == 1) {
1778 $toselect = array();
1785if (!$error && ($massaction ==
'clonetasks' || ($action ==
'clonetasks' && $confirm ==
'yes'))) {
1788 include_once DOL_DOCUMENT_ROOT.
'/projet/class/task.class.php';
1790 $origin_task =
new Task($db);
1791 $clone_task =
new Task($db);
1792 $newproject =
new Project($db);
1796 $iscontactofnewproject = 0;
1797 if (empty($newproject->public)) {
1798 $tmps = $newproject->getProjectsAuthorizedForUser($user, 0, 1, 0,
'(fk_statut:=:1)');
1799 $tmparray = explode(
',', $tmps);
1800 if (!in_array($newproject->id, $tmparray)) {
1801 $iscontactofnewproject = 1;
1806 $permisstiontoadd =
false;
1807 if ($user->hasRight(
'project',
'all',
'creer') || ($user->hasRight(
'project',
'creer') && ($newproject->public || $iscontactofnewproject))) {
1808 $permisstiontoadd =
true;
1811 if ($permisstiontoadd) {
1812 foreach (
GETPOST(
'selected') as $task) {
1813 $origin_task->fetch($task,
'', 0);
1818 require_once DOL_DOCUMENT_ROOT .
"/core/modules/project/task/" .
getDolGlobalString(
'PROJECT_TASK_ADDON') .
'.php';
1819 $modTask =
new $classnamemodtask();
1820 '@phan-var-force ModeleNumRefTask $modTask';
1821 $defaultref = $modTask->getNextValue(
null, $clone_task);
1825 $clone_task->fk_project =
GETPOSTINT(
'projectid');
1826 $clone_task->ref = $defaultref;
1827 $clone_task->label = $origin_task->label;
1828 $clone_task->description = $origin_task->description;
1829 $clone_task->planned_workload = $origin_task->planned_workload;
1830 $clone_task->fk_task_parent = $origin_task->fk_task_parent;
1831 $clone_task->date_c =
dol_now();
1832 $clone_task->date_start = $origin_task->date_start;
1833 $clone_task->date_end = $origin_task->date_end;
1834 $clone_task->progress = $origin_task->progress;
1837 $ret = $extrafields->setOptionalsFromPost(
null, $clone_task);
1839 $taskid = $clone_task->create($user);
1842 $result = $clone_task->add_contact(
GETPOSTINT(
"userid"),
'TASKEXECUTIVE',
'internal');
1845 if ($db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1846 $langs->load(
"projects");
1848 $duplicate_code_error =
true;
1859 setEventMessages($langs->trans(
'NumberOfTasksCloned', $num),
null,
'mesgs');
1860 header(
"Location: ".DOL_URL_ROOT.
'/projet/tasks.php?id='.
GETPOSTINT(
'projectid'));
1868$parameters[
'toselect'] = (empty($toselect) ? array() : $toselect);
1869$parameters[
'uploaddir'] = $uploaddir;
1870$parameters[
'massaction'] = $massaction;
1871$parameters[
'diroutputmassaction'] = isset($diroutputmassaction) ? $diroutputmassaction :
null;
1873$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)
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)
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).
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
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 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)
pdf_getFormat(Translate $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.