source: trunk/plugins/admin_multi_view/controller.php @ 8126

Revision 8126, 7.8 KB checked in by patdenice, 9 years ago (diff)

feature 2060: Remove adviser mode.
First commit: only php files.

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