| 1 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
class Home extends TPage
|
|
|
4 |
{
|
|
|
5 |
public function onLoad($param)
|
|
|
6 |
{
|
|
|
7 |
$username = $this->Application->User->Name;
|
|
|
8 |
if(!$this->Application->Modules['users']->usernameExists($username))
|
|
|
9 |
{
|
|
|
10 |
$auth = $this->Application->Modules['auth'];
|
|
|
11 |
$auth->logout();
|
|
|
12 |
|
|
|
13 |
//redirect to login page.
|
|
|
14 |
$this->Response->Redirect($this->Service->ConstructUrl($auth->LoginPage));
|
|
|
15 |
}
|
|
|
16 |
}
|
|
|
17 |
|
|
|
18 |
function processMessage($sender, $param)
|
|
|
19 |
{
|
|
|
20 |
if(strlen($this->userinput->Text) > 0)
|
|
|
21 |
{
|
|
|
22 |
$record = new ChatBufferRecord();
|
|
|
23 |
$record->message = $this->userinput->Text;
|
|
|
24 |
$record->from_user = $this->Application->User->Name;
|
|
|
25 |
$record->saveMessage();
|
|
|
26 |
$this->userinput->Text = '';
|
|
|
27 |
$this->refresh($sender, $param);
|
|
|
28 |
$this->CallbackClient->focus($this->userinput);
|
|
|
29 |
}
|
|
|
30 |
}
|
|
|
31 |
|
|
|
32 |
function refresh($sender, $param)
|
|
|
33 |
{
|
|
|
34 |
//refresh the message list
|
|
|
35 |
$content = ChatBufferRecord::finder()->getUserMessages($this->Application->User->Name);
|
|
|
36 |
if(strlen($content) > 0)
|
|
|
37 |
{
|
|
|
38 |
$client = $this->Page->CallbackClient;
|
|
|
39 |
$anchor = (string)time();
|
|
|
40 |
$content .= "<a href=\"#\" id=\"{$anchor}\"> </a>";
|
|
|
41 |
$client->appendContent("messages", $content);
|
|
|
42 |
$client->focus($anchor);
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
//refresh the user list
|
|
|
46 |
$lastUpdate = $this->getViewState('userList','');
|
|
|
47 |
$users = ChatUserRecord::finder()->getUserList();
|
|
|
48 |
if($lastUpdate != $users)
|
|
|
49 |
{
|
|
|
50 |
$this->Page->CallbackClient->update('users', $users);
|
|
|
51 |
$this->setViewstate('userList', $users);
|
|
|
52 |
}
|
|
|
53 |
}
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
?>
|