Commit a8667673724be82bd2b6b60ee3f910583debf054

Authored by rob
1 parent af52c24a

Altered some outputs


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@348 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing 1 changed file with 136 additions and 105 deletions
lib/documentmanagement/Document.inc
@@ -65,111 +65,6 @@ class Document { @@ -65,111 +65,6 @@ class Document {
65 $this->bIsCheckedOut = false; 65 $this->bIsCheckedOut = false;
66 } 66 }
67 67
68 - /**  
69 - * Insert the current document into the database  
70 - *  
71 - * @return boolean true on successful insert, false otherwise and set $_SESSION["errorMessage"]  
72 - */  
73 - function create() {  
74 - global $default, $lang_err_doc_exist, $lang_err_database;  
75 - //if the id >= 0, then the object has already been created  
76 - if ($this->iId < 0) {  
77 - $sql = new Owl_DB();  
78 - $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) " .  
79 - "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) . ")");  
80 - if ($result) {  
81 - //set the current documents primary key  
82 - $this->iId = $sql->insert_id();  
83 - return true;  
84 - }  
85 - $_SESSION["errorMessage"] = $lang_err_database;  
86 - return false;  
87 - }  
88 - $_SESSION["errorMessage"] = $lang_err_object_exists . "id = " . $this->iId . " table = documents";  
89 - return false;  
90 -  
91 - }  
92 -  
93 - /**  
94 - * Update the documents current values in the database  
95 - *  
96 - * @return boolean true on successful update, false otherwise and set $_SESSION["errorMessage"]  
97 - */  
98 - function update() {  
99 - global $default, $lang_err_database, $lang_err_object_key;  
100 - if ($this->iId >= 0) {  
101 - $sql = new Owl_DB();  
102 - $result = $sql->query("UPDATE " . $default->owl_documents_table . " SET " .  
103 - "document_typeid = $this->iDocumentTypeID, " .  
104 - "file_name = '" . addslashes($this->file_name) . "', " .  
105 - "size = $this->iSize, " .  
106 - "creator_id = $this->iCreatorID, " .  
107 - "modified = " . getCurrentDateTime() . ", " .  
108 - "description = '" . addslashes($this->sDescription) . "', " .  
109 - "mime_id = $this->iMimeTypeID, " .  
110 - "folder_id = $this->iFolderID, " .  
111 - "major_revision = $this->iMajorRevision, " .  
112 - "minor_revision = $this->iMinorRevision, " .  
113 - "is_checked_out = $this->bIsCheckedOut " .  
114 - "WHERE id = $this->id");  
115 - if ($result) {  
116 - return true;  
117 - }  
118 - $_SESSION["errorMessage"] = $lang_err_database;  
119 - return false;  
120 - }  
121 - $_SESSION["errorMessage"] = $lang_err_object_key;  
122 - return false;  
123 -  
124 - }  
125 -  
126 - /**  
127 - * Delete the current document from the database. Set the primary key to -1  
128 - * on successful deletion  
129 - *  
130 - * @return boolean true and reset id to -1 on successful deletion, false otherwise and set $_SESSION["errorMessage"]  
131 - */  
132 - function delete() {  
133 - global $default, $lang_err_database, $lang_err_object_key;  
134 - if ($this->iId >= 0) {  
135 - $sql = new Owl_DB();  
136 - $result = $sql->query("DELETE FROM " . $default->owl_documents_table . " WHERE id = $this->iId");  
137 - if ($result) {  
138 - $this->iId = -1;  
139 - return true;  
140 - }  
141 - $_SESSION["errorMessage"] = $lang_err_database;  
142 - return false;  
143 - }  
144 - $_SESSION["errorMessage"] = $lang_err_object_key;  
145 - return false;  
146 - }  
147 -  
148 -  
149 - /**  
150 - *  
151 - * Static function. Given a document primary key will create  
152 - * a document object and populate it with the corresponding  
153 - * database values  
154 - *  
155 - * @return Document populated Document object on success, false otherwise and set $_SESSION["errorMessage"]  
156 - */  
157 - function & get($iDocumentID) {  
158 - global $default, $lang_err_doc_not_exist;  
159 - $sql = new Owl_DB();  
160 - $sql->query("SELECT * FROM " . $default->owl_documents_table . " WHERE id = " . $iDocumentID);  
161 - if ($sql->next_record()) {  
162 - $doc = & 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"));  
163 - $doc->setDocumentTypeID($sql->f("document_type_id"));  
164 - $doc->setMajorVersionNumber($sql->f("major_version"));  
165 - $doc->setMinorVersionNumber($sql->f("minor_version"));  
166 - $doc->setIsCheckedOut($sql->f("is_checked_out"));  
167 - return $doc;  
168 - }  
169 - $_SESSION["errorMessage"] = $lang_err_object_not_exist . "id = " . $iDocumentID . " table = documents";  
170 - return false;  
171 - }  
172 -  
173 /** Get the document primary key */ 68 /** Get the document primary key */
174 function getID() { 69 function getID() {
175 return $this->iID; 70 return $this->iID;
@@ -295,6 +190,142 @@ class Document { @@ -295,6 +190,142 @@ class Document {
295 $this->bCheckedOut = $bNewValue; 190 $this->bCheckedOut = $bNewValue;
296 } 191 }
297 192
  193 + /**
  194 + * Insert the current document into the database
  195 + *
  196 + * @return boolean true on successful insert, false otherwise and set $_SESSION["errorMessage"]
  197 + */
  198 + function create() {
  199 + global $default, $lang_err_doc_exist, $lang_err_database;
  200 + //if the id >= 0, then the object has already been created
  201 + if ($this->iId < 0) {
  202 + $sql = new Owl_DB();
  203 + $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) " .
  204 + "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) . ")");
  205 + if ($result) {
  206 + //set the current documents primary key
  207 + $this->iId = $sql->insert_id();
  208 + return true;
  209 + }
  210 + $_SESSION["errorMessage"] = $lang_err_database;
  211 + return false;
  212 + }
  213 + $_SESSION["errorMessage"] = $lang_err_object_exists . "id = " . $this->iId . " table = documents";
  214 + return false;
  215 +
  216 + }
  217 +
  218 + /**
  219 + * Update the documents current values in the database
  220 + *
  221 + * @return boolean true on successful update, false otherwise and set $_SESSION["errorMessage"]
  222 + */
  223 + function update() {
  224 + global $default, $lang_err_database, $lang_err_object_key;
  225 + if ($this->iId >= 0) {
  226 + $sql = new Owl_DB();
  227 + $result = $sql->query("UPDATE " . $default->owl_documents_table . " SET " .
  228 + "document_typeid = $this->iDocumentTypeID, " .
  229 + "file_name = '" . addslashes($this->file_name) . "', " .
  230 + "size = $this->iSize, " .
  231 + "creator_id = $this->iCreatorID, " .
  232 + "modified = " . getCurrentDateTime() . ", " .
  233 + "description = '" . addslashes($this->sDescription) . "', " .
  234 + "mime_id = $this->iMimeTypeID, " .
  235 + "folder_id = $this->iFolderID, " .
  236 + "major_revision = $this->iMajorRevision, " .
  237 + "minor_revision = $this->iMinorRevision, " .
  238 + "is_checked_out = $this->bIsCheckedOut " .
  239 + "WHERE id = $this->id");
  240 + if ($result) {
  241 + return true;
  242 + }
  243 + $_SESSION["errorMessage"] = $lang_err_database;
  244 + return false;
  245 + }
  246 + $_SESSION["errorMessage"] = $lang_err_object_key;
  247 + return false;
  248 +
  249 + }
  250 +
  251 + /**
  252 + * Delete the current document from the database. Set the primary key to -1
  253 + * on successful deletion
  254 + *
  255 + * @return boolean true and reset id to -1 on successful deletion, false otherwise and set $_SESSION["errorMessage"]
  256 + */
  257 + function delete() {
  258 + global $default, $lang_err_database, $lang_err_object_key;
  259 + if ($this->iId >= 0) {
  260 + $sql = new Owl_DB();
  261 + $result = $sql->query("DELETE FROM " . $default->owl_documents_table . " WHERE id = $this->iId");
  262 + if ($result) {
  263 + $this->iId = -1;
  264 + return true;
  265 + }
  266 + $_SESSION["errorMessage"] = $lang_err_database;
  267 + return false;
  268 + }
  269 + $_SESSION["errorMessage"] = $lang_err_object_key;
  270 + return false;
  271 + }
  272 +
  273 +
  274 + /**
  275 + *
  276 + * Static function. Given a document primary key will create
  277 + * a document object and populate it with the corresponding
  278 + * database values
  279 + *
  280 + * @return Document populated Document object on success, false otherwise and set $_SESSION["errorMessage"]
  281 + */
  282 + function & get($iDocumentID) {
  283 + global $default, $lang_err_doc_not_exist;
  284 + $sql = new Owl_DB();
  285 + $sql->query("SELECT * FROM " . $default->owl_documents_table . " WHERE id = " . $iDocumentID);
  286 + if ($sql->next_record()) {
  287 + $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"));
  288 + $oDocument->setDocumentTypeID($sql->f("document_type_id"));
  289 + $oDocument->setMajorVersionNumber($sql->f("major_version"));
  290 + $oDocument->setMinorVersionNumber($sql->f("minor_version"));
  291 + $oDocument->setIsCheckedOut($sql->f("is_checked_out"));
  292 + $oDocument->iId = $iDocumentID;
  293 + return $doc;
  294 + }
  295 + $_SESSION["errorMessage"] = $lang_err_object_not_exist . "id = " . $iDocumentID . " table = documents";
  296 + return false;
  297 + }
  298 +
  299 + /**
  300 + * Static function.
  301 + * Get all the document field's associated with a document type
  302 + *
  303 + * @param Document type primary key
  304 + * @param Get only the mandatory fields
  305 + *
  306 + * @return array array of document field objects, false otherwise and $_SESSION["errorMessage"]
  307 + */
  308 + function getDocumentFieldsForDocumentType($iDocumentTypeID, $bMandatoryOnly = false) {
  309 + $aDocumentFieldArray;
  310 + settype($aDocumentFieldArray,"array");
  311 + $sql = new Owl_DB();
  312 + $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");
  313 + if ($result) {
  314 + $iCount = 0;
  315 + while ($sql->next_record()) {
  316 + $oDocumentField = DocumentField::get($sql->f("id"));
  317 + if (!($oDocumentField === false)) {
  318 + $aDocumentFieldArray[$iCount] = $oDocumentField;
  319 + $iCount++;
  320 + }
  321 + }
  322 + return $aDocumentFieldArray;
  323 + }
  324 + $_SESSION["errorMessage"] = $lang_err_database;
  325 + return false;
  326 +
  327 + }
  328 +
298 } 329 }
299 330
300 ?> 331 ?>