diff --git a/htdocs/admin/mails.php b/htdocs/admin/mails.php index ec3faca6625..e29bea1a2e6 100644 --- a/htdocs/admin/mails.php +++ b/htdocs/admin/mails.php @@ -132,7 +132,7 @@ if (! empty($_POST['removedfile']) || ! empty($_POST['removedfilehtml'])) if (($action == 'send' || $action == 'sendhtml') && ! GETPOST('addfile') && ! GETPOST('addfilehtml') && ! GETPOST('removedfile') && ! GETPOST('cancel')) { $error=0; - + $email_from=''; if (! empty($_POST["fromname"])) $email_from=$_POST["fromname"].' '; if (! empty($_POST["frommail"])) $email_from.='<'.$_POST["frommail"].'>'; @@ -144,12 +144,12 @@ if (($action == 'send' || $action == 'sendhtml') && ! GETPOST('addfile') && ! GE $subject = $_POST['subject']; $body = $_POST['message']; $deliveryreceipt= $_POST["deliveryreceipt"]; - + //Check if we have to decode HTML if (!empty($conf->global->FCKEDITOR_ENABLE_MAILING) && dol_textishtml(dol_html_entity_decode($body, ENT_COMPAT | ENT_HTML401))) { $body=dol_html_entity_decode($body, ENT_COMPAT | ENT_HTML401); } - + // Create form object include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; $formmail = new FormMail($db); @@ -693,7 +693,7 @@ else $formmail->clear_attached_files(); } - $formmail->show_form(($action == 'testhtml'?'addfilehtml':'addfile'),($action == 'testhtml'?'removefilehtml':'removefile')); + print $formmail->get_form(($action == 'testhtml'?'addfilehtml':'addfile'),($action == 'testhtml'?'removefilehtml':'removefile')); print '
'; } diff --git a/htdocs/comm/mailing/fiche.php b/htdocs/comm/mailing/fiche.php index 8217727e202..bc833b18955 100644 --- a/htdocs/comm/mailing/fiche.php +++ b/htdocs/comm/mailing/fiche.php @@ -947,7 +947,7 @@ else $formmail->param["mailid"]=$object->id; $formmail->param["returnurl"]=$_SERVER['PHP_SELF']."?id=".$object->id; - $formmail->show_form(); + print $formmail->get_form(); print '
'; } diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index a8dd4ab2a9e..4ad74c01af3 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -2149,14 +2149,14 @@ else { print '
'.$langs->trans('Modify').'
'; } - + // ReOpen if (($object->statut == 2 || $object->statut == 3) && $user->rights->propal->cloturer) { print '
global->MAIN_JUMP_TAG)?'':'#reopen').'"'; print '>'.$langs->trans('ReOpen').'
'; } - + // Send if ($object->statut == 1 || $object->statut == 2) { @@ -2166,7 +2166,7 @@ else } else print '
'.$langs->trans('SendByMail').'
'; } - + // Create an order if (! empty($conf->commande->enabled) && $object->statut == 2) { @@ -2175,18 +2175,18 @@ else print '
'.$langs->trans("AddOrder").'
'; } } - + // Create contract if ($conf->contrat->enabled && $object->statut == 2) { $langs->load("contracts"); - + if ($user->rights->contrat->creer) { print '
'.$langs->trans('AddContract').'
'; } } - + // Create an invoice and classify billed if ($object->statut == 2) { @@ -2194,37 +2194,37 @@ else { print '
'.$langs->trans("AddBill").'
'; } - + $arraypropal=$object->getInvoiceArrayList(); if (is_array($arraypropal) && count($arraypropal) > 0) { print '
socid.'">'.$langs->trans("ClassifyBilled").'
'; } } - + // Close if ($object->statut == 1 && $user->rights->propal->cloturer) { print '
global->MAIN_JUMP_TAG)?'':'#close').'"'; print '>'.$langs->trans('Close').'
'; } - + // Clone if ($user->rights->propal->creer) { print '
'.$langs->trans("ToClone").'
'; } - + // Delete if ($user->rights->propal->supprimer) { print '
'.$langs->trans('Delete').'
'; } - + } } - + print ''; } print "
\n"; @@ -2374,7 +2374,7 @@ else $formmail->add_attached_files($file,basename($file),dol_mimetype($file)); } - $formmail->show_form(); + print $formmail->get_form(); print '
'; } diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index 760324d23e8..480fdb95841 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -2676,7 +2676,7 @@ else } // Show form - $formmail->show_form(); + print $formmail->get_form(); print '
'; } diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index c900b0d7ebb..de05b11a64c 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -3914,8 +3914,8 @@ else if ($id > 0 || ! empty($ref)) { $liste[$key]=$value; } - $formmail->withto=GETPOST('sendto')?GETPOST('sendto'):$liste; - $formmail->withtocc=$liste; + $formmail->withto=GETPOST('sendto')?GETPOST('sendto'):$liste; // List suggested for send to + $formmail->withtocc=$liste; // List suggested for CC $formmail->withtoccc=$conf->global->MAIN_EMAIL_USECCC; if(empty($object->ref_client)) { @@ -3972,7 +3972,7 @@ else if ($id > 0 || ! empty($ref)) $formmail->add_attached_files($file,basename($file),dol_mimetype($file)); } - $formmail->show_form(); + print $formmail->get_form(); print '
'; } diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 53adade47ab..cf15d3f13fc 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -90,7 +90,7 @@ class Facture extends CommonInvoice var $close_code; //! Commentaire si mis a paye sans paiement complet var $close_note; - //! 1 if invoice paid COMPLETELY, 0 otherwise (do not use it anymore, use statut and close_code + //! 1 if invoice paid COMPLETELY, 0 otherwise (do not use it anymore, use statut and close_code) var $paye; //! id of source invoice if replacement invoice or credit note var $fk_facture_source; diff --git a/htdocs/compta/facture/impayees.php b/htdocs/compta/facture/impayees.php index dd374eb1a6f..36cc7944105 100644 --- a/htdocs/compta/facture/impayees.php +++ b/htdocs/compta/facture/impayees.php @@ -37,6 +37,7 @@ $langs->load("bills"); $id = (GETPOST('facid','int') ? GETPOST('facid','int') : GETPOST('id','int')); $action = GETPOST('action','alpha'); $option = GETPOST('option'); +$mode=GETPOST('mode'); // Security check if ($user->societe_id) $socid=$user->societe_id; @@ -45,11 +46,157 @@ $result = restrictedArea($user,'facture',$id,''); $diroutputpdf=$conf->facture->dir_output . '/unpaid/temp'; if (! $user->rights->societe->client->voir || $socid) $diroutputpdf.='/private/'.$user->id; // If user has no permission to see all, output dir is specific to user +$resultmasssend=''; + /* * Action */ +// Send remind email +if ($action == 'presend' && GETPOST('cancel')) $action=''; + +if ($action == 'presend' && GETPOST('sendmail')) +{ + if (!isset($user->email)) + { + $error++; + setEventMessage("NoSenderEmailDefined"); + } + + $countToSend = count($_POST['toSend']); + if (empty($countToSend)) + { + $error++; + setEventMessage("InvoiceNotChecked","warnings"); + } + + if (! $error) + { + $compteEmailEnvoi = 0; + $nbignored = 0; + + for ($i = 0; $i < $countToSend; $i++) + { + $object = new Facture($db); + $result = $object->fetch($_POST['toSend'][$i]); + + if ($result > 0) // Invoice was found + { + if ($object->statut != 1) continue; // Payment done or started or canceled + + // Read PDF + $filename=dol_sanitizeFileName($object->ref); + $filedir=$conf->facture->dir_output . '/' . dol_sanitizeFileName($object->ref); + $file = $filedir . '/' . $filename.'.pdf'; // TODO What if ODT ? + + if (dol_is_file($file)) + { + $object->fetch_thirdparty(); + $sendto = $object->thirdparty->email; + + if (empty($sendto)) $nbignored++; + + if (dol_strlen($sendto)) + { + $langs->load("commercial"); + $from = $user->getFullName($langs) . ' <' . $user->email .'>'; + $replyto = $from; + $message = $conf->global->RELANCES_MASSE_TEXTE_EMAIL; + $subject = $conf->global->RELANCES_MASSE_OBJET_EMAIL; + + $substitutionarray= + make_substitutions($message, $substitutionarray); + + $actiontypecode='AC_FAC'; + $actionmsg=$langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto.".\n"; + if ($message) + { + $actionmsg.=$langs->transnoentities('MailTopic').": ".$subject."\n"; + $actionmsg.=$langs->transnoentities('TextUsedInTheMessageBody').":\n"; + $actionmsg.=$message; + } + // Create form object + include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'); + $formmail = new FormMail($db); + $formmail->clear_attached_files(); + $formmail->add_attached_files($file, $object->ref.'.pdf', 'application/pdf'); + $attachedfiles=$formmail->get_attached_files(); + $filepath = $attachedfiles['paths']; + $filename = $attachedfiles['names']; + $mimetype = $attachedfiles['mimes']; + + // Send mail + require_once(DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'); + $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,'',$deliveryreceipt,-1); + if ($mailfile->error) + { + $resultmasssend.='
'.$mailfile->error.'
'; + } + else + { + $result=$mailfile->sendfile(); + if ($result) + { + $resultmasssend.=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($from,2),$mailfile->getValidAddress($sendto,2)); // Must not contain " + + $error=0; + + // Initialisation donnees + $object->sendtoid = 0; + $object->actiontypecode = $actiontypecode; + $object->actionmsg = $actionmsg; // Long text + $object->actionmsg2 = $actionmsg2; // Short text + $object->fk_element = $object->id; + $object->elementtype = $object->element; + + // Appel des triggers + include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); + $interface=new Interfaces($db); + $result=$interface->run_triggers('BILL_SENTBYMAIL',$object,$user,$langs,$conf); + if ($result < 0) { $error++; $this->errors=$interface->errors; } + // Fin appel triggers + + if ($error) + { + dol_print_error($db); + } + $compteEmailEnvoi ++; + + } + else + { + $langs->load("other"); + $resultmasssend.='
'; + if ($mailfile->error) + { + $resultmasssend.=$langs->trans('ErrorFailedToSendMail',$from,$sendto); + $resultmasssend.='
'.$mailfile->error; + } + else + { + $resultmasssend.='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS'; + } + $resultmasssend.='
'; + } + } + } + } + else + { + $langs->load("other"); + print $resultmasssend='
'.$langs->trans('ErrorCantReadFile',$file).'
'; + dol_syslog('Failed to read file: '.$file); + break ; + } + } + } + + setEventMessage($compteEmailEnvoi. '/'.$countToSend.' '.$langs->trans("RemindSent")); + } +} + + if ($action == "builddoc" && $user->rights->facture->lire && ! GETPOST('button_search')) { if (is_array($_POST['toGenerate'])) @@ -61,9 +208,12 @@ if ($action == "builddoc" && $user->rights->facture->lire && ! GETPOST('button_s // liste les fichiers $files = array(); $factures_bak = $factures ; - foreach($_POST['toGenerate'] as $basename){ - foreach($factures as $facture){ - if(strstr($facture["name"],$basename)){ + foreach($_POST['toGenerate'] as $basename) + { + foreach($factures as $facture) + { + if(strstr($facture["name"],$basename)) + { $files[] = $conf->facture->dir_output.'/'.$basename.'/'.$facture["name"]; } } @@ -121,12 +271,12 @@ if ($action == "builddoc" && $user->rights->facture->lire && ! GETPOST('button_s } else { - $mesg='
'.$langs->trans('NoPDFAvailableForChecked').'
'; + setEventMessage($langs->trans('NoPDFAvailableForChecked'),'errors'); } } else { - $mesg='
'.$langs->trans('InvoiceNotChecked').'
' ; + setEventMessage($langs->trans('InvoiceNotChecked'), 'warnings'); } } @@ -167,6 +317,12 @@ $(document).ready(function() { $("#checknone").click(function() { $(".checkformerge").attr('checked', false); }); + $("#checkallsend").click(function() { + $(".checkforsend").attr('checked', true); + }); + $("#checknonesend").click(function() { + $(".checkforsend").attr('checked', false); + }); }); '; print ''; + print ''; if ($late) print ''; $i = 0; @@ -283,7 +440,14 @@ if ($resql) print_liste_field_titre($langs->trans("Received"),$_SERVER["PHP_SELF"],"am","",$param,'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("Rest"),$_SERVER["PHP_SELF"],"am","",$param,'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"fk_statut,paye,am","",$param,'align="right"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Merge"),$_SERVER["PHP_SELF"],"","",$param,'align="center"',$sortfield,$sortorder); + if (empty($mode)) + { + print_liste_field_titre($langs->trans("PDFMerge"),$_SERVER["PHP_SELF"],"","",$param,'align="center"',$sortfield,$sortorder); + } + else + { + print_liste_field_titre($langs->trans("Remind"),$_SERVER["PHP_SELF"],"","",$param,'align="center"',$sortfield,$sortorder); + } print "\n"; // Lignes des champs de filtre @@ -302,9 +466,18 @@ if ($resql) print ''; print ''; print ''; - print ''; - if ($conf->use_javascript_ajax) print ''.$langs->trans("All").' / '.$langs->trans("None").''; - print ''; + if (empty($mode)) + { + print ''; + if ($conf->use_javascript_ajax) print ''.$langs->trans("All").' / '.$langs->trans("None").''; + print ''; + } + else + { + print ''; + if ($conf->use_javascript_ajax) print ''.$langs->trans("All").' / '.$langs->trans("None").''; + print ''; + } print "\n"; if ($num > 0) @@ -384,13 +557,23 @@ if ($resql) print $facturestatic->LibStatut($objp->paye,$objp->fk_statut,5,$objp->am); print ''; - // Checkbox - print ''; - if (! empty($formfile->numoffiles)) - print ''; + if (empty($mode)) + { + // Checkbox to merge + print ''; + if (! empty($formfile->numoffiles)) + print ''; + else + print ' '; + print '' ; + } else - print ' '; - print '' ; + { + // Checkbox to send remind + print ''; + print ''; + print '' ; + } print "\n"; $total_ht+=$objp->total_ht; @@ -415,17 +598,85 @@ if ($resql) print ""; - /* - * Show list of available documents - */ - $filedir=$diroutputpdf; - $genallowed=$user->rights->facture->lire; - $delallowed=$user->rights->facture->lire; - print '
'; - print ''; - // We disable multilang because we concat already existing pdf. - $formfile->show_documents('unpaid','',$filedir,$urlsource,$genallowed,$delallowed,'',1,1,0,48,1,$param,$langs->trans("PDFMerge"),$langs->trans("PDFMerge")); + if (empty($mode)) + { + /* + * Show list of available documents + */ + $filedir=$diroutputpdf; + $genallowed=$user->rights->facture->lire; + $delallowed=$user->rights->facture->lire; + + print '
'; + print ''; + // We disable multilang because we concat already existing pdf. + $formfile->show_documents('unpaid','',$filedir,$urlsource,$genallowed,$delallowed,'',1,1,0,48,1,$param,$langs->trans("PDFMerge"),$langs->trans("PDFMerge")); + } + else + { + $langs->load("mails"); + + if ($action != 'presend') + { + print '
'; + print ''.$langs->trans("SendRemind").''; + print '
'; + } + else + { + include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; + $formmail = new FormMail($db); + + print '
'; + print_fiche_titre($langs->trans("SendRemind"),'','').'
'; + + $topicmail="MailTopicSendRemindUnpaidInvoices"; + $modelmail="facture_relance"; + + // Cree l'objet formulaire mail + include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; + $formmail = new FormMail($db); + $formmail->fromtype = 'user'; + $formmail->fromid = $user->id; + $formmail->fromname = $user->getFullName($langs); + $formmail->frommail = $user->email; + $formmail->withfrom=1; + $liste=array(); + $formmail->withto=''; + $formmail->withtocc=1; + $formmail->withtoccc=$conf->global->MAIN_EMAIL_USECCC; + $formmail->withtopic=$langs->transnoentities($topicmail, '__FACREF__', '__REFCLIENT__'); + $formmail->withfile=$langs->trans("EachInvoiceWillBeAttachedToEmail"); + $formmail->withbody=1; + $formmail->withdeliveryreceipt=1; + $formmail->withcancel=1; + // Tableau des substitutions + //$formmail->substit['__FACREF__']=''; + $formmail->substit['__SIGNATURE__']=$user->signature; + //$formmail->substit['__REFCLIENT__']=''; + $formmail->substit['__PERSONALIZED__']=''; + $formmail->substit['__CONTACTCIVNAME__']=''; + + // Tableau des parametres complementaires du post + $formmail->param['action']=$action; + $formmail->param['models']=$modelmail; + $formmail->param['facid']=$object->id; + $formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id; + + print $formmail->get_form(); + + + } + + if ($resultmasssend) + { + print '
'.$langs->trans("ResultOfMassSending").':
'."\n"; + print $resultmasssend; + print '
'; + } + } + print ''; $db->free($resql); diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php index c39c5f05277..7746d178e67 100644 --- a/htdocs/core/class/html.formmail.class.php +++ b/htdocs/core/class/html.formmail.class.php @@ -503,39 +503,47 @@ class FormMail { $out.= ''; $out.= ''.$langs->trans("MailFile").''; + $out.= ''; - // TODO Trick to have param removedfile containing nb of image to delete. But this does not works without javascript - $out.= ''."\n"; - $out.= ''."\n"; - if (count($listofpaths)) + if (is_numeric($this->withfile)) { - foreach($listofpaths as $key => $val) - { - $out.= '
'; - $out.= img_mime($listofnames[$key]).' '.$listofnames[$key]; - if (! $this->withfilereadonly) - { - $out.= ' '; - //$out.= ' '.img_delete($langs->trans("Delete").''; - } - $out.= '
'; - } + // TODO Trick to have param removedfile containing nb of image to delete. But this does not works without javascript + $out.= ''."\n"; + $out.= ''."\n"; + if (count($listofpaths)) + { + foreach($listofpaths as $key => $val) + { + $out.= '
'; + $out.= img_mime($listofnames[$key]).' '.$listofnames[$key]; + if (! $this->withfilereadonly) + { + $out.= ' '; + //$out.= ' '.img_delete($langs->trans("Delete").''; + } + $out.= '
'; + } + } + else + { + $out.= $langs->trans("NoAttachedFiles").'
'; + } + if ($this->withfile == 2) // Can add other files + { + $out.= ''; + $out.= ' '; + $out.= ''; + } } else { - $out.= $langs->trans("NoAttachedFiles").'
'; - } - if ($this->withfile == 2) // Can add other files - { - $out.= ''; - $out.= ' '; - $out.= ''; + $out.=$this->withfile; } $out.= "\n"; } diff --git a/htdocs/expedition/fiche.php b/htdocs/expedition/fiche.php index 0a5d3d0cfcf..c04c4966efe 100644 --- a/htdocs/expedition/fiche.php +++ b/htdocs/expedition/fiche.php @@ -1542,7 +1542,7 @@ else if ($id || $ref) } // Show form - $formmail->show_form(); + print $formmail->get_form(); print '
'; } diff --git a/htdocs/fichinter/fiche.php b/htdocs/fichinter/fiche.php index e40d2b44daa..15e08bad604 100644 --- a/htdocs/fichinter/fiche.php +++ b/htdocs/fichinter/fiche.php @@ -1709,7 +1709,7 @@ else if ($id > 0 || ! empty($ref)) $formmail->add_attached_files($file,basename($file),dol_mimetype($file)); } - $formmail->show_form(); + print $formmail->get_form(); print '
'; } diff --git a/htdocs/fourn/commande/fiche.php b/htdocs/fourn/commande/fiche.php index ffa72ecf9ac..8da53a67477 100644 --- a/htdocs/fourn/commande/fiche.php +++ b/htdocs/fourn/commande/fiche.php @@ -1634,13 +1634,13 @@ elseif (! empty($object->id)) } print ''.price($line->total_ht).''; - + if (is_object($hookmanager)) { $parameters=array('line'=>$line,'num'=>$num,'i'=>$i); $reshook=$hookmanager->executeHooks('printObjectLine',$parameters,$object,$action); } - + if ($object->statut == 0 && $user->rights->fournisseur->commande->creer) { print 'id.'#'.$line->id.'">'; @@ -2132,7 +2132,7 @@ elseif (! empty($object->id)) } // Show form - $formmail->show_form(); + print $formmail->get_form(); print '
'; } diff --git a/htdocs/fourn/facture/fiche.php b/htdocs/fourn/facture/fiche.php index 3722ceaac51..6d095e48b93 100644 --- a/htdocs/fourn/facture/fiche.php +++ b/htdocs/fourn/facture/fiche.php @@ -1996,13 +1996,13 @@ else print ''.price($object->lines[$i]->total_ht).''; print ''.price($object->lines[$i]->total_ttc).''; - + if (is_object($hookmanager)) { $parameters=array('line'=>$object->lines[$i],'num'=>$num,'i'=>$i); $reshook=$hookmanager->executeHooks('printObjectLine',$parameters,$object,$action); } - + print ''; if ($object->statut == 0) print '
lines[$i]->rowid.'">'.img_edit().''; else print ' '; @@ -2370,7 +2370,7 @@ else } // Show form - $formmail->show_form(); + print $formmail->get_form(); print '
'; } diff --git a/htdocs/langs/en_US/mails.lang b/htdocs/langs/en_US/mails.lang index c16827bbdee..88d499ac7e0 100644 --- a/htdocs/langs/en_US/mails.lang +++ b/htdocs/langs/en_US/mails.lang @@ -79,6 +79,10 @@ MailtoEMail=Hyper link to email ActivateCheckRead=Allow to use the "Unsubcribe" link ActivateCheckReadKey=Key use to encrypt URL use for "Read Receipt" and "Unsubcribe" feature EMailSentToNRecipients=EMail sent to %s recipients. +EachInvoiceWillBeAttachedToEmail=A document using default invoice document template will be created and attached to each email. +MailTopicSendRemindUnpaidInvoices=Remind of invoice %s (%s) +SendRemind=Send remind by EMails +RemindSent=%S remind(s) sent # Libelle des modules de liste de destinataires mailing MailingModuleDescContactCompanies=Contacts/addresses of all third parties (customer, prospect, supplier, ...) diff --git a/htdocs/societe/soc.php b/htdocs/societe/soc.php index e415c808c5f..5731ce0196a 100644 --- a/htdocs/societe/soc.php +++ b/htdocs/societe/soc.php @@ -1932,7 +1932,7 @@ else $formmail->add_attached_files($file,basename($file),dol_mimetype($file)); } - $formmail->show_form(); + print $formmail->get_form(); print '
'; }