<?php


class soap{
    private $_soap;
   public function __construct($conn){
        $this->_soap = $conn;
    }

   public function send_func(){

        $argumentos = func_get_args();
        $res = array();

        if (count($argumentos)==1 )
            $res = $this->_soap->{$argumentos[0]}();
        else if (count($argumentos)>1){
            $func = array_shift($argumentos) ;
            for($x = 0 ; $x < count($argumentos) ; $x++){
                $argumentos[$x] =  "'".$argumentos[$x]."'";
            }

            eval( '$res = $this->_soap->'.$func.'('.implode(",",$argumentos).' );');
        }

        return $res;
    }

}

class SoapClientParch extends SoapClient {

    function __construct($wsdl, $options) {
        parent::__construct($wsdl, $options);
    }

    public function __doRequest($req, $location, $action, $version = "SOAP_1_2", $one_way = 0) {
        $response = parent::__doRequest($req, $location, $action, $version, $one_way);
        $response = preg_replace('/^(\x00\x00\xFE\xFF|\xFF\xFE\x00\x00|\xFE\xFF|\xFF\xFE|\xEF\xBB\xBF)/', "", $response);
        $response = mb_convert_encoding($response, "UTF-8", 'HTML-ENTITIES');
        /*if (substr($response, -1) != ">") {
          //  $response .= "e>";
			$response = str_replace('</env:Envelope>e>', '</env:Envelope>', $response);
        }*/
        return $response;
    }

}

$conn = array();
foreach($_config['soap'] as $key=>$val){

    $conn = new SoapClientParch(
            $_config['soap'][$key]['wsdl'],
            array(
                "soap_version"=>SOAP_1_2,
                "login"=>$_config['soap'][$key]['login'],
                "password"=>$_config['soap'][$key]['password'],
                "location"=>$_config['soap'][$key]['location'],
                "uri"=>$_config['soap'][$key]['uri']
            )
    );

    $_soap = new soap($conn);
    $global['_soap'][$key] = $_soap;
}

/*
$d1 = strtotime('2015-02-01 00:00');
$d2 = strtotime('2015-02-15 23:59');
try {
    $algo = $conn->resumen_cuenta('29689', $d1, $d2, '0', '0', '0', '0');
   
    var_dump($algo);
    die;
} catch (SoapFault $e) {
  //  print_r($conn->__getLastResponse());
    die("acaa");
}*/
?>