diff --git a/lib/browse/CategoryBrowser.inc b/lib/browse/CategoryBrowser.inc deleted file mode 100644 index 6a00f24..0000000 --- a/lib/browse/CategoryBrowser.inc +++ /dev/null @@ -1,132 +0,0 @@ -, Jam Warehouse (Pty) Ltd, South Africa - * @package lib.browse - */ -class CategoryBrowser extends Browser { - - /** - * Construct a new FolderBrowser instance with the specified sort criteria - * - * @param string the field to sort the results by - * @param string the direction to sort the results - */ - function CategoryBrowser($sSortField = "name", $sSortDirection = "asc", $aNewSortCriteria = array()) { - Browser::Browser($sSortField, $sSortDirection, $aNewSortCriteria); - } - - /** - * Browse the documents by category - * - * @return array categories and documents - */ - function browse() { - global $default; - - // XXX: Shouldn't be picking it out of $_REQUEST - $sCategoryName = $_REQUEST['fCategoryName']; - - // browsing by category - $this->setBrowseStart($sCategoryName); - $sCategoryName = $sCategoryName; - - // TODO: add this to default inserts - $categoryField = "Category"; - $results = array(); - $sql = $default->db; - - // lookup document_fields id for category - $categoryFieldID = lookupID($default->document_fields_table, "name", "$categoryField"); - $default->log->debug("CategoryBrowser::browse() categoryFieldID=$categoryFieldID"); - - if ($sCategoryName == "") { - if ($categoryFieldID) { - // no category value supplied, so return a list of categories - // set the first value to "categories" - $results["categories"][] = "Categories"; - // get a list of category values - // FIXME: exclude deleted document metadata - $query = "SELECT DISTINCT value FROM $default->document_fields_link_table WHERE document_field_id = ? ORDER BY value " . ($this->sSortField == "name" ? $this->sSortDirection : "ASC");/*ok*/ - $aParams = array($categoryFieldID); - $default->log->info("CategoryBrowser::browse() category listing query=$query; $this->sSortField"); - $sql->query(array($query, $aParams)); - // loop through resultset, build array and return - while ($sql->next_record()) { - $results["categories"][] = $sql->f("value"); - } - } - // its ok if we return an empty array- the UI's responsibility to check and print an error - return $results; - } else { - $aLookupCriteria = $this->aSortCriteria[$this->sSortField]["lookup"]; - - $results["categories"][] = $sCategoryName; - - // we have a category to use, so find all the documents - // with this category value - $categoryQuery = "SELECT df.document_id FROM $default->document_fields_link_table df " . /*ok*/ - "INNER JOIN $default->documents_table d ON df.document_id = d.id "; - if ( isset($aLookupCriteria) ) { - $categoryQuery .= "INNER JOIN " . $aLookupCriteria["table"] . " lt ON "; - $categoryQuery .= "d.$this->sSortField" . "=lt." . (isset($aLookupCriteria["joinColumn"]) ? $aLookupCriteria["joinColumn"] : "id"); - } - $categoryQuery .= " WHERE df.document_field_id = ? AND value = ? " . (isset($aLookupCriteria["whereClause"]) ? "AND lt." . $aLookupCriteria["whereClause"] : "") . " ";; - $aParams = array($categoryFieldID, $sCategoryName); - if ( isset($aLookupCriteria) ) { - $categoryQuery .= "ORDER BY lt." . $aLookupCriteria["field"] . " $this->sSortDirection"; - } else { - $categoryQuery .= "ORDER BY d.$this->sSortField $this->sSortDirection"; - } - - - $default->log->debug("categoryQuery=$categoryQuery"); - - $sql->query(array($categoryQuery, $aParams)); - // loop through resultset and add to array - $results["accessDenied"] = false; - while ($sql->next_record()) { - $oDocument = & Document::get($sql->f("document_id")); - // only if the document is live - if ($oDocument->isLive()) { - if (Permission::userHasDocumentReadPermission($oDocument)) { - $results["documents"][] = $oDocument; - } else { - $results["accessDenied"] = true; - } - } - } - - return $results; - } - } - - function getSectionName() { - return "Manage Categories"; - } -} diff --git a/lib/browse/DocumentTypeBrowser.inc b/lib/browse/DocumentTypeBrowser.inc deleted file mode 100644 index 3bbddf6..0000000 --- a/lib/browse/DocumentTypeBrowser.inc +++ /dev/null @@ -1,122 +0,0 @@ -, Jam Warehouse (Pty) Ltd, South Africa - * @package lib.browse - */ -class DocumentTypeBrowser extends Browser { - - /** - * Construct a new FolderBrowser instance with the specified sort criteria - * - * @param string the field to sort the results by - * @param string the direction to sort the results - */ - function DocumentTypeBrowser($sSortField = "name", $sSortDirection = "asc", $aNewSortCriteria = array()) { - Browser::Browser($sSortField, $sSortDirection, $aNewSortCriteria); - } - - /** - * Browse the documents by document type - * - * @return array document types and documents - */ - function browse() { - global $default; - - // XXX: Shouldn't be getting this from $_REQUEST - $iDocumentTypeID = $_REQUEST['fDocumentTypeID']; - - // browsing by document type id - $this->setBrowseStart($iDocumentTypeID); - $iDocumentTypeID = $iDocumentTypeID; - - $results = array(); - $sql = $default->db; - - if ($iDocumentTypeID == "") { - // no document type id supplied, so return a list of document types - // set the first value to "Document Types" - $results["documentTypes"][] = array("name" => "Document Types"); - - // return a list of document types - /*ok*/$query = "SELECT * FROM $default->document_types_table ORDER BY name " . ($this->sSortField == "name" ? $this->sSortDirection : "ASC"); - - $sql->query($query); - while ($sql->next_record()) { - $results["documentTypes"][] = array ("id" => $sql->f("id"), "name" => $sql->f("name")); - } - return $results; - } else { - $aLookupCriteria = $this->aSortCriteria[$this->sSortField]["lookup"]; - - // lookup document type name from the passed in id - $documentTypeName = lookupField($default->document_types_table, "name", "id", $iDocumentTypeID); - $results["documentTypes"][] = array("id" => $iDocumentTypeID, "name" => $documentTypeName); - - // create query to retrieve documents with this document type - $documentQuery = "SELECT d.id as id FROM $default->documents_table d ";/*wc*/ - if ( isset($aLookupCriteria) ) { - //$documentQuery .= "INNER JOIN " . $aLookupCriteria["table"] . " lt ON d.$this->sSortField=lt.id "; - $documentQuery .= "INNER JOIN " . $aLookupCriteria["table"] . " lt ON "; - $documentQuery .= "d.$this->sSortField" . "=lt." . (isset($aLookupCriteria["joinColumn"]) ? $aLookupCriteria["joinColumn"] : "id"); - - } - //$documentQuery .= "WHERE document_type_id=$iDocumentTypeID "; - $documentQuery .= " WHERE document_type_id=$iDocumentTypeID " . (isset($aLookupCriteria["whereClause"]) ? "AND lt." . $aLookupCriteria["whereClause"] : "") . " "; - if ( isset($aLookupCriteria) ) { - $documentQuery .= "ORDER BY lt." . $aLookupCriteria["field"] . " $this->sSortDirection"; - } else { - $documentQuery .= "ORDER BY $this->sSortField $this->sSortDirection"; - } - - $default->log->debug("docTypeQuery=$documentQuery"); - - // loop through resultset and populate array with document objects - $sql->query($documentQuery); - $results["accessDenied"] = false; - while ($sql->next_record()) { - $oDocument = & Document::get($sql->f("id")); - // proceed if the document is live - if ($oDocument->isLive()) { - if (Permission::userHasDocumentReadPermission($oDocument)) { - $results["documents"][] = $oDocument; - } else { - $results["accessDenied"] = true; - } - } - } - $default->log->debug("DocumentTypeBrowser::browse() results=" . arrayToString($results)); - - return $results; - } - } - - function getSectionName() { - return "Manage Document Types"; - } -} diff --git a/lib/documentmanagement/Document.inc b/lib/documentmanagement/Document.inc index 83d0e77..cd5baa0 100644 --- a/lib/documentmanagement/Document.inc +++ b/lib/documentmanagement/Document.inc @@ -367,11 +367,12 @@ class Document { * Deletes content from document data tables */ function cleanupDocumentData($iDocumentID) { - global $default; - $sql = $default->db; - - $result = $sql->query("DELETE FROM $default->document_text_table WHERE document_id = $iDocumentID"); - return $result; + // FIXME this appears to be deprecated, or at least should be + $sTable = KTUtil::getTableName('document_text') + $sQuery = "DELETE FROM $sTable WHERE document_id = ?"; + $aParams = array($iDocumentID); + $res = DBUtil::runQuery(array($sQuery, $aParams)); + return $res; } // }}} diff --git a/lib/documentmanagement/DocumentField.inc b/lib/documentmanagement/DocumentField.inc index e9e5884..c775e50 100644 --- a/lib/documentmanagement/DocumentField.inc +++ b/lib/documentmanagement/DocumentField.inc @@ -142,37 +142,16 @@ class DocumentField extends KTEntity { * * @return DocumentFieldLink populated DocumentFieldLink object on success, false otherwise and set $_SESSION["errorMessage"] */ - function getAllDataTypes() { - global $default, $lang_err_database; - $aDataTypes; - settype($aDataTypes, "array"); - $sql = $default->db; - $result = $sql->query("SELECT id, name FROM " . $default->data_types_table );/*ok*/ - if ($result) { - $iCount = 0; - while ($sql->next_record()) { - - $aDataTypes[$iCount]["id"] = $sql->f("id"); - $aDataTypes[$iCount]["name"] = $sql->f("name"); - $iCount++; - } - return $aDataTypes; - } - $_SESSION["errorMessage"] = $lang_err_database; - return false; - } - function getLookupCount($iDocumentFieldID){ - global $default; - - $sql = $default->db; - $result = $sql->query(array("SELECT COUNT(*) AS count FROM " . $default->metadata_table . " WHERE document_field_id = ?", $iDocumentFieldID));/*ok*/ - if ($result) { - if ($sql->next_record()) { - return $sql->f("count"); - } - } - return false; + $sTable = 'metadata'; + $sQuery = "SELECT COUNT(*) AS count FROM " . $sTable . " WHERE document_field_id = ?"; + $aParams = array($iDocumentFieldID); + + $res = DBUtil::getOneResultKey(array($sQuery, $aParams), 'count'); + if (PEAR::isError($res)) { + return false; // return $res; + } + return $res; } function getType() { diff --git a/lib/documentmanagement/DocumentFieldLink.inc b/lib/documentmanagement/DocumentFieldLink.inc index bc1a311..26d5f2a 100644 --- a/lib/documentmanagement/DocumentFieldLink.inc +++ b/lib/documentmanagement/DocumentFieldLink.inc @@ -129,8 +129,7 @@ class DocumentFieldLink extends KTEntity { } function _table () { - global $default; - return $default->document_fields_link_table; + KUtil::getTableName('document_fields_link'); } /** diff --git a/lib/documentmanagement/DocumentType.inc b/lib/documentmanagement/DocumentType.inc index 92e9b17..d5fb9d6 100644 --- a/lib/documentmanagement/DocumentType.inc +++ b/lib/documentmanagement/DocumentType.inc @@ -157,33 +157,6 @@ class DocumentType extends KTEntity { function &getFieldsets() { return KTFieldset::getForDocumentType($this); } - - - /** - * Static function. - * Given a document_fields primary key it will create a - * DocumentTypes object and populate it with the - * corresponding database values - * - * @return DocumentType populated DocumentType object on successful query, false otherwise and set $_SESSION["errorMessage"] - */ - function & get($iDocumentTypeID) { - global $default; - $sql = $default->db; - $result = $sql->query(array("SELECT * FROM ". $default->document_types_table ." WHERE id = ?", $iDocumentTypeID));/*ok*/ - if ($result) { - if ($sql->next_record()) { - $oDocumentType = & new DocumentType($sql->f("name")); - $oDocumentType->iId = $sql->f("id"); - $oDocumentType->bDisabled = $sql->f("disabled"); - return $oDocumentType; - } - $_SESSION["errorMessage"] = $lang_err_object_not_exist . "id = " . $iDocumentID . " table = document_types"; - return false; - } - $_SESSION["errorMessage"] = $lang_err_database; - return false; - } /** * Static- Get a list document types; diff --git a/lib/documentmanagement/MetaData.inc b/lib/documentmanagement/MetaData.inc index 0ad2c9b..00a8925 100644 --- a/lib/documentmanagement/MetaData.inc +++ b/lib/documentmanagement/MetaData.inc @@ -86,39 +86,24 @@ class MetaData extends KTEntity { return KTEntityUtil::get('MetaData', $iId); } -/* - * static function - * - * sets the id of the groupunit using their groupid - * - * @param String - * The unit_ID - * - */ - + // FIXME this function makes no sense. function setMetaDataID($iDocFieldId, $sMetaDataName) { - global $default; - $sql = $default->db; - $sQuery = "SELECT id FROM $default->metadata_table WHERE document_field_id = ? and name = ?";/*ok*/ - $aParams = array($iDocFieldId, $sMetaDataName); - $result = $sql->query(array($sQuery, $aParams)); - if ($result) { - if ($sql->next_record()) { - $id = $sql->f("id"); - - }else{ - $_SESSION["errorMessage"] = $lang_err_database; - return false; - } - - }else{ - $_SESSION["errorMessage"] = $lang_err_database; - return false; - } - - $this->iId = $id; - + $sTable = KTUtil::getTableName('metadata'); + $sQuery = "SELECT id FROM $sTable WHERE document_field_id = ? and name = ?"; + $aParams = array($iDocFieldId, $sMetaDataName); + $res = DBUtil::getResultArray(array($sQuery, $aParams)); + + if (PEAR::isError($res)) { + return false; // return $res; + } + + if (count($res) != 0) { + $this->iId = $id; + return $res[0]['id']; + } else { + return false; // return PEAR::raiseError(_kt('No such plugin pack')) + } } function getList($sWhereClause = null) {