made a copy
[atutor.git] / users / preferences.php
1 <?php
2 /************************************************************************/
3 /* ATutor                                                                                                                               */
4 /************************************************************************/
5 /* Copyright (c) 2002-2008 by Greg Gay, Joel Kronenberg & Heidi Hazelton*/
6 /* Adaptive Technology Resource Centre / University of Toronto                  */
7 /* http://atutor.ca                                                                                                             */
8 /*                                                                                                                                              */
9 /* This program is free software. You can redistribute it and/or                */
10 /* modify it under the terms of the GNU General Public License                  */
11 /* as published by the Free Software Foundation.                                                */
12 /************************************************************************/
13 // $Id$
14
15 $_user_location = 'users';
16 define('AT_INCLUDE_PATH', '../include/');
17 require(AT_INCLUDE_PATH.'vitals.inc.php');
18 require(AT_INCLUDE_PATH.'lib/themes.inc.php');
19 require(AT_INCLUDE_PATH.'lib/pref_tab_functions.inc.php');
20 /* whether or not, any settings are being changed when this page loads. */
21 /* ie. is ANY action being performed right now?                                                 */
22
23 $action = false;
24
25 if (!$_SESSION['valid_user']) {                         
26         /* we're not logged in */
27         $msg->addFeedback('PREFS_LOGIN');
28 }
29
30 if (isset($_POST['submit']) || isset($_POST['set_default'])) {
31         if (isset($_POST['submit']))
32         {
33                 /* custom prefs */
34                 // atutor settings (tab 0)
35                 $temp_prefs['PREF_NUMBERING']      = intval($_POST['numbering']);
36                 $temp_prefs['PREF_THEME']          = $addslashes($_POST['theme']);
37                 $temp_prefs['PREF_TIMEZONE']         = $addslashes($_POST['time_zone']);
38                 $temp_prefs['PREF_JUMP_REDIRECT']  = intval($_POST['use_jump_redirect']);
39                 $temp_prefs['PREF_FORM_FOCUS']     = intval($_POST['form_focus']);
40                 $temp_prefs['PREF_CONTENT_EDITOR'] = intval($_POST['content_editor']);
41                 $temp_prefs['PREF_SHOW_GUIDE']     = intval($_POST['show_guide']);
42                 
43                 // display settings (tab 1)
44                 $temp_prefs['PREF_FONT_FACE']      = $addslashes($_POST['fontface']);
45                 $temp_prefs['PREF_FONT_TIMES']     = $addslashes($_POST['font_times']);
46                 $temp_prefs['PREF_FG_COLOUR']      = $addslashes($_POST['fg']);
47                 $temp_prefs['PREF_BG_COLOUR']      = $addslashes($_POST['bg']);
48                 $temp_prefs['PREF_HL_COLOUR']      = $addslashes($_POST['hl']);
49         
50                 // content settings (tab 2)
51                 $temp_prefs['PREF_USE_ALTERNATIVE_TO_TEXT'] = intval($_POST['use_alternative_to_text']);
52                 $temp_prefs['PREF_ALT_TO_TEXT'] = $addslashes($_POST['preferred_alt_to_text']);
53                 $temp_prefs['PREF_ALT_TO_TEXT_APPEND_OR_REPLACE'] = $addslashes($_POST['alt_to_text_append_or_replace']);
54                 $temp_prefs['PREF_ALT_TEXT_PREFER_LANG'] = $addslashes($_POST['alt_text_prefer_lang']);
55                 $temp_prefs['PREF_USE_ALTERNATIVE_TO_AUDIO'] = intval($_POST['use_alternative_to_audio']);
56                 $temp_prefs['PREF_ALT_TO_AUDIO'] = $addslashes($_POST['preferred_alt_to_audio']);
57                 $temp_prefs['PREF_ALT_TO_AUDIO_APPEND_OR_REPLACE'] = $addslashes($_POST['alt_to_audio_append_or_replace']);
58                 $temp_prefs['PREF_ALT_AUDIO_PREFER_LANG'] = $addslashes($_POST['alt_audio_prefer_lang']);
59                 $temp_prefs['PREF_USE_ALTERNATIVE_TO_VISUAL'] = intval($_POST['use_alternative_to_visual']);
60                 $temp_prefs['PREF_ALT_TO_VISUAL'] = $addslashes($_POST['preferred_alt_to_visual']);
61                 $temp_prefs['PREF_ALT_TO_VISUAL_APPEND_OR_REPLACE'] = $addslashes($_POST['alt_to_visual_append_or_replace']);
62                 $temp_prefs['PREF_ALT_VISUAL_PREFER_LANG'] = $addslashes($_POST['alt_visual_prefer_lang']);
63         
64                 // tool settings (tab 3)
65                 $temp_prefs['PREF_DICTIONARY'] = intval($_POST['dictionary_val']);
66                 $temp_prefs['PREF_THESAURUS'] = intval($_POST['thesaurus_val']);
67                 $temp_prefs['PREF_NOTE_TAKING'] = intval($_POST['note_taking_val']);
68                 $temp_prefs['PREF_CALCULATOR'] = intval($_POST['calculator_val']);
69                 $temp_prefs['PREF_ABACUS'] = intval($_POST['abacus_val']);
70                 $temp_prefs['PREF_ATLAS'] = intval($_POST['atlas_val']);
71                 $temp_prefs['PREF_ENCYCLOPEDIA'] = intval($_POST['encyclopedia_val']);  
72         
73                 // control settings (tab 4)
74                 $temp_prefs['PREF_SHOW_CONTENTS'] = intval($_POST['show_contents']);
75                 $temp_prefs['PREF_SHOW_NEXT_PREVIOUS_BUTTONS'] = intval($_POST['show_next_previous_buttons']);
76                 $temp_prefs['PREF_SHOW_BREAD_CRUMBS'] = intval($_POST['show_bread_crumbs']);
77
78                 $mnot = intval($_POST['mnot']);
79                 if (isset($_POST['auto'])) $auto_login = $_POST['auto'];
80         }
81         else if (isset($_POST['set_default']))
82         {
83                 $sql    = "SELECT value FROM ".TABLE_PREFIX."config WHERE name='pref_defaults'";
84                 $result = mysql_query($sql, $db);
85                 
86                 if (mysql_num_rows($result) > 0)
87                 {
88                         $row_defaults = mysql_fetch_assoc($result);
89                         $default = $row_defaults["value"];
90                         
91                         $temp_prefs = unserialize($default);
92                         
93                         // Many new preferences are introduced in 1.6.2 that are missing in old admin 
94                         // default preference string. Solve this case by completing settings on new
95                         // preferences with $_config_defaults
96                         foreach (unserialize($_config_defaults['pref_defaults']) as $name => $value)
97                                 if (!isset($temp_prefs[$name])) $temp_prefs[$name] = $value;
98                 }
99                 else
100                         $temp_prefs = unserialize($_config_defaults['pref_defaults']);
101
102                 $sql    = "SELECT value FROM ".TABLE_PREFIX."config WHERE name='pref_inbox_notify'";
103                 $result = mysql_query($sql, $db);
104                 if (mysql_num_rows($result) > 0)
105                 {
106                         $row_notify = mysql_fetch_assoc($result);
107                         $mnot = $row_notify["value"];
108                 }
109                 else
110                         $mnot = $_config_defaults['pref_inbox_notify'];
111                 
112                 $sql    = "SELECT value FROM ".TABLE_PREFIX."config WHERE name='pref_is_auto_login'";
113                 $result = mysql_query($sql, $db);
114                 if (mysql_num_rows($result) > 0)
115                 {
116                         $row_is_auto_login = mysql_fetch_assoc($result);
117                         $auto_login = $row_is_auto_login["value"];
118                 }
119                 else
120                         $auto_login = $_config_defaults['pref_is_auto_login'];
121                 
122                 unset($_POST);
123         }
124
125         /* we do this instead of assigning to the $_SESSION directly, b/c       */
126         /* assign_session_prefs functionality might change slightly.            */
127         assign_session_prefs($temp_prefs);
128
129         /* save as pref for ALL courses */
130         save_prefs();
131
132         //update auto-login settings
133         if (isset($auto_login) && ($auto_login == 'disable')) {
134                 $parts = parse_url(AT_BASE_HREF);
135                 $is_cookie_login_set = setcookie('ATLogin', '', time()-172800, $parts['path']);
136                 $is_cookie_paa_set = setcookie('ATPass',  '', time()-172800, $parts['path']);
137
138                 // The usage of flag $is_auto_login is because the set cookies are only accessible at the next page reload
139                 if ($is_cookie_login_set && $is_cookie_pass_set) $is_auto_login = 'enable';
140                 else $is_auto_login = 'disable';
141         } else if (isset($auto_login) && ($auto_login == 'enable')) {
142                 $parts = parse_url(AT_BASE_HREF);
143                 $sql    = "SELECT password FROM ".TABLE_PREFIX."members WHERE member_id=$_SESSION[member_id]";
144                 $result = mysql_query($sql, $db);
145                 $row    = mysql_fetch_assoc($result);
146                 $password = $row["password"];
147                 $is_cookie_login_set = setcookie('ATLogin', $_SESSION['login'], time()+172800, $parts['path']);
148                 $is_cookie_pass_set = setcookie('ATPass',  $password, time()+172800, $parts['path']);
149                 
150                 if ($is_cookie_login_set && $is_cookie_pass_set) $is_auto_login = 'enable';
151                 else $is_auto_login = 'disable';
152         }
153
154         /* also update message notification pref */
155         $sql = "UPDATE ".TABLE_PREFIX."members SET inbox_notify =". $mnot .", creation_date=creation_date, last_login=last_login WHERE member_id = $_SESSION[member_id]";
156         $result = mysql_query($sql, $db);
157
158         $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
159 }
160
161 $sql    = "SELECT inbox_notify FROM ".TABLE_PREFIX."members WHERE member_id=$_SESSION[member_id]";
162 $result = mysql_query($sql, $db);
163 $row_notify = mysql_fetch_assoc($result);
164
165 $languages = $languageManager->getAvailableLanguages();
166
167 /* page contents starts here */
168 $savant->assign('notify', $row_notify['inbox_notify']);
169 $savant->assign('languages', $languages);
170 $savant->assign('is_auto_login', $is_auto_login);
171
172 $savant->display('users/preferences.tmpl.php');
173
174 ?>