From 8726b3a73cf5515c594be8516703aae448e60b6b Mon Sep 17 00:00:00 2001 From: kevin_fourie Date: Mon, 15 Sep 2008 16:07:40 +0000 Subject: [PATCH] Merged in from STABLE trunk... --- lib/subscriptions/Subscription.inc | 46 ++++++++++++++++++++++++++++++++++++---------- lib/subscriptions/subscriptions.inc.php | 579 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- plugins/ktstandard/KTSubscriptions.php | 223 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------------- sql/mysql/install/structure.sql | 3 ++- sql/mysql/upgrade/3.5.3/subscriptions.sql | 1 + templates/kt3/portlets/actions_portlet.smarty | 37 +++++++++++++++++++------------------ 6 files changed, 345 insertions(+), 544 deletions(-) create mode 100644 sql/mysql/upgrade/3.5.3/subscriptions.sql diff --git a/lib/subscriptions/Subscription.inc b/lib/subscriptions/Subscription.inc index 7db0f87..259b304 100644 --- a/lib/subscriptions/Subscription.inc +++ b/lib/subscriptions/Subscription.inc @@ -4,31 +4,31 @@ * Document Management Made Simple * Copyright (C) 2008 KnowledgeTree Inc. * Portions copyright The Jam Warehouse Software (Pty) Limited - * + * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3 as published by the * Free Software Foundation. - * + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . - * - * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, + * + * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, * California 94120-7775, or email info@knowledgetree.com. - * + * * The interactive user interfaces in modified source and object code versions * of this program must display Appropriate Legal Notices, as required under * Section 5 of the GNU General Public License version 3. - * + * * In accordance with Section 7(b) of the GNU General Public License version 3, * these Appropriate Legal Notices must retain the display of the "Powered by - * KnowledgeTree" logo and retain the original copyright notice. If the display of the + * KnowledgeTree" logo and retain the original copyright notice. If the display of the * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices - * must display the words "Powered by KnowledgeTree" and retain the original + * must display the words "Powered by KnowledgeTree" and retain the original * copyright notice. * Contributor( s): ______________________________________ * @@ -62,6 +62,10 @@ class Subscription extends KTEntity { */ var $bIsAlerted; /** + * Whether subfolders should be included + */ + var $bWithSubFolders; + /** * The subscription database table to use */ var $sTableName; @@ -155,6 +159,24 @@ class Subscription extends KTEntity { } /** + * Get the depth of the subscription + * + * @return boolean the depth of this subscription + */ + function getWithSubFolders() { + return $this->bWithSubFolders; + } + + /** + * Set the depth of the subscription + * + * @param boolean new depth status + */ + function setWithSubFolders($iNewValue) { + $this->bWithSubFolders = $iNewValue; + } + + /** * Returns the display path to the subscription content */ function getContentDisplayPath() { @@ -217,11 +239,15 @@ class Subscription extends KTEntity { } function _fieldValues () { - return array( + $fields = array( 'user_id' => $this->iUserID, $this->sIdFieldName => $this->iExternalID, 'is_alerted' => KTUtil::anyToBool($this->bIsAlerted), ); + if($this->sIdFieldName == 'folder_id'){ + $fields['with_subfolders'] = KTUtil::anyToBool($this->bWithSubFolders); + } + return $fields; } function _table () { diff --git a/lib/subscriptions/subscriptions.inc.php b/lib/subscriptions/subscriptions.inc.php index a6e5c76..1c27614 100644 --- a/lib/subscriptions/subscriptions.inc.php +++ b/lib/subscriptions/subscriptions.inc.php @@ -6,31 +6,31 @@ * Document Management Made Simple * Copyright (C) 2008 KnowledgeTree Inc. * Portions copyright The Jam Warehouse Software (Pty) Limited - * + * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3 as published by the * Free Software Foundation. - * + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . - * - * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, + * + * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, * California 94120-7775, or email info@knowledgetree.com. - * + * * The interactive user interfaces in modified source and object code versions * of this program must display Appropriate Legal Notices, as required under * Section 5 of the GNU General Public License version 3. - * + * * In accordance with Section 7(b) of the GNU General Public License version 3, * these Appropriate Legal Notices must retain the display of the "Powered by - * KnowledgeTree" logo and retain the original copyright notice. If the display of the + * KnowledgeTree" logo and retain the original copyright notice. If the display of the * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices - * must display the words "Powered by KnowledgeTree" and retain the original + * must display the words "Powered by KnowledgeTree" and retain the original * copyright notice. * Contributor( s): ______________________________________ * @@ -101,55 +101,20 @@ class SubscriptionEvent { // only useful for folder subscriptions. $aUsers = $this->_getSubscribers($oParentFolder->getId(), $this->subscriptionTypes["Folder"]); - foreach ($aUsers as $oSubscriber) { - // notification object first. - $aNotificationOptions = array(); - $aNotificationOptions['target_user'] = $oSubscriber->getID(); - $aNotificationOptions['actor_id'] = KTUtil::arrayGet($_SESSION,"userID", null); // _won't_ be null. - $aNotificationOptions['target_name'] = $oAddedFolder->getName(); - $aNotificationOptions['location_name'] = Folder::generateFullFolderPath($oParentFolder->getId()); - $aNotificationOptions['object_id'] = $oAddedFolder->getId(); // parent folder_id, in this case. - $aNotificationOptions['event_type'] = "AddFolder"; - $oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions); - - // now the email content. - // FIXME this needs to be handled entirely within notifications from now on. - if ($oSubscriber->getEmailNotification() && (strlen($oSubscriber->getEmail()) > 0)) { - $emailContent = $content->getEmailAlertContent($oNotification); - $emailSubject = $content->getEmailAlertSubject($oNotification); - $oEmail = new EmailAlert($oSubscriber->getEmail(), $emailSubject, $emailContent); - $oEmail->send(); - } - } + $parentId = $oParentFolder->getId(); + $this->sendNotification($aUsers, 'AddFolder', $oAddedFolder->getName(), $oAddedFolder->getId(), $parentId); } + function AddDocument ($oAddedDocument, $oParentFolder) { $content = new SubscriptionContent(); // needed for i18n // two parts to this: $aUsers = $this->_getSubscribers($oParentFolder->getId(), $this->subscriptionTypes["Folder"]); - foreach ($aUsers as $oSubscriber) { - - // notification object first. - $aNotificationOptions = array(); - $aNotificationOptions['target_user'] = $oSubscriber->getID(); - $aNotificationOptions['actor_id'] = KTUtil::arrayGet($_SESSION,"userID", null); // _won't_ be null - is this valid? - $aNotificationOptions['target_name'] = $oAddedDocument->getName(); - $aNotificationOptions['location_name'] = Folder::generateFullFolderPath($oParentFolder->getId()); - $aNotificationOptions['object_id'] = $oAddedDocument->getId(); // parent folder_id, in this case. - $aNotificationOptions['event_type'] = "AddDocument"; - $oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions); - - // now the email content. - // FIXME this needs to be handled entirely within notifications from now on. - if ($oSubscriber->getEmailNotification() && (strlen($oSubscriber->getEmail()) > 0)) { - $emailContent = $content->getEmailAlertContent($oNotification); - $emailSubject = $content->getEmailAlertSubject($oNotification); - $oEmail = new EmailAlert($oSubscriber->getEmail(), $emailSubject, $emailContent); - $oEmail->send(); - } - } + $parentId = $oParentFolder->getId(); + $this->sendNotification($aUsers, 'AddDocument', $oAddedDocument->getName(), $oAddedDocument->getId(), $parentId); } + function RemoveFolder($oRemovedFolder, $oParentFolder) { $content = new SubscriptionContent(); // needed for i18n // two cases to consider here: @@ -188,29 +153,11 @@ class SubscriptionEvent { // now handle (for those who haven't been alerted) users watching the folder. $aUsers = $this->_getSubscribers($oParentFolder->getId(), $this->subscriptionTypes["Folder"]); - foreach ($aUsers as $oSubscriber) { - - // notification object first. - $aNotificationOptions = array(); - $aNotificationOptions['target_user'] = $oSubscriber->getID(); - $aNotificationOptions['actor_id'] = KTUtil::arrayGet($_SESSION,"userID", null); // _won't_ be null. - $aNotificationOptions['target_name'] = $oRemovedFolder->getName(); - $aNotificationOptions['location_name'] = Folder::generateFullFolderPath($oParentFolder->getId()); - $aNotificationOptions['object_id'] = $oParentFolder->getId(); // parent folder_id, since the removed one is removed. - $aNotificationOptions['event_type'] = "RemoveChildFolder"; - $oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions); - - // now the email content. - // FIXME this needs to be handled entirely within notifications from now on. - if ($oSubscriber->getEmailNotification() && (strlen($oSubscriber->getEmail()) > 0)) { - $emailContent = $content->getEmailAlertContent($oNotification); - $emailSubject = $content->getEmailAlertSubject($oNotification); - $oEmail = new EmailAlert($oSubscriber->getEmail(), $emailSubject, $emailContent); - $oEmail->send(); - } - } + $parentId = $oParentFolder->getId(); + $this->sendNotification($aUsers, 'RemoveChildFolder', $oRemovedFolder->getName(), $oParentFolder->getId(), $parentId); } + function RemoveDocument($oRemovedDocument, $oParentFolder) { $content = new SubscriptionContent(); // needed for i18n // two cases to consider here: @@ -249,457 +196,126 @@ class SubscriptionEvent { // now handle (for those who haven't been alerted) users watching the folder. $aUsers = $this->_getSubscribers($oParentFolder->getId(), $this->subscriptionTypes["Folder"]); - foreach ($aUsers as $oSubscriber) { - - // notification object first. - $aNotificationOptions = array(); - $aNotificationOptions['target_user'] = $oSubscriber->getID(); - $aNotificationOptions['actor_id'] = KTUtil::arrayGet($_SESSION,"userID", null); // _won't_ be null. - $aNotificationOptions['target_name'] = $oRemovedDocument->getName(); - $aNotificationOptions['location_name'] = Folder::generateFullFolderPath($oParentFolder->getId()); - $aNotificationOptions['object_id'] = $oParentFolder->getId(); // parent folder_id, since the removed one is removed. - $aNotificationOptions['event_type'] = "RemoveChildDocument"; - $oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions); - - // now the email content. - // FIXME this needs to be handled entirely within notifications from now on. - if ($oSubscriber->getEmailNotification() && (strlen($oSubscriber->getEmail()) > 0)) { - $emailContent = $content->getEmailAlertContent($oNotification); - $emailSubject = $content->getEmailAlertSubject($oNotification); - $oEmail = new EmailAlert($oSubscriber->getEmail(), $emailSubject, $emailContent); - $oEmail->send(); - } - } + $parentId = $oParentFolder->getId(); + $this->sendNotification($aUsers, 'RemoveChildDocument', $oRemovedDocument->getName(), $oParentFolder->getId(), $parentId); } function ModifyDocument($oModifiedDocument, $oParentFolder) { $content = new SubscriptionContent(); // needed for i18n // OK: two actions: document registrants, folder registrants. - $aUsers = $this->_getSubscribers($oModifiedDocument->getId(), $this->subscriptionTypes["Document"]); - foreach ($aUsers as $oSubscriber) { - - // notification object first. - $aNotificationOptions = array(); - $aNotificationOptions['target_user'] = $oSubscriber->getID(); - $aNotificationOptions['actor_id'] = KTUtil::arrayGet($_SESSION,"userID", null); // _won't_ be null. - $aNotificationOptions['target_name'] = $oModifiedDocument->getName(); - $aNotificationOptions['location_name'] = Folder::generateFullFolderPath($oParentFolder->getId()); - $aNotificationOptions['object_id'] = $oModifiedDocument->getId(); // parent folder_id, in this case. - $aNotificationOptions['event_type'] = "ModifyDocument"; - $oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions); - - // now the email content. - // FIXME this needs to be handled entirely within notifications from now on. - if ($oSubscriber->getEmailNotification() && (strlen($oSubscriber->getEmail()) > 0)) { - $emailContent = $content->getEmailAlertContent($oNotification); - $emailSubject = $content->getEmailAlertSubject($oNotification); - $oEmail = new EmailAlert($oSubscriber->getEmail(), $emailSubject, $emailContent); - $oEmail->send(); - } - } - + $aDocUsers = $this->_getSubscribers($oModifiedDocument->getId(), $this->subscriptionTypes["Document"]); + $aFolderUsers = $this->_getSubscribers($oParentFolder->getId(), $this->subscriptionTypes["Folder"]); + $aUsers = array_merge($aDocUsers, $aFolderUsers); - $aUsers = $this->_getSubscribers($oParentFolder->getId(), $this->subscriptionTypes["Folder"]); - foreach ($aUsers as $oSubscriber) { - - // notification object first. - $aNotificationOptions = array(); - $aNotificationOptions['target_user'] = $oSubscriber->getID(); - $aNotificationOptions['actor_id'] = KTUtil::arrayGet($_SESSION,"userID", null); // _won't_ be null. - $aNotificationOptions['target_name'] = $oModifiedDocument->getName(); - $aNotificationOptions['location_name'] = Folder::generateFullFolderPath($oParentFolder->getId()); - $aNotificationOptions['object_id'] = $oModifiedDocument->getId(); // parent folder_id, in this case. - $aNotificationOptions['event_type'] = "ModifyDocument"; - $oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions); - - // now the email content. - // FIXME this needs to be handled entirely within notifications from now on. - if ($oSubscriber->getEmailNotification() && (strlen($oSubscriber->getEmail()) > 0)) { - $emailContent = $content->getEmailAlertContent($oNotification); - $emailSubject = $content->getEmailAlertSubject($oNotification); - $oEmail = new EmailAlert($oSubscriber->getEmail(), $emailSubject, $emailContent); - $oEmail->send(); - } - } + $parentId = $oParentFolder->getId(); + $this->sendNotification($aUsers, 'ModifyDocument', $oModifiedDocument->getName(), $oModifiedDocument->getId(), $parentId); } function DiscussDocument($oModifiedDocument, $oParentFolder) { $content = new SubscriptionContent(); // needed for i18n // OK: two actions: document registrants, folder registrants. - $aUsers = $this->_getSubscribers($oModifiedDocument->getId(), $this->subscriptionTypes["Document"]); - foreach ($aUsers as $oSubscriber) { - - // notification object first. - $aNotificationOptions = array(); - $aNotificationOptions['target_user'] = $oSubscriber->getID(); - $aNotificationOptions['actor_id'] = KTUtil::arrayGet($_SESSION,"userID", null); // _won't_ be null. - $aNotificationOptions['target_name'] = $oModifiedDocument->getName(); - $aNotificationOptions['location_name'] = Folder::generateFullFolderPath($oParentFolder->getId()); - $aNotificationOptions['object_id'] = $oModifiedDocument->getId(); // parent folder_id, in this case. - $aNotificationOptions['event_type'] = "DiscussDocument"; - $oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions); + $aDocUsers = $this->_getSubscribers($oModifiedDocument->getId(), $this->subscriptionTypes["Document"]); + $aFolderUsers = $this->_getSubscribers($oParentFolder->getId(), $this->subscriptionTypes["Folder"]); + $aUsers = array_merge($aDocUsers, $aFolderUsers); - // now the email content. - // FIXME this needs to be handled entirely within notifications from now on. - if ($oSubscriber->getEmailNotification() && (strlen($oSubscriber->getEmail()) > 0)) { - $emailContent = $content->getEmailAlertContent($oNotification); - $emailSubject = $content->getEmailAlertSubject($oNotification); - $oEmail = new EmailAlert($oSubscriber->getEmail(), $emailSubject, $emailContent); - $oEmail->send(); - } - } - - $aUsers = $this->_getSubscribers($oParentFolder->getId(), $this->subscriptionTypes["Folder"]); - foreach ($aUsers as $oSubscriber) { - - // notification object first. - $aNotificationOptions = array(); - $aNotificationOptions['target_user'] = $oSubscriber->getID(); - $aNotificationOptions['actor_id'] = KTUtil::arrayGet($_SESSION,"userID", null); // _won't_ be null. - $aNotificationOptions['target_name'] = $oModifiedDocument->getName(); - $aNotificationOptions['location_name'] = Folder::generateFullFolderPath($oParentFolder->getId()); - $aNotificationOptions['object_id'] = $oModifiedDocument->getId(); // parent folder_id, in this case. - $aNotificationOptions['event_type'] = "DiscussDocument"; - $oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions); - - // now the email content. - // FIXME this needs to be handled entirely within notifications from now on. - if ($oSubscriber->getEmailNotification() && (strlen($oSubscriber->getEmail()) > 0)) { - $emailContent = $content->getEmailAlertContent($oNotification); - $emailSubject = $content->getEmailAlertSubject($oNotification); - $oEmail = new EmailAlert($oSubscriber->getEmail(), $emailSubject, $emailContent); - $oEmail->send(); - } - } + $parentId = $oParentFolder->getId(); + $this->sendNotification($aUsers, 'DiscussDocument', $oModifiedDocument->getName(), $oModifiedDocument->getId(), $parentId); } function CheckInDocument($oModifiedDocument, $oParentFolder) { $content = new SubscriptionContent(); // needed for i18n // OK: two actions: document registrants, folder registrants. - $aUsers = $this->_getSubscribers($oModifiedDocument->getId(), $this->subscriptionTypes["Document"]); - foreach ($aUsers as $oSubscriber) { - - // notification object first. - $aNotificationOptions = array(); - $aNotificationOptions['target_user'] = $oSubscriber->getID(); - $aNotificationOptions['actor_id'] = KTUtil::arrayGet($_SESSION,"userID", null); // _won't_ be null. - $aNotificationOptions['target_name'] = $oModifiedDocument->getName(); - $aNotificationOptions['location_name'] = Folder::generateFullFolderPath($oParentFolder->getId()); - $aNotificationOptions['object_id'] = $oModifiedDocument->getId(); // parent folder_id, in this case. - $aNotificationOptions['event_type'] = "CheckInDocument"; - $oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions); - - // now the email content. - // FIXME this needs to be handled entirely within notifications from now on. - if ($oSubscriber->getEmailNotification() && (strlen($oSubscriber->getEmail()) > 0)) { - $emailContent = $content->getEmailAlertContent($oNotification); - $emailSubject = $content->getEmailAlertSubject($oNotification); - $oEmail = new EmailAlert($oSubscriber->getEmail(), $emailSubject, $emailContent); - $oEmail->send(); - } - } - + $aDocUsers = $this->_getSubscribers($oModifiedDocument->getId(), $this->subscriptionTypes["Document"]); + $aFolderUsers = $this->_getSubscribers($oParentFolder->getId(), $this->subscriptionTypes["Folder"]); + $aUsers = array_merge($aDocUsers, $aFolderUsers); - $aUsers = $this->_getSubscribers($oParentFolder->getId(), $this->subscriptionTypes["Folder"]); - - foreach ($aUsers as $oSubscriber) { - - // notification object first. - $aNotificationOptions = array(); - $aNotificationOptions['target_user'] = $oSubscriber->getID(); - $aNotificationOptions['actor_id'] = KTUtil::arrayGet($_SESSION,"userID", null); // _won't_ be null. - $aNotificationOptions['target_name'] = $oModifiedDocument->getName(); - $aNotificationOptions['location_name'] = Folder::generateFullFolderPath($oParentFolder->getId()); - $aNotificationOptions['object_id'] = $oModifiedDocument->getId(); // parent folder_id, in this case. - $aNotificationOptions['event_type'] = "CheckInDocument"; - $oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions); - - // now the email content. - // FIXME this needs to be handled entirely within notifications from now on. - if ($oSubscriber->getEmailNotification() && (strlen($oSubscriber->getEmail()) > 0)) { - $emailContent = $content->getEmailAlertContent($oNotification); - $emailSubject = $content->getEmailAlertSubject($oNotification); - $oEmail = new EmailAlert($oSubscriber->getEmail(), $emailSubject, $emailContent); - $oEmail->send(); - - } - } + $parentId = $oParentFolder->getId(); + $this->sendNotification($aUsers, 'CheckInDocument', $oModifiedDocument->getName(), $oModifiedDocument->getId(), $parentId); } + function CheckOutDocument($oModifiedDocument, $oParentFolder) { $content = new SubscriptionContent(); // needed for i18n // OK: two actions: document registrants, folder registrants. - $aUsers = $this->_getSubscribers($oModifiedDocument->getId(), $this->subscriptionTypes["Document"]); - - foreach ($aUsers as $oSubscriber) { - - // notification object first. - $aNotificationOptions = array(); - $aNotificationOptions['target_user'] = $oSubscriber->getID(); - $aNotificationOptions['actor_id'] = KTUtil::arrayGet($_SESSION,"userID", null); // _won't_ be null. - $aNotificationOptions['target_name'] = $oModifiedDocument->getName(); - $aNotificationOptions['location_name'] = Folder::generateFullFolderPath($oParentFolder->getId()); - $aNotificationOptions['object_id'] = $oModifiedDocument->getId(); // parent folder_id, in this case. - $aNotificationOptions['event_type'] = "CheckOutDocument"; - $oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions); - - // now the email content. - // FIXME this needs to be handled entirely within notifications from now on. - if ($oSubscriber->getEmailNotification() && (strlen($oSubscriber->getEmail()) > 0)) { - $emailContent = $content->getEmailAlertContent($oNotification); - $emailSubject = $content->getEmailAlertSubject($oNotification); - $oEmail = new EmailAlert($oSubscriber->getEmail(), $emailSubject, $emailContent); - $oEmail->send(); - } - } - + $aDocUsers = $this->_getSubscribers($oModifiedDocument->getId(), $this->subscriptionTypes["Document"]); + $aFolderUsers = $this->_getSubscribers($oParentFolder->getId(), $this->subscriptionTypes["Folder"]); + $aUsers = array_merge($aDocUsers, $aFolderUsers); - $aUsers = $this->_getSubscribers($oParentFolder->getId(), $this->subscriptionTypes["Folder"]); - foreach ($aUsers as $oSubscriber) { - - // notification object first. - $aNotificationOptions = array(); - $aNotificationOptions['target_user'] = $oSubscriber->getID(); - $aNotificationOptions['actor_id'] = KTUtil::arrayGet($_SESSION,"userID", null); // _won't_ be null. - $aNotificationOptions['target_name'] = $oModifiedDocument->getName(); - $aNotificationOptions['location_name'] = Folder::generateFullFolderPath($oParentFolder->getId()); - $aNotificationOptions['object_id'] = $oModifiedDocument->getId(); // parent folder_id, in this case. - $aNotificationOptions['event_type'] = "CheckOutDocument"; - $oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions); - - // now the email content. - // FIXME this needs to be handled entirely within notifications from now on. - if ($oSubscriber->getEmailNotification() && (strlen($oSubscriber->getEmail()) > 0)) { - $emailContent = $content->getEmailAlertContent($oNotification); - $emailSubject = $content->getEmailAlertSubject($oNotification); - $oEmail = new EmailAlert($oSubscriber->getEmail(), $emailSubject, $emailContent); - $oEmail->send(); - } - } + $parentId = $oParentFolder->getId(); + $this->sendNotification($aUsers, 'CheckOutDocument', $oModifiedDocument->getName(), $oModifiedDocument->getId(), $parentId); } function MoveDocument($oMovedDocument, $oToFolder, $oFromFolder, $moveOrCopy = "MovedDocument") { $content = new SubscriptionContent(); // needed for i18n // OK: two actions: document registrants, folder registrants. - $aUsers = $this->_getSubscribers($oMovedDocument->getId(), $this->subscriptionTypes["Document"]); - - foreach ($aUsers as $oSubscriber) { - // notification object first. - $aNotificationOptions = array(); - $aNotificationOptions['target_user'] = $oSubscriber->getID(); - $aNotificationOptions['actor_id'] = KTUtil::arrayGet($_SESSION,"userID", null); // _won't_ be null. - $aNotificationOptions['target_name'] = $oMovedDocument->getName(); - $aNotificationOptions['location_name'] = Folder::generateFullFolderPath($oToFolder->getId()); - $aNotificationOptions['object_id'] = $oToFolder->getId(); // parent folder_id, in this case. - $aNotificationOptions['event_type'] = $moveOrCopy; - $oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions); - - // now the email content. - // FIXME this needs to be handled entirely within notifications from now on. - if ($oSubscriber->getEmailNotification() && (strlen($oSubscriber->getEmail()) > 0)) { - $emailContent = $content->getEmailAlertContent($oNotification); - $emailSubject = $content->getEmailAlertSubject($oNotification); - $oEmail = new EmailAlert($oSubscriber->getEmail(), $emailSubject, $emailContent); - $oEmail->send(); - } - } - - - $aUsers = $this->_getSubscribers($oFromFolder->getId(), $this->subscriptionTypes["Folder"]); - - foreach ($aUsers as $oSubscriber) { - - // notification object first. - $aNotificationOptions = array(); - $aNotificationOptions['target_user'] = $oSubscriber->getID(); - $aNotificationOptions['actor_id'] = KTUtil::arrayGet($_SESSION,"userID", null); // _won't_ be null. - $aNotificationOptions['target_name'] = $oMovedDocument->getName(); - $aNotificationOptions['location_name'] = Folder::generateFullFolderPath($oToFolder->getId()); - $aNotificationOptions['object_id'] = $oToFolder->getId(); // parent folder_id, in this case. - $aNotificationOptions['event_type'] = $moveOrCopy; - $oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions); - - // now the email content. - // FIXME this needs to be handled entirely within notifications from now on. - if ($oSubscriber->getEmailNotification() && (strlen($oSubscriber->getEmail()) > 0)) { - $emailContent = $content->getEmailAlertContent($oNotification); - $emailSubject = $content->getEmailAlertSubject($oNotification); - $oEmail = new EmailAlert($oSubscriber->getEmail(), $emailSubject, $emailContent); - $oEmail->send(); - } - } - - $aUsers = $this->_getSubscribers($oToFolder->getId(), $this->subscriptionTypes["Folder"]); - foreach ($aUsers as $oSubscriber) { - - // notification object first. - $aNotificationOptions = array(); - $aNotificationOptions['target_user'] = $oSubscriber->getID(); - $aNotificationOptions['actor_id'] = KTUtil::arrayGet($_SESSION,"userID", null); // _won't_ be null. - $aNotificationOptions['target_name'] = $oMovedDocument->getName(); - $aNotificationOptions['location_name'] = Folder::generateFullFolderPath($oToFolder->getId()); - $aNotificationOptions['object_id'] = $oToFolder->getId(); // parent folder_id, in this case. - $aNotificationOptions['event_type'] = $moveOrCopy; - $oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions); - - // now the email content. - // FIXME this needs to be handled entirely within notifications from now on. - if ($oSubscriber->getEmailNotification() && (strlen($oSubscriber->getEmail()) > 0)) { - $emailContent = $content->getEmailAlertContent($oNotification); - $emailSubject = $content->getEmailAlertSubject($oNotification); - $oEmail = new EmailAlert($oSubscriber->getEmail(), $emailSubject, $emailContent); - $oEmail->send(); - } - } + $aDocUsers = $this->_getSubscribers($oMovedDocument->getId(), $this->subscriptionTypes["Document"]); + $aFromUsers = $this->_getSubscribers($oFromFolder->getId(), $this->subscriptionTypes["Folder"]); + $aFolderUsers = $this->_getSubscribers($oToFolder->getId(), $this->subscriptionTypes["Folder"]); + $aUsers = array_merge($aDocUsers, $aFromUsers); + $aUsers = array_merge($aUsers, $aFolderUsers); + + $parentId = $oToFolder->getId(); + $this->sendNotification($aUsers, $moveOrCopy, $oMovedDocument->getName(), $oToFolder->getId(), $parentId); } function ArchivedDocument($oModifiedDocument, $oParentFolder) { $content = new SubscriptionContent(); // needed for i18n // OK: two actions: document registrants, folder registrants. - $aUsers = $this->_getSubscribers($oModifiedDocument->getId(), $this->subscriptionTypes["Document"]); - foreach ($aUsers as $oSubscriber) { + $aDocUsers = $this->_getSubscribers($oModifiedDocument->getId(), $this->subscriptionTypes["Document"]); + $aFolderUsers = $this->_getSubscribers($oParentFolder->getId(), $this->subscriptionTypes["Folder"]); + $aUsers = array_merge($aDocUsers, $aFolderUsers); - // notification object first. - $aNotificationOptions = array(); - $aNotificationOptions['target_user'] = $oSubscriber->getID(); - $aNotificationOptions['actor_id'] = KTUtil::arrayGet($_SESSION,"userID", null); // _won't_ be null. - $aNotificationOptions['target_name'] = $oModifiedDocument->getName(); - $aNotificationOptions['location_name'] = Folder::generateFullFolderPath($oParentFolder->getId()); - $aNotificationOptions['object_id'] = $oModifiedDocument->getId(); // parent folder_id, in this case. - $aNotificationOptions['event_type'] = "ArchivedDocument"; - $oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions); - - // now the email content. - // FIXME this needs to be handled entirely within notifications from now on. - if ($oSubscriber->getEmailNotification() && (strlen($oSubscriber->getEmail()) > 0)) { - $emailContent = $content->getEmailAlertContent($oNotification); - $emailSubject = $content->getEmailAlertSubject($oNotification); - $oEmail = new EmailAlert($oSubscriber->getEmail(), $emailSubject, $emailContent); - $oEmail->send(); - } - } - - - $aUsers = $this->_getSubscribers($oParentFolder->getId(), $this->subscriptionTypes["Folder"]); - foreach ($aUsers as $oSubscriber) { - - // notification object first. - $aNotificationOptions = array(); - $aNotificationOptions['target_user'] = $oSubscriber->getID(); - $aNotificationOptions['actor_id'] = KTUtil::arrayGet($_SESSION,"userID", null); // _won't_ be null. - $aNotificationOptions['target_name'] = $oModifiedDocument->getName(); - $aNotificationOptions['location_name'] = Folder::generateFullFolderPath($oParentFolder->getId()); - $aNotificationOptions['object_id'] = $oModifiedDocument->getId(); // parent folder_id, in this case. - $aNotificationOptions['event_type'] = "ArchivedDocument"; - $oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions); - - // now the email content. - // FIXME this needs to be handled entirely within notifications from now on. - if ($oSubscriber->getEmailNotification() && (strlen($oSubscriber->getEmail()) > 0)) { - $emailContent = $content->getEmailAlertContent($oNotification); - $emailSubject = $content->getEmailAlertSubject($oNotification); - $oEmail = new EmailAlert($oSubscriber->getEmail(), $emailSubject, $emailContent); - $oEmail->send(); - } - } + $parentId = $oParentFolder->getId(); + $this->sendNotification($aUsers, 'ArchivedDocument', $oModifiedDocument->getName(), $oModifiedDocument->getId(), $parentId); } function RestoreDocument($oModifiedDocument, $oParentFolder) { $content = new SubscriptionContent(); // needed for i18n // OK: two actions: document registrants, folder registrants. - $aUsers = $this->_getSubscribers($oModifiedDocument->getId(), $this->subscriptionTypes["Document"]); - foreach ($aUsers as $oSubscriber) { - - // notification object first. - $aNotificationOptions = array(); - $aNotificationOptions['target_user'] = $oSubscriber->getID(); - $aNotificationOptions['actor_id'] = KTUtil::arrayGet($_SESSION,"userID", null); // _won't_ be null. - $aNotificationOptions['target_name'] = $oModifiedDocument->getName(); - $aNotificationOptions['location_name'] = Folder::generateFullFolderPath($oParentFolder->getId()); - $aNotificationOptions['object_id'] = $oModifiedDocument->getId(); // parent folder_id, in this case. - $aNotificationOptions['event_type'] = "RestoreArchivedDocument"; - $oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions); - - // now the email content. - // FIXME this needs to be handled entirely within notifications from now on. - if ($oSubscriber->getEmailNotification() && (strlen($oSubscriber->getEmail()) > 0)) { - $emailContent = $content->getEmailAlertContent($oNotification); - $emailSubject = $content->getEmailAlertSubject($oNotification); - $oEmail = new EmailAlert($oSubscriber->getEmail(), $emailSubject, $emailContent); - $oEmail->send(); - } - } - - - $aUsers = $this->_getSubscribers($oParentFolder->getId(), $this->subscriptionTypes["Folder"]); - foreach ($aUsers as $oSubscriber) { + $aDocUsers = $this->_getSubscribers($oModifiedDocument->getId(), $this->subscriptionTypes["Document"]); + $aFolderUsers = $this->_getSubscribers($oParentFolder->getId(), $this->subscriptionTypes["Folder"]); + $aUsers = array_merge($aDocUsers, $aFolderUsers); - // notification object first. - $aNotificationOptions = array(); - $aNotificationOptions['target_user'] = $oSubscriber->getID(); - $aNotificationOptions['actor_id'] = KTUtil::arrayGet($_SESSION,"userID", null); // _won't_ be null. - $aNotificationOptions['target_name'] = $oModifiedDocument->getName(); - $aNotificationOptions['location_name'] = Folder::generateFullFolderPath($oParentFolder->getId()); - $aNotificationOptions['object_id'] = $oModifiedDocument->getId(); // parent folder_id, in this case. - $aNotificationOptions['event_type'] = "RestoreArchivedDocument"; - $oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions); - - // now the email content. - // FIXME this needs to be handled entirely within notifications from now on. - if ($oSubscriber->getEmailNotification() && (strlen($oSubscriber->getEmail()) > 0)) { - $emailContent = $content->getEmailAlertContent($oNotification); - $emailSubject = $content->getEmailAlertSubject($oNotification); - $oEmail = new EmailAlert($oSubscriber->getEmail(), $emailSubject, $emailContent); - $oEmail->send(); - } - } + $parentId = $oParentFolder->getId(); + $this->sendNotification($aUsers, 'RestoreArchivedDocument', $oModifiedDocument->getName(), $oModifiedDocument->getId(), $parentId); } function DownloadDocument($oDocument, $oParentFolder) { $content = new SubscriptionContent(); // needed for i18n // OK: two actions: document registrants, folder registrants. - $aUsers = $this->_getSubscribers($oDocument->getId(), $this->subscriptionTypes["Document"]); - foreach ($aUsers as $oSubscriber) { + $aDocUsers = $this->_getSubscribers($oDocument->getId(), $this->subscriptionTypes["Document"]); + $aFolderUsers = $this->_getSubscribers($oParentFolder->getId(), $this->subscriptionTypes["Folder"]); + $aUsers = array_merge($aDocUsers, $aFolderUsers); - // notification object first. - $aNotificationOptions = array(); - $aNotificationOptions['target_user'] = $oSubscriber->getID(); - $aNotificationOptions['actor_id'] = KTUtil::arrayGet($_SESSION,"userID", null); // _won't_ be null. - $aNotificationOptions['target_name'] = $oDocument->getName(); - $aNotificationOptions['location_name'] = Folder::generateFullFolderPath($oParentFolder->getId()); - $aNotificationOptions['object_id'] = $oDocument->getId(); // parent folder_id, in this case. - $aNotificationOptions['event_type'] = "DownloadDocument"; - $oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions); + $parentId = $oParentFolder->getId(); + $this->sendNotification($aUsers, 'DownloadDocument', $oDocument->getName(), $oDocument->getId(), $parentId); + } - // now the email content. - // FIXME this needs to be handled entirely within notifications from now on. - if ($oSubscriber->getEmailNotification() && (strlen($oSubscriber->getEmail()) > 0)) { - $emailContent = $content->getEmailAlertContent($oNotification); - $emailSubject = $content->getEmailAlertSubject($oNotification); - $oEmail = new EmailAlert($oSubscriber->getEmail(), $emailSubject, $emailContent); - $oEmail->send(); - } - } + function sendNotification($aUsers, $eventType, $targetName, $objectId, $parentId) { + $content = new SubscriptionContent(); // needed for i18n + //$aUsers = $this->_getSubscribers($oDocument->getId(), $this->subscriptionTypes["Document"]); - $aUsers = $this->_getSubscribers($oParentFolder->getId(), $this->subscriptionTypes["Folder"]); + $locationName = Folder::generateFullFolderPath($parentId); + $userId = $_SESSION['userID']; foreach ($aUsers as $oSubscriber) { - // notification object first. - $aNotificationOptions = array(); - $aNotificationOptions['target_user'] = $oSubscriber->getID(); - $aNotificationOptions['actor_id'] = KTUtil::arrayGet($_SESSION,"userID", null); // _won't_ be null. - $aNotificationOptions['target_name'] = $oDocument->getName(); - $aNotificationOptions['location_name'] = Folder::generateFullFolderPath($oParentFolder->getId()); - $aNotificationOptions['object_id'] = $oDocument->getId(); // parent folder_id, in this case. - $aNotificationOptions['event_type'] = "DownloadDocument"; - $oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions); + $emailAddress = $oSubscriber->getEmail(); + if ($oSubscriber->getEmailNotification() && !empty($emailAddress)) { - // now the email content. - // FIXME this needs to be handled entirely within notifications from now on. - if ($oSubscriber->getEmailNotification() && (strlen($oSubscriber->getEmail()) > 0)) { + // notification object first. + $aNotificationOptions = array(); + $aNotificationOptions['target_user'] = $oSubscriber->getID(); + $aNotificationOptions['actor_id'] = $userId; + $aNotificationOptions['target_name'] = $targetName; + $aNotificationOptions['location_name'] = $locationName; + $aNotificationOptions['object_id'] = $objectId; + $aNotificationOptions['event_type'] = $eventType; + $oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions); + + // now the email content. $emailContent = $content->getEmailAlertContent($oNotification); $emailSubject = $content->getEmailAlertSubject($oNotification); - $oEmail = new EmailAlert($oSubscriber->getEmail(), $emailSubject, $emailContent); + $oEmail = new EmailAlert($emailAddress, $emailSubject, $emailContent); $oEmail->send(); } } @@ -729,11 +345,32 @@ class SubscriptionEvent { global $default; // for the logging. if (KTLOG_CACHE) $default->log->debug("_getSubscribers(id=$iObjectId, type=$iSubType); table=" .Subscription::getTableName($iSubType). "; id=" .Subscription::getIdFieldName($iSubType)); - $aUsers = array(); - $sQuery = "SELECT user_id FROM " . Subscription::getTableName($iSubType) . " WHERE " . Subscription::getIdFieldName($iSubType) . " = ?"; + $aUsers = array(); + $aNewUsers = array(); + $aSubUsers = array(); + $table = Subscription::getTableName($iSubType); + $field = Subscription::getIdFieldName($iSubType); + + // If we're dealing with a folder then get those user who are subscribed to one of the parent folders and want notifications on sub folders + if($iSubType == $this->subscriptionTypes["Folder"] && $iObjectId != 1){ + // Get parent folder ids + $query= "SELECT parent_folder_ids FROM folders WHERE id = {$iObjectId}"; + $aParentIds = DBUtil::getResultArrayKey($query, 'parent_folder_ids'); + $parentIds = $aParentIds[0]; + + // Get those users who have checked the subfolders option on the above folders + $query = "SELECT user_id FROM {$table} WHERE {$field} IN ({$parentIds}) AND with_subfolders = 1"; + $aSubUsers = DBUtil::getResultArrayKey($query, 'user_id'); + } + + $sQuery = "SELECT user_id FROM {$table} WHERE {$field} = ?"; $aParams = array($iObjectId); - $aNewUsers = DBUtil::getResultArrayKey(array($sQuery, $aParams), "user_id"); + $aNewUsers = DBUtil::getResultArrayKey(array($sQuery, $aParams), 'user_id'); + + // Add any users from parent folders + $aNewUsers = array_merge($aNewUsers, $aSubUsers); + $aNewUsers = array_unique($aNewUsers); // Remove alerted users $aNewUsers = $this->_pruneAlertedUsers($aNewUsers); diff --git a/plugins/ktstandard/KTSubscriptions.php b/plugins/ktstandard/KTSubscriptions.php index 585ab3b..262f43a 100644 --- a/plugins/ktstandard/KTSubscriptions.php +++ b/plugins/ktstandard/KTSubscriptions.php @@ -6,31 +6,31 @@ * Document Management Made Simple * Copyright (C) 2008 KnowledgeTree Inc. * Portions copyright The Jam Warehouse Software (Pty) Limited - * + * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3 as published by the * Free Software Foundation. - * + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . - * - * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, + * + * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, * California 94120-7775, or email info@knowledgetree.com. - * + * * The interactive user interfaces in modified source and object code versions * of this program must display Appropriate Legal Notices, as required under * Section 5 of the GNU General Public License version 3. - * + * * In accordance with Section 7(b) of the GNU General Public License version 3, * these Appropriate Legal Notices must retain the display of the "Powered by - * KnowledgeTree" logo and retain the original copyright notice. If the display of the + * KnowledgeTree" logo and retain the original copyright notice. If the display of the * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices - * must display the words "Powered by KnowledgeTree" and retain the original + * must display the words "Powered by KnowledgeTree" and retain the original * copyright notice. * Contributor( s): ______________________________________ * @@ -95,46 +95,94 @@ class KTSubscriptionPortlet extends KTPortlet { } function render() { - if (!$this->oDispatcher->oDocument && !$this->oDispatcher->oFolder) { + if ($this->oDispatcher->oUser->isAnonymous()) { return null; } - if ($this->oDispatcher->oUser->isAnonymous()) { + + if($this->oDispatcher->oDocument){ + $oObject = $this->oDispatcher->oDocument; + $type = 'documentsubscriptionaction'; + }else if($this->oDispatcher->oFolder){ + $oObject = $this->oDispatcher->oFolder; + $type = 'foldersubscriptionaction'; + }else{ + // not in a folder or document return null; } - if ($this->oDispatcher->oDocument) { - $oKTActionRegistry =& KTActionRegistry::getSingleton(); - $actions = $oKTActionRegistry->getActions('documentsubscriptionaction'); - foreach ($actions as $aAction) { - list($sClassName, $sPath) = $aAction; - if (!empty($sPath)) { - // require_once(KT_DIR . - // Or something... + + global $default; + $serverName = $default->serverName; + $base_url = ($default->sslEnabled ? 'https' : 'http') .'://'.$serverName; + $oUser = $this->oDispatcher->oUser; + $this->actions = array(); + + // Get the actions + $oKTActionRegistry =& KTActionRegistry::getSingleton(); + $actions = $oKTActionRegistry->getActions($type); + + foreach ($actions as $aAction){ + list($sClassName, $sPath) = $aAction; + $oSubscription = new $sClassName($oObject, $oUser); + $actionInfo = $oSubscription->getInfo(); + if(!empty($actionInfo)){ + if(isset($actionInfo['active']) && $actionInfo['active'] == 'no'){ + $nonActiveUrl = $base_url.$actionInfo['url']; + $nonActiveName = $actionInfo['name']; + }else { + $aInfo = $actionInfo; } - $oObject =new $sClassName($this->oDispatcher->oDocument, $this->oDispatcher->oUser); - $this->actions[] = $oObject->getInfo(); } } - if ($this->oDispatcher->oFolder) { - $oKTActionRegistry =& KTActionRegistry::getSingleton(); - $actions = $oKTActionRegistry->getActions('foldersubscriptionaction'); - foreach ($actions as $aAction) { - list($sClassName, $sPath) = $aAction; - if (!empty($sPath)) { - // require_once(KT_DIR . - // Or something... - } - $oObject =new $sClassName($this->oDispatcher->oFolder, $this->oDispatcher->oUser); - $this->actions[] = $oObject->getInfo(); + // Create js script + $url = $base_url.$aInfo['url']; + $script = ''; + + $script .= "{$aInfo['name']}"; + + $aInfo['js'] = $script; + $this->actions[] = $aInfo; + + if(isset($aInfo['subaction'])){ + $subInfo = array(); + $subInfo['js'] = "{$aInfo['subaction']}"; + +// $script .= "
    {$aInfo['subaction']}"; + $this->actions[] = $subInfo; } $this->actions[] = array("name" => _kt("Manage subscriptions"), "url" => $this->oPlugin->getPagePath('manage')); + $btn = ''; $oTemplating =& KTTemplating::getSingleton(); $oTemplate = $oTemplating->loadTemplate("kt3/portlets/actions_portlet"); $aTemplateData = array( - "context" => $this, + 'context' => $this, + 'btn' => $btn ); return $oTemplate->render($aTemplateData); } @@ -150,10 +198,27 @@ class KTDocumentSubscriptionAction extends KTDocumentAction { } function getInfo() { + $aInfo = parent::getInfo(); if (Subscription::exists($this->oUser->getID(), $this->oDocument->getID(), SubscriptionEvent::subTypes('Document'))) { - return null; + $aInfo['active'] = 'no'; + } + return $aInfo; + } + + function do_ajax() { + $iSubscriptionType = SubscriptionEvent::subTypes('Document'); + if (Subscription::exists($this->oUser->getId(), $this->oDocument->getId(), $iSubscriptionType)) { + echo _kt('You are already subscribed to that document'); + } else { + $oSubscription = new Subscription($this->oUser->getId(), $this->oDocument->getId(), $iSubscriptionType); + $res = $oSubscription->create(); + if ($res) { + echo _kt('You have been subscribed to this document'); + } else { + echo _kt('There was a problem subscribing you to this document'); + } } - return parent::getInfo(); + exit(0); } function do_main() { @@ -184,10 +249,27 @@ class KTDocumentUnsubscriptionAction extends KTDocumentAction { } function getInfo() { - if (Subscription::exists($this->oUser->getID(), $this->oDocument->getID(), SubscriptionEvent::subTypes('Document'))) { - return parent::getInfo(); + $aInfo = parent::getInfo(); + if (!Subscription::exists($this->oUser->getID(), $this->oDocument->getID(), SubscriptionEvent::subTypes('Document'))) { + $aInfo['active'] = 'no'; + } + return $aInfo; + } + + function do_ajax() { + $iSubscriptionType = SubscriptionEvent::subTypes('Document'); + if (!Subscription::exists($this->oUser->getId(), $this->oDocument->getId(), $iSubscriptionType)) { + echo _kt('You are not subscribed to this document'); + } else { + $oSubscription = new Subscription($this->oUser->getId(), $this->oDocument->getId(), $iSubscriptionType); + $res = $oSubscription->create(); + if ($res) { + echo _kt('You have been unsubscribed from this document'); + } else { + echo _kt('There was a problem unsubscribing you from this document'); + } } - return null; + exit(0); } function do_main() { @@ -342,17 +424,53 @@ class KTFolderSubscriptionAction extends KTFolderAction { } function getInfo() { + $aInfo = parent::getInfo(); if (Subscription::exists($this->oUser->getID(), $this->oFolder->getID(), SubscriptionEvent::subTypes('Folder'))) { // KTFolderUnsubscriptionAction will display instead. - return null; + $aInfo['active'] = 'no'; + } + // return the url to the action for subfolders - display the Subscribe link, on clicking, display the include subfolders link. + $aInfo['subaction'] = _kt('Subscribe to folder and subfolders'); + return $aInfo; + } + + function do_ajax() { + $this->subscribe(); + } + + function do_add_subfolders() { + $this->subscribe(true); + } + + function subscribe($incSubFolders = false) { + $iSubscriptionType = SubscriptionEvent::subTypes('Folder'); + if (Subscription::exists($this->oUser->getId(), $this->oFolder->getId(), $iSubscriptionType)) { + echo _kt('You are already subscribed to this folder'); + } else { + $oSubscription = new Subscription($this->oUser->getId(), $this->oFolder->getId(), $iSubscriptionType); + + if($incSubFolders){ + $oSubscription->setWithSubFolders(true); + } + + $res = $oSubscription->create(); + if ($res) { + if($incSubFolders){ + echo _kt('You have been subscribed to this folder and its subfolders'); + }else{ + echo _kt('You have been subscribed to this folder'); + } + } else { + echo _kt('There was a problem subscribing you to this folder'); + } } - return parent::getInfo(); + exit(0); } function do_main() { $iSubscriptionType = SubscriptionEvent::subTypes('Folder'); if (Subscription::exists($this->oUser->getId(), $this->oFolder->getId(), $iSubscriptionType)) { - $_SESSION['KTErrorMessage'][] = _kt("You are already subscribed to that folder"); + $_SESSION['KTErrorMessage'][] = _kt("You are already subscribed to this folder"); } else { $oSubscription = new Subscription($this->oUser->getId(), $this->oFolder->getId(), $iSubscriptionType); $res = $oSubscription->create(); @@ -377,10 +495,27 @@ class KTFolderUnsubscriptionAction extends KTFolderAction { } function getInfo() { - if (Subscription::exists($this->oUser->getID(), $this->oFolder->getID(), SubscriptionEvent::subTypes('Folder'))) { - return parent::getInfo(); + $aInfo = parent::getInfo(); + if (!Subscription::exists($this->oUser->getID(), $this->oFolder->getID(), SubscriptionEvent::subTypes('Folder'))) { + $aInfo['active'] = 'no'; } - return null; + return $aInfo; + } + + function do_ajax() { + $iSubscriptionType = SubscriptionEvent::subTypes('Folder'); + if (!Subscription::exists($this->oUser->getId(), $this->oFolder->getId(), $iSubscriptionType)) { + echo _kt('You were not subscribed to that folder'); + } else { + $oSubscription = & Subscription::getByIDs($this->oUser->getId(), $this->oFolder->getId(), $iSubscriptionType); + $res = $oSubscription->delete(); + if ($res) { + echo _kt('You have been unsubscribed from this folder'); + } else { + echo _kt('There was a problem unsubscribing you from this folder'); + } + } + exit(0); } function do_main() { diff --git a/sql/mysql/install/structure.sql b/sql/mysql/install/structure.sql index 5485cee..0a45f0e 100644 --- a/sql/mysql/install/structure.sql +++ b/sql/mysql/install/structure.sql @@ -511,7 +511,7 @@ CREATE TABLE `document_transaction_types_lookup` ( CREATE TABLE `document_transactions` ( `id` int(11) NOT NULL auto_increment, `document_id` int(11) default NULL, - `version` float default NULL, + `version` varchar(10), `user_id` int(11) default NULL, `datetime` datetime NOT NULL default '0000-00-00 00:00:00', `ip` varchar(15) default NULL, @@ -775,6 +775,7 @@ CREATE TABLE `folder_subscriptions` ( `user_id` int(11) NOT NULL default '0', `folder_id` int(11) NOT NULL default '0', `is_alerted` tinyint(1) default NULL, + `with_subfolders` tinyint(1) NOT NULL default '0', PRIMARY KEY (`id`), KEY `user_id` (`user_id`), KEY `folder_id` (`folder_id`), diff --git a/sql/mysql/upgrade/3.5.3/subscriptions.sql b/sql/mysql/upgrade/3.5.3/subscriptions.sql new file mode 100644 index 0000000..d006677 --- /dev/null +++ b/sql/mysql/upgrade/3.5.3/subscriptions.sql @@ -0,0 +1 @@ +ALTER TABLE folder_subscriptions ADD COLUMN with_subfolders TINYINT(1) NOT NULL default 0; \ No newline at end of file diff --git a/templates/kt3/portlets/actions_portlet.smarty b/templates/kt3/portlets/actions_portlet.smarty index 5e116b0..d75beae 100644 --- a/templates/kt3/portlets/actions_portlet.smarty +++ b/templates/kt3/portlets/actions_portlet.smarty @@ -1,21 +1,22 @@ {if $btn} -
{$btn}
+
{$btn}
{/if}
    -{foreach item=action from=$context->actions } -{if $action != null} -
  • -{if $action.js} - {$action.js} -{else} -{if ($action.url)} - - {$action.name} - -{else} - {$action.name} -{/if}
  • -{/if} -{/if} -{/foreach} -
+ {foreach item=action from=$context->actions } + {if $action != null} +
  • + {if $action.js} + {$action.js} + {else} + {if ($action.url)} + + {$action.name} + + {else} + {$action.name} + {/if} + {/if} +
  • + {/if} + {/foreach} + \ No newline at end of file -- libgit2 0.21.4