New support of option BANK_ACCOUNT_ALLOW_EXTERNAL_DOWNLOAD

This commit is contained in:
Laurent Destailleur 2018-04-20 14:50:11 +02:00
parent 38d200d8a6
commit d0efc41983
4 changed files with 53 additions and 18 deletions

View File

@ -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)
{

View File

@ -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)
{

View File

@ -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);

View File

@ -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 '<br>eee<!-- Link to download main doc -->'."\n";
print showDirectDownloadLink($object).'<br>';
}*/
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 '<br><!-- Link to download main doc -->'."\n";
print showDirectDownloadLink($companybankaccounttemp).'<br>';
}
}
print '</div><div class="fichehalfright"><div class="ficheaddleft">';