Commit f0a9c0b7652e070ef9dbfd471695515da6d028a6

Authored by michael
1 parent 1f1cd630

added lookups relative to userID instead of expecting organisation and unit iden…

…tifiers to be on the session


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@328 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/documentmanagement/DocumentBrowser.inc
... ... @@ -26,33 +26,47 @@ class DocumentBrowser {
26 26  
27 27 if ($folderID == -1) {
28 28 // no folder specified, so start at the root for this users organisation
29   - // TODO: organisationID (and name) should be on session
  29 +
  30 + // lookup this users groups
  31 + $groupIDs = lookupGroupIDs($_SESSION["userID"]);
  32 + $default->log->debug("DocumentBrowser::browseByFolder: groupIDs=" . arrayToString($groupIDs));
30 33  
31   - // TODO: use the organisation to find the root folder
32   - if (!isset($_SESSION["organisationName"])) {
33   - $_SESSION["organisationName"] = "MRC";
34   - }
35   - $rootFolderName = $_SESSION["organisationName"] . " Document Root";
  34 + // look up this users unit
  35 + // FIXME: what if the user belongs to multiple units?
  36 + $unitID = lookupID($default->owl_groups_units_table, "group_id", $groupIDs[0]);
  37 + // lookup the unit name
  38 + $unitName = lookupField($default->owl_units_table, "name", "id", $unitID);
  39 + $default->log->debug("DocumentBrowser::browseByFolder: unitID=$unitID; unitName=$unitName");
  40 +
  41 + // look up the organisation name for this user
  42 + $organisationID = lookupField($default->owl_units_table, "organisation_id", "id", $unitID);
  43 + $organisationName = lookupField($default->owl_organisations_table, "name", "id", $organisationID);
  44 + $default->log->debug("DocumentBrowser::browseByFolder: organisationID=$organisationID; orgName=$organisationName");
  45 +
  46 + // construct the folder name from the organisation
  47 + $rootFolderName = $organisationName . " Document Root";
  48 +
36 49 // lookup the id of the root folder
37   - $folderID = lookupID($default->owl_folders_table, "name", "'$rootFolderName'");
  50 + $folderID = lookupID($default->owl_folders_table, "name", "$rootFolderName");
  51 + $default->log->debug("DocumentBrowser::browseByFolder: folderID=$folderID");
38 52  
39 53 // if this is a system administrator, start her at the ROOT
40 54 // TODO: add to default->sysadmin_group
41   - if ($this->checkGroup("System Administrators", $_SESSION["groupID"])) {
  55 + if ($this->checkGroup("System Administrators", $groupIDs)) {
42 56 $folderQuery = "SELECT * FROM $default->owl_folders_table WHERE name='$rootFolderName'";
43 57 } else {
44 58 // otherwise start everyone relative to their unit
45 59  
46 60 // FIXME: actually need to lookup the unit root folder- which should map to the unitname
47 61 // and descend directly from the organisation document root
48   - $unitRootFolder = $_SESSION["unitName"] . " Document Root";
  62 +
  63 + $default->log->debug("DocumentBrowser::browseByFolder: unitName=$unitName");
  64 +
  65 + $unitRootFolder = $unitName . " Document Root";
49 66  
50   - $unitID = $_SESSION["unitID"];
51 67 // lookup descendant folders with the appropriate unit set
52 68 $folderQuery = "SELECT * from $default->owl_folders_table " .
53   - "WHERE unit_id=" . $unitID .
54   - " AND parent_id='$folderID'" .
55   - " AND name='$unitRootFolder'";
  69 + "WHERE name='$unitRootFolder'";
56 70 }
57 71 } else {
58 72 // start from the specified folder
... ... @@ -121,7 +135,7 @@ class DocumentBrowser {
121 135 $sql = new Owl_DB();
122 136  
123 137 // lookup document_fields id for category
124   - $categoryFieldID = lookupID($default->owl_fields_table, "name", "'$categoryField'");
  138 + $categoryFieldID = lookupID($default->owl_fields_table, "name", "$categoryField");
125 139 $default->log->debug("DocumentBrowser::browseByCategory categoryFieldID=$categoryFieldID");
126 140  
127 141 if ($category == "") {
... ... @@ -216,7 +230,7 @@ class DocumentBrowser {
216 230 global $default;
217 231 $sql = new Owl_DB();
218 232 // lookup the id of $requiredGroupName
219   - $requiredGroupID = lookupID($default->owl_groups_table, "name", "'$requiredGroupName'");
  233 + $requiredGroupID = lookupID($default->owl_groups_table, "name", "$requiredGroupName");
220 234 $default->log->debug("DocumentBrowser::checkGroup reqGrpID=$requiredGroupID");
221 235 if ($requiredGroupID) {
222 236 // now loop through the array and check if we're in the group
... ...