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

Last change on this file since 28446 was 20977, checked in by rvelices, 12 years ago

admin multi view smaller controller size (use sans serif fonts, less margins ...)

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