Commit 4deb0cf272c007a04e3ff5b5542c23f9581323b5

Authored by nbm
1 parent bc76ba38

Re-organise and stylify a bit, marking private functions, removing tabs

and so forth.  No algorithm changes.


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@3440 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing 1 changed file with 295 additions and 414 deletions
lib/documentmanagement/Document.inc
1 <?php 1 <?php
2 -// document statuses  
3 -DEFINE("LIVE", 1);  
4 -DEFINE("PUBLISHED", 2);  
5 -DEFINE("DELETED", 3);  
6 -DEFINE("ARCHIVED", 4);  
7 -DEFINE("STATUS_INCOMPLETE", 5);  
8 -  
9 -require_once(KT_LIB_DIR . "/foldermanagement/Folder.inc");  
10 -  
11 /** 2 /**
12 * $Id$ 3 * $Id$
13 * 4 *
14 * Represents a document as per the documents database table. 5 * Represents a document as per the documents database table.
15 * 6 *
16 - * Copyright (c) 2003 Jam Warehouse http://www.jamwarehouse.com 7 + * Copyright (c) 2003, 2005 Jam Warehouse http://www.jamwarehouse.com
17 * 8 *
18 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by 10 * it under the terms of the GNU General Public License as published by
@@ -32,10 +23,19 @@ require_once(KT_LIB_DIR . &quot;/foldermanagement/Folder.inc&quot;); @@ -32,10 +23,19 @@ require_once(KT_LIB_DIR . &quot;/foldermanagement/Folder.inc&quot;);
32 * @version $Revision$ 23 * @version $Revision$
33 * @author Rob Cherry, Jam Warehouse (Pty) Ltd, South Africa 24 * @author Rob Cherry, Jam Warehouse (Pty) Ltd, South Africa
34 * @package lib.documentmanagement 25 * @package lib.documentmanagement
35 - * @todo add in document change transaction functionality  
36 */ 26 */
37 27
  28 +// document statuses
  29 +DEFINE("LIVE", 1);
  30 +DEFINE("PUBLISHED", 2);
  31 +DEFINE("DELETED", 3);
  32 +DEFINE("ARCHIVED", 4);
  33 +DEFINE("STATUS_INCOMPLETE", 5);
  34 +
  35 +require_once(KT_LIB_DIR . "/foldermanagement/Folder.inc");
  36 +
