Merge pull request #6012 from atm-florian/dev_NEW_copyeventfiles
NEW : option to copy attachment files of emails into the event document area
This commit is contained in:
commit
78c3a1a3a1
@ -1,25 +1,25 @@
|
|||||||
<?php
|
<?php
|
||||||
/* Copyright (C) 2013 Laurent Destailleur <eldy@users.sourceforge.net>
|
/* Copyright (C) 2013 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation; either version 3 of the License, or
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* or see http://www.gnu.org/
|
* or see http://www.gnu.org/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \file htdocs/core/actions_sendmails.inc.php
|
* \file htdocs/core/actions_sendmails.inc.php
|
||||||
* \brief Code for actions on sending mails from object page
|
* \brief Code for actions on sending mails from object page
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// $mysoc must be defined
|
// $mysoc must be defined
|
||||||
// $id must be defined
|
// $id must be defined
|
||||||
@ -31,12 +31,12 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Add file in email form
|
* Add file in email form
|
||||||
*/
|
*/
|
||||||
if (GETPOST('addfile'))
|
if (GETPOST('addfile'))
|
||||||
{
|
{
|
||||||
$trackid = GETPOST('trackid','aZ09');
|
$trackid = GETPOST('trackid','aZ09');
|
||||||
|
|
||||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||||
|
|
||||||
// Set tmp user directory
|
// Set tmp user directory
|
||||||
$vardir=$conf->user->dir_output."/".$user->id;
|
$vardir=$conf->user->dir_output."/".$user->id;
|
||||||
@ -72,10 +72,10 @@ if (GETPOST('removAll'))
|
|||||||
{
|
{
|
||||||
$trackid = GETPOST('trackid','aZ09');
|
$trackid = GETPOST('trackid','aZ09');
|
||||||
|
|
||||||
$listofpaths=array();
|
$listofpaths=array();
|
||||||
$listofnames=array();
|
$listofnames=array();
|
||||||
$listofmimes=array();
|
$listofmimes=array();
|
||||||
$keytoavoidconflict = empty($trackid)?'':'-'.$trackid;
|
$keytoavoidconflict = empty($trackid)?'':'-'.$trackid;
|
||||||
if (! empty($_SESSION["listofpaths".$keytoavoidconflict])) $listofpaths=explode(';',$_SESSION["listofpaths".$keytoavoidconflict]);
|
if (! empty($_SESSION["listofpaths".$keytoavoidconflict])) $listofpaths=explode(';',$_SESSION["listofpaths".$keytoavoidconflict]);
|
||||||
if (! empty($_SESSION["listofnames".$keytoavoidconflict])) $listofnames=explode(';',$_SESSION["listofnames".$keytoavoidconflict]);
|
if (! empty($_SESSION["listofnames".$keytoavoidconflict])) $listofnames=explode(';',$_SESSION["listofnames".$keytoavoidconflict]);
|
||||||
if (! empty($_SESSION["listofmimes".$keytoavoidconflict])) $listofmimes=explode(';',$_SESSION["listofmimes".$keytoavoidconflict]);
|
if (! empty($_SESSION["listofmimes".$keytoavoidconflict])) $listofmimes=explode(';',$_SESSION["listofmimes".$keytoavoidconflict]);
|
||||||
@ -105,56 +105,56 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
|
|||||||
$trackid = GETPOST('trackid','aZ09');
|
$trackid = GETPOST('trackid','aZ09');
|
||||||
$subject='';$actionmsg='';$actionmsg2='';
|
$subject='';$actionmsg='';$actionmsg2='';
|
||||||
|
|
||||||
if (! empty($conf->dolimail->enabled)) $langs->load("dolimail@dolimail");
|
if (! empty($conf->dolimail->enabled)) $langs->load("dolimail@dolimail");
|
||||||
$langs->load('mails');
|
$langs->load('mails');
|
||||||
|
|
||||||
if (is_object($object))
|
if (is_object($object))
|
||||||
{
|
{
|
||||||
$result=$object->fetch($id);
|
$result=$object->fetch($id);
|
||||||
|
|
||||||
$sendtosocid=0; // Thirdparty on object
|
$sendtosocid=0; // Thirdparty on object
|
||||||
if (method_exists($object,"fetch_thirdparty") && $object->element != 'societe')
|
if (method_exists($object,"fetch_thirdparty") && $object->element != 'societe')
|
||||||
{
|
{
|
||||||
$result=$object->fetch_thirdparty();
|
$result=$object->fetch_thirdparty();
|
||||||
$thirdparty=$object->thirdparty;
|
$thirdparty=$object->thirdparty;
|
||||||
$sendtosocid=$thirdparty->id;
|
$sendtosocid=$thirdparty->id;
|
||||||
}
|
}
|
||||||
else if ($object->element == 'societe')
|
else if ($object->element == 'societe')
|
||||||
{
|
{
|
||||||
$thirdparty=$object;
|
$thirdparty=$object;
|
||||||
if ($thirdparty->id > 0) $sendtosocid=$thirdparty->id;
|
if ($thirdparty->id > 0) $sendtosocid=$thirdparty->id;
|
||||||
elseif (! empty($conf->dolimail->enabled))
|
elseif (! empty($conf->dolimail->enabled))
|
||||||
{
|
{
|
||||||
$dolimail = new Dolimail($db);
|
$dolimail = new Dolimail($db);
|
||||||
$possibleaccounts=$dolimail->get_societe_by_email($_POST['sendto'],"1");
|
$possibleaccounts=$dolimail->get_societe_by_email($_POST['sendto'],"1");
|
||||||
$possibleuser=$dolimail->get_from_user_by_mail($_POST['sendto'],"1"); // suche in llx_societe and socpeople
|
$possibleuser=$dolimail->get_from_user_by_mail($_POST['sendto'],"1"); // suche in llx_societe and socpeople
|
||||||
if (!$possibleaccounts && !$possibleuser)
|
if (!$possibleaccounts && !$possibleuser)
|
||||||
{
|
{
|
||||||
setEventMessages($langs->trans('ErrorFailedToFindSocieteRecord',$_POST['sendto']), null, 'errors');
|
setEventMessages($langs->trans('ErrorFailedToFindSocieteRecord',$_POST['sendto']), null, 'errors');
|
||||||
}
|
}
|
||||||
elseif (count($possibleaccounts)>1)
|
elseif (count($possibleaccounts)>1)
|
||||||
{
|
{
|
||||||
$sendtosocid=$possibleaccounts[1]['id'];
|
$sendtosocid=$possibleaccounts[1]['id'];
|
||||||
$result=$object->fetch($sendtosocid);
|
$result=$object->fetch($sendtosocid);
|
||||||
|
|
||||||
setEventMessages($langs->trans('ErrorFoundMoreThanOneRecordWithEmail',$_POST['sendto'],$object->name), null, 'mesgs');
|
setEventMessages($langs->trans('ErrorFoundMoreThanOneRecordWithEmail',$_POST['sendto'],$object->name), null, 'mesgs');
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if($possibleaccounts){
|
if($possibleaccounts){
|
||||||
$sendtosocid=$possibleaccounts[1]['id'];
|
$sendtosocid=$possibleaccounts[1]['id'];
|
||||||
$result=$object->fetch($sendtosocid);
|
$result=$object->fetch($sendtosocid);
|
||||||
}elseif($possibleuser){
|
}elseif($possibleuser){
|
||||||
$sendtosocid=$possibleuser[0]['id'];
|
$sendtosocid=$possibleuser[0]['id'];
|
||||||
|
|
||||||
$result=$uobject->fetch($sendtosocid);
|
$result=$uobject->fetch($sendtosocid);
|
||||||
$object=$uobject;
|
$object=$uobject;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else dol_print_error('','Use actions_sendmails.in.php for a type that is not supported');
|
else dol_print_error('','Use actions_sendmails.in.php for a type that is not supported');
|
||||||
}
|
}
|
||||||
else $thirdparty = $mysoc;
|
else $thirdparty = $mysoc;
|
||||||
|
|
||||||
@ -169,8 +169,8 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
|
|||||||
$receiver=$_POST['receiver'];
|
$receiver=$_POST['receiver'];
|
||||||
if (! is_array($receiver))
|
if (! is_array($receiver))
|
||||||
{
|
{
|
||||||
if ($receiver == '-1') $receiver=array();
|
if ($receiver == '-1') $receiver=array();
|
||||||
else $receiver=array($receiver);
|
else $receiver=array($receiver);
|
||||||
}
|
}
|
||||||
$tmparray=array();
|
$tmparray=array();
|
||||||
if (trim($_POST['sendto']))
|
if (trim($_POST['sendto']))
|
||||||
@ -200,8 +200,8 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
|
|||||||
$receivercc=$_POST['receivercc'];
|
$receivercc=$_POST['receivercc'];
|
||||||
if (! is_array($receivercc))
|
if (! is_array($receivercc))
|
||||||
{
|
{
|
||||||
if ($receivercc == '-1') $receivercc=array();
|
if ($receivercc == '-1') $receivercc=array();
|
||||||
else $receivercc=array($receivercc);
|
else $receivercc=array($receivercc);
|
||||||
}
|
}
|
||||||
$tmparray=array();
|
$tmparray=array();
|
||||||
if (trim($_POST['sendtocc']))
|
if (trim($_POST['sendtocc']))
|
||||||
@ -233,25 +233,25 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
|
|||||||
$langs->load("commercial");
|
$langs->load("commercial");
|
||||||
|
|
||||||
$fromtype = GETPOST('fromtype');
|
$fromtype = GETPOST('fromtype');
|
||||||
if ($fromtype === 'user') {
|
if ($fromtype === 'user') {
|
||||||
$from = $user->getFullName($langs) .' <'.$user->email.'>';
|
$from = $user->getFullName($langs) .' <'.$user->email.'>';
|
||||||
}
|
}
|
||||||
elseif ($fromtype === 'company') {
|
elseif ($fromtype === 'company') {
|
||||||
$from = $conf->global->MAIN_INFO_SOCIETE_NOM .' <'.$conf->global->MAIN_INFO_SOCIETE_MAIL.'>';
|
$from = $conf->global->MAIN_INFO_SOCIETE_NOM .' <'.$conf->global->MAIN_INFO_SOCIETE_MAIL.'>';
|
||||||
}
|
}
|
||||||
elseif (preg_match('/user_aliases_(\d+)/', $fromtype, $reg)) {
|
elseif (preg_match('/user_aliases_(\d+)/', $fromtype, $reg)) {
|
||||||
$tmp=explode(',', $user->email_aliases);
|
$tmp=explode(',', $user->email_aliases);
|
||||||
$from = trim($tmp[($reg[1] - 1)]);
|
$from = trim($tmp[($reg[1] - 1)]);
|
||||||
}
|
}
|
||||||
elseif (preg_match('/global_aliases_(\d+)/', $fromtype, $reg)) {
|
elseif (preg_match('/global_aliases_(\d+)/', $fromtype, $reg)) {
|
||||||
$tmp=explode(',', $conf->global->MAIN_INFO_SOCIETE_MAIL_ALIASES);
|
$tmp=explode(',', $conf->global->MAIN_INFO_SOCIETE_MAIL_ALIASES);
|
||||||
$from = trim($tmp[($reg[1] - 1)]);
|
$from = trim($tmp[($reg[1] - 1)]);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$from = $_POST['fromname'] . ' <' . $_POST['frommail'] .'>';
|
$from = $_POST['fromname'] . ' <' . $_POST['frommail'] .'>';
|
||||||
}
|
}
|
||||||
|
|
||||||
$replyto = $_POST['replytoname']. ' <' . $_POST['replytomail'].'>';
|
$replyto = $_POST['replytoname']. ' <' . $_POST['replytomail'].'>';
|
||||||
$message = $_POST['message'];
|
$message = $_POST['message'];
|
||||||
|
|
||||||
$sendtobcc= GETPOST('sendtoccc');
|
$sendtobcc= GETPOST('sendtoccc');
|
||||||
@ -356,35 +356,35 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
|
|||||||
$dolimail=new DoliMail($db);
|
$dolimail=new DoliMail($db);
|
||||||
$dolimail->id = $mid;
|
$dolimail->id = $mid;
|
||||||
$res=$dolimail->set_prop($user, 'answered',1);
|
$res=$dolimail->set_prop($user, 'answered',1);
|
||||||
}
|
}
|
||||||
if ($imap==1)
|
if ($imap==1)
|
||||||
{
|
{
|
||||||
// write mail to IMAP Server
|
// write mail to IMAP Server
|
||||||
$movemail = $mailboxconfig->putMail($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,$folder,$deliveryreceipt,$mailfile);
|
$movemail = $mailboxconfig->putMail($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,$folder,$deliveryreceipt,$mailfile);
|
||||||
if ($movemail) setEventMessages($langs->trans("MailMovedToImapFolder",$folder), null, 'mesgs');
|
if ($movemail) setEventMessages($langs->trans("MailMovedToImapFolder",$folder), null, 'mesgs');
|
||||||
else setEventMessages($langs->trans("MailMovedToImapFolder_Warning",$folder), null, 'warnings');
|
else setEventMessages($langs->trans("MailMovedToImapFolder_Warning",$folder), null, 'warnings');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialisation of datas
|
// Initialisation of datas
|
||||||
if (is_object($object))
|
if (is_object($object))
|
||||||
{
|
{
|
||||||
$object->socid = $sendtosocid; // To link to a company
|
$object->socid = $sendtosocid; // To link to a company
|
||||||
$object->sendtoid = $sendtoid; // To link to contacts/addresses. This is an array.
|
$object->sendtoid = $sendtoid; // To link to contacts/addresses. This is an array.
|
||||||
$object->actiontypecode = $actiontypecode;
|
$object->actiontypecode = $actiontypecode;
|
||||||
$object->actionmsg = $actionmsg; // Long text
|
$object->actionmsg = $actionmsg; // Long text
|
||||||
$object->actionmsg2 = $actionmsg2; // Short text
|
$object->actionmsg2 = $actionmsg2; // Short text
|
||||||
$object->trackid = $trackid;
|
$object->trackid = $trackid;
|
||||||
$object->fk_element = $object->id;
|
$object->fk_element = $object->id;
|
||||||
$object->elementtype = $object->element;
|
$object->elementtype = $object->element;
|
||||||
|
|
||||||
// Call of triggers
|
// Call of triggers
|
||||||
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
|
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
|
||||||
$interface=new Interfaces($db);
|
$interface=new Interfaces($db);
|
||||||
$result=$interface->run_triggers($trigger_name,$object,$user,$langs,$conf);
|
$result=$interface->run_triggers($trigger_name,$object,$user,$langs,$conf);
|
||||||
if ($result < 0) {
|
if ($result < 0) {
|
||||||
$error++; $errors=$interface->errors;
|
$error++; $errors=$interface->errors;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($error)
|
if ($error)
|
||||||
|
|||||||
@ -865,6 +865,21 @@ class InterfaceActionsAuto extends DolibarrTriggers
|
|||||||
|
|
||||||
$ret=$actioncomm->create($user); // User creating action
|
$ret=$actioncomm->create($user); // User creating action
|
||||||
|
|
||||||
|
if ($ret > 0 && $conf->global->MAIN_COPY_FILE_IN_EVENT_AUTO)
|
||||||
|
{
|
||||||
|
if (is_array($object->attachedfiles) && array_key_exists('paths',$object->attachedfiles) && count($object->attachedfiles['paths'])>0) {
|
||||||
|
foreach($object->attachedfiles['paths'] as $key=>$filespath) {
|
||||||
|
$srcfile = $filespath;
|
||||||
|
$destdir = $conf->agenda->dir_output . '/' . $ret;
|
||||||
|
$destfile = $destdir . '/' . $object->attachedfiles['names'][$key];
|
||||||
|
if (dol_mkdir($destdir) >= 0) {
|
||||||
|
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||||
|
dol_copy($srcfile, $destfile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
unset($object->actionmsg); unset($object->actionmsg2); unset($object->actiontypecode); // When several action are called on same object, we must be sure to not reuse value of first action.
|
unset($object->actionmsg); unset($object->actionmsg2); unset($object->actiontypecode); // When several action are called on same object, we must be sure to not reuse value of first action.
|
||||||
|
|
||||||
if ($ret > 0)
|
if ($ret > 0)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user