UW sends \NoSelect in LIST and not in LSUB, which is perfectly fine by
[squirrelmail.git] / functions / prefs.php
1 <?php
2
3 /**
4 * prefs.php
5 *
6 * Copyright (c) 1999-2003 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * This contains functions for manipulating user preferences
10 *
11 * $Id$
12 */
13
14 require_once(SM_PATH . 'functions/global.php');
15
16 sqgetGlobalVar('prefs_cache', $prefs_cache, SQ_SESSION );
17 sqgetGlobalVar('prefs_are_cached', $prefs_are_cached, SQ_SESSION );
18
19 $rg = ini_get('register_globals');
20
21 /* if php version >= 4.1 OR (4.0 AND $rg = off) */
22 if ( !sqsession_is_registered('prefs_are_cached') ||
23 !isset( $prefs_cache) ||
24 !is_array( $prefs_cache) ||
25 check_php_version(4,1) ||
26 empty($rg)
27 ) {
28 $prefs_are_cached = false;
29 $prefs_cache = array();
30 }
31
32 if (isset($prefs_dsn) && !empty($prefs_dsn)) {
33 require_once(SM_PATH . 'functions/db_prefs.php');
34 } else {
35 require_once(SM_PATH . 'functions/file_prefs.php');
36 }
37
38 /* Hashing functions */
39
40 function getHashedFile($username, $dir, $datafile, $hash_search = true) {
41 global $dir_hash_level;
42
43 /* Remove trailing slash from $dir if found */
44 if (substr($dir, -1) == '/') {
45 $dir = substr($dir, 0, strlen($dir) - 1);
46 }
47
48 /* Compute the hash for this user and extract the hash directories. */
49 $hash_dirs = computeHashDirs($username);
50
51 /* First, get and make sure the full hash directory exists. */
52 $real_hash_dir = getHashedDir($username, $dir, $hash_dirs);
53
54 /* Set the value of our real data file, after we've removed unwanted characters. */
55 $datafile = str_replace('/', '_', $datafile);
56 $result = "$real_hash_dir/$datafile";
57
58 /* Check for this file in the real hash directory. */
59 if ($hash_search && !@file_exists($result)) {
60 /* First check the base directory, the most common location. */
61 if (@file_exists("$dir/$datafile")) {
62 rename("$dir/$datafile", $result);
63
64 /* Then check the full range of possible hash directories. */
65 } else {
66 $check_hash_dir = $dir;
67 for ($h = 0; $h < 4; ++$h) {
68 $check_hash_dir .= '/' . $hash_dirs[$h];
69 if (@is_readable("$check_hash_dir/$datafile")) {
70 rename("$check_hash_dir/$datafile", $result);
71 break;
72 }
73 }
74 }
75 }
76
77 /* Return the full hashed datafile path. */
78 return ($result);
79 }
80
81 function getHashedDir($username, $dir, $hash_dirs = '') {
82 global $dir_hash_level;
83
84 /* Remove trailing slash from $dir if found */
85 if (substr($dir, -1) == '/') {
86 $dir = substr($dir, 0, strlen($dir) - 1);
87 }
88
89 /* If necessary, populate the hash dir variable. */
90 if ($hash_dirs == '') {
91 $hash_dirs = computeHashDirs($username);
92 }
93
94 /* Make sure the full hash directory exists. */
95 $real_hash_dir = $dir;
96 for ($h = 0; $h < $dir_hash_level; ++$h) {
97 $real_hash_dir .= '/' . $hash_dirs[$h];
98 if (!@is_dir($real_hash_dir)) {
99 if (!@mkdir($real_hash_dir, 0770)) {
100 echo sprintf(_("Error creating directory %s."), $real_hash_dir) . '<br>' .
101 _("Could not create hashed directory structure!") . "<br>\n" .
102 _("Please contact your system administrator and report this error.") . "<br>\n";
103 exit;
104 }
105 }
106 }
107
108 /* And return that directory. */
109 return ($real_hash_dir);
110 }
111
112 function computeHashDirs($username) {
113 /* Compute the hash for this user and extract the hash directories. */
114 $hash = base_convert(crc32($username), 10, 16);
115 $hash_dirs = array();
116 for ($h = 0; $h < 4; ++ $h) {
117 $hash_dirs[] = substr($hash, $h, 1);
118 }
119
120 /* Return our array of hash directories. */
121 return ($hash_dirs);
122 }
123
124 ?>