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