Source for file user.php

Documentation is available at user.php

  1. <?php
  2. /**
  3. * User object (extends dbo), with extra customisations for other links
  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 DBObjects
  11. */
  12.  
  13. /** Load ancillary functions */
  14. require_once 'inc/typeinfo.php';
  15.  
  16. require_once 'inc/bb/configreader.php';
  17.  
  18. /** parent object */
  19. require_once 'inc/formslib/dbrow.php';
  20. require_once 'inc/formslib/idfield.php';
  21. require_once 'inc/formslib/textfield.php';
  22. require_once 'inc/formslib/radiolist.php';
  23. require_once 'inc/formslib/checkbox.php';
  24. require_once 'inc/formslib/bitmask.php';
  25. require_once 'inc/formslib/passwdfield.php';
  26. require_once 'inc/formslib/droplist.php';
  27. require_once 'inc/formslib/joindata.php';
  28.  
  29. /**
  30. * User object (extends dbo), with extra customisations for other links
  31. *
  32. @package    Bumblebee
  33. @subpackage DBObjects
  34. @todo //TODO:       Editing method for new permissions model
  35. */
  36. class User extends DBRow {
  37.  
  38.   var $_authList;
  39.   var $_magicPassList;
  40.   var $_authMethod;
  41.   var $_auth;
  42.  
  43.   function User($auth$id$passwdOnly=false{
  44.     $conf ConfigReader::getInstance();
  45.  
  46.     $this->DBRow('users'$id);
  47.     #$this->DEBUG=10;
  48.     $this->_auth = $auth;
  49.     $this->editable = $passwdOnly;
  50.     $this->use2StepSync = 1;
  51.     $this->deleteFromTable = 0;
  52.     $f new IdField('id'T_('User ID'));
  53.     $f->editable 0;
  54.     $this->addElement($f);
  55.     $f new TextField('username'T_('Username'));
  56.     $attrs array('size' => '48');
  57.     $f->required 1;
  58.     $f->requiredTwoStage 1;
  59.     $f->isValidTest 'is_valid_username';
  60.     $f->setAttr($attrs);
  61.     $this->addElement($f);
  62.     $f new TextField('name'T_('Name'));
  63.     $f->isValidTest 'is_empty_string';
  64.     $f->setAttr($attrs);
  65.     $this->addElement($f);
  66.     $f new TextField('email'T_('Email'));
  67.     $f->required $passwdOnly;
  68.     $f->isValidTest 'is_empty_string';
  69.     $f->setAttr($attrs);
  70.     $this->addElement($f);
  71.     $f new TextField('phone'T_('Phone'));
  72.     $f->required $passwdOnly;
  73.     $f->isValidTest 'is_empty_string';
  74.     $f->setAttr($attrs);
  75.     $this->addElement($f);
  76.  
  77.     if ($passwdOnly{
  78.       $f new CheckBox('suspended'T_('Suspended'));
  79.       $this->addElement($f);
  80.  
  81.       if ($conf->value('auth''permissionsModel'false)) {
  82.         $f new CheckBox('isadmin'T_('System Administrator'));
  83.         $this->addElement($f);
  84.       else {
  85.         $f new Bitmask('permissions',  T_('System permissions')T_('Grant these system-wide permissions to the user')T_('Grant'));
  86.         $f->setValuesArray($this->SystemPermissions()'id''iv');
  87.         $f->showHideButtons true;
  88.         if ($id == -1{
  89.           $f->set(BBPERM_USER_BASIC);
  90.         }
  91.         $this->addElement($f);
  92.       }
  93.     }
  94.  
  95.     // association of user with an authentication method
  96.     $this->_findAuthMethods();
  97.     $f new RadioList('auth_method'T_('User authentication method'));
  98.     $f->sqlHidden 1;
  99.     $f->setValuesArray($this->_authList'id''iv');
  100.     $f->setFormat('id''%s'array('iv'));
  101.     $f->setAttr($attrs);
  102.     $f->required 1;
  103.     $f->hidden $passwdOnly;
  104.     $this->addElement($f);
  105.     if ($this->_localAuthPermitted{
  106.       $password new PasswdField('passwd'T_('Password (for local login)'));
  107.       $password->setAttr(array('size' => 24));
  108.       //$password->isValidTest = 'is_nonempty_string';
  109.       $password->suppressValidation 0;
  110.       $password->editable 1;
  111.       //$f->list->append(array('local','Local login: '), $password);
  112.       $this->addElement($password);
  113.  
  114.       //repeat the password field so that we can check that the user entered
  115.       //what they thought they did
  116.       $password_veri new PasswdField('passwd_veri'T_('Please re-enter password'));
  117.       $password_veri->setAttr(array('size' => 24));
  118.       $password_veri->suppressValidation 0;
  119.       $password_veri->editable 1;
  120.       $password_veri->sqlHidden true;
  121.  
  122.       $this->addElement($password_veri);
  123.     }
  124.  
  125.     if ($passwdOnly{
  126.       // association of users to projects
  127.       $f new JoinData('userprojects',
  128.                         'userid'$this->id,
  129.                         'projects'T_('Project membership'));
  130.       $projectfield new DropList('projectid'T_('Project'));
  131.       $projectfield->connectDB('projects'array('id''name''longname'));
  132.       $projectfield->prepend(array('0',T_('(none)')T_('no selection')));
  133.       $projectfield->setDefault(0);
  134.       $projectfield->setFormat('id''%s'array('name')' (%25.25s)'array('longname'));
  135.       $f->addElement($projectfield);
  136.       $f->joinSetup('projectid'array('minspare' => 2));
  137.       $f->colspan 2;
  138.       $this->addElement($f);
  139.       //preDump($f);
  140.       // association of users with instrumental permissions
  141.       $f new JoinData('permissions',
  142.                         'userid'$this->id,
  143.                         'instruments'T_('Instrument permissions'));
  144.       $instrfield new DropList('instrid'T_('Instrument'));
  145.       $instrfield->connectDB('instruments'array('id''name''longname'));
  146.       $instrfield->prepend(array('0'T_('(none)')T_('no selection')));
  147.       $instrfield->setDefault(0);
  148.       $instrfield->setFormat('id''%s'array('name')' (%25.25s)'array('longname'));
  149.       $f->addElement($instrfield);
  150.       $subscribeAnnounce new CheckBox('announce'T_('Subscribe: announce'));
  151.       $subscribeAnnounce->defaultValue 1;
  152.       $f->addElement($subscribeAnnounce);
  153.       $unbookAnnounce new CheckBox('unbook'T_('Subscribe: unbook'));
  154.       $f->addElement($unbookAnnounce);
  155.  
  156.       if ($conf->value('auth''permissionsModel'false)) {
  157.         $instradmin new CheckBox('isadmin'T_('Instrument admin'));
  158.         $f->addElement($instradmin);
  159.       else {
  160.         $bm new Bitmask('permissions',  T_('Instrument permissions')T_('Grant these instrument permissions to the user')T_('Grant'));
  161.         $bm->setValuesArray($this->InstrumentPermissions()'id''iv');
  162.         $bm->showHideButtons true;
  163.         $bm->defaultValue BBPERM_INSTR_BASIC;
  164.         $f->addElement($bm);
  165.       }
  166.  
  167.       /*
  168.       //Add these fields in once we need this functinality
  169.       $hasPriority = new CheckBox('haspriority', 'Booking priority');
  170.       $f->addElement($hasPriority);
  171.       $bookPoints = new TextField('points', 'Booking points');
  172.       $f->addElement($bookPoints);
  173.       $bookPointsRecharge = new TextField('pointsrecharge', 'Booking points recharge');
  174.       $f->addElement($bookPointsRecharge);
  175.       */
  176.       $f->joinSetup('instrid'array('minspare' => 2));
  177.       $f->colspan 2;
  178.       $this->addElement($f);
  179.     }
  180.  
  181.     $this->fill($id);
  182.     $this->dumpheader = 'User object';
  183.   }
  184.  
  185.   function _findAuthMethods({
  186.     $conf ConfigReader::getInstance();
  187.  
  188.     $this->_localAuthPermitted = ($conf->value('auth''useLocal'!== null)
  189.                                         && $conf->value('auth''useLocal')?true:false;
  190.     $this->_authList = array();
  191.     foreach ($conf->getSection('auth'as $key => $val{
  192.       if (strpos($key'use'=== && $val{
  193.         $method substr($key,3);
  194.         $this->_authList[$method$method;
  195.         $this->_magicPassList[$method$conf->value('auth'$method.'PassToken');
  196.       }
  197.     }
  198.   }
  199.  
  200.   function fill({
  201.     parent::fill();
  202.     //now edit the passwd/auth fields
  203.     $this->_authMethod = 'Local';
  204.     foreach($this->_magicPassList as $meth => $passtok{
  205.       if ($this->fields['passwd']->value == $passtok{
  206.         $this->_authMethod = $meth;
  207.       }
  208.     }
  209.     if ($this->_authMethod != 'Local'{
  210.      $this->fields['passwd']->crypt_method '';
  211.     else {
  212.      $this->fields['passwd']->crypt_method $this->_magicPassList['Local'];
  213.     }
  214.     $this->fields['auth_method']->set($this->_authMethod);
  215.     //echo $this->fields['passwd']->value;
  216.   }
  217.  
  218.   function sync({
  219.     //$this->DEBUG = 10;
  220.     //monkey the passwd/auth fields
  221.     //echo $this->_authMethod. '-';
  222.     //preDump($this->fields['passwd']);
  223.     //echo $this->fields['passwd']->value;
  224.     //echo $this->fields['auth_method']->changed.'/'.$this->fields['passwd']->value;
  225.     $this->_authMethod = $this->fields['auth_method']->getValue();
  226.     if ($this->_authMethod == 'Local'{
  227.       $this->fields['passwd']->crypt_method $this->_magicPassList['Local'];
  228.       if (in_array($this->fields['passwd']->value$this->_magicPassList)) {
  229.         $this->fields['passwd']->value '';
  230.       }
  231.     }
  232.     if ($this->fields['auth_method']->changed || $this->fields['passwd']->changed{
  233.  
  234.       if($this->_authMethod == 'Local' &&
  235.      $this->fields['passwd']->value != $this->fields['passwd_veri']->value{
  236.  
  237.      $this->fields['passwd']->isValid 0;
  238.      $this->fields['passwd']->changed 1;
  239.  
  240.      $this->fields['passwd_veri']->isValid 0;
  241.      $this->fields['passwd_veri']->changed 0;
  242.  
  243.  
  244.      $this->errorMessage .= T_('The supplied passwords did not match. Please retry.').'<br/>';
  245.      $this->isValid = 0;
  246.      $this->changed = 1;
  247.  
  248.       elseif ($this->_authMethod != 'Local'
  249.             /*&& $this->fields['passwd']->value != ''*/
  250.             && $this->fields['passwd']->value != $this->_magicPassList[$this->_authMethod]{
  251.         $this->log('User::sync(): indulging in password munging, '$this->_authMethod);
  252.         $this->fields['passwd']->set($this->_magicPassList[$this->_authMethod]);
  253.         $this->fields['passwd']->crypt_method '';
  254.         $this->fields['passwd']->changed 1;
  255.         $this->changed = 1;
  256.  
  257.       elseif ($this->_authMethod == 'Local' && $this->fields['passwd']->value == ''
  258.                         && $this->fields['username']->value != '')  {
  259.         $this->fields['passwd']->changed 1;
  260.         $this->fields['passwd']->isValid 0;
  261.         $this->errorMessage .= T_('password must be set for local login.').'<br/>';
  262.         $this->isValid = 0;
  263.       else {
  264.       }
  265.     }
  266.     return parent::sync();
  267.   }
  268.  
  269.   function display({
  270.     return $this->displayAsTable();
  271.   }
  272.  
  273.   function SystemPermissions({
  274.     $p array();
  275.     $p[BBPERM_USER_VIEW_LIST_ALL]     T_('View list of all instruments');
  276.     $p[BBPERM_USER_VIEW_CALENDAR_ALLT_('View calendar of all instruments');
  277.     $p[BBPERM_USER_VIEW_BOOKINGS_ALLT_('View bookings on all instruments');
  278.     $p[BBPERM_USER_MAKE_BOOKINGS_ALLT_('Make bookings on all instruments');
  279.     $p[BBPERM_USER_PASSWD]            T_('Change own password');
  280.     $p[BBPERM_USER_LOGOUT]            T_('Logout from system');
  281.     $p[BBPERM_ADMIN_GROUPS]           T_('Admin: edit groups');
  282.     $p[BBPERM_ADMIN_PROJECTS]         T_('Admin: edit projects');
  283.     $p[BBPERM_ADMIN_USERS]            T_('Admin: edit users');
  284.     $p[BBPERM_ADMIN_INSTRUMENTS]      T_('Admin: edit instruments');
  285.     $p[BBPERM_ADMIN_CONSUMABLES]      T_('Admin: edit consumables');
  286.     $p[BBPERM_ADMIN_CONSUME]          T_('Admin: record consumables');
  287.     $p[BBPERM_ADMIN_COSTS]            T_('Admin: edit costs');
  288.     $p[BBPERM_ADMIN_DELETEDBOOKINGS]  T_('Admin: view deleted bookings');
  289.     $p[BBPERM_ADMIN_MASQ]             T_('Admin: masquerade as another user');
  290.     $p[BBPERM_ADMIN_EMAILLIST]        T_('Admin: export email list');
  291.     $p[BBPERM_ADMIN_EXPORT]           T_('Admin: export usage data');
  292.     $p[BBPERM_ADMIN_BILLING]          T_('Admin: send out billing emails');
  293.     $p[BBPERM_ADMIN_BACKUPDB]         T_('Admin: backup database');
  294.     return $p;
  295.   }
  296.  
  297.  
  298.   function InstrumentPermissions({
  299.     $p array();
  300.     $p[BBPERM_INSTR_VIEW]          T_('View booking sheet');
  301.     $p[BBPERM_INSTR_VIEW_BOOKINGST_('View bookings');
  302.     $p[BBPERM_INSTR_BOOK]          T_('Make bookings');
  303.     $p[BBPERM_INSTR_UNBOOK]        T_('Delete own bookings');
  304.  
  305.     $p[BBPERM_INSTR_VIEW_FUTURE]   T_('View booking sheet into the future');
  306.     $p[BBPERM_INSTR_BOOK_FUTURE]   T_('Make bookings into the future');
  307.     $p[BBPERM_INSTR_UNBOOK_PAST]   T_('Delete own past bookings');
  308.  
  309.     $p[BBPERM_INSTR_MASQ]          T_('Masquerade as other users');
  310.     $p[BBPERM_INSTR_BOOK_FREE]     T_('Make bookings at any time');
  311.     $p[BBPERM_INSTR_VIEW_DETAILS]  T_('Admin: View detailed booking information');
  312.     $p[BBPERM_INSTR_EDIT_ALL]      T_('Admin: Edit others\' bookings');
  313.     $p[BBPERM_INSTR_UNBOOK_OTHER]  T_('Admin: Delete others\' bookings');
  314.     $p[BBPERM_INSTR_EDIT_CONFIG]   T_('Admin: change instrument config');
  315.     return $p;
  316.   }
  317.  

Documentation generated on Tue, 06 Mar 2007 10:02:08 +0000 by phpDocumentor 1.3.0