Commit d990808ad2e675918716ae7a6192c2af4b88b21a
1 parent
89f6a530
Initial revision
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@97 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
3 changed files
with
372 additions
and
0 deletions
lib/documentmanagement/documentManager.inc
0 → 100644
| 1 | +<?php | |
| 2 | + | |
| 3 | +/** | |
| 4 | +* Class DocumentManager | |
| 5 | +* | |
| 6 | +* Contains all functions required for document management, | |
| 7 | +* such as the creation/deletion/removal of document types. | |
| 8 | +* | |
| 9 | +* @author Rob Cherry, Jam Warehouse (Pty) Ltd, South Africa | |
| 10 | +* @date 8 January 2003 | |
| 11 | +* | |
| 12 | +* @todo Complete updateDocumentType() function | |
| 13 | +* | |
| 14 | +*/ | |
| 15 | + | |
| 16 | +require_once ("$default->owl_root_url/lib/owl.lib.php"); | |
| 17 | + | |
| 18 | +class DocumentManager { | |
| 19 | + | |
| 20 | + /** | |
| 21 | + * Create a new document type | |
| 22 | + * | |
| 23 | + * @param $sName Name of new document type | |
| 24 | + * | |
| 25 | + * @return true on successful creation, false otherwise and set $default->errorMessage | |
| 26 | + */ | |
| 27 | + function createDocumentType($sName) { | |
| 28 | + //escape all the necessary characters that may affect db query | |
| 29 | + $sName = addslashes($sName); | |
| 30 | + //Get hold of the global error string | |
| 31 | + global $default; | |
| 32 | + //if the document type doesn't exist | |
| 33 | + if (!($this->documentTypeExists($sName))) { | |
| 34 | + $sql = new Owl_DB(); | |
| 35 | + $result = $sql->query("INSERT INTO " . $default->owl_document_types_table . " (name) values ('" . $sName . "')"); | |
| 36 | + if (!$result) { | |
| 37 | + $default->errorMessage = "Database Error. Failed to insert document type " . $sName; | |
| 38 | + return false; | |
| 39 | + } | |
| 40 | + return true; | |
| 41 | + } | |
| 42 | + $default->errorMessage = "A document type with this name already exists"; | |
| 43 | + return false; | |
| 44 | + } | |
| 45 | + | |
| 46 | + /** | |
| 47 | + * Delete an existing document type | |
| 48 | + * | |
| 49 | + * @param $sName Name of document type to delete | |
| 50 | + * | |
| 51 | + * @return true on successful removal, false otherwise and set $default->errorMessage | |
| 52 | + */ | |
| 53 | + function deleteDocumentType($sName) { | |
| 54 | + //escape all the necessary characters that may affect db query | |
| 55 | + $sName = addslashes($sName); | |
| 56 | + //Get hold of the global error string | |
| 57 | + global $default; | |
| 58 | + //only remove the document type if it exists | |
| 59 | + if ($this->documentTypeExists($sName)) { | |
| 60 | + $sql = new Owl_DB(); | |
| 61 | + $result = $sql->query("DELETE FROM " . $default->owl_document_types_table . " WHERE name = '" . $sName . "'"); | |
| 62 | + if (!$result) { | |
| 63 | + $default->errorMessage = "Database Error. Failed to delete document type " . $sName; | |
| 64 | + return false; | |
| 65 | + } | |
| 66 | + return true; | |
| 67 | + } | |
| 68 | + $default->errorMessage = "There is no document type with this name"; | |
| 69 | + return false; | |
| 70 | + } | |
| 71 | + | |
| 72 | + /** | |
| 73 | + * Update a document type | |
| 74 | + * | |
| 75 | + * @param $iDocumentTypeID Primary key of document type to updatee | |
| 76 | + * @param $sName New document type name | |
| 77 | + * | |
| 78 | + * @return true on successful update, false otherwise and set $default->errorMessage | |
| 79 | + */ | |
| 80 | + function updateDocumentType($iDocumentTypeID, $sName) { | |
| 81 | + | |
| 82 | + } | |
| 83 | + | |
| 84 | + /** | |
| 85 | + * Checks to see if a document type with a given name | |
| 86 | + * already exists | |
| 87 | + * | |
| 88 | + * @param $sName Name of document type to check | |
| 89 | + * | |
| 90 | + * @return true if the document type exists, false otherwise | |
| 91 | + */ | |
| 92 | + function documentTypeExists($sName) { | |
| 93 | + //escape all the necessary characters that may affect db query | |
| 94 | + $sName = addslashes($sName); | |
| 95 | + //Get hold of the global error string | |
| 96 | + global $default; | |
| 97 | + $sql = new Owl_DB(); | |
| 98 | + $sql->query("SELECT * FROM " . $default->owl_document_types_table . " WHERE Name = '" . $sName . "'"); | |
| 99 | + return $sql->next_record(); | |
| 100 | + } | |
| 101 | + | |
| 102 | + /** | |
| 103 | + * Link a document type field with a specific document type | |
| 104 | + * | |
| 105 | + * @param $iDocumentTypeID Primary key of document type | |
| 106 | + * @param $iDocumentTypeFieldID Primary key of document field type | |
| 107 | + * @param $bIsMandatory Whether or not the field is mandatory | |
| 108 | + * | |
| 109 | + * @return true on successful creation, false otherwise and set $default->errorMessage | |
| 110 | + */ | |
| 111 | + function createDocumentTypeFieldLink($iDocumentTypeID, $iDocumentTypeFieldID, $bIsMandatory) { | |
| 112 | + //Get hold of the global error string | |
| 113 | + global $default; | |
| 114 | + //if the document field type is not associated with the document | |
| 115 | + if (!$this->documentTypeFieldExistsForDocumentType($iDocumentTypeID, $iDocumentTypeFieldID)) { | |
| 116 | + $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 . ")"); | |
| 118 | + if (!$result) { | |
| 119 | + $default->errorMessage = "Database Error. Failed to insert document field type with ID " . $iDocumentTypeFieldID; | |
| 120 | + return false; | |
| 121 | + } | |
| 122 | + return true; | |
| 123 | + } | |
| 124 | + $default->errorMessage = "This field type is already linked to this document type"; | |
| 125 | + return false; | |
| 126 | + } | |
| 127 | + | |
| 128 | + /** | |
| 129 | + * Delete the link between a document type field and a specific document type | |
| 130 | + * | |
| 131 | + * @param $iDocumentTypeID Primary key of document type | |
| 132 | + * @param $iDocumentTypeFieldID Primary key of document type field | |
| 133 | + */ | |
| 134 | + function deleteDocumentTypeFieldLink($iDocumentTypeID, $iDocumentTypeFieldID) { | |
| 135 | + //Get hold of the global error string | |
| 136 | + global $default; | |
| 137 | + if ($this->documentTypeFieldExistsForDocumentType($iDocumentTypeID, $iDocumentTypeFieldID)) { | |
| 138 | + $sql = new Owl_DB(); | |
| 139 | + $result = $sql->query("DELETE FROM " . $default->document_type_fields_table . " where document_type_id = " . $iDocumentTypeID . " AND field_id = " . $iDocumentTypeFieldID); | |
| 140 | + if (!result) { | |
| 141 | + $default->errorMessage = "Database Error. Failed to deleted document type field with document_type_id " . $iDocumentTypeID . " and field_id " . $iDocumentTypeFieldID; | |
| 142 | + return false; | |
| 143 | + } | |
| 144 | + return true; | |
| 145 | + } | |
| 146 | + $default->errorMessage = "A dcoument field type with document_type_id " . $iDocumentTypeID . " and a document_id " . $iDocumentTypeID . " does not exist"; | |
| 147 | + return false; | |
| 148 | + } | |
| 149 | + | |
| 150 | + | |
| 151 | + /** | |
| 152 | + * Checks to see if the given document type field is already linked to the given | |
| 153 | + * document type. | |
| 154 | + * | |
| 155 | + * @param $iDocumentTypeID Primary key of document type | |
| 156 | + * @param $iDocumentTypeFieldID Primary key of document field type | |
| 157 | + * | |
| 158 | + * @return true is the document field type is linked to the document type, false otherwise | |
| 159 | + */ | |
| 160 | + function documentTypeFieldExistsForDocumentType($iDocumentTypeID, $iDocumentTypeFieldID) { | |
| 161 | + $sql = new Owl_DB(); | |
| 162 | + $sql->query("SELECT * FROM " . $default->document_type_fields_table . " WHERE document_type_id = " . $iDocumentTypeID . " AND field_id = " . $iDocumentTypeFieldID); | |
| 163 | + return $sql->next_record(); | |
| 164 | + } | |
| 165 | + | |
| 166 | + /** | |
| 167 | + * Creates a document type field | |
| 168 | + * | |
| 169 | + * @param $sName Document type field name | |
| 170 | + * @param $sDataType Field data type | |
| 171 | + * | |
| 172 | + * @return true on successful insertion, false otherwise and sets $default->errorMessage | |
| 173 | + */ | |
| 174 | + function createDocumentTypeField($sName, $sDataType) { | |
| 175 | + //escape all the necessary characters that may affect db query | |
| 176 | + $sName = addslashes($sName); | |
| 177 | + $sDataType = addslashes($sDataType); | |
| 178 | + //Get hold of the global error string | |
| 179 | + global $default; | |
| 180 | + if (!$this->documentTypeFieldExists($sName)) { | |
| 181 | + $sql = new Owl_DB(); | |
| 182 | + $result = $sql->query("INSERT INTO " . $default->owl_fields_table . " (name, data_type) VALUES ('" . $sName . "', '" . $sDataType . "')"); | |
| 183 | + if (!$result) { | |
| 184 | + $default->errorMessage = "Database Error. Could not insert document field " . $sName . " with data type " . $sDataType . " into table " . $default->owl_fields_table; | |
| 185 | + return false; | |
| 186 | + } | |
| 187 | + return true; | |
| 188 | + } | |
| 189 | + $default->errorMessage = "A document type field with this name already exists"; | |
| 190 | + return false; | |
| 191 | + } | |
| 192 | + | |
| 193 | + /** | |
| 194 | + * Deletes a document type field | |
| 195 | + * | |
| 196 | + * @param $sName Name of document field type to delete | |
| 197 | + * | |
| 198 | + * @return true on successful deletion, false otherwise and set $default->errorMessage | |
| 199 | + */ | |
| 200 | + function deleteDocumentTypeField($sName) { | |
| 201 | + //escape any characters that may affect db query | |
| 202 | + $sName = addslashes($sName); | |
| 203 | + //Get hold of the global error string | |
| 204 | + global $default; | |
| 205 | + if ($this->documentTypeFieldExists($sName)) { | |
| 206 | + $sql = new Owl_DB(); | |
| 207 | + $result = $sql->query("DELETE FROM " . $default->owl_fields_table . " WHERE Name = '" . $sName . "'"); | |
| 208 | + if (!$result) { | |
| 209 | + $default->errorMessage = "Database Error. Could not delete document type field " . $sName . " from table " . $default->owl_field_table; | |
| 210 | + return false; | |
| 211 | + } | |
| 212 | + return true; | |
| 213 | + } | |
| 214 | + $default->errorMessage = "A document type field with the name " . $sName . " does not exist"; | |
| 215 | + return false; | |
| 216 | + } | |
| 217 | + | |
| 218 | + /** | |
| 219 | + * Checks whether a document type field exists | |
| 220 | + * | |
| 221 | + * @param $sName Document type field name to check | |
| 222 | + * | |
| 223 | + * @return true if document type field exists, false otherwise | |
| 224 | + */ | |
| 225 | + function documentTypeFieldExists($sName) { | |
| 226 | + global $default; | |
| 227 | + $sql = new Owl_DB(); | |
| 228 | + $sql->query("SELECT * FROM " . $default->owl_fields_table . " WHERE name = '" . $sName . "'"); | |
| 229 | + return $sql->next_record(); | |
| 230 | + } | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | +} | |
| 235 | + | |
| 236 | + | |
| 237 | +?> | ... | ... |
tests/documentmanagement/documentTypeTest.php
0 → 100644
| 1 | +<?php | |
| 2 | + | |
| 3 | +/** | |
| 4 | +* Unit tests for ./lib/documentmanagement/DocumentManager class, | |
| 5 | +* document type functionality | |
| 6 | +* | |
| 7 | +*/ | |
| 8 | + | |
| 9 | +require_once ("../../../config/dmsDefaults.php"); | |
| 10 | +require_once ("$default->owl_root_url/lib/owl.lib.php"); | |
| 11 | +require_once ("../../../lib/documentmanagement/documentManager.inc"); | |
| 12 | + | |
| 13 | +/** | |
| 14 | +* Database backend unit tests for: | |
| 15 | +* o Document type (document_types) | |
| 16 | +* o Field (fields) | |
| 17 | +* | |
| 18 | +* @author Rob Cherry, Jam Warehouse (Pty Ltd), South Africa | |
| 19 | +* @date 9 January 2003 | |
| 20 | +*/ | |
| 21 | + | |
| 22 | +//test creation of document type | |
| 23 | + | |
| 24 | +global $default; | |
| 25 | + | |
| 26 | +$docManager = new DocumentManager(); | |
| 27 | + | |
| 28 | +if ($docManager->createDocumentType("Test")) { | |
| 29 | + echo "Passed document type creation test<br>"; | |
| 30 | +} else { | |
| 31 | + echo "Failed 'document type creation' test: " . $default->errorMessage . "<br>"; | |
| 32 | +} | |
| 33 | + | |
| 34 | +//test creation of duplicate document types | |
| 35 | +if (!$docManager->createDocumentType("Test")) { | |
| 36 | + echo "Passed 'duplicate document type creation' test<br>"; | |
| 37 | +} else { | |
| 38 | + echo "Failed duplicate document type creation test<br>"; | |
| 39 | +} | |
| 40 | + | |
| 41 | +//test deletion of an existing document type | |
| 42 | +if ($docManager->deleteDocumentType("Test")) { | |
| 43 | + echo "Passed 'existing document type deletion' test<br>"; | |
| 44 | +} else { | |
| 45 | + echo "Failed existing document type deletion test<br>"; | |
| 46 | +} | |
| 47 | + | |
| 48 | +//test deletion of a document type that doesn't exist | |
| 49 | +if (!$docManager->deleteDocumentType("Does not exist")) { | |
| 50 | + echo "Passed 'deletion of non-existing document type' test<br>"; | |
| 51 | +} else { | |
| 52 | + echo "Failed 'deletion of non-existant document type' test<br>"; | |
| 53 | +} | |
| 54 | + | |
| 55 | +/** | |
| 56 | +* | |
| 57 | +* Field type tests | |
| 58 | +* | |
| 59 | +*/ | |
| 60 | + | |
| 61 | +//test creation of a field | |
| 62 | +if ($docManager->createDocumentTypeField("Test Field","VARCHAR")) { | |
| 63 | + echo "Passed 'creation of document type field' test<br>"; | |
| 64 | +} else { | |
| 65 | + echo "Failed 'creation of document type field' test<br>"; | |
| 66 | +} | |
| 67 | + | |
| 68 | +//test creation of duplicate field | |
| 69 | +if (!($docManager->createDocumentTypeField("Test Field","VARCHAR"))) { | |
| 70 | + echo "Passed 'creation of duplicate document type field ' test<br>"; | |
| 71 | +} else { | |
| 72 | + echo "Failed 'creation of duplicated document type field ' test<br>: $default->errorMessage"; | |
| 73 | +} | |
| 74 | + | |
| 75 | +//test deletion of a field | |
| 76 | +if ($docManager->deleteDocumentTypeField("Test Field")) { | |
| 77 | + echo "Passed 'deletion of document type field ' test<br>"; | |
| 78 | +} else { | |
| 79 | + echo "Failed 'deletion of document type field ' test<<br>"; | |
| 80 | +} | |
| 81 | + | |
| 82 | +//test deletion of a non-existant field | |
| 83 | +if (!$docManager->deleteDocumentTypeField("Test Field that doesn't exist")) { | |
| 84 | + echo "Passed 'deletion of non-existant document type field ' test<br>"; | |
| 85 | +} else { | |
| 86 | + echo "Failed 'deletion of non-existant document type field ' test<<br>"; | |
| 87 | +} | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | +?> | ... | ... |
tests/visualpatterns/test.php
0 → 100644
| 1 | +<?php | |
| 2 | +require_once ("./config/dmsDefaults.php"); | |
| 3 | +require_once ("./lib/owl.lib.php"); | |
| 4 | +require_once ("./lib/documentmanagement/documentManager.inc"); | |
| 5 | + | |
| 6 | +echo DocumentManager::createDocumentType("bobby"); | |
| 7 | +/* | |
| 8 | +//--------------------------------------------------------- | |
| 9 | +require_once ("./lib/visualpatterns/PatternMainPage.inc"); | |
| 10 | +require_once ("./lib/visualpatterns/PatternImage.inc"); | |
| 11 | +require_once ("./lib/visualpatterns/PatternTableLinks.inc"); | |
| 12 | +require_once ("./lib/visualpatterns/PatternTableSqlQuery.inc"); | |
| 13 | + | |
| 14 | + | |
| 15 | +//North west image | |
| 16 | +$img = new PatternImage("file://C:/temp/test/al.jpg"); | |
| 17 | + | |
| 18 | +//build the top menu of links | |
| 19 | +$aTopMenuLinks = array(0=>"www.google.com",1=>"www.yahoo.com",2=>"www.msn.com"); | |
| 20 | +$aTopMenuText = array(0=>"google",1=>"yahoo",2=>"msn"); | |
| 21 | +$oPatternTableLinks = new PatternTableLinks($aTopMenuLinks, $aTopMenuText, 3, 1); | |
| 22 | + | |
| 23 | +//build the central grid for paging through results | |
| 24 | +$aCentralPageColumns = array(0=>"name",1=>"parent",2=>"security"); | |
| 25 | +$aColumnTypes = array(0=>1,1=>2,2=>1); | |
| 26 | +$oTableSqlQuery = & new PatternTableSqlQuery("Folders", $aCentralPageColumns, $aColumnTypes); | |
| 27 | +($HTTP_GET_VARS["fStartIndex"]) ? $oTableSqlQuery->setStartIndex($HTTP_GET_VARS["fStartIndex"]) : $oTableSqlQuery->setStartIndex(0); | |
| 28 | +$oTableSqlQuery->setLinkType(1); | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | +//get a page | |
| 33 | +$tmp = new PatternMainPage(); | |
| 34 | + | |
| 35 | +//put the page together | |
| 36 | +$tmp->setNorthWestPayload($img); | |
| 37 | +$tmp->setNorthPayload($oPatternTableLinks); | |
| 38 | +$tmp->setCentralPayload($oTableSqlQuery); | |
| 39 | +$tmp->setFormAction("Navigate.inc"); | |
| 40 | +$tmp->render(); | |
| 41 | +*/ | |
| 42 | +?> | ... | ... |