Merge pull request #3412 from gschratzer/develop
NEW update actions_sendmails.inc.php files.inc.php
This commit is contained in:
commit
2a8ebcefcc
@ -47,7 +47,7 @@ if (GETPOST('addfile'))
|
|||||||
/*
|
/*
|
||||||
* Remove file in email form
|
* Remove file in email form
|
||||||
*/
|
*/
|
||||||
if (! empty($_POST['removedfile']))
|
if (! empty($_POST['removedfile']) && empty($_POST['removAll']))
|
||||||
{
|
{
|
||||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||||
|
|
||||||
@ -60,11 +60,41 @@ if (! empty($_POST['removedfile']))
|
|||||||
$action='presend';
|
$action='presend';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Remove all files in email form
|
||||||
|
*/
|
||||||
|
|
||||||
|
if(! empty($_POST['removAll']))
|
||||||
|
{
|
||||||
|
$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"]);
|
||||||
|
|
||||||
|
include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
|
||||||
|
$formmail = new FormMail($db);
|
||||||
|
|
||||||
|
foreach($listofpaths as $key => $value)
|
||||||
|
{
|
||||||
|
$pathtodelete = $value;
|
||||||
|
$filetodelete = $listofnames[$key];
|
||||||
|
$result = dol_delete_file($pathtodelete,1); // Delete uploded Files
|
||||||
|
|
||||||
|
$langs->load("other");
|
||||||
|
setEventMessage($langs->trans("FileWasRemoved",$filetodelete));
|
||||||
|
|
||||||
|
$formmail->remove_attached_files($key); // Update Session
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Send mail
|
* Send mail
|
||||||
*/
|
*/
|
||||||
if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_POST['removedfile'] && ! $_POST['cancel'] && !$_POST['modelselected'])
|
if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_POST['removAll'] && ! $_POST['removedfile'] && ! $_POST['cancel'] && !$_POST['modelselected'])
|
||||||
{
|
{
|
||||||
|
if($conf->dolimail->enabled) $langs->load("dolimail@dolimail");
|
||||||
$langs->load('mails');
|
$langs->load('mails');
|
||||||
|
|
||||||
$subject='';$actionmsg='';$actionmsg2='';
|
$subject='';$actionmsg='';$actionmsg2='';
|
||||||
@ -81,7 +111,37 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
|
|||||||
else if ($object->element == 'societe')
|
else if ($object->element == 'societe')
|
||||||
{
|
{
|
||||||
$thirdparty=$object;
|
$thirdparty=$object;
|
||||||
$sendtosocid=$thirdparty->id;
|
if ($thirdparty->id > 0) $sendtosocid=$thirdparty->id;
|
||||||
|
elseif($conf->dolimail->enabled)
|
||||||
|
{
|
||||||
|
$dolimail = new Dolimail($db);
|
||||||
|
$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
|
||||||
|
if (!$possibleaccounts && !$possibleuser)
|
||||||
|
{
|
||||||
|
setEventMessage($langs->trans('ErrorFailedToFindSocieteRecord',$_POST['sendto']),'errors');
|
||||||
|
}
|
||||||
|
elseif (count($possibleaccounts)>1)
|
||||||
|
{
|
||||||
|
$sendtosocid=$possibleaccounts[1]['id'];
|
||||||
|
$result=$object->fetch($sendtosocid);
|
||||||
|
|
||||||
|
setEventMessage($langs->trans('ErrorFoundMoreThanOneRecordWithEmail',$_POST['sendto'],$object->name));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if($possibleaccounts){
|
||||||
|
$sendtosocid=$possibleaccounts[1]['id'];
|
||||||
|
$result=$object->fetch($sendtosocid);
|
||||||
|
}elseif($possibleuser){
|
||||||
|
$sendtosocid=$possibleuser[0]['id'];
|
||||||
|
|
||||||
|
$result=$uobject->fetch($sendtosocid);
|
||||||
|
$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');
|
||||||
|
|
||||||
@ -163,6 +223,46 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
|
|||||||
|
|
||||||
$trackid = GETPOST('trackid','aZ');
|
$trackid = GETPOST('trackid','aZ');
|
||||||
|
|
||||||
|
if($conf->dolimail->enabled)
|
||||||
|
{
|
||||||
|
$mailfromid = explode ("#", $_POST['frommail'],3);
|
||||||
|
if (count($mailfromid)==0) $from = $_POST['fromname'] . ' <' . $_POST['frommail'] .'>';
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$mbid = $mailfromid[1];
|
||||||
|
|
||||||
|
/*IMAP Postbox*/
|
||||||
|
$mailboxconfig = new IMAP($db);
|
||||||
|
$mailboxconfig->fetch($mbid);
|
||||||
|
if ($mailboxconfig->mailbox_imap_host) $ref=$mailboxconfig->get_ref();
|
||||||
|
|
||||||
|
$mailboxconfig->folder_id=$mailboxconfig->mailbox_imap_outbox;
|
||||||
|
$mailboxconfig->userfolder_fetch();
|
||||||
|
|
||||||
|
if ($mailboxconfig->mailbox_save_sent_mails == 1)
|
||||||
|
{
|
||||||
|
|
||||||
|
$folder=str_replace($ref, '', $mailboxconfig->folder_cache_key);
|
||||||
|
if (!$folder) $folder = "Sent";
|
||||||
|
|
||||||
|
$mailboxconfig->mbox = imap_open($mailboxconfig->get_connector_url().$folder, $mailboxconfig->mailbox_imap_login, $mailboxconfig->mailbox_imap_password);
|
||||||
|
if (FALSE === $mailboxconfig->mbox)
|
||||||
|
{
|
||||||
|
$info = FALSE;
|
||||||
|
$err = $langs->trans('Error3_Imap_Connection_Error');
|
||||||
|
setEventMessage($err,$mailboxconfig->element,'errors');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$mailboxconfig->mailboxid=$_POST['frommail'];
|
||||||
|
$mailboxconfig->foldername=$folder;
|
||||||
|
$from = $mailfromid[0] . $mailfromid[2];
|
||||||
|
$imap=1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
// Send mail
|
// Send mail
|
||||||
require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
|
require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
|
||||||
$mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,$sendtobcc,$deliveryreceipt,-1,'','',$trackid);
|
$mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,$sendtobcc,$deliveryreceipt,-1,'','',$trackid);
|
||||||
@ -176,6 +276,25 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
|
|||||||
if ($result)
|
if ($result)
|
||||||
{
|
{
|
||||||
$error=0;
|
$error=0;
|
||||||
|
if($conf->dolimail->enabled)
|
||||||
|
{
|
||||||
|
$mid = (GETPOST('mid','int') ? GETPOST('mid','int') : 0);
|
||||||
|
if ($mid)
|
||||||
|
{
|
||||||
|
// set imap flag answered if it is a answered mail
|
||||||
|
|
||||||
|
$dolimail=new DoliMail($db);
|
||||||
|
$dolimail->id = $mid;
|
||||||
|
$res=$dolimail->set_prop($user, 'answered',1);
|
||||||
|
}
|
||||||
|
if ($imap==1)
|
||||||
|
{
|
||||||
|
// write mail to IMAP Server
|
||||||
|
$movemail = $mailboxconfig->putMail($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,$folder,$deliveryreceipt,$mailfile);
|
||||||
|
if ($movemail) setEventMessage($langs->trans("MailMovedToImapFolder",$folder),'mesgs');
|
||||||
|
else setEventMessage($langs->trans("MailMovedToImapFolder_Warning",$folder),'warnings');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Initialisation donnees
|
// Initialisation donnees
|
||||||
$object->socid = $sendtosocid; // To link to a company
|
$object->socid = $sendtosocid; // To link to a company
|
||||||
@ -205,24 +324,27 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
|
|||||||
// This avoid sending mail twice if going out and then back to page
|
// This avoid sending mail twice if going out and then back to page
|
||||||
$mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($from,2),$mailfile->getValidAddress($sendto,2));
|
$mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($from,2),$mailfile->getValidAddress($sendto,2));
|
||||||
setEventMessage($mesg);
|
setEventMessage($mesg);
|
||||||
header('Location: '.$_SERVER["PHP_SELF"].'?'.($paramname?$paramname:'id').'='.$object->id);
|
if($conf->dolimail->enabled) header('Location: '.$_SERVER["PHP_SELF"].'?'.($paramname?$paramname:'id').'='.$object->id.'&'.($paramname2?$paramname2:'mid').'='.$parm2val);
|
||||||
|
else header('Location: '.$_SERVER["PHP_SELF"].'?'.($paramname?$paramname:'id').'='.$object->id);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$langs->load("other");
|
$langs->load("other");
|
||||||
|
$mesg='<div class="error">';
|
||||||
if ($mailfile->error)
|
if ($mailfile->error)
|
||||||
{
|
{
|
||||||
$mesg='';
|
|
||||||
$mesg.=$langs->trans('ErrorFailedToSendMail',$from,$sendto);
|
$mesg.=$langs->trans('ErrorFailedToSendMail',$from,$sendto);
|
||||||
$mesg.='<br>'.$mailfile->error;
|
$mesg.='<br>'.$mailfile->error;
|
||||||
setEventMessage($mesg,'errors');
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
setEventMessage('No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', 'warnings');
|
$mesg.='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
|
||||||
}
|
}
|
||||||
|
$mesg.='</div>';
|
||||||
|
|
||||||
|
setEventMessage($mesg,'warnings');
|
||||||
$action = 'presend';
|
$action = 'presend';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -202,6 +202,329 @@ function dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefil
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scan a directory and return a array of files/directories from a selection.
|
||||||
|
* Content for string is UTF8 and dir separator is "/".
|
||||||
|
*
|
||||||
|
* @param int $fk_soc select socid - for your selection in array
|
||||||
|
* @param string $module_get Starting path from which to search
|
||||||
|
* @param string $sortorder SORT_ASC or SORT_DESC
|
||||||
|
* @param array $excludefiles Array of Regex for exclude filter (example: array('(\.meta|_preview\.png)$','^\.'))
|
||||||
|
* @return array Array of array( filefolder=> array( filelabel=> array( file=> array('name'=>'xxx','date'=>'yyy','size'=>99,'type'=>'dir|file'))))
|
||||||
|
*/
|
||||||
|
function get_soc_file_array($fk_soc, $module_get = false, $sortorder = false, $excludefiles = false)
|
||||||
|
{
|
||||||
|
global $user, $conf, $db;
|
||||||
|
|
||||||
|
$sortfield = "date";
|
||||||
|
|
||||||
|
if(!$sortorder){
|
||||||
|
$sorting = SORT_DESC;
|
||||||
|
}else{
|
||||||
|
$sorting = $sortorder;
|
||||||
|
}
|
||||||
|
|
||||||
|
$ar_modules_get = array();
|
||||||
|
if (is_array($module_get)) $ar_modules_get = $module_get;
|
||||||
|
elseif (strlen($module_get) > 0) $ar_modules_get[$module_get] = $module_get;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$ar_modules_get['company'] = 'company';
|
||||||
|
$ar_modules_get['dolimail'] = 'dolimail';
|
||||||
|
$ar_modules_get['actions'] = 'actions';
|
||||||
|
$ar_modules_get['invoice'] = 'invoice';
|
||||||
|
$ar_modules_get['order'] = 'order';
|
||||||
|
$ar_modules_get['propal'] = 'propal';
|
||||||
|
$ar_modules_get['contract'] = 'contract';
|
||||||
|
$ar_modules_get['project'] = 'project';
|
||||||
|
$ar_modules_get['invoice_supplier'] = 'invoice_supplier';
|
||||||
|
$ar_modules_get['order_supplier'] = 'order_supplier';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// rights
|
||||||
|
if (count($ar_modules_get) > 0)
|
||||||
|
foreach($ar_modules_get as $curmodule)
|
||||||
|
{
|
||||||
|
switch($curmodule)
|
||||||
|
{
|
||||||
|
case 'company':
|
||||||
|
if (! empty($conf->societe->enabled)) // Recht Alle oder nur die Vertriebspartneradressen
|
||||||
|
$ar_modules_secure['company']['outputdir'] = $conf->societe->dir_output;
|
||||||
|
break;
|
||||||
|
case 'dolimail':
|
||||||
|
if (! empty($conf->dolimail->enabled) && ($user->rights->dolimail->read || $user->admin))
|
||||||
|
$ar_modules_secure[$curmodule]['outputdir']=$conf->dolimail->dir_output.'/attachments';
|
||||||
|
break;
|
||||||
|
case 'actions':
|
||||||
|
if (! empty($conf->agenda->enabled) || ($user->rights->agenda->allactions->read || $user->admin))
|
||||||
|
$ar_modules_secure[$curmodule]['outputdir']=$conf->agenda->dir_output;
|
||||||
|
break;
|
||||||
|
case 'invoice':
|
||||||
|
if (! empty($conf->facture->enabled) && ($user->rights->facture->lire || $user->admin))
|
||||||
|
$ar_modules_secure[$curmodule]['outputdir']=$conf->facture->dir_output;
|
||||||
|
break;
|
||||||
|
case 'order':
|
||||||
|
if (!empty($conf->commande->enabled) && ($user->rights->commande->lire || $user->admin))
|
||||||
|
$ar_modules_secure[$curmodule]['outputdir']=$conf->commande->dir_output;
|
||||||
|
break;
|
||||||
|
case 'propal':
|
||||||
|
if (!empty($conf->propal->enabled) && ($user->rights->propale->lire || $user->admin))
|
||||||
|
$ar_modules_secure[$curmodule]['outputdir']=$conf->propal->dir_output;
|
||||||
|
break;
|
||||||
|
case 'project':
|
||||||
|
if (! empty($conf->projet->enabled) && ($user->rights->projet->lire || $user->admin))
|
||||||
|
$ar_modules_secure[$curmodule]['outputdir']=$conf->projet->dir_output;
|
||||||
|
break;
|
||||||
|
case 'invoice_supplier':
|
||||||
|
if (! empty($conf->fournisseur->enabled) && ($user->rights->fournisseur->facture->lire || $user->admin))
|
||||||
|
$ar_modules_secure[$curmodule]['outputdir']=$conf->fournisseur->dir_output.'/facture';
|
||||||
|
break;
|
||||||
|
case 'order_supplier':
|
||||||
|
if (! empty($conf->fournisseur->enabled) && ($user->rights->fournisseur->commande->lire || $user->admin))
|
||||||
|
$ar_modules_secure[$curmodule]['outputdir']=$conf->fournisseur->dir_output.'/commande';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* TODO make a outputdir*/
|
||||||
|
//unset($ar_modules_secure['dolimail']);
|
||||||
|
unset($ar_modules_secure['project']); // project (list with project) is "ref"
|
||||||
|
unset($ar_modules_secure['actions']);
|
||||||
|
unset($ar_modules_secure['contract']);
|
||||||
|
/* TODO make a outputdir*/
|
||||||
|
unset($curmodule);
|
||||||
|
|
||||||
|
if($fk_soc > 0)
|
||||||
|
$ar_modules_get = $ar_modules_secure;
|
||||||
|
|
||||||
|
$xy=0;
|
||||||
|
if (count($ar_modules_get)>0)
|
||||||
|
foreach($ar_modules_get as $curmodule => $myarray)
|
||||||
|
{
|
||||||
|
if($fk_soc > 0 && $curmodule != "company")
|
||||||
|
{
|
||||||
|
|
||||||
|
// SQL to find documents (ref number)
|
||||||
|
|
||||||
|
if($curmodule == "invoice") $sql = "SELECT facnumber as refstr FROM ".MAIN_DB_PREFIX."facture";
|
||||||
|
elseif($curmodule == "order") $sql = "SELECT ref as refstr FROM ".MAIN_DB_PREFIX."commande";
|
||||||
|
elseif($curmodule == "invoice_supplier") $sql = "SELECT rowid as refstr FROM ".MAIN_DB_PREFIX."facture_fourn";
|
||||||
|
elseif($curmodule == "order_supplier") $sql = "SELECT ref as refstr FROM ".MAIN_DB_PREFIX."commande_fournisseur";
|
||||||
|
elseif($curmodule == "propal") $sql = "SELECT ref as refstr FROM ".MAIN_DB_PREFIX."propal";
|
||||||
|
elseif($curmodule == "contract") $sql = "SELECT ref as refstr FROM ".MAIN_DB_PREFIX."contrat";
|
||||||
|
elseif($curmodule == "dolimail") $sql = "SELECT uid as refstr, subject FROM ".MAIN_DB_PREFIX."mails";
|
||||||
|
|
||||||
|
$sql.= ' WHERE entity IN ('.getEntity('societe', 1).')';
|
||||||
|
$sql.= " AND fk_soc = '".$fk_soc."'";
|
||||||
|
|
||||||
|
|
||||||
|
$res = $db->query($sql);
|
||||||
|
if ($res && $db->num_rows($res) > 0)
|
||||||
|
{
|
||||||
|
while($obj = $db->fetch_object($res))
|
||||||
|
{
|
||||||
|
$ar_modules_secure[$curmodule]['socref'][] = $obj->refstr;
|
||||||
|
if($curmodule == "dolimail") $ar_modules_secure['dolimail']['subject'][$obj->refstr] = $obj->subject;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
unset($ar_modules_secure[$curmodule]);
|
||||||
|
continue;
|
||||||
|
$errors[]="SQL Error: ".$sql;
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}else{
|
||||||
|
if($curmodule == "dolimail") $sql = "SELECT uid as refstr, subject FROM ".MAIN_DB_PREFIX."mails";
|
||||||
|
|
||||||
|
$res = $db->query($sql);
|
||||||
|
if ($res && $db->num_rows($res) > 0)
|
||||||
|
{
|
||||||
|
while($obj = $db->fetch_object($res))
|
||||||
|
{
|
||||||
|
if($curmodule == "dolimail") $ar_modules_secure['dolimail']['subject'][$obj->refstr] = $obj->subject;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Data in Array
|
||||||
|
// Get Array from ar_module
|
||||||
|
|
||||||
|
$output[$curmodule]=dol_dir_list($myarray['outputdir'],"files",1,'', $excludefiles, $sortfield, $sorting,1);
|
||||||
|
if($fk_soc > 0)
|
||||||
|
{
|
||||||
|
if($curmodule == "company")
|
||||||
|
{
|
||||||
|
foreach($output["company"] as $label => $filedata)
|
||||||
|
{
|
||||||
|
if($filedata['level1name'] != $fk_soc)
|
||||||
|
{
|
||||||
|
unset($output['company'][$label]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
elseif($curmodule == "invoice")
|
||||||
|
{
|
||||||
|
if (! is_array($ar_modules_secure[$curmodule]['socref'])) { unset($output[$curmodule]); continue; } // wenn no file exsit
|
||||||
|
foreach($output["invoice"] as $label => $filedata)
|
||||||
|
{
|
||||||
|
if (! in_array($filedata['level1name'], $ar_modules_secure[$curmodule]['socref']))
|
||||||
|
{
|
||||||
|
unset($output[$curmodule][$label]); // throw all ref number who are not in ($fac_supp_N_arr) array
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
elseif($curmodule == "invoice_supplier")
|
||||||
|
{
|
||||||
|
if (! is_array($ar_modules_secure[$curmodule]['socref'])) { unset($output[$curmodule]); } // throw all ref number who are not in ($fac_invoice_arr) array
|
||||||
|
foreach($output["invoice_supplier"] as $label => $filedata)
|
||||||
|
{
|
||||||
|
if (! in_array($filedata['level1name'], $ar_modules_secure[$curmodule]['socref'])) {
|
||||||
|
unset($output[$curmodule][$label]); // throw all ref number who are not in ($fac_supp_N_arr) array
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
elseif($curmodule == "order")
|
||||||
|
{
|
||||||
|
if (! is_array($ar_modules_secure[$curmodule]['socref'])) { unset($output[$curmodule]); continue; } // throw all ref number who are not in ($fac_invoice_arr) array
|
||||||
|
foreach($output["order"] as $label => $filedata)
|
||||||
|
{
|
||||||
|
if (! in_array($filedata['level1name'], $ar_modules_secure[$curmodule]['socref'])) {
|
||||||
|
unset($output[$curmodule][$label]); // throw all ref number who are not in ($ref_order_arr) array
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
elseif($curmodule == "order_supplier")
|
||||||
|
{
|
||||||
|
if (! is_array($ar_modules_secure[$curmodule]['socref'])) { unset($output[$curmodule]); continue; } // throw all ref number who are not in ($fac_invoice_arr) array
|
||||||
|
foreach($output["order_supplier"] as $label => $filedata)
|
||||||
|
{
|
||||||
|
if (! in_array($filedata['level1name'], $ar_modules_secure[$curmodule]['socref'])) {
|
||||||
|
unset($output[$curmodule][$label]); // throw all ref number who are not in ($ref_order_supp_arr) array
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
elseif($curmodule == "propal")
|
||||||
|
{
|
||||||
|
if (! is_array($ar_modules_secure[$curmodule]['socref'])) { unset($output[$curmodule]); continue; } // throw all ref number who are not in ($fac_invoice_arr) array
|
||||||
|
foreach($output["propal"] as $label => $filedata)
|
||||||
|
{
|
||||||
|
if (! in_array($filedata['level1name'], $ar_modules_secure[$curmodule]['socref'])) {
|
||||||
|
unset($output[$curmodule][$label]); // throw all ref number who are not in ($ref_propal_arr) array
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
elseif($curmodule == "contract")
|
||||||
|
{
|
||||||
|
if (! is_array($ar_modules_secure[$curmodule]['socref'])) { unset($output[$curmodule]); continue; } // throw all ref number who are not in ($fac_invoice_arr) array
|
||||||
|
foreach($output["contract"] as $label => $filedata)
|
||||||
|
{
|
||||||
|
if (! in_array($filedata['level1name'], $ar_modules_secure[$curmodule]['socref'])) {
|
||||||
|
unset($output[$curmodule][$label]); // throw all ref number who are not in ($ref_contract_arr) array
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
elseif($curmodule == "dolimail")
|
||||||
|
{
|
||||||
|
|
||||||
|
if (! is_array($ar_modules_secure[$curmodule]['socref'])) { unset($output[$curmodule]); continue; } // throw all ref number who are not in ($fac_invoice_arr) array
|
||||||
|
foreach($output["dolimail"] as $label => $filedata)
|
||||||
|
{
|
||||||
|
if($filedata['name'] == "winmail.dat" || $filedata['name'] == "smime.p7s") unset($output[$curmodule][$label]);
|
||||||
|
else
|
||||||
|
if (! in_array($filedata['level1name'], $ar_modules_secure[$curmodule]['socref'])) {
|
||||||
|
unset($output[$curmodule][$label]); // throw all ref number who are not in ($ref_propal_arr) array
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Error if ther isn't any File
|
||||||
|
if(count($output[$curmodule]) == 0)
|
||||||
|
{
|
||||||
|
$error++;
|
||||||
|
$errors[]="Error [404]: No File found for User: ".$fk_soc." in module: ".$curmodule;
|
||||||
|
unset($output[$curmodule]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extra for Mail attachments
|
||||||
|
if($curmodule == "dolimail" && count($output["dolimail"])>0)
|
||||||
|
{
|
||||||
|
foreach($output["dolimail"] as $label => $filedata)
|
||||||
|
{
|
||||||
|
$output[$curmodule][$label]['subject'] = $ar_modules_secure['dolimail']['subject'][$filedata['level1name']];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extra for Mail attachments
|
||||||
|
if($curmodule == "invoice" && count($output["invoice"])>0)
|
||||||
|
{
|
||||||
|
foreach($output["invoice"] as $label => $filedata)
|
||||||
|
{
|
||||||
|
$output[$curmodule][$label]['subject'] = $filedata['level1name'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extra for Mail attachments
|
||||||
|
if($curmodule == "invoice_supplier" && count($output["invoice_supplier"])>0)
|
||||||
|
{
|
||||||
|
foreach($output["invoice_supplier"] as $label => $filedata)
|
||||||
|
{
|
||||||
|
$output[$curmodule][$label]['subject'] = $filedata['level1name'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extra for Mail attachments
|
||||||
|
if($curmodule == "contract" && count($output["contract"])>0)
|
||||||
|
{
|
||||||
|
foreach($output["contract"] as $label => $filedata)
|
||||||
|
{
|
||||||
|
$output[$curmodule][$label]['subject'] = $filedata['level1name'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$xy++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(count($output) > 0)
|
||||||
|
{
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculate Bytes to kb, mb and translate it to current language
|
||||||
|
*
|
||||||
|
* @param int $byt Bytes
|
||||||
|
* @return string calculated string
|
||||||
|
*/
|
||||||
|
function calculate_byte($byt)
|
||||||
|
{
|
||||||
|
global $langs;
|
||||||
|
|
||||||
|
if ($byt < 1024) {
|
||||||
|
$unit = ' '.$langs->trans("b");
|
||||||
|
$mailsize=$byt;
|
||||||
|
} else if ($byt / 1024 > 1024) {
|
||||||
|
$mailsize = $byt / 1024 / 1024;
|
||||||
|
$unit = ' '.$langs->trans("Mb");
|
||||||
|
} else {
|
||||||
|
$mailsize = $byt / 1024;
|
||||||
|
$unit = ' '.$langs->trans("Kb");
|
||||||
|
}
|
||||||
|
|
||||||
|
$val = number_format($mailsize, 2).$unit;
|
||||||
|
|
||||||
|
return $val;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fast compare of 2 files identified by their properties ->name, ->date and ->size
|
* Fast compare of 2 files identified by their properties ->name, ->date and ->size
|
||||||
*
|
*
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user