Subversion Repositories Applications.papyrus

Rev

Rev 1087 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
493 ddelon 1
<?php
2
/**
3
* Description: a SOAP Calendar Server
4
*/
5
if (!@include('SOAP'.DIRECTORY_SEPARATOR.'Server.php')) {
6
    die('You must have PEAR::SOAP installed');
7
}
8
 
9
if (!@include 'Calendar'.DIRECTORY_SEPARATOR.'Calendar.php') {
10
    define('CALENDAR_ROOT', '../../');
11
}
12
 
13
class Calendar_Server
14
{
15
    var $__dispatch_map = array();
16
    var $__typedef      = array();
17
 
18
    function Calendar_Server()
19
    {
20
        $this->__dispatch_map['getMonth'] =
21
            array('in'  => array('year' => 'int', 'month'=>'int'),
22
                  'out' => array('month' => '{urn:PEAR_SOAP_Calendar}Month'),
23
                  );
24
        $this->__typedef['Month'] = array (
25
                'monthname' => 'string',
26
                'days' => '{urn:PEAR_SOAP_Calendar}MonthDays'
27
            );
28
        $this->__typedef['MonthDays'] = array (array ('{urn:PEAR_SOAP_Calendar}Day'));
29
        $this->__typedef['Day'] = array (
30
                'isFirst' => 'int',
31
                'isLast'  => 'int',
32
                'isEmpty' => 'int',
33
                'day'     => 'int' );
34
    }
35
 
36
    function __dispatch($methodname)
37
    {
38
        if (isset($this->__dispatch_map[$methodname]))
39
            return $this->__dispatch_map[$methodname];
40
        return NULL;
41
    }
42
 
43
    function getMonth($year, $month)
44
    {
45
        require_once(CALENDAR_ROOT.'Month'.DIRECTORY_SEPARATOR.'Weekdays.php');
46
        $Month = & new Calendar_Month_Weekdays($year,$month);
47
        if (!$Month->isValid()) {
48
            $V = & $Month->getValidator();
49
            $errorMsg = '';
50
            while ($error = $V->fetch()) {
51
                $errorMsg .= $error->toString()."\n";
52
            }
53
            return new SOAP_Fault($errorMsg, 'Client');
54
        } else {
55
            $monthname = date('F Y', $Month->getTimeStamp());
56
            $days = array();
57
            $Month->build();
58
            while ($Day = & $Month->fetch()) {
59
                $day = array(
60
                    'isFirst' => (int)$Day->isFirst(),
61
                    'isLast'  => (int)$Day->isLast(),
62
                    'isEmpty' => (int)$Day->isEmpty(),
63
                    'day'     => (int)$Day->thisDay(),
64
                    );
65
                $days[] = $day;
66
            }
67
            return array('monthname' => $monthname, 'days' => $days);
68
        }
69
    }
70
}
71
 
72
$server = new SOAP_Server();
73
$server->_auto_translation = true;
74
$calendar = new Calendar_Server();
75
$server->addObjectMap($calendar, 'urn:PEAR_SOAP_Calendar');
76
 
77
if (strtoupper($_SERVER['REQUEST_METHOD'])=='POST') {
78
    $server->service($GLOBALS['HTTP_RAW_POST_DATA']);
79
} else {
80
    require_once 'SOAP'.DIRECTORY_SEPARATOR.'Disco.php';
81
    $disco = new SOAP_DISCO_Server($server, "PEAR_SOAP_Calendar");
82
    if (isset($_SERVER['QUERY_STRING']) &&
83
        strcasecmp($_SERVER['QUERY_STRING'], 'wsdl')==0) {
84
        header("Content-type: text/xml");
85
        echo $disco->getWSDL();
86
    } else {
87
        echo 'This is a PEAR::SOAP Calendar Server. For client try <a href="8.php">here</a><br />';
88
        echo 'For WSDL try <a href="?wsdl">here</a>';
89
    }
90
    exit;
91
}
92
?>