Вход Регистрация
Файл: billing/_rootinc/avdesk.inc.php
Строк: 92
<?

class AVDESK
{
    public 
$controller true;
    public 
$url null;
    public 
$user null;
    public 
$password null;
    public 
$error null;

    public function 
startup(&$controller)
    {
        
$this->controller =& $controller;
    }

    public function 
init($url,$user,$password)
    {
        
$this->url=$url;
        
$this->user=$user;
        
$this->password=$password;
    }

    public function 
send($api$request)
    {
        
$fp curl_init(); 
        
curl_setopt($fpCURLOPT_URL$this->url.$api);
        
curl_setopt($fpCURL_HTTP_VERSION_1_11);
        
curl_setopt($fpCURLOPT_USERPWD$this->user.":".$this->password);  
        
curl_setopt($fpCURLOPT_POST1);
        
curl_setopt($fpCURLOPT_POSTFIELDS$request);
        
curl_setopt($fpCURLOPT_SSL_VERIFYPEER0);
        
curl_setopt($fpCURLOPT_SSL_VERIFYHOST0);
        
curl_setopt($fpCURLOPT_RETURNTRANSFER,1);
        
curl_setopt($fpCURLOPT_TIMEOUT120);

        
$result curl_exec($fp);

        
curl_close($fp);  

        return 
$result;
    }



    public function 
createUser($id,$pwd,$pgrp,$year,$month,$day,$nograce)
    {
        
$result $this->send("avdesk/api/add-customer.ds","id=$id&pwd=$pwd&pgrp=$pgrp&year=$year&month=$month&day=$day&nograce=$nograce");

        
$result $this->parseResult($result);

        if (
$result["avdesk-xml-api"][rc] == "true") {
            return 
$result[customer][url];
        } else {
            
$this->error "createUser: ".$result["avdesk-xml-api"][message];
            return 
false;
        }
    }

    public function 
renewUser($id,$year,$month,$day)
    {
        
$result $this->send("avdesk/api/set-expiration.ds","id=$id&year=$year&month=$month&day=$day");

        
$result $this->parseResult($result);

        if (
$result["avdesk-xml-api"][rc] == "true") {
            return 
true;
        } else {
            
$this->error "renewUser: ".$result["avdesk-xml-api"][message];
            return 
false;
        }
    }

    public function 
deleteUser($id)
    {
        
$result $this->send("avdesk/api/del-customer.ds","id=$id");

        
$result $this->parseResult($result);

        if (
$result["avdesk-xml-api"][rc] == "true") {
            return 
true;
        } else {
            
$this->error "deleteUser: ".$result["avdesk-xml-api"][message];
            return 
false;
        }
    }

    public function 
getUserInfo($id)
    {
        
$result $this->send("avdesk/api/get-customer-info.ds","id=$id");

        
$result $this->parseResult($result);

        if (
$result["avdesk-xml-api"][rc] == "true") {
            return 
$result;
        } else {
            
$this->error "getUserInfo: ".$result["avdesk-xml-api"][message];
            return 
false;
        }
    }

    public function 
getUserStats($id)
    {
        
$result $this->send("avdesk/api/get-customer-stat.ds","id=$id");

        
$result $this->parseResult($result);

        if (
$result["avdesk-xml-api"][rc] == "true") {
            return 
$result;
        } else {
            
$this->error "getUserStats: ".$result["avdesk-xml-api"][message];
            return 
false;
        }
    }

    public function 
parseResult($input)
    {
        
$input preg_replace("/r/ui","",$input);
        
$input preg_replace("/n/ui","",$input);

        
preg_match_all("/<([S]+) ([^>]*)>/iu",$input,$arr);

        print 
"nn";
        while (list(
$i,$v) = each($arr[1])) {
            if (isset(
$cnt[$v])) {$cnt[$v]++;} else {$cnt[$v]="";}

            
$v $v.$cnt[$v];

            
$line $arr[2][$i];
            
$line preg_replace("//$/ui","",$line);

            
# $v - имя блока
            # $line - строка

            
if (!preg_match("/UTF-8/ui",$line)) {
                while (
preg_match('/([^=]+)="([^"]*)"/ui',$line,$arr2)) {
                    if (
$lastline == $line) {break;}

                    
$name $arr2[1]; $value=$arr2[2];
                    
$name preg_replace("/^ /ui","",$name);

                    
$result[$v][$name] = $value;

                    
$lastline $line;
                    
$line=@preg_replace("/".$arr2[0]."/ui","",$line);
                }
            }
        }

        return 
$result;
    }
}
?>
Онлайн: 0
Реклама