<?php

    mysql_connect('localhost','root','');
    mysql_select_db('test');

function getPrice($myName) {

    $query = "SELECT price FROM books where name='$myName'";
    $result = mysql_query($query);
    $row = mysql_fetch_assoc($result);
   
    return $row['price'];
}

function getBookInfo($myId) {

	$query = "SELECT * FROM books where id='$myId' ";
    $result = mysql_query($query);
    $row = mysql_fetch_assoc($result);
    return $row;
}

function getFullList() {

    $query = "SELECT * FROM books ";
    $result = mysql_query($query);
    while($row = mysql_fetch_assoc($result))
    {
	    $rows[] = $row;
    }
    return $rows;
}
    

require('lib/nusoap.php');

$server = new soap_server();

$server->configureWSDL('bookserver', 'http://localhost/soap');

$server->wsdl->schemaTargetNamespace = 'http://localhost/soap';

$server->wsdl->addComplexType(
        'BooksStruct',
        'complexType',
        'struct',
        'all',
        '',
        array(
            'id' => array('name'=>'id', 'type'=>'xsd:int'), 
            'name' => array('name'=>'name', 'type'=>'xsd:string'),
            'price' => array('name'=>'price', 'type'=>'xsd:float'))
    );

$server->wsdl->addComplexType(
        'BooksData',
        'complexType',
        'array',
		'',
		'SOAP-ENC:Array',
		array(),
		array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:BooksStruct[]')),
		'tns:BooksStruct'
    );

$server->register("getFullList", 
				array(),
                array('return' => 'tns:BooksData'
                ),
                'urn:getlist',
                'urn:getlist#getFullList');
                
$server->register("getPrice", 
				array('simbol'=>'xsd:string'),
                array('return' => 'xsd:float'
                ),
                'urn:getprice',
                'urn:getprice#getPrice');
                
$server->register("getBookInfo", 
				array('simbol'=>'xsd:int'),
                array('return' => 'tns:BooksStruct'
                ),
                'urn:getbook',
                'urn:getbook#getBookInfo');


$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA)
                      ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>