KTDocumentActions.php
13.5 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
<?php
require_once(KT_LIB_DIR . '/actions/documentaction.inc.php');
require_once(KT_LIB_DIR . '/subscriptions/Subscription.inc');
require_once(KT_LIB_DIR . '/widgets/fieldWidgets.php');
require_once(KT_LIB_DIR . '/browse/browseutil.inc.php');
require_once(KT_LIB_DIR . '/documentmanagement/documentutil.inc.php');
$oKTActionRegistry =& KTActionRegistry::getSingleton();
// {{{ KTDocumentViewAction
class KTDocumentViewAction extends KTDocumentAction {
var $sBuiltInAction = 'downloadDocument';
var $sDisplayName = 'Download';
var $sName = 'ktcore.actions.document.view';
function customiseInfo($aInfo) {
$aInfo['alert'] = _("This will download a copy of the document and is not the same as Checking Out a document. Changes to this downloaded file will not be managed in the DMS.");
return $aInfo;
}
function do_main() {
$oStorage =& KTStorageManagerUtil::getSingleton();
$oDocumentTransaction = & new DocumentTransaction($this->oDocument->getId(), "Document downloaded", DOWNLOAD);
$oDocumentTransaction->create();
$oStorage->download($this->oDocument);
exit(0);
}
}
$oKTActionRegistry->registerAction('documentaction', 'KTDocumentViewAction', 'ktcore.actions.document.view');
// }}}
// {{{ KTDocumentCheckOutAction
class KTDocumentCheckOutAction extends KTDocumentAction {
var $sBuiltInAction = 'checkOutDocument';
var $sDisplayName = 'Checkout';
var $sName = 'ktcore.actions.document.checkout';
var $_sDisablePermission = "ktcore.permissions.write";
function getInfo() {
if ($this->oDocument->getIsCheckedOut()) {
return null;
}
return parent::getInfo();
}
function check() {
$res = parent::check();
if ($res !== true) {
return $res;
}
if ($this->oDocument->getIsCheckedOut()) {
$_SESSION['KTErrorMessage'][] = "This document is already checked out";
controllerRedirect('viewDocument', 'fDocumentId=' . $this->oDocument->getId());
exit(0);
}
return true;
}
function do_main() {
$this->oPage->setBreadcrumbDetails("checkout");
$oTemplate =& $this->oValidator->validateTemplate('ktcore/action/checkout');
$checkout_fields = array();
$checkout_fields[] = new KTStringWidget('Reason', 'The reason for the checkout of this document for historical purposes, and to inform those who wish to check out this document.', 'reason', "", $this->oPage, true);
$oTemplate->setData(array(
'context' => &$this,
'checkout_fields' => $checkout_fields,
));
return $oTemplate->render();
}
function do_checkout() {
$sReason = KTUtil::arrayGet($_REQUEST, 'reason');
$this->oValidator->notEmpty($sReason);
$oTemplate =& $this->oValidator->validateTemplate('ktcore/action/checkout_final');
$oTemplate->setData(array(
'context' => &$this,
'reason' => $sReason,
));
return $oTemplate->render();
}
function do_checkout_final() {
$sReason = KTUtil::arrayGet($_REQUEST, 'reason');
$this->oValidator->notEmpty($sReason);
// flip the checkout status
$this->oDocument->setIsCheckedOut(true);
// set the user checking the document out
$this->oDocument->setCheckedOutUserID($_SESSION["userID"]);
// update it
if (!$this->oDocument->update()) {
$_SESSION['KTErrorMessage'][] = "There was a problem checking out the document.";
controllerRedirect('viewDocument', 'fDocumentId=' . $this->oDocument->getId());
}
$oKTTriggerRegistry = KTTriggerRegistry::getSingleton();
$aTriggers = $oKTTriggerRegistry->getTriggers('checkout', 'postValidate');
foreach ($aTriggers as $aTrigger) {
$sTrigger = $aTrigger[0];
$oTrigger = new $sTrigger;
$aInfo = array(
"document" => $this->oDocument,
);
$oTrigger->setInfo($aInfo);
$ret = $oTrigger->postValidate();
if (PEAR::isError($ret)) {
$this->oDocument->delete();
return $ret;
}
}
$oDocumentTransaction = & new DocumentTransaction($this->oDocument->getID(), $sReason, CHECKOUT);
$oDocumentTransaction->create();
$oStorage =& KTStorageManagerUtil::getSingleton();
$oStorage->download($this->oDocument);
exit(0);
}
}
$oKTActionRegistry->registerAction('documentaction', 'KTDocumentCheckOutAction', 'ktcore.actions.document.checkout');
// }}}
class KTDocumentCheckInAction extends KTDocumentAction {
var $sBuiltInAction = 'checkInDocument';
var $sDisplayName = 'Checkin';
var $sName = 'ktcore.actions.document.checkin';
var $_sShowPermission = "ktcore.permissions.write";
function getInfo() {
if (!$this->oDocument->getIsCheckedOut()) {
return null;
}
if ($this->oDocument->getCheckedOutUserID() != $this->oUser->getId()) {
return null;
}
return parent::getInfo();
}
function check() {
$res = parent::check();
if ($res !== true) {
return $res;
}
if (!$this->oDocument->getIsCheckedOut()) {
$_SESSION['KTErrorMessage'][] = "This document is not checked out";
controllerRedirect('viewDocument', 'fDocumentId=' . $this->oDocument->getId());
exit(0);
}
if ($this->oDocument->getCheckedOutUserID() != $this->oUser->getId()) {
$_SESSION['KTErrorMessage'][] = "This document is checked out, but not by you";
controllerRedirect('viewDocument', 'fDocumentId=' . $this->oDocument->getId());
exit(0);
}
return true;
}
function do_main() {
$this->oPage->setBreadcrumbDetails("checkin");
$oTemplate =& $this->oValidator->validateTemplate('ktcore/action/checkin');
$sReason = KTUtil::arrayGet($_REQUEST, 'reason', "");
$checkin_fields = array();
$checkin_fields[] = new KTFileUploadWidget('File', 'The updated document.', 'file', "", $this->oPage, true);
$checkin_fields[] = new KTStringWidget('Description', 'Describe the changes made to the document.', 'reason', $sReason, $this->oPage, true);
$oTemplate->setData(array(
'context' => &$this,
'checkin_fields' => $checkin_fields,
));
return $oTemplate->render();
}
function do_checkin() {
$sReason = KTUtil::arrayGet($_REQUEST, 'reason');
$sReason = $this->oValidator->notEmpty($sReason);
// make sure the user actually selected a file first
if (strlen($_FILES['file']['name']) == 0) {
$this->errorRedirectToMain("No file was uploaded", 'fDocumentId=' . $this->oDocument->getId() . '&reason=' . $sReason);
}
// and that the filename matches
global $default;
$default->log->info("checkInDocumentBL.php uploaded filename=" . $_FILES['file']['name'] . "; current filename=" . $this->oDocument->getFileName());
if ($this->oDocument->getFileName() != $_FILES['file']['name']) {
$this->errorRedirectToMain("The file name of the uploaded file does not match the file name of the document in the system", 'fDocumentId=' . $this->oDocument->getId() . '&reason=' . $sReason);
}
$res = KTDocumentUtil::checkin($this->oDocument, $_FILES['file']['tmp_name'], $sReason, $this->oUser);
if (PEAR::isError($res)) {
$this->errorRedirectToMain("An error occurred while trying to check in the document", 'fDocumentId=' . $this->oDocument->getId() . '&reason=' . $sReason);
}
redirect("$default->rootUrl/control.php?action=viewDocument&fDocumentID=" . $this->oDocument->getID());
}
}
$oKTActionRegistry->registerAction('documentaction', 'KTDocumentCheckInAction', 'ktcore.actions.document.checkin');
class KTDocumentDeleteAction extends KTBuiltInDocumentActionSingle {
var $sBuiltInAction = 'deleteDocument';
var $sDisplayName = 'Delete';
var $sName = 'ktcore.actions.document.delete';
var $_sDisablePermission = "ktcore.permissions.write";
function _disable() {
if ($this->oDocument->getIsCheckedOut()) {
$this->_sDisabledText = _("This document can't be deleted because its checked out");
return true;
}
return parent::_disable();
}
}
$oKTActionRegistry->registerAction('documentaction', 'KTDocumentDeleteAction', 'ktcore.actions.document.delete');
class KTDocumentMoveAction extends KTBuiltInDocumentActionSingle {
var $sBuiltInAction = 'moveDocument';
var $sDisplayName = 'Move';
var $sName = 'ktcore.actions.document.move';
var $_sDisablePermission = "ktcore.permissions.write";
function _disable() {
if ($this->oDocument->getIsCheckedOut()) {
$this->_sDisabledText = _("This document can't be deleted because its checked out");
return true;
}
return parent::_disable();
}
function getURL() {
return sprintf("/control.php?action=%s&fDocumentIDs[]=%d&fReturnDocumentID=%d&fFolderID=%d", $this->sBuiltInAction, $this->oDocument->getID(), $this->oDocument->getID(), $this->oDocument->getFolderID());
}
}
$oKTActionRegistry->registerAction('documentaction', 'KTDocumentMoveAction', 'ktcore.actions.document.move');
class KTDocumentHistoryAction extends KTBuiltInDocumentAction {
var $sBuiltInAction = 'viewHistory';
var $sDisplayName = 'History';
var $sName = 'ktcore.actions.document.history';
}
$oKTActionRegistry->registerAction('documentaction', 'KTDocumentHistoryAction', 'ktcore.actions.document.history');
class KTDocumentDiscussionAction extends KTBuiltInDocumentAction {
var $sBuiltInAction = 'viewDiscussion';
var $sDisplayName = 'Discussion';
var $sName = 'ktcore.actions.document.discussion';
}
$oKTActionRegistry->registerAction('documentaction', 'KTDocumentDiscussionAction', 'ktcore.actions.document.discussion');
class KTDocumentArchiveAction extends KTBuiltInDocumentAction {
var $_sDisablePermission = "ktcore.permissions.write";
var $sBuiltInAction = 'archiveDocument';
var $sDisplayName = 'Archive';
var $sName = 'ktcore.actions.document.archive';
function _disable() {
/*
if ($this->oDocument->hasCollaboration() &&
DocumentCollaboration::documentCollaborationStarted($this->oDocument->getID()) &&
!DocumentCollaboration::documentCollaborationDone($this->oDocument->getID())) {
$sDisabledText = _("This document is in collaboration and cannot be archived");
}
*/
if ($this->oDocument->getIsCheckedOut()) {
$this->_sDisabledText = _("This document is checked out and cannot be archived.");
return true;
}
return parent::_disable();
}
}
$oKTActionRegistry->registerAction('documentaction', 'KTDocumentArchiveAction', 'ktcore.actions.document.archive');
class KTDocumentDependentAction extends KTBuiltInDocumentAction {
var $sBuiltInAction = 'createDependantDocument';
var $sDisplayName = 'Link New Doc';
var $sName = 'ktcore.actions.document.dependent';
}
$oKTActionRegistry->registerAction('documentaction', 'KTDocumentDependentAction', 'ktcore.actions.document.dependent');
class KTDocumentPublishAction extends KTDocumentAction {
var $_sDisablePermission = "ktcore.permissions.write";
var $sDisplayName = 'Publish';
var $sName = 'ktcore.actions.document.publish';
function _disable() {
$oDocument =& $this->oDocument;
if ($oDocument->getIsCheckedOut()) {
$this->_sDisabledText = _("This document is checked out and cannot be archived.");
return true;
}
/*
if (DocumentCollaboration::documentIsPublished($oDocument->getID())) {
$this->_sDisabledText = _("This document is already published.");
return true;
}
if (DocumentCollaboration::documentIsPendingWebPublishing($oDocument->getID())) {
$this->_sDisabledText = _("This document has been marked as pending publishing and the web publisher has been notified.");
return true;
}
if ($oDocument->hasCollaboration()) {
if (!DocumentCollaboration::documentCollaborationDone($oDocument->getID())) {
$this->_sDisabledText = _("You cannot publish this document until collaboration is complete");
return true;
}
}
*/
return parent::_disable();
}
function getURL() {
return sprintf("/control.php?action=%s&fDocumentID=%d&fForPublish=1", 'viewDocument', $this->oDocument->getID(), $this->oDocument->getID());
}
}
$oKTActionRegistry->registerAction('documentaction', 'KTDocumentPublishAction', 'ktcore.actions.document.publish');
class KTDocumentPermissionsAction extends KTBuiltInDocumentAction {
var $sBuiltInAction = 'editDocumentPermissions';
var $sDisplayName = 'Permissions';
var $sName = 'ktcore.actions.document.permissions';
}
$oKTActionRegistry->registerAction('documentaction', 'KTDocumentPermissionsAction', 'ktcore.actions.document.permissions');
class KTDocumentWorkflowAction extends KTBuiltInDocumentAction {
var $sBuiltInAction = 'documentWorkflow';
var $sDisplayName = 'Workflow';
var $sName = 'ktcore.actions.document.workflow';
}
$oKTActionRegistry->registerAction('documentaction', 'KTDocumentWorkflowAction', 'ktcore.actions.document.workflow');
?>