Skip to content

Commit

Permalink
Merge pull request #30 from anvk/cssThemeName
Browse files Browse the repository at this point in the history
Css theme name
  • Loading branch information
atutorlangs committed Feb 4, 2013
2 parents a615366 + 4f3e074 commit cb1ac27
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 22 deletions.
36 changes: 36 additions & 0 deletions include/lib/vital_funcs.inc.php
Expand Up @@ -1077,4 +1077,40 @@ function debug($var, $title='') {
echo '</pre>';
}

/**
* This function is used to make a DB query the same along the whole codebase
* @access public
* @param Query string in the vsprintf format. Basically the first parameter of vsprintf function
* @param Array of parameters which will be converted and inserted into the query
* @param OPTIONAL Function returns the first element of the return array if set to TRUE. Basically returns the first row if it exists
* @return ALWAYS returns result of the query execution as an array of rows. If no results were found than array would be empty
* @author Alexey Novak
*/
function queryDB($query, $params, $oneRow = FALSE) {
global $db;
if (!$query || $query == '') {
return $resultArray;
}

try {
$sql = vsprintf($query, $params);
// Query DB and if something goes wrong then log the problem
$result = mysql_query($sql, $db) or debug_to_log(mysql_error());
// If we need only one row then just grab it otherwise get all the results
if ($oneRow) {
$row = mysql_fetch_assoc($result);
unset($result);
return ($row) ? $row : array();
}

$resultArray = array();
while ($row = mysql_fetch_assoc($result)) {
$resultArray[] = $row;
}
unset($result);
return $resultArray;
} catch (Exception $e) {
debug_to_log($e);
}
}
?>
34 changes: 12 additions & 22 deletions users/preferences.php
Expand Up @@ -13,8 +13,8 @@

$_user_location = 'users';
define('AT_INCLUDE_PATH', '../include/');
require(AT_INCLUDE_PATH.'vitals.inc.php');
require(AT_INCLUDE_PATH.'../mods/_core/themes/lib/themes.inc.php');
require_once(AT_INCLUDE_PATH.'vitals.inc.php');
require_once(AT_INCLUDE_PATH.'../mods/_core/themes/lib/themes.inc.php');
require_once(AT_INCLUDE_PATH.'../mods/_core/users/lib/pref_tab_functions.inc.php');
/* whether or not, any settings are being changed when this page loads. */
/* ie. is ANY action being performed right now? */
Expand All @@ -30,18 +30,14 @@

if (isset($_POST['submit']) || isset($_POST['set_default'])) {
$current_tab = $_POST['current_tab'];
if (isset($_POST['submit']))
{
if (isset($_POST['submit'])) {
//copy posted variables to a temporary array
$temp_prefs = assignPostVars();

//email notification and auto-login settings are handled
//separately from other preferences
$mnot = intval($_POST['mnot']);
if (isset($_POST['auto'])) $auto_login = $_POST['auto'];
}
else if (isset($_POST['set_default']))
{
$auto_login = isset($_POST['auto']) ? $_POST['auto'] : NULL;
} else if (isset($_POST['set_default'])) {
$temp_prefs = assignDefaultPrefs();
$mnot = assignDefaultMnot();
$auto_login = assignDefaultAutologin();
Expand All @@ -54,30 +50,26 @@

//update email notification and auto-login settings separately
save_email_notification($mnot);
if (isset($auto_login)) {
$is_auto_login = setAutoLoginCookie($auto_login);
}
$is_auto_login = isset($auto_login) ? setAutoLoginCookie($auto_login) : $is_auto_login;

$msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
header('Location: preferences.php?current_tab='.$current_tab);
exit;
}

$member_id = $_SESSION['member_id'];

// Re-set selected desktop theme if the request is from a mobile device
// because now $_SESSION['prefs']['PREF_THEME'] == $_SESSION['prefs']['PREF_MOBILE_THEME'] instead of the desktop theme
// The code below re-assign $_SESSION['prefs']['PREF_THEME'] back to what it should be
if (is_mobile_device()) {
$sql = "SELECT * FROM ".TABLE_PREFIX."members WHERE member_id=".$_SESSION['member_id'];
$result = mysql_query($sql, $db);
$row = mysql_fetch_assoc($result);
$row = queryDB('SELECT * FROM %smembers WHERE member_id=%d', array(TABLE_PREFIX, $member_id), TRUE);

foreach (unserialize(stripslashes($row['preferences'])) as $pref_name => $value) {
if ($pref_name == 'PREF_THEME') {
$desktop_theme = $value;
}
$desktop_theme = ($pref_name == 'PREF_THEME') ? $value : $desktop_theme;
}
} else {
$desktop_theme = $_SESSION['prefs']['theme'];
$desktop_theme = $_SESSION['prefs']['PREF_THEME'];
}

if ($_SESSION['first_login']) {
Expand All @@ -86,9 +78,7 @@
}

unset($_SESSION['first_login']);
$sql = "SELECT inbox_notify FROM ".TABLE_PREFIX."members WHERE member_id=$_SESSION[member_id]";
$result = mysql_query($sql, $db);
$row_notify = mysql_fetch_assoc($result);
$row_notify = queryDB('SELECT inbox_notify FROM %smembers WHERE member_id=%d', array(TABLE_PREFIX, $member_id), TRUE);

$languages = $languageManager->getAvailableLanguages();

Expand Down

0 comments on commit cb1ac27

Please sign in to comment.