1<?php
2
3require_once dirname(__FILE__)."/pfcglobalconfig.class.php";
4
5class pfcUserConfig
6{
7  var $nick;
8  var $channels;
9  var $privmsg;
10  var $active;
11
12  var $timeout;
13  var $nickid;
14  var $serverid;
15
16  //  var $is_init = false; // used internaly to know if the chat config is initialized
17  //  var $errors = array();
18
19  function pfcUserConfig()
20  {
21    $c =& pfcGlobalConfig::Instance();
22
23    // start the session : session is used for locking purpose and cache purpose
24    if(session_id() == "") session_start();
25
26    // the nickid is a public identifier shared between all the chatters
27    // this is why the session_id must not be assigned directly to the nickid
28    $this->nickid = sha1(session_id());
29
30    // user parameters are cached in sessions
31    $this->_getParam("nick");
32    if (!isset($this->nick)) $this->_setParam("nick",""); // setup a blank nick if it is not yet in session
33    $this->_getParam("active");
34    if (!isset($this->active)) $this->_setParam("active",false);
35    $this->_getParam("channels");
36    if (!isset($this->channels)) $this->_setParam("channels",array());
37    $this->_getParam("privmsg");
38    if (!isset($this->privmsg)) $this->_setParam("privmsg",array());
39    $this->_getParam("serverid");
40    if (!isset($this->serverid)) $this->_setParam("serverid",$c->serverid);
41  }
42
43  function &Instance()
44  {
45    static $i;
46
47    if (!isset($i))
48    {
49      $i = new pfcUserConfig();
50    }
51    return $i;
52  }
53
54  function &_getParam($p)
55  {
56    if (!isset($this->$p))
57    {
58      $c =& pfcGlobalConfig::Instance();
59      $nickid       = 'pfcuserconfig_'.$c->getId().'_'.$this->nickid;
60      $nickid_param = $nickid."_".$p;
61      if (isset($_SESSION[$nickid_param]))
62        $this->$p = $_SESSION[$nickid_param];
63    }
64    return $this->$p;
65  }
66
67  function _setParam($p, $v)
68  {
69    $c =& pfcGlobalConfig::Instance();
70    $nickid_param = 'pfcuserconfig_'.$c->getId().'_'.$this->nickid.'_'.$p;
71    $_SESSION[$nickid_param] = $v;
72    $this->$p = $v;
73  }
74
75  function _rmParam($p)
76  {
77    $c =& pfcGlobalConfig::Instance();
78    $nickid_param = 'pfcuserconfig_'.$c->getId().'_'.$this->nickid.'_'.$p;
79    unset($_SESSION[$nickid_param]);
80    unset($this->$p);
81    if ($p == 'active') $this->active = false;
82  }
83
84
85  function destroy()
86  {
87    $this->_rmParam("nick");
88    $this->_rmParam("active");
89    $this->_rmParam("channels");
90    $this->_rmParam("privmsg");
91    $this->_rmParam("serverid");
92  }
93
94  function saveInCache()
95  {
96    //    echo "saveInCache()<br>";
97    $c =& pfcGlobalConfig::Instance();
98
99    // do not save anything as long as nickname is not assigned
100    //if ($this->active && $this->nick != "")
101    {
102      $this->_setParam("nick",     $this->nick);
103      $this->_setParam("active",   $this->active);
104      $this->_setParam("channels", $this->channels);
105      $this->_setParam("privmsg",  $this->privmsg);
106      $this->_setParam("serverid", $this->serverid);
107    }
108  }
109
110  function isOnline()
111  {
112    $ct =& pfcContainer::Instance();
113    $online = $ct->isNickOnline(NULL, $this->nickid);
114    return $online;
115  }
116
117  function getNickname()
118  {
119    if ($this->nick != '') return $this->nick;
120    $ct =& pfcContainer::Instance();
121    return $ct->getNickname($this->nickid);
122  }
123
124  function getChannelNames()
125  {
126    $list = array();
127    foreach( $this->channels as $v )
128      $list[] = $v["name"];
129    return $list;
130  }
131  function getPrivMsgNames()
132  {
133    $list = array();
134    foreach( $this->privmsg as $v )
135      $list[] = $v["name"];
136    return $list;
137  }
138}
139
140?>