Commit a5750f90b5e7ecf8743f2aac9d7fa13ca57f0065

Authored by michael
1 parent e98b1213

reformatted, some phpdoc updates and added getFolderID, getDocumentName and getD…

…ocumentDisplayPath static methods


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@810 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing 1 changed file with 456 additions and 408 deletions
lib/documentmanagement/Document.inc
1 <?php 1 <?php
2 /** 2 /**
3 -*  
4 -* Class Document  
5 -*  
6 -* Represents a document as per the documents database table  
7 -*  
8 -* @author Rob Cherry, Jam Warehouse (Pty) Ltd, South Africa  
9 -* @date 15 January 2003  
10 -*  
11 -* @todo add in document change transaction functionality  
12 -*  
13 -* @package lib.documentmanagement  
14 -*/  
15 - 3 + * $Id$
  4 + *
  5 + * Represents a document as per the documents database table
  6 + *
  7 + * @version $Revision$
  8 + * @author Rob Cherry, Jam Warehouse (Pty) Ltd, South Africa
  9 + * @package lib.documentmanagement
  10 + * @todo add in document change transaction functionality
  11 + */
16 class Document { 12 class Document {
17 - /** primary key */  
18 - var $iId;  
19 - /** document type primary key */  
20 - var $iDocumentTypeID;  
21 - /** document name */  
22 - var $sName;  
23 - /** document file name (path to document on file system) */  
24 - var $sFileName;  
25 - /** document file size */  
26 - var $iSize;  
27 - /** primary key of user who created document */  
28 - var $iCreatorID;  
29 - /** date the document was last modified */  
30 - var $dModified;  
31 - /** file description */  
32 - var $sDescription;  
33 - /** primary key of file mime type */  
34 - var $iMimeTypeID;  
35 - /** primary key of folder under which document is stored */  
36 - var $iFolderID;  
37 - /** major revision number */  
38 - var $iMajorVersion;  
39 - /** minor revision number */  
40 - var $iMinorVersion;  
41 - /** document checked out status */  
42 - var $bIsCheckedOut;  
43 -  
44 - /**  
45 - * Document class constructor  
46 - *  
47 - * @param $sName File Name  
48 - * @param $iSize File size in bytes  
49 - * @param $iCreatorID Primary key of user who created document  
50 - * @param $sDescription Description  
51 - * @param $iMimeID Primary key of file mime type  
52 - * @param $iFolderID Primary key of folder to which document belongs  
53 - *  
54 - */  
55 - function Document($sNewName, $sNewFileName, $iNewSize, $iNewCreatorID, $iNewMimeID, $iNewFolderID, $sNewDescription = "None") {  
56 - $this->iId = -1; //primary key not set as document is not stored yet  
57 - $this->sName = $sNewName;  
58 - $this->iSize = $iNewSize;  
59 - $this->iCreatorID = $iNewCreatorID;  
60 - $this->sFileName = $sNewFileName;  
61 - $this->sDescription = $sNewDescription;  
62 - $this->iMimeTypeID = $iNewMimeID;  
63 - $this->iFolderID = $iNewFolderID;  
64 - $this->iDocumentTypeID = Folder::getFolderDocumentType($this->iFolderID);  
65 - $this->iMajorVersion = 0;  
66 - $this->iMinorVersion = 1;  
67 - $this->bIsCheckedOut = false;  
68 - }  
69 -  
70 - /** Get the document primary key */  
71 - function getID() {  
72 - return $this->iId;  
73 - }  
74 -  
75 - /** Get the document type id */  
76 - function getDocumentTypeID() {  
77 - return $this->iDocumentTypeID;  
78 - }  
79 -  
80 - /** set the document type id */  
81 - function setDocumentTypeID($sNewValue) {  
82 - $this->iDocumentTypeID = $sNewValue;  
83 - }  
84 -  
85 - /** get the document name */  
86 - function getName() {  
87 - return $this->sName;  
88 - }  
89 -  
90 - /** set the document name */  
91 - function setName($sNewValue) {  
92 - $this->sName = $sNewValue;  
93 - }  
94 -  
95 - /** get the document path on the file system */  
96 - function getFileName() {  
97 - return $this->sFileName;  
98 - }  
99 -  
100 - /** set the document path on the file system */  
101 - function setFileName() {  
102 - $this->sFileName = $sNewValue;  
103 - }  
104 -  
105 - /** get the primary key of the folder in which the document is stored */  
106 - function getFolderID() {  
107 - return $this->iFolderID;  
108 - }  
109 -  
110 - /** set the primary key of the folder in which the document is stored */  
111 - function setFolderID($iNewValue) {  
112 - $this->iFolderID = $iNewValue;  
113 - }  
114 -  
115 - /** get the document file size in bytes */  
116 - function getFileSize() {  
117 - return $this->iSize;  
118 - }  
119 -  
120 - /** set the document file size in bytes */  
121 - function setFileSize($iNewValue) {  
122 - $this->iSize = $iNewValue;  
123 - }  
124 -  
125 - /** get the document creator id */  
126 - function getCreatorID() {  
127 - return $this->iCreatorID;  
128 - }  
129 -  
130 - /** set the document creator id */  
131 - function setCreatorID($iNewValue) {  
132 - $this->iCreatorID = $iNewValue;  
133 - }  
134 -  
135 - /** get the document last modified date */  
136 - function getLastModifiedDate() {  
137 - return $this->dModified;  
138 - }  
139 -  
140 - /** set the document last modified date */  
141 - function setLastModifiedDate($dNewValue) {  
142 - $this->dModified = $dNewValue;  
143 - }  
144 -  
145 - /** get the document description */  
146 - function getDescription() {  
147 - return $this->sDescription;  
148 - }  
149 -  
150 - /** set the document description */  
151 - function setDescription($sNewValue) {  
152 - $this->sDescription = $sNewValue;  
153 - }  
154 -  
155 - /** get the document mime type primary key */  
156 - function getMimeTypeID() {  
157 - return $this->iMimeTypeID;  
158 - }  
159 -  
160 - /** get the document mime type primary key */  
161 - function setMimeTypeID($iNewValue) {  
162 - $this->iMimeTypeID = $iNewValue;  
163 - }  
164 -  
165 - /** get the major version number */  
166 - function getMajorVersionNumber() {  
167 - return $this->iMajorVersion;  
168 - }  
169 -  
170 - /** set the major version number */  
171 - function setMajorVersionNumber($iNewValue) {  
172 - $this->iMajorVersion = $iNewValue;  
173 - }  
174 -  
175 - /** get the minor version number */  
176 - function getMinorVersionNumber() {  
177 - return $this->iMinorVersion;  
178 - }  
179 -  
180 - /** set the minor version number */  
181 - function setMinorVersionNumber($iNewValue) {  
182 - $this->iMinorVersionNumber = $iNewValue;  
183 - }  
184 -  
185 - /** get the document check out status */  
186 - function getIsCheckedOut() {  
187 - return $this->bCheckedOut;  
188 - }  
189 -  
190 - /** set the document check out status */  
191 - function setIsCheckedOut($bNewValue) {  
192 - $this->bCheckedOut = $bNewValue;  
193 - }  
194 -  
195 - /**  
196 - * Insert the current document into the database  
197 - *  
198 - * @return boolean true on successful insert, false otherwise and set $_SESSION["errorMessage"]  
199 - */  
200 - function create() {  
201 - global $default, $lang_err_doc_exist, $lang_err_database;  
202 - //if the id >= 0, then the object has already been created  
203 - if ($this->iId < 0) {  
204 - $sql = $default->db;  
205 - $result = $sql->query("INSERT INTO " . $default->owl_documents_table . " (document_type_id, name, filename, size, creator_id, modified, description, mime_id, folder_id, major_version, minor_version, is_checked_out) " .  
206 - "VALUES (" . $this->iDocumentTypeID . ", '" . addslashes($this->sName) . "', '" . addslashes($this->sFileName) . "', $this->iSize, $this->iCreatorID, '" . getCurrentDateTime() . "', '" . addslashes($this->sDescription) . "', $this->iMimeTypeID, $this->iFolderID, $this->iMajorVersion, $this->iMinorVersion, " . ($this->bIsCheckedOut ? 1 : 0) . ")");  
207 - if ($result) {  
208 - //set the current documents primary key  
209 - $this->iId = $sql->insert_id();  
210 - return true;  
211 - }  
212 - $_SESSION["errorMessage"] = $lang_err_database;  
213 - return false;  
214 - }  
215 - $_SESSION["errorMessage"] = $lang_err_object_exists . "id = " . $this->iId . " table = documents";  
216 - return false;  
217 -  
218 - }  
219 -  
220 - /**  
221 - * Update the documents current values in the database  
222 - *  
223 - * @return boolean true on successful update, false otherwise and set $_SESSION["errorMessage"]  
224 - */  
225 - function update() {  
226 - global $default, $lang_err_database, $lang_err_object_key;  
227 - if ($this->iId >= 0) {  
228 - $sql = $default->db;  
229 - $result = $sql->query("UPDATE " . $default->owl_documents_table . " SET " .  
230 - "document_typeid = $this->iDocumentTypeID, " .  
231 - "file_name = '" . addslashes($this->file_name) . "', " .  
232 - "size = $this->iSize, " .  
233 - "creator_id = $this->iCreatorID, " .  
234 - "modified = " . getCurrentDateTime() . ", " .  
235 - "description = '" . addslashes($this->sDescription) . "', " .  
236 - "mime_id = $this->iMimeTypeID, " .  
237 - "folder_id = $this->iFolderID, " .  
238 - "major_revision = $this->iMajorRevision, " .  
239 - "minor_revision = $this->iMinorRevision, " .  
240 - "is_checked_out = $this->bIsCheckedOut " .  
241 - "WHERE id = $this->id");  
242 - if ($result) {  
243 - return true;  
244 - }  
245 - $_SESSION["errorMessage"] = $lang_err_database;  
246 - return false;  
247 - }  
248 - $_SESSION["errorMessage"] = $lang_err_object_key;  
249 - return false;  
250 -  
251 - }  
252 -  
253 - /**  
254 - * Delete the current document from the database. Set the primary key to -1  
255 - * on successful deletion  
256 - *  
257 - * @return boolean true and reset id to -1 on successful deletion, false otherwise and set $_SESSION["errorMessage"]  
258 - */  
259 - function delete() {  
260 - global $default, $lang_err_database, $lang_err_object_key;  
261 - if ($this->iId >= 0) {  
262 - $sql = $default->db;  
263 - $result = $sql->query("DELETE FROM " . $default->owl_documents_table . " WHERE id = $this->iId");  
264 - if ($result) {  
265 - $this->iId = -1;  
266 - return true;  
267 - }  
268 - $_SESSION["errorMessage"] = $lang_err_database;  
269 - return false;  
270 - }  
271 - $_SESSION["errorMessage"] = $lang_err_object_key;  
272 - return false;  
273 - }  
274 -  
275 -  
276 - /**  
277 - *  
278 - * Static function. Given a document primary key will create  
279 - * a document object and populate it with the corresponding  
280 - * database values  
281 - *  
282 - * @return Document populated Document object on success, false otherwise and set $_SESSION["errorMessage"]  
283 - */  
284 - function & get($iDocumentID) {  
285 - global $default, $lang_err_doc_not_exist;  
286 - $sql = $default->db;  
287 - $sql->query("SELECT * FROM $default->owl_documents_table WHERE id = $iDocumentID");  
288 - if ($sql->next_record()) {  
289 - $oDocument = & new Document(stripslashes($sql->f("name")), $sql->f("filename"), $sql->f("size"), stripslashes($sql->f("creator_id")), $sql->f("mime_id"), $sql->f("folder_id"), $sql->f("description"));  
290 - $oDocument->setDocumentTypeID($sql->f("document_type_id"));  
291 - $oDocument->setMajorVersionNumber($sql->f("major_version"));  
292 - $oDocument->setMinorVersionNumber($sql->f("minor_version"));  
293 - $oDocument->setIsCheckedOut($sql->f("is_checked_out"));  
294 - $oDocument->iId = $iDocumentID;  
295 - return $oDocument;  
296 - }  
297 - $_SESSION["errorMessage"] = $lang_err_object_not_exist . "id = " . $iDocumentID . " table = documents";  
298 - return false;  
299 - }  
300 -  
301 - /**  
302 - * Static function  
303 - * Get a list of Documents  
304 - *  
305 - * @param String Where clause (not required)  
306 - *  
307 - * @return Array array of Documents objects, false otherwise and set $_SESSION["errorMessage"]  
308 - */  
309 - function getList($sWhereClause = null) {  
310 - global $default, $lang_err_database;  
311 - $aDocumentArray;  
312 - settype($aDocumentArray, "array");  
313 - $sql = $default->db;  
314 - $result = $sql->query("SELECT * FROM " . $default->owl_documents_table . (isset($sWhereClause) ? " WHERE " . $sWhereClause : ""));  
315 - if ($result) {  
316 - $iCount = 0;  
317 - while ($sql->next_record()) {  
318 - $oDocument = & Document::get($sql->f("id"));  
319 - $aDocumentArray[$iCount] = $oDocument;  
320 - $iCount++;  
321 - }  
322 - return $aDocumentArray;  
323 - }  
324 - $_SESSION["errorMessage"] = $lang_err_database;  
325 - return false;  
326 - }  
327 -  
328 - /**  
329 - * Static function.  
330 - * Get all the document field's associated with a document type  
331 - *  
332 - * @param Document type primary key  
333 - * @param Get only the mandatory fields  
334 - *  
335 - * @return array array of document field objects, false otherwise and $_SESSION["errorMessage"]  
336 - */  
337 - function getDocumentFieldsForDocumentType($iDocumentTypeID, $bMandatoryOnly = false) {  
338 - $aDocumentFieldArray;  
339 - settype($aDocumentFieldArray,"array");  
340 - $sql = $default->db;  
341 - $result = $sql->query("SELECT DF.id AS id, DF.name AS name, DF.data_type AS data_type FROM document_fields AS DF INNER JOIN document_type_fields_link AS DTFL ON DF.id = DTFL.field_id WHERE DTFL.document_type_id = $iDocumentTypeID " . ($bMandatoryOnly ? "AND DFTL.is_mandatory = 1 " : " ") . "ORDER BY DF.name ASC");  
342 - if ($result) {  
343 - $iCount = 0;  
344 - while ($sql->next_record()) {  
345 - $oDocumentField = DocumentField::get($sql->f("id"));  
346 - if (!($oDocumentField === false)) {  
347 - $aDocumentFieldArray[$iCount] = $oDocumentField;  
348 - $iCount++;  
349 - }  
350 - }  
351 - return $aDocumentFieldArray;  
352 - }  
353 - $_SESSION["errorMessage"] = $lang_err_database;  
354 - return false;  
355 -  
356 - }  
357 -  
358 - /**  
359 - * Get a document's transaction history  
360 - *  
361 - * @return Array array of DocumentTransaction objects  
362 - *  
363 - */  
364 - function getDocumentHistory() {  
365 - global $default, $lang_err_database;  
366 - $aDocumentHistory;  
367 - settype($aDocumentHistory, "array");  
368 - $sql = $default->db;  
369 - $result = $sql->query("SELECT * FROM " . $default->owl_document_transactions_table . " WHERE document_id = $this->iId ORDER BY datetime ASC");  
370 - if ($result) {  
371 - $iCount = 0;  
372 - while($sql->next_record()) {  
373 - $oDocumentTransaction = DocumentTransaction::get($sql->f("id"));  
374 - $aDocumentHistory[$iCount] = $oDocumentTransaction;  
375 - $iCount++;  
376 - }  
377 - return $history;  
378 - }  
379 - $_SESSION["errorMessage"] = $lang_err_database;  
380 - return false;  
381 -  
382 - }  
383 -  
384 - /**  
385 - * Static function.  
386 - * Check if a document already exists  
387 - *  
388 - * @param String File name of document  
389 - * @param int Primary key of folder to which document is assigned  
390 - *  
391 - * @return boolean true if document exists, false otherwise and set $_SESSION["errorMessage"]  
392 - */  
393 - function documentExists($sFileName, $iFolderID) {  
394 - global $default, $lang_err_doc_not_exist;  
395 - $sql = $default->db;  
396 - $sql->query("SELECT * FROM $default->owl_documents_table WHERE name = '" . addslashes($sFileName) . "' AND folder_id = $iFolderID");  
397 - if ($sql->next_record()) {  
398 - return true;  
399 - }  
400 - $_SESSION["errorMessage"] = $lang_err_doc_not_exist . "name = " . $sName . " folder_id = " . $iFolderID;  
401 - return false;  
402 - }  
403 - 13 + /** primary key */
  14 + var $iId;
  15 + /** document type primary key */
  16 + var $iDocumentTypeID;
  17 + /** document name */
  18 + var $sName;
  19 + /** document file name (path to document on file system) */
  20 + var $sFileName;
  21 + /** document file size */
  22 + var $iSize;
  23 + /** primary key of user who created document */
  24 + var $iCreatorID;
  25 + /** date the document was last modified */
  26 + var $dModified;
  27 + /** file description */
  28 + var $sDescription;
  29 + /** primary key of file mime type */
  30 + var $iMimeTypeID;
  31 + /** primary key of folder under which document is stored */
  32 + var $iFolderID;
  33 + /** major revision number */
  34 + var $iMajorVersion;
  35 + /** minor revision number */
  36 + var $iMinorVersion;
  37 + /** document checked out status */
  38 + var $bIsCheckedOut;
  39 +
  40 + /**
  41 + * Document class constructor
  42 + *
  43 + * @param $sName File Name
  44 + * @param $iSize File size in bytes
  45 + * @param $iCreatorID Primary key of user who created document
  46 + * @param $sDescription Description
  47 + * @param $iMimeID Primary key of file mime type
  48 + * @param $iFolderID Primary key of folder to which document belongs
  49 + *
  50 + */
  51 + function Document($sNewName, $sNewFileName, $iNewSize, $iNewCreatorID, $iNewMimeID, $iNewFolderID, $sNewDescription = "None") {
  52 + $this->iId = -1; //primary key not set as document is not stored yet
  53 + $this->sName = $sNewName;
  54 + $this->iSize = $iNewSize;
  55 + $this->iCreatorID = $iNewCreatorID;
  56 + $this->sFileName = $sNewFileName;
  57 + $this->sDescription = $sNewDescription;
  58 + $this->iMimeTypeID = $iNewMimeID;
  59 + $this->iFolderID = $iNewFolderID;
  60 + $this->iDocumentTypeID = Folder::getFolderDocumentType($this->iFolderID);
  61 + $this->iMajorVersion = 0;
  62 + $this->iMinorVersion = 1;
  63 + $this->bIsCheckedOut = false;
  64 + }
  65 +
  66 + /** Get the document primary key */
  67 + function getID() {
  68 + return $this->iId;
  69 + }
  70 +
  71 + /** Get the document type id */
  72 + function getDocumentTypeID() {
  73 + return $this->iDocumentTypeID;
  74 + }
  75 +
  76 + /** set the document type id */
  77 + function setDocumentTypeID($sNewValue) {
  78 + $this->iDocumentTypeID = $sNewValue;
  79 + }
  80 +
  81 + /** get the document name */
  82 + function getName() {
  83 + return $this->sName;
  84 + }
  85 +
  86 + /** set the document name */
  87 + function setName($sNewValue) {
  88 + $this->sName = $sNewValue;
  89 + }
  90 +
  91 + /** get the document path on the file system */
  92 + function getFileName() {
  93 + return $this->sFileName;
  94 + }
  95 +
  96 + /** set the document path on the file system */
  97 + function setFileName() {
  98 + $this->sFileName = $sNewValue;
  99 + }
  100 +
  101 + /** get the primary key of the folder in which the document is stored */
  102 + function getFolderID() {
  103 + return $this->iFolderID;
  104 + }
  105 +
  106 + /** set the primary key of the folder in which the document is stored */
  107 + function setFolderID($iNewValue) {
  108 + $this->iFolderID = $iNewValue;
  109 + }
  110 +
  111 + /** get the document file size in bytes */
  112 + function getFileSize() {
  113 + return $this->iSize;
  114 + }
  115 +
  116 + /** set the document file size in bytes */
  117 + function setFileSize($iNewValue) {
  118 + $this->iSize = $iNewValue;
  119 + }
  120 +
  121 + /** get the document creator id */
  122 + function getCreatorID() {
  123 + return $this->iCreatorID;
  124 + }
  125 +
  126 + /** set the document creator id */
  127 + function setCreatorID($iNewValue) {
  128 + $this->iCreatorID = $iNewValue;
  129 + }
  130 +
  131 + /** get the document last modified date */
  132 + function getLastModifiedDate() {
  133 + return $this->dModified;
  134 + }
  135 +
  136 + /** set the document last modified date */
  137 + function setLastModifiedDate($dNewValue) {
  138 + $this->dModified = $dNewValue;
  139 + }
  140 +
  141 + /** get the document description */
  142 + function getDescription() {
  143 + return $this->sDescription;
  144 + }
  145 +
  146 + /** set the document description */
  147 + function setDescription($sNewValue) {
  148 + $this->sDescription = $sNewValue;
  149 + }
  150 +
  151 + /** get the document mime type primary key */
  152 + function getMimeTypeID() {
  153 + return $this->iMimeTypeID;
  154 + }
  155 +
  156 + /** get the document mime type primary key */
  157 + function setMimeTypeID($iNewValue) {
  158 + $this->iMimeTypeID = $iNewValue;
  159 + }
  160 +
  161 + /** get the major version number */
  162 + function getMajorVersionNumber() {
  163 + return $this->iMajorVersion;
  164 + }
  165 +
  166 + /** set the major version number */
  167 + function setMajorVersionNumber($iNewValue) {
  168 + $this->iMajorVersion = $iNewValue;
  169 + }
  170 +
  171 + /** get the minor version number */
  172 + function getMinorVersionNumber() {
  173 + return $this->iMinorVersion;
  174 + }
  175 +
  176 + /** set the minor version number */
  177 + function setMinorVersionNumber($iNewValue) {
  178 + $this->iMinorVersionNumber = $iNewValue;
  179 + }
  180 +
  181 + /** get the document check out status */
  182 + function getIsCheckedOut() {
  183 + return $this->bCheckedOut;
  184 + }
  185 +
  186 + /** set the document check out status */
  187 + function setIsCheckedOut($bNewValue) {
  188 + $this->bCheckedOut = $bNewValue;
  189 + }
  190 +
  191 + /**
  192 + * Insert the current document into the database
  193 + *
  194 + * @return boolean true on successful insert, false otherwise and set $_SESSION["errorMessage"]
  195 + */
  196 + function create() {
  197 + global $default, $lang_err_doc_exist, $lang_err_database;
  198 + //if the id >= 0, then the object has already been created
  199 + if ($this->iId < 0) {
  200 + $sql = $default->db;
  201 + $result = $sql->query("INSERT INTO " . $default->owl_documents_table . " (document_type_id, name, filename, size, creator_id, modified, description, mime_id, folder_id, major_version, minor_version, is_checked_out) " .
  202 + "VALUES (" . $this->iDocumentTypeID . ", '" . addslashes($this->sName) . "', '" . addslashes($this->sFileName) . "', $this->iSize, $this->iCreatorID, '" . getCurrentDateTime() . "', '" . addslashes($this->sDescription) . "', $this->iMimeTypeID, $this->iFolderID, $this->iMajorVersion, $this->iMinorVersion, " . ($this->bIsCheckedOut ? 1 : 0) . ")");
  203 + if ($result) {
  204 + //set the current documents primary key
  205 + $this->iId = $sql->insert_id();
  206 + return true;
  207 + }
  208 + $_SESSION["errorMessage"] = $lang_err_database;
  209 + return false;
  210 + }
  211 + $_SESSION["errorMessage"] = $lang_err_object_exists . "id = " . $this->iId . " table = documents";
  212 + return false;
  213 +
  214 + }
  215 +
  216 + /**
  217 + * Update the documents current values in the database
  218 + *
  219 + * @return boolean true on successful update, false otherwise and set $_SESSION["errorMessage"]
  220 + */
  221 + function update() {
  222 + global $default, $lang_err_database, $lang_err_object_key;
  223 + if ($this->iId >= 0) {
  224 + $sql = $default->db;
  225 + $result = $sql->query("UPDATE " . $default->owl_documents_table . " SET " .
  226 + "document_typeid = $this->iDocumentTypeID, " .
  227 + "file_name = '" . addslashes($this->file_name) . "', " .
  228 + "size = $this->iSize, " .
  229 + "creator_id = $this->iCreatorID, " .
  230 + "modified = " . getCurrentDateTime() . ", " .
  231 + "description = '" . addslashes($this->sDescription) . "', " .
  232 + "mime_id = $this->iMimeTypeID, " .
  233 + "folder_id = $this->iFolderID, " .
  234 + "major_revision = $this->iMajorRevision, " .
  235 + "minor_revision = $this->iMinorRevision, " .
  236 + "is_checked_out = $this->bIsCheckedOut " .
  237 + "WHERE id = $this->id");
  238 + if ($result) {
  239 + return true;
  240 + }
  241 + $_SESSION["errorMessage"] = $lang_err_database;
  242 + return false;
  243 + }
  244 + $_SESSION["errorMessage"] = $lang_err_object_key;
  245 + return false;
  246 +
  247 + }
  248 +
  249 + /**
  250 + * Delete the current document from the database. Set the primary key to -1
  251 + * on successful deletion
  252 + *
  253 + * @return boolean true and reset id to -1 on successful deletion, false otherwise and set $_SESSION["errorMessage"]
  254 + */
  255 + function delete() {
  256 + global $default, $lang_err_database, $lang_err_object_key;
  257 + if ($this->iId >= 0) {
  258 + $sql = $default->db;
  259 + $result = $sql->query("DELETE FROM " . $default->owl_documents_table . " WHERE id = $this->iId");
  260 + if ($result) {
  261 + $this->iId = -1;
  262 + return true;
  263 + }
  264 + $_SESSION["errorMessage"] = $lang_err_database;
  265 + return false;
  266 + }
  267 + $_SESSION["errorMessage"] = $lang_err_object_key;
  268 + return false;
  269 + }
  270 +
  271 +
  272 + /**
  273 + *
  274 + * Static function. Given a document primary key will create
  275 + * a document object and populate it with the corresponding
  276 + * database values
  277 + *
  278 + * @return Document populated Document object on success, false otherwise and set $_SESSION["errorMessage"]
  279 + */
  280 + function & get($iDocumentID) {
  281 + global $default, $lang_err_doc_not_exist;
  282 + $sql = $default->db;
  283 + $sql->query("SELECT * FROM $default->owl_documents_table WHERE id = $iDocumentID");
  284 + if ($sql->next_record()) {
  285 + $oDocument = & new Document(stripslashes($sql->f("name")), $sql->f("filename"), $sql->f("size"), stripslashes($sql->f("creator_id")), $sql->f("mime_id"), $sql->f("folder_id"), $sql->f("description"));
  286 + $oDocument->setDocumentTypeID($sql->f("document_type_id"));
  287 + $oDocument->setMajorVersionNumber($sql->f("major_version"));
  288 + $oDocument->setMinorVersionNumber($sql->f("minor_version"));
  289 + $oDocument->setIsCheckedOut($sql->f("is_checked_out"));
  290 + $oDocument->iId = $iDocumentID;
  291 + return $oDocument;
  292 + }
  293 + $_SESSION["errorMessage"] = $lang_err_object_not_exist . "id = " . $iDocumentID . " table = documents";
  294 + return false;
  295 + }
  296 +
  297 + /**
  298 + * Static function
  299 + * Get a list of Documents
  300 + *
  301 + * @param String Where clause (not required)
  302 + *
  303 + * @return Array array of Documents objects, false otherwise and set $_SESSION["errorMessage"]
  304 + */
  305 + function getList($sWhereClause = null) {
  306 + global $default, $lang_err_database;
  307 + $aDocumentArray;
  308 + settype($aDocumentArray, "array");
  309 + $sql = $default->db;
  310 + $result = $sql->query("SELECT * FROM " . $default->owl_documents_table . (isset($sWhereClause) ? " WHERE " . $sWhereClause : ""));
  311 + if ($result) {
  312 + $iCount = 0;
  313 + while ($sql->next_record()) {
  314 + $oDocument = & Document::get($sql->f("id"));
  315 + $aDocumentArray[$iCount] = $oDocument;
  316 + $iCount++;
  317 + }
  318 + return $aDocumentArray;
  319 + }
  320 + $_SESSION["errorMessage"] = $lang_err_database;
  321 + return false;
  322 + }
  323 +
  324 + /**
  325 + * Static function.
  326 + * Get all the document field's associated with a document type
  327 + *
  328 + * @param Document type primary key
  329 + * @param Get only the mandatory fields
  330 + *
  331 + * @return array array of document field objects, false otherwise and $_SESSION["errorMessage"]
  332 + */
  333 + function getDocumentFieldsForDocumentType($iDocumentTypeID, $bMandatoryOnly = false) {
  334 + $aDocumentFieldArray;
  335 + settype($aDocumentFieldArray,"array");
  336 + $sql = $default->db;
  337 + $result = $sql->query("SELECT DF.id AS id, DF.name AS name, DF.data_type AS data_type FROM document_fields AS DF INNER JOIN document_type_fields_link AS DTFL ON DF.id = DTFL.field_id WHERE DTFL.document_type_id = $iDocumentTypeID " . ($bMandatoryOnly ? "AND DFTL.is_mandatory = 1 " : " ") . "ORDER BY DF.name ASC");
  338 + if ($result) {
  339 + $iCount = 0;
  340 + while ($sql->next_record()) {
  341 + $oDocumentField = DocumentField::get($sql->f("id"));
  342 + if (!($oDocumentField === false)) {
  343 + $aDocumentFieldArray[$iCount] = $oDocumentField;
  344 + $iCount++;
  345 + }
  346 + }
  347 + return $aDocumentFieldArray;
  348 + }
  349 + $_SESSION["errorMessage"] = $lang_err_database;
  350 + return false;
  351 +
  352 + }
  353 +
  354 + /**
  355 + * Get a document's transaction history
  356 + *
  357 + * @return Array array of DocumentTransaction objects
  358 + *
  359 + */
  360 + function getDocumentHistory() {
  361 + global $default, $lang_err_database;
  362 + $aDocumentHistory;
  363 + settype($aDocumentHistory, "array");
  364 + $sql = $default->db;
  365 + $result = $sql->query("SELECT * FROM " . $default->owl_document_transactions_table . " WHERE document_id = $this->iId ORDER BY datetime ASC");
  366 + if ($result) {
  367 + $iCount = 0;
  368 + while($sql->next_record()) {
  369 + $oDocumentTransaction = DocumentTransaction::get($sql->f("id"));
  370 + $aDocumentHistory[$iCount] = $oDocumentTransaction;
  371 + $iCount++;
  372 + }
  373 + return $history;
  374 + }
  375 + $_SESSION["errorMessage"] = $lang_err_database;
  376 + return false;
  377 +
  378 + }
  379 +
  380 + /**
  381 + * Static function.
  382 + * Check if a document already exists
  383 + *
  384 + * @param String File name of document
  385 + * @param int Primary key of folder to which document is assigned
  386 + *
  387 + * @return boolean true if document exists, false otherwise and set $_SESSION["errorMessage"]
  388 + */
  389 + function documentExists($sFileName, $iFolderID) {
  390 + global $default, $lang_err_doc_not_exist;
  391 + $sql = $default->db;
  392 + $sql->query("SELECT * FROM $default->owl_documents_table WHERE name = '" . addslashes($sFileName) . "' AND folder_id = $iFolderID");
  393 + if ($sql->next_record()) {
  394 + return true;
  395 + }
  396 + $_SESSION["errorMessage"] = $lang_err_doc_not_exist . "name = " . $sName . " folder_id = " . $iFolderID;
  397 + return false;
  398 + }
  399 +
404 /** 400 /**
405 * Returns the url to the file type icon associated with this document 401 * Returns the url to the file type icon associated with this document
406 * 402 *
@@ -411,7 +407,7 @@ class Document { @@ -411,7 +407,7 @@ class Document {
411 if ($this->iMimeTypeID) { 407 if ($this->iMimeTypeID) {
412 // lookup the icon from the table 408 // lookup the icon from the table
413 $sIconPath = lookupField($default->owl_mime_table, "icon_path", "id", $this->iMimeTypeID); 409 $sIconPath = lookupField($default->owl_mime_table, "icon_path", "id", $this->iMimeTypeID);
414 - if (strlen($sIconPath) > 0) { 410 + if (strlen($sIconPath) > 0) {
415 return $default->owl_graphics_url . "/" . $sIconPath; 411 return $default->owl_graphics_url . "/" . $sIconPath;
416 } else { 412 } else {
417 return false; 413 return false;
@@ -420,23 +416,75 @@ class Document { @@ -420,23 +416,75 @@ class Document {
420 return false; 416 return false;
421 } 417 }
422 } 418 }
423 -  
424 - /** 419 +
  420 + /**
425 * Get the full path for a document as an array 421 * Get the full path for a document as an array
426 - *  
427 - * @param int primary key of document to generate path for  
428 * 422 *
  423 + * @param int primary key of document to generate path for
429 * @return array full path of document as an array 424 * @return array full path of document as an array
430 */ 425 */
431 function getDocumentPathAsArray($iDocumentID) { 426 function getDocumentPathAsArray($iDocumentID) {
432 - global $default; 427 + global $default;
433 // get the path of the folder as an array 428 // get the path of the folder as an array
434 $aPathArray = Folder::getFolderPathAsArray($this->iFolderID); 429 $aPathArray = Folder::getFolderPathAsArray($this->iFolderID);
435 // add the document to the path 430 // add the document to the path
436 $aPathArray[] = $this->sName; 431 $aPathArray[] = $this->sName;
437 $default->log->debug("Document::getDocumentPathAsArray path=" . arrayToString($aPathArray)); 432 $default->log->debug("Document::getDocumentPathAsArray path=" . arrayToString($aPathArray));
438 - return $aPathArray;  
439 - } 433 + return $aPathArray;
  434 + }
  435 +
  436 + /**
  437 + * Get the folder id for the document
  438 + *
  439 + * @param int the ID of the document to lookup the folderID for
  440 + * @return int folderID on success, false otherwise and set $_SESSION["errorMessage"]
  441 + */
  442 + function getFolderID($iDocumentID) {
  443 + global $default, $lang_err_database, $lang_err_doc_not_exist;
  444 + $sql = $default->db;
  445 + if ($sql->query("SELECT folder_id FROM " . $default->owl_documents_table . " WHERE id = $iDocumentID")) {
  446 + if ($sql->next_record()) {
  447 + return $sql->f("folder_id");
  448 + } else {
  449 + $_SESSION["errorMessage"] = $lang_err_doc_not_exist;
  450 + }
  451 + } else {
  452 + $_SESSION["errorMessage"] = $lang_err_database;
  453 + }
  454 + return false;
  455 + }
  456 +
  457 + /**
  458 + * Lookup the document name for the document
  459 + *
  460 + * @param int the ID of the document to lookup the document name for
  461 + * @return string the name of the document on success, false otherwise and set $_SESSION["errorMessage"]
  462 + */
  463 + function getDocumentName($iDocumentID) {
  464 + global $default, $lang_err_database, $lang_err_doc_not_exist;
  465 + $sql = $default->db;
  466 + if ($sql->query("SELECT name FROM " . $default->owl_documents_table . " WHERE id = $iDocumentID")) {
  467 + if ($sql->next_record()) {
  468 + return $sql->f("name");
  469 + } else {
  470 + $_SESSION["errorMessage"] = $lang_err_doc_not_exist;
  471 + }
  472 + } else {
  473 + $_SESSION["errorMessage"] = $lang_err_database;
  474 + }
  475 + return false;
  476 + }
  477 +
  478 + /**
  479 + * Static function.
  480 + * Get the path for a document that will be displayed to the user
  481 + *
  482 + * @param integer primary key of document to generate path for
  483 + * @return string full path to document
  484 + */
  485 + function getDocumentDisplayPath($iDocumentID) {
  486 + return Folder::getFolderDisplayPath(Document::getFolderID($iDocumentID)) . " > " . Document::getDocumentName($iDocumentID);
  487 + }
440 } 488 }
441 489
442 ?> 490 ?>