1 | <?php |
---|
2 | define('MULTIVIEW_CONTROLLER', 1); |
---|
3 | define('PHPWG_ROOT_PATH','../../'); |
---|
4 | include_once( PHPWG_ROOT_PATH.'include/common.inc.php' ); |
---|
5 | |
---|
6 | if (!is_admin() or !function_exists('multiview_user_init') ) |
---|
7 | { |
---|
8 | pwg_unset_session_var( 'multiview_as' ); |
---|
9 | pwg_unset_session_var( 'multiview_theme' ); |
---|
10 | pwg_unset_session_var( 'multiview_lang' ); |
---|
11 | pwg_unset_session_var( 'multiview_show_queries' ); |
---|
12 | pwg_unset_session_var( 'multiview_debug_l10n' ); |
---|
13 | pwg_unset_session_var( 'multiview_debug_template' ); |
---|
14 | pwg_unset_session_var( 'multiview_no_history' ); |
---|
15 | ?> |
---|
16 | |
---|
17 | <script type="text/javascript"> |
---|
18 | window.close(); |
---|
19 | </script> |
---|
20 | <?php |
---|
21 | exit(); |
---|
22 | } |
---|
23 | ?> |
---|
24 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" |
---|
25 | "http://www.w3.org/TR/html4/strict.dtd"> |
---|
26 | <?php |
---|
27 | |
---|
28 | $refresh_main = false; |
---|
29 | |
---|
30 | if ( isset($_GET['view_as']) ) |
---|
31 | { |
---|
32 | if ( is_adviser() and $user['id']!=$_GET['view_as'] and $conf['guest_id']!=$_GET['view_as']) |
---|
33 | die('security error'); |
---|
34 | if ($user['id']===$_GET['view_as']) |
---|
35 | pwg_unset_session_var( 'multiview_as' ); |
---|
36 | else |
---|
37 | pwg_set_session_var( 'multiview_as', (int)$_GET['view_as'] ); |
---|
38 | // user change resets theme/lang |
---|
39 | pwg_unset_session_var( 'multiview_theme' ); |
---|
40 | pwg_unset_session_var( 'multiview_lang' ); |
---|
41 | $refresh_main = true; |
---|
42 | } |
---|
43 | if (pwg_get_session_var( 'multiview_as', $user['id']) != $user['id'] ) |
---|
44 | $view_as_user = build_user( pwg_get_session_var( 'multiview_as',0), false); |
---|
45 | else |
---|
46 | $view_as_user = $user; |
---|
47 | |
---|
48 | if ( isset($_GET['theme']) ) |
---|
49 | { |
---|
50 | pwg_set_session_var( 'multiview_theme', $_GET['theme'] ); |
---|
51 | $refresh_main = true; |
---|
52 | } |
---|
53 | |
---|
54 | if ( isset($_GET['lang']) ) |
---|
55 | { |
---|
56 | pwg_set_session_var( 'multiview_lang', $_GET['lang'] ); |
---|
57 | $refresh_main = true; |
---|
58 | } |
---|
59 | |
---|
60 | if ( isset($_GET['show_queries']) ) |
---|
61 | { |
---|
62 | if ( $_GET['show_queries']> 0 ) |
---|
63 | pwg_set_session_var( 'multiview_show_queries', 1 ); |
---|
64 | else |
---|
65 | pwg_unset_session_var( 'multiview_show_queries' ); |
---|
66 | $refresh_main = true; |
---|
67 | } |
---|
68 | |
---|
69 | if ( isset($_GET['debug_l10n']) ) |
---|
70 | { |
---|
71 | if ( $_GET['debug_l10n']>0 ) |
---|
72 | pwg_set_session_var( 'multiview_debug_l10n', 1 ); |
---|
73 | else |
---|
74 | pwg_unset_session_var( 'multiview_debug_l10n' ); |
---|
75 | $refresh_main = true; |
---|
76 | } |
---|
77 | |
---|
78 | |
---|
79 | if ( isset($_GET['debug_template']) ) |
---|
80 | { |
---|
81 | if ( $_GET['debug_template']>0 ) |
---|
82 | pwg_set_session_var( 'multiview_debug_template', 1 ); |
---|
83 | else |
---|
84 | pwg_unset_session_var( 'multiview_debug_template' ); |
---|
85 | $refresh_main = true; |
---|
86 | } |
---|
87 | |
---|
88 | if ( isset($_GET['no_history']) ) |
---|
89 | { |
---|
90 | if ( $_GET['no_history']>0 ) |
---|
91 | pwg_set_session_var( 'multiview_no_history', 1 ); |
---|
92 | else |
---|
93 | pwg_unset_session_var( 'multiview_no_history' ); |
---|
94 | $refresh_main = true; |
---|
95 | } |
---|
96 | |
---|
97 | $my_url = get_root_url().'plugins/'.basename(dirname(__FILE__)).'/'.basename(__FILE__); |
---|
98 | |
---|
99 | // +-----------------------------------------------------------------------+ |
---|
100 | // | users | |
---|
101 | $query = ' |
---|
102 | SELECT '.$conf['user_fields']['id'].' AS id,'.$conf['user_fields']['username'].' AS username |
---|
103 | FROM '.USERS_TABLE; |
---|
104 | if (is_adviser()) |
---|
105 | { |
---|
106 | $query .=' |
---|
107 | WHERE '.$conf['user_fields']['id']. ' IN ('.$user['id'].','.$conf['guest_id'].') |
---|
108 | '; |
---|
109 | } |
---|
110 | $query .=' |
---|
111 | ORDER BY CONVERT('.$conf['user_fields']['username'].',CHAR) |
---|
112 | ;'; |
---|
113 | $user_map = simple_hash_from_query($query, 'id', 'username'); |
---|
114 | |
---|
115 | $users_html = '<select onchange="document.location = this.options[this.selectedIndex].value;">'; |
---|
116 | foreach( $user_map as $id=>$username) |
---|
117 | { |
---|
118 | $selected = ($id==$view_as_user['id']) ? 'selected="selected"' : ''; |
---|
119 | $users_html .= |
---|
120 | '<option value="' |
---|
121 | .$my_url.'?view_as='.$id |
---|
122 | .'" '.$selected.'>' |
---|
123 | .$username |
---|
124 | .'</option>'; |
---|
125 | } |
---|
126 | $users_html.= '</select>'; |
---|
127 | |
---|
128 | |
---|
129 | // +-----------------------------------------------------------------------+ |
---|
130 | // | templates | |
---|
131 | $my_theme = ''; |
---|
132 | $themes_html='<select onchange="document.location = this.options[this.selectedIndex].value;">'; |
---|
133 | include_once(PHPWG_ROOT_PATH.'admin/include/themes.class.php'); |
---|
134 | $themes = new themes(); |
---|
135 | foreach ($themes->fs_themes as $pwg_theme => $fs_theme) |
---|
136 | { |
---|
137 | $selected = $pwg_theme == pwg_get_session_var( 'multiview_theme', $view_as_user['theme'] ) ? 'selected="selected"' : ''; |
---|
138 | $my_theme = $selected == '' ? $my_theme : 'themes/'.$view_as_user['theme']; |
---|
139 | $themes_html .= |
---|
140 | '<option value="' |
---|
141 | .$my_url.'?theme='.$pwg_theme |
---|
142 | .'" '.$selected.'>' |
---|
143 | .$pwg_theme |
---|
144 | .'</option>'; |
---|
145 | } |
---|
146 | $themes_html .= '</select>'; |
---|
147 | |
---|
148 | // +-----------------------------------------------------------------------+ |
---|
149 | // | language | |
---|
150 | $lang_html='<select onchange="document.location = this.options[this.selectedIndex].value;">'; |
---|
151 | foreach (get_languages() as $language_code => $language_name) |
---|
152 | { |
---|
153 | $selected = $language_code == pwg_get_session_var( 'multiview_lang', $view_as_user['language'] ) ? 'selected="selected"' : ''; |
---|
154 | $lang_html .= |
---|
155 | '<option value="' |
---|
156 | .$my_url.'?lang='.$language_code |
---|
157 | .'" '.$selected.'>' |
---|
158 | .$language_name |
---|
159 | .'</option>'; |
---|
160 | } |
---|
161 | $lang_html .= '</select>'; |
---|
162 | |
---|
163 | // +-----------------------------------------------------------------------+ |
---|
164 | // | show queries | |
---|
165 | $show_queries_html=''; |
---|
166 | if (!$conf['show_queries']) |
---|
167 | { |
---|
168 | if ( !pwg_get_session_var( 'multiview_show_queries', 0 ) ) |
---|
169 | $show_queries_html.='<a href="'.$my_url.'?show_queries=1">Show SQL queries</a>'; |
---|
170 | else |
---|
171 | $show_queries_html.='<a href="'.$my_url.'?show_queries=0">Hide SQL queries</a>'; |
---|
172 | } |
---|
173 | |
---|
174 | // +-----------------------------------------------------------------------+ |
---|
175 | // | debug language | |
---|
176 | $debug_l10n_html=''; |
---|
177 | if (!$conf['debug_l10n']) |
---|
178 | { |
---|
179 | if ( !pwg_get_session_var( 'multiview_debug_l10n', 0 ) ) |
---|
180 | $debug_l10n_html.='<a href="'.$my_url.'?debug_l10n=1">Debug language</a>'; |
---|
181 | else |
---|
182 | $debug_l10n_html.='<a href="'.$my_url.'?debug_l10n=0">Revert debug language</a>'; |
---|
183 | } |
---|
184 | |
---|
185 | // +-----------------------------------------------------------------------+ |
---|
186 | // | debug template | |
---|
187 | $debug_template_html=''; |
---|
188 | if (!$conf['debug_template']) |
---|
189 | { |
---|
190 | if ( !pwg_get_session_var( 'multiview_debug_template', 0 ) ) |
---|
191 | $debug_template_html.='<a href="'.$my_url.'?debug_template=1">Debug template</a>'; |
---|
192 | else |
---|
193 | $debug_template_html.='<a href="'.$my_url.'?debug_template=0">Revert debug template</a>'; |
---|
194 | } |
---|
195 | |
---|
196 | // +-----------------------------------------------------------------------+ |
---|
197 | // | no history | |
---|
198 | $no_history_html=''; |
---|
199 | if ( !pwg_get_session_var( 'multiview_no_history', 0 ) ) |
---|
200 | $no_history_html.='<a href="'.$my_url.'?no_history=1">Don\'t save to visit history</a>'; |
---|
201 | else |
---|
202 | $no_history_html.='<a href="'.$my_url.'?no_history=0">Save to visit history</a>'; |
---|
203 | |
---|
204 | ?> |
---|
205 | <html> |
---|
206 | <head> |
---|
207 | <meta http-equiv="Content-Type" content="text/html; charset=<?php echo get_pwg_charset() ?>"> |
---|
208 | <title>Controller</title> |
---|
209 | |
---|
210 | </head> |
---|
211 | <body> |
---|
212 | <div> |
---|
213 | <script type="text/javascript"> |
---|
214 | if (window.opener==null) { |
---|
215 | window.close(); |
---|
216 | document.write("<"+"h2>How did you get here ???<"+"/h2>"); |
---|
217 | } |
---|
218 | </script> |
---|
219 | |
---|
220 | <table> |
---|
221 | <tr><td>User</td><td><?php echo $users_html; ?></td></tr> |
---|
222 | |
---|
223 | <tr><td>Theme</td><td><?php echo $themes_html; ?></td></tr> |
---|
224 | |
---|
225 | <tr><td>Lang</td><td><?php echo $lang_html; ?></td></tr> |
---|
226 | </table> |
---|
227 | <?php echo implode( "<br/>\n", array($show_queries_html, $debug_l10n_html, $debug_template_html, $no_history_html) ); ?> |
---|
228 | |
---|
229 | <script type="text/javascript"> |
---|
230 | <?php |
---|
231 | if ($refresh_main) echo ' |
---|
232 | window.opener.location = window.opener.location;'; |
---|
233 | ?> |
---|
234 | </script> |
---|
235 | </div> |
---|
236 | </body> |
---|
237 | </html> |
---|