From ccc0f58726306c9ccf7ae345075ebed3eefee4e7 Mon Sep 17 00:00:00 2001 From: nbm Date: Tue, 11 Jul 2006 13:42:11 +0000 Subject: [PATCH] Add a "Request Assistance" action on documents for those who want to change a document when they can't. --- plugins/ktcore/KTAssist.php | 238 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ templates/ktcore/action/assistance.smarty | 20 ++++++++++++++++++++ templates/ktcore/assist/assist_notification.smarty | 14 ++++++++++++++ templates/ktcore/assist/assist_notification_details.smarty | 18 ++++++++++++++++++ 4 files changed, 290 insertions(+), 0 deletions(-) create mode 100644 plugins/ktcore/KTAssist.php create mode 100644 templates/ktcore/action/assistance.smarty create mode 100644 templates/ktcore/assist/assist_notification.smarty create mode 100644 templates/ktcore/assist/assist_notification_details.smarty diff --git a/plugins/ktcore/KTAssist.php b/plugins/ktcore/KTAssist.php new file mode 100644 index 0000000..5adecdf --- /dev/null +++ b/plugins/ktcore/KTAssist.php @@ -0,0 +1,238 @@ +oPage->setBreadcrumbDetails(_kt("assistance")); + $oTemplate =& $this->oValidator->validateTemplate('ktcore/action/assistance'); + $fields = array(); + $fields[] = new KTStringWidget(_kt('Subject'), _kt('A one-line description introducing the assistance that you wish to receive'), 'subject', "", $this->oPage, true); + $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); + + $oTemplate->setData(array( + 'context' => &$this, + 'fields' => $fields, + )); + return $oTemplate->render(); + } + + function do_assistance() { + $sSubject = $this->oValidator->validateString($_REQUEST['subject']); + $sDetails = $this->oValidator->validateString($_REQUEST['details']); + $aUsers = array(); + $aGroups = array(); + $aRoles = array(); + + foreach (Group::getAdministratorGroups() as $oGroup) { + $aGroups[$oGroup->getId()] =& $oGroup; + } + + foreach (Unit::getUnitsForFolder($this->oDocument->getFolderId()) as $oUnit) { + foreach (Group::getUnitAdministratorGroupsByUnit($oUnit) as $oGroup) { + $aGroups[$oGroup->getId()] =& $oGroup; + } + } + + $aRoles[-2] = Role::get(-2); + $oDocument =& $this->oDocument; + + foreach ($aRoles as $oRole) { + // Ignore anonymous or Everyone roles + $iRoleId = KTUtil::getId($oRole); + if (($iRoleId == -3) || ($iRoleId == -4)) { + continue; + } + // first try on the document, then the folder above it. + $oRoleAllocation = DocumentRoleAllocation::getAllocationsForDocumentAndRole($oDocument->getId(), $iRoleId); + if (is_null($oRoleAllocation)) { + // if we don't get a document role, try folder role. + $oRoleAllocation = RoleAllocation::getAllocationsForFolderAndRole($oDocument->getFolderID(), $oRole->getId()); + } + if (is_null($oRoleAllocation) || PEAR::isError($oRoleAllocation)) { + continue; + } + $aRoleUsers = $oRoleAllocation->getUsers(); + $aRoleGroups = $oRoleAllocation->getGroups(); + + foreach ($aRoleUsers as $id => $oU) { + $aUsers[$id] = $oU; + } + foreach ($aRoleGroups as $id => $oGroup) { + $aGroups[$id] = $oGroup; + } + } + + $aGroupMembershipSet = GroupUtil::buildGroupArray(); + $aAllIds = array_keys($aGroups); + foreach ($aGroups as $id => $oGroup) { + $aAllIds = kt_array_merge($aGroupMembershipSet[$id], $aAllIds); + } + + foreach ($aAllIds as $id) { + if (!array_key_exists($id, $aGroups)) { + $aGroups[$id] = Group::get($id); + } + } + + // now, merge this (again) into the user-set. + foreach ($aGroups as $oGroup) { + $aNewUsers = $oGroup->getMembers(); + foreach ($aNewUsers as $oU) { + $id = $oU->getId(); + if (!array_key_exists($id, $aUsers)) { + $aUsers[$id] = $oU; + } + } + } + + foreach ($aUsers as $oU) { + if (!PEAR::isError($oU)) { + KTAssistNotification::newNotificationForDocument($this->oDocument, $oU, $this->oUser, $sSubject, $sDetails); + } + } + + + $this->commitTransaction(); + $params = 'fDocumentId=' . $oDocument->getId(); + $url = generateControllerLink('viewDocument', $params); + exit(redirect($url)); + } +} +// }}} + +class KTAssistNotification extends KTNotificationHandler { + function & clearNotificationsForDocument($oDocument) { + $aNotifications = KTNotification::getList('data_int_1 = ' . $oDocument->getId()); + foreach ($aNotifications as $oNotification) { + $oNotification->delete(); + } + } + + function &newNotificationForDocument($oDocument, $oUser, $oActor, $sSubject, $sDetails) { + $aInfo = array(); + $aInfo['sData1'] = $sSubject; + $aInfo['sText1'] = $sDetails; + $aInfo['iData1'] = $oDocument->getId(); + $aInfo['iData2'] = $oActor->getId(); + $aInfo['sType'] = 'ktcore/assist'; + $aInfo['dCreationDate'] = getCurrentDateTime(); + $aInfo['iUserId'] = $oUser->getId(); + $aInfo['sLabel'] = $oDocument->getName(); + + $oNotification = KTNotification::createFromArray($aInfo); + + $handler = new KTAssistNotification(); + + if ($oUser->getEmailNotification() && (strlen($oUser->getEmail()) > 0)) { + $emailContent = $handler->handleNotification($oNotification); + $emailSubject = sprintf(_kt('Assistance request: %s'), $oDocument->getName()); + $oEmail = new EmailAlert($oUser->getEmail(), $emailSubject, $emailContent); + $oEmail->send(); + } + + return $oNotification; + } + + function handleNotification($oKTNotification) { + $oTemplating =& KTTemplating::getSingleton(); + $oTemplate =& $oTemplating->loadTemplate('ktcore/assist/assist_notification'); + + $oDoc = Document::get($oKTNotification->getIntData1()); + $isBroken = (PEAR::isError($oDoc) || ($oDoc->getStatusID() != LIVE)); + + $oTemplate->setData(array( + 'context' => $this, + 'document_id' => $oKTNotification->getIntData1(), + 'subject' => $oKTNotification->getStrData1(), + 'actor' => User::get($oKTNotification->getIntData2()), + 'document_name' => $oKTNotification->getLabel(), + 'notify_id' => $oKTNotification->getId(), + 'details' => $oKTNotification->getTextData1(), + 'document' => $oDoc, + 'is_broken' => $isBroken, + )); + return $oTemplate->render(); + } + + function resolveNotification($oKTNotification) { + $notify_action = KTUtil::arrayGet($_REQUEST, 'notify_action', null); + $this->oNotification =& $oKTNotification; + $this->redispatch('notify_action', 'notify'); + exit(0); + } + + function notify_main() { + $oTemplating =& KTTemplating::getSingleton(); + $oKTNotification =& $this->oNotification; + $oDoc = Document::get($oKTNotification->getIntData1()); + $isBroken = (PEAR::isError($oDoc) || ($oDoc->getStatusID() != LIVE)); + + $oTemplate =& $oTemplating->loadTemplate('ktcore/assist/assist_notification_details'); + $oTemplate->setData(array( + 'context' => $this, + 'document_id' => $oKTNotification->getIntData1(), + 'subject' => $oKTNotification->getStrData1(), + 'actor' => User::get($oKTNotification->getIntData2()), + 'document_name' => $oKTNotification->getLabel(), + 'notify_id' => $oKTNotification->getId(), + 'details' => $oKTNotification->getTextData1(), + 'document' => $oDoc, + 'is_broken' => $isBroken, + + )); + return $oTemplate->render(); + } + + function notify_clear() { + $_SESSION['KTInfoMessage'][] = _kt('Assistance Request cleared.'); + $this->oNotification->delete(); + exit(redirect(generateControllerLink('dashboard'))); + } + + function notify_view() { + $params = 'fDocumentId=' . $this->oNotification->getIntData1(); + $url = generateControllerLink('viewDocument', $params); + // $this->oNotification->delete(); // clear the alert. + exit(redirect($url)); + } +} + +?> diff --git a/templates/ktcore/action/assistance.smarty b/templates/ktcore/action/assistance.smarty new file mode 100644 index 0000000..d43ed68 --- /dev/null +++ b/templates/ktcore/action/assistance.smarty @@ -0,0 +1,20 @@ +

