Commit 23f4e3e7fa5ff08b7b8b7278534935fa1d941d63
1 parent
ff9e8987
Initial revision. Moved all static document collaboration functionality
from Document.inc to this file git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@1755 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
318 additions
and
0 deletions
lib/documentmanagement/DocumentCollaboration.inc
0 → 100644
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | + * | ||
| 4 | + * Static functions dealing with the document approval process | ||
| 5 | + * | ||
| 6 | + * @author Rob Cherry, Jam Warehouse (Pty) Ltd, South Africa | ||
| 7 | + * @package lib.documentmanagement | ||
| 8 | + */ | ||
| 9 | + | ||
| 10 | +class DocumentCollaboration { | ||
| 11 | + | ||
| 12 | + /** | ||
| 13 | + * Checks if the collaboration process for the document | ||
| 14 | + * is started yet | ||
| 15 | + * | ||
| 16 | + */ | ||
| 17 | + function documentCollaborationStarted($iDocumentID) { | ||
| 18 | + global $default; | ||
| 19 | + $sql = $default->db; | ||
| 20 | + $sql->query("SELECT id FROM $default->owl_folders_user_roles_table WHERE document_id = $iDocumentID AND (active = 1 OR done = 1)"); | ||
| 21 | + if ($sql->next_record()) { | ||
| 22 | + return true; | ||
| 23 | + } | ||
| 24 | + return false; | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + function documentCollaborationDone($iDocumentID) { | ||
| 28 | + global $default; | ||
| 29 | + $sql = $default->db; | ||
| 30 | + $sql->query("SELECT id FROM $default->owl_folders_user_roles_table WHERE document_id = $iDocumentID AND done = 0"); | ||
| 31 | + if ($sql->num_rows() > 0) { | ||
| 32 | + return false; | ||
| 33 | + } else { | ||
| 34 | + return true; | ||
| 35 | + } | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + /** | ||
| 39 | + * Checks if the current user has an active role in the document | ||
| 40 | + * collaboration process | ||
| 41 | + * | ||
| 42 | + */ | ||
| 43 | + function userIsPerformingCurrentCollaborationStep($iDocumentID) { | ||
| 44 | + global $default; | ||
| 45 | + $sql = $default->db; | ||
| 46 | + $sql->query("SELECT id FROM $default->owl_folders_user_roles_table WHERE document_id = $iDocumentID AND active = 1 AND user_id = " . $_SESSION["userID"]); | ||
| 47 | + if ($sql->next_record()) { | ||
| 48 | + return true; | ||
| 49 | + } | ||
| 50 | + return false; | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + | ||
| 54 | + /** | ||
| 55 | + * Reset the entire document collaboration process by setting all roles | ||
| 56 | + * to inactive and undone | ||
| 57 | + * | ||
| 58 | + */ | ||
| 59 | + function resetDocumentCollaborationSteps($iDocumentID) { | ||
| 60 | + global $default; | ||
| 61 | + $sql = $default->db; | ||
| 62 | + if ($sql->query("UPDATE $default->owl_folders_user_roles_table SET active = 0, done = 0 WHERE document_id = $iDocumentID")) { | ||
| 63 | + return true; | ||
| 64 | + } | ||
| 65 | + return false; | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + /** | ||
| 69 | + * Checks if a there are any more steps to be be performed in | ||
| 70 | + * the current document collaboration process | ||
| 71 | + * | ||
| 72 | + */ | ||
| 73 | + function isLastStepInCollaborationProcess($iDocumentID) { | ||
| 74 | + global $default; | ||
| 75 | + $sql = $default->db; | ||
| 76 | + $sQuery = "SELECT id FROM $default->owl_folders_user_roles_table WHERE document_id = $iDocumentID AND done = 0"; | ||
| 77 | + $sql->query($sQuery); | ||
| 78 | + $default->log->info("lastCollabStep:$sQuery"); | ||
| 79 | + if ($sql->num_rows() > 1) { | ||
| 80 | + return false; | ||
| 81 | + } else { | ||
| 82 | + return true; | ||
| 83 | + } | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + /** | ||
| 87 | + * Returns the userID of the last user in the collaboration process | ||
| 88 | + */ | ||
| 89 | + function getLastCollaboratorID($iDocumentID) { | ||
| 90 | + | ||
| 91 | + global $default; | ||
| 92 | + $sql = $default->db; | ||
| 93 | + // returns all users, the sequence of their collaboration and the time of completion | ||
| 94 | + $sQuery = "SELECT FURL.user_id, FURL.datetime, GFAL.precedence FROM $default->owl_folders_user_roles_table FURL " . | ||
| 95 | + "INNER JOIN $default->owl_groups_folders_approval_table GFAL ON FURL.group_folder_approval_id = GFAL.id " . | ||
| 96 | + "WHERE FURL.document_id = $iDocumentID " . | ||
| 97 | + "ORDER BY GFAL.precedence"; | ||
| 98 | + $sql->query($sQuery); | ||
| 99 | + $iPrecedence = -1; | ||
| 100 | + $iDateTime = 0; | ||
| 101 | + $iUserID = -1; | ||
| 102 | + while ($sql->next_record()) { | ||
| 103 | + if ($sql->f("precedence") >= $iPrecedence) { | ||
| 104 | + $iPrecedence = $sql->f("precedence"); | ||
| 105 | + $iDateCompleted = strtotime($sql->f("datetime")); | ||
| 106 | + if ($iDateCompleted > $iDateTime) { | ||
| 107 | + $iDateTime = $iDateCompleted; | ||
| 108 | + $iUserID = $sql->f("user_id"); | ||
| 109 | + } | ||
| 110 | + } | ||
| 111 | + } | ||
| 112 | + return ($iUserID == -1) ? false : $iUserID; | ||
| 113 | + } | ||
| 114 | + | ||
| 115 | + /** | ||
| 116 | + * Begins the next step(s) in the document | ||
| 117 | + * collaboration process | ||
| 118 | + * | ||
| 119 | + */ | ||
| 120 | + function beginNextStepInCollaborationProcess($iDocumentID, $iUserID) { | ||
| 121 | + global $default; | ||
| 122 | + $sql = $default->db; | ||
| 123 | + //get the current step | ||
| 124 | + //if the user is assinged to two or more roles, make sure we get the current | ||
| 125 | + //one by ordering by precedence | ||
| 126 | + $sql->query("SELECT FURL.id AS id, GFAT.precedence " . | ||
| 127 | + "FROM $default->owl_groups_folders_approval_table AS GFAT INNER JOIN $default->owl_folders_user_roles_table AS FURL ON GFAT.id = FURL.group_folder_approval_id " . | ||
| 128 | + "WHERE document_id = $iDocumentID AND user_id = " . $_SESSION["userID"] . " AND done=0 " . | ||
| 129 | + "ORDER BY precedence ASC"); | ||
| 130 | + if ($sql->next_record()) { | ||
| 131 | + //set it as done | ||
| 132 | + $oFolderUserRole = FolderUserRole::get($sql->f("id")); | ||
| 133 | + $oFolderUserRole->setActive(false); | ||
| 134 | + $oFolderUserRole->setDone(true); | ||
| 135 | + $oFolderUserRole->setDateTime(getCurrentDateTime()); | ||
| 136 | + $oFolderUserRole->update(); | ||
| 137 | + //get it's sequence number | ||
| 138 | + $iCurrentSequenceNumber = $sql->f("precedence"); | ||
| 139 | + $sql->query("SELECT MIN(precedence) AS precedence " . | ||
| 140 | + "FROM $default->owl_groups_folders_approval_table AS GFAT INNER JOIN $default->owl_folders_user_roles_table AS FURL ON GFAT.id = FURL.group_folder_approval_id " . | ||
| 141 | + "WHERE document_id = $iDocumentID AND done = 0"); | ||
| 142 | + if ($sql->next_record()) { | ||
| 143 | + if ($sql->f("precedence") != $iCurrentSequenceNumber) { | ||
| 144 | + //if there are no concurrent steps outstanding | ||
| 145 | + $iNextSequenceNumber = $sql->f("precedence"); | ||
| 146 | + $sql->query("SELECT FURL.id " . | ||
| 147 | + "FROM $default->owl_groups_folders_approval_table AS GFAT INNER JOIN $default->owl_folders_user_roles_table AS FURL ON GFAT.id = FURL.group_folder_approval_id " . | ||
| 148 | + "WHERE document_id = $iDocumentID AND precedence = $iNextSequenceNumber"); | ||
| 149 | + while ($sql->next_record()) { | ||
| 150 | + $oFolderUserRole = FolderUserRole::get($sql->f("id")); | ||
| 151 | + $oFolderUserRole->setActive(true); | ||
| 152 | + $oFolderUserRole->update(); | ||
| 153 | + $oFolderCollaboration = FolderCollaboration::get($oFolderUserRole->getGroupFolderApprovalID()); | ||
| 154 | + //get the role the user must perform | ||
| 155 | + $oRole = Role::get($oFolderCollaboration->getRoleID()); | ||
| 156 | + //get the user to email | ||
| 157 | + $oUser = User::get($oFolderUserRole->getUserID()); | ||
| 158 | + if ($oUser->getEmailNotification()) { | ||
| 159 | + $oDocument = & Document::get($iDocumentID); | ||
| 160 | + $sBody = $oUser->getName() . ", your role of '" . $oRole->getName() . "' in the document, '" . $oDocument->getName() . "' collaboration process is now active. " . | ||
| 161 | + "Click " . generateLink("/presentation/lookAndFeel/knowledgeTree/documentmanagement/viewBL.php", "fDocumentID=$iDocumentID", "here") . " to access " . | ||
| 162 | + "the document"; | ||
| 163 | + | ||
| 164 | + $oEmail = & new Email(); | ||
| 165 | + $oEmail->send($oUser->getEmail(), "Document collaboration role active", $sBody); | ||
| 166 | + } | ||
| 167 | + } | ||
| 168 | + return true; | ||
| 169 | + } | ||
| 170 | + return false; | ||
| 171 | + } | ||
| 172 | + return false; | ||
| 173 | + } | ||
| 174 | + return false; | ||
| 175 | + } | ||
| 176 | + | ||
| 177 | + /** | ||
| 178 | + * Rolls back a collaboration step if it is | ||
| 179 | + * rejected by the user. This is a problem function as | ||
| 180 | + * it really should have transactions, but doesn't | ||
| 181 | + * | ||
| 182 | + */ | ||
| 183 | + function rollbackCollaborationStep($iDocumentID, $sComment = "") { | ||
| 184 | + global $default; | ||
| 185 | + //get the current sequence number | ||
| 186 | + $sQuery = "SELECT GFAT.precedence, GFAT.folder_id, FURL.id AS furl_id " . | ||
| 187 | + "FROM $default->owl_folders_user_roles_table AS FURL INNER JOIN $default->owl_groups_folders_approval_table AS GFAT ON FURL.group_folder_approval_id = GFAT.id " . | ||
| 188 | + "WHERE FURL.document_id = $iDocumentID " . | ||
| 189 | + "AND user_id = " . $_SESSION["userID"] . " " . | ||
| 190 | + "AND FURL.active = 1 " . | ||
| 191 | + "ORDER BY GFAT.precedence ASC"; | ||
| 192 | + | ||
| 193 | + //echo $sQuery; | ||
| 194 | + | ||
| 195 | + | ||
| 196 | + | ||
| 197 | + $sql = $default->db; | ||
| 198 | + $sql->query($sQuery); | ||
| 199 | + if ($sql->next_record()) { | ||
| 200 | + $iCurrentSequenceNumber = $sql->f("precedence"); | ||
| 201 | + $iFolderID = $sql->f("folder_id"); | ||
| 202 | + $iCurrentFolderUserRoleID = $sql->f("furl_id"); | ||
| 203 | + | ||
| 204 | + //get the previous sequence number | ||
| 205 | + $sQuery = "SELECT COALESCE(MAX(precedence), -1) AS precedence " . | ||
| 206 | + "FROM $default->owl_groups_folders_approval_table AS GFAT " . | ||
| 207 | + "WHERE precedence < $iCurrentSequenceNumber"; | ||
| 208 | + "AND folder_id = $iFolderID"; | ||
| 209 | + $sql->query($sQuery); | ||
| 210 | + //there will always be a result in the result set | ||
| 211 | + $sql->next_record(); | ||
| 212 | + if ($sql->f("precedence") == -1) { | ||
| 213 | + //the current step is the first step | ||
| 214 | + //reset all steps and email the creator | ||
| 215 | + DocumentCollaboration::resetDocumentCollaborationSteps($iDocumentID); | ||
| 216 | + $oDocument = Document::get($iDocumentID); | ||
| 217 | + $oUser = User::get($oDocument->getCreatorID()); | ||
| 218 | + if ($oUser->getEmailNotification()) { | ||
| 219 | + $oCurrentUser = User::get($_SESSION["userID"]); | ||
| 220 | + | ||
| 221 | + $sBody = $oUser->getUserName() . ", the document, '" . generateLink("/presentation/lookAndFeel/knowledgeTree/documentmanagement/viewBL.php", "fDocumentID=" . $this->iId, $oDocument->getName()) . "' " . | ||
| 222 | + "has been rejected by " . $oCurrentUser->getName() . " in the document collaboration process. The collaboration process has been stopped. " . | ||
| 223 | + "The comment entered by " . $oCurrentUser->getName() . " was: $sComment"; | ||
| 224 | + | ||
| 225 | + $oEmail = & new Email(); | ||
| 226 | + $oEmail->send($oUser->getEmail(), "Document rejected in collaboration process", $sBody); | ||
| 227 | + } | ||
| 228 | + } else { | ||
| 229 | + //there are steps prior to this step | ||
| 230 | + $sQuery = "SELECT FURL.id AS furl_id " . | ||
| 231 | + "FROM $default->owl_folders_user_roles_table AS FURL INNER JOIN $default->owl_groups_folders_approval_table AS GFAT ON FURL.group_folder_approval_id = GFAT.id " . | ||
| 232 | + "WHERE FURL.document_id = $iDocumentID " . | ||
| 233 | + "AND GFAT.precedence = " . $sql->f("precedence"); | ||
| 234 | + | ||
| 235 | + $sql->query($sQuery); | ||
| 236 | + while ($sql->next_record()) { | ||
| 237 | + //reset all the previous steps and email the users | ||
| 238 | + //to tell them to re-reperform their steps | ||
| 239 | + $oFolderUserRole = FolderUserRole::get($sql->f("furl_id")); | ||
| 240 | + $oFolderUserRole->setActive(true); | ||
| 241 | + $oFolderUserRole->setDone(false); | ||
| 242 | + $oFolderUserRole->setDateTime(""); | ||
| 243 | + $oFolderUserRole->update(); | ||
| 244 | + | ||
| 245 | + $oDocument = Document::get($iDocumentID); | ||
| 246 | + $oUser = User::get($oDocument->getCreatorID()); | ||
| 247 | + if ($oUser->getEmailNotification()) { | ||
| 248 | + $oUser = User::get($oFolderUserRole->getUserID()); | ||
| 249 | + $oCurrentUser = User::get($_SESSION["userID"]); | ||
| 250 | + | ||
| 251 | + $sBody = $oUser->getUserName() . ", the document, '" . generateLink("/presentation/lookAndFeel/knowledgeTree/documentmanagement/viewBL.php", "fDocumentID=" . $this->iId, $oDocument->getName()) . "' " . | ||
| 252 | + "has been rejected by " . $oCurrentUser->getName() . " in the document collaboration process. Please re-perform you step in the collaboration process." . | ||
| 253 | + "The comment entered by " . $oCurrentUser->getName() . " was: $sComment"; | ||
| 254 | + | ||
| 255 | + $oEmail = & new Email(); | ||
| 256 | + $oEmail->send($oUser->getEmail(), "Document rejected in collaboration process", $sBody); | ||
| 257 | + } | ||
| 258 | + | ||
| 259 | + } | ||
| 260 | + $oFolderUserRole = FolderUserRole::get($iCurrentFolderUserRoleID); | ||
| 261 | + $oFolderUserRole->setActive(false); | ||
| 262 | + $oFolderUserRole->setDone(false); | ||
| 263 | + $oFolderUserRole->update(); | ||
| 264 | + } | ||
| 265 | + | ||
| 266 | + } | ||
| 267 | + } | ||
| 268 | + | ||
| 269 | + /** | ||
| 270 | + * Checks if a document is pending web publishing | ||
| 271 | + * | ||
| 272 | + * | ||
| 273 | + */ | ||
| 274 | + function documentIsPendingWebPublishing($iDocumentID) { | ||
| 275 | + global $default; | ||
| 276 | + $sQuery = "SELECT id FROM $default->owl_web_documents_table WHERE document_id = $iDocumentID AND status_id = 1"; | ||
| 277 | + $sql = $default->db; | ||
| 278 | + $sql->query($sQuery); | ||
| 279 | + if ($sql->next_record()) { | ||
| 280 | + return true;; | ||
| 281 | + } | ||
| 282 | + return false; | ||
| 283 | + } | ||
| 284 | + | ||
| 285 | + /** | ||
| 286 | + * Notify the web master when a document is awaiting publishing | ||
| 287 | + * | ||
| 288 | + * @param integer the docoument to publish | ||
| 289 | + * @param string comment to the web master from the publisher | ||
| 290 | + */ | ||
| 291 | + function notifyWebMaster($iDocumentID, $sComment) { | ||
| 292 | + global $default; | ||
| 293 | + $sQuery = "SELECT WS.web_master_id, WS.web_site_name, WS.web_site_url " . | ||
| 294 | + "FROM $default->owl_web_sites_table AS WS " . | ||
| 295 | + "INNER JOIN $default->owl_web_documents_table AS WD ON WS.id = WD.web_site_id " . | ||
| 296 | + "WHERE WD.document_id = $iDocumentID"; | ||
| 297 | + | ||
| 298 | + $sql = $default->db; | ||
| 299 | + $sql->query($sQuery); | ||
| 300 | + if ($sql->next_record()) { | ||
| 301 | + $oUser = User::get($sql->f("web_master_id")); | ||
| 302 | + if (!($oUser === false)) { | ||
| 303 | + if ($oUser->getEmailNotification()) { | ||
| 304 | + $oDocument = Document::get($iDocumentID); | ||
| 305 | + $sBody = $oUser->getUserName() . ", the document, '" . generateLink("/presentation/lookAndFeel/knowledgeTree/documentmanagement/viewBL.php", "fDocumentID=" . $oDocument->iId, $oDocument->getName()) . "' " . | ||
| 306 | + "is pending web publishing to " . $sql->f("web_site_name") . " (" . $sql->f("web_site_url") . ").\n\n The publisher had these additional comments to make:\n$sComment" ; | ||
| 307 | + | ||
| 308 | + $oEmail = & new Email(); | ||
| 309 | + $oEmail->send($oUser->getEmail(), "Document for Web Publishing", $sBody); | ||
| 310 | + } | ||
| 311 | + } | ||
| 312 | + } | ||
| 313 | + } | ||
| 314 | + | ||
| 315 | + | ||
| 316 | +} | ||
| 317 | + | ||
| 318 | +?> | ||
| 0 | \ No newline at end of file | 319 | \ No newline at end of file |