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

Revision 15150, 8.0 KB checked in by mistic100, 8 years ago (diff)

add link to purge templates

  • 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
106if ( isset($_GET['purge_template']) )
107{
108  pwg_set_session_var( 'purge_template', 1 );
109  $refresh_main = true;
110}
111
112$my_url = get_root_url().'plugins/'.basename(dirname(__FILE__)).'/'.basename(__FILE__);
113
114// +-----------------------------------------------------------------------+
115// | users                                                                 |
116$query = '
117SELECT '.$conf['user_fields']['id'].' AS id,'.$conf['user_fields']['username'].' AS username
118FROM '.USERS_TABLE.'
119  ORDER BY CONVERT('.$conf['user_fields']['username'].',CHAR)
120;';
121$user_map = simple_hash_from_query($query, 'id', 'username');
122
123$users_html = '<select onchange="document.location = this.options[this.selectedIndex].value;">';
124foreach( $user_map as $id=>$username)
125{
126  $selected = ($id==$view_as_user['id']) ? 'selected="selected"' : '';
127  $users_html .=
128    '<option value="'
129    .$my_url.'?view_as='.$id
130    .'" '.$selected.'>'
131    .$username
132    .'</option>';
133}
134$users_html.= '</select>';
135
136
137// +-----------------------------------------------------------------------+
138// | templates                                                             |
139$my_theme = '';
140$themes_html='<select onchange="document.location = this.options[this.selectedIndex].value;">';
141include_once(PHPWG_ROOT_PATH.'admin/include/themes.class.php');
142$themes = new themes();
143foreach ($themes->fs_themes as $pwg_theme => $fs_theme)
144{
145  $selected = $pwg_theme == pwg_get_session_var( 'multiview_theme', $view_as_user['theme'] ) ? 'selected="selected"' : '';
146  $my_theme = $selected == '' ? $my_theme : 'themes/'.$view_as_user['theme'];
147  $themes_html .=
148    '<option value="'
149    .$my_url.'?theme='.$pwg_theme
150    .'" '.$selected.'>'
151    .$pwg_theme
152    .'</option>';
153}
154$themes_html .= '</select>';
155
156// +-----------------------------------------------------------------------+
157// | language                                                              |
158$lang_html='<select onchange="document.location = this.options[this.selectedIndex].value;">';
159foreach (get_languages() as $language_code => $language_name)
160{
161  $selected = $language_code == pwg_get_session_var( 'multiview_lang', $view_as_user['language'] ) ? 'selected="selected"' : '';
162  $lang_html .=
163    '<option value="'
164    .$my_url.'?lang='.$language_code
165    .'" '.$selected.'>'
166    .$language_name
167    .'</option>';
168}
169$lang_html .= '</select>';
170
171// +-----------------------------------------------------------------------+
172// | show queries                                                          |
173$show_queries_html='';
174if (!$conf['show_queries'])
175{
176  if ( !pwg_get_session_var( 'multiview_show_queries', 0 ) )
177    $show_queries_html.='<a href="'.$my_url.'?show_queries=1">Show SQL queries</a>';
178  else
179    $show_queries_html.='<a href="'.$my_url.'?show_queries=0">Hide SQL queries</a>';
180}
181
182// +-----------------------------------------------------------------------+
183// | debug language                                                        |
184$debug_l10n_html='';
185if (!$conf['debug_l10n'])
186{
187  if ( !pwg_get_session_var( 'multiview_debug_l10n', 0 ) )
188    $debug_l10n_html.='<a href="'.$my_url.'?debug_l10n=1">Debug language</a>';
189  else
190    $debug_l10n_html.='<a href="'.$my_url.'?debug_l10n=0">Revert debug language</a>';
191}
192
193// +-----------------------------------------------------------------------+
194// | debug template                                                        |
195$debug_template_html='';
196if (!$conf['debug_template'])
197{
198  if ( !pwg_get_session_var( 'multiview_debug_template', 0 ) )
199    $debug_template_html.='<a href="'.$my_url.'?debug_template=1">Debug template</a>';
200  else
201    $debug_template_html.='<a href="'.$my_url.'?debug_template=0">Revert debug template</a>';
202}
203
204// +-----------------------------------------------------------------------+
205// | template combine files                                                |
206$template_combine_files_html='';
207if ($conf['template_combine_files'])
208{
209  if ( pwg_get_session_var( 'multiview_template_combine_files', 1 ) )
210    $template_combine_files_html.='<a href="'.$my_url.'?template_combine_files=0">Don\'t combine js&amp;css</a>';
211  else
212    $template_combine_files_html.='<a href="'.$my_url.'?template_combine_files=1">Combine js&amp;css</a>';
213}
214
215// +-----------------------------------------------------------------------+
216// | no history                                                            |
217$no_history_html='';
218if ( !pwg_get_session_var( 'multiview_no_history', 0 ) )
219  $no_history_html.='<a href="'.$my_url.'?no_history=1">Don\'t save to visit history</a>';
220else
221  $no_history_html.='<a href="'.$my_url.'?no_history=0">Save to visit history</a>';
222
223?>
224<html>
225<head>
226<meta http-equiv="Content-Type" content="text/html; charset=<?php echo get_pwg_charset() ?>">
227<title>Controller</title>
228
229</head>
230<body>
231<div>
232<script type="text/javascript">
233if (window.opener==null) {
234  window.close();
235  document.write("<"+"h2>How did you get here ???<"+"/h2>");
236}
237</script>
238
239<table>
240<tr><td>User</td><td><?php echo $users_html; ?></td></tr>
241
242<tr><td>Theme</td><td><?php echo $themes_html; ?></td></tr>
243
244<tr><td>Lang</td><td><?php echo $lang_html; ?></td></tr>
245</table>
246<?php echo implode( "<br/>\n", array($show_queries_html, $debug_l10n_html, $debug_template_html, $template_combine_files_html, $no_history_html) ); ?>
247<br/><a href="<?php echo $my_url; ?>?purge_template">Purge compiled templates</a>
248
249<script type="text/javascript">
250<?php
251  if ($refresh_main) echo '
252window.opener.location = window.opener.location;';
253?>
254</script>
255</div>
256</body>
257</html>
Note: See TracBrowser for help on using the repository browser.