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