2 // Copyright (C) 2010 Brady Miller <brady@sparmy.com>
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 require_once(dirname(__FILE__) . "/sql.inc");
10 require_once(dirname(__FILE__) . "/formdata.inc.php");
12 //This will return the user setting(s) from the 'users' table.
13 // $choice can be used to return only one specific user setting
14 // $user is the user id number in the 'users' table
15 // Returns the selected user setting (if does not exist, then returns 0)
16 function getUserSetting($label,$user=NULL) {
18 // if no user id is sent, then use the currently logged in user
20 $user = $_SESSION['authUserID'];
23 // Collect entry if it exist.
24 // If does not exist, then look for a default entry.
25 // If default entry does not exist, then return a '0'.
27 $result = sqlQuery("SELECT setting_value FROM user_settings " .
28 "WHERE setting_user=? AND setting_label=?", array($user, $label) );
30 $result = sqlQuery("SELECT setting_value FROM user_settings " .
31 "WHERE setting_user='0' AND setting_label=?", array($label) );
37 // Only one value, so collect it
38 $tempResult = $result;
39 foreach($tempResult as $key=>$value) {
46 //This will check a user setting
47 // $name is the setting name in the 'users' table
48 // $value is the setting value to be checked in the 'users' table
49 // $user is the user id number in the 'users' table
50 // Returns true if setting exist and false if does not exist
51 function checkUserSetting($label, $value, $user=NULL) {
53 // if no user id is sent, then use the currently logged in user
55 $user = $_SESSION['authUserID'];
58 // Check for the user settings
59 // If does not exist, then check for a default entry.
60 // (return false if setting does not exist)
61 $result = sqlQuery("SELECT setting_value FROM user_settings " .
62 "WHERE setting_user=? AND setting_label=? AND setting_value=?", array($user, $label, $value) );
64 $result = sqlQuery("SELECT setting_value FROM user_settings " .
65 "WHERE setting_user='0' AND setting_label=? AND setting_value=?", array($label, $value) );
71 // Setting exist, so return true
75 //This will set a user setting
76 // $name is the setting name in the 'users' table
77 // $value is the setting value to be set in the 'users' table
78 // $user is the user id number in the 'users' table
79 // $createDefault is flag to create a default value if it does not yet exist
80 function setUserSetting($label, $value, $user=NULL, $createDefault=TRUE) {
81 // if no user id is sent, then use the currently logged in user
83 $user = $_SESSION['authUserID'];
89 // Check for a custom settings
90 $row = sqlQuery("SELECT setting_value FROM user_settings " .
91 "WHERE setting_user=? AND setting_label=?", array($user, $label) );
96 // Set the custom setting
98 sqlStatement("INSERT INTO user_settings " .
99 "(setting_user, setting_label, setting_value) " .
100 "VALUES (?,?,?)", array($user, $label, $value) );
103 sqlStatement("UPDATE user_settings SET setting_value=? " .
104 "WHERE setting_user=? AND setting_label=?", array($value, $user, $label) );
107 // Check for a default settings
108 $row = sqlQuery("SELECT setting_value FROM user_settings " .
109 "WHERE setting_user='0' AND setting_label=?", array($label) );
114 // Place a default setting if it does not already exist (and createDefault flag is set)
115 if ($newDefault && $createDefault) {
116 sqlStatement("INSERT INTO user_settings " .
117 "(setting_user, setting_label, setting_value) " .
118 "VALUES ('0',?,?)", array($label, $value) );
122 //This will remove the selected user setting from the 'user_settings' table.
123 // $label is used to determine which setting to remove
124 // $user is the user id number in the 'users' table
125 function removeUserSetting($label,$user=NULL) {
126 // if no user id is sent, then use the currently logged in user
128 $user = $_SESSION['authUserID'];
131 // Collect entry if it exist.
132 // If it exists, then delete the entry.
133 $result = sqlQuery("SELECT setting_value FROM user_settings " .
134 "WHERE setting_user=? AND setting_label=?", array($user, $label) );
135 if (!empty($result)) {
136 sqlQuery("DELETE FROM user_settings " .
137 "WHERE setting_user=? AND setting_label=?", array($user, $label) );
142 function getUserIDInfo($id)
144 $res= sqlStatement("SELECT fname,lname,username FROM users where id=?",array($id));
145 return sqlFetchArray($res);