Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
mahara
mahara
Commits
4af41c32
Commit
4af41c32
authored
Nov 13, 2006
by
Penny Leach
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
account prefs stuff
parent
650d0306
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
184 additions
and
1 deletion
+184
-1
htdocs/auth/session.php
htdocs/auth/session.php
+42
-1
htdocs/init.php
htdocs/init.php
+1
-0
htdocs/lib/user.php
htdocs/lib/user.php
+141
-0
No files found.
htdocs/auth/session.php
View file @
4af41c32
...
...
@@ -71,7 +71,9 @@ class Session {
'firstname'
=>
''
,
'lastname'
=>
''
,
'prefname'
=>
''
,
'email'
=>
''
'email'
=>
''
,
'accountprefs'
=>
array
(),
'activityprefs'
=>
array
(),
);
// Resume an existing session if required
if
(
isset
(
$_COOKIE
[
'PHPSESSID'
]))
{
...
...
@@ -99,6 +101,33 @@ class Session {
return
$this
->
defaults
[
$key
];
}
/**
* This function returns a method for a particular
* activity type.
* or null if it's not set.
*
* @param string $key the activity type
*/
public
function
get_activity_preference
(
$key
)
{
if
(
isset
(
$_SESSION
[
'activityprefs'
][
$key
]))
{
return
$_SESSION
[
'activityprefs'
][
$key
];
}
return
null
;
}
/**
* This function returns a value for a particular
* account preference, or null if it's not set.
*
* @param string $key the field name
*/
public
function
get_account_preference
(
$key
)
{
if
(
isset
(
$_SESSION
[
'accountprefs'
][
$key
]))
{
return
$_SESSION
[
'accountprefs'
][
$key
];
}
return
null
;
}
/**
* Sets the session property keyed by $key.
*
...
...
@@ -115,6 +144,16 @@ class Session {
$_SESSION
[
$key
]
=
$value
;
}
function
set_account_preference
(
$field
,
$value
)
{
set_account_preference
(
$this
->
get
(
'id'
),
$field
,
$value
);
$_SESSION
[
'accountprefs'
][
$field
]
=
$value
;
}
function
set_activity_preference
(
$activity
,
$method
)
{
set_activity_preference
(
$this
->
get
(
'id'
),
$activity
,
$method
);
$_SESSION
[
'activityprefs'
][
$activity
]
=
$method
;
}
/**
* Logs in the given user.
*
...
...
@@ -132,6 +171,8 @@ class Session {
$this
->
set
(
$key
,
(
isset
(
$USER
->
{
$key
}))
?
$USER
->
{
$key
}
:
$this
->
defaults
[
$key
]);
}
$this
->
set
(
'logout_time'
,
time
()
+
get_config
(
'session_timeout'
));
$_SESSION
[
'activityprefs'
]
=
load_activity_preferences
(
$this
->
get
(
'id'
));
$_SESSION
[
'accountprefs'
]
=
load_account_preferences
(
$this
->
get
(
'id'
));
}
/**
...
...
htdocs/init.php
View file @
4af41c32
...
...
@@ -83,6 +83,7 @@ require('ddl.php');
require
(
'constants.php'
);
require
(
'web.php'
);
require
(
'activity.php'
);
require
(
'user.php'
);
// Database access functions
require
(
'adodb/adodb-exceptions.inc.php'
);
...
...
htdocs/lib/user.php
0 → 100644
View file @
4af41c32
<?php
/**
* This program is part of Mahara
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage core
* @author Penny Leach <penny@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
defined
(
'INTERNAL'
)
||
die
();
/**
* loads up activity preferences for a given user
*
* @param int $userid to load preferences for
* @todo caching
*/
function
load_activity_preferences
(
$userid
)
{
$prefs
=
array
();
if
(
empty
(
$userid
))
{
throw
new
InvalidArgumentException
(
"couldn't load activity preferences, no user id specified"
);
}
if
(
$prefs
=
get_records
(
'usr_activity_preference'
,
'usr'
,
$userid
))
{
foreach
(
$prefs
as
$p
)
{
$prefs
[
$p
->
activity
]
=
$p
->
method
;
}
}
return
$prefs
;
}
/**
* loads up account preferences for a given user
* if you want them for the current user
* use $SESSION->accountprefs
*
* @param int $userid to load preferences for
* @todo caching
* @todo defaults?
*/
function
load_account_preferences
(
$userid
)
{
$prefs
=
array
();
$expectedprefs
=
expected_account_preferences
();
if
(
empty
(
$userid
))
{
throw
new
InvalidArgumentException
(
"couldn't load account preferences, no user id specified"
);
}
if
(
$prefs
=
get_records
(
'usr_account_preference'
,
'usr'
,
$userid
))
{
foreach
(
$prefs
as
$p
)
{
$prefs
[
$p
->
field
]
=
$p
->
value
;
}
}
foreach
(
$expectedprefs
as
$field
=>
$default
)
{
if
(
!
isset
(
$prefs
[
$field
]))
{
$prefs
[
$field
]
=
$default
;
}
}
return
$prefs
;
}
/**
* sets a user preference in the database
* if you want to set it in the session as well
* use SESSION->set_account_preference
*
* @param int $userid user id to set preference for
* @param string $field preference field to set
* @param string $value preference value to set.
*/
function
set_account_preference
(
$userid
,
$field
,
$value
)
{
if
(
record_exists
(
'usr_account_preference'
,
'usr'
,
$userid
,
'field'
,
$field
))
{
set_field
(
'usr_account_preference'
,
'value'
,
$value
,
'usr'
,
$userid
,
'field'
,
$field
);
}
else
{
try
{
$pref
=
new
StdClass
;
$pref
->
usr
=
$userid
;
$pref
->
field
=
$field
;
$pref
->
value
=
$value
;
insert_record
(
'usr_account_preference'
,
$pref
);
}
catch
(
Exception
$e
)
{
throw
new
InvalidArgumentException
(
"Failed to insert account preference "
.
"
$value
for
$field
for user
$userid
"
);
}
}
}
/**
* sets an activity preference in the database
* if you want to set it in the session as well
* use $SESSION->set_activity_preference
*
* @param int $userid user id to set preference for
* @param string $activity activity type to set
* @param string $method notification method to set.
*/
function
set_activity_preference
(
$userid
,
$activity
,
$method
)
{
if
(
record_exists
(
'usr_activity_preference'
,
'usr'
,
$userid
,
'activity'
,
$activity
))
{
set_field
(
'usr_activity_preference'
,
'method'
,
$method
,
'usr'
,
$userid
,
'activity'
,
$activity
);
}
else
{
try
{
$pref
=
new
StdClass
;
$pref
->
usr
=
$userid
;
$pref
->
activity
=
$activity
;
$pref
->
method
=
$method
;
insert_record
(
'usr_activity_preference'
,
$pref
);
}
catch
(
Exception
$e
)
{
throw
new
InvalidArgumentException
(
"Failed to insert activity preference "
.
"
$methodfor
$activity
for user
$userid
"
);
}
}
}
function
expected_account_preferences
()
{
return
array
(
'friendscontrol'
=>
'auth'
,
'wysiwyg'
=>
1
,
'messages'
=>
'allow'
,
'lang'
=>
'en.utf8'
);
}
?>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment