Commit 1a034c0bac478454e69a4b8628e0ba90bb6afb18

Authored by Megan Watson
1 parent 4aacefa0

KTS-3239

"When navigating to an archived document, the user should have the ability to request a document to be unarchived."
Fixed. The user can send a request which plugs into the "request assistance" notification plugin.

Committed by: Megan Watson
Reviewed by: Conrad Vermeulen



git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@8428 c91229c3-7414-0410-bfa2-8a42b809f60b
plugins/ktcore/KTAssist.php
... ... @@ -7,31 +7,31 @@
7 7 * Document Management Made Simple
8 8 * Copyright (C) 2008 KnowledgeTree Inc.
9 9 * Portions copyright The Jam Warehouse Software (Pty) Limited
10   - *
  10 + *
11 11 * This program is free software; you can redistribute it and/or modify it under
12 12 * the terms of the GNU General Public License version 3 as published by the
13 13 * Free Software Foundation.
14   - *
  14 + *
15 15 * This program is distributed in the hope that it will be useful, but WITHOUT
16 16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 17 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18 18 * details.
19   - *
  19 + *
20 20 * You should have received a copy of the GNU General Public License
21 21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22   - *
23   - * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
  22 + *
  23 + * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
24 24 * California 94120-7775, or email info@knowledgetree.com.
25   - *
  25 + *
26 26 * The interactive user interfaces in modified source and object code versions
27 27 * of this program must display Appropriate Legal Notices, as required under
28 28 * Section 5 of the GNU General Public License version 3.
29   - *
  29 + *
30 30 * In accordance with Section 7(b) of the GNU General Public License version 3,
31 31 * these Appropriate Legal Notices must retain the display of the "Powered by
32   - * KnowledgeTree" logo and retain the original copyright notice. If the display of the
  32 + * KnowledgeTree" logo and retain the original copyright notice. If the display of the
33 33 * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
34   - * must display the words "Powered by KnowledgeTree" and retain the original
  34 + * must display the words "Powered by KnowledgeTree" and retain the original
