Commit 13acb6f059d70e95ec20d9a2a718beae5efa2267

Authored by rob
1 parent 6cff93be

Added document type, document link type functionality


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@106 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/documentmanagement/documentManager.inc
@@ -81,6 +81,29 @@ class DocumentManager { @@ -81,6 +81,29 @@ class DocumentManager {
81 81
82 } 82 }
83 83
  84 +
  85 + /**
  86 + * Get the primary key for a document type
  87 + *
  88 + * @param $sName Name of document type to get ID for
  89 + *
  90 + * @return int document type id if the document type exists, false otherwise
  91 + */
  92 + function & getDocumentTypeID($sName) {
  93 + global $lang_err_document_type_field_does_not_exist, $default;
  94 + //escape special characters that may interfere with the db query
  95 + $sName = addslashes($sName);
  96 +
  97 + if ($this->documentTypeExists($sName)) {
  98 + $sql = new Owl_DB();
  99 + $sql->query("SELECT ID FROM " . $default->owl_document_types_table . " WHERE name = '" . $sName . "'");
  100 + $sql->next_record();
  101 + return $sql->f("ID");
  102 + }
  103 + $default->errorMessage = $lang_err_document_type_does_not_exist . $sName;
  104 + return false;
  105 + }
  106 +
84 /** 107 /**
85 * Checks to see if a document type with a given name 108 * Checks to see if a document type with a given name
86 * already exists 109 * already exists
@@ -112,9 +135,9 @@ class DocumentManager { @@ -112,9 +135,9 @@ class DocumentManager {
112 //Get hold of the global error string 135 //Get hold of the global error string
113 global $default; 136 global $default;
114 //if the document field type is not associated with the document 137 //if the document field type is not associated with the document
115 - if (!$this->documentTypeFieldExistsForDocumentType($iDocumentTypeID, $iDocumentTypeFieldID)) { 138 + if (!($this->documentTypeFieldExistsForDocumentType($iDocumentTypeID, $iDocumentTypeFieldID))) {
116 $sql = new Owl_DB(); 139 $sql = new Owl_DB();
117 - $result = $sql->query("INSERT INTO " . $default->document_type_fields_table . " (document_type_id, field_id, is_mandatory) VALUES (" . $iDocumentTypeID . ", " . $iDocumentTypeFieldID . ", " . $bIsMandatory . ")"); 140 + $result = $sql->query("INSERT INTO " . $default->owl_document_type_fields_table . " (document_type_id, field_id, is_mandatory) VALUES (" . $iDocumentTypeID . ", " . $iDocumentTypeFieldID . ", " . $bIsMandatory . ")");
118 if (!$result) { 141 if (!$result) {
119 $default->errorMessage = "Database Error. Failed to insert document field type with ID " . $iDocumentTypeFieldID; 142 $default->errorMessage = "Database Error. Failed to insert document field type with ID " . $iDocumentTypeFieldID;
120 return false; 143 return false;
@@ -132,11 +155,12 @@ class DocumentManager { @@ -132,11 +155,12 @@ class DocumentManager {
132 * @param $iDocumentTypeFieldID Primary key of document type field 155 * @param $iDocumentTypeFieldID Primary key of document type field
133 */ 156 */
134 function deleteDocumentTypeFieldLink($iDocumentTypeID, $iDocumentTypeFieldID) { 157 function deleteDocumentTypeFieldLink($iDocumentTypeID, $iDocumentTypeFieldID) {
  158 + global $default;
135 //Get hold of the global error string 159 //Get hold of the global error string
136 global $default; 160 global $default;
137 if ($this->documentTypeFieldExistsForDocumentType($iDocumentTypeID, $iDocumentTypeFieldID)) { 161 if ($this->documentTypeFieldExistsForDocumentType($iDocumentTypeID, $iDocumentTypeFieldID)) {
138 $sql = new Owl_DB(); 162 $sql = new Owl_DB();
139 - $result = $sql->query("DELETE FROM " . $default->document_type_fields_table . " where document_type_id = " . $iDocumentTypeID . " AND field_id = " . $iDocumentTypeFieldID); 163 + $result = $sql->query("DELETE FROM " . $default->owl_document_type_fields_table . " where document_type_id = " . $iDocumentTypeID . " AND field_id = " . $iDocumentTypeFieldID);
140 if (!result) { 164 if (!result) {
141 $default->errorMessage = "Database Error. Failed to deleted document type field with document_type_id " . $iDocumentTypeID . " and field_id " . $iDocumentTypeFieldID; 165 $default->errorMessage = "Database Error. Failed to deleted document type field with document_type_id " . $iDocumentTypeID . " and field_id " . $iDocumentTypeFieldID;
142 return false; 166 return false;
@@ -157,9 +181,10 @@ class DocumentManager { @@ -157,9 +181,10 @@ class DocumentManager {
157 * 181 *
158 * @return true is the document field type is linked to the document type, false otherwise 182 * @return true is the document field type is linked to the document type, false otherwise
159 */ 183 */
160 - function documentTypeFieldExistsForDocumentType($iDocumentTypeID, $iDocumentTypeFieldID) { 184 + function documentTypeFieldExistsForDocumentType($iDocumentTypeID, $iDocumentTypeFieldID) {
  185 + global $default;
161 $sql = new Owl_DB(); 186 $sql = new Owl_DB();
162 - $sql->query("SELECT * FROM " . $default->document_type_fields_table . " WHERE document_type_id = " . $iDocumentTypeID . " AND field_id = " . $iDocumentTypeFieldID); 187 + $sql->query("SELECT * FROM " . $default->owl_document_type_fields_table . " WHERE document_type_id = " . $iDocumentTypeID . " AND field_id = " . $iDocumentTypeFieldID);
163 return $sql->next_record(); 188 return $sql->next_record();
164 } 189 }
165 190
@@ -216,6 +241,26 @@ class DocumentManager { @@ -216,6 +241,26 @@ class DocumentManager {
216 } 241 }
217 242
218 /** 243 /**
  244 + * Get the primary key for a document type field
  245 + *
  246 + * @param $sName Document type field name to get primary key for
  247 + *
  248 + * @return ID if document type field exists, false otherwise and sets $default->errorMessage
  249 + */
  250 + function & getDocumentTypeFieldID($sName) {
  251 + global $lang_err_document_type_field_does_not_exist, $default;
  252 + $sName = addslashes($sName);
  253 + if ($this->documentTypeFieldExists($sName)) {
  254 + $sql = new Owl_DB();
  255 + $sql->query("SELECT id FROM " . $default->owl_fields_table . " WHERE name = '" . $sName . "'");
  256 + $sql->next_record();
  257 + return $sql->f("id");
  258 + }
  259 + $default->errorMessage = $lang_err_document_type_field_does_not_exist . $sName;
  260 + return false;
  261 + }
  262 +
  263 + /**
219 * Checks whether a document type field exists 264 * Checks whether a document type field exists
220 * 265 *
221 * @param $sName Document type field name to check 266 * @param $sName Document type field name to check
@@ -232,6 +277,4 @@ class DocumentManager { @@ -232,6 +277,4 @@ class DocumentManager {
232 277
233 278
234 } 279 }
235 -  
236 -  
237 ?> 280 ?>