{i18n}If you are unable to perform an action +on this document that you think you should be able to, or wish to +request a change in location, metadata values, or workflow status, you +can use this form to contact the owner of the document and/or the +administrators to request this change.{/i18n}

+ +{assign var=iDocumentId value=$context->oDocument->getId()} + +
+
{i18n}Request Assistance{/i18n} + + +{foreach from=$fields item=oWidget } + {$oWidget->render()} +{/foreach} +
+ +
+
+
diff --git a/templates/ktcore/assist/assist_notification.smarty b/templates/ktcore/assist/assist_notification.smarty new file mode 100644 index 0000000..a67782a --- /dev/null +++ b/templates/ktcore/assist/assist_notification.smarty @@ -0,0 +1,14 @@ +
{$subject}
+
+ {i18n arg_name=$document_name arg_state=$state_name arg_user=$actor->getName()}A + user, #user#, has requested help on the document #name#, and you are + the owner or an admin of this document.{/i18n} +
+ {if !$is_broken} + {i18n}View Document{/i18n} + {else} + {i18n}Document is no longer available{/i18n} + {/if} + | {i18n}Clear Alert{/i18n} +
+
diff --git a/templates/ktcore/assist/assist_notification_details.smarty b/templates/ktcore/assist/assist_notification_details.smarty new file mode 100644 index 0000000..18ce6ca --- /dev/null +++ b/templates/ktcore/assist/assist_notification_details.smarty @@ -0,0 +1,18 @@ +

+ {i18n arg_name=$document_name arg_state=$state_name arg_user=$actor->getName()}A + user, #user#, has requested help on the document #name#, and you are + the owner or an admin of this document.{/i18n} +

+ +
+
Subject
+
{$subject}
+
Details
+
{$details}
+
+ +
+ {i18n}View Document{/i18n} + | {i18n}Clear Alert{/i18n} +
+ -- libgit2 0.21.4