38 class Document extends KTEntity { 37 class Document extends KTEntity {
  38 + // {{{ attributes
39 /** primary key */ 39 /** primary key */
40 var $iId; 40 var $iId;
41 /** document type primary key */ 41 /** document type primary key */
@@ -67,12 +67,13 @@ class Document extends KTEntity { @@ -67,12 +67,13 @@ class Document extends KTEntity {
67 var $iStatusID; 67 var $iStatusID;
68 /** the user that currently has the document checked out */ 68 /** the user that currently has the document checked out */
69 var $iCheckedOutUserID; 69 var $iCheckedOutUserID;
70 - /** comma delimited string of folder hierarch this document falls under */  
71 - var $sParentFolderIDs;  
72 - /** forward slash deliminated path from file system root */  
73 - var $sFullPath; 70 + /** comma delimited string of folder hierarch this document falls under */
  71 + var $sParentFolderIDs;
  72 + /** forward slash deliminated path from file system root */
  73 + var $sFullPath;
74 /** date the document was created */ 74 /** date the document was created */
75 var $dCreated; 75 var $dCreated;
  76 + // }}}
76 77
77 /** 78 /**
78 * Document class constructor 79 * Document class constructor
@@ -103,172 +104,54 @@ class Document extends KTEntity { @@ -103,172 +104,54 @@ class Document extends KTEntity {
103 $this->iStatusID = LIVE; 104 $this->iStatusID = LIVE;
104 } 105 }
105 106
106 - /** Get the document primary key */  
107 - function getID() {  
108 - return $this->iId;  
109 - }  
110 -  
111 - /** Get the document type id */  
112 - function getDocumentTypeID() {  
113 - return $this->iDocumentTypeID;  
114 - }  
115 -  
116 - /** set the document type id */  
117 - function setDocumentTypeID($sNewValue) {  
118 - $this->iDocumentTypeID = $sNewValue;  
119 - }  
120 -  
121 - /** get the document name */  
122 - function getName() {  
123 - return $this->sName;  
124 - }  
125 -  
126 - /** set the document name */  
127 - function setName($sNewValue) {  
128 - $this->sName = $sNewValue;  
129 - }  
130 -  
131 - /** get the document path on the file system */  
132 - function getFileName() {  
133 - return $this->sFileName;  
134 - }  
135 -  
136 - /** set the document path on the file system */  
137 - function setFileName($sNewValue) {  
138 - $this->sFileName = $sNewValue;  
139 - }  
140 -  
141 - /** get the primary key of the folder in which the document is stored */  
142 - function getFolderID() {  
143 - return $this->iFolderID;  
144 - }  
145 -  
146 - /** set the primary key of the folder in which the document is stored */  
147 - function setFolderID($iNewValue) {  
148 - $this->iFolderID = $iNewValue;  
149 - }  
150 -  
151 - /** get the document file size in bytes */  
152 - function getFileSize() {  
153 - return $this->iSize;  
154 - }  
155 -  
156 - /** set the document file size in bytes */  
157 - function setFileSize($iNewValue) {  
158 - $this->iSize = $iNewValue;  
159 - }  
160 -  
161 - /** get the document creator id */  
162 - function getCreatorID() {  
163 - return $this->iCreatorID;  
164 - }  
165 -  
166 - /** set the document creator id */  
167 - function setCreatorID($iNewValue) {  
168 - $this->iCreatorID = $iNewValue;  
169 - }  
170 -  
171 - /** get the document last modified date */  
172 - function getLastModifiedDate() {  
173 - return $this->dModified;  
174 - }  
175 -  
176 - /** set the document last modified date */  
177 - function setLastModifiedDate($dNewValue) {  
178 - $this->dModified = $dNewValue;  
179 - }  
180 -  
181 - function getCreatedDateTime() {  
182 - return $this->dCreated;  
183 - }  
184 -  
185 - /** get the document description */  
186 - function getDescription() {  
187 - return $this->sDescription;  
188 - }  
189 -  
190 - /** set the document description */  
191 - function setDescription($sNewValue) {  
192 - $this->sDescription = $sNewValue;  
193 - }  
194 -  
195 - /** get the document mime type primary key */  
196 - function getMimeTypeID() {  
197 - return $this->iMimeTypeID;  
198 - }  
199 -  
200 - /** get the document mime type primary key */  
201 - function setMimeTypeID($iNewValue) {  
202 - $this->iMimeTypeID = $iNewValue;  
203 - }  
204 -  
205 - /** get the major version number */  
206 - function getMajorVersionNumber() {  
207 - return $this->iMajorVersion;  
208 - }  
209 -  
210 - /** set the major version number */  
211 - function setMajorVersionNumber($iNewValue) {  
212 - $this->iMajorVersion = $iNewValue;  
213 - }  
214 -  
215 - /** get the minor version number */  
216 - function getMinorVersionNumber() {  
217 - return $this->iMinorVersion;  
218 - }  
219 -  
220 - /** set the minor version number */  
221 - function setMinorVersionNumber($iNewValue) {  
222 - $this->iMinorVersion = $iNewValue;  
223 - }  
224 -  
225 - /** returns the complete version number as a string */  
226 - function getVersion() {  
227 - return $this->iMajorVersion . "." . $this->iMinorVersion;  
228 - }  
229 -  
230 - /** get the document check out status */  
231 - function getIsCheckedOut() {  
232 - return $this->bIsCheckedOut;  
233 - }  
234 -  
235 - /** set the document check out status */  
236 - function setIsCheckedOut($bNewValue) {  
237 - $this->bIsCheckedOut = KTUtil::anyToBool($bNewValue);  
238 - }  
239 -  
240 - /** get the user id that has the document checked out **/  
241 - function getCheckedOutUserID() {  
242 - return $this->iCheckedOutUserID;  
243 - }  
244 -  
245 - /** set the user id that has the document checked out **/  
246 - function setCheckedOutUserID($iNewValue) {  
247 - $this->iCheckedOutUserID = $iNewValue;  
248 - }  
249 -  
250 - /** Get the status id */  
251 - function getStatusID() {  
252 - return $this->iStatusID;  
253 - }  
254 -  
255 - /** set the status id */  
256 - function setStatusID($iNewValue) {  
257 - $this->iStatusID = $iNewValue;  
258 - }  
259 -  
260 - /**  
261 - * Returns the live status of the document  
262 - */ 107 + // {{{ getters/setters
  108 + function getID() { return $this->iId; }
  109 + function getDocumentTypeID() { return $this->iDocumentTypeID; }
  110 + function setDocumentTypeID($sNewValue) { $this->iDocumentTypeID = $sNewValue; }
  111 + function getName() { return $this->sName; }
  112 + function setName($sNewValue) { $this->sName = $sNewValue; }
  113 + function getFileName() { return $this->sFileName; }
  114 + function setFileName($sNewValue) { $this->sFileName = $sNewValue; }
  115 + function getFolderID() { return $this->iFolderID; }
  116 + function setFolderID($iNewValue) { $this->iFolderID = $iNewValue; }
  117 + function getFileSize() { return $this->iSize; }
  118 + function setFileSize($iNewValue) { $this->iSize = $iNewValue; }
  119 + function getCreatorID() { return $this->iCreatorID; }
  120 + function setCreatorID($iNewValue) { $this->iCreatorID = $iNewValue; }
  121 + function getLastModifiedDate() { return $this->dModified; }
  122 + function setLastModifiedDate($dNewValue) { $this->dModified = $dNewValue; }
  123 + function getCreatedDateTime() { return $this->dCreated; }
  124 + function getDescription() { return $this->sDescription; }
  125 + function setDescription($sNewValue) { $this->sDescription = $sNewValue; }
  126 + function getMimeTypeID() { return $this->iMimeTypeID; }
  127 + function setMimeTypeID($iNewValue) { $this->iMimeTypeID = $iNewValue; }
  128 + function getMajorVersionNumber() { return $this->iMajorVersion; }
  129 + function setMajorVersionNumber($iNewValue) { $this->iMajorVersion = $iNewValue; }
  130 + function getMinorVersionNumber() { return $this->iMinorVersion; }
  131 + function setMinorVersionNumber($iNewValue) { $this->iMinorVersion = $iNewValue; }
  132 + function getIsCheckedOut() { return $this->bIsCheckedOut; }
  133 + function setIsCheckedOut($bNewValue) { $this->bIsCheckedOut = KTUtil::anyToBool($bNewValue); }
  134 + function getCheckedOutUserID() { return $this->iCheckedOutUserID; }
  135 + function setCheckedOutUserID($iNewValue) { $this->iCheckedOutUserID = $iNewValue; }
  136 + function getStatusID() { return $this->iStatusID; }
  137 + function setStatusID($iNewValue) { $this->iStatusID = $iNewValue; }
  138 + // }}}
  139 +
  140 + // {{{ compound getters
  141 +
  142 + /** returns the complete version number as a string */
  143 + function getVersion() {
  144 + return $this->iMajorVersion . "." . $this->iMinorVersion;
  145 + }
  146 +
  147 + /** * Returns the live status of the document */
263 function isLive() { 148 function isLive() {
264 - return $this->getStatusID() == LIVE; 149 + return $this->getStatusID() == LIVE;
265 } 150 }
266 151
267 - /**  
268 - * Get status ID wrapper for archived status  
269 - */ 152 + /** * Get status ID wrapper for archived status */
270 function isArchived() { 153 function isArchived() {
271 - return $this->getStatusID() == ARCHIVED; 154 + return $this->getStatusID() == ARCHIVED;
272 } 155 }
273 156
274 /** returns the number of days since this document has been last modified **/ 157 /** returns the number of days since this document has been last modified **/
@@ -284,67 +167,12 @@ class Document extends KTEntity { @@ -284,67 +167,12 @@ class Document extends KTEntity {
284 $iDays = $iHours / 24; 167 $iDays = $iHours / 24;
285 return floor($iDays); 168 return floor($iDays);
286 } 169 }
287 -  
288 - /**  
289 - * Recursive function to generate a comma delimited string containing  
290 - * the parent folder ids  
291 - *  
292 - * @return String comma delimited string containing the parent folder ids  
293 - */  
294 - function generateParentFolderIDS($iFolderID) {  
295 - global $default;  
296 - //if the folder is not the root folder  
297 - if ($iFolderID != 0) {  
298 - $sql = $default->db;  
299 - $sql->query(array("SELECT parent_id FROM $default->folders_table WHERE ID = ?", $iFolderID));/*ok*/  
300 - $sql->next_record();  
301 - return $this->generateParentFolderIDS($sql->f("parent_id")) . ",$iFolderID";  
302 - }  
303 - return;  
304 -  
305 - }  
306 -  
307 - /**  
308 - * Returns a comma delimited string containing the parent folder ids, strips leading /  
309 - *  
310 - * @return String comma delimited string containing the parent folder ids  
311 - */  
312 - function generateFolderIDs($iFolderID) {  
313 - $sFolderIDs = $this->generateParentFolderIDS($iFolderID);  
314 - return substr($sFolderIDs, 1, strlen($sFolderIDs));  
315 - }  
316 -  
317 -  
318 - /**  
319 - * Recursively generates forward slash deliminated string giving full path of document  
320 - * from file system root url  
321 - */  
322 - function generateFullFolderPath($iFolderID) {  
323 - global $default;  
324 - //if the folder is not the root folder  
325 - if ($iFolderID != 0) {  
326 - $sql = $default->db;  
327 - $sql->query(array("SELECT name, parent_id FROM $default->folders_table WHERE ID = ?", $iFolderID));/*ok*/  
328 - $sql->next_record();  
329 - return $this->generateFullFolderPath($sql->f("parent_id")) . "/" . $sql->f("name");  
330 - }  
331 - return;  
332 - }  
333 -  
334 - /**  
335 - * Returns a forward slash deliminated string giving full path of document, strips leading /  
336 - */  
337 - function generateFolderPath($iFolderID) {  
338 - global $default;  
339 - $sPath = $this->generateFullFolderPath($iFolderID);  
340 - $sPath = substr($sPath, 1, strlen($sPath));  
341 - $sPath = addslashes($sPath);  
342 - return $sPath;  
343 - } 170 + // }}}
344 171
  172 + // {{{ ktentity requirements
345 function _fieldValues () { 173 function _fieldValues () {
346 - $this->sFullPath = $this->generateFolderPath($this->iFolderID);  
347 - $this->sParentFolderIDs = $this->generateFolderIDs($this->iFolderID); 174 + $this->sFullPath = $this->_generateFolderPath($this->iFolderID);
  175 + $this->sParentFolderIDs = $this->_generateFolderIDs($this->iFolderID);
348 return array( 176 return array(
349 'document_type_id' => $this->iDocumentTypeID, 177 'document_type_id' => $this->iDocumentTypeID,
350 'name' => $this->sName, 178 'name' => $this->sName,
@@ -371,6 +199,61 @@ class Document extends KTEntity { @@ -371,6 +199,61 @@ class Document extends KTEntity {
371 return $default->documents_table; 199 return $default->documents_table;
372 } 200 }
373 201
  202 + /**
  203 + * Recursive function to generate a comma delimited string containing
  204 + * the parent folder ids
  205 + *
  206 + * @return String comma delimited string containing the parent folder ids
  207 + */
  208 + function _generateParentFolderIDS($iFolderID) {
  209 + global $default;
  210 + //if the folder is not the root folder
  211 + if ($iFolderID != 0) {
  212 + $sql = $default->db;
  213 + $sql->query(array("SELECT parent_id FROM $default->folders_table WHERE ID = ?", $iFolderID));/*ok*/
  214 + $sql->next_record();
  215 + return $this->generateParentFolderIDS($sql->f("parent_id")) . ",$iFolderID";
  216 + }
  217 + return;
  218 + }
  219 +
  220 + /**
  221 + * Returns a comma delimited string containing the parent folder ids, strips leading /
  222 + *
  223 + * @return String comma delimited string containing the parent folder ids
  224 + */
  225 + function _generateFolderIDs($iFolderID) {
  226 + $sFolderIDs = $this->generateParentFolderIDS($iFolderID);
  227 + return substr($sFolderIDs, 1, strlen($sFolderIDs));
  228 + }
  229 +
  230 + /**
  231 + * Recursively generates forward slash deliminated string giving full path of document
  232 + * from file system root url
  233 + */
  234 + function _generateFullFolderPath($iFolderID) {
  235 + global $default;
  236 + //if the folder is not the root folder
  237 + if ($iFolderID != 0) {
  238 + $sql = $default->db;
  239 + $sql->query(array("SELECT name, parent_id FROM $default->folders_table WHERE ID = ?", $iFolderID));/*ok*/
  240 + $sql->next_record();
  241 + return $this->_generateFullFolderPath($sql->f("parent_id")) . "/" . $sql->f("name");
  242 + }
  243 + return;
  244 + }
  245 +
  246 + /**
  247 + * Returns a forward slash deliminated string giving full path of document, strips leading /
  248 + */
  249 + function _generateFolderPath($iFolderID) {
  250 + global $default;
  251 + $sPath = $this->_generateFullFolderPath($iFolderID);
  252 + $sPath = substr($sPath, 1, strlen($sPath));
  253 + $sPath = addslashes($sPath);
  254 + return $sPath;
  255 + }
  256 + // }}}
374 257
375 /** 258 /**
376 * Insert the current document into the database 259 * Insert the current document into the database
@@ -384,8 +267,8 @@ class Document extends KTEntity { @@ -384,8 +267,8 @@ class Document extends KTEntity {
384 if ($res === true) { 267 if ($res === true) {
385 Permission::updateSearchPermissionsForDocument($this->getID()); 268 Permission::updateSearchPermissionsForDocument($this->getID());
386 } 269 }
387 - return $res;  
388 270
  271 + return $res;
389 } 272 }
390 273
391 function update($bPathMove = false) { 274 function update($bPathMove = false) {
@@ -396,88 +279,88 @@ class Document extends KTEntity { @@ -396,88 +279,88 @@ class Document extends KTEntity {
396 return $res; 279 return $res;
397 } 280 }
398 281
399 - /**  
400 - * Begin the current document's collaboration process  
401 - *  
402 - */  
403 - function beginCollaborationProcess() {  
404 - global $default;  
405 - //get the steps in this document's collaboration process  
406 - $sQuery = array("SELECT FURL.id, GFAL.precedence " ./*ok*/  
407 - "FROM $default->folders_user_roles_table AS FURL " . 282 + /**
  283 + * Begin the current document's collaboration process
  284 + *
  285 + */
  286 + function beginCollaborationProcess() {
  287 + global $default;
  288 + //get the steps in this document's collaboration process
  289 + $sQuery = array("SELECT FURL.id, GFAL.precedence " ./*ok*/
  290 + "FROM $default->folders_user_roles_table AS FURL " .
408 "INNER JOIN $default->groups_folders_approval_table AS GFAL ON FURL.group_folder_approval_id = GFAL.id " . 291 "INNER JOIN $default->groups_folders_approval_table AS GFAL ON FURL.group_folder_approval_id = GFAL.id " .
409 - "WHERE document_id = ? " .  
410 - "ORDER BY GFAL.precedence ASC", $this->iId);  
411 - $sql = $default->db;  
412 - $sql->query($sQuery);  
413 - if ($sql->next_record()) {  
414 - //get the first step in the collaboration process  
415 - $iMinimumSequenceNumber = $sql->f("precedence");  
416 - $oFolderUserRole = FolderUserRole::get($sql->f("id"));  
417 - $oFolderUserRole->setActive(true);  
418 - $oFolderUserRole->update();  
419 - $oFolderCollaboration = FolderCollaboration::get($oFolderUserRole->getGroupFolderApprovalID());  
420 - //get the role the user must perform  
421 - $oRole = Role::get($oFolderCollaboration->getRoleID());  
422 - //get the user to email  
423 - $oUser = User::get($oFolderUserRole->getUserID());  
424 - // FIXME: delegate this to message templating handling messaging layer 292 + "WHERE document_id = ? " .
  293 + "ORDER BY GFAL.precedence ASC", $this->iId);
  294 + $sql = $default->db;
  295 + $sql->query($sQuery);
  296 + if ($sql->next_record()) {
  297 + //get the first step in the collaboration process
  298 + $iMinimumSequenceNumber = $sql->f("precedence");
  299 + $oFolderUserRole = FolderUserRole::get($sql->f("id"));
  300 + $oFolderUserRole->setActive(true);
  301 + $oFolderUserRole->update();
  302 + $oFolderCollaboration = FolderCollaboration::get($oFolderUserRole->getGroupFolderApprovalID());
  303 + //get the role the user must perform
  304 + $oRole = Role::get($oFolderCollaboration->getRoleID());
  305 + //get the user to email
  306 + $oUser = User::get($oFolderUserRole->getUserID());
  307 + // FIXME: delegate this to message templating handling messaging layer
425 // construct and send the mail 308 // construct and send the mail
426 - $sBody = $oUser->getUserName() . ", your role of '" . $oRole->getName() . "' in the document, '" . $this->sName . "' collaboration process is now active. " .  
427 - "Click " . generateLink("/presentation/lookAndFeel/knowledgeTree/documentmanagement/viewBL.php", "fDocumentID=" . $this->iId, "here") . " to access " .  
428 - "the document";  
429 - $oEmail = & new Email();  
430 - $oEmail->send($oUser->getEmail(), "Document collaboration role active", $sBody);  
431 - DocumentCollaboration::createDependantDocuments($oFolderUserRole);  
432 -  
433 - //check if there are any other parallel steps that have to be started  
434 - while ($sql->next_record()) {  
435 - if ($sql->f("precedence") == $iMinimumSequenceNumber) {  
436 - $oFolderUserRole = FolderUserRole::get($sql->f("id"));  
437 - $oFolderUserRole->setActive(true);  
438 - $oFolderUserRole->update();  
439 - $oFolderCollaboration = FolderCollaboration::get($oFolderUserRole->getGroupFolderApprovalID());  
440 - //get the role the user must perform  
441 - $oRole = Role::get($oFolderCollaboration->getRoleID());  
442 - //get the user to email  
443 - $oUser = User::get($oFolderUserRole->getUserID()); 309 + $sBody = $oUser->getUserName() . ", your role of '" . $oRole->getName() . "' in the document, '" . $this->sName . "' collaboration process is now active. " .
  310 + "Click " . generateLink("/presentation/lookAndFeel/knowledgeTree/documentmanagement/viewBL.php", "fDocumentID=" . $this->iId, "here") . " to access " .
  311 + "the document";
  312 + $oEmail = & new Email();
  313 + $oEmail->send($oUser->getEmail(), "Document collaboration role active", $sBody);
  314 + DocumentCollaboration::createDependantDocuments($oFolderUserRole);
  315 +
  316 + //check if there are any other parallel steps that have to be started
  317 + while ($sql->next_record()) {
  318 + if ($sql->f("precedence") == $iMinimumSequenceNumber) {
  319 + $oFolderUserRole = FolderUserRole::get($sql->f("id"));
  320 + $oFolderUserRole->setActive(true);
  321 + $oFolderUserRole->update();
  322 + $oFolderCollaboration = FolderCollaboration::get($oFolderUserRole->getGroupFolderApprovalID());
  323 + //get the role the user must perform
  324 + $oRole = Role::get($oFolderCollaboration->getRoleID());
  325 + //get the user to email
  326 + $oUser = User::get($oFolderUserRole->getUserID());
444 // FIXME: delegate this to message templating handling messaging layer 327 // FIXME: delegate this to message templating handling messaging layer
445 - // construct and send the mail  
446 - $sBody = $oUser->getUserName() . ", your role of '" . $oRole->getName() . "' in the document, '" . $this->sName . "' collaboration process is now active. " .  
447 - "Click " . generateLink("/presentation/lookAndFeel/knowledgeTree/documentmanagement/viewBL.php", "fDocumentID=" . $this->iId, "here") . " to access " .  
448 - "the document";  
449 - $oEmail = & new Email();  
450 - $oEmail->send($oUser->getEmail(), "Document collaboration role active", $sBody);  
451 - DocumentCollaboration::createDependantDocuments($oFolderUserRole);  
452 - } else {  
453 - return;  
454 - }  
455 - }  
456 - }  
457 - }  
458 -  
459 - function endCollaborationProcess() {  
460 - global $default;  
461 - $sql = $default->db;  
462 - //get the current step  
463 - //if the user is assinged to two or more roles, make sure we get the current  
464 - //one by ordering by precedence  
465 - $sql->query(array("SELECT FURL.id AS id, GFAT.precedence " ./*ok*/  
466 - "FROM $default->groups_folders_approval_table AS GFAT " .  
467 - "INNER JOIN $default->folders_user_roles_table AS FURL ON GFAT.id = FURL.group_folder_approval_id " .  
468 - "WHERE document_id = ? AND FURL.user_id = ? " .  
469 - "AND done = 0 " .  
470 - "ORDER BY precedence ASC", array($this->iId, $_SESSION["userID"])));  
471 - if ($sql->next_record()) {  
472 - //set it as done  
473 - $oFolderUserRole = FolderUserRole::get($sql->f("id"));  
474 - $oFolderUserRole->setActive(false);  
475 - $oFolderUserRole->setDone(true);  
476 - $oFolderUserRole->setDateTime(getCurrentDateTime());  
477 - return $oFolderUserRole->update();  
478 - }  
479 - return false;  
480 - } 328 + // construct and send the mail
  329 + $sBody = $oUser->getUserName() . ", your role of '" . $oRole->getName() . "' in the document, '" . $this->sName . "' collaboration process is now active. " .
  330 + "Click " . generateLink("/presentation/lookAndFeel/knowledgeTree/documentmanagement/viewBL.php", "fDocumentID=" . $this->iId, "here") . " to access " .
  331 + "the document";
  332 + $oEmail = & new Email();
  333 + $oEmail->send($oUser->getEmail(), "Document collaboration role active", $sBody);
  334 + DocumentCollaboration::createDependantDocuments($oFolderUserRole);
  335 + } else {
  336 + return;
  337 + }
  338 + }
  339 + }
  340 + }
  341 +
  342 + function endCollaborationProcess() {
  343 + global $default;
  344 + $sql = $default->db;
  345 + //get the current step
  346 + //if the user is assinged to two or more roles, make sure we get the current
  347 + //one by ordering by precedence
  348 + $sql->query(array("SELECT FURL.id AS id, GFAT.precedence " ./*ok*/
  349 + "FROM $default->groups_folders_approval_table AS GFAT " .
  350 + "INNER JOIN $default->folders_user_roles_table AS FURL ON GFAT.id = FURL.group_folder_approval_id " .
  351 + "WHERE document_id = ? AND FURL.user_id = ? " .
  352 + "AND done = 0 " .
  353 + "ORDER BY precedence ASC", array($this->iId, $_SESSION["userID"])));
  354 + if ($sql->next_record()) {
  355 + //set it as done
  356 + $oFolderUserRole = FolderUserRole::get($sql->f("id"));
  357 + $oFolderUserRole->setActive(false);
  358 + $oFolderUserRole->setDone(true);
  359 + $oFolderUserRole->setDateTime(getCurrentDateTime());
  360 + return $oFolderUserRole->update();
  361 + }
  362 + return false;
  363 + }
481 364
482 /** 365 /**
483 * 366 *
@@ -490,27 +373,27 @@ class Document extends KTEntity { @@ -490,27 +373,27 @@ class Document extends KTEntity {
490 function & get($iDocumentID) { 373 function & get($iDocumentID) {
491 global $default, $lang_err_doc_not_exist; 374 global $default, $lang_err_doc_not_exist;
492 if (strlen($iDocumentID) > 0) { 375 if (strlen($iDocumentID) > 0) {
493 - $sql = $default->db;  
494 - $sql->query(array("SELECT * FROM $default->documents_table WHERE id = ?", $iDocumentID));/*ok*/  
495 - if ($sql->next_record()) {  
496 - $oDocument = & new Document($sql->f("name"), $sql->f("filename"), $sql->f("size"), $sql->f("creator_id"), $sql->f("mime_id"), $sql->f("folder_id"), $sql->f("description"));  
497 - $oDocument->setDocumentTypeID($sql->f("document_type_id"));  
498 - $oDocument->setMajorVersionNumber($sql->f("major_version"));  
499 - $oDocument->setMinorVersionNumber($sql->f("minor_version"));  
500 - $oDocument->setIsCheckedOut($sql->f("is_checked_out"));  
501 - $oDocument->setLastModifiedDate($sql->f("modified"));  
502 - $oDocument->dCreated = $sql->f("created");  
503 - $oDocument->sParentFolderIDs = $sql->f("parent_folder_ids");  
504 - $oDocument->sFullPath = $sql->f("full_path");  
505 - $oDocument->setCheckedOutUserID($sql->f("checked_out_user_id"));  
506 - // FIXME: nasty hack- paying the penalty for adding status_id late in phase 2  
507 - $oDocument->setStatusID( ($sql->f("status_id") == "" ? LIVE : $sql->f("status_id")) );  
508 - $oDocument->iId = $iDocumentID;  
509 - return $oDocument;  
510 - }  
511 - return false; 376 + $sql = $default->db;
  377 + $sql->query(array("SELECT * FROM $default->documents_table WHERE id = ?", $iDocumentID));/*ok*/
  378 + if ($sql->next_record()) {
  379 + $oDocument = & new Document($sql->f("name"), $sql->f("filename"), $sql->f("size"), $sql->f("creator_id"), $sql->f("mime_id"), $sql->f("folder_id"), $sql->f("description"));
  380 + $oDocument->setDocumentTypeID($sql->f("document_type_id"));
  381 + $oDocument->setMajorVersionNumber($sql->f("major_version"));
  382 + $oDocument->setMinorVersionNumber($sql->f("minor_version"));
  383 + $oDocument->setIsCheckedOut($sql->f("is_checked_out"));
  384 + $oDocument->setLastModifiedDate($sql->f("modified"));
  385 + $oDocument->dCreated = $sql->f("created");
  386 + $oDocument->sParentFolderIDs = $sql->f("parent_folder_ids");
  387 + $oDocument->sFullPath = $sql->f("full_path");
  388 + $oDocument->setCheckedOutUserID($sql->f("checked_out_user_id"));
  389 + // FIXME: nasty hack- paying the penalty for adding status_id late in phase 2
  390 + $oDocument->setStatusID( ($sql->f("status_id") == "" ? LIVE : $sql->f("status_id")) );
  391 + $oDocument->iId = $iDocumentID;
  392 + return $oDocument;
  393 + }
  394 + return false;
512 } else { 395 } else {
513 - return false; 396 + return false;
514 } 397 }
515 } 398 }
516 399
@@ -615,8 +498,8 @@ class Document extends KTEntity { @@ -615,8 +498,8 @@ class Document extends KTEntity {
615 * Returns the html to display the document icon image 498 * Returns the html to display the document icon image
616 */ 499 */
617 function getIcon() { 500 function getIcon() {
618 - global $default;  
619 - return generateImage($this->getMimeTypeIconUrl() ? $this->getMimeTypeIconUrl() : "$default->graphicsUrl/unknown.gif"); 501 + global $default;
  502 + return generateImage($this->getMimeTypeIconUrl() ? $this->getMimeTypeIconUrl() : "$default->graphicsUrl/unknown.gif");
620 } 503 }
621 504
622 /** 505 /**
@@ -634,10 +517,10 @@ class Document extends KTEntity { @@ -634,10 +517,10 @@ class Document extends KTEntity {
634 * @return string full path to document 517 * @return string full path to document
635 */ 518 */
636 function getDisplayPath($bDisplayIcon = false) { 519 function getDisplayPath($bDisplayIcon = false) {
637 - $sFolderPath = Folder::getFolderDisplayPath($this->iFolderID);  
638 - // #3425 for consistency 520 + $sFolderPath = Folder::getFolderDisplayPath($this->iFolderID);
  521 + // #3425 for consistency
639 return ($bDisplayIcon ? $this->getIcon() : "") . 522 return ($bDisplayIcon ? $this->getIcon() : "") .
640 - ($sFolderPath == "" ? "Deleted Folder" : $sFolderPath) . " > " . $this->sFileName; 523 + ($sFolderPath == "" ? "Deleted Folder" : $sFolderPath) . " > " . $this->sFileName;
641 } 524 }
642 525
643 /** 526 /**
@@ -653,9 +536,9 @@ class Document extends KTEntity { @@ -653,9 +536,9 @@ class Document extends KTEntity {
653 global $default; 536 global $default;
654 $sql = $default->db; 537 $sql = $default->db;
655 $sQuery = "SELECT * FROM $default->documents_table " ./*ok*/ 538 $sQuery = "SELECT * FROM $default->documents_table " ./*ok*/
656 - "WHERE filename = ? " .  
657 - " AND folder_id = ?" .  
658 - " AND status_id = ?"; 539 + "WHERE filename = ? " .
  540 + " AND folder_id = ?" .
  541 + " AND status_id = ?";
659 $aParams = array($sFileName, $iFolderID, LIVE); 542 $aParams = array($sFileName, $iFolderID, LIVE);
660 $sql->query(array($sQuery, $aParams)); 543 $sql->query(array($sQuery, $aParams));
661 if ($sql->next_record()) { 544 if ($sql->next_record()) {
@@ -695,84 +578,82 @@ class Document extends KTEntity { @@ -695,84 +578,82 @@ class Document extends KTEntity {
695 $oDocument = & Document::get($iDocumentID); 578 $oDocument = & Document::get($iDocumentID);
696 return $oDocument->getDisplayPath(); 579 return $oDocument->getDisplayPath();
697 } 580 }
698 -  
699 - /**  
700 - * Check if any documents are assigned the given  
701 - * document type in a specified folder  
702 - *  
703 - */  
704 - function documentIsAssignedDocTypeInFolder($iFolderID, $iFolderDocTypeID) {  
705 - global $default;  
706 - $sql = $default->db;  
707 - $sql->query(array("SELECT * " . /*ok*/  
708 - "FROM $default->folder_doctypes_table AS FDL " .  
709 - "INNER JOIN $default->documents_table AS D ON D.document_type_id = FDL.document_type_id " .  
710 - "WHERE FDL.id = ? " .  
711 - "AND D.folder_id = ?", array($iFolderDocTypeID, $iFolderID)));  
712 - if ($sql->next_record()) {  
713 - return true;  
714 - }  
715 - return false;  
716 - }  
717 -  
718 - /**  
719 - * On a document type change, delete all document field entries for the  
720 - * old document type  
721 - */  
722 - function removeInvalidDocumentTypeEntries() {  
723 - global $default;  
724 - $sQuery = array("SELECT field_id FROM $default->document_type_fields_table DTFL " . /*ok*/  
725 - "INNER JOIN $default->document_fields_table AS DF ON DF.id = DTFL.field_id " .  
726 - "WHERE DTFL.document_type_id = ? " .  
727 - "AND DF.is_generic = ?", array($this->iDocumentTypeID, false));  
728 - $sql = $default->db;  
729 - $sql->query($sQuery);  
730 - $aFieldIDs = array();  
731 - //get all the fields from the old document type  
732 - while ($sql->next_record()) {  
733 - $aFieldIDs[count($aFieldIDs)] = $sql->f("field_id");  
734 - }  
735 - if (count($aFieldIDs) > 0) {  
736 - //delete the entries  
737 - $sQuery = "DELETE FROM $default->document_fields_link_table " . 581 +
  582 + /**
  583 + * Check if any documents are assigned the given
  584 + * document type in a specified folder
  585 + *
  586 + */
  587 + function documentIsAssignedDocTypeInFolder($iFolderID, $iFolderDocTypeID) {
  588 + global $default;
  589 + $sql = $default->db;
  590 + $sql->query(array("SELECT * " . /*ok*/
  591 + "FROM $default->folder_doctypes_table AS FDL " .
  592 + "INNER JOIN $default->documents_table AS D ON D.document_type_id = FDL.document_type_id " .
  593 + "WHERE FDL.id = ? " .
  594 + "AND D.folder_id = ?", array($iFolderDocTypeID, $iFolderID)));
  595 + if ($sql->next_record()) {
  596 + return true;
  597 + }
  598 + return false;
  599 + }
  600 +
  601 + /**
  602 + * On a document type change, delete all document field entries for the
  603 + * old document type
  604 + */
  605 + function removeInvalidDocumentTypeEntries() {
  606 + global $default;
  607 + $sQuery = array("SELECT field_id FROM $default->document_type_fields_table DTFL " . /*ok*/
  608 + "INNER JOIN $default->document_fields_table AS DF ON DF.id = DTFL.field_id " .
  609 + "WHERE DTFL.document_type_id = ? " .
  610 + "AND DF.is_generic = ?", array($this->iDocumentTypeID, false));
  611 + $sql = $default->db;
  612 + $sql->query($sQuery);
  613 + $aFieldIDs = array();
  614 + //get all the fields from the old document type
  615 + while ($sql->next_record()) {
  616 + $aFieldIDs[count($aFieldIDs)] = $sql->f("field_id");
  617 + }
  618 + if (count($aFieldIDs) > 0) {
  619 + //delete the entries
  620 + $sQuery = "DELETE FROM $default->document_fields_link_table " .
738 "WHERE document_id = " . quote($this->iId) . " 621 "WHERE document_id = " . quote($this->iId) . "
739 AND document_field_id IN (" . implode(",",$aFieldIDs) . ")"; 622 AND document_field_id IN (" . implode(",",$aFieldIDs) . ")";
740 - if ($sql->query($sQuery)) {  
741 - return true;  
742 - }  
743 - return false;  
744 - }  
745 - //none to remove if we get here  
746 - return true;  
747 -  
748 -  
749 - }  
750 - 623 + if ($sql->query($sQuery)) {
  624 + return true;
  625 + }
  626 + return false;
  627 + }
  628 + //none to remove if we get here
  629 + return true;
  630 + }
  631 +
751 /** 632 /**
752 * Checks if there is collaboration for this document 633 * Checks if there is collaboration for this document
753 * 634 *
754 * @param integer the id of the document 635 * @param integer the id of the document
755 */ 636 */
756 function hasCollaboration() { 637 function hasCollaboration() {
757 - global $default;  
758 - $sql = $default->db;  
759 - $sql->query(array("SELECT id AS count from $default->groups_folders_approval_table WHERE folder_id = ?", $this->iFolderID));/*ok*/  
760 - if ($sql->next_record()) {  
761 - return true;  
762 - }  
763 - return false; 638 + global $default;
  639 + $sql = $default->db;
  640 + $sql->query(array("SELECT id AS count from $default->groups_folders_approval_table WHERE folder_id = ?", $this->iFolderID));/*ok*/
  641 + if ($sql->next_record()) {
  642 + return true;
  643 + }
  644 + return false;
764 } 645 }
765 -  
766 - /**  
767 - * Deletes content from document data tables  
768 - */  
769 - function cleanupDocumentData($iDocumentID) {  
770 - global $default;  
771 - $sql = $default->db;  
772 - $result = $sql->query("DELETE FROM $default->document_text_table WHERE document_id = $iDocumentID") &&  
773 - $sql->query("DELETE FROM $default->search_permissions_table WHERE document_id = $iDocumentID") &&  
774 - $sql->query("DELETE FROM $default->document_fields_link_table WHERE document_id = $iDocumentID");  
775 - return $result;  
776 - } 646 +
  647 + /**
  648 + * Deletes content from document data tables
  649 + */
  650 + function cleanupDocumentData($iDocumentID) {
  651 + global $default;
  652 + $sql = $default->db;
  653 + $result = $sql->query("DELETE FROM $default->document_text_table WHERE document_id = $iDocumentID") &&
  654 + $sql->query("DELETE FROM $default->search_permissions_table WHERE document_id = $iDocumentID") &&
  655 + $sql->query("DELETE FROM $default->document_fields_link_table WHERE document_id = $iDocumentID");
  656 + return $result;
  657 + }
777 } 658 }
778 ?> 659 ?>