Check for flags column
[squirrelmail.git] / functions / prefs.php
CommitLineData
59177427 1<?php
2ba13803 2
35586184 3/**
4 * prefs.php
5 *
6c84ba1e 6 * Copyright (c) 1999-2005 The SquirrelMail Project Team
35586184 7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * This contains functions for manipulating user preferences
10 *
31841a9e 11 * @version $Id$
d6c32258 12 * @package squirrelmail
35586184 13 */
14
d6c32258 15/** Include global.php */
0b97a708 16require_once(SM_PATH . 'functions/global.php');
9d0239af 17require_once(SM_PATH . 'functions/plugin.php');
0b97a708 18
0365891c 19sqgetGlobalVar('prefs_cache', $prefs_cache, SQ_SESSION );
20sqgetGlobalVar('prefs_are_cached', $prefs_are_cached, SQ_SESSION );
0b97a708 21
d7c82551 22if ( !sqsession_is_registered('prefs_are_cached') ||
93b2364f 23 !isset( $prefs_cache) ||
62f7daa5 24 !is_array( $prefs_cache)
cccfa9c2 25 ) {
35586184 26 $prefs_are_cached = false;
27 $prefs_cache = array();
28}
31ac7db8 29
9d0239af 30$prefs_backend = do_hook_function('prefs_backend');
31if (isset($prefs_backend) && !empty($prefs_backend) && file_exists(SM_PATH . $prefs_backend)) {
55994cd6 32 require_once(SM_PATH . $prefs_backend);
33} elseif (isset($prefs_dsn) && !empty($prefs_dsn)) {
b68edc75 34 require_once(SM_PATH . 'functions/db_prefs.php');
3499f99f 35} else {
b68edc75 36 require_once(SM_PATH . 'functions/file_prefs.php');
7b294953 37}
38
3499f99f 39/* Hashing functions */
fb120846 40
8b096f0a 41/**
42 * Given a username and datafilename, this will return the path to the
43 * hashed location of that datafile.
44 *
45 * @param string username the username of the current user
598294a7 46 * @param string dir the SquirrelMail datadir
8b096f0a 47 * @param string datafile the name of the file to open
48 * @param bool hash_seach default true
49 * @return string the hashed location of datafile
50 */
3392dc86 51function getHashedFile($username, $dir, $datafile, $hash_search = true) {
3392dc86 52
311339a0 53 /* Remove trailing slash from $dir if found */
54 if (substr($dir, -1) == '/') {
55 $dir = substr($dir, 0, strlen($dir) - 1);
56 }
62f7daa5 57
3392dc86 58 /* Compute the hash for this user and extract the hash directories. */
59 $hash_dirs = computeHashDirs($username);
60
61 /* First, get and make sure the full hash directory exists. */
62 $real_hash_dir = getHashedDir($username, $dir, $hash_dirs);
63
12719a10 64 /* Set the value of our real data file, after we've removed unwanted characters. */
65 $datafile = str_replace('/', '_', $datafile);
4fc152a6 66 $result = "$real_hash_dir/$datafile";
3392dc86 67
68 /* Check for this file in the real hash directory. */
3a94810f 69 if ($hash_search && !@file_exists($result)) {
3392dc86 70 /* First check the base directory, the most common location. */
3a94810f 71 if (@file_exists("$dir/$datafile")) {
3392dc86 72 rename("$dir/$datafile", $result);
73
74 /* Then check the full range of possible hash directories. */
75 } else {
76 $check_hash_dir = $dir;
77 for ($h = 0; $h < 4; ++$h) {
78 $check_hash_dir .= '/' . $hash_dirs[$h];
311339a0 79 if (@is_readable("$check_hash_dir/$datafile")) {
3392dc86 80 rename("$check_hash_dir/$datafile", $result);
81 break;
82 }
83 }
84 }
85 }
62f7daa5 86
3392dc86 87 /* Return the full hashed datafile path. */
88 return ($result);
89}
90
8b096f0a 91/**
92 * Helper function for getHashedFile, given a username returns the hashed
93 * dir for that username.
94 *
95 * @param string username the username of the current user
598294a7 96 * @param string dir the SquirrelMail datadir
8b096f0a 97 * @param string hash_dirs default ''
98 * @return the path to the hash dir for username
99 */
3392dc86 100function getHashedDir($username, $dir, $hash_dirs = '') {
101 global $dir_hash_level;
102
3a94810f 103 /* Remove trailing slash from $dir if found */
104 if (substr($dir, -1) == '/') {
105 $dir = substr($dir, 0, strlen($dir) - 1);
106 }
62f7daa5 107
3392dc86 108 /* If necessary, populate the hash dir variable. */
109 if ($hash_dirs == '') {
110 $hash_dirs = computeHashDirs($username);
111 }
112
113 /* Make sure the full hash directory exists. */
114 $real_hash_dir = $dir;
115 for ($h = 0; $h < $dir_hash_level; ++$h) {
116 $real_hash_dir .= '/' . $hash_dirs[$h];
3a94810f 117 if (!@is_dir($real_hash_dir)) {
118 if (!@mkdir($real_hash_dir, 0770)) {
6fd95361 119 echo sprintf(_("Error creating directory %s."), $real_hash_dir) . '<br />' .
120 _("Could not create hashed directory structure!") . "<br />\n" .
121 _("Please contact your system administrator and report this error.") . "<br />\n";
3a94810f 122 exit;
123 }
3392dc86 124 }
125 }
126
127 /* And return that directory. */
128 return ($real_hash_dir);
129}
130
8b096f0a 131/**
132 * Helper function for getHashDir which does the actual hash calculation.
133 *
134 * @param string username the username to calculate the hash dir for
135 * @return array a list of hash dirs for this username
136 */
3392dc86 137function computeHashDirs($username) {
138 /* Compute the hash for this user and extract the hash directories. */
139 $hash = base_convert(crc32($username), 10, 16);
140 $hash_dirs = array();
141 for ($h = 0; $h < 4; ++ $h) {
142 $hash_dirs[] = substr($hash, $h, 1);
143 }
144
145 /* Return our array of hash directories. */
146 return ($hash_dirs);
147}
148
e9219f94 149/**
150 * FIXME: Undocumented function
e9219f94 151 */
ae958cd3 152function checkForJavascript($reset = FALSE)
1a531551 153{
ae958cd3 154 global $data_dir, $username, $javascript_on, $javascript_setting;
1a531551 155
ae958cd3 156 if ( !$reset && sqGetGlobalVar('javascript_on', $javascript_on, SQ_SESSION) )
157 return $javascript_on;
158
159 if ( $reset || !isset($javascript_setting) )
160 $javascript_setting = getPref($data_dir, $username, 'javascript_setting', SMPREF_JS_AUTODETECT);
1a531551 161
ae958cd3 162 if ( !sqGetGlobalVar('new_js_autodetect_results', $js_autodetect_results) &&
163 !sqGetGlobalVar('js_autodetect_results', $js_autodetect_results) )
164 $js_autodetect_results = SMPREF_JS_OFF;
1a531551 165
166 if ( $javascript_setting == SMPREF_JS_AUTODETECT )
ae958cd3 167 $javascript_on = $js_autodetect_results;
1a531551 168 else
ae958cd3 169 $javascript_on = $javascript_setting;
1a531551 170
ae958cd3 171 sqsession_register($javascript_on, 'javascript_on');
172 return $javascript_on;
1a531551 173}
174
e9219f94 175?>