From d0efc41983e91c8a5d0e3bc739de30a1db41fd70 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 20 Apr 2018 14:50:11 +0200 Subject: [PATCH] New support of option BANK_ACCOUNT_ALLOW_EXTERNAL_DOWNLOAD --- htdocs/core/class/commonobject.class.php | 5 +++- htdocs/core/lib/functions.lib.php | 6 ++--- htdocs/ecm/class/ecmfiles.class.php | 31 +++++++++++++++--------- htdocs/societe/paymentmodes.php | 29 ++++++++++++++++++++-- 4 files changed, 53 insertions(+), 18 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index c912ae98b4c..f7e0d451506 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -599,7 +599,7 @@ abstract class CommonObject if (empty($this->last_main_doc)) { - return ''; // No known last doc + return ''; // No way to known which document name to use } include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; @@ -4387,6 +4387,9 @@ abstract class CommonObject $ecmfile->gen_or_uploaded = 'generated'; $ecmfile->description = ''; // indexed content $ecmfile->keyword = ''; // keyword content + $ecmfile->src_object_type = $this->table_element; + $ecmfile->src_object_id = $this->id; + $result = $ecmfile->create($user); if ($result < 0) { diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 2faf8082056..4cbb3043bda 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -7219,10 +7219,10 @@ function natural_search($fields, $value, $mode=0, $nofirstand=0) } /** - * Return string with full Url + * Return string with full Url. The file qualified is the one defined by relative path in $object->last_main_doc * - * @param Object $object Object - * @return string Url string + * @param Object $object Object + * @return string Url string */ function showDirectDownloadLink($object) { diff --git a/htdocs/ecm/class/ecmfiles.class.php b/htdocs/ecm/class/ecmfiles.class.php index 5581d10fe7a..f1c0b6b1448 100644 --- a/htdocs/ecm/class/ecmfiles.class.php +++ b/htdocs/ecm/class/ecmfiles.class.php @@ -167,13 +167,13 @@ class EcmFiles extends CommonObject $obj = $this->db->fetch_object($resql); $maxposition = (int) $obj->maxposition; } - else + else { $this->errors[] = 'Error ' . $this->db->lasterror(); return --$error; } $maxposition=$maxposition+1; - } + } else { $maxposition=$this->position; @@ -274,14 +274,16 @@ class EcmFiles extends CommonObject /** * Load object in memory from the database * - * @param int $id Id object - * @param string $ref Hash of file name (filename+filepath). Not always defined on some version. - * @param string $relativepath Relative path of file from document directory. Example: path/path2/file - * @param string $hashoffile Hash of file content. Take the first one found if same file is at different places. This hash will also change if file content is changed. - * @param string $hashforshare Hash of file sharing. - * @return int <0 if KO, 0 if not found, >0 if OK + * @param int $id Id object + * @param string $ref Hash of file name (filename+filepath). Not always defined on some version. + * @param string $relativepath Relative path of file from document directory. Example: path/path2/file + * @param string $hashoffile Hash of file content. Take the first one found if same file is at different places. This hash will also change if file content is changed. + * @param string $hashforshare Hash of file sharing. + * @param string $src_object_type src_object_type to search + * @param string $src_object_id src_object_id to search + * @return int <0 if KO, 0 if not found, >0 if OK */ - public function fetch($id, $ref = '', $relativepath = '', $hashoffile='', $hashforshare='') + public function fetch($id, $ref = '', $relativepath = '', $hashoffile='', $hashforshare='', $src_object_type='', $src_object_id=0) { dol_syslog(__METHOD__, LOG_DEBUG); @@ -324,8 +326,13 @@ class EcmFiles extends CommonObject } elseif (! empty($hashforshare)) { $sql .= " AND t.share = '".$this->db->escape($hashforshare)."'"; - } else { - $sql .= ' AND t.rowid = ' . $id; + } + elseif ($src_object_type && $src_object_id) + { + $sql.= " AND t.src_object_type ='".$this->db->escape($src_object_type)."' AND t.src_object_id = ".$this->db->escape($src_object_id); + } + else { + $sql .= ' AND t.rowid = '.$this->db->escape($id); } // When we search on hash of content, we take the first one. Solve also hash conflict. $this->db->plimit(1); @@ -363,7 +370,7 @@ class EcmFiles extends CommonObject // Retrieve all extrafields for invoice // fetch optionals attributes and labels // $this->fetch_optionals(); - + // $this->fetch_lines(); $this->db->free($resql); diff --git a/htdocs/societe/paymentmodes.php b/htdocs/societe/paymentmodes.php index a63d55c5e8f..c149d16b0f1 100644 --- a/htdocs/societe/paymentmodes.php +++ b/htdocs/societe/paymentmodes.php @@ -469,8 +469,8 @@ if (empty($reshook)) 'use_companybankid'=>GETPOST('companybankid'), 'force_dir_output'=>$conf->societe->multidir_output[$object->entity].'/'.dol_sanitizeFileName($object->id) ); - $_POST['lang_id'] = GETPOST('lang_idrib'.GETPOST('companybankid')); - $_POST['model'] = GETPOST('modelrib'.GETPOST('companybankid')); + $_POST['lang_id'] = GETPOST('lang_idrib'.GETPOST('companybankid','int'), 'alpha'); + $_POST['model'] = GETPOST('modelrib'.GETPOST('companybankid','int'), 'alpha'); } $id = $socid; @@ -1255,6 +1255,31 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard' print $formfile->showdocuments('company', $object->id, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 0, 0, 0, 28, 0, 'entity='.$object->entity, 0, '', $object->default_lang); + // Show direct download link + /* + $conf->global->THIRDPARTY_ALLOW_EXTERNAL_DOWNLOAD=1; + if (! empty($conf->global->THIRDPARTY_ALLOW_EXTERNAL_DOWNLOAD)) + { + print '
eee'."\n"; + print showDirectDownloadLink($object).'
'; + }*/ + if (! empty($conf->global->BANK_ACCOUNT_ALLOW_EXTERNAL_DOWNLOAD)) + { + $companybankaccounttemp = new CompanyBankAccount($db); + $companypaymentmodetemp = new CompanyPaymentMode($db); + $result = $companypaymentmodetemp->fetch(0, null, $object->id, 'ban'); + + include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; + $ecmfile = new EcmFiles($db); + $result = $ecmfile->fetch(0, '', '', '', '', $companybankaccounttemp->table_element, $companypaymentmodetemp->id); + if ($result > 0) + { + $companybankaccounttemp->last_main_doc = $ecmfile->filepath.'/'.$ecmfile->filename; + print '
'."\n"; + print showDirectDownloadLink($companybankaccounttemp).'
'; + } + } + print '
';