Commit ccc0f58726306c9ccf7ae345075ebed3eefee4e7
1 parent
f83de704
Add a "Request Assistance" action on documents for those who want to
change a document when they can't. git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@5665 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
4 changed files
with
290 additions
and
0 deletions
plugins/ktcore/KTAssist.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * $Id$ | ||
| 5 | + * | ||
| 6 | + * Copyright (c) 2006 Jam Warehouse http://www.jamwarehouse.com | ||
| 7 | + * | ||
| 8 | + * This program is free software; you can redistribute it and/or modify | ||
| 9 | + * it under the terms of the GNU General Public License as published by | ||
| 10 | + * the Free Software Foundation; using version 2 of the License. | ||
| 11 | + * | ||
| 12 | + * This program is distributed in the hope that it will be useful, | ||
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 15 | + * GNU General Public License for more details. | ||
| 16 | + * | ||
| 17 | + * You should have received a copy of the GNU General Public License | ||
| 18 | + * along with this program; if not, write to the Free Software | ||
| 19 | + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 20 | + * | ||
| 21 | + * ------------------------------------------------------------------------- | ||
| 22 | + * | ||
| 23 | + * You can contact the copyright owner regarding licensing via the contact | ||
| 24 | + * details that can be found on the KnowledgeTree web site: | ||
| 25 | + * | ||
| 26 | + * http://www.ktdms.com/ | ||
| 27 | + */ | ||
| 28 | + | ||
| 29 | +require_once(KT_LIB_DIR . '/actions/documentaction.inc.php'); | ||
| 30 | +require_once(KT_LIB_DIR . '/subscriptions/Subscription.inc'); | ||
| 31 | +require_once(KT_LIB_DIR . '/widgets/fieldWidgets.php'); | ||
| 32 | +require_once(KT_LIB_DIR . '/browse/browseutil.inc.php'); | ||
| 33 | +require_once(KT_LIB_DIR . '/documentmanagement/documentutil.inc.php'); | ||
| 34 | + | ||
| 35 | +// {{{ KTDocumentAssistAction | ||
| 36 | +class KTDocumentAssistAction extends KTDocumentAction { | ||
| 37 | + var $sName = 'ktcore.actions.document.assist'; | ||
| 38 | + | ||
| 39 | + function getDisplayName() { | ||
| 40 | + return _kt('Request Assistance'); | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + function do_main() { | ||
| 44 | + $this->oPage->setBreadcrumbDetails(_kt("assistance")); | ||
| 45 | + $oTemplate =& $this->oValidator->validateTemplate('ktcore/action/assistance'); | ||
| 46 | + $fields = array(); | ||
| 47 | + $fields[] = new KTStringWidget(_kt('Subject'), _kt('A one-line description introducing the assistance that you wish to receive'), 'subject', "", $this->oPage, true); | ||
| 48 | + $fields[] = new KTTextWidget(_kt('Details'), _kt('A full description of the assistance that you with to receive. Provide all necessary information to assist in your request.'), 'details', "", $this->oPage, true); | ||
| 49 | + | ||
| 50 | + $oTemplate->setData(array( | ||
| 51 | + 'context' => &$this, | ||
| 52 | + 'fields' => $fields, | ||
| 53 | + )); | ||
| 54 | + return $oTemplate->render(); | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + function do_assistance() { | ||
| 58 | + $sSubject = $this->oValidator->validateString($_REQUEST['subject']); | ||
| 59 | + $sDetails = $this->oValidator->validateString($_REQUEST['details']); | ||
| 60 | + $aUsers = array(); | ||
| 61 | + $aGroups = array(); | ||
| 62 | + $aRoles = array(); | ||
| 63 | + | ||
| 64 | + foreach (Group::getAdministratorGroups() as $oGroup) { | ||
| 65 | + $aGroups[$oGroup->getId()] =& $oGroup; | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + foreach (Unit::getUnitsForFolder($this->oDocument->getFolderId()) as $oUnit) { | ||
| 69 | + foreach (Group::getUnitAdministratorGroupsByUnit($oUnit) as $oGroup) { | ||
| 70 | + $aGroups[$oGroup->getId()] =& $oGroup; | ||
| 71 | + } | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + $aRoles[-2] = Role::get(-2); | ||
| 75 | + $oDocument =& $this->oDocument; | ||
| 76 | + | ||
| 77 | + foreach ($aRoles as $oRole) { | ||
| 78 | + // Ignore anonymous or Everyone roles | ||
| 79 | + $iRoleId = KTUtil::getId($oRole); | ||
| 80 | + if (($iRoleId == -3) || ($iRoleId == -4)) { | ||
| 81 | + continue; | ||
| 82 | + } | ||
| 83 | + // first try on the document, then the folder above it. | ||
| 84 | + $oRoleAllocation = DocumentRoleAllocation::getAllocationsForDocumentAndRole($oDocument->getId(), $iRoleId); | ||
| 85 | + if (is_null($oRoleAllocation)) { | ||
| 86 | + // if we don't get a document role, try folder role. | ||
| 87 | + $oRoleAllocation = RoleAllocation::getAllocationsForFolderAndRole($oDocument->getFolderID(), $oRole->getId()); | ||
| 88 | + } | ||
| 89 | + if (is_null($oRoleAllocation) || PEAR::isError($oRoleAllocation)) { | ||
| 90 | + continue; | ||
| 91 | + } | ||
| 92 | + $aRoleUsers = $oRoleAllocation->getUsers(); | ||
| 93 | + $aRoleGroups = $oRoleAllocation->getGroups(); | ||
| 94 | + | ||
| 95 | + foreach ($aRoleUsers as $id => $oU) { | ||
| 96 | + $aUsers[$id] = $oU; | ||
| 97 | + } | ||
| 98 | + foreach ($aRoleGroups as $id => $oGroup) { | ||
| 99 | + $aGroups[$id] = $oGroup; | ||
| 100 | + } | ||
| 101 | + } | ||
| 102 | + | ||
| 103 | + $aGroupMembershipSet = GroupUtil::buildGroupArray(); | ||
| 104 | + $aAllIds = array_keys($aGroups); | ||
| 105 | + foreach ($aGroups as $id => $oGroup) { | ||
| 106 | + $aAllIds = kt_array_merge($aGroupMembershipSet[$id], $aAllIds); | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + foreach ($aAllIds as $id) { | ||
| 110 | + if (!array_key_exists($id, $aGroups)) { | ||
| 111 | + $aGroups[$id] = Group::get($id); | ||
| 112 | + } | ||
| 113 | + } | ||
| 114 | + | ||
| 115 | + // now, merge this (again) into the user-set. | ||
| 116 | + foreach ($aGroups as $oGroup) { | ||
| 117 | + $aNewUsers = $oGroup->getMembers(); | ||
| 118 | + foreach ($aNewUsers as $oU) { | ||
| 119 | + $id = $oU->getId(); | ||
| 120 | + if (!array_key_exists($id, $aUsers)) { | ||
| 121 | + $aUsers[$id] = $oU; | ||
| 122 | + } | ||
| 123 | + } | ||
| 124 | + } | ||
| 125 | + | ||
| 126 | + foreach ($aUsers as $oU) { | ||
| 127 | + if (!PEAR::isError($oU)) { | ||
| 128 | + KTAssistNotification::newNotificationForDocument($this->oDocument, $oU, $this->oUser, $sSubject, $sDetails); | ||
| 129 | + } | ||
| 130 | + } | ||
| 131 | + | ||
| 132 | + | ||
| 133 | + $this->commitTransaction(); | ||
| 134 | + $params = 'fDocumentId=' . $oDocument->getId(); | ||
| 135 | + $url = generateControllerLink('viewDocument', $params); | ||
| 136 | + exit(redirect($url)); | ||
| 137 | + } | ||
| 138 | +} | ||
| 139 | +// }}} | ||
| 140 | + | ||
| 141 | +class KTAssistNotification extends KTNotificationHandler { | ||
| 142 | + function & clearNotificationsForDocument($oDocument) { | ||
| 143 | + $aNotifications = KTNotification::getList('data_int_1 = ' . $oDocument->getId()); | ||
| 144 | + foreach ($aNotifications as $oNotification) { | ||
| 145 | + $oNotification->delete(); | ||
| 146 | + } | ||
| 147 | + } | ||
| 148 | + | ||
| 149 | + function &newNotificationForDocument($oDocument, $oUser, $oActor, $sSubject, $sDetails) { | ||
| 150 | + $aInfo = array(); | ||
| 151 | + $aInfo['sData1'] = $sSubject; | ||
| 152 | + $aInfo['sText1'] = $sDetails; | ||
| 153 | + $aInfo['iData1'] = $oDocument->getId(); | ||
| 154 | + $aInfo['iData2'] = $oActor->getId(); | ||
| 155 | + $aInfo['sType'] = 'ktcore/assist'; | ||
| 156 | + $aInfo['dCreationDate'] = getCurrentDateTime(); | ||
| 157 | + $aInfo['iUserId'] = $oUser->getId(); | ||
| 158 | + $aInfo['sLabel'] = $oDocument->getName(); | ||
| 159 | + | ||
| 160 | + $oNotification = KTNotification::createFromArray($aInfo); | ||
| 161 | + | ||
| 162 | + $handler = new KTAssistNotification(); | ||
| 163 | + | ||
| 164 | + if ($oUser->getEmailNotification() && (strlen($oUser->getEmail()) > 0)) { | ||
| 165 | + $emailContent = $handler->handleNotification($oNotification); | ||
| 166 | + $emailSubject = sprintf(_kt('Assistance request: %s'), $oDocument->getName()); | ||
| 167 | + $oEmail = new EmailAlert($oUser->getEmail(), $emailSubject, $emailContent); | ||
| 168 | + $oEmail->send(); | ||
| 169 | + } | ||
| 170 | + | ||
| 171 | + return $oNotification; | ||
| 172 | + } | ||
| 173 | + | ||
| 174 | + function handleNotification($oKTNotification) { | ||
| 175 | + $oTemplating =& KTTemplating::getSingleton(); | ||
| 176 | + $oTemplate =& $oTemplating->loadTemplate('ktcore/assist/assist_notification'); | ||
| 177 | + | ||
| 178 | + $oDoc = Document::get($oKTNotification->getIntData1()); | ||
| 179 | + $isBroken = (PEAR::isError($oDoc) || ($oDoc->getStatusID() != LIVE)); | ||
| 180 | + | ||
| 181 | + $oTemplate->setData(array( | ||
| 182 | + 'context' => $this, | ||
| 183 | + 'document_id' => $oKTNotification->getIntData1(), | ||
| 184 | + 'subject' => $oKTNotification->getStrData1(), | ||
| 185 | + 'actor' => User::get($oKTNotification->getIntData2()), | ||
| 186 | + 'document_name' => $oKTNotification->getLabel(), | ||
| 187 | + 'notify_id' => $oKTNotification->getId(), | ||
| 188 | + 'details' => $oKTNotification->getTextData1(), | ||
| 189 | + 'document' => $oDoc, | ||
| 190 | + 'is_broken' => $isBroken, | ||
| 191 | + )); | ||
| 192 | + return $oTemplate->render(); | ||
| 193 | + } | ||
| 194 | + | ||
| 195 | + function resolveNotification($oKTNotification) { | ||
| 196 | + $notify_action = KTUtil::arrayGet($_REQUEST, 'notify_action', null); | ||
| 197 | + $this->oNotification =& $oKTNotification; | ||
| 198 | + $this->redispatch('notify_action', 'notify'); | ||
| 199 | + exit(0); | ||
| 200 | + } | ||
| 201 | + | ||
| 202 | + function notify_main() { | ||
| 203 | + $oTemplating =& KTTemplating::getSingleton(); | ||
| 204 | + $oKTNotification =& $this->oNotification; | ||
| 205 | + $oDoc = Document::get($oKTNotification->getIntData1()); | ||
| 206 | + $isBroken = (PEAR::isError($oDoc) || ($oDoc->getStatusID() != LIVE)); | ||
| 207 | + | ||
| 208 | + $oTemplate =& $oTemplating->loadTemplate('ktcore/assist/assist_notification_details'); | ||
| 209 | + $oTemplate->setData(array( | ||
| 210 | + 'context' => $this, | ||
| 211 | + 'document_id' => $oKTNotification->getIntData1(), | ||
| 212 | + 'subject' => $oKTNotification->getStrData1(), | ||
| 213 | + 'actor' => User::get($oKTNotification->getIntData2()), | ||
| 214 | + 'document_name' => $oKTNotification->getLabel(), | ||
| 215 | + 'notify_id' => $oKTNotification->getId(), | ||
| 216 | + 'details' => $oKTNotification->getTextData1(), | ||
| 217 | + 'document' => $oDoc, | ||
| 218 | + 'is_broken' => $isBroken, | ||
| 219 | + | ||
| 220 | + )); | ||
| 221 | + return $oTemplate->render(); | ||
| 222 | + } | ||
| 223 | + | ||
| 224 | + function notify_clear() { | ||
| 225 | + $_SESSION['KTInfoMessage'][] = _kt('Assistance Request cleared.'); | ||
| 226 | + $this->oNotification->delete(); | ||
| 227 | + exit(redirect(generateControllerLink('dashboard'))); | ||
| 228 | + } | ||
| 229 | + | ||
| 230 | + function notify_view() { | ||
| 231 | + $params = 'fDocumentId=' . $this->oNotification->getIntData1(); | ||
| 232 | + $url = generateControllerLink('viewDocument', $params); | ||
| 233 | + // $this->oNotification->delete(); // clear the alert. | ||
| 234 | + exit(redirect($url)); | ||
| 235 | + } | ||
| 236 | +} | ||
| 237 | + | ||
| 238 | +?> |
templates/ktcore/action/assistance.smarty
0 → 100644
| 1 | +<p class="descriptiveText">{i18n}If you are unable to perform an action | ||
| 2 | +on this document that you think you should be able to, or wish to | ||
| 3 | +request a change in location, metadata values, or workflow status, you | ||
| 4 | +can use this form to contact the owner of the document and/or the | ||
| 5 | +administrators to request this change.{/i18n}</p> | ||
| 6 | + | ||
| 7 | +{assign var=iDocumentId value=$context->oDocument->getId()} | ||
| 8 | + | ||
| 9 | +<form method="POST" action="{$smarty.server.PHP_SELF}"> | ||
| 10 | +<fieldset><legend>{i18n}Request Assistance{/i18n}</legend> | ||
| 11 | +<input type="hidden" name="action" value="assistance" /> | ||
| 12 | +<input type="hidden" name="fDocumentId" value="{$iDocumentId}" /> | ||
| 13 | +{foreach from=$fields item=oWidget } | ||
| 14 | + {$oWidget->render()} | ||
| 15 | +{/foreach} | ||
| 16 | +<div class="form_actions"> | ||
| 17 | +<input type="submit" name="submit" value="{i18n}Request Assistance{/i18n}" /> | ||
| 18 | +</div> | ||
| 19 | +</fieldset> | ||
| 20 | +</form> |
templates/ktcore/assist/assist_notification.smarty
0 → 100644
| 1 | +<dt class="actionitem">{$subject}</dt> | ||
| 2 | +<dd class="actionmessage"> | ||
| 3 | + {i18n arg_name=$document_name arg_state=$state_name arg_user=$actor->getName()}A | ||
| 4 | + user, <b>#user#</b>, has requested help on the document <b>#name#</b>, and you are | ||
| 5 | + the owner or an admin of this document.{/i18n} | ||
| 6 | + <div class="actionoptions"> | ||
| 7 | + {if !$is_broken} | ||
| 8 | + <a href="{ktLink base="notify.php" query="id=`$notify_id`"}">{i18n}View Document{/i18n}</a> | ||
| 9 | + {else} | ||
| 10 | + <span class="descriptiveText">{i18n}Document is no longer available{/i18n}</span> | ||
| 11 | + {/if} | ||
| 12 | + | <a href="{ktLink base="notify.php" query="id=`$notify_id`¬ify_action=clear"}">{i18n}Clear Alert{/i18n}</a> | ||
| 13 | + </div> | ||
| 14 | +</dd> |
templates/ktcore/assist/assist_notification_details.smarty
0 → 100644
| 1 | +<p class="descriptiveText"> | ||
| 2 | + {i18n arg_name=$document_name arg_state=$state_name arg_user=$actor->getName()}A | ||
| 3 | + user, <b>#user#</b>, has requested help on the document <b>#name#</b>, and you are | ||
| 4 | + the owner or an admin of this document.{/i18n} | ||
| 5 | +</p> | ||
| 6 | + | ||
| 7 | +<dl> | ||
| 8 | +<dt>Subject</dt> | ||
| 9 | +<dd>{$subject}</dd> | ||
| 10 | +<dt>Details</dt> | ||
| 11 | +<dd>{$details} </dd> | ||
| 12 | +</dl> | ||
| 13 | + | ||
| 14 | + <div class="actionoptions"> | ||
| 15 | + <a href="{ktLink base="notify.php" query="id=`$notify_id`¬ify_action=view"}">{i18n}View Document{/i18n}</a> | ||
| 16 | + | <a href="{ktLink base="notify.php" query="id=`$notify_id`¬ify_action=clear"}">{i18n}Clear Alert{/i18n}</a> | ||
| 17 | + </div> | ||
| 18 | + |