2 // This program is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU General Public License
4 // as published by the Free Software Foundation; either version 2
5 // of the License, or (at your option) any later version.
7 require_once(dirname(__FILE__) . "/sql.inc");
8 require_once(dirname(__FILE__) . "/formdata.inc.php");
10 //This will return the user setting(s) from the 'users' table.
11 // $choice can be used to return only one specific user setting
12 // $user is the user id number in the 'users' table
13 function getUserSetting($label,$user=NULL) {
15 // if no user id is sent, then use the currently logged in user
17 $user = $_SESSION['authUserID'];
20 // Collect entry if it exist.
21 // If does not exist, then look for a default entry.
22 // If default entry does not exist, then return a '0'.
24 $result = sqlQuery("SELECT setting_value FROM user_settings " .
25 "WHERE setting_user=? AND setting_label=?", array($user, $label) );
27 $result = sqlQuery("SELECT setting_value FROM user_settings " .
28 "WHERE setting_user='0' AND setting_label=?", array($label) );
34 // Only one value, so collect it
35 $tempResult = $result;
36 foreach($tempResult as $key=>$value) {
43 //This will set a user setting
44 // $name is the setting name in the 'users' table
45 // $value is the setting value to be set in the 'users' table
46 // $user is the user id number in the 'users' table
47 function setUserSetting($label, $value, $user=NULL) {
49 // if no user id is sent, then use the currently logged in user
51 $user = $_SESSION['authUserID'];
57 // Check for a custom settings
58 $row = sqlQuery("SELECT setting_value FROM user_settings " .
59 "WHERE setting_user=? AND setting_label=?", array($user, $label) );
64 // Set the custom setting
66 sqlStatement("INSERT INTO user_settings " .
67 "(setting_user, setting_label, setting_value) " .
68 "VALUES (?,?,?)", array($user, $label, $value) );
71 sqlStatement("UPDATE user_settings SET setting_value=? " .
72 "WHERE setting_user=? AND setting_label=?", array($value, $user, $label) );
75 // Check for a default settings
76 $row = sqlQuery("SELECT setting_value FROM user_settings " .
77 "WHERE setting_user='0' AND setting_label=?", array($label) );
82 // Place a default setting if it does not already exist
84 sqlStatement("INSERT INTO user_settings " .
85 "(setting_user, setting_label, setting_value) " .
86 "VALUES ('0',?,?)", array($label, $value) );