move code up one directory
[atutor.git] / users / preferences.php
1 <?php
2 /************************************************************************/
3 /* ATutor                                                                                                                               */
4 /************************************************************************/
5 /* Copyright (c) 2002-2010                                              */
6 /* Inclusive Design Institute                                           */
7 /* http://atutor.ca                                                     */
8 /* This program is free software. You can redistribute it and/or        */
9 /* modify it under the terms of the GNU General Public License          */
10 /* as published by the Free Software Foundation.                        */
11 /************************************************************************/
12 // $Id$
13
14 $_user_location = 'users';
15 define('AT_INCLUDE_PATH', '../include/');
16 require(AT_INCLUDE_PATH.'vitals.inc.php');
17 require(AT_INCLUDE_PATH.'../mods/_core/themes/lib/themes.inc.php');
18 require_once(AT_INCLUDE_PATH.'../mods/_core/users/lib/pref_tab_functions.inc.php');
19 /* whether or not, any settings are being changed when this page loads. */
20 /* ie. is ANY action being performed right now?                                                 */
21
22 $action = false;
23
24 if (!$_SESSION['valid_user']) {                         
25         /* we're not logged in */
26         $msg->addFeedback('PREFS_LOGIN');
27 }
28
29 $is_auto_login = checkAutoLoginCookie();
30
31 if (isset($_POST['submit']) || isset($_POST['set_default'])) {
32         $current_tab = $_POST['current_tab'];
33         if (isset($_POST['submit']))
34         {
35             //copy posted variables to a temporary array
36                 $temp_prefs = assignPostVars();
37     
38                 //email notification and auto-login settings are handled
39                 //separately from other preferences
40                 $mnot = intval($_POST['mnot']);
41                 if (isset($_POST['auto'])) $auto_login = $_POST['auto'];
42         }
43         else if (isset($_POST['set_default']))
44         {
45             $temp_prefs = assignDefaultPrefs();
46         $mnot = assignDefaultMnot();
47         $auto_login = assignDefaultAutologin();
48                 unset($_POST);
49         }
50
51         //save most preferences to session and db
52         assign_session_prefs($temp_prefs);
53         save_prefs();
54
55         //update email notification and auto-login settings separately
56     save_email_notification($mnot);
57         if (isset($auto_login)) {
58         $is_auto_login = setAutoLoginCookie($auto_login);
59     }
60
61         $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
62         header('Location: preferences.php?current_tab='.$current_tab);
63         exit;
64 }
65
66 // re-set session prefs if the request is from a mobile device 
67 // because now $_SESSION['prefs']['PREF_THEME'] == $_SESSION['prefs']['PREF_MOBILE_THEME'] instead of the desktop theme
68 // The code below re-assign $_SESSION['prefs']['PREF_THEME'] back to what it should be
69 if (is_mobile_device()) {
70         $sql = "SELECT * FROM ".TABLE_PREFIX."members WHERE member_id=".$_SESSION['member_id'];
71         $result = mysql_query($sql, $db);
72         $row = mysql_fetch_assoc($result);
73         assign_session_prefs(unserialize(stripslashes($row['preferences'])));
74 }
75
76 if ($_SESSION['first_login']) {
77     $_SESSION['prefs']['PREF_MODIFIED'] = 1;    //flag to indicate that this preference has been changed.
78     save_prefs();
79 }
80
81 unset($_SESSION['first_login']);
82 $sql    = "SELECT inbox_notify FROM ".TABLE_PREFIX."members WHERE member_id=$_SESSION[member_id]";
83 $result = mysql_query($sql, $db);
84 $row_notify = mysql_fetch_assoc($result);
85
86 $languages = $languageManager->getAvailableLanguages();
87
88 /* page contents starts here */
89 $savant->assign('notify', $row_notify['inbox_notify']);
90 $savant->assign('languages', $languages);
91
92 //problem here - if auto login is enabled, but we don't check that there is a cookie, how do we know if it is enabled?
93
94 $savant->assign('is_auto_login', $is_auto_login);
95
96 $savant->display('users/preferences.tmpl.php');
97
98 ?>