From 7c550fdba522195d0f1f5a337529da97df506858 Mon Sep 17 00:00:00 2001 From: gschratzer Date: Mon, 24 Aug 2015 16:05:15 +0200 Subject: [PATCH 1/6] New: IMAP dolimail Support --- htdocs/core/actions_sendmails.inc.php | 148 +++++++++++++++++++++++--- 1 file changed, 134 insertions(+), 14 deletions(-) diff --git a/htdocs/core/actions_sendmails.inc.php b/htdocs/core/actions_sendmails.inc.php index d27e6e59fb4..2da72b8074e 100644 --- a/htdocs/core/actions_sendmails.inc.php +++ b/htdocs/core/actions_sendmails.inc.php @@ -22,7 +22,7 @@ */ -// TODO Include this include file into all element pages allowing email sending +// TODO Include this include file into all class objects // $id must be defined // $actiontypecode must be defined @@ -47,7 +47,7 @@ if (GETPOST('addfile')) /* * 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'; @@ -60,11 +60,41 @@ if (! empty($_POST['removedfile'])) $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 */ -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']) { + if($conf->dolimail->enabled) $langs->load("dolimail@dolimail"); $langs->load('mails'); $subject='';$actionmsg='';$actionmsg2=''; @@ -81,7 +111,37 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO else if ($object->element == 'societe') { $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 (sizeof($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'); @@ -103,7 +163,7 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO } else // Id du contact { - $sendto = $thirdparty->contact_get_property((int) $_POST['receiver'],'email'); + $sendto = $thirdparty->contact_get_property($_POST['receiver'],'email'); $sendtoid = $_POST['receiver']; } } @@ -120,7 +180,7 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO } else // Id du contact { - $sendtocc = $thirdparty->contact_get_property((int) $_POST['receivercc'],'email'); + $sendtocc = $thirdparty->contact_get_property($_POST['receivercc'],'email'); } } @@ -160,12 +220,50 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO $filepath = $attachedfiles['paths']; $filename = $attachedfiles['names']; $mimetype = $attachedfiles['mimes']; + + if($conf->dolimail->enabled) + { + $mailfromid = explode ("#", $_POST['frommail'],3); + if (sizeof($mailfromid)==0) $from = $_POST['fromname'] . ' <' . $_POST['frommail'] .'>'; + else + { + $mbid = $mailfromid[1]; - $trackid = GETPOST('trackid','aZ'); - + /*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 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); if ($mailfile->error) { $mesgs[]='
'.$mailfile->error.'
'; @@ -176,7 +274,26 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO if ($result) { $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 $object->socid = $sendtosocid; // To link to a company $object->sendtoid = $sendtoid; // To link to a contact/address @@ -205,24 +322,27 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO // 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)); 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; } } else { $langs->load("other"); + $mesg='
'; if ($mailfile->error) { - $mesg=''; $mesg.=$langs->trans('ErrorFailedToSendMail',$from,$sendto); $mesg.='
'.$mailfile->error; - setEventMessage($mesg,'errors'); } else { - setEventMessage('No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', 'warnings'); + $mesg.='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS'; } + $mesg.='
'; + + setEventMessage($mesg,'warnings'); $action = 'presend'; } } From bf00b5d7957e98456c92813db34ea88476029b14 Mon Sep 17 00:00:00 2001 From: gschratzer Date: Mon, 24 Aug 2015 16:22:21 +0200 Subject: [PATCH 2/6] New: IMAP dolimail Support --- htdocs/core/actions_sendmails.inc.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/htdocs/core/actions_sendmails.inc.php b/htdocs/core/actions_sendmails.inc.php index 2da72b8074e..2c7d0063905 100644 --- a/htdocs/core/actions_sendmails.inc.php +++ b/htdocs/core/actions_sendmails.inc.php @@ -163,7 +163,7 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO } else // Id du contact { - $sendto = $thirdparty->contact_get_property($_POST['receiver'],'email'); + $sendto = $thirdparty->contact_get_property((int) $_POST['receiver'],'email'); $sendtoid = $_POST['receiver']; } } @@ -180,7 +180,7 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO } else // Id du contact { - $sendtocc = $thirdparty->contact_get_property($_POST['receivercc'],'email'); + $sendtocc = $thirdparty->contact_get_property((int) $_POST['receivercc'],'email'); } } @@ -220,7 +220,9 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO $filepath = $attachedfiles['paths']; $filename = $attachedfiles['names']; $mimetype = $attachedfiles['mimes']; - + + $trackid = GETPOST('trackid','aZ'); + if($conf->dolimail->enabled) { $mailfromid = explode ("#", $_POST['frommail'],3); @@ -263,7 +265,7 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO } // Send mail require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; - $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,$sendtobcc,$deliveryreceipt,-1); + $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,$sendtobcc,$deliveryreceipt,-1,'','',$trackid); if ($mailfile->error) { $mesgs[]='
'.$mailfile->error.'
'; From 0aabf5eb08bca9b5ec1d6a2a35e3fc06088cec51 Mon Sep 17 00:00:00 2001 From: Guido Schratzer Date: Mon, 24 Aug 2015 16:35:08 +0200 Subject: [PATCH 3/6] Update actions_sendmails.inc.php --- htdocs/core/actions_sendmails.inc.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/actions_sendmails.inc.php b/htdocs/core/actions_sendmails.inc.php index 2c7d0063905..93c495077ec 100644 --- a/htdocs/core/actions_sendmails.inc.php +++ b/htdocs/core/actions_sendmails.inc.php @@ -22,7 +22,7 @@ */ -// TODO Include this include file into all class objects +// TODO Include this include file into all element pages allowing email sending // $id must be defined // $actiontypecode must be defined @@ -92,7 +92,7 @@ if(! empty($_POST['removAll'])) /* * Send mail */ -if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_POST['removAll'] && ! $_POST['removedfile'] && ! $_POST['cancel']) +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'); From 16268e9f0a5fe8d82a5db1a68227b9f9507c36c0 Mon Sep 17 00:00:00 2001 From: gschratzer Date: Tue, 25 Aug 2015 17:05:08 +0200 Subject: [PATCH 4/6] New: function calculate_byte --- htdocs/core/lib/files.lib.php | 328 ++++++++++++++++++++++++++++++++++ 1 file changed, 328 insertions(+) diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index 2f197d8b645..ecfb71d252b 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -202,6 +202,334 @@ 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 string $module_get Starting path from which to search + * @param int $fk_soc select socid - for your selection in array + * @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($module_get = false, $fk_soc, $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 (sizeof($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 (sizeof($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(sizeof($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" && sizeof($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" && sizeof($output["invoice"])>0) + { + foreach($output["invoice"] as $label => $filedata) + { + $output[$curmodule][$label]['subject'] = $filedata['level1name']; + } + } + + // Extra for Mail attachments + if($curmodule == "invoice_supplier" && sizeof($output["invoice_supplier"])>0) + { + foreach($output["invoice_supplier"] as $label => $filedata) + { + $output[$curmodule][$label]['subject'] = $filedata['level1name']; + } + } + + // Extra for Mail attachments + if($curmodule == "contract" && sizeof($output["contract"])>0) + { + foreach($output["contract"] as $label => $filedata) + { + $output[$curmodule][$label]['subject'] = $filedata['level1name']; + } + } + + $xy++; + } + + if(sizeof($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 * From 2f08ddef5485ea497ec2d0a50fc63b65c8a0ce0d Mon Sep 17 00:00:00 2001 From: Niklas Spanring Date: Wed, 26 Aug 2015 15:04:50 +0200 Subject: [PATCH 5/6] Fix: travis-ci error actions_sendmails.inc.php error line="124""The use of function sizeof() is forbidden; use count() instead" error line="229" "The use of function sizeof() is forbidden; use count() instead" --- htdocs/core/actions_sendmails.inc.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/actions_sendmails.inc.php b/htdocs/core/actions_sendmails.inc.php index 93c495077ec..67458fd401d 100644 --- a/htdocs/core/actions_sendmails.inc.php +++ b/htdocs/core/actions_sendmails.inc.php @@ -121,7 +121,7 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO { setEventMessage($langs->trans('ErrorFailedToFindSocieteRecord',$_POST['sendto']),'errors'); } - elseif (sizeof($possibleaccounts)>1) + elseif (count($possibleaccounts)>1) { $sendtosocid=$possibleaccounts[1]['id']; $result=$object->fetch($sendtosocid); @@ -226,7 +226,7 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO if($conf->dolimail->enabled) { $mailfromid = explode ("#", $_POST['frommail'],3); - if (sizeof($mailfromid)==0) $from = $_POST['fromname'] . ' <' . $_POST['frommail'] .'>'; + if (count($mailfromid)==0) $from = $_POST['fromname'] . ' <' . $_POST['frommail'] .'>'; else { $mbid = $mailfromid[1]; From 53a02e5863bbae36a1f22511631dc3938703b7a3 Mon Sep 17 00:00:00 2001 From: Niklas Spanring Date: Wed, 26 Aug 2015 15:12:17 +0200 Subject: [PATCH 6/6] Fix: travis-ci error files.lib.php error line="215" message="There must be no blank lines after the function comment" error line="217" message="Arguments with default values must be at the end of the argument list" error line="248" message="The use of function sizeof() is forbidden; use count() instead" error line="303" message="The use of function sizeof() is forbidden; use count() instead" error line="447" message="The use of function sizeof() is forbidden; use count() instead" error line="456" message="The use of function sizeof() is forbidden; use count() instead" error line="465" message="The use of function sizeof() is forbidden; use count() instead" error line="474" message="The use of function sizeof() is forbidden; use count() instead" error line="483" message="The use of function sizeof() is forbidden; use count() instead" error line="494" message="The use of function sizeof() is forbidden; use count() instead" error line="510" message="There must be no blank lines after the function comment" --- htdocs/core/lib/files.lib.php | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index ecfb71d252b..8f6471f4af0 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -202,19 +202,17 @@ 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 int $fk_soc select socid - for your selection in array - * @param string $sortorder SORT_ASC or SORT_DESC + * @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')))) + * @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($module_get = false, $fk_soc, $sortorder = false, $excludefiles = false) +function get_soc_file_array($fk_soc, $module_get = false, $sortorder = false, $excludefiles = false) { global $user, $conf, $db; @@ -245,7 +243,7 @@ function get_soc_file_array($module_get = false, $fk_soc, $sortorder = false, $e // rights - if (sizeof($ar_modules_get) > 0) + if (count($ar_modules_get) > 0) foreach($ar_modules_get as $curmodule) { switch($curmodule) @@ -300,7 +298,7 @@ function get_soc_file_array($module_get = false, $fk_soc, $sortorder = false, $e $ar_modules_get = $ar_modules_secure; $xy=0; - if (sizeof($ar_modules_get)>0) + if (count($ar_modules_get)>0) foreach($ar_modules_get as $curmodule => $myarray) { if($fk_soc > 0 && $curmodule != "company") @@ -444,7 +442,7 @@ function get_soc_file_array($module_get = false, $fk_soc, $sortorder = false, $e } } // Error if ther isn't any File - if(sizeof($output[$curmodule]) == 0) + if(count($output[$curmodule]) == 0) { $error++; $errors[]="Error [404]: No File found for User: ".$fk_soc." in module: ".$curmodule; @@ -453,7 +451,7 @@ function get_soc_file_array($module_get = false, $fk_soc, $sortorder = false, $e } // Extra for Mail attachments - if($curmodule == "dolimail" && sizeof($output["dolimail"])>0) + if($curmodule == "dolimail" && count($output["dolimail"])>0) { foreach($output["dolimail"] as $label => $filedata) { @@ -462,7 +460,7 @@ function get_soc_file_array($module_get = false, $fk_soc, $sortorder = false, $e } // Extra for Mail attachments - if($curmodule == "invoice" && sizeof($output["invoice"])>0) + if($curmodule == "invoice" && count($output["invoice"])>0) { foreach($output["invoice"] as $label => $filedata) { @@ -471,7 +469,7 @@ function get_soc_file_array($module_get = false, $fk_soc, $sortorder = false, $e } // Extra for Mail attachments - if($curmodule == "invoice_supplier" && sizeof($output["invoice_supplier"])>0) + if($curmodule == "invoice_supplier" && count($output["invoice_supplier"])>0) { foreach($output["invoice_supplier"] as $label => $filedata) { @@ -480,7 +478,7 @@ function get_soc_file_array($module_get = false, $fk_soc, $sortorder = false, $e } // Extra for Mail attachments - if($curmodule == "contract" && sizeof($output["contract"])>0) + if($curmodule == "contract" && count($output["contract"])>0) { foreach($output["contract"] as $label => $filedata) { @@ -491,7 +489,7 @@ function get_soc_file_array($module_get = false, $fk_soc, $sortorder = false, $e $xy++; } - if(sizeof($output) > 0) + if(count($output) > 0) { return $output; } @@ -501,15 +499,12 @@ function get_soc_file_array($module_get = false, $fk_soc, $sortorder = false, $e } } - /** * Calculate Bytes to kb, mb and translate it to current language * - * @param int $byt Bytes - * @return string calculated string + * @param int $byt Bytes + * @return string calculated string */ - - function calculate_byte($byt) { global $langs;