Commit 03754f49cb0e9de980a4151d5345143bc0fe198e

Authored by nbm
1 parent c983afe6

Add browseToUnitFolder, defaulting to false, which determines whether

the user browses to the root folder first, or to their (first) unit
folder.


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@5093 c91229c3-7414-0410-bfa2-8a42b809f60b
browse.php
... ... @@ -109,9 +109,17 @@ class BrowseDispatcher extends KTStandardDispatcher {
109 109  
110 110 // if we're going to main ...
111 111 if ($this->browse_mode == 'folder') {
112   -
113   -
114   - $in_folder_id = KTUtil::arrayGet($_REQUEST, "fFolderId", 1);
  112 + $in_folder_id = KTUtil::arrayGet($_REQUEST, "fFolderId");
  113 + if (empty($in_folder_id)) {
  114 + $oConfig = KTConfig::getSingleton();
  115 + if ($oConfig->get('tweaks/browseToUnitFolder')) {
  116 + $iHomeFolderId = $this->oUser->getHomeFolderId();
  117 + if ($iHomeFolderId) {
  118 + $in_folder_id = $iHomeFolderId;
  119 + }
  120 + }
  121 + }
  122 +
115 123 $folder_id = (int) $in_folder_id; // conveniently, will be 0 if not possible.
116 124 if ($folder_id == 0) {
117 125 $folder_id = 1;
... ...
config/config.ini
... ... @@ -104,6 +104,10 @@ useAcceptLanguageHeader = true
104 104 ; file, change the following to true
105 105 phpErrorLogFile = false
106 106  
  107 +; Whether to browse to the user's (first) unit when first going to the
  108 +; browse section
  109 +browseToUnitFolder = default
  110 +
107 111 [email]
108 112 ; email settings
109 113 emailServer = localhost
... ...
config/dmsDefaults.php
... ... @@ -412,7 +412,7 @@ $oKTConfig->setdefaultns("KnowledgeTree", "execSearchPath", $_SERVER['PATH']);
412 412 $oKTConfig->setdefaultns("KnowledgeTree", "pathInfoSupport", false);
413 413 $oKTConfig->setdefaultns("storage", "manager", 'KTOnDiskPathStorageManager');
414 414 $oKTConfig->setdefaultns("config", "useDatabaseConfiguration", false);
415   -$oKTConfig->setdefaultns("tweaks", "browseToRoot", false);
  415 +$oKTConfig->setdefaultns("tweaks", "browseToUnitFolder", false);
416 416 $oKTConfig->setdefaultns("tweaks", "genericMetaDataRequired", true);
417 417 $oKTConfig->setdefaultns("tweaks", "phpErrorLogFile", false);
418 418 $oKTConfig->setdefaultns("tweaks", "developmentWindowLog", false);
... ...
lib/users/User.inc
... ... @@ -110,28 +110,6 @@ class User extends KTEntity {
110 110 function getAuthenticationDetails2() { return $this->sAuthenticationDetails2; }
111 111 function setAuthenticationDetails2($sNewValue) { $this->sAuthenticationDetails2 = $sNewValue; }
112 112  
113   - /**
114   - * Delete the current object from the database
115   - *
116   - * @return boolean true on successful deletion, false otherwise and set $_SESSION["errorMessage"]
117   - *
118   - */
119   - function deleteFromSystem() {
120   - global $default, $lang_err_database, $lang_err_object_key;
121   - //only delete the object if it exists in the database
122   - if ($this->iId >= 0) {
123   - $sql = $default->db;
124   - $result = $sql->query("DELETE FROM $default->users_groups_table WHERE user_id = $this->iId");
125   - if ($result) {
126   - return true;
127   - }
128   - $_SESSION["errorMessage"] = $lang_err_database;
129   - return false;
130   - }
131   - $_SESSION["errorMessage"] = $lang_err_object_key;
132   - return false;
133   - }
134   -
135 113 function &get($iId) {
136 114 return KTEntityUtil::get('User', $iId);
137 115 }
... ... @@ -195,49 +173,19 @@ class User extends KTEntity {
195 173  
196 174 /**
197 175 * Static function
198   - * Return the unitIDs of the specified user
199   - *
200   - * @param int the id the user to lookup the unit for
201   - * @return array the unitIDs, false otherwise
202   - */
203   - function getUnitIDs($userID) {
204   - global $default, $lang_err_database;
205   -
206   - $sql = $default->db;
207   - /*ok*/$result = $sql->query(array("SELECT DISTINCT gul.unit_id FROM $default->users_groups_table ugl " .
208   - "INNER JOIN $default->groups_units_table gul ON ugl.group_id = gul.group_id ".
209   - "WHERE ugl.user_id = ?", $userID));
210   - if ($result) {
211   - $aUnitIDs = array();
212   - while ($sql->next_record()) {
213   - $aUnitIDs[] = $sql->f("unit_id");
214   - }
215   - return $aUnitIDs;
216   - }
217   - return false;
218   - }
219   -
220   - /**
221   - * Static function
222 176 * Return the useID for the specified user
223 177 *
224 178 * @param int the id the user to lookup the unit for
225 179 * @return int the unitID, false otherwise and $_SESSION["errorMessage"] set
226 180 */
227   - function getUnitID($userID) {
228   - global $default, $lang_err_database;
229   -
230   - $sql = $default->db;
231   - /*ok*/$result = $sql->query(array("SELECT DISTINCT gul.unit_id FROM $default->users_groups_table ugl " .
232   - "INNER JOIN $default->groups_units_table gul ON ugl.group_id = gul.group_id ".
233   - "WHERE ugl.user_id = ?", $userID));
234   - if ($result) {
235   - if ($sql->next_record()) {
236   - return $sql->f("unit_id");
237   - }
238   - }
239   - $_SESSION["errorMessage"] = $lang_err_database;
240   - return false;
  181 + function getUnitId() {
  182 + $ugl = KTUtil::getTableName("users_groups");
  183 + $g = KTUtil::getTableName("groups");
  184 + $aQuery = array(
  185 + "SELECT DISTINCT g.unit_id AS unit_id FROM $ugl AS ugl INNER JOIN $g AS g ON ugl.group_id = g.id WHERE ugl.user_id = ?",
  186 + array($this->iId),
  187 + );
  188 + return DBUtil::getOneResultKey($aQuery, 'unit_id');
241 189 }
242 190  
243 191 /**
... ... @@ -258,71 +206,16 @@ class User extends KTEntity {
258 206 /** Static function
259 207 * Gets the user's default top level folder for the current user
260 208 */
261   - function getUserRootFolderID() {
262   - global $default;
263   -
264   - $unitID = User::getUnitID($_SESSION["userID"]);
265   - $iFolderID;
266   -
267   - if ($unitID) {
268   - // if the user is in a unit, start at the unit's root folder
269   -
270   - // lookup the unit name
271   - $unitName = lookupField($default->units_table, "name", "id", $unitID);
  209 + function getHomeFolderID() {
  210 + $iUnitId = $this->getUnitId();
272 211  
273   - // the unit root folder has the same name as the unit
274   - // FIXME: dodgy i know, but its easy
275   - $unitRootFolderName = $unitName;
276   -
277   - // now lookup the folderID
278   - $aFolders = Folder::getList(array("name = ? and parent_id = 1", $unitRootFolderName));/*ok*/
279   -
280   - if (!$aFolders) {
281   - // no folder exists with this name, so start at the root
282   - $iFolderID = lookupID($default->folders_table, "parent_id", 0);
283   - } else {
284   - $iFolderID = $aFolders[0]->getID();
285   - }
286   - } else {
287   - $iFolderID = lookupID($default->folders_table, "parent_id", 0);
  212 + if (empty($iUnitId)) {
  213 + return false;
288 214 }
289   - return $iFolderID;
290   - }
291   -
292 215  
293   - /**
294   - * Returns a unit administrator for the current user
295   - */
296   - function getUnitAdminUser() {
297   - global $default;
298   - // find out what unit we're in
299   - $iUnitID = User::getUnitID($_SESSION["userID"]);
300   - if ($iUnitID) {
301   - // then find the group that is unit_admin
302   - $sql = $default->db;
303   - $sEmail = "";
304   - if ($sql->query(array("SELECT group_id FROM $default->groups_units_table GUL " . /*ok*/
305   - "INNER JOIN $default->groups_table GL on GUL.group_id=GL.id " .
306   - "WHERE GL.is_unit_admin=1 " .
307   - "AND unit_id = ?", $iUnitID))) {
308   - // get the first record
309   - if ($sql->next_record()) {
310   - $iGroupID = $sql->f("group_id");
311   - // then find the first user in this group that has an email address
312   - if ($sql->query(array("SELECT U.id, U.email FROM $default->users_table U " . /*ok*/
313   - "INNER JOIN $default->users_groups_table UGL on UGL.user_id=U.id " .
314   - "WHERE group_id = ?", $iGroupID))) {
315   - while ($sql->next_record()) {
316   - if (strlen($sql->f("email")) > 0) {
317   - return User::get($sql->f("id"));
318   - }
319   - }
320   - }
321   - }
322   - }
323   - }
324   - return false;
325   - }
  216 + $oUnit =& Unit::get($iUnitId);
  217 + return $oUnit->getFolderId();
  218 + }
326 219  
327 220 function &createFromArray($aOptions) { return KTEntityUtil::createFromArray('User', $aOptions); }
328 221 function &getByUserName($sUserName, $aOptions = null) {
... ...