<?php
  class Tickets_Service extends Controller
  {
  	public $server;
	
  	function Tickets_Service()
	{
		parent::Controller();
		require_once('files/nusoap/nusoap.php');
		$this->load->library('session');	
		$this->load->helper(array('url'));
				
		//$this->load->library("Nusoap_lib");
		
        $NAMESPACE = base_url().'tickets_service';
        $this->nusoap_server 	= new soap_server();
        $this->nusoap_server->configureWSDL('TicketsWSDL', 'urn:TicketsWSDL');
        /*
        $this->nusoap_server->wsdl->addComplexType(
            "TicketRecordset",
            "complexType",
            "array",
            "",
            "SOAP-ENC:Array",
            array(
                "id"=>array("name"=>"id", "type"=>"xsd:int"),
                "firstname"=>array("name"=>"firstname", "type"=>"xsd:string"),
                "lastname"=>array("name"=>"lastname", "type"=>"xsd:string")
            )
        ); */   
        
		$this->nusoap_server->register(
			"hello",
			array("name" => "xsd:int"),
			array("return" => "xsd:int"),
            "urn:TicketsWSDL",
            "urn:TicketsWSDL#hello",
            "rpc",
            "encoded",
            "Get hello message"			
		);
		
		
		
		
        $this->nusoap_server->register(
            "login",
            array(
                "login" => "xsd:int",
				"password" => "xsd:int"
            ),
            array("return"=>"xsd:boolean"),
            "urn:TicketsWSDL",
            "urn:TicketsWSDL#list_items",
            "rpc",
            "encoded",
            "Get login"
        );		
		
		/*
        $this->nusoap_server->register(
            "list_items",
            array(
                "type" => "xsd:int",
				"pageId" => "xsd:int",
				"monthCondition" => "xsd:int"
            ),
            array("return"=>"tns:TicketRecordset"),
            "urn:TicketsWSDL",
            "urn:TicketsWSDL#list_items",
            "rpc",
            "encoded",
            "Get ticket's list"
        );
		*/
	
	}
	function index($wsdl=null)
	{
		
        if($this->uri->segment(3) == "wsdl") {
            $_SERVER['QUERY_STRING'] = "wsdl";
        } else {
            $_SERVER['QUERY_STRING'] = "";
        }
        $this->nusoap_server->service(file_get_contents("php://input"));
		//$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
		//$this->nusoap_server->service($HTTP_RAW_POST_DATA);
	    
		
		
        function list_items($type=0,$pageId=0,$monthCondition=null) {
			return array("id"=>array(1,2,3),
			                 "firstname"=>array('aa','bb','cc'),
							 "lastname"=>array('xx','yy','zz'));
        }
		
		function login($login,$password)
		{
			if($login == 'admin' || $password == 'admin..')
			{
				return TRUE;				
			}
			else
				return FALSE;
		}
		
		function hello($name=22) {
		    return $name;
		}
		
		
		/*
		$NAMESPACE = 'http://new.networds.datatask.net/tickets_service';
	 
		$this->server = new soap_server;
		$this->server->configureWSDL('networds tickets service', $NAMESPACE);
		$this->server->wsdl->schemaTargetNamespace = $NAMESPACE;
	
		$this->server->wsdl->addComplexType(
		    'Chapter',
		    'complexType',
		    'struct',
		    'all',
		    '',
		    array(
		        'title' => array('name'=>'title','type'=>'xsd:string'),
		        'page' => array('name'=>'page','type'=>'xsd:int')
		    )
		);
	 
		$this->server->wsdl->addComplexType(
		    'ChapterArray',
		    'complexType',
		    'array',
		    '',
		    'SOAP-ENC:Array',
		    array(),
		    array(
		        array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:Chapter[]')
		    ),
		    'tns:Chapter'
		);
	 
		$this->server->wsdl->addComplexType(
		    'Book',
		    'complexType',
		    'struct',
		    'all',
		    '',
		    array(
		        'author' => array('name'=>'author','type'=>'xsd:string'),
		        'title' => array('name'=>'title','type'=>'xsd:string'),
		        'numpages' => array('name'=>'numpages','type'=>'xsd:int'),
		        'toc' => array('name'=>'toc','type'=>'tns:ChapterArray')
		    )
		);	
	
		$this->server->register(
		    'login',
		    array(),
		    array('return'=>'xsd:boolean'),
		    $NAMESPACE);
			
		$this->server->register(
		    'logout',
		    array(),
		    array('return'=>'xsd:boolean'),
		    $NAMESPACE);			
				
		$server->register(
		    'getBook',
		    array('title'=>'xsd:string'),
		    array('return'=>'tns:Book'),
		    $NAMESPACE);	
		
		function getBook($title) {
		     // Create TOC
		     $toc = array();
		     $toc[] = array('title' => 'Chapter One', 'page' => 1);
		     $toc[] = array('title' => 'Chapter Two', 'page' => 30);
		  
		     // Create book
		     $book = array(
		                 'author' => "Jack London",
		                 'title' => $title,
		                 'numpages' => 42,
		                 'toc' => $toc);
		  
		     return $book;
		}
		*/
		
	
		// Use the request to (try to) invoke the service
		//$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
		//$this->server->service($HTTP_RAW_POST_DATA);
		
		/*
		require_once('tickets.php');
		$tc = new Tickets();
		$result = $tc->list_items();
		echo 'hello world';
		*/		
	}
    function select_member_info() {
        function list_items($member_id) {
			return null;
        }
        
        //$this->nusoap_server->service(file_get_contents("php://input"));
    }	
  }
?>