source: branches/2.0/plugins/admin_multi_view/controller.php @ 2727

Last change on this file since 2727 was 2490, checked in by rvelices, 16 years ago
  • fix an issue on category modify (lock/unlock display was reversed) and improved queries on submit
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 6.8 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?>
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
29if ( 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  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
87$my_url = get_root_url().'plugins/'.basename(dirname(__FILE__)).'/'.basename(__FILE__);
88
89// +-----------------------------------------------------------------------+
90// | users                                                                 |
91$query = '
92SELECT '.$conf['user_fields']['id'].' AS id,'.$conf['user_fields']['username'].' AS username
93FROM '.USERS_TABLE;
94if (is_adviser())
95{
96  $query .='
97  WHERE '.$conf['user_fields']['id']. ' IN ('.$user['id'].','.$conf['guest_id'].')
98';
99}
100$query .='
101  ORDER BY CONVERT('.$conf['user_fields']['username'].',CHAR)
102;';
103$user_map = simple_hash_from_query($query, 'id', 'username');
104
105$users_html = '<select onchange="document.location = this.options[this.selectedIndex].value;">';
106foreach( $user_map as $id=>$username)
107{
108  $selected = ($id==$view_as_user['id']) ? 'selected="selected"' : '';
109  $users_html .=
110    '<option value="'
111    .$my_url.'?view_as='.$id
112    .'" '.$selected.'>'
113    .$username
114    .'</option>';
115}
116$users_html.= '</select>';
117
118
119// +-----------------------------------------------------------------------+
120// | templates                                                             |
121$my_template = '';
122$themes_html='<select onchange="document.location = this.options[this.selectedIndex].value;">';
123foreach (get_pwg_themes() as $pwg_template)
124{
125  $selected = $pwg_template == pwg_get_session_var( 'multiview_theme', $view_as_user['template'].'/'.$view_as_user['theme'] ) ? 'selected="selected"' : '';
126  $my_template = $selected == '' ? $my_template : $view_as_user['template'].'/theme/'.$view_as_user['theme'];
127  $themes_html .=
128    '<option value="'
129    .$my_url.'?theme='.$pwg_template
130    .'" '.$selected.'>'
131    .$pwg_template
132    .'</option>';
133}
134$themes_html .= '</select>';
135
136// +-----------------------------------------------------------------------+
137// | language                                                              |
138$lang_html='<select onchange="document.location = this.options[this.selectedIndex].value;">';
139foreach (get_languages() as $language_code => $language_name)
140{
141  $selected = $language_code == pwg_get_session_var( 'multiview_lang', $view_as_user['language'] ) ? 'selected="selected"' : '';
142  $lang_html .=
143    '<option value="'
144    .$my_url.'?lang='.$language_code
145    .'" '.$selected.'>'
146    .$language_name
147    .'</option>';
148}
149$lang_html .= '</select>';
150
151// +-----------------------------------------------------------------------+
152// | show queries                                                          |
153$show_queries_html='';
154if (!$conf['show_queries'])
155{
156  if ( !pwg_get_session_var( 'multiview_show_queries', 0 ) )
157    $show_queries_html.='<a href="'.$my_url.'?show_queries=1">Show SQL queries</a>';
158  else
159    $show_queries_html.='<a href="'.$my_url.'?show_queries=0">Hide SQL queries</a>';
160}
161
162// +-----------------------------------------------------------------------+
163// | debug language                                                        |
164$debug_l10n_html='';
165if (!$conf['debug_l10n'])
166{
167  if ( !pwg_get_session_var( 'multiview_debug_l10n', 0 ) )
168    $debug_l10n_html.='<a href="'.$my_url.'?debug_l10n=1">Debug language</a>';
169  else
170    $debug_l10n_html.='<a href="'.$my_url.'?debug_l10n=0">Revert debug language</a>';
171}
172
173// +-----------------------------------------------------------------------+
174// | debug template                                                        |
175$debug_template_html='';
176if (!$conf['debug_template'])
177{
178  if ( !pwg_get_session_var( 'multiview_debug_template', 0 ) )
179    $debug_template_html.='<a href="'.$my_url.'?debug_template=1">Debug template</a>';
180  else
181    $debug_template_html.='<a href="'.$my_url.'?debug_template=0">Revert debug template</a>';
182}
183
184?>
185<html>
186<head>
187<meta http-equiv="Content-Type" content="text/html; charset=<?php echo get_pwg_charset() ?>">
188<title>Controller</title>
189<?php
190// Controller will be displayed  with  the **real admin template** (without Any if it has been removed)
191if ( $my_template !== '') {
192  $my_template = get_root_url().'template/'.$my_template.'/theme.css';
193  echo '<link rel="stylesheet" type="text/css" href="' . $my_template .'">';
194}
195?>
196
197</head>
198<body>
199<div>
200<script type="text/javascript">
201if (window.opener==null) {
202  window.close();
203  document.write("<"+"h2>How did you get here ???<"+"/h2>");
204}
205</script>
206
207<table>
208<tr><td>User</td><td><?php echo $users_html; ?></td></tr>
209
210<tr><td>Theme</td><td><?php echo $themes_html; ?></td></tr>
211
212<tr><td>Lang</td><td><?php echo $lang_html; ?></td></tr>
213</table>
214<?php echo implode( "<br/>\n", array($show_queries_html, $debug_l10n_html, $debug_template_html) ); ?>
215
216<script type="text/javascript">
217<?php
218  if ($refresh_main) echo '
219window.opener.location = window.opener.location;';
220?>
221</script>
222</div>
223</body>
224</html>
Note: See TracBrowser for help on using the repository browser.