diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index e770bb5ea72..07fcee8e709 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -4964,7 +4964,7 @@ class Form * @param string $paramid Name of parameter to use to name the id into the URL link * @param string $morehtml More html content to output just before the nav bar * @param int $shownav Show Condition (navigation is shown if value is 1) - * @param string $fieldid Nom du champ en base a utiliser pour select next et previous + * @param string $fieldid Nom du champ en base a utiliser pour select next et previous (we make the select max and min on this field) * @param string $fieldref Nom du champ objet ref (object->ref) a utiliser pour select next et previous * @param string $morehtmlref Code html supplementaire a afficher apres ref * @param string $moreparam More param to add in nav link url. @@ -4990,7 +4990,7 @@ class Form //print "xx".$previous_ref."x".$next_ref; //if ($previous_ref || $next_ref || $morehtml) { //$ret.='
| ';
- $ret.=' ';
+ $ret.=' ';
//}
$ret.=dol_htmlentities($object->$fieldref);
diff --git a/htdocs/expensereport/card.php b/htdocs/expensereport/card.php
index 2d9bcbceead..0b688790af7 100644
--- a/htdocs/expensereport/card.php
+++ b/htdocs/expensereport/card.php
@@ -46,6 +46,7 @@ $date_start = dol_mktime(0, 0, 0, GETPOST('date_debutmonth'), GETPOST('date_debu
$date_end = dol_mktime(0, 0, 0, GETPOST('date_finmonth'), GETPOST('date_finday'), GETPOST('date_finyear'));
$date = dol_mktime(0, 0, 0, GETPOST('datemonth'), GETPOST('dateday'), GETPOST('dateyear'));
$fk_projet=GETPOST('fk_projet');
+$ref=GETPOST("ref",'alpha');
// If socid provided by ajax company selector
if (! empty($_REQUEST['socid_id']))
@@ -92,7 +93,7 @@ if ($cancel) $action='';
if ($action == 'confirm_delete' && GETPOST("confirm") == "yes" && $id > 0 && $user->rights->expensereport->supprimer)
{
$object = new ExpenseReport($db);
- $result=$object->delete($id);
+ $result=$object->delete($id, $user);
if ($result >= 0)
{
header("Location: index.php");
@@ -214,59 +215,67 @@ if ($action == "confirm_save" && GETPOST("confirm") == "yes" && $id > 0 && $user
$expediteur->fetch($object->fk_user_author);
$emailFrom = $expediteur->email;
- // SUBJECT
- $subject = $langs->trans("ExpenseReportWaitingForApproval");
-
- // CONTENT
- $link = $urlwithroot.'/expensereport/card.php?id='.$object->id;
- $message = $langs->trans("ExpenseReportWaitingForApprovalMessage", $expediteur->getFullName($langs), get_date_range($object->date_debut,$object->date_fin,'',$langs), $link);
-
- // Rebuild pdf
- /*
- $object->setDocModel($user,"");
- $resultPDF = expensereport_pdf_create($db,$id,'',"",$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)
+ if ($emailTo && $emailFrom)
{
- // SEND
- $result=$mailfile->sendfile();
- if ($result)
+ // SUBJECT
+ $subject = $langs->trans("ExpenseReportWaitingForApproval");
+
+ // CONTENT
+ $link = $urlwithroot.'/expensereport/card.php?id='.$object->id;
+ $message = $langs->trans("ExpenseReportWaitingForApprovalMessage", $expediteur->getFullName($langs), get_date_range($object->date_debut,$object->date_fin,'',$langs), $link);
+
+ // Rebuild pdf
+ /*
+ $object->setDocModel($user,"");
+ $resultPDF = expensereport_pdf_create($db,$id,'',"",$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)
{
- $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($emailFrom,2),$mailfile->getValidAddress($emailTo,2));
- setEventMessage($mesg);
- header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
- exit;
- }
- else
- {
- $langs->load("other");
- if ($mailfile->error)
+ // SEND
+ $result=$mailfile->sendfile();
+ if ($result)
{
- $mesg='';
- $mesg.=$langs->trans('ErrorFailedToSendMail',$from,$sendto);
- $mesg.=' '.$mailfile->error; - setEventMessage($mesg,'errors'); + $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($emailFrom,2),$mailfile->getValidAddress($emailTo,2)); + setEventMessage($mesg); + header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); + exit; } else { - setEventMessage('No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', 'warnings'); + $langs->load("other"); + if ($mailfile->error) + { + $mesg=''; + $mesg.=$langs->trans('ErrorFailedToSendMail',$from,$sendto); + $mesg.=' '.$mailfile->error; + setEventMessage($mesg,'errors'); + } + else + { + setEventMessage('No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', 'warnings'); + } } } + else + { + setEventMessages($mailfile->error,$mailfile->errors,'errors'); + $action=''; + } } else { - setEventMessages($mailfile->error,$mailfile->errors,'errors'); + setEventMessage($langs->trans("NoEmailSentBadSenderOrRecipientEmail"), 'warnings'); $action=''; } } @@ -304,66 +313,73 @@ if ($action == "confirm_save_from_refuse" && GETPOST("confirm") == "yes" && $id if ($result > 0) { - // Send mail if (! empty($conf->global->DEPLACEMENT_TO_CLEAN)) { + // Send mail + // TO $destinataire = new User($db); $destinataire->fetch($object->fk_user_validator); $emailTo = $destinataire->email; - // FROM - $expediteur = new User($db); - $expediteur->fetch($object->fk_user_author); - $emailFrom = $expediteur->email; + if ($emailTo) + { + // FROM + $expediteur = new User($db); + $expediteur->fetch($object->fk_user_author); + $emailFrom = $expediteur->email; - // SUBJECT - $subject = "' ERP - Note de frais à re-approuver"; + // SUBJECT + $subject = "' ERP - Note de frais à re-approuver"; - // CONTENT - $dateRefusEx = explode(" ",$object->date_refuse); + // CONTENT + $dateRefusEx = explode(" ",$object->date_refuse); - $message = "Bonjour {$destinataire->firstname},\n\n"; - $message.= "Le {$dateRefusEx[0]} à {$dateRefusEx[1]} vous avez refusé d'approuver la note de frais \"{$object->ref}\". Vous aviez émis le motif suivant : {$object->detail_refuse}\n\n"; - $message.= "L'auteur vient de modifier la note de frais, veuillez trouver la nouvelle version en pièce jointe.\n"; - $message.= "- Déclarant : {$expediteur->firstname} {$expediteur->lastname}\n"; - $message.= "- Période : du {$object->date_debut} au {$object->date_fin}\n"; - $message.= "- Lien : {$dolibarr_main_url_root}/expensereport/card.php?id={$object->id}\n\n"; - $message.= "Bien cordialement,\n' SI"; + $message = "Bonjour {$destinataire->firstname},\n\n"; + $message.= "Le {$dateRefusEx[0]} à {$dateRefusEx[1]} vous avez refusé d'approuver la note de frais \"{$object->ref}\". Vous aviez émis le motif suivant : {$object->detail_refuse}\n\n"; + $message.= "L'auteur vient de modifier la note de frais, veuillez trouver la nouvelle version en pièce jointe.\n"; + $message.= "- Déclarant : {$expediteur->firstname} {$expediteur->lastname}\n"; + $message.= "- Période : du {$object->date_debut} au {$object->date_fin}\n"; + $message.= "- Lien : {$dolibarr_main_url_root}/expensereport/card.php?id={$object->id}\n\n"; + $message.= "Bien cordialement,\n' SI"; - // Génération du pdf avant attachement - $object->setDocModel($user,""); - $resultPDF = expensereport_pdf_create($db,$object,'',"",$langs); + // Génération du pdf avant attachement + $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_number).".pdf"); - array_push($mimetype,"application/pdf"); + 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_number).".pdf"); + array_push($mimetype,"application/pdf"); - // PREPARE SEND - $mailfile = new CMailFile($subject,$emailTo,$emailFrom,$message,$filedir,$mimetype,$filename); + // PREPARE SEND + $mailfile = new CMailFile($subject,$emailTo,$emailFrom,$message,$filedir,$mimetype,$filename); - if(!$mailfile->error): - - // SEND - $result=$mailfile->sendfile(); - if ($result): - Header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); - exit; - endif; - - else: - - $mesg="Impossible d'envoyer l'email."; - - endif; - // END - Send mail - else: - dol_print_error($db,$resultPDF); - exit; - endif; + if (! $mailfile->error) + { + // SEND + $result=$mailfile->sendfile(); + if ($result) + { + Header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); + exit; + } + else + { + $mesg=$mailfile->error; + } + // END - Send mail + } + else + { + dol_print_error($db,$resultPDF); + exit; + } + } + } } } else @@ -1168,10 +1184,10 @@ if ($action == 'create') } else { - if($id > 0) + if($id > 0 || $ref) { $object = new ExpenseReport($db); - $result = $object->fetch($id); + $result = $object->fetch($id, $ref); if ($result > 0) { @@ -1218,7 +1234,7 @@ else // Ref print ' '.$langs->trans("Ref").' | ';
- print $form->showrefnav($object, 'id', $linkback, 1, 'rowid', 'ref', '');
+ print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref', '');
print ' | '.$langs->trans("Ref").' | ';
- print $form->showrefnav($object, 'id', $linkback, 1, 'ref', 'ref', '');
+ print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref', '');
print ' | |