2013-07-21 09:51:59 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Implementation of Download controller
|
|
|
|
*
|
|
|
|
* @category DMS
|
|
|
|
* @package SeedDMS
|
|
|
|
* @license GPL 2
|
|
|
|
* @version @version@
|
|
|
|
* @author Uwe Steinmann <uwe@steinmann.cx>
|
|
|
|
* @copyright Copyright (C) 2010-2013 Uwe Steinmann
|
|
|
|
* @version Release: @package_version@
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class which does the busines logic for downloading a document
|
|
|
|
*
|
|
|
|
* @category DMS
|
|
|
|
* @package SeedDMS
|
|
|
|
* @author Uwe Steinmann <uwe@steinmann.cx>
|
|
|
|
* @copyright Copyright (C) 2010-2013 Uwe Steinmann
|
|
|
|
* @version Release: @package_version@
|
|
|
|
*/
|
|
|
|
class SeedDMS_Controller_Download extends SeedDMS_Controller_Common {
|
|
|
|
|
2016-08-11 20:56:12 +00:00
|
|
|
public function version() { /* {{{ */
|
|
|
|
$dms = $this->params['dms'];
|
|
|
|
$content = $this->params['content'];
|
|
|
|
|
2016-11-22 09:34:15 +00:00
|
|
|
if(null === $this->callHook('version')) {
|
2016-08-11 20:56:12 +00:00
|
|
|
if(file_exists($dms->contentDir . $content->getPath())) {
|
|
|
|
header("Content-Transfer-Encoding: binary");
|
|
|
|
header("Content-Length: " . filesize($dms->contentDir . $content->getPath() ));
|
|
|
|
$efilename = rawurlencode($content->getOriginalFileName());
|
|
|
|
header("Content-Disposition: attachment; filename=\"" . $efilename . "\"; filename*=UTF-8''".$efilename);
|
|
|
|
header("Content-Type: " . $content->getMimeType());
|
|
|
|
header("Cache-Control: must-revalidate");
|
|
|
|
|
2018-01-18 16:28:30 +00:00
|
|
|
sendFile($dms->contentDir . $content->getPath());
|
2016-08-11 20:56:12 +00:00
|
|
|
}
|
|
|
|
}
|
2019-02-11 18:20:07 +00:00
|
|
|
return true;
|
2016-08-11 20:56:12 +00:00
|
|
|
} /* }}} */
|
|
|
|
|
|
|
|
public function file() { /* {{{ */
|
|
|
|
$dms = $this->params['dms'];
|
|
|
|
$file = $this->params['file'];
|
|
|
|
|
2016-11-22 09:34:15 +00:00
|
|
|
if(null === $this->callHook('file')) {
|
2016-08-11 20:56:12 +00:00
|
|
|
if(file_exists($dms->contentDir . $file->getPath())) {
|
|
|
|
header("Content-Transfer-Encoding: binary");
|
|
|
|
header("Content-Length: " . filesize($dms->contentDir . $file->getPath() ));
|
|
|
|
header("Content-Disposition: attachment; filename=\"" . $file->getOriginalFileName() . "\"");
|
|
|
|
header("Content-Type: " . $file->getMimeType());
|
|
|
|
header("Cache-Control: must-revalidate");
|
|
|
|
|
2018-01-18 16:28:30 +00:00
|
|
|
sendFile($dms->contentDir . $file->getPath());
|
2016-08-11 20:56:12 +00:00
|
|
|
}
|
|
|
|
}
|
2019-02-11 18:20:07 +00:00
|
|
|
return true;
|
2016-08-11 20:56:12 +00:00
|
|
|
} /* }}} */
|
|
|
|
|
|
|
|
public function archive() { /* {{{ */
|
|
|
|
$dms = $this->params['dms'];
|
|
|
|
$filename = $this->params['file'];
|
|
|
|
$basedir = $this->params['basedir'];
|
|
|
|
|
2016-11-22 09:34:15 +00:00
|
|
|
if(null === $this->callHook('archive')) {
|
2016-08-11 20:56:12 +00:00
|
|
|
if(file_exists($basedir . $filename)) {
|
|
|
|
header('Content-Description: File Transfer');
|
|
|
|
header("Content-Type: application/zip");
|
|
|
|
header("Content-Transfer-Encoding: binary");
|
|
|
|
header("Content-Length: " . filesize($basedir . $filename ));
|
|
|
|
$efilename = rawurlencode($filename);
|
|
|
|
header("Content-Disposition: attachment; filename=\"" .$efilename . "\"; filename*=UTF-8''".$efilename);
|
|
|
|
header("Cache-Control: public");
|
|
|
|
|
2018-01-18 16:28:30 +00:00
|
|
|
sendFile($basedir .$filename );
|
2016-08-11 20:56:12 +00:00
|
|
|
}
|
|
|
|
}
|
2019-02-11 18:20:07 +00:00
|
|
|
return true;
|
2016-08-11 20:56:12 +00:00
|
|
|
} /* }}} */
|
|
|
|
|
|
|
|
public function log() { /* {{{ */
|
|
|
|
$dms = $this->params['dms'];
|
|
|
|
$filename = $this->params['file'];
|
|
|
|
$basedir = $this->params['basedir'];
|
|
|
|
|
2016-11-22 09:34:15 +00:00
|
|
|
if(null === $this->callHook('log')) {
|
2016-08-11 20:56:12 +00:00
|
|
|
if(file_exists($basedir . $filename)) {
|
|
|
|
header("Content-Type: text/plain; name=\"" . $filename . "\"");
|
|
|
|
header("Content-Transfer-Encoding: binary");
|
|
|
|
header("Content-Length: " . filesize($basedir . $filename ));
|
|
|
|
$efilename = rawurlencode($filename);
|
|
|
|
header("Content-Disposition: attachment; filename=\"" .$efilename . "\"; filename*=UTF-8''".$efilename);
|
|
|
|
header("Cache-Control: must-revalidate");
|
|
|
|
|
2018-01-18 16:28:30 +00:00
|
|
|
sendFile($basedir.$filename);
|
2016-08-11 20:56:12 +00:00
|
|
|
}
|
|
|
|
}
|
2019-02-11 18:20:07 +00:00
|
|
|
return true;
|
2016-08-11 20:56:12 +00:00
|
|
|
} /* }}} */
|
|
|
|
|
|
|
|
public function sqldump() { /* {{{ */
|
|
|
|
$dms = $this->params['dms'];
|
|
|
|
$filename = $this->params['file'];
|
|
|
|
$basedir = $this->params['basedir'];
|
|
|
|
|
2016-11-22 09:34:15 +00:00
|
|
|
if(null === $this->callHook('sqldump')) {
|
2016-08-11 20:56:12 +00:00
|
|
|
if(file_exists($basedir . $filename)) {
|
2018-01-18 16:28:30 +00:00
|
|
|
header("Content-Type: application/zip");
|
2016-08-11 20:56:12 +00:00
|
|
|
header("Content-Transfer-Encoding: binary");
|
|
|
|
header("Content-Length: " . filesize($basedir . $filename ));
|
|
|
|
$efilename = rawurlencode($filename);
|
|
|
|
header("Content-Disposition: attachment; filename=\"" .$efilename . "\"; filename*=UTF-8''".$efilename);
|
|
|
|
header("Cache-Control: must-revalidate");
|
|
|
|
|
2018-01-18 16:28:30 +00:00
|
|
|
sendFile($basedir.$filename);
|
2016-08-11 20:56:12 +00:00
|
|
|
}
|
|
|
|
}
|
2019-02-11 18:20:07 +00:00
|
|
|
return true;
|
2016-08-11 20:56:12 +00:00
|
|
|
} /* }}} */
|
|
|
|
|
|
|
|
public function approval() { /* {{{ */
|
|
|
|
$dms = $this->params['dms'];
|
|
|
|
$document = $this->params['document'];
|
|
|
|
$logid = $this->params['approvelogid'];
|
|
|
|
|
|
|
|
$filename = $dms->contentDir . $document->getDir().'a'.$logid;
|
|
|
|
if (!file_exists($filename) ) {
|
|
|
|
$this->error = 1;
|
2019-02-11 18:20:07 +00:00
|
|
|
return false;
|
2016-08-11 20:56:12 +00:00
|
|
|
}
|
|
|
|
|
2016-11-22 09:34:15 +00:00
|
|
|
if(null === $this->callHook('approval')) {
|
2017-08-21 11:43:36 +00:00
|
|
|
$finfo = finfo_open(FILEINFO_MIME_TYPE);
|
|
|
|
$mimetype = finfo_file($finfo, $filename);
|
|
|
|
|
2018-01-18 16:28:30 +00:00
|
|
|
header("Content-Type: ".$mimetype);
|
2017-08-21 11:43:36 +00:00
|
|
|
header("Content-Transfer-Encoding: binary");
|
|
|
|
header("Content-Length: " . filesize($filename ));
|
|
|
|
header("Content-Disposition: attachment; filename=\"approval-" . $document->getID()."-".(int) $_GET['approvelogid'] . get_extension($mimetype) . "\"");
|
|
|
|
header("Cache-Control: must-revalidate");
|
2018-01-18 16:28:30 +00:00
|
|
|
sendFile($filename);
|
2016-08-11 20:56:12 +00:00
|
|
|
}
|
2019-02-11 18:20:07 +00:00
|
|
|
return true;
|
2016-08-11 20:56:12 +00:00
|
|
|
} /* }}} */
|
|
|
|
|
|
|
|
public function review() { /* {{{ */
|
|
|
|
$dms = $this->params['dms'];
|
|
|
|
$document = $this->params['document'];
|
|
|
|
$logid = $this->params['reviewlogid'];
|
|
|
|
|
|
|
|
$filename = $dms->contentDir . $document->getDir().'r'.$logid;
|
|
|
|
if (!file_exists($filename) ) {
|
|
|
|
$this->error = 1;
|
2019-02-11 18:20:07 +00:00
|
|
|
return false;
|
2016-08-11 20:56:12 +00:00
|
|
|
}
|
|
|
|
|
2016-11-22 09:34:15 +00:00
|
|
|
if(null === $this->callHook('review')) {
|
2017-08-21 11:43:36 +00:00
|
|
|
$finfo = finfo_open(FILEINFO_MIME_TYPE);
|
|
|
|
$mimetype = finfo_file($finfo, $filename);
|
|
|
|
|
2018-01-18 16:28:30 +00:00
|
|
|
header("Content-Type: ".$mimetype);
|
2017-08-21 11:43:36 +00:00
|
|
|
header("Content-Transfer-Encoding: binary");
|
|
|
|
header("Content-Length: " . filesize($filename ));
|
|
|
|
header("Content-Disposition: attachment; filename=\"review-" . $document->getID()."-".(int) $_GET['reviewlogid'] . get_extension($mimetype) . "\"");
|
|
|
|
header("Cache-Control: must-revalidate");
|
2018-01-18 16:28:30 +00:00
|
|
|
sendFile($filename);
|
2016-08-11 20:56:12 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} /* }}} */
|
|
|
|
|
|
|
|
public function run() { /* {{{ */
|
2013-07-21 09:51:59 +00:00
|
|
|
$dms = $this->params['dms'];
|
|
|
|
$type = $this->params['type'];
|
|
|
|
|
2019-02-07 14:03:43 +00:00
|
|
|
$version = $this->params['version'];
|
|
|
|
$document = $this->params['document'];
|
2019-03-14 08:08:07 +00:00
|
|
|
if($version < 1) {
|
|
|
|
$content = $this->callHook('documentLatestContent', $document);
|
|
|
|
if($content === null)
|
|
|
|
$content = $document->getLatestContent();
|
|
|
|
} else {
|
|
|
|
$content = $this->callHook('documentContent', $document, $version);
|
|
|
|
if($content === null)
|
|
|
|
$content = $document->getContentByVersion($version);
|
|
|
|
}
|
2019-02-07 14:03:43 +00:00
|
|
|
if (!is_object($content)) {
|
|
|
|
$this->errormsg = 'invalid_version';
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
/* set params['content'] for compatiblity with older extensions which
|
|
|
|
* expect the content in the controller
|
|
|
|
*/
|
|
|
|
$this->params['content'] = $content;
|
2013-07-21 09:51:59 +00:00
|
|
|
switch($type) {
|
|
|
|
case "version":
|
2019-02-11 18:20:07 +00:00
|
|
|
return $this->version();
|
2013-07-21 09:51:59 +00:00
|
|
|
break;
|
2015-06-08 19:59:56 +00:00
|
|
|
case "file":
|
2019-02-11 18:20:07 +00:00
|
|
|
return $this->file();
|
2016-08-11 20:56:12 +00:00
|
|
|
break;
|
|
|
|
case "archive":
|
2019-02-11 18:20:07 +00:00
|
|
|
return $this->archive();
|
2016-08-11 20:56:12 +00:00
|
|
|
break;
|
|
|
|
case "log":
|
2019-02-11 18:20:07 +00:00
|
|
|
return $this->log();
|
2016-08-11 20:56:12 +00:00
|
|
|
break;
|
|
|
|
case "sqldump":
|
2019-02-11 18:20:07 +00:00
|
|
|
return $this->sqldump();
|
2016-08-11 20:56:12 +00:00
|
|
|
break;
|
|
|
|
case "approval":
|
2019-02-11 18:20:07 +00:00
|
|
|
return $this->approval();
|
2016-08-11 20:56:12 +00:00
|
|
|
break;
|
|
|
|
case "review":
|
2019-02-11 18:20:07 +00:00
|
|
|
return $this->review();
|
2015-06-08 19:59:56 +00:00
|
|
|
break;
|
2013-07-21 09:51:59 +00:00
|
|
|
}
|
2016-08-11 20:56:12 +00:00
|
|
|
} /* }}} */
|
2013-07-21 09:51:59 +00:00
|
|
|
}
|