Source for file masquerade.php

Documentation is available at masquerade.php

  1. <?php
  2. /**
  3. * Allow the admin user to masquerade as another user to make some bookings. A bit like "su".
  4. *
  5. * @author    Stuart Prescott
  6. * @copyright  Copyright Stuart Prescott
  7. * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  8. * @version    $Id$
  9. * @package    Bumblebee
  10. * @subpackage Actions
  11. *
  12. *  path (bumblebee root)/inc/actions/masquerade.php
  13. */
  14.  
  15. /** Load ancillary functions */
  16. require_once 'inc/typeinfo.php';
  17.  
  18. /** user object */
  19. require_once 'inc/bb/user.php';
  20. /** list of choices */
  21. require_once 'inc/formslib/anchortablelist.php';
  22. /** parent object */
  23. require_once 'inc/actions/actionaction.php';
  24.  
  25. /**
  26. * Allow the admin user to masquerade as another user to make some bookings. A bit like "su".
  27. *
  28. * @package    Bumblebee
  29. * @subpackage Actions
  30. */
  31. class ActionMasquerade extends ActionAction {
  32.  
  33.   /**
  34.   * Initialising the class
  35.   *
  36.   * @param  BumblebeeAuth $auth  Authorisation object
  37.   * @param  array $pdata   extra state data from the call path
  38.   * @return void nothing
  39.   */
  40.   function ActionMasquerade($auth, $pdata) {
  41.     parent::ActionAction($auth, $pdata);
  42.     $this->mungeInputData();
  43.   }
  44.  
  45.   function go() {
  46.     if (! isset($this->PD['id'])) {
  47.       $this->selectUser();
  48.     } elseif ($this->PD['id'] == -1) {
  49.       $this->removeMasquerade();
  50.       echo "<br /><br /><a href='".makeURL('masquerade')."'>".T_('Return to user list')."</a>";
  51.     } else {
  52.       $this->assumeMasquerade();
  53.       echo "<br /><br /><a href='".makeURL('masquerade')."'>".T_('Return to user list')."</a>";
  54.     }
  55.   }
  56.  
  57.   /**
  58.   * Print an HTML list of users to allow the user to masquerade as for making bookings
  59.   *
  60.   */
  61.   function selectUser() {
  62.     $select = new AnchorTableList(T_('Users'), T_('Select which user to masquerade as'));
  63.     $select->connectDB('users', array('id', 'name', 'username'),'id!='.qw($this->auth->uid));
  64.     $select->hrefbase = makeURL('masquerade', array('id'=>'__id__'));
  65.     $select->setFormat('id', '%s', array('name'), ' %s', array('username'));
  66.     if ($this->auth->amMasqed()) {
  67.       $select->list->prepend(array('-1', T_('End current Masquerade')));
  68.       echo T_('Currently wearing the mask of:')
  69.         .'<blockquote class="highlight">'
  70.         .xssqw($this->auth->ename).' ('.xssqw($this->auth->eusername).')</blockquote>';
  71.     }
  72.     echo $select->display();
  73.   }
  74.  
  75.   /**
  76.   * Put on the selected mask
  77.   */
  78.   function assumeMasquerade() {
  79.     if ($row = $this->auth->assumeMasq($this->PD['id'])) {
  80.       echo '<h3>'. T_('Masquerade started') .'</h3>';
  81.       echo sprintf(
  82.               T_('<p>The music has started and you are now wearing the mask that looks like:</p><blockquote class="highlight">%s (%s)</blockquote><p>Is that a scary thought?</p>'),
  83.                 xssqw($row['name']), xssqw($row['username'])
  84.                 );
  85.       echo '<p>'
  86.            . T_('When you are tired of wearing your mask, remove it by returning to the "Masquerade" menu once more.')
  87.            .'</p>';
  88.       echo '<p>'
  89.           . T_('Note that even with your mask on, you can only edit/create bookings on instruments for which you have administrative rights.')
  90.           .'</p>';
  91.     } else {
  92.       echo '<div class="msgerror">';
  93.       echo '<h3>'. T_('Masquerade Error!') .'</h3>';
  94.       echo '<p>'
  95.          . T_('Sorry, but if you\'re comming to a masquerade ball, you really should wear a decent mask! Masquerade didn\'t start properly: mask failed to apply and music didn\'t start.')
  96.           .'</p>';
  97.       echo '<p>'
  98.           . T_('Are you sure you\'re allowed to do this?')
  99.           .'</p>';
  100.       echo '</div>';
  101.     }
  102.   }
  103.  
  104.   /**
  105.   * Remove the mask
  106.   */
  107.   function removeMasquerade() {
  108.     $this->auth->removeMasq();
  109.     echo '<h3>' . T_('Masquerade finished') . '</h3>';
  110.     echo '<p>'
  111.         . T_('Oh well. All good things have to come to an end. The music has stopped and you have taken your mask off. Hope you didn\'t get too much of a surprise when eveyrone else took their masks off too!')
  112.         . '</p>';
  113.   }
  114.  
  115. } //ActionMasquerade
  116. ?>

Documentation generated on Tue, 06 Mar 2007 10:01:45 +0000 by phpDocumentor 1.3.0