Commit 1a5a55e0835448e50595bbc8b2f8844f70d73e2a
1 parent
b6140065
added multiple unsubscribe functionality
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@1198 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
2 changed files
with
135 additions
and
20 deletions
presentation/lookAndFeel/knowledgeTree/subscriptions/manageSubscriptionsBL.php
| @@ -25,11 +25,56 @@ require_once("$default->fileSystemRoot/lib/subscriptions/SubscriptionManager.inc | @@ -25,11 +25,56 @@ require_once("$default->fileSystemRoot/lib/subscriptions/SubscriptionManager.inc | ||
| 25 | if (checkSession()) { | 25 | if (checkSession()) { |
| 26 | 26 | ||
| 27 | require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCustom.inc"); | 27 | require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCustom.inc"); |
| 28 | + require_once("$default->fileSystemRoot/lib/subscriptions/Subscription.inc"); | ||
| 28 | require_once("subscriptionUI.inc"); | 29 | require_once("subscriptionUI.inc"); |
| 30 | + $oPatternCustom = & new PatternCustom(); | ||
| 29 | 31 | ||
| 32 | + if (isset($fFolderSubscriptionIDs) || isset($fDocumentSubscriptionIDs)) { | ||
| 33 | + // we've got subscriptions to remove, | ||
| 34 | + $aFolderSubscriptions = array(); | ||
| 35 | + $aDocumentSubscriptions = array(); | ||
| 36 | + | ||
| 37 | + for ($i = 0; $i < count($fFolderSubscriptionIDs); $i++) { | ||
| 38 | + $aFolderSubscriptions[] = & Subscription::get($fFolderSubscriptionIDs[$i], SubscriptionConstants::subscriptionType("FolderSubscription")); | ||
| 39 | + } | ||
| 40 | + for ($i = 0; $i < count($fDocumentSubscriptionIDs); $i++) { | ||
| 41 | + $aDocumentSubscriptions[] = & Subscription::get($fDocumentSubscriptionIDs[$i], SubscriptionConstants::subscriptionType("DocumentSubscription")); | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + if (isset($fConfirmed)) { | ||
| 45 | + // remove subscriptions | ||
| 46 | + $oSubscriptions = array_merge($aFolderSubscriptions, $aDocumentSubscriptions); | ||
| 47 | + | ||
| 48 | + $sErrorMessage = ""; | ||
| 49 | + for ($i = 0; $i < count($oSubscriptions); $i++) { | ||
| 50 | + if ($oSubscriptions[$i]->delete()) { | ||
| 51 | + $default->log->info("manageSubscriptionBL.php removed subscription for userID=$iUserID, subType=$iSubscriptionType, id=$iExternalID"); | ||
| 52 | + } else { | ||
| 53 | + // error removing subscription | ||
| 54 | + $default->log->error("manageSubscriptionBL.php error removing subscription=" . $oSubscriptions[$i]); | ||
| 55 | + // add to error message | ||
| 56 | + if (strlen($sErrorMessage) > 0) { | ||
| 57 | + $sErrorMessage .= ", "; | ||
| 58 | + } | ||
| 59 | + $sErrorMessage .= $oSubscriptions[$i]->getContentDisplayPath(); | ||
| 60 | + } | ||
| 61 | + } | ||
| 62 | + if (strlen($sErrorMessage) > 0) { | ||
| 63 | + $oPatternCustom->setHtml(renderErrorPage("There were errors removing the following subscriptions: $sErrorMessage")); | ||
| 64 | + } else { | ||
| 65 | + // display the manage subscriptions page | ||
| 66 | + $oPatternCustom->setHtml(renderManagePage()); | ||
| 67 | + } | ||
| 68 | + } else { | ||
| 69 | + // display confirmation page | ||
| 70 | + $oPatternCustom->setHtml(renderMultipleRemoveConfirmationPage($aFolderSubscriptions, $aDocumentSubscriptions)); | ||
| 71 | + } | ||
| 72 | + } else { | ||
| 73 | + // display the manage subscriptions page | ||
| 74 | + $oPatternCustom->setHtml(renderManagePage()); | ||
| 75 | + } | ||
| 76 | + | ||
| 30 | require_once("../../../webpageTemplate.inc"); | 77 | require_once("../../../webpageTemplate.inc"); |
| 31 | - $oPatternCustom = & new PatternCustom(); | ||
| 32 | - $oPatternCustom->setHtml(renderManageSubscriptions()); | ||
| 33 | $main->setCentralPayload($oPatternCustom); | 78 | $main->setCentralPayload($oPatternCustom); |
| 34 | $main->setFormAction($_SERVER["PHP_SELF"]); | 79 | $main->setFormAction($_SERVER["PHP_SELF"]); |
| 35 | $main->render(); | 80 | $main->render(); |
presentation/lookAndFeel/knowledgeTree/subscriptions/subscriptionUI.inc
| @@ -11,38 +11,108 @@ | @@ -11,38 +11,108 @@ | ||
| 11 | * @author Michael Joseph <michael@jamwarehouse.com>, Jam Warehouse (Pty) Ltd, South Africa | 11 | * @author Michael Joseph <michael@jamwarehouse.com>, Jam Warehouse (Pty) Ltd, South Africa |
| 12 | * @package presentation.lookAndFeel.knowledgeTree.subscriptions | 12 | * @package presentation.lookAndFeel.knowledgeTree.subscriptions |
| 13 | */ | 13 | */ |
| 14 | - | ||
| 15 | 14 | ||
| 16 | /** | 15 | /** |
| 17 | * Displays all current subscriptions with remove checkbox | 16 | * Displays all current subscriptions with remove checkbox |
| 18 | */ | 17 | */ |
| 19 | -function renderManageSubscriptions() { | 18 | +function renderManagePage() { |
| 20 | global $default; | 19 | global $default; |
| 21 | 20 | ||
| 22 | // retrieve subscriptions for this user | 21 | // retrieve subscriptions for this user |
| 23 | - $aSubscriptionList = SubscriptionManager::listSubscriptions($_SESSION["userID"]); | ||
| 24 | - | 22 | + $aFolderSubscriptions = SubscriptionManager::retrieveSubscriptions($_SESSION["userID"], SubscriptionConstants::subscriptionType("FolderSubscription")); |
| 23 | + $aDocumentSubscriptions = SubscriptionManager::retrieveSubscriptions($_SESSION["userID"], SubscriptionConstants::subscriptionType("DocumentSubscription")); | ||
| 24 | + $bNoSubscriptions = ( (count($aFolderSubscriptions) == 0) && (count($aFolderSubscriptions) == 0) ) ? true : false; | ||
| 25 | + | ||
| 25 | $sToRender = "<table>\n"; | 26 | $sToRender = "<table>\n"; |
| 27 | + if ($bNoSubscriptions) { | ||
| 28 | + $sToRender .= "<tr><td>You are not subscribed to any documents or folders.</td></tr>\n"; | ||
| 29 | + } else { | ||
| 30 | + $sToRender .= "<tr><td>The documents and folders you're subscribed to are listed below.</td></tr>\n"; | ||
| 31 | + $sToRender .= "<tr><td>Select the subscriptions you'd like to unsubscribe from, and click 'Unsubscribe'</td></tr>\n"; | ||
| 32 | + } | ||
| 33 | + $sToRender .= "<tr/>\n"; | ||
| 34 | + $sToRender .= "<tr/>\n"; | ||
| 35 | + | ||
| 26 | // loop through them | 36 | // loop through them |
| 27 | - for ($i = 0; $i < count($aSubscriptionList); $i++) { | 37 | + for ($i = 0; $i < count($aFolderSubscriptions); $i++) { |
| 38 | + $sToRender .= "\t<tr>\n"; | ||
| 39 | + $sToRender .= "\t\t<td>\n"; | ||
| 40 | + $sToRender .= "<input type=\"checkbox\" name=\"fFolderSubscriptionIDs[]\" value=\"" . $aFolderSubscriptions[$i]->getID() . "\"/>\n"; | ||
| 41 | + if ($aFolderSubscriptions[$i]->getIsAlerted()) { | ||
| 42 | + $sToRender .= $aFolderSubscriptions[$i]->getAlertLink() . "\n"; | ||
| 43 | + } else { | ||
| 44 | + $sToRender .= $aFolderSubscriptions[$i]->getContentLink() . "\n"; | ||
| 45 | + } | ||
| 46 | + $sToRender .= "\t\t</td>\n"; | ||
| 47 | + $sToRender .= "\t</tr>\n"; | ||
| 48 | + } | ||
| 49 | + for ($i = 0; $i < count($aDocumentSubscriptions); $i++) { | ||
| 28 | $sToRender .= "\t<tr>\n"; | 50 | $sToRender .= "\t<tr>\n"; |
| 29 | $sToRender .= "\t\t<td>\n"; | 51 | $sToRender .= "\t\t<td>\n"; |
| 30 | - $sToRender .= "<input type=\"checkbox\" name=\"fSubscriptionID\" value=\"" . $aSubscriptionList[$i]->getID() . "\"/>\n"; | ||
| 31 | - if ($aSubscriptionList[$i]->getIsAlerted()) { | ||
| 32 | - $sToRender .= $aSubscriptionList[$i]->getAlertLink() . "\n"; | 52 | + $sToRender .= "<input type=\"checkbox\" name=\"fDocumentSubscriptionIDs[]\" value=\"" . $aDocumentSubscriptions[$i]->getID() . "\"/>\n"; |
| 53 | + if ($aDocumentSubscriptions[$i]->getIsAlerted()) { | ||
| 54 | + $sToRender .= $aDocumentSubscriptions[$i]->getAlertLink() . "\n"; | ||
| 33 | } else { | 55 | } else { |
| 34 | - $sToRender .= $aSubscriptionList[$i]->getContentLink() . "\n"; | 56 | + $sToRender .= $aDocumentSubscriptions[$i]->getContentLink() . "\n"; |
| 35 | } | 57 | } |
| 36 | $sToRender .= "\t\t</td>\n"; | 58 | $sToRender .= "\t\t</td>\n"; |
| 37 | $sToRender .= "\t</tr>\n"; | 59 | $sToRender .= "\t</tr>\n"; |
| 60 | + } | ||
| 61 | + | ||
| 62 | + $sToRender .= "<tr/>\n"; | ||
| 63 | + $sToRender .= "<tr/>\n"; | ||
| 64 | + $sToRender .= "<tr><td>"; | ||
| 65 | + if (!$bNoSubscriptions) { | ||
| 66 | + $sToRender .= "<input type=\"image\" src=\"$default->graphicsUrl/widgets/unsubscribe.gif\"/></a>\n"; | ||
| 38 | } | 67 | } |
| 68 | + $sToRender .= "<a href=\"javascript:history.go(-1)\"><img src=\"$default->graphicsUrl/widgets/cancel.gif\" border=\"0\"></a>\n"; | ||
| 69 | + $sToRender .= "</td></tr>\n"; | ||
| 70 | + $sToRender .= "</table>\n"; | ||
| 71 | + | ||
| 72 | + return $sToRender; | ||
| 73 | +} | ||
| 39 | 74 | ||
| 40 | - $sToRender .= "<tr><td><a href=\"$default->rootUrl/control.php?action=removeSubscription&$sContentUrl&fConfirmed=1\"><img src =\"$default->graphicsUrl/widgets/unsubscribe.gif\" border=\"0\"/></a>\n"; | ||
| 41 | - $sToRender .= "<a href=\"\"><img src=\"$default->graphicsUrl/widgets/cancel.gif\" border=\"0\"></a></td>\n"; | ||
| 42 | - $sToRender .= "</tr>\n"; | 75 | +/** |
| 76 | + * Asks for confirmation for removing multiple subscriptions | ||
| 77 | + * | ||
| 78 | + * @param array subscriptions to remove | ||
| 79 | + */ | ||
| 80 | +function renderMultipleRemoveConfirmationPage($aFolderSubscriptions, $aDocumentSubscriptions) { | ||
| 81 | + global $default; | ||
| 82 | + | ||
| 83 | + $sToRender = "<table>\n"; | ||
| 84 | + $sToRender .= "<tr><td>You have chosen to delete the following subscription(s):</td></tr>\n"; | ||
| 85 | + $sToRender .= "<tr/>\n"; | ||
| 86 | + $sToRender .= "<tr/>\n"; | ||
| 87 | + | ||
| 88 | + // loop through them | ||
| 89 | + for ($i = 0; $i < count($aFolderSubscriptions); $i++) { | ||
| 90 | + $sToRender .= "\t<tr>\n"; | ||
| 91 | + $sToRender .= "\t\t<td>\n"; | ||
| 92 | + $sToRender .= $aFolderSubscriptions[$i]->getContentDisplayPath() . "\n"; | ||
| 93 | + $sToRender .= "\t\t</td>\n"; | ||
| 94 | + $sToRender .= "\t</tr>\n"; | ||
| 95 | + $sToRender .= "<input type=\"hidden\" name=\"fFolderSubscriptionIDs[]\" value=\"" . $aFolderSubscriptions[$i]->getID() . "\"/>"; | ||
| 96 | + } | ||
| 97 | + | ||
| 98 | + for ($i = 0; $i < count($aDocumentSubscriptions); $i++) { | ||
| 99 | + $sToRender .= "\t<tr>\n"; | ||
| 100 | + $sToRender .= "\t\t<td>\n"; | ||
| 101 | + $sToRender .= $aDocumentSubscriptions[$i]->getContentDisplayPath() . "\n"; | ||
| 102 | + $sToRender .= "\t\t</td>\n"; | ||
| 103 | + $sToRender .= "\t</tr>\n"; | ||
| 104 | + $sToRender .= "<input type=\"hidden\" name=\"fDocumentSubscriptionIDs[]\" value=\"" . $aDocumentSubscriptions[$i]->getID() . "\"/>"; | ||
| 105 | + } | ||
| 43 | 106 | ||
| 44 | - //$sToRender .= "<tr><td><a href=\"$default->rootUrl/control.php?action=removeSubscription&fRemoveMultiple=1\"><img src=\"$default->graphicsUrl/widgets/unsubscribe.gif\" border=\"0\"/></a></td></tr>\n"; | ||
| 45 | - //$sToRender .= "<a href=\"" . $oSubscription->getContentUrl() . "\"><img src=\"$default->graphicsUrl/widgets/cancel.gif\" border=\"0\"></a></td>\n"; | 107 | + $sToRender .= "<tr/>\n"; |
| 108 | + $sToRender .= "<tr/>\n"; | ||
| 109 | + $sToRender .= "<td>Select 'Unsubscribe' to confirm the deletion(s), or 'Cancel' to cancel them</td>\n"; | ||
| 110 | + $sToRender .= "<tr/>\n"; | ||
| 111 | + $sToRender .= "<tr/>\n"; | ||
| 112 | + $sToRender .= "<input type=\"hidden\" name=\"fConfirmed\" value=\"1\"/>"; | ||
| 113 | + $sToRender .= "<tr><td><input type=\"image\" src=\"$default->graphicsUrl/widgets/unsubscribe.gif\"/></a>\n"; | ||
| 114 | + $sToRender .= "<a href=\"javascript:history.go(-1)\"><img src=\"$default->graphicsUrl/widgets/cancel.gif\" border=\"0\"></a></td>\n"; | ||
| 115 | + $sToRender .= "</tr>\n"; | ||
| 46 | $sToRender .= "</table>\n"; | 116 | $sToRender .= "</table>\n"; |
| 47 | 117 | ||
| 48 | return $sToRender; | 118 | return $sToRender; |
| @@ -53,7 +123,7 @@ function renderManageSubscriptions() { | @@ -53,7 +123,7 @@ function renderManageSubscriptions() { | ||
| 53 | * | 123 | * |
| 54 | * @param object the subscription | 124 | * @param object the subscription |
| 55 | */ | 125 | */ |
| 56 | -function renderSubscriptionRemoveConfirmationPage($oSubscription) { | 126 | +function renderRemoveConfirmationPage($oSubscription) { |
| 57 | global $default; | 127 | global $default; |
| 58 | 128 | ||
| 59 | $sContentType = $oSubscription->getSubscriptionTypeName(); | 129 | $sContentType = $oSubscription->getSubscriptionTypeName(); |
| @@ -66,7 +136,7 @@ function renderSubscriptionRemoveConfirmationPage($oSubscription) { | @@ -66,7 +136,7 @@ function renderSubscriptionRemoveConfirmationPage($oSubscription) { | ||
| 66 | } | 136 | } |
| 67 | 137 | ||
| 68 | $sToRender = "<table>\n"; | 138 | $sToRender = "<table>\n"; |
| 69 | - $sToRender .= "<td>You have chosen to delete the your $sContentType subscription to '$sContentName'.</td>\n"; | 139 | + $sToRender .= "<tr><td>You have chosen to delete the your $sContentType subscription to '$sContentName'.</td></tr>\n"; |
| 70 | $sToRender .= "<tr/>\n"; | 140 | $sToRender .= "<tr/>\n"; |
| 71 | $sToRender .= "<tr/>\n"; | 141 | $sToRender .= "<tr/>\n"; |
| 72 | $sToRender .= "<td>Select 'Unsubscribe' to confirm the deletion, or 'Cancel' to cancel it</td>\n"; | 142 | $sToRender .= "<td>Select 'Unsubscribe' to confirm the deletion, or 'Cancel' to cancel it</td>\n"; |
| @@ -85,7 +155,7 @@ function renderSubscriptionRemoveConfirmationPage($oSubscription) { | @@ -85,7 +155,7 @@ function renderSubscriptionRemoveConfirmationPage($oSubscription) { | ||
| 85 | * | 155 | * |
| 86 | * @param object the subscription | 156 | * @param object the subscription |
| 87 | */ | 157 | */ |
| 88 | -function renderSubscriptionAddConfirmationPage($oSubscription) { | 158 | +function renderAddConfirmationPage($oSubscription) { |
| 89 | global $default; | 159 | global $default; |
| 90 | 160 | ||
| 91 | $sContentType = $oSubscription->getSubscriptionTypeName(); | 161 | $sContentType = $oSubscription->getSubscriptionTypeName(); |
| @@ -98,7 +168,7 @@ function renderSubscriptionAddConfirmationPage($oSubscription) { | @@ -98,7 +168,7 @@ function renderSubscriptionAddConfirmationPage($oSubscription) { | ||
| 98 | } | 168 | } |
| 99 | 169 | ||
| 100 | $sToRender = "<table>\n"; | 170 | $sToRender = "<table>\n"; |
| 101 | - $sToRender .= "<td>You have chosen to subscribe to the $sContentType entitled '$sContentName'.</td>\n"; | 171 | + $sToRender .= "<tr><td>You have chosen to subscribe to the $sContentType entitled '$sContentName'.</td></tr>\n"; |
| 102 | $sToRender .= "<tr/>\n"; | 172 | $sToRender .= "<tr/>\n"; |
| 103 | $sToRender .= "<tr>\n"; | 173 | $sToRender .= "<tr>\n"; |
| 104 | $sToRender .= "<td>Select 'Subscribe' to confirm the subscription, or 'Cancel' to cancel it</td>\n"; | 174 | $sToRender .= "<td>Select 'Subscribe' to confirm the subscription, or 'Cancel' to cancel it</td>\n"; |