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