diff --git a/htdocs/core/actions_massactions.inc.php b/htdocs/core/actions_massactions.inc.php index 5313b79dc04..0d4a6c6d80c 100644 --- a/htdocs/core/actions_massactions.inc.php +++ b/htdocs/core/actions_massactions.inc.php @@ -90,6 +90,8 @@ if (! $error && $massaction == 'confirm_presend') } //var_dump($listofobjectthirdparties);exit; + + // Loop on each thirdparty foreach ($listofobjectthirdparties as $thirdpartyid) { $result = $thirdparty->fetch($thirdpartyid); @@ -99,62 +101,90 @@ if (! $error && $massaction == 'confirm_presend') exit; } - // Define recipient $sendto and $sendtocc + $sendto=''; + $sendtocc=''; + $sendtobcc=''; + $sendtoid = array(); + + // Define $sendto + $receiver=$_POST['receiver']; + if (! is_array($receiver)) + { + if ($receiver == '-1') $receiver=array(); + else $receiver=array($receiver); + } + $tmparray=array(); if (trim($_POST['sendto'])) { - // Recipient is provided into free text - $sendto = trim($_POST['sendto']); - $sendtoid = 0; + // Recipients are provided into free text + $tmparray[] = trim($_POST['sendto']); } - elseif ($_POST['receiver'] != '-1') + if (count($receiver)>0) { - // Recipient was provided from combo list - if ($_POST['receiver'] == 'thirdparty') // Id of third party - { - $sendto = $thirdparty->email; - $sendtoid = 0; - } - else // Id du contact - { - $sendto = $thirdparty->contact_get_property((int) $_POST['receiver'],'email'); - $sendtoid = $_POST['receiver']; - } + foreach($receiver as $key=>$val) + { + // Recipient was provided from combo list + if ($val == 'thirdparty') // Id of third party + { + $tmparray[] = $thirdparty->name.' <'.$thirdparty->email.'>'; + } + elseif ($val) // Id du contact + { + $tmparray[] = $thirdparty->contact_get_property((int) $val,'email'); + $sendtoid[] = $val; + } + } } + $sendto=implode(',',$tmparray); + + // Define $sendtocc + $receivercc=$_POST['receivercc']; + if (! is_array($receivercc)) + { + if ($receivercc == '-1') $receivercc=array(); + else $receivercc=array($receivercc); + } + $tmparray=array(); if (trim($_POST['sendtocc'])) { - $sendtocc = trim($_POST['sendtocc']); + $tmparray[] = trim($_POST['sendtocc']); } - elseif ($_POST['receivercc'] != '-1') + if (count($receivercc) > 0) { - // Recipient was provided from combo list - if ($_POST['receivercc'] == 'thirdparty') // Id of third party - { - $sendtocc = $thirdparty->email; - } - else // Id du contact - { - $sendtocc = $thirdparty->contact_get_property((int) $_POST['receivercc'],'email'); - } + foreach($receivercc as $key=>$val) + { + // Recipient was provided from combo list + if ($val == 'thirdparty') // Id of third party + { + $tmparray[] = $thirdparty->name.' <'.$thirdparty->email.'>'; + } + elseif ($val) // Id du contact + { + $tmparray[] = $thirdparty->contact_get_property((int) $val,'email'); + //$sendtoid[] = $val; TODO Add also id of contact in CC ? + } + } } + $sendtocc=implode(',',$tmparray); - //var_dump($listofobjectref[$thirdpartyid]); // Array of invoice for this thirdparty - + //var_dump($listofobjectref);exit; $attachedfiles=array('paths'=>array(), 'names'=>array(), 'mimes'=>array()); $listofqualifiedinvoice=array(); $listofqualifiedref=array(); foreach($listofobjectref[$thirdpartyid] as $objectid => $object) { - //var_dump($object); //var_dump($thirdpartyid.' - '.$objectid.' - '.$object->statut); if ($objectclass == 'Facture' && $object->statut != Facture::STATUS_VALIDATED) { + $langs->load("errors"); $nbignored++; $resaction.='