Ignore:
Timestamp:
May 15, 2008, 2:09:44 AM (17 years ago)
Author:
rvelices
Message:
  • admin multi view plugin allows to view the gallery as any user (not only guest/admin)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/branch-1_7/plugins/admin_multi_view/controller.php

    r2017 r2341  
    1212  pwg_unset_session_var( 'multiview_debug_l10n' );
    1313?>
     14
    1415<script type="text/javascript">
    1516  window.close();
     
    2122$refresh_main = false;
    2223
    23 if ( isset($_GET['view_guest']) )
     24if ( isset($_GET['view_as']) )
    2425{
    25   pwg_set_session_var( 'multiview_as', $conf['guest_id'] );
     26  if ( is_adviser() and $user['id']!=$_GET['view_as'] and $conf['guest_id']!=$_GET['view_as'])
     27    die('security error');
     28  pwg_set_session_var( 'multiview_as', (int)$_GET['view_as'] );
     29  // user change resets theme/lang
     30  pwg_unset_session_var( 'multiview_theme' );
     31  pwg_unset_session_var( 'multiview_lang' );
    2632  $refresh_main = true;
    2733}
    28 elseif ( isset($_GET['view_admin']) )
    29 {
    30   pwg_unset_session_var('multiview_as');
    31   $refresh_main = true;
    32 }
    33 $view_as = pwg_get_session_var( 'multiview_as', 0 );
    34 
     34if (pwg_get_session_var( 'multiview_as', $user['id']) != $user['id'] )
     35  $view_as_user = build_user( pwg_get_session_var( 'multiview_as',0), false);
     36else
     37  $view_as_user = $user;
    3538
    3639if ( isset($_GET['theme']) )
     
    6467}
    6568
     69
    6670$my_url = get_root_url().'plugins/'.basename(dirname(__FILE__)).'/'.basename(__FILE__);
    67 $my_theme = get_root_url().'template/'.$user['template'].'/theme/'.$user['theme'].'/theme.css';
    6871
    69 $themes_html='Theme: <select onchange="document.location = this.options[this.selectedIndex].value;">';
     72// +-----------------------------------------------------------------------+
     73// | users                                                                 |
     74$query = '
     75SELECT '.$conf['user_fields']['id'].' AS id,'.$conf['user_fields']['username'].' AS username
     76FROM '.USERS_TABLE;
     77if (is_adviser())
     78{
     79  $query .='
     80  WHERE '.$conf['user_fields']['id']. ' IN ('.$user['id'].','.$conf['guest_id'].')
     81';
     82}
     83$query .='
     84  ORDER BY CONVERT('.$conf['user_fields']['username'].',CHAR)
     85;';
     86$user_map = simple_hash_from_query($query, 'id', 'username');
     87
     88$users_html = '<select onchange="document.location = this.options[this.selectedIndex].value;">';
     89foreach( $user_map as $id=>$username)
     90{
     91  $selected = ($id==$view_as_user['id']) ? 'selected="selected"' : '';
     92  $users_html .=
     93    '<option value="'
     94    .$my_url.'?view_as='.$id
     95    .'" '.$selected.'>'
     96    .$username
     97    .'</option>';
     98}
     99$users_html.= '</select>';
     100
     101
     102// +-----------------------------------------------------------------------+
     103// | templates                                                             |
     104$my_template = '';
     105$themes_html='<select onchange="document.location = this.options[this.selectedIndex].value;">';
    70106foreach (get_pwg_themes() as $pwg_template)
    71107{
    72   $selected = $pwg_template == pwg_get_session_var( 'multiview_theme', $user['template'].'/'.$user['theme'] ) ? 'selected="selected"' : '';
     108  $selected = $pwg_template == pwg_get_session_var( 'multiview_theme', $view_as_user['template'].'/'.$view_as_user['theme'] ) ? 'selected="selected"' : '';
     109  $my_template = $selected == '' ? $my_template : $view_as_user['template'].'/theme/'.$view_as_user['theme'];
    73110  $themes_html .=
    74111    '<option value="'
     
    80117$themes_html .= '</select>';
    81118
    82 $lang_html='Language: <select onchange="document.location = this.options[this.selectedIndex].value;">';
     119// +-----------------------------------------------------------------------+
     120// | language                                                              |
     121$lang_html='<select onchange="document.location = this.options[this.selectedIndex].value;">';
    83122foreach (get_languages() as $language_code => $language_name)
    84123{
    85   $selected = $language_code == pwg_get_session_var( 'multiview_lang', $user['language'] ) ? 'selected="selected"' : '';
     124  $selected = $language_code == pwg_get_session_var( 'multiview_lang', $view_as_user['language'] ) ? 'selected="selected"' : '';
    86125  $lang_html .=
    87126    '<option value="'
     
    93132$lang_html .= '</select>';
    94133
     134// +-----------------------------------------------------------------------+
     135// | show queries                                                          |
    95136$show_queries_html='';
    96137if (!$conf['show_queries'])
    97138{
    98   $show_queries_html = '<br/>';
    99139  if ( !pwg_get_session_var( 'multiview_show_queries', 0 ) )
    100140    $show_queries_html.='<a href="'.$my_url.'?show_queries=1">Show SQL queries</a>';
     
    103143}
    104144
     145// +-----------------------------------------------------------------------+
     146// | debug language                                                        |
    105147$debug_l10n_html='';
    106 if (!$conf['show_queries'])
     148if (!$conf['debug_l10n'])
    107149{
    108   $debug_l10n_html = '<br/>';
    109150  if ( !pwg_get_session_var( 'multiview_debug_l10n', 0 ) )
    110151    $debug_l10n_html.='<a href="'.$my_url.'?debug_l10n=1">Debug language</a>';
     
    112153    $debug_l10n_html.='<a href="'.$my_url.'?debug_l10n=0">Revert debug language</a>';
    113154}
     155
    114156?>
    115 
    116157<html>
    117158<head>
    118159<title>Controller</title>
     160<?php
     161// Controller will be displayed  with  the **real admin template** (without Any if it has been removed)
     162if ( $my_template !== '') {
     163  $my_template = get_root_url().'template/'.$my_template.'/theme.css';
     164  echo '<link rel="stylesheet" type="text/css" href="' . $my_template .'">';
     165}
     166?>
     167
    119168</head>
    120 <link rel="stylesheet" type="text/css" href="<?php
    121 echo $my_theme;
    122 ?>">
    123169<body>
    124 
     170<div>
    125171<script type="text/javascript">
    126172if (window.opener==null) {
    127173  window.close();
    128   document.write("<h2>How did you get here ???</h2>");
     174  document.write("<"+"h2>How did you get here ???<"+"/h2>");
    129175}
    130176</script>
    131177
    132 View as:
    133 <?php
    134   if ($view_as)
    135     echo '<a href="'.$my_url.'?view_admin">admin</a>';
    136   else
    137     echo '<a href="'.$my_url.'?view_guest">guest</a>';
    138 ?>
     178<table>
     179<tr><td>User</td><td><?php echo $users_html; ?></td></tr>
    139180
    140 <br />
    141 <?php echo $themes_html; ?>
     181<tr><td>Theme</td><td><?php echo $themes_html; ?></td></tr>
    142182
    143 <br />
    144 <?php echo $lang_html; ?>
    145 
    146 <?php echo $show_queries_html; ?>
    147 <?php echo $debug_l10n_html; ?>
     183<tr><td>Lang</td><td><?php echo $lang_html; ?></td></tr>
     184</table>
     185<?php echo implode( "<br/>\n", array($show_queries_html, $debug_l10n_html) ); ?>
    148186
    149187<script type="text/javascript">
     
    153191?>
    154192</script>
    155 
     193</div>
    156194</body>
    157 
    158195</html>
Note: See TracChangeset for help on using the changeset viewer.