FIX Solve problem of sending joinded files of another email when several
tabs are opened on form to send emails.
This commit is contained in:
parent
6033b09344
commit
2767df2e01
@ -180,8 +180,8 @@ class modMyModule extends DolibarrModules
|
||||
|
||||
// Cronjobs
|
||||
$this->cronjobs = array(); // List of cron jobs entries to add
|
||||
// Example: $this->cronjobs=array(0=>array('label'=>'My label', 'jobtype'=>'method', 'class'=>'/dir/class/file.class.php', 'objectname'=>'MyClass', 'method'=>'myMethod', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>2, 'unitfrequency'=>3600),
|
||||
// 1=>array('label'=>'My label', 'jobtype'=>'command', 'command'=>'', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>1, 'unitfrequency'=>3600*24)
|
||||
// Example: $this->cronjobs=array(0=>array('label'=>'My label', 'jobtype'=>'method', 'class'=>'/dir/class/file.class.php', 'objectname'=>'MyClass', 'method'=>'myMethod', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>2, 'unitfrequency'=>3600, 'test'=>true),
|
||||
// 1=>array('label'=>'My label', 'jobtype'=>'command', 'command'=>'', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>1, 'unitfrequency'=>3600*24, 'test'=>true)
|
||||
// );
|
||||
|
||||
// Permissions
|
||||
|
||||
@ -259,7 +259,8 @@ if (empty($reshook))
|
||||
}
|
||||
|
||||
// Fabrication du mail
|
||||
$mail = new CMailFile($newsubject, $sendto, $from, $newmessage, $arr_file, $arr_mime, $arr_name, '', '', 0, $msgishtml, $errorsto, $arr_css);
|
||||
$trackid=''; // TODO Define a trackid for mass emailing too. We can use source type for this.
|
||||
$mail = new CMailFile($newsubject, $sendto, $from, $newmessage, $arr_file, $arr_mime, $arr_name, '', '', 0, $msgishtml, $errorsto, $arr_css, $trackid);
|
||||
|
||||
if ($mail->error)
|
||||
{
|
||||
@ -1115,7 +1116,8 @@ else
|
||||
// Subject
|
||||
print '<tr><td width="25%" class="fieldrequired">'.$langs->trans("MailTopic").'</td><td colspan="3"><input class="flat" type="text" size=60 name="sujet" value="'.$object->sujet.'"></td></tr>';
|
||||
|
||||
dol_init_file_process($upload_dir);
|
||||
$trackid=''; // TODO To avoid conflicts with 2 mass emailing, we shoul set a trackid here, even if we use another one into email header.
|
||||
dol_init_file_process($upload_dir, $trackid);
|
||||
|
||||
// Joined files
|
||||
$addfileaction='addfile';
|
||||
|
||||
@ -22,8 +22,6 @@
|
||||
*/
|
||||
|
||||
|
||||
// TODO Include this include file into all element pages allowing email sending
|
||||
|
||||
// $id must be defined
|
||||
// $actiontypecode must be defined
|
||||
// $paramname must be defined
|
||||
@ -34,13 +32,15 @@
|
||||
*/
|
||||
if (GETPOST('addfile'))
|
||||
{
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||
$trackid = GETPOST('trackid','aZ09');
|
||||
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||
|
||||
// Set tmp user directory
|
||||
$vardir=$conf->user->dir_output."/".$user->id;
|
||||
$upload_dir_tmp = $vardir.'/temp';
|
||||
$upload_dir_tmp = $vardir.'/temp'; // TODO Add $keytoavoidconflict in upload_dir path
|
||||
|
||||
dol_add_file_process($upload_dir_tmp,0,0);
|
||||
dol_add_file_process($upload_dir_tmp, 0, 0, 'addedfile', '', null, $trackid);
|
||||
$action='presend';
|
||||
}
|
||||
|
||||
@ -49,33 +49,39 @@ if (GETPOST('addfile'))
|
||||
*/
|
||||
if (! empty($_POST['removedfile']) && empty($_POST['removAll']))
|
||||
{
|
||||
$trackid = GETPOST('trackid','aZ09');
|
||||
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||
|
||||
// Set tmp user directory
|
||||
$vardir=$conf->user->dir_output."/".$user->id;
|
||||
$upload_dir_tmp = $vardir.'/temp';
|
||||
$upload_dir_tmp = $vardir.'/temp'; // TODO Add $keytoavoidconflict in upload_dir path
|
||||
|
||||
// TODO Delete only files that was uploaded from email form
|
||||
dol_remove_file_process(GETPOST('removedfile','alpha'),0);
|
||||
// TODO Delete only files that was uploaded from email form. This can be addressed by adding the trackid into the temp path then changing donotdeletefile to 2 instead of 1 to say "delete only if into temp dir"
|
||||
// GETPOST('removedfile','alpha') is position of file into $_SESSION["listofpaths"...] array.
|
||||
dol_remove_file_process(GETPOST('removedfile','alpha'), 0, 1, $trackid); // We do not delete because if file is the official PDF of doc, we don't want to remove it physically
|
||||
$action='presend';
|
||||
}
|
||||
|
||||
/*
|
||||
* Remove all files in email form
|
||||
*/
|
||||
|
||||
if(! empty($_POST['removAll']))
|
||||
if (GETPOST('removAll'))
|
||||
{
|
||||
$listofpaths=array();
|
||||
$trackid = GETPOST('trackid','aZ09');
|
||||
|
||||
$listofpaths=array();
|
||||
$listofnames=array();
|
||||
$listofmimes=array();
|
||||
if (! empty($_SESSION["listofpaths"])) $listofpaths=explode(';',$_SESSION["listofpaths"]);
|
||||
if (! empty($_SESSION["listofnames"])) $listofnames=explode(';',$_SESSION["listofnames"]);
|
||||
if (! empty($_SESSION["listofmimes"])) $listofmimes=explode(';',$_SESSION["listofmimes"]);
|
||||
$keytoavoidconflict = empty($trackid)?'':'-'.$trackid;
|
||||
if (! empty($_SESSION["listofpaths".$keytoavoidconflict])) $listofpaths=explode(';',$_SESSION["listofpaths".$keytoavoidconflict]);
|
||||
if (! empty($_SESSION["listofnames".$keytoavoidconflict])) $listofnames=explode(';',$_SESSION["listofnames".$keytoavoidconflict]);
|
||||
if (! empty($_SESSION["listofmimes".$keytoavoidconflict])) $listofmimes=explode(';',$_SESSION["listofmimes".$keytoavoidconflict]);
|
||||
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
|
||||
$formmail = new FormMail($db);
|
||||
|
||||
$formmail->trackid = $trackid;
|
||||
|
||||
foreach($listofpaths as $key => $value)
|
||||
{
|
||||
$pathtodelete = $value;
|
||||
@ -94,7 +100,9 @@ if(! empty($_POST['removAll']))
|
||||
*/
|
||||
if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_POST['removAll'] && ! $_POST['removedfile'] && ! $_POST['cancel'] && !$_POST['modelselected'])
|
||||
{
|
||||
if($conf->dolimail->enabled) $langs->load("dolimail@dolimail");
|
||||
$trackid = GETPOST('trackid','aZ09');
|
||||
|
||||
if (! empty($conf->dolimail->enabled)) $langs->load("dolimail@dolimail");
|
||||
$langs->load('mails');
|
||||
|
||||
$subject='';$actionmsg='';$actionmsg2='';
|
||||
@ -195,7 +203,10 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
|
||||
if ($mode == 'emailfromproposal') $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO));
|
||||
if ($mode == 'emailfromorder') $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_ORDER_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_ORDER_TO));
|
||||
if ($mode == 'emailfrominvoice') $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO));
|
||||
|
||||
if ($mode == 'emailfromsupplierproposal') $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO));
|
||||
if ($mode == 'emailfromsupplierorder') $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO));
|
||||
if ($mode == 'emailfromsupplierinvoice') $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO));
|
||||
|
||||
$deliveryreceipt = $_POST['deliveryreceipt'];
|
||||
|
||||
if ($action == 'send' || $action == 'relance')
|
||||
@ -215,13 +226,13 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
|
||||
// Create form object
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
|
||||
$formmail = new FormMail($db);
|
||||
|
||||
$formmail->trackid = $trackid; // $trackid must be defined
|
||||
|
||||
$attachedfiles=$formmail->get_attached_files();
|
||||
$filepath = $attachedfiles['paths'];
|
||||
$filename = $attachedfiles['names'];
|
||||
$mimetype = $attachedfiles['mimes'];
|
||||
|
||||
$trackid = GETPOST('trackid','aZ09');
|
||||
|
||||
// Feature to push mail sent into Sent folder
|
||||
if (! empty($conf->dolimail->enabled))
|
||||
@ -270,7 +281,8 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
|
||||
$mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,$sendtobcc,$deliveryreceipt,-1,'','',$trackid);
|
||||
if ($mailfile->error)
|
||||
{
|
||||
$mesgs[]='<div class="error">'.$mailfile->error.'</div>';
|
||||
setEventMessage($mailfile->error, 'errors');
|
||||
$action='presend';
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -351,13 +363,6 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
|
||||
$action = 'presend';
|
||||
}
|
||||
}
|
||||
/* }
|
||||
else
|
||||
{
|
||||
$langs->load("other");
|
||||
$mesgs[]='<div class="error">'.$langs->trans('ErrorMailRecipientIsEmpty').'</div>';
|
||||
dol_syslog('Recipient email is empty');
|
||||
}*/
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@ -121,7 +121,7 @@ class FormMail extends Form
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear list of attached files in send mail form (stored in session)
|
||||
* Clear list of attached files in send mail form (also stored in session)
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@ -132,12 +132,13 @@ class FormMail extends Form
|
||||
|
||||
// Set tmp user directory
|
||||
$vardir=$conf->user->dir_output."/".$user->id;
|
||||
$upload_dir = $vardir.'/temp/';
|
||||
$upload_dir = $vardir.'/temp/'; // TODO Add $keytoavoidconflict in upload_dir path
|
||||
if (is_dir($upload_dir)) dol_delete_dir_recursive($upload_dir);
|
||||
|
||||
unset($_SESSION["listofpaths"]);
|
||||
unset($_SESSION["listofnames"]);
|
||||
unset($_SESSION["listofmimes"]);
|
||||
$keytoavoidconflict = empty($this->trackid)?'':'-'.$this->trackid; // this->trackid must be defined
|
||||
unset($_SESSION["listofpaths".$keytoavoidconflict]);
|
||||
unset($_SESSION["listofnames".$keytoavoidconflict]);
|
||||
unset($_SESSION["listofmimes".$keytoavoidconflict]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -153,17 +154,19 @@ class FormMail extends Form
|
||||
$listofpaths=array();
|
||||
$listofnames=array();
|
||||
$listofmimes=array();
|
||||
if (! empty($_SESSION["listofpaths"])) $listofpaths=explode(';',$_SESSION["listofpaths"]);
|
||||
if (! empty($_SESSION["listofnames"])) $listofnames=explode(';',$_SESSION["listofnames"]);
|
||||
if (! empty($_SESSION["listofmimes"])) $listofmimes=explode(';',$_SESSION["listofmimes"]);
|
||||
|
||||
$keytoavoidconflict = empty($this->trackid)?'':'-'.$this->trackid; // this->trackid must be defined
|
||||
if (! empty($_SESSION["listofpaths".$keytoavoidconflict])) $listofpaths=explode(';',$_SESSION["listofpaths".$keytoavoidconflict]);
|
||||
if (! empty($_SESSION["listofnames".$keytoavoidconflict])) $listofnames=explode(';',$_SESSION["listofnames".$keytoavoidconflict]);
|
||||
if (! empty($_SESSION["listofmimes".$keytoavoidconflict])) $listofmimes=explode(';',$_SESSION["listofmimes".$keytoavoidconflict]);
|
||||
if (! in_array($file,$listofnames))
|
||||
{
|
||||
$listofpaths[]=$path;
|
||||
$listofnames[]=$file;
|
||||
$listofmimes[]=$type;
|
||||
$_SESSION["listofpaths"]=join(';',$listofpaths);
|
||||
$_SESSION["listofnames"]=join(';',$listofnames);
|
||||
$_SESSION["listofmimes"]=join(';',$listofmimes);
|
||||
$_SESSION["listofpaths".$keytoavoidconflict]=join(';',$listofpaths);
|
||||
$_SESSION["listofnames".$keytoavoidconflict]=join(';',$listofnames);
|
||||
$_SESSION["listofmimes".$keytoavoidconflict]=join(';',$listofmimes);
|
||||
}
|
||||
}
|
||||
|
||||
@ -178,17 +181,19 @@ class FormMail extends Form
|
||||
$listofpaths=array();
|
||||
$listofnames=array();
|
||||
$listofmimes=array();
|
||||
if (! empty($_SESSION["listofpaths"])) $listofpaths=explode(';',$_SESSION["listofpaths"]);
|
||||
if (! empty($_SESSION["listofnames"])) $listofnames=explode(';',$_SESSION["listofnames"]);
|
||||
if (! empty($_SESSION["listofmimes"])) $listofmimes=explode(';',$_SESSION["listofmimes"]);
|
||||
|
||||
$keytoavoidconflict = empty($this->trackid)?'':'-'.$this->trackid; // this->trackid must be defined
|
||||
if (! empty($_SESSION["listofpaths".$keytoavoidconflict])) $listofpaths=explode(';',$_SESSION["listofpaths".$keytoavoidconflict]);
|
||||
if (! empty($_SESSION["listofnames".$keytoavoidconflict])) $listofnames=explode(';',$_SESSION["listofnames".$keytoavoidconflict]);
|
||||
if (! empty($_SESSION["listofmimes".$keytoavoidconflict])) $listofmimes=explode(';',$_SESSION["listofmimes".$keytoavoidconflict]);
|
||||
if ($keytodelete >= 0)
|
||||
{
|
||||
unset ($listofpaths[$keytodelete]);
|
||||
unset ($listofnames[$keytodelete]);
|
||||
unset ($listofmimes[$keytodelete]);
|
||||
$_SESSION["listofpaths"]=join(';',$listofpaths);
|
||||
$_SESSION["listofnames"]=join(';',$listofnames);
|
||||
$_SESSION["listofmimes"]=join(';',$listofmimes);
|
||||
$_SESSION["listofpaths".$keytoavoidconflict]=join(';',$listofpaths);
|
||||
$_SESSION["listofnames".$keytoavoidconflict]=join(';',$listofnames);
|
||||
$_SESSION["listofmimes".$keytoavoidconflict]=join(';',$listofmimes);
|
||||
//var_dump($_SESSION['listofpaths']);
|
||||
}
|
||||
}
|
||||
@ -203,9 +208,11 @@ class FormMail extends Form
|
||||
$listofpaths=array();
|
||||
$listofnames=array();
|
||||
$listofmimes=array();
|
||||
if (! empty($_SESSION["listofpaths"])) $listofpaths=explode(';',$_SESSION["listofpaths"]);
|
||||
if (! empty($_SESSION["listofnames"])) $listofnames=explode(';',$_SESSION["listofnames"]);
|
||||
if (! empty($_SESSION["listofmimes"])) $listofmimes=explode(';',$_SESSION["listofmimes"]);
|
||||
|
||||
$keytoavoidconflict = empty($this->trackid)?'':'-'.$this->trackid; // this->trackid must be defined
|
||||
if (! empty($_SESSION["listofpaths".$keytoavoidconflict])) $listofpaths=explode(';',$_SESSION["listofpaths".$keytoavoidconflict]);
|
||||
if (! empty($_SESSION["listofnames".$keytoavoidconflict])) $listofnames=explode(';',$_SESSION["listofnames".$keytoavoidconflict]);
|
||||
if (! empty($_SESSION["listofmimes".$keytoavoidconflict])) $listofmimes=explode(';',$_SESSION["listofmimes".$keytoavoidconflict]);
|
||||
return array('paths'=>$listofpaths, 'names'=>$listofnames, 'mimes'=>$listofmimes);
|
||||
}
|
||||
|
||||
@ -260,9 +267,10 @@ class FormMail extends Form
|
||||
$listofpaths=array();
|
||||
$listofnames=array();
|
||||
$listofmimes=array();
|
||||
if (! empty($_SESSION["listofpaths"])) $listofpaths=explode(';',$_SESSION["listofpaths"]);
|
||||
if (! empty($_SESSION["listofnames"])) $listofnames=explode(';',$_SESSION["listofnames"]);
|
||||
if (! empty($_SESSION["listofmimes"])) $listofmimes=explode(';',$_SESSION["listofmimes"]);
|
||||
$keytoavoidconflict = empty($this->trackid)?'':'-'.$this->trackid; // this->trackid must be defined
|
||||
if (! empty($_SESSION["listofpaths".$keytoavoidconflict])) $listofpaths=explode(';',$_SESSION["listofpaths".$keytoavoidconflict]);
|
||||
if (! empty($_SESSION["listofnames".$keytoavoidconflict])) $listofnames=explode(';',$_SESSION["listofnames".$keytoavoidconflict]);
|
||||
if (! empty($_SESSION["listofmimes".$keytoavoidconflict])) $listofmimes=explode(';',$_SESSION["listofmimes".$keytoavoidconflict]);
|
||||
|
||||
// Define output language
|
||||
$outputlangs = $langs;
|
||||
|
||||
@ -1392,12 +1392,14 @@ function dol_meta_create($object)
|
||||
|
||||
|
||||
/**
|
||||
* Init $_SESSION with uploaded files
|
||||
* Scan a directory and init $_SESSION to manage uploaded files with list of all found files.
|
||||
* Note: Only email module seems to use this. Other feature initialize the $_SESSION doing $formmail->clear_attached_files(); $formmail->add_attached_files()
|
||||
*
|
||||
* @param string $pathtoscan Path to scan
|
||||
* @param string $trackid Track id (used to prefix name of session vars to avoid conflict)
|
||||
* @return void
|
||||
*/
|
||||
function dol_init_file_process($pathtoscan='')
|
||||
function dol_init_file_process($pathtoscan='', $trackid='')
|
||||
{
|
||||
$listofpaths=array();
|
||||
$listofnames=array();
|
||||
@ -1413,9 +1415,10 @@ function dol_init_file_process($pathtoscan='')
|
||||
$listofmimes[]=dol_mimetype($val['name']);
|
||||
}
|
||||
}
|
||||
$_SESSION["listofpaths"]=join(';',$listofpaths);
|
||||
$_SESSION["listofnames"]=join(';',$listofnames);
|
||||
$_SESSION["listofmimes"]=join(';',$listofmimes);
|
||||
$keytoavoidconflict = empty($trackid)?'':'-'.$trackid;
|
||||
$_SESSION["listofpaths".$keytoavoidconflict]=join(';',$listofpaths);
|
||||
$_SESSION["listofnames".$keytoavoidconflict]=join(';',$listofnames);
|
||||
$_SESSION["listofmimes".$keytoavoidconflict]=join(';',$listofmimes);
|
||||
}
|
||||
|
||||
|
||||
@ -1430,9 +1433,10 @@ function dol_init_file_process($pathtoscan='')
|
||||
* @param string $varfiles _FILES var name
|
||||
* @param string $savingdocmask Mask to use to define output filename. For example 'XXXXX-__YYYYMMDD__-__file__'
|
||||
* @param string $link Link to add
|
||||
* @param string $trackid Track id (used to prefix name of session vars to avoid conflict)
|
||||
* @return void
|
||||
*/
|
||||
function dol_add_file_process($upload_dir, $allowoverwrite=0, $donotupdatesession=0, $varfiles='addedfile', $savingdocmask='', $link=null)
|
||||
function dol_add_file_process($upload_dir, $allowoverwrite=0, $donotupdatesession=0, $varfiles='addedfile', $savingdocmask='', $link=null, $trackid='')
|
||||
{
|
||||
global $db,$user,$conf,$langs;
|
||||
|
||||
@ -1482,6 +1486,7 @@ function dol_add_file_process($upload_dir, $allowoverwrite=0, $donotupdatesessio
|
||||
{
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
|
||||
$formmail = new FormMail($db);
|
||||
$formmail->trackid = $trackid;
|
||||
$formmail->add_attached_files($destpath, $destfile, $TFile['type'][$i]);
|
||||
}
|
||||
if (image_format_supported($destpath) == 1)
|
||||
@ -1550,9 +1555,10 @@ function dol_add_file_process($upload_dir, $allowoverwrite=0, $donotupdatesessio
|
||||
* @param int $filenb File nb to delete
|
||||
* @param int $donotupdatesession 1=Do not edit _SESSION variable
|
||||
* @param int $donotdeletefile 1=Do not delete physically file
|
||||
* @param string $trackid Track id (used to prefix name of session vars to avoid conflict)
|
||||
* @return void
|
||||
*/
|
||||
function dol_remove_file_process($filenb,$donotupdatesession=0,$donotdeletefile=1)
|
||||
function dol_remove_file_process($filenb,$donotupdatesession=0,$donotdeletefile=1,$trackid='')
|
||||
{
|
||||
global $db,$user,$conf,$langs,$_FILES;
|
||||
|
||||
@ -1562,9 +1568,10 @@ function dol_remove_file_process($filenb,$donotupdatesession=0,$donotdeletefile=
|
||||
$listofpaths=array();
|
||||
$listofnames=array();
|
||||
$listofmimes=array();
|
||||
if (! empty($_SESSION["listofpaths"])) $listofpaths=explode(';',$_SESSION["listofpaths"]);
|
||||
if (! empty($_SESSION["listofnames"])) $listofnames=explode(';',$_SESSION["listofnames"]);
|
||||
if (! empty($_SESSION["listofmimes"])) $listofmimes=explode(';',$_SESSION["listofmimes"]);
|
||||
$keytoavoidconflict = empty($trackid)?'':'-'.$trackid;
|
||||
if (! empty($_SESSION["listofpaths".$keytoavoidconflict])) $listofpaths=explode(';',$_SESSION["listofpaths".$keytoavoidconflict]);
|
||||
if (! empty($_SESSION["listofnames".$keytoavoidconflict])) $listofnames=explode(';',$_SESSION["listofnames".$keytoavoidconflict]);
|
||||
if (! empty($_SESSION["listofmimes".$keytoavoidconflict])) $listofmimes=explode(';',$_SESSION["listofmimes".$keytoavoidconflict]);
|
||||
|
||||
if ($keytodelete >= 0)
|
||||
{
|
||||
@ -1583,6 +1590,7 @@ function dol_remove_file_process($filenb,$donotupdatesession=0,$donotdeletefile=
|
||||
{
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
|
||||
$formmail = new FormMail($db);
|
||||
$formmail->trackid = $trackid;
|
||||
$formmail->remove_attached_files($keytodelete);
|
||||
}
|
||||
}
|
||||
|
||||
@ -101,7 +101,7 @@ class modCron extends DolibarrModules
|
||||
|
||||
// Cronjobs
|
||||
$this->cronjobs = array(
|
||||
0=>array('label'=>'PurgeDeleteTemporaryFilesShort', 'jobtype'=>'method', 'class'=>'core/class/utils.class.php', 'objectname'=>'Utils', 'method'=>'purgeFiles', 'parameters'=>'', 'comment'=>'PurgeDeleteTemporaryFiles', 'frequency'=>1, 'unitfrequency'=>3600 * 24 * 7, 'priority'=>10, 'status'=>1, 'test'=>true),
|
||||
0=>array('label'=>'PurgeDeleteTemporaryFilesShort', 'jobtype'=>'method', 'class'=>'core/class/utils.class.php', 'objectname'=>'Utils', 'method'=>'purgeFiles', 'parameters'=>'', 'comment'=>'PurgeDeleteTemporaryFiles', 'frequency'=>2, 'unitfrequency'=>3600 * 24 * 7, 'priority'=>10, 'status'=>1, 'test'=>true),
|
||||
1=>array('label'=>'MakeLocalDatabaseDumpShort', 'jobtype'=>'method', 'class'=>'core/class/utils.class.php', 'objectname'=>'Utils', 'method'=>'dumpDatabase', 'parameters'=>'none', 'comment'=>'MakeLocalDatabaseDump', 'frequency'=>1, 'unitfrequency'=>3600 * 24 * 7, 'priority'=>20, 'status'=>0, 'test'=>in_array($db->type, array('mysql','mysqli'))),
|
||||
// 1=>array('label'=>'My label', 'jobtype'=>'command', 'command'=>'', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>1, 'unitfrequency'=>3600*24)
|
||||
);
|
||||
|
||||
@ -1925,7 +1925,6 @@ else if ($id || $ref)
|
||||
$formmail->setSubstitFromObject($object);
|
||||
$formmail->substit['__SHIPPINGREF__']=$object->ref;
|
||||
|
||||
//Find the good contact adress
|
||||
//Find the good contact adress
|
||||
if ($typeobject == 'commande' && $object->$typeobject->id && ! empty($conf->commande->enabled)) {
|
||||
$objectsrc=new Commande($db);
|
||||
@ -1937,8 +1936,11 @@ else if ($id || $ref)
|
||||
}
|
||||
$custcontact='';
|
||||
$contactarr=array();
|
||||
$contactarr=$objectsrc->liste_contact(-1,'external');
|
||||
|
||||
if (is_object($objectsrc)) // For the case the shipment was created without orders
|
||||
{
|
||||
$contactarr=$objectsrc->liste_contact(-1,'external');
|
||||
}
|
||||
|
||||
if (is_array($contactarr) && count($contactarr)>0) {
|
||||
foreach($contactarr as $contact) {
|
||||
|
||||
|
||||
@ -700,174 +700,19 @@ if (empty($reshook))
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Add file in email form
|
||||
*/
|
||||
if (GETPOST('addfile','alpha'))
|
||||
{
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||
|
||||
// Set tmp user directory TODO Use a dedicated directory for temp mails files
|
||||
$vardir=$conf->user->dir_output."/".$user->id;
|
||||
$upload_dir_tmp = $vardir.'/temp';
|
||||
|
||||
dol_add_file_process($upload_dir_tmp,0,0);
|
||||
$action='presend';
|
||||
}
|
||||
|
||||
/*
|
||||
* Remove file in email form
|
||||
*/
|
||||
if (GETPOST('removedfile','alpha'))
|
||||
{
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||
|
||||
// Set tmp user directory
|
||||
$vardir=$conf->user->dir_output."/".$user->id;
|
||||
$upload_dir_tmp = $vardir.'/temp';
|
||||
|
||||
// TODO Delete only files that was uploaded from email form
|
||||
dol_remove_file_process(GETPOST('removedfile','alpha'),0);
|
||||
$action='presend';
|
||||
}
|
||||
|
||||
/*
|
||||
* Send mail
|
||||
*/
|
||||
if ($action == 'send' && ! GETPOST('cancel','alpha') && (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->ficheinter->ficheinter_advance->send))
|
||||
{
|
||||
$langs->load('mails');
|
||||
*/
|
||||
|
||||
// Actions to send emails
|
||||
$actiontypecode='AC_OTH_AUTO';
|
||||
$trigger_name='FICHINTER_SENTBYMAIL';
|
||||
$paramname='id';
|
||||
$mode='emailfromintervention';
|
||||
include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
|
||||
|
||||
|
||||
if (GETPOST('sendto','alpha'))
|
||||
{
|
||||
// Le destinataire a ete fourni via le champ libre
|
||||
$sendto = GETPOST('sendto','alpha');
|
||||
$sendtoid = 0;
|
||||
}
|
||||
elseif (GETPOST('receiver','alpha') != '-1')
|
||||
{
|
||||
// Recipient was provided from combo list
|
||||
if (GETPOST('receiver','alpha') == 'thirdparty') // Id of third party
|
||||
{
|
||||
$sendto = $object->thirdparty->email;
|
||||
$sendtoid = 0;
|
||||
}
|
||||
else // Id du contact
|
||||
{
|
||||
$sendto = $object->thirdparty->contact_get_property(GETPOST('receiver'),'email');
|
||||
$sendtoid = GETPOST('receiver','alpha');
|
||||
}
|
||||
}
|
||||
|
||||
if (dol_strlen($sendto))
|
||||
{
|
||||
$langs->load("commercial");
|
||||
|
||||
$from = GETPOST('fromname','alpha') . ' <' . GETPOST('frommail','alpha') .'>';
|
||||
$replyto = GETPOST('replytoname','alpha'). ' <' . GETPOST('replytomail','alpha').'>';
|
||||
$message = GETPOST('message');
|
||||
$sendtocc = GETPOST('sendtocc','alpha');
|
||||
$deliveryreceipt = GETPOST('deliveryreceipt','alpha');
|
||||
|
||||
if ($action == 'send')
|
||||
{
|
||||
if (strlen(GETPOST('subject','alphs'))) $subject = GETPOST('subject','alpha');
|
||||
else $subject = $langs->transnoentities('Intervention').' '.$object->ref;
|
||||
$actiontypecode='AC_OTH_AUTO';
|
||||
$actionmsg = $langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto;
|
||||
if ($message)
|
||||
{
|
||||
if ($sendtocc) $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc') . ": " . $sendtocc);
|
||||
$actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic') . ": " . $subject);
|
||||
$actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody') . ":");
|
||||
$actionmsg = dol_concatdesc($actionmsg, $message);
|
||||
}
|
||||
$actionmsg2=$langs->transnoentities("InterventionSentByEMail",$object->ref);
|
||||
}
|
||||
|
||||
// Create form object
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
|
||||
$formmail = new FormMail($db);
|
||||
|
||||
$attachedfiles=$formmail->get_attached_files();
|
||||
$filepath = $attachedfiles['paths'];
|
||||
$filename = $attachedfiles['names'];
|
||||
$mimetype = $attachedfiles['mimes'];
|
||||
|
||||
// Send by email
|
||||
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)
|
||||
{
|
||||
$mesg='<div class="error">'.$mailfile->error.'</div>';
|
||||
}
|
||||
else
|
||||
{
|
||||
$result=$mailfile->sendfile();
|
||||
if ($result)
|
||||
{
|
||||
$mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($from,2),$mailfile->getValidAddress($sendto,2));
|
||||
setEventMessages($mesg, null, 'mesgs');
|
||||
$error=0;
|
||||
|
||||
// Initialisation donnees
|
||||
$object->sendtoid = $sendtoid;
|
||||
$object->actiontypecode = $actiontypecode;
|
||||
$object->actionmsg = $actionmsg;
|
||||
$object->actionmsg2 = $actionmsg2;
|
||||
$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('FICHINTER_SENTBYMAIL',$object,$user,$langs,$conf);
|
||||
if ($result < 0) {
|
||||
$error++; $object->errors=$interface->errors;
|
||||
}
|
||||
// Fin appel triggers
|
||||
|
||||
if ($error)
|
||||
{
|
||||
dol_print_error($db);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Redirect here
|
||||
// This avoid sending mail twice if going out and then back to page
|
||||
header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$langs->load("other");
|
||||
$mesg='<div class="error">';
|
||||
if ($mailfile->error)
|
||||
{
|
||||
$mesg.=$langs->trans('ErrorFailedToSendMail',$from,$sendto);
|
||||
$mesg.='<br>'.$mailfile->error;
|
||||
}
|
||||
else
|
||||
{
|
||||
$mesg.='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
|
||||
}
|
||||
$mesg.='</div>';
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$langs->load("other");
|
||||
$mesg='<div class="error">'.$langs->trans('ErrorMailRecipientIsEmpty').' !</div>';
|
||||
dol_syslog('Recipient email is empty');
|
||||
}
|
||||
|
||||
$action='presend';
|
||||
}
|
||||
|
||||
else if ($action == 'update_extras')
|
||||
if ($action == 'update_extras')
|
||||
{
|
||||
// Fill array 'array_options' with data from update form
|
||||
$extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
|
||||
|
||||
@ -870,10 +870,10 @@ if (empty($reshook))
|
||||
if ($action == 'builddoc' && $user->rights->fournisseur->commande->creer) // En get ou en post
|
||||
{
|
||||
// Build document
|
||||
|
||||
// Save last template used to generate document
|
||||
if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha'));
|
||||
|
||||
|
||||
// Save last template used to generate document
|
||||
if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha'));
|
||||
|
||||
$outputlangs = $langs;
|
||||
if (GETPOST('lang_id'))
|
||||
{
|
||||
@ -883,7 +883,7 @@ if (empty($reshook))
|
||||
$result= $object->generateDocument($object->modelpdf,$outputlangs, $hidedetails, $hidedesc, $hideref);
|
||||
if ($result <= 0)
|
||||
{
|
||||
setEventMessages($object->error, $object->errors, 'errors');
|
||||
setEventMessages($object->error, $object->errors, 'errors');
|
||||
$action='';
|
||||
}
|
||||
}
|
||||
@ -899,7 +899,7 @@ if (empty($reshook))
|
||||
if ($ret) setEventMessages($langs->trans("FileWasRemoved", GETPOST('urlfile')), null, 'mesgs');
|
||||
else setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), null, 'errors');
|
||||
}
|
||||
|
||||
|
||||
if ($action == 'update_extras')
|
||||
{
|
||||
// Fill array 'array_options' with data from add form
|
||||
@ -1145,190 +1145,17 @@ if (empty($reshook))
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Add file in email form
|
||||
*/
|
||||
if (GETPOST('addfile'))
|
||||
{
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||
|
||||
// Set tmp user directory TODO Use a dedicated directory for temp mails files
|
||||
$vardir=$conf->user->dir_output."/".$user->id;
|
||||
$upload_dir_tmp = $vardir.'/temp';
|
||||
|
||||
dol_add_file_process($upload_dir_tmp,0,0);
|
||||
$action='presend';
|
||||
}
|
||||
|
||||
/*
|
||||
* Remove file in email form
|
||||
*/
|
||||
if (GETPOST('removedfile'))
|
||||
{
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||
|
||||
// Set tmp user directory
|
||||
$vardir=$conf->user->dir_output."/".$user->id;
|
||||
$upload_dir_tmp = $vardir.'/temp';
|
||||
|
||||
// TODO Delete only files that was uploaded from email form
|
||||
dol_remove_file_process(GETPOST('removedfile','alpha'),0);
|
||||
$action='presend';
|
||||
}
|
||||
|
||||
/*
|
||||
* Send mail
|
||||
*/
|
||||
if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! GETPOST('cancel'))
|
||||
{
|
||||
$langs->load('mails');
|
||||
|
||||
if ($object->id > 0)
|
||||
{
|
||||
// $ref = dol_sanitizeFileName($object->ref);
|
||||
// $file = $conf->fournisseur->commande->dir_output . '/' . $ref . '/' . $ref . '.pdf';
|
||||
|
||||
// if (is_readable($file))
|
||||
// {
|
||||
if (GETPOST('sendto','alpha'))
|
||||
{
|
||||
// Le destinataire a ete fourni via le champ libre
|
||||
$sendto = GETPOST('sendto','alpha');
|
||||
$sendtoid = 0;
|
||||
}
|
||||
elseif (GETPOST('receiver','alpha') != '-1')
|
||||
{
|
||||
// Recipient was provided from combo list
|
||||
if (GETPOST('receiver','alpha') == 'thirdparty') // Id of third party
|
||||
{
|
||||
$sendto = $object->thirdparty->email;
|
||||
$sendtoid = 0;
|
||||
}
|
||||
else // Id du contact
|
||||
{
|
||||
$sendto = $object->thirdparty->contact_get_property(GETPOST('receiver','alpha'),'email');
|
||||
$sendtoid = GETPOST('receiver','alpha');
|
||||
}
|
||||
}
|
||||
|
||||
if (dol_strlen($sendto))
|
||||
{
|
||||
$langs->load("commercial");
|
||||
|
||||
$from = GETPOST('fromname','alpha') . ' <' . GETPOST('frommail','alpha') .'>';
|
||||
$replyto = GETPOST('replytoname','alpha'). ' <' . GETPOST('replytomail','alpha').'>';
|
||||
$message = GETPOST('message');
|
||||
$sendtocc = GETPOST('sendtocc','alpha');
|
||||
$deliveryreceipt = GETPOST('deliveryreceipt','alpha');
|
||||
|
||||
if ($action == 'send')
|
||||
{
|
||||
if (dol_strlen(GETPOST('subject'))) $subject=GETPOST('subject');
|
||||
else $subject = $langs->transnoentities('CustomerOrder').' '.$object->ref;
|
||||
$actiontypecode='AC_SUP_ORD';
|
||||
$actionmsg = $langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto;
|
||||
if ($message)
|
||||
{
|
||||
if ($sendtocc) $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc') . ": " . $sendtocc);
|
||||
$actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic') . ": " . $subject);
|
||||
$actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody') . ":");
|
||||
$actionmsg = dol_concatdesc($actionmsg, $message);
|
||||
}
|
||||
$actionmsg2=$langs->transnoentities('Action'.$actiontypecode);
|
||||
}
|
||||
|
||||
// Create form object
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
|
||||
$formmail = new FormMail($db);
|
||||
|
||||
$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)
|
||||
{
|
||||
setEventMessages($mailfile->error, $mailfile->errors, 'errors');
|
||||
}
|
||||
else
|
||||
{
|
||||
$result=$mailfile->sendfile();
|
||||
if ($result)
|
||||
{
|
||||
$mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($from,2),$mailfile->getValidAddress($sendto,2)); // Must not contain "
|
||||
setEventMessages($mesg, null, 'mesgs');
|
||||
|
||||
$error=0;
|
||||
|
||||
// Initialisation donnees
|
||||
$object->sendtoid = $sendtoid;
|
||||
$object->actiontypecode = $actiontypecode;
|
||||
$object->actionmsg = $actionmsg;
|
||||
$object->actionmsg2 = $actionmsg2;
|
||||
$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('ORDER_SUPPLIER_SENTBYMAIL',$object,$user,$langs,$conf);
|
||||
if ($result < 0) { $error++; $errors=$interface->errors; }
|
||||
// Fin appel triggers
|
||||
|
||||
if ($error)
|
||||
{
|
||||
setEventMessages($object->error, $object->errors, 'errors');
|
||||
}
|
||||
else
|
||||
{
|
||||
// Redirect here
|
||||
// This avoid sending mail twice if going out and then back to page
|
||||
header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$langs->load("other");
|
||||
if ($mailfile->error)
|
||||
{
|
||||
$mesg = $langs->trans('ErrorFailedToSendMail',$from,$sendto);
|
||||
$mesg.= '<br>'.$mailfile->error;
|
||||
}
|
||||
else
|
||||
{
|
||||
$mesg = 'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
|
||||
}
|
||||
|
||||
setEventMessages($mesg, null, 'errors');
|
||||
}
|
||||
}
|
||||
/* }
|
||||
else
|
||||
{
|
||||
$langs->load("other");
|
||||
$mesg='<div class="error">'.$langs->trans('ErrorMailRecipientIsEmpty').' !</div>';
|
||||
$action='presend';
|
||||
dol_syslog('Recipient email is empty');
|
||||
}*/
|
||||
}
|
||||
else
|
||||
{
|
||||
$langs->load("errors");
|
||||
setEventMessages($langs->trans('ErrorCantReadFile',$file), null, 'errors');
|
||||
dol_syslog('Failed to read file: '.$file);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$langs->load("other");
|
||||
setEventMessages($langs->trans('ErrorFailedToReadEntity',$langs->trans("Invoice")), null, 'errors');
|
||||
dol_syslog('Impossible de lire les donnees de la facture. Le fichier facture n\'a peut-etre pas ete genere.');
|
||||
}
|
||||
}
|
||||
|
||||
// Actions to send emails
|
||||
$actiontypecode='AC_SUP_ORD';
|
||||
$trigger_name='ORDER_SUPPLIER_SENTBYMAIL';
|
||||
$paramname='id';
|
||||
$mode='emailfromsupplierorder';
|
||||
include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
|
||||
|
||||
|
||||
if ($action == 'webservice' && GETPOST('mode', 'alpha') == "send" && ! GETPOST('cancel'))
|
||||
{
|
||||
|
||||
@ -932,184 +932,17 @@ if (empty($reshook))
|
||||
}
|
||||
}
|
||||
|
||||
// Add file in email form
|
||||
if (GETPOST('addfile'))
|
||||
{
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||
|
||||
// Set tmp user directory TODO Use a dedicated directory for temp mails files
|
||||
$vardir=$conf->user->dir_output."/".$user->id;
|
||||
$upload_dir_tmp = $vardir.'/temp';
|
||||
|
||||
dol_add_file_process($upload_dir_tmp,0,0);
|
||||
$action='presend';
|
||||
}
|
||||
|
||||
// Remove file in email form
|
||||
if (! empty($_POST['removedfile']))
|
||||
{
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||
|
||||
// Set tmp user directory
|
||||
$vardir=$conf->user->dir_output."/".$user->id;
|
||||
$upload_dir_tmp = $vardir.'/temp';
|
||||
|
||||
// TODO Delete only files that was uploaded from email form
|
||||
dol_remove_file_process(GETPOST('removedfile','alpha'),0);
|
||||
$action='presend';
|
||||
}
|
||||
|
||||
// Send mail
|
||||
if ($action == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile'] && ! $_POST['cancel'])
|
||||
{
|
||||
$langs->load('mails');
|
||||
|
||||
$object->fetch($id);
|
||||
$result=$object->fetch_thirdparty();
|
||||
if ($result > 0)
|
||||
{
|
||||
if ($_POST['sendto'])
|
||||
{
|
||||
// Le destinataire a ete fourni via le champ libre
|
||||
$sendto = $_POST['sendto'];
|
||||
$sendtoid = 0;
|
||||
}
|
||||
elseif ($_POST['receiver'] != '-1')
|
||||
{
|
||||
// Recipient was provided from combo list
|
||||
if ($_POST['receiver'] == 'thirdparty') // Id of third party
|
||||
{
|
||||
$sendto = $object->thirdparty->email;
|
||||
$sendtoid = 0;
|
||||
}
|
||||
else // Id du contact
|
||||
{
|
||||
$sendto = $object->thirdparty->contact_get_property($_POST['receiver'],'email');
|
||||
$sendtoid = $_POST['receiver'];
|
||||
}
|
||||
}
|
||||
|
||||
if (dol_strlen($sendto))
|
||||
{
|
||||
$langs->load("commercial");
|
||||
|
||||
$from = $_POST['fromname'] . ' <' . $_POST['frommail'] .'>';
|
||||
$replyto = $_POST['replytoname']. ' <' . $_POST['replytomail'].'>';
|
||||
$message = $_POST['message'];
|
||||
$sendtocc = $_POST['sendtocc'];
|
||||
$deliveryreceipt = $_POST['deliveryreceipt'];
|
||||
|
||||
if ($action == 'send')
|
||||
{
|
||||
if (dol_strlen($_POST['subject'])) $subject=$_POST['subject'];
|
||||
else $subject = $langs->transnoentities('CustomerOrder').' '.$object->ref;
|
||||
$actiontypecode='AC_SUP_INV';
|
||||
$actionmsg = $langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto;
|
||||
if ($message)
|
||||
{
|
||||
if ($sendtocc) $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc') . ": " . $sendtocc);
|
||||
$actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic') . ": " . $subject);
|
||||
$actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody') . ":");
|
||||
$actionmsg = dol_concatdesc($actionmsg, $message);
|
||||
}
|
||||
$actionmsg2=$langs->transnoentities('Action'.$actiontypecode);
|
||||
}
|
||||
|
||||
// Create form object
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
|
||||
$formmail = new FormMail($db);
|
||||
|
||||
$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)
|
||||
{
|
||||
setEventMessages($mailfile->error, $mailfile->errors, 'errors');
|
||||
}
|
||||
else
|
||||
{
|
||||
$result=$mailfile->sendfile();
|
||||
if ($result)
|
||||
{
|
||||
$mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($from,2),$mailfile->getValidAddress($sendto,2)); // Must not contain "
|
||||
setEventMessages($mesg, null, 'mesgs');
|
||||
|
||||
$error=0;
|
||||
|
||||
// Init data for trigger
|
||||
$object->sendtoid = $sendtoid;
|
||||
$object->actiontypecode = $actiontypecode;
|
||||
$object->actionmsg = $actionmsg;
|
||||
$object->actionmsg2 = $actionmsg2;
|
||||
$object->fk_element = $object->id;
|
||||
$object->elementtype = $object->element;
|
||||
|
||||
$object->email_subject = $subject;
|
||||
$object->email_to = $sendto;
|
||||
$object->email_tocc = $sendtocc;
|
||||
$object->email_tobcc = $sendtobcc;
|
||||
$object->email_from = $from;
|
||||
$object->email_content = $_POST['message'];
|
||||
|
||||
// Call triggers
|
||||
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
|
||||
$interface=new Interfaces($db);
|
||||
$result=$interface->run_triggers('BILL_SUPPLIER_SENTBYMAIL',$object,$user,$langs,$conf);
|
||||
if ($result < 0) {
|
||||
$error++; $object->errors=$interface->errors;
|
||||
}
|
||||
// End call triggers
|
||||
|
||||
if ($error)
|
||||
{
|
||||
dol_print_error($db);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Redirect here
|
||||
// This avoid sending mail twice if going out and then back to page
|
||||
header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$langs->load("other");
|
||||
if ($mailfile->error)
|
||||
{
|
||||
$mesg.=$langs->trans('ErrorFailedToSendMail',$from,$sendto);
|
||||
$mesg.='<br>'.$mailfile->error;
|
||||
}
|
||||
else
|
||||
{
|
||||
$mesg.='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
|
||||
}
|
||||
setEventMessages($mesg, null, 'errors');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
$langs->load("other");
|
||||
setEventMessages($langs->trans('ErrorMailRecipientIsEmpty'), null, 'errors');
|
||||
dol_syslog('Recipient email is empty');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$langs->load("other");
|
||||
setEventMessages($langs->trans('ErrorFailedToReadEntity',$langs->trans("Invoice")), null, 'errors');
|
||||
dol_syslog('Unable to read data from the invoice. The invoice file has perhaps not been generated.');
|
||||
}
|
||||
|
||||
//$action = 'presend';
|
||||
}
|
||||
/*
|
||||
* Send mail
|
||||
*/
|
||||
|
||||
// Actions to send emails
|
||||
$actiontypecode='AC_SUP_INV';
|
||||
$trigger_name='BILL_SUPPLIER_SENTBYMAIL';
|
||||
$paramname='id';
|
||||
$mode='emailfromsupplierinvoice';
|
||||
include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
|
||||
|
||||
|
||||
// Build document
|
||||
if ($action == 'builddoc')
|
||||
|
||||
@ -476,7 +476,7 @@ if (empty($reshook))
|
||||
$actiontypecode='AC_ASKPRICE';
|
||||
$trigger_name='SUPPLIER_PROPOSAL_SENTBYMAIL';
|
||||
$paramname='id';
|
||||
$mode='emailfromsupplier_proposal';
|
||||
$mode='emailfromsupplierproposal';
|
||||
include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user