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

Revision 4208, 7.5 KB checked in by rvelices, 10 years ago (diff)

admin multi view plugin : new option "do not save page visits to history table"

  • 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_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
30if ( 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}
43if (pwg_get_session_var( 'multiview_as', $user['id']) != $user['id'] )
44  $view_as_user = build_user( pwg_get_session_var( 'multiview_as',0), false);
45else
46  $view_as_user = $user;
47
48if ( isset($_GET['theme']) )
49{
50  pwg_set_session_var( 'multiview_theme', $_GET['theme'] );
51  $refresh_main = true;
52}
53
54if ( isset($_GET['lang']) )
55{
56  pwg_set_session_var( 'multiview_lang', $_GET['lang'] );
57  $refresh_main = true;
58}
59
60if ( 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
69if ( 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
79if ( 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
88if ( 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 = '
102SELECT '.$conf['user_fields']['id'].' AS id,'.$conf['user_fields']['username'].' AS username
103FROM '.USERS_TABLE;
104if (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;">';
116foreach( $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_template = '';
132$themes_html='<select onchange="document.location = this.options[this.selectedIndex].value;">';
133foreach (get_pwg_themes() as $pwg_template)
134{
135  $selected = $pwg_template == pwg_get_session_var( 'multiview_theme', $view_as_user['template'].'/'.$view_as_user['theme'] ) ? 'selected="selected"' : '';
136  $my_template = $selected == '' ? $my_template : $view_as_user['template'].'/theme/'.$view_as_user['theme'];
137  $themes_html .=
138    '<option value="'
139    .$my_url.'?theme='.$pwg_template
140    .'" '.$selected.'>'
141    .$pwg_template
142    .'</option>';
143}
144$themes_html .= '</select>';
145
146// +-----------------------------------------------------------------------+
147// | language                                                              |
148$lang_html='<select onchange="document.location = this.options[this.selectedIndex].value;">';
149foreach (get_languages() as $language_code => $language_name)
150{
151  $selected = $language_code == pwg_get_session_var( 'multiview_lang', $view_as_user['language'] ) ? 'selected="selected"' : '';
152  $lang_html .=
153    '<option value="'
154    .$my_url.'?lang='.$language_code
155    .'" '.$selected.'>'
156    .$language_name
157    .'</option>';
158}
159$lang_html .= '</select>';
160
161// +-----------------------------------------------------------------------+
162// | show queries                                                          |
163$show_queries_html='';
164if (!$conf['show_queries'])
165{
166  if ( !pwg_get_session_var( 'multiview_show_queries', 0 ) )
167    $show_queries_html.='<a href="'.$my_url.'?show_queries=1">Show SQL queries</a>';
168  else
169    $show_queries_html.='<a href="'.$my_url.'?show_queries=0">Hide SQL queries</a>';
170}
171
172// +-----------------------------------------------------------------------+
173// | debug language                                                        |
174$debug_l10n_html='';
175if (!$conf['debug_l10n'])
176{
177  if ( !pwg_get_session_var( 'multiview_debug_l10n', 0 ) )
178    $debug_l10n_html.='<a href="'.$my_url.'?debug_l10n=1">Debug language</a>';
179  else
180    $debug_l10n_html.='<a href="'.$my_url.'?debug_l10n=0">Revert debug language</a>';
181}
182
183// +-----------------------------------------------------------------------+
184// | debug template                                                        |
185$debug_template_html='';
186if (!$conf['debug_template'])
187{
188  if ( !pwg_get_session_var( 'multiview_debug_template', 0 ) )
189    $debug_template_html.='<a href="'.$my_url.'?debug_template=1">Debug template</a>';
190  else
191    $debug_template_html.='<a href="'.$my_url.'?debug_template=0">Revert debug template</a>';
192}
193
194// +-----------------------------------------------------------------------+
195// | no history                                                            |
196$no_history_html='';
197if ( !pwg_get_session_var( 'multiview_no_history', 0 ) )
198  $no_history_html.='<a href="'.$my_url.'?no_history=1">Don\'t save to visit history</a>';
199else
200  $no_history_html.='<a href="'.$my_url.'?no_history=0">Save to visit history</a>';
201
202?>
203<html>
204<head>
205<meta http-equiv="Content-Type" content="text/html; charset=<?php echo get_pwg_charset() ?>">
206<title>Controller</title>
207<?php
208// Controller will be displayed  with  the **real admin template** (without Any if it has been removed)
209if ( $my_template !== '') {
210  $my_template = get_root_url().'template/'.$my_template.'/theme.css';
211  echo '<link rel="stylesheet" type="text/css" href="' . $my_template .'">';
212}
213?>
214
215</head>
216<body>
217<div>
218<script type="text/javascript">
219if (window.opener==null) {
220  window.close();
221  document.write("<"+"h2>How did you get here ???<"+"/h2>");
222}
223</script>
224
225<table>
226<tr><td>User</td><td><?php echo $users_html; ?></td></tr>
227
228<tr><td>Theme</td><td><?php echo $themes_html; ?></td></tr>
229
230<tr><td>Lang</td><td><?php echo $lang_html; ?></td></tr>
231</table>
232<?php echo implode( "<br/>\n", array($show_queries_html, $debug_l10n_html, $debug_template_html, $no_history_html) ); ?>
233
234<script type="text/javascript">
235<?php
236  if ($refresh_main) echo '
237window.opener.location = window.opener.location;';
238?>
239</script>
240</div>
241</body>
242</html>
Note: See TracBrowser for help on using the repository browser.