1<?php
2
3require_once(dirname(__FILE__)."/../pfccommand.class.php");
4
5class pfcCommand_update extends pfcCommand
6{
7  function run(&$xml_reponse, $p)
8  {
9    $clientid    = $p["clientid"];
10    $param       = $p["param"];
11    $sender      = $p["sender"];
12    $recipient   = $p["recipient"];
13    $recipientid = $p["recipientid"];
14
15    $c =& pfcGlobalConfig::Instance();
16    $u =& pfcUserConfig::Instance();
17
18    // check the user has not been disconnected from the server by timeout
19    // if he has been disconnected, then I reconnect him with /connect command
20    if ($u->nick != '' && !$u->isOnline())
21    {
22      $cmd =& pfcCommand::Factory("connect");
23      $cmdp = $p;
24      $cmdp['params'] = array($u->nick);
25      $cmdp['getoldmsg']   = false;
26      $cmdp['joinoldchan'] = false;
27      $cmd->run($xml_reponse, $cmdp);
28    }
29
30    // do not update if user isn't active (didn't connect)
31    if ($u->isOnline())
32    {
33      $cmdp = $p;
34
35      // update the user nickname timestamp on the server
36      $cmd =& pfcCommand::Factory("updatemynick");
37      $cmdp["recipient"]   = NULL;
38      $cmdp["recipientid"] = NULL;
39      $cmd->run($xml_reponse, $cmdp);
40
41      // get other online users on each channels
42      $cmd =& pfcCommand::Factory("who2");
43      foreach( $u->channels as $id => $chan )
44      {
45        $cmdp["recipient"]   = $chan["recipient"];
46        $cmdp["recipientid"] = $id;
47        $cmdp["param"] = ''; // don't forward the parameter because it will be interpreted as a channel name
48        $cmd->run($xml_reponse, $cmdp);
49      }
50      foreach( $u->privmsg as $id => $pv )
51      {
52        $cmdp["recipient"]   = $pv["recipient"];
53        $cmdp["recipientid"] = $id;
54        $cmdp["param"] = ''; // don't forward the parameter because it will be interpreted as a channel name
55        $cmd->run($xml_reponse, $cmdp);
56      }
57
58      // get new message posted on each channels
59      $cmd =& pfcCommand::Factory("getnewmsg");
60      foreach( $u->channels as $id => $chan )
61      {
62        $cmdp["recipient"]   = $chan["recipient"];
63        $cmdp["recipientid"] = $id;
64        $cmd->run($xml_reponse, $cmdp);
65      }
66      foreach( $u->privmsg as $id => $pv )
67      {
68        $cmdp["recipient"]   = $pv["recipient"];
69        $cmdp["recipientid"] = $id;
70        $cmd->run($xml_reponse, $cmdp);
71      }
72
73      $xml_reponse->script("pfc.handleResponse('update', 'ok', '');");
74    }
75    else
76    {
77      $xml_reponse->script("pfc.handleResponse('update', 'ko', '');");
78    }
79
80  }
81}
82
83?>