Change signature of file to match other urls to link/download files.
This commit is contained in:
parent
1cacfe4935
commit
f0b314dfd7
@ -23,7 +23,6 @@ use Luracast\Restler\Format\UploadFormat;
|
|||||||
|
|
||||||
require_once DOL_DOCUMENT_ROOT.'/main.inc.php';
|
require_once DOL_DOCUMENT_ROOT.'/main.inc.php';
|
||||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||||
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API class for receive files
|
* API class for receive files
|
||||||
@ -52,11 +51,13 @@ class Documents extends DolibarrApi
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a document.
|
* Returns a document. Note that, this API is similar to using the wrapper link "documents.php" to download
|
||||||
|
* a file (used for internal HTML links of documents into application), but with no need to be into a logged session (no need to post the session cookie).
|
||||||
*
|
*
|
||||||
* @param string $module_part Name of module or area concerned by file download ('facture', ...)
|
* @param string $module_part Name of module or area concerned by file download ('facture', ...)
|
||||||
* @param string $ref Reference of object (This will define subdir automatically)
|
* @param string $original_file Relative path with filename, relative to modulepart (for example: IN201701-999/IN201701-999.pdf)
|
||||||
* @param string $subdir NOT YET AVAILABLE : Subdirectory (Only if ref not provided)
|
* @param int $regeneratedoc If requested document is the main document of an object, setting this to 1 ask API to regenerate document before returning it (supported for some module_part only). It is no effect in other cases.
|
||||||
|
* Also, note that setting this to 1 nead write access on object.
|
||||||
* @return array List of documents
|
* @return array List of documents
|
||||||
*
|
*
|
||||||
* @throws 500
|
* @throws 500
|
||||||
@ -65,44 +66,21 @@ class Documents extends DolibarrApi
|
|||||||
* @throws 401
|
* @throws 401
|
||||||
* @throws 200
|
* @throws 200
|
||||||
*/
|
*/
|
||||||
public function index($module_part, $ref='', $subdir='') {
|
public function index($module_part, $original_file='', $regeneratedoc=0)
|
||||||
|
{
|
||||||
global $conf;
|
global $conf;
|
||||||
$this->invoice = new Facture($this->db);
|
|
||||||
|
|
||||||
if (empty($module_part)) {
|
if (empty($module_part)) {
|
||||||
throw new RestException(400, 'bad value for parameter modulepart');
|
throw new RestException(400, 'bad value for parameter modulepart');
|
||||||
}
|
}
|
||||||
if (empty($ref) && empty($subdir)) {
|
if (empty($original_file)) {
|
||||||
throw new RestException(400, 'bad value for parameter ref or subdir');
|
throw new RestException(400, 'bad value for parameter ref or subdir');
|
||||||
}
|
}
|
||||||
if (empty($ref)) {
|
|
||||||
throw new RestException(501, 'FeatureNotYetAvailable');
|
|
||||||
}
|
|
||||||
if (!DolibarrApiAccess::$user->rights->ecm->read) {
|
|
||||||
throw new RestException(401);
|
|
||||||
}
|
|
||||||
|
|
||||||
//--- Generates the document
|
|
||||||
$hidedetails = empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 0 : 1;
|
|
||||||
$hidedesc = empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 0 : 1;
|
|
||||||
$hideref = empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 0 : 1;
|
|
||||||
$result = $this->invoice->fetch(0, $ref);
|
|
||||||
if( ! $result ) {
|
|
||||||
throw new RestException(404, 'Invoice not found');
|
|
||||||
}
|
|
||||||
$result = $this->invoice->generateDocument($this->invoice->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
|
|
||||||
if( $result <= 0 ) {
|
|
||||||
throw new RestException(500, 'Error generating document');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//--- Finds and returns the document
|
//--- Finds and returns the document
|
||||||
$original_file = str_replace("../","/", $ref.'/'.$ref.'.pdf');
|
|
||||||
$refname=basename(dirname($original_file)."/");
|
|
||||||
$entity=$conf->entity;
|
$entity=$conf->entity;
|
||||||
|
|
||||||
$check_access = dol_check_secure_access_document($module_part,$original_file,$entity,DolibarrApiAccess::$user);
|
$check_access = dol_check_secure_access_document($module_part, $original_file, $entity, DolibarrApiAccess::$user, '', ($regeneratedoc ? 'write' : 'read'));
|
||||||
$accessallowed = $check_access['accessallowed'];
|
$accessallowed = $check_access['accessallowed'];
|
||||||
$sqlprotectagainstexternals = $check_access['sqlprotectagainstexternals'];
|
$sqlprotectagainstexternals = $check_access['sqlprotectagainstexternals'];
|
||||||
$original_file = $check_access['original_file'];
|
$original_file = $check_access['original_file'];
|
||||||
@ -115,6 +93,27 @@ class Documents extends DolibarrApi
|
|||||||
throw new RestException(401);
|
throw new RestException(401);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- Generates the document
|
||||||
|
if ($regeneratedoc)
|
||||||
|
{
|
||||||
|
$hidedetails = empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 0 : 1;
|
||||||
|
$hidedesc = empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 0 : 1;
|
||||||
|
$hideref = empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 0 : 1;
|
||||||
|
|
||||||
|
if ($module_part == 'facture' || $module_part == 'invoice')
|
||||||
|
{
|
||||||
|
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
|
||||||
|
$this->invoice = new Facture($this->db);
|
||||||
|
$result = $this->invoice->fetch(0, $ref);
|
||||||
|
if( ! $result ) {
|
||||||
|
throw new RestException(404, 'Invoice not found');
|
||||||
|
}
|
||||||
|
$result = $this->invoice->generateDocument($this->invoice->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
|
||||||
|
if( $result <= 0 ) {
|
||||||
|
throw new RestException(500, 'Error generating document');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$filename = basename($original_file);
|
$filename = basename($original_file);
|
||||||
$original_file_osencoded=dol_osencode($original_file); // New file name encoded in OS encoding charset
|
$original_file_osencoded=dol_osencode($original_file); // New file name encoded in OS encoding charset
|
||||||
|
|||||||
@ -27,6 +27,7 @@
|
|||||||
* \remarks Call of this wrapper is made with URL:
|
* \remarks Call of this wrapper is made with URL:
|
||||||
* document.php?modulepart=repfichierconcerne&file=relativepathoffile
|
* document.php?modulepart=repfichierconcerne&file=relativepathoffile
|
||||||
* document.php?modulepart=logs&file=dolibarr.log
|
* document.php?modulepart=logs&file=dolibarr.log
|
||||||
|
* document.php?modulepart=logs&hashp=sharekey
|
||||||
*/
|
*/
|
||||||
|
|
||||||
define('NOTOKENRENEWAL',1); // Disables token renewal
|
define('NOTOKENRENEWAL',1); // Disables token renewal
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user