aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrvelices <rv-github@modusoptimus.com>2008-05-15 00:09:44 +0000
committerrvelices <rv-github@modusoptimus.com>2008-05-15 00:09:44 +0000
commit097a91db3997d00642273e3884d18fac7ada9c70 (patch)
tree111ce7e7e3b831fa946d25bcf175950b254bcac3
parent59262acebdb83fe29acc0c449eb338197ba97972 (diff)
- admin multi view plugin allows to view the gallery as any user (not only guest/admin)
git-svn-id: http://piwigo.org/svn/branches/branch-1_7@2341 68402e56-0260-453c-a942-63ccdbb3a9ee
-rw-r--r--plugins/admin_multi_view/controller.php115
1 files changed, 76 insertions, 39 deletions
diff --git a/plugins/admin_multi_view/controller.php b/plugins/admin_multi_view/controller.php
index 32ad18b88..f62dfeefa 100644
--- a/plugins/admin_multi_view/controller.php
+++ b/plugins/admin_multi_view/controller.php
@@ -11,6 +11,7 @@ if (!is_admin() or !function_exists('multiview_user_init') )
pwg_unset_session_var( 'multiview_show_queries' );
pwg_unset_session_var( 'multiview_debug_l10n' );
?>
+
<script type="text/javascript">
window.close();
</script>
@@ -20,18 +21,20 @@ if (!is_admin() or !function_exists('multiview_user_init') )
$refresh_main = false;
-if ( isset($_GET['view_guest']) )
-{
- pwg_set_session_var( 'multiview_as', $conf['guest_id'] );
- $refresh_main = true;
-}
-elseif ( isset($_GET['view_admin']) )
+if ( isset($_GET['view_as']) )
{
- pwg_unset_session_var('multiview_as');
+ if ( is_adviser() and $user['id']!=$_GET['view_as'] and $conf['guest_id']!=$_GET['view_as'])
+ die('security error');
+ pwg_set_session_var( 'multiview_as', (int)$_GET['view_as'] );
+ // user change resets theme/lang
+ pwg_unset_session_var( 'multiview_theme' );
+ pwg_unset_session_var( 'multiview_lang' );
$refresh_main = true;
}
-$view_as = pwg_get_session_var( 'multiview_as', 0 );
-
+if (pwg_get_session_var( 'multiview_as', $user['id']) != $user['id'] )
+ $view_as_user = build_user( pwg_get_session_var( 'multiview_as',0), false);
+else
+ $view_as_user = $user;
if ( isset($_GET['theme']) )
{
@@ -63,13 +66,47 @@ if ( isset($_GET['debug_l10n']) )
$refresh_main = true;
}
+
$my_url = get_root_url().'plugins/'.basename(dirname(__FILE__)).'/'.basename(__FILE__);
-$my_theme = get_root_url().'template/'.$user['template'].'/theme/'.$user['theme'].'/theme.css';
-$themes_html='Theme: <select onchange="document.location = this.options[this.selectedIndex].value;">';
+// +-----------------------------------------------------------------------+
+// | users |
+$query = '
+SELECT '.$conf['user_fields']['id'].' AS id,'.$conf['user_fields']['username'].' AS username
+FROM '.USERS_TABLE;
+if (is_adviser())
+{
+ $query .='
+ WHERE '.$conf['user_fields']['id']. ' IN ('.$user['id'].','.$conf['guest_id'].')
+';
+}
+$query .='
+ ORDER BY CONVERT('.$conf['user_fields']['username'].',CHAR)
+;';
+$user_map = simple_hash_from_query($query, 'id', 'username');
+
+$users_html = '<select onchange="document.location = this.options[this.selectedIndex].value;">';
+foreach( $user_map as $id=>$username)
+{
+ $selected = ($id==$view_as_user['id']) ? 'selected="selected"' : '';
+ $users_html .=
+ '<option value="'
+ .$my_url.'?view_as='.$id
+ .'" '.$selected.'>'
+ .$username
+ .'</option>';
+}
+$users_html.= '</select>';
+
+
+// +-----------------------------------------------------------------------+
+// | templates |
+$my_template = '';
+$themes_html='<select onchange="document.location = this.options[this.selectedIndex].value;">';
foreach (get_pwg_themes() as $pwg_template)
{
- $selected = $pwg_template == pwg_get_session_var( 'multiview_theme', $user['template'].'/'.$user['theme'] ) ? 'selected="selected"' : '';
+ $selected = $pwg_template == pwg_get_session_var( 'multiview_theme', $view_as_user['template'].'/'.$view_as_user['theme'] ) ? 'selected="selected"' : '';
+ $my_template = $selected == '' ? $my_template : $view_as_user['template'].'/theme/'.$view_as_user['theme'];
$themes_html .=
'<option value="'
.$my_url.'?theme='.$pwg_template
@@ -79,10 +116,12 @@ foreach (get_pwg_themes() as $pwg_template)
}
$themes_html .= '</select>';
-$lang_html='Language: <select onchange="document.location = this.options[this.selectedIndex].value;">';
+// +-----------------------------------------------------------------------+
+// | language |
+$lang_html='<select onchange="document.location = this.options[this.selectedIndex].value;">';
foreach (get_languages() as $language_code => $language_name)
{
- $selected = $language_code == pwg_get_session_var( 'multiview_lang', $user['language'] ) ? 'selected="selected"' : '';
+ $selected = $language_code == pwg_get_session_var( 'multiview_lang', $view_as_user['language'] ) ? 'selected="selected"' : '';
$lang_html .=
'<option value="'
.$my_url.'?lang='.$language_code
@@ -92,59 +131,58 @@ foreach (get_languages() as $language_code => $language_name)
}
$lang_html .= '</select>';
+// +-----------------------------------------------------------------------+
+// | show queries |
$show_queries_html='';
if (!$conf['show_queries'])
{
- $show_queries_html = '<br/>';
if ( !pwg_get_session_var( 'multiview_show_queries', 0 ) )
$show_queries_html.='<a href="'.$my_url.'?show_queries=1">Show SQL queries</a>';
else
$show_queries_html.='<a href="'.$my_url.'?show_queries=0">Hide SQL queries</a>';
}
+// +-----------------------------------------------------------------------+
+// | debug language |
$debug_l10n_html='';
-if (!$conf['show_queries'])
+if (!$conf['debug_l10n'])
{
- $debug_l10n_html = '<br/>';
if ( !pwg_get_session_var( 'multiview_debug_l10n', 0 ) )
$debug_l10n_html.='<a href="'.$my_url.'?debug_l10n=1">Debug language</a>';
else
$debug_l10n_html.='<a href="'.$my_url.'?debug_l10n=0">Revert debug language</a>';
}
-?>
+?>
<html>
<head>
<title>Controller</title>
+<?php
+// Controller will be displayed with the **real admin template** (without Any if it has been removed)
+if ( $my_template !== '') {
+ $my_template = get_root_url().'template/'.$my_template.'/theme.css';
+ echo '<link rel="stylesheet" type="text/css" href="' . $my_template .'">';
+}
+?>
+
</head>
-<link rel="stylesheet" type="text/css" href="<?php
-echo $my_theme;
-?>">
<body>
-
+<div>
<script type="text/javascript">
if (window.opener==null) {
window.close();
- document.write("<h2>How did you get here ???</h2>");
+ document.write("<"+"h2>How did you get here ???<"+"/h2>");
}
</script>
-View as:
-<?php
- if ($view_as)
- echo '<a href="'.$my_url.'?view_admin">admin</a>';
- else
- echo '<a href="'.$my_url.'?view_guest">guest</a>';
-?>
-
-<br />
-<?php echo $themes_html; ?>
+<table>
+<tr><td>User</td><td><?php echo $users_html; ?></td></tr>
-<br />
-<?php echo $lang_html; ?>
+<tr><td>Theme</td><td><?php echo $themes_html; ?></td></tr>
-<?php echo $show_queries_html; ?>
-<?php echo $debug_l10n_html; ?>
+<tr><td>Lang</td><td><?php echo $lang_html; ?></td></tr>
+</table>
+<?php echo implode( "<br/>\n", array($show_queries_html, $debug_l10n_html) ); ?>
<script type="text/javascript">
<?php
@@ -152,7 +190,6 @@ View as:
window.opener.location = window.opener.location;';
?>
</script>
-
+</div>
</body>
-
</html>