35 35 * copyright notice.
36 36 * Contributor( s): ______________________________________
37 37 *
... ... @@ -187,7 +187,7 @@ class KTAssistNotification extends KTNotificationHandler {
187 187 $oTemplate =& $oTemplating->loadTemplate('ktcore/assist/assist_notification');
188 188  
189 189 $oDoc = Document::get($oKTNotification->getIntData1());
190   - $isBroken = (PEAR::isError($oDoc) || ($oDoc->getStatusID() != LIVE));
  190 + $isBroken = (PEAR::isError($oDoc) || ($oDoc->getStatusID() != LIVE && $oDoc->getStatusID() != ARCHIVED));
191 191  
192 192 $oTemplate->setData(array(
193 193 'context' => $this,
... ... @@ -211,10 +211,14 @@ class KTAssistNotification extends KTNotificationHandler {
211 211 }
212 212  
213 213 function notify_main() {
  214 + $this->aBreadcrumbs = array(array('action' => 'dashboard', 'name' => _kt('Dashboard')));
  215 + $this->oPage->setBreadcrumbDetails(_kt('Help request'));
  216 +
214 217 $oTemplating =& KTTemplating::getSingleton();
215 218 $oKTNotification =& $this->oNotification;
216 219 $oDoc = Document::get($oKTNotification->getIntData1());
217 220 $isBroken = (PEAR::isError($oDoc) || ($oDoc->getStatusID() != LIVE));
  221 + $isArchived = ($oDoc->getStatusID() == ARCHIVED)? true : false;
218 222  
219 223 $oTemplate =& $oTemplating->loadTemplate('ktcore/assist/assist_notification_details');
220 224 $oTemplate->setData(array(
... ... @@ -227,7 +231,8 @@ class KTAssistNotification extends KTNotificationHandler {
227 231 'details' => $oKTNotification->getTextData1(),
228 232 'document' => $oDoc,
229 233 'is_broken' => $isBroken,
230   -
  234 + 'is_archived' => $isArchived,
  235 +
231 236 ));
232 237 return $oTemplate->render();
233 238 }
... ... @@ -244,6 +249,70 @@ class KTAssistNotification extends KTNotificationHandler {
244 249 // $this->oNotification->delete(); // clear the alert.
245 250 exit(redirect($url));
246 251 }
  252 +
  253 + function notify_restore() {
  254 + $iDocId = $this->oNotification->getIntData1();
  255 + $res = $this->restore($iDocId);
  256 + if(PEAR::isError($res) || !$res){
  257 + $msg = _kt('Document could not be restored');
  258 + if($res){
  259 + $msg .= ': '.$res->getMessage();
  260 + }
  261 + $this->addErrorMessage($msg);
  262 + }else{
  263 + $this->addInfoMessage(_kt('The document has been successfully restored.'));
  264 + }
  265 +
  266 + $notify_id = $_REQUEST['id'];
  267 + $url = KTUtil::ktLink("notify.php", '', "id=$notify_id");
  268 + exit(redirect($url));
  269 + }
  270 +
  271 + function restore($iDocId) {
  272 + // Get the document object
  273 + $oDoc = Document::get($iDocId);
  274 +
  275 + if (PEAR::isError($oDoc) || ($oDoc === false)) {
  276 + return $oDoc;
  277 + }
  278 +
  279 + $this->startTransaction();
  280 + $iRestoreFolder = $oDoc->getRestoreFolderId();
  281 + $oFolder = Folder::get($iRestoreFolder);
  282 +
  283 + // move to root if parent no longer exists.
  284 + if (PEAR::isError($oFolder)) {
  285 + $oDoc->setFolderId(1);
  286 + $oFolder = Folder::get(1);
  287 + } else {
  288 + $oDoc->setFolderId($iRestoreFolder);
  289 + }
  290 +
  291 + $oStorage = KTStorageManagerUtil::getSingleton();
  292 +
  293 + if ($oStorage->restore($oDoc)) {
  294 + $oDoc = Document::get($iDocId); // storage path has changed for most recent object...
  295 + $oDoc->setStatusId(LIVE);
  296 + $oDoc->setPermissionObjectId($oFolder->getPermissionObjectId());
  297 + $res = $oDoc->update();
  298 +
  299 + if (PEAR::isError($res) || ($res == false)) {
  300 + return $res;
  301 + }
  302 +
  303 + $res = KTPermissionUtil::updatePermissionLookup($oDoc);
  304 +
  305 + if (PEAR::isError($res)) {
  306 + return $res;
  307 + }
  308 +
  309 + // create a doc-transaction.
  310 + $oTransaction = new DocumentTransaction($oDoc, sprintf(_kt("Restored from deleted state by %s"), $this->oUser->getName()), 'ktcore.transactions.update');
  311 + $oTransaction->create();
  312 + }
  313 + $this->commitTransaction();
  314 + return true;
  315 + }
247 316 }
248 317  
249 318 ?>
... ...
templates/ktcore/assist/assist_notification.smarty
... ... @@ -15,7 +15,7 @@
15 15  
16 16 <a href='{ktLink base="notify.php" query="id=`$notify_id`&notify_action=clear"}'
17 17 kt:deleteMessage="{i18n}Are you sure you wish to clear the notification?{/i18n}"
18   - class="ktAction ktInline ktDelete" style="position: relative;" >{i18n}Clear Alert{/i18n}</a>
  18 + class="ktAction ktInline ktDelete" style="position: relative;" ></a>
19 19  
20 20 <a href='{ktLink base="notify.php" query="id=`$notify_id`&notify_action=clear"}'
21 21 kt:deleteMessage="{i18n}Are you sure you wish to clear the notification?{/i18n}"">{i18n}Clear Alert{/i18n}</a>
... ...
templates/ktcore/assist/assist_notification_details.smarty
1   -<p class="descriptiveText">
  1 +<h2>Request Assistance</h2>
  2 +<p class="descriptiveText" style="padding-top: 5px;">
2 3 {i18n arg_name=$document_name|sanitize arg_state=$state_name arg_user=$actor->getName()}A
3 4 user, <b>#user#</b>, has requested help on the document <b>#name#</b>, and you are
4 5 the owner or an admin of this document.{/i18n}
5 6 </p>
6 7  
7   -<dl>
8   -<dt>{i18n}Subject{/i18n}</dt>
9   -<dd>{$subject|sanitize}</dd>
10   -<dt>{i18n}Details{/i18n}</dt>
11   -<dd>{$details|sanitize} </dd>
12   -</dl>
  8 +<p style="padding-top: 5px;"><b>{i18n}Subject{/i18n}</b><br /> {$subject|sanitize}</p>
  9 +<p style="padding-top: 5px;"><b>{i18n}Details{/i18n}</b><br />
  10 +{$details|sanitize} </p>
13 11  
14   - <div class="actionoptions">
  12 + <div class="actionoptions" style="padding-top: 10px;">
15 13 <div style="float:left; position: relative;">
  14 + {if $is_archived}
  15 + <a href='{ktLink base="notify.php" query="id=`$notify_id`&notify_action=restore"}'>{i18n}Restore Document{/i18n}</a>
  16 + {else}
16 17 <a href='{ktLink base="notify.php" query="id=`$notify_id`&notify_action=view"}'>{i18n}View Document{/i18n}</a>
  18 + {/if}
17 19 &nbsp;|&nbsp;
18 20 </div>
19 21  
20 22 <a href='{ktLink base="notify.php" query="id=`$notify_id`&notify_action=clear"}'
21 23 kt:deleteMessage="{i18n}Are you sure you wish to clear the notification?{/i18n}"
22   - class="ktAction ktInline ktDelete" style="position: relative;" >{i18n}Clear Alert{/i18n}</a>
  24 + class="ktAction ktInline ktDelete" style="position: relative;" ></a>
23 25  
24 26 <a href='{ktLink base="notify.php" query="id=`$notify_id`&notify_action=clear"}'
25 27 kt:deleteMessage="{i18n}Are you sure you wish to clear the notification?{/i18n}"">{i18n}Clear Alert{/i18n}</a>
... ...
view.php
... ... @@ -6,31 +6,31 @@
6 6 * Document Management Made Simple
7 7 * Copyright (C) 2008 KnowledgeTree Inc.
8 8 * Portions copyright The Jam Warehouse Software (Pty) Limited
9   - *
  9 + *
10 10 * This program is free software; you can redistribute it and/or modify it under
11 11 * the terms of the GNU General Public License version 3 as published by the
12 12 * Free Software Foundation.
13   - *
  13 + *
14 14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 16 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 17 * details.
18   - *
  18 + *
19 19 * You should have received a copy of the GNU General Public License
20 20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21   - *
22   - * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
  21 + *
  22 + * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
23 23 * California 94120-7775, or email info@knowledgetree.com.
24   - *
  24 + *
25 25 * The interactive user interfaces in modified source and object code versions
26 26 * of this program must display Appropriate Legal Notices, as required under
27 27 * Section 5 of the GNU General Public License version 3.
28   - *
  28 + *
29 29 * In accordance with Section 7(b) of the GNU General Public License version 3,
30 30 * these Appropriate Legal Notices must retain the display of the "Powered by
31   - * KnowledgeTree" logo and retain the original copyright notice. If the display of the
  31 + * KnowledgeTree" logo and retain the original copyright notice. If the display of the
32 32 * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
33   - * must display the words "Powered by KnowledgeTree" and retain the original
  33 + * must display the words "Powered by KnowledgeTree" and retain the original
34 34 * copyright notice.
35 35 * Contributor( s): ______________________________________
36 36 */
... ... @@ -128,7 +128,7 @@ class ViewDocumentDispatcher extends KTStandardDispatcher {
128 128 if (!KTBrowseUtil::inAdminMode($this->oUser, $oDocument->getFolderId())) {
129 129 if ($oDocument->getStatusID() == ARCHIVED) {
130 130 $this->oPage->addError(_kt('This document has been archived. Please contact the system administrator to have it restored if it is still needed.'));
131   - return $this->do_error();
  131 + return $this->do_request($oDocument);
132 132 } else if ($oDocument->getStatusID() == DELETED) {
133 133 $this->oPage->addError(_kt('This document has been deleted. Please contact the system administrator to have it restored if it is still needed.'));
134 134 return $this->do_error();
... ... @@ -396,6 +396,73 @@ class ViewDocumentDispatcher extends KTStandardDispatcher {
396 396 return '&nbsp;'; // don't actually do anything.
397 397 }
398 398  
  399 + function do_request($oDocument) {
  400 + // Display form for sending a request through the the sys admin to unarchive the document
  401 + // name, document, request, submit
  402 +
  403 + $oForm = new KTForm;
  404 + $oForm->setOptions(array(
  405 + 'label' => _kt('Request restoration of document'),
  406 + 'submit_label' => _kt('Send request'),
  407 + 'identifier' => '',
  408 + 'cancel_url' => KTBrowseUtil::getUrlForFolder($oFolder),
  409 + 'fail_action' => 'main',
  410 + 'context' => $this,
  411 + ));
  412 +
  413 + $oForm->addWidget(
  414 + array('ktcore.widgets.text', array(
  415 + 'label' => _kt('Reason'),
  416 + 'name' => 'reason',
  417 + 'required' => true,
  418 + ))
  419 + );
  420 +
  421 + $data = isset($_REQUEST['data']) ? $_REQUEST['data'] : array();
  422 +
  423 + $iFolderId = $oDocument->getFolderID();
  424 + $oFolder = Folder::get($iFolderId);
  425 + $sFolderUrl = KTBrowseUtil::getUrlForFolder($oFolder);
  426 +
  427 + if(!empty($data)){
  428 + $res = $oForm->validate();
  429 + if (!empty($res['errors'])) {
  430 + return $oForm->handleError('', $aError);
  431 + }
  432 +
  433 + $aAdminGroups = Group::getAdministratorGroups();
  434 + if(!PEAR::isError($aAdminGroups) && !empty($aAdminGroups)){
  435 + foreach ($aAdminGroups as $oGroup) {
  436 + $aGroupUsers = $oGroup->getMembers();
  437 +
  438 + // ensure unique users
  439 + foreach ($aGroupUsers as $oUser){
  440 + $aUsers[$oUser->getId()] = $oUser;
  441 + }
  442 + }
  443 +
  444 + $sSubject = _kt('Request for an archived document to be restored');
  445 + $sDetails = $data['reason'];
  446 +
  447 + // Send request
  448 + foreach ($aUsers as $oU) {
  449 + if (!PEAR::isError($oU)) {
  450 + include_once(KT_DIR.'/plugins/ktcore/KTAssist.php');
  451 + KTAssistNotification::newNotificationForDocument($oDocument, $oU, $this->oUser, $sSubject, $sDetails);
  452 + }
  453 + }
  454 +
  455 + // Redirect to folder
  456 + $this->addInfoMessage(_kt('The System Administrators have been notified of your request.'));
  457 + redirect($sFolderUrl);
  458 + exit();
  459 + }
  460 + }
  461 +
  462 + return $oForm->renderPage(_kt('Archived document request') . ': '.$oDocument->getName());
  463 + }
  464 +
  465 +
399 466  
400 467 function getUserForId($iUserId) {
401 468 $u = User::get($iUserId);
... ...