From 245edb8596e727331d4e00049e1ea95e572a7639 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 16 Mar 2012 00:34:41 +0100 Subject: [PATCH] Fix: Maxi debug on sending document by email. Works now with odt too. --- htdocs/admin/mails.php | 4 +- htdocs/comm/propal.php | 103 ++++++++++++++-------- htdocs/commande/fiche.php | 57 ++++++++---- htdocs/compta/facture.php | 29 +++--- htdocs/core/class/html.formmail.class.php | 2 +- htdocs/core/lib/files.lib.php | 16 +++- htdocs/expedition/fiche.php | 64 +++++++++----- htdocs/fichinter/fiche.php | 55 ++++++++---- htdocs/fourn/commande/fiche.php | 51 +++++++---- htdocs/fourn/facture/fiche.php | 44 +++++++-- 10 files changed, 289 insertions(+), 136 deletions(-) diff --git a/htdocs/admin/mails.php b/htdocs/admin/mails.php index a36e6cc0215..ad47a7e4dc8 100644 --- a/htdocs/admin/mails.php +++ b/htdocs/admin/mails.php @@ -695,7 +695,7 @@ else $formmail->param["returnurl"]=$_SERVER["PHP_SELF"]; // Init list of files - if (! empty($_REQUEST["mode"]) && $_REQUEST["mode"]=='init') + if (GETPOST("mode")=='init') { $formmail->clear_attached_files(); } @@ -741,7 +741,7 @@ else $formmail->param["returnurl"]=$_SERVER["PHP_SELF"]; // Init list of files - if (! empty($_REQUEST["mode"]) && $_REQUEST["mode"]=='init') + if (GETPOST("mode")=='init') { $formmail->clear_attached_files(); } diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index 5289521295b..f7c44c9e1fa 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -498,11 +498,11 @@ if ($action == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile'] && ! $_P if ($result > 0) { - $objectref = dol_sanitizeFileName($object->ref); - $file = $conf->propale->dir_output . '/' . $objectref . '/' . $objectref . '.pdf'; +// $objectref = dol_sanitizeFileName($object->ref); +// $file = $conf->propale->dir_output . '/' . $objectref . '/' . $objectref . '.pdf'; - if (is_readable($file)) - { +// if (is_readable($file)) +// { if ($_POST['sendto']) { // Le destinataire a ete fourni via le champ libre @@ -624,13 +624,13 @@ if ($action == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile'] && ! $_P $mesg='
'.$langs->trans('ErrorMailRecipientIsEmpty').' !
'; dol_syslog('Recipient email is empty'); } - } +/* } else { $langs->load("errors"); $mesg='
'.$langs->trans('ErrorCantReadFile',$file).'
'; dol_syslog('Failed to read file: '.$file); - } + }*/ } else { @@ -1483,26 +1483,30 @@ if ($id > 0 || ! empty($ref)) // Statut print ''.$langs->trans('Status').''.$object->getLibStatut(4).''; - - print ''.$langs->trans('Notes').''; - - // Public note - print ''; - print $form->editfieldkey("NotePublic",'note_public',$object->note_public,$object,$user->rights->propale->creer,'textarea'); - print ''; - print $form->editfieldval("NotePublic",'note_public',$object->note_public,$object,$user->rights->propale->creer,'textarea'); - print ""; - - // Private note - if (! $user->societe_id) - { - print ''; - print $form->editfieldkey("NotePrivate",'note',$object->note_private,$object,$user->rights->propale->creer,'textarea'); - print ''; - print $form->editfieldval("NotePrivate",'note',$object->note_private,$object,$user->rights->propale->creer,'textarea'); - print ""; - } - + + + if (! empty($conf->global->MAIN_DISABLE_NOTES_TAB)) + { + print ''.$langs->trans('Notes').''; + + // Public note + print ''; + print $form->editfieldkey("NotePublic",'note_public',$object->note_public,$object,$user->rights->propale->creer,'textarea'); + print ''; + print $form->editfieldval("NotePublic",'note_public',$object->note_public,$object,$user->rights->propale->creer,'textarea'); + print ""; + + // Private note + if (! $user->societe_id) + { + print ''; + print $form->editfieldkey("NotePrivate",'note',$object->note_private,$object,$user->rights->propale->creer,'textarea'); + print ''; + print $form->editfieldval("NotePrivate",'note',$object->note_private,$object,$user->rights->propale->creer,'textarea'); + print ""; + } + } + print '
'; /* @@ -1617,16 +1621,11 @@ if ($id > 0 || ! empty($ref)) // Send if ($object->statut == 1 || $object->statut == 2) { - $propref = dol_sanitizeFileName($object->ref); - $file = $conf->propale->dir_output . '/'.$propref.'/'.$propref.'.pdf'; - if (file_exists($file)) - { - if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->propale->propal_advance->send) - { - print ''.$langs->trans('SendByMail').''; - } - else print ''.$langs->trans('SendByMail').''; - } + if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->propale->propal_advance->send) + { + print ''.$langs->trans('SendByMail').''; + } + else print ''.$langs->trans('SendByMail').''; } // Create an order @@ -1722,7 +1721,33 @@ if ($id > 0 || ! empty($ref)) if ($action == 'presend') { $ref = dol_sanitizeFileName($object->ref); - $file = $conf->propale->dir_output . '/' . $ref . '/' . $ref . '.pdf'; + include_once(DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'); + $fileparams = dol_most_recent_file($conf->propale->dir_output . '/' . $ref); + $file=$fileparams['fullname']; + + // Build document if it not exists + if (! $file || ! is_readable($file)) + { + // Define output language + $outputlangs = $langs; + $newlang=''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id']; + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; + if (! empty($newlang)) + { + $outputlangs = new Translate("",$conf); + $outputlangs->setDefaultLang($newlang); + } + + $result=propale_pdf_create($db, $object, GETPOST('model')?GETPOST('model'):$object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref'), $hookmanager); + if ($result <= 0) + { + dol_print_error($db,$result); + exit; + } + $fileparams = dol_most_recent_file($conf->propale->dir_output . '/' . $ref); + $file=$fileparams['fullname']; + } print '
'; print_titre($langs->trans('SendPropalByMail')); @@ -1756,10 +1781,10 @@ if ($id > 0 || ! empty($ref)) $formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id; // Init list of files - if (! empty($_REQUEST["mode"]) && $_REQUEST["mode"]=='init') + if (GETPOST("mode")=='init') { $formmail->clear_attached_files(); - $formmail->add_attached_files($file,dol_sanitizeFilename($object->ref).'.pdf','application/pdf'); + $formmail->add_attached_files($file,basename($file),dol_mimetype($file)); } $formmail->show_form(); diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index 6b04d51f2de..8217740f008 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -1034,11 +1034,11 @@ if ($action == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile'] && ! $_P if ($result > 0) { - $ref = dol_sanitizeFileName($object->ref); - $file = $conf->commande->dir_output . '/' . $ref . '/' . $ref . '.pdf'; +// $ref = dol_sanitizeFileName($object->ref); +// $file = $conf->commande->dir_output . '/' . $ref . '/' . $ref . '.pdf'; - if (is_readable($file)) - { +// if (is_readable($file)) +// { if ($_POST['sendto']) { // Le destinataire a ete fourni via le champ libre @@ -1153,14 +1153,14 @@ if ($action == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile'] && ! $_P $mesg.=''; } } - } +/* } else { $langs->load("other"); $mesg='
'.$langs->trans('ErrorMailRecipientIsEmpty').' !
'; $action='presend'; dol_syslog('Recipient email is empty'); - } + }*/ } else { @@ -1243,7 +1243,7 @@ if ($action == 'create' && $user->rights->commande->creer) $remise_percent = (!empty($objectsrc->remise_percent)?$objectsrc->remise_percent:(!empty($soc->remise_percent)?$soc->remise_percent:0)); $remise_absolue = (!empty($objectsrc->remise_absolue)?$objectsrc->remise_absolue:(!empty($soc->remise_absolue)?$soc->remise_absolue:0)); $dateinvoice = empty($conf->global->MAIN_AUTOFILL_DATE)?-1:0; - + $note_private = (! empty($objectsrc->note) ? $objectsrc->note : (! empty($objectsrc->note_private) ? $objectsrc->note_private : '')); $note_public = (! empty($objectsrc->note_public) ? $objectsrc->note_public : ''); @@ -2008,16 +2008,11 @@ else // Send if ($object->statut > 0) { - $comref = dol_sanitizeFileName($object->ref); - $file = $conf->commande->dir_output . '/'.$comref.'/'.$comref.'.pdf'; - if (file_exists($file)) + if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->commande->order_advance->send)) { - if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->commande->order_advance->send)) - { - print ''.$langs->trans('SendByMail').''; - } - else print ''.$langs->trans('SendByMail').''; + print ''.$langs->trans('SendByMail').''; } + else print ''.$langs->trans('SendByMail').''; } // Ship @@ -2147,7 +2142,33 @@ else if ($action == 'presend') { $ref = dol_sanitizeFileName($object->ref); - $file = $conf->commande->dir_output . '/' . $ref . '/' . $ref . '.pdf'; + include_once(DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'); + $fileparams = dol_most_recent_file($conf->commande->dir_output . '/' . $ref); + $file=$fileparams['fullname']; + + // Build document if it not exists + if (! $file || ! is_readable($file)) + { + // Define output language + $outputlangs = $langs; + $newlang=''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id']; + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; + if (! empty($newlang)) + { + $outputlangs = new Translate("",$conf); + $outputlangs->setDefaultLang($newlang); + } + + $result=commande_pdf_create($db, $object, GETPOST('model')?GETPOST('model'):$object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref'), $hookmanager); + if ($result <= 0) + { + dol_print_error($db,$result); + exit; + } + $fileparams = dol_most_recent_file($conf->commande->dir_output . '/' . $ref); + $file=$fileparams['fullname']; + } print '
'; print_titre($langs->trans('SendOrderByMail')); @@ -2180,10 +2201,10 @@ else $formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id; // Init list of files - if (! empty($_REQUEST["mode"]) && $_REQUEST["mode"]=='init') + if (GETPOST("mode")=='init') { $formmail->clear_attached_files(); - $formmail->add_attached_files($file,dol_sanitizeFilename($ref.'.pdf'),'application/pdf'); + $formmail->add_attached_files($file,basename($file),dol_mimetype($file)); } // Show form diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 44b0e140df3..06307be1876 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -1307,11 +1307,11 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO if ($result > 0) { - $ref = dol_sanitizeFileName($object->ref); - $file = $conf->facture->dir_output . '/' . $ref . '/' . $ref . '.pdf'; +// $ref = dol_sanitizeFileName($object->ref); +// $file = $conf->facture->dir_output . '/' . $ref . '/' . $ref . '.pdf'; - if (is_readable($file)) - { +// if (is_readable($file)) +// { if ($_POST['sendto']) { // Le destinataire a ete fourni via le champ libre @@ -1440,13 +1440,13 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO $mesg.=''; } } - } +/* } else { $langs->load("other"); $mesg='
'.$langs->trans('ErrorMailRecipientIsEmpty').'
'; dol_syslog('Recipient email is empty'); - } + }*/ } else { @@ -3048,10 +3048,12 @@ else } $ref = dol_sanitizeFileName($object->ref); - $file = $conf->facture->dir_output . '/' . $ref . '/' . $ref . '.pdf'; + include_once(DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'); + $fileparams = dol_most_recent_file($conf->facture->dir_output . '/' . $ref); + $file=$fileparams['fullname']; - // Construit PDF si non existant - if (! is_readable($file)) + // Build document if it not exists + if (! $file || ! is_readable($file)) { // Define output language $outputlangs = $langs; @@ -3063,12 +3065,15 @@ else $outputlangs = new Translate("",$conf); $outputlangs->setDefaultLang($newlang); } - $result=facture_pdf_create($db, $object, $_REQUEST['model'], $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref'), $hookmanager); + + $result=facture_pdf_create($db, $object, GETPOST('model')?GETPOST('model'):$object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref'), $hookmanager); if ($result <= 0) { dol_print_error($db,$result); exit; } + $fileparams = dol_most_recent_file($conf->facture->dir_output . '/' . $ref); + $file=$fileparams['fullname']; } print '
'; @@ -3102,10 +3107,10 @@ else $formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id; // Init list of files - if (! empty($_REQUEST["mode"]) && $_REQUEST["mode"]=='init') + if (GETPOST("mode")=='init') { $formmail->clear_attached_files(); - $formmail->add_attached_files($file,dol_sanitizeFilename($ref.'.pdf'),'application/pdf'); + $formmail->add_attached_files($file,basename($file),dol_mimetype($file)); } $formmail->show_form(); diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php index 7d95b981b1a..a60c2ef21aa 100644 --- a/htdocs/core/class/html.formmail.class.php +++ b/htdocs/core/class/html.formmail.class.php @@ -104,7 +104,7 @@ class FormMail /** * Clear list of attached files in send mail form (stored in session) - * + * * @return void */ function clear_attached_files() diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index 88e71bf78e9..7cd28292c32 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -30,7 +30,7 @@ * @param string $types Can be "directories", "files", or "all" * @param int $recursive Determines whether subdirectories are searched * @param string $filter Regex for include filter - * @param string $excludefilter Array of Regex for exclude filter (example: array('\.meta$','^\.') + * @param string $excludefilter Array of Regex for exclude filter (example: array('\.meta$','^\.')) * @param string $sortcriteria Sort criteria ("","fullname","name","date","size") * @param string $sortorder Sort order (SORT_ASC, SORT_DESC) * @param int $mode 0=Return array minimum keys loaded (faster), 1=Force all keys like date and size to be loaded (slower), 2=Force load of date only, 3=Force load of size only @@ -1047,4 +1047,18 @@ function dol_compress_file($inputfile, $outputfile, $mode="gz") } } + +/** + * Return most recent file + * + * @param string $dir Directory to scan + * @param string $regexfilter Regexfilter + * @param string $excludefilter Array of Regex for exclude filter (example: array('\.meta$','^\.')) + * @return strnig Full path to most recent file + */ +function dol_most_recent_file($dir,$regexfilter='',$excludefilter=array('\.meta$','^\.')) +{ + $tmparray=dol_dir_list($dir,'files',0,$regexfilter,$excludefilter,'date',SORT_DESC); + return $tmparray[0]; +} ?> diff --git a/htdocs/expedition/fiche.php b/htdocs/expedition/fiche.php index 6f6069c8767..d449c127102 100644 --- a/htdocs/expedition/fiche.php +++ b/htdocs/expedition/fiche.php @@ -4,17 +4,17 @@ * Copyright (C) 2005 Simon TOSSER * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2011-2012 Juanjo Menent - * + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ @@ -359,11 +359,11 @@ if ($action == 'send' && ! GETPOST('addfile','alpha') && ! GETPOST('removedfile' if ($result > 0) { - $ref = dol_sanitizeFileName($object->ref); - $file = $conf->expedition->dir_output . '/sending/' . $ref . '/' . $ref . '.pdf'; +// $ref = dol_sanitizeFileName($object->ref); +// $file = $conf->expedition->dir_output . '/sending/' . $ref . '/' . $ref . '.pdf'; - if (is_readable($file)) - { +// if (is_readable($file)) +// { if (GETPOST('sendto','alpha')) { // Le destinataire a ete fourni via le champ libre @@ -488,13 +488,13 @@ if ($action == 'send' && ! GETPOST('addfile','alpha') && ! GETPOST('removedfile' $action='presend'; dol_syslog('Recipient email is empty'); } - } +/* } else { $langs->load("errors"); $mesg='
'.$langs->trans('ErrorCantReadFile',$file).'
'; dol_syslog('Failed to read file: '.$file); - } + }*/ } else { @@ -1280,16 +1280,11 @@ else // Send if ($object->statut > 0) { - $ref = dol_sanitizeFileName($object->ref); - $file = $conf->expedition->dir_output . '/sending/'.$ref.'/'.$ref.'.pdf'; - if (file_exists($file)) + if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->expedition->shipping_advance->send) { - if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->expedition->shipping_advance->send) - { - print ''.$langs->trans('SendByMail').''; - } - else print ''.$langs->trans('SendByMail').''; + print ''.$langs->trans('SendByMail').''; } + else print ''.$langs->trans('SendByMail').''; } // Create bill and Classify billed @@ -1362,12 +1357,37 @@ else /* * Action presend - * - */ + */ if ($action == 'presend') { $ref = dol_sanitizeFileName($object->ref); - $file = $conf->expedition->dir_output . '/sending/' . $ref . '/' . $ref . '.pdf'; + include_once(DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'); + $fileparams = dol_most_recent_file($conf->expedition->dir_output . '/sending/' . $ref); + $file=$fileparams['fullname']; + + // Build document if it not exists + if (! $file || ! is_readable($file)) + { + // Define output language + $outputlangs = $langs; + $newlang=''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id']; + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; + if (! empty($newlang)) + { + $outputlangs = new Translate("",$conf); + $outputlangs->setDefaultLang($newlang); + } + + $result=expedition_pdf_create($db, $object, GETPOST('model')?GETPOST('model'):$object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref'), $hookmanager); + if ($result <= 0) + { + dol_print_error($db,$result); + exit; + } + $fileparams = dol_most_recent_file($conf->expedition->dir_output . '/sending/' . $ref); + $file=$fileparams['fullname']; + } print '
'; print_titre($langs->trans('SendShippingByEMail')); @@ -1400,10 +1420,10 @@ else $formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id; // Init list of files - if (GETPOST('mode','alpha')=='init') + if (GETPOST("mode")=='init') { $formmail->clear_attached_files(); - $formmail->add_attached_files($file,dol_sanitizeFilename($ref.'.pdf'),'application/pdf'); + $formmail->add_attached_files($file,basename($file),dol_mimetype($file)); } // Show form diff --git a/htdocs/fichinter/fiche.php b/htdocs/fichinter/fiche.php index e618463fef9..a6882b8a785 100644 --- a/htdocs/fichinter/fiche.php +++ b/htdocs/fichinter/fiche.php @@ -482,11 +482,11 @@ if ($action == 'send' && ! GETPOST('cancel','alpha') && (empty($conf->global->MA if ($object->fetch($id) > 0) { - $objectref = dol_sanitizeFileName($object->ref); - $file = $conf->ficheinter->dir_output . '/' . $objectref . '/' . $objectref . '.pdf'; +// $objectref = dol_sanitizeFileName($object->ref); +// $file = $conf->ficheinter->dir_output . '/' . $objectref . '/' . $objectref . '.pdf'; - if (is_readable($file)) - { +// if (is_readable($file)) +// { $object->fetch_thirdparty(); if (GETPOST('sendto','alpha')) @@ -610,13 +610,13 @@ if ($action == 'send' && ! GETPOST('cancel','alpha') && (empty($conf->global->MA $mesg='
'.$langs->trans('ErrorMailRecipientIsEmpty').' !
'; dol_syslog('Recipient email is empty'); } - } +/* } else { $langs->load("errors"); $mesg='
'.$langs->trans('ErrorCantReadFile',$file).'
'; dol_syslog('Failed to read file: '.$file); - } + }*/ } else { @@ -1099,16 +1099,11 @@ else if ($id > 0 || ! empty($ref)) // Send if ($object->statut > 0) { - $objectref = dol_sanitizeFileName($object->ref); - $file = $conf->ficheinter->dir_output . '/'.$objectref.'/'.$objectref.'.pdf'; - if (file_exists($file)) + if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->ficheinter->ficheinter_advance->send) { - if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->ficheinter->ficheinter_advance->send) - { - print ''.$langs->trans('SendByMail').''; - } - else print ''.$langs->trans('SendByMail').''; + print ''.$langs->trans('SendByMail').''; } + else print ''.$langs->trans('SendByMail').''; } // Invoicing @@ -1184,7 +1179,33 @@ else if ($id > 0 || ! empty($ref)) if ($action == 'presend') { $ref = dol_sanitizeFileName($object->ref); - $file = $conf->ficheinter->dir_output . '/' . $ref . '/' . $ref . '.pdf'; + include_once(DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'); + $fileparams = dol_most_recent_file($conf->ficheinter->dir_output . '/' . $ref); + $file=$fileparams['fullname']; + + // Build document if it not exists + if (! $file || ! is_readable($file)) + { + // Define output language + $outputlangs = $langs; + $newlang=''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id']; + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; + if (! empty($newlang)) + { + $outputlangs = new Translate("",$conf); + $outputlangs->setDefaultLang($newlang); + } + + $result=fichinter_create($db, $object, GETPOST('model')?GETPOST('model'):$object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref'), $hookmanager); + if ($result <= 0) + { + dol_print_error($db,$result); + exit; + } + $fileparams = dol_most_recent_file($conf->ficheinter->dir_output . '/' . $ref); + $file=$fileparams['fullname']; + } print '
'; print_titre($langs->trans('SendInterventionByMail')); @@ -1218,10 +1239,10 @@ else if ($id > 0 || ! empty($ref)) $formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id; // Init list of files - if (GETPOST('mode','alpha')=='init') + if (GETPOST("mode")=='init') { $formmail->clear_attached_files(); - $formmail->add_attached_files($file,$object->ref.'.pdf','application/pdf'); + $formmail->add_attached_files($file,basename($file),dol_mimetype($file)); } $formmail->show_form(); diff --git a/htdocs/fourn/commande/fiche.php b/htdocs/fourn/commande/fiche.php index 677c477bb02..0fd28a371ef 100644 --- a/htdocs/fourn/commande/fiche.php +++ b/htdocs/fourn/commande/fiche.php @@ -658,11 +658,11 @@ if ($action == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile'] && ! $_P if ($result > 0) { - $ref = dol_sanitizeFileName($object->ref); - $file = $conf->fournisseur->commande->dir_output . '/' . $ref . '/' . $ref . '.pdf'; +// $ref = dol_sanitizeFileName($object->ref); +// $file = $conf->fournisseur->commande->dir_output . '/' . $ref . '/' . $ref . '.pdf'; - if (is_readable($file)) - { +// if (is_readable($file)) +// { if ($_POST['sendto']) { // Le destinataire a ete fourni via le champ libre @@ -777,14 +777,14 @@ if ($action == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile'] && ! $_P $mesg.=''; } } - } +/* } else { $langs->load("other"); $mesg='
'.$langs->trans('ErrorMailRecipientIsEmpty').' !
'; $action='presend'; dol_syslog('Recipient email is empty'); - } + }*/ } else { @@ -1393,12 +1393,7 @@ if ($id > 0 || ! empty($ref)) { if ($user->rights->fournisseur->commande->commander) { - $comref = dol_sanitizeFileName($object->ref); - $file = $conf->fournisseur->commande->dir_output . '/'.$comref.'/'.$comref.'.pdf'; - if (file_exists($file)) - { - print ''.$langs->trans('SendByMail').''; - } + print ''.$langs->trans('SendByMail').''; } } @@ -1550,7 +1545,33 @@ if ($id > 0 || ! empty($ref)) if ($action == 'presend') { $ref = dol_sanitizeFileName($object->ref); - $file = $conf->fournisseur->commande->dir_output . '/' . $ref . '/' . $ref . '.pdf'; + include_once(DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'); + $fileparams = dol_most_recent_file($conf->fournisseur->commande->dir_output . '/' . $ref); + $file=$fileparams['fullname']; + + // Build document if it not exists + if (! $file || ! is_readable($file)) + { + // Define output language + $outputlangs = $langs; + $newlang=''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id']; + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; + if (! empty($newlang)) + { + $outputlangs = new Translate("",$conf); + $outputlangs->setDefaultLang($newlang); + } + + $result=supplier_order_pdf_create($db, $object, GETPOST('model')?GETPOST('model'):$object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref'), $hookmanager); + if ($result <= 0) + { + dol_print_error($db,$result); + exit; + } + $fileparams = dol_most_recent_file($conf->fournisseur->commande->dir_output . '/' . $ref); + $file=$fileparams['fullname']; + } print '
'; print_titre($langs->trans('SendOrderByMail')); @@ -1583,10 +1604,10 @@ if ($id > 0 || ! empty($ref)) $formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id; // Init list of files - if (! empty($_REQUEST["mode"]) && $_REQUEST["mode"]=='init') + if (GETPOST("mode")=='init') { $formmail->clear_attached_files(); - $formmail->add_attached_files($file,dol_sanitizeFilename($ref.'.pdf'),'application/pdf'); + $formmail->add_attached_files($file,basename($file),dol_mimetype($file)); } // Show form diff --git a/htdocs/fourn/facture/fiche.php b/htdocs/fourn/facture/fiche.php index d0acf26d822..e84eedb9ef5 100644 --- a/htdocs/fourn/facture/fiche.php +++ b/htdocs/fourn/facture/fiche.php @@ -629,11 +629,11 @@ if ($action == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile'] && ! $_P $result=$object->fetch_thirdparty(); if ($result > 0) { - $ref = dol_sanitizeFileName($object->ref); - $file = $conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id,2).$ref.'/'.$ref.'.pdf'; +// $ref = dol_sanitizeFileName($object->ref); +// $file = $conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id,2).$ref.'/'.$ref.'.pdf'; - if (is_readable($file)) - { +// if (is_readable($file)) +// { if ($_POST['sendto']) { // Le destinataire a ete fourni via le champ libre @@ -758,13 +758,13 @@ if ($action == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile'] && ! $_P $mesg='
'.$langs->trans('ErrorMailRecipientIsEmpty').'
'; dol_syslog('Recipient email is empty'); } - } +/* } else { $langs->load("errors"); $mesg='
'.$langs->trans('ErrorCantReadFile',$file).'
'; dol_syslog('Failed to read file: '.$file); - } + }*/ } else { @@ -1792,7 +1792,33 @@ else if ($action == 'presend') { $ref = dol_sanitizeFileName($object->ref); - $file = $conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id,2).$ref.'/'.$ref.'.pdf'; + include_once(DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'); + $fileparams = dol_most_recent_file($conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id,2).$ref); + $file=$fileparams['fullname']; + + // Build document if it not exists + if (! $file || ! is_readable($file)) + { + // Define output language + $outputlangs = $langs; + $newlang=''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id']; + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; + if (! empty($newlang)) + { + $outputlangs = new Translate("",$conf); + $outputlangs->setDefaultLang($newlang); + } + + $result=supplier_invoice_pdf_create($db, $object, GETPOST('model')?GETPOST('model'):$object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref'), $hookmanager); + if ($result <= 0) + { + dol_print_error($db,$result); + exit; + } + $fileparams = dol_most_recent_file($conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id,2).$ref); + $file=$fileparams['fullname']; + } print '
'; print_titre($langs->trans('SendBillByMail')); @@ -1825,10 +1851,10 @@ else $formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id; // Init list of files - if (! empty($_REQUEST["mode"]) && $_REQUEST["mode"]=='init') + if (GETPOST("mode")=='init') { $formmail->clear_attached_files(); - $formmail->add_attached_files($file,dol_sanitizeFilename($ref.'.pdf'),'application/pdf'); + $formmail->add_attached_files($file,basename($file),dol_mimetype($file)); } // Show form