fileSystemRoot/presentation/Html.inc"); require_once("$default->uiDirectory/foldermanagement/folderUI.inc"); require_once("$default->uiDirectory/documentmanagement/documentUI.inc"); require_once("$default->uiDirectory/foldermanagement/addFolderUI.inc"); /** * $Id$ * * Document browsing page html UI building functions. * * Copyright (c) 2003 Jam Warehouse http://www.jamwarehouse.com * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * @version $Revision$ * @author Michael Joseph , Jam Warehouse (Pty) Ltd, South Africa * @package documentmanagement */ /** * Generates radio button selects for document browse by type * Javascript refreshes the form when it changes * * @param string the selected browse by option */ function renderBrowseTypeSelect($sBrowseType) { global $browse_view_documents_by_heading, $browse_view_documents_by_folder, $browse_view_documents_by_category, $browse_view_documents_by_doctype; // TODO: write function for onChange that checks if the new value return "\n \t" . $browse_view_documents_by_heading . ": " . $browse_view_documents_by_folder ."\n" . " " . $browse_view_documents_by_category . "\n" . " " . $browse_view_documents_by_doctype . "\n"; } // /** * Displays the passed category path as a link * * @param string the category name to display */ function displayCategoryPathLink($aCategories) { // if the first value in arr["categories"] == Categories then we've got a list of categories if ($aCategories[0] == "Categories") { return displayCategoryLink($aCategories[0]); } else { // else the first entry is the category name, so build a little path return displayCategoryLink("Categories") . ($aCategories[0] ? " > " . displayCategoryLink($aCategories[0]) : ""); } } /** * Displays the passed category as a link * * @param string the category name to display */ function displayCategoryLink($sCategoryName) { if ($sCategoryName != "") { return generateLink($_SERVER["PHP_SELF"], "fBrowseType=category" . // if the category title is passed in, link back to the list of categories (($sCategoryName == "Categories") ? "" : "&fCategoryName=" . urlencode($sCategoryName)), $sCategoryName); } else { return false; } } /** * Displays the results for category browsing * * @param array the category browse results */ function renderCategoryResults($aResults) { $sToRender = ""; //var_dump($aResults["categories"][0]); // if the first value in arr["categories"] == Categories then we've got a list of categories if ($aResults["categories"][0] == "Categories") { // loop through categories and display them for ($i=1; $i"; // category name $sToRender .= "" . displayCategoryLink($aResults["categories"][$i]) . ""; // blank filename $sToRender .= " "; // creator name $sToRender .= " "; // modified date $sToRender .= " "; // document type $sToRender .= " "; $sToRender .= "\n"; } } else { if (count($aResults["categories"]) > 0) { // else the first entry is the category name, so display the documents in the category $sToRender .= renderDocumentList($aResults, "This category contains no documents", "You don't have access to the documents in this category"); } else { $sToRender .= "There is no Category Document Field- contact a System Administrator."; } } return $sToRender; } // // /** * Displays the passed document type path as a link * * @param string the document type to display */ function displayDocumentTypePathLink($aDocumentTypes) { // if the first value in arr["categories"] == Categories then we've got a list of categories if ($aDocumentTypes[0]["name"] == "Document Types") { return displayDocumentTypeLink($aDocumentTypes[0]); } else { // else the first entry is the category name, so build a little path return displayDocumentTypeLink(array("name"=>"Document Types")) . " > " . displayDocumentTypeLink($aDocumentTypes[0]); } } /** * Displays the passed document type as a link * * @param string the document type to display */ function displayDocumentTypeLink($aDocumentType) { return generateLink($_SERVER["PHP_SELF"], "fBrowseType=documentType" . // if the document type title is passed in, link back to the list of document types (($aDocumentType["name"] == "Document Types") ? "" : "&fDocumentTypeID=" . $aDocumentType["id"]), $aDocumentType["name"]); } /** * Displays the results for document type browsing * * @param array the document type browse results */ function renderDocumentTypeResults($aResults) { $sToRender = ""; // if the first value in arr["documentTypes"] == Document Types then we've got a list of document types if ($aResults["documentTypes"][0]["name"] == "Document Types") { // loop through document types and display them for ($i=1; $i"; // document type name $sToRender .= "" . displayDocumentTypeLink($aResults["documentTypes"][$i]) . ""; // blank filename $sToRender .= " "; // creator name $sToRender .= " "; // modified date $sToRender .= " "; // document type $sToRender .= " "; $sToRender .= "\n"; } } else { // else the first entry is the document type name, so display the documents in the document type $sToRender .= renderDocumentList($aResults, "This document type contains no documents", "You don't have access to the documents in this document type"); } return $sToRender; } // // /** * Displays the folders in the browse results * * @param array the browse result objects */ function renderFolderResults($aResults, $bTemplateBrowsing = false) { global $default, $browse_no_sub_folders, $browse_no_documents, $browse_no_document_permission; $sToRender = ""; // now loop through the rest of the folders and display links if (count($aResults["folders"]) > 1) { for ($i=1; $igetCreatorID()); // the first element of the array contains the current folder name $sToRender .= ""; // folder name $sToRender .= "" . $sFolderLink . ""; // blank filename (folder description?) $sToRender .= "" . $aResults["folders"][$i]->getDescription() . ""; // creator name $sToRender .= "" . ($oCreator ? $oCreator->getName() : " ") . ""; // modified date (TODO: add to db) $sToRender .= " "; // document type (??: display one of the mapped document types? which one?) $sToRender .= " "; $sToRender .= "\n"; } } else { $sToRender .= "" . $browse_no_sub_folders . ""; } $sToRender .= "" . renderDocumentList($aResults, $browse_no_documents, $browse_no_document_permission, false, $bTemplateBrowsing) . "\n"; return $sToRender; } // /** * Displays the headings for the displayed document details and enables * resorting the contents * * @param string the field currently sorting by * @param string the direction currently sorted in */ function renderSortHeadings($sSortBy, $sSortDirection) { global $default, $oBrowser, $fBrowseType, $fFolderID, $fCategoryName, $fDocumentTypeID; $sSectionName = $default->siteMap->getSectionName(substr($_SERVER["PHP_SELF"], strlen($default->rootUrl), strlen($_SERVER["PHP_SELF"]))); $sTDBGColour = $default->siteMap->getSectionColour($sSectionName, "td"); // need list of display criteria and sort name $aSortCriteria = $oBrowser->getSortCriteria(); $sToRender .= ""; while (list($key, $value) = each ($aSortCriteria)) { $sCurrentSortDirection = "asc"; $displayText = $value["display"]; // if the current heading is being sorted then flip the sort direction if ($sSortBy == $key) { $sCurrentSortDirection = ($sSortDirection == "asc" ? "desc" : "asc"); $displayText = "graphicsUrl/" . $sCurrentSortDirection . ".gif\">" . $displayText; } switch ($fBrowseType) { case "folder" : $queryString = "fFolderID=$fFolderID"; break; case "category" : $queryString = "fCategoryName=$fCategoryName"; break; case "documentType" : $queryString = "fDocumentTypeID=$fDocumentTypeID"; break; } $sToRender .= "" . generateLink($_SERVER["PHP_SELF"], "fBrowseType=$fBrowseType&$queryString&fSortBy=$key&fSortDirection=$sCurrentSortDirection", $displayText) . ""; } $sToRender .= "\n"; return $sToRender; } /** * Displays the documents in the browse results * * @param array the browse result objects * @param string the message to display if there are no documents * @param string the message to display if the current user doesn't have permission to view the documents * @param boolean whether to display the complete path to the document or not */ function renderDocumentList($aResults, $sNoDocumentsMessage, $sNoPermissionMessage, $bDisplayFullPath = false, $bTemplateBrowsing = false) { global $default; $iFolderCount = count($aResults["folders"]) - 1; // loop through the files and display links if (count($aResults["documents"]) > 0) { for ($i=0; $i" . ($bTemplateBrowsing ? displayDocumentLinkForTemplateBrowsing($aResults["documents"][$i], $bDisplayFullPath) : displayDocumentLink($aResults["documents"][$i], $bDisplayFullPath)) . ""; // #3425 the title is now the filename, and the description is the title $sToRender .= "" . $aResults["documents"][$i]->getName() . ""; $oCreator = User::get($aResults["documents"][$i]->getCreatorID()); $sToRender .= "" . ($oCreator ? $oCreator->getName() : "") . ""; $aDocumentTransaction = DocumentTransaction::getList("transaction_id=1 AND document_id=" . $aResults["documents"][$i]->getID()); $sToRender .= "" . $aDocumentTransaction[0]->dDateTime . ""; $oDocumentType = DocumentType::get($aResults["documents"][$i]->getDocumentTypeID()); if ($oDocumentType) { $sToRender .= "" . $oDocumentType->getName() . ""; } $sToRender .= "\n"; } } else if ($aResults["accessDenied"]) { $sToRender .= "$sNoPermissionMessage"; } else { $sToRender .= "$sNoDocumentsMessage"; } return $sToRender; } /** * #3426 * Appends folder and document counts to the last folder path */ function appendCounts($aFolderPath, $iFolderCount, $iDocumentCount) { // append to the last path component and return $aFolderPath[count($aFolderPath)-1] = $aFolderPath[count($aFolderPath)-1] . " ($iFolderCount folder" . (($iFolderCount > 1) || ($iFolderCount == 0) ? "s" : "") . ", $iDocumentCount document" . (($iDocumentCount > 1) || ($iDocumentCount == 0) ? "s" : "") . ")"; return $aFolderPath; } /** * Displays the browse page- lists folders and documents * * @param array the browse results to display * @param string the browse view (folder, category, document type) * @param string the field to sort the results by * @param string the direction to sort */ function renderPage($aResults, $sBrowseType, $sSortBy, $sSortDirection, $bTemplateBrowsing = false) { global $default, $browse_collection_heading; $sSectionName = $default->siteMap->getSectionName(substr($_SERVER["PHP_SELF"], strlen($default->rootUrl), strlen($_SERVER["PHP_SELF"]))); $sTDBGColour = $default->siteMap->getSectionColour($sSectionName, "td"); $sToRender = renderHeading($browse_collection_heading); $sToRender .= "
"; switch ($sBrowseType) { case "folder" : $sToRender .= displayFolderPathLink(Folder::getFolderPathAsArray($aResults["folders"][0]->getID()), appendCounts(Folder::getFolderPathNamesAsArray($aResults["folders"][0]->getID()), count($aResults["folders"])-1, count($aResults["documents"]))); break; case "category" : $sToRender .= displayCategoryPathLink($aResults["categories"]); break; case "documentType" : $sToRender .= displayDocumentTypePathLink($aResults["documentTypes"]); break; } $sToRender .= "
\n"; // browse type select $sToRender .= "\n"; $sToRender .= "\t"; $sToRender .= "\t
" . renderBrowseTypeSelect($sBrowseType) . "
"; // display folders|documents $sToRender .= "\n"; $sToRender .= renderSortHeadings($sSortBy, $sSortDirection); $sToRender .= "\n"; $sToRender .= "\t
\n"; switch ($sBrowseType) { case "folder" : $sToRender .= renderFolderResults($aResults, $bTemplateBrowsing); break; case "category" : $sToRender .= renderCategoryResults($aResults); break; case "documentType" : $sToRender .= renderDocumentTypeResults($aResults); break; } $sToRender .= "
"; return $sToRender; } ?>