Commit 59f8600ff754969362266d8a5be6fbcceb3e8905

Authored by conradverm
1 parent 878f93dc

KTS-2178

"cross site scripting"
Updated.

Reviewed By: Kevin Fourie

git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@6921 c91229c3-7414-0410-bfa2-8a42b809f60b
plugins/ktcore/KTDocumentActions.php
@@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
6 * License Version 1.1.2 ("License"); You may not use this file except in 6 * License Version 1.1.2 ("License"); You may not use this file except in
7 * compliance with the License. You may obtain a copy of the License at 7 * compliance with the License. You may obtain a copy of the License at
8 * http://www.knowledgetree.com/KPL 8 * http://www.knowledgetree.com/KPL
9 - * 9 + *
10 * Software distributed under the License is distributed on an "AS IS" 10 * Software distributed under the License is distributed on an "AS IS"
11 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. 11 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
12 * See the License for the specific language governing rights and 12 * See the License for the specific language governing rights and
@@ -17,9 +17,9 @@ @@ -17,9 +17,9 @@
17 * (ii) the KnowledgeTree copyright notice 17 * (ii) the KnowledgeTree copyright notice
18 * in the same form as they appear in the distribution. See the License for 18 * in the same form as they appear in the distribution. See the License for
19 * requirements. 19 * requirements.
20 - * 20 + *
21 * The Original Code is: KnowledgeTree Open Source 21 * The Original Code is: KnowledgeTree Open Source
22 - * 22 + *
23 * The Initial Developer of the Original Code is The Jam Warehouse Software 23 * The Initial Developer of the Original Code is The Jam Warehouse Software
24 * (Pty) Ltd, trading as KnowledgeTree. 24 * (Pty) Ltd, trading as KnowledgeTree.
25 * Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright 25 * Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright
@@ -42,7 +42,7 @@ require_once(KT_LIB_DIR . '/browse/PartialQuery.inc.php'); @@ -42,7 +42,7 @@ require_once(KT_LIB_DIR . '/browse/PartialQuery.inc.php');
42 42
43 require_once(KT_LIB_DIR . '/widgets/forms.inc.php'); 43 require_once(KT_LIB_DIR . '/widgets/forms.inc.php');
44 44
45 -// {{{ KTDocumentDetailsAction 45 +// {{{ KTDocumentDetailsAction
46 class KTDocumentDetailsAction extends KTDocumentAction { 46 class KTDocumentDetailsAction extends KTDocumentAction {
47 var $sName = 'ktcore.actions.document.displaydetails'; 47 var $sName = 'ktcore.actions.document.displaydetails';
48 48
@@ -143,7 +143,7 @@ class KTDocumentVersionHistoryAction extends KTDocumentAction { @@ -143,7 +143,7 @@ class KTDocumentVersionHistoryAction extends KTDocumentAction {
143 ); 143 );
144 return $oTemplate->render($aTemplateData); 144 return $oTemplate->render($aTemplateData);
145 } 145 }
146 - 146 +
147 function do_startComparison() { 147 function do_startComparison() {
148 $comparison_version = KTUtil::arrayGet($_REQUEST, 'fComparisonVersion'); 148 $comparison_version = KTUtil::arrayGet($_REQUEST, 'fComparisonVersion');
149 149
@@ -151,7 +151,7 @@ class KTDocumentVersionHistoryAction extends KTDocumentAction { @@ -151,7 +151,7 @@ class KTDocumentVersionHistoryAction extends KTDocumentAction {
151 if (PEAR::isError($oDocument)) { 151 if (PEAR::isError($oDocument)) {
152 return $this->redirectToMain(_kt('The document you selected was invalid')); 152 return $this->redirectToMain(_kt('The document you selected was invalid'));
153 } 153 }
154 - 154 +
155 if (!Permission::userHasDocumentReadPermission($oDocument)) { 155 if (!Permission::userHasDocumentReadPermission($oDocument)) {
156 return $this->errorRedirectToMain(_kt('You are not allowed to view this document')); 156 return $this->errorRedirectToMain(_kt('You are not allowed to view this document'));
157 } 157 }
@@ -176,7 +176,7 @@ class KTDocumentVersionHistoryAction extends KTDocumentAction { @@ -176,7 +176,7 @@ class KTDocumentVersionHistoryAction extends KTDocumentAction {
176 ); 176 );
177 return $oTemplate->render($aTemplateData); 177 return $oTemplate->render($aTemplateData);
178 } 178 }
179 - 179 +
180 function do_viewComparison() { 180 function do_viewComparison() {
181 // this is just a redirector 181 // this is just a redirector
182 $QS = array( 182 $QS = array(
@@ -185,22 +185,22 @@ class KTDocumentVersionHistoryAction extends KTDocumentAction { @@ -185,22 +185,22 @@ class KTDocumentVersionHistoryAction extends KTDocumentAction {
185 'fBaseVersion' => $_REQUEST['fBaseVersion'], 185 'fBaseVersion' => $_REQUEST['fBaseVersion'],
186 'fComparisonVersion' => $_REQUEST['fComparisonVersion'], 186 'fComparisonVersion' => $_REQUEST['fComparisonVersion'],
187 ); 187 );
188 - 188 +
189 $frag = array(); 189 $frag = array();
190 - 190 +
191 foreach ($QS as $k => $v) { 191 foreach ($QS as $k => $v) {
192 $frag[] = sprintf('%s=%s', urlencode($k), urlencode($v)); 192 $frag[] = sprintf('%s=%s', urlencode($k), urlencode($v));
193 } 193 }
194 - 194 +
195 redirect(KTUtil::ktLink('view.php',null,implode('&', $frag))); 195 redirect(KTUtil::ktLink('view.php',null,implode('&', $frag)));
196 } 196 }
197 -  
198 - 197 +
  198 +
199 function getUserForId($iUserId) { 199 function getUserForId($iUserId) {
200 $u = User::get($iUserId); 200 $u = User::get($iUserId);
201 if (PEAR::isError($u) || ($u == false)) { return _kt('User no longer exists'); } 201 if (PEAR::isError($u) || ($u == false)) { return _kt('User no longer exists'); }
202 return $u->getName(); 202 return $u->getName();
203 - } 203 + }
204 } 204 }
205 // }}} 205 // }}}
206 206
@@ -208,7 +208,7 @@ class KTDocumentVersionHistoryAction extends KTDocumentAction { @@ -208,7 +208,7 @@ class KTDocumentVersionHistoryAction extends KTDocumentAction {
208 // {{{ KTDocumentViewAction 208 // {{{ KTDocumentViewAction
209 class KTDocumentViewAction extends KTDocumentAction { 209 class KTDocumentViewAction extends KTDocumentAction {
210 var $sName = 'ktcore.actions.document.view'; 210 var $sName = 'ktcore.actions.document.view';
211 - var $sIconClass = 'download'; 211 + var $sIconClass = 'download';
212 212
213 function getDisplayName() { 213 function getDisplayName() {
214 return _kt('Download'); 214 return _kt('Download');
@@ -230,13 +230,13 @@ class KTDocumentViewAction extends KTDocumentAction { @@ -230,13 +230,13 @@ class KTDocumentViewAction extends KTDocumentAction {
230 } else { 230 } else {
231 $res = $oStorage->download($this->oDocument); 231 $res = $oStorage->download($this->oDocument);
232 } 232 }
233 - 233 +
234 if ($res === false) { 234 if ($res === false) {
235 $this->addErrorMessage(_kt('The file you requested is not available - please contact the system administrator if this is incorrect.')); 235 $this->addErrorMessage(_kt('The file you requested is not available - please contact the system administrator if this is incorrect.'));
236 redirect(generateControllerLink('viewDocument',sprintf(_kt('fDocumentId=%d'),$this->oDocument->getId()))); 236 redirect(generateControllerLink('viewDocument',sprintf(_kt('fDocumentId=%d'),$this->oDocument->getId())));
237 - exit(0); 237 + exit(0);
238 } 238 }
239 - 239 +
240 $oDocumentTransaction = & new DocumentTransaction($this->oDocument, _kt('Document downloaded'), 'ktcore.transactions.download', $aOptions); 240 $oDocumentTransaction = & new DocumentTransaction($this->oDocument, _kt('Document downloaded'), 'ktcore.transactions.download', $aOptions);
241 $oDocumentTransaction->create(); 241 $oDocumentTransaction->create();
242 exit(0); 242 exit(0);
@@ -258,7 +258,7 @@ class KTDocumentCheckOutAction extends KTDocumentAction { @@ -258,7 +258,7 @@ class KTDocumentCheckOutAction extends KTDocumentAction {
258 return _kt('Checkout'); 258 return _kt('Checkout');
259 } 259 }
260 260
261 - function getInfo() { 261 + function getInfo() {
262 if ($this->oDocument->getIsCheckedOut()) { 262 if ($this->oDocument->getIsCheckedOut()) {
263 return null; 263 return null;
264 } 264 }
@@ -272,10 +272,10 @@ class KTDocumentCheckOutAction extends KTDocumentAction { @@ -272,10 +272,10 @@ class KTDocumentCheckOutAction extends KTDocumentAction {
272 return $res; 272 return $res;
273 } 273 }
274 // since we actually check the doc out, then download it ... 274 // since we actually check the doc out, then download it ...
275 - if (($_REQUEST[$this->event_var] == 'checkout_final') && ($this->oDocument->getCheckedOutUserID() == $_SESSION['userID'])) {  
276 - return true; 275 + if (($_REQUEST[$this->event_var] == 'checkout_final') && ($this->oDocument->getCheckedOutUserID() == $_SESSION['userID'])) {
  276 + return true;
277 } 277 }
278 - 278 +
279 // "normal". 279 // "normal".
280 if ($this->oDocument->getIsCheckedOut()) { 280 if ($this->oDocument->getIsCheckedOut()) {
281 $_SESSION['KTErrorMessage'][] = _kt('This document is already checked out'); 281 $_SESSION['KTErrorMessage'][] = _kt('This document is already checked out');
@@ -317,9 +317,9 @@ class KTDocumentCheckOutAction extends KTDocumentAction { @@ -317,9 +317,9 @@ class KTDocumentCheckOutAction extends KTDocumentAction {
317 array('ktcore.validators.boolean', array( 317 array('ktcore.validators.boolean', array(
318 'test' => 'download_file', 318 'test' => 'download_file',
319 'output' => 'download_file', 319 'output' => 'download_file',
320 - )), 320 + )),
321 )); 321 ));
322 - 322 +
323 return $oForm; 323 return $oForm;
324 } 324 }
325 325
@@ -337,13 +337,13 @@ class KTDocumentCheckOutAction extends KTDocumentAction { @@ -337,13 +337,13 @@ class KTDocumentCheckOutAction extends KTDocumentAction {
337 } 337 }
338 338
339 function do_checkout() { 339 function do_checkout() {
340 - 340 +
341 $oForm = $this->form_checkout(); 341 $oForm = $this->form_checkout();
342 $res = $oForm->validate(); 342 $res = $oForm->validate();
343 if (!empty($res['errors'])) { 343 if (!empty($res['errors'])) {
344 return $oForm->handleError(); 344 return $oForm->handleError();
345 } 345 }
346 - 346 +
347 $data = $res['results']; 347 $data = $res['results'];
348 348
349 $oTemplate =& $this->oValidator->validateTemplate('ktcore/action/checkout_final'); 349 $oTemplate =& $this->oValidator->validateTemplate('ktcore/action/checkout_final');
@@ -354,17 +354,17 @@ class KTDocumentCheckOutAction extends KTDocumentAction { @@ -354,17 +354,17 @@ class KTDocumentCheckOutAction extends KTDocumentAction {
354 if (PEAR::isError($res)) { 354 if (PEAR::isError($res)) {
355 return $this->errorRedirectToMain(sprintf(_kt('Failed to check out the document: %s'), $res->getMessage())); 355 return $this->errorRedirectToMain(sprintf(_kt('Failed to check out the document: %s'), $res->getMessage()));
356 } 356 }
357 -  
358 357
359 - 358 +
  359 +
360 $this->commitTransaction(); 360 $this->commitTransaction();
361 - 361 +
362 if (!$data['download_file']) { 362 if (!$data['download_file']) {
363 $this->addInfoMessage(_kt('Document checked out.')); 363 $this->addInfoMessage(_kt('Document checked out.'));
364 redirect(KTBrowseUtil::getUrlForDocument($this->oDocument)); 364 redirect(KTBrowseUtil::getUrlForDocument($this->oDocument));
365 exit(0); 365 exit(0);
366 } 366 }
367 - 367 +
368 $oTemplate->setData(array( 368 $oTemplate->setData(array(
369 'context' => &$this, 369 'context' => &$this,
370 'reason' => $sReason, 370 'reason' => $sReason,
@@ -376,7 +376,7 @@ class KTDocumentCheckOutAction extends KTDocumentAction { @@ -376,7 +376,7 @@ class KTDocumentCheckOutAction extends KTDocumentAction {
376 $sReason = KTUtil::arrayGet($_REQUEST, 'reason'); 376 $sReason = KTUtil::arrayGet($_REQUEST, 'reason');
377 $this->oValidator->notEmpty($sReason); 377 $this->oValidator->notEmpty($sReason);
378 378
379 - 379 +
380 $oStorage =& KTStorageManagerUtil::getSingleton(); 380 $oStorage =& KTStorageManagerUtil::getSingleton();
381 $oStorage->download($this->oDocument, true); 381 $oStorage->download($this->oDocument, true);
382 exit(0); 382 exit(0);
@@ -446,33 +446,33 @@ class KTDocumentCheckInAction extends KTDocumentAction { @@ -446,33 +446,33 @@ class KTDocumentCheckInAction extends KTDocumentAction {
446 'context' => &$this, 446 'context' => &$this,
447 'file_upload' => true, // otherwise the post is not received. 447 'file_upload' => true, // otherwise the post is not received.
448 )); 448 ));
449 - 449 +
450 $major_inc = sprintf('%d.%d', $this->oDocument->getMajorVersionNumber()+1, 0); 450 $major_inc = sprintf('%d.%d', $this->oDocument->getMajorVersionNumber()+1, 0);
451 - $minor_inc = sprintf('%d.%d', $this->oDocument->getMajorVersionNumber(), $this->oDocument->getMinorVersionNumber()+1);  
452 - 451 + $minor_inc = sprintf('%d.%d', $this->oDocument->getMajorVersionNumber(), $this->oDocument->getMinorVersionNumber()+1);
  452 +
453 $oForm->setWidgets(array( 453 $oForm->setWidgets(array(
454 array('ktcore.widgets.file', array( 454 array('ktcore.widgets.file', array(
455 'label' => _kt('File'), 455 'label' => _kt('File'),
456 - 'description' => sprintf(_kt('Please specify the file you wish to upload. Unless you also indicate that you are changing its filename (see "Force Original Filename" below), this will need to be called <strong>%s</strong>'), $this->oDocument->getFilename()), 456 + 'description' => sprintf(_kt('Please specify the file you wish to upload. Unless you also indicate that you are changing its filename (see "Force Original Filename" below), this will need to be called <strong>%s</strong>'), htmlentities($this->oDocument->getFilename(),ENT_QUOTES,'UTF-8')),
457 'name' => 'file', 457 'name' => 'file',
458 'basename' => 'file', 458 'basename' => 'file',
459 'required' => true, 459 'required' => true,
460 )), 460 )),
461 array('ktcore.widgets.boolean',array( 461 array('ktcore.widgets.boolean',array(
462 - 'label' => _kt('Major Update'),  
463 - 'description' => sprintf(_kt('If this is checked, then the document\'s version number will be increased to %s. Otherwise, it will be considered a minor update, and the version number will be %s.'), $major_inc, $minor_inc),  
464 - 'name' => 'major_update', 462 + 'label' => _kt('Major Update'),
  463 + 'description' => sprintf(_kt('If this is checked, then the document\'s version number will be increased to %s. Otherwise, it will be considered a minor update, and the version number will be %s.'), $major_inc, $minor_inc),
  464 + 'name' => 'major_update',
465 'value' => false, 465 'value' => false,
466 - )), 466 + )),
467 array('ktcore.widgets.reason', array( 467 array('ktcore.widgets.reason', array(
468 'label' => _kt('Reason'), 468 'label' => _kt('Reason'),
469 'description' => _kt('Please describe the changes you made to the document. Bear in mind that you can use a maximum of <strong>250</strong> characters.'), 469 'description' => _kt('Please describe the changes you made to the document. Bear in mind that you can use a maximum of <strong>250</strong> characters.'),
470 'name' => 'reason', 470 'name' => 'reason',
471 )), 471 )),
472 array('ktcore.widgets.boolean',array( 472 array('ktcore.widgets.boolean',array(
473 - 'label' => _kt('Force Original Filename'),  
474 - 'description' => sprintf(_kt('If this is checked, the uploaded document must have the same filename as the original: <strong>%s</strong>'), $this->oDocument->getFilename()),  
475 - 'name' => 'forcefilename', 473 + 'label' => _kt('Force Original Filename'),
  474 + 'description' => sprintf(_kt('If this is checked, the uploaded document must have the same filename as the original: <strong>%s</strong>'), htmlentities($this->oDocument->getFilename(),ENT_QUOTES,'UTF-8')),
  475 + 'name' => 'forcefilename',
476 'value' => true, 476 'value' => true,
477 )), 477 )),
478 )); 478 ));
@@ -485,17 +485,17 @@ class KTDocumentCheckInAction extends KTDocumentAction { @@ -485,17 +485,17 @@ class KTDocumentCheckInAction extends KTDocumentAction {
485 array('ktcore.validators.boolean', array( 485 array('ktcore.validators.boolean', array(
486 'test' => 'major_update', 486 'test' => 'major_update',
487 'output' => 'major_update', 487 'output' => 'major_update',
488 - )), 488 + )),
489 array('ktcore.validators.file', array( 489 array('ktcore.validators.file', array(
490 'test' => 'file', 490 'test' => 'file',
491 'output' => 'file', 491 'output' => 'file',
492 - )), 492 + )),
493 array('ktcore.validators.boolean', array( 493 array('ktcore.validators.boolean', array(
494 'test' => 'forcefilename', 494 'test' => 'forcefilename',
495 'output' => 'forcefilename', 495 'output' => 'forcefilename',
496 - )), 496 + )),
497 )); 497 ));
498 - 498 +
499 return $oForm; 499 return $oForm;
500 } 500 }
501 501
@@ -503,7 +503,7 @@ class KTDocumentCheckInAction extends KTDocumentAction { @@ -503,7 +503,7 @@ class KTDocumentCheckInAction extends KTDocumentAction {
503 function do_main() { 503 function do_main() {
504 $this->oPage->setBreadcrumbDetails(_kt('Checkin')); 504 $this->oPage->setBreadcrumbDetails(_kt('Checkin'));
505 $oTemplate =& $this->oValidator->validateTemplate('ktcore/action/checkin'); 505 $oTemplate =& $this->oValidator->validateTemplate('ktcore/action/checkin');
506 - 506 +
507 $oForm = $this->form_main(); 507 $oForm = $this->form_main();
508 508
509 $oTemplate->setData(array( 509 $oTemplate->setData(array(
@@ -517,24 +517,24 @@ class KTDocumentCheckInAction extends KTDocumentAction { @@ -517,24 +517,24 @@ class KTDocumentCheckInAction extends KTDocumentAction {
517 $oForm = $this->form_main(); 517 $oForm = $this->form_main();
518 $res = $oForm->validate(); 518 $res = $oForm->validate();
519 $data = $res['results']; 519 $data = $res['results'];
520 - 520 +
521 $extra_errors = array(); 521 $extra_errors = array();
522 - 522 +
523 if ($data['forcefilename'] && ($data['file']['name'] != $this->oDocument->getFilename())) { 523 if ($data['forcefilename'] && ($data['file']['name'] != $this->oDocument->getFilename())) {
524 - $extra_errors['file'] = sprintf(_kt('The file you uploaded was not called "%s". If you wish to change the filename, please set "Force Original Filename" below to false. '), $this->oDocument->getFilename()); 524 + $extra_errors['file'] = sprintf(_kt('The file you uploaded was not called "%s". If you wish to change the filename, please set "Force Original Filename" below to false. '), htmlentities($this->oDocument->getFilename(),ENT_QUOTES,'UTF-8'));
525 } 525 }
526 - 526 +
527 if (!empty($res['errors']) || !empty($extra_errors)) { 527 if (!empty($res['errors']) || !empty($extra_errors)) {
528 return $oForm->handleError(null, $extra_errors); 528 return $oForm->handleError(null, $extra_errors);
529 } 529 }
530 - 530 +
531 $sReason = $data['reason']; 531 $sReason = $data['reason'];
532 - 532 +
533 $sCurrentFilename = $this->oDocument->getFileName(); 533 $sCurrentFilename = $this->oDocument->getFileName();
534 $sNewFilename = $data['file']['name']; 534 $sNewFilename = $data['file']['name'];
535 535
536 $aOptions = array(); 536 $aOptions = array();
537 - 537 +
538 if ($data['major_update']) { 538 if ($data['major_update']) {
539 $aOptions['major_update'] = true; 539 $aOptions['major_update'] = true;
540 } 540 }
@@ -542,7 +542,7 @@ class KTDocumentCheckInAction extends KTDocumentAction { @@ -542,7 +542,7 @@ class KTDocumentCheckInAction extends KTDocumentAction {
542 if ($sCurrentFilename != $sNewFilename) { 542 if ($sCurrentFilename != $sNewFilename) {
543 $aOptions['newfilename'] = $sNewFilename; 543 $aOptions['newfilename'] = $sNewFilename;
544 } 544 }
545 - 545 +
546 $res = KTDocumentUtil::checkin($this->oDocument, $data['file']['tmp_name'], $sReason, $this->oUser, $aOptions); 546 $res = KTDocumentUtil::checkin($this->oDocument, $data['file']['tmp_name'], $sReason, $this->oUser, $aOptions);
547 if (PEAR::isError($res)) { 547 if (PEAR::isError($res)) {
548 $this->errorRedirectToMain(_kt('An error occurred while trying to check in the document'), 'fDocumentId=' . $this->oDocument->getId() . '&reason=' . $sReason); 548 $this->errorRedirectToMain(_kt('An error occurred while trying to check in the document'), 'fDocumentId=' . $this->oDocument->getId() . '&reason=' . $sReason);
@@ -561,7 +561,7 @@ class KTDocumentCancelCheckOutAction extends KTDocumentAction { @@ -561,7 +561,7 @@ class KTDocumentCancelCheckOutAction extends KTDocumentAction {
561 var $_sShowPermission = 'ktcore.permissions.write'; 561 var $_sShowPermission = 'ktcore.permissions.write';
562 var $bAllowInAdminMode = true; 562 var $bAllowInAdminMode = true;
563 var $bInAdminMode = null; 563 var $bInAdminMode = null;
564 - var $sIconClass = 'cancel_checkout'; 564 + var $sIconClass = 'cancel_checkout';
565 565
566 function getDisplayName() { 566 function getDisplayName() {
567 return _kt('Cancel Checkout'); 567 return _kt('Cancel Checkout');
@@ -573,10 +573,10 @@ class KTDocumentCancelCheckOutAction extends KTDocumentAction { @@ -573,10 +573,10 @@ class KTDocumentCancelCheckOutAction extends KTDocumentAction {
573 } 573 }
574 if (is_null($this->bInAdminMode)) { 574 if (is_null($this->bInAdminMode)) {
575 $oFolder = Folder::get($this->oDocument->getFolderId()); 575 $oFolder = Folder::get($this->oDocument->getFolderId());
576 - if (KTBrowseUtil::inAdminMode($this->oUser, $oFolder)) { 576 + if (KTBrowseUtil::inAdminMode($this->oUser, $oFolder)) {
577 $this->bAdminMode = true; 577 $this->bAdminMode = true;
578 - return parent::getInfo();  
579 - } 578 + return parent::getInfo();
  579 + }
580 } else if ($this->bInAdminMode == true) { 580 } else if ($this->bInAdminMode == true) {
581 return parent::getInfo(); 581 return parent::getInfo();
582 } 582 }
@@ -588,7 +588,7 @@ class KTDocumentCancelCheckOutAction extends KTDocumentAction { @@ -588,7 +588,7 @@ class KTDocumentCancelCheckOutAction extends KTDocumentAction {
588 588
589 function check() { 589 function check() {
590 $res = parent::check(); 590 $res = parent::check();
591 - 591 +
592 if ($res !== true) { 592 if ($res !== true) {
593 return $res; 593 return $res;
594 } 594 }
@@ -600,10 +600,10 @@ class KTDocumentCancelCheckOutAction extends KTDocumentAction { @@ -600,10 +600,10 @@ class KTDocumentCancelCheckOutAction extends KTDocumentAction {
600 // hard override if we're in admin mode for this doc. 600 // hard override if we're in admin mode for this doc.
601 if (is_null($this->bInAdminMode)) { 601 if (is_null($this->bInAdminMode)) {
602 $oFolder = Folder::get($this->oDocument->getFolderId()); 602 $oFolder = Folder::get($this->oDocument->getFolderId());
603 - if (KTBrowseUtil::inAdminMode($this->oUser, $oFolder)) { 603 + if (KTBrowseUtil::inAdminMode($this->oUser, $oFolder)) {
604 $this->bAdminMode = true; 604 $this->bAdminMode = true;
605 - return true;  
606 - } 605 + return true;
  606 + }
607 } else if ($this->bInAdminMode == true) { 607 } else if ($this->bInAdminMode == true) {
608 return true; 608 return true;
609 } 609 }
@@ -639,16 +639,16 @@ class KTDocumentCancelCheckOutAction extends KTDocumentAction { @@ -639,16 +639,16 @@ class KTDocumentCancelCheckOutAction extends KTDocumentAction {
639 'output' => 'reason', 639 'output' => 'reason',
640 )), 640 )),
641 )); 641 ));
642 - 642 +
643 return $oForm; 643 return $oForm;
644 } 644 }
645 645
646 function do_main() { 646 function do_main() {
647 $this->oPage->setBreadcrumbDetails(_kt('cancel checkout')); 647 $this->oPage->setBreadcrumbDetails(_kt('cancel checkout'));
648 $oTemplate =& $this->oValidator->validateTemplate('ktcore/action/cancel_checkout'); 648 $oTemplate =& $this->oValidator->validateTemplate('ktcore/action/cancel_checkout');
649 - 649 +
650 $oForm = $this->form_main(); 650 $oForm = $this->form_main();
651 - 651 +
652 $oTemplate->setData(array( 652 $oTemplate->setData(array(
653 'context' => &$this, 653 'context' => &$this,
654 'form' => $oForm, 654 'form' => $oForm,
@@ -663,9 +663,9 @@ class KTDocumentCancelCheckOutAction extends KTDocumentAction { @@ -663,9 +663,9 @@ class KTDocumentCancelCheckOutAction extends KTDocumentAction {
663 if (!empty($res['errors'])) { 663 if (!empty($res['errors'])) {
664 return $oForm->handleError(); 664 return $oForm->handleError();
665 } 665 }
666 - 666 +
667 $data = $res['results']; 667 $data = $res['results'];
668 - 668 +
669 $this->startTransaction(); 669 $this->startTransaction();
670 // actually do the checkin. 670 // actually do the checkin.
671 $this->oDocument->setIsCheckedOut(0); 671 $this->oDocument->setIsCheckedOut(0);
@@ -675,7 +675,7 @@ class KTDocumentCancelCheckOutAction extends KTDocumentAction { @@ -675,7 +675,7 @@ class KTDocumentCancelCheckOutAction extends KTDocumentAction {
675 $this->rollbackTransaction(); 675 $this->rollbackTransaction();
676 return $this->errorRedirectToMain(_kt('Failed to force the document\'s checkin.'),sprintf('fDocumentId=%d'),$this->oDocument->getId()); 676 return $this->errorRedirectToMain(_kt('Failed to force the document\'s checkin.'),sprintf('fDocumentId=%d'),$this->oDocument->getId());
677 } 677 }
678 - 678 +
679 // checkout cancelled transaction 679 // checkout cancelled transaction
680 $oDocumentTransaction = & new DocumentTransaction($this->oDocument, $data['reason'], 'ktcore.transactions.force_checkin'); 680 $oDocumentTransaction = & new DocumentTransaction($this->oDocument, $data['reason'], 'ktcore.transactions.force_checkin');
681 $res = $oDocumentTransaction->create(); 681 $res = $oDocumentTransaction->create();
@@ -683,7 +683,7 @@ class KTDocumentCancelCheckOutAction extends KTDocumentAction { @@ -683,7 +683,7 @@ class KTDocumentCancelCheckOutAction extends KTDocumentAction {
683 $this->rollbackTransaction(); 683 $this->rollbackTransaction();
684 return $this->errorRedirectToMain(_kt('Failed to force the document\'s checkin.'),sprintf('fDocumentId=%d'),$this->oDocument->getId()); 684 return $this->errorRedirectToMain(_kt('Failed to force the document\'s checkin.'),sprintf('fDocumentId=%d'),$this->oDocument->getId());
685 } 685 }
686 - $this->commitTransaction(); 686 + $this->commitTransaction();
687 redirect(KTBrowseUtil::getUrlForDocument($this->oDocument)); 687 redirect(KTBrowseUtil::getUrlForDocument($this->oDocument));
688 } 688 }
689 } 689 }
@@ -746,7 +746,7 @@ class KTDocumentDeleteAction extends KTDocumentAction { @@ -746,7 +746,7 @@ class KTDocumentDeleteAction extends KTDocumentAction {
746 'output' => 'reason', 746 'output' => 'reason',
747 )), 747 )),
748 )); 748 ));
749 - 749 +
750 return $oForm; 750 return $oForm;
751 } 751 }
752 752
@@ -770,17 +770,17 @@ class KTDocumentDeleteAction extends KTDocumentAction { @@ -770,17 +770,17 @@ class KTDocumentDeleteAction extends KTDocumentAction {
770 if (!empty($res['errors'])) { 770 if (!empty($res['errors'])) {
771 return $oForm->handleError(); 771 return $oForm->handleError();
772 } 772 }
773 - 773 +
774 $sReason = $data['reason']; 774 $sReason = $data['reason'];
775 - 775 +
776 $fFolderId = $this->oDocument->getFolderId(); 776 $fFolderId = $this->oDocument->getFolderId();
777 $res = KTDocumentUtil::delete($this->oDocument, $sReason); 777 $res = KTDocumentUtil::delete($this->oDocument, $sReason);
778 if (PEAR::isError($res)) { 778 if (PEAR::isError($res)) {
779 $this->errorRedirectToMain(sprintf(_kt('Unexpected failure deleting document: %s'), $res->getMessage())); 779 $this->errorRedirectToMain(sprintf(_kt('Unexpected failure deleting document: %s'), $res->getMessage()));
780 - } 780 + }
781 781
782 $_SESSION['KTInfoMessage'][] = sprintf(_kt('Document "%s" Deleted.'),$this->oDocument->getName()); 782 $_SESSION['KTInfoMessage'][] = sprintf(_kt('Document "%s" Deleted.'),$this->oDocument->getName());
783 - 783 +
784 controllerRedirect('browse', 'fFolderId=' . $fFolderId); 784 controllerRedirect('browse', 'fFolderId=' . $fFolderId);
785 exit(0); 785 exit(0);
786 } 786 }
@@ -838,15 +838,15 @@ class KTDocumentMoveAction extends KTDocumentAction { @@ -838,15 +838,15 @@ class KTDocumentMoveAction extends KTDocumentAction {
838 'cancel_url' => KTBrowseUtil::getUrlForDocument($this->oDocument), 838 'cancel_url' => KTBrowseUtil::getUrlForDocument($this->oDocument),
839 'fail_action' => 'main', 839 'fail_action' => 'main',
840 'context' => $this, 840 'context' => $this,
841 - )); 841 + ));
842 842
843 /* 843 /*
844 * This is somewhat more complex than most forms, since the "filename" 844 * This is somewhat more complex than most forms, since the "filename"
845 * and title shouldn't appear unless there's a clash. 845 * and title shouldn't appear unless there's a clash.
846 * 846 *
847 * This is still not the most elegant solution. 847 * This is still not the most elegant solution.
848 - */  
849 - 848 + */
  849 +
850 $oForm->setWidgets(array( 850 $oForm->setWidgets(array(
851 array('ktcore.widgets.foldercollection', array( 851 array('ktcore.widgets.foldercollection', array(
852 'label' => _kt('Target Folder'), 852 'label' => _kt('Target Folder'),
@@ -861,8 +861,8 @@ class KTDocumentMoveAction extends KTDocumentAction { @@ -861,8 +861,8 @@ class KTDocumentMoveAction extends KTDocumentAction {
861 'name' => 'reason', 861 'name' => 'reason',
862 )), 862 )),
863 )); 863 ));
864 -  
865 - 864 +
  865 +
866 $oForm->setValidators(array( 866 $oForm->setValidators(array(
867 array('ktcore.validators.string', array( 867 array('ktcore.validators.string', array(
868 'test' => 'reason', 868 'test' => 'reason',
@@ -874,10 +874,10 @@ class KTDocumentMoveAction extends KTDocumentAction { @@ -874,10 +874,10 @@ class KTDocumentMoveAction extends KTDocumentAction {
874 'test' => 'browse', 874 'test' => 'browse',
875 'output' => 'browse', 875 'output' => 'browse',
876 )), 876 )),
877 - ));  
878 - 877 + ));
  878 +
879 // here's the ugly bit. 879 // here's the ugly bit.
880 - 880 +
881 $err = $oForm->getErrors(); 881 $err = $oForm->getErrors();
882 if (!empty($err['name']) || !empty($err['filename'])) { 882 if (!empty($err['name']) || !empty($err['filename'])) {
883 $oForm->addWidget( 883 $oForm->addWidget(
@@ -914,7 +914,7 @@ class KTDocumentMoveAction extends KTDocumentAction { @@ -914,7 +914,7 @@ class KTDocumentMoveAction extends KTDocumentAction {
914 } 914 }
915 return $oForm; 915 return $oForm;
916 } 916 }
917 - 917 +
918 function do_move() { 918 function do_move() {
919 $oForm = $this->form_move(); 919 $oForm = $this->form_move();
920 $res = $oForm->validate(); 920 $res = $oForm->validate();
@@ -926,59 +926,59 @@ class KTDocumentMoveAction extends KTDocumentAction { @@ -926,59 +926,59 @@ class KTDocumentMoveAction extends KTDocumentAction {
926 if ($data['browse']->getId() == $this->oDocument->getFolderID()) { 926 if ($data['browse']->getId() == $this->oDocument->getFolderID()) {
927 $extra_errors['browse'] = _kt('You cannot move the document within the same folder.'); 927 $extra_errors['browse'] = _kt('You cannot move the document within the same folder.');
928 } else { 928 } else {
929 - $bNameClash = KTDocumentUtil::nameExists($data['browse'], $this->oDocument->getName()); 929 + $bNameClash = KTDocumentUtil::nameExists($data['browse'], $this->oDocument->getName());
930 if ($bNameClash && isset($data['name'])) { 930 if ($bNameClash && isset($data['name'])) {
931 $name = $data['name']; 931 $name = $data['name'];
932 - $bNameClash = KTDocumentUtil::nameExists($data['browse'], $name); 932 + $bNameClash = KTDocumentUtil::nameExists($data['browse'], $name);
933 } else { 933 } else {
934 $name = $this->oDocument->getName(); 934 $name = $this->oDocument->getName();
935 } 935 }
936 if ($bNameClash) { 936 if ($bNameClash) {
937 $extra_errors['name'] = _kt('A document with this title already exists in your chosen folder. Please choose a different folder, or specify a new title for the copied document.'); 937 $extra_errors['name'] = _kt('A document with this title already exists in your chosen folder. Please choose a different folder, or specify a new title for the copied document.');
938 } 938 }
939 -  
940 - $bFileClash = KTDocumentUtil::fileExists($data['browse'], $this->oDocument->getFilename()); 939 +
  940 + $bFileClash = KTDocumentUtil::fileExists($data['browse'], $this->oDocument->getFilename());
941 if ($bFileClash && isset($data['filename'])) { 941 if ($bFileClash && isset($data['filename'])) {
942 $filename = $data['filename']; 942 $filename = $data['filename'];
943 - $bFileClash = KTDocumentUtil::fileExists($data['browse'], $filename); 943 + $bFileClash = KTDocumentUtil::fileExists($data['browse'], $filename);
944 } else { 944 } else {
945 $filename = $this->oDocument->getFilename(); 945 $filename = $this->oDocument->getFilename();
946 - } 946 + }
947 if ($bFileClash) { 947 if ($bFileClash) {
948 $extra_errors['filename'] = _kt('A document with this filename already exists in your chosen folder. Please choose a different folder, or specify a new filename for the copied document.'); 948 $extra_errors['filename'] = _kt('A document with this filename already exists in your chosen folder. Please choose a different folder, or specify a new filename for the copied document.');
949 } 949 }
950 - 950 +
951 if (!Permission::userHasFolderWritePermission($data['browse'])) { 951 if (!Permission::userHasFolderWritePermission($data['browse'])) {
952 $extra_errors['browse'] = _kt('You do not have permission to create new documents in that folder.'); 952 $extra_errors['browse'] = _kt('You do not have permission to create new documents in that folder.');
953 } 953 }
954 } 954 }
955 } 955 }
956 - 956 +
957 if (!empty($errors) || !empty($extra_errors)) { 957 if (!empty($errors) || !empty($extra_errors)) {
958 - return $oForm->handleError(null, $extra_errors); 958 + return $oForm->handleError(null, $extra_errors);
959 } 959 }
960 - 960 +
961 $this->startTransaction(); 961 $this->startTransaction();
962 // now try update it. 962 // now try update it.
963 - 963 +
964 $res = KTDocumentUtil::move($this->oDocument, $data['browse'], $this->oUser, $sReason); 964 $res = KTDocumentUtil::move($this->oDocument, $data['browse'], $this->oUser, $sReason);
965 if (PEAR::isError($oNewDoc)) { 965 if (PEAR::isError($oNewDoc)) {
966 $this->errorRedirectTo('main', _kt('Failed to move document: ') . $oNewDoc->getMessage()); 966 $this->errorRedirectTo('main', _kt('Failed to move document: ') . $oNewDoc->getMessage());
967 exit(0); 967 exit(0);
968 } 968 }
969 - 969 +
970 $this->oDocument->setName($name); // if needed. 970 $this->oDocument->setName($name); // if needed.
971 $this->oDocument->setFilename($filename); // if needed. 971 $this->oDocument->setFilename($filename); // if needed.
972 - 972 +
973 $res = $this->oDocument->update(); 973 $res = $this->oDocument->update();
974 if (PEAR::isError($res)) { 974 if (PEAR::isError($res)) {
975 return $this->errorRedirectTo('main', _kt('Failed to move document: ') . $res->getMessage()); 975 return $this->errorRedirectTo('main', _kt('Failed to move document: ') . $res->getMessage());
976 } 976 }
977 977
978 $this->commitTransaction(); 978 $this->commitTransaction();
979 - 979 +
980 controllerRedirect('viewDocument', 'fDocumentId=' . $this->oDocument->getId()); 980 controllerRedirect('viewDocument', 'fDocumentId=' . $this->oDocument->getId());
981 - exit(0); 981 + exit(0);
982 } 982 }
983 983
984 } 984 }
@@ -1009,7 +1009,7 @@ class KTDocumentCopyAction extends KTDocumentAction { @@ -1009,7 +1009,7 @@ class KTDocumentCopyAction extends KTDocumentAction {
1009 if ($this->oDocument->getIsCheckedOut()) { 1009 if ($this->oDocument->getIsCheckedOut()) {
1010 return null; 1010 return null;
1011 } 1011 }
1012 - 1012 +
1013 return parent::getInfo(); 1013 return parent::getInfo();
1014 } 1014 }
1015 1015
@@ -1028,7 +1028,7 @@ class KTDocumentCopyAction extends KTDocumentAction { @@ -1028,7 +1028,7 @@ class KTDocumentCopyAction extends KTDocumentAction {
1028 $this->oDocumentFolder = $this->oValidator->validateFolder($this->oDocument->getFolderId()); 1028 $this->oDocumentFolder = $this->oValidator->validateFolder($this->oDocument->getFolderId());
1029 return true; 1029 return true;
1030 } 1030 }
1031 - 1031 +
1032 function form_copyselection() { 1032 function form_copyselection() {
1033 $oForm = new KTForm; 1033 $oForm = new KTForm;
1034 $oForm->setOptions(array( 1034 $oForm->setOptions(array(
@@ -1039,15 +1039,15 @@ class KTDocumentCopyAction extends KTDocumentAction { @@ -1039,15 +1039,15 @@ class KTDocumentCopyAction extends KTDocumentAction {
1039 'cancel_url' => KTBrowseUtil::getUrlForDocument($this->oDocument), 1039 'cancel_url' => KTBrowseUtil::getUrlForDocument($this->oDocument),
1040 'fail_action' => 'main', 1040 'fail_action' => 'main',
1041 'context' => $this, 1041 'context' => $this,
1042 - )); 1042 + ));
1043 1043
1044 /* 1044 /*
1045 * This is somewhat more complex than most forms, since the "filename" 1045 * This is somewhat more complex than most forms, since the "filename"
1046 * and title shouldn't appear unless there's a clash. 1046 * and title shouldn't appear unless there's a clash.
1047 * 1047 *
1048 * This is still not the most elegant solution. 1048 * This is still not the most elegant solution.
1049 - */  
1050 - 1049 + */
  1050 +
1051 $oForm->setWidgets(array( 1051 $oForm->setWidgets(array(
1052 array('ktcore.widgets.foldercollection', array( 1052 array('ktcore.widgets.foldercollection', array(
1053 'label' => _kt('Target Folder'), 1053 'label' => _kt('Target Folder'),
@@ -1062,8 +1062,8 @@ class KTDocumentCopyAction extends KTDocumentAction { @@ -1062,8 +1062,8 @@ class KTDocumentCopyAction extends KTDocumentAction {
1062 'name' => 'reason', 1062 'name' => 'reason',
1063 )), 1063 )),
1064 )); 1064 ));
1065 -  
1066 - 1065 +
  1066 +
1067 $oForm->setValidators(array( 1067 $oForm->setValidators(array(
1068 array('ktcore.validators.string', array( 1068 array('ktcore.validators.string', array(
1069 'test' => 'reason', 1069 'test' => 'reason',
@@ -1075,10 +1075,10 @@ class KTDocumentCopyAction extends KTDocumentAction { @@ -1075,10 +1075,10 @@ class KTDocumentCopyAction extends KTDocumentAction {
1075 'test' => 'browse', 1075 'test' => 'browse',
1076 'output' => 'browse', 1076 'output' => 'browse',
1077 )), 1077 )),
1078 - ));  
1079 - 1078 + ));
  1079 +
1080 // here's the ugly bit. 1080 // here's the ugly bit.
1081 - 1081 +
1082 $err = $oForm->getErrors(); 1082 $err = $oForm->getErrors();
1083 if (!empty($err['name']) || !empty($err['filename'])) { 1083 if (!empty($err['name']) || !empty($err['filename'])) {
1084 $oForm->addWidget( 1084 $oForm->addWidget(
@@ -1122,7 +1122,7 @@ class KTDocumentCopyAction extends KTDocumentAction { @@ -1122,7 +1122,7 @@ class KTDocumentCopyAction extends KTDocumentAction {
1122 return $oForm->renderPage(_kt('Copy Document') . ': ' . $this->oDocument->getName()); 1122 return $oForm->renderPage(_kt('Copy Document') . ': ' . $this->oDocument->getName());
1123 } 1123 }
1124 1124
1125 - function do_copy() { 1125 + function do_copy() {
1126 $oForm = $this->form_copyselection(); 1126 $oForm = $this->form_copyselection();
1127 $res = $oForm->validate(); 1127 $res = $oForm->validate();
1128 $errors = $res['errors']; 1128 $errors = $res['errors'];
@@ -1131,59 +1131,59 @@ class KTDocumentCopyAction extends KTDocumentAction { @@ -1131,59 +1131,59 @@ class KTDocumentCopyAction extends KTDocumentAction {
1131 1131
1132 1132
1133 if (!is_null($data['browse'])) { 1133 if (!is_null($data['browse'])) {
1134 - $bNameClash = KTDocumentUtil::nameExists($data['browse'], $this->oDocument->getName()); 1134 + $bNameClash = KTDocumentUtil::nameExists($data['browse'], $this->oDocument->getName());
1135 if ($bNameClash && isset($data['name'])) { 1135 if ($bNameClash && isset($data['name'])) {
1136 $name = $data['name']; 1136 $name = $data['name'];
1137 - $bNameClash = KTDocumentUtil::nameExists($data['browse'], $name); 1137 + $bNameClash = KTDocumentUtil::nameExists($data['browse'], $name);
1138 } else { 1138 } else {
1139 $name = $this->oDocument->getName(); 1139 $name = $this->oDocument->getName();
1140 } 1140 }
1141 if ($bNameClash) { 1141 if ($bNameClash) {
1142 $extra_errors['name'] = _kt('A document with this title already exists in your chosen folder. Please choose a different folder, or specify a new title for the copied document.'); 1142 $extra_errors['name'] = _kt('A document with this title already exists in your chosen folder. Please choose a different folder, or specify a new title for the copied document.');
1143 } 1143 }
1144 -  
1145 - $bFileClash = KTDocumentUtil::fileExists($data['browse'], $this->oDocument->getFilename()); 1144 +
  1145 + $bFileClash = KTDocumentUtil::fileExists($data['browse'], $this->oDocument->getFilename());
1146 1146
1147 if ($bFileClash && isset($data['filename'])) { 1147 if ($bFileClash && isset($data['filename'])) {
1148 $filename = $data['filename']; 1148 $filename = $data['filename'];
1149 - $bFileClash = KTDocumentUtil::fileExists($data['browse'], $filename); 1149 + $bFileClash = KTDocumentUtil::fileExists($data['browse'], $filename);
1150 } else { 1150 } else {
1151 $filename = $this->oDocument->getFilename(); 1151 $filename = $this->oDocument->getFilename();
1152 - } 1152 + }
1153 if ($bFileClash) { 1153 if ($bFileClash) {
1154 $extra_errors['filename'] = _kt('A document with this filename already exists in your chosen folder. Please choose a different folder, or specify a new filename for the copied document.'); 1154 $extra_errors['filename'] = _kt('A document with this filename already exists in your chosen folder. Please choose a different folder, or specify a new filename for the copied document.');
1155 } 1155 }
1156 - 1156 +
1157 if (!Permission::userHasFolderWritePermission($data['browse'])) { 1157 if (!Permission::userHasFolderWritePermission($data['browse'])) {
1158 $extra_errors['browse'] = _kt('You do not have permission to create new documents in that folder.'); 1158 $extra_errors['browse'] = _kt('You do not have permission to create new documents in that folder.');
1159 } 1159 }
1160 } 1160 }
1161 - 1161 +
1162 if (!empty($errors) || !empty($extra_errors)) { 1162 if (!empty($errors) || !empty($extra_errors)) {
1163 - return $oForm->handleError(null, $extra_errors); 1163 + return $oForm->handleError(null, $extra_errors);
1164 } 1164 }
1165 - 1165 +
1166 // FIXME agree on document-duplication rules re: naming, etc. 1166 // FIXME agree on document-duplication rules re: naming, etc.
1167 - 1167 +
1168 $this->startTransaction(); 1168 $this->startTransaction();
1169 // now try update it. 1169 // now try update it.
1170 - 1170 +
1171 $oNewDoc = KTDocumentUtil::copy($this->oDocument, $data['browse'], $sReason); 1171 $oNewDoc = KTDocumentUtil::copy($this->oDocument, $data['browse'], $sReason);
1172 if (PEAR::isError($oNewDoc)) { 1172 if (PEAR::isError($oNewDoc)) {
1173 $this->errorRedirectTo('main', _kt('Failed to copy document: ') . $oNewDoc->getMessage(), sprintf('fDocumentId=%d&fFolderId=%d', $this->oDocument->getId(), $this->oFolder->getId())); 1173 $this->errorRedirectTo('main', _kt('Failed to copy document: ') . $oNewDoc->getMessage(), sprintf('fDocumentId=%d&fFolderId=%d', $this->oDocument->getId(), $this->oFolder->getId()));
1174 exit(0); 1174 exit(0);
1175 } 1175 }
1176 - 1176 +
1177 $oNewDoc->setName($name); 1177 $oNewDoc->setName($name);
1178 $oNewDoc->setFilename($filename); 1178 $oNewDoc->setFilename($filename);
1179 - 1179 +
1180 $res = $oNewDoc->update(); 1180 $res = $oNewDoc->update();
1181 if (PEAR::isError($res)) { 1181 if (PEAR::isError($res)) {
1182 return $this->errorRedirectTo('main', _kt('Failed to copy document: ') . $res->getMessage(), sprintf('fDocumentId=%d&fFolderId=%d', $this->oDocument->getId(), $this->oFolder->getId())); 1182 return $this->errorRedirectTo('main', _kt('Failed to copy document: ') . $res->getMessage(), sprintf('fDocumentId=%d&fFolderId=%d', $this->oDocument->getId(), $this->oFolder->getId()));
1183 } 1183 }
1184 1184
1185 $this->commitTransaction(); 1185 $this->commitTransaction();
1186 - 1186 +
1187 // FIXME do we need to refactor all trigger usage into the util function? 1187 // FIXME do we need to refactor all trigger usage into the util function?
1188 $oKTTriggerRegistry = KTTriggerRegistry::getSingleton(); 1188 $oKTTriggerRegistry = KTTriggerRegistry::getSingleton();
1189 $aTriggers = $oKTTriggerRegistry->getTriggers('copyDocument', 'postValidate'); 1189 $aTriggers = $oKTTriggerRegistry->getTriggers('copyDocument', 'postValidate');
@@ -1198,13 +1198,13 @@ class KTDocumentCopyAction extends KTDocumentAction { @@ -1198,13 +1198,13 @@ class KTDocumentCopyAction extends KTDocumentAction {
1198 $oTrigger->setInfo($aInfo); 1198 $oTrigger->setInfo($aInfo);
1199 $ret = $oTrigger->postValidate(); 1199 $ret = $oTrigger->postValidate();
1200 } 1200 }
1201 - 1201 +
1202 //$aOptions = array('user' => $oUser); 1202 //$aOptions = array('user' => $oUser);
1203 //$oDocumentTransaction = & new DocumentTransaction($oNewDoc, 'Document copied from old version.', 'ktcore.transactions.create', $aOptions); 1203 //$oDocumentTransaction = & new DocumentTransaction($oNewDoc, 'Document copied from old version.', 'ktcore.transactions.create', $aOptions);
1204 //$res = $oDocumentTransaction->create(); 1204 //$res = $oDocumentTransaction->create();
1205 - 1205 +
1206 $_SESSION['KTInfoMessage'][] = _kt('Document copied.'); 1206 $_SESSION['KTInfoMessage'][] = _kt('Document copied.');
1207 - 1207 +
1208 controllerRedirect('viewDocument', 'fDocumentId=' . $oNewDoc->getId()); 1208 controllerRedirect('viewDocument', 'fDocumentId=' . $oNewDoc->getId());
1209 exit(0); 1209 exit(0);
1210 } 1210 }
@@ -1252,10 +1252,10 @@ class KTDocumentArchiveAction extends KTDocumentAction { @@ -1252,10 +1252,10 @@ class KTDocumentArchiveAction extends KTDocumentAction {
1252 'output' => 'reason', 1252 'output' => 'reason',
1253 )), 1253 )),
1254 )); 1254 ));
1255 - 1255 +
1256 return $oForm; 1256 return $oForm;
1257 } 1257 }
1258 - 1258 +
1259 function do_main() { 1259 function do_main() {
1260 $this->oPage->setBreadcrumbDetails(_kt('Archive Document')); 1260 $this->oPage->setBreadcrumbDetails(_kt('Archive Document'));
1261 $oTemplate =& $this->oValidator->validateTemplate('ktcore/action/archive'); 1261 $oTemplate =& $this->oValidator->validateTemplate('ktcore/action/archive');
@@ -1270,16 +1270,16 @@ class KTDocumentArchiveAction extends KTDocumentAction { @@ -1270,16 +1270,16 @@ class KTDocumentArchiveAction extends KTDocumentAction {
1270 } 1270 }
1271 1271
1272 function do_archive() { 1272 function do_archive() {
1273 - 1273 +
1274 $oForm = $this->form_main(); 1274 $oForm = $this->form_main();
1275 $res = $oForm->validate(); 1275 $res = $oForm->validate();
1276 $data = $res['results']; 1276 $data = $res['results'];
1277 if (!empty($res['errors'])) { 1277 if (!empty($res['errors'])) {
1278 return $oForm->handleError(); 1278 return $oForm->handleError();
1279 } 1279 }
1280 - 1280 +
1281 $sReason = $data['reason']; 1281 $sReason = $data['reason'];
1282 - 1282 +
1283 $this->startTransaction(); 1283 $this->startTransaction();
1284 $this->oDocument->setStatusID(ARCHIVED); 1284 $this->oDocument->setStatusID(ARCHIVED);
1285 $res = $this->oDocument->update(); 1285 $res = $this->oDocument->update();
@@ -1290,7 +1290,7 @@ class KTDocumentArchiveAction extends KTDocumentAction { @@ -1290,7 +1290,7 @@ class KTDocumentArchiveAction extends KTDocumentAction {
1290 } 1290 }
1291 $oDocumentTransaction = & new DocumentTransaction($this->oDocument, sprintf(_kt('Document archived: %s'), $sReason), 'ktcore.transactions.update'); 1291 $oDocumentTransaction = & new DocumentTransaction($this->oDocument, sprintf(_kt('Document archived: %s'), $sReason), 'ktcore.transactions.update');
1292 $oDocumentTransaction->create(); 1292 $oDocumentTransaction->create();
1293 - 1293 +
1294 $this->commitTransaction(); 1294 $this->commitTransaction();
1295 1295
1296 $oKTTriggerRegistry = KTTriggerRegistry::getSingleton(); 1296 $oKTTriggerRegistry = KTTriggerRegistry::getSingleton();
@@ -1320,11 +1320,11 @@ class KTDocumentArchiveAction extends KTDocumentAction { @@ -1320,11 +1320,11 @@ class KTDocumentArchiveAction extends KTDocumentAction {
1320 class KTDocumentWorkflowAction extends KTDocumentAction { 1320 class KTDocumentWorkflowAction extends KTDocumentAction {
1321 var $sName = 'ktcore.actions.document.workflow'; 1321 var $sName = 'ktcore.actions.document.workflow';
1322 var $_sShowPermission = 'ktcore.permissions.read'; 1322 var $_sShowPermission = 'ktcore.permissions.read';
1323 -  
1324 - var $sHelpPage = 'ktcore/user/workflow.html'; 1323 +
  1324 + var $sHelpPage = 'ktcore/user/workflow.html';
1325 1325
1326 function predispatch() { 1326 function predispatch() {
1327 - $this->persistParams(array('fTransitionId')); 1327 + $this->persistParams(array('fTransitionId'));
1328 } 1328 }
1329 1329
1330 function getDisplayName() { 1330 function getDisplayName() {
@@ -1350,7 +1350,7 @@ class KTDocumentWorkflowAction extends KTDocumentAction { @@ -1350,7 +1350,7 @@ class KTDocumentWorkflowAction extends KTDocumentAction {
1350 } 1350 }
1351 1351
1352 $fieldErrors = null; 1352 $fieldErrors = null;
1353 - 1353 +
1354 $transition_fields = array(); 1354 $transition_fields = array();
1355 if ($aTransitions) { 1355 if ($aTransitions) {
1356 $aVocab = array(); 1356 $aVocab = array();
@@ -1364,8 +1364,8 @@ class KTDocumentWorkflowAction extends KTDocumentAction { @@ -1364,8 +1364,8 @@ class KTDocumentWorkflowAction extends KTDocumentAction {
1364 $fieldOptions = array('vocab' => $aVocab); 1364 $fieldOptions = array('vocab' => $aVocab);
1365 $transition_fields[] = new KTLookupWidget(_kt('Transition to perform'), _kt('The transition listed will cause the document to change from its current state to the listed destination state.'), 'fTransitionId', null, $this->oPage, true, null, $fieldErrors, $fieldOptions); 1365 $transition_fields[] = new KTLookupWidget(_kt('Transition to perform'), _kt('The transition listed will cause the document to change from its current state to the listed destination state.'), 'fTransitionId', null, $this->oPage, true, null, $fieldErrors, $fieldOptions);
1366 $transition_fields[] = new KTTextWidget( 1366 $transition_fields[] = new KTTextWidget(
1367 - _kt('Reason for transition'), _kt('Describe why this document qualifies to be changed from its current state to the destination state of the transition chosen.'),  
1368 - 'fComments', '', 1367 + _kt('Reason for transition'), _kt('Describe why this document qualifies to be changed from its current state to the destination state of the transition chosen.'),
  1368 + 'fComments', '',
1369 $this->oPage, true, null, null, 1369 $this->oPage, true, null, null,
1370 array('cols' => 80, 'rows' => 4)); 1370 array('cols' => 80, 'rows' => 4));
1371 } 1371 }
@@ -1399,7 +1399,7 @@ class KTDocumentWorkflowAction extends KTDocumentAction { @@ -1399,7 +1399,7 @@ class KTDocumentWorkflowAction extends KTDocumentAction {
1399 1399
1400 function do_performTransition() { 1400 function do_performTransition() {
1401 $oDocument =& $this->oValidator->validateDocument($_REQUEST['fDocumentId']); 1401 $oDocument =& $this->oValidator->validateDocument($_REQUEST['fDocumentId']);
1402 - $oTransition =& $this->oValidator->validateWorkflowTransition($_REQUEST['fTransitionId']); 1402 + $oTransition =& $this->oValidator->validateWorkflowTransition($_REQUEST['fTransitionId']);
1403 1403
1404 $aErrorOptions = array( 1404 $aErrorOptions = array(
1405 'redirect_to' => array('main', sprintf('fDocumentId=%d', $_REQUEST['fDocumentId'])), 1405 'redirect_to' => array('main', sprintf('fDocumentId=%d', $_REQUEST['fDocumentId'])),
@@ -1407,7 +1407,7 @@ class KTDocumentWorkflowAction extends KTDocumentAction { @@ -1407,7 +1407,7 @@ class KTDocumentWorkflowAction extends KTDocumentAction {
1407 ); 1407 );
1408 1408
1409 $sComments =& $this->oValidator->validateString($_REQUEST['fComments'], $aErrorOptions); 1409 $sComments =& $this->oValidator->validateString($_REQUEST['fComments'], $aErrorOptions);
1410 - 1410 +
1411 $oUser =& User::get($_SESSION['userID']); 1411 $oUser =& User::get($_SESSION['userID']);
1412 $res = KTWorkflowUtil::performTransitionOnDocument($oTransition, $oDocument, $oUser, $sComments); 1412 $res = KTWorkflowUtil::performTransitionOnDocument($oTransition, $oDocument, $oUser, $sComments);
1413 1413
@@ -1420,7 +1420,7 @@ class KTDocumentWorkflowAction extends KTDocumentAction { @@ -1420,7 +1420,7 @@ class KTDocumentWorkflowAction extends KTDocumentAction {
1420 array('fDocumentId' => $oDocument->getId())); 1420 array('fDocumentId' => $oDocument->getId()));
1421 } 1421 }
1422 } 1422 }
1423 - 1423 +
1424 function form_quicktransition() { 1424 function form_quicktransition() {
1425 1425
1426 $oForm = new KTForm; 1426 $oForm = new KTForm;
@@ -1446,36 +1446,36 @@ class KTDocumentWorkflowAction extends KTDocumentAction { @@ -1446,36 +1446,36 @@ class KTDocumentWorkflowAction extends KTDocumentAction {
1446 'test' => 'reason', 1446 'test' => 'reason',
1447 'max_length' => 250, 1447 'max_length' => 250,
1448 'output' => 'reason', 1448 'output' => 'reason',
1449 - )), 1449 + )),
1450 )); 1450 ));
1451 - 1451 +
1452 return $oForm; 1452 return $oForm;
1453 } 1453 }
1454 1454
1455 function do_quicktransition() { 1455 function do_quicktransition() {
1456 // make sure this gets through. 1456 // make sure this gets through.
1457 $this->persistParams(array('fTransitionId')); 1457 $this->persistParams(array('fTransitionId'));
1458 - 1458 +
1459 $transition_id = $_REQUEST['fTransitionId']; 1459 $transition_id = $_REQUEST['fTransitionId'];
1460 $oTransition = KTWorkflowTransition::get($transition_id); 1460 $oTransition = KTWorkflowTransition::get($transition_id);
1461 - 1461 +
1462 $oForm = $this->form_quicktransition(); 1462 $oForm = $this->form_quicktransition();
1463 return $oForm->renderPage(sprintf(_kt('Perform Transition: %s'), $oTransition->getName())); 1463 return $oForm->renderPage(sprintf(_kt('Perform Transition: %s'), $oTransition->getName()));
1464 } 1464 }
1465 - 1465 +
1466 function do_performquicktransition() { 1466 function do_performquicktransition() {
1467 $oForm = $this->form_quicktransition(); 1467 $oForm = $this->form_quicktransition();
1468 $res = $oForm->validate(); 1468 $res = $oForm->validate();
1469 - 1469 +
1470 if (!empty($res['errors'])) { 1470 if (!empty($res['errors'])) {
1471 return $oForm->handleError(); 1471 return $oForm->handleError();
1472 - }  
1473 - 1472 + }
  1473 +
1474 $this->startTransaction(); 1474 $this->startTransaction();
1475 - 1475 +
1476 $data = $res['results']; 1476 $data = $res['results'];
1477 $oTransition = KTWorkflowTransition::get($_REQUEST['fTransitionId']); 1477 $oTransition = KTWorkflowTransition::get($_REQUEST['fTransitionId']);
1478 - 1478 +
1479 $res = KTWorkflowUtil::performTransitionOnDocument($oTransition, $this->oDocument, $this->oUser, $data['reason']); 1479 $res = KTWorkflowUtil::performTransitionOnDocument($oTransition, $this->oDocument, $this->oUser, $data['reason']);
1480 1480
1481 if(!Permission::userHasDocumentReadPermission($this->oDocument)) { 1481 if(!Permission::userHasDocumentReadPermission($this->oDocument)) {
@@ -1483,10 +1483,10 @@ class KTDocumentWorkflowAction extends KTDocumentAction { @@ -1483,10 +1483,10 @@ class KTDocumentWorkflowAction extends KTDocumentAction {
1483 $_SESSION['KTInfoMessage'][] = _kt('Transition performed') . '. ' . _kt('You no longer have permission to view this document'); 1483 $_SESSION['KTInfoMessage'][] = _kt('Transition performed') . '. ' . _kt('You no longer have permission to view this document');
1484 controllerRedirect('browse', sprintf('fFolderId=%d', $this->oDocument->getFolderId())); 1484 controllerRedirect('browse', sprintf('fFolderId=%d', $this->oDocument->getFolderId()));
1485 } else { 1485 } else {
1486 - $this->commitTransaction(); 1486 + $this->commitTransaction();
1487 $_SESSION['KTInfoMessage'][] = _kt('Transition performed'); 1487 $_SESSION['KTInfoMessage'][] = _kt('Transition performed');
1488 controllerRedirect('viewDocument', sprintf('fDocumentId=%d', $this->oDocument->getId())); 1488 controllerRedirect('viewDocument', sprintf('fDocumentId=%d', $this->oDocument->getId()));
1489 - } 1489 + }
1490 } 1490 }
1491 1491
1492 } 1492 }
@@ -1499,7 +1499,7 @@ class KTOwnershipChangeAction extends KTDocumentAction { @@ -1499,7 +1499,7 @@ class KTOwnershipChangeAction extends KTDocumentAction {
1499 function getDisplayName() { 1499 function getDisplayName() {
1500 return _kt('Change Document Ownership'); 1500 return _kt('Change Document Ownership');
1501 } 1501 }
1502 - 1502 +
1503 function form_owner() { 1503 function form_owner() {
1504 $oForm = new KTForm; 1504 $oForm = new KTForm;
1505 $oForm->setOptions(array( 1505 $oForm->setOptions(array(
@@ -1529,49 +1529,49 @@ class KTOwnershipChangeAction extends KTDocumentAction { @@ -1529,49 +1529,49 @@ class KTOwnershipChangeAction extends KTDocumentAction {
1529 'output' => 'user', 1529 'output' => 'user',
1530 )), 1530 )),
1531 )); 1531 ));
1532 - 1532 +
1533 return $oForm; 1533 return $oForm;
1534 } 1534 }
1535 1535
1536 - function do_main() { 1536 + function do_main() {
1537 $this->oPage->setBreadcrumbDetails(_kt('Changing Ownership')); 1537 $this->oPage->setBreadcrumbDetails(_kt('Changing Ownership'));
1538 $oTemplate =& $this->oValidator->validateTemplate('ktcore/document/ownershipchangeaction'); 1538 $oTemplate =& $this->oValidator->validateTemplate('ktcore/document/ownershipchangeaction');
1539 - 1539 +
1540 $change_form = $this->form_owner(); 1540 $change_form = $this->form_owner();
1541 - 1541 +
1542 $oTemplate->setData(array( 1542 $oTemplate->setData(array(
1543 'context' => $this, 1543 'context' => $this,
1544 'form' => $change_form, 1544 'form' => $change_form,
1545 - )); 1545 + ));
1546 return $oTemplate->render(); 1546 return $oTemplate->render();
1547 } 1547 }
1548 - 1548 +
1549 function do_reown() { 1549 function do_reown() {
1550 $oForm = $this->form_owner(); 1550 $oForm = $this->form_owner();
1551 $res = $oForm->validate(); 1551 $res = $oForm->validate();
1552 $data = $res['results']; 1552 $data = $res['results'];
1553 $errors = $res['errors']; 1553 $errors = $res['errors'];
1554 - 1554 +
1555 if (!empty($errors)) { 1555 if (!empty($errors)) {
1556 - return $oForm->handleError(); 1556 + return $oForm->handleError();
1557 } 1557 }
1558 1558
1559 $oUser = $data['user']; 1559 $oUser = $data['user'];
1560 - 1560 +
1561 $this->startTransaction(); 1561 $this->startTransaction();
1562 - 1562 +
1563 $this->oDocument->setOwnerID($oUser->getId()); 1563 $this->oDocument->setOwnerID($oUser->getId());
1564 $res = $this->oDocument->update(); 1564 $res = $this->oDocument->update();
1565 if (PEAR::isError($res)) { 1565 if (PEAR::isError($res)) {
1566 $this->errorRedirectToMain(sprintf(_kt('Failed to update document: %s'), $res->getMessage()), sprintf('fDocumentId=%d', $this->oDocument->getId())); 1566 $this->errorRedirectToMain(sprintf(_kt('Failed to update document: %s'), $res->getMessage()), sprintf('fDocumentId=%d', $this->oDocument->getId()));
1567 } 1567 }
1568 - 1568 +
1569 $res = KTPermissionUtil::updatePermissionLookup($this->oDocument); 1569 $res = KTPermissionUtil::updatePermissionLookup($this->oDocument);
1570 - 1570 +
1571 if (PEAR::isError($res)) { 1571 if (PEAR::isError($res)) {
1572 $this->errorRedirectToMain(sprintf(_kt('Failed to update document: %s'), $res->getMessage()), sprintf('fDocumentId=%d', $this->oDocument->getId())); 1572 $this->errorRedirectToMain(sprintf(_kt('Failed to update document: %s'), $res->getMessage()), sprintf('fDocumentId=%d', $this->oDocument->getId()));
1573 } 1573 }
1574 - 1574 +
1575 $this->successRedirectToMain(_kt('Ownership changed.'), sprintf('fDocumentId=%d', $this->oDocument->getId())); 1575 $this->successRedirectToMain(_kt('Ownership changed.'), sprintf('fDocumentId=%d', $this->oDocument->getId()));
1576 } 1576 }
1577 } 1577 }