Skip to content
Snippets Groups Projects

Pdf Download Notifier

Module permettant la notification par un email ou un événement d'un PDF téléchargé via le lien de partage.

Si vous utiliser une version de Dolibarr antérieur à la v12, il faudra modifier le fichier document.php se trouvant à la racine d'une façon similaire.

// Output file on browser
dol_syslog("document.php download $fullpath_original_file filename=$filename content-type=$type");
$fullpath_original_file_osencoded=dol_osencode($fullpath_original_file);	// New file name encoded in OS encoding charset

// This test if file exists should be useless. We keep it to find bug more easily
if (! file_exists($fullpath_original_file_osencoded))
{
	dol_syslog("ErrorFileDoesNotExists: ".$fullpath_original_file);
	print "ErrorFileDoesNotExists: ".$original_file;
	exit;
}

//-----------------------------------------------------------------
// Modification à rajouter dans le fichier - Begin
// Hooks
if (!is_object($hookmanager)) {
	include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php';
	$hookmanager = new HookManager($this->db);
}
$hookmanager->initHooks(array('document'));
$parameters = array('ecmfile' => $ecmfile, 'modulepart' => $modulepart, 'original_file' => $original_file,
	'entity' => $entity, 'refname' => $refname, 'fullpath_original_file' => $fullpath_original_file,
	'filename' => $filename, 'fullpath_original_file_osencoded' => $fullpath_original_file_osencoded);
$reshook = $hookmanager->executeHooks('downloadDocument', $parameters); // Note that $action and $object may have been
if ($reshook < 0) {
	$errors = $hookmanager->error . (is_array($hookmanager->errors) ? (!empty($hookmanager->error) ? ', ' : '') . join($separator, $hookmanager->errors) : '');
	dol_syslog("document.php - Errors when executing the hook 'downloadDocument' : " . $errors);
	print "ErrorDownloadDocumentHooks: " . $errors;
	exit;
}
// Modification à rajouter dans le fichier - End
//-----------------------------------------------------------------

// Permissions are ok and file found, so we return it
top_httphead($type);
header('Content-Description: File Transfer');
if ($encoding)   header('Content-Encoding: '.$encoding);
// Add MIME Content-Disposition from RFC 2183 (inline=automatically displayed, attachment=need user action to open)
if ($attachment) header('Content-Disposition: attachment; filename="'.$filename.'"');
else header('Content-Disposition: inline; filename="'.$filename.'"');
header('Content-Length: ' . dol_filesize($fullpath_original_file));
// Ajout directives pour resoudre bug IE
header('Cache-Control: Public, must-revalidate');
header('Pragma: public');

readfile($fullpath_original_file_osencoded);

if (is_object($db)) $db->close();