1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105:
<?php
/**
* A Class for faking sessions which are anonymous access to a resource
*
* @package davical
* @subpackage PublicSession
* @author Andrew McMillan <andrew@morphoss.com>
* @copyright Morphoss Ltd
* @license http://gnu.org/copyleft/gpl.html GNU GPL v2 or later
*/
/**
* A Class for handling a public (anonymous) session
*
* @package davical
*/
class PublicSession {
/**#@+
* @access private
*/
/**
* Username
* @var username string
*/
public $username;
/**
* User ID number
* @var user_no int
*/
public $user_no;
/**
* Principal ID
* @var principal_id int
*/
public $principal_id;
/**
* User e-mail
* @var email string
*/
public $email;
/**
* User full name
* @var fullname string
*/
public $fullname;
/**
* Group rights
* @var groups array
*/
public $groups;
/**#@-*/
/**
* The constructor, which just calls the actual type configured
*/
function PublicSession() {
global $c;
$principal = new Principal('username','unauthenticated');
// Assign each field in the selected record to the object
foreach( $principal AS $k => $v ) {
$this->{$k} = $v;
}
$this->username = $principal->username();
$this->user_no = $principal->user_no();
$this->principal_id = $principal->principal_id();
$this->email = $principal->email();
$this->fullname = $principal->fullname;
$this->dav_name = $principal->dav_name();
$this->principal = $principal;
if ( function_exists("awl_set_locale") && isset($this->locale) && $this->locale != "" ) {
awl_set_locale($this->locale);
}
$this->groups = ( isset($c->public_groups) ? $c->public_groups : array() );
$this->roles = array( 'Public' => true );
$this->logged_in = false;
}
/**
* Checks whether a user is allowed to do something.
*
* The check is performed to see if the user has that role.
*
* @param string $whatever The role we want to know if the user has.
* @return boolean Whether or not the user has the specified role.
*/
function AllowedTo ( $whatever ) {
dbg_error_log('session', 'Checking whether "Public" is allowed to "%s"', $whatever);
return ( isset($this->roles[$whatever]) && $this->roles[$whatever] );
}
}