Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezpreferences.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezpreferences.php 6912 2001-09-04 10:48:49Z fh $
5 //
6 // Definition of eZPreferences class
7 //
8 // Created on: <18-Jan-2001 13:05:06 bf>
9 //
10 // This source file is part of Exponential Basic, publishing software.
11 //
12 // Copyright (C) 1999-2001 eZ Systems. All rights reserved.
13 //
14 // This program is free software; you can redistribute it and/or
15 // modify it under the terms of the GNU General Public License
16 // as published by the Free Software Foundation; either version 2
17 // of the License, or (at your option) any later version.
18 //
19 // This program is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 // GNU General Public License for more details.
23 //
24 // You should have received a copy of the GNU General Public License
25 // along with this program; if not, write to the Free Software
26 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US
27 //
28
31
58 // include_once( "classes/ezdb.php" );
59 // include_once( "classes/ezdatetime.php" );
60
61 class eZPreferences
62 {
68 function __construct( )
69 {
70 }
71
72
78 function variableArray( $name, $group = false )
79 {
80 $val =& $this->variable( $name, $group );
81 if ( $val != "" )
82 {
83 $val =& explode( ";", $val );
84 }
85 else
86 $val = array();
87 return $val;
88 }
89
95 static public function variable( $name, $group = false )
96 {
97 $ret = false;
98 $user =& eZUser::currentUser();
99 if( !$user )
100 return 0;
101
102 if ( is_a( $user, "eZUser" ) )
103 {
104 $db =& eZDB::globalDatabase();
105 $userID = $user->id();
106
107 if ( !is_bool( $group ) )
108 $group_sql = "GroupName='$group'";
109 else
110 $group_sql = "GroupName=''";
111 $db->array_query( $value_array, "SELECT Value FROM eZSession_Preferences
112 WHERE UserID='$userID' AND Name='$name'
113 AND $group_sql" );
114
115 if ( count( $value_array ) == 1 )
116 {
117 $ret = $value_array[0][$db->fieldName("Value")];
118 }
119 }
120 return $ret;
121 }
122
128 static public function setVariable( $name, $value, $group = false )
129 {
130 $ret = false;
131 $user =& eZUser::currentUser();
132 if( !$user )
133 return 0;
134
135 if ( is_a( $user, "eZUser" ) )
136 {
137 if ( is_array( $value ) )
138 {
139 $value =& implode( ";", $value );
140 }
141 $db =& eZDB::globalDatabase();
142
143 $dbError = false;
144 $db->begin( );
145
146 $userID = $user->id();
147
148 $name = addslashes( $name );
149 $value = addslashes( $value );
150 if ( !is_bool( $group ) )
151 $group_sql = "GroupName='$group'";
152 else
153 $group_sql = "GroupName=''";
154 $db->array_query( $value_array, "SELECT ID FROM eZSession_Preferences
155 WHERE UserID='$userID' AND Name='$name'
156 AND $group_sql" );
157 if ( count( $value_array ) == 1 )
158 {
159 $valueID = $value_array[0][$db->fieldName("ID")];
160 $db->query( "UPDATE eZSession_Preferences SET
161 Value='$value' WHERE ID='$valueID'
162 " );
163 $ret = true;
164 }
165 else
166 {
167 if ( is_bool( $group ) )
168 $group = "";
169 else
170 $group = "'$group'";
171
172 $db->lock( "eZSession_Preferences" );
173
174 $nextID = $db->nextID( "eZSession_Preferences", "ID" );
175
176
177 $res = $db->query( "INSERT INTO eZSession_Preferences
178 ( ID, UserID, Name, Value, GroupName )
179 VALUES
180 ( '$nextID', '$userID', '$name', '$value', '$group' )" );
181
182 $db->unlock();
183
184 if ( $res != false )
185 $ret = true;
186 else
187 $dbError = true;
188 }
189
190 if ( $dbError == true )
191 $db->rollback( );
192 else
193 $db->commit();
194 }
195
196 return $ret;
197 }
198 }
199
200 ?>
$group
$group
Definition: admin/articleedit.php:799
$userID
else $userID
Definition: appointmentedit.php:121
eZDB\globalDatabase
static & globalDatabase()
Definition: ezdb.php:134
eZPreferences
Definition: ezpreferences.php:62
eZPreferences\__construct
__construct()
Definition: ezpreferences.php:68
eZPreferences\variable
static variable( $name, $group=false)
Definition: ezpreferences.php:95
eZPreferences\variableArray
variableArray( $name, $group=false)
Definition: ezpreferences.php:78
eZPreferences\setVariable
static setVariable( $name, $value, $group=false)
Definition: ezpreferences.php:128
eZUser\currentUser
static & currentUser()
Definition: ezuser.php:896
$name
$name
Definition: companytypelist.php:194
$db
$db
Definition: ezarticle/user/authorlist.php:53
$ret
$ret
Definition: ezsitemanager/admin/filelist.php:88
$res
$res
Definition: ezstats/admin/cron.php:45
$user
$user
Definition: user/adlist.php:39
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.