1<?php
2
3require_once(dirname(__FILE__)."/../pfccommand.class.php");
4
5class pfcCommand_unban extends pfcCommand
6{
7  var $usage = "/unban {nickname}";
8
9  function run(&$xml_reponse, $p)
10  {
11    $clientid    = $p["clientid"];
12    $param       = $p["param"];
13    $params      = $p["params"];
14    $sender      = $p["sender"];
15    $recipient   = $p["recipient"];
16    $recipientid = $p["recipientid"];
17
18    $c =& pfcGlobalConfig::Instance();
19    $u =& pfcUserConfig::Instance();
20
21    $ct =& pfcContainer::Instance();
22
23    $nick = isset($params[0]) ? $params[0] : '';
24    $nickid = $ct->getNickId($nick);
25
26    if ($nick == "")
27    {
28      // error
29      $cmdp = $p;
30      $cmdp["param"] = _pfc("Missing parameter");
31      $cmdp["param"] .= " (".$this->usage.")";
32      $cmd =& pfcCommand::Factory("error");
33      $cmd->run($xml_reponse, $cmdp);
34      return;
35    }
36
37
38    $updated = false;
39    $msg = "<p>"._pfc("Nobody has been unbanished")."</p>";
40
41    // update the recipient banlist
42    $banlist = $ct->getChanMeta($recipient, 'banlist_nickid');
43    if ($banlist == NULL)
44      $banlist = array();
45    else
46      $banlist = unserialize($banlist);
47    $nb = count($banlist);
48
49    if (in_array($nickid, $banlist))
50    {
51      $banlist = array_diff($banlist, array($nickid));
52      $ct->setChanMeta($recipient, 'banlist_nickid', serialize($banlist));
53      $updated = true;
54      $msg = "<p>"._pfc("%s has been unbanished", $nick)."</p>";
55    }
56    else if ($nick == "all") // @todo move the "/unban all" command in another command /unbanall
57    {
58      $banlist = array();
59      $ct->setChanMeta($recipient, 'banlist_nickid', serialize($banlist));
60      $updated = true;
61      $msg = "<p>"._pfc("%s users have been unbanished", $nb)."</p>";
62    }
63
64    if ($updated)
65      $xml_reponse->script("pfc.handleResponse('".$this->name."', 'ok', '".$msg."');");
66    else
67      $xml_reponse->script("pfc.handleResponse('".$this->name."', 'ko', '".$msg."');");
68  }
69}
70
71?>