folderaction.inc.php
4.47 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<?php
require_once(KT_LIB_DIR . '/actions/actionregistry.inc.php');
class KTFolderAction extends KTStandardDispatcher {
var $sName;
var $sDescription;
var $sDisplayName;
var $_sShowPermission;
var $_sDisablePermission;
var $_bDisabled;
var $_sDisabledText = null;
var $sSection = "view_details";
var $aBreadcrumbs = array(
array('action' => 'browse', 'name' => 'Browse'),
);
function KTFolderAction($oFolder = null, $oUser = null) {
$this->oFolder = $oFolder;
$this->oUser = $oUser;
parent::KTStandardDispatcher();
}
function setFolder(&$oFolder) {
$this->oFolder =& $oFolder;
}
function setUser(&$oUser) {
$this->oUser =& $oUser;
}
function _show() {
if (is_null($this->_sShowPermission)) {
return true;
}
$oPermission =& KTPermission::getByName($this->_sShowPermission);
if (PEAR::isError($oPermission)) {
return true;
}
return KTPermissionUtil::userHasPermissionOnItem($this->oUser, $oPermission, $this->oFolder);
}
function _disable() {
if ($this->_bDisabled === true) {
return true;
}
if (is_null($this->_sDisablePermission)) {
return false;
}
$oPermission =& KTPermission::getByName($this->_sDisablePermission);
if (PEAR::isError($oPermission)) {
return false;
}
$bResult = KTPermissionUtil::userHasPermissionOnItem($this->oUser, $oPermission, $this->oFolder);
if ($bResult === false) {
$this->_sDisabledText = "Insufficient privileges";
}
return !$bResult;
}
function getURL() {
return sprintf("/action.php/%s?fFolderId=%d", $this->sName, $this->oFolder->getID());
}
function getInfo() {
if ($this->_show() === false) {
return null;
}
$aInfo = array(
'disabled' => $this->_disable(),
'description' => $this->sDescription,
'name' => $this->sDisplayName,
'url' => generateLink($this->getURL(), ""),
'disabled_text' => $this->_sDisabledText,
);
return $this->customiseInfo($aInfo);
}
function getName() {
return $this->sName;
}
function getDisplayName() {
return $this->sDisplayName;
}
function getDescription() {
return $this->sDescription;
}
function customiseInfo($aInfo) {
return $aInfo;
}
function check() {
$this->oFolder =& $this->oValidator->validateFolder($_REQUEST['fFolderId']);
if (!is_null($this->_sShowPermission)) {
$oPermission =& KTPermission::getByName($this->_sShowPermission);
if (!PEAR::isError($oPermission)) {
$res = KTPermissionUtil::userHasPermissionOnItem($this->oUser, $oPermission, $this->oFolder);
if (!$res) {
return false;
}
}
}
$aOptions = array(
"final" => false,
"documentaction" => "viewDocument",
"folderaction" => "browse",
);
$this->aBreadcrumbs = array_merge($this->aBreadcrumbs,
KTBrowseUtil::breadcrumbsForFolder($this->oFolder, $aOptions));
return true;
}
function do_main() {
return "Dispatcher component of action not implemented.";
}
}
class KTFolderActionUtil {
function getFolderActions() {
$oRegistry =& KTActionRegistry::getSingleton();
return $oRegistry->getActions('folderaction');
}
function &getFolderActionsForFolder($oFolder, $oUser) {
$aObjects = array();
foreach (KTFolderActionUtil::getFolderActions() as $aAction) {
list($sClassName, $sPath) = $aAction;
if (!empty($sPath)) {
// require_once(KT_DIR .
// Or something...
}
$aObjects[] =& new $sClassName($oFolder, $oUser);
}
return $aObjects;
}
}
class KTBuiltInFolderAction extends KTFolderAction {
var $sBuildInAction;
function getURL() {
return sprintf("/control.php?action=%s&fFolderID=%d", $this->sBuiltInAction, $this->oFolder->getID());
}
}
class KTBuiltInFolderActionSingle extends KTBuiltInFolderAction {
function getURL() {
return sprintf("/control.php?action=%s&fFolderIDs[]=%d&fReturnFolderID=%d", $this->sBuiltInAction, $this->oFolder->getID(), $this->oFolder->getID());
}
}
?>