PDFGeneratorAction.php
2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
require_once(KT_LIB_DIR . '/actions/folderaction.inc.php');
require_once(KT_LIB_DIR . '/permissions/permission.inc.php');
require_once(KT_LIB_DIR . '/permissions/permissionutil.inc.php');
require_once(KT_LIB_DIR . '/browse/browseutil.inc.php');
require_once(KT_LIB_DIR . '/plugins/plugin.inc.php');
require_once(KT_LIB_DIR . '/plugins/pluginregistry.inc.php');
require_once(KT_LIB_DIR . '/roles/Role.inc');
class PDFGeneratorAction extends KTDocumentAction {
var $sName = 'ktstandard.pdf.action';
var $_sShowPermission = "ktcore.permissions.read";
var $sDisplayName = 'Generate PDF';
var $aAcceptedMimeTypes = array('doc', 'ods', 'odt');
function getDisplayName() {
// check if open office and plugin available
$this->HAVE_GRAPHVIZ = false;
$dotCommand = KTUtil::findCommand("ui/dot", 'dot');
if (!empty($dotCommand)) {
$this->HAVE_GRAPHVIZ = true;
$this->dotCommand = $dotCommand;
$sDocType = $this->getMimeExtension();
// make sure that the selected document id of an acceptable extension
foreach($this->aAcceptedMimeTypes as $acceptType){
if($acceptType == $sDocType){
return _kt('Generate PDF');
}
}
}
return '';
}
function do_main() {
$oTemplating =& KTTemplating::getSingleton();
$oTemplate = $oTemplating->loadTemplate('ktstandard/PDFPlugin/PDFPlugin');
$aTemplateData = array(
'context' => $this,
);
return $oTemplate->render($aTemplateData);
}
/**
* Method for getting the MIME type extension for the current document.
*
* @return string mime time extension
*/
function getMimeExtension() {
$oDocument = $this->oDocument;
$iMimeTypeId = $oDocument->getMimeTypeID();
$mimetypename = KTMime::getMimeTypeName($iMimeTypeId); // mime type name
$sTable = KTUtil::getTableName('mimetypes');
$sQuery = "SELECT filetypes FROM " . $sTable . " WHERE mimetypes = ?";
$aQuery = array($sQuery, array($mimetypename));
$res = DBUtil::getResultArray($aQuery);
if (PEAR::isError($res)) {
return $res;
} else if (count($res) != 0){
return $res[0]['filetypes'];
}
return _kt('Unknown Type');
}
}
?>