diff --git a/htdocs/core/class/CMailFile.class.php b/htdocs/core/class/CMailFile.class.php index b3027b90885..a37f6b1562b 100644 --- a/htdocs/core/class/CMailFile.class.php +++ b/htdocs/core/class/CMailFile.class.php @@ -117,7 +117,7 @@ class CMailFile * @param string $sendcontext 'standard', 'emailing', ... (used to define with sending mode and parameters to use) * @param string $replyto Reply-to email (will be set to same value than From by default if not provided) */ - function __construct($subject,$to,$from,$msg,$filename_list=array(),$mimetype_list=array(),$mimefilename_list=array(),$addr_cc="",$addr_bcc="",$deliveryreceipt=0,$msgishtml=0,$errors_to='',$css='',$trackid='',$moreinheader='',$sendcontext='standard',$replyto='') + function __construct($subject, $to, $from, $msg, $filename_list=array(), $mimetype_list=array(), $mimefilename_list=array(), $addr_cc="", $addr_bcc="", $deliveryreceipt=0, $msgishtml=0, $errors_to='', $css='', $trackid='', $moreinheader='', $sendcontext='standard', $replyto='') { global $conf, $dolibarr_main_data_root; diff --git a/htdocs/core/class/translate.class.php b/htdocs/core/class/translate.class.php index 17f83452ba5..2e489f6ba65 100644 --- a/htdocs/core/class/translate.class.php +++ b/htdocs/core/class/translate.class.php @@ -655,11 +655,12 @@ class Translate * @param string $param2 chaine de param2 * @param string $param3 chaine de param3 * @param string $param4 chaine de param4 + * @param string $param5 chaine de param5 * @return string Translated string (encoded into UTF8) */ - function transnoentities($key, $param1='', $param2='', $param3='', $param4='') + function transnoentities($key, $param1='', $param2='', $param3='', $param4='', $param5='') { - return $this->convToOutputCharset($this->transnoentitiesnoconv($key, $param1, $param2, $param3, $param4)); + return $this->convToOutputCharset($this->transnoentitiesnoconv($key, $param1, $param2, $param3, $param4, $param5)); } @@ -675,9 +676,10 @@ class Translate * @param string $param2 chaine de param2 * @param string $param3 chaine de param3 * @param string $param4 chaine de param4 + * @param string $param5 chaine de param5 * @return string Translated string */ - function transnoentitiesnoconv($key, $param1='', $param2='', $param3='', $param4='') + function transnoentitiesnoconv($key, $param1='', $param2='', $param3='', $param4='', $param5='') { global $conf; @@ -700,7 +702,7 @@ class Translate if (! preg_match('/^Format/',$key)) { //print $str; - $str=sprintf($str,$param1,$param2,$param3,$param4); // Replace %s and %d except for FormatXXX strings. + $str=sprintf($str, $param1, $param2, $param3, $param4, $param5); // Replace %s and %d except for FormatXXX strings. } return $str; diff --git a/htdocs/expensereport/card.php b/htdocs/expensereport/card.php index d877ad00b2f..62315912209 100644 --- a/htdocs/expensereport/card.php +++ b/htdocs/expensereport/card.php @@ -375,7 +375,7 @@ if (empty($reshook)) */ // PREPARE SEND - $mailfile = new CMailFile($subject,$emailTo,$emailFrom,$message,$filedir,$mimetype,$filename); + $mailfile = new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename, '', '', 0, -1); if ($mailfile) { @@ -496,7 +496,7 @@ if (empty($reshook)) // PREPARE SEND - $mailfile = new CMailFile($subject,$emailTo,$emailFrom,$message,$filedir,$mimetype,$filename); + $mailfile = new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename, '', '', 0, -1); if ($mailfile) { @@ -615,7 +615,7 @@ if (empty($reshook)) } */ - $mailfile = new CMailFile($subject,$emailTo,$emailFrom,$message,$filedir,$mimetype,$filename); + $mailfile = new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename, '', '', 0, -1); if ($mailfile) { @@ -735,7 +735,7 @@ if (empty($reshook)) */ // PREPARE SEND - $mailfile = new CMailFile($subject,$emailTo,$emailFrom,$message,$filedir,$mimetype,$filename); + $mailfile = new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename, '', '', 0, -1); if ($mailfile) { @@ -788,126 +788,133 @@ if (empty($reshook)) } //var_dump($user->id == $object->fk_user_validator);exit; - if ($action == "confirm_cancel" && GETPOST('confirm', 'alpha')=="yes" && GETPOST('detail_cancel', 'alpha') && $id > 0 && $user->rights->expensereport->creer) + if ($action == "confirm_cancel" && GETPOST('confirm', 'alpha')=="yes" && $id > 0 && $user->rights->expensereport->creer) { - $object = new ExpenseReport($db); - $object->fetch($id); - - if ($user->id == $object->fk_user_valid || $user->id == $object->fk_user_author) + if (! GETPOST('detail_cancel', 'alpha')) { - $result = $object->set_cancel($user, GETPOST('detail_cancel', 'alpha')); - - if ($result > 0) - { - // Define output language - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) - { - $outputlangs = $langs; - $newlang = ''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang = GETPOST('lang_id','aZ09'); - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; - if (! empty($newlang)) { - $outputlangs = new Translate("", $conf); - $outputlangs->setDefaultLang($newlang); - } - $model=$object->modelpdf; - $ret = $object->fetch($id); // Reload to get new records - - $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); - } - } - - if ($result > 0) - { - // Send mail - - // TO - $destinataire = new User($db); - $destinataire->fetch($object->fk_user_author); - $emailTo = $destinataire->email; - - // FROM - $expediteur = new User($db); - $expediteur->fetch($object->fk_user_cancel); - $emailFrom = $expediteur->email; - - if ($emailFrom && $emailTo) - { - $filename=array(); $filedir=array(); $mimetype=array(); - - // SUBJECT - $subject = $langs->transnoentities("ExpenseReportCanceled"); - - // CONTENT - $link = $urlwithroot.'/expensereport/card.php?id='.$object->id; - $message = $langs->transnoentities("ExpenseReportCanceledMessage", $object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $_POST['detail_cancel'], $link); - - // Rebuilt pdf - /* - $object->setDocModel($user,""); - $resultPDF = expensereport_pdf_create($db,$object,'',"",$langs); - - if($resultPDF - { - // ATTACHMENT - $filename=array(); $filedir=array(); $mimetype=array(); - array_push($filename,dol_sanitizeFileName($object->ref).".pdf"); - array_push($filedir, $conf->expensereport->dir_output."/".dol_sanitizeFileName($object->ref)."/".dol_sanitizeFileName($object->ref).".pdf"); - array_push($mimetype,"application/pdf"); - } - */ - - // PREPARE SEND - $mailfile = new CMailFile($subject,$emailTo,$emailFrom,$message,$filedir,$mimetype,$filename); - - if ($mailfile) - { - // SEND - $result=$mailfile->sendfile(); - if ($result) - { - $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($emailFrom,2),$mailfile->getValidAddress($emailTo,2)); - setEventMessages($mesg, null, 'mesgs'); - header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); - exit; - } - else - { - $langs->load("other"); - if ($mailfile->error) - { - $mesg=''; - $mesg.=$langs->trans('ErrorFailedToSendMail', $emailFrom, $emailTo); - $mesg.='
'.$mailfile->error; - setEventMessages($mesg, null, 'errors'); - } - else - { - setEventMessages('No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', null, 'warnings'); - } - } - } - else - { - setEventMessages($mailfile->error,$mailfile->errors,'errors'); - $action=''; - } - } - else - { - setEventMessages($langs->trans("NoEmailSentBadSenderOrRecipientEmail"), null, 'warnings'); - $action=''; - } - } - else - { - setEventMessages($langs->trans("FailedToSetToCancel"), null, 'warnings'); - $action=''; - } + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Comment")), null, 'errors'); } else { - setEventMessages($object->error, $object->errors, 'errors'); + $object = new ExpenseReport($db); + $object->fetch($id); + + if ($user->id == $object->fk_user_valid || $user->id == $object->fk_user_author) + { + $result = $object->set_cancel($user, GETPOST('detail_cancel', 'alpha')); + + if ($result > 0) + { + // Define output language + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + { + $outputlangs = $langs; + $newlang = ''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang = GETPOST('lang_id','aZ09'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; + if (! empty($newlang)) { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); + } + $model=$object->modelpdf; + $ret = $object->fetch($id); // Reload to get new records + + $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); + } + } + + if ($result > 0) + { + // Send mail + + // TO + $destinataire = new User($db); + $destinataire->fetch($object->fk_user_author); + $emailTo = $destinataire->email; + + // FROM + $expediteur = new User($db); + $expediteur->fetch($object->fk_user_cancel); + $emailFrom = $expediteur->email; + + if ($emailFrom && $emailTo) + { + $filename=array(); $filedir=array(); $mimetype=array(); + + // SUBJECT + $subject = $langs->transnoentities("ExpenseReportCanceled"); + + // CONTENT + $link = $urlwithroot.'/expensereport/card.php?id='.$object->id; + $message = $langs->transnoentities("ExpenseReportCanceledMessage", $object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), GETPOST('detail_cancel','alpha'), $link); + + // Rebuilt pdf + /* + $object->setDocModel($user,""); + $resultPDF = expensereport_pdf_create($db,$object,'',"",$langs); + + if($resultPDF + { + // ATTACHMENT + $filename=array(); $filedir=array(); $mimetype=array(); + array_push($filename,dol_sanitizeFileName($object->ref).".pdf"); + array_push($filedir, $conf->expensereport->dir_output."/".dol_sanitizeFileName($object->ref)."/".dol_sanitizeFileName($object->ref).".pdf"); + array_push($mimetype,"application/pdf"); + } + */ + + // PREPARE SEND + $mailfile = new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename, '', '', 0, -1); + + if ($mailfile) + { + // SEND + $result=$mailfile->sendfile(); + if ($result) + { + $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($emailFrom,2),$mailfile->getValidAddress($emailTo,2)); + setEventMessages($mesg, null, 'mesgs'); + header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); + exit; + } + else + { + $langs->load("other"); + if ($mailfile->error) + { + $mesg=''; + $mesg.=$langs->trans('ErrorFailedToSendMail', $emailFrom, $emailTo); + $mesg.='
'.$mailfile->error; + setEventMessages($mesg, null, 'errors'); + } + else + { + setEventMessages('No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', null, 'warnings'); + } + } + } + else + { + setEventMessages($mailfile->error,$mailfile->errors,'errors'); + $action=''; + } + } + else + { + setEventMessages($langs->trans("NoEmailSentBadSenderOrRecipientEmail"), null, 'warnings'); + $action=''; + } + } + else + { + setEventMessages($langs->trans("FailedToSetToCancel"), null, 'warnings'); + $action=''; + } + } + else + { + setEventMessages($object->error, $object->errors, 'errors'); + } } } @@ -1019,7 +1026,7 @@ if (empty($reshook)) $resultPDF = expensereport_pdf_create($db,$object,'',"",$langs); // PREPARE SEND - $mailfile = new CMailFile($subject,$emailTo,$emailFrom,$message,$filedir,$mimetype,$filename); + $mailfile = new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename, '', '', 0, -1); if ($mailfile) { @@ -1614,7 +1621,7 @@ else if ($action == 'cancel') { - $array_input = array('text'=>$langs->trans("ConfirmCancelTrip"), array('type'=>"text",'label'=>$langs->trans("Comment"),'name'=>"detail_cancel",'size'=>"50",'value'=>"")); + $array_input = array('text'=>$langs->trans("ConfirmCancelTrip"), array('type'=>"text",'label'=>''.$langs->trans("Comment").'','name'=>"detail_cancel",'size'=>"50",'value'=>"")); $formconfirm=$form->formconfirm($_SEVER["PHP_SELF"]."?id=".$id,$langs->trans("Cancel"),"","confirm_cancel",$array_input,"",1); }