Completed
Branch develop (f852e3)
by
unknown
22:24
created
htdocs/includes/nusoap/lib/nusoap.php 1 patch
Indentation   +8417 added lines, -8417 removed lines patch added patch discarded remove patch
@@ -85,844 +85,844 @@  discard block
 block discarded – undo
85 85
  */
86 86
 class nusoap_base
87 87
 {
88
-    /**
89
-     * Identification for HTTP headers.
90
-     *
91
-     * @var string
92
-     * @access private
93
-     */
94
-    var $title = 'NuSOAP';
95
-    /**
96
-     * Version for HTTP headers.
97
-     *
98
-     * @var string
99
-     * @access private
100
-     */
101
-    var $version = '0.9.11';
102
-    /**
103
-     * CVS revision for HTTP headers.
104
-     *
105
-     * @var string
106
-     * @access private
107
-     */
108
-    var $revision = '$Revision: 1.123 $';
109
-    /**
110
-     * Current error string (manipulated by getError/setError)
111
-     *
112
-     * @var string
113
-     * @access private
114
-     */
115
-    var $error_str = '';
116
-    /**
117
-     * Current debug string (manipulated by debug/appendDebug/clearDebug/getDebug/getDebugAsXMLComment)
118
-     *
119
-     * @var string
120
-     * @access private
121
-     */
122
-    var $debug_str = '';
123
-    /**
124
-     * toggles automatic encoding of special characters as entities
125
-     * (should always be true, I think)
126
-     *
127
-     * @var boolean
128
-     * @access private
129
-     */
130
-    var $charencoding = true;
131
-    /**
132
-     * the debug level for this instance
133
-     *
134
-     * @var    integer
135
-     * @access private
136
-     */
137
-    var $debugLevel;
138
-
139
-    /**
140
-     * set schema version
141
-     *
142
-     * @var      string
143
-     * @access   public
144
-     */
145
-    var $XMLSchemaVersion = 'http://www.w3.org/2001/XMLSchema';
146
-
147
-    /**
148
-     * charset encoding for outgoing messages
149
-     *
150
-     * @var      string
151
-     * @access   public
152
-     */
153
-    var $soap_defencoding = 'ISO-8859-1';
154
-    //var $soap_defencoding = 'UTF-8';
155
-
156
-    /**
157
-     * namespaces in an array of prefix => uri
158
-     *
159
-     * this is "seeded" by a set of constants, but it may be altered by code
160
-     *
161
-     * @var      array
162
-     * @access   public
163
-     */
164
-    var $namespaces = array(
165
-        'SOAP-ENV' => 'http://schemas.xmlsoap.org/soap/envelope/',
166
-        'xsd' => 'http://www.w3.org/2001/XMLSchema',
167
-        'xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
168
-        'SOAP-ENC' => 'http://schemas.xmlsoap.org/soap/encoding/'
169
-    );
170
-
171
-    /**
172
-     * namespaces used in the current context, e.g. during serialization
173
-     *
174
-     * @var      array
175
-     * @access   private
176
-     */
177
-    var $usedNamespaces = array();
178
-
179
-    /**
180
-     * XML Schema types in an array of uri => (array of xml type => php type)
181
-     * is this legacy yet?
182
-     * no, this is used by the nusoap_xmlschema class to verify type => namespace mappings.
183
-     *
184
-     * @var      array
185
-     * @access   public
186
-     */
187
-    var $typemap = array(
188
-        'http://www.w3.org/2001/XMLSchema' => array(
189
-            'string' => 'string', 'boolean' => 'boolean', 'float' => 'double', 'double' => 'double', 'decimal' => 'double',
190
-            'duration' => '', 'dateTime' => 'string', 'time' => 'string', 'date' => 'string', 'gYearMonth' => '',
191
-            'gYear' => '', 'gMonthDay' => '', 'gDay' => '', 'gMonth' => '', 'hexBinary' => 'string', 'base64Binary' => 'string',
192
-            // abstract "any" types
193
-            'anyType' => 'string', 'anySimpleType' => 'string',
194
-            // derived datatypes
195
-            'normalizedString' => 'string', 'token' => 'string', 'language' => '', 'NMTOKEN' => '', 'NMTOKENS' => '', 'Name' => '', 'NCName' => '', 'ID' => '',
196
-            'IDREF' => '', 'IDREFS' => '', 'ENTITY' => '', 'ENTITIES' => '', 'integer' => 'integer', 'nonPositiveInteger' => 'integer',
197
-            'negativeInteger' => 'integer', 'long' => 'integer', 'int' => 'integer', 'short' => 'integer', 'byte' => 'integer', 'nonNegativeInteger' => 'integer',
198
-            'unsignedLong' => '', 'unsignedInt' => '', 'unsignedShort' => '', 'unsignedByte' => '', 'positiveInteger' => ''),
199
-        'http://www.w3.org/2000/10/XMLSchema' => array(
200
-            'i4' => '', 'int' => 'integer', 'boolean' => 'boolean', 'string' => 'string', 'double' => 'double',
201
-            'float' => 'double', 'dateTime' => 'string',
202
-            'timeInstant' => 'string', 'base64Binary' => 'string', 'base64' => 'string', 'ur-type' => 'array'),
203
-        'http://www.w3.org/1999/XMLSchema' => array(
204
-            'i4' => '', 'int' => 'integer', 'boolean' => 'boolean', 'string' => 'string', 'double' => 'double',
205
-            'float' => 'double', 'dateTime' => 'string',
206
-            'timeInstant' => 'string', 'base64Binary' => 'string', 'base64' => 'string', 'ur-type' => 'array'),
207
-        'http://soapinterop.org/xsd' => array('SOAPStruct' => 'struct'),
208
-        'http://schemas.xmlsoap.org/soap/encoding/' => array('base64' => 'string', 'array' => 'array', 'Array' => 'array'),
209
-        'http://xml.apache.org/xml-soap' => array('Map')
210
-    );
211
-
212
-    /**
213
-     * XML entities to convert
214
-     *
215
-     * @var      array
216
-     * @access   public
217
-     * @deprecated
218
-     * @see    expandEntities
219
-     */
220
-    var $xmlEntities = array('quot' => '"', 'amp' => '&',
221
-        'lt' => '<', 'gt' => '>', 'apos' => "'");
222
-
223
-    /**
224
-     * HTTP Content-type to be used for SOAP calls and responses
225
-     *
226
-     * @var string
227
-     */
228
-    var $contentType = "text/xml";
229
-
230
-
231
-    /**
232
-     * constructor
233
-     *
234
-     * @access    public
235
-     */
236
-    function __construct()
237
-    {
238
-        $this->debugLevel = $GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel'];
239
-    }
240
-
241
-    /**
242
-     * gets the global debug level, which applies to future instances
243
-     *
244
-     * @return    integer    Debug level 0-9, where 0 turns off
245
-     * @access    public
246
-     */
247
-    function getGlobalDebugLevel()
248
-    {
249
-        return $GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel'];
250
-    }
251
-
252
-    /**
253
-     * sets the global debug level, which applies to future instances
254
-     *
255
-     * @param    int $level Debug level 0-9, where 0 turns off
256
-     * @access    public
257
-     */
258
-    function setGlobalDebugLevel($level)
259
-    {
260
-        $GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel'] = $level;
261
-    }
262
-
263
-    /**
264
-     * gets the debug level for this instance
265
-     *
266
-     * @return    int    Debug level 0-9, where 0 turns off
267
-     * @access    public
268
-     */
269
-    function getDebugLevel()
270
-    {
271
-        return $this->debugLevel;
272
-    }
273
-
274
-    /**
275
-     * sets the debug level for this instance
276
-     *
277
-     * @param    int $level Debug level 0-9, where 0 turns off
278
-     * @access    public
279
-     */
280
-    function setDebugLevel($level)
281
-    {
282
-        $this->debugLevel = $level;
283
-    }
284
-
285
-    /**
286
-     * adds debug data to the instance debug string with formatting
287
-     *
288
-     * @param    string $string debug data
289
-     * @access   private
290
-     */
291
-    function debug($string)
292
-    {
293
-        if ($this->debugLevel > 0) {
294
-            $this->appendDebug($this->getmicrotime() . ' ' . get_class($this) . ": $string\n");
295
-        }
296
-    }
297
-
298
-    /**
299
-     * adds debug data to the instance debug string without formatting
300
-     *
301
-     * @param    string $string debug data
302
-     * @access   public
303
-     */
304
-    function appendDebug($string)
305
-    {
306
-        if ($this->debugLevel > 0) {
307
-            // it would be nice to use a memory stream here to use
308
-            // memory more efficiently
309
-            $this->debug_str .= $string;
310
-        }
311
-    }
312
-
313
-    /**
314
-     * clears the current debug data for this instance
315
-     *
316
-     * @access   public
317
-     */
318
-    function clearDebug()
319
-    {
320
-        // it would be nice to use a memory stream here to use
321
-        // memory more efficiently
322
-        $this->debug_str = '';
323
-    }
324
-
325
-    /**
326
-     * gets the current debug data for this instance
327
-     *
328
-     * @return   string data
329
-     * @access   public
330
-     */
331
-    function &getDebug()
332
-    {
333
-        // it would be nice to use a memory stream here to use
334
-        // memory more efficiently
335
-        return $this->debug_str;
336
-    }
337
-
338
-    /**
339
-     * gets the current debug data for this instance as an XML comment
340
-     * this may change the contents of the debug data
341
-     *
342
-     * @return   string data as an XML comment
343
-     * @access   public
344
-     */
345
-    function &getDebugAsXMLComment()
346
-    {
347
-        // it would be nice to use a memory stream here to use
348
-        // memory more efficiently
349
-        while (strpos($this->debug_str, '--')) {
350
-            $this->debug_str = str_replace('--', '- -', $this->debug_str);
351
-        }
352
-        $ret = "<!--\n" . $this->debug_str . "\n-->";
353
-        return $ret;
354
-    }
355
-
356
-    /**
357
-     * expands entities, e.g. changes '<' to '&lt;'.
358
-     *
359
-     * @param    string $val The string in which to expand entities.
360
-     * @access    private
361
-     */
362
-    function expandEntities($val)
363
-    {
364
-        if ($this->charencoding) {
365
-            $val = str_replace('&', '&amp;', $val);
366
-            $val = str_replace("'", '&apos;', $val);
367
-            $val = str_replace('"', '&quot;', $val);
368
-            $val = str_replace('<', '&lt;', $val);
369
-            $val = str_replace('>', '&gt;', $val);
370
-        }
371
-        return $val;
372
-    }
373
-
374
-    /**
375
-     * returns error string if present
376
-     *
377
-     * @return   false|string error string or false
378
-     * @access   public
379
-     */
380
-    function getError()
381
-    {
382
-        if ($this->error_str != '') {
383
-            return $this->error_str;
384
-        }
385
-        return false;
386
-    }
387
-
388
-    /**
389
-     * sets error string
390
-     *
391
-     * @return   void
392
-     * @access   private
393
-     */
394
-    function setError($str)
395
-    {
396
-        $this->error_str = $str;
397
-    }
398
-
399
-    /**
400
-     * detect if array is a simple array or a struct (associative array)
401
-     *
402
-     * @param    mixed $val The PHP array
403
-     * @return    string    (arraySimple|arrayStruct)
404
-     * @access    private
405
-     */
406
-    function isArraySimpleOrStruct($val)
407
-    {
408
-        $keyList = array_keys($val);
409
-        foreach ($keyList as $keyListValue) {
410
-            if (!is_int($keyListValue)) {
411
-                return 'arrayStruct';
412
-            }
413
-        }
414
-        return 'arraySimple';
415
-    }
416
-
417
-    /**
418
-     * serializes PHP values in accordance w/ section 5. Type information is
419
-     * not serialized if $use == 'literal'.
420
-     *
421
-     * @param    mixed $val The value to serialize
422
-     * @param    string $name The name (local part) of the XML element
423
-     * @param    string $type The XML schema type (local part) for the element
424
-     * @param    string $name_ns The namespace for the name of the XML element
425
-     * @param    string $type_ns The namespace for the type of the element
426
-     * @param    array $attributes The attributes to serialize as name=>value pairs
427
-     * @param    string $use The WSDL "use" (encoded|literal)
428
-     * @param    boolean $soapval Whether this is called from soapval.
429
-     * @return    string    The serialized element, possibly with child elements
430
-     * @access    public
431
-     */
432
-    function serialize_val($val, $name = false, $type = false, $name_ns = false, $type_ns = false, $attributes = false, $use = 'encoded', $soapval = false)
433
-    {
434
-        $this->debug("in serialize_val: name=$name, type=$type, name_ns=$name_ns, type_ns=$type_ns, use=$use, soapval=$soapval");
435
-        $this->appendDebug('value=' . $this->varDump($val));
436
-        $this->appendDebug('attributes=' . $this->varDump($attributes));
437
-
438
-        if (is_object($val) && get_class($val) == 'soapval' && (!$soapval)) {
439
-            $this->debug("serialize_val: serialize soapval");
440
-            $xml = $val->serialize($use);
441
-            $this->appendDebug($val->getDebug());
442
-            $val->clearDebug();
443
-            $this->debug("serialize_val of soapval returning $xml");
444
-            return $xml;
445
-        }
446
-        // force valid name if necessary
447
-        if (is_numeric($name)) {
448
-            $name = '__numeric_' . $name;
449
-        } elseif (!$name) {
450
-            $name = 'noname';
451
-        }
452
-        // if name has ns, add ns prefix to name
453
-        $xmlns = '';
454
-        if ($name_ns) {
455
-            $prefix = 'nu' . rand(1000, 9999);
456
-            $name = $prefix . ':' . $name;
457
-            $xmlns .= " xmlns:$prefix=\"$name_ns\"";
458
-        }
459
-        // if type is prefixed, create type prefix
460
-        if ($type_ns != '' && $type_ns == $this->namespaces['xsd']) {
461
-            // need to fix this. shouldn't default to xsd if no ns specified
462
-            // w/o checking against typemap
463
-            $type_prefix = 'xsd';
464
-        } elseif ($type_ns) {
465
-            $type_prefix = 'ns' . rand(1000, 9999);
466
-            $xmlns .= " xmlns:$type_prefix=\"$type_ns\"";
467
-        }
468
-        // serialize attributes if present
469
-        $atts = '';
470
-        if ($attributes) {
471
-            foreach ($attributes as $k => $v) {
472
-                $atts .= " $k=\"" . $this->expandEntities($v) . '"';
473
-            }
474
-        }
475
-        // serialize null value
476
-        if (is_null($val)) {
477
-            $this->debug("serialize_val: serialize null");
478
-            if ($use == 'literal') {
479
-                // TODO: depends on minOccurs
480
-                $xml = "<$name$xmlns$atts/>";
481
-            } else {
482
-                if (isset($type) && isset($type_prefix)) {
483
-                    $type_str = " xsi:type=\"$type_prefix:$type\"";
484
-                } else {
485
-                    $type_str = '';
486
-                }
487
-                $xml = "<$name$xmlns$type_str$atts xsi:nil=\"true\"/>";
488
-            }
489
-            $this->debug("serialize_val returning $xml");
490
-            return $xml;
491
-        }
492
-        // serialize if an xsd built-in primitive type
493
-        if ($type != '' && isset($this->typemap[$this->XMLSchemaVersion][$type])) {
494
-            $this->debug("serialize_val: serialize xsd built-in primitive type");
495
-            if (is_bool($val)) {
496
-                if ($type == 'boolean') {
497
-                    $val = $val ? 'true' : 'false';
498
-                } elseif (!$val) {
499
-                    $val = 0;
500
-                }
501
-            } elseif (is_string($val)) {
502
-                $val = $this->expandEntities($val);
503
-            }
504
-            if ($use == 'literal') {
505
-                $xml = "<$name$xmlns$atts>$val</$name>";
506
-            } else {
507
-                $xml = "<$name$xmlns xsi:type=\"xsd:$type\"$atts>$val</$name>";
508
-            }
509
-            $this->debug("serialize_val returning $xml");
510
-            return $xml;
511
-        }
512
-        // detect type and serialize
513
-        $xml = '';
514
-        switch (true) {
515
-            case (is_bool($val) || $type == 'boolean'):
516
-                $this->debug("serialize_val: serialize boolean");
517
-                if ($type == 'boolean') {
518
-                    $val = $val ? 'true' : 'false';
519
-                } elseif (!$val) {
520
-                    $val = 0;
521
-                }
522
-                if ($use == 'literal') {
523
-                    $xml .= "<$name$xmlns$atts>$val</$name>";
524
-                } else {
525
-                    $xml .= "<$name$xmlns xsi:type=\"xsd:boolean\"$atts>$val</$name>";
526
-                }
527
-                break;
528
-            case (is_int($val) || is_long($val) || $type == 'int'):
529
-                $this->debug("serialize_val: serialize int");
530
-                if ($use == 'literal') {
531
-                    $xml .= "<$name$xmlns$atts>$val</$name>";
532
-                } else {
533
-                    $xml .= "<$name$xmlns xsi:type=\"xsd:int\"$atts>$val</$name>";
534
-                }
535
-                break;
536
-            case (is_float($val) || is_double($val) || $type == 'float'):
537
-                $this->debug("serialize_val: serialize float");
538
-                if ($use == 'literal') {
539
-                    $xml .= "<$name$xmlns$atts>$val</$name>";
540
-                } else {
541
-                    $xml .= "<$name$xmlns xsi:type=\"xsd:float\"$atts>$val</$name>";
542
-                }
543
-                break;
544
-            case (is_string($val) || $type == 'string'):
545
-                $this->debug("serialize_val: serialize string");
546
-                $val = $this->expandEntities($val);
547
-                if ($use == 'literal') {
548
-                    $xml .= "<$name$xmlns$atts>$val</$name>";
549
-                } else {
550
-                    $xml .= "<$name$xmlns xsi:type=\"xsd:string\"$atts>$val</$name>";
551
-                }
552
-                break;
553
-            case is_object($val):
554
-                $this->debug("serialize_val: serialize object");
555
-                $pXml = "";
556
-                if (get_class($val) == 'soapval') {
557
-                    $this->debug("serialize_val: serialize soapval object");
558
-                    $pXml = $val->serialize($use);
559
-                    $this->appendDebug($val->getDebug());
560
-                    $val->clearDebug();
561
-                } else {
562
-                    if (!$name) {
563
-                        $name = get_class($val);
564
-                        $this->debug("In serialize_val, used class name $name as element name");
565
-                    } else {
566
-                        $this->debug("In serialize_val, do not override name $name for element name for class " . get_class($val));
567
-                    }
568
-                    foreach (get_object_vars($val) as $k => $v) {
569
-                        $pXml = isset($pXml) ? $pXml . $this->serialize_val($v, $k, false, false, false, false, $use) : $this->serialize_val($v, $k, false, false, false, false, $use);
570
-                    }
571
-                }
572
-                if (isset($type) && isset($type_prefix)) {
573
-                    $type_str = " xsi:type=\"$type_prefix:$type\"";
574
-                } else {
575
-                    $type_str = '';
576
-                }
577
-                if ($use == 'literal') {
578
-                    $xml .= "<$name$xmlns$atts>$pXml</$name>";
579
-                } else {
580
-                    $xml .= "<$name$xmlns$type_str$atts>$pXml</$name>";
581
-                }
582
-                break;
583
-            case (is_array($val) || $type):
584
-                // detect if struct or array
585
-                $valueType = $this->isArraySimpleOrStruct($val);
586
-                if ($valueType == 'arraySimple' || preg_match('/^ArrayOf/', $type)) {
587
-                    $this->debug("serialize_val: serialize array");
588
-                    $i = 0;
589
-                    if (is_array($val) && count($val) > 0) {
590
-                        $array_types = array ();
591
-                        $tt_ns = "";
592
-                        $tt = "";
593
-                        foreach ($val as $v) {
594
-                            if (is_object($v) && get_class($v) == 'soapval') {
595
-                                $tt_ns = $v->type_ns;
596
-                                $tt = $v->type;
597
-                            } elseif (is_array($v)) {
598
-                                $tt = $this->isArraySimpleOrStruct($v);
599
-                            } else {
600
-                                $tt = gettype($v);
601
-                            }
602
-                            $array_types[$tt] = 1;
603
-                            // TODO: for literal, the name should be $name
604
-                            $xml .= $this->serialize_val($v, 'item', false, false, false, false, $use);
605
-                            ++$i;
606
-                        }
607
-                        if (count($array_types) > 1) {
608
-                            $array_typename = 'xsd:anyType';
609
-                        } elseif (isset($tt) && isset($this->typemap[$this->XMLSchemaVersion][$tt])) {
610
-                            if ($tt == 'integer') {
611
-                                $tt = 'int';
612
-                            }
613
-                            $array_typename = 'xsd:' . $tt;
614
-                        } elseif (isset($tt) && $tt == 'arraySimple') {
615
-                            $array_typename = 'SOAP-ENC:Array';
616
-                        } elseif (isset($tt) && $tt == 'arrayStruct') {
617
-                            $array_typename = 'unnamed_struct_use_soapval';
618
-                        } else {
619
-                            // if type is prefixed, create type prefix
620
-                            if ($tt_ns != '' && $tt_ns == $this->namespaces['xsd']) {
621
-                                $array_typename = 'xsd:' . $tt;
622
-                            } elseif ($tt_ns) {
623
-                                $tt_prefix = 'ns' . rand(1000, 9999);
624
-                                $array_typename = "$tt_prefix:$tt";
625
-                                $xmlns .= " xmlns:$tt_prefix=\"$tt_ns\"";
626
-                            } else {
627
-                                $array_typename = $tt;
628
-                            }
629
-                        }
630
-                        $array_type = $i;
631
-                        if ($use == 'literal') {
632
-                            $type_str = '';
633
-                        } elseif (isset($type) && isset($type_prefix)) {
634
-                            $type_str = " xsi:type=\"$type_prefix:$type\"";
635
-                        } else {
636
-                            $type_str = " xsi:type=\"SOAP-ENC:Array\" SOAP-ENC:arrayType=\"" . $array_typename . "[$array_type]\"";
637
-                        }
638
-                        // empty array
639
-                    } else {
640
-                        if ($use == 'literal') {
641
-                            $type_str = '';
642
-                        } elseif (isset($type) && isset($type_prefix)) {
643
-                            $type_str = " xsi:type=\"$type_prefix:$type\"";
644
-                        } else {
645
-                            $type_str = " xsi:type=\"SOAP-ENC:Array\" SOAP-ENC:arrayType=\"xsd:anyType[0]\"";
646
-                        }
647
-                    }
648
-                    // TODO: for array in literal, there is no wrapper here
649
-                    $xml = "<$name$xmlns$type_str$atts>" . $xml . "</$name>";
650
-                } else {
651
-                    // got a struct
652
-                    $this->debug("serialize_val: serialize struct");
653
-                    if (isset($type) && isset($type_prefix)) {
654
-                        $type_str = " xsi:type=\"$type_prefix:$type\"";
655
-                    } else {
656
-                        $type_str = '';
657
-                    }
658
-                    if ($use == 'literal') {
659
-                        $xml .= "<$name$xmlns$atts>";
660
-                    } else {
661
-                        $xml .= "<$name$xmlns$type_str$atts>";
662
-                    }
663
-                    foreach ($val as $k => $v) {
664
-                        // Apache Map
665
-                        if ($type == 'Map' && $type_ns == 'http://xml.apache.org/xml-soap') {
666
-                            $xml .= '<item>';
667
-                            $xml .= $this->serialize_val($k, 'key', false, false, false, false, $use);
668
-                            $xml .= $this->serialize_val($v, 'value', false, false, false, false, $use);
669
-                            $xml .= '</item>';
670
-                        } else {
671
-                            $xml .= $this->serialize_val($v, $k, false, false, false, false, $use);
672
-                        }
673
-                    }
674
-                    $xml .= "</$name>";
675
-                }
676
-                break;
677
-            default:
678
-                $this->debug("serialize_val: serialize unknown");
679
-                $xml .= 'not detected, got ' . gettype($val) . ' for ' . $val;
680
-                break;
681
-        }
682
-        $this->debug("serialize_val returning $xml");
683
-        return $xml;
684
-    }
685
-
686
-    /**
687
-     * serializes a message
688
-     *
689
-     * @param string $body the XML of the SOAP body
690
-     * @param mixed $headers optional string of XML with SOAP header content, or array of soapval objects for SOAP headers, or associative array
691
-     * @param array $namespaces optional the namespaces used in generating the body and headers
692
-     * @param string $style optional (rpc|document)
693
-     * @param string $use optional (encoded|literal)
694
-     * @param string $encodingStyle optional (usually 'http://schemas.xmlsoap.org/soap/encoding/' for encoded)
695
-     * @return string the message
696
-     * @access public
697
-     */
698
-    function serializeEnvelope($body, $headers = false, $namespaces = array(), $style = 'rpc', $use = 'encoded', $encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/')
699
-    {
700
-        // TODO: add an option to automatically run utf8_encode on $body and $headers
701
-        // if $this->soap_defencoding is UTF-8.  Not doing this automatically allows
702
-        // one to send arbitrary UTF-8 characters, not just characters that map to ISO-8859-1
703
-
704
-        $this->debug("In serializeEnvelope length=" . strlen($body) . " body (max 1000 characters)=" . substr($body, 0, 1000) . " style=$style use=$use encodingStyle=$encodingStyle");
705
-        $this->debug("headers:");
706
-        $this->appendDebug($this->varDump($headers));
707
-        $this->debug("namespaces:");
708
-        $this->appendDebug($this->varDump($namespaces));
709
-
710
-        // serialize namespaces
711
-        $ns_string = '';
712
-        foreach (array_merge($this->namespaces, $namespaces) as $k => $v) {
713
-            $ns_string .= " xmlns:$k=\"$v\"";
714
-        }
715
-        if ($encodingStyle) {
716
-            $ns_string = " SOAP-ENV:encodingStyle=\"$encodingStyle\"$ns_string";
717
-        }
718
-
719
-        // serialize headers
720
-        if ($headers) {
721
-            if (is_array($headers)) {
722
-                $xml = '';
723
-                foreach ($headers as $k => $v) {
724
-                    if (is_object($v) && get_class($v) == 'soapval') {
725
-                        $xml .= $this->serialize_val($v, false, false, false, false, false, $use);
726
-                    } else {
727
-                        $xml .= $this->serialize_val($v, $k, false, false, false, false, $use);
728
-                    }
729
-                }
730
-                $headers = $xml;
731
-                $this->debug("In serializeEnvelope, serialized array of headers to $headers");
732
-            }
733
-            $headers = "<SOAP-ENV:Header>" . $headers . "</SOAP-ENV:Header>";
734
-        }
735
-        // serialize envelope
736
-        return
737
-            '<?xml version="1.0" encoding="' . $this->soap_defencoding . '"?' . ">" .
738
-            '<SOAP-ENV:Envelope' . $ns_string . ">" .
739
-            $headers .
740
-            "<SOAP-ENV:Body>" .
741
-            $body .
742
-            "</SOAP-ENV:Body>" .
743
-            "</SOAP-ENV:Envelope>";
744
-    }
745
-
746
-    /**
747
-     * formats a string to be inserted into an HTML stream
748
-     *
749
-     * @param string $str The string to format
750
-     * @return string The formatted string
751
-     * @access public
752
-     * @deprecated
753
-     */
754
-    function formatDump($str)
755
-    {
756
-        $str = htmlspecialchars($str);
757
-        return nl2br($str);
758
-    }
759
-
760
-    /**
761
-     * contracts (changes namespace to prefix) a qualified name
762
-     *
763
-     * @param    string $qname qname
764
-     * @return    string contracted qname
765
-     * @access   private
766
-     */
767
-    function contractQname($qname)
768
-    {
769
-        // get element namespace
770
-        //$this->xdebug("Contract $qname");
771
-        if (strrpos($qname, ':')) {
772
-            // get unqualified name
773
-            $name = substr($qname, strrpos($qname, ':') + 1);
774
-            // get ns
775
-            $ns = substr($qname, 0, strrpos($qname, ':'));
776
-            $p = $this->getPrefixFromNamespace($ns);
777
-            if ($p) {
778
-                return $p . ':' . $name;
779
-            }
780
-        }
781
-        return $qname;
782
-    }
783
-
784
-    /**
785
-     * expands (changes prefix to namespace) a qualified name
786
-     *
787
-     * @param    string $qname qname
788
-     * @return    string expanded qname
789
-     * @access   private
790
-     */
791
-    function expandQname($qname)
792
-    {
793
-        // get element prefix
794
-        if (strpos($qname, ':') && !preg_match('/^http:\/\//', $qname)) {
795
-            // get unqualified name
796
-            $name = substr(strstr($qname, ':'), 1);
797
-            // get ns prefix
798
-            $prefix = substr($qname, 0, strpos($qname, ':'));
799
-            if (isset($this->namespaces[$prefix])) {
800
-                return $this->namespaces[$prefix] . ':' . $name;
801
-            } else {
802
-                return $qname;
803
-            }
804
-        } else {
805
-            return $qname;
806
-        }
807
-    }
808
-
809
-    /**
810
-     * returns the local part of a prefixed string
811
-     * returns the original string, if not prefixed
812
-     *
813
-     * @param string $str The prefixed string
814
-     * @return string The local part
815
-     * @access public
816
-     */
817
-    function getLocalPart($str)
818
-    {
819
-        if ($sstr = strrchr($str, ':')) {
820
-            // get unqualified name
821
-            return substr($sstr, 1);
822
-        } else {
823
-            return $str;
824
-        }
825
-    }
826
-
827
-    /**
828
-     * returns the prefix part of a prefixed string
829
-     * returns false, if not prefixed
830
-     *
831
-     * @param string $str The prefixed string
832
-     * @return false|string The prefix or false if there is no prefix
833
-     * @access public
834
-     */
835
-    function getPrefix($str)
836
-    {
837
-        if ($pos = strrpos($str, ':')) {
838
-            // get prefix
839
-            return substr($str, 0, $pos);
840
-        }
841
-        return false;
842
-    }
843
-
844
-    /**
845
-     * pass it a prefix, it returns a namespace
846
-     *
847
-     * @param string $prefix The prefix
848
-     * @return mixed The namespace, false if no namespace has the specified prefix
849
-     * @access public
850
-     */
851
-    function getNamespaceFromPrefix($prefix)
852
-    {
853
-        if (isset($this->namespaces[$prefix])) {
854
-            return $this->namespaces[$prefix];
855
-        }
856
-        //$this->setError("No namespace registered for prefix '$prefix'");
857
-        return false;
858
-    }
859
-
860
-    /**
861
-     * returns the prefix for a given namespace (or prefix)
862
-     * or false if no prefixes registered for the given namespace
863
-     *
864
-     * @param string $ns The namespace
865
-     * @return false|string The prefix, false if the namespace has no prefixes
866
-     * @access public
867
-     */
868
-    function getPrefixFromNamespace($ns)
869
-    {
870
-        foreach ($this->namespaces as $p => $n) {
871
-            if ($ns == $n || $ns == $p) {
872
-                $this->usedNamespaces[$p] = $n;
873
-                return $p;
874
-            }
875
-        }
876
-        return false;
877
-    }
878
-
879
-    /**
880
-     * returns the time in ODBC canonical form with microseconds
881
-     *
882
-     * @return string The time in ODBC canonical form with microseconds
883
-     * @access public
884
-     */
885
-    function getmicrotime()
886
-    {
887
-        if (function_exists('gettimeofday')) {
888
-            $tod = gettimeofday();
889
-            $sec = $tod['sec'];
890
-            $usec = $tod['usec'];
891
-        } else {
892
-            $sec = time();
893
-            $usec = 0;
894
-        }
895
-        $dtx = new DateTime("@$sec");
88
+	/**
89
+	 * Identification for HTTP headers.
90
+	 *
91
+	 * @var string
92
+	 * @access private
93
+	 */
94
+	var $title = 'NuSOAP';
95
+	/**
96
+	 * Version for HTTP headers.
97
+	 *
98
+	 * @var string
99
+	 * @access private
100
+	 */
101
+	var $version = '0.9.11';
102
+	/**
103
+	 * CVS revision for HTTP headers.
104
+	 *
105
+	 * @var string
106
+	 * @access private
107
+	 */
108
+	var $revision = '$Revision: 1.123 $';
109
+	/**
110
+	 * Current error string (manipulated by getError/setError)
111
+	 *
112
+	 * @var string
113
+	 * @access private
114
+	 */
115
+	var $error_str = '';
116
+	/**
117
+	 * Current debug string (manipulated by debug/appendDebug/clearDebug/getDebug/getDebugAsXMLComment)
118
+	 *
119
+	 * @var string
120
+	 * @access private
121
+	 */
122
+	var $debug_str = '';
123
+	/**
124
+	 * toggles automatic encoding of special characters as entities
125
+	 * (should always be true, I think)
126
+	 *
127
+	 * @var boolean
128
+	 * @access private
129
+	 */
130
+	var $charencoding = true;
131
+	/**
132
+	 * the debug level for this instance
133
+	 *
134
+	 * @var    integer
135
+	 * @access private
136
+	 */
137
+	var $debugLevel;
138
+
139
+	/**
140
+	 * set schema version
141
+	 *
142
+	 * @var      string
143
+	 * @access   public
144
+	 */
145
+	var $XMLSchemaVersion = 'http://www.w3.org/2001/XMLSchema';
146
+
147
+	/**
148
+	 * charset encoding for outgoing messages
149
+	 *
150
+	 * @var      string
151
+	 * @access   public
152
+	 */
153
+	var $soap_defencoding = 'ISO-8859-1';
154
+	//var $soap_defencoding = 'UTF-8';
155
+
156
+	/**
157
+	 * namespaces in an array of prefix => uri
158
+	 *
159
+	 * this is "seeded" by a set of constants, but it may be altered by code
160
+	 *
161
+	 * @var      array
162
+	 * @access   public
163
+	 */
164
+	var $namespaces = array(
165
+		'SOAP-ENV' => 'http://schemas.xmlsoap.org/soap/envelope/',
166
+		'xsd' => 'http://www.w3.org/2001/XMLSchema',
167
+		'xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
168
+		'SOAP-ENC' => 'http://schemas.xmlsoap.org/soap/encoding/'
169
+	);
170
+
171
+	/**
172
+	 * namespaces used in the current context, e.g. during serialization
173
+	 *
174
+	 * @var      array
175
+	 * @access   private
176
+	 */
177
+	var $usedNamespaces = array();
178
+
179
+	/**
180
+	 * XML Schema types in an array of uri => (array of xml type => php type)
181
+	 * is this legacy yet?
182
+	 * no, this is used by the nusoap_xmlschema class to verify type => namespace mappings.
183
+	 *
184
+	 * @var      array
185
+	 * @access   public
186
+	 */
187
+	var $typemap = array(
188
+		'http://www.w3.org/2001/XMLSchema' => array(
189
+			'string' => 'string', 'boolean' => 'boolean', 'float' => 'double', 'double' => 'double', 'decimal' => 'double',
190
+			'duration' => '', 'dateTime' => 'string', 'time' => 'string', 'date' => 'string', 'gYearMonth' => '',
191
+			'gYear' => '', 'gMonthDay' => '', 'gDay' => '', 'gMonth' => '', 'hexBinary' => 'string', 'base64Binary' => 'string',
192
+			// abstract "any" types
193
+			'anyType' => 'string', 'anySimpleType' => 'string',
194
+			// derived datatypes
195
+			'normalizedString' => 'string', 'token' => 'string', 'language' => '', 'NMTOKEN' => '', 'NMTOKENS' => '', 'Name' => '', 'NCName' => '', 'ID' => '',
196
+			'IDREF' => '', 'IDREFS' => '', 'ENTITY' => '', 'ENTITIES' => '', 'integer' => 'integer', 'nonPositiveInteger' => 'integer',
197
+			'negativeInteger' => 'integer', 'long' => 'integer', 'int' => 'integer', 'short' => 'integer', 'byte' => 'integer', 'nonNegativeInteger' => 'integer',
198
+			'unsignedLong' => '', 'unsignedInt' => '', 'unsignedShort' => '', 'unsignedByte' => '', 'positiveInteger' => ''),
199
+		'http://www.w3.org/2000/10/XMLSchema' => array(
200
+			'i4' => '', 'int' => 'integer', 'boolean' => 'boolean', 'string' => 'string', 'double' => 'double',
201
+			'float' => 'double', 'dateTime' => 'string',
202
+			'timeInstant' => 'string', 'base64Binary' => 'string', 'base64' => 'string', 'ur-type' => 'array'),
203
+		'http://www.w3.org/1999/XMLSchema' => array(
204
+			'i4' => '', 'int' => 'integer', 'boolean' => 'boolean', 'string' => 'string', 'double' => 'double',
205
+			'float' => 'double', 'dateTime' => 'string',
206
+			'timeInstant' => 'string', 'base64Binary' => 'string', 'base64' => 'string', 'ur-type' => 'array'),
207
+		'http://soapinterop.org/xsd' => array('SOAPStruct' => 'struct'),
208
+		'http://schemas.xmlsoap.org/soap/encoding/' => array('base64' => 'string', 'array' => 'array', 'Array' => 'array'),
209
+		'http://xml.apache.org/xml-soap' => array('Map')
210
+	);
211
+
212
+	/**
213
+	 * XML entities to convert
214
+	 *
215
+	 * @var      array
216
+	 * @access   public
217
+	 * @deprecated
218
+	 * @see    expandEntities
219
+	 */
220
+	var $xmlEntities = array('quot' => '"', 'amp' => '&',
221
+		'lt' => '<', 'gt' => '>', 'apos' => "'");
222
+
223
+	/**
224
+	 * HTTP Content-type to be used for SOAP calls and responses
225
+	 *
226
+	 * @var string
227
+	 */
228
+	var $contentType = "text/xml";
229
+
230
+
231
+	/**
232
+	 * constructor
233
+	 *
234
+	 * @access    public
235
+	 */
236
+	function __construct()
237
+	{
238
+		$this->debugLevel = $GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel'];
239
+	}
240
+
241
+	/**
242
+	 * gets the global debug level, which applies to future instances
243
+	 *
244
+	 * @return    integer    Debug level 0-9, where 0 turns off
245
+	 * @access    public
246
+	 */
247
+	function getGlobalDebugLevel()
248
+	{
249
+		return $GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel'];
250
+	}
251
+
252
+	/**
253
+	 * sets the global debug level, which applies to future instances
254
+	 *
255
+	 * @param    int $level Debug level 0-9, where 0 turns off
256
+	 * @access    public
257
+	 */
258
+	function setGlobalDebugLevel($level)
259
+	{
260
+		$GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel'] = $level;
261
+	}
262
+
263
+	/**
264
+	 * gets the debug level for this instance
265
+	 *
266
+	 * @return    int    Debug level 0-9, where 0 turns off
267
+	 * @access    public
268
+	 */
269
+	function getDebugLevel()
270
+	{
271
+		return $this->debugLevel;
272
+	}
273
+
274
+	/**
275
+	 * sets the debug level for this instance
276
+	 *
277
+	 * @param    int $level Debug level 0-9, where 0 turns off
278
+	 * @access    public
279
+	 */
280
+	function setDebugLevel($level)
281
+	{
282
+		$this->debugLevel = $level;
283
+	}
284
+
285
+	/**
286
+	 * adds debug data to the instance debug string with formatting
287
+	 *
288
+	 * @param    string $string debug data
289
+	 * @access   private
290
+	 */
291
+	function debug($string)
292
+	{
293
+		if ($this->debugLevel > 0) {
294
+			$this->appendDebug($this->getmicrotime() . ' ' . get_class($this) . ": $string\n");
295
+		}
296
+	}
297
+
298
+	/**
299
+	 * adds debug data to the instance debug string without formatting
300
+	 *
301
+	 * @param    string $string debug data
302
+	 * @access   public
303
+	 */
304
+	function appendDebug($string)
305
+	{
306
+		if ($this->debugLevel > 0) {
307
+			// it would be nice to use a memory stream here to use
308
+			// memory more efficiently
309
+			$this->debug_str .= $string;
310
+		}
311
+	}
312
+
313
+	/**
314
+	 * clears the current debug data for this instance
315
+	 *
316
+	 * @access   public
317
+	 */
318
+	function clearDebug()
319
+	{
320
+		// it would be nice to use a memory stream here to use
321
+		// memory more efficiently
322
+		$this->debug_str = '';
323
+	}
324
+
325
+	/**
326
+	 * gets the current debug data for this instance
327
+	 *
328
+	 * @return   string data
329
+	 * @access   public
330
+	 */
331
+	function &getDebug()
332
+	{
333
+		// it would be nice to use a memory stream here to use
334
+		// memory more efficiently
335
+		return $this->debug_str;
336
+	}
337
+
338
+	/**
339
+	 * gets the current debug data for this instance as an XML comment
340
+	 * this may change the contents of the debug data
341
+	 *
342
+	 * @return   string data as an XML comment
343
+	 * @access   public
344
+	 */
345
+	function &getDebugAsXMLComment()
346
+	{
347
+		// it would be nice to use a memory stream here to use
348
+		// memory more efficiently
349
+		while (strpos($this->debug_str, '--')) {
350
+			$this->debug_str = str_replace('--', '- -', $this->debug_str);
351
+		}
352
+		$ret = "<!--\n" . $this->debug_str . "\n-->";
353
+		return $ret;
354
+	}
355
+
356
+	/**
357
+	 * expands entities, e.g. changes '<' to '&lt;'.
358
+	 *
359
+	 * @param    string $val The string in which to expand entities.
360
+	 * @access    private
361
+	 */
362
+	function expandEntities($val)
363
+	{
364
+		if ($this->charencoding) {
365
+			$val = str_replace('&', '&amp;', $val);
366
+			$val = str_replace("'", '&apos;', $val);
367
+			$val = str_replace('"', '&quot;', $val);
368
+			$val = str_replace('<', '&lt;', $val);
369
+			$val = str_replace('>', '&gt;', $val);
370
+		}
371
+		return $val;
372
+	}
373
+
374
+	/**
375
+	 * returns error string if present
376
+	 *
377
+	 * @return   false|string error string or false
378
+	 * @access   public
379
+	 */
380
+	function getError()
381
+	{
382
+		if ($this->error_str != '') {
383
+			return $this->error_str;
384
+		}
385
+		return false;
386
+	}
387
+
388
+	/**
389
+	 * sets error string
390
+	 *
391
+	 * @return   void
392
+	 * @access   private
393
+	 */
394
+	function setError($str)
395
+	{
396
+		$this->error_str = $str;
397
+	}
398
+
399
+	/**
400
+	 * detect if array is a simple array or a struct (associative array)
401
+	 *
402
+	 * @param    mixed $val The PHP array
403
+	 * @return    string    (arraySimple|arrayStruct)
404
+	 * @access    private
405
+	 */
406
+	function isArraySimpleOrStruct($val)
407
+	{
408
+		$keyList = array_keys($val);
409
+		foreach ($keyList as $keyListValue) {
410
+			if (!is_int($keyListValue)) {
411
+				return 'arrayStruct';
412
+			}
413
+		}
414
+		return 'arraySimple';
415
+	}
416
+
417
+	/**
418
+	 * serializes PHP values in accordance w/ section 5. Type information is
419
+	 * not serialized if $use == 'literal'.
420
+	 *
421
+	 * @param    mixed $val The value to serialize
422
+	 * @param    string $name The name (local part) of the XML element
423
+	 * @param    string $type The XML schema type (local part) for the element
424
+	 * @param    string $name_ns The namespace for the name of the XML element
425
+	 * @param    string $type_ns The namespace for the type of the element
426
+	 * @param    array $attributes The attributes to serialize as name=>value pairs
427
+	 * @param    string $use The WSDL "use" (encoded|literal)
428
+	 * @param    boolean $soapval Whether this is called from soapval.
429
+	 * @return    string    The serialized element, possibly with child elements
430
+	 * @access    public
431
+	 */
432
+	function serialize_val($val, $name = false, $type = false, $name_ns = false, $type_ns = false, $attributes = false, $use = 'encoded', $soapval = false)
433
+	{
434
+		$this->debug("in serialize_val: name=$name, type=$type, name_ns=$name_ns, type_ns=$type_ns, use=$use, soapval=$soapval");
435
+		$this->appendDebug('value=' . $this->varDump($val));
436
+		$this->appendDebug('attributes=' . $this->varDump($attributes));
437
+
438
+		if (is_object($val) && get_class($val) == 'soapval' && (!$soapval)) {
439
+			$this->debug("serialize_val: serialize soapval");
440
+			$xml = $val->serialize($use);
441
+			$this->appendDebug($val->getDebug());
442
+			$val->clearDebug();
443
+			$this->debug("serialize_val of soapval returning $xml");
444
+			return $xml;
445
+		}
446
+		// force valid name if necessary
447
+		if (is_numeric($name)) {
448
+			$name = '__numeric_' . $name;
449
+		} elseif (!$name) {
450
+			$name = 'noname';
451
+		}
452
+		// if name has ns, add ns prefix to name
453
+		$xmlns = '';
454
+		if ($name_ns) {
455
+			$prefix = 'nu' . rand(1000, 9999);
456
+			$name = $prefix . ':' . $name;
457
+			$xmlns .= " xmlns:$prefix=\"$name_ns\"";
458
+		}
459
+		// if type is prefixed, create type prefix
460
+		if ($type_ns != '' && $type_ns == $this->namespaces['xsd']) {
461
+			// need to fix this. shouldn't default to xsd if no ns specified
462
+			// w/o checking against typemap
463
+			$type_prefix = 'xsd';
464
+		} elseif ($type_ns) {
465
+			$type_prefix = 'ns' . rand(1000, 9999);
466
+			$xmlns .= " xmlns:$type_prefix=\"$type_ns\"";
467
+		}
468
+		// serialize attributes if present
469
+		$atts = '';
470
+		if ($attributes) {
471
+			foreach ($attributes as $k => $v) {
472
+				$atts .= " $k=\"" . $this->expandEntities($v) . '"';
473
+			}
474
+		}
475
+		// serialize null value
476
+		if (is_null($val)) {
477
+			$this->debug("serialize_val: serialize null");
478
+			if ($use == 'literal') {
479
+				// TODO: depends on minOccurs
480
+				$xml = "<$name$xmlns$atts/>";
481
+			} else {
482
+				if (isset($type) && isset($type_prefix)) {
483
+					$type_str = " xsi:type=\"$type_prefix:$type\"";
484
+				} else {
485
+					$type_str = '';
486
+				}
487
+				$xml = "<$name$xmlns$type_str$atts xsi:nil=\"true\"/>";
488
+			}
489
+			$this->debug("serialize_val returning $xml");
490
+			return $xml;
491
+		}
492
+		// serialize if an xsd built-in primitive type
493
+		if ($type != '' && isset($this->typemap[$this->XMLSchemaVersion][$type])) {
494
+			$this->debug("serialize_val: serialize xsd built-in primitive type");
495
+			if (is_bool($val)) {
496
+				if ($type == 'boolean') {
497
+					$val = $val ? 'true' : 'false';
498
+				} elseif (!$val) {
499
+					$val = 0;
500
+				}
501
+			} elseif (is_string($val)) {
502
+				$val = $this->expandEntities($val);
503
+			}
504
+			if ($use == 'literal') {
505
+				$xml = "<$name$xmlns$atts>$val</$name>";
506
+			} else {
507
+				$xml = "<$name$xmlns xsi:type=\"xsd:$type\"$atts>$val</$name>";
508
+			}
509
+			$this->debug("serialize_val returning $xml");
510
+			return $xml;
511
+		}
512
+		// detect type and serialize
513
+		$xml = '';
514
+		switch (true) {
515
+			case (is_bool($val) || $type == 'boolean'):
516
+				$this->debug("serialize_val: serialize boolean");
517
+				if ($type == 'boolean') {
518
+					$val = $val ? 'true' : 'false';
519
+				} elseif (!$val) {
520
+					$val = 0;
521
+				}
522
+				if ($use == 'literal') {
523
+					$xml .= "<$name$xmlns$atts>$val</$name>";
524
+				} else {
525
+					$xml .= "<$name$xmlns xsi:type=\"xsd:boolean\"$atts>$val</$name>";
526
+				}
527
+				break;
528
+			case (is_int($val) || is_long($val) || $type == 'int'):
529
+				$this->debug("serialize_val: serialize int");
530
+				if ($use == 'literal') {
531
+					$xml .= "<$name$xmlns$atts>$val</$name>";
532
+				} else {
533
+					$xml .= "<$name$xmlns xsi:type=\"xsd:int\"$atts>$val</$name>";
534
+				}
535
+				break;
536
+			case (is_float($val) || is_double($val) || $type == 'float'):
537
+				$this->debug("serialize_val: serialize float");
538
+				if ($use == 'literal') {
539
+					$xml .= "<$name$xmlns$atts>$val</$name>";
540
+				} else {
541
+					$xml .= "<$name$xmlns xsi:type=\"xsd:float\"$atts>$val</$name>";
542
+				}
543
+				break;
544
+			case (is_string($val) || $type == 'string'):
545
+				$this->debug("serialize_val: serialize string");
546
+				$val = $this->expandEntities($val);
547
+				if ($use == 'literal') {
548
+					$xml .= "<$name$xmlns$atts>$val</$name>";
549
+				} else {
550
+					$xml .= "<$name$xmlns xsi:type=\"xsd:string\"$atts>$val</$name>";
551
+				}
552
+				break;
553
+			case is_object($val):
554
+				$this->debug("serialize_val: serialize object");
555
+				$pXml = "";
556
+				if (get_class($val) == 'soapval') {
557
+					$this->debug("serialize_val: serialize soapval object");
558
+					$pXml = $val->serialize($use);
559
+					$this->appendDebug($val->getDebug());
560
+					$val->clearDebug();
561
+				} else {
562
+					if (!$name) {
563
+						$name = get_class($val);
564
+						$this->debug("In serialize_val, used class name $name as element name");
565
+					} else {
566
+						$this->debug("In serialize_val, do not override name $name for element name for class " . get_class($val));
567
+					}
568
+					foreach (get_object_vars($val) as $k => $v) {
569
+						$pXml = isset($pXml) ? $pXml . $this->serialize_val($v, $k, false, false, false, false, $use) : $this->serialize_val($v, $k, false, false, false, false, $use);
570
+					}
571
+				}
572
+				if (isset($type) && isset($type_prefix)) {
573
+					$type_str = " xsi:type=\"$type_prefix:$type\"";
574
+				} else {
575
+					$type_str = '';
576
+				}
577
+				if ($use == 'literal') {
578
+					$xml .= "<$name$xmlns$atts>$pXml</$name>";
579
+				} else {
580
+					$xml .= "<$name$xmlns$type_str$atts>$pXml</$name>";
581
+				}
582
+				break;
583
+			case (is_array($val) || $type):
584
+				// detect if struct or array
585
+				$valueType = $this->isArraySimpleOrStruct($val);
586
+				if ($valueType == 'arraySimple' || preg_match('/^ArrayOf/', $type)) {
587
+					$this->debug("serialize_val: serialize array");
588
+					$i = 0;
589
+					if (is_array($val) && count($val) > 0) {
590
+						$array_types = array ();
591
+						$tt_ns = "";
592
+						$tt = "";
593
+						foreach ($val as $v) {
594
+							if (is_object($v) && get_class($v) == 'soapval') {
595
+								$tt_ns = $v->type_ns;
596
+								$tt = $v->type;
597
+							} elseif (is_array($v)) {
598
+								$tt = $this->isArraySimpleOrStruct($v);
599
+							} else {
600
+								$tt = gettype($v);
601
+							}
602
+							$array_types[$tt] = 1;
603
+							// TODO: for literal, the name should be $name
604
+							$xml .= $this->serialize_val($v, 'item', false, false, false, false, $use);
605
+							++$i;
606
+						}
607
+						if (count($array_types) > 1) {
608
+							$array_typename = 'xsd:anyType';
609
+						} elseif (isset($tt) && isset($this->typemap[$this->XMLSchemaVersion][$tt])) {
610
+							if ($tt == 'integer') {
611
+								$tt = 'int';
612
+							}
613
+							$array_typename = 'xsd:' . $tt;
614
+						} elseif (isset($tt) && $tt == 'arraySimple') {
615
+							$array_typename = 'SOAP-ENC:Array';
616
+						} elseif (isset($tt) && $tt == 'arrayStruct') {
617
+							$array_typename = 'unnamed_struct_use_soapval';
618
+						} else {
619
+							// if type is prefixed, create type prefix
620
+							if ($tt_ns != '' && $tt_ns == $this->namespaces['xsd']) {
621
+								$array_typename = 'xsd:' . $tt;
622
+							} elseif ($tt_ns) {
623
+								$tt_prefix = 'ns' . rand(1000, 9999);
624
+								$array_typename = "$tt_prefix:$tt";
625
+								$xmlns .= " xmlns:$tt_prefix=\"$tt_ns\"";
626
+							} else {
627
+								$array_typename = $tt;
628
+							}
629
+						}
630
+						$array_type = $i;
631
+						if ($use == 'literal') {
632
+							$type_str = '';
633
+						} elseif (isset($type) && isset($type_prefix)) {
634
+							$type_str = " xsi:type=\"$type_prefix:$type\"";
635
+						} else {
636
+							$type_str = " xsi:type=\"SOAP-ENC:Array\" SOAP-ENC:arrayType=\"" . $array_typename . "[$array_type]\"";
637
+						}
638
+						// empty array
639
+					} else {
640
+						if ($use == 'literal') {
641
+							$type_str = '';
642
+						} elseif (isset($type) && isset($type_prefix)) {
643
+							$type_str = " xsi:type=\"$type_prefix:$type\"";
644
+						} else {
645
+							$type_str = " xsi:type=\"SOAP-ENC:Array\" SOAP-ENC:arrayType=\"xsd:anyType[0]\"";
646
+						}
647
+					}
648
+					// TODO: for array in literal, there is no wrapper here
649
+					$xml = "<$name$xmlns$type_str$atts>" . $xml . "</$name>";
650
+				} else {
651
+					// got a struct
652
+					$this->debug("serialize_val: serialize struct");
653
+					if (isset($type) && isset($type_prefix)) {
654
+						$type_str = " xsi:type=\"$type_prefix:$type\"";
655
+					} else {
656
+						$type_str = '';
657
+					}
658
+					if ($use == 'literal') {
659
+						$xml .= "<$name$xmlns$atts>";
660
+					} else {
661
+						$xml .= "<$name$xmlns$type_str$atts>";
662
+					}
663
+					foreach ($val as $k => $v) {
664
+						// Apache Map
665
+						if ($type == 'Map' && $type_ns == 'http://xml.apache.org/xml-soap') {
666
+							$xml .= '<item>';
667
+							$xml .= $this->serialize_val($k, 'key', false, false, false, false, $use);
668
+							$xml .= $this->serialize_val($v, 'value', false, false, false, false, $use);
669
+							$xml .= '</item>';
670
+						} else {
671
+							$xml .= $this->serialize_val($v, $k, false, false, false, false, $use);
672
+						}
673
+					}
674
+					$xml .= "</$name>";
675
+				}
676
+				break;
677
+			default:
678
+				$this->debug("serialize_val: serialize unknown");
679
+				$xml .= 'not detected, got ' . gettype($val) . ' for ' . $val;
680
+				break;
681
+		}
682
+		$this->debug("serialize_val returning $xml");
683
+		return $xml;
684
+	}
685
+
686
+	/**
687
+	 * serializes a message
688
+	 *
689
+	 * @param string $body the XML of the SOAP body
690
+	 * @param mixed $headers optional string of XML with SOAP header content, or array of soapval objects for SOAP headers, or associative array
691
+	 * @param array $namespaces optional the namespaces used in generating the body and headers
692
+	 * @param string $style optional (rpc|document)
693
+	 * @param string $use optional (encoded|literal)
694
+	 * @param string $encodingStyle optional (usually 'http://schemas.xmlsoap.org/soap/encoding/' for encoded)
695
+	 * @return string the message
696
+	 * @access public
697
+	 */
698
+	function serializeEnvelope($body, $headers = false, $namespaces = array(), $style = 'rpc', $use = 'encoded', $encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/')
699
+	{
700
+		// TODO: add an option to automatically run utf8_encode on $body and $headers
701
+		// if $this->soap_defencoding is UTF-8.  Not doing this automatically allows
702
+		// one to send arbitrary UTF-8 characters, not just characters that map to ISO-8859-1
703
+
704
+		$this->debug("In serializeEnvelope length=" . strlen($body) . " body (max 1000 characters)=" . substr($body, 0, 1000) . " style=$style use=$use encodingStyle=$encodingStyle");
705
+		$this->debug("headers:");
706
+		$this->appendDebug($this->varDump($headers));
707
+		$this->debug("namespaces:");
708
+		$this->appendDebug($this->varDump($namespaces));
709
+
710
+		// serialize namespaces
711
+		$ns_string = '';
712
+		foreach (array_merge($this->namespaces, $namespaces) as $k => $v) {
713
+			$ns_string .= " xmlns:$k=\"$v\"";
714
+		}
715
+		if ($encodingStyle) {
716
+			$ns_string = " SOAP-ENV:encodingStyle=\"$encodingStyle\"$ns_string";
717
+		}
718
+
719
+		// serialize headers
720
+		if ($headers) {
721
+			if (is_array($headers)) {
722
+				$xml = '';
723
+				foreach ($headers as $k => $v) {
724
+					if (is_object($v) && get_class($v) == 'soapval') {
725
+						$xml .= $this->serialize_val($v, false, false, false, false, false, $use);
726
+					} else {
727
+						$xml .= $this->serialize_val($v, $k, false, false, false, false, $use);
728
+					}
729
+				}
730
+				$headers = $xml;
731
+				$this->debug("In serializeEnvelope, serialized array of headers to $headers");
732
+			}
733
+			$headers = "<SOAP-ENV:Header>" . $headers . "</SOAP-ENV:Header>";
734
+		}
735
+		// serialize envelope
736
+		return
737
+			'<?xml version="1.0" encoding="' . $this->soap_defencoding . '"?' . ">" .
738
+			'<SOAP-ENV:Envelope' . $ns_string . ">" .
739
+			$headers .
740
+			"<SOAP-ENV:Body>" .
741
+			$body .
742
+			"</SOAP-ENV:Body>" .
743
+			"</SOAP-ENV:Envelope>";
744
+	}
745
+
746
+	/**
747
+	 * formats a string to be inserted into an HTML stream
748
+	 *
749
+	 * @param string $str The string to format
750
+	 * @return string The formatted string
751
+	 * @access public
752
+	 * @deprecated
753
+	 */
754
+	function formatDump($str)
755
+	{
756
+		$str = htmlspecialchars($str);
757
+		return nl2br($str);
758
+	}
759
+
760
+	/**
761
+	 * contracts (changes namespace to prefix) a qualified name
762
+	 *
763
+	 * @param    string $qname qname
764
+	 * @return    string contracted qname
765
+	 * @access   private
766
+	 */
767
+	function contractQname($qname)
768
+	{
769
+		// get element namespace
770
+		//$this->xdebug("Contract $qname");
771
+		if (strrpos($qname, ':')) {
772
+			// get unqualified name
773
+			$name = substr($qname, strrpos($qname, ':') + 1);
774
+			// get ns
775
+			$ns = substr($qname, 0, strrpos($qname, ':'));
776
+			$p = $this->getPrefixFromNamespace($ns);
777
+			if ($p) {
778
+				return $p . ':' . $name;
779
+			}
780
+		}
781
+		return $qname;
782
+	}
783
+
784
+	/**
785
+	 * expands (changes prefix to namespace) a qualified name
786
+	 *
787
+	 * @param    string $qname qname
788
+	 * @return    string expanded qname
789
+	 * @access   private
790
+	 */
791
+	function expandQname($qname)
792
+	{
793
+		// get element prefix
794
+		if (strpos($qname, ':') && !preg_match('/^http:\/\//', $qname)) {
795
+			// get unqualified name
796
+			$name = substr(strstr($qname, ':'), 1);
797
+			// get ns prefix
798
+			$prefix = substr($qname, 0, strpos($qname, ':'));
799
+			if (isset($this->namespaces[$prefix])) {
800
+				return $this->namespaces[$prefix] . ':' . $name;
801
+			} else {
802
+				return $qname;
803
+			}
804
+		} else {
805
+			return $qname;
806
+		}
807
+	}
808
+
809
+	/**
810
+	 * returns the local part of a prefixed string
811
+	 * returns the original string, if not prefixed
812
+	 *
813
+	 * @param string $str The prefixed string
814
+	 * @return string The local part
815
+	 * @access public
816
+	 */
817
+	function getLocalPart($str)
818
+	{
819
+		if ($sstr = strrchr($str, ':')) {
820
+			// get unqualified name
821
+			return substr($sstr, 1);
822
+		} else {
823
+			return $str;
824
+		}
825
+	}
826
+
827
+	/**
828
+	 * returns the prefix part of a prefixed string
829
+	 * returns false, if not prefixed
830
+	 *
831
+	 * @param string $str The prefixed string
832
+	 * @return false|string The prefix or false if there is no prefix
833
+	 * @access public
834
+	 */
835
+	function getPrefix($str)
836
+	{
837
+		if ($pos = strrpos($str, ':')) {
838
+			// get prefix
839
+			return substr($str, 0, $pos);
840
+		}
841
+		return false;
842
+	}
843
+
844
+	/**
845
+	 * pass it a prefix, it returns a namespace
846
+	 *
847
+	 * @param string $prefix The prefix
848
+	 * @return mixed The namespace, false if no namespace has the specified prefix
849
+	 * @access public
850
+	 */
851
+	function getNamespaceFromPrefix($prefix)
852
+	{
853
+		if (isset($this->namespaces[$prefix])) {
854
+			return $this->namespaces[$prefix];
855
+		}
856
+		//$this->setError("No namespace registered for prefix '$prefix'");
857
+		return false;
858
+	}
859
+
860
+	/**
861
+	 * returns the prefix for a given namespace (or prefix)
862
+	 * or false if no prefixes registered for the given namespace
863
+	 *
864
+	 * @param string $ns The namespace
865
+	 * @return false|string The prefix, false if the namespace has no prefixes
866
+	 * @access public
867
+	 */
868
+	function getPrefixFromNamespace($ns)
869
+	{
870
+		foreach ($this->namespaces as $p => $n) {
871
+			if ($ns == $n || $ns == $p) {
872
+				$this->usedNamespaces[$p] = $n;
873
+				return $p;
874
+			}
875
+		}
876
+		return false;
877
+	}
878
+
879
+	/**
880
+	 * returns the time in ODBC canonical form with microseconds
881
+	 *
882
+	 * @return string The time in ODBC canonical form with microseconds
883
+	 * @access public
884
+	 */
885
+	function getmicrotime()
886
+	{
887
+		if (function_exists('gettimeofday')) {
888
+			$tod = gettimeofday();
889
+			$sec = $tod['sec'];
890
+			$usec = $tod['usec'];
891
+		} else {
892
+			$sec = time();
893
+			$usec = 0;
894
+		}
895
+		$dtx = new DateTime("@$sec");
896 896
 	return
897
-          date_format($dtx, 'Y-m-d H:i:s') . '.' . sprintf('%06d', $usec);
898
-    }
899
-
900
-    /**
901
-     * Returns a string with the output of var_dump
902
-     *
903
-     * @param mixed $data The variable to var_dump
904
-     * @return string The output of var_dump
905
-     * @access public
906
-     */
907
-    function varDump($data)
908
-    {
909
-        ob_start();
910
-        var_dump($data);
911
-        $ret_val = ob_get_contents();
912
-        ob_end_clean();
913
-        return $ret_val;
914
-    }
915
-
916
-    /**
917
-     * represents the object as a string
918
-     *
919
-     * @return    string
920
-     * @access   public
921
-     */
922
-    function __toString()
923
-    {
924
-        return $this->varDump($this);
925
-    }
897
+		  date_format($dtx, 'Y-m-d H:i:s') . '.' . sprintf('%06d', $usec);
898
+	}
899
+
900
+	/**
901
+	 * Returns a string with the output of var_dump
902
+	 *
903
+	 * @param mixed $data The variable to var_dump
904
+	 * @return string The output of var_dump
905
+	 * @access public
906
+	 */
907
+	function varDump($data)
908
+	{
909
+		ob_start();
910
+		var_dump($data);
911
+		$ret_val = ob_get_contents();
912
+		ob_end_clean();
913
+		return $ret_val;
914
+	}
915
+
916
+	/**
917
+	 * represents the object as a string
918
+	 *
919
+	 * @return    string
920
+	 * @access   public
921
+	 */
922
+	function __toString()
923
+	{
924
+		return $this->varDump($this);
925
+	}
926 926
 }
927 927
 
928 928
 // XML Schema Datatype Helper Functions
@@ -939,35 +939,35 @@  discard block
 block discarded – undo
939 939
  */
940 940
 function timestamp_to_iso8601($timestamp, $utc = true)
941 941
 {
942
-    $datestr = date('Y-m-d\TH:i:sO', $timestamp);
943
-    $pos = strrpos($datestr, "+");
944
-    if ($pos === false) {
945
-        $pos = strrpos($datestr, "-");
946
-    }
947
-    if ($pos !== false) {
948
-        if (strlen($datestr) == $pos + 5) {
949
-            $datestr = substr($datestr, 0, $pos + 3) . ':' . substr($datestr, -2);
950
-        }
951
-    }
952
-    if ($utc) {
953
-        $pattern = '/' .
954
-            '([0-9]{4})-' .    // centuries & years CCYY-
955
-            '([0-9]{2})-' .    // months MM-
956
-            '([0-9]{2})' .    // days DD
957
-            'T' .            // separator T
958
-            '([0-9]{2}):' .    // hours hh:
959
-            '([0-9]{2}):' .    // minutes mm:
960
-            '([0-9]{2})(\.[0-9]*)?' . // seconds ss.ss...
961
-            '(Z|[+\-][0-9]{2}:?[0-9]{2})?' . // Z to indicate UTC, -/+HH:MM:SS.SS... for local tz's
962
-            '/';
963
-
964
-        if (preg_match($pattern, $datestr, $regs)) {
965
-            return sprintf('%04d-%02d-%02dT%02d:%02d:%02dZ', $regs[1], $regs[2], $regs[3], $regs[4], $regs[5], $regs[6]);
966
-        }
967
-        return false;
968
-    } else {
969
-        return $datestr;
970
-    }
942
+	$datestr = date('Y-m-d\TH:i:sO', $timestamp);
943
+	$pos = strrpos($datestr, "+");
944
+	if ($pos === false) {
945
+		$pos = strrpos($datestr, "-");
946
+	}
947
+	if ($pos !== false) {
948
+		if (strlen($datestr) == $pos + 5) {
949
+			$datestr = substr($datestr, 0, $pos + 3) . ':' . substr($datestr, -2);
950
+		}
951
+	}
952
+	if ($utc) {
953
+		$pattern = '/' .
954
+			'([0-9]{4})-' .    // centuries & years CCYY-
955
+			'([0-9]{2})-' .    // months MM-
956
+			'([0-9]{2})' .    // days DD
957
+			'T' .            // separator T
958
+			'([0-9]{2}):' .    // hours hh:
959
+			'([0-9]{2}):' .    // minutes mm:
960
+			'([0-9]{2})(\.[0-9]*)?' . // seconds ss.ss...
961
+			'(Z|[+\-][0-9]{2}:?[0-9]{2})?' . // Z to indicate UTC, -/+HH:MM:SS.SS... for local tz's
962
+			'/';
963
+
964
+		if (preg_match($pattern, $datestr, $regs)) {
965
+			return sprintf('%04d-%02d-%02dT%02d:%02d:%02dZ', $regs[1], $regs[2], $regs[3], $regs[4], $regs[5], $regs[6]);
966
+		}
967
+		return false;
968
+	} else {
969
+		return $datestr;
970
+	}
971 971
 }
972 972
 
973 973
 /**
@@ -979,35 +979,35 @@  discard block
 block discarded – undo
979 979
  */
980 980
 function iso8601_to_timestamp($datestr)
981 981
 {
982
-    $pattern = '/' .
983
-        '([0-9]{4})-' .    // centuries & years CCYY-
984
-        '([0-9]{2})-' .    // months MM-
985
-        '([0-9]{2})' .    // days DD
986
-        'T' .            // separator T
987
-        '([0-9]{2}):' .    // hours hh:
988
-        '([0-9]{2}):' .    // minutes mm:
989
-        '([0-9]{2})(\.[0-9]+)?' . // seconds ss.ss...
990
-        '(Z|[+\-][0-9]{2}:?[0-9]{2})?' . // Z to indicate UTC, -/+HH:MM:SS.SS... for local tz's
991
-        '/';
992
-    if (preg_match($pattern, $datestr, $regs)) {
993
-        // not utc
994
-        if ($regs[8] != 'Z') {
995
-            $op = substr($regs[8], 0, 1);
996
-            $h = substr($regs[8], 1, 2);
997
-            $m = substr($regs[8], strlen($regs[8]) - 2, 2);
998
-            if ($op == '-') {
999
-                $regs[4] = intval ($regs[4]) + intval ($h);
1000
-                $regs[5] = intval ($regs[5]) + intval ($m);
1001
-            } elseif ($op == '+') {
1002
-                $regs[4] = intval ($regs[4]) - intval ($h);
1003
-                $regs[5] = intval ($regs[5]) - intval ($m);
1004
-            }
1005
-        }
1006
-        return gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
982
+	$pattern = '/' .
983
+		'([0-9]{4})-' .    // centuries & years CCYY-
984
+		'([0-9]{2})-' .    // months MM-
985
+		'([0-9]{2})' .    // days DD
986
+		'T' .            // separator T
987
+		'([0-9]{2}):' .    // hours hh:
988
+		'([0-9]{2}):' .    // minutes mm:
989
+		'([0-9]{2})(\.[0-9]+)?' . // seconds ss.ss...
990
+		'(Z|[+\-][0-9]{2}:?[0-9]{2})?' . // Z to indicate UTC, -/+HH:MM:SS.SS... for local tz's
991
+		'/';
992
+	if (preg_match($pattern, $datestr, $regs)) {
993
+		// not utc
994
+		if ($regs[8] != 'Z') {
995
+			$op = substr($regs[8], 0, 1);
996
+			$h = substr($regs[8], 1, 2);
997
+			$m = substr($regs[8], strlen($regs[8]) - 2, 2);
998
+			if ($op == '-') {
999
+				$regs[4] = intval ($regs[4]) + intval ($h);
1000
+				$regs[5] = intval ($regs[5]) + intval ($m);
1001
+			} elseif ($op == '+') {
1002
+				$regs[4] = intval ($regs[4]) - intval ($h);
1003
+				$regs[5] = intval ($regs[5]) - intval ($m);
1004
+			}
1005
+		}
1006
+		return gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
1007 1007
 //		return strtotime("$regs[1]-$regs[2]-$regs[3] $regs[4]:$regs[5]:$regs[6]Z");
1008
-    } else {
1009
-        return false;
1010
-    }
1008
+	} else {
1009
+		return false;
1010
+	}
1011 1011
 }
1012 1012
 
1013 1013
 /**
@@ -1019,13 +1019,13 @@  discard block
 block discarded – undo
1019 1019
  */
1020 1020
 function usleepWindows($usec)
1021 1021
 {
1022
-    $start = gettimeofday();
1022
+	$start = gettimeofday();
1023 1023
 
1024
-    do {
1025
-        $stop = gettimeofday();
1026
-        $timePassed = 1000000 * ($stop['sec'] - $start['sec'])
1027
-            + $stop['usec'] - $start['usec'];
1028
-    } while ($timePassed < $usec);
1024
+	do {
1025
+		$stop = gettimeofday();
1026
+		$timePassed = 1000000 * ($stop['sec'] - $start['sec'])
1027
+			+ $stop['usec'] - $start['usec'];
1028
+	} while ($timePassed < $usec);
1029 1029
 }
1030 1030
 
1031 1031
 
@@ -1040,77 +1040,77 @@  discard block
 block discarded – undo
1040 1040
  */
1041 1041
 class nusoap_fault extends nusoap_base
1042 1042
 {
1043
-    /**
1044
-     * The fault code (client|server)
1045
-     *
1046
-     * @var string
1047
-     * @access private
1048
-     */
1049
-    var $faultcode;
1050
-    /**
1051
-     * The fault actor
1052
-     *
1053
-     * @var string
1054
-     * @access private
1055
-     */
1056
-    var $faultactor;
1057
-    /**
1058
-     * The fault string, a description of the fault
1059
-     *
1060
-     * @var string
1061
-     * @access private
1062
-     */
1063
-    var $faultstring;
1064
-    /**
1065
-     * The fault detail, typically a string or array of string
1066
-     *
1067
-     * @var mixed
1068
-     * @access private
1069
-     */
1070
-    var $faultdetail;
1071
-
1072
-    /**
1073
-     * constructor
1074
-     *
1075
-     * @param string $faultcode (SOAP-ENV:Client | SOAP-ENV:Server)
1076
-     * @param string $faultactor only used when msg routed between multiple actors
1077
-     * @param string $faultstring human readable error message
1078
-     * @param mixed $faultdetail detail, typically a string or array of string
1079
-     */
1080
-    function __construct($faultcode, $faultactor = '', $faultstring = '', $faultdetail = '')
1081
-    {
1082
-        parent::__construct();
1083
-        $this->faultcode = $faultcode;
1084
-        $this->faultactor = $faultactor;
1085
-        $this->faultstring = $faultstring;
1086
-        $this->faultdetail = $faultdetail;
1087
-    }
1088
-
1089
-    /**
1090
-     * serialize a fault
1091
-     *
1092
-     * @return    string    The serialization of the fault instance.
1093
-     * @access   public
1094
-     */
1095
-    function serialize()
1096
-    {
1097
-        $ns_string = '';
1098
-        foreach ($this->namespaces as $k => $v) {
1099
-            $ns_string .= "\n  xmlns:$k=\"$v\"";
1100
-        }
1101
-
1102
-      return '<?xml version="1.0" encoding="' . $this->soap_defencoding . '"?>' .
1103
-       '<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"' . $ns_string . ">\n" .
1104
-       '<SOAP-ENV:Body>' .
1105
-       '<SOAP-ENV:Fault>' .
1106
-       $this->serialize_val($this->faultcode, 'faultcode') .
1107
-       $this->serialize_val($this->faultstring, 'faultstring') .
1108
-       $this->serialize_val($this->faultactor, 'faultactor') .
1109
-       $this->serialize_val($this->faultdetail, 'detail') .
1110
-       '</SOAP-ENV:Fault>' .
1111
-       '</SOAP-ENV:Body>' .
1112
-       '</SOAP-ENV:Envelope>';
1113
-    }
1043
+	/**
1044
+	 * The fault code (client|server)
1045
+	 *
1046
+	 * @var string
1047
+	 * @access private
1048
+	 */
1049
+	var $faultcode;
1050
+	/**
1051
+	 * The fault actor
1052
+	 *
1053
+	 * @var string
1054
+	 * @access private
1055
+	 */
1056
+	var $faultactor;
1057
+	/**
1058
+	 * The fault string, a description of the fault
1059
+	 *
1060
+	 * @var string
1061
+	 * @access private
1062
+	 */
1063
+	var $faultstring;
1064
+	/**
1065
+	 * The fault detail, typically a string or array of string
1066
+	 *
1067
+	 * @var mixed
1068
+	 * @access private
1069
+	 */
1070
+	var $faultdetail;
1071
+
1072
+	/**
1073
+	 * constructor
1074
+	 *
1075
+	 * @param string $faultcode (SOAP-ENV:Client | SOAP-ENV:Server)
1076
+	 * @param string $faultactor only used when msg routed between multiple actors
1077
+	 * @param string $faultstring human readable error message
1078
+	 * @param mixed $faultdetail detail, typically a string or array of string
1079
+	 */
1080
+	function __construct($faultcode, $faultactor = '', $faultstring = '', $faultdetail = '')
1081
+	{
1082
+		parent::__construct();
1083
+		$this->faultcode = $faultcode;
1084
+		$this->faultactor = $faultactor;
1085
+		$this->faultstring = $faultstring;
1086
+		$this->faultdetail = $faultdetail;
1087
+	}
1088
+
1089
+	/**
1090
+	 * serialize a fault
1091
+	 *
1092
+	 * @return    string    The serialization of the fault instance.
1093
+	 * @access   public
1094
+	 */
1095
+	function serialize()
1096
+	{
1097
+		$ns_string = '';
1098
+		foreach ($this->namespaces as $k => $v) {
1099
+			$ns_string .= "\n  xmlns:$k=\"$v\"";
1100
+		}
1101
+
1102
+	  return '<?xml version="1.0" encoding="' . $this->soap_defencoding . '"?>' .
1103
+	   '<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"' . $ns_string . ">\n" .
1104
+	   '<SOAP-ENV:Body>' .
1105
+	   '<SOAP-ENV:Fault>' .
1106
+	   $this->serialize_val($this->faultcode, 'faultcode') .
1107
+	   $this->serialize_val($this->faultstring, 'faultstring') .
1108
+	   $this->serialize_val($this->faultactor, 'faultactor') .
1109
+	   $this->serialize_val($this->faultdetail, 'detail') .
1110
+	   '</SOAP-ENV:Fault>' .
1111
+	   '</SOAP-ENV:Body>' .
1112
+	   '</SOAP-ENV:Envelope>';
1113
+	}
1114 1114
 }
1115 1115
 
1116 1116
 
@@ -1134,5579 +1134,5579 @@  discard block
 block discarded – undo
1134 1134
 class nusoap_xmlschema extends nusoap_base
1135 1135
 {
1136 1136
 
1137
-    // files
1138
-    var $schema = '';
1139
-    var $xml = '';
1140
-    // namespaces
1141
-    var $enclosingNamespaces;
1142
-    // schema info
1143
-    var $schemaInfo = array();
1144
-    var $schemaTargetNamespace = '';
1145
-    // types, elements, attributes defined by the schema
1146
-    var $attributes = array();
1147
-    var $complexTypes = array();
1148
-    var $complexTypeStack = array();
1149
-    var $currentComplexType = null;
1150
-    var $elements = array();
1151
-    var $elementStack = array();
1152
-    var $currentElement = null;
1153
-    var $simpleTypes = array();
1154
-    var $simpleTypeStack = array();
1155
-    var $currentSimpleType = null;
1156
-    // imports
1157
-    var $imports = array();
1158
-    // parser vars
1159
-    var $parser;
1160
-    var $position = 0;
1161
-    var $depth = 0;
1162
-    var $depth_array = array();
1163
-    var $message = array();
1164
-    var $defaultNamespace = array();
1165
-
1166
-    /**
1167
-     * constructor
1168
-     *
1169
-     * @param    string $schema schema document URI
1170
-     * @param    string $xml xml document URI
1171
-     * @param    string $namespaces namespaces defined in enclosing XML
1172
-     * @access   public
1173
-     */
1174
-    function __construct($schema = '', $xml = '', $namespaces = array())
1175
-    {
1176
-        parent::__construct();
1177
-        $this->debug('nusoap_xmlschema class instantiated, inside constructor');
1178
-        // files
1179
-        $this->schema = $schema;
1180
-        $this->xml = $xml;
1181
-
1182
-        // namespaces
1183
-        $this->enclosingNamespaces = $namespaces;
1184
-        $this->namespaces = array_merge($this->namespaces, $namespaces);
1185
-
1186
-        // parse schema file
1187
-        if ($schema != '') {
1188
-            $this->debug('initial schema file: ' . $schema);
1189
-            $this->parseFile($schema, 'schema');
1190
-        }
1191
-
1192
-        // parse xml file
1193
-        if ($xml != '') {
1194
-            $this->debug('initial xml file: ' . $xml);
1195
-            $this->parseFile($xml, 'xml');
1196
-        }
1197
-
1198
-    }
1199
-
1200
-    /**
1201
-     * parse an XML file
1202
-     *
1203
-     * @param string $xml path/URL to XML file
1204
-     * @param string $type (schema | xml)
1205
-     * @return boolean
1206
-     * @access public
1207
-     */
1208
-    function parseFile($xml, $type)
1209
-    {
1210
-        // parse xml file
1211
-        if ($xml != "") {
1212
-            $xmlStr = @join("", @file($xml));
1213
-            if ($xmlStr == "") {
1214
-                $msg = 'Error reading XML from ' . $xml;
1215
-                $this->setError($msg);
1216
-                $this->debug($msg);
1217
-                return false;
1218
-            } else {
1219
-                $this->debug("parsing $xml");
1220
-                $this->parseString($xmlStr, $type);
1221
-                $this->debug("done parsing $xml");
1222
-                return true;
1223
-            }
1224
-        }
1225
-        return false;
1226
-    }
1227
-
1228
-    /**
1229
-     * parse an XML string
1230
-     *
1231
-     * @param    string $xml path or URL
1232
-     * @param    string $type (schema|xml)
1233
-     * @access   private
1234
-     */
1235
-    function parseString($xml, $type)
1236
-    {
1237
-        // parse xml string
1238
-        if ($xml != "") {
1239
-
1240
-            // Create an XML parser.
1241
-            $this->parser = xml_parser_create();
1242
-            // Set the options for parsing the XML data.
1243
-            xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
1244
-
1245
-            // Set the object for the parser.
1246
-            xml_set_object($this->parser, $this);
1247
-
1248
-            // Set the element handlers for the parser.
1249
-            if ($type == "schema") {
1250
-                xml_set_element_handler($this->parser, 'schemaStartElement', 'schemaEndElement');
1251
-                xml_set_character_data_handler($this->parser, 'schemaCharacterData');
1252
-            } elseif ($type == "xml") {
1253
-                xml_set_element_handler($this->parser, 'xmlStartElement', 'xmlEndElement');
1254
-                xml_set_character_data_handler($this->parser, 'xmlCharacterData');
1255
-            }
1256
-
1257
-            libxml_disable_entity_loader(true);	// Avoid load of external entities (security problem). Required only for libxml < 2.
1258
-
1259
-            // Parse the XML file.
1260
-            if (!xml_parse($this->parser, $xml, true)) {
1261
-                // Display an error message.
1262
-                $errstr = sprintf('XML error parsing XML schema on line %d: %s',
1263
-                    xml_get_current_line_number($this->parser),
1264
-                    xml_error_string(xml_get_error_code($this->parser))
1265
-                );
1266
-                $this->debug($errstr);
1267
-                $this->debug("XML payload:\n" . $xml);
1268
-                $this->setError($errstr);
1269
-            }
1270
-
1271
-            xml_parser_free($this->parser);
1272
-            unset($this->parser);
1273
-        } else {
1274
-            $this->debug('no xml passed to parseString()!!');
1275
-            $this->setError('no xml passed to parseString()!!');
1276
-        }
1277
-    }
1278
-
1279
-    /**
1280
-     * gets a type name for an unnamed type
1281
-     *
1282
-     * @param    string $ename Element name
1283
-     * @return    string    A type name for an unnamed type
1284
-     * @access    private
1285
-     */
1286
-    function CreateTypeName($ename)
1287
-    {
1288
-        $scope = '';
1289
-        for ($i = 0; $i < count($this->complexTypeStack); $i++) {
1290
-            $scope .= $this->complexTypeStack[$i] . '_';
1291
-        }
1292
-        return $scope . $ename . '_ContainedType';
1293
-    }
1294
-
1295
-    /**
1296
-     * start-element handler
1297
-     *
1298
-     * @param    string $parser XML parser object
1299
-     * @param    string $name element name
1300
-     * @param    array $attrs associative array of attributes
1301
-     * @access   private
1302
-     */
1303
-    function schemaStartElement($parser, $name, $attrs)
1304
-    {
1305
-
1306
-        // position in the total number of elements, starting from 0
1307
-        $pos = $this->position++;
1308
-        $depth = $this->depth++;
1309
-        // set self as current value for this depth
1310
-        $this->depth_array[$depth] = $pos;
1311
-        $this->message[$pos] = array('cdata' => '');
1312
-        if ($depth > 0) {
1313
-            $this->defaultNamespace[$pos] = $this->defaultNamespace[$this->depth_array[$depth - 1]];
1314
-        } else {
1315
-            $this->defaultNamespace[$pos] = false;
1316
-        }
1317
-
1318
-        // get element prefix
1319
-        if ($prefix = $this->getPrefix($name)) {
1320
-            // get unqualified name
1321
-            $name = $this->getLocalPart($name);
1322
-        } else {
1323
-            $prefix = '';
1324
-        }
1325
-
1326
-        // loop thru attributes, expanding, and registering namespace declarations
1327
-        if (count($attrs) > 0) {
1328
-            foreach ($attrs as $k => $v) {
1329
-                // if ns declarations, add to class level array of valid namespaces
1330
-                if (preg_match('/^xmlns/', $k)) {
1331
-                    //$this->xdebug("$k: $v");
1332
-                    //$this->xdebug('ns_prefix: '.$this->getPrefix($k));
1333
-                    if ($ns_prefix = substr(strrchr($k, ':'), 1)) {
1334
-                        //$this->xdebug("Add namespace[$ns_prefix] = $v");
1335
-                        $this->namespaces[$ns_prefix] = $v;
1336
-                    } else {
1337
-                        $this->defaultNamespace[$pos] = $v;
1338
-                        if (!$this->getPrefixFromNamespace($v)) {
1339
-                            $this->namespaces['ns' . (count($this->namespaces) + 1)] = $v;
1340
-                        }
1341
-                    }
1342
-                    if ($v == 'http://www.w3.org/2001/XMLSchema' || $v == 'http://www.w3.org/1999/XMLSchema' || $v == 'http://www.w3.org/2000/10/XMLSchema') {
1343
-                        $this->XMLSchemaVersion = $v;
1344
-                        $this->namespaces['xsi'] = $v . '-instance';
1345
-                    }
1346
-                }
1347
-            }
1348
-            $eAttrs = array ();
1349
-            foreach ($attrs as $k => $v) {
1350
-                // expand each attribute
1351
-                $k = strpos($k, ':') ? $this->expandQname($k) : $k;
1352
-                $v = strpos($v, ':') ? $this->expandQname($v) : $v;
1353
-                $eAttrs[$k] = $v;
1354
-            }
1355
-            $attrs = $eAttrs;
1356
-        } else {
1357
-            $attrs = array();
1358
-        }
1359
-        // find status, register data
1360
-        switch ($name) {
1361
-            case 'all':            // (optional) compositor content for a complexType
1362
-            case 'choice':
1363
-            case 'group':
1364
-            case 'sequence':
1365
-                //$this->xdebug("compositor $name for currentComplexType: $this->currentComplexType and currentElement: $this->currentElement");
1366
-                $this->complexTypes[$this->currentComplexType]['compositor'] = $name;
1367
-                //if($name == 'all' || $name == 'sequence'){
1368
-                //	$this->complexTypes[$this->currentComplexType]['phpType'] = 'struct';
1369
-                //}
1370
-                break;
1371
-            case 'attribute':    // complexType attribute
1372
-                //$this->xdebug("parsing attribute $attrs[name] $attrs[ref] of value: ".$attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']);
1373
-                $this->xdebug("parsing attribute:");
1374
-                $this->appendDebug($this->varDump($attrs));
1375
-                if (!isset($attrs['form'])) {
1376
-                    // TODO: handle globals
1377
-                    $attrs['form'] = $this->schemaInfo['attributeFormDefault'];
1378
-                }
1379
-                if (isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])) {
1380
-                    $v = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'];
1381
-                    if (!strpos($v, ':')) {
1382
-                        // no namespace in arrayType attribute value...
1383
-                        if ($this->defaultNamespace[$pos]) {
1384
-                            // ...so use the default
1385
-                            $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'] = $this->defaultNamespace[$pos] . ':' . $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'];
1386
-                        }
1387
-                    }
1388
-                }
1389
-                if (isset($attrs['name'])) {
1390
-                    $this->attributes[$attrs['name']] = $attrs;
1391
-                    $aname = $attrs['name'];
1392
-                } elseif (isset($attrs['ref']) && $attrs['ref'] == 'http://schemas.xmlsoap.org/soap/encoding/:arrayType') {
1393
-                    if (isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])) {
1394
-                        $aname = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'];
1395
-                    } else {
1396
-                        $aname = '';
1397
-                    }
1398
-                } elseif (isset($attrs['ref'])) {
1399
-                    $aname = $attrs['ref'];
1400
-                    $this->attributes[$attrs['ref']] = $attrs;
1401
-                } else {
1402
-                    $aname = '';
1403
-                }
1404
-
1405
-                if ($this->currentComplexType) {    // This should *always* be
1406
-                    $this->complexTypes[$this->currentComplexType]['attrs'][$aname] = $attrs;
1407
-                }
1408
-                // arrayType attribute
1409
-                if (isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']) || $this->getLocalPart($aname) == 'arrayType') {
1410
-                    $this->complexTypes[$this->currentComplexType]['phpType'] = 'array';
1411
-                    if (isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])) {
1412
-                        $v = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'];
1413
-                    } else {
1414
-                        $v = '';
1415
-                    }
1416
-                    if (strpos($v, '[,]')) {
1417
-                        $this->complexTypes[$this->currentComplexType]['multidimensional'] = true;
1418
-                    }
1419
-                    $v = substr($v, 0, strpos($v, '[')); // clip the []
1420
-                    if (!strpos($v, ':') && isset($this->typemap[$this->XMLSchemaVersion][$v])) {
1421
-                        $v = $this->XMLSchemaVersion . ':' . $v;
1422
-                    }
1423
-                    $this->complexTypes[$this->currentComplexType]['arrayType'] = $v;
1424
-                }
1425
-                break;
1426
-            case 'complexContent':    // (optional) content for a complexType
1427
-                $this->xdebug("do nothing for element $name");
1428
-                break;
1429
-            case 'complexType':
1430
-                $this->complexTypeStack[] = $this->currentComplexType;
1431
-                if (isset($attrs['name'])) {
1432
-                    // TODO: what is the scope of named complexTypes that appear
1433
-                    //       nested within other c complexTypes?
1434
-                    $this->xdebug('processing named complexType ' . $attrs['name']);
1435
-                    //$this->currentElement = false;
1436
-                    $this->currentComplexType = $attrs['name'];
1437
-                } else {
1438
-                    $name = $this->CreateTypeName($this->currentElement);
1439
-                    $this->xdebug('processing unnamed complexType for element ' . $this->currentElement . ' named ' . $name);
1440
-                    $this->currentComplexType = $name;
1441
-                    //$this->currentElement = false;
1442
-                }
1443
-                $this->complexTypes[$this->currentComplexType] = $attrs;
1444
-                $this->complexTypes[$this->currentComplexType]['typeClass'] = 'complexType';
1445
-                // This is for constructs like
1446
-                //           <complexType name="ListOfString" base="soap:Array">
1447
-                //                <sequence>
1448
-                //                    <element name="string" type="xsd:string"
1449
-                //                        minOccurs="0" maxOccurs="unbounded" />
1450
-                //                </sequence>
1451
-                //            </complexType>
1452
-                if (isset($attrs['base']) && preg_match('/:Array$/', $attrs['base'])) {
1453
-                    $this->xdebug('complexType is unusual array');
1454
-                    $this->complexTypes[$this->currentComplexType]['phpType'] = 'array';
1455
-                } else {
1456
-                    $this->complexTypes[$this->currentComplexType]['phpType'] = 'struct';
1457
-                }
1458
-                $this->complexTypes[$this->currentComplexType]['simpleContent'] = 'false';
1459
-                break;
1460
-            case 'element':
1461
-                $this->elementStack[] = $this->currentElement;
1462
-                if (!isset($attrs['form'])) {
1463
-                    if ($this->currentComplexType) {
1464
-                        $attrs['form'] = $this->schemaInfo['elementFormDefault'];
1465
-                    } else {
1466
-                        // global
1467
-                        $attrs['form'] = 'qualified';
1468
-                    }
1469
-                }
1470
-                if (isset($attrs['type'])) {
1471
-                    $this->xdebug("processing typed element " . $attrs['name'] . " of type " . $attrs['type']);
1472
-                    if (!$this->getPrefix($attrs['type'])) {
1473
-                        if ($this->defaultNamespace[$pos]) {
1474
-                            $attrs['type'] = $this->defaultNamespace[$pos] . ':' . $attrs['type'];
1475
-                            $this->xdebug('used default namespace to make type ' . $attrs['type']);
1476
-                        }
1477
-                    }
1478
-                    // This is for constructs like
1479
-                    //           <complexType name="ListOfString" base="soap:Array">
1480
-                    //                <sequence>
1481
-                    //                    <element name="string" type="xsd:string"
1482
-                    //                        minOccurs="0" maxOccurs="unbounded" />
1483
-                    //                </sequence>
1484
-                    //            </complexType>
1485
-                    if ($this->currentComplexType && $this->complexTypes[$this->currentComplexType]['phpType'] == 'array') {
1486
-                        $this->xdebug('arrayType for unusual array is ' . $attrs['type']);
1487
-                        $this->complexTypes[$this->currentComplexType]['arrayType'] = $attrs['type'];
1488
-                    }
1489
-                    $this->currentElement = $attrs['name'];
1490
-                    $ename = $attrs['name'];
1491
-                } elseif (isset($attrs['ref'])) {
1492
-                    $this->xdebug("processing element as ref to " . $attrs['ref']);
1493
-                    $this->currentElement = "ref to " . $attrs['ref'];
1494
-                    $ename = $this->getLocalPart($attrs['ref']);
1495
-                } else {
1496
-                    $type = $this->CreateTypeName($this->currentComplexType . '_' . $attrs['name']);
1497
-                    $this->xdebug("processing untyped element " . $attrs['name'] . ' type ' . $type);
1498
-                    $this->currentElement = $attrs['name'];
1499
-                    $attrs['type'] = $this->schemaTargetNamespace . ':' . $type;
1500
-                    $ename = $attrs['name'];
1501
-                }
1502
-                if (isset($ename) && $this->currentComplexType) {
1503
-                    $this->xdebug("add element $ename to complexType $this->currentComplexType");
1504
-                    $this->complexTypes[$this->currentComplexType]['elements'][$ename] = $attrs;
1505
-                } elseif (!isset($attrs['ref'])) {
1506
-                    $this->xdebug("add element $ename to elements array");
1507
-                    $this->elements[$attrs['name']] = $attrs;
1508
-                    $this->elements[$attrs['name']]['typeClass'] = 'element';
1509
-                }
1510
-                break;
1511
-            case 'enumeration':    //	restriction value list member
1512
-                $this->xdebug('enumeration ' . $attrs['value']);
1513
-                if ($this->currentSimpleType) {
1514
-                    $this->simpleTypes[$this->currentSimpleType]['enumeration'][] = $attrs['value'];
1515
-                } elseif ($this->currentComplexType) {
1516
-                    $this->complexTypes[$this->currentComplexType]['enumeration'][] = $attrs['value'];
1517
-                }
1518
-                break;
1519
-            case 'extension':    // simpleContent or complexContent type extension
1520
-                $this->xdebug('extension ' . $attrs['base']);
1521
-                if ($this->currentComplexType) {
1522
-                    $ns = $this->getPrefix($attrs['base']);
1523
-                    if ($ns == '') {
1524
-                        $this->complexTypes[$this->currentComplexType]['extensionBase'] = $this->schemaTargetNamespace . ':' . $attrs['base'];
1525
-                    } else {
1526
-                        $this->complexTypes[$this->currentComplexType]['extensionBase'] = $attrs['base'];
1527
-                    }
1528
-                } else {
1529
-                    $this->xdebug('no current complexType to set extensionBase');
1530
-                }
1531
-                break;
1532
-            case 'import':
1533
-                if (isset($attrs['schemaLocation'])) {
1534
-                    $this->xdebug('import namespace ' . $attrs['namespace'] . ' from ' . $attrs['schemaLocation']);
1535
-                    $this->imports[$attrs['namespace']][] = array('location' => $attrs['schemaLocation'], 'loaded' => false);
1536
-                } else {
1537
-                    $this->xdebug('import namespace ' . $attrs['namespace']);
1538
-                    $this->imports[$attrs['namespace']][] = array('location' => '', 'loaded' => true);
1539
-                    if (!$this->getPrefixFromNamespace($attrs['namespace'])) {
1540
-                        $this->namespaces['ns' . (count($this->namespaces) + 1)] = $attrs['namespace'];
1541
-                    }
1542
-                }
1543
-                break;
1544
-            case 'include':
1545
-                if (isset($attrs['schemaLocation'])) {
1546
-                    $this->xdebug('include into namespace ' . $this->schemaTargetNamespace . ' from ' . $attrs['schemaLocation']);
1547
-                    $this->imports[$this->schemaTargetNamespace][] = array('location' => $attrs['schemaLocation'], 'loaded' => false);
1548
-                } else {
1549
-                    $this->xdebug('ignoring invalid XML Schema construct: include without schemaLocation attribute');
1550
-                }
1551
-                break;
1552
-            case 'list':    // simpleType value list
1553
-                $this->xdebug("do nothing for element $name");
1554
-                break;
1555
-            case 'restriction':    // simpleType, simpleContent or complexContent value restriction
1556
-                $this->xdebug('restriction ' . $attrs['base']);
1557
-                if ($this->currentSimpleType) {
1558
-                    $this->simpleTypes[$this->currentSimpleType]['type'] = $attrs['base'];
1559
-                } elseif ($this->currentComplexType) {
1560
-                    $this->complexTypes[$this->currentComplexType]['restrictionBase'] = $attrs['base'];
1561
-                    if (strstr($attrs['base'], ':') == ':Array') {
1562
-                        $this->complexTypes[$this->currentComplexType]['phpType'] = 'array';
1563
-                    }
1564
-                }
1565
-                break;
1566
-            case 'schema':
1567
-                $this->schemaInfo = $attrs;
1568
-                $this->schemaInfo['schemaVersion'] = $this->getNamespaceFromPrefix($prefix);
1569
-                if (isset($attrs['targetNamespace'])) {
1570
-                    $this->schemaTargetNamespace = $attrs['targetNamespace'];
1571
-                }
1572
-                if (!isset($attrs['elementFormDefault'])) {
1573
-                    $this->schemaInfo['elementFormDefault'] = 'unqualified';
1574
-                }
1575
-                if (!isset($attrs['attributeFormDefault'])) {
1576
-                    $this->schemaInfo['attributeFormDefault'] = 'unqualified';
1577
-                }
1578
-                break;
1579
-            case 'simpleContent':    // (optional) content for a complexType
1580
-                if ($this->currentComplexType) {    // This should *always* be
1581
-                    $this->complexTypes[$this->currentComplexType]['simpleContent'] = 'true';
1582
-                } else {
1583
-                    $this->xdebug("do nothing for element $name because there is no current complexType");
1584
-                }
1585
-                break;
1586
-            case 'simpleType':
1587
-                $this->simpleTypeStack[] = $this->currentSimpleType;
1588
-                if (isset($attrs['name'])) {
1589
-                    $this->xdebug("processing simpleType for name " . $attrs['name']);
1590
-                    $this->currentSimpleType = $attrs['name'];
1591
-                    $this->simpleTypes[$attrs['name']] = $attrs;
1592
-                    $this->simpleTypes[$attrs['name']]['typeClass'] = 'simpleType';
1593
-                    $this->simpleTypes[$attrs['name']]['phpType'] = 'scalar';
1594
-                } else {
1595
-                    $name = $this->CreateTypeName($this->currentComplexType . '_' . $this->currentElement);
1596
-                    $this->xdebug('processing unnamed simpleType for element ' . $this->currentElement . ' named ' . $name);
1597
-                    $this->currentSimpleType = $name;
1598
-                    //$this->currentElement = false;
1599
-                    $this->simpleTypes[$this->currentSimpleType] = $attrs;
1600
-                    $this->simpleTypes[$this->currentSimpleType]['phpType'] = 'scalar';
1601
-                }
1602
-                break;
1603
-            case 'union':    // simpleType type list
1604
-                $this->xdebug("do nothing for element $name");
1605
-                break;
1606
-            default:
1607
-                $this->xdebug("do not have any logic to process element $name");
1608
-        }
1609
-    }
1610
-
1611
-    /**
1612
-     * end-element handler
1613
-     *
1614
-     * @param    string $parser XML parser object
1615
-     * @param    string $name element name
1616
-     * @access   private
1617
-     */
1618
-    function schemaEndElement($parser, $name)
1619
-    {
1620
-        // bring depth down a notch
1621
-        $this->depth--;
1622
-        // get element prefix
1623
-        if ($this->getPrefix($name)) {
1624
-            // get unqualified name
1625
-            $name = $this->getLocalPart($name);
1626
-        }
1627
-        // move on...
1628
-        if ($name == 'complexType') {
1629
-            $this->xdebug('done processing complexType ' . ($this->currentComplexType ?: '(unknown)'));
1630
-            $this->xdebug($this->varDump($this->complexTypes[$this->currentComplexType]));
1631
-            $this->currentComplexType = array_pop($this->complexTypeStack);
1632
-            //$this->currentElement = false;
1633
-        }
1634
-        if ($name == 'element') {
1635
-            $this->xdebug('done processing element ' . ($this->currentElement ?: '(unknown)'));
1636
-            $this->currentElement = array_pop($this->elementStack);
1637
-        }
1638
-        if ($name == 'simpleType') {
1639
-            $this->xdebug('done processing simpleType ' . ($this->currentSimpleType ?: '(unknown)'));
1640
-            $this->xdebug($this->varDump($this->simpleTypes[$this->currentSimpleType]));
1641
-            $this->currentSimpleType = array_pop($this->simpleTypeStack);
1642
-        }
1643
-    }
1644
-
1645
-    /**
1646
-     * element content handler
1647
-     *
1648
-     * @param    string $parser XML parser object
1649
-     * @param    string $data element content
1650
-     * @access   private
1651
-     */
1652
-    function schemaCharacterData($parser, $data)
1653
-    {
1654
-        $pos = $this->depth_array[$this->depth - 1];
1655
-        $this->message[$pos]['cdata'] .= $data;
1656
-    }
1657
-
1658
-    /**
1659
-     * serialize the schema
1660
-     *
1661
-     * @access   public
1662
-     */
1663
-    function serializeSchema()
1664
-    {
1665
-
1666
-        $schemaPrefix = $this->getPrefixFromNamespace($this->XMLSchemaVersion);
1667
-        $xml = '';
1668
-        // imports
1669
-        if (sizeof($this->imports) > 0) {
1670
-            foreach ($this->imports as $ns => $list) {
1671
-                foreach ($list as $ii) {
1672
-                    if ($ii['location'] != '') {
1673
-                        $xml .= " <$schemaPrefix:import location=\"" . $ii['location'] . '" namespace="' . $ns . "\" />\n";
1674
-                    } else {
1675
-                        $xml .= " <$schemaPrefix:import namespace=\"" . $ns . "\" />\n";
1676
-                    }
1677
-                }
1678
-            }
1679
-        }
1680
-        // complex types
1681
-        foreach ($this->complexTypes as $typeName => $attrs) {
1682
-            $contentStr = '';
1683
-            // serialize child elements
1684
-            if (isset($attrs['elements']) && (count($attrs['elements']) > 0)) {
1685
-                foreach ($attrs['elements'] as $element => $eParts) {
1686
-                    if (isset($eParts['ref'])) {
1687
-                        $contentStr .= "   <$schemaPrefix:element ref=\"$element\"/>\n";
1688
-                    } else {
1689
-                        $contentStr .= "   <$schemaPrefix:element name=\"$element\" type=\"" . $this->contractQName($eParts['type']) . "\"";
1690
-                        foreach ($eParts as $aName => $aValue) {
1691
-                            // handle, e.g., abstract, default, form, minOccurs, maxOccurs, nillable
1692
-                            if ($aName != 'name' && $aName != 'type') {
1693
-                                $contentStr .= " $aName=\"$aValue\"";
1694
-                            }
1695
-                        }
1696
-                        $contentStr .= "/>\n";
1697
-                    }
1698
-                }
1699
-                // compositor wraps elements
1700
-                if (isset($attrs['compositor']) && ($attrs['compositor'] != '')) {
1701
-                    $contentStr = "  <$schemaPrefix:$attrs[compositor]>\n" . $contentStr . "  </$schemaPrefix:$attrs[compositor]>\n";
1702
-                }
1703
-            }
1704
-            // attributes
1705
-            if (isset($attrs['attrs']) && (count($attrs['attrs']) >= 1)) {
1706
-                foreach ($attrs['attrs'] as $aParts) {
1707
-                    $contentStr .= "    <$schemaPrefix:attribute";
1708
-                    foreach ($aParts as $a => $v) {
1709
-                        if ($a == 'ref' || $a == 'type') {
1710
-                            $contentStr .= " $a=\"" . $this->contractQName($v) . '"';
1711
-                        } elseif ($a == 'http://schemas.xmlsoap.org/wsdl/:arrayType') {
1712
-                            $this->usedNamespaces['wsdl'] = $this->namespaces['wsdl'];
1713
-                            $contentStr .= ' wsdl:arrayType="' . $this->contractQName($v) . '"';
1714
-                        } else {
1715
-                            $contentStr .= " $a=\"$v\"";
1716
-                        }
1717
-                    }
1718
-                    $contentStr .= "/>\n";
1719
-                }
1720
-            }
1721
-            // if restriction
1722
-            if (isset($attrs['restrictionBase']) && $attrs['restrictionBase'] != '') {
1723
-                $contentStr = "   <$schemaPrefix:restriction base=\"" . $this->contractQName($attrs['restrictionBase']) . "\">\n" . $contentStr . "   </$schemaPrefix:restriction>\n";
1724
-                // complex or simple content
1725
-                if ((isset($attrs['elements']) && count($attrs['elements']) > 0) || (isset($attrs['attrs']) && count($attrs['attrs']) > 0)) {
1726
-                    $contentStr = "  <$schemaPrefix:complexContent>\n" . $contentStr . "  </$schemaPrefix:complexContent>\n";
1727
-                }
1728
-            }
1729
-            // finalize complex type
1730
-            if ($contentStr != '') {
1731
-                $contentStr = " <$schemaPrefix:complexType name=\"$typeName\">\n" . $contentStr . " </$schemaPrefix:complexType>\n";
1732
-            } else {
1733
-                $contentStr = " <$schemaPrefix:complexType name=\"$typeName\"/>\n";
1734
-            }
1735
-            $xml .= $contentStr;
1736
-        }
1737
-        // simple types
1738
-        if (isset($this->simpleTypes) && count($this->simpleTypes) > 0) {
1739
-            foreach ($this->simpleTypes as $typeName => $eParts) {
1740
-                $xml .= " <$schemaPrefix:simpleType name=\"$typeName\">\n  <$schemaPrefix:restriction base=\"" . $this->contractQName($eParts['type']) . "\">\n";
1741
-                if (isset($eParts['enumeration'])) {
1742
-                    foreach ($eParts['enumeration'] as $e) {
1743
-                        $xml .= "  <$schemaPrefix:enumeration value=\"$e\"/>\n";
1744
-                    }
1745
-                }
1746
-                $xml .= "  </$schemaPrefix:restriction>\n </$schemaPrefix:simpleType>";
1747
-            }
1748
-        }
1749
-        // elements
1750
-        if (isset($this->elements) && count($this->elements) > 0) {
1751
-            foreach ($this->elements as $element => $eParts) {
1752
-                $xml .= " <$schemaPrefix:element name=\"$element\" type=\"" . $this->contractQName($eParts['type']) . "\"/>\n";
1753
-            }
1754
-        }
1755
-        // attributes
1756
-        if (isset($this->attributes) && count($this->attributes) > 0) {
1757
-            foreach ($this->attributes as $attr => $aParts) {
1758
-                $xml .= " <$schemaPrefix:attribute name=\"$attr\" type=\"" . $this->contractQName($aParts['type']) . "\"\n/>";
1759
-            }
1760
-        }
1761
-        // finish 'er up
1762
-        $attr = '';
1763
-        foreach ($this->schemaInfo as $k => $v) {
1764
-            if ($k == 'elementFormDefault' || $k == 'attributeFormDefault') {
1765
-                $attr .= " $k=\"$v\"";
1766
-            }
1767
-        }
1768
-        $el = "<$schemaPrefix:schema$attr targetNamespace=\"$this->schemaTargetNamespace\"\n";
1769
-        foreach (array_diff($this->usedNamespaces, $this->enclosingNamespaces) as $nsp => $ns) {
1770
-            $el .= " xmlns:$nsp=\"$ns\"";
1771
-        }
1772
-
1773
-      return $el . ">\n" . $xml . "</$schemaPrefix:schema>\n";
1774
-    }
1775
-
1776
-    /**
1777
-     * adds debug data to the clas level debug string
1778
-     *
1779
-     * @param    string $string debug data
1780
-     * @access   private
1781
-     */
1782
-    function xdebug($string)
1783
-    {
1784
-        $this->debug('<' . $this->schemaTargetNamespace . '> ' . $string);
1785
-    }
1786
-
1787
-    /**
1788
-     * get the PHP type of a user defined type in the schema
1789
-     * PHP type is kind of a misnomer since it actually returns 'struct' for assoc. arrays
1790
-     * returns false if no type exists, or not w/ the given namespace
1791
-     * else returns a string that is either a native php type, or 'struct'
1792
-     *
1793
-     * @param string $type name of defined type
1794
-     * @param string $ns namespace of type
1795
-     * @return mixed
1796
-     * @access public
1797
-     * @deprecated
1798
-     */
1799
-    function getPHPType($type, $ns)
1800
-    {
1801
-        if (isset($this->typemap[$ns][$type])) {
1802
-            //print "found type '$type' and ns $ns in typemap<br>";
1803
-            return $this->typemap[$ns][$type];
1804
-        } elseif (isset($this->complexTypes[$type])) {
1805
-            //print "getting type '$type' and ns $ns from complexTypes array<br>";
1806
-            return $this->complexTypes[$type]['phpType'];
1807
-        }
1808
-        return false;
1809
-    }
1810
-
1811
-    /**
1812
-     * returns an associative array of information about a given type
1813
-     * returns false if no type exists by the given name
1814
-     *
1815
-     *    For a complexType typeDef = array(
1816
-     *    'restrictionBase' => '',
1817
-     *    'phpType' => '',
1818
-     *    'compositor' => '(sequence|all)',
1819
-     *    'elements' => array(), // refs to elements array
1820
-     *    'attrs' => array() // refs to attributes array
1821
-     *    ... and so on (see addComplexType)
1822
-     *    )
1823
-     *
1824
-     *   For simpleType or element, the array has different keys.
1825
-     *
1826
-     * @param string $type
1827
-     * @return mixed
1828
-     * @access public
1829
-     * @see addComplexType
1830
-     * @see addSimpleType
1831
-     * @see addElement
1832
-     */
1833
-    function getTypeDef($type)
1834
-    {
1835
-        //$this->debug("in getTypeDef for type $type");
1836
-        if (substr($type, -1) == '^') {
1837
-            $is_element = 1;
1838
-            $type = substr($type, 0, -1);
1839
-        } else {
1840
-            $is_element = 0;
1841
-        }
1842
-
1843
-        if ((!$is_element) && isset($this->complexTypes[$type])) {
1844
-            $this->xdebug("in getTypeDef, found complexType $type");
1845
-            return $this->complexTypes[$type];
1846
-        } elseif ((!$is_element) && isset($this->simpleTypes[$type])) {
1847
-            $this->xdebug("in getTypeDef, found simpleType $type");
1848
-            if (!isset($this->simpleTypes[$type]['phpType'])) {
1849
-                // get info for type to tack onto the simple type
1850
-                // TODO: can this ever really apply (i.e. what is a simpleType really?)
1851
-                $uqType = substr($this->simpleTypes[$type]['type'], strrpos($this->simpleTypes[$type]['type'], ':') + 1);
1852
-                $etype = $this->getTypeDef($uqType);
1853
-                if ($etype) {
1854
-                    $this->xdebug("in getTypeDef, found type for simpleType $type:");
1855
-                    $this->xdebug($this->varDump($etype));
1856
-                    if (isset($etype['phpType'])) {
1857
-                        $this->simpleTypes[$type]['phpType'] = $etype['phpType'];
1858
-                    }
1859
-                    if (isset($etype['elements'])) {
1860
-                        $this->simpleTypes[$type]['elements'] = $etype['elements'];
1861
-                    }
1862
-                }
1863
-            }
1864
-            return $this->simpleTypes[$type];
1865
-        } elseif (isset($this->elements[$type])) {
1866
-            $this->xdebug("in getTypeDef, found element $type");
1867
-            if (!isset($this->elements[$type]['phpType'])) {
1868
-                // get info for type to tack onto the element
1869
-                $uqType = substr($this->elements[$type]['type'], strrpos($this->elements[$type]['type'], ':') + 1);
1870
-                $ns = substr($this->elements[$type]['type'], 0, strrpos($this->elements[$type]['type'], ':'));
1871
-                $etype = $this->getTypeDef($uqType);
1872
-                if ($etype) {
1873
-                    $this->xdebug("in getTypeDef, found type for element $type:");
1874
-                    $this->xdebug($this->varDump($etype));
1875
-                    if (isset($etype['phpType'])) {
1876
-                        $this->elements[$type]['phpType'] = $etype['phpType'];
1877
-                    }
1878
-                    if (isset($etype['elements'])) {
1879
-                        $this->elements[$type]['elements'] = $etype['elements'];
1880
-                    }
1881
-                    if (isset($etype['extensionBase'])) {
1882
-                        $this->elements[$type]['extensionBase'] = $etype['extensionBase'];
1883
-                    }
1884
-                } elseif ($ns == 'http://www.w3.org/2001/XMLSchema') {
1885
-                    $this->xdebug("in getTypeDef, element $type is an XSD type");
1886
-                    $this->elements[$type]['phpType'] = 'scalar';
1887
-                }
1888
-            }
1889
-            return $this->elements[$type];
1890
-        } elseif (isset($this->attributes[$type])) {
1891
-            $this->xdebug("in getTypeDef, found attribute $type");
1892
-            return $this->attributes[$type];
1893
-        } elseif (preg_match('/_ContainedType$/', $type)) {
1894
-            $this->xdebug("in getTypeDef, have an untyped element $type");
1895
-            $typeDef['typeClass'] = 'simpleType';
1896
-            $typeDef['phpType'] = 'scalar';
1897
-            $typeDef['type'] = 'http://www.w3.org/2001/XMLSchema:string';
1898
-            return $typeDef;
1899
-        }
1900
-        $this->xdebug("in getTypeDef, did not find $type");
1901
-        return false;
1902
-    }
1903
-
1904
-    /**
1905
-     * returns a sample serialization of a given type, or false if no type by the given name
1906
-     *
1907
-     * @param string $type name of type
1908
-     * @return false|string
1909
-     * @access public
1910
-     */
1911
-    function serializeTypeDef($type)
1912
-    {
1913
-        $str = '';
1914
-        //print "in sTD() for type $type<br>";
1915
-        if ($typeDef = $this->getTypeDef($type)) {
1916
-            $str .= '<' . $type;
1917
-            if (is_array($typeDef['attrs'])) {
1918
-                foreach ($typeDef['attrs'] as $attName => $data) {
1919
-                    $str .= " $attName=\"{type = " . $data['type'] . "}\"";
1920
-                }
1921
-            }
1922
-            $str .= " xmlns=\"" . $this->schema['targetNamespace'] . "\"";
1923
-            if (count($typeDef['elements']) > 0) {
1924
-                $str .= ">";
1925
-                foreach ($typeDef['elements'] as $element => $eData) {
1926
-                    $str .= $this->serializeTypeDef($element);
1927
-                }
1928
-                $str .= "</$type>";
1929
-            } elseif ($typeDef['typeClass'] == 'element') {
1930
-                $str .= "></$type>";
1931
-            } else {
1932
-                $str .= "/>";
1933
-            }
1934
-            return $str;
1935
-        }
1936
-        return false;
1937
-    }
1938
-
1939
-    /**
1940
-     * returns HTML form elements that allow a user
1941
-     * to enter values for creating an instance of the given type.
1942
-     *
1943
-     * @param string $name name for type instance
1944
-     * @param string $type name of type
1945
-     * @return string
1946
-     * @access public
1947
-     * @deprecated
1948
-     */
1949
-    function typeToForm($name, $type)
1950
-    {
1951
-        $buffer = '';
1952
-        // get typedef
1953
-        if ($typeDef = $this->getTypeDef($type)) {
1954
-            // if struct
1955
-            if ($typeDef['phpType'] == 'struct') {
1956
-                $buffer .= '<table>';
1957
-                foreach ($typeDef['elements'] as $childDef) {
1958
-                    $buffer .= "
1959
-					<tr><td align='right'>$childDef[name] (type: " . $this->getLocalPart($childDef['type']) . "):</td>
1960
-					<td><input type='text' name='parameters[" . $name . "][$childDef[name]]'></td></tr>";
1961
-                }
1962
-                $buffer .= '</table>';
1963
-                // if array
1964
-            } elseif ($typeDef['phpType'] == 'array') {
1965
-                $buffer .= '<table>';
1966
-              $buffer .= str_repeat ("
1967
-					<tr><td align='right'>array item (type: $typeDef[arrayType]):</td>
1968
-					<td><input type='text' name='parameters[" . $name . "][]'></td></tr>", 3);
1969
-                $buffer .= '</table>';
1970
-                // if scalar
1971
-            } else {
1972
-                $buffer .= "<input type='text' name='parameters[$name]'>";
1973
-            }
1974
-        } else {
1975
-            $buffer .= "<input type='text' name='parameters[$name]'>";
1976
-        }
1977
-        return $buffer;
1978
-    }
1979
-
1980
-    /**
1981
-     * adds a complex type to the schema
1982
-     * example: array
1983
-     * addType(
1984
-     *    'ArrayOfstring',
1985
-     *    'complexType',
1986
-     *    'array',
1987
-     *    '',
1988
-     *    'SOAP-ENC:Array',
1989
-     *    array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'string[]'),
1990
-     *    'xsd:string'
1991
-     * );
1992
-     * example: PHP associative array ( SOAP Struct )
1993
-     * addType(
1994
-     *    'SOAPStruct',
1995
-     *    'complexType',
1996
-     *    'struct',
1997
-     *    'all',
1998
-     *    array('myVar'=> array('name'=>'myVar','type'=>'string')
1999
-     * );
2000
-     *
2001
-     * @param string $name
2002
-     * @param string $typeClass (complexType|simpleType|attribute)
2003
-     * @param string $phpType : currently supported are array and struct (php assoc array)
2004
-     * @param string $compositor (all|sequence|choice)
2005
-     * @param string $restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
2006
-     * @param array $elements = array ( name = array(name=>'',type=>'') )
2007
-     * @param array $attrs = array(
2008
-     *    array(
2009
-     *        'ref' => "http://schemas.xmlsoap.org/soap/encoding/:arrayType",
2010
-     *        "http://schemas.xmlsoap.org/wsdl/:arrayType" => "string[]"
2011
-     *    )
2012
-     * )
2013
-     * @param array $arrayType : namespace:name (http://www.w3.org/2001/XMLSchema:string)
2014
-     *
2015
-     * @access public
2016
-     * @see getTypeDef
2017
-     */
2018
-    function addComplexType($name, $typeClass = 'complexType', $phpType = 'array', $compositor = '', $restrictionBase = '', $elements = array(), $attrs = array(), $arrayType = '')
2019
-    {
2020
-        $this->complexTypes[$name] = array(
2021
-            'name' => $name,
2022
-            'typeClass' => $typeClass,
2023
-            'phpType' => $phpType,
2024
-            'compositor' => $compositor,
2025
-            'restrictionBase' => $restrictionBase,
2026
-            'elements' => $elements,
2027
-            'attrs' => $attrs,
2028
-            'arrayType' => $arrayType
2029
-        );
2030
-
2031
-        $this->xdebug("addComplexType $name:");
2032
-        $this->appendDebug($this->varDump($this->complexTypes[$name]));
2033
-    }
2034
-
2035
-    /**
2036
-     * adds a simple type to the schema
2037
-     *
2038
-     * @param string $name
2039
-     * @param string $restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
2040
-     * @param string $typeClass (should always be simpleType)
2041
-     * @param string $phpType (should always be scalar)
2042
-     * @param array $enumeration array of values
2043
-     * @access public
2044
-     * @see nusoap_xmlschema
2045
-     * @see getTypeDef
2046
-     */
2047
-    function addSimpleType($name, $restrictionBase = '', $typeClass = 'simpleType', $phpType = 'scalar', $enumeration = array())
2048
-    {
2049
-        $this->simpleTypes[$name] = array(
2050
-            'name' => $name,
2051
-            'typeClass' => $typeClass,
2052
-            'phpType' => $phpType,
2053
-            'type' => $restrictionBase,
2054
-            'enumeration' => $enumeration
2055
-        );
2056
-
2057
-        $this->xdebug("addSimpleType $name:");
2058
-        $this->appendDebug($this->varDump($this->simpleTypes[$name]));
2059
-    }
2060
-
2061
-    /**
2062
-     * adds an element to the schema
2063
-     *
2064
-     * @param array $attrs attributes that must include name and type
2065
-     * @see nusoap_xmlschema
2066
-     * @access public
2067
-     */
2068
-    function addElement($attrs)
2069
-    {
2070
-        if (!$this->getPrefix($attrs['type'])) {
2071
-            $attrs['type'] = $this->schemaTargetNamespace . ':' . $attrs['type'];
2072
-        }
2073
-        $this->elements[$attrs['name']] = $attrs;
2074
-        $this->elements[$attrs['name']]['typeClass'] = 'element';
2075
-
2076
-        $this->xdebug("addElement " . $attrs['name']);
2077
-        $this->appendDebug($this->varDump($this->elements[$attrs['name']]));
2078
-    }
2079
-}
1137
+	// files
1138
+	var $schema = '';
1139
+	var $xml = '';
1140
+	// namespaces
1141
+	var $enclosingNamespaces;
1142
+	// schema info
1143
+	var $schemaInfo = array();
1144
+	var $schemaTargetNamespace = '';
1145
+	// types, elements, attributes defined by the schema
1146
+	var $attributes = array();
1147
+	var $complexTypes = array();
1148
+	var $complexTypeStack = array();
1149
+	var $currentComplexType = null;
1150
+	var $elements = array();
1151
+	var $elementStack = array();
1152
+	var $currentElement = null;
1153
+	var $simpleTypes = array();
1154
+	var $simpleTypeStack = array();
1155
+	var $currentSimpleType = null;
1156
+	// imports
1157
+	var $imports = array();
1158
+	// parser vars
1159
+	var $parser;
1160
+	var $position = 0;
1161
+	var $depth = 0;
1162
+	var $depth_array = array();
1163
+	var $message = array();
1164
+	var $defaultNamespace = array();
1165
+
1166
+	/**
1167
+	 * constructor
1168
+	 *
1169
+	 * @param    string $schema schema document URI
1170
+	 * @param    string $xml xml document URI
1171
+	 * @param    string $namespaces namespaces defined in enclosing XML
1172
+	 * @access   public
1173
+	 */
1174
+	function __construct($schema = '', $xml = '', $namespaces = array())
1175
+	{
1176
+		parent::__construct();
1177
+		$this->debug('nusoap_xmlschema class instantiated, inside constructor');
1178
+		// files
1179
+		$this->schema = $schema;
1180
+		$this->xml = $xml;
1181
+
1182
+		// namespaces
1183
+		$this->enclosingNamespaces = $namespaces;
1184
+		$this->namespaces = array_merge($this->namespaces, $namespaces);
1185
+
1186
+		// parse schema file
1187
+		if ($schema != '') {
1188
+			$this->debug('initial schema file: ' . $schema);
1189
+			$this->parseFile($schema, 'schema');
1190
+		}
2080 1191
 
2081
-/**
2082
- * Backward compatibility
2083
- */
2084
-class XMLSchema extends nusoap_xmlschema
2085
-{
2086
-}
1192
+		// parse xml file
1193
+		if ($xml != '') {
1194
+			$this->debug('initial xml file: ' . $xml);
1195
+			$this->parseFile($xml, 'xml');
1196
+		}
2087 1197
 
1198
+	}
2088 1199
 
2089
-/**
2090
- * For creating serializable abstractions of native PHP types.  This class
2091
- * allows element name/namespace, XSD type, and XML attributes to be
2092
- * associated with a value.  This is extremely useful when WSDL is not
2093
- * used, but is also useful when WSDL is used with polymorphic types, including
2094
- * xsd:anyType and user-defined types.
2095
- *
2096
- * @author   Dietrich Ayala <[email protected]>
2097
- * @version  $Id: nusoap.php,v 1.123 2010/04/26 20:15:08 snichol Exp $
2098
- * @access   public
2099
- */
2100
-class soapval extends nusoap_base
2101
-{
2102
-    /**
2103
-     * The XML element name
2104
-     *
2105
-     * @var string
2106
-     * @access private
2107
-     */
2108
-    var $name;
2109
-    /**
2110
-     * The XML type name (string or false)
2111
-     *
2112
-     * @var mixed
2113
-     * @access private
2114
-     */
2115
-    var $type;
2116
-    /**
2117
-     * The PHP value
2118
-     *
2119
-     * @var mixed
2120
-     * @access private
2121
-     */
2122
-    var $value;
2123
-    /**
2124
-     * The XML element namespace (string or false)
2125
-     *
2126
-     * @var mixed
2127
-     * @access private
2128
-     */
2129
-    var $element_ns;
2130
-    /**
2131
-     * The XML type namespace (string or false)
2132
-     *
2133
-     * @var mixed
2134
-     * @access private
2135
-     */
2136
-    var $type_ns;
2137
-    /**
2138
-     * The XML element attributes (array or false)
2139
-     *
2140
-     * @var mixed
2141
-     * @access private
2142
-     */
2143
-    var $attributes;
2144
-
2145
-    /** @var false|resource */
2146
-    var $fp;
2147
-
2148
-    /**
2149
-     * constructor
2150
-     *
2151
-     * @param    string $name optional name
2152
-     * @param    mixed $type optional type name
2153
-     * @param    mixed $value optional value
2154
-     * @param    mixed $element_ns optional namespace of value
2155
-     * @param    mixed $type_ns optional namespace of type
2156
-     * @param    mixed $attributes associative array of attributes to add to element serialization
2157
-     * @access   public
2158
-     */
2159
-    function __construct($name = 'soapval', $type = false, $value = -1, $element_ns = false, $type_ns = false, $attributes = false)
2160
-    {
2161
-        parent::__construct();
2162
-        $this->name = $name;
2163
-        $this->type = $type;
2164
-        $this->value = $value;
2165
-        $this->element_ns = $element_ns;
2166
-        $this->type_ns = $type_ns;
2167
-        $this->attributes = $attributes;
2168
-    }
2169
-
2170
-    /**
2171
-     * return serialized value
2172
-     *
2173
-     * @param    string $use The WSDL use value (encoded|literal)
2174
-     * @return    string XML data
2175
-     * @access   public
2176
-     */
2177
-    function serialize($use = 'encoded')
2178
-    {
2179
-        return $this->serialize_val($this->value, $this->name, $this->type, $this->element_ns, $this->type_ns, $this->attributes, $use, true);
2180
-    }
2181
-
2182
-    /**
2183
-     * decodes a soapval object into a PHP native type
2184
-     *
2185
-     * @return    mixed
2186
-     * @access   public
2187
-     */
2188
-    function decode()
2189
-    {
2190
-        return $this->value;
2191
-    }
2192
-}
1200
+	/**
1201
+	 * parse an XML file
1202
+	 *
1203
+	 * @param string $xml path/URL to XML file
1204
+	 * @param string $type (schema | xml)
1205
+	 * @return boolean
1206
+	 * @access public
1207
+	 */
1208
+	function parseFile($xml, $type)
1209
+	{
1210
+		// parse xml file
1211
+		if ($xml != "") {
1212
+			$xmlStr = @join("", @file($xml));
1213
+			if ($xmlStr == "") {
1214
+				$msg = 'Error reading XML from ' . $xml;
1215
+				$this->setError($msg);
1216
+				$this->debug($msg);
1217
+				return false;
1218
+			} else {
1219
+				$this->debug("parsing $xml");
1220
+				$this->parseString($xmlStr, $type);
1221
+				$this->debug("done parsing $xml");
1222
+				return true;
1223
+			}
1224
+		}
1225
+		return false;
1226
+	}
2193 1227
 
1228
+	/**
1229
+	 * parse an XML string
1230
+	 *
1231
+	 * @param    string $xml path or URL
1232
+	 * @param    string $type (schema|xml)
1233
+	 * @access   private
1234
+	 */
1235
+	function parseString($xml, $type)
1236
+	{
1237
+		// parse xml string
1238
+		if ($xml != "") {
1239
+
1240
+			// Create an XML parser.
1241
+			$this->parser = xml_parser_create();
1242
+			// Set the options for parsing the XML data.
1243
+			xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
1244
+
1245
+			// Set the object for the parser.
1246
+			xml_set_object($this->parser, $this);
1247
+
1248
+			// Set the element handlers for the parser.
1249
+			if ($type == "schema") {
1250
+				xml_set_element_handler($this->parser, 'schemaStartElement', 'schemaEndElement');
1251
+				xml_set_character_data_handler($this->parser, 'schemaCharacterData');
1252
+			} elseif ($type == "xml") {
1253
+				xml_set_element_handler($this->parser, 'xmlStartElement', 'xmlEndElement');
1254
+				xml_set_character_data_handler($this->parser, 'xmlCharacterData');
1255
+			}
2194 1256
 
2195
-/**
2196
- * transport class for sending/receiving data via HTTP and HTTPS
2197
- * NOTE: PHP must be compiled with the CURL extension for HTTPS support
2198
- *
2199
- * @author   Dietrich Ayala <[email protected]>
2200
- * @author   Scott Nichol <[email protected]>
2201
- * @version  $Id: nusoap.php,v 1.123 2010/04/26 20:15:08 snichol Exp $
2202
- * @access public
2203
- */
2204
-class soap_transport_http extends nusoap_base
2205
-{
1257
+			libxml_disable_entity_loader(true);	// Avoid load of external entities (security problem). Required only for libxml < 2.
1258
+
1259
+			// Parse the XML file.
1260
+			if (!xml_parse($this->parser, $xml, true)) {
1261
+				// Display an error message.
1262
+				$errstr = sprintf('XML error parsing XML schema on line %d: %s',
1263
+					xml_get_current_line_number($this->parser),
1264
+					xml_error_string(xml_get_error_code($this->parser))
1265
+				);
1266
+				$this->debug($errstr);
1267
+				$this->debug("XML payload:\n" . $xml);
1268
+				$this->setError($errstr);
1269
+			}
2206 1270
 
2207
-    var $query = '';
2208
-    var $tryagain = false;
2209
-    var $url = '';
2210
-    var $uri = '';
2211
-    var $digest_uri = '';
2212
-    var $scheme = '';
2213
-    var $host = '';
2214
-    var $port = '';
2215
-    var $path = '';
2216
-    var $request_method = 'POST';
2217
-    var $protocol_version = '1.0';
2218
-    var $encoding = '';
2219
-    var $outgoing_headers = array();
2220
-    var $incoming_headers = array();
2221
-    var $incoming_cookies = array();
2222
-    var $outgoing_payload = '';
2223
-    var $incoming_payload = '';
2224
-    var $response_status_line;    // HTTP response status line
2225
-    var $useSOAPAction = true;
2226
-    var $persistentConnection = false;
2227
-    var $ch = false;    // cURL handle
2228
-    var $ch_options = array();    // cURL custom options
2229
-    var $use_curl = false;        // force cURL use
2230
-    var $proxy = null;            // proxy information (associative array)
2231
-    var $username = '';
2232
-    var $password = '';
2233
-    var $authtype = '';
2234
-    var $digestRequest = array();
2235
-    var $certRequest = array();    // keys must be cainfofile (optional), sslcertfile, sslkeyfile, passphrase, certpassword (optional), verifypeer (optional), verifyhost (optional)
2236
-    // cainfofile: certificate authority file, e.g. '$pathToPemFiles/rootca.pem'
2237
-    // sslcertfile: SSL certificate file, e.g. '$pathToPemFiles/mycert.pem'
2238
-    // sslkeyfile: SSL key file, e.g. '$pathToPemFiles/mykey.pem'
2239
-    // passphrase: SSL key password/passphrase
2240
-    // certpassword: SSL certificate password
2241
-    // verifypeer: default is 1
2242
-    // verifyhost: default is 1
2243
-
2244
-    /** @var false|resource */
2245
-    var $fp;
2246
-    var $errno;
2247
-
2248
-    /**
2249
-     * constructor
2250
-     *
2251
-     * @param string $url The URL to which to connect
2252
-     * @param array $curl_options User-specified cURL options
2253
-     * @param boolean $use_curl Whether to try to force cURL use
2254
-     * @access public
2255
-     */
2256
-    function __construct($url, $curl_options = null, $use_curl = false)
2257
-    {
2258
-        parent::__construct();
2259
-        $this->debug("ctor url=$url use_curl=$use_curl curl_options:");
2260
-        $this->appendDebug($this->varDump($curl_options));
2261
-        $this->setURL($url);
2262
-        if (is_array($curl_options)) {
2263
-            $this->ch_options = $curl_options;
2264
-        }
2265
-        $this->use_curl = $use_curl;
2266
-        preg_match('/\$Revisio' . 'n: ([^ ]+)/', $this->revision, $rev);
2267
-        $this->setHeader('User-Agent', $this->title . '/' . $this->version . ' (' . $rev[1] . ')');
2268
-    }
2269
-
2270
-    /**
2271
-     * sets a cURL option
2272
-     *
2273
-     * @param    mixed $option The cURL option (always integer?)
2274
-     * @param    mixed $value The cURL option value
2275
-     * @access   private
2276
-     */
2277
-    function setCurlOption($option, $value)
2278
-    {
2279
-        $this->debug("setCurlOption option=$option, value=");
2280
-        $this->appendDebug($this->varDump($value));
2281
-        curl_setopt($this->ch, $option, $value);
2282
-    }
2283
-
2284
-    /**
2285
-     * sets an HTTP header
2286
-     *
2287
-     * @param string $name The name of the header
2288
-     * @param string $value The value of the header
2289
-     * @access private
2290
-     */
2291
-    function setHeader($name, $value)
2292
-    {
2293
-        $this->outgoing_headers[$name] = $value;
2294
-        $this->debug("set header $name: $value");
2295
-    }
2296
-
2297
-    /**
2298
-     * unsets an HTTP header
2299
-     *
2300
-     * @param string $name The name of the header
2301
-     * @access private
2302
-     */
2303
-    function unsetHeader($name)
2304
-    {
2305
-        if (isset($this->outgoing_headers[$name])) {
2306
-            $this->debug("unset header $name");
2307
-            unset($this->outgoing_headers[$name]);
2308
-        }
2309
-    }
2310
-
2311
-    /**
2312
-     * sets the URL to which to connect
2313
-     *
2314
-     * @param string $url The URL to which to connect
2315
-     * @access private
2316
-     */
2317
-    function setURL($url)
2318
-    {
2319
-        $this->url = $url;
2320
-
2321
-        $u = parse_url($url);
2322
-        foreach ($u as $k => $v) {
2323
-            $this->debug("parsed URL $k = $v");
2324
-            $this->$k = $v;
2325
-        }
2326
-
2327
-        // add any GET params to path
2328
-        if (isset($u['query']) && $u['query'] != '') {
2329
-            $this->path .= '?' . $u['query'];
2330
-        }
2331
-
2332
-        // set default port
2333
-        if (!isset($u['port'])) {
2334
-            if ($u['scheme'] == 'https') {
2335
-                $this->port = 443;
2336
-            } else {
2337
-                $this->port = 80;
2338
-            }
2339
-        }
2340
-
2341
-        $this->uri = $this->path;
2342
-        $this->digest_uri = $this->uri;
2343
-
2344
-        // build headers
2345
-        if (!isset($u['port'])) {
2346
-            $this->setHeader('Host', $this->host);
2347
-        } else {
2348
-            $this->setHeader('Host', $this->host . ':' . $this->port);
2349
-        }
2350
-
2351
-        if (isset($u['user']) && $u['user'] != '') {
2352
-            $this->setCredentials(urldecode($u['user']), isset($u['pass']) ? urldecode($u['pass']) : '');
2353
-        }
2354
-    }
2355
-
2356
-    /**
2357
-     * gets the I/O method to use
2358
-     *
2359
-     * @return    string    I/O method to use (socket|curl|unknown)
2360
-     * @access    private
2361
-     */
2362
-    function io_method()
2363
-    {
2364
-        if ($this->use_curl || ($this->scheme == 'https') || ($this->scheme == 'http' && $this->authtype == 'ntlm') || ($this->scheme == 'http' && is_array($this->proxy) && $this->proxy['authtype'] == 'ntlm')) {
2365
-            return 'curl';
2366
-        }
2367
-        if (($this->scheme == 'http' || $this->scheme == 'ssl') && $this->authtype != 'ntlm' && (!is_array($this->proxy) || $this->proxy['authtype'] != 'ntlm')) {
2368
-            return 'socket';
2369
-        }
2370
-        return 'unknown';
2371
-    }
2372
-
2373
-    /**
2374
-     * establish an HTTP connection
2375
-     *
2376
-     * @param    integer $connection_timeout set connection timeout in seconds
2377
-     * @param    integer $response_timeout set response timeout in seconds
2378
-     * @return    boolean true if connected, false if not
2379
-     * @access   private
2380
-     */
2381
-    function connect($connection_timeout = 0, $response_timeout = 30)
2382
-    {
2383
-        // For PHP 4.3 with OpenSSL, change https scheme to ssl, then treat like
2384
-        // "regular" socket.
2385
-        // TODO: disabled for now because OpenSSL must be *compiled* in (not just
2386
-        //       loaded), and until PHP5 stream_get_wrappers is not available.
2387
-//	  	if ($this->scheme == 'https') {
2388
-//		  	if (version_compare(phpversion(), '4.3.0') >= 0) {
2389
-//		  		if (extension_loaded('openssl')) {
2390
-//		  			$this->scheme = 'ssl';
2391
-//		  			$this->debug('Using SSL over OpenSSL');
2392
-//		  		}
2393
-//		  	}
2394
-//		}
2395
-        $this->debug("connect connection_timeout $connection_timeout, response_timeout $response_timeout, scheme $this->scheme, host $this->host, port $this->port");
2396
-        if ($this->io_method() == 'socket') {
2397
-            if (!is_array($this->proxy)) {
2398
-                $host = $this->host;
2399
-            } else {
2400
-                $host = $this->proxy['host'];
2401
-            }
2402
-
2403
-            // use persistent connection
2404
-            if ($this->persistentConnection && isset($this->fp) && is_resource($this->fp)) {
2405
-                if (!feof($this->fp)) {
2406
-                    $this->debug('Re-use persistent connection');
2407
-                    return true;
2408
-                }
2409
-                fclose($this->fp);
2410
-                $this->debug('Closed persistent connection at EOF');
2411
-            }
2412
-
2413
-            // munge host if using OpenSSL
2414
-            if ($this->scheme == 'ssl') {
2415
-                $host = 'ssl://' . $host;
2416
-            }
2417
-            $this->debug('calling fsockopen with host ' . $host . ' connection_timeout ' . $connection_timeout);
2418
-
2419
-            // open socket
2420
-            if ($connection_timeout > 0) {
2421
-                $this->fp = @fsockopen($host, $this->port, $this->errno, $this->error_str, $connection_timeout);
2422
-            } else {
2423
-                $this->fp = @fsockopen($host, $this->port, $this->errno, $this->error_str);
2424
-            }
2425
-
2426
-            // test pointer
2427
-            if (!$this->fp) {
2428
-                $msg = 'Couldn\'t open socket connection to server ' . $this->url;
2429
-                if ($this->errno) {
2430
-                    $msg .= ', Error (' . $this->errno . '): ' . $this->error_str;
2431
-                } else {
2432
-                    $msg .= ' prior to connect().  This is often a problem looking up the host name.';
2433
-                }
2434
-                $this->debug($msg);
2435
-                $this->setError($msg);
2436
-                return false;
2437
-            }
2438
-
2439
-            // set response timeout
2440
-            $this->debug('set response timeout to ' . $response_timeout);
2441
-            socket_set_timeout($this->fp, $response_timeout, 0);
2442
-
2443
-            $this->debug('socket connected');
2444
-            return true;
2445
-        } elseif ($this->io_method() == 'curl') {
2446
-            if (!extension_loaded('curl')) {
2447
-//			$this->setError('cURL Extension, or OpenSSL extension w/ PHP version >= 4.3 is required for HTTPS');
2448
-                $this->setError('The PHP cURL Extension is required for HTTPS or NLTM.  You will need to re-build or update your PHP to include cURL or change php.ini to load the PHP cURL extension.');
2449
-                return false;
2450
-            }
2451
-            // Avoid warnings when PHP does not have these options
2452
-            if (defined('CURLOPT_CONNECTIONTIMEOUT')) {
2453
-                $CURLOPT_CONNECTIONTIMEOUT = CURLOPT_CONNECTIONTIMEOUT;
2454
-            } else {
2455
-                $CURLOPT_CONNECTIONTIMEOUT = 78;
2456
-            }
2457
-            if (defined('CURLOPT_HTTPAUTH')) {
2458
-                $CURLOPT_HTTPAUTH = CURLOPT_HTTPAUTH;
2459
-            } else {
2460
-                $CURLOPT_HTTPAUTH = 107;
2461
-            }
2462
-            if (defined('CURLOPT_PROXYAUTH')) {
2463
-                $CURLOPT_PROXYAUTH = CURLOPT_PROXYAUTH;
2464
-            } else {
2465
-                $CURLOPT_PROXYAUTH = 111;
2466
-            }
2467
-            if (defined('CURLAUTH_BASIC')) {
2468
-                $CURLAUTH_BASIC = CURLAUTH_BASIC;
2469
-            } else {
2470
-                $CURLAUTH_BASIC = 1;
2471
-            }
2472
-            if (defined('CURLAUTH_DIGEST')) {
2473
-                $CURLAUTH_DIGEST = CURLAUTH_DIGEST;
2474
-            } else {
2475
-                $CURLAUTH_DIGEST = 2;
2476
-            }
2477
-            if (defined('CURLAUTH_NTLM')) {
2478
-                $CURLAUTH_NTLM = CURLAUTH_NTLM;
2479
-            } else {
2480
-                $CURLAUTH_NTLM = 8;
2481
-            }
2482
-
2483
-            $this->debug('connect using cURL');
2484
-            // init CURL
2485
-            $this->ch = curl_init();
2486
-            // set url
2487
-            $hostURL = ($this->port != '') ? "$this->scheme://$this->host:$this->port" : "$this->scheme://$this->host";
2488
-            // add path
2489
-            $hostURL .= $this->path;
2490
-            $this->setCurlOption(CURLOPT_URL, $hostURL);
2491
-            // follow location headers (re-directs)
2492
-            if (ini_get('safe_mode') || ini_get('open_basedir')) {
2493
-                $this->debug('safe_mode or open_basedir set, so do not set CURLOPT_FOLLOWLOCATION');
2494
-                $this->debug('safe_mode = ');
2495
-                $this->appendDebug($this->varDump(ini_get('safe_mode')));
2496
-                $this->debug('open_basedir = ');
2497
-                $this->appendDebug($this->varDump(ini_get('open_basedir')));
2498
-            } else {
2499
-                $this->setCurlOption(CURLOPT_FOLLOWLOCATION, 1);
2500
-            }
2501
-            // ask for headers in the response output
2502
-            $this->setCurlOption(CURLOPT_HEADER, 1);
2503
-            // ask for the response output as the return value
2504
-            $this->setCurlOption(CURLOPT_RETURNTRANSFER, 1);
2505
-            // encode
2506
-            // We manage this ourselves through headers and encoding
2507
-//		if(function_exists('gzuncompress')){
2508
-//			$this->setCurlOption(CURLOPT_ENCODING, 'deflate');
2509
-//		}
2510
-            // persistent connection
2511
-            if ($this->persistentConnection) {
2512
-                // I believe the following comment is now bogus, having applied to
2513
-                // the code when it used CURLOPT_CUSTOMREQUEST to send the request.
2514
-                // The way we send data, we cannot use persistent connections, since
2515
-                // there will be some "junk" at the end of our request.
2516
-                //$this->setCurlOption(CURL_HTTP_VERSION_1_1, true);
2517
-                $this->persistentConnection = false;
2518
-                $this->setHeader('Connection', 'close');
2519
-            }
2520
-            // set timeouts
2521
-            if ($connection_timeout != 0) {
2522
-                $this->setCurlOption($CURLOPT_CONNECTIONTIMEOUT, $connection_timeout);
2523
-            }
2524
-            if ($response_timeout != 0) {
2525
-                $this->setCurlOption(CURLOPT_TIMEOUT, $response_timeout);
2526
-            }
2527
-
2528
-            if ($this->scheme == 'https') {
2529
-                $this->debug('set cURL SSL verify options');
2530
-                // recent versions of cURL turn on peer/host checking by default,
2531
-                // while PHP binaries are not compiled with a default location for the
2532
-                // CA cert bundle, so disable peer/host checking.
2533
-                //$this->setCurlOption(CURLOPT_CAINFO, 'f:\php-4.3.2-win32\extensions\curl-ca-bundle.crt');
2534
-                $this->setCurlOption(CURLOPT_SSL_VERIFYPEER, 0);
2535
-                $this->setCurlOption(CURLOPT_SSL_VERIFYHOST, 0);
2536
-
2537
-                // support client certificates (thanks Tobias Boes, Doug Anarino, Eryan Ariobowo)
2538
-                if ($this->authtype == 'certificate') {
2539
-                    $this->debug('set cURL certificate options');
2540
-                    if (isset($this->certRequest['cainfofile'])) {
2541
-                        $this->setCurlOption(CURLOPT_CAINFO, $this->certRequest['cainfofile']);
2542
-                    }
2543
-                    if (isset($this->certRequest['verifypeer'])) {
2544
-                        $this->setCurlOption(CURLOPT_SSL_VERIFYPEER, $this->certRequest['verifypeer']);
2545
-                    } else {
2546
-                        $this->setCurlOption(CURLOPT_SSL_VERIFYPEER, 1);
2547
-                    }
2548
-                    if (isset($this->certRequest['verifyhost'])) {
2549
-                        $this->setCurlOption(CURLOPT_SSL_VERIFYHOST, $this->certRequest['verifyhost']);
2550
-                    } else {
2551
-                        $this->setCurlOption(CURLOPT_SSL_VERIFYHOST, 1);
2552
-                    }
2553
-                    if (isset($this->certRequest['sslcertfile'])) {
2554
-                        $this->setCurlOption(CURLOPT_SSLCERT, $this->certRequest['sslcertfile']);
2555
-                    }
2556
-                    if (isset($this->certRequest['sslkeyfile'])) {
2557
-                        $this->setCurlOption(CURLOPT_SSLKEY, $this->certRequest['sslkeyfile']);
2558
-                    }
2559
-                    if (isset($this->certRequest['passphrase'])) {
2560
-                        $this->setCurlOption(CURLOPT_SSLKEYPASSWD, $this->certRequest['passphrase']);
2561
-                    }
2562
-                    if (isset($this->certRequest['certpassword'])) {
2563
-                        $this->setCurlOption(CURLOPT_SSLCERTPASSWD, $this->certRequest['certpassword']);
2564
-                    }
2565
-                }
2566
-            }
2567
-            if ($this->authtype && ($this->authtype != 'certificate')) {
2568
-                if ($this->username) {
2569
-                    $this->debug('set cURL username/password');
2570
-                    $this->setCurlOption(CURLOPT_USERPWD, "$this->username:$this->password");
2571
-                }
2572
-                if ($this->authtype == 'basic') {
2573
-                    $this->debug('set cURL for Basic authentication');
2574
-                    $this->setCurlOption($CURLOPT_HTTPAUTH, $CURLAUTH_BASIC);
2575
-                }
2576
-                if ($this->authtype == 'digest') {
2577
-                    $this->debug('set cURL for digest authentication');
2578
-                    $this->setCurlOption($CURLOPT_HTTPAUTH, $CURLAUTH_DIGEST);
2579
-                }
2580
-                if ($this->authtype == 'ntlm') {
2581
-                    $this->debug('set cURL for NTLM authentication');
2582
-                    $this->setCurlOption($CURLOPT_HTTPAUTH, $CURLAUTH_NTLM);
2583
-                }
2584
-            }
2585
-            if (is_array($this->proxy)) {
2586
-                $this->debug('set cURL proxy options');
2587
-                if ($this->proxy['port'] != '') {
2588
-                    $this->setCurlOption(CURLOPT_PROXY, $this->proxy['host'] . ':' . $this->proxy['port']);
2589
-                } else {
2590
-                    $this->setCurlOption(CURLOPT_PROXY, $this->proxy['host']);
2591
-                }
2592
-                if ($this->proxy['username'] || $this->proxy['password']) {
2593
-                    $this->debug('set cURL proxy authentication options');
2594
-                    $this->setCurlOption(CURLOPT_PROXYUSERPWD, $this->proxy['username'] . ':' . $this->proxy['password']);
2595
-                    if ($this->proxy['authtype'] == 'basic') {
2596
-                        $this->setCurlOption($CURLOPT_PROXYAUTH, $CURLAUTH_BASIC);
2597
-                    }
2598
-                    if ($this->proxy['authtype'] == 'ntlm') {
2599
-                        $this->setCurlOption($CURLOPT_PROXYAUTH, $CURLAUTH_NTLM);
2600
-                    }
2601
-                }
2602
-            }
2603
-            $this->debug('cURL connection set up');
2604
-            return true;
2605
-        } else {
2606
-            $this->setError('Unknown scheme ' . $this->scheme);
2607
-            $this->debug('Unknown scheme ' . $this->scheme);
2608
-            return false;
2609
-        }
2610
-    }
2611
-
2612
-    /**
2613
-     * sends the SOAP request and gets the SOAP response via HTTP[S]
2614
-     *
2615
-     * @param    string $data message data
2616
-     * @param    integer $timeout set connection timeout in seconds
2617
-     * @param    integer $response_timeout set response timeout in seconds
2618
-     * @param    array $cookies cookies to send
2619
-     * @return    string data
2620
-     * @access   public
2621
-     */
2622
-    function send($data, $timeout = 0, $response_timeout = 30, $cookies = null)
2623
-    {
2624
-        $this->debug('entered send() with data of length: ' . strlen($data));
2625
-
2626
-        $respdata = "";
2627
-        $this->tryagain = true;
2628
-        $tries = 0;
2629
-        while ($this->tryagain) {
2630
-            $this->tryagain = false;
2631
-            if ($tries++ < 2) {
2632
-                // make connnection
2633
-                if (!$this->connect($timeout, $response_timeout)) {
2634
-                    return false;
2635
-                }
2636
-
2637
-                // send request
2638
-                if (!$this->sendRequest($data, $cookies)) {
2639
-                    return false;
2640
-                }
2641
-
2642
-                // get response
2643
-                $respdata = $this->getResponse();
2644
-            } else {
2645
-                $this->setError("Too many tries to get an OK response ($this->response_status_line)");
2646
-            }
2647
-        }
2648
-        $this->debug('end of send()');
2649
-        return $respdata;
2650
-    }
2651
-
2652
-
2653
-    /**
2654
-     * sends the SOAP request and gets the SOAP response via HTTPS using CURL
2655
-     *
2656
-     * @param    string $data message data
2657
-     * @param    integer $timeout set connection timeout in seconds
2658
-     * @param    integer $response_timeout set response timeout in seconds
2659
-     * @param    array $cookies cookies to send
2660
-     * @return    string data
2661
-     * @access   public
2662
-     */
2663
-    function sendHTTPS($data, $timeout = 0, $response_timeout = 30, $cookies = NULL)
2664
-    {
2665
-        return $this->send($data, $timeout, $response_timeout, $cookies);
2666
-    }
2667
-
2668
-    /**
2669
-     * if authenticating, set user credentials here
2670
-     *
2671
-     * @param    string $username
2672
-     * @param    string $password
2673
-     * @param    string $authtype (basic|digest|certificate|ntlm)
2674
-     * @param    array $digestRequest (keys must be nonce, nc, realm, qop)
2675
-     * @param    array $certRequest (keys must be cainfofile (optional), sslcertfile, sslkeyfile, passphrase, certpassword (optional), verifypeer (optional), verifyhost (optional): see corresponding options in cURL docs)
2676
-     * @access   public
2677
-     */
2678
-    function setCredentials($username, $password, $authtype = 'basic', $digestRequest = array(), $certRequest = array())
2679
-    {
2680
-        $this->debug("setCredentials username=$username authtype=$authtype digestRequest=");
2681
-        $this->appendDebug($this->varDump($digestRequest));
2682
-        $this->debug("certRequest=");
2683
-        $this->appendDebug($this->varDump($certRequest));
2684
-        // cf. RFC 2617
2685
-        if ($authtype == 'basic') {
2686
-            $this->setHeader('Authorization', 'Basic ' . base64_encode(str_replace(':', '', $username) . ':' . $password));
2687
-        } elseif ($authtype == 'digest') {
2688
-            if (isset($digestRequest['nonce'])) {
2689
-                $digestRequest['nc'] = isset($digestRequest['nc']) ? $digestRequest['nc']++ : 1;
2690
-
2691
-                // calculate the Digest hashes (calculate code based on digest implementation found at: http://www.rassoc.com/gregr/weblog/stories/2002/07/09/webServicesSecurityHttpDigestAuthenticationWithoutActiveDirectory.html)
2692
-
2693
-                // A1 = unq(username-value) ":" unq(realm-value) ":" passwd
2694
-                $A1 = $username . ':' . (isset($digestRequest['realm']) ? $digestRequest['realm'] : '') . ':' . $password;
2695
-
2696
-                // H(A1) = MD5(A1)
2697
-                $HA1 = md5($A1);
2698
-
2699
-                // A2 = Method ":" digest-uri-value
2700
-                $A2 = $this->request_method . ':' . $this->digest_uri;
2701
-
2702
-                // H(A2)
2703
-                $HA2 = md5($A2);
2704
-
2705
-                // KD(secret, data) = H(concat(secret, ":", data))
2706
-                // if qop == auth:
2707
-                // request-digest  = <"> < KD ( H(A1),     unq(nonce-value)
2708
-                //                              ":" nc-value
2709
-                //                              ":" unq(cnonce-value)
2710
-                //                              ":" unq(qop-value)
2711
-                //                              ":" H(A2)
2712
-                //                            ) <">
2713
-                // if qop is missing,
2714
-                // request-digest  = <"> < KD ( H(A1), unq(nonce-value) ":" H(A2) ) > <">
2715
-
2716
-                $nonce = $digestRequest['nonce'];
2717
-                $cnonce = $nonce;
2718
-                if ($digestRequest['qop'] != '') {
2719
-                    $unhashedDigest = $HA1 . ':' . $nonce . ':' . sprintf("%08d", $digestRequest['nc']) . ':' . $cnonce . ':' . $digestRequest['qop'] . ':' . $HA2;
2720
-                } else {
2721
-                    $unhashedDigest = $HA1 . ':' . $nonce . ':' . $HA2;
2722
-                }
2723
-
2724
-                $hashedDigest = md5($unhashedDigest);
2725
-
2726
-                $opaque = '';
2727
-                if (isset($digestRequest['opaque'])) {
2728
-                    $opaque = ', opaque="' . $digestRequest['opaque'] . '"';
2729
-                }
2730
-
2731
-                $this->setHeader('Authorization', 'Digest username="' . $username . '", realm="' . $digestRequest['realm'] . '", nonce="' . $nonce . '", uri="' . $this->digest_uri . $opaque . '", cnonce="' . $cnonce . '", nc=' . sprintf("%08x", $digestRequest['nc']) . ', qop="' . $digestRequest['qop'] . '", response="' . $hashedDigest . '"');
2732
-            }
2733
-        } elseif ($authtype == 'certificate') {
2734
-            $this->certRequest = $certRequest;
2735
-            $this->debug('Authorization header not set for certificate');
2736
-        } elseif ($authtype == 'ntlm') {
2737
-            // do nothing
2738
-            $this->debug('Authorization header not set for ntlm');
2739
-        }
2740
-        $this->username = $username;
2741
-        $this->password = $password;
2742
-        $this->authtype = $authtype;
2743
-        $this->digestRequest = $digestRequest;
2744
-    }
2745
-
2746
-    /**
2747
-     * set the soapaction value
2748
-     *
2749
-     * @param    string $soapaction
2750
-     * @access   public
2751
-     */
2752
-    function setSOAPAction($soapaction)
2753
-    {
2754
-        $this->setHeader('SOAPAction', '"' . $soapaction . '"');
2755
-    }
2756
-
2757
-    /**
2758
-     * use http encoding
2759
-     *
2760
-     * @param    string $enc encoding style. supported values: gzip, deflate, or both
2761
-     * @access   public
2762
-     */
2763
-    function setEncoding($enc = 'gzip, deflate')
2764
-    {
2765
-        if (function_exists('gzdeflate')) {
2766
-            $this->protocol_version = '1.1';
2767
-            $this->setHeader('Accept-Encoding', $enc);
2768
-            if (!isset($this->outgoing_headers['Connection'])) {
2769
-                $this->setHeader('Connection', 'close');
2770
-                $this->persistentConnection = false;
2771
-            }
2772
-            // deprecated as of PHP 5.3.0
2773
-            //set_magic_quotes_runtime(0);
2774
-            $this->encoding = $enc;
2775
-        }
2776
-    }
2777
-
2778
-    /**
2779
-     * set proxy info here
2780
-     *
2781
-     * @param    string $proxyhost use an empty string to remove proxy
2782
-     * @param    string $proxyport
2783
-     * @param    string $proxyusername
2784
-     * @param    string $proxypassword
2785
-     * @param    string $proxyauthtype (basic|ntlm)
2786
-     * @access   public
2787
-     */
2788
-    function setProxy($proxyhost, $proxyport, $proxyusername = '', $proxypassword = '', $proxyauthtype = 'basic')
2789
-    {
2790
-        if ($proxyhost) {
2791
-            $this->proxy = array(
2792
-                'host' => $proxyhost,
2793
-                'port' => $proxyport,
2794
-                'username' => $proxyusername,
2795
-                'password' => $proxypassword,
2796
-                'authtype' => $proxyauthtype
2797
-            );
2798
-            if ($proxyusername != '' && $proxypassword != '' && $proxyauthtype == 'basic') {
2799
-                $this->setHeader('Proxy-Authorization', ' Basic ' . base64_encode($proxyusername . ':' . $proxypassword));
2800
-            }
2801
-        } else {
2802
-            $this->debug('remove proxy');
2803
-            $this->unsetHeader('Proxy-Authorization');
2804
-        }
2805
-    }
2806
-
2807
-
2808
-    /**
2809
-     * Test if the given string starts with a header that is to be skipped.
2810
-     * Skippable headers result from chunked transfer and proxy requests.
2811
-     *
2812
-     * @param    string $data The string to check.
2813
-     * @returns    boolean    Whether a skippable header was found.
2814
-     * @access    private
2815
-     */
2816
-    function isSkippableCurlHeader($data)
2817
-    {
2818
-        $skipHeaders = array('HTTP/1.1 100',
2819
-            'HTTP/1.0 301',
2820
-            'HTTP/1.1 301',
2821
-            'HTTP/1.0 302',
2822
-            'HTTP/1.1 302',
2823
-            'HTTP/1.0 401',
2824
-            'HTTP/1.1 401',
2825
-            'HTTP/1.0 200 Connection established',
2826
-            'HTTP/1.1 200 Connection established');
2827
-        foreach ($skipHeaders as $hd) {
2828
-            $prefix = substr($data, 0, strlen($hd));
2829
-            if ($prefix == $hd) {
2830
-                return true;
2831
-            }
2832
-        }
2833
-
2834
-        return false;
2835
-    }
2836
-
2837
-    /**
2838
-     * decode a string that is encoded w/ "chunked' transfer encoding
2839
-     * as defined in RFC2068 19.4.6
2840
-     *
2841
-     * @param    string $buffer
2842
-     * @param    string $lb
2843
-     * @returns    string
2844
-     * @access   public
2845
-     * @deprecated
2846
-     */
2847
-    function decodeChunked($buffer, $lb)
2848
-    {
2849
-        $new = '';
2850
-
2851
-        // read chunk-size, chunk-extension (if any) and CRLF
2852
-        // get the position of the linebreak
2853
-        $chunkend = strpos($buffer, $lb);
2854
-        if (!$chunkend) {
2855
-            $this->debug('no linebreak found in decodeChunked');
2856
-            return $new;
2857
-        }
2858
-        $temp = substr($buffer, 0, $chunkend);
2859
-        $chunk_size = hexdec(trim($temp));
2860
-        $chunkstart = $chunkend + strlen($lb);
2861
-        // while (chunk-size > 0) {
2862
-        while ($chunk_size > 0) {
2863
-            $this->debug("chunkstart: $chunkstart chunk_size: $chunk_size");
2864
-            $chunkend = strpos($buffer, $lb, $chunkstart + $chunk_size);
2865
-
2866
-            // Just in case we got a broken connection
2867
-            if (!$chunkend) {
2868
-                $chunk = substr($buffer, $chunkstart);
2869
-                // append chunk-data to entity-body
2870
-                $new .= $chunk;
2871
-                break;
2872
-            }
2873
-
2874
-            // read chunk-data and CRLF
2875
-            $chunk = substr($buffer, $chunkstart, $chunkend - $chunkstart);
2876
-            // append chunk-data to entity-body
2877
-            $new .= $chunk;
2878
-            // length := length + chunk-size
2879
-            // read chunk-size and CRLF
2880
-            $chunkstart = $chunkend + strlen($lb);
2881
-
2882
-            $chunkend = strpos($buffer, $lb, $chunkstart) + strlen($lb);
2883
-            if (!$chunkend) {
2884
-                break; //Just in case we got a broken connection
2885
-            }
2886
-            $temp = substr($buffer, $chunkstart, $chunkend - $chunkstart);
2887
-            $chunk_size = hexdec(trim($temp));
2888
-            $chunkstart = $chunkend;
2889
-        }
2890
-        return $new;
2891
-    }
2892
-
2893
-    /**
2894
-     * Writes the payload, including HTTP headers, to $this->outgoing_payload.
2895
-     *
2896
-     * @param    string $data HTTP body
2897
-     * @param    string $cookie_str data for HTTP Cookie header
2898
-     * @return    void
2899
-     * @access    private
2900
-     */
2901
-    function buildPayload($data, $cookie_str = '')
2902
-    {
2903
-        // Note: for cURL connections, $this->outgoing_payload is ignored,
2904
-        // as is the Content-Length header, but these are still created as
2905
-        // debugging guides.
2906
-
2907
-        // add content-length header
2908
-        if ($this->request_method != 'GET') {
2909
-            $this->setHeader('Content-Length', strlen($data));
2910
-        }
2911
-
2912
-        // start building outgoing payload:
2913
-        if ($this->proxy) {
2914
-            $uri = $this->url;
2915
-        } else {
2916
-            $uri = $this->uri;
2917
-        }
2918
-        $req = "$this->request_method $uri HTTP/$this->protocol_version";
2919
-        $this->debug("HTTP request: $req");
2920
-        $this->outgoing_payload = "$req\r\n";
2921
-
2922
-        // loop thru headers, serializing
2923
-        foreach ($this->outgoing_headers as $k => $v) {
2924
-            $hdr = $k . ': ' . $v;
2925
-            $this->debug("HTTP header: $hdr");
2926
-            $this->outgoing_payload .= "$hdr\r\n";
2927
-        }
2928
-
2929
-        // add any cookies
2930
-        if ($cookie_str != '') {
2931
-            $hdr = 'Cookie: ' . $cookie_str;
2932
-            $this->debug("HTTP header: $hdr");
2933
-            $this->outgoing_payload .= "$hdr\r\n";
2934
-        }
2935
-
2936
-        // header/body separator
2937
-        $this->outgoing_payload .= "\r\n";
2938
-
2939
-        // add data
2940
-        $this->outgoing_payload .= $data;
2941
-    }
2942
-
2943
-    /**
2944
-     * sends the SOAP request via HTTP[S]
2945
-     *
2946
-     * @param    string $data message data
2947
-     * @param    array $cookies cookies to send
2948
-     * @return    boolean    true if OK, false if problem
2949
-     * @access   private
2950
-     */
2951
-    function sendRequest($data, $cookies = null)
2952
-    {
2953
-        // build cookie string
2954
-        $cookie_str = $this->getCookiesForRequest($cookies, (($this->scheme == 'ssl') || ($this->scheme == 'https')));
2955
-
2956
-        // build payload
2957
-        $this->buildPayload($data, $cookie_str);
2958
-
2959
-        if ($this->io_method() == 'socket') {
2960
-            // send payload
2961
-            if (!fputs($this->fp, $this->outgoing_payload, strlen($this->outgoing_payload))) {
2962
-                $this->setError('couldn\'t write message data to socket');
2963
-                $this->debug('couldn\'t write message data to socket');
2964
-                return false;
2965
-            }
2966
-            $this->debug('wrote data to socket, length = ' . strlen($this->outgoing_payload));
2967
-            return true;
2968
-        } elseif ($this->io_method() == 'curl') {
2969
-            // set payload
2970
-            // cURL does say this should only be the verb, and in fact it
2971
-            // turns out that the URI and HTTP version are appended to this, which
2972
-            // some servers refuse to work with (so we no longer use this method!)
2973
-            //$this->setCurlOption(CURLOPT_CUSTOMREQUEST, $this->outgoing_payload);
2974
-            $curl_headers = array();
2975
-            foreach ($this->outgoing_headers as $k => $v) {
2976
-                if ($k == 'Connection' || $k == 'Content-Length' || $k == 'Host' || $k == 'Authorization' || $k == 'Proxy-Authorization') {
2977
-                    $this->debug("Skip cURL header $k: $v");
2978
-                } else {
2979
-                    $curl_headers[] = "$k: $v";
2980
-                }
2981
-            }
2982
-            if ($cookie_str != '') {
2983
-                $curl_headers[] = 'Cookie: ' . $cookie_str;
2984
-            }
2985
-            $this->setCurlOption(CURLOPT_HTTPHEADER, $curl_headers);
2986
-            $this->debug('set cURL HTTP headers');
2987
-            if ($this->request_method == "POST") {
2988
-                $this->setCurlOption(CURLOPT_POST, 1);
2989
-                $this->setCurlOption(CURLOPT_POSTFIELDS, $data);
2990
-                $this->debug('set cURL POST data');
2991
-            }
2992
-            // insert custom user-set cURL options
2993
-            foreach ($this->ch_options as $key => $val) {
2994
-                $this->setCurlOption($key, $val);
2995
-            }
2996
-
2997
-            $this->debug('set cURL payload');
2998
-            return true;
2999
-        }
3000
-        return false;
3001
-    }
3002
-
3003
-    /**
3004
-     * gets the SOAP response via HTTP[S]
3005
-     *
3006
-     * @return    string the response (also sets member variables like incoming_payload)
3007
-     * @access   private
3008
-     */
3009
-    function getResponse()
3010
-    {
3011
-        $this->incoming_payload = '';
3012
-        $header_array = array ();
3013
-        $data = '';
3014
-
3015
-        if ($this->io_method() == 'socket') {
3016
-            // loop until headers have been retrieved
3017
-            $pos = 0;
3018
-            while (!isset($lb)) {
3019
-                // We might EOF during header read.
3020
-                if (feof($this->fp)) {
3021
-                    $this->incoming_payload = $data;
3022
-                    $this->debug('found no headers before EOF after length ' . strlen($data));
3023
-                    $this->debug("received before EOF:\n" . $data);
3024
-                    $this->setError('server failed to send headers');
3025
-                    return false;
3026
-                }
3027
-
3028
-                $tmp = fgets($this->fp, 256);
3029
-                $tmplen = strlen($tmp);
3030
-                $this->debug("read line of $tmplen bytes: " . trim($tmp));
3031
-
3032
-                if ($tmplen == 0) {
3033
-                    $this->incoming_payload = $data;
3034
-                    $this->debug('socket read of headers timed out after length ' . strlen($data));
3035
-                    $this->debug("read before timeout: " . $data);
3036
-                    $this->setError('socket read of headers timed out');
3037
-                    return false;
3038
-                }
3039
-
3040
-                $data .= $tmp;
3041
-                $pos = strpos($data, "\r\n\r\n");
3042
-                if ($pos > 1) {
3043
-                    $lb = "\r\n";
3044
-                } else {
3045
-                    $pos = strpos($data, "\n\n");
3046
-                    if ($pos > 1) {
3047
-                        $lb = "\n";
3048
-                    }
3049
-                }
3050
-                // remove 100 headers
3051
-                if (isset($lb) && preg_match('/^HTTP\/1.1 100/', $data)) {
3052
-                    unset($lb);
3053
-                    $data = '';
3054
-                }//
3055
-            }
3056
-            // store header data
3057
-            $this->incoming_payload .= $data;
3058
-            $this->debug('found end of headers after length ' . strlen($data));
3059
-            // process headers
3060
-            $header_data = trim(substr($data, 0, $pos));
3061
-            $header_array = explode($lb, $header_data);
3062
-            $this->incoming_headers = array();
3063
-            $this->incoming_cookies = array();
3064
-            foreach ($header_array as $header_line) {
3065
-                $arr = explode(':', $header_line, 2);
3066
-                if (count($arr) > 1) {
3067
-                    $header_name = strtolower(trim($arr[0]));
3068
-                    $this->incoming_headers[$header_name] = trim($arr[1]);
3069
-                    if ($header_name == 'set-cookie') {
3070
-                        // TODO: allow multiple cookies from parseCookie
3071
-                        $cookie = $this->parseCookie(trim($arr[1]));
3072
-                        if ($cookie) {
3073
-                            $this->incoming_cookies[] = $cookie;
3074
-                            $this->debug('found cookie: ' . $cookie['name'] . ' = ' . $cookie['value']);
3075
-                        } else {
3076
-                            $this->debug('did not find cookie in ' . trim($arr[1]));
3077
-                        }
3078
-                    }
3079
-                } elseif (isset($header_name)) {
3080
-                    // append continuation line to previous header
3081
-                    $this->incoming_headers[$header_name] .= $lb . ' ' . $header_line;
3082
-                }
3083
-            }
3084
-
3085
-            // loop until msg has been received
3086
-            if (isset($this->incoming_headers['transfer-encoding']) && strtolower($this->incoming_headers['transfer-encoding']) == 'chunked') {
3087
-                $content_length = 2147483647;    // ignore any content-length header
3088
-                $chunked = true;
3089
-                $this->debug("want to read chunked content");
3090
-            } elseif (isset($this->incoming_headers['content-length'])) {
3091
-                $content_length = $this->incoming_headers['content-length'];
3092
-                $chunked = false;
3093
-                $this->debug("want to read content of length $content_length");
3094
-            } else {
3095
-                $content_length = 2147483647;
3096
-                $chunked = false;
3097
-                $this->debug("want to read content to EOF");
3098
-            }
3099
-            $data = '';
3100
-            do {
3101
-                if ($chunked) {
3102
-                    $tmp = fgets($this->fp, 256);
3103
-                    $tmplen = strlen($tmp);
3104
-                    $this->debug("read chunk line of $tmplen bytes");
3105
-                    if ($tmplen == 0) {
3106
-                        $this->incoming_payload = $data;
3107
-                        $this->debug('socket read of chunk length timed out after length ' . strlen($data));
3108
-                        $this->debug("read before timeout:\n" . $data);
3109
-                        $this->setError('socket read of chunk length timed out');
3110
-                        return false;
3111
-                    }
3112
-                    $content_length = hexdec(trim($tmp));
3113
-                    $this->debug("chunk length $content_length");
3114
-                }
3115
-                $strlen = 0;
3116
-                while (($strlen < $content_length) && (!feof($this->fp))) {
3117
-                    $readlen = min(8192, $content_length - $strlen);
3118
-                    $tmp = fread($this->fp, $readlen);
3119
-                    $tmplen = strlen($tmp);
3120
-                    $this->debug("read buffer of $tmplen bytes");
3121
-                    if (($tmplen == 0) && (!feof($this->fp))) {
3122
-                        $this->incoming_payload = $data;
3123
-                        $this->debug('socket read of body timed out after length ' . strlen($data));
3124
-                        $this->debug("read before timeout:\n" . $data);
3125
-                        $this->setError('socket read of body timed out');
3126
-                        return false;
3127
-                    }
3128
-                    $strlen += $tmplen;
3129
-                    $data .= $tmp;
3130
-                }
3131
-                if ($chunked && ($content_length > 0)) {
3132
-                    $tmp = fgets($this->fp, 256);
3133
-                    $tmplen = strlen($tmp);
3134
-                    $this->debug("read chunk terminator of $tmplen bytes");
3135
-                    if ($tmplen == 0) {
3136
-                        $this->incoming_payload = $data;
3137
-                        $this->debug('socket read of chunk terminator timed out after length ' . strlen($data));
3138
-                        $this->debug("read before timeout:\n" . $data);
3139
-                        $this->setError('socket read of chunk terminator timed out');
3140
-                        return false;
3141
-                    }
3142
-                }
3143
-            } while ($chunked && ($content_length > 0) && (!feof($this->fp)));
3144
-            if (feof($this->fp)) {
3145
-                $this->debug('read to EOF');
3146
-            }
3147
-            $this->debug('read body of length ' . strlen($data));
3148
-            $this->incoming_payload .= $data;
3149
-            $this->debug('received a total of ' . strlen($this->incoming_payload) . ' bytes of data from server');
3150
-
3151
-            // close filepointer
3152
-            if (
3153
-                (isset($this->incoming_headers['connection']) && strtolower($this->incoming_headers['connection']) == 'close') ||
3154
-                (!$this->persistentConnection) || feof($this->fp)
3155
-            ) {
3156
-                fclose($this->fp);
3157
-                $this->fp = false;
3158
-                $this->debug('closed socket');
3159
-            }
3160
-
3161
-            // connection was closed unexpectedly
3162
-            if ($this->incoming_payload == '') {
3163
-                $this->setError('no response from server');
3164
-                return false;
3165
-            }
3166
-
3167
-            // decode transfer-encoding
3168
-//		if(isset($this->incoming_headers['transfer-encoding']) && strtolower($this->incoming_headers['transfer-encoding']) == 'chunked'){
3169
-//			if(!$data = $this->decodeChunked($data, $lb)){
3170
-//				$this->setError('Decoding of chunked data failed');
3171
-//				return false;
3172
-//			}
3173
-            //print "<pre>\nde-chunked:\n---------------\n$data\n\n---------------\n</pre>";
3174
-            // set decoded payload
3175
-//			$this->incoming_payload = $header_data.$lb.$lb.$data;
3176
-//		}
1271
+			xml_parser_free($this->parser);
1272
+			unset($this->parser);
1273
+		} else {
1274
+			$this->debug('no xml passed to parseString()!!');
1275
+			$this->setError('no xml passed to parseString()!!');
1276
+		}
1277
+	}
3177 1278
 
3178
-        } elseif ($this->io_method() == 'curl') {
3179
-            // send and receive
3180
-            $this->debug('send and receive with cURL');
3181
-            $this->incoming_payload = curl_exec($this->ch);
3182
-            $data = $this->incoming_payload;
3183
-
3184
-            $cErr = curl_error($this->ch);
3185
-            if ($cErr != '') {
3186
-                $err = 'cURL ERROR: ' . curl_errno($this->ch) . ': ' . $cErr . '<br>';
3187
-                // TODO: there is a PHP bug that can cause this to SEGV for CURLINFO_CONTENT_TYPE
3188
-                foreach (curl_getinfo($this->ch) as $k => $v) {
3189
-                    if (is_array($v)) {
3190
-                        $this->debug("$k: " . json_encode($v));
3191
-                    } else {
3192
-                        $this->debug("$k: $v<br>");
3193
-                    }
3194
-                }
3195
-                $this->debug($err);
3196
-                $this->setError($err);
3197
-                curl_close($this->ch);
3198
-                return false;
3199
-            }
3200
-            // close curl
3201
-            $this->debug('No cURL error, closing cURL');
3202
-            curl_close($this->ch);
3203
-
3204
-            // try removing skippable headers
3205
-            $savedata = $data;
3206
-            while ($this->isSkippableCurlHeader($data)) {
3207
-                $this->debug("Found HTTP header to skip");
3208
-                if ($pos = strpos($data, "\r\n\r\n")) {
3209
-                    $data = ltrim(substr($data, $pos));
3210
-                } elseif ($pos = strpos($data, "\n\n")) {
3211
-                    $data = ltrim(substr($data, $pos));
3212
-                }
3213
-            }
3214
-
3215
-            if ($data == '') {
3216
-                // have nothing left; just remove 100 header(s)
3217
-                $data = $savedata;
3218
-                while (preg_match('/^HTTP\/1.1 100/', $data)) {
3219
-                    if ($pos = strpos($data, "\r\n\r\n")) {
3220
-                        $data = ltrim(substr($data, $pos));
3221
-                    } elseif ($pos = strpos($data, "\n\n")) {
3222
-                        $data = ltrim(substr($data, $pos));
3223
-                    }
3224
-                }
3225
-            }
3226
-
3227
-            // separate content from HTTP headers
3228
-            if ($pos = strpos($data, "\r\n\r\n")) {
3229
-                $lb = "\r\n";
3230
-            } elseif ($pos = strpos($data, "\n\n")) {
3231
-                $lb = "\n";
3232
-            } else {
3233
-                $this->debug('no proper separation of headers and document');
3234
-                $this->setError('no proper separation of headers and document');
3235
-                return false;
3236
-            }
3237
-            $header_data = trim(substr($data, 0, $pos));
3238
-            $header_array = explode($lb, $header_data);
3239
-            $data = ltrim(substr($data, $pos));
3240
-            $this->debug('found proper separation of headers and document');
3241
-            $this->debug('cleaned data, stringlen: ' . strlen($data));
3242
-            // clean headers
3243
-            foreach ($header_array as $header_line) {
3244
-                $arr = explode(':', $header_line, 2);
3245
-                if (count($arr) > 1) {
3246
-                    $header_name = strtolower(trim($arr[0]));
3247
-                    $this->incoming_headers[$header_name] = trim($arr[1]);
3248
-                    if ($header_name == 'set-cookie') {
3249
-                        // TODO: allow multiple cookies from parseCookie
3250
-                        $cookie = $this->parseCookie(trim($arr[1]));
3251
-                        if ($cookie) {
3252
-                            $this->incoming_cookies[] = $cookie;
3253
-                            $this->debug('found cookie: ' . $cookie['name'] . ' = ' . $cookie['value']);
3254
-                        } else {
3255
-                            $this->debug('did not find cookie in ' . trim($arr[1]));
3256
-                        }
3257
-                    }
3258
-                } elseif (isset($header_name)) {
3259
-                    // append continuation line to previous header
3260
-                    $this->incoming_headers[$header_name] .= $lb . ' ' . $header_line;
3261
-                }
3262
-            }
3263
-        }
3264
-
3265
-        $this->response_status_line = $header_array[0];
3266
-        $arr = explode(' ', $this->response_status_line, 3);
3267
-        $http_status = intval($arr[1]);
3268
-        $http_reason = count($arr) > 2 ? $arr[2] : '';
3269
-
3270
-        // see if we need to resend the request with http digest authentication
3271
-        if (isset($this->incoming_headers['location']) && ($http_status == 301 || $http_status == 302)) {
3272
-            $this->debug("Got $http_status $http_reason with Location: " . $this->incoming_headers['location']);
3273
-            $this->setURL($this->incoming_headers['location']);
3274
-            $this->tryagain = true;
3275
-            return false;
3276
-        }
3277
-
3278
-        // see if we need to resend the request with http digest authentication
3279
-        if (isset($this->incoming_headers['www-authenticate']) && $http_status == 401) {
3280
-            $this->debug("Got 401 $http_reason with WWW-Authenticate: " . $this->incoming_headers['www-authenticate']);
3281
-            if (strstr($this->incoming_headers['www-authenticate'], "Digest ")) {
3282
-                $this->debug('Server wants digest authentication');
3283
-                // remove "Digest " from our elements
3284
-                $digestString = str_replace('Digest ', '', $this->incoming_headers['www-authenticate']);
3285
-
3286
-                // parse elements into array
3287
-                $digestElements = explode(',', $digestString);
3288
-                foreach ($digestElements as $val) {
3289
-                    $tempElement = explode('=', trim($val), 2);
3290
-                    $digestRequest[$tempElement[0]] = str_replace("\"", '', $tempElement[1]);
3291
-                }
3292
-
3293
-                // should have (at least) qop, realm, nonce
3294
-                if (isset($digestRequest['nonce'])) {
3295
-                    $this->setCredentials($this->username, $this->password, 'digest', $digestRequest);
3296
-                    $this->tryagain = true;
3297
-                    return false;
3298
-                }
3299
-            }
3300
-            $this->debug('HTTP authentication failed');
3301
-            $this->setError('HTTP authentication failed');
3302
-            return false;
3303
-        }
3304
-
3305
-        if (
3306
-            ($http_status >= 300 && $http_status <= 307) ||
3307
-            ($http_status >= 400 && $http_status <= 417) ||
3308
-            ($http_status >= 501 && $http_status <= 505)
3309
-        ) {
3310
-            $this->setError("Unsupported HTTP response status $http_status $http_reason (soapclient->response has contents of the response)");
3311
-            return false;
3312
-        }
3313
-
3314
-        // decode content-encoding
3315
-        if (isset($this->incoming_headers['content-encoding']) && $this->incoming_headers['content-encoding'] != '') {
3316
-            if (strtolower($this->incoming_headers['content-encoding']) == 'deflate' || strtolower($this->incoming_headers['content-encoding']) == 'gzip') {
3317
-                $header_data = "";
3318
-                // if decoding works, use it. else assume data wasn't gzencoded
3319
-                if (function_exists('gzinflate')) {
3320
-                    //$timer->setMarker('starting decoding of gzip/deflated content');
3321
-                    // IIS 5 requires gzinflate instead of gzuncompress (similar to IE 5 and gzdeflate v. gzcompress)
3322
-                    // this means there are no Zlib headers, although there should be
3323
-                    $this->debug('The gzinflate function exists');
3324
-                    $datalen = strlen($data);
3325
-                    if ($this->incoming_headers['content-encoding'] == 'deflate') {
3326
-                        if ($degzdata = @gzinflate($data)) {
3327
-                            $data = $degzdata;
3328
-                            $this->debug('The payload has been inflated to ' . strlen($data) . ' bytes');
3329
-                            if (strlen($data) < $datalen) {
3330
-                                // test for the case that the payload has been compressed twice
3331
-                                $this->debug('The inflated payload is smaller than the gzipped one; try again');
3332
-                                if ($degzdata = @gzinflate($data)) {
3333
-                                    $data = $degzdata;
3334
-                                    $this->debug('The payload has been inflated again to ' . strlen($data) . ' bytes');
3335
-                                }
3336
-                            }
3337
-                        } else {
3338
-                            $this->debug('Error using gzinflate to inflate the payload');
3339
-                            $this->setError('Error using gzinflate to inflate the payload');
3340
-                        }
3341
-                    } elseif ($this->incoming_headers['content-encoding'] == 'gzip') {
3342
-                        if ($degzdata = @gzinflate(substr($data, 10))) {    // do our best
3343
-                            $data = $degzdata;
3344
-                            $this->debug('The payload has been un-gzipped to ' . strlen($data) . ' bytes');
3345
-                            if (strlen($data) < $datalen) {
3346
-                                // test for the case that the payload has been compressed twice
3347
-                                $this->debug('The un-gzipped payload is smaller than the gzipped one; try again');
3348
-                                if ($degzdata = @gzinflate(substr($data, 10))) {
3349
-                                    $data = $degzdata;
3350
-                                    $this->debug('The payload has been un-gzipped again to ' . strlen($data) . ' bytes');
3351
-                                }
3352
-                            }
3353
-                        } else {
3354
-                            $this->debug('Error using gzinflate to un-gzip the payload');
3355
-                            $this->setError('Error using gzinflate to un-gzip the payload');
3356
-                        }
3357
-                    }
3358
-                    //$timer->setMarker('finished decoding of gzip/deflated content');
3359
-                    //print "<xmp>\nde-inflated:\n---------------\n$data\n-------------\n</xmp>";
3360
-                    // set decoded payload
3361
-                    $this->incoming_payload = $header_data . (isset ($lb) ? $lb : "") . (isset ($lb) ? $lb : "") . $data;
3362
-                } else {
3363
-                    $this->debug('The server sent compressed data. Your php install must have the Zlib extension compiled in to support this.');
3364
-                    $this->setError('The server sent compressed data. Your php install must have the Zlib extension compiled in to support this.');
3365
-                }
3366
-            } else {
3367
-                $this->debug('Unsupported Content-Encoding ' . $this->incoming_headers['content-encoding']);
3368
-                $this->setError('Unsupported Content-Encoding ' . $this->incoming_headers['content-encoding']);
3369
-            }
3370
-        } else {
3371
-            $this->debug('No Content-Encoding header');
3372
-        }
3373
-
3374
-        if (strlen($data) == 0) {
3375
-            $this->debug('no data after headers!');
3376
-            $this->setError('no data present after HTTP headers');
3377
-            return false;
3378
-        }
3379
-
3380
-        return $data;
3381
-    }
3382
-
3383
-    /**
3384
-     * sets the content-type for the SOAP message to be sent
3385
-     *
3386
-     * @param    string $type the content type, MIME style
3387
-     * @param    mixed $charset character set used for encoding (or false)
3388
-     * @access    public
3389
-     */
3390
-    function setContentType($type, $charset = false)
3391
-    {
3392
-        $this->setHeader('Content-Type', $type . ($charset ? '; charset=' . $charset : ''));
3393
-    }
3394
-
3395
-    /**
3396
-     * specifies that an HTTP persistent connection should be used
3397
-     *
3398
-     * @return    boolean whether the request was honored by this method.
3399
-     * @access    public
3400
-     */
3401
-    function usePersistentConnection()
3402
-    {
3403
-        if (isset($this->outgoing_headers['Accept-Encoding'])) {
3404
-            return false;
3405
-        }
3406
-        $this->protocol_version = '1.1';
3407
-        $this->persistentConnection = true;
3408
-        $this->setHeader('Connection', 'Keep-Alive');
3409
-        return true;
3410
-    }
3411
-
3412
-    /**
3413
-     * parse an incoming Cookie into it's parts
3414
-     *
3415
-     * @param    string $cookie_str content of cookie
3416
-     * @return    array with data of that cookie
3417
-     * @access    private
3418
-     */
3419
-    /*
3420
-	 * TODO: allow a Set-Cookie string to be parsed into multiple cookies
1279
+	/**
1280
+	 * gets a type name for an unnamed type
1281
+	 *
1282
+	 * @param    string $ename Element name
1283
+	 * @return    string    A type name for an unnamed type
1284
+	 * @access    private
3421 1285
 	 */
3422
-    function parseCookie($cookie_str)
3423
-    {
3424
-        $cookie_str = str_replace('; ', ';', $cookie_str) . ';';
3425
-        $data = explode (';', $cookie_str);
3426
-        $value_str = $data[0];
3427
-
3428
-        $cookie_param = 'domain=';
3429
-        $start = strpos($cookie_str, $cookie_param);
3430
-        if ($start > 0) {
3431
-            $domain = substr($cookie_str, $start + strlen($cookie_param));
3432
-            $domain = substr($domain, 0, strpos($domain, ';'));
3433
-        } else {
3434
-            $domain = '';
3435
-        }
3436
-
3437
-        $cookie_param = 'expires=';
3438
-        $start = strpos($cookie_str, $cookie_param);
3439
-        if ($start > 0) {
3440
-            $expires = substr($cookie_str, $start + strlen($cookie_param));
3441
-            $expires = substr($expires, 0, strpos($expires, ';'));
3442
-        } else {
3443
-            $expires = '';
3444
-        }
3445
-
3446
-        $cookie_param = 'path=';
3447
-        $start = strpos($cookie_str, $cookie_param);
3448
-        if ($start > 0) {
3449
-            $path = substr($cookie_str, $start + strlen($cookie_param));
3450
-            $path = substr($path, 0, strpos($path, ';'));
3451
-        } else {
3452
-            $path = '/';
3453
-        }
3454
-
3455
-        $cookie_param = ';secure;';
3456
-        if (strpos($cookie_str, $cookie_param) !== false) {
3457
-            $secure = true;
3458
-        } else {
3459
-            $secure = false;
3460
-        }
3461
-
3462
-        $sep_pos = strpos($value_str, '=');
3463
-
3464
-        if ($sep_pos) {
3465
-            $name = substr($value_str, 0, $sep_pos);
3466
-            $value = substr($value_str, $sep_pos + 1);
3467
-
3468
-          return array('name' => $name,
3469
-                     'value' => $value,
3470
-                     'domain' => $domain,
3471
-                     'path' => $path,
3472
-                     'expires' => $expires,
3473
-                     'secure' => $secure
3474
-          );
3475
-        }
3476
-        return array ();
3477
-    }
3478
-
3479
-    /**
3480
-     * sort out cookies for the current request
3481
-     *
3482
-     * @param    array $cookies array with all cookies
3483
-     * @param    boolean $secure is the send-content secure or not?
3484
-     * @return    string for Cookie-HTTP-Header
3485
-     * @access    private
3486
-     */
3487
-    function getCookiesForRequest($cookies, $secure = false)
3488
-    {
3489
-        $cookie_str = '';
3490
-        if ((is_array($cookies))) {
3491
-            foreach ($cookies as $cookie) {
3492
-                if (!is_array($cookie)) {
3493
-                    continue;
3494
-                }
3495
-                $this->debug("check cookie for validity: " . $cookie['name'] . '=' . $cookie['value']);
3496
-                if ((isset($cookie['expires'])) && (!empty($cookie['expires']))) {
3497
-                    if (strtotime($cookie['expires']) <= time()) {
3498
-                        $this->debug('cookie has expired');
3499
-                        continue;
3500
-                    }
3501
-                }
3502
-                if ((isset($cookie['domain'])) && (!empty($cookie['domain']))) {
3503
-                    $domain = preg_quote($cookie['domain'], "'");
3504
-                    if (!preg_match("'.*$domain$'i", $this->host)) {
3505
-                        $this->debug('cookie has different domain');
3506
-                        continue;
3507
-                    }
3508
-                }
3509
-                if ((isset($cookie['path'])) && (!empty($cookie['path']))) {
3510
-                    $path = preg_quote($cookie['path'], "'");
3511
-                    if (!preg_match("'^$path.*'i", $this->path)) {
3512
-                        $this->debug('cookie is for a different path');
3513
-                        continue;
3514
-                    }
3515
-                }
3516
-                if ((!$secure) && (isset($cookie['secure'])) && ($cookie['secure'])) {
3517
-                    $this->debug('cookie is secure, transport is not');
3518
-                    continue;
3519
-                }
3520
-                $cookie_str .= $cookie['name'] . '=' . $cookie['value'] . '; ';
3521
-                $this->debug('add cookie to Cookie-String: ' . $cookie['name'] . '=' . $cookie['value']);
3522
-            }
3523
-        }
3524
-        return $cookie_str;
3525
-    }
3526
-}
1286
+	function CreateTypeName($ename)
1287
+	{
1288
+		$scope = '';
1289
+		for ($i = 0; $i < count($this->complexTypeStack); $i++) {
1290
+			$scope .= $this->complexTypeStack[$i] . '_';
1291
+		}
1292
+		return $scope . $ename . '_ContainedType';
1293
+	}
3527 1294
 
1295
+	/**
1296
+	 * start-element handler
1297
+	 *
1298
+	 * @param    string $parser XML parser object
1299
+	 * @param    string $name element name
1300
+	 * @param    array $attrs associative array of attributes
1301
+	 * @access   private
1302
+	 */
1303
+	function schemaStartElement($parser, $name, $attrs)
1304
+	{
1305
+
1306
+		// position in the total number of elements, starting from 0
1307
+		$pos = $this->position++;
1308
+		$depth = $this->depth++;
1309
+		// set self as current value for this depth
1310
+		$this->depth_array[$depth] = $pos;
1311
+		$this->message[$pos] = array('cdata' => '');
1312
+		if ($depth > 0) {
1313
+			$this->defaultNamespace[$pos] = $this->defaultNamespace[$this->depth_array[$depth - 1]];
1314
+		} else {
1315
+			$this->defaultNamespace[$pos] = false;
1316
+		}
3528 1317
 
3529
-/**
3530
- *
3531
- * nusoap_server allows the user to create a SOAP server
3532
- * that is capable of receiving messages and returning responses
3533
- *
1318
+		// get element prefix
1319
+		if ($prefix = $this->getPrefix($name)) {
1320
+			// get unqualified name
1321
+			$name = $this->getLocalPart($name);
1322
+		} else {
1323
+			$prefix = '';
1324
+		}
1325
+
1326
+		// loop thru attributes, expanding, and registering namespace declarations
1327
+		if (count($attrs) > 0) {
1328
+			foreach ($attrs as $k => $v) {
1329
+				// if ns declarations, add to class level array of valid namespaces
1330
+				if (preg_match('/^xmlns/', $k)) {
1331
+					//$this->xdebug("$k: $v");
1332
+					//$this->xdebug('ns_prefix: '.$this->getPrefix($k));
1333
+					if ($ns_prefix = substr(strrchr($k, ':'), 1)) {
1334
+						//$this->xdebug("Add namespace[$ns_prefix] = $v");
1335
+						$this->namespaces[$ns_prefix] = $v;
1336
+					} else {
1337
+						$this->defaultNamespace[$pos] = $v;
1338
+						if (!$this->getPrefixFromNamespace($v)) {
1339
+							$this->namespaces['ns' . (count($this->namespaces) + 1)] = $v;
1340
+						}
1341
+					}
1342
+					if ($v == 'http://www.w3.org/2001/XMLSchema' || $v == 'http://www.w3.org/1999/XMLSchema' || $v == 'http://www.w3.org/2000/10/XMLSchema') {
1343
+						$this->XMLSchemaVersion = $v;
1344
+						$this->namespaces['xsi'] = $v . '-instance';
1345
+					}
1346
+				}
1347
+			}
1348
+			$eAttrs = array ();
1349
+			foreach ($attrs as $k => $v) {
1350
+				// expand each attribute
1351
+				$k = strpos($k, ':') ? $this->expandQname($k) : $k;
1352
+				$v = strpos($v, ':') ? $this->expandQname($v) : $v;
1353
+				$eAttrs[$k] = $v;
1354
+			}
1355
+			$attrs = $eAttrs;
1356
+		} else {
1357
+			$attrs = array();
1358
+		}
1359
+		// find status, register data
1360
+		switch ($name) {
1361
+			case 'all':            // (optional) compositor content for a complexType
1362
+			case 'choice':
1363
+			case 'group':
1364
+			case 'sequence':
1365
+				//$this->xdebug("compositor $name for currentComplexType: $this->currentComplexType and currentElement: $this->currentElement");
1366
+				$this->complexTypes[$this->currentComplexType]['compositor'] = $name;
1367
+				//if($name == 'all' || $name == 'sequence'){
1368
+				//	$this->complexTypes[$this->currentComplexType]['phpType'] = 'struct';
1369
+				//}
1370
+				break;
1371
+			case 'attribute':    // complexType attribute
1372
+				//$this->xdebug("parsing attribute $attrs[name] $attrs[ref] of value: ".$attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']);
1373
+				$this->xdebug("parsing attribute:");
1374
+				$this->appendDebug($this->varDump($attrs));
1375
+				if (!isset($attrs['form'])) {
1376
+					// TODO: handle globals
1377
+					$attrs['form'] = $this->schemaInfo['attributeFormDefault'];
1378
+				}
1379
+				if (isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])) {
1380
+					$v = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'];
1381
+					if (!strpos($v, ':')) {
1382
+						// no namespace in arrayType attribute value...
1383
+						if ($this->defaultNamespace[$pos]) {
1384
+							// ...so use the default
1385
+							$attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'] = $this->defaultNamespace[$pos] . ':' . $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'];
1386
+						}
1387
+					}
1388
+				}
1389
+				if (isset($attrs['name'])) {
1390
+					$this->attributes[$attrs['name']] = $attrs;
1391
+					$aname = $attrs['name'];
1392
+				} elseif (isset($attrs['ref']) && $attrs['ref'] == 'http://schemas.xmlsoap.org/soap/encoding/:arrayType') {
1393
+					if (isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])) {
1394
+						$aname = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'];
1395
+					} else {
1396
+						$aname = '';
1397
+					}
1398
+				} elseif (isset($attrs['ref'])) {
1399
+					$aname = $attrs['ref'];
1400
+					$this->attributes[$attrs['ref']] = $attrs;
1401
+				} else {
1402
+					$aname = '';
1403
+				}
1404
+
1405
+				if ($this->currentComplexType) {    // This should *always* be
1406
+					$this->complexTypes[$this->currentComplexType]['attrs'][$aname] = $attrs;
1407
+				}
1408
+				// arrayType attribute
1409
+				if (isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']) || $this->getLocalPart($aname) == 'arrayType') {
1410
+					$this->complexTypes[$this->currentComplexType]['phpType'] = 'array';
1411
+					if (isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])) {
1412
+						$v = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'];
1413
+					} else {
1414
+						$v = '';
1415
+					}
1416
+					if (strpos($v, '[,]')) {
1417
+						$this->complexTypes[$this->currentComplexType]['multidimensional'] = true;
1418
+					}
1419
+					$v = substr($v, 0, strpos($v, '[')); // clip the []
1420
+					if (!strpos($v, ':') && isset($this->typemap[$this->XMLSchemaVersion][$v])) {
1421
+						$v = $this->XMLSchemaVersion . ':' . $v;
1422
+					}
1423
+					$this->complexTypes[$this->currentComplexType]['arrayType'] = $v;
1424
+				}
1425
+				break;
1426
+			case 'complexContent':    // (optional) content for a complexType
1427
+				$this->xdebug("do nothing for element $name");
1428
+				break;
1429
+			case 'complexType':
1430
+				$this->complexTypeStack[] = $this->currentComplexType;
1431
+				if (isset($attrs['name'])) {
1432
+					// TODO: what is the scope of named complexTypes that appear
1433
+					//       nested within other c complexTypes?
1434
+					$this->xdebug('processing named complexType ' . $attrs['name']);
1435
+					//$this->currentElement = false;
1436
+					$this->currentComplexType = $attrs['name'];
1437
+				} else {
1438
+					$name = $this->CreateTypeName($this->currentElement);
1439
+					$this->xdebug('processing unnamed complexType for element ' . $this->currentElement . ' named ' . $name);
1440
+					$this->currentComplexType = $name;
1441
+					//$this->currentElement = false;
1442
+				}
1443
+				$this->complexTypes[$this->currentComplexType] = $attrs;
1444
+				$this->complexTypes[$this->currentComplexType]['typeClass'] = 'complexType';
1445
+				// This is for constructs like
1446
+				//           <complexType name="ListOfString" base="soap:Array">
1447
+				//                <sequence>
1448
+				//                    <element name="string" type="xsd:string"
1449
+				//                        minOccurs="0" maxOccurs="unbounded" />
1450
+				//                </sequence>
1451
+				//            </complexType>
1452
+				if (isset($attrs['base']) && preg_match('/:Array$/', $attrs['base'])) {
1453
+					$this->xdebug('complexType is unusual array');
1454
+					$this->complexTypes[$this->currentComplexType]['phpType'] = 'array';
1455
+				} else {
1456
+					$this->complexTypes[$this->currentComplexType]['phpType'] = 'struct';
1457
+				}
1458
+				$this->complexTypes[$this->currentComplexType]['simpleContent'] = 'false';
1459
+				break;
1460
+			case 'element':
1461
+				$this->elementStack[] = $this->currentElement;
1462
+				if (!isset($attrs['form'])) {
1463
+					if ($this->currentComplexType) {
1464
+						$attrs['form'] = $this->schemaInfo['elementFormDefault'];
1465
+					} else {
1466
+						// global
1467
+						$attrs['form'] = 'qualified';
1468
+					}
1469
+				}
1470
+				if (isset($attrs['type'])) {
1471
+					$this->xdebug("processing typed element " . $attrs['name'] . " of type " . $attrs['type']);
1472
+					if (!$this->getPrefix($attrs['type'])) {
1473
+						if ($this->defaultNamespace[$pos]) {
1474
+							$attrs['type'] = $this->defaultNamespace[$pos] . ':' . $attrs['type'];
1475
+							$this->xdebug('used default namespace to make type ' . $attrs['type']);
1476
+						}
1477
+					}
1478
+					// This is for constructs like
1479
+					//           <complexType name="ListOfString" base="soap:Array">
1480
+					//                <sequence>
1481
+					//                    <element name="string" type="xsd:string"
1482
+					//                        minOccurs="0" maxOccurs="unbounded" />
1483
+					//                </sequence>
1484
+					//            </complexType>
1485
+					if ($this->currentComplexType && $this->complexTypes[$this->currentComplexType]['phpType'] == 'array') {
1486
+						$this->xdebug('arrayType for unusual array is ' . $attrs['type']);
1487
+						$this->complexTypes[$this->currentComplexType]['arrayType'] = $attrs['type'];
1488
+					}
1489
+					$this->currentElement = $attrs['name'];
1490
+					$ename = $attrs['name'];
1491
+				} elseif (isset($attrs['ref'])) {
1492
+					$this->xdebug("processing element as ref to " . $attrs['ref']);
1493
+					$this->currentElement = "ref to " . $attrs['ref'];
1494
+					$ename = $this->getLocalPart($attrs['ref']);
1495
+				} else {
1496
+					$type = $this->CreateTypeName($this->currentComplexType . '_' . $attrs['name']);
1497
+					$this->xdebug("processing untyped element " . $attrs['name'] . ' type ' . $type);
1498
+					$this->currentElement = $attrs['name'];
1499
+					$attrs['type'] = $this->schemaTargetNamespace . ':' . $type;
1500
+					$ename = $attrs['name'];
1501
+				}
1502
+				if (isset($ename) && $this->currentComplexType) {
1503
+					$this->xdebug("add element $ename to complexType $this->currentComplexType");
1504
+					$this->complexTypes[$this->currentComplexType]['elements'][$ename] = $attrs;
1505
+				} elseif (!isset($attrs['ref'])) {
1506
+					$this->xdebug("add element $ename to elements array");
1507
+					$this->elements[$attrs['name']] = $attrs;
1508
+					$this->elements[$attrs['name']]['typeClass'] = 'element';
1509
+				}
1510
+				break;
1511
+			case 'enumeration':    //	restriction value list member
1512
+				$this->xdebug('enumeration ' . $attrs['value']);
1513
+				if ($this->currentSimpleType) {
1514
+					$this->simpleTypes[$this->currentSimpleType]['enumeration'][] = $attrs['value'];
1515
+				} elseif ($this->currentComplexType) {
1516
+					$this->complexTypes[$this->currentComplexType]['enumeration'][] = $attrs['value'];
1517
+				}
1518
+				break;
1519
+			case 'extension':    // simpleContent or complexContent type extension
1520
+				$this->xdebug('extension ' . $attrs['base']);
1521
+				if ($this->currentComplexType) {
1522
+					$ns = $this->getPrefix($attrs['base']);
1523
+					if ($ns == '') {
1524
+						$this->complexTypes[$this->currentComplexType]['extensionBase'] = $this->schemaTargetNamespace . ':' . $attrs['base'];
1525
+					} else {
1526
+						$this->complexTypes[$this->currentComplexType]['extensionBase'] = $attrs['base'];
1527
+					}
1528
+				} else {
1529
+					$this->xdebug('no current complexType to set extensionBase');
1530
+				}
1531
+				break;
1532
+			case 'import':
1533
+				if (isset($attrs['schemaLocation'])) {
1534
+					$this->xdebug('import namespace ' . $attrs['namespace'] . ' from ' . $attrs['schemaLocation']);
1535
+					$this->imports[$attrs['namespace']][] = array('location' => $attrs['schemaLocation'], 'loaded' => false);
1536
+				} else {
1537
+					$this->xdebug('import namespace ' . $attrs['namespace']);
1538
+					$this->imports[$attrs['namespace']][] = array('location' => '', 'loaded' => true);
1539
+					if (!$this->getPrefixFromNamespace($attrs['namespace'])) {
1540
+						$this->namespaces['ns' . (count($this->namespaces) + 1)] = $attrs['namespace'];
1541
+					}
1542
+				}
1543
+				break;
1544
+			case 'include':
1545
+				if (isset($attrs['schemaLocation'])) {
1546
+					$this->xdebug('include into namespace ' . $this->schemaTargetNamespace . ' from ' . $attrs['schemaLocation']);
1547
+					$this->imports[$this->schemaTargetNamespace][] = array('location' => $attrs['schemaLocation'], 'loaded' => false);
1548
+				} else {
1549
+					$this->xdebug('ignoring invalid XML Schema construct: include without schemaLocation attribute');
1550
+				}
1551
+				break;
1552
+			case 'list':    // simpleType value list
1553
+				$this->xdebug("do nothing for element $name");
1554
+				break;
1555
+			case 'restriction':    // simpleType, simpleContent or complexContent value restriction
1556
+				$this->xdebug('restriction ' . $attrs['base']);
1557
+				if ($this->currentSimpleType) {
1558
+					$this->simpleTypes[$this->currentSimpleType]['type'] = $attrs['base'];
1559
+				} elseif ($this->currentComplexType) {
1560
+					$this->complexTypes[$this->currentComplexType]['restrictionBase'] = $attrs['base'];
1561
+					if (strstr($attrs['base'], ':') == ':Array') {
1562
+						$this->complexTypes[$this->currentComplexType]['phpType'] = 'array';
1563
+					}
1564
+				}
1565
+				break;
1566
+			case 'schema':
1567
+				$this->schemaInfo = $attrs;
1568
+				$this->schemaInfo['schemaVersion'] = $this->getNamespaceFromPrefix($prefix);
1569
+				if (isset($attrs['targetNamespace'])) {
1570
+					$this->schemaTargetNamespace = $attrs['targetNamespace'];
1571
+				}
1572
+				if (!isset($attrs['elementFormDefault'])) {
1573
+					$this->schemaInfo['elementFormDefault'] = 'unqualified';
1574
+				}
1575
+				if (!isset($attrs['attributeFormDefault'])) {
1576
+					$this->schemaInfo['attributeFormDefault'] = 'unqualified';
1577
+				}
1578
+				break;
1579
+			case 'simpleContent':    // (optional) content for a complexType
1580
+				if ($this->currentComplexType) {    // This should *always* be
1581
+					$this->complexTypes[$this->currentComplexType]['simpleContent'] = 'true';
1582
+				} else {
1583
+					$this->xdebug("do nothing for element $name because there is no current complexType");
1584
+				}
1585
+				break;
1586
+			case 'simpleType':
1587
+				$this->simpleTypeStack[] = $this->currentSimpleType;
1588
+				if (isset($attrs['name'])) {
1589
+					$this->xdebug("processing simpleType for name " . $attrs['name']);
1590
+					$this->currentSimpleType = $attrs['name'];
1591
+					$this->simpleTypes[$attrs['name']] = $attrs;
1592
+					$this->simpleTypes[$attrs['name']]['typeClass'] = 'simpleType';
1593
+					$this->simpleTypes[$attrs['name']]['phpType'] = 'scalar';
1594
+				} else {
1595
+					$name = $this->CreateTypeName($this->currentComplexType . '_' . $this->currentElement);
1596
+					$this->xdebug('processing unnamed simpleType for element ' . $this->currentElement . ' named ' . $name);
1597
+					$this->currentSimpleType = $name;
1598
+					//$this->currentElement = false;
1599
+					$this->simpleTypes[$this->currentSimpleType] = $attrs;
1600
+					$this->simpleTypes[$this->currentSimpleType]['phpType'] = 'scalar';
1601
+				}
1602
+				break;
1603
+			case 'union':    // simpleType type list
1604
+				$this->xdebug("do nothing for element $name");
1605
+				break;
1606
+			default:
1607
+				$this->xdebug("do not have any logic to process element $name");
1608
+		}
1609
+	}
1610
+
1611
+	/**
1612
+	 * end-element handler
1613
+	 *
1614
+	 * @param    string $parser XML parser object
1615
+	 * @param    string $name element name
1616
+	 * @access   private
1617
+	 */
1618
+	function schemaEndElement($parser, $name)
1619
+	{
1620
+		// bring depth down a notch
1621
+		$this->depth--;
1622
+		// get element prefix
1623
+		if ($this->getPrefix($name)) {
1624
+			// get unqualified name
1625
+			$name = $this->getLocalPart($name);
1626
+		}
1627
+		// move on...
1628
+		if ($name == 'complexType') {
1629
+			$this->xdebug('done processing complexType ' . ($this->currentComplexType ?: '(unknown)'));
1630
+			$this->xdebug($this->varDump($this->complexTypes[$this->currentComplexType]));
1631
+			$this->currentComplexType = array_pop($this->complexTypeStack);
1632
+			//$this->currentElement = false;
1633
+		}
1634
+		if ($name == 'element') {
1635
+			$this->xdebug('done processing element ' . ($this->currentElement ?: '(unknown)'));
1636
+			$this->currentElement = array_pop($this->elementStack);
1637
+		}
1638
+		if ($name == 'simpleType') {
1639
+			$this->xdebug('done processing simpleType ' . ($this->currentSimpleType ?: '(unknown)'));
1640
+			$this->xdebug($this->varDump($this->simpleTypes[$this->currentSimpleType]));
1641
+			$this->currentSimpleType = array_pop($this->simpleTypeStack);
1642
+		}
1643
+	}
1644
+
1645
+	/**
1646
+	 * element content handler
1647
+	 *
1648
+	 * @param    string $parser XML parser object
1649
+	 * @param    string $data element content
1650
+	 * @access   private
1651
+	 */
1652
+	function schemaCharacterData($parser, $data)
1653
+	{
1654
+		$pos = $this->depth_array[$this->depth - 1];
1655
+		$this->message[$pos]['cdata'] .= $data;
1656
+	}
1657
+
1658
+	/**
1659
+	 * serialize the schema
1660
+	 *
1661
+	 * @access   public
1662
+	 */
1663
+	function serializeSchema()
1664
+	{
1665
+
1666
+		$schemaPrefix = $this->getPrefixFromNamespace($this->XMLSchemaVersion);
1667
+		$xml = '';
1668
+		// imports
1669
+		if (sizeof($this->imports) > 0) {
1670
+			foreach ($this->imports as $ns => $list) {
1671
+				foreach ($list as $ii) {
1672
+					if ($ii['location'] != '') {
1673
+						$xml .= " <$schemaPrefix:import location=\"" . $ii['location'] . '" namespace="' . $ns . "\" />\n";
1674
+					} else {
1675
+						$xml .= " <$schemaPrefix:import namespace=\"" . $ns . "\" />\n";
1676
+					}
1677
+				}
1678
+			}
1679
+		}
1680
+		// complex types
1681
+		foreach ($this->complexTypes as $typeName => $attrs) {
1682
+			$contentStr = '';
1683
+			// serialize child elements
1684
+			if (isset($attrs['elements']) && (count($attrs['elements']) > 0)) {
1685
+				foreach ($attrs['elements'] as $element => $eParts) {
1686
+					if (isset($eParts['ref'])) {
1687
+						$contentStr .= "   <$schemaPrefix:element ref=\"$element\"/>\n";
1688
+					} else {
1689
+						$contentStr .= "   <$schemaPrefix:element name=\"$element\" type=\"" . $this->contractQName($eParts['type']) . "\"";
1690
+						foreach ($eParts as $aName => $aValue) {
1691
+							// handle, e.g., abstract, default, form, minOccurs, maxOccurs, nillable
1692
+							if ($aName != 'name' && $aName != 'type') {
1693
+								$contentStr .= " $aName=\"$aValue\"";
1694
+							}
1695
+						}
1696
+						$contentStr .= "/>\n";
1697
+					}
1698
+				}
1699
+				// compositor wraps elements
1700
+				if (isset($attrs['compositor']) && ($attrs['compositor'] != '')) {
1701
+					$contentStr = "  <$schemaPrefix:$attrs[compositor]>\n" . $contentStr . "  </$schemaPrefix:$attrs[compositor]>\n";
1702
+				}
1703
+			}
1704
+			// attributes
1705
+			if (isset($attrs['attrs']) && (count($attrs['attrs']) >= 1)) {
1706
+				foreach ($attrs['attrs'] as $aParts) {
1707
+					$contentStr .= "    <$schemaPrefix:attribute";
1708
+					foreach ($aParts as $a => $v) {
1709
+						if ($a == 'ref' || $a == 'type') {
1710
+							$contentStr .= " $a=\"" . $this->contractQName($v) . '"';
1711
+						} elseif ($a == 'http://schemas.xmlsoap.org/wsdl/:arrayType') {
1712
+							$this->usedNamespaces['wsdl'] = $this->namespaces['wsdl'];
1713
+							$contentStr .= ' wsdl:arrayType="' . $this->contractQName($v) . '"';
1714
+						} else {
1715
+							$contentStr .= " $a=\"$v\"";
1716
+						}
1717
+					}
1718
+					$contentStr .= "/>\n";
1719
+				}
1720
+			}
1721
+			// if restriction
1722
+			if (isset($attrs['restrictionBase']) && $attrs['restrictionBase'] != '') {
1723
+				$contentStr = "   <$schemaPrefix:restriction base=\"" . $this->contractQName($attrs['restrictionBase']) . "\">\n" . $contentStr . "   </$schemaPrefix:restriction>\n";
1724
+				// complex or simple content
1725
+				if ((isset($attrs['elements']) && count($attrs['elements']) > 0) || (isset($attrs['attrs']) && count($attrs['attrs']) > 0)) {
1726
+					$contentStr = "  <$schemaPrefix:complexContent>\n" . $contentStr . "  </$schemaPrefix:complexContent>\n";
1727
+				}
1728
+			}
1729
+			// finalize complex type
1730
+			if ($contentStr != '') {
1731
+				$contentStr = " <$schemaPrefix:complexType name=\"$typeName\">\n" . $contentStr . " </$schemaPrefix:complexType>\n";
1732
+			} else {
1733
+				$contentStr = " <$schemaPrefix:complexType name=\"$typeName\"/>\n";
1734
+			}
1735
+			$xml .= $contentStr;
1736
+		}
1737
+		// simple types
1738
+		if (isset($this->simpleTypes) && count($this->simpleTypes) > 0) {
1739
+			foreach ($this->simpleTypes as $typeName => $eParts) {
1740
+				$xml .= " <$schemaPrefix:simpleType name=\"$typeName\">\n  <$schemaPrefix:restriction base=\"" . $this->contractQName($eParts['type']) . "\">\n";
1741
+				if (isset($eParts['enumeration'])) {
1742
+					foreach ($eParts['enumeration'] as $e) {
1743
+						$xml .= "  <$schemaPrefix:enumeration value=\"$e\"/>\n";
1744
+					}
1745
+				}
1746
+				$xml .= "  </$schemaPrefix:restriction>\n </$schemaPrefix:simpleType>";
1747
+			}
1748
+		}
1749
+		// elements
1750
+		if (isset($this->elements) && count($this->elements) > 0) {
1751
+			foreach ($this->elements as $element => $eParts) {
1752
+				$xml .= " <$schemaPrefix:element name=\"$element\" type=\"" . $this->contractQName($eParts['type']) . "\"/>\n";
1753
+			}
1754
+		}
1755
+		// attributes
1756
+		if (isset($this->attributes) && count($this->attributes) > 0) {
1757
+			foreach ($this->attributes as $attr => $aParts) {
1758
+				$xml .= " <$schemaPrefix:attribute name=\"$attr\" type=\"" . $this->contractQName($aParts['type']) . "\"\n/>";
1759
+			}
1760
+		}
1761
+		// finish 'er up
1762
+		$attr = '';
1763
+		foreach ($this->schemaInfo as $k => $v) {
1764
+			if ($k == 'elementFormDefault' || $k == 'attributeFormDefault') {
1765
+				$attr .= " $k=\"$v\"";
1766
+			}
1767
+		}
1768
+		$el = "<$schemaPrefix:schema$attr targetNamespace=\"$this->schemaTargetNamespace\"\n";
1769
+		foreach (array_diff($this->usedNamespaces, $this->enclosingNamespaces) as $nsp => $ns) {
1770
+			$el .= " xmlns:$nsp=\"$ns\"";
1771
+		}
1772
+
1773
+	  return $el . ">\n" . $xml . "</$schemaPrefix:schema>\n";
1774
+	}
1775
+
1776
+	/**
1777
+	 * adds debug data to the clas level debug string
1778
+	 *
1779
+	 * @param    string $string debug data
1780
+	 * @access   private
1781
+	 */
1782
+	function xdebug($string)
1783
+	{
1784
+		$this->debug('<' . $this->schemaTargetNamespace . '> ' . $string);
1785
+	}
1786
+
1787
+	/**
1788
+	 * get the PHP type of a user defined type in the schema
1789
+	 * PHP type is kind of a misnomer since it actually returns 'struct' for assoc. arrays
1790
+	 * returns false if no type exists, or not w/ the given namespace
1791
+	 * else returns a string that is either a native php type, or 'struct'
1792
+	 *
1793
+	 * @param string $type name of defined type
1794
+	 * @param string $ns namespace of type
1795
+	 * @return mixed
1796
+	 * @access public
1797
+	 * @deprecated
1798
+	 */
1799
+	function getPHPType($type, $ns)
1800
+	{
1801
+		if (isset($this->typemap[$ns][$type])) {
1802
+			//print "found type '$type' and ns $ns in typemap<br>";
1803
+			return $this->typemap[$ns][$type];
1804
+		} elseif (isset($this->complexTypes[$type])) {
1805
+			//print "getting type '$type' and ns $ns from complexTypes array<br>";
1806
+			return $this->complexTypes[$type]['phpType'];
1807
+		}
1808
+		return false;
1809
+	}
1810
+
1811
+	/**
1812
+	 * returns an associative array of information about a given type
1813
+	 * returns false if no type exists by the given name
1814
+	 *
1815
+	 *    For a complexType typeDef = array(
1816
+	 *    'restrictionBase' => '',
1817
+	 *    'phpType' => '',
1818
+	 *    'compositor' => '(sequence|all)',
1819
+	 *    'elements' => array(), // refs to elements array
1820
+	 *    'attrs' => array() // refs to attributes array
1821
+	 *    ... and so on (see addComplexType)
1822
+	 *    )
1823
+	 *
1824
+	 *   For simpleType or element, the array has different keys.
1825
+	 *
1826
+	 * @param string $type
1827
+	 * @return mixed
1828
+	 * @access public
1829
+	 * @see addComplexType
1830
+	 * @see addSimpleType
1831
+	 * @see addElement
1832
+	 */
1833
+	function getTypeDef($type)
1834
+	{
1835
+		//$this->debug("in getTypeDef for type $type");
1836
+		if (substr($type, -1) == '^') {
1837
+			$is_element = 1;
1838
+			$type = substr($type, 0, -1);
1839
+		} else {
1840
+			$is_element = 0;
1841
+		}
1842
+
1843
+		if ((!$is_element) && isset($this->complexTypes[$type])) {
1844
+			$this->xdebug("in getTypeDef, found complexType $type");
1845
+			return $this->complexTypes[$type];
1846
+		} elseif ((!$is_element) && isset($this->simpleTypes[$type])) {
1847
+			$this->xdebug("in getTypeDef, found simpleType $type");
1848
+			if (!isset($this->simpleTypes[$type]['phpType'])) {
1849
+				// get info for type to tack onto the simple type
1850
+				// TODO: can this ever really apply (i.e. what is a simpleType really?)
1851
+				$uqType = substr($this->simpleTypes[$type]['type'], strrpos($this->simpleTypes[$type]['type'], ':') + 1);
1852
+				$etype = $this->getTypeDef($uqType);
1853
+				if ($etype) {
1854
+					$this->xdebug("in getTypeDef, found type for simpleType $type:");
1855
+					$this->xdebug($this->varDump($etype));
1856
+					if (isset($etype['phpType'])) {
1857
+						$this->simpleTypes[$type]['phpType'] = $etype['phpType'];
1858
+					}
1859
+					if (isset($etype['elements'])) {
1860
+						$this->simpleTypes[$type]['elements'] = $etype['elements'];
1861
+					}
1862
+				}
1863
+			}
1864
+			return $this->simpleTypes[$type];
1865
+		} elseif (isset($this->elements[$type])) {
1866
+			$this->xdebug("in getTypeDef, found element $type");
1867
+			if (!isset($this->elements[$type]['phpType'])) {
1868
+				// get info for type to tack onto the element
1869
+				$uqType = substr($this->elements[$type]['type'], strrpos($this->elements[$type]['type'], ':') + 1);
1870
+				$ns = substr($this->elements[$type]['type'], 0, strrpos($this->elements[$type]['type'], ':'));
1871
+				$etype = $this->getTypeDef($uqType);
1872
+				if ($etype) {
1873
+					$this->xdebug("in getTypeDef, found type for element $type:");
1874
+					$this->xdebug($this->varDump($etype));
1875
+					if (isset($etype['phpType'])) {
1876
+						$this->elements[$type]['phpType'] = $etype['phpType'];
1877
+					}
1878
+					if (isset($etype['elements'])) {
1879
+						$this->elements[$type]['elements'] = $etype['elements'];
1880
+					}
1881
+					if (isset($etype['extensionBase'])) {
1882
+						$this->elements[$type]['extensionBase'] = $etype['extensionBase'];
1883
+					}
1884
+				} elseif ($ns == 'http://www.w3.org/2001/XMLSchema') {
1885
+					$this->xdebug("in getTypeDef, element $type is an XSD type");
1886
+					$this->elements[$type]['phpType'] = 'scalar';
1887
+				}
1888
+			}
1889
+			return $this->elements[$type];
1890
+		} elseif (isset($this->attributes[$type])) {
1891
+			$this->xdebug("in getTypeDef, found attribute $type");
1892
+			return $this->attributes[$type];
1893
+		} elseif (preg_match('/_ContainedType$/', $type)) {
1894
+			$this->xdebug("in getTypeDef, have an untyped element $type");
1895
+			$typeDef['typeClass'] = 'simpleType';
1896
+			$typeDef['phpType'] = 'scalar';
1897
+			$typeDef['type'] = 'http://www.w3.org/2001/XMLSchema:string';
1898
+			return $typeDef;
1899
+		}
1900
+		$this->xdebug("in getTypeDef, did not find $type");
1901
+		return false;
1902
+	}
1903
+
1904
+	/**
1905
+	 * returns a sample serialization of a given type, or false if no type by the given name
1906
+	 *
1907
+	 * @param string $type name of type
1908
+	 * @return false|string
1909
+	 * @access public
1910
+	 */
1911
+	function serializeTypeDef($type)
1912
+	{
1913
+		$str = '';
1914
+		//print "in sTD() for type $type<br>";
1915
+		if ($typeDef = $this->getTypeDef($type)) {
1916
+			$str .= '<' . $type;
1917
+			if (is_array($typeDef['attrs'])) {
1918
+				foreach ($typeDef['attrs'] as $attName => $data) {
1919
+					$str .= " $attName=\"{type = " . $data['type'] . "}\"";
1920
+				}
1921
+			}
1922
+			$str .= " xmlns=\"" . $this->schema['targetNamespace'] . "\"";
1923
+			if (count($typeDef['elements']) > 0) {
1924
+				$str .= ">";
1925
+				foreach ($typeDef['elements'] as $element => $eData) {
1926
+					$str .= $this->serializeTypeDef($element);
1927
+				}
1928
+				$str .= "</$type>";
1929
+			} elseif ($typeDef['typeClass'] == 'element') {
1930
+				$str .= "></$type>";
1931
+			} else {
1932
+				$str .= "/>";
1933
+			}
1934
+			return $str;
1935
+		}
1936
+		return false;
1937
+	}
1938
+
1939
+	/**
1940
+	 * returns HTML form elements that allow a user
1941
+	 * to enter values for creating an instance of the given type.
1942
+	 *
1943
+	 * @param string $name name for type instance
1944
+	 * @param string $type name of type
1945
+	 * @return string
1946
+	 * @access public
1947
+	 * @deprecated
1948
+	 */
1949
+	function typeToForm($name, $type)
1950
+	{
1951
+		$buffer = '';
1952
+		// get typedef
1953
+		if ($typeDef = $this->getTypeDef($type)) {
1954
+			// if struct
1955
+			if ($typeDef['phpType'] == 'struct') {
1956
+				$buffer .= '<table>';
1957
+				foreach ($typeDef['elements'] as $childDef) {
1958
+					$buffer .= "
1959
+					<tr><td align='right'>$childDef[name] (type: " . $this->getLocalPart($childDef['type']) . "):</td>
1960
+					<td><input type='text' name='parameters[" . $name . "][$childDef[name]]'></td></tr>";
1961
+				}
1962
+				$buffer .= '</table>';
1963
+				// if array
1964
+			} elseif ($typeDef['phpType'] == 'array') {
1965
+				$buffer .= '<table>';
1966
+			  $buffer .= str_repeat ("
1967
+					<tr><td align='right'>array item (type: $typeDef[arrayType]):</td>
1968
+					<td><input type='text' name='parameters[" . $name . "][]'></td></tr>", 3);
1969
+				$buffer .= '</table>';
1970
+				// if scalar
1971
+			} else {
1972
+				$buffer .= "<input type='text' name='parameters[$name]'>";
1973
+			}
1974
+		} else {
1975
+			$buffer .= "<input type='text' name='parameters[$name]'>";
1976
+		}
1977
+		return $buffer;
1978
+	}
1979
+
1980
+	/**
1981
+	 * adds a complex type to the schema
1982
+	 * example: array
1983
+	 * addType(
1984
+	 *    'ArrayOfstring',
1985
+	 *    'complexType',
1986
+	 *    'array',
1987
+	 *    '',
1988
+	 *    'SOAP-ENC:Array',
1989
+	 *    array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'string[]'),
1990
+	 *    'xsd:string'
1991
+	 * );
1992
+	 * example: PHP associative array ( SOAP Struct )
1993
+	 * addType(
1994
+	 *    'SOAPStruct',
1995
+	 *    'complexType',
1996
+	 *    'struct',
1997
+	 *    'all',
1998
+	 *    array('myVar'=> array('name'=>'myVar','type'=>'string')
1999
+	 * );
2000
+	 *
2001
+	 * @param string $name
2002
+	 * @param string $typeClass (complexType|simpleType|attribute)
2003
+	 * @param string $phpType : currently supported are array and struct (php assoc array)
2004
+	 * @param string $compositor (all|sequence|choice)
2005
+	 * @param string $restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
2006
+	 * @param array $elements = array ( name = array(name=>'',type=>'') )
2007
+	 * @param array $attrs = array(
2008
+	 *    array(
2009
+	 *        'ref' => "http://schemas.xmlsoap.org/soap/encoding/:arrayType",
2010
+	 *        "http://schemas.xmlsoap.org/wsdl/:arrayType" => "string[]"
2011
+	 *    )
2012
+	 * )
2013
+	 * @param array $arrayType : namespace:name (http://www.w3.org/2001/XMLSchema:string)
2014
+	 *
2015
+	 * @access public
2016
+	 * @see getTypeDef
2017
+	 */
2018
+	function addComplexType($name, $typeClass = 'complexType', $phpType = 'array', $compositor = '', $restrictionBase = '', $elements = array(), $attrs = array(), $arrayType = '')
2019
+	{
2020
+		$this->complexTypes[$name] = array(
2021
+			'name' => $name,
2022
+			'typeClass' => $typeClass,
2023
+			'phpType' => $phpType,
2024
+			'compositor' => $compositor,
2025
+			'restrictionBase' => $restrictionBase,
2026
+			'elements' => $elements,
2027
+			'attrs' => $attrs,
2028
+			'arrayType' => $arrayType
2029
+		);
2030
+
2031
+		$this->xdebug("addComplexType $name:");
2032
+		$this->appendDebug($this->varDump($this->complexTypes[$name]));
2033
+	}
2034
+
2035
+	/**
2036
+	 * adds a simple type to the schema
2037
+	 *
2038
+	 * @param string $name
2039
+	 * @param string $restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
2040
+	 * @param string $typeClass (should always be simpleType)
2041
+	 * @param string $phpType (should always be scalar)
2042
+	 * @param array $enumeration array of values
2043
+	 * @access public
2044
+	 * @see nusoap_xmlschema
2045
+	 * @see getTypeDef
2046
+	 */
2047
+	function addSimpleType($name, $restrictionBase = '', $typeClass = 'simpleType', $phpType = 'scalar', $enumeration = array())
2048
+	{
2049
+		$this->simpleTypes[$name] = array(
2050
+			'name' => $name,
2051
+			'typeClass' => $typeClass,
2052
+			'phpType' => $phpType,
2053
+			'type' => $restrictionBase,
2054
+			'enumeration' => $enumeration
2055
+		);
2056
+
2057
+		$this->xdebug("addSimpleType $name:");
2058
+		$this->appendDebug($this->varDump($this->simpleTypes[$name]));
2059
+	}
2060
+
2061
+	/**
2062
+	 * adds an element to the schema
2063
+	 *
2064
+	 * @param array $attrs attributes that must include name and type
2065
+	 * @see nusoap_xmlschema
2066
+	 * @access public
2067
+	 */
2068
+	function addElement($attrs)
2069
+	{
2070
+		if (!$this->getPrefix($attrs['type'])) {
2071
+			$attrs['type'] = $this->schemaTargetNamespace . ':' . $attrs['type'];
2072
+		}
2073
+		$this->elements[$attrs['name']] = $attrs;
2074
+		$this->elements[$attrs['name']]['typeClass'] = 'element';
2075
+
2076
+		$this->xdebug("addElement " . $attrs['name']);
2077
+		$this->appendDebug($this->varDump($this->elements[$attrs['name']]));
2078
+	}
2079
+}
2080
+
2081
+/**
2082
+ * Backward compatibility
2083
+ */
2084
+class XMLSchema extends nusoap_xmlschema
2085
+{
2086
+}
2087
+
2088
+
2089
+/**
2090
+ * For creating serializable abstractions of native PHP types.  This class
2091
+ * allows element name/namespace, XSD type, and XML attributes to be
2092
+ * associated with a value.  This is extremely useful when WSDL is not
2093
+ * used, but is also useful when WSDL is used with polymorphic types, including
2094
+ * xsd:anyType and user-defined types.
2095
+ *
3534 2096
  * @author   Dietrich Ayala <[email protected]>
3535
- * @author   Scott Nichol <[email protected]>
3536 2097
  * @version  $Id: nusoap.php,v 1.123 2010/04/26 20:15:08 snichol Exp $
3537 2098
  * @access   public
3538 2099
  */
3539
-class nusoap_server extends nusoap_base
2100
+class soapval extends nusoap_base
3540 2101
 {
3541
-    /**
3542
-     * HTTP headers of request
3543
-     *
3544
-     * @var array
3545
-     * @access private
3546
-     */
3547
-    var $headers = array();
3548
-    /**
3549
-     * HTTP request
3550
-     *
3551
-     * @var string
3552
-     * @access private
3553
-     */
3554
-    var $request = '';
3555
-    /**
3556
-     * SOAP headers from request (incomplete namespace resolution; special characters not escaped) (text)
3557
-     *
3558
-     * @var string
3559
-     * @access public
3560
-     */
3561
-    var $requestHeaders = '';
3562
-    /**
3563
-     * SOAP Headers from request (parsed)
3564
-     *
3565
-     * @var mixed
3566
-     * @access public
3567
-     */
3568
-    var $requestHeader = null;
3569
-    /**
3570
-     * SOAP body request portion (incomplete namespace resolution; special characters not escaped) (text)
3571
-     *
3572
-     * @var string
3573
-     * @access public
3574
-     */
3575
-    var $document = '';
3576
-    /**
3577
-     * SOAP payload for request (text)
3578
-     *
3579
-     * @var string
3580
-     * @access public
3581
-     */
3582
-    var $requestSOAP = '';
3583
-    /**
3584
-     * requested method namespace URI
3585
-     *
3586
-     * @var string
3587
-     * @access private
3588
-     */
3589
-    var $methodURI = '';
3590
-    /**
3591
-     * name of method requested
3592
-     *
3593
-     * @var string
3594
-     * @access private
3595
-     */
3596
-    var $methodname = '';
3597
-    /**
3598
-     * name of the response tag name
3599
-     *
3600
-     * @var string
3601
-     * @access private
3602
-     */
3603
-    var $responseTagName = '';
3604
-    /**
3605
-     * method parameters from request
3606
-     *
3607
-     * @var array
3608
-     * @access private
3609
-     */
3610
-    var $methodparams = array();
3611
-    /**
3612
-     * SOAP Action from request
3613
-     *
3614
-     * @var string
3615
-     * @access private
3616
-     */
3617
-    var $SOAPAction = '';
3618
-    /**
3619
-     * character set encoding of incoming (request) messages
3620
-     *
3621
-     * @var string
3622
-     * @access public
3623
-     */
3624
-    var $xml_encoding = '';
3625
-    /**
3626
-     * toggles whether the parser decodes element content w/ utf8_decode()
3627
-     *
3628
-     * @var boolean
3629
-     * @access public
3630
-     */
3631
-    var $decode_utf8 = true;
3632
-
3633
-    /**
3634
-     * HTTP headers of response
3635
-     *
3636
-     * @var array
3637
-     * @access public
3638
-     */
3639
-    var $outgoing_headers = array();
3640
-    /**
3641
-     * HTTP response
3642
-     *
3643
-     * @var string
3644
-     * @access private
3645
-     */
3646
-    var $response = '';
3647
-    /**
3648
-     * SOAP headers for response (text or array of soapval or associative array)
3649
-     *
3650
-     * @var mixed
3651
-     * @access public
3652
-     */
3653
-    var $responseHeaders = '';
3654
-    /**
3655
-     * SOAP payload for response (text)
3656
-     *
3657
-     * @var string
3658
-     * @access private
3659
-     */
3660
-    var $responseSOAP = '';
3661
-    /**
3662
-     * SOAP attachments in response
3663
-     *
3664
-     * @var string
3665
-     * @access private
3666
-     */
3667
-    var $attachments= '';
3668
-    /**
3669
-     * method return value to place in response
3670
-     *
3671
-     * @var mixed
3672
-     * @access private
3673
-     */
3674
-    var $methodreturn = false;
3675
-    /**
3676
-     * whether $methodreturn is a string of literal XML
3677
-     *
3678
-     * @var boolean
3679
-     * @access public
3680
-     */
3681
-    var $methodreturnisliteralxml = false;
3682
-    /**
3683
-     * SOAP fault for response (or false)
3684
-     *
3685
-     * @var mixed
3686
-     * @access private
3687
-     */
3688
-    var $fault = false;
3689
-    /**
3690
-     * text indication of result (for debugging)
3691
-     *
3692
-     * @var string
3693
-     * @access private
3694
-     */
3695
-    var $result = 'successful';
3696
-
3697
-    /**
3698
-     * assoc array of operations => opData; operations are added by the register()
3699
-     * method or by parsing an external WSDL definition
3700
-     *
3701
-     * @var array
3702
-     * @access private
3703
-     */
3704
-    var $operations = array();
3705
-    /**
3706
-     * wsdl instance (if one)
3707
-     *
3708
-     * @var mixed
3709
-     * @access private
3710
-     */
3711
-    var $wsdl = false;
3712
-    /**
3713
-     * URL for WSDL (if one)
3714
-     *
3715
-     * @var mixed
3716
-     * @access private
3717
-     */
3718
-    var $externalWSDLURL = false;
3719
-    /**
3720
-     * whether to append debug to response as XML comment
3721
-     *
3722
-     * @var boolean
3723
-     * @access public
3724
-     */
3725
-    var $debug_flag = false;
3726
-
3727
-    /** @var array */
3728
-    var $opData;
3729
-
3730
-
3731
-    /**
3732
-     * constructor
3733
-     * the optional parameter is a path to a WSDL file that you'd like to bind the server instance to.
3734
-     *
3735
-     * @param mixed $wsdl file path or URL (string), or wsdl instance (object)
3736
-     * @access   public
3737
-     */
3738
-    function __construct($wsdl = false)
3739
-    {
3740
-        parent::__construct();
3741
-        // turn on debugging?
3742
-        global $debug;
3743
-        global $HTTP_SERVER_VARS;
3744
-
3745
-        if (isset($_SERVER)) {
3746
-            $this->debug("_SERVER is defined:");
3747
-            $this->appendDebug($this->varDump($_SERVER));
3748
-        } elseif (isset($HTTP_SERVER_VARS)) {
3749
-            $this->debug("HTTP_SERVER_VARS is defined:");
3750
-            $this->appendDebug($this->varDump($HTTP_SERVER_VARS));
3751
-        } else {
3752
-            $this->debug("Neither _SERVER nor HTTP_SERVER_VARS is defined.");
3753
-        }
3754
-
3755
-        if (isset($debug)) {
3756
-            $this->debug("In nusoap_server, set debug_flag=$debug based on global flag");
3757
-            $this->debug_flag = $debug;
3758
-        } elseif (isset($_SERVER['QUERY_STRING'])) {
3759
-            $qs = explode('&', $_SERVER['QUERY_STRING']);
3760
-            foreach ($qs as $v) {
3761
-                if (substr($v, 0, 6) == 'debug=') {
3762
-                    $this->debug("In nusoap_server, set debug_flag=" . substr($v, 6) . " based on query string #1");
3763
-                    $this->debug_flag = substr($v, 6);
3764
-                }
3765
-            }
3766
-        } elseif (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
3767
-            $qs = explode('&', $HTTP_SERVER_VARS['QUERY_STRING']);
3768
-            foreach ($qs as $v) {
3769
-                if (substr($v, 0, 6) == 'debug=') {
3770
-                    $this->debug("In nusoap_server, set debug_flag=" . substr($v, 6) . " based on query string #2");
3771
-                    $this->debug_flag = substr($v, 6);
3772
-                }
3773
-            }
3774
-        }
3775
-
3776
-        // wsdl
3777
-        if ($wsdl) {
3778
-            $this->debug("In nusoap_server, WSDL is specified");
3779
-            if (is_object($wsdl) && (get_class($wsdl) == 'wsdl')) {
3780
-                $this->wsdl = $wsdl;
3781
-                $this->externalWSDLURL = $this->wsdl->wsdl;
3782
-                $this->debug('Use existing wsdl instance from ' . $this->externalWSDLURL);
3783
-            } else {
3784
-                $this->debug('Create wsdl from ' . $wsdl);
3785
-                $this->wsdl = new wsdl($wsdl);
3786
-                $this->externalWSDLURL = $wsdl;
3787
-            }
3788
-            $this->appendDebug($this->wsdl->getDebug());
3789
-            $this->wsdl->clearDebug();
3790
-            if ($err = $this->wsdl->getError()) {
3791
-                die('WSDL ERROR: ' . $err);
3792
-            }
3793
-        }
3794
-    }
3795
-
3796
-    /**
3797
-     * processes request and returns response
3798
-     *
3799
-     * @param    string $data usually is the value of $HTTP_RAW_POST_DATA
3800
-     * @access   public
3801
-     */
3802
-    function service($data)
3803
-    {
3804
-        global $HTTP_SERVER_VARS;
3805
-
3806
-        if (isset($_SERVER['REQUEST_METHOD'])) {
3807
-            $rm = $_SERVER['REQUEST_METHOD'];
3808
-        } elseif (isset($HTTP_SERVER_VARS['REQUEST_METHOD'])) {
3809
-            $rm = $HTTP_SERVER_VARS['REQUEST_METHOD'];
3810
-        } else {
3811
-            $rm = '';
3812
-        }
3813
-
3814
-        if (isset($_SERVER['QUERY_STRING'])) {
3815
-            $qs = $_SERVER['QUERY_STRING'];
3816
-        } elseif (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
3817
-            $qs = $HTTP_SERVER_VARS['QUERY_STRING'];
3818
-        } else {
3819
-            $qs = '';
3820
-        }
3821
-        $this->debug("In service, request method=$rm query string=$qs strlen(\$data)=" . strlen($data));
3822
-
3823
-        if ($rm == 'POST') {
3824
-            $this->debug("In service, invoke the request");
3825
-            $this->parse_request($data);
3826
-            if (!$this->fault) {
3827
-                $this->invoke_method();
3828
-            }
3829
-            if (!$this->fault) {
3830
-                $this->serialize_return();
3831
-            }
3832
-            $this->send_response();
3833
-        } elseif (preg_match('/wsdl/', $qs)) {
3834
-            $this->debug("In service, this is a request for WSDL");
3835
-            if ($this->externalWSDLURL) {
3836
-                if (strpos($this->externalWSDLURL, "http://") !== false) { // assume URL
3837
-                    $this->debug("In service, re-direct for WSDL");
3838
-                    header('Location: ' . $this->externalWSDLURL);
3839
-                } else { // assume file
3840
-                    $this->debug("In service, use file passthru for WSDL");
3841
-                    header("Content-Type: text/xml\r\n");
3842
-                    $fp = fopen($this->externalWSDLURL, 'r');
3843
-                    fpassthru($fp);
3844
-                }
3845
-            } elseif ($this->wsdl) {
3846
-                $this->debug("In service, serialize WSDL");
3847
-                header("Content-Type: text/xml; charset=ISO-8859-1\r\n");
3848
-                print $this->wsdl->serialize($this->debug_flag);
3849
-                if ($this->debug_flag) {
3850
-                    $this->debug('wsdl:');
3851
-                    $this->appendDebug($this->varDump($this->wsdl));
3852
-                    print $this->getDebugAsXMLComment();
3853
-                }
3854
-            } else {
3855
-                $this->debug("In service, there is no WSDL");
3856
-                header("Content-Type: text/html; charset=ISO-8859-1\r\n");
3857
-                print "This service does not provide WSDL";
3858
-            }
3859
-        } elseif ($this->wsdl) {
3860
-            $this->debug("In service, return Web description");
3861
-            print $this->wsdl->webDescription();
3862
-        } else {
3863
-            $this->debug("In service, no Web description");
3864
-            header("Content-Type: text/html; charset=ISO-8859-1\r\n");
3865
-            print "This service does not provide a Web description";
3866
-        }
3867
-    }
3868
-
3869
-    /**
3870
-     * parses HTTP request headers.
3871
-     *
3872
-     * The following fields are set by this function (when successful)
3873
-     *
3874
-     * headers
3875
-     * request
3876
-     * xml_encoding
3877
-     * SOAPAction
3878
-     *
3879
-     * @access   private
3880
-     */
3881
-    function parse_http_headers()
3882
-    {
3883
-        global $HTTP_SERVER_VARS;
3884
-
3885
-        $this->request = '';
3886
-        $this->SOAPAction = '';
3887
-        if (function_exists('getallheaders')) {
3888
-            $this->debug("In parse_http_headers, use getallheaders");
3889
-            $headers = getallheaders();
3890
-            foreach ($headers as $k => $v) {
3891
-                $k = strtolower($k);
3892
-                $this->headers[$k] = $v;
3893
-                $this->request .= "$k: $v\r\n";
3894
-                $this->debug("$k: $v");
3895
-            }
3896
-            // get SOAPAction header
3897
-            if (isset($this->headers['soapaction'])) {
3898
-                $this->SOAPAction = str_replace('"', '', $this->headers['soapaction']);
3899
-            }
3900
-            // get the character encoding of the incoming request
3901
-            if (isset($this->headers['content-type']) && strpos($this->headers['content-type'], '=')) {
3902
-                $enc = str_replace('"', '', substr(strstr($this->headers["content-type"], '='), 1));
3903
-                if (preg_match('/^(ISO-8859-1|US-ASCII|UTF-8)$/i', $enc)) {
3904
-                    $this->xml_encoding = strtoupper($enc);
3905
-                } else {
3906
-                    $this->xml_encoding = 'US-ASCII';
3907
-                }
3908
-            } else {
3909
-                // should be US-ASCII for HTTP 1.0 or ISO-8859-1 for HTTP 1.1
3910
-                $this->xml_encoding = 'ISO-8859-1';
3911
-            }
3912
-        } elseif (isset($_SERVER) && is_array($_SERVER)) {
3913
-            $this->debug("In parse_http_headers, use _SERVER");
3914
-            foreach ($_SERVER as $k => $v) {
3915
-                if (substr($k, 0, 5) == 'HTTP_') {
3916
-                    $k = str_replace(' ', '-', strtolower(str_replace('_', ' ', substr($k, 5))));
3917
-                } else {
3918
-                    $k = str_replace(' ', '-', strtolower(str_replace('_', ' ', $k)));
3919
-                }
3920
-                if ($k == 'soapaction') {
3921
-                    // get SOAPAction header
3922
-                    $k = 'SOAPAction';
3923
-                    $v = str_replace('"', '', $v);
3924
-                    $v = str_replace('\\', '', $v);
3925
-                    $this->SOAPAction = $v;
3926
-                } elseif ($k == 'content-type') {
3927
-                    // get the character encoding of the incoming request
3928
-                    if (strpos($v, '=')) {
3929
-                        $enc = substr(strstr($v, '='), 1);
3930
-                        $enc = str_replace('"', '', $enc);
3931
-                        $enc = str_replace('\\', '', $enc);
3932
-                        if (preg_match('/^(ISO-8859-1|US-ASCII|UTF-8)$/i', $enc)) {
3933
-                            $this->xml_encoding = strtoupper($enc);
3934
-                        } else {
3935
-                            $this->xml_encoding = 'US-ASCII';
3936
-                        }
3937
-                    } else {
3938
-                        // should be US-ASCII for HTTP 1.0 or ISO-8859-1 for HTTP 1.1
3939
-                        $this->xml_encoding = 'ISO-8859-1';
3940
-                    }
3941
-                }
3942
-                $this->headers[$k] = $v;
3943
-                if (is_array($v)) {
3944
-                    $this->request .= "$k: " . json_encode($v) . "\r\n";
3945
-                    $this->debug("$k: " . json_encode($v));
3946
-                } else {
3947
-                    $this->request .= "$k: $v\r\n";
3948
-                    $this->debug("$k: $v");
3949
-                }
3950
-            }
3951
-        } elseif (is_array($HTTP_SERVER_VARS)) {
3952
-            $this->debug("In parse_http_headers, use HTTP_SERVER_VARS");
3953
-            foreach ($HTTP_SERVER_VARS as $k => $v) {
3954
-                if (substr($k, 0, 5) == 'HTTP_') {
3955
-                    $k = str_replace(' ', '-', strtolower(str_replace('_', ' ', substr($k, 5))));
3956
-                    $k = strtolower(substr($k, 5));
3957
-                } else {
3958
-                    $k = str_replace(' ', '-', strtolower(str_replace('_', ' ', $k)));
3959
-                    $k = strtolower($k);
3960
-                }
3961
-                if ($k == 'soapaction') {
3962
-                    // get SOAPAction header
3963
-                    $k = 'SOAPAction';
3964
-                    $v = str_replace('"', '', $v);
3965
-                    $v = str_replace('\\', '', $v);
3966
-                    $this->SOAPAction = $v;
3967
-                } elseif ($k == 'content-type') {
3968
-                    // get the character encoding of the incoming request
3969
-                    if (strpos($v, '=')) {
3970
-                        $enc = substr(strstr($v, '='), 1);
3971
-                        $enc = str_replace('"', '', $enc);
3972
-                        $enc = str_replace('\\', '', $enc);
3973
-                        if (preg_match('/^(ISO-8859-1|US-ASCII|UTF-8)$/i', $enc)) {
3974
-                            $this->xml_encoding = strtoupper($enc);
3975
-                        } else {
3976
-                            $this->xml_encoding = 'US-ASCII';
3977
-                        }
3978
-                    } else {
3979
-                        // should be US-ASCII for HTTP 1.0 or ISO-8859-1 for HTTP 1.1
3980
-                        $this->xml_encoding = 'ISO-8859-1';
3981
-                    }
3982
-                }
3983
-                $this->headers[$k] = $v;
3984
-                $this->request .= "$k: $v\r\n";
3985
-                $this->debug("$k: $v");
3986
-            }
3987
-        } else {
3988
-            $this->debug("In parse_http_headers, HTTP headers not accessible");
3989
-            $this->setError("HTTP headers not accessible");
3990
-        }
3991
-    }
3992
-
3993
-    /**
3994
-     * parses a request
3995
-     *
3996
-     * The following fields are set by this function (when successful)
3997
-     *
3998
-     * headers
3999
-     * request
4000
-     * xml_encoding
4001
-     * SOAPAction
4002
-     * request
4003
-     * requestSOAP
4004
-     * methodURI
4005
-     * methodname
4006
-     * methodparams
4007
-     * requestHeaders
4008
-     * document
4009
-     *
4010
-     * This sets the fault field on error
4011
-     *
4012
-     * @param    string $data XML string
4013
-     * @access   private
4014
-     */
4015
-    function parse_request($data = '')
4016
-    {
4017
-        $this->debug('entering parse_request()');
4018
-        $this->parse_http_headers();
4019
-        $this->debug('got character encoding: ' . $this->xml_encoding);
4020
-        // uncompress if necessary
4021
-        if (isset($this->headers['content-encoding']) && $this->headers['content-encoding'] != '') {
4022
-            $this->debug('got content encoding: ' . $this->headers['content-encoding']);
4023
-            if ($this->headers['content-encoding'] == 'deflate' || $this->headers['content-encoding'] == 'gzip') {
4024
-                // if decoding works, use it. else assume data wasn't gzencoded
4025
-                if (function_exists('gzuncompress')) {
4026
-                    if ($this->headers['content-encoding'] == 'deflate' && $degzdata = @gzuncompress($data)) {
4027
-                        $data = $degzdata;
4028
-                    } elseif ($this->headers['content-encoding'] == 'gzip' && $degzdata = gzinflate(substr($data, 10))) {
4029
-                        $data = $degzdata;
4030
-                    } else {
4031
-                        $this->fault('SOAP-ENV:Client', 'Errors occurred when trying to decode the data');
4032
-                        return;
4033
-                    }
4034
-                } else {
4035
-                    $this->fault('SOAP-ENV:Client', 'This Server does not support compressed data');
4036
-                    return;
4037
-                }
4038
-            }
4039
-        }
4040
-        $this->request .= "\r\n" . $data;
4041
-        $data = $this->parseRequest($this->headers, $data);
4042
-        $this->requestSOAP = $data;
4043
-        $this->debug('leaving parse_request');
4044
-    }
4045
-
4046
-    /**
4047
-     * invokes a PHP function for the requested SOAP method
4048
-     *
4049
-     * The following fields are set by this function (when successful)
4050
-     *
4051
-     * methodreturn
4052
-     *
4053
-     * Note that the PHP function that is called may also set the following
4054
-     * fields to affect the response sent to the client
4055
-     *
4056
-     * responseHeaders
4057
-     * outgoing_headers
4058
-     *
4059
-     * This sets the fault field on error
4060
-     *
4061
-     * @access   private
4062
-     */
4063
-    function invoke_method()
4064
-    {
4065
-        $this->debug('in invoke_method, methodname=' . $this->methodname . ' methodURI=' . $this->methodURI . ' SOAPAction=' . $this->SOAPAction);
4066
-
4067
-        //
4068
-        // if you are debugging in this area of the code, your service uses a class to implement methods,
4069
-        // you use SOAP RPC, and the client is .NET, please be aware of the following...
4070
-        // when the .NET wsdl.exe utility generates a proxy, it will remove the '.' or '..' from the
4071
-        // method name.  that is fine for naming the .NET methods.  it is not fine for properly constructing
4072
-        // the XML request and reading the XML response.  you need to add the RequestElementName and
4073
-        // ResponseElementName to the System.Web.Services.Protocols.SoapRpcMethodAttribute that wsdl.exe
4074
-        // generates for the method.  these parameters are used to specify the correct XML element names
4075
-        // for .NET to use, i.e. the names with the '.' in them.
4076
-        //
4077
-        $orig_methodname = $this->methodname;
4078
-        if ($this->wsdl) {
4079
-            if ($this->opData = $this->wsdl->getOperationData($this->methodname)) {
4080
-                $this->debug('in invoke_method, found WSDL operation=' . $this->methodname);
4081
-                $this->appendDebug('opData=' . $this->varDump($this->opData));
4082
-            } elseif ($this->opData = $this->wsdl->getOperationDataForSoapAction($this->SOAPAction)) {
4083
-                // Note: hopefully this case will only be used for doc/lit, since rpc services should have wrapper element
4084
-                $this->debug('in invoke_method, found WSDL soapAction=' . $this->SOAPAction . ' for operation=' . $this->opData['name']);
4085
-                $this->appendDebug('opData=' . $this->varDump($this->opData));
4086
-                $this->methodname = $this->opData['name'];
4087
-            } else {
4088
-                $this->debug('in invoke_method, no WSDL for operation=' . $this->methodname);
4089
-                $this->fault('SOAP-ENV:Client', "Operation '" . $this->methodname . "' is not defined in the WSDL for this service");
4090
-                return;
4091
-            }
4092
-        } else {
4093
-            $this->debug('in invoke_method, no WSDL to validate method');
4094
-        }
4095
-
4096
-        // if a . is present in $this->methodname, we see if there is a class in scope,
4097
-        // which could be referred to. We will also distinguish between two deliminators,
4098
-        // to allow methods to be called a the class or an instance
4099
-        if (strpos($this->methodname, '..') > 0) {
4100
-            $delim = '..';
4101
-        } elseif (strpos($this->methodname, '.') > 0) {
4102
-            $delim = '.';
4103
-        } else {
4104
-            $delim = '';
4105
-        }
4106
-        $this->debug("in invoke_method, delim=$delim");
4107
-
4108
-        $class = '';
4109
-        $method = '';
4110
-        $try_class = '';
4111
-        if (strlen($delim) > 0 && substr_count($this->methodname, $delim) == 1) {
4112
-            $try_class = substr($this->methodname, 0, strpos($this->methodname, $delim));
4113
-            if (class_exists($try_class)) {
4114
-                // get the class and method name
4115
-                $class = $try_class;
4116
-                $method = substr($this->methodname, strpos($this->methodname, $delim) + strlen($delim));
4117
-                $this->debug("in invoke_method, class=$class method=$method delim=$delim");
4118
-            } else {
4119
-                $this->debug("in invoke_method, class=$try_class not found");
4120
-            }
4121
-        } elseif (strlen($delim) > 0 && substr_count($this->methodname, $delim) > 1) {
4122
-            $split = explode($delim, $this->methodname);
4123
-            $method = array_pop($split);
4124
-            $class = implode('\\', $split);
4125
-        } else {
4126
-            $this->debug("in invoke_method, no class to try");
4127
-        }
4128
-
4129
-        // does method exist?
4130
-        if ($class == '') {
4131
-            if (!function_exists($this->methodname)) {
4132
-                $this->debug("in invoke_method, function '$this->methodname' not found!");
4133
-                $this->result = 'fault: method not found';
4134
-                $this->fault('SOAP-ENV:Client', "method '$this->methodname'('$orig_methodname') not defined in service('$try_class' '$delim')");
4135
-                return;
4136
-            }
4137
-        } else {
4138
-            $method_to_compare = (substr(phpversion(), 0, 2) == '4.') ? strtolower($method) : $method;
4139
-            if (!in_array($method_to_compare, get_class_methods($class))) {
4140
-                $this->debug("in invoke_method, method '$this->methodname' not found in class '$class'!");
4141
-                $this->result = 'fault: method not found';
4142
-                $this->fault('SOAP-ENV:Client', "method '$this->methodname'/'$method_to_compare'('$orig_methodname') not defined in service/'$class'('$try_class' '$delim')");
4143
-                return;
4144
-            }
4145
-        }
4146
-
4147
-        // evaluate message, getting back parameters
4148
-        // verify that request parameters match the method's signature
4149
-        if (!$this->verify_method($this->methodname, $this->methodparams)) {
4150
-            // debug
4151
-            $this->debug('ERROR: request not verified against method signature');
4152
-            $this->result = 'fault: request failed validation against method signature';
4153
-            // return fault
4154
-            $this->fault('SOAP-ENV:Client', "Operation '$this->methodname' not defined in service.");
4155
-            return;
4156
-        }
4157
-
4158
-        // if there are parameters to pass
4159
-        $this->debug('in invoke_method, params:');
4160
-        $this->appendDebug($this->varDump($this->methodparams));
4161
-        $this->debug("in invoke_method, calling '$this->methodname'");
4162
-        if (!function_exists('call_user_func_array')) {
4163
-            if ($class == '') {
4164
-                $this->debug('in invoke_method, calling function using eval()');
4165
-                $funcCall = "\$this->methodreturn = $this->methodname(";
4166
-            } else {
4167
-                if ($delim == '..') {
4168
-                    $this->debug('in invoke_method, calling class method using eval()');
4169
-                    $funcCall = "\$this->methodreturn = " . $class . "::" . $method . "(";
4170
-                } else {
4171
-                    $this->debug('in invoke_method, calling instance method using eval()');
4172
-                    // generate unique instance name
4173
-                    $instname = "\$inst_" . time();
4174
-                    $funcCall = $instname . " = new " . $class . "(); ";
4175
-                    $funcCall .= "\$this->methodreturn = " . $instname . "->" . $method . "(";
4176
-                }
4177
-            }
4178
-            if ($this->methodparams) {
4179
-                foreach ($this->methodparams as $param) {
4180
-                    if (is_array($param) || is_object($param)) {
4181
-                        $this->fault('SOAP-ENV:Client', 'NuSOAP does not handle complexType parameters correctly when using eval; call_user_func_array must be available');
4182
-                        return;
4183
-                    }
4184
-                    $funcCall .= "\"$param\",";
4185
-                }
4186
-                $funcCall = substr($funcCall, 0, -1);
4187
-            }
4188
-            $funcCall .= ');';
4189
-            $this->debug('in invoke_method, function call: ' . $funcCall);
4190
-            @eval($funcCall);
4191
-        } else {
4192
-            if ($class == '') {
4193
-                $this->debug('in invoke_method, calling function using call_user_func_array()');
4194
-                $call_arg = "$this->methodname";    // straight assignment changes $this->methodname to lower case after call_user_func_array()
4195
-            } elseif ($delim == '..') {
4196
-                $this->debug('in invoke_method, calling class method using call_user_func_array()');
4197
-                $call_arg = array($class, $method);
4198
-            } else {
4199
-                $this->debug('in invoke_method, calling instance method using call_user_func_array()');
4200
-                $instance = new $class ();
4201
-                $call_arg = array(&$instance, $method);
4202
-            }
4203
-            if (is_array($this->methodparams)) {
4204
-                $this->methodreturn = call_user_func_array($call_arg, array_values($this->methodparams));
4205
-            } else {
4206
-                $this->methodreturn = call_user_func_array($call_arg, array());
4207
-            }
4208
-        }
4209
-        $this->debug('in invoke_method, methodreturn:');
4210
-        $this->appendDebug($this->varDump($this->methodreturn));
4211
-        $this->debug("in invoke_method, called method $this->methodname, received data of type " . gettype($this->methodreturn));
4212
-    }
4213
-
4214
-    /**
4215
-     * serializes the return value from a PHP function into a full SOAP Envelope
4216
-     *
4217
-     * The following fields are set by this function (when successful)
4218
-     *
4219
-     * responseSOAP
4220
-     *
4221
-     * This sets the fault field on error
4222
-     *
4223
-     * @access   private
4224
-     */
4225
-    function serialize_return()
4226
-    {
4227
-        $this->debug('Entering serialize_return methodname: ' . $this->methodname . ' methodURI: ' . $this->methodURI);
4228
-        // if fault
4229
-        if (isset($this->methodreturn) && is_object($this->methodreturn) && ((get_class($this->methodreturn) == 'soap_fault') || (get_class($this->methodreturn) == 'nusoap_fault'))) {
4230
-            $this->debug('got a fault object from method');
4231
-            $this->fault = $this->methodreturn;
4232
-            return;
4233
-        } elseif ($this->methodreturnisliteralxml) {
4234
-            $return_val = $this->methodreturn;
4235
-            // returned value(s)
4236
-        } else {
4237
-            $this->debug('got a(n) ' . gettype($this->methodreturn) . ' from method');
4238
-            $this->debug('serializing return value');
4239
-            if ($this->wsdl) {
4240
-                if (sizeof($this->opData['output']['parts']) > 1) {
4241
-                    $this->debug('more than one output part, so use the method return unchanged');
4242
-                    $opParams = $this->methodreturn;
4243
-                } elseif (sizeof($this->opData['output']['parts']) == 1) {
4244
-                    $this->debug('exactly one output part, so wrap the method return in a simple array');
4245
-                    // TODO: verify that it is not already wrapped!
4246
-                    //foreach ($this->opData['output']['parts'] as $name => $type) {
4247
-                    //	$this->debug('wrap in element named ' . $name);
4248
-                    //}
4249
-                    $opParams = array($this->methodreturn);
4250
-                }
4251
-                $opParams = isset($opParams) ? $opParams : [];
4252
-                $return_val = $this->wsdl->serializeRPCParameters($this->methodname, 'output', $opParams);
4253
-                $this->appendDebug($this->wsdl->getDebug());
4254
-                $this->wsdl->clearDebug();
4255
-                if ($errstr = $this->wsdl->getError()) {
4256
-                    $this->debug('got wsdl error: ' . $errstr);
4257
-                    $this->fault('SOAP-ENV:Server', 'unable to serialize result');
4258
-                    return;
4259
-                }
4260
-            } else {
4261
-                if (isset($this->methodreturn)) {
4262
-                    $return_val = $this->serialize_val($this->methodreturn, 'return');
4263
-                } else {
4264
-                    $return_val = '';
4265
-                    $this->debug('in absence of WSDL, assume void return for backward compatibility');
4266
-                }
4267
-            }
4268
-        }
4269
-        $this->debug('return value:');
4270
-        $this->appendDebug($this->varDump($return_val));
4271
-
4272
-        $this->debug('serializing response');
4273
-        if ($this->wsdl) {
4274
-            $this->debug('have WSDL for serialization: style is ' . $this->opData['style']);
4275
-            if ($this->opData['style'] == 'rpc') {
4276
-                $this->debug('style is rpc for serialization: use is ' . $this->opData['output']['use']);
4277
-                if ($this->opData['output']['use'] == 'literal') {
4278
-                    // http://www.ws-i.org/Profiles/BasicProfile-1.1-2004-08-24.html R2735 says rpc/literal accessor elements should not be in a namespace
4279
-                    if ($this->methodURI) {
4280
-                        $payload = '<ns1:' . $this->responseTagName . ' xmlns:ns1="' . $this->methodURI . '">' . $return_val . '</ns1:' . $this->responseTagName . ">";
4281
-                    } else {
4282
-                        $payload = '<' . $this->responseTagName . '>' . $return_val . '</' . $this->responseTagName . 'Response>';
4283
-                    }
4284
-                } else {
4285
-                    if ($this->methodURI) {
4286
-                        $payload = '<ns1:' . $this->responseTagName . ' xmlns:ns1="' . $this->methodURI . '">' . $return_val . '</ns1:' . $this->responseTagName . ">";
4287
-                    } else {
4288
-                        $payload = '<' . $this->responseTagName . '>' . $return_val . '</' . $this->responseTagName . '>';
4289
-                    }
4290
-                }
4291
-            } else {
4292
-                $this->debug('style is not rpc for serialization: assume document');
4293
-                $payload = $return_val;
4294
-            }
4295
-        } else {
4296
-            $this->debug('do not have WSDL for serialization: assume rpc/encoded');
4297
-            $payload = '<ns1:' . $this->responseTagName . ' xmlns:ns1="' . $this->methodURI . '">' . $return_val . '</ns1:' . $this->responseTagName . ">";
4298
-        }
4299
-        $this->result = 'successful';
4300
-        if ($this->wsdl) {
4301
-            //if($this->debug_flag){
4302
-            $this->appendDebug($this->wsdl->getDebug());
4303
-            //	}
4304
-            if (isset($this->opData['output']['encodingStyle'])) {
4305
-                $encodingStyle = $this->opData['output']['encodingStyle'];
4306
-            } else {
4307
-                $encodingStyle = '';
4308
-            }
4309
-            // Added: In case we use a WSDL, return a serialized env. WITH the usedNamespaces.
4310
-            $this->responseSOAP = $this->serializeEnvelope($payload, $this->responseHeaders, $this->wsdl->usedNamespaces, $this->opData['style'], $this->opData['output']['use'], $encodingStyle);
4311
-        } else {
4312
-            $this->responseSOAP = $this->serializeEnvelope($payload, $this->responseHeaders);
4313
-        }
4314
-        $this->debug("Leaving serialize_return");
4315
-    }
4316
-
4317
-    /**
4318
-     * sends an HTTP response
4319
-     *
4320
-     * The following fields are set by this function (when successful)
4321
-     *
4322
-     * outgoing_headers
4323
-     * response
4324
-     *
4325
-     * @access   private
4326
-     */
4327
-    function send_response()
4328
-    {
4329
-        $this->debug('Enter send_response');
4330
-        if ($this->fault) {
4331
-            $payload = $this->fault->serialize();
4332
-            $this->outgoing_headers[] = "HTTP/1.0 500 Internal Server Error";
4333
-            $this->outgoing_headers[] = "Status: 500 Internal Server Error";
4334
-        } else {
4335
-            $payload = $this->responseSOAP;
4336
-            // Some combinations of PHP+Web server allow the Status
4337
-            // to come through as a header.  Since OK is the default
4338
-            // just do nothing.
4339
-            // $this->outgoing_headers[] = "HTTP/1.0 200 OK";
4340
-            // $this->outgoing_headers[] = "Status: 200 OK";
4341
-        }
4342
-        // add debug data if in debug mode
4343
-        if (isset($this->debug_flag) && $this->debug_flag) {
4344
-            $payload .= $this->getDebugAsXMLComment();
4345
-        }
4346
-        $this->outgoing_headers[] = "Server: $this->title Server v$this->version";
4347
-        $rev = array();
4348
-        preg_match('/\$Revisio' . 'n: ([^ ]+)/', $this->revision, $rev);
4349
-        $this->outgoing_headers[] = "X-SOAP-Server: $this->title/$this->version (" . (isset($rev[1]) ? $rev[1] : '') . ")";
4350
-        // Let the Web server decide about this
4351
-        //$this->outgoing_headers[] = "Connection: Close\r\n";
4352
-        $payload = $this->getHTTPBody($payload);
4353
-        $type = $this->getHTTPContentType();
4354
-        $charset = $this->getHTTPContentTypeCharset();
4355
-        $this->outgoing_headers[] = "Content-Type: $type" . ($charset ? '; charset=' . $charset : '');
4356
-        //begin code to compress payload - by John
4357
-        // NOTE: there is no way to know whether the Web server will also compress
4358
-        // this data.
4359
-        if (strlen($payload) > 1024 && isset($this->headers) && isset($this->headers['accept-encoding'])) {
4360
-            if (strstr($this->headers['accept-encoding'], 'gzip')) {
4361
-                if (function_exists('gzencode')) {
4362
-                    if (isset($this->debug_flag) && $this->debug_flag) {
4363
-                        $payload .= "<!-- Content being gzipped -->";
4364
-                    }
4365
-                    $this->outgoing_headers[] = "Content-Encoding: gzip";
4366
-                    $payload = gzencode($payload);
4367
-                } else {
4368
-                    if (isset($this->debug_flag) && $this->debug_flag) {
4369
-                        $payload .= "<!-- Content will not be gzipped: no gzencode -->";
4370
-                    }
4371
-                }
4372
-            } elseif (strstr($this->headers['accept-encoding'], 'deflate')) {
4373
-                // Note: MSIE requires gzdeflate output (no Zlib header and checksum),
4374
-                // instead of gzcompress output,
4375
-                // which conflicts with HTTP 1.1 spec (http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.5)
4376
-                if (function_exists('gzdeflate')) {
4377
-                    if (isset($this->debug_flag) && $this->debug_flag) {
4378
-                        $payload .= "<!-- Content being deflated -->";
4379
-                    }
4380
-                    $this->outgoing_headers[] = "Content-Encoding: deflate";
4381
-                    $payload = gzdeflate($payload);
4382
-                } else {
4383
-                    if (isset($this->debug_flag) && $this->debug_flag) {
4384
-                        $payload .= "<!-- Content will not be deflated: no gzcompress -->";
4385
-                    }
4386
-                }
4387
-            }
4388
-        }
4389
-        //end code
4390
-        $this->outgoing_headers[] = "Content-Length: " . strlen($payload);
4391
-        reset($this->outgoing_headers);
4392
-        foreach ($this->outgoing_headers as $hdr) {
4393
-            header($hdr, false);
4394
-        }
4395
-        print $payload;
4396
-        $this->response = join("\r\n", $this->outgoing_headers) . "\r\n\r\n" . $payload;
4397
-    }
4398
-
4399
-    /**
4400
-     * takes the value that was created by parsing the request
4401
-     * and compares to the method's signature, if available.
4402
-     *
4403
-     * @param    string $operation The operation to be invoked
4404
-     * @param    array $request The array of parameter values
4405
-     * @return    boolean    Whether the operation was found
4406
-     * @access   private
4407
-     */
4408
-    function verify_method($operation, $request)
4409
-    {
4410
-        if (isset($this->wsdl) && is_object($this->wsdl)) {
4411
-            if ($this->wsdl->getOperationData($operation)) {
4412
-                return true;
4413
-            }
4414
-        } elseif (isset($this->operations[$operation])) {
4415
-            return true;
4416
-        }
4417
-        return false;
4418
-    }
4419
-
4420
-    /**
4421
-     * processes SOAP message received from client
4422
-     *
4423
-     * @param    array $headers The HTTP headers
4424
-     * @param    string $data unprocessed request data from client
4425
-     * @return   false|void void or false on error
4426
-     * @access   private
4427
-     */
4428
-    function parseRequest($headers, $data)
4429
-    {
4430
-        $this->debug('Entering parseRequest() for data of length ' . strlen($data) . ' headers:');
4431
-        $this->appendDebug($this->varDump($headers));
4432
-        if (!isset($headers['content-type'])) {
4433
-            $this->setError('Request not of type '.$this->contentType.' (no content-type header)');
4434
-            return false;
4435
-        }
4436
-        if (!strstr($headers['content-type'], $this->contentType)) {
4437
-            $this->setError('Request not of type '.$this->contentType.': ' . $headers['content-type']);
4438
-            return false;
4439
-        }
4440
-        if (strpos($headers['content-type'], '=')) {
4441
-            $enc = str_replace('"', '', substr(strstr($headers["content-type"], '='), 1));
4442
-            $this->debug('Got response encoding: ' . $enc);
4443
-            if (preg_match('/^(ISO-8859-1|US-ASCII|UTF-8)$/i', $enc)) {
4444
-                $this->xml_encoding = strtoupper($enc);
4445
-            } else {
4446
-                $this->xml_encoding = 'US-ASCII';
4447
-            }
4448
-        } else {
4449
-            // should be US-ASCII for HTTP 1.0 or ISO-8859-1 for HTTP 1.1
4450
-            $this->xml_encoding = 'ISO-8859-1';
4451
-        }
4452
-        $this->debug('Use encoding: ' . $this->xml_encoding . ' when creating nusoap_parser');
4453
-        // parse response, get soap parser obj
4454
-        $parser = new nusoap_parser($data, $this->xml_encoding, '', $this->decode_utf8);
4455
-        // parser debug
4456
-        $this->debug("parser debug: \n" . $parser->getDebug());
4457
-        // if fault occurred during message parsing
4458
-        if ($err = $parser->getError()) {
4459
-            $this->result = 'fault: error in msg parsing: ' . $err;
4460
-            $this->fault('SOAP-ENV:Client', "error in msg parsing:\n" . $err);
4461
-            // else successfully parsed request into soapval object
4462
-        } else {
4463
-            // get/set methodname
4464
-            $this->methodURI = $parser->root_struct_namespace;
4465
-            $this->methodname = $parser->root_struct_name;
4466
-            $this->debug('methodname: ' . $this->methodname . ' methodURI: ' . $this->methodURI);
4467
-
4468
-            // get/set custom response tag name
4469
-            $tmparray = $this->wsdl->getOperationData($this->methodname);
4470
-            $outputMessage = (empty($tmparray) ? '' : $tmparray['output']['message']);
4471
-            $this->responseTagName = $outputMessage;
4472
-            $this->debug('responseTagName: ' . $this->responseTagName . ' methodURI: ' . $this->methodURI);
4473
-
4474
-            $this->debug('calling parser->get_soapbody()');
4475
-            $this->methodparams = $parser->get_soapbody();
4476
-            // get SOAP headers
4477
-            $this->requestHeaders = $parser->getHeaders();
4478
-            // get SOAP Header
4479
-            $this->requestHeader = $parser->get_soapheader();
4480
-            // add document for doclit support
4481
-            $this->document = $parser->document;
4482
-        }
4483
-    }
4484
-
4485
-    /**
4486
-     * gets the HTTP body for the current response.
4487
-     *
4488
-     * @param string $soapmsg The SOAP payload
4489
-     * @return string The HTTP body, which includes the SOAP payload
4490
-     * @access private
4491
-     */
4492
-    function getHTTPBody($soapmsg)
4493
-    {
4494
-        return $soapmsg;
4495
-    }
4496
-
4497
-    /**
4498
-     * gets the HTTP content type for the current response.
4499
-     *
4500
-     * Note: getHTTPBody must be called before this.
4501
-     *
4502
-     * @return string the HTTP content type for the current response.
4503
-     * @access private
4504
-     */
4505
-    function getHTTPContentType()
4506
-    {
4507
-        return 'text/xml';
4508
-    }
4509
-
4510
-    /**
4511
-     * gets the HTTP content type charset for the current response.
4512
-     * returns false for non-text content types.
4513
-     *
4514
-     * Note: getHTTPBody must be called before this.
4515
-     *
4516
-     * @return string the HTTP content type charset for the current response.
4517
-     * @access private
4518
-     */
4519
-    function getHTTPContentTypeCharset()
4520
-    {
4521
-        return $this->soap_defencoding;
4522
-    }
4523
-
4524
-    /**
4525
-     * add a method to the dispatch map (this has been replaced by the register method)
4526
-     *
4527
-     * @param    string $methodname
4528
-     * @param    string $in array of input values
4529
-     * @param    string $out array of output values
4530
-     * @access   public
4531
-     * @deprecated
4532
-     */
4533
-    function add_to_map($methodname, $in, $out)
4534
-    {
4535
-        $this->operations[$methodname] = array('name' => $methodname, 'in' => $in, 'out' => $out);
4536
-    }
4537
-
4538
-    /**
4539
-     * register a service function with the server
4540
-     *
4541
-     * @param    string $name the name of the PHP function, class.method or class..method
4542
-     * @param    array $in assoc array of input values: key = param name, value = param type
4543
-     * @param    array $out assoc array of output values: key = param name, value = param type
4544
-     * @param    mixed $namespace the element namespace for the method or false
4545
-     * @param    mixed $soapaction the soapaction for the method or false
4546
-     * @param    mixed $style optional (rpc|document) or false Note: when 'document' is specified, parameter and return wrappers are created for you automatically
4547
-     * @param    mixed $use optional (encoded|literal) or false
4548
-     * @param    string $documentation optional Description to include in WSDL
4549
-     * @param    string $encodingStyle optional (usually 'http://schemas.xmlsoap.org/soap/encoding/' for encoded)
4550
-     * @param    string $customResponseTagName optional Name of the outgoing response, default $name . 'Response'
4551
-     * @access   public
4552
-     */
4553
-    function register($name, $in = array(), $out = array(), $namespace = false, $soapaction = false, $style = false, $use = false, $documentation = '', $encodingStyle = '', $customResponseTagName = '')
4554
-    {
4555
-        global $HTTP_SERVER_VARS;
4556
-
4557
-        if ($this->externalWSDLURL) {
4558
-            die('You cannot bind to an external WSDL file, and register methods outside of it! Please choose either WSDL or no WSDL.');
4559
-        }
4560
-        if (!$name) {
4561
-            die('You must specify a name when you register an operation');
4562
-        }
4563
-        if (!is_array($in)) {
4564
-            die('You must provide an array for operation inputs');
4565
-        }
4566
-        if (!is_array($out)) {
4567
-            die('You must provide an array for operation outputs');
4568
-        }
4569
-        if (!$soapaction) {
4570
-            if (isset($_SERVER)) {
4571
-                $SERVER_NAME = $_SERVER['SERVER_NAME'];
4572
-                $SCRIPT_NAME = $_SERVER['SCRIPT_NAME'];
4573
-                $HTTPS = isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : (isset($HTTP_SERVER_VARS['HTTPS']) ? $HTTP_SERVER_VARS['HTTPS'] : 'off');
4574
-            } elseif (isset($HTTP_SERVER_VARS)) {
4575
-                $SERVER_NAME = $HTTP_SERVER_VARS['SERVER_NAME'];
4576
-                $SCRIPT_NAME = $HTTP_SERVER_VARS['SCRIPT_NAME'];
4577
-                $HTTPS = isset($HTTP_SERVER_VARS['HTTPS']) ? $HTTP_SERVER_VARS['HTTPS'] : 'off';
4578
-            } else {
4579
-                $this->setError("Neither _SERVER nor HTTP_SERVER_VARS is available");
4580
-                $HTTPS = '';
4581
-                $SERVER_NAME = '';
4582
-                $SCRIPT_NAME = '';
4583
-            }
4584
-            if ($HTTPS == '1' || $HTTPS == 'on') {
4585
-                $SCHEME = 'https';
4586
-            } else {
4587
-                $SCHEME = 'http';
4588
-            }
4589
-            $soapaction = "$SCHEME://$SERVER_NAME$SCRIPT_NAME/$name";
4590
-        }
4591
-        if (!$style) {
4592
-            $style = "rpc";
4593
-        }
4594
-        if (!$use) {
4595
-            $use = "encoded";
4596
-        }
4597
-        if ($use == 'encoded' && $encodingStyle == '') {
4598
-            $encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/';
4599
-        }
4600
-        if (!$customResponseTagName) {
4601
-            $customResponseTagName = $name . 'Response';
4602
-        }
4603
-
4604
-        $this->operations[$name] = array(
4605
-            'name' => $name,
4606
-            'in' => $in,
4607
-            'out' => $out,
4608
-            'namespace' => $namespace,
4609
-            'soapaction' => $soapaction,
4610
-            'style' => $style,
4611
-            'outputMessage' => $customResponseTagName,
4612
-        );
4613
-        if ($this->wsdl) {
4614
-            $this->wsdl->addOperation($name, $in, $out, $namespace, $soapaction, $style, $use, $documentation, $encodingStyle, $customResponseTagName);
4615
-        }
4616
-        return true;
4617
-    }
4618
-
4619
-    /**
4620
-     * Specify a fault to be returned to the client.
4621
-     * This also acts as a flag to the server that a fault has occured.
4622
-     *
4623
-     * @param    string $faultcode
4624
-     * @param    string $faultstring
4625
-     * @param    string $faultactor
4626
-     * @param    string $faultdetail
4627
-     * @access   public
4628
-     */
4629
-    function fault($faultcode, $faultstring, $faultactor = '', $faultdetail = '')
4630
-    {
4631
-        if ($faultdetail == '' && $this->debug_flag) {
4632
-            $faultdetail = $this->getDebug();
4633
-        }
4634
-        $this->fault = new nusoap_fault($faultcode, $faultactor, $faultstring, $faultdetail);
4635
-        $this->fault->soap_defencoding = $this->soap_defencoding;
4636
-    }
4637
-
4638
-    /**
4639
-     * Sets up wsdl object.
4640
-     * Acts as a flag to enable internal WSDL generation
4641
-     *
4642
-     * @param string $serviceName , name of the service
4643
-     * @param mixed $namespace optional 'tns' service namespace or false
4644
-     * @param mixed $endpoint optional URL of service endpoint or false
4645
-     * @param string $style optional (rpc|document) WSDL style (also specified by operation)
4646
-     * @param string $transport optional SOAP transport
4647
-     * @param mixed $schemaTargetNamespace optional 'types' targetNamespace for service schema or false
4648
-     */
4649
-    function configureWSDL($serviceName, $namespace = false, $endpoint = false, $style = 'rpc', $transport = 'http://schemas.xmlsoap.org/soap/http', $schemaTargetNamespace = false)
4650
-    {
4651
-        global $HTTP_SERVER_VARS;
4652
-
4653
-        if (isset($_SERVER)) {
4654
-            $SERVER_NAME = $_SERVER['SERVER_NAME'];
4655
-            $SERVER_PORT = $_SERVER['SERVER_PORT'];
4656
-            $SCRIPT_NAME = $_SERVER['SCRIPT_NAME'];
4657
-            $HTTPS = isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : (isset($HTTP_SERVER_VARS['HTTPS']) ? $HTTP_SERVER_VARS['HTTPS'] : 'off');
4658
-        } elseif (isset($HTTP_SERVER_VARS)) {
4659
-            $SERVER_NAME = $HTTP_SERVER_VARS['SERVER_NAME'];
4660
-            $SERVER_PORT = $HTTP_SERVER_VARS['SERVER_PORT'];
4661
-            $SCRIPT_NAME = $HTTP_SERVER_VARS['SCRIPT_NAME'];
4662
-            $HTTPS = isset($HTTP_SERVER_VARS['HTTPS']) ? $HTTP_SERVER_VARS['HTTPS'] : 'off';
4663
-        } else {
4664
-            $this->setError("Neither _SERVER nor HTTP_SERVER_VARS is available");
4665
-            $SERVER_PORT = '';
4666
-            $SERVER_NAME = '';
4667
-            $SCRIPT_NAME = '';
4668
-            $HTTPS = '';
4669
-        }
4670
-        // If server name has port number attached then strip it (else port number gets duplicated in WSDL output) (occurred using lighttpd and FastCGI)
4671
-        $colon = strpos($SERVER_NAME, ":");
4672
-        if ($colon) {
4673
-            $SERVER_NAME = substr($SERVER_NAME, 0, $colon);
4674
-        }
4675
-        if ($SERVER_PORT == 80) {
4676
-            $SERVER_PORT = '';
4677
-        } else {
4678
-            $SERVER_PORT = ':' . $SERVER_PORT;
4679
-        }
4680
-        if (!$namespace) {
4681
-            $namespace = "http://$SERVER_NAME/soap/$serviceName";
4682
-        }
4683
-
4684
-        if (!$endpoint) {
4685
-            if ($HTTPS == '1' || $HTTPS == 'on') {
4686
-                $SCHEME = 'https';
4687
-            } else {
4688
-                $SCHEME = 'http';
4689
-            }
4690
-            $endpoint = "$SCHEME://$SERVER_NAME$SERVER_PORT$SCRIPT_NAME";
4691
-        }
4692
-
4693
-        if (!$schemaTargetNamespace) {
4694
-            $schemaTargetNamespace = $namespace;
4695
-        }
4696
-
4697
-        $this->wsdl = new wsdl;
4698
-        $this->wsdl->serviceName = $serviceName;
4699
-        $this->wsdl->endpoint = $endpoint;
4700
-        $this->wsdl->namespaces['tns'] = $namespace;
4701
-        $this->wsdl->namespaces['soap'] = 'http://schemas.xmlsoap.org/wsdl/soap/';
4702
-        $this->wsdl->namespaces['wsdl'] = 'http://schemas.xmlsoap.org/wsdl/';
4703
-        if ($schemaTargetNamespace != $namespace) {
4704
-            $this->wsdl->namespaces['types'] = $schemaTargetNamespace;
4705
-        }
4706
-        $this->wsdl->schemas[$schemaTargetNamespace][0] = new nusoap_xmlschema('', '', $this->wsdl->namespaces);
4707
-        if ($style == 'document') {
4708
-            $this->wsdl->schemas[$schemaTargetNamespace][0]->schemaInfo['elementFormDefault'] = 'qualified';
4709
-        }
4710
-        $this->wsdl->schemas[$schemaTargetNamespace][0]->schemaTargetNamespace = $schemaTargetNamespace;
4711
-        $this->wsdl->schemas[$schemaTargetNamespace][0]->imports['http://schemas.xmlsoap.org/soap/encoding/'][0] = array('location' => '', 'loaded' => true);
4712
-        $this->wsdl->schemas[$schemaTargetNamespace][0]->imports['http://schemas.xmlsoap.org/wsdl/'][0] = array('location' => '', 'loaded' => true);
4713
-        $this->wsdl->bindings[$serviceName . 'Binding'] = array(
4714
-            'name' => $serviceName . 'Binding',
4715
-            'style' => $style,
4716
-            'transport' => $transport,
4717
-            'portType' => $serviceName . 'PortType');
4718
-        $this->wsdl->ports[$serviceName . 'Port'] = array(
4719
-            'binding' => $serviceName . 'Binding',
4720
-            'location' => $endpoint,
4721
-            'bindingType' => 'http://schemas.xmlsoap.org/wsdl/soap/');
4722
-    }
2102
+	/**
2103
+	 * The XML element name
2104
+	 *
2105
+	 * @var string
2106
+	 * @access private
2107
+	 */
2108
+	var $name;
2109
+	/**
2110
+	 * The XML type name (string or false)
2111
+	 *
2112
+	 * @var mixed
2113
+	 * @access private
2114
+	 */
2115
+	var $type;
2116
+	/**
2117
+	 * The PHP value
2118
+	 *
2119
+	 * @var mixed
2120
+	 * @access private
2121
+	 */
2122
+	var $value;
2123
+	/**
2124
+	 * The XML element namespace (string or false)
2125
+	 *
2126
+	 * @var mixed
2127
+	 * @access private
2128
+	 */
2129
+	var $element_ns;
2130
+	/**
2131
+	 * The XML type namespace (string or false)
2132
+	 *
2133
+	 * @var mixed
2134
+	 * @access private
2135
+	 */
2136
+	var $type_ns;
2137
+	/**
2138
+	 * The XML element attributes (array or false)
2139
+	 *
2140
+	 * @var mixed
2141
+	 * @access private
2142
+	 */
2143
+	var $attributes;
2144
+
2145
+	/** @var false|resource */
2146
+	var $fp;
2147
+
2148
+	/**
2149
+	 * constructor
2150
+	 *
2151
+	 * @param    string $name optional name
2152
+	 * @param    mixed $type optional type name
2153
+	 * @param    mixed $value optional value
2154
+	 * @param    mixed $element_ns optional namespace of value
2155
+	 * @param    mixed $type_ns optional namespace of type
2156
+	 * @param    mixed $attributes associative array of attributes to add to element serialization
2157
+	 * @access   public
2158
+	 */
2159
+	function __construct($name = 'soapval', $type = false, $value = -1, $element_ns = false, $type_ns = false, $attributes = false)
2160
+	{
2161
+		parent::__construct();
2162
+		$this->name = $name;
2163
+		$this->type = $type;
2164
+		$this->value = $value;
2165
+		$this->element_ns = $element_ns;
2166
+		$this->type_ns = $type_ns;
2167
+		$this->attributes = $attributes;
2168
+	}
2169
+
2170
+	/**
2171
+	 * return serialized value
2172
+	 *
2173
+	 * @param    string $use The WSDL use value (encoded|literal)
2174
+	 * @return    string XML data
2175
+	 * @access   public
2176
+	 */
2177
+	function serialize($use = 'encoded')
2178
+	{
2179
+		return $this->serialize_val($this->value, $this->name, $this->type, $this->element_ns, $this->type_ns, $this->attributes, $use, true);
2180
+	}
2181
+
2182
+	/**
2183
+	 * decodes a soapval object into a PHP native type
2184
+	 *
2185
+	 * @return    mixed
2186
+	 * @access   public
2187
+	 */
2188
+	function decode()
2189
+	{
2190
+		return $this->value;
2191
+	}
4723 2192
 }
4724 2193
 
4725
-/**
4726
- * Backward compatibility
4727
- */
4728
-class soap_server extends nusoap_server
4729
-{
4730
-}
4731 2194
 
2195
+/**
2196
+ * transport class for sending/receiving data via HTTP and HTTPS
2197
+ * NOTE: PHP must be compiled with the CURL extension for HTTPS support
2198
+ *
2199
+ * @author   Dietrich Ayala <[email protected]>
2200
+ * @author   Scott Nichol <[email protected]>
2201
+ * @version  $Id: nusoap.php,v 1.123 2010/04/26 20:15:08 snichol Exp $
2202
+ * @access public
2203
+ */
2204
+class soap_transport_http extends nusoap_base
2205
+{
2206
+
2207
+	var $query = '';
2208
+	var $tryagain = false;
2209
+	var $url = '';
2210
+	var $uri = '';
2211
+	var $digest_uri = '';
2212
+	var $scheme = '';
2213
+	var $host = '';
2214
+	var $port = '';
2215
+	var $path = '';
2216
+	var $request_method = 'POST';
2217
+	var $protocol_version = '1.0';
2218
+	var $encoding = '';
2219
+	var $outgoing_headers = array();
2220
+	var $incoming_headers = array();
2221
+	var $incoming_cookies = array();
2222
+	var $outgoing_payload = '';
2223
+	var $incoming_payload = '';
2224
+	var $response_status_line;    // HTTP response status line
2225
+	var $useSOAPAction = true;
2226
+	var $persistentConnection = false;
2227
+	var $ch = false;    // cURL handle
2228
+	var $ch_options = array();    // cURL custom options
2229
+	var $use_curl = false;        // force cURL use
2230
+	var $proxy = null;            // proxy information (associative array)
2231
+	var $username = '';
2232
+	var $password = '';
2233
+	var $authtype = '';
2234
+	var $digestRequest = array();
2235
+	var $certRequest = array();    // keys must be cainfofile (optional), sslcertfile, sslkeyfile, passphrase, certpassword (optional), verifypeer (optional), verifyhost (optional)
2236
+	// cainfofile: certificate authority file, e.g. '$pathToPemFiles/rootca.pem'
2237
+	// sslcertfile: SSL certificate file, e.g. '$pathToPemFiles/mycert.pem'
2238
+	// sslkeyfile: SSL key file, e.g. '$pathToPemFiles/mykey.pem'
2239
+	// passphrase: SSL key password/passphrase
2240
+	// certpassword: SSL certificate password
2241
+	// verifypeer: default is 1
2242
+	// verifyhost: default is 1
2243
+
2244
+	/** @var false|resource */
2245
+	var $fp;
2246
+	var $errno;
2247
+
2248
+	/**
2249
+	 * constructor
2250
+	 *
2251
+	 * @param string $url The URL to which to connect
2252
+	 * @param array $curl_options User-specified cURL options
2253
+	 * @param boolean $use_curl Whether to try to force cURL use
2254
+	 * @access public
2255
+	 */
2256
+	function __construct($url, $curl_options = null, $use_curl = false)
2257
+	{
2258
+		parent::__construct();
2259
+		$this->debug("ctor url=$url use_curl=$use_curl curl_options:");
2260
+		$this->appendDebug($this->varDump($curl_options));
2261
+		$this->setURL($url);
2262
+		if (is_array($curl_options)) {
2263
+			$this->ch_options = $curl_options;
2264
+		}
2265
+		$this->use_curl = $use_curl;
2266
+		preg_match('/\$Revisio' . 'n: ([^ ]+)/', $this->revision, $rev);
2267
+		$this->setHeader('User-Agent', $this->title . '/' . $this->version . ' (' . $rev[1] . ')');
2268
+	}
2269
+
2270
+	/**
2271
+	 * sets a cURL option
2272
+	 *
2273
+	 * @param    mixed $option The cURL option (always integer?)
2274
+	 * @param    mixed $value The cURL option value
2275
+	 * @access   private
2276
+	 */
2277
+	function setCurlOption($option, $value)
2278
+	{
2279
+		$this->debug("setCurlOption option=$option, value=");
2280
+		$this->appendDebug($this->varDump($value));
2281
+		curl_setopt($this->ch, $option, $value);
2282
+	}
2283
+
2284
+	/**
2285
+	 * sets an HTTP header
2286
+	 *
2287
+	 * @param string $name The name of the header
2288
+	 * @param string $value The value of the header
2289
+	 * @access private
2290
+	 */
2291
+	function setHeader($name, $value)
2292
+	{
2293
+		$this->outgoing_headers[$name] = $value;
2294
+		$this->debug("set header $name: $value");
2295
+	}
2296
+
2297
+	/**
2298
+	 * unsets an HTTP header
2299
+	 *
2300
+	 * @param string $name The name of the header
2301
+	 * @access private
2302
+	 */
2303
+	function unsetHeader($name)
2304
+	{
2305
+		if (isset($this->outgoing_headers[$name])) {
2306
+			$this->debug("unset header $name");
2307
+			unset($this->outgoing_headers[$name]);
2308
+		}
2309
+	}
2310
+
2311
+	/**
2312
+	 * sets the URL to which to connect
2313
+	 *
2314
+	 * @param string $url The URL to which to connect
2315
+	 * @access private
2316
+	 */
2317
+	function setURL($url)
2318
+	{
2319
+		$this->url = $url;
2320
+
2321
+		$u = parse_url($url);
2322
+		foreach ($u as $k => $v) {
2323
+			$this->debug("parsed URL $k = $v");
2324
+			$this->$k = $v;
2325
+		}
2326
+
2327
+		// add any GET params to path
2328
+		if (isset($u['query']) && $u['query'] != '') {
2329
+			$this->path .= '?' . $u['query'];
2330
+		}
2331
+
2332
+		// set default port
2333
+		if (!isset($u['port'])) {
2334
+			if ($u['scheme'] == 'https') {
2335
+				$this->port = 443;
2336
+			} else {
2337
+				$this->port = 80;
2338
+			}
2339
+		}
2340
+
2341
+		$this->uri = $this->path;
2342
+		$this->digest_uri = $this->uri;
2343
+
2344
+		// build headers
2345
+		if (!isset($u['port'])) {
2346
+			$this->setHeader('Host', $this->host);
2347
+		} else {
2348
+			$this->setHeader('Host', $this->host . ':' . $this->port);
2349
+		}
2350
+
2351
+		if (isset($u['user']) && $u['user'] != '') {
2352
+			$this->setCredentials(urldecode($u['user']), isset($u['pass']) ? urldecode($u['pass']) : '');
2353
+		}
2354
+	}
2355
+
2356
+	/**
2357
+	 * gets the I/O method to use
2358
+	 *
2359
+	 * @return    string    I/O method to use (socket|curl|unknown)
2360
+	 * @access    private
2361
+	 */
2362
+	function io_method()
2363
+	{
2364
+		if ($this->use_curl || ($this->scheme == 'https') || ($this->scheme == 'http' && $this->authtype == 'ntlm') || ($this->scheme == 'http' && is_array($this->proxy) && $this->proxy['authtype'] == 'ntlm')) {
2365
+			return 'curl';
2366
+		}
2367
+		if (($this->scheme == 'http' || $this->scheme == 'ssl') && $this->authtype != 'ntlm' && (!is_array($this->proxy) || $this->proxy['authtype'] != 'ntlm')) {
2368
+			return 'socket';
2369
+		}
2370
+		return 'unknown';
2371
+	}
2372
+
2373
+	/**
2374
+	 * establish an HTTP connection
2375
+	 *
2376
+	 * @param    integer $connection_timeout set connection timeout in seconds
2377
+	 * @param    integer $response_timeout set response timeout in seconds
2378
+	 * @return    boolean true if connected, false if not
2379
+	 * @access   private
2380
+	 */
2381
+	function connect($connection_timeout = 0, $response_timeout = 30)
2382
+	{
2383
+		// For PHP 4.3 with OpenSSL, change https scheme to ssl, then treat like
2384
+		// "regular" socket.
2385
+		// TODO: disabled for now because OpenSSL must be *compiled* in (not just
2386
+		//       loaded), and until PHP5 stream_get_wrappers is not available.
2387
+//	  	if ($this->scheme == 'https') {
2388
+//		  	if (version_compare(phpversion(), '4.3.0') >= 0) {
2389
+//		  		if (extension_loaded('openssl')) {
2390
+//		  			$this->scheme = 'ssl';
2391
+//		  			$this->debug('Using SSL over OpenSSL');
2392
+//		  		}
2393
+//		  	}
2394
+//		}
2395
+		$this->debug("connect connection_timeout $connection_timeout, response_timeout $response_timeout, scheme $this->scheme, host $this->host, port $this->port");
2396
+		if ($this->io_method() == 'socket') {
2397
+			if (!is_array($this->proxy)) {
2398
+				$host = $this->host;
2399
+			} else {
2400
+				$host = $this->proxy['host'];
2401
+			}
2402
+
2403
+			// use persistent connection
2404
+			if ($this->persistentConnection && isset($this->fp) && is_resource($this->fp)) {
2405
+				if (!feof($this->fp)) {
2406
+					$this->debug('Re-use persistent connection');
2407
+					return true;
2408
+				}
2409
+				fclose($this->fp);
2410
+				$this->debug('Closed persistent connection at EOF');
2411
+			}
2412
+
2413
+			// munge host if using OpenSSL
2414
+			if ($this->scheme == 'ssl') {
2415
+				$host = 'ssl://' . $host;
2416
+			}
2417
+			$this->debug('calling fsockopen with host ' . $host . ' connection_timeout ' . $connection_timeout);
2418
+
2419
+			// open socket
2420
+			if ($connection_timeout > 0) {
2421
+				$this->fp = @fsockopen($host, $this->port, $this->errno, $this->error_str, $connection_timeout);
2422
+			} else {
2423
+				$this->fp = @fsockopen($host, $this->port, $this->errno, $this->error_str);
2424
+			}
2425
+
2426
+			// test pointer
2427
+			if (!$this->fp) {
2428
+				$msg = 'Couldn\'t open socket connection to server ' . $this->url;
2429
+				if ($this->errno) {
2430
+					$msg .= ', Error (' . $this->errno . '): ' . $this->error_str;
2431
+				} else {
2432
+					$msg .= ' prior to connect().  This is often a problem looking up the host name.';
2433
+				}
2434
+				$this->debug($msg);
2435
+				$this->setError($msg);
2436
+				return false;
2437
+			}
2438
+
2439
+			// set response timeout
2440
+			$this->debug('set response timeout to ' . $response_timeout);
2441
+			socket_set_timeout($this->fp, $response_timeout, 0);
2442
+
2443
+			$this->debug('socket connected');
2444
+			return true;
2445
+		} elseif ($this->io_method() == 'curl') {
2446
+			if (!extension_loaded('curl')) {
2447
+//			$this->setError('cURL Extension, or OpenSSL extension w/ PHP version >= 4.3 is required for HTTPS');
2448
+				$this->setError('The PHP cURL Extension is required for HTTPS or NLTM.  You will need to re-build or update your PHP to include cURL or change php.ini to load the PHP cURL extension.');
2449
+				return false;
2450
+			}
2451
+			// Avoid warnings when PHP does not have these options
2452
+			if (defined('CURLOPT_CONNECTIONTIMEOUT')) {
2453
+				$CURLOPT_CONNECTIONTIMEOUT = CURLOPT_CONNECTIONTIMEOUT;
2454
+			} else {
2455
+				$CURLOPT_CONNECTIONTIMEOUT = 78;
2456
+			}
2457
+			if (defined('CURLOPT_HTTPAUTH')) {
2458
+				$CURLOPT_HTTPAUTH = CURLOPT_HTTPAUTH;
2459
+			} else {
2460
+				$CURLOPT_HTTPAUTH = 107;
2461
+			}
2462
+			if (defined('CURLOPT_PROXYAUTH')) {
2463
+				$CURLOPT_PROXYAUTH = CURLOPT_PROXYAUTH;
2464
+			} else {
2465
+				$CURLOPT_PROXYAUTH = 111;
2466
+			}
2467
+			if (defined('CURLAUTH_BASIC')) {
2468
+				$CURLAUTH_BASIC = CURLAUTH_BASIC;
2469
+			} else {
2470
+				$CURLAUTH_BASIC = 1;
2471
+			}
2472
+			if (defined('CURLAUTH_DIGEST')) {
2473
+				$CURLAUTH_DIGEST = CURLAUTH_DIGEST;
2474
+			} else {
2475
+				$CURLAUTH_DIGEST = 2;
2476
+			}
2477
+			if (defined('CURLAUTH_NTLM')) {
2478
+				$CURLAUTH_NTLM = CURLAUTH_NTLM;
2479
+			} else {
2480
+				$CURLAUTH_NTLM = 8;
2481
+			}
2482
+
2483
+			$this->debug('connect using cURL');
2484
+			// init CURL
2485
+			$this->ch = curl_init();
2486
+			// set url
2487
+			$hostURL = ($this->port != '') ? "$this->scheme://$this->host:$this->port" : "$this->scheme://$this->host";
2488
+			// add path
2489
+			$hostURL .= $this->path;
2490
+			$this->setCurlOption(CURLOPT_URL, $hostURL);
2491
+			// follow location headers (re-directs)
2492
+			if (ini_get('safe_mode') || ini_get('open_basedir')) {
2493
+				$this->debug('safe_mode or open_basedir set, so do not set CURLOPT_FOLLOWLOCATION');
2494
+				$this->debug('safe_mode = ');
2495
+				$this->appendDebug($this->varDump(ini_get('safe_mode')));
2496
+				$this->debug('open_basedir = ');
2497
+				$this->appendDebug($this->varDump(ini_get('open_basedir')));
2498
+			} else {
2499
+				$this->setCurlOption(CURLOPT_FOLLOWLOCATION, 1);
2500
+			}
2501
+			// ask for headers in the response output
2502
+			$this->setCurlOption(CURLOPT_HEADER, 1);
2503
+			// ask for the response output as the return value
2504
+			$this->setCurlOption(CURLOPT_RETURNTRANSFER, 1);
2505
+			// encode
2506
+			// We manage this ourselves through headers and encoding
2507
+//		if(function_exists('gzuncompress')){
2508
+//			$this->setCurlOption(CURLOPT_ENCODING, 'deflate');
2509
+//		}
2510
+			// persistent connection
2511
+			if ($this->persistentConnection) {
2512
+				// I believe the following comment is now bogus, having applied to
2513
+				// the code when it used CURLOPT_CUSTOMREQUEST to send the request.
2514
+				// The way we send data, we cannot use persistent connections, since
2515
+				// there will be some "junk" at the end of our request.
2516
+				//$this->setCurlOption(CURL_HTTP_VERSION_1_1, true);
2517
+				$this->persistentConnection = false;
2518
+				$this->setHeader('Connection', 'close');
2519
+			}
2520
+			// set timeouts
2521
+			if ($connection_timeout != 0) {
2522
+				$this->setCurlOption($CURLOPT_CONNECTIONTIMEOUT, $connection_timeout);
2523
+			}
2524
+			if ($response_timeout != 0) {
2525
+				$this->setCurlOption(CURLOPT_TIMEOUT, $response_timeout);
2526
+			}
2527
+
2528
+			if ($this->scheme == 'https') {
2529
+				$this->debug('set cURL SSL verify options');
2530
+				// recent versions of cURL turn on peer/host checking by default,
2531
+				// while PHP binaries are not compiled with a default location for the
2532
+				// CA cert bundle, so disable peer/host checking.
2533
+				//$this->setCurlOption(CURLOPT_CAINFO, 'f:\php-4.3.2-win32\extensions\curl-ca-bundle.crt');
2534
+				$this->setCurlOption(CURLOPT_SSL_VERIFYPEER, 0);
2535
+				$this->setCurlOption(CURLOPT_SSL_VERIFYHOST, 0);
2536
+
2537
+				// support client certificates (thanks Tobias Boes, Doug Anarino, Eryan Ariobowo)
2538
+				if ($this->authtype == 'certificate') {
2539
+					$this->debug('set cURL certificate options');
2540
+					if (isset($this->certRequest['cainfofile'])) {
2541
+						$this->setCurlOption(CURLOPT_CAINFO, $this->certRequest['cainfofile']);
2542
+					}
2543
+					if (isset($this->certRequest['verifypeer'])) {
2544
+						$this->setCurlOption(CURLOPT_SSL_VERIFYPEER, $this->certRequest['verifypeer']);
2545
+					} else {
2546
+						$this->setCurlOption(CURLOPT_SSL_VERIFYPEER, 1);
2547
+					}
2548
+					if (isset($this->certRequest['verifyhost'])) {
2549
+						$this->setCurlOption(CURLOPT_SSL_VERIFYHOST, $this->certRequest['verifyhost']);
2550
+					} else {
2551
+						$this->setCurlOption(CURLOPT_SSL_VERIFYHOST, 1);
2552
+					}
2553
+					if (isset($this->certRequest['sslcertfile'])) {
2554
+						$this->setCurlOption(CURLOPT_SSLCERT, $this->certRequest['sslcertfile']);
2555
+					}
2556
+					if (isset($this->certRequest['sslkeyfile'])) {
2557
+						$this->setCurlOption(CURLOPT_SSLKEY, $this->certRequest['sslkeyfile']);
2558
+					}
2559
+					if (isset($this->certRequest['passphrase'])) {
2560
+						$this->setCurlOption(CURLOPT_SSLKEYPASSWD, $this->certRequest['passphrase']);
2561
+					}
2562
+					if (isset($this->certRequest['certpassword'])) {
2563
+						$this->setCurlOption(CURLOPT_SSLCERTPASSWD, $this->certRequest['certpassword']);
2564
+					}
2565
+				}
2566
+			}
2567
+			if ($this->authtype && ($this->authtype != 'certificate')) {
2568
+				if ($this->username) {
2569
+					$this->debug('set cURL username/password');
2570
+					$this->setCurlOption(CURLOPT_USERPWD, "$this->username:$this->password");
2571
+				}
2572
+				if ($this->authtype == 'basic') {
2573
+					$this->debug('set cURL for Basic authentication');
2574
+					$this->setCurlOption($CURLOPT_HTTPAUTH, $CURLAUTH_BASIC);
2575
+				}
2576
+				if ($this->authtype == 'digest') {
2577
+					$this->debug('set cURL for digest authentication');
2578
+					$this->setCurlOption($CURLOPT_HTTPAUTH, $CURLAUTH_DIGEST);
2579
+				}
2580
+				if ($this->authtype == 'ntlm') {
2581
+					$this->debug('set cURL for NTLM authentication');
2582
+					$this->setCurlOption($CURLOPT_HTTPAUTH, $CURLAUTH_NTLM);
2583
+				}
2584
+			}
2585
+			if (is_array($this->proxy)) {
2586
+				$this->debug('set cURL proxy options');
2587
+				if ($this->proxy['port'] != '') {
2588
+					$this->setCurlOption(CURLOPT_PROXY, $this->proxy['host'] . ':' . $this->proxy['port']);
2589
+				} else {
2590
+					$this->setCurlOption(CURLOPT_PROXY, $this->proxy['host']);
2591
+				}
2592
+				if ($this->proxy['username'] || $this->proxy['password']) {
2593
+					$this->debug('set cURL proxy authentication options');
2594
+					$this->setCurlOption(CURLOPT_PROXYUSERPWD, $this->proxy['username'] . ':' . $this->proxy['password']);
2595
+					if ($this->proxy['authtype'] == 'basic') {
2596
+						$this->setCurlOption($CURLOPT_PROXYAUTH, $CURLAUTH_BASIC);
2597
+					}
2598
+					if ($this->proxy['authtype'] == 'ntlm') {
2599
+						$this->setCurlOption($CURLOPT_PROXYAUTH, $CURLAUTH_NTLM);
2600
+					}
2601
+				}
2602
+			}
2603
+			$this->debug('cURL connection set up');
2604
+			return true;
2605
+		} else {
2606
+			$this->setError('Unknown scheme ' . $this->scheme);
2607
+			$this->debug('Unknown scheme ' . $this->scheme);
2608
+			return false;
2609
+		}
2610
+	}
2611
+
2612
+	/**
2613
+	 * sends the SOAP request and gets the SOAP response via HTTP[S]
2614
+	 *
2615
+	 * @param    string $data message data
2616
+	 * @param    integer $timeout set connection timeout in seconds
2617
+	 * @param    integer $response_timeout set response timeout in seconds
2618
+	 * @param    array $cookies cookies to send
2619
+	 * @return    string data
2620
+	 * @access   public
2621
+	 */
2622
+	function send($data, $timeout = 0, $response_timeout = 30, $cookies = null)
2623
+	{
2624
+		$this->debug('entered send() with data of length: ' . strlen($data));
2625
+
2626
+		$respdata = "";
2627
+		$this->tryagain = true;
2628
+		$tries = 0;
2629
+		while ($this->tryagain) {
2630
+			$this->tryagain = false;
2631
+			if ($tries++ < 2) {
2632
+				// make connnection
2633
+				if (!$this->connect($timeout, $response_timeout)) {
2634
+					return false;
2635
+				}
2636
+
2637
+				// send request
2638
+				if (!$this->sendRequest($data, $cookies)) {
2639
+					return false;
2640
+				}
2641
+
2642
+				// get response
2643
+				$respdata = $this->getResponse();
2644
+			} else {
2645
+				$this->setError("Too many tries to get an OK response ($this->response_status_line)");
2646
+			}
2647
+		}
2648
+		$this->debug('end of send()');
2649
+		return $respdata;
2650
+	}
2651
+
2652
+
2653
+	/**
2654
+	 * sends the SOAP request and gets the SOAP response via HTTPS using CURL
2655
+	 *
2656
+	 * @param    string $data message data
2657
+	 * @param    integer $timeout set connection timeout in seconds
2658
+	 * @param    integer $response_timeout set response timeout in seconds
2659
+	 * @param    array $cookies cookies to send
2660
+	 * @return    string data
2661
+	 * @access   public
2662
+	 */
2663
+	function sendHTTPS($data, $timeout = 0, $response_timeout = 30, $cookies = NULL)
2664
+	{
2665
+		return $this->send($data, $timeout, $response_timeout, $cookies);
2666
+	}
2667
+
2668
+	/**
2669
+	 * if authenticating, set user credentials here
2670
+	 *
2671
+	 * @param    string $username
2672
+	 * @param    string $password
2673
+	 * @param    string $authtype (basic|digest|certificate|ntlm)
2674
+	 * @param    array $digestRequest (keys must be nonce, nc, realm, qop)
2675
+	 * @param    array $certRequest (keys must be cainfofile (optional), sslcertfile, sslkeyfile, passphrase, certpassword (optional), verifypeer (optional), verifyhost (optional): see corresponding options in cURL docs)
2676
+	 * @access   public
2677
+	 */
2678
+	function setCredentials($username, $password, $authtype = 'basic', $digestRequest = array(), $certRequest = array())
2679
+	{
2680
+		$this->debug("setCredentials username=$username authtype=$authtype digestRequest=");
2681
+		$this->appendDebug($this->varDump($digestRequest));
2682
+		$this->debug("certRequest=");
2683
+		$this->appendDebug($this->varDump($certRequest));
2684
+		// cf. RFC 2617
2685
+		if ($authtype == 'basic') {
2686
+			$this->setHeader('Authorization', 'Basic ' . base64_encode(str_replace(':', '', $username) . ':' . $password));
2687
+		} elseif ($authtype == 'digest') {
2688
+			if (isset($digestRequest['nonce'])) {
2689
+				$digestRequest['nc'] = isset($digestRequest['nc']) ? $digestRequest['nc']++ : 1;
2690
+
2691
+				// calculate the Digest hashes (calculate code based on digest implementation found at: http://www.rassoc.com/gregr/weblog/stories/2002/07/09/webServicesSecurityHttpDigestAuthenticationWithoutActiveDirectory.html)
2692
+
2693
+				// A1 = unq(username-value) ":" unq(realm-value) ":" passwd
2694
+				$A1 = $username . ':' . (isset($digestRequest['realm']) ? $digestRequest['realm'] : '') . ':' . $password;
2695
+
2696
+				// H(A1) = MD5(A1)
2697
+				$HA1 = md5($A1);
2698
+
2699
+				// A2 = Method ":" digest-uri-value
2700
+				$A2 = $this->request_method . ':' . $this->digest_uri;
2701
+
2702
+				// H(A2)
2703
+				$HA2 = md5($A2);
2704
+
2705
+				// KD(secret, data) = H(concat(secret, ":", data))
2706
+				// if qop == auth:
2707
+				// request-digest  = <"> < KD ( H(A1),     unq(nonce-value)
2708
+				//                              ":" nc-value
2709
+				//                              ":" unq(cnonce-value)
2710
+				//                              ":" unq(qop-value)
2711
+				//                              ":" H(A2)
2712
+				//                            ) <">
2713
+				// if qop is missing,
2714
+				// request-digest  = <"> < KD ( H(A1), unq(nonce-value) ":" H(A2) ) > <">
2715
+
2716
+				$nonce = $digestRequest['nonce'];
2717
+				$cnonce = $nonce;
2718
+				if ($digestRequest['qop'] != '') {
2719
+					$unhashedDigest = $HA1 . ':' . $nonce . ':' . sprintf("%08d", $digestRequest['nc']) . ':' . $cnonce . ':' . $digestRequest['qop'] . ':' . $HA2;
2720
+				} else {
2721
+					$unhashedDigest = $HA1 . ':' . $nonce . ':' . $HA2;
2722
+				}
2723
+
2724
+				$hashedDigest = md5($unhashedDigest);
2725
+
2726
+				$opaque = '';
2727
+				if (isset($digestRequest['opaque'])) {
2728
+					$opaque = ', opaque="' . $digestRequest['opaque'] . '"';
2729
+				}
2730
+
2731
+				$this->setHeader('Authorization', 'Digest username="' . $username . '", realm="' . $digestRequest['realm'] . '", nonce="' . $nonce . '", uri="' . $this->digest_uri . $opaque . '", cnonce="' . $cnonce . '", nc=' . sprintf("%08x", $digestRequest['nc']) . ', qop="' . $digestRequest['qop'] . '", response="' . $hashedDigest . '"');
2732
+			}
2733
+		} elseif ($authtype == 'certificate') {
2734
+			$this->certRequest = $certRequest;
2735
+			$this->debug('Authorization header not set for certificate');
2736
+		} elseif ($authtype == 'ntlm') {
2737
+			// do nothing
2738
+			$this->debug('Authorization header not set for ntlm');
2739
+		}
2740
+		$this->username = $username;
2741
+		$this->password = $password;
2742
+		$this->authtype = $authtype;
2743
+		$this->digestRequest = $digestRequest;
2744
+	}
2745
+
2746
+	/**
2747
+	 * set the soapaction value
2748
+	 *
2749
+	 * @param    string $soapaction
2750
+	 * @access   public
2751
+	 */
2752
+	function setSOAPAction($soapaction)
2753
+	{
2754
+		$this->setHeader('SOAPAction', '"' . $soapaction . '"');
2755
+	}
2756
+
2757
+	/**
2758
+	 * use http encoding
2759
+	 *
2760
+	 * @param    string $enc encoding style. supported values: gzip, deflate, or both
2761
+	 * @access   public
2762
+	 */
2763
+	function setEncoding($enc = 'gzip, deflate')
2764
+	{
2765
+		if (function_exists('gzdeflate')) {
2766
+			$this->protocol_version = '1.1';
2767
+			$this->setHeader('Accept-Encoding', $enc);
2768
+			if (!isset($this->outgoing_headers['Connection'])) {
2769
+				$this->setHeader('Connection', 'close');
2770
+				$this->persistentConnection = false;
2771
+			}
2772
+			// deprecated as of PHP 5.3.0
2773
+			//set_magic_quotes_runtime(0);
2774
+			$this->encoding = $enc;
2775
+		}
2776
+	}
2777
+
2778
+	/**
2779
+	 * set proxy info here
2780
+	 *
2781
+	 * @param    string $proxyhost use an empty string to remove proxy
2782
+	 * @param    string $proxyport
2783
+	 * @param    string $proxyusername
2784
+	 * @param    string $proxypassword
2785
+	 * @param    string $proxyauthtype (basic|ntlm)
2786
+	 * @access   public
2787
+	 */
2788
+	function setProxy($proxyhost, $proxyport, $proxyusername = '', $proxypassword = '', $proxyauthtype = 'basic')
2789
+	{
2790
+		if ($proxyhost) {
2791
+			$this->proxy = array(
2792
+				'host' => $proxyhost,
2793
+				'port' => $proxyport,
2794
+				'username' => $proxyusername,
2795
+				'password' => $proxypassword,
2796
+				'authtype' => $proxyauthtype
2797
+			);
2798
+			if ($proxyusername != '' && $proxypassword != '' && $proxyauthtype == 'basic') {
2799
+				$this->setHeader('Proxy-Authorization', ' Basic ' . base64_encode($proxyusername . ':' . $proxypassword));
2800
+			}
2801
+		} else {
2802
+			$this->debug('remove proxy');
2803
+			$this->unsetHeader('Proxy-Authorization');
2804
+		}
2805
+	}
2806
+
2807
+
2808
+	/**
2809
+	 * Test if the given string starts with a header that is to be skipped.
2810
+	 * Skippable headers result from chunked transfer and proxy requests.
2811
+	 *
2812
+	 * @param    string $data The string to check.
2813
+	 * @returns    boolean    Whether a skippable header was found.
2814
+	 * @access    private
2815
+	 */
2816
+	function isSkippableCurlHeader($data)
2817
+	{
2818
+		$skipHeaders = array('HTTP/1.1 100',
2819
+			'HTTP/1.0 301',
2820
+			'HTTP/1.1 301',
2821
+			'HTTP/1.0 302',
2822
+			'HTTP/1.1 302',
2823
+			'HTTP/1.0 401',
2824
+			'HTTP/1.1 401',
2825
+			'HTTP/1.0 200 Connection established',
2826
+			'HTTP/1.1 200 Connection established');
2827
+		foreach ($skipHeaders as $hd) {
2828
+			$prefix = substr($data, 0, strlen($hd));
2829
+			if ($prefix == $hd) {
2830
+				return true;
2831
+			}
2832
+		}
2833
+
2834
+		return false;
2835
+	}
2836
+
2837
+	/**
2838
+	 * decode a string that is encoded w/ "chunked' transfer encoding
2839
+	 * as defined in RFC2068 19.4.6
2840
+	 *
2841
+	 * @param    string $buffer
2842
+	 * @param    string $lb
2843
+	 * @returns    string
2844
+	 * @access   public
2845
+	 * @deprecated
2846
+	 */
2847
+	function decodeChunked($buffer, $lb)
2848
+	{
2849
+		$new = '';
2850
+
2851
+		// read chunk-size, chunk-extension (if any) and CRLF
2852
+		// get the position of the linebreak
2853
+		$chunkend = strpos($buffer, $lb);
2854
+		if (!$chunkend) {
2855
+			$this->debug('no linebreak found in decodeChunked');
2856
+			return $new;
2857
+		}
2858
+		$temp = substr($buffer, 0, $chunkend);
2859
+		$chunk_size = hexdec(trim($temp));
2860
+		$chunkstart = $chunkend + strlen($lb);
2861
+		// while (chunk-size > 0) {
2862
+		while ($chunk_size > 0) {
2863
+			$this->debug("chunkstart: $chunkstart chunk_size: $chunk_size");
2864
+			$chunkend = strpos($buffer, $lb, $chunkstart + $chunk_size);
2865
+
2866
+			// Just in case we got a broken connection
2867
+			if (!$chunkend) {
2868
+				$chunk = substr($buffer, $chunkstart);
2869
+				// append chunk-data to entity-body
2870
+				$new .= $chunk;
2871
+				break;
2872
+			}
2873
+
2874
+			// read chunk-data and CRLF
2875
+			$chunk = substr($buffer, $chunkstart, $chunkend - $chunkstart);
2876
+			// append chunk-data to entity-body
2877
+			$new .= $chunk;
2878
+			// length := length + chunk-size
2879
+			// read chunk-size and CRLF
2880
+			$chunkstart = $chunkend + strlen($lb);
2881
+
2882
+			$chunkend = strpos($buffer, $lb, $chunkstart) + strlen($lb);
2883
+			if (!$chunkend) {
2884
+				break; //Just in case we got a broken connection
2885
+			}
2886
+			$temp = substr($buffer, $chunkstart, $chunkend - $chunkstart);
2887
+			$chunk_size = hexdec(trim($temp));
2888
+			$chunkstart = $chunkend;
2889
+		}
2890
+		return $new;
2891
+	}
2892
+
2893
+	/**
2894
+	 * Writes the payload, including HTTP headers, to $this->outgoing_payload.
2895
+	 *
2896
+	 * @param    string $data HTTP body
2897
+	 * @param    string $cookie_str data for HTTP Cookie header
2898
+	 * @return    void
2899
+	 * @access    private
2900
+	 */
2901
+	function buildPayload($data, $cookie_str = '')
2902
+	{
2903
+		// Note: for cURL connections, $this->outgoing_payload is ignored,
2904
+		// as is the Content-Length header, but these are still created as
2905
+		// debugging guides.
2906
+
2907
+		// add content-length header
2908
+		if ($this->request_method != 'GET') {
2909
+			$this->setHeader('Content-Length', strlen($data));
2910
+		}
2911
+
2912
+		// start building outgoing payload:
2913
+		if ($this->proxy) {
2914
+			$uri = $this->url;
2915
+		} else {
2916
+			$uri = $this->uri;
2917
+		}
2918
+		$req = "$this->request_method $uri HTTP/$this->protocol_version";
2919
+		$this->debug("HTTP request: $req");
2920
+		$this->outgoing_payload = "$req\r\n";
2921
+
2922
+		// loop thru headers, serializing
2923
+		foreach ($this->outgoing_headers as $k => $v) {
2924
+			$hdr = $k . ': ' . $v;
2925
+			$this->debug("HTTP header: $hdr");
2926
+			$this->outgoing_payload .= "$hdr\r\n";
2927
+		}
2928
+
2929
+		// add any cookies
2930
+		if ($cookie_str != '') {
2931
+			$hdr = 'Cookie: ' . $cookie_str;
2932
+			$this->debug("HTTP header: $hdr");
2933
+			$this->outgoing_payload .= "$hdr\r\n";
2934
+		}
2935
+
2936
+		// header/body separator
2937
+		$this->outgoing_payload .= "\r\n";
2938
+
2939
+		// add data
2940
+		$this->outgoing_payload .= $data;
2941
+	}
2942
+
2943
+	/**
2944
+	 * sends the SOAP request via HTTP[S]
2945
+	 *
2946
+	 * @param    string $data message data
2947
+	 * @param    array $cookies cookies to send
2948
+	 * @return    boolean    true if OK, false if problem
2949
+	 * @access   private
2950
+	 */
2951
+	function sendRequest($data, $cookies = null)
2952
+	{
2953
+		// build cookie string
2954
+		$cookie_str = $this->getCookiesForRequest($cookies, (($this->scheme == 'ssl') || ($this->scheme == 'https')));
2955
+
2956
+		// build payload
2957
+		$this->buildPayload($data, $cookie_str);
2958
+
2959
+		if ($this->io_method() == 'socket') {
2960
+			// send payload
2961
+			if (!fputs($this->fp, $this->outgoing_payload, strlen($this->outgoing_payload))) {
2962
+				$this->setError('couldn\'t write message data to socket');
2963
+				$this->debug('couldn\'t write message data to socket');
2964
+				return false;
2965
+			}
2966
+			$this->debug('wrote data to socket, length = ' . strlen($this->outgoing_payload));
2967
+			return true;
2968
+		} elseif ($this->io_method() == 'curl') {
2969
+			// set payload
2970
+			// cURL does say this should only be the verb, and in fact it
2971
+			// turns out that the URI and HTTP version are appended to this, which
2972
+			// some servers refuse to work with (so we no longer use this method!)
2973
+			//$this->setCurlOption(CURLOPT_CUSTOMREQUEST, $this->outgoing_payload);
2974
+			$curl_headers = array();
2975
+			foreach ($this->outgoing_headers as $k => $v) {
2976
+				if ($k == 'Connection' || $k == 'Content-Length' || $k == 'Host' || $k == 'Authorization' || $k == 'Proxy-Authorization') {
2977
+					$this->debug("Skip cURL header $k: $v");
2978
+				} else {
2979
+					$curl_headers[] = "$k: $v";
2980
+				}
2981
+			}
2982
+			if ($cookie_str != '') {
2983
+				$curl_headers[] = 'Cookie: ' . $cookie_str;
2984
+			}
2985
+			$this->setCurlOption(CURLOPT_HTTPHEADER, $curl_headers);
2986
+			$this->debug('set cURL HTTP headers');
2987
+			if ($this->request_method == "POST") {
2988
+				$this->setCurlOption(CURLOPT_POST, 1);
2989
+				$this->setCurlOption(CURLOPT_POSTFIELDS, $data);
2990
+				$this->debug('set cURL POST data');
2991
+			}
2992
+			// insert custom user-set cURL options
2993
+			foreach ($this->ch_options as $key => $val) {
2994
+				$this->setCurlOption($key, $val);
2995
+			}
2996
+
2997
+			$this->debug('set cURL payload');
2998
+			return true;
2999
+		}
3000
+		return false;
3001
+	}
3002
+
3003
+	/**
3004
+	 * gets the SOAP response via HTTP[S]
3005
+	 *
3006
+	 * @return    string the response (also sets member variables like incoming_payload)
3007
+	 * @access   private
3008
+	 */
3009
+	function getResponse()
3010
+	{
3011
+		$this->incoming_payload = '';
3012
+		$header_array = array ();
3013
+		$data = '';
3014
+
3015
+		if ($this->io_method() == 'socket') {
3016
+			// loop until headers have been retrieved
3017
+			$pos = 0;
3018
+			while (!isset($lb)) {
3019
+				// We might EOF during header read.
3020
+				if (feof($this->fp)) {
3021
+					$this->incoming_payload = $data;
3022
+					$this->debug('found no headers before EOF after length ' . strlen($data));
3023
+					$this->debug("received before EOF:\n" . $data);
3024
+					$this->setError('server failed to send headers');
3025
+					return false;
3026
+				}
3027
+
3028
+				$tmp = fgets($this->fp, 256);
3029
+				$tmplen = strlen($tmp);
3030
+				$this->debug("read line of $tmplen bytes: " . trim($tmp));
3031
+
3032
+				if ($tmplen == 0) {
3033
+					$this->incoming_payload = $data;
3034
+					$this->debug('socket read of headers timed out after length ' . strlen($data));
3035
+					$this->debug("read before timeout: " . $data);
3036
+					$this->setError('socket read of headers timed out');
3037
+					return false;
3038
+				}
3039
+
3040
+				$data .= $tmp;
3041
+				$pos = strpos($data, "\r\n\r\n");
3042
+				if ($pos > 1) {
3043
+					$lb = "\r\n";
3044
+				} else {
3045
+					$pos = strpos($data, "\n\n");
3046
+					if ($pos > 1) {
3047
+						$lb = "\n";
3048
+					}
3049
+				}
3050
+				// remove 100 headers
3051
+				if (isset($lb) && preg_match('/^HTTP\/1.1 100/', $data)) {
3052
+					unset($lb);
3053
+					$data = '';
3054
+				}//
3055
+			}
3056
+			// store header data
3057
+			$this->incoming_payload .= $data;
3058
+			$this->debug('found end of headers after length ' . strlen($data));
3059
+			// process headers
3060
+			$header_data = trim(substr($data, 0, $pos));
3061
+			$header_array = explode($lb, $header_data);
3062
+			$this->incoming_headers = array();
3063
+			$this->incoming_cookies = array();
3064
+			foreach ($header_array as $header_line) {
3065
+				$arr = explode(':', $header_line, 2);
3066
+				if (count($arr) > 1) {
3067
+					$header_name = strtolower(trim($arr[0]));
3068
+					$this->incoming_headers[$header_name] = trim($arr[1]);
3069
+					if ($header_name == 'set-cookie') {
3070
+						// TODO: allow multiple cookies from parseCookie
3071
+						$cookie = $this->parseCookie(trim($arr[1]));
3072
+						if ($cookie) {
3073
+							$this->incoming_cookies[] = $cookie;
3074
+							$this->debug('found cookie: ' . $cookie['name'] . ' = ' . $cookie['value']);
3075
+						} else {
3076
+							$this->debug('did not find cookie in ' . trim($arr[1]));
3077
+						}
3078
+					}
3079
+				} elseif (isset($header_name)) {
3080
+					// append continuation line to previous header
3081
+					$this->incoming_headers[$header_name] .= $lb . ' ' . $header_line;
3082
+				}
3083
+			}
3084
+
3085
+			// loop until msg has been received
3086
+			if (isset($this->incoming_headers['transfer-encoding']) && strtolower($this->incoming_headers['transfer-encoding']) == 'chunked') {
3087
+				$content_length = 2147483647;    // ignore any content-length header
3088
+				$chunked = true;
3089
+				$this->debug("want to read chunked content");
3090
+			} elseif (isset($this->incoming_headers['content-length'])) {
3091
+				$content_length = $this->incoming_headers['content-length'];
3092
+				$chunked = false;
3093
+				$this->debug("want to read content of length $content_length");
3094
+			} else {
3095
+				$content_length = 2147483647;
3096
+				$chunked = false;
3097
+				$this->debug("want to read content to EOF");
3098
+			}
3099
+			$data = '';
3100
+			do {
3101
+				if ($chunked) {
3102
+					$tmp = fgets($this->fp, 256);
3103
+					$tmplen = strlen($tmp);
3104
+					$this->debug("read chunk line of $tmplen bytes");
3105
+					if ($tmplen == 0) {
3106
+						$this->incoming_payload = $data;
3107
+						$this->debug('socket read of chunk length timed out after length ' . strlen($data));
3108
+						$this->debug("read before timeout:\n" . $data);
3109
+						$this->setError('socket read of chunk length timed out');
3110
+						return false;
3111
+					}
3112
+					$content_length = hexdec(trim($tmp));
3113
+					$this->debug("chunk length $content_length");
3114
+				}
3115
+				$strlen = 0;
3116
+				while (($strlen < $content_length) && (!feof($this->fp))) {
3117
+					$readlen = min(8192, $content_length - $strlen);
3118
+					$tmp = fread($this->fp, $readlen);
3119
+					$tmplen = strlen($tmp);
3120
+					$this->debug("read buffer of $tmplen bytes");
3121
+					if (($tmplen == 0) && (!feof($this->fp))) {
3122
+						$this->incoming_payload = $data;
3123
+						$this->debug('socket read of body timed out after length ' . strlen($data));
3124
+						$this->debug("read before timeout:\n" . $data);
3125
+						$this->setError('socket read of body timed out');
3126
+						return false;
3127
+					}
3128
+					$strlen += $tmplen;
3129
+					$data .= $tmp;
3130
+				}
3131
+				if ($chunked && ($content_length > 0)) {
3132
+					$tmp = fgets($this->fp, 256);
3133
+					$tmplen = strlen($tmp);
3134
+					$this->debug("read chunk terminator of $tmplen bytes");
3135
+					if ($tmplen == 0) {
3136
+						$this->incoming_payload = $data;
3137
+						$this->debug('socket read of chunk terminator timed out after length ' . strlen($data));
3138
+						$this->debug("read before timeout:\n" . $data);
3139
+						$this->setError('socket read of chunk terminator timed out');
3140
+						return false;
3141
+					}
3142
+				}
3143
+			} while ($chunked && ($content_length > 0) && (!feof($this->fp)));
3144
+			if (feof($this->fp)) {
3145
+				$this->debug('read to EOF');
3146
+			}
3147
+			$this->debug('read body of length ' . strlen($data));
3148
+			$this->incoming_payload .= $data;
3149
+			$this->debug('received a total of ' . strlen($this->incoming_payload) . ' bytes of data from server');
3150
+
3151
+			// close filepointer
3152
+			if (
3153
+				(isset($this->incoming_headers['connection']) && strtolower($this->incoming_headers['connection']) == 'close') ||
3154
+				(!$this->persistentConnection) || feof($this->fp)
3155
+			) {
3156
+				fclose($this->fp);
3157
+				$this->fp = false;
3158
+				$this->debug('closed socket');
3159
+			}
3160
+
3161
+			// connection was closed unexpectedly
3162
+			if ($this->incoming_payload == '') {
3163
+				$this->setError('no response from server');
3164
+				return false;
3165
+			}
3166
+
3167
+			// decode transfer-encoding
3168
+//		if(isset($this->incoming_headers['transfer-encoding']) && strtolower($this->incoming_headers['transfer-encoding']) == 'chunked'){
3169
+//			if(!$data = $this->decodeChunked($data, $lb)){
3170
+//				$this->setError('Decoding of chunked data failed');
3171
+//				return false;
3172
+//			}
3173
+			//print "<pre>\nde-chunked:\n---------------\n$data\n\n---------------\n</pre>";
3174
+			// set decoded payload
3175
+//			$this->incoming_payload = $header_data.$lb.$lb.$data;
3176
+//		}
3177
+
3178
+		} elseif ($this->io_method() == 'curl') {
3179
+			// send and receive
3180
+			$this->debug('send and receive with cURL');
3181
+			$this->incoming_payload = curl_exec($this->ch);
3182
+			$data = $this->incoming_payload;
3183
+
3184
+			$cErr = curl_error($this->ch);
3185
+			if ($cErr != '') {
3186
+				$err = 'cURL ERROR: ' . curl_errno($this->ch) . ': ' . $cErr . '<br>';
3187
+				// TODO: there is a PHP bug that can cause this to SEGV for CURLINFO_CONTENT_TYPE
3188
+				foreach (curl_getinfo($this->ch) as $k => $v) {
3189
+					if (is_array($v)) {
3190
+						$this->debug("$k: " . json_encode($v));
3191
+					} else {
3192
+						$this->debug("$k: $v<br>");
3193
+					}
3194
+				}
3195
+				$this->debug($err);
3196
+				$this->setError($err);
3197
+				curl_close($this->ch);
3198
+				return false;
3199
+			}
3200
+			// close curl
3201
+			$this->debug('No cURL error, closing cURL');
3202
+			curl_close($this->ch);
3203
+
3204
+			// try removing skippable headers
3205
+			$savedata = $data;
3206
+			while ($this->isSkippableCurlHeader($data)) {
3207
+				$this->debug("Found HTTP header to skip");
3208
+				if ($pos = strpos($data, "\r\n\r\n")) {
3209
+					$data = ltrim(substr($data, $pos));
3210
+				} elseif ($pos = strpos($data, "\n\n")) {
3211
+					$data = ltrim(substr($data, $pos));
3212
+				}
3213
+			}
3214
+
3215
+			if ($data == '') {
3216
+				// have nothing left; just remove 100 header(s)
3217
+				$data = $savedata;
3218
+				while (preg_match('/^HTTP\/1.1 100/', $data)) {
3219
+					if ($pos = strpos($data, "\r\n\r\n")) {
3220
+						$data = ltrim(substr($data, $pos));
3221
+					} elseif ($pos = strpos($data, "\n\n")) {
3222
+						$data = ltrim(substr($data, $pos));
3223
+					}
3224
+				}
3225
+			}
3226
+
3227
+			// separate content from HTTP headers
3228
+			if ($pos = strpos($data, "\r\n\r\n")) {
3229
+				$lb = "\r\n";
3230
+			} elseif ($pos = strpos($data, "\n\n")) {
3231
+				$lb = "\n";
3232
+			} else {
3233
+				$this->debug('no proper separation of headers and document');
3234
+				$this->setError('no proper separation of headers and document');
3235
+				return false;
3236
+			}
3237
+			$header_data = trim(substr($data, 0, $pos));
3238
+			$header_array = explode($lb, $header_data);
3239
+			$data = ltrim(substr($data, $pos));
3240
+			$this->debug('found proper separation of headers and document');
3241
+			$this->debug('cleaned data, stringlen: ' . strlen($data));
3242
+			// clean headers
3243
+			foreach ($header_array as $header_line) {
3244
+				$arr = explode(':', $header_line, 2);
3245
+				if (count($arr) > 1) {
3246
+					$header_name = strtolower(trim($arr[0]));
3247
+					$this->incoming_headers[$header_name] = trim($arr[1]);
3248
+					if ($header_name == 'set-cookie') {
3249
+						// TODO: allow multiple cookies from parseCookie
3250
+						$cookie = $this->parseCookie(trim($arr[1]));
3251
+						if ($cookie) {
3252
+							$this->incoming_cookies[] = $cookie;
3253
+							$this->debug('found cookie: ' . $cookie['name'] . ' = ' . $cookie['value']);
3254
+						} else {
3255
+							$this->debug('did not find cookie in ' . trim($arr[1]));
3256
+						}
3257
+					}
3258
+				} elseif (isset($header_name)) {
3259
+					// append continuation line to previous header
3260
+					$this->incoming_headers[$header_name] .= $lb . ' ' . $header_line;
3261
+				}
3262
+			}
3263
+		}
3264
+
3265
+		$this->response_status_line = $header_array[0];
3266
+		$arr = explode(' ', $this->response_status_line, 3);
3267
+		$http_status = intval($arr[1]);
3268
+		$http_reason = count($arr) > 2 ? $arr[2] : '';
3269
+
3270
+		// see if we need to resend the request with http digest authentication
3271
+		if (isset($this->incoming_headers['location']) && ($http_status == 301 || $http_status == 302)) {
3272
+			$this->debug("Got $http_status $http_reason with Location: " . $this->incoming_headers['location']);
3273
+			$this->setURL($this->incoming_headers['location']);
3274
+			$this->tryagain = true;
3275
+			return false;
3276
+		}
3277
+
3278
+		// see if we need to resend the request with http digest authentication
3279
+		if (isset($this->incoming_headers['www-authenticate']) && $http_status == 401) {
3280
+			$this->debug("Got 401 $http_reason with WWW-Authenticate: " . $this->incoming_headers['www-authenticate']);
3281
+			if (strstr($this->incoming_headers['www-authenticate'], "Digest ")) {
3282
+				$this->debug('Server wants digest authentication');
3283
+				// remove "Digest " from our elements
3284
+				$digestString = str_replace('Digest ', '', $this->incoming_headers['www-authenticate']);
3285
+
3286
+				// parse elements into array
3287
+				$digestElements = explode(',', $digestString);
3288
+				foreach ($digestElements as $val) {
3289
+					$tempElement = explode('=', trim($val), 2);
3290
+					$digestRequest[$tempElement[0]] = str_replace("\"", '', $tempElement[1]);
3291
+				}
3292
+
3293
+				// should have (at least) qop, realm, nonce
3294
+				if (isset($digestRequest['nonce'])) {
3295
+					$this->setCredentials($this->username, $this->password, 'digest', $digestRequest);
3296
+					$this->tryagain = true;
3297
+					return false;
3298
+				}
3299
+			}
3300
+			$this->debug('HTTP authentication failed');
3301
+			$this->setError('HTTP authentication failed');
3302
+			return false;
3303
+		}
3304
+
3305
+		if (
3306
+			($http_status >= 300 && $http_status <= 307) ||
3307
+			($http_status >= 400 && $http_status <= 417) ||
3308
+			($http_status >= 501 && $http_status <= 505)
3309
+		) {
3310
+			$this->setError("Unsupported HTTP response status $http_status $http_reason (soapclient->response has contents of the response)");
3311
+			return false;
3312
+		}
3313
+
3314
+		// decode content-encoding
3315
+		if (isset($this->incoming_headers['content-encoding']) && $this->incoming_headers['content-encoding'] != '') {
3316
+			if (strtolower($this->incoming_headers['content-encoding']) == 'deflate' || strtolower($this->incoming_headers['content-encoding']) == 'gzip') {
3317
+				$header_data = "";
3318
+				// if decoding works, use it. else assume data wasn't gzencoded
3319
+				if (function_exists('gzinflate')) {
3320
+					//$timer->setMarker('starting decoding of gzip/deflated content');
3321
+					// IIS 5 requires gzinflate instead of gzuncompress (similar to IE 5 and gzdeflate v. gzcompress)
3322
+					// this means there are no Zlib headers, although there should be
3323
+					$this->debug('The gzinflate function exists');
3324
+					$datalen = strlen($data);
3325
+					if ($this->incoming_headers['content-encoding'] == 'deflate') {
3326
+						if ($degzdata = @gzinflate($data)) {
3327
+							$data = $degzdata;
3328
+							$this->debug('The payload has been inflated to ' . strlen($data) . ' bytes');
3329
+							if (strlen($data) < $datalen) {
3330
+								// test for the case that the payload has been compressed twice
3331
+								$this->debug('The inflated payload is smaller than the gzipped one; try again');
3332
+								if ($degzdata = @gzinflate($data)) {
3333
+									$data = $degzdata;
3334
+									$this->debug('The payload has been inflated again to ' . strlen($data) . ' bytes');
3335
+								}
3336
+							}
3337
+						} else {
3338
+							$this->debug('Error using gzinflate to inflate the payload');
3339
+							$this->setError('Error using gzinflate to inflate the payload');
3340
+						}
3341
+					} elseif ($this->incoming_headers['content-encoding'] == 'gzip') {
3342
+						if ($degzdata = @gzinflate(substr($data, 10))) {    // do our best
3343
+							$data = $degzdata;
3344
+							$this->debug('The payload has been un-gzipped to ' . strlen($data) . ' bytes');
3345
+							if (strlen($data) < $datalen) {
3346
+								// test for the case that the payload has been compressed twice
3347
+								$this->debug('The un-gzipped payload is smaller than the gzipped one; try again');
3348
+								if ($degzdata = @gzinflate(substr($data, 10))) {
3349
+									$data = $degzdata;
3350
+									$this->debug('The payload has been un-gzipped again to ' . strlen($data) . ' bytes');
3351
+								}
3352
+							}
3353
+						} else {
3354
+							$this->debug('Error using gzinflate to un-gzip the payload');
3355
+							$this->setError('Error using gzinflate to un-gzip the payload');
3356
+						}
3357
+					}
3358
+					//$timer->setMarker('finished decoding of gzip/deflated content');
3359
+					//print "<xmp>\nde-inflated:\n---------------\n$data\n-------------\n</xmp>";
3360
+					// set decoded payload
3361
+					$this->incoming_payload = $header_data . (isset ($lb) ? $lb : "") . (isset ($lb) ? $lb : "") . $data;
3362
+				} else {
3363
+					$this->debug('The server sent compressed data. Your php install must have the Zlib extension compiled in to support this.');
3364
+					$this->setError('The server sent compressed data. Your php install must have the Zlib extension compiled in to support this.');
3365
+				}
3366
+			} else {
3367
+				$this->debug('Unsupported Content-Encoding ' . $this->incoming_headers['content-encoding']);
3368
+				$this->setError('Unsupported Content-Encoding ' . $this->incoming_headers['content-encoding']);
3369
+			}
3370
+		} else {
3371
+			$this->debug('No Content-Encoding header');
3372
+		}
3373
+
3374
+		if (strlen($data) == 0) {
3375
+			$this->debug('no data after headers!');
3376
+			$this->setError('no data present after HTTP headers');
3377
+			return false;
3378
+		}
3379
+
3380
+		return $data;
3381
+	}
3382
+
3383
+	/**
3384
+	 * sets the content-type for the SOAP message to be sent
3385
+	 *
3386
+	 * @param    string $type the content type, MIME style
3387
+	 * @param    mixed $charset character set used for encoding (or false)
3388
+	 * @access    public
3389
+	 */
3390
+	function setContentType($type, $charset = false)
3391
+	{
3392
+		$this->setHeader('Content-Type', $type . ($charset ? '; charset=' . $charset : ''));
3393
+	}
3394
+
3395
+	/**
3396
+	 * specifies that an HTTP persistent connection should be used
3397
+	 *
3398
+	 * @return    boolean whether the request was honored by this method.
3399
+	 * @access    public
3400
+	 */
3401
+	function usePersistentConnection()
3402
+	{
3403
+		if (isset($this->outgoing_headers['Accept-Encoding'])) {
3404
+			return false;
3405
+		}
3406
+		$this->protocol_version = '1.1';
3407
+		$this->persistentConnection = true;
3408
+		$this->setHeader('Connection', 'Keep-Alive');
3409
+		return true;
3410
+	}
3411
+
3412
+	/**
3413
+	 * parse an incoming Cookie into it's parts
3414
+	 *
3415
+	 * @param    string $cookie_str content of cookie
3416
+	 * @return    array with data of that cookie
3417
+	 * @access    private
3418
+	 */
3419
+	/*
3420
+	 * TODO: allow a Set-Cookie string to be parsed into multiple cookies
3421
+	 */
3422
+	function parseCookie($cookie_str)
3423
+	{
3424
+		$cookie_str = str_replace('; ', ';', $cookie_str) . ';';
3425
+		$data = explode (';', $cookie_str);
3426
+		$value_str = $data[0];
3427
+
3428
+		$cookie_param = 'domain=';
3429
+		$start = strpos($cookie_str, $cookie_param);
3430
+		if ($start > 0) {
3431
+			$domain = substr($cookie_str, $start + strlen($cookie_param));
3432
+			$domain = substr($domain, 0, strpos($domain, ';'));
3433
+		} else {
3434
+			$domain = '';
3435
+		}
3436
+
3437
+		$cookie_param = 'expires=';
3438
+		$start = strpos($cookie_str, $cookie_param);
3439
+		if ($start > 0) {
3440
+			$expires = substr($cookie_str, $start + strlen($cookie_param));
3441
+			$expires = substr($expires, 0, strpos($expires, ';'));
3442
+		} else {
3443
+			$expires = '';
3444
+		}
3445
+
3446
+		$cookie_param = 'path=';
3447
+		$start = strpos($cookie_str, $cookie_param);
3448
+		if ($start > 0) {
3449
+			$path = substr($cookie_str, $start + strlen($cookie_param));
3450
+			$path = substr($path, 0, strpos($path, ';'));
3451
+		} else {
3452
+			$path = '/';
3453
+		}
3454
+
3455
+		$cookie_param = ';secure;';
3456
+		if (strpos($cookie_str, $cookie_param) !== false) {
3457
+			$secure = true;
3458
+		} else {
3459
+			$secure = false;
3460
+		}
3461
+
3462
+		$sep_pos = strpos($value_str, '=');
3463
+
3464
+		if ($sep_pos) {
3465
+			$name = substr($value_str, 0, $sep_pos);
3466
+			$value = substr($value_str, $sep_pos + 1);
3467
+
3468
+		  return array('name' => $name,
3469
+					 'value' => $value,
3470
+					 'domain' => $domain,
3471
+					 'path' => $path,
3472
+					 'expires' => $expires,
3473
+					 'secure' => $secure
3474
+		  );
3475
+		}
3476
+		return array ();
3477
+	}
3478
+
3479
+	/**
3480
+	 * sort out cookies for the current request
3481
+	 *
3482
+	 * @param    array $cookies array with all cookies
3483
+	 * @param    boolean $secure is the send-content secure or not?
3484
+	 * @return    string for Cookie-HTTP-Header
3485
+	 * @access    private
3486
+	 */
3487
+	function getCookiesForRequest($cookies, $secure = false)
3488
+	{
3489
+		$cookie_str = '';
3490
+		if ((is_array($cookies))) {
3491
+			foreach ($cookies as $cookie) {
3492
+				if (!is_array($cookie)) {
3493
+					continue;
3494
+				}
3495
+				$this->debug("check cookie for validity: " . $cookie['name'] . '=' . $cookie['value']);
3496
+				if ((isset($cookie['expires'])) && (!empty($cookie['expires']))) {
3497
+					if (strtotime($cookie['expires']) <= time()) {
3498
+						$this->debug('cookie has expired');
3499
+						continue;
3500
+					}
3501
+				}
3502
+				if ((isset($cookie['domain'])) && (!empty($cookie['domain']))) {
3503
+					$domain = preg_quote($cookie['domain'], "'");
3504
+					if (!preg_match("'.*$domain$'i", $this->host)) {
3505
+						$this->debug('cookie has different domain');
3506
+						continue;
3507
+					}
3508
+				}
3509
+				if ((isset($cookie['path'])) && (!empty($cookie['path']))) {
3510
+					$path = preg_quote($cookie['path'], "'");
3511
+					if (!preg_match("'^$path.*'i", $this->path)) {
3512
+						$this->debug('cookie is for a different path');
3513
+						continue;
3514
+					}
3515
+				}
3516
+				if ((!$secure) && (isset($cookie['secure'])) && ($cookie['secure'])) {
3517
+					$this->debug('cookie is secure, transport is not');
3518
+					continue;
3519
+				}
3520
+				$cookie_str .= $cookie['name'] . '=' . $cookie['value'] . '; ';
3521
+				$this->debug('add cookie to Cookie-String: ' . $cookie['name'] . '=' . $cookie['value']);
3522
+			}
3523
+		}
3524
+		return $cookie_str;
3525
+	}
3526
+}
3527
+
3528
+
3529
+/**
3530
+ *
3531
+ * nusoap_server allows the user to create a SOAP server
3532
+ * that is capable of receiving messages and returning responses
3533
+ *
3534
+ * @author   Dietrich Ayala <[email protected]>
3535
+ * @author   Scott Nichol <[email protected]>
3536
+ * @version  $Id: nusoap.php,v 1.123 2010/04/26 20:15:08 snichol Exp $
3537
+ * @access   public
3538
+ */
3539
+class nusoap_server extends nusoap_base
3540
+{
3541
+	/**
3542
+	 * HTTP headers of request
3543
+	 *
3544
+	 * @var array
3545
+	 * @access private
3546
+	 */
3547
+	var $headers = array();
3548
+	/**
3549
+	 * HTTP request
3550
+	 *
3551
+	 * @var string
3552
+	 * @access private
3553
+	 */
3554
+	var $request = '';
3555
+	/**
3556
+	 * SOAP headers from request (incomplete namespace resolution; special characters not escaped) (text)
3557
+	 *
3558
+	 * @var string
3559
+	 * @access public
3560
+	 */
3561
+	var $requestHeaders = '';
3562
+	/**
3563
+	 * SOAP Headers from request (parsed)
3564
+	 *
3565
+	 * @var mixed
3566
+	 * @access public
3567
+	 */
3568
+	var $requestHeader = null;
3569
+	/**
3570
+	 * SOAP body request portion (incomplete namespace resolution; special characters not escaped) (text)
3571
+	 *
3572
+	 * @var string
3573
+	 * @access public
3574
+	 */
3575
+	var $document = '';
3576
+	/**
3577
+	 * SOAP payload for request (text)
3578
+	 *
3579
+	 * @var string
3580
+	 * @access public
3581
+	 */
3582
+	var $requestSOAP = '';
3583
+	/**
3584
+	 * requested method namespace URI
3585
+	 *
3586
+	 * @var string
3587
+	 * @access private
3588
+	 */
3589
+	var $methodURI = '';
3590
+	/**
3591
+	 * name of method requested
3592
+	 *
3593
+	 * @var string
3594
+	 * @access private
3595
+	 */
3596
+	var $methodname = '';
3597
+	/**
3598
+	 * name of the response tag name
3599
+	 *
3600
+	 * @var string
3601
+	 * @access private
3602
+	 */
3603
+	var $responseTagName = '';
3604
+	/**
3605
+	 * method parameters from request
3606
+	 *
3607
+	 * @var array
3608
+	 * @access private
3609
+	 */
3610
+	var $methodparams = array();
3611
+	/**
3612
+	 * SOAP Action from request
3613
+	 *
3614
+	 * @var string
3615
+	 * @access private
3616
+	 */
3617
+	var $SOAPAction = '';
3618
+	/**
3619
+	 * character set encoding of incoming (request) messages
3620
+	 *
3621
+	 * @var string
3622
+	 * @access public
3623
+	 */
3624
+	var $xml_encoding = '';
3625
+	/**
3626
+	 * toggles whether the parser decodes element content w/ utf8_decode()
3627
+	 *
3628
+	 * @var boolean
3629
+	 * @access public
3630
+	 */
3631
+	var $decode_utf8 = true;
3632
+
3633
+	/**
3634
+	 * HTTP headers of response
3635
+	 *
3636
+	 * @var array
3637
+	 * @access public
3638
+	 */
3639
+	var $outgoing_headers = array();
3640
+	/**
3641
+	 * HTTP response
3642
+	 *
3643
+	 * @var string
3644
+	 * @access private
3645
+	 */
3646
+	var $response = '';
3647
+	/**
3648
+	 * SOAP headers for response (text or array of soapval or associative array)
3649
+	 *
3650
+	 * @var mixed
3651
+	 * @access public
3652
+	 */
3653
+	var $responseHeaders = '';
3654
+	/**
3655
+	 * SOAP payload for response (text)
3656
+	 *
3657
+	 * @var string
3658
+	 * @access private
3659
+	 */
3660
+	var $responseSOAP = '';
3661
+	/**
3662
+	 * SOAP attachments in response
3663
+	 *
3664
+	 * @var string
3665
+	 * @access private
3666
+	 */
3667
+	var $attachments= '';
3668
+	/**
3669
+	 * method return value to place in response
3670
+	 *
3671
+	 * @var mixed
3672
+	 * @access private
3673
+	 */
3674
+	var $methodreturn = false;
3675
+	/**
3676
+	 * whether $methodreturn is a string of literal XML
3677
+	 *
3678
+	 * @var boolean
3679
+	 * @access public
3680
+	 */
3681
+	var $methodreturnisliteralxml = false;
3682
+	/**
3683
+	 * SOAP fault for response (or false)
3684
+	 *
3685
+	 * @var mixed
3686
+	 * @access private
3687
+	 */
3688
+	var $fault = false;
3689
+	/**
3690
+	 * text indication of result (for debugging)
3691
+	 *
3692
+	 * @var string
3693
+	 * @access private
3694
+	 */
3695
+	var $result = 'successful';
3696
+
3697
+	/**
3698
+	 * assoc array of operations => opData; operations are added by the register()
3699
+	 * method or by parsing an external WSDL definition
3700
+	 *
3701
+	 * @var array
3702
+	 * @access private
3703
+	 */
3704
+	var $operations = array();
3705
+	/**
3706
+	 * wsdl instance (if one)
3707
+	 *
3708
+	 * @var mixed
3709
+	 * @access private
3710
+	 */
3711
+	var $wsdl = false;
3712
+	/**
3713
+	 * URL for WSDL (if one)
3714
+	 *
3715
+	 * @var mixed
3716
+	 * @access private
3717
+	 */
3718
+	var $externalWSDLURL = false;
3719
+	/**
3720
+	 * whether to append debug to response as XML comment
3721
+	 *
3722
+	 * @var boolean
3723
+	 * @access public
3724
+	 */
3725
+	var $debug_flag = false;
3726
+
3727
+	/** @var array */
3728
+	var $opData;
3729
+
3730
+
3731
+	/**
3732
+	 * constructor
3733
+	 * the optional parameter is a path to a WSDL file that you'd like to bind the server instance to.
3734
+	 *
3735
+	 * @param mixed $wsdl file path or URL (string), or wsdl instance (object)
3736
+	 * @access   public
3737
+	 */
3738
+	function __construct($wsdl = false)
3739
+	{
3740
+		parent::__construct();
3741
+		// turn on debugging?
3742
+		global $debug;
3743
+		global $HTTP_SERVER_VARS;
3744
+
3745
+		if (isset($_SERVER)) {
3746
+			$this->debug("_SERVER is defined:");
3747
+			$this->appendDebug($this->varDump($_SERVER));
3748
+		} elseif (isset($HTTP_SERVER_VARS)) {
3749
+			$this->debug("HTTP_SERVER_VARS is defined:");
3750
+			$this->appendDebug($this->varDump($HTTP_SERVER_VARS));
3751
+		} else {
3752
+			$this->debug("Neither _SERVER nor HTTP_SERVER_VARS is defined.");
3753
+		}
3754
+
3755
+		if (isset($debug)) {
3756
+			$this->debug("In nusoap_server, set debug_flag=$debug based on global flag");
3757
+			$this->debug_flag = $debug;
3758
+		} elseif (isset($_SERVER['QUERY_STRING'])) {
3759
+			$qs = explode('&', $_SERVER['QUERY_STRING']);
3760
+			foreach ($qs as $v) {
3761
+				if (substr($v, 0, 6) == 'debug=') {
3762
+					$this->debug("In nusoap_server, set debug_flag=" . substr($v, 6) . " based on query string #1");
3763
+					$this->debug_flag = substr($v, 6);
3764
+				}
3765
+			}
3766
+		} elseif (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
3767
+			$qs = explode('&', $HTTP_SERVER_VARS['QUERY_STRING']);
3768
+			foreach ($qs as $v) {
3769
+				if (substr($v, 0, 6) == 'debug=') {
3770
+					$this->debug("In nusoap_server, set debug_flag=" . substr($v, 6) . " based on query string #2");
3771
+					$this->debug_flag = substr($v, 6);
3772
+				}
3773
+			}
3774
+		}
3775
+
3776
+		// wsdl
3777
+		if ($wsdl) {
3778
+			$this->debug("In nusoap_server, WSDL is specified");
3779
+			if (is_object($wsdl) && (get_class($wsdl) == 'wsdl')) {
3780
+				$this->wsdl = $wsdl;
3781
+				$this->externalWSDLURL = $this->wsdl->wsdl;
3782
+				$this->debug('Use existing wsdl instance from ' . $this->externalWSDLURL);
3783
+			} else {
3784
+				$this->debug('Create wsdl from ' . $wsdl);
3785
+				$this->wsdl = new wsdl($wsdl);
3786
+				$this->externalWSDLURL = $wsdl;
3787
+			}
3788
+			$this->appendDebug($this->wsdl->getDebug());
3789
+			$this->wsdl->clearDebug();
3790
+			if ($err = $this->wsdl->getError()) {
3791
+				die('WSDL ERROR: ' . $err);
3792
+			}
3793
+		}
3794
+	}
3795
+
3796
+	/**
3797
+	 * processes request and returns response
3798
+	 *
3799
+	 * @param    string $data usually is the value of $HTTP_RAW_POST_DATA
3800
+	 * @access   public
3801
+	 */
3802
+	function service($data)
3803
+	{
3804
+		global $HTTP_SERVER_VARS;
3805
+
3806
+		if (isset($_SERVER['REQUEST_METHOD'])) {
3807
+			$rm = $_SERVER['REQUEST_METHOD'];
3808
+		} elseif (isset($HTTP_SERVER_VARS['REQUEST_METHOD'])) {
3809
+			$rm = $HTTP_SERVER_VARS['REQUEST_METHOD'];
3810
+		} else {
3811
+			$rm = '';
3812
+		}
3813
+
3814
+		if (isset($_SERVER['QUERY_STRING'])) {
3815
+			$qs = $_SERVER['QUERY_STRING'];
3816
+		} elseif (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
3817
+			$qs = $HTTP_SERVER_VARS['QUERY_STRING'];
3818
+		} else {
3819
+			$qs = '';
3820
+		}
3821
+		$this->debug("In service, request method=$rm query string=$qs strlen(\$data)=" . strlen($data));
3822
+
3823
+		if ($rm == 'POST') {
3824
+			$this->debug("In service, invoke the request");
3825
+			$this->parse_request($data);
3826
+			if (!$this->fault) {
3827
+				$this->invoke_method();
3828
+			}
3829
+			if (!$this->fault) {
3830
+				$this->serialize_return();
3831
+			}
3832
+			$this->send_response();
3833
+		} elseif (preg_match('/wsdl/', $qs)) {
3834
+			$this->debug("In service, this is a request for WSDL");
3835
+			if ($this->externalWSDLURL) {
3836
+				if (strpos($this->externalWSDLURL, "http://") !== false) { // assume URL
3837
+					$this->debug("In service, re-direct for WSDL");
3838
+					header('Location: ' . $this->externalWSDLURL);
3839
+				} else { // assume file
3840
+					$this->debug("In service, use file passthru for WSDL");
3841
+					header("Content-Type: text/xml\r\n");
3842
+					$fp = fopen($this->externalWSDLURL, 'r');
3843
+					fpassthru($fp);
3844
+				}
3845
+			} elseif ($this->wsdl) {
3846
+				$this->debug("In service, serialize WSDL");
3847
+				header("Content-Type: text/xml; charset=ISO-8859-1\r\n");
3848
+				print $this->wsdl->serialize($this->debug_flag);
3849
+				if ($this->debug_flag) {
3850
+					$this->debug('wsdl:');
3851
+					$this->appendDebug($this->varDump($this->wsdl));
3852
+					print $this->getDebugAsXMLComment();
3853
+				}
3854
+			} else {
3855
+				$this->debug("In service, there is no WSDL");
3856
+				header("Content-Type: text/html; charset=ISO-8859-1\r\n");
3857
+				print "This service does not provide WSDL";
3858
+			}
3859
+		} elseif ($this->wsdl) {
3860
+			$this->debug("In service, return Web description");
3861
+			print $this->wsdl->webDescription();
3862
+		} else {
3863
+			$this->debug("In service, no Web description");
3864
+			header("Content-Type: text/html; charset=ISO-8859-1\r\n");
3865
+			print "This service does not provide a Web description";
3866
+		}
3867
+	}
3868
+
3869
+	/**
3870
+	 * parses HTTP request headers.
3871
+	 *
3872
+	 * The following fields are set by this function (when successful)
3873
+	 *
3874
+	 * headers
3875
+	 * request
3876
+	 * xml_encoding
3877
+	 * SOAPAction
3878
+	 *
3879
+	 * @access   private
3880
+	 */
3881
+	function parse_http_headers()
3882
+	{
3883
+		global $HTTP_SERVER_VARS;
3884
+
3885
+		$this->request = '';
3886
+		$this->SOAPAction = '';
3887
+		if (function_exists('getallheaders')) {
3888
+			$this->debug("In parse_http_headers, use getallheaders");
3889
+			$headers = getallheaders();
3890
+			foreach ($headers as $k => $v) {
3891
+				$k = strtolower($k);
3892
+				$this->headers[$k] = $v;
3893
+				$this->request .= "$k: $v\r\n";
3894
+				$this->debug("$k: $v");
3895
+			}
3896
+			// get SOAPAction header
3897
+			if (isset($this->headers['soapaction'])) {
3898
+				$this->SOAPAction = str_replace('"', '', $this->headers['soapaction']);
3899
+			}
3900
+			// get the character encoding of the incoming request
3901
+			if (isset($this->headers['content-type']) && strpos($this->headers['content-type'], '=')) {
3902
+				$enc = str_replace('"', '', substr(strstr($this->headers["content-type"], '='), 1));
3903
+				if (preg_match('/^(ISO-8859-1|US-ASCII|UTF-8)$/i', $enc)) {
3904
+					$this->xml_encoding = strtoupper($enc);
3905
+				} else {
3906
+					$this->xml_encoding = 'US-ASCII';
3907
+				}
3908
+			} else {
3909
+				// should be US-ASCII for HTTP 1.0 or ISO-8859-1 for HTTP 1.1
3910
+				$this->xml_encoding = 'ISO-8859-1';
3911
+			}
3912
+		} elseif (isset($_SERVER) && is_array($_SERVER)) {
3913
+			$this->debug("In parse_http_headers, use _SERVER");
3914
+			foreach ($_SERVER as $k => $v) {
3915
+				if (substr($k, 0, 5) == 'HTTP_') {
3916
+					$k = str_replace(' ', '-', strtolower(str_replace('_', ' ', substr($k, 5))));
3917
+				} else {
3918
+					$k = str_replace(' ', '-', strtolower(str_replace('_', ' ', $k)));
3919
+				}
3920
+				if ($k == 'soapaction') {
3921
+					// get SOAPAction header
3922
+					$k = 'SOAPAction';
3923
+					$v = str_replace('"', '', $v);
3924
+					$v = str_replace('\\', '', $v);
3925
+					$this->SOAPAction = $v;
3926
+				} elseif ($k == 'content-type') {
3927
+					// get the character encoding of the incoming request
3928
+					if (strpos($v, '=')) {
3929
+						$enc = substr(strstr($v, '='), 1);
3930
+						$enc = str_replace('"', '', $enc);
3931
+						$enc = str_replace('\\', '', $enc);
3932
+						if (preg_match('/^(ISO-8859-1|US-ASCII|UTF-8)$/i', $enc)) {
3933
+							$this->xml_encoding = strtoupper($enc);
3934
+						} else {
3935
+							$this->xml_encoding = 'US-ASCII';
3936
+						}
3937
+					} else {
3938
+						// should be US-ASCII for HTTP 1.0 or ISO-8859-1 for HTTP 1.1
3939
+						$this->xml_encoding = 'ISO-8859-1';
3940
+					}
3941
+				}
3942
+				$this->headers[$k] = $v;
3943
+				if (is_array($v)) {
3944
+					$this->request .= "$k: " . json_encode($v) . "\r\n";
3945
+					$this->debug("$k: " . json_encode($v));
3946
+				} else {
3947
+					$this->request .= "$k: $v\r\n";
3948
+					$this->debug("$k: $v");
3949
+				}
3950
+			}
3951
+		} elseif (is_array($HTTP_SERVER_VARS)) {
3952
+			$this->debug("In parse_http_headers, use HTTP_SERVER_VARS");
3953
+			foreach ($HTTP_SERVER_VARS as $k => $v) {
3954
+				if (substr($k, 0, 5) == 'HTTP_') {
3955
+					$k = str_replace(' ', '-', strtolower(str_replace('_', ' ', substr($k, 5))));
3956
+					$k = strtolower(substr($k, 5));
3957
+				} else {
3958
+					$k = str_replace(' ', '-', strtolower(str_replace('_', ' ', $k)));
3959
+					$k = strtolower($k);
3960
+				}
3961
+				if ($k == 'soapaction') {
3962
+					// get SOAPAction header
3963
+					$k = 'SOAPAction';
3964
+					$v = str_replace('"', '', $v);
3965
+					$v = str_replace('\\', '', $v);
3966
+					$this->SOAPAction = $v;
3967
+				} elseif ($k == 'content-type') {
3968
+					// get the character encoding of the incoming request
3969
+					if (strpos($v, '=')) {
3970
+						$enc = substr(strstr($v, '='), 1);
3971
+						$enc = str_replace('"', '', $enc);
3972
+						$enc = str_replace('\\', '', $enc);
3973
+						if (preg_match('/^(ISO-8859-1|US-ASCII|UTF-8)$/i', $enc)) {
3974
+							$this->xml_encoding = strtoupper($enc);
3975
+						} else {
3976
+							$this->xml_encoding = 'US-ASCII';
3977
+						}
3978
+					} else {
3979
+						// should be US-ASCII for HTTP 1.0 or ISO-8859-1 for HTTP 1.1
3980
+						$this->xml_encoding = 'ISO-8859-1';
3981
+					}
3982
+				}
3983
+				$this->headers[$k] = $v;
3984
+				$this->request .= "$k: $v\r\n";
3985
+				$this->debug("$k: $v");
3986
+			}
3987
+		} else {
3988
+			$this->debug("In parse_http_headers, HTTP headers not accessible");
3989
+			$this->setError("HTTP headers not accessible");
3990
+		}
3991
+	}
3992
+
3993
+	/**
3994
+	 * parses a request
3995
+	 *
3996
+	 * The following fields are set by this function (when successful)
3997
+	 *
3998
+	 * headers
3999
+	 * request
4000
+	 * xml_encoding
4001
+	 * SOAPAction
4002
+	 * request
4003
+	 * requestSOAP
4004
+	 * methodURI
4005
+	 * methodname
4006
+	 * methodparams
4007
+	 * requestHeaders
4008
+	 * document
4009
+	 *
4010
+	 * This sets the fault field on error
4011
+	 *
4012
+	 * @param    string $data XML string
4013
+	 * @access   private
4014
+	 */
4015
+	function parse_request($data = '')
4016
+	{
4017
+		$this->debug('entering parse_request()');
4018
+		$this->parse_http_headers();
4019
+		$this->debug('got character encoding: ' . $this->xml_encoding);
4020
+		// uncompress if necessary
4021
+		if (isset($this->headers['content-encoding']) && $this->headers['content-encoding'] != '') {
4022
+			$this->debug('got content encoding: ' . $this->headers['content-encoding']);
4023
+			if ($this->headers['content-encoding'] == 'deflate' || $this->headers['content-encoding'] == 'gzip') {
4024
+				// if decoding works, use it. else assume data wasn't gzencoded
4025
+				if (function_exists('gzuncompress')) {
4026
+					if ($this->headers['content-encoding'] == 'deflate' && $degzdata = @gzuncompress($data)) {
4027
+						$data = $degzdata;
4028
+					} elseif ($this->headers['content-encoding'] == 'gzip' && $degzdata = gzinflate(substr($data, 10))) {
4029
+						$data = $degzdata;
4030
+					} else {
4031
+						$this->fault('SOAP-ENV:Client', 'Errors occurred when trying to decode the data');
4032
+						return;
4033
+					}
4034
+				} else {
4035
+					$this->fault('SOAP-ENV:Client', 'This Server does not support compressed data');
4036
+					return;
4037
+				}
4038
+			}
4039
+		}
4040
+		$this->request .= "\r\n" . $data;
4041
+		$data = $this->parseRequest($this->headers, $data);
4042
+		$this->requestSOAP = $data;
4043
+		$this->debug('leaving parse_request');
4044
+	}
4045
+
4046
+	/**
4047
+	 * invokes a PHP function for the requested SOAP method
4048
+	 *
4049
+	 * The following fields are set by this function (when successful)
4050
+	 *
4051
+	 * methodreturn
4052
+	 *
4053
+	 * Note that the PHP function that is called may also set the following
4054
+	 * fields to affect the response sent to the client
4055
+	 *
4056
+	 * responseHeaders
4057
+	 * outgoing_headers
4058
+	 *
4059
+	 * This sets the fault field on error
4060
+	 *
4061
+	 * @access   private
4062
+	 */
4063
+	function invoke_method()
4064
+	{
4065
+		$this->debug('in invoke_method, methodname=' . $this->methodname . ' methodURI=' . $this->methodURI . ' SOAPAction=' . $this->SOAPAction);
4066
+
4067
+		//
4068
+		// if you are debugging in this area of the code, your service uses a class to implement methods,
4069
+		// you use SOAP RPC, and the client is .NET, please be aware of the following...
4070
+		// when the .NET wsdl.exe utility generates a proxy, it will remove the '.' or '..' from the
4071
+		// method name.  that is fine for naming the .NET methods.  it is not fine for properly constructing
4072
+		// the XML request and reading the XML response.  you need to add the RequestElementName and
4073
+		// ResponseElementName to the System.Web.Services.Protocols.SoapRpcMethodAttribute that wsdl.exe
4074
+		// generates for the method.  these parameters are used to specify the correct XML element names
4075
+		// for .NET to use, i.e. the names with the '.' in them.
4076
+		//
4077
+		$orig_methodname = $this->methodname;
4078
+		if ($this->wsdl) {
4079
+			if ($this->opData = $this->wsdl->getOperationData($this->methodname)) {
4080
+				$this->debug('in invoke_method, found WSDL operation=' . $this->methodname);
4081
+				$this->appendDebug('opData=' . $this->varDump($this->opData));
4082
+			} elseif ($this->opData = $this->wsdl->getOperationDataForSoapAction($this->SOAPAction)) {
4083
+				// Note: hopefully this case will only be used for doc/lit, since rpc services should have wrapper element
4084
+				$this->debug('in invoke_method, found WSDL soapAction=' . $this->SOAPAction . ' for operation=' . $this->opData['name']);
4085
+				$this->appendDebug('opData=' . $this->varDump($this->opData));
4086
+				$this->methodname = $this->opData['name'];
4087
+			} else {
4088
+				$this->debug('in invoke_method, no WSDL for operation=' . $this->methodname);
4089
+				$this->fault('SOAP-ENV:Client', "Operation '" . $this->methodname . "' is not defined in the WSDL for this service");
4090
+				return;
4091
+			}
4092
+		} else {
4093
+			$this->debug('in invoke_method, no WSDL to validate method');
4094
+		}
4095
+
4096
+		// if a . is present in $this->methodname, we see if there is a class in scope,
4097
+		// which could be referred to. We will also distinguish between two deliminators,
4098
+		// to allow methods to be called a the class or an instance
4099
+		if (strpos($this->methodname, '..') > 0) {
4100
+			$delim = '..';
4101
+		} elseif (strpos($this->methodname, '.') > 0) {
4102
+			$delim = '.';
4103
+		} else {
4104
+			$delim = '';
4105
+		}
4106
+		$this->debug("in invoke_method, delim=$delim");
4107
+
4108
+		$class = '';
4109
+		$method = '';
4110
+		$try_class = '';
4111
+		if (strlen($delim) > 0 && substr_count($this->methodname, $delim) == 1) {
4112
+			$try_class = substr($this->methodname, 0, strpos($this->methodname, $delim));
4113
+			if (class_exists($try_class)) {
4114
+				// get the class and method name
4115
+				$class = $try_class;
4116
+				$method = substr($this->methodname, strpos($this->methodname, $delim) + strlen($delim));
4117
+				$this->debug("in invoke_method, class=$class method=$method delim=$delim");
4118
+			} else {
4119
+				$this->debug("in invoke_method, class=$try_class not found");
4120
+			}
4121
+		} elseif (strlen($delim) > 0 && substr_count($this->methodname, $delim) > 1) {
4122
+			$split = explode($delim, $this->methodname);
4123
+			$method = array_pop($split);
4124
+			$class = implode('\\', $split);
4125
+		} else {
4126
+			$this->debug("in invoke_method, no class to try");
4127
+		}
4128
+
4129
+		// does method exist?
4130
+		if ($class == '') {
4131
+			if (!function_exists($this->methodname)) {
4132
+				$this->debug("in invoke_method, function '$this->methodname' not found!");
4133
+				$this->result = 'fault: method not found';
4134
+				$this->fault('SOAP-ENV:Client', "method '$this->methodname'('$orig_methodname') not defined in service('$try_class' '$delim')");
4135
+				return;
4136
+			}
4137
+		} else {
4138
+			$method_to_compare = (substr(phpversion(), 0, 2) == '4.') ? strtolower($method) : $method;
4139
+			if (!in_array($method_to_compare, get_class_methods($class))) {
4140
+				$this->debug("in invoke_method, method '$this->methodname' not found in class '$class'!");
4141
+				$this->result = 'fault: method not found';
4142
+				$this->fault('SOAP-ENV:Client', "method '$this->methodname'/'$method_to_compare'('$orig_methodname') not defined in service/'$class'('$try_class' '$delim')");
4143
+				return;
4144
+			}
4145
+		}
4146
+
4147
+		// evaluate message, getting back parameters
4148
+		// verify that request parameters match the method's signature
4149
+		if (!$this->verify_method($this->methodname, $this->methodparams)) {
4150
+			// debug
4151
+			$this->debug('ERROR: request not verified against method signature');
4152
+			$this->result = 'fault: request failed validation against method signature';
4153
+			// return fault
4154
+			$this->fault('SOAP-ENV:Client', "Operation '$this->methodname' not defined in service.");
4155
+			return;
4156
+		}
4157
+
4158
+		// if there are parameters to pass
4159
+		$this->debug('in invoke_method, params:');
4160
+		$this->appendDebug($this->varDump($this->methodparams));
4161
+		$this->debug("in invoke_method, calling '$this->methodname'");
4162
+		if (!function_exists('call_user_func_array')) {
4163
+			if ($class == '') {
4164
+				$this->debug('in invoke_method, calling function using eval()');
4165
+				$funcCall = "\$this->methodreturn = $this->methodname(";
4166
+			} else {
4167
+				if ($delim == '..') {
4168
+					$this->debug('in invoke_method, calling class method using eval()');
4169
+					$funcCall = "\$this->methodreturn = " . $class . "::" . $method . "(";
4170
+				} else {
4171
+					$this->debug('in invoke_method, calling instance method using eval()');
4172
+					// generate unique instance name
4173
+					$instname = "\$inst_" . time();
4174
+					$funcCall = $instname . " = new " . $class . "(); ";
4175
+					$funcCall .= "\$this->methodreturn = " . $instname . "->" . $method . "(";
4176
+				}
4177
+			}
4178
+			if ($this->methodparams) {
4179
+				foreach ($this->methodparams as $param) {
4180
+					if (is_array($param) || is_object($param)) {
4181
+						$this->fault('SOAP-ENV:Client', 'NuSOAP does not handle complexType parameters correctly when using eval; call_user_func_array must be available');
4182
+						return;
4183
+					}
4184
+					$funcCall .= "\"$param\",";
4185
+				}
4186
+				$funcCall = substr($funcCall, 0, -1);
4187
+			}
4188
+			$funcCall .= ');';
4189
+			$this->debug('in invoke_method, function call: ' . $funcCall);
4190
+			@eval($funcCall);
4191
+		} else {
4192
+			if ($class == '') {
4193
+				$this->debug('in invoke_method, calling function using call_user_func_array()');
4194
+				$call_arg = "$this->methodname";    // straight assignment changes $this->methodname to lower case after call_user_func_array()
4195
+			} elseif ($delim == '..') {
4196
+				$this->debug('in invoke_method, calling class method using call_user_func_array()');
4197
+				$call_arg = array($class, $method);
4198
+			} else {
4199
+				$this->debug('in invoke_method, calling instance method using call_user_func_array()');
4200
+				$instance = new $class ();
4201
+				$call_arg = array(&$instance, $method);
4202
+			}
4203
+			if (is_array($this->methodparams)) {
4204
+				$this->methodreturn = call_user_func_array($call_arg, array_values($this->methodparams));
4205
+			} else {
4206
+				$this->methodreturn = call_user_func_array($call_arg, array());
4207
+			}
4208
+		}
4209
+		$this->debug('in invoke_method, methodreturn:');
4210
+		$this->appendDebug($this->varDump($this->methodreturn));
4211
+		$this->debug("in invoke_method, called method $this->methodname, received data of type " . gettype($this->methodreturn));
4212
+	}
4213
+
4214
+	/**
4215
+	 * serializes the return value from a PHP function into a full SOAP Envelope
4216
+	 *
4217
+	 * The following fields are set by this function (when successful)
4218
+	 *
4219
+	 * responseSOAP
4220
+	 *
4221
+	 * This sets the fault field on error
4222
+	 *
4223
+	 * @access   private
4224
+	 */
4225
+	function serialize_return()
4226
+	{
4227
+		$this->debug('Entering serialize_return methodname: ' . $this->methodname . ' methodURI: ' . $this->methodURI);
4228
+		// if fault
4229
+		if (isset($this->methodreturn) && is_object($this->methodreturn) && ((get_class($this->methodreturn) == 'soap_fault') || (get_class($this->methodreturn) == 'nusoap_fault'))) {
4230
+			$this->debug('got a fault object from method');
4231
+			$this->fault = $this->methodreturn;
4232
+			return;
4233
+		} elseif ($this->methodreturnisliteralxml) {
4234
+			$return_val = $this->methodreturn;
4235
+			// returned value(s)
4236
+		} else {
4237
+			$this->debug('got a(n) ' . gettype($this->methodreturn) . ' from method');
4238
+			$this->debug('serializing return value');
4239
+			if ($this->wsdl) {
4240
+				if (sizeof($this->opData['output']['parts']) > 1) {
4241
+					$this->debug('more than one output part, so use the method return unchanged');
4242
+					$opParams = $this->methodreturn;
4243
+				} elseif (sizeof($this->opData['output']['parts']) == 1) {
4244
+					$this->debug('exactly one output part, so wrap the method return in a simple array');
4245
+					// TODO: verify that it is not already wrapped!
4246
+					//foreach ($this->opData['output']['parts'] as $name => $type) {
4247
+					//	$this->debug('wrap in element named ' . $name);
4248
+					//}
4249
+					$opParams = array($this->methodreturn);
4250
+				}
4251
+				$opParams = isset($opParams) ? $opParams : [];
4252
+				$return_val = $this->wsdl->serializeRPCParameters($this->methodname, 'output', $opParams);
4253
+				$this->appendDebug($this->wsdl->getDebug());
4254
+				$this->wsdl->clearDebug();
4255
+				if ($errstr = $this->wsdl->getError()) {
4256
+					$this->debug('got wsdl error: ' . $errstr);
4257
+					$this->fault('SOAP-ENV:Server', 'unable to serialize result');
4258
+					return;
4259
+				}
4260
+			} else {
4261
+				if (isset($this->methodreturn)) {
4262
+					$return_val = $this->serialize_val($this->methodreturn, 'return');
4263
+				} else {
4264
+					$return_val = '';
4265
+					$this->debug('in absence of WSDL, assume void return for backward compatibility');
4266
+				}
4267
+			}
4268
+		}
4269
+		$this->debug('return value:');
4270
+		$this->appendDebug($this->varDump($return_val));
4271
+
4272
+		$this->debug('serializing response');
4273
+		if ($this->wsdl) {
4274
+			$this->debug('have WSDL for serialization: style is ' . $this->opData['style']);
4275
+			if ($this->opData['style'] == 'rpc') {
4276
+				$this->debug('style is rpc for serialization: use is ' . $this->opData['output']['use']);
4277
+				if ($this->opData['output']['use'] == 'literal') {
4278
+					// http://www.ws-i.org/Profiles/BasicProfile-1.1-2004-08-24.html R2735 says rpc/literal accessor elements should not be in a namespace
4279
+					if ($this->methodURI) {
4280
+						$payload = '<ns1:' . $this->responseTagName . ' xmlns:ns1="' . $this->methodURI . '">' . $return_val . '</ns1:' . $this->responseTagName . ">";
4281
+					} else {
4282
+						$payload = '<' . $this->responseTagName . '>' . $return_val . '</' . $this->responseTagName . 'Response>';
4283
+					}
4284
+				} else {
4285
+					if ($this->methodURI) {
4286
+						$payload = '<ns1:' . $this->responseTagName . ' xmlns:ns1="' . $this->methodURI . '">' . $return_val . '</ns1:' . $this->responseTagName . ">";
4287
+					} else {
4288
+						$payload = '<' . $this->responseTagName . '>' . $return_val . '</' . $this->responseTagName . '>';
4289
+					}
4290
+				}
4291
+			} else {
4292
+				$this->debug('style is not rpc for serialization: assume document');
4293
+				$payload = $return_val;
4294
+			}
4295
+		} else {
4296
+			$this->debug('do not have WSDL for serialization: assume rpc/encoded');
4297
+			$payload = '<ns1:' . $this->responseTagName . ' xmlns:ns1="' . $this->methodURI . '">' . $return_val . '</ns1:' . $this->responseTagName . ">";
4298
+		}
4299
+		$this->result = 'successful';
4300
+		if ($this->wsdl) {
4301
+			//if($this->debug_flag){
4302
+			$this->appendDebug($this->wsdl->getDebug());
4303
+			//	}
4304
+			if (isset($this->opData['output']['encodingStyle'])) {
4305
+				$encodingStyle = $this->opData['output']['encodingStyle'];
4306
+			} else {
4307
+				$encodingStyle = '';
4308
+			}
4309
+			// Added: In case we use a WSDL, return a serialized env. WITH the usedNamespaces.
4310
+			$this->responseSOAP = $this->serializeEnvelope($payload, $this->responseHeaders, $this->wsdl->usedNamespaces, $this->opData['style'], $this->opData['output']['use'], $encodingStyle);
4311
+		} else {
4312
+			$this->responseSOAP = $this->serializeEnvelope($payload, $this->responseHeaders);
4313
+		}
4314
+		$this->debug("Leaving serialize_return");
4315
+	}
4316
+
4317
+	/**
4318
+	 * sends an HTTP response
4319
+	 *
4320
+	 * The following fields are set by this function (when successful)
4321
+	 *
4322
+	 * outgoing_headers
4323
+	 * response
4324
+	 *
4325
+	 * @access   private
4326
+	 */
4327
+	function send_response()
4328
+	{
4329
+		$this->debug('Enter send_response');
4330
+		if ($this->fault) {
4331
+			$payload = $this->fault->serialize();
4332
+			$this->outgoing_headers[] = "HTTP/1.0 500 Internal Server Error";
4333
+			$this->outgoing_headers[] = "Status: 500 Internal Server Error";
4334
+		} else {
4335
+			$payload = $this->responseSOAP;
4336
+			// Some combinations of PHP+Web server allow the Status
4337
+			// to come through as a header.  Since OK is the default
4338
+			// just do nothing.
4339
+			// $this->outgoing_headers[] = "HTTP/1.0 200 OK";
4340
+			// $this->outgoing_headers[] = "Status: 200 OK";
4341
+		}
4342
+		// add debug data if in debug mode
4343
+		if (isset($this->debug_flag) && $this->debug_flag) {
4344
+			$payload .= $this->getDebugAsXMLComment();
4345
+		}
4346
+		$this->outgoing_headers[] = "Server: $this->title Server v$this->version";
4347
+		$rev = array();
4348
+		preg_match('/\$Revisio' . 'n: ([^ ]+)/', $this->revision, $rev);
4349
+		$this->outgoing_headers[] = "X-SOAP-Server: $this->title/$this->version (" . (isset($rev[1]) ? $rev[1] : '') . ")";
4350
+		// Let the Web server decide about this
4351
+		//$this->outgoing_headers[] = "Connection: Close\r\n";
4352
+		$payload = $this->getHTTPBody($payload);
4353
+		$type = $this->getHTTPContentType();
4354
+		$charset = $this->getHTTPContentTypeCharset();
4355
+		$this->outgoing_headers[] = "Content-Type: $type" . ($charset ? '; charset=' . $charset : '');
4356
+		//begin code to compress payload - by John
4357
+		// NOTE: there is no way to know whether the Web server will also compress
4358
+		// this data.
4359
+		if (strlen($payload) > 1024 && isset($this->headers) && isset($this->headers['accept-encoding'])) {
4360
+			if (strstr($this->headers['accept-encoding'], 'gzip')) {
4361
+				if (function_exists('gzencode')) {
4362
+					if (isset($this->debug_flag) && $this->debug_flag) {
4363
+						$payload .= "<!-- Content being gzipped -->";
4364
+					}
4365
+					$this->outgoing_headers[] = "Content-Encoding: gzip";
4366
+					$payload = gzencode($payload);
4367
+				} else {
4368
+					if (isset($this->debug_flag) && $this->debug_flag) {
4369
+						$payload .= "<!-- Content will not be gzipped: no gzencode -->";
4370
+					}
4371
+				}
4372
+			} elseif (strstr($this->headers['accept-encoding'], 'deflate')) {
4373
+				// Note: MSIE requires gzdeflate output (no Zlib header and checksum),
4374
+				// instead of gzcompress output,
4375
+				// which conflicts with HTTP 1.1 spec (http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.5)
4376
+				if (function_exists('gzdeflate')) {
4377
+					if (isset($this->debug_flag) && $this->debug_flag) {
4378
+						$payload .= "<!-- Content being deflated -->";
4379
+					}
4380
+					$this->outgoing_headers[] = "Content-Encoding: deflate";
4381
+					$payload = gzdeflate($payload);
4382
+				} else {
4383
+					if (isset($this->debug_flag) && $this->debug_flag) {
4384
+						$payload .= "<!-- Content will not be deflated: no gzcompress -->";
4385
+					}
4386
+				}
4387
+			}
4388
+		}
4389
+		//end code
4390
+		$this->outgoing_headers[] = "Content-Length: " . strlen($payload);
4391
+		reset($this->outgoing_headers);
4392
+		foreach ($this->outgoing_headers as $hdr) {
4393
+			header($hdr, false);
4394
+		}
4395
+		print $payload;
4396
+		$this->response = join("\r\n", $this->outgoing_headers) . "\r\n\r\n" . $payload;
4397
+	}
4398
+
4399
+	/**
4400
+	 * takes the value that was created by parsing the request
4401
+	 * and compares to the method's signature, if available.
4402
+	 *
4403
+	 * @param    string $operation The operation to be invoked
4404
+	 * @param    array $request The array of parameter values
4405
+	 * @return    boolean    Whether the operation was found
4406
+	 * @access   private
4407
+	 */
4408
+	function verify_method($operation, $request)
4409
+	{
4410
+		if (isset($this->wsdl) && is_object($this->wsdl)) {
4411
+			if ($this->wsdl->getOperationData($operation)) {
4412
+				return true;
4413
+			}
4414
+		} elseif (isset($this->operations[$operation])) {
4415
+			return true;
4416
+		}
4417
+		return false;
4418
+	}
4419
+
4420
+	/**
4421
+	 * processes SOAP message received from client
4422
+	 *
4423
+	 * @param    array $headers The HTTP headers
4424
+	 * @param    string $data unprocessed request data from client
4425
+	 * @return   false|void void or false on error
4426
+	 * @access   private
4427
+	 */
4428
+	function parseRequest($headers, $data)
4429
+	{
4430
+		$this->debug('Entering parseRequest() for data of length ' . strlen($data) . ' headers:');
4431
+		$this->appendDebug($this->varDump($headers));
4432
+		if (!isset($headers['content-type'])) {
4433
+			$this->setError('Request not of type '.$this->contentType.' (no content-type header)');
4434
+			return false;
4435
+		}
4436
+		if (!strstr($headers['content-type'], $this->contentType)) {
4437
+			$this->setError('Request not of type '.$this->contentType.': ' . $headers['content-type']);
4438
+			return false;
4439
+		}
4440
+		if (strpos($headers['content-type'], '=')) {
4441
+			$enc = str_replace('"', '', substr(strstr($headers["content-type"], '='), 1));
4442
+			$this->debug('Got response encoding: ' . $enc);
4443
+			if (preg_match('/^(ISO-8859-1|US-ASCII|UTF-8)$/i', $enc)) {
4444
+				$this->xml_encoding = strtoupper($enc);
4445
+			} else {
4446
+				$this->xml_encoding = 'US-ASCII';
4447
+			}
4448
+		} else {
4449
+			// should be US-ASCII for HTTP 1.0 or ISO-8859-1 for HTTP 1.1
4450
+			$this->xml_encoding = 'ISO-8859-1';
4451
+		}
4452
+		$this->debug('Use encoding: ' . $this->xml_encoding . ' when creating nusoap_parser');
4453
+		// parse response, get soap parser obj
4454
+		$parser = new nusoap_parser($data, $this->xml_encoding, '', $this->decode_utf8);
4455
+		// parser debug
4456
+		$this->debug("parser debug: \n" . $parser->getDebug());
4457
+		// if fault occurred during message parsing
4458
+		if ($err = $parser->getError()) {
4459
+			$this->result = 'fault: error in msg parsing: ' . $err;
4460
+			$this->fault('SOAP-ENV:Client', "error in msg parsing:\n" . $err);
4461
+			// else successfully parsed request into soapval object
4462
+		} else {
4463
+			// get/set methodname
4464
+			$this->methodURI = $parser->root_struct_namespace;
4465
+			$this->methodname = $parser->root_struct_name;
4466
+			$this->debug('methodname: ' . $this->methodname . ' methodURI: ' . $this->methodURI);
4467
+
4468
+			// get/set custom response tag name
4469
+			$tmparray = $this->wsdl->getOperationData($this->methodname);
4470
+			$outputMessage = (empty($tmparray) ? '' : $tmparray['output']['message']);
4471
+			$this->responseTagName = $outputMessage;
4472
+			$this->debug('responseTagName: ' . $this->responseTagName . ' methodURI: ' . $this->methodURI);
4473
+
4474
+			$this->debug('calling parser->get_soapbody()');
4475
+			$this->methodparams = $parser->get_soapbody();
4476
+			// get SOAP headers
4477
+			$this->requestHeaders = $parser->getHeaders();
4478
+			// get SOAP Header
4479
+			$this->requestHeader = $parser->get_soapheader();
4480
+			// add document for doclit support
4481
+			$this->document = $parser->document;
4482
+		}
4483
+	}
4484
+
4485
+	/**
4486
+	 * gets the HTTP body for the current response.
4487
+	 *
4488
+	 * @param string $soapmsg The SOAP payload
4489
+	 * @return string The HTTP body, which includes the SOAP payload
4490
+	 * @access private
4491
+	 */
4492
+	function getHTTPBody($soapmsg)
4493
+	{
4494
+		return $soapmsg;
4495
+	}
4496
+
4497
+	/**
4498
+	 * gets the HTTP content type for the current response.
4499
+	 *
4500
+	 * Note: getHTTPBody must be called before this.
4501
+	 *
4502
+	 * @return string the HTTP content type for the current response.
4503
+	 * @access private
4504
+	 */
4505
+	function getHTTPContentType()
4506
+	{
4507
+		return 'text/xml';
4508
+	}
4509
+
4510
+	/**
4511
+	 * gets the HTTP content type charset for the current response.
4512
+	 * returns false for non-text content types.
4513
+	 *
4514
+	 * Note: getHTTPBody must be called before this.
4515
+	 *
4516
+	 * @return string the HTTP content type charset for the current response.
4517
+	 * @access private
4518
+	 */
4519
+	function getHTTPContentTypeCharset()
4520
+	{
4521
+		return $this->soap_defencoding;
4522
+	}
4523
+
4524
+	/**
4525
+	 * add a method to the dispatch map (this has been replaced by the register method)
4526
+	 *
4527
+	 * @param    string $methodname
4528
+	 * @param    string $in array of input values
4529
+	 * @param    string $out array of output values
4530
+	 * @access   public
4531
+	 * @deprecated
4532
+	 */
4533
+	function add_to_map($methodname, $in, $out)
4534
+	{
4535
+		$this->operations[$methodname] = array('name' => $methodname, 'in' => $in, 'out' => $out);
4536
+	}
4537
+
4538
+	/**
4539
+	 * register a service function with the server
4540
+	 *
4541
+	 * @param    string $name the name of the PHP function, class.method or class..method
4542
+	 * @param    array $in assoc array of input values: key = param name, value = param type
4543
+	 * @param    array $out assoc array of output values: key = param name, value = param type
4544
+	 * @param    mixed $namespace the element namespace for the method or false
4545
+	 * @param    mixed $soapaction the soapaction for the method or false
4546
+	 * @param    mixed $style optional (rpc|document) or false Note: when 'document' is specified, parameter and return wrappers are created for you automatically
4547
+	 * @param    mixed $use optional (encoded|literal) or false
4548
+	 * @param    string $documentation optional Description to include in WSDL
4549
+	 * @param    string $encodingStyle optional (usually 'http://schemas.xmlsoap.org/soap/encoding/' for encoded)
4550
+	 * @param    string $customResponseTagName optional Name of the outgoing response, default $name . 'Response'
4551
+	 * @access   public
4552
+	 */
4553
+	function register($name, $in = array(), $out = array(), $namespace = false, $soapaction = false, $style = false, $use = false, $documentation = '', $encodingStyle = '', $customResponseTagName = '')
4554
+	{
4555
+		global $HTTP_SERVER_VARS;
4556
+
4557
+		if ($this->externalWSDLURL) {
4558
+			die('You cannot bind to an external WSDL file, and register methods outside of it! Please choose either WSDL or no WSDL.');
4559
+		}
4560
+		if (!$name) {
4561
+			die('You must specify a name when you register an operation');
4562
+		}
4563
+		if (!is_array($in)) {
4564
+			die('You must provide an array for operation inputs');
4565
+		}
4566
+		if (!is_array($out)) {
4567
+			die('You must provide an array for operation outputs');
4568
+		}
4569
+		if (!$soapaction) {
4570
+			if (isset($_SERVER)) {
4571
+				$SERVER_NAME = $_SERVER['SERVER_NAME'];
4572
+				$SCRIPT_NAME = $_SERVER['SCRIPT_NAME'];
4573
+				$HTTPS = isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : (isset($HTTP_SERVER_VARS['HTTPS']) ? $HTTP_SERVER_VARS['HTTPS'] : 'off');
4574
+			} elseif (isset($HTTP_SERVER_VARS)) {
4575
+				$SERVER_NAME = $HTTP_SERVER_VARS['SERVER_NAME'];
4576
+				$SCRIPT_NAME = $HTTP_SERVER_VARS['SCRIPT_NAME'];
4577
+				$HTTPS = isset($HTTP_SERVER_VARS['HTTPS']) ? $HTTP_SERVER_VARS['HTTPS'] : 'off';
4578
+			} else {
4579
+				$this->setError("Neither _SERVER nor HTTP_SERVER_VARS is available");
4580
+				$HTTPS = '';
4581
+				$SERVER_NAME = '';
4582
+				$SCRIPT_NAME = '';
4583
+			}
4584
+			if ($HTTPS == '1' || $HTTPS == 'on') {
4585
+				$SCHEME = 'https';
4586
+			} else {
4587
+				$SCHEME = 'http';
4588
+			}
4589
+			$soapaction = "$SCHEME://$SERVER_NAME$SCRIPT_NAME/$name";
4590
+		}
4591
+		if (!$style) {
4592
+			$style = "rpc";
4593
+		}
4594
+		if (!$use) {
4595
+			$use = "encoded";
4596
+		}
4597
+		if ($use == 'encoded' && $encodingStyle == '') {
4598
+			$encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/';
4599
+		}
4600
+		if (!$customResponseTagName) {
4601
+			$customResponseTagName = $name . 'Response';
4602
+		}
4603
+
4604
+		$this->operations[$name] = array(
4605
+			'name' => $name,
4606
+			'in' => $in,
4607
+			'out' => $out,
4608
+			'namespace' => $namespace,
4609
+			'soapaction' => $soapaction,
4610
+			'style' => $style,
4611
+			'outputMessage' => $customResponseTagName,
4612
+		);
4613
+		if ($this->wsdl) {
4614
+			$this->wsdl->addOperation($name, $in, $out, $namespace, $soapaction, $style, $use, $documentation, $encodingStyle, $customResponseTagName);
4615
+		}
4616
+		return true;
4617
+	}
4618
+
4619
+	/**
4620
+	 * Specify a fault to be returned to the client.
4621
+	 * This also acts as a flag to the server that a fault has occured.
4622
+	 *
4623
+	 * @param    string $faultcode
4624
+	 * @param    string $faultstring
4625
+	 * @param    string $faultactor
4626
+	 * @param    string $faultdetail
4627
+	 * @access   public
4628
+	 */
4629
+	function fault($faultcode, $faultstring, $faultactor = '', $faultdetail = '')
4630
+	{
4631
+		if ($faultdetail == '' && $this->debug_flag) {
4632
+			$faultdetail = $this->getDebug();
4633
+		}
4634
+		$this->fault = new nusoap_fault($faultcode, $faultactor, $faultstring, $faultdetail);
4635
+		$this->fault->soap_defencoding = $this->soap_defencoding;
4636
+	}
4637
+
4638
+	/**
4639
+	 * Sets up wsdl object.
4640
+	 * Acts as a flag to enable internal WSDL generation
4641
+	 *
4642
+	 * @param string $serviceName , name of the service
4643
+	 * @param mixed $namespace optional 'tns' service namespace or false
4644
+	 * @param mixed $endpoint optional URL of service endpoint or false
4645
+	 * @param string $style optional (rpc|document) WSDL style (also specified by operation)
4646
+	 * @param string $transport optional SOAP transport
4647
+	 * @param mixed $schemaTargetNamespace optional 'types' targetNamespace for service schema or false
4648
+	 */
4649
+	function configureWSDL($serviceName, $namespace = false, $endpoint = false, $style = 'rpc', $transport = 'http://schemas.xmlsoap.org/soap/http', $schemaTargetNamespace = false)
4650
+	{
4651
+		global $HTTP_SERVER_VARS;
4652
+
4653
+		if (isset($_SERVER)) {
4654
+			$SERVER_NAME = $_SERVER['SERVER_NAME'];
4655
+			$SERVER_PORT = $_SERVER['SERVER_PORT'];
4656
+			$SCRIPT_NAME = $_SERVER['SCRIPT_NAME'];
4657
+			$HTTPS = isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : (isset($HTTP_SERVER_VARS['HTTPS']) ? $HTTP_SERVER_VARS['HTTPS'] : 'off');
4658
+		} elseif (isset($HTTP_SERVER_VARS)) {
4659
+			$SERVER_NAME = $HTTP_SERVER_VARS['SERVER_NAME'];
4660
+			$SERVER_PORT = $HTTP_SERVER_VARS['SERVER_PORT'];
4661
+			$SCRIPT_NAME = $HTTP_SERVER_VARS['SCRIPT_NAME'];
4662
+			$HTTPS = isset($HTTP_SERVER_VARS['HTTPS']) ? $HTTP_SERVER_VARS['HTTPS'] : 'off';
4663
+		} else {
4664
+			$this->setError("Neither _SERVER nor HTTP_SERVER_VARS is available");
4665
+			$SERVER_PORT = '';
4666
+			$SERVER_NAME = '';
4667
+			$SCRIPT_NAME = '';
4668
+			$HTTPS = '';
4669
+		}
4670
+		// If server name has port number attached then strip it (else port number gets duplicated in WSDL output) (occurred using lighttpd and FastCGI)
4671
+		$colon = strpos($SERVER_NAME, ":");
4672
+		if ($colon) {
4673
+			$SERVER_NAME = substr($SERVER_NAME, 0, $colon);
4674
+		}
4675
+		if ($SERVER_PORT == 80) {
4676
+			$SERVER_PORT = '';
4677
+		} else {
4678
+			$SERVER_PORT = ':' . $SERVER_PORT;
4679
+		}
4680
+		if (!$namespace) {
4681
+			$namespace = "http://$SERVER_NAME/soap/$serviceName";
4682
+		}
4683
+
4684
+		if (!$endpoint) {
4685
+			if ($HTTPS == '1' || $HTTPS == 'on') {
4686
+				$SCHEME = 'https';
4687
+			} else {
4688
+				$SCHEME = 'http';
4689
+			}
4690
+			$endpoint = "$SCHEME://$SERVER_NAME$SERVER_PORT$SCRIPT_NAME";
4691
+		}
4692
+
4693
+		if (!$schemaTargetNamespace) {
4694
+			$schemaTargetNamespace = $namespace;
4695
+		}
4696
+
4697
+		$this->wsdl = new wsdl;
4698
+		$this->wsdl->serviceName = $serviceName;
4699
+		$this->wsdl->endpoint = $endpoint;
4700
+		$this->wsdl->namespaces['tns'] = $namespace;
4701
+		$this->wsdl->namespaces['soap'] = 'http://schemas.xmlsoap.org/wsdl/soap/';
4702
+		$this->wsdl->namespaces['wsdl'] = 'http://schemas.xmlsoap.org/wsdl/';
4703
+		if ($schemaTargetNamespace != $namespace) {
4704
+			$this->wsdl->namespaces['types'] = $schemaTargetNamespace;
4705
+		}
4706
+		$this->wsdl->schemas[$schemaTargetNamespace][0] = new nusoap_xmlschema('', '', $this->wsdl->namespaces);
4707
+		if ($style == 'document') {
4708
+			$this->wsdl->schemas[$schemaTargetNamespace][0]->schemaInfo['elementFormDefault'] = 'qualified';
4709
+		}
4710
+		$this->wsdl->schemas[$schemaTargetNamespace][0]->schemaTargetNamespace = $schemaTargetNamespace;
4711
+		$this->wsdl->schemas[$schemaTargetNamespace][0]->imports['http://schemas.xmlsoap.org/soap/encoding/'][0] = array('location' => '', 'loaded' => true);
4712
+		$this->wsdl->schemas[$schemaTargetNamespace][0]->imports['http://schemas.xmlsoap.org/wsdl/'][0] = array('location' => '', 'loaded' => true);
4713
+		$this->wsdl->bindings[$serviceName . 'Binding'] = array(
4714
+			'name' => $serviceName . 'Binding',
4715
+			'style' => $style,
4716
+			'transport' => $transport,
4717
+			'portType' => $serviceName . 'PortType');
4718
+		$this->wsdl->ports[$serviceName . 'Port'] = array(
4719
+			'binding' => $serviceName . 'Binding',
4720
+			'location' => $endpoint,
4721
+			'bindingType' => 'http://schemas.xmlsoap.org/wsdl/soap/');
4722
+	}
4723
+}
4724
+
4725
+/**
4726
+ * Backward compatibility
4727
+ */
4728
+class soap_server extends nusoap_server
4729
+{
4730
+}
4731
+
4732
+
4733
+/**
4734
+ * parses a WSDL file, allows access to it's data, other utility methods.
4735
+ * also builds WSDL structures programmatically.
4736
+ *
4737
+ * @author   Dietrich Ayala <[email protected]>
4738
+ * @author   Scott Nichol <[email protected]>
4739
+ * @version  $Id: nusoap.php,v 1.123 2010/04/26 20:15:08 snichol Exp $
4740
+ * @access public
4741
+ */
4742
+class wsdl extends nusoap_base
4743
+{
4744
+	// URL or filename of the root of this WSDL
4745
+	var $wsdl;
4746
+	// define internal arrays of bindings, ports, operations, messages, etc.
4747
+	var $schemas = array();
4748
+	var $currentSchema;
4749
+	var $message = array();
4750
+	var $complexTypes = array();
4751
+	var $messages = array();
4752
+	var $currentMessage;
4753
+	var $currentOperation;
4754
+	var $portTypes = array();
4755
+	var $currentPortType;
4756
+	var $bindings = array();
4757
+	var $currentBinding;
4758
+	var $ports = array();
4759
+	var $currentPort;
4760
+	var $opData = array();
4761
+	var $status = '';
4762
+	var $documentation = false;
4763
+	var $endpoint = '';
4764
+	// array of wsdl docs to import
4765
+	var $import = array();
4766
+	// parser vars
4767
+	var $parser;
4768
+	var $position = 0;
4769
+	var $depth = 0;
4770
+	var $depth_array = array();
4771
+	// for getting wsdl
4772
+	var $proxyhost = '';
4773
+	var $proxyport = '';
4774
+	var $proxyusername = '';
4775
+	var $proxypassword = '';
4776
+	var $timeout = 0;
4777
+	var $response_timeout = 30;
4778
+	var $curl_options = array();    // User-specified cURL options
4779
+	var $use_curl = false;            // whether to always try to use cURL
4780
+	// for HTTP authentication
4781
+	var $username = '';                // Username for HTTP authentication
4782
+	var $password = '';                // Password for HTTP authentication
4783
+	var $authtype = '';                // Type of HTTP authentication
4784
+	var $certRequest = array();        // Certificate for HTTP SSL authentication
4785
+
4786
+	/** @var mixed */
4787
+	var $currentPortOperation;
4788
+	/** @var string */
4789
+	var $opStatus;
4790
+	/** @var mixed */
4791
+	var $serviceName;
4792
+	var $wsdl_info;
4793
+
4794
+	/** @var string */
4795
+	var $schemaTargetNamespace;
4796
+
4797
+	/**
4798
+	 * constructor
4799
+	 *
4800
+	 * @param string $wsdl WSDL document URL
4801
+	 * @param string $proxyhost
4802
+	 * @param string $proxyport
4803
+	 * @param string $proxyusername
4804
+	 * @param string $proxypassword
4805
+	 * @param integer $timeout set the connection timeout
4806
+	 * @param integer $response_timeout set the response timeout
4807
+	 * @param array $curl_options user-specified cURL options
4808
+	 * @param boolean $use_curl try to use cURL
4809
+	 * @access public
4810
+	 */
4811
+	function __construct($wsdl = '', $proxyhost = false, $proxyport = false, $proxyusername = false, $proxypassword = false, $timeout = 0, $response_timeout = 30, $curl_options = null, $use_curl = false)
4812
+	{
4813
+		parent::__construct();
4814
+		$this->debug("ctor wsdl=$wsdl timeout=$timeout response_timeout=$response_timeout");
4815
+		$this->proxyhost = $proxyhost;
4816
+		$this->proxyport = $proxyport;
4817
+		$this->proxyusername = $proxyusername;
4818
+		$this->proxypassword = $proxypassword;
4819
+		$this->timeout = $timeout;
4820
+		$this->response_timeout = $response_timeout;
4821
+		if (is_array($curl_options)) {
4822
+			$this->curl_options = $curl_options;
4823
+		}
4824
+		$this->use_curl = $use_curl;
4825
+		$this->fetchWSDL($wsdl);
4826
+	}
4827
+
4828
+	/**
4829
+	 * fetches the WSDL document and parses it
4830
+	 *
4831
+	 * @access public
4832
+	 */
4833
+	function fetchWSDL($wsdl)
4834
+	{
4835
+		$this->debug("parse and process WSDL path=$wsdl");
4836
+		$this->wsdl = $wsdl;
4837
+		// parse wsdl file
4838
+		if ($this->wsdl != "") {
4839
+			$this->parseWSDL($this->wsdl);
4840
+		}
4841
+		// imports
4842
+		// TODO: handle imports more properly, grabbing them in-line and nesting them
4843
+		$imported_urls = array();
4844
+		$imported = 1;
4845
+		while ($imported > 0) {
4846
+			$imported = 0;
4847
+			// Schema imports
4848
+			foreach ($this->schemas as $ns => $list) {
4849
+				foreach ($list as $xsKey => $xs) {
4850
+					$wsdlparts = parse_url($this->wsdl);    // this is bogusly simple!
4851
+					foreach ($xs->imports as $ns2 => $list2) {
4852
+						for ($ii = 0; $ii < count($list2); $ii++) {
4853
+							if (array_key_exists($ii, $list2) && (!isset($list2[$ii]['loaded']) || !$list2[$ii]['loaded'])) {
4854
+								@$this->schemas[$ns][$xsKey]->imports[$ns2][$ii]['loaded'] = true;
4855
+								$url = $list2[$ii]['location'];
4856
+								if ($url != '') {
4857
+									$urlparts = parse_url($url);
4858
+									if (!isset($urlparts['host'])) {
4859
+										$url = $wsdlparts['scheme'] . '://' . $wsdlparts['host'] . (isset($wsdlparts['port']) ? ':' . $wsdlparts['port'] : '') .
4860
+											substr($wsdlparts['path'], 0, strrpos($wsdlparts['path'], '/') + 1) . $urlparts['path'];
4861
+									}
4862
+									if (!in_array($url, $imported_urls)) {
4863
+										$this->parseWSDL($url);
4864
+										$imported++;
4865
+										$imported_urls[] = $url;
4866
+									}
4867
+								} else {
4868
+									$this->debug("Unexpected scenario: empty URL for unloaded import");
4869
+								}
4870
+							}
4871
+						}
4872
+					}
4873
+				}
4874
+			}
4875
+			// WSDL imports
4876
+			$wsdlparts = parse_url($this->wsdl);    // this is bogusly simple!
4877
+			foreach ($this->import as $ns => $list) {
4878
+				for ($ii = 0; $ii < count($list); $ii++) {
4879
+					if (!$list[$ii]['loaded']) {
4880
+						$this->import[$ns][$ii]['loaded'] = true;
4881
+						$url = $list[$ii]['location'];
4882
+						if ($url != '') {
4883
+							$urlparts = parse_url($url);
4884
+							if (!isset($urlparts['host'])) {
4885
+								$url = $wsdlparts['scheme'] . '://' . $wsdlparts['host'] . (isset($wsdlparts['port']) ? ':' . $wsdlparts['port'] : '') .
4886
+									substr($wsdlparts['path'], 0, strrpos($wsdlparts['path'], '/') + 1) . $urlparts['path'];
4887
+							}
4888
+							if (!in_array($url, $imported_urls)) {
4889
+								$this->parseWSDL($url);
4890
+								$imported++;
4891
+								$imported_urls[] = $url;
4892
+							}
4893
+						} else {
4894
+							$this->debug("Unexpected scenario: empty URL for unloaded import");
4895
+						}
4896
+					}
4897
+				}
4898
+			}
4899
+		}
4900
+		// add new data to operation data
4901
+		foreach ($this->bindings as $binding => $bindingData) {
4902
+			if (isset($bindingData['operations']) && is_array($bindingData['operations'])) {
4903
+				foreach ($bindingData['operations'] as $operation => $data) {
4904
+					$this->debug('post-parse data gathering for ' . $operation);
4905
+					$this->bindings[$binding]['operations'][$operation]['input'] =
4906
+						isset($this->bindings[$binding]['operations'][$operation]['input']) ?
4907
+							array_merge($this->bindings[$binding]['operations'][$operation]['input'], $this->portTypes[$bindingData['portType']][$operation]['input']) :
4908
+							$this->portTypes[$bindingData['portType']][$operation]['input'];
4909
+					$this->bindings[$binding]['operations'][$operation]['output'] =
4910
+						isset($this->bindings[$binding]['operations'][$operation]['output']) ?
4911
+							array_merge($this->bindings[$binding]['operations'][$operation]['output'], $this->portTypes[$bindingData['portType']][$operation]['output']) :
4912
+							$this->portTypes[$bindingData['portType']][$operation]['output'];
4913
+					if (isset($this->messages[$this->bindings[$binding]['operations'][$operation]['input']['message']])) {
4914
+						$this->bindings[$binding]['operations'][$operation]['input']['parts'] = $this->messages[$this->bindings[$binding]['operations'][$operation]['input']['message']];
4915
+					}
4916
+					if (isset($this->messages[$this->bindings[$binding]['operations'][$operation]['output']['message']])) {
4917
+						$this->bindings[$binding]['operations'][$operation]['output']['parts'] = $this->messages[$this->bindings[$binding]['operations'][$operation]['output']['message']];
4918
+					}
4919
+					// Set operation style if necessary, but do not override one already provided
4920
+					if (isset($bindingData['style']) && !isset($this->bindings[$binding]['operations'][$operation]['style'])) {
4921
+						$this->bindings[$binding]['operations'][$operation]['style'] = $bindingData['style'];
4922
+					}
4923
+					$this->bindings[$binding]['operations'][$operation]['transport'] = isset($bindingData['transport']) ? $bindingData['transport'] : '';
4924
+					$this->bindings[$binding]['operations'][$operation]['documentation'] = isset($this->portTypes[$bindingData['portType']][$operation]['documentation']) ? $this->portTypes[$bindingData['portType']][$operation]['documentation'] : '';
4925
+					$this->bindings[$binding]['operations'][$operation]['endpoint'] = isset($bindingData['endpoint']) ? $bindingData['endpoint'] : '';
4926
+				}
4927
+			}
4928
+		}
4929
+	}
4930
+
4931
+	/**
4932
+	 * parses the wsdl document
4933
+	 *
4934
+	 * @param string $wsdl path or URL
4935
+	 * @access private
4936
+	 */
4937
+	function parseWSDL($wsdl = '')
4938
+	{
4939
+		$this->debug("parse WSDL at path=$wsdl");
4940
+
4941
+		if ($wsdl == '') {
4942
+			$this->debug('no wsdl passed to parseWSDL()!!');
4943
+			$this->setError('no wsdl passed to parseWSDL()!!');
4944
+			return false;
4945
+		}
4946
+
4947
+		// parse $wsdl for url format
4948
+		$wsdl_props = parse_url($wsdl);
4949
+
4950
+		if (isset($wsdl_props['scheme']) && ($wsdl_props['scheme'] == 'http' || $wsdl_props['scheme'] == 'https')) {
4951
+			$this->debug('getting WSDL http(s) URL ' . $wsdl);
4952
+			// get wsdl
4953
+			$tr = new soap_transport_http($wsdl, $this->curl_options, $this->use_curl);
4954
+			$tr->request_method = 'GET';
4955
+			$tr->useSOAPAction = false;
4956
+			if ($this->proxyhost && $this->proxyport) {
4957
+				$tr->setProxy($this->proxyhost, $this->proxyport, $this->proxyusername, $this->proxypassword);
4958
+			}
4959
+			if ($this->authtype != '') {
4960
+				$tr->setCredentials($this->username, $this->password, $this->authtype, array(), $this->certRequest);
4961
+			}
4962
+			$tr->setEncoding();
4963
+			$wsdl_string = $tr->send('', $this->timeout, $this->response_timeout);
4964
+			//$this->debug("WSDL request\n" . $tr->outgoing_payload);
4965
+			//$this->debug("WSDL response\n" . $tr->incoming_payload);
4966
+			$this->appendDebug($tr->getDebug());
4967
+			// catch errors
4968
+			if ($err = $tr->getError()) {
4969
+				$errstr = 'Getting ' . $wsdl . ' - HTTP ERROR: ' . $err;
4970
+				$this->debug($errstr);
4971
+				$this->setError($errstr);
4972
+				unset($tr);
4973
+				return false;
4974
+			}
4975
+			unset($tr);
4976
+			$this->debug("got WSDL URL");
4977
+		} else {
4978
+			// $wsdl is not http(s), so treat it as a file URL or plain file path
4979
+			if (isset($wsdl_props['scheme']) && ($wsdl_props['scheme'] == 'file') && isset($wsdl_props['path'])) {
4980
+				$path = isset($wsdl_props['host']) ? ($wsdl_props['host'] . ':' . $wsdl_props['path']) : $wsdl_props['path'];
4981
+			} else {
4982
+				$path = $wsdl;
4983
+			}
4984
+			$this->debug('getting WSDL file ' . $path);
4985
+			if ($fp = @fopen($path, 'r')) {
4986
+				$wsdl_string = '';
4987
+				while ($data = fread($fp, 32768)) {
4988
+					$wsdl_string .= $data;
4989
+				}
4990
+				fclose($fp);
4991
+			} else {
4992
+				$errstr = "Bad path to WSDL file $path";
4993
+				$this->debug($errstr);
4994
+				$this->setError($errstr);
4995
+				return false;
4996
+			}
4997
+		}
4998
+		$this->debug('Parse WSDL');
4999
+		// end new code added
5000
+		// Create an XML parser.
5001
+		$this->parser = xml_parser_create();
5002
+		// Set the options for parsing the XML data.
5003
+		// xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
5004
+		xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
5005
+		// Set the object for the parser.
5006
+		xml_set_object($this->parser, $this);
5007
+		// Set the element handlers for the parser.
5008
+		xml_set_element_handler($this->parser, 'start_element', 'end_element');
5009
+		xml_set_character_data_handler($this->parser, 'character_data');
5010
+		// Parse the XML file.
5011
+		if (!xml_parse($this->parser, $wsdl_string, true)) {
5012
+			// Display an error message.
5013
+			$errstr = sprintf(
5014
+				'XML error parsing WSDL from %s on line %d: %s',
5015
+				$wsdl,
5016
+				xml_get_current_line_number($this->parser),
5017
+				xml_error_string(xml_get_error_code($this->parser))
5018
+			);
5019
+			$this->debug($errstr);
5020
+			$this->debug("XML payload:\n" . $wsdl_string);
5021
+			$this->setError($errstr);
5022
+			xml_parser_free($this->parser);
5023
+			unset($this->parser);
5024
+			return false;
5025
+		}
5026
+		// free the parser
5027
+		xml_parser_free($this->parser);
5028
+		unset($this->parser);
5029
+		$this->debug('Parsing WSDL done');
5030
+		// catch wsdl parse errors
5031
+		if ($this->getError()) {
5032
+			return false;
5033
+		}
5034
+		return true;
5035
+	}
5036
+
5037
+	/**
5038
+	 * start-element handler
5039
+	 *
5040
+	 * @param string $parser XML parser object
5041
+	 * @param string $name element name
5042
+	 * @param array $attrs associative array of attributes
5043
+	 * @access private
5044
+	 */
5045
+	function start_element($parser, $name, $attrs)
5046
+	{
5047
+		if ($this->status == 'schema') {
5048
+			$this->currentSchema->schemaStartElement($parser, $name, $attrs);
5049
+			$this->appendDebug($this->currentSchema->getDebug());
5050
+			$this->currentSchema->clearDebug();
5051
+		} elseif (preg_match('/schema$/', $name)) {
5052
+			$this->debug('Parsing WSDL schema');
5053
+			// $this->debug("startElement for $name ($attrs[name]). status = $this->status (".$this->getLocalPart($name).")");
5054
+			$this->status = 'schema';
5055
+			$this->currentSchema = new nusoap_xmlschema('', '', $this->namespaces);
5056
+			$this->currentSchema->schemaStartElement($parser, $name, $attrs);
5057
+			$this->appendDebug($this->currentSchema->getDebug());
5058
+			$this->currentSchema->clearDebug();
5059
+		} else {
5060
+			// position in the total number of elements, starting from 0
5061
+			$pos = $this->position++;
5062
+			$depth = $this->depth++;
5063
+			// set self as current value for this depth
5064
+			$this->depth_array[$depth] = $pos;
5065
+			$this->message[$pos] = array('cdata' => '');
5066
+			// process attributes
5067
+			if (count($attrs) > 0) {
5068
+				// register namespace declarations
5069
+				foreach ($attrs as $k => $v) {
5070
+					if (preg_match('/^xmlns/', $k)) {
5071
+						if ($ns_prefix = substr(strrchr($k, ':'), 1)) {
5072
+							$this->namespaces[$ns_prefix] = $v;
5073
+						} else {
5074
+							$this->namespaces['ns' . (count($this->namespaces) + 1)] = $v;
5075
+						}
5076
+						if ($v == 'http://www.w3.org/2001/XMLSchema' || $v == 'http://www.w3.org/1999/XMLSchema' || $v == 'http://www.w3.org/2000/10/XMLSchema') {
5077
+							$this->XMLSchemaVersion = $v;
5078
+							$this->namespaces['xsi'] = $v . '-instance';
5079
+						}
5080
+					}
5081
+				}
5082
+				// expand each attribute prefix to its namespace
5083
+				$eAttrs = array ();
5084
+				foreach ($attrs as $k => $v) {
5085
+					$k = strpos($k, ':') ? $this->expandQname($k) : $k;
5086
+					if ($k != 'location' && $k != 'soapAction' && $k != 'namespace') {
5087
+						$v = strpos($v, ':') ? $this->expandQname($v) : $v;
5088
+					}
5089
+					$eAttrs[$k] = $v;
5090
+				}
5091
+				$attrs = $eAttrs;
5092
+			} else {
5093
+				$attrs = array();
5094
+			}
5095
+		// Set default prefix and namespace
5096
+		// to prevent error Undefined variable $prefix and $namespace if (preg_match('/:/', $name)) return 0 or FALSE
5097
+		$prefix = '';
5098
+		$namespace = '';
5099
+			// get element prefix, namespace and name
5100
+			if (preg_match('/:/', $name)) {
5101
+				// get ns prefix
5102
+				$prefix = substr($name, 0, strpos($name, ':'));
5103
+				// get ns
5104
+				$namespace = isset($this->namespaces[$prefix]) ? $this->namespaces[$prefix] : '';
5105
+				// get unqualified name
5106
+				$name = substr(strstr($name, ':'), 1);
5107
+			}
5108
+			// process attributes, expanding any prefixes to namespaces
5109
+			// find status, register data
5110
+			switch ($this->status) {
5111
+				case 'message':
5112
+					if ($name == 'part') {
5113
+						if (isset($attrs['type'])) {
5114
+							$this->debug("msg " . $this->currentMessage . ": found part (with type) $attrs[name]: " . implode(',', $attrs));
5115
+							$this->messages[$this->currentMessage][$attrs['name']] = $attrs['type'];
5116
+						}
5117
+						if (isset($attrs['element'])) {
5118
+							$this->debug("msg " . $this->currentMessage . ": found part (with element) $attrs[name]: " . implode(',', $attrs));
5119
+							$this->messages[$this->currentMessage][$attrs['name']] = $attrs['element'] . '^';
5120
+						}
5121
+					}
5122
+					break;
5123
+				case 'portType':
5124
+					switch ($name) {
5125
+						case 'operation':
5126
+							$this->currentPortOperation = $attrs['name'];
5127
+							$this->debug("portType $this->currentPortType operation: $this->currentPortOperation");
5128
+							if (isset($attrs['parameterOrder'])) {
5129
+								$this->portTypes[$this->currentPortType][$attrs['name']]['parameterOrder'] = $attrs['parameterOrder'];
5130
+							}
5131
+							break;
5132
+						case 'documentation':
5133
+							$this->documentation = true;
5134
+							break;
5135
+						// merge input/output data
5136
+						default:
5137
+							$m = isset($attrs['message']) ? $this->getLocalPart($attrs['message']) : '';
5138
+							$this->portTypes[$this->currentPortType][$this->currentPortOperation][$name]['message'] = $m;
5139
+							break;
5140
+					}
5141
+					break;
5142
+				case 'binding':
5143
+					switch ($name) {
5144
+						case 'binding':
5145
+							// get ns prefix
5146
+							if (isset($attrs['style'])) {
5147
+								$this->bindings[$this->currentBinding]['prefix'] = $prefix;
5148
+							}
5149
+							$this->bindings[$this->currentBinding] = array_merge($this->bindings[$this->currentBinding], $attrs);
5150
+							break;
5151
+						case 'header':
5152
+							$this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus]['headers'][] = $attrs;
5153
+							break;
5154
+						case 'operation':
5155
+							if (isset($attrs['soapAction'])) {
5156
+								$this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['soapAction'] = $attrs['soapAction'];
5157
+							}
5158
+							if (isset($attrs['style'])) {
5159
+								$this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['style'] = $attrs['style'];
5160
+							}
5161
+							if (isset($attrs['name'])) {
5162
+								$this->currentOperation = $attrs['name'];
5163
+								$this->debug("current binding operation: $this->currentOperation");
5164
+								$this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['name'] = $attrs['name'];
5165
+								$this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['binding'] = $this->currentBinding;
5166
+								$this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['endpoint'] = isset($this->bindings[$this->currentBinding]['endpoint']) ? $this->bindings[$this->currentBinding]['endpoint'] : '';
5167
+							}
5168
+							break;
5169
+						case 'input':
5170
+							$this->opStatus = 'input';
5171
+							break;
5172
+						case 'output':
5173
+							$this->opStatus = 'output';
5174
+							break;
5175
+						case 'body':
5176
+							if (isset($this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus])) {
5177
+								$this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus] = array_merge($this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus], $attrs);
5178
+							} else {
5179
+								$this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus] = $attrs;
5180
+							}
5181
+							break;
5182
+					}
5183
+					break;
5184
+				case 'service':
5185
+					switch ($name) {
5186
+						case 'port':
5187
+							$this->currentPort = $attrs['name'];
5188
+							$this->debug('current port: ' . $this->currentPort);
5189
+							$this->ports[$this->currentPort]['binding'] = $this->getLocalPart($attrs['binding']);
5190
+
5191
+							break;
5192
+						case 'address':
5193
+							$this->ports[$this->currentPort]['location'] = $attrs['location'];
5194
+							$this->ports[$this->currentPort]['bindingType'] = $namespace;
5195
+							$this->bindings[$this->ports[$this->currentPort]['binding']]['bindingType'] = $namespace;
5196
+							$this->bindings[$this->ports[$this->currentPort]['binding']]['endpoint'] = $attrs['location'];
5197
+							break;
5198
+					}
5199
+					break;
5200
+			}
5201
+			// set status
5202
+			switch ($name) {
5203
+				case 'import':
5204
+					if (isset($attrs['location'])) {
5205
+						$this->import[$attrs['namespace']][] = array('location' => $attrs['location'], 'loaded' => false);
5206
+						$this->debug('parsing import ' . $attrs['namespace'] . ' - ' . $attrs['location'] . ' (' . count($this->import[$attrs['namespace']]) . ')');
5207
+					} else {
5208
+						$this->import[$attrs['namespace']][] = array('location' => '', 'loaded' => true);
5209
+						if (!$this->getPrefixFromNamespace($attrs['namespace'])) {
5210
+							$this->namespaces['ns' . (count($this->namespaces) + 1)] = $attrs['namespace'];
5211
+						}
5212
+						$this->debug('parsing import ' . $attrs['namespace'] . ' - [no location] (' . count($this->import[$attrs['namespace']]) . ')');
5213
+					}
5214
+					break;
5215
+				//wait for schema
5216
+				//case 'types':
5217
+				//	$this->status = 'schema';
5218
+				//	break;
5219
+				case 'message':
5220
+					$this->status = 'message';
5221
+					$this->messages[$attrs['name']] = array();
5222
+					$this->currentMessage = $attrs['name'];
5223
+					break;
5224
+				case 'portType':
5225
+					$this->status = 'portType';
5226
+					$this->portTypes[$attrs['name']] = array();
5227
+					$this->currentPortType = $attrs['name'];
5228
+					break;
5229
+				case "binding":
5230
+					if (isset($attrs['name'])) {
5231
+						// get binding name
5232
+						if (strpos($attrs['name'], ':')) {
5233
+							$this->currentBinding = $this->getLocalPart($attrs['name']);
5234
+						} else {
5235
+							$this->currentBinding = $attrs['name'];
5236
+						}
5237
+						$this->status = 'binding';
5238
+						$this->bindings[$this->currentBinding]['portType'] = $this->getLocalPart($attrs['type']);
5239
+						$this->debug("current binding: $this->currentBinding of portType: " . $attrs['type']);
5240
+					}
5241
+					break;
5242
+				case 'service':
5243
+					$this->serviceName = $attrs['name'];
5244
+					$this->status = 'service';
5245
+					$this->debug('current service: ' . $this->serviceName);
5246
+					break;
5247
+				case 'definitions':
5248
+					foreach ($attrs as $name => $value) {
5249
+						$this->wsdl_info[$name] = $value;
5250
+					}
5251
+					break;
5252
+			}
5253
+		}
5254
+	}
5255
+
5256
+	/**
5257
+	 * end-element handler
5258
+	 *
5259
+	 * @param string $parser XML parser object
5260
+	 * @param string $name element name
5261
+	 * @access private
5262
+	 */
5263
+	function end_element($parser, $name)
5264
+	{
5265
+		// unset schema status
5266
+		if (/*preg_match('/types$/', $name) ||*/
5267
+		preg_match('/schema$/', $name)
5268
+		) {
5269
+			$this->status = "";
5270
+			$this->appendDebug($this->currentSchema->getDebug());
5271
+			$this->currentSchema->clearDebug();
5272
+			$this->schemas[$this->currentSchema->schemaTargetNamespace][] = $this->currentSchema;
5273
+			$this->debug('Parsing WSDL schema done');
5274
+		}
5275
+		if ($this->status == 'schema') {
5276
+			$this->currentSchema->schemaEndElement($parser, $name);
5277
+		} else {
5278
+			// bring depth down a notch
5279
+			$this->depth--;
5280
+		}
5281
+		// end documentation
5282
+		if ($this->documentation) {
5283
+			//TODO: track the node to which documentation should be assigned; it can be a part, message, etc.
5284
+			//$this->portTypes[$this->currentPortType][$this->currentPortOperation]['documentation'] = $this->documentation;
5285
+			$this->documentation = false;
5286
+		}
5287
+	}
5288
+
5289
+	/**
5290
+	 * element content handler
5291
+	 *
5292
+	 * @param string $parser XML parser object
5293
+	 * @param string $data element content
5294
+	 * @access private
5295
+	 */
5296
+	function character_data($parser, $data)
5297
+	{
5298
+		$pos = isset($this->depth_array[$this->depth]) ? $this->depth_array[$this->depth] : 0;
5299
+		if (isset($this->message[$pos]['cdata'])) {
5300
+			$this->message[$pos]['cdata'] .= $data;
5301
+		}
5302
+		if ($this->documentation) {
5303
+			$this->documentation .= $data;
5304
+		}
5305
+	}
5306
+
5307
+	/**
5308
+	 * if authenticating, set user credentials here
5309
+	 *
5310
+	 * @param    string $username
5311
+	 * @param    string $password
5312
+	 * @param    string $authtype (basic|digest|certificate|ntlm)
5313
+	 * @param    array $certRequest (keys must be cainfofile (optional), sslcertfile, sslkeyfile, passphrase, certpassword (optional), verifypeer (optional), verifyhost (optional): see corresponding options in cURL docs)
5314
+	 * @access   public
5315
+	 */
5316
+	function setCredentials($username, $password, $authtype = 'basic', $certRequest = array())
5317
+	{
5318
+		$this->debug("setCredentials username=$username authtype=$authtype certRequest=");
5319
+		$this->appendDebug($this->varDump($certRequest));
5320
+		$this->username = $username;
5321
+		$this->password = $password;
5322
+		$this->authtype = $authtype;
5323
+		$this->certRequest = $certRequest;
5324
+	}
5325
+
5326
+	function getBindingData($binding)
5327
+	{
5328
+		if (is_array($this->bindings[$binding])) {
5329
+			return $this->bindings[$binding];
5330
+		}
5331
+		return false;
5332
+	}
5333
+
5334
+	/**
5335
+	 * returns an assoc array of operation names => operation data
5336
+	 *
5337
+	 * @param string $portName WSDL port name
5338
+	 * @param string $bindingType eg: soap, smtp, dime (only soap and soap12 are currently supported)
5339
+	 * @return array
5340
+	 * @access public
5341
+	 */
5342
+	function getOperations($portName = '', $bindingType = 'soap')
5343
+	{
5344
+		$ops = array();
5345
+		if ($bindingType == 'soap') {
5346
+			$bindingType = 'http://schemas.xmlsoap.org/wsdl/soap/';
5347
+		} elseif ($bindingType == 'soap12') {
5348
+			$bindingType = 'http://schemas.xmlsoap.org/wsdl/soap12/';
5349
+		} else {
5350
+			$this->debug("getOperations bindingType $bindingType may not be supported");
5351
+		}
5352
+		$this->debug("getOperations for port '$portName' bindingType $bindingType");
5353
+		// loop thru ports
5354
+		foreach ($this->ports as $port => $portData) {
5355
+			$this->debug("getOperations checking port $port bindingType " . $portData['bindingType']);
5356
+			if ($portName == '' || $port == $portName) {
5357
+				// binding type of port matches parameter
5358
+				if ($portData['bindingType'] == $bindingType) {
5359
+					$this->debug("getOperations found port $port bindingType $bindingType");
5360
+					//$this->debug("port data: " . $this->varDump($portData));
5361
+					//$this->debug("bindings: " . $this->varDump($this->bindings[ $portData['binding'] ]));
5362
+					// merge bindings
5363
+					if (isset($this->bindings[$portData['binding']]['operations'])) {
5364
+						$ops = array_merge($ops, $this->bindings[$portData['binding']]['operations']);
5365
+					}
5366
+				}
5367
+			}
5368
+		}
5369
+		if (count($ops) == 0) {
5370
+			$this->debug("getOperations found no operations for port '$portName' bindingType $bindingType");
5371
+		}
5372
+		return $ops;
5373
+	}
5374
+
5375
+	/**
5376
+	 * returns an associative array of data necessary for calling an operation
5377
+	 *
5378
+	 * @param string $operation name of operation
5379
+	 * @param string $bindingType type of binding eg: soap, soap12
5380
+	 * @return array
5381
+	 * @access public
5382
+	 */
5383
+	function getOperationData($operation, $bindingType = 'soap')
5384
+	{
5385
+		if ($bindingType == 'soap') {
5386
+			$bindingType = 'http://schemas.xmlsoap.org/wsdl/soap/';
5387
+		} elseif ($bindingType == 'soap12') {
5388
+			$bindingType = 'http://schemas.xmlsoap.org/wsdl/soap12/';
5389
+		}
5390
+		// loop thru ports
5391
+		foreach ($this->ports as $portData) {
5392
+			// binding type of port matches parameter
5393
+			if ($portData['bindingType'] == $bindingType) {
5394
+				// get binding
5395
+				//foreach($this->bindings[ $portData['binding'] ]['operations'] as $bOperation => $opData) {
5396
+				// note that we could/should also check the namespace here
5397
+				if (in_array ($operation, array_keys ($this->bindings[$portData['binding']]['operations'])))
5398
+				{
5399
+					return $this->bindings[$portData['binding']]['operations'][$operation];
5400
+				}
5401
+			}
5402
+		}
5403
+		return array ();
5404
+	}
5405
+
5406
+	/**
5407
+	 * returns an associative array of data necessary for calling an operation
5408
+	 *
5409
+	 * @param string $soapAction soapAction for operation
5410
+	 * @param string $bindingType type of binding eg: soap, soap12
5411
+	 * @return array
5412
+	 * @access public
5413
+	 */
5414
+	function getOperationDataForSoapAction($soapAction, $bindingType = 'soap')
5415
+	{
5416
+		if ($bindingType == 'soap') {
5417
+			$bindingType = 'http://schemas.xmlsoap.org/wsdl/soap/';
5418
+		} elseif ($bindingType == 'soap12') {
5419
+			$bindingType = 'http://schemas.xmlsoap.org/wsdl/soap12/';
5420
+		}
5421
+		// loop thru ports
5422
+		foreach ($this->ports as $portData) {
5423
+			// binding type of port matches parameter
5424
+			if ($portData['bindingType'] == $bindingType) {
5425
+				// loop through operations for the binding
5426
+				foreach ($this->bindings[$portData['binding']]['operations'] as $opData) {
5427
+					if ($opData['soapAction'] == $soapAction) {
5428
+						return $opData;
5429
+					}
5430
+				}
5431
+			}
5432
+		}
5433
+		return array ();
5434
+	}
5435
+
5436
+	/**
5437
+	 * returns an array of information about a given type
5438
+	 * returns false if no type exists by the given name
5439
+	 *     typeDef = array(
5440
+	 *     'elements' => array(), // refs to elements array
5441
+	 *    'restrictionBase' => '',
5442
+	 *    'phpType' => '',
5443
+	 *    'order' => '(sequence|all)',
5444
+	 *    'attrs' => array() // refs to attributes array
5445
+	 *    )
5446
+	 *
5447
+	 * @param string $type the type
5448
+	 * @param string $ns namespace (not prefix) of the type
5449
+	 * @return false
5450
+	 * @access public
5451
+	 * @see nusoap_xmlschema
5452
+	 */
5453
+	function getTypeDef($type, $ns)
5454
+	{
5455
+		$this->debug("in getTypeDef: type=$type, ns=$ns");
5456
+		if ((!$ns) && isset($this->namespaces['tns'])) {
5457
+			$ns = $this->namespaces['tns'];
5458
+			$this->debug("in getTypeDef: type namespace forced to $ns");
5459
+		}
5460
+		if (!isset($this->schemas[$ns])) {
5461
+			foreach ($this->schemas as $ns0 => $schema0) {
5462
+				if (strcasecmp($ns, $ns0) == 0) {
5463
+					$this->debug("in getTypeDef: replacing schema namespace $ns with $ns0");
5464
+					$ns = $ns0;
5465
+					break;
5466
+				}
5467
+			}
5468
+		}
5469
+		if (isset($this->schemas[$ns])) {
5470
+			$this->debug("in getTypeDef: have schema for namespace $ns");
5471
+			for ($i = 0; $i < count($this->schemas[$ns]); $i++) {
5472
+				$xs = &$this->schemas[$ns][$i];
5473
+				$t = $xs->getTypeDef($type);
5474
+				$this->appendDebug($xs->getDebug());
5475
+				$xs->clearDebug();
5476
+				if ($t) {
5477
+					$this->debug("in getTypeDef: found type $type");
5478
+					if (!isset($t['phpType'])) {
5479
+						// get info for type to tack onto the element
5480
+						$uqType = substr($t['type'], strrpos($t['type'], ':') + 1);
5481
+						$ns = substr($t['type'], 0, strrpos($t['type'], ':'));
5482
+						$etype = $this->getTypeDef($uqType, $ns);
5483
+						if ($etype) {
5484
+							$this->debug("found type for [element] $type:");
5485
+							$this->debug($this->varDump($etype));
5486
+							if (isset($etype['phpType'])) {
5487
+								$t['phpType'] = $etype['phpType'];
5488
+							}
5489
+							if (isset($etype['elements'])) {
5490
+								$t['elements'] = $etype['elements'];
5491
+							}
5492
+							if (isset($etype['attrs'])) {
5493
+								$t['attrs'] = $etype['attrs'];
5494
+							}
5495
+						} else {
5496
+							$this->debug("did not find type for [element] $type");
5497
+						}
5498
+					}
5499
+					return $t;
5500
+				}
5501
+			}
5502
+			$this->debug("in getTypeDef: did not find type $type");
5503
+		} else {
5504
+			$this->debug("in getTypeDef: do not have schema for namespace $ns");
5505
+		}
5506
+		return false;
5507
+	}
5508
+
5509
+	/**
5510
+	 * prints html description of services
5511
+	 *
5512
+	 * @access private
5513
+	 */
5514
+	function webDescription()
5515
+	{
5516
+		global $HTTP_SERVER_VARS;
5517
+
5518
+		if (isset($_SERVER)) {
5519
+			$PHP_SELF = $_SERVER['PHP_SELF'];
5520
+		} elseif (isset($HTTP_SERVER_VARS)) {
5521
+			$PHP_SELF = $HTTP_SERVER_VARS['PHP_SELF'];
5522
+		} else {
5523
+			$this->setError("Neither _SERVER nor HTTP_SERVER_VARS is available");
5524
+			$PHP_SELF = '';
5525
+		}
5526
+
5527
+		$b = '
5528
+		<html><head><title>NuSOAP: ' . $this->serviceName . '</title>
5529
+		<style type="text/css">
5530
+		    body    { font-family: arial; color: #000000; background-color: #ffffff; margin: 0px 0px 0px 0px; }
5531
+		    p       { font-family: arial; color: #000000; margin-top: 0px; margin-bottom: 12px; }
5532
+		    pre { background-color: silver; padding: 5px; font-family: Courier New; font-size: x-small; color: #000000;}
5533
+		    ul      { margin-top: 10px; margin-left: 20px; }
5534
+		    li      { list-style-type: none; margin-top: 10px; color: #000000; }
5535
+		    .content{
5536
+			margin-left: 0px; padding-bottom: 2em; }
5537
+		    .nav {
5538
+			padding-top: 10px; padding-bottom: 10px; padding-left: 15px; font-size: .70em;
5539
+			margin-top: 10px; margin-left: 0px; color: #000000;
5540
+			background-color: #ccccff; width: 20%; margin-left: 20px; margin-top: 20px; }
5541
+		    .title {
5542
+			font-family: arial; font-size: 26px; color: #ffffff;
5543
+			background-color: #999999; width: 100%;
5544
+			margin-left: 0px; margin-right: 0px;
5545
+			padding-top: 10px; padding-bottom: 10px;}
5546
+		    .hidden {
5547
+			position: absolute; visibility: hidden; z-index: 200; left: 250px; top: 100px;
5548
+			font-family: arial; overflow: hidden; width: 600;
5549
+			padding: 20px; font-size: 10px; background-color: #999999;
5550
+			layer-background-color:#FFFFFF; }
5551
+		    a,a:active  { color: charcoal; font-weight: bold; }
5552
+		    a:visited   { color: #666666; font-weight: bold; }
5553
+		    a:hover     { color: cc3300; font-weight: bold; }
5554
+		</style>
5555
+		<script language="JavaScript" type="text/javascript">
5556
+		<!--
5557
+		// POP-UP CAPTIONS...
5558
+		function lib_bwcheck(){ //Browsercheck (needed)
5559
+		    this.ver=navigator.appVersion
5560
+		    this.agent=navigator.userAgent
5561
+		    this.dom=document.getElementById?1:0
5562
+		    this.opera5=this.agent.indexOf("Opera 5")>-1
5563
+		    this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0;
5564
+		    this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
5565
+		    this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
5566
+		    this.ie=this.ie4||this.ie5||this.ie6
5567
+		    this.mac=this.agent.indexOf("Mac")>-1
5568
+		    this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0;
5569
+		    this.ns4=(document.layers && !this.dom)?1:0;
5570
+		    this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
5571
+		    return this
5572
+		}
5573
+		var bw = new lib_bwcheck()
5574
+		//Makes crossbrowser object.
5575
+		function makeObj(obj){
5576
+		    this.evnt=bw.dom? document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?document.layers[obj]:0;
5577
+		    if(!this.evnt) return false
5578
+		    this.css=bw.dom||bw.ie4?this.evnt.style:bw.ns4?this.evnt:0;
5579
+		    this.wref=bw.dom||bw.ie4?this.evnt:bw.ns4?this.css.document:0;
5580
+		    this.writeIt=b_writeIt;
5581
+		    return this
5582
+		}
5583
+		// A unit of measure that will be added when setting the position of a layer.
5584
+		//var px = bw.ns4||window.opera?"":"px";
5585
+		function b_writeIt(text){
5586
+		    if (bw.ns4){this.wref.write(text);this.wref.close()}
5587
+		    else this.wref.innerHTML = text
5588
+		}
5589
+		//Shows the messages
5590
+		var oDesc;
5591
+		function popup(divid){
5592
+		    if(oDesc = new makeObj(divid)){
5593
+			oDesc.css.visibility = "visible"
5594
+		    }
5595
+		}
5596
+		function popout(){ // Hides message
5597
+		    if(oDesc) oDesc.css.visibility = "hidden"
5598
+		}
5599
+		//-->
5600
+		</script>
5601
+		</head>
5602
+		<body>
5603
+		<div class=content>
5604
+			<br><br>
5605
+			<div class=title>' . $this->serviceName . '</div>
5606
+			<div class=nav>
5607
+				<p>View the <a href="?wsdl">WSDL</a> for the service.
5608
+				Click on an operation name to view it&apos;s details.</p>
5609
+				<ul>';
5610
+		foreach ($this->getOperations() as $op => $data) {
5611
+			$b .= "<li><a href='#' onclick=\"popout();popup('$op')\">$op</a></li>";
5612
+			// create hidden div
5613
+			$b .= "<div id='$op' class='hidden'>
5614
+				    <a href='#' onclick='popout()'><font color='#ffffff'>Close</font></a><br><br>";
5615
+			foreach ($data as $donnie => $marie) { // loop through opdata
5616
+				if ($donnie == 'input' || $donnie == 'output') { // show input/output data
5617
+					$b .= "<font color='white'>" . ucfirst($donnie) . ':</font><br>';
5618
+					foreach ($marie as $captain => $tenille) { // loop through data
5619
+						if ($captain == 'parts') { // loop thru parts
5620
+							$b .= "&nbsp;&nbsp;$captain:<br>";
5621
+							//if(is_array($tenille)){
5622
+							foreach ($tenille as $joanie => $chachi) {
5623
+								$b .= "&nbsp;&nbsp;&nbsp;&nbsp;$joanie: $chachi<br>";
5624
+							}
5625
+							//}
5626
+						} else {
5627
+							$b .= "&nbsp;&nbsp;$captain: $tenille<br>";
5628
+						}
5629
+					}
5630
+				} else {
5631
+					$b .= "<font color='white'>" . ucfirst($donnie) . ":</font> $marie<br>";
5632
+				}
5633
+			}
5634
+			$b .= '</div>';
5635
+		}
5636
+		$b .= '
5637
+				<ul>
5638
+			</div>
5639
+		</div></body></html>';
5640
+		return $b;
5641
+	}
5642
+
5643
+	/**
5644
+	 * serialize the parsed wsdl
5645
+	 *
5646
+	 * @param mixed $debug whether to put debug=1 in endpoint URL
5647
+	 * @return string serialization of WSDL
5648
+	 * @access public
5649
+	 */
5650
+	function serialize($debug = 0)
5651
+	{
5652
+		$xml = '<?xml version="1.0" encoding="ISO-8859-1"?>';
5653
+		$xml .= "\n<definitions";
5654
+		foreach ($this->namespaces as $k => $v) {
5655
+			$xml .= " xmlns:$k=\"$v\"";
5656
+		}
5657
+		// 10.9.02 - add poulter fix for wsdl and tns declarations
5658
+		if (isset($this->namespaces['wsdl'])) {
5659
+			$xml .= " xmlns=\"" . $this->namespaces['wsdl'] . "\"";
5660
+		}
5661
+		if (isset($this->namespaces['tns'])) {
5662
+			$xml .= " targetNamespace=\"" . $this->namespaces['tns'] . "\"";
5663
+		}
5664
+		$xml .= '>';
5665
+		// imports
5666
+		if (sizeof($this->import) > 0) {
5667
+			foreach ($this->import as $ns => $list) {
5668
+				foreach ($list as $ii) {
5669
+					if ($ii['location'] != '') {
5670
+						$xml .= '<import location="' . $ii['location'] . '" namespace="' . $ns . '" />';
5671
+					} else {
5672
+						$xml .= '<import namespace="' . $ns . '" />';
5673
+					}
5674
+				}
5675
+			}
5676
+		}
5677
+		// types
5678
+		if (count($this->schemas) >= 1) {
5679
+			$xml .= "\n<types>\n";
5680
+			foreach ($this->schemas as $list) {
5681
+				foreach ($list as $xs) {
5682
+					$xml .= $xs->serializeSchema();
5683
+				}
5684
+			}
5685
+			$xml .= '</types>';
5686
+		}
5687
+		// messages
5688
+		if (count($this->messages) >= 1) {
5689
+			foreach ($this->messages as $msgName => $msgParts) {
5690
+				$xml .= "\n<message name=\"" . $msgName . '">';
5691
+				if (is_array($msgParts)) {
5692
+					foreach ($msgParts as $partName => $partType) {
5693
+						// print 'serializing '.$partType.', sv: '.$this->XMLSchemaVersion.'<br>';
5694
+						if (strpos($partType, ':')) {
5695
+							$typePrefix = $this->getPrefixFromNamespace($this->getPrefix($partType));
5696
+						} elseif (isset($this->typemap[$this->namespaces['xsd']][$partType])) {
5697
+							// print 'checking typemap: '.$this->XMLSchemaVersion.'<br>';
5698
+							$typePrefix = 'xsd';
5699
+						} else {
5700
+							foreach ($this->typemap as $ns => $types) {
5701
+								if (isset($types[$partType])) {
5702
+									$typePrefix = $this->getPrefixFromNamespace($ns);
5703
+								}
5704
+							}
5705
+							if (!isset($typePrefix)) {
5706
+								die("$partType has no namespace!");
5707
+							}
5708
+						}
5709
+						$ns = $this->getNamespaceFromPrefix($typePrefix);
5710
+						$localPart = $this->getLocalPart($partType);
5711
+						$typeDef = $this->getTypeDef($localPart, $ns);
5712
+						if (isset($typeDef['typeClass']) && $typeDef['typeClass'] == 'element') {
5713
+							$elementortype = 'element';
5714
+							if (substr($localPart, -1) == '^') {
5715
+								$localPart = substr($localPart, 0, -1);
5716
+							}
5717
+						} else {
5718
+							$elementortype = 'type';
5719
+						}
5720
+						$xml .= "\n" . '  <part name="' . $partName . '" ' . $elementortype . '="' . $typePrefix . ':' . $localPart . '" />';
5721
+					}
5722
+				}
5723
+				$xml .= '</message>';
5724
+			}
5725
+		}
5726
+		// bindings & porttypes
5727
+		if (count($this->bindings) >= 1) {
5728
+			$binding_xml = '';
5729
+			$portType_xml = '';
5730
+			foreach ($this->bindings as $bindingName => $attrs) {
5731
+				$binding_xml .= "\n<binding name=\"" . $bindingName . '" type="tns:' . $attrs['portType'] . '">';
5732
+				$binding_xml .= "\n" . '  <soap:binding style="' . $attrs['style'] . '" transport="' . $attrs['transport'] . '"/>';
5733
+				$portType_xml .= "\n<portType name=\"" . $attrs['portType'] . '">';
5734
+				foreach ($attrs['operations'] as $opName => $opParts) {
5735
+					$binding_xml .= "\n" . '  <operation name="' . $opName . '">';
5736
+					$binding_xml .= "\n" . '    <soap:operation soapAction="' . $opParts['soapAction'] . '" style="' . $opParts['style'] . '"/>';
5737
+					if (isset($opParts['input']['encodingStyle']) && $opParts['input']['encodingStyle'] != '') {
5738
+						$enc_style = ' encodingStyle="' . $opParts['input']['encodingStyle'] . '"';
5739
+					} else {
5740
+						$enc_style = '';
5741
+					}
5742
+					$binding_xml .= "\n" . '    <input><soap:body use="' . $opParts['input']['use'] . '" namespace="' . $opParts['input']['namespace'] . '"' . $enc_style . '/></input>';
5743
+					if (isset($opParts['output']['encodingStyle']) && $opParts['output']['encodingStyle'] != '') {
5744
+						$enc_style = ' encodingStyle="' . $opParts['output']['encodingStyle'] . '"';
5745
+					} else {
5746
+						$enc_style = '';
5747
+					}
5748
+					$binding_xml .= "\n" . '    <output><soap:body use="' . $opParts['output']['use'] . '" namespace="' . $opParts['output']['namespace'] . '"' . $enc_style . '/></output>';
5749
+					$binding_xml .= "\n" . '  </operation>';
5750
+					$portType_xml .= "\n" . '  <operation name="' . $opParts['name'] . '"';
5751
+					if (isset($opParts['parameterOrder'])) {
5752
+						$portType_xml .= ' parameterOrder="' . $opParts['parameterOrder'] . '"';
5753
+					}
5754
+					$portType_xml .= '>';
5755
+					if (isset($opParts['documentation']) && $opParts['documentation'] != '') {
5756
+						$portType_xml .= "\n" . '    <documentation>' . htmlspecialchars($opParts['documentation']) . '</documentation>';
5757
+					}
5758
+					$portType_xml .= "\n" . '    <input message="tns:' . $opParts['input']['message'] . '"/>';
5759
+					$portType_xml .= "\n" . '    <output message="tns:' . $opParts['output']['message'] . '"/>';
5760
+					$portType_xml .= "\n" . '  </operation>';
5761
+				}
5762
+				$portType_xml .= "\n" . '</portType>';
5763
+				$binding_xml .= "\n" . '</binding>';
5764
+			}
5765
+			$xml .= $portType_xml . $binding_xml;
5766
+		}
5767
+		// services
5768
+		$xml .= "\n<service name=\"" . $this->serviceName . '">';
5769
+		if (count($this->ports) >= 1) {
5770
+			foreach ($this->ports as $pName => $attrs) {
5771
+				$xml .= "\n" . '  <port name="' . $pName . '" binding="tns:' . $attrs['binding'] . '">';
5772
+				$xml .= "\n" . '    <soap:address location="' . $attrs['location'] . ($debug ? '?debug=1' : '') . '"/>';
5773
+				$xml .= "\n" . '  </port>';
5774
+			}
5775
+		}
5776
+		$xml .= "\n" . '</service>';
5777
+		return $xml . "\n</definitions>";
5778
+	}
5779
+
5780
+	/**
5781
+	 * determine whether a set of parameters are unwrapped
5782
+	 * when they are expect to be wrapped, Microsoft-style.
5783
+	 *
5784
+	 * @param string $type the type (element name) of the wrapper
5785
+	 * @param array $parameters the parameter values for the SOAP call
5786
+	 * @return boolean whether they parameters are unwrapped (and should be wrapped)
5787
+	 * @access private
5788
+	 */
5789
+	function parametersMatchWrapped($type, $parameters)
5790
+	{
5791
+		$this->debug("in parametersMatchWrapped type=$type, parameters=");
5792
+		$this->appendDebug($this->varDump($parameters));
5793
+
5794
+		// split type into namespace:unqualified-type
5795
+		if (strpos($type, ':')) {
5796
+			$uqType = substr($type, strrpos($type, ':') + 1);
5797
+			$ns = substr($type, 0, strrpos($type, ':'));
5798
+			$this->debug("in parametersMatchWrapped: got a prefixed type: $uqType, $ns");
5799
+			if ($this->getNamespaceFromPrefix($ns)) {
5800
+				$ns = $this->getNamespaceFromPrefix($ns);
5801
+				$this->debug("in parametersMatchWrapped: expanded prefixed type: $uqType, $ns");
5802
+			}
5803
+		} else {
5804
+			// TODO: should the type be compared to types in XSD, and the namespace
5805
+			// set to XSD if the type matches?
5806
+			$this->debug("in parametersMatchWrapped: No namespace for type $type");
5807
+			$ns = '';
5808
+			$uqType = $type;
5809
+		}
5810
+
5811
+		// get the type information
5812
+		if (!$typeDef = $this->getTypeDef($uqType, $ns)) {
5813
+			$this->debug("in parametersMatchWrapped: $type ($uqType) is not a supported type.");
5814
+			return false;
5815
+		}
5816
+		$this->debug("in parametersMatchWrapped: found typeDef=");
5817
+		$this->appendDebug($this->varDump($typeDef));
5818
+		if (substr($uqType, -1) == '^') {
5819
+			$uqType = substr($uqType, 0, -1);
5820
+		}
5821
+		$phpType = $typeDef['phpType'];
5822
+		$arrayType = (isset($typeDef['arrayType']) ? $typeDef['arrayType'] : '');
5823
+		$this->debug("in parametersMatchWrapped: uqType: $uqType, ns: $ns, phptype: $phpType, arrayType: $arrayType");
5824
+
5825
+		// we expect a complexType or element of complexType
5826
+		if ($phpType != 'struct') {
5827
+			$this->debug("in parametersMatchWrapped: not a struct");
5828
+			return false;
5829
+		}
5830
+
5831
+		// see whether the parameter names match the elements
5832
+		if (isset($typeDef['elements']) && is_array($typeDef['elements'])) {
5833
+			$elements = 0;
5834
+			$matches = 0;
5835
+			foreach ($typeDef['elements'] as $name => $attrs) {
5836
+				if (isset($parameters[$name])) {
5837
+					$this->debug("in parametersMatchWrapped: have parameter named $name");
5838
+					$matches++;
5839
+				} else {
5840
+					$this->debug("in parametersMatchWrapped: do not have parameter named $name");
5841
+				}
5842
+				$elements++;
5843
+			}
5844
+
5845
+			$this->debug("in parametersMatchWrapped: $matches parameter names match $elements wrapped parameter names");
5846
+			if ($matches == 0) {
5847
+				return false;
5848
+			}
5849
+			return true;
5850
+		}
5851
+
5852
+		// since there are no elements for the type, if the user passed no
5853
+		// parameters, the parameters match wrapped.
5854
+		$this->debug("in parametersMatchWrapped: no elements type $ns:$uqType");
5855
+		return count($parameters) == 0;
5856
+	}
5857
+
5858
+	/**
5859
+	 * serialize PHP values according to a WSDL message definition
5860
+	 * contrary to the method name, this is not limited to RPC
5861
+	 *
5862
+	 * TODO
5863
+	 * - multi-ref serialization
5864
+	 * - validate PHP values against type definitions, return errors if invalid
5865
+	 *
5866
+	 * @param string $operation operation name
5867
+	 * @param string $direction (input|output)
5868
+	 * @param mixed $parameters parameter value(s)
5869
+	 * @param string $bindingType (soap|soap12)
5870
+	 * @return false|string parameters serialized as XML or false on error (e.g. operation not found)
5871
+	 * @access public
5872
+	 */
5873
+	function serializeRPCParameters($operation, $direction, $parameters, $bindingType = 'soap')
5874
+	{
5875
+		$this->debug("in serializeRPCParameters: operation=$operation, direction=$direction, XMLSchemaVersion=$this->XMLSchemaVersion, bindingType=$bindingType");
5876
+		$this->appendDebug('parameters=' . $this->varDump($parameters));
5877
+
5878
+		if ($direction != 'input' && $direction != 'output') {
5879
+			$this->debug('The value of the \$direction argument needs to be either "input" or "output"');
5880
+			$this->setError('The value of the \$direction argument needs to be either "input" or "output"');
5881
+			return false;
5882
+		}
5883
+		if (!$opData = $this->getOperationData($operation, $bindingType)) {
5884
+			$this->debug('Unable to retrieve WSDL data for operation: ' . $operation . ' bindingType: ' . $bindingType);
5885
+			$this->setError('Unable to retrieve WSDL data for operation: ' . $operation . ' bindingType: ' . $bindingType);
5886
+			return false;
5887
+		}
5888
+		$this->debug('in serializeRPCParameters: opData:');
5889
+		$this->appendDebug($this->varDump($opData));
5890
+
5891
+		// Get encoding style for output and set to current
5892
+		$encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/';
5893
+		if (($direction == 'input') && isset($opData['output']['encodingStyle']) && ($opData['output']['encodingStyle'] != $encodingStyle)) {
5894
+			$encodingStyle = $opData['output']['encodingStyle'];
5895
+		}
5896
+
5897
+		// set input params
5898
+		$xml = '';
5899
+		if (isset($opData[$direction]['parts']) && sizeof($opData[$direction]['parts']) > 0) {
5900
+			$parts = &$opData[$direction]['parts'];
5901
+			$part_count = sizeof($parts);
5902
+			$style = $opData['style'];
5903
+			$use = $opData[$direction]['use'];
5904
+			$this->debug("have $part_count part(s) to serialize using $style/$use");
5905
+			if (is_array($parameters)) {
5906
+				$parametersArrayType = $this->isArraySimpleOrStruct($parameters);
5907
+				$parameter_count = count($parameters);
5908
+				$this->debug("have $parameter_count parameter(s) provided as $parametersArrayType to serialize");
5909
+				// check for Microsoft-style wrapped parameters
5910
+				if ($style == 'document' && $use == 'literal' && $part_count == 1 && isset($parts['parameters'])) {
5911
+					$this->debug('check whether the caller has wrapped the parameters');
5912
+					if ($direction == 'output' && $parametersArrayType == 'arraySimple' && $parameter_count == 1) {
5913
+						// TODO: consider checking here for double-wrapping, when
5914
+						// service function wraps, then NuSOAP wraps again
5915
+						$this->debug("change simple array to associative with 'parameters' element");
5916
+						$parameters['parameters'] = $parameters[0];
5917
+						unset($parameters[0]);
5918
+					}
5919
+					if (($parametersArrayType == 'arrayStruct' || $parameter_count == 0) && !isset($parameters['parameters'])) {
5920
+						$this->debug('check whether caller\'s parameters match the wrapped ones');
5921
+						if ($this->parametersMatchWrapped($parts['parameters'], $parameters)) {
5922
+							$this->debug('wrap the parameters for the caller');
5923
+							$parameters = array('parameters' => $parameters);
5924
+						}
5925
+					}
5926
+				}
5927
+				foreach ($parts as $name => $type) {
5928
+					$this->debug("serializing part $name of type $type");
5929
+					// Track encoding style
5930
+					if (isset($opData[$direction]['encodingStyle']) && $encodingStyle != $opData[$direction]['encodingStyle']) {
5931
+						$encodingStyle = $opData[$direction]['encodingStyle'];
5932
+						$enc_style = $encodingStyle;
5933
+					} else {
5934
+						$enc_style = false;
5935
+					}
5936
+					// NOTE: add error handling here
5937
+					// if serializeType returns false, then catch global error and fault
5938
+					if ($parametersArrayType == 'arraySimple') {
5939
+						$p = array_shift($parameters);
5940
+						$this->debug('calling serializeType w/indexed param');
5941
+						$xml .= $this->serializeType($name, $type, $p, $use, $enc_style);
5942
+					} elseif (isset($parameters[$name])) {
5943
+						$this->debug('calling serializeType w/named param');
5944
+						$xml .= $this->serializeType($name, $type, $parameters[$name], $use, $enc_style);
5945
+					} else {
5946
+						// TODO: only send nillable
5947
+						$this->debug('calling serializeType w/null param');
5948
+						$xml .= $this->serializeType($name, $type, null, $use, $enc_style);
5949
+					}
5950
+				}
5951
+			} else {
5952
+				$this->debug('no parameters passed.');
5953
+			}
5954
+		}
5955
+		$this->debug("serializeRPCParameters returning: $xml");
5956
+		return $xml;
5957
+	}
5958
+
5959
+	/**
5960
+	 * serialize a PHP value according to a WSDL message definition
5961
+	 *
5962
+	 * TODO
5963
+	 * - multi-ref serialization
5964
+	 * - validate PHP values against type definitions, return errors if invalid
5965
+	 *
5966
+	 * @param string $operation operation name
5967
+	 * @param string $direction (input|output)
5968
+	 * @param mixed $parameters parameter value(s)
5969
+	 * @return false|string parameters serialized as XML or false on error (e.g. operation not found)
5970
+	 * @access public
5971
+	 * @deprecated
5972
+	 */
5973
+	function serializeParameters($operation, $direction, $parameters)
5974
+	{
5975
+		$this->debug("in serializeParameters: operation=$operation, direction=$direction, XMLSchemaVersion=$this->XMLSchemaVersion");
5976
+		$this->appendDebug('parameters=' . $this->varDump($parameters));
5977
+
5978
+		if ($direction != 'input' && $direction != 'output') {
5979
+			$this->debug('The value of the \$direction argument needs to be either "input" or "output"');
5980
+			$this->setError('The value of the \$direction argument needs to be either "input" or "output"');
5981
+			return false;
5982
+		}
5983
+		if (!$opData = $this->getOperationData($operation)) {
5984
+			$this->debug('Unable to retrieve WSDL data for operation: ' . $operation);
5985
+			$this->setError('Unable to retrieve WSDL data for operation: ' . $operation);
5986
+			return false;
5987
+		}
5988
+		$this->debug('opData:');
5989
+		$this->appendDebug($this->varDump($opData));
5990
+
5991
+		// Get encoding style for output and set to current
5992
+		$encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/';
5993
+		if (($direction == 'input') && isset($opData['output']['encodingStyle']) && ($opData['output']['encodingStyle'] != $encodingStyle)) {
5994
+			$encodingStyle = $opData['output']['encodingStyle'];
5995
+		}
5996
+
5997
+		// set input params
5998
+		$xml = '';
5999
+		if (isset($opData[$direction]['parts']) && sizeof($opData[$direction]['parts']) > 0) {
6000
+
6001
+			$use = $opData[$direction]['use'];
6002
+			$this->debug("use=$use");
6003
+			$this->debug('got ' . count($opData[$direction]['parts']) . ' part(s)');
6004
+			if (is_array($parameters)) {
6005
+				$parametersArrayType = $this->isArraySimpleOrStruct($parameters);
6006
+				$this->debug('have ' . $parametersArrayType . ' parameters');
6007
+				foreach ($opData[$direction]['parts'] as $name => $type) {
6008
+					$this->debug('serializing part "' . $name . '" of type "' . $type . '"');
6009
+					// Track encoding style
6010
+					if (isset($opData[$direction]['encodingStyle']) && $encodingStyle != $opData[$direction]['encodingStyle']) {
6011
+						$encodingStyle = $opData[$direction]['encodingStyle'];
6012
+						$enc_style = $encodingStyle;
6013
+					} else {
6014
+						$enc_style = false;
6015
+					}
6016
+					// NOTE: add error handling here
6017
+					// if serializeType returns false, then catch global error and fault
6018
+					if ($parametersArrayType == 'arraySimple') {
6019
+						$p = array_shift($parameters);
6020
+						$this->debug('calling serializeType w/indexed param');
6021
+						$xml .= $this->serializeType($name, $type, $p, $use, $enc_style);
6022
+					} elseif (isset($parameters[$name])) {
6023
+						$this->debug('calling serializeType w/named param');
6024
+						$xml .= $this->serializeType($name, $type, $parameters[$name], $use, $enc_style);
6025
+					} else {
6026
+						// TODO: only send nillable
6027
+						$this->debug('calling serializeType w/null param');
6028
+						$xml .= $this->serializeType($name, $type, null, $use, $enc_style);
6029
+					}
6030
+				}
6031
+			} else {
6032
+				$this->debug('no parameters passed.');
6033
+			}
6034
+		}
6035
+		$this->debug("serializeParameters returning: $xml");
6036
+		return $xml;
6037
+	}
6038
+
6039
+	/**
6040
+	 * serializes a PHP value according a given type definition
6041
+	 *
6042
+	 * @param string $name name of value (part or element)
6043
+	 * @param string $type XML schema type of value (type or element)
6044
+	 * @param mixed $value a native PHP value (parameter value)
6045
+	 * @param string $use use for part (encoded|literal)
6046
+	 * @param string $encodingStyle SOAP encoding style for the value (if different than the enclosing style)
6047
+	 * @param boolean $unqualified a kludge for what should be XML namespace form handling
6048
+	 * @return string value serialized as an XML string
6049
+	 * @access private
6050
+	 */
6051
+	function serializeType($name, $type, $value, $use = 'encoded', $encodingStyle = false, $unqualified = false)
6052
+	{
6053
+		$this->debug("in serializeType: name=$name, type=$type, use=$use, encodingStyle=$encodingStyle, unqualified=" . ($unqualified ? "unqualified" : "qualified"));
6054
+		$this->appendDebug("value=" . $this->varDump($value));
6055
+		if ($use == 'encoded' && $encodingStyle) {
6056
+			$encodingStyle = ' SOAP-ENV:encodingStyle="' . $encodingStyle . '"';
6057
+		}
6058
+
6059
+		// if a soapval has been supplied, let its type override the WSDL
6060
+		if (is_object($value) && get_class($value) == 'soapval') {
6061
+			if ($value->type_ns) {
6062
+				$type = $value->type_ns . ':' . $value->type;
6063
+				$forceType = true;
6064
+				$this->debug("in serializeType: soapval overrides type to $type");
6065
+			} elseif ($value->type) {
6066
+				$type = $value->type;
6067
+				$forceType = true;
6068
+				$this->debug("in serializeType: soapval overrides type to $type");
6069
+			} else {
6070
+				$forceType = false;
6071
+				$this->debug("in serializeType: soapval does not override type");
6072
+			}
6073
+			$attrs = $value->attributes;
6074
+			$value = $value->value;
6075
+			$this->debug("in serializeType: soapval overrides value to $value");
6076
+			if ($attrs) {
6077
+				if (!is_array($value)) {
6078
+					$value['!'] = $value;
6079
+				}
6080
+				foreach ($attrs as $n => $v) {
6081
+					$value['!' . $n] = $v;
6082
+				}
6083
+				$this->debug("in serializeType: soapval provides attributes");
6084
+			}
6085
+		} else {
6086
+			$forceType = false;
6087
+		}
6088
+
6089
+		$xml = '';
6090
+		if (strpos($type, ':')) {
6091
+			$uqType = substr($type, strrpos($type, ':') + 1);
6092
+			$ns = substr($type, 0, strrpos($type, ':'));
6093
+			$this->debug("in serializeType: got a prefixed type: $uqType, $ns");
6094
+			if ($this->getNamespaceFromPrefix($ns)) {
6095
+				$ns = $this->getNamespaceFromPrefix($ns);
6096
+				$this->debug("in serializeType: expanded prefixed type: $uqType, $ns");
6097
+			}
6098
+
6099
+			if ($ns == $this->XMLSchemaVersion || $ns == 'http://schemas.xmlsoap.org/soap/encoding/') {
6100
+				$this->debug('in serializeType: type namespace indicates XML Schema or SOAP Encoding type');
6101
+				if ($unqualified && $use == 'literal') {
6102
+					$elementNS = " xmlns=\"\"";
6103
+				} else {
6104
+					$elementNS = '';
6105
+				}
6106
+				if (is_null($value)) {
6107
+					if ($use == 'literal') {
6108
+						// TODO: depends on minOccurs
6109
+						$xml = "<$name$elementNS/>";
6110
+					} else {
6111
+						// TODO: depends on nillable, which should be checked before calling this method
6112
+						$xml = "<$name$elementNS xsi:nil=\"true\" xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"/>";
6113
+					}
6114
+					$this->debug("in serializeType: returning: $xml");
6115
+					return $xml;
6116
+				}
6117
+				if ($uqType == 'Array') {
6118
+					// JBoss/Axis does this sometimes
6119
+					return $this->serialize_val($value, $name, false, false, false, false, $use);
6120
+				}
6121
+				if ($uqType == 'boolean') {
6122
+					if ((is_string($value) && $value == 'false') || (!$value)) {
6123
+						$value = 'false';
6124
+					} else {
6125
+						$value = 'true';
6126
+					}
6127
+				}
6128
+				if ($uqType == 'string' && gettype($value) == 'string') {
6129
+					$value = $this->expandEntities($value);
6130
+				}
6131
+				if (($uqType == 'long' || $uqType == 'unsignedLong') && gettype($value) == 'double') {
6132
+					$value = sprintf("%.0lf", $value);
6133
+				}
6134
+				// it's a scalar
6135
+				// TODO: what about null/nil values?
6136
+				// check type isn't a custom type extending xmlschema namespace
6137
+				if (!$this->getTypeDef($uqType, $ns)) {
6138
+					if ($use == 'literal') {
6139
+						if ($forceType) {
6140
+							$xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\">$value</$name>";
6141
+						} else {
6142
+							$xml = "<$name$elementNS>$value</$name>";
6143
+						}
6144
+					} else {
6145
+						$xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"$encodingStyle>$value</$name>";
6146
+					}
6147
+					$this->debug("in serializeType: returning: $xml");
6148
+					return $xml;
6149
+				}
6150
+				$this->debug('custom type extends XML Schema or SOAP Encoding namespace (yuck)');
6151
+			} elseif ($ns == 'http://xml.apache.org/xml-soap') {
6152
+				$this->debug('in serializeType: appears to be Apache SOAP type');
6153
+				if ($uqType == 'Map') {
6154
+					$tt_prefix = $this->getPrefixFromNamespace('http://xml.apache.org/xml-soap');
6155
+					if (!$tt_prefix) {
6156
+						$this->debug('in serializeType: Add namespace for Apache SOAP type');
6157
+						$tt_prefix = 'ns' . rand(1000, 9999);
6158
+						$this->namespaces[$tt_prefix] = 'http://xml.apache.org/xml-soap';
6159
+						// force this to be added to usedNamespaces
6160
+						$tt_prefix = $this->getPrefixFromNamespace('http://xml.apache.org/xml-soap');
6161
+					}
6162
+					$contents = '';
6163
+					foreach ($value as $k => $v) {
6164
+						$this->debug("serializing map element: key $k, value $v");
6165
+						$contents .= '<item>';
6166
+						$contents .= $this->serialize_val($k, 'key', false, false, false, false, $use);
6167
+						$contents .= $this->serialize_val($v, 'value', false, false, false, false, $use);
6168
+						$contents .= '</item>';
6169
+					}
6170
+					if ($use == 'literal') {
6171
+						if ($forceType) {
6172
+							$xml = "<$name xsi:type=\"" . $tt_prefix . ":$uqType\">$contents</$name>";
6173
+						} else {
6174
+							$xml = "<$name>$contents</$name>";
6175
+						}
6176
+					} else {
6177
+						$xml = "<$name xsi:type=\"" . $tt_prefix . ":$uqType\"$encodingStyle>$contents</$name>";
6178
+					}
6179
+					$this->debug("in serializeType: returning: $xml");
6180
+					return $xml;
6181
+				}
6182
+				$this->debug('in serializeType: Apache SOAP type, but only support Map');
6183
+			}
6184
+		} else {
6185
+			// TODO: should the type be compared to types in XSD, and the namespace
6186
+			// set to XSD if the type matches?
6187
+			$this->debug("in serializeType: No namespace for type $type");
6188
+			$ns = '';
6189
+			$uqType = $type;
6190
+		}
6191
+		if (!$typeDef = $this->getTypeDef($uqType, $ns)) {
6192
+			$this->setError("$type ($uqType) is not a supported type.");
6193
+			$this->debug("in serializeType: $type ($uqType) is not a supported type.");
6194
+			return false;
6195
+		} else {
6196
+			$this->debug("in serializeType: found typeDef");
6197
+			$this->appendDebug('typeDef=' . $this->varDump($typeDef));
6198
+			if (substr($uqType, -1) == '^') {
6199
+				$uqType = substr($uqType, 0, -1);
6200
+			}
6201
+		}
6202
+		if (!isset($typeDef['phpType'])) {
6203
+			$this->setError("$type ($uqType) has no phpType.");
6204
+			$this->debug("in serializeType: $type ($uqType) has no phpType.");
6205
+			return false;
6206
+		}
6207
+		$phpType = $typeDef['phpType'];
6208
+		$this->debug("in serializeType: uqType: $uqType, ns: $ns, phptype: $phpType, arrayType: " . (isset($typeDef['arrayType']) ? $typeDef['arrayType'] : ''));
6209
+		// if php type == struct, map value to the <all> element names
6210
+		if ($phpType == 'struct') {
6211
+			if (isset($typeDef['typeClass']) && $typeDef['typeClass'] == 'element') {
6212
+				$elementName = $uqType;
6213
+				if (isset($typeDef['form']) && ($typeDef['form'] == 'qualified')) {
6214
+					$elementNS = " xmlns=\"$ns\"";
6215
+				} else {
6216
+					$elementNS = " xmlns=\"\"";
6217
+				}
6218
+			} else {
6219
+				$elementName = $name;
6220
+				if ($unqualified) {
6221
+					$elementNS = " xmlns=\"\"";
6222
+				} else {
6223
+					$elementNS = '';
6224
+				}
6225
+			}
6226
+			if (is_null($value)) {
6227
+				if ($use == 'literal') {
6228
+					// TODO: depends on minOccurs and nillable
6229
+					$xml = "<$elementName$elementNS/>";
6230
+				} else {
6231
+					$xml = "<$elementName$elementNS xsi:nil=\"true\" xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"/>";
6232
+				}
6233
+				$this->debug("in serializeType: returning: $xml");
6234
+				return $xml;
6235
+			}
6236
+			if (is_object($value)) {
6237
+				$value = get_object_vars($value);
6238
+			}
6239
+			if (is_array($value)) {
6240
+				$elementAttrs = $this->serializeComplexTypeAttributes($typeDef, $value, $ns, $uqType);
6241
+				if ($use == 'literal') {
6242
+					if ($forceType) {
6243
+						$xml = "<$elementName$elementNS$elementAttrs xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\">";
6244
+					} else {
6245
+						$xml = "<$elementName$elementNS$elementAttrs>";
6246
+					}
6247
+				} else {
6248
+					$xml = "<$elementName$elementNS$elementAttrs xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"$encodingStyle>";
6249
+				}
6250
+
6251
+				if (isset($typeDef['simpleContent']) && $typeDef['simpleContent'] == 'true') {
6252
+					if (isset($value['!'])) {
6253
+						$xml .= $value['!'];
6254
+						$this->debug("in serializeType: serialized simpleContent for type $type");
6255
+					} else {
6256
+						$this->debug("in serializeType: no simpleContent to serialize for type $type");
6257
+					}
6258
+				} else {
6259
+					// complexContent
6260
+					$xml .= $this->serializeComplexTypeElements($typeDef, $value, $ns, $uqType, $use, $encodingStyle);
6261
+				}
6262
+				$xml .= "</$elementName>";
6263
+			} else {
6264
+				$this->debug("in serializeType: phpType is struct, but value is not an array");
6265
+				$this->setError("phpType is struct, but value is not an array: see debug output for details");
6266
+			}
6267
+		} elseif ($phpType == 'array') {
6268
+			if (isset($typeDef['form']) && ($typeDef['form'] == 'qualified')) {
6269
+				$elementNS = " xmlns=\"$ns\"";
6270
+			} else {
6271
+				if ($unqualified) {
6272
+					$elementNS = " xmlns=\"\"";
6273
+				} else {
6274
+					$elementNS = '';
6275
+				}
6276
+			}
6277
+			if (is_null($value)) {
6278
+				if ($use == 'literal') {
6279
+					// TODO: depends on minOccurs
6280
+					$xml = "<$name$elementNS/>";
6281
+				} else {
6282
+					$xml = "<$name$elementNS xsi:nil=\"true\" xsi:type=\"" .
6283
+						$this->getPrefixFromNamespace('http://schemas.xmlsoap.org/soap/encoding/') .
6284
+						":Array\" " .
6285
+						$this->getPrefixFromNamespace('http://schemas.xmlsoap.org/soap/encoding/') .
6286
+						':arrayType="' .
6287
+						$this->getPrefixFromNamespace($this->getPrefix($typeDef['arrayType'])) .
6288
+						':' .
6289
+						$this->getLocalPart($typeDef['arrayType']) . "[0]\"/>";
6290
+				}
6291
+				$this->debug("in serializeType: returning: $xml");
6292
+				return $xml;
6293
+			}
6294
+			$cols = '';
6295
+			if (isset($typeDef['multidimensional'])) {
6296
+				$nv = array();
6297
+				foreach ($value as $v) {
6298
+					$cols = ',' . sizeof($v);
6299
+					$nv = array_merge($nv, $v);
6300
+				}
6301
+				$value = $nv;
6302
+			}
6303
+			if (is_array($value) && sizeof($value) >= 1) {
6304
+				$rows = sizeof($value);
6305
+				$contents = '';
6306
+				foreach ($value as $v) {
6307
+					//$this->debug breaks when serializing ArrayOfComplexType
6308
+					//Error: Object of class [COMPLEX-TYPE] could not be converted to string
6309
+					//$this->debug("serializing array element: $k, " . (is_array($v) ? "array" : $v) . " of type: $typeDef[arrayType]");
6310
+					//if (strpos($typeDef['arrayType'], ':') ) {
6311
+					if (!in_array($typeDef['arrayType'], $this->typemap['http://www.w3.org/2001/XMLSchema'])) {
6312
+						$contents .= $this->serializeType('item', $typeDef['arrayType'], $v, $use);
6313
+					} else {
6314
+						$contents .= $this->serialize_val($v, 'item', $typeDef['arrayType'], null, $this->XMLSchemaVersion, false, $use);
6315
+					}
6316
+				}
6317
+			} else {
6318
+				$rows = 0;
6319
+				$contents = null;
6320
+			}
6321
+			// TODO: for now, an empty value will be serialized as a zero element
6322
+			// array.  Revisit this when coding the handling of null/nil values.
6323
+			if ($use == 'literal') {
6324
+				$xml = "<$name$elementNS>"
6325
+					. $contents
6326
+					. "</$name>";
6327
+			} else {
6328
+				$xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace('http://schemas.xmlsoap.org/soap/encoding/') . ':Array" ' .
6329
+					$this->getPrefixFromNamespace('http://schemas.xmlsoap.org/soap/encoding/')
6330
+					. ':arrayType="'
6331
+					. $this->getPrefixFromNamespace($this->getPrefix($typeDef['arrayType']))
6332
+					. ":" . $this->getLocalPart($typeDef['arrayType']) . "[$rows$cols]\">"
6333
+					. $contents
6334
+					. "</$name>";
6335
+			}
6336
+		} elseif ($phpType == 'scalar') {
6337
+			if (isset($typeDef['form']) && ($typeDef['form'] == 'qualified')) {
6338
+				$elementNS = " xmlns=\"$ns\"";
6339
+			} else {
6340
+				if ($unqualified) {
6341
+					$elementNS = " xmlns=\"\"";
6342
+				} else {
6343
+					$elementNS = '';
6344
+				}
6345
+			}
6346
+			if ($use == 'literal') {
6347
+				if ($forceType) {
6348
+					$xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\">$value</$name>";
6349
+				} else {
6350
+					$xml = "<$name$elementNS>$value</$name>";
6351
+				}
6352
+			} else {
6353
+				$xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"$encodingStyle>$value</$name>";
6354
+			}
6355
+		}
6356
+		$this->debug("in serializeType: returning: $xml");
6357
+		return $xml;
6358
+	}
6359
+
6360
+	/**
6361
+	 * serializes the attributes for a complexType
6362
+	 *
6363
+	 * @param array $typeDef our internal representation of an XML schema type (or element)
6364
+	 * @param mixed $value a native PHP value (parameter value)
6365
+	 * @param string $ns the namespace of the type
6366
+	 * @param string $uqType the local part of the type
6367
+	 * @return string value serialized as an XML string
6368
+	 * @access private
6369
+	 */
6370
+	function serializeComplexTypeAttributes($typeDef, $value, $ns, $uqType)
6371
+	{
6372
+		$this->debug("serializeComplexTypeAttributes for XML Schema type $ns:$uqType");
6373
+		$xml = '';
6374
+		if (isset($typeDef['extensionBase'])) {
6375
+			$nsx = $this->getPrefix($typeDef['extensionBase']);
6376
+			$uqTypex = $this->getLocalPart($typeDef['extensionBase']);
6377
+			if ($this->getNamespaceFromPrefix($nsx)) {
6378
+				$nsx = $this->getNamespaceFromPrefix($nsx);
6379
+			}
6380
+			if ($typeDefx = $this->getTypeDef($uqTypex, $nsx)) {
6381
+				$this->debug("serialize attributes for extension base $nsx:$uqTypex");
6382
+				$xml .= $this->serializeComplexTypeAttributes($typeDefx, $value, $nsx, $uqTypex);
6383
+			} else {
6384
+				$this->debug("extension base $nsx:$uqTypex is not a supported type");
6385
+			}
6386
+		}
6387
+		if (isset($typeDef['attrs']) && is_array($typeDef['attrs'])) {
6388
+			$this->debug("serialize attributes for XML Schema type $ns:$uqType");
6389
+			if (is_array($value)) {
6390
+				$xvalue = $value;
6391
+			} elseif (is_object($value)) {
6392
+				$xvalue = get_object_vars($value);
6393
+			} else {
6394
+				$this->debug("value is neither an array nor an object for XML Schema type $ns:$uqType");
6395
+				$xvalue = array();
6396
+			}
6397
+			foreach ($typeDef['attrs'] as $aName => $attrs) {
6398
+				if (isset($xvalue['!' . $aName])) {
6399
+					$xname = '!' . $aName;
6400
+					$this->debug("value provided for attribute $aName with key $xname");
6401
+				} elseif (isset($xvalue[$aName])) {
6402
+					$xname = $aName;
6403
+					$this->debug("value provided for attribute $aName with key $xname");
6404
+				} elseif (isset($attrs['default'])) {
6405
+					$xname = '!' . $aName;
6406
+					$xvalue[$xname] = $attrs['default'];
6407
+					$this->debug('use default value of ' . $xvalue[$aName] . ' for attribute ' . $aName);
6408
+				} else {
6409
+					$xname = '';
6410
+					$this->debug("no value provided for attribute $aName");
6411
+				}
6412
+				if ($xname) {
6413
+					$xml .= " $aName=\"" . $this->expandEntities($xvalue[$xname]) . "\"";
6414
+				}
6415
+			}
6416
+		} else {
6417
+			$this->debug("no attributes to serialize for XML Schema type $ns:$uqType");
6418
+		}
6419
+		return $xml;
6420
+	}
6421
+
6422
+	/**
6423
+	 * serializes the elements for a complexType
6424
+	 *
6425
+	 * @param array $typeDef our internal representation of an XML schema type (or element)
6426
+	 * @param mixed $value a native PHP value (parameter value)
6427
+	 * @param string $ns the namespace of the type
6428
+	 * @param string $uqType the local part of the type
6429
+	 * @param string $use use for part (encoded|literal)
6430
+	 * @param string $encodingStyle SOAP encoding style for the value (if different than the enclosing style)
6431
+	 * @return string value serialized as an XML string
6432
+	 * @access private
6433
+	 */
6434
+	function serializeComplexTypeElements($typeDef, $value, $ns, $uqType, $use = 'encoded', $encodingStyle = false)
6435
+	{
6436
+		$this->debug("in serializeComplexTypeElements for XML Schema type $ns:$uqType");
6437
+		$xml = '';
6438
+		if (isset($typeDef['extensionBase'])) {
6439
+			$nsx = $this->getPrefix($typeDef['extensionBase']);
6440
+			$uqTypex = $this->getLocalPart($typeDef['extensionBase']);
6441
+			if ($this->getNamespaceFromPrefix($nsx)) {
6442
+				$nsx = $this->getNamespaceFromPrefix($nsx);
6443
+			}
6444
+			if ($typeDefx = $this->getTypeDef($uqTypex, $nsx)) {
6445
+				$this->debug("serialize elements for extension base $nsx:$uqTypex");
6446
+				$xml .= $this->serializeComplexTypeElements($typeDefx, $value, $nsx, $uqTypex, $use, $encodingStyle);
6447
+			} else {
6448
+				$this->debug("extension base $nsx:$uqTypex is not a supported type");
6449
+			}
6450
+		}
6451
+		if (isset($typeDef['elements']) && is_array($typeDef['elements'])) {
6452
+			$this->debug("in serializeComplexTypeElements, serialize elements for XML Schema type $ns:$uqType");
6453
+			if (is_array($value)) {
6454
+				$xvalue = $value;
6455
+			} elseif (is_object($value)) {
6456
+				$xvalue = get_object_vars($value);
6457
+			} else {
6458
+				$this->debug("value is neither an array nor an object for XML Schema type $ns:$uqType");
6459
+				$xvalue = array();
6460
+			}
6461
+			// toggle whether all elements are present - ideally should validate against schema
6462
+			if (count($typeDef['elements']) != count($xvalue)) {
6463
+				$optionals = true;
6464
+			}
6465
+			foreach ($typeDef['elements'] as $eName => $attrs) {
6466
+				if (!isset($xvalue[$eName])) {
6467
+					if (isset($attrs['default'])) {
6468
+						$xvalue[$eName] = $attrs['default'];
6469
+						$this->debug('use default value of ' . $xvalue[$eName] . ' for element ' . $eName);
6470
+					}
6471
+				}
6472
+				// if user took advantage of a minOccurs=0, then only serialize named parameters
6473
+				if (isset($optionals)
6474
+					&& (!isset($xvalue[$eName]))
6475
+					&& ((!isset($attrs['nillable'])) || $attrs['nillable'] != 'true')
6476
+				) {
6477
+					if (isset($attrs['minOccurs']) && $attrs['minOccurs'] <> '0') {
6478
+						$this->debug("apparent error: no value provided for element $eName with minOccurs=" . $attrs['minOccurs']);
6479
+					}
6480
+					// do nothing
6481
+					$this->debug("no value provided for complexType element $eName and element is not nillable, so serialize nothing");
6482
+				} else {
6483
+					// get value
6484
+					if (isset($xvalue[$eName])) {
6485
+						$v = $xvalue[$eName];
6486
+					} else {
6487
+						$v = null;
6488
+					}
6489
+					if (isset($attrs['form'])) {
6490
+						$unqualified = ($attrs['form'] == 'unqualified');
6491
+					} else {
6492
+						$unqualified = false;
6493
+					}
6494
+					if (isset($attrs['maxOccurs']) && ($attrs['maxOccurs'] == 'unbounded' || $attrs['maxOccurs'] > 1) && isset($v) && is_array($v) && $this->isArraySimpleOrStruct($v) == 'arraySimple') {
6495
+						$vv = $v;
6496
+						foreach ($vv as $v) {
6497
+							if (isset($attrs['type']) || isset($attrs['ref'])) {
6498
+								// serialize schema-defined type
6499
+								$xml .= $this->serializeType($eName, isset($attrs['type']) ? $attrs['type'] : $attrs['ref'], $v, $use, $encodingStyle, $unqualified);
6500
+							} else {
6501
+								// serialize generic type (can this ever really happen?)
6502
+								$this->debug("calling serialize_val() for $v, $eName, false, false, false, false, $use");
6503
+								$xml .= $this->serialize_val($v, $eName, false, false, false, false, $use);
6504
+							}
6505
+						}
6506
+					} else {
6507
+						if (!is_null ($v) || !isset($attrs['minOccurs']) || $attrs['minOccurs'] != '0')
6508
+						{
6509
+							if (is_null ($v) && isset($attrs['nillable']) && $attrs['nillable'] == 'true')
6510
+							{
6511
+								// TODO: serialize a nil correctly, but for now serialize schema-defined type
6512
+								$xml .= $this->serializeType ($eName,
6513
+															  isset($attrs['type']) ? $attrs['type'] : $attrs['ref'],
6514
+															  $v, $use, $encodingStyle, $unqualified);
6515
+							}
6516
+							elseif (isset($attrs['type']) || isset($attrs['ref']))
6517
+							{
6518
+								// serialize schema-defined type
6519
+								$xml .= $this->serializeType ($eName,
6520
+															  isset($attrs['type']) ? $attrs['type'] : $attrs['ref'],
6521
+															  $v, $use, $encodingStyle, $unqualified);
6522
+							}
6523
+							else
6524
+							{
6525
+								// serialize generic type (can this ever really happen?)
6526
+								$this->debug ("calling serialize_val() for $v, $eName, false, false, false, false, $use");
6527
+								$xml .= $this->serialize_val ($v, $eName, false, false, false, false, $use);
6528
+							}
6529
+						}
6530
+					}
6531
+				}
6532
+			}
6533
+		} else {
6534
+			$this->debug("no elements to serialize for XML Schema type $ns:$uqType");
6535
+		}
6536
+		return $xml;
6537
+	}
6538
+
6539
+	/**
6540
+	 * adds an XML Schema complex type to the WSDL types
6541
+	 *
6542
+	 * @param string $name
6543
+	 * @param string $typeClass (complexType|simpleType|attribute)
6544
+	 * @param string $phpType currently supported are array and struct (php assoc array)
6545
+	 * @param string $compositor (all|sequence|choice)
6546
+	 * @param string $restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
6547
+	 * @param array $elements e.g. array ( name => array(name=>'',type=>'') )
6548
+	 * @param array $attrs e.g. array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'xsd:string[]'))
6549
+	 * @param string $arrayType as namespace:name (xsd:string)
6550
+	 * @see nusoap_xmlschema
6551
+	 * @access public
6552
+	 */
6553
+	function addComplexType($name, $typeClass = 'complexType', $phpType = 'array', $compositor = '', $restrictionBase = '', $elements = array(), $attrs = array(), $arrayType = '')
6554
+	{
6555
+		if (count($elements) > 0) {
6556
+			$eElements = array();
6557
+			foreach ($elements as $n => $e) {
6558
+				// expand each element
6559
+				$ee = array();
6560
+				foreach ($e as $k => $v) {
6561
+					$k = strpos($k, ':') ? $this->expandQname($k) : $k;
6562
+					$v = strpos($v, ':') ? $this->expandQname($v) : $v;
6563
+					$ee[$k] = $v;
6564
+				}
6565
+				$eElements[$n] = $ee;
6566
+			}
6567
+			$elements = $eElements;
6568
+		}
4732 6569
 
4733
-/**
4734
- * parses a WSDL file, allows access to it's data, other utility methods.
4735
- * also builds WSDL structures programmatically.
4736
- *
4737
- * @author   Dietrich Ayala <[email protected]>
4738
- * @author   Scott Nichol <[email protected]>
4739
- * @version  $Id: nusoap.php,v 1.123 2010/04/26 20:15:08 snichol Exp $
4740
- * @access public
4741
- */
4742
-class wsdl extends nusoap_base
4743
-{
4744
-    // URL or filename of the root of this WSDL
4745
-    var $wsdl;
4746
-    // define internal arrays of bindings, ports, operations, messages, etc.
4747
-    var $schemas = array();
4748
-    var $currentSchema;
4749
-    var $message = array();
4750
-    var $complexTypes = array();
4751
-    var $messages = array();
4752
-    var $currentMessage;
4753
-    var $currentOperation;
4754
-    var $portTypes = array();
4755
-    var $currentPortType;
4756
-    var $bindings = array();
4757
-    var $currentBinding;
4758
-    var $ports = array();
4759
-    var $currentPort;
4760
-    var $opData = array();
4761
-    var $status = '';
4762
-    var $documentation = false;
4763
-    var $endpoint = '';
4764
-    // array of wsdl docs to import
4765
-    var $import = array();
4766
-    // parser vars
4767
-    var $parser;
4768
-    var $position = 0;
4769
-    var $depth = 0;
4770
-    var $depth_array = array();
4771
-    // for getting wsdl
4772
-    var $proxyhost = '';
4773
-    var $proxyport = '';
4774
-    var $proxyusername = '';
4775
-    var $proxypassword = '';
4776
-    var $timeout = 0;
4777
-    var $response_timeout = 30;
4778
-    var $curl_options = array();    // User-specified cURL options
4779
-    var $use_curl = false;            // whether to always try to use cURL
4780
-    // for HTTP authentication
4781
-    var $username = '';                // Username for HTTP authentication
4782
-    var $password = '';                // Password for HTTP authentication
4783
-    var $authtype = '';                // Type of HTTP authentication
4784
-    var $certRequest = array();        // Certificate for HTTP SSL authentication
4785
-
4786
-    /** @var mixed */
4787
-    var $currentPortOperation;
4788
-    /** @var string */
4789
-    var $opStatus;
4790
-    /** @var mixed */
4791
-    var $serviceName;
4792
-    var $wsdl_info;
4793
-
4794
-    /** @var string */
4795
-    var $schemaTargetNamespace;
4796
-
4797
-    /**
4798
-     * constructor
4799
-     *
4800
-     * @param string $wsdl WSDL document URL
4801
-     * @param string $proxyhost
4802
-     * @param string $proxyport
4803
-     * @param string $proxyusername
4804
-     * @param string $proxypassword
4805
-     * @param integer $timeout set the connection timeout
4806
-     * @param integer $response_timeout set the response timeout
4807
-     * @param array $curl_options user-specified cURL options
4808
-     * @param boolean $use_curl try to use cURL
4809
-     * @access public
4810
-     */
4811
-    function __construct($wsdl = '', $proxyhost = false, $proxyport = false, $proxyusername = false, $proxypassword = false, $timeout = 0, $response_timeout = 30, $curl_options = null, $use_curl = false)
4812
-    {
4813
-        parent::__construct();
4814
-        $this->debug("ctor wsdl=$wsdl timeout=$timeout response_timeout=$response_timeout");
4815
-        $this->proxyhost = $proxyhost;
4816
-        $this->proxyport = $proxyport;
4817
-        $this->proxyusername = $proxyusername;
4818
-        $this->proxypassword = $proxypassword;
4819
-        $this->timeout = $timeout;
4820
-        $this->response_timeout = $response_timeout;
4821
-        if (is_array($curl_options)) {
4822
-            $this->curl_options = $curl_options;
4823
-        }
4824
-        $this->use_curl = $use_curl;
4825
-        $this->fetchWSDL($wsdl);
4826
-    }
4827
-
4828
-    /**
4829
-     * fetches the WSDL document and parses it
4830
-     *
4831
-     * @access public
4832
-     */
4833
-    function fetchWSDL($wsdl)
4834
-    {
4835
-        $this->debug("parse and process WSDL path=$wsdl");
4836
-        $this->wsdl = $wsdl;
4837
-        // parse wsdl file
4838
-        if ($this->wsdl != "") {
4839
-            $this->parseWSDL($this->wsdl);
4840
-        }
4841
-        // imports
4842
-        // TODO: handle imports more properly, grabbing them in-line and nesting them
4843
-        $imported_urls = array();
4844
-        $imported = 1;
4845
-        while ($imported > 0) {
4846
-            $imported = 0;
4847
-            // Schema imports
4848
-            foreach ($this->schemas as $ns => $list) {
4849
-                foreach ($list as $xsKey => $xs) {
4850
-                    $wsdlparts = parse_url($this->wsdl);    // this is bogusly simple!
4851
-                    foreach ($xs->imports as $ns2 => $list2) {
4852
-                        for ($ii = 0; $ii < count($list2); $ii++) {
4853
-                            if (array_key_exists($ii, $list2) && (!isset($list2[$ii]['loaded']) || !$list2[$ii]['loaded'])) {
4854
-                                @$this->schemas[$ns][$xsKey]->imports[$ns2][$ii]['loaded'] = true;
4855
-                                $url = $list2[$ii]['location'];
4856
-                                if ($url != '') {
4857
-                                    $urlparts = parse_url($url);
4858
-                                    if (!isset($urlparts['host'])) {
4859
-                                        $url = $wsdlparts['scheme'] . '://' . $wsdlparts['host'] . (isset($wsdlparts['port']) ? ':' . $wsdlparts['port'] : '') .
4860
-                                            substr($wsdlparts['path'], 0, strrpos($wsdlparts['path'], '/') + 1) . $urlparts['path'];
4861
-                                    }
4862
-                                    if (!in_array($url, $imported_urls)) {
4863
-                                        $this->parseWSDL($url);
4864
-                                        $imported++;
4865
-                                        $imported_urls[] = $url;
4866
-                                    }
4867
-                                } else {
4868
-                                    $this->debug("Unexpected scenario: empty URL for unloaded import");
4869
-                                }
4870
-                            }
4871
-                        }
4872
-                    }
4873
-                }
4874
-            }
4875
-            // WSDL imports
4876
-            $wsdlparts = parse_url($this->wsdl);    // this is bogusly simple!
4877
-            foreach ($this->import as $ns => $list) {
4878
-                for ($ii = 0; $ii < count($list); $ii++) {
4879
-                    if (!$list[$ii]['loaded']) {
4880
-                        $this->import[$ns][$ii]['loaded'] = true;
4881
-                        $url = $list[$ii]['location'];
4882
-                        if ($url != '') {
4883
-                            $urlparts = parse_url($url);
4884
-                            if (!isset($urlparts['host'])) {
4885
-                                $url = $wsdlparts['scheme'] . '://' . $wsdlparts['host'] . (isset($wsdlparts['port']) ? ':' . $wsdlparts['port'] : '') .
4886
-                                    substr($wsdlparts['path'], 0, strrpos($wsdlparts['path'], '/') + 1) . $urlparts['path'];
4887
-                            }
4888
-                            if (!in_array($url, $imported_urls)) {
4889
-                                $this->parseWSDL($url);
4890
-                                $imported++;
4891
-                                $imported_urls[] = $url;
4892
-                            }
4893
-                        } else {
4894
-                            $this->debug("Unexpected scenario: empty URL for unloaded import");
4895
-                        }
4896
-                    }
4897
-                }
4898
-            }
4899
-        }
4900
-        // add new data to operation data
4901
-        foreach ($this->bindings as $binding => $bindingData) {
4902
-            if (isset($bindingData['operations']) && is_array($bindingData['operations'])) {
4903
-                foreach ($bindingData['operations'] as $operation => $data) {
4904
-                    $this->debug('post-parse data gathering for ' . $operation);
4905
-                    $this->bindings[$binding]['operations'][$operation]['input'] =
4906
-                        isset($this->bindings[$binding]['operations'][$operation]['input']) ?
4907
-                            array_merge($this->bindings[$binding]['operations'][$operation]['input'], $this->portTypes[$bindingData['portType']][$operation]['input']) :
4908
-                            $this->portTypes[$bindingData['portType']][$operation]['input'];
4909
-                    $this->bindings[$binding]['operations'][$operation]['output'] =
4910
-                        isset($this->bindings[$binding]['operations'][$operation]['output']) ?
4911
-                            array_merge($this->bindings[$binding]['operations'][$operation]['output'], $this->portTypes[$bindingData['portType']][$operation]['output']) :
4912
-                            $this->portTypes[$bindingData['portType']][$operation]['output'];
4913
-                    if (isset($this->messages[$this->bindings[$binding]['operations'][$operation]['input']['message']])) {
4914
-                        $this->bindings[$binding]['operations'][$operation]['input']['parts'] = $this->messages[$this->bindings[$binding]['operations'][$operation]['input']['message']];
4915
-                    }
4916
-                    if (isset($this->messages[$this->bindings[$binding]['operations'][$operation]['output']['message']])) {
4917
-                        $this->bindings[$binding]['operations'][$operation]['output']['parts'] = $this->messages[$this->bindings[$binding]['operations'][$operation]['output']['message']];
4918
-                    }
4919
-                    // Set operation style if necessary, but do not override one already provided
4920
-                    if (isset($bindingData['style']) && !isset($this->bindings[$binding]['operations'][$operation]['style'])) {
4921
-                        $this->bindings[$binding]['operations'][$operation]['style'] = $bindingData['style'];
4922
-                    }
4923
-                    $this->bindings[$binding]['operations'][$operation]['transport'] = isset($bindingData['transport']) ? $bindingData['transport'] : '';
4924
-                    $this->bindings[$binding]['operations'][$operation]['documentation'] = isset($this->portTypes[$bindingData['portType']][$operation]['documentation']) ? $this->portTypes[$bindingData['portType']][$operation]['documentation'] : '';
4925
-                    $this->bindings[$binding]['operations'][$operation]['endpoint'] = isset($bindingData['endpoint']) ? $bindingData['endpoint'] : '';
4926
-                }
4927
-            }
4928
-        }
4929
-    }
4930
-
4931
-    /**
4932
-     * parses the wsdl document
4933
-     *
4934
-     * @param string $wsdl path or URL
4935
-     * @access private
4936
-     */
4937
-    function parseWSDL($wsdl = '')
4938
-    {
4939
-        $this->debug("parse WSDL at path=$wsdl");
4940
-
4941
-        if ($wsdl == '') {
4942
-            $this->debug('no wsdl passed to parseWSDL()!!');
4943
-            $this->setError('no wsdl passed to parseWSDL()!!');
4944
-            return false;
4945
-        }
4946
-
4947
-        // parse $wsdl for url format
4948
-        $wsdl_props = parse_url($wsdl);
4949
-
4950
-        if (isset($wsdl_props['scheme']) && ($wsdl_props['scheme'] == 'http' || $wsdl_props['scheme'] == 'https')) {
4951
-            $this->debug('getting WSDL http(s) URL ' . $wsdl);
4952
-            // get wsdl
4953
-            $tr = new soap_transport_http($wsdl, $this->curl_options, $this->use_curl);
4954
-            $tr->request_method = 'GET';
4955
-            $tr->useSOAPAction = false;
4956
-            if ($this->proxyhost && $this->proxyport) {
4957
-                $tr->setProxy($this->proxyhost, $this->proxyport, $this->proxyusername, $this->proxypassword);
4958
-            }
4959
-            if ($this->authtype != '') {
4960
-                $tr->setCredentials($this->username, $this->password, $this->authtype, array(), $this->certRequest);
4961
-            }
4962
-            $tr->setEncoding();
4963
-            $wsdl_string = $tr->send('', $this->timeout, $this->response_timeout);
4964
-            //$this->debug("WSDL request\n" . $tr->outgoing_payload);
4965
-            //$this->debug("WSDL response\n" . $tr->incoming_payload);
4966
-            $this->appendDebug($tr->getDebug());
4967
-            // catch errors
4968
-            if ($err = $tr->getError()) {
4969
-                $errstr = 'Getting ' . $wsdl . ' - HTTP ERROR: ' . $err;
4970
-                $this->debug($errstr);
4971
-                $this->setError($errstr);
4972
-                unset($tr);
4973
-                return false;
4974
-            }
4975
-            unset($tr);
4976
-            $this->debug("got WSDL URL");
4977
-        } else {
4978
-            // $wsdl is not http(s), so treat it as a file URL or plain file path
4979
-            if (isset($wsdl_props['scheme']) && ($wsdl_props['scheme'] == 'file') && isset($wsdl_props['path'])) {
4980
-                $path = isset($wsdl_props['host']) ? ($wsdl_props['host'] . ':' . $wsdl_props['path']) : $wsdl_props['path'];
4981
-            } else {
4982
-                $path = $wsdl;
4983
-            }
4984
-            $this->debug('getting WSDL file ' . $path);
4985
-            if ($fp = @fopen($path, 'r')) {
4986
-                $wsdl_string = '';
4987
-                while ($data = fread($fp, 32768)) {
4988
-                    $wsdl_string .= $data;
4989
-                }
4990
-                fclose($fp);
4991
-            } else {
4992
-                $errstr = "Bad path to WSDL file $path";
4993
-                $this->debug($errstr);
4994
-                $this->setError($errstr);
4995
-                return false;
4996
-            }
4997
-        }
4998
-        $this->debug('Parse WSDL');
4999
-        // end new code added
5000
-        // Create an XML parser.
5001
-        $this->parser = xml_parser_create();
5002
-        // Set the options for parsing the XML data.
5003
-        // xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
5004
-        xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
5005
-        // Set the object for the parser.
5006
-        xml_set_object($this->parser, $this);
5007
-        // Set the element handlers for the parser.
5008
-        xml_set_element_handler($this->parser, 'start_element', 'end_element');
5009
-        xml_set_character_data_handler($this->parser, 'character_data');
5010
-        // Parse the XML file.
5011
-        if (!xml_parse($this->parser, $wsdl_string, true)) {
5012
-            // Display an error message.
5013
-            $errstr = sprintf(
5014
-                'XML error parsing WSDL from %s on line %d: %s',
5015
-                $wsdl,
5016
-                xml_get_current_line_number($this->parser),
5017
-                xml_error_string(xml_get_error_code($this->parser))
5018
-            );
5019
-            $this->debug($errstr);
5020
-            $this->debug("XML payload:\n" . $wsdl_string);
5021
-            $this->setError($errstr);
5022
-            xml_parser_free($this->parser);
5023
-            unset($this->parser);
5024
-            return false;
5025
-        }
5026
-        // free the parser
5027
-        xml_parser_free($this->parser);
5028
-        unset($this->parser);
5029
-        $this->debug('Parsing WSDL done');
5030
-        // catch wsdl parse errors
5031
-        if ($this->getError()) {
5032
-            return false;
5033
-        }
5034
-        return true;
5035
-    }
5036
-
5037
-    /**
5038
-     * start-element handler
5039
-     *
5040
-     * @param string $parser XML parser object
5041
-     * @param string $name element name
5042
-     * @param array $attrs associative array of attributes
5043
-     * @access private
5044
-     */
5045
-    function start_element($parser, $name, $attrs)
5046
-    {
5047
-        if ($this->status == 'schema') {
5048
-            $this->currentSchema->schemaStartElement($parser, $name, $attrs);
5049
-            $this->appendDebug($this->currentSchema->getDebug());
5050
-            $this->currentSchema->clearDebug();
5051
-        } elseif (preg_match('/schema$/', $name)) {
5052
-            $this->debug('Parsing WSDL schema');
5053
-            // $this->debug("startElement for $name ($attrs[name]). status = $this->status (".$this->getLocalPart($name).")");
5054
-            $this->status = 'schema';
5055
-            $this->currentSchema = new nusoap_xmlschema('', '', $this->namespaces);
5056
-            $this->currentSchema->schemaStartElement($parser, $name, $attrs);
5057
-            $this->appendDebug($this->currentSchema->getDebug());
5058
-            $this->currentSchema->clearDebug();
5059
-        } else {
5060
-            // position in the total number of elements, starting from 0
5061
-            $pos = $this->position++;
5062
-            $depth = $this->depth++;
5063
-            // set self as current value for this depth
5064
-            $this->depth_array[$depth] = $pos;
5065
-            $this->message[$pos] = array('cdata' => '');
5066
-            // process attributes
5067
-            if (count($attrs) > 0) {
5068
-                // register namespace declarations
5069
-                foreach ($attrs as $k => $v) {
5070
-                    if (preg_match('/^xmlns/', $k)) {
5071
-                        if ($ns_prefix = substr(strrchr($k, ':'), 1)) {
5072
-                            $this->namespaces[$ns_prefix] = $v;
5073
-                        } else {
5074
-                            $this->namespaces['ns' . (count($this->namespaces) + 1)] = $v;
5075
-                        }
5076
-                        if ($v == 'http://www.w3.org/2001/XMLSchema' || $v == 'http://www.w3.org/1999/XMLSchema' || $v == 'http://www.w3.org/2000/10/XMLSchema') {
5077
-                            $this->XMLSchemaVersion = $v;
5078
-                            $this->namespaces['xsi'] = $v . '-instance';
5079
-                        }
5080
-                    }
5081
-                }
5082
-                // expand each attribute prefix to its namespace
5083
-                $eAttrs = array ();
5084
-                foreach ($attrs as $k => $v) {
5085
-                    $k = strpos($k, ':') ? $this->expandQname($k) : $k;
5086
-                    if ($k != 'location' && $k != 'soapAction' && $k != 'namespace') {
5087
-                        $v = strpos($v, ':') ? $this->expandQname($v) : $v;
5088
-                    }
5089
-                    $eAttrs[$k] = $v;
5090
-                }
5091
-                $attrs = $eAttrs;
5092
-            } else {
5093
-                $attrs = array();
5094
-            }
5095
-		// Set default prefix and namespace
5096
-		// to prevent error Undefined variable $prefix and $namespace if (preg_match('/:/', $name)) return 0 or FALSE
5097
-		$prefix = '';
5098
-		$namespace = '';
5099
-            // get element prefix, namespace and name
5100
-            if (preg_match('/:/', $name)) {
5101
-                // get ns prefix
5102
-                $prefix = substr($name, 0, strpos($name, ':'));
5103
-                // get ns
5104
-                $namespace = isset($this->namespaces[$prefix]) ? $this->namespaces[$prefix] : '';
5105
-                // get unqualified name
5106
-                $name = substr(strstr($name, ':'), 1);
5107
-            }
5108
-            // process attributes, expanding any prefixes to namespaces
5109
-            // find status, register data
5110
-            switch ($this->status) {
5111
-                case 'message':
5112
-                    if ($name == 'part') {
5113
-                        if (isset($attrs['type'])) {
5114
-                            $this->debug("msg " . $this->currentMessage . ": found part (with type) $attrs[name]: " . implode(',', $attrs));
5115
-                            $this->messages[$this->currentMessage][$attrs['name']] = $attrs['type'];
5116
-                        }
5117
-                        if (isset($attrs['element'])) {
5118
-                            $this->debug("msg " . $this->currentMessage . ": found part (with element) $attrs[name]: " . implode(',', $attrs));
5119
-                            $this->messages[$this->currentMessage][$attrs['name']] = $attrs['element'] . '^';
5120
-                        }
5121
-                    }
5122
-                    break;
5123
-                case 'portType':
5124
-                    switch ($name) {
5125
-                        case 'operation':
5126
-                            $this->currentPortOperation = $attrs['name'];
5127
-                            $this->debug("portType $this->currentPortType operation: $this->currentPortOperation");
5128
-                            if (isset($attrs['parameterOrder'])) {
5129
-                                $this->portTypes[$this->currentPortType][$attrs['name']]['parameterOrder'] = $attrs['parameterOrder'];
5130
-                            }
5131
-                            break;
5132
-                        case 'documentation':
5133
-                            $this->documentation = true;
5134
-                            break;
5135
-                        // merge input/output data
5136
-                        default:
5137
-                            $m = isset($attrs['message']) ? $this->getLocalPart($attrs['message']) : '';
5138
-                            $this->portTypes[$this->currentPortType][$this->currentPortOperation][$name]['message'] = $m;
5139
-                            break;
5140
-                    }
5141
-                    break;
5142
-                case 'binding':
5143
-                    switch ($name) {
5144
-                        case 'binding':
5145
-                            // get ns prefix
5146
-                            if (isset($attrs['style'])) {
5147
-                                $this->bindings[$this->currentBinding]['prefix'] = $prefix;
5148
-                            }
5149
-                            $this->bindings[$this->currentBinding] = array_merge($this->bindings[$this->currentBinding], $attrs);
5150
-                            break;
5151
-                        case 'header':
5152
-                            $this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus]['headers'][] = $attrs;
5153
-                            break;
5154
-                        case 'operation':
5155
-                            if (isset($attrs['soapAction'])) {
5156
-                                $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['soapAction'] = $attrs['soapAction'];
5157
-                            }
5158
-                            if (isset($attrs['style'])) {
5159
-                                $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['style'] = $attrs['style'];
5160
-                            }
5161
-                            if (isset($attrs['name'])) {
5162
-                                $this->currentOperation = $attrs['name'];
5163
-                                $this->debug("current binding operation: $this->currentOperation");
5164
-                                $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['name'] = $attrs['name'];
5165
-                                $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['binding'] = $this->currentBinding;
5166
-                                $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['endpoint'] = isset($this->bindings[$this->currentBinding]['endpoint']) ? $this->bindings[$this->currentBinding]['endpoint'] : '';
5167
-                            }
5168
-                            break;
5169
-                        case 'input':
5170
-                            $this->opStatus = 'input';
5171
-                            break;
5172
-                        case 'output':
5173
-                            $this->opStatus = 'output';
5174
-                            break;
5175
-                        case 'body':
5176
-                            if (isset($this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus])) {
5177
-                                $this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus] = array_merge($this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus], $attrs);
5178
-                            } else {
5179
-                                $this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus] = $attrs;
5180
-                            }
5181
-                            break;
5182
-                    }
5183
-                    break;
5184
-                case 'service':
5185
-                    switch ($name) {
5186
-                        case 'port':
5187
-                            $this->currentPort = $attrs['name'];
5188
-                            $this->debug('current port: ' . $this->currentPort);
5189
-                            $this->ports[$this->currentPort]['binding'] = $this->getLocalPart($attrs['binding']);
5190
-
5191
-                            break;
5192
-                        case 'address':
5193
-                            $this->ports[$this->currentPort]['location'] = $attrs['location'];
5194
-                            $this->ports[$this->currentPort]['bindingType'] = $namespace;
5195
-                            $this->bindings[$this->ports[$this->currentPort]['binding']]['bindingType'] = $namespace;
5196
-                            $this->bindings[$this->ports[$this->currentPort]['binding']]['endpoint'] = $attrs['location'];
5197
-                            break;
5198
-                    }
5199
-                    break;
5200
-            }
5201
-            // set status
5202
-            switch ($name) {
5203
-                case 'import':
5204
-                    if (isset($attrs['location'])) {
5205
-                        $this->import[$attrs['namespace']][] = array('location' => $attrs['location'], 'loaded' => false);
5206
-                        $this->debug('parsing import ' . $attrs['namespace'] . ' - ' . $attrs['location'] . ' (' . count($this->import[$attrs['namespace']]) . ')');
5207
-                    } else {
5208
-                        $this->import[$attrs['namespace']][] = array('location' => '', 'loaded' => true);
5209
-                        if (!$this->getPrefixFromNamespace($attrs['namespace'])) {
5210
-                            $this->namespaces['ns' . (count($this->namespaces) + 1)] = $attrs['namespace'];
5211
-                        }
5212
-                        $this->debug('parsing import ' . $attrs['namespace'] . ' - [no location] (' . count($this->import[$attrs['namespace']]) . ')');
5213
-                    }
5214
-                    break;
5215
-                //wait for schema
5216
-                //case 'types':
5217
-                //	$this->status = 'schema';
5218
-                //	break;
5219
-                case 'message':
5220
-                    $this->status = 'message';
5221
-                    $this->messages[$attrs['name']] = array();
5222
-                    $this->currentMessage = $attrs['name'];
5223
-                    break;
5224
-                case 'portType':
5225
-                    $this->status = 'portType';
5226
-                    $this->portTypes[$attrs['name']] = array();
5227
-                    $this->currentPortType = $attrs['name'];
5228
-                    break;
5229
-                case "binding":
5230
-                    if (isset($attrs['name'])) {
5231
-                        // get binding name
5232
-                        if (strpos($attrs['name'], ':')) {
5233
-                            $this->currentBinding = $this->getLocalPart($attrs['name']);
5234
-                        } else {
5235
-                            $this->currentBinding = $attrs['name'];
5236
-                        }
5237
-                        $this->status = 'binding';
5238
-                        $this->bindings[$this->currentBinding]['portType'] = $this->getLocalPart($attrs['type']);
5239
-                        $this->debug("current binding: $this->currentBinding of portType: " . $attrs['type']);
5240
-                    }
5241
-                    break;
5242
-                case 'service':
5243
-                    $this->serviceName = $attrs['name'];
5244
-                    $this->status = 'service';
5245
-                    $this->debug('current service: ' . $this->serviceName);
5246
-                    break;
5247
-                case 'definitions':
5248
-                    foreach ($attrs as $name => $value) {
5249
-                        $this->wsdl_info[$name] = $value;
5250
-                    }
5251
-                    break;
5252
-            }
5253
-        }
5254
-    }
5255
-
5256
-    /**
5257
-     * end-element handler
5258
-     *
5259
-     * @param string $parser XML parser object
5260
-     * @param string $name element name
5261
-     * @access private
5262
-     */
5263
-    function end_element($parser, $name)
5264
-    {
5265
-        // unset schema status
5266
-        if (/*preg_match('/types$/', $name) ||*/
5267
-        preg_match('/schema$/', $name)
5268
-        ) {
5269
-            $this->status = "";
5270
-            $this->appendDebug($this->currentSchema->getDebug());
5271
-            $this->currentSchema->clearDebug();
5272
-            $this->schemas[$this->currentSchema->schemaTargetNamespace][] = $this->currentSchema;
5273
-            $this->debug('Parsing WSDL schema done');
5274
-        }
5275
-        if ($this->status == 'schema') {
5276
-            $this->currentSchema->schemaEndElement($parser, $name);
5277
-        } else {
5278
-            // bring depth down a notch
5279
-            $this->depth--;
5280
-        }
5281
-        // end documentation
5282
-        if ($this->documentation) {
5283
-            //TODO: track the node to which documentation should be assigned; it can be a part, message, etc.
5284
-            //$this->portTypes[$this->currentPortType][$this->currentPortOperation]['documentation'] = $this->documentation;
5285
-            $this->documentation = false;
5286
-        }
5287
-    }
5288
-
5289
-    /**
5290
-     * element content handler
5291
-     *
5292
-     * @param string $parser XML parser object
5293
-     * @param string $data element content
5294
-     * @access private
5295
-     */
5296
-    function character_data($parser, $data)
5297
-    {
5298
-        $pos = isset($this->depth_array[$this->depth]) ? $this->depth_array[$this->depth] : 0;
5299
-        if (isset($this->message[$pos]['cdata'])) {
5300
-            $this->message[$pos]['cdata'] .= $data;
5301
-        }
5302
-        if ($this->documentation) {
5303
-            $this->documentation .= $data;
5304
-        }
5305
-    }
5306
-
5307
-    /**
5308
-     * if authenticating, set user credentials here
5309
-     *
5310
-     * @param    string $username
5311
-     * @param    string $password
5312
-     * @param    string $authtype (basic|digest|certificate|ntlm)
5313
-     * @param    array $certRequest (keys must be cainfofile (optional), sslcertfile, sslkeyfile, passphrase, certpassword (optional), verifypeer (optional), verifyhost (optional): see corresponding options in cURL docs)
5314
-     * @access   public
5315
-     */
5316
-    function setCredentials($username, $password, $authtype = 'basic', $certRequest = array())
5317
-    {
5318
-        $this->debug("setCredentials username=$username authtype=$authtype certRequest=");
5319
-        $this->appendDebug($this->varDump($certRequest));
5320
-        $this->username = $username;
5321
-        $this->password = $password;
5322
-        $this->authtype = $authtype;
5323
-        $this->certRequest = $certRequest;
5324
-    }
5325
-
5326
-    function getBindingData($binding)
5327
-    {
5328
-        if (is_array($this->bindings[$binding])) {
5329
-            return $this->bindings[$binding];
5330
-        }
5331
-        return false;
5332
-    }
5333
-
5334
-    /**
5335
-     * returns an assoc array of operation names => operation data
5336
-     *
5337
-     * @param string $portName WSDL port name
5338
-     * @param string $bindingType eg: soap, smtp, dime (only soap and soap12 are currently supported)
5339
-     * @return array
5340
-     * @access public
5341
-     */
5342
-    function getOperations($portName = '', $bindingType = 'soap')
5343
-    {
5344
-        $ops = array();
5345
-        if ($bindingType == 'soap') {
5346
-            $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap/';
5347
-        } elseif ($bindingType == 'soap12') {
5348
-            $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap12/';
5349
-        } else {
5350
-            $this->debug("getOperations bindingType $bindingType may not be supported");
5351
-        }
5352
-        $this->debug("getOperations for port '$portName' bindingType $bindingType");
5353
-        // loop thru ports
5354
-        foreach ($this->ports as $port => $portData) {
5355
-            $this->debug("getOperations checking port $port bindingType " . $portData['bindingType']);
5356
-            if ($portName == '' || $port == $portName) {
5357
-                // binding type of port matches parameter
5358
-                if ($portData['bindingType'] == $bindingType) {
5359
-                    $this->debug("getOperations found port $port bindingType $bindingType");
5360
-                    //$this->debug("port data: " . $this->varDump($portData));
5361
-                    //$this->debug("bindings: " . $this->varDump($this->bindings[ $portData['binding'] ]));
5362
-                    // merge bindings
5363
-                    if (isset($this->bindings[$portData['binding']]['operations'])) {
5364
-                        $ops = array_merge($ops, $this->bindings[$portData['binding']]['operations']);
5365
-                    }
5366
-                }
5367
-            }
5368
-        }
5369
-        if (count($ops) == 0) {
5370
-            $this->debug("getOperations found no operations for port '$portName' bindingType $bindingType");
5371
-        }
5372
-        return $ops;
5373
-    }
5374
-
5375
-    /**
5376
-     * returns an associative array of data necessary for calling an operation
5377
-     *
5378
-     * @param string $operation name of operation
5379
-     * @param string $bindingType type of binding eg: soap, soap12
5380
-     * @return array
5381
-     * @access public
5382
-     */
5383
-    function getOperationData($operation, $bindingType = 'soap')
5384
-    {
5385
-        if ($bindingType == 'soap') {
5386
-            $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap/';
5387
-        } elseif ($bindingType == 'soap12') {
5388
-            $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap12/';
5389
-        }
5390
-        // loop thru ports
5391
-        foreach ($this->ports as $portData) {
5392
-            // binding type of port matches parameter
5393
-            if ($portData['bindingType'] == $bindingType) {
5394
-                // get binding
5395
-                //foreach($this->bindings[ $portData['binding'] ]['operations'] as $bOperation => $opData) {
5396
-                // note that we could/should also check the namespace here
5397
-                if (in_array ($operation, array_keys ($this->bindings[$portData['binding']]['operations'])))
5398
-                {
5399
-                    return $this->bindings[$portData['binding']]['operations'][$operation];
5400
-                }
5401
-            }
5402
-        }
5403
-        return array ();
5404
-    }
5405
-
5406
-    /**
5407
-     * returns an associative array of data necessary for calling an operation
5408
-     *
5409
-     * @param string $soapAction soapAction for operation
5410
-     * @param string $bindingType type of binding eg: soap, soap12
5411
-     * @return array
5412
-     * @access public
5413
-     */
5414
-    function getOperationDataForSoapAction($soapAction, $bindingType = 'soap')
5415
-    {
5416
-        if ($bindingType == 'soap') {
5417
-            $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap/';
5418
-        } elseif ($bindingType == 'soap12') {
5419
-            $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap12/';
5420
-        }
5421
-        // loop thru ports
5422
-        foreach ($this->ports as $portData) {
5423
-            // binding type of port matches parameter
5424
-            if ($portData['bindingType'] == $bindingType) {
5425
-                // loop through operations for the binding
5426
-                foreach ($this->bindings[$portData['binding']]['operations'] as $opData) {
5427
-                    if ($opData['soapAction'] == $soapAction) {
5428
-                        return $opData;
5429
-                    }
5430
-                }
5431
-            }
5432
-        }
5433
-        return array ();
5434
-    }
5435
-
5436
-    /**
5437
-     * returns an array of information about a given type
5438
-     * returns false if no type exists by the given name
5439
-     *     typeDef = array(
5440
-     *     'elements' => array(), // refs to elements array
5441
-     *    'restrictionBase' => '',
5442
-     *    'phpType' => '',
5443
-     *    'order' => '(sequence|all)',
5444
-     *    'attrs' => array() // refs to attributes array
5445
-     *    )
5446
-     *
5447
-     * @param string $type the type
5448
-     * @param string $ns namespace (not prefix) of the type
5449
-     * @return false
5450
-     * @access public
5451
-     * @see nusoap_xmlschema
5452
-     */
5453
-    function getTypeDef($type, $ns)
5454
-    {
5455
-        $this->debug("in getTypeDef: type=$type, ns=$ns");
5456
-        if ((!$ns) && isset($this->namespaces['tns'])) {
5457
-            $ns = $this->namespaces['tns'];
5458
-            $this->debug("in getTypeDef: type namespace forced to $ns");
5459
-        }
5460
-        if (!isset($this->schemas[$ns])) {
5461
-            foreach ($this->schemas as $ns0 => $schema0) {
5462
-                if (strcasecmp($ns, $ns0) == 0) {
5463
-                    $this->debug("in getTypeDef: replacing schema namespace $ns with $ns0");
5464
-                    $ns = $ns0;
5465
-                    break;
5466
-                }
5467
-            }
5468
-        }
5469
-        if (isset($this->schemas[$ns])) {
5470
-            $this->debug("in getTypeDef: have schema for namespace $ns");
5471
-            for ($i = 0; $i < count($this->schemas[$ns]); $i++) {
5472
-                $xs = &$this->schemas[$ns][$i];
5473
-                $t = $xs->getTypeDef($type);
5474
-                $this->appendDebug($xs->getDebug());
5475
-                $xs->clearDebug();
5476
-                if ($t) {
5477
-                    $this->debug("in getTypeDef: found type $type");
5478
-                    if (!isset($t['phpType'])) {
5479
-                        // get info for type to tack onto the element
5480
-                        $uqType = substr($t['type'], strrpos($t['type'], ':') + 1);
5481
-                        $ns = substr($t['type'], 0, strrpos($t['type'], ':'));
5482
-                        $etype = $this->getTypeDef($uqType, $ns);
5483
-                        if ($etype) {
5484
-                            $this->debug("found type for [element] $type:");
5485
-                            $this->debug($this->varDump($etype));
5486
-                            if (isset($etype['phpType'])) {
5487
-                                $t['phpType'] = $etype['phpType'];
5488
-                            }
5489
-                            if (isset($etype['elements'])) {
5490
-                                $t['elements'] = $etype['elements'];
5491
-                            }
5492
-                            if (isset($etype['attrs'])) {
5493
-                                $t['attrs'] = $etype['attrs'];
5494
-                            }
5495
-                        } else {
5496
-                            $this->debug("did not find type for [element] $type");
5497
-                        }
5498
-                    }
5499
-                    return $t;
5500
-                }
5501
-            }
5502
-            $this->debug("in getTypeDef: did not find type $type");
5503
-        } else {
5504
-            $this->debug("in getTypeDef: do not have schema for namespace $ns");
5505
-        }
5506
-        return false;
5507
-    }
5508
-
5509
-    /**
5510
-     * prints html description of services
5511
-     *
5512
-     * @access private
5513
-     */
5514
-    function webDescription()
5515
-    {
5516
-        global $HTTP_SERVER_VARS;
5517
-
5518
-        if (isset($_SERVER)) {
5519
-            $PHP_SELF = $_SERVER['PHP_SELF'];
5520
-        } elseif (isset($HTTP_SERVER_VARS)) {
5521
-            $PHP_SELF = $HTTP_SERVER_VARS['PHP_SELF'];
5522
-        } else {
5523
-            $this->setError("Neither _SERVER nor HTTP_SERVER_VARS is available");
5524
-            $PHP_SELF = '';
5525
-        }
5526
-
5527
-        $b = '
5528
-		<html><head><title>NuSOAP: ' . $this->serviceName . '</title>
5529
-		<style type="text/css">
5530
-		    body    { font-family: arial; color: #000000; background-color: #ffffff; margin: 0px 0px 0px 0px; }
5531
-		    p       { font-family: arial; color: #000000; margin-top: 0px; margin-bottom: 12px; }
5532
-		    pre { background-color: silver; padding: 5px; font-family: Courier New; font-size: x-small; color: #000000;}
5533
-		    ul      { margin-top: 10px; margin-left: 20px; }
5534
-		    li      { list-style-type: none; margin-top: 10px; color: #000000; }
5535
-		    .content{
5536
-			margin-left: 0px; padding-bottom: 2em; }
5537
-		    .nav {
5538
-			padding-top: 10px; padding-bottom: 10px; padding-left: 15px; font-size: .70em;
5539
-			margin-top: 10px; margin-left: 0px; color: #000000;
5540
-			background-color: #ccccff; width: 20%; margin-left: 20px; margin-top: 20px; }
5541
-		    .title {
5542
-			font-family: arial; font-size: 26px; color: #ffffff;
5543
-			background-color: #999999; width: 100%;
5544
-			margin-left: 0px; margin-right: 0px;
5545
-			padding-top: 10px; padding-bottom: 10px;}
5546
-		    .hidden {
5547
-			position: absolute; visibility: hidden; z-index: 200; left: 250px; top: 100px;
5548
-			font-family: arial; overflow: hidden; width: 600;
5549
-			padding: 20px; font-size: 10px; background-color: #999999;
5550
-			layer-background-color:#FFFFFF; }
5551
-		    a,a:active  { color: charcoal; font-weight: bold; }
5552
-		    a:visited   { color: #666666; font-weight: bold; }
5553
-		    a:hover     { color: cc3300; font-weight: bold; }
5554
-		</style>
5555
-		<script language="JavaScript" type="text/javascript">
5556
-		<!--
5557
-		// POP-UP CAPTIONS...
5558
-		function lib_bwcheck(){ //Browsercheck (needed)
5559
-		    this.ver=navigator.appVersion
5560
-		    this.agent=navigator.userAgent
5561
-		    this.dom=document.getElementById?1:0
5562
-		    this.opera5=this.agent.indexOf("Opera 5")>-1
5563
-		    this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0;
5564
-		    this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
5565
-		    this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
5566
-		    this.ie=this.ie4||this.ie5||this.ie6
5567
-		    this.mac=this.agent.indexOf("Mac")>-1
5568
-		    this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0;
5569
-		    this.ns4=(document.layers && !this.dom)?1:0;
5570
-		    this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
5571
-		    return this
6570
+		if (is_array($attrs) && count($attrs) > 0) {
6571
+			$eAttrs = array ();
6572
+			foreach ($attrs as $n => $a) {
6573
+				$aa = array ();
6574
+				// expand each attribute
6575
+				foreach ($a as $k => $v) {
6576
+					$k = strpos($k, ':') ? $this->expandQname($k) : $k;
6577
+					$v = strpos($v, ':') ? $this->expandQname($v) : $v;
6578
+					$aa[$k] = $v;
6579
+				}
6580
+				$eAttrs[$n] = $aa;
6581
+			}
6582
+			$attrs = $eAttrs;
5572 6583
 		}
5573
-		var bw = new lib_bwcheck()
5574
-		//Makes crossbrowser object.
5575
-		function makeObj(obj){
5576
-		    this.evnt=bw.dom? document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?document.layers[obj]:0;
5577
-		    if(!this.evnt) return false
5578
-		    this.css=bw.dom||bw.ie4?this.evnt.style:bw.ns4?this.evnt:0;
5579
-		    this.wref=bw.dom||bw.ie4?this.evnt:bw.ns4?this.css.document:0;
5580
-		    this.writeIt=b_writeIt;
5581
-		    return this
6584
+
6585
+		$restrictionBase = strpos($restrictionBase, ':') ? $this->expandQname($restrictionBase) : $restrictionBase;
6586
+		$arrayType = strpos($arrayType, ':') ? $this->expandQname($arrayType) : $arrayType;
6587
+
6588
+		$typens = isset($this->namespaces['types']) ? $this->namespaces['types'] : $this->namespaces['tns'];
6589
+		$this->schemas[$typens][0]->addComplexType($name, $typeClass, $phpType, $compositor, $restrictionBase, $elements, $attrs, $arrayType);
6590
+	}
6591
+
6592
+	/**
6593
+	 * adds an XML Schema simple type to the WSDL types
6594
+	 *
6595
+	 * @param string $name
6596
+	 * @param string $restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
6597
+	 * @param string $typeClass (should always be simpleType)
6598
+	 * @param string $phpType (should always be scalar)
6599
+	 * @param array $enumeration array of values
6600
+	 * @see nusoap_xmlschema
6601
+	 * @access public
6602
+	 */
6603
+	function addSimpleType($name, $restrictionBase = '', $typeClass = 'simpleType', $phpType = 'scalar', $enumeration = array())
6604
+	{
6605
+		$restrictionBase = strpos($restrictionBase, ':') ? $this->expandQname($restrictionBase) : $restrictionBase;
6606
+
6607
+		$typens = isset($this->namespaces['types']) ? $this->namespaces['types'] : $this->namespaces['tns'];
6608
+		$this->schemas[$typens][0]->addSimpleType($name, $restrictionBase, $typeClass, $phpType, $enumeration);
6609
+	}
6610
+
6611
+	/**
6612
+	 * adds an element to the WSDL types
6613
+	 *
6614
+	 * @param array $attrs attributes that must include name and type
6615
+	 * @see nusoap_xmlschema
6616
+	 * @access public
6617
+	 */
6618
+	function addElement($attrs)
6619
+	{
6620
+		$typens = isset($this->namespaces['types']) ? $this->namespaces['types'] : $this->namespaces['tns'];
6621
+		$this->schemas[$typens][0]->addElement($attrs);
6622
+	}
6623
+
6624
+	/**
6625
+	 * register an operation with the server
6626
+	 *
6627
+	 * @param string $name operation (method) name
6628
+	 * @param array $in assoc array of input values: key = param name, value = param type
6629
+	 * @param array $out assoc array of output values: key = param name, value = param type
6630
+	 * @param string $namespace optional The namespace for the operation
6631
+	 * @param string $soapaction optional The soapaction for the operation
6632
+	 * @param string $style (rpc|document) optional The style for the operation Note: when 'document' is specified, parameter and return wrappers are created for you automatically
6633
+	 * @param string $use (encoded|literal) optional The use for the parameters (cannot mix right now)
6634
+	 * @param string $documentation optional The description to include in the WSDL
6635
+	 * @param string $encodingStyle optional (usually 'http://schemas.xmlsoap.org/soap/encoding/' for encoded)
6636
+	 * @param string $customResponseTagName optional Name of the outgoing response
6637
+	 * @access public
6638
+	 */
6639
+	function addOperation($name, $in = false, $out = false, $namespace = false, $soapaction = false, $style = 'rpc', $use = 'encoded', $documentation = '', $encodingStyle = '', $customResponseTagName = '')
6640
+	{
6641
+		if ($use == 'encoded' && $encodingStyle == '') {
6642
+			$encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/';
5582 6643
 		}
5583
-		// A unit of measure that will be added when setting the position of a layer.
5584
-		//var px = bw.ns4||window.opera?"":"px";
5585
-		function b_writeIt(text){
5586
-		    if (bw.ns4){this.wref.write(text);this.wref.close()}
5587
-		    else this.wref.innerHTML = text
6644
+
6645
+		if ($style == 'document') {
6646
+			$elements = array();
6647
+			foreach ($in as $n => $t) {
6648
+				$elements[$n] = array('name' => $n, 'type' => $t, 'form' => 'unqualified');
6649
+			}
6650
+			$this->addComplexType($name . 'RequestType', 'complexType', 'struct', 'all', '', $elements);
6651
+			$this->addElement(array('name' => $name, 'type' => $name . 'RequestType'));
6652
+			$in = array('parameters' => 'tns:' . $name . '^');
6653
+
6654
+			$elements = array();
6655
+			foreach ($out as $n => $t) {
6656
+				$elements[$n] = array('name' => $n, 'type' => $t, 'form' => 'unqualified');
6657
+			}
6658
+			$this->addComplexType($name . 'ResponseType', 'complexType', 'struct', 'all', '', $elements);
6659
+			$this->addElement(array('name' => $customResponseTagName, 'type' => $name . 'ResponseType', 'form' => 'qualified'));
6660
+			$out = array('parameters' => 'tns:' . $customResponseTagName . '^');
5588 6661
 		}
5589
-		//Shows the messages
5590
-		var oDesc;
5591
-		function popup(divid){
5592
-		    if(oDesc = new makeObj(divid)){
5593
-			oDesc.css.visibility = "visible"
5594
-		    }
6662
+
6663
+		// get binding
6664
+		$this->bindings[$this->serviceName . 'Binding']['operations'][$name] =
6665
+			array(
6666
+				'name' => $name,
6667
+				'binding' => $this->serviceName . 'Binding',
6668
+				'endpoint' => $this->endpoint,
6669
+				'soapAction' => $soapaction,
6670
+				'style' => $style,
6671
+				'input' => array(
6672
+					'use' => $use,
6673
+					'namespace' => $namespace,
6674
+					'encodingStyle' => $encodingStyle,
6675
+					'message' => $name,
6676
+					'parts' => $in),
6677
+				'output' => array(
6678
+					'use' => $use,
6679
+					'namespace' => $namespace,
6680
+					'encodingStyle' => $encodingStyle,
6681
+					'message' => $customResponseTagName,
6682
+					'parts' => $out),
6683
+				'namespace' => $namespace,
6684
+				'transport' => 'http://schemas.xmlsoap.org/soap/http',
6685
+				'documentation' => $documentation);
6686
+		// add portTypes
6687
+		// add messages
6688
+		if ($in) {
6689
+			foreach ($in as $pName => $pType) {
6690
+				if (strpos($pType, ':')) {
6691
+					$pType = $this->getNamespaceFromPrefix($this->getPrefix($pType)) . ":" . $this->getLocalPart($pType);
6692
+				}
6693
+				$this->messages[$name][$pName] = $pType;
6694
+			}
6695
+		} else {
6696
+			$this->messages[$name] = '0';
5595 6697
 		}
5596
-		function popout(){ // Hides message
5597
-		    if(oDesc) oDesc.css.visibility = "hidden"
6698
+		if ($out) {
6699
+			foreach ($out as $pName => $pType) {
6700
+				if (strpos($pType, ':')) {
6701
+					$pType = $this->getNamespaceFromPrefix($this->getPrefix($pType)) . ":" . $this->getLocalPart($pType);
6702
+				}
6703
+				$this->messages[$customResponseTagName][$pName] = $pType;
6704
+			}
6705
+		} else {
6706
+			$this->messages[$customResponseTagName] = '0';
5598 6707
 		}
5599
-		//-->
5600
-		</script>
5601
-		</head>
5602
-		<body>
5603
-		<div class=content>
5604
-			<br><br>
5605
-			<div class=title>' . $this->serviceName . '</div>
5606
-			<div class=nav>
5607
-				<p>View the <a href="?wsdl">WSDL</a> for the service.
5608
-				Click on an operation name to view it&apos;s details.</p>
5609
-				<ul>';
5610
-        foreach ($this->getOperations() as $op => $data) {
5611
-            $b .= "<li><a href='#' onclick=\"popout();popup('$op')\">$op</a></li>";
5612
-            // create hidden div
5613
-            $b .= "<div id='$op' class='hidden'>
5614
-				    <a href='#' onclick='popout()'><font color='#ffffff'>Close</font></a><br><br>";
5615
-            foreach ($data as $donnie => $marie) { // loop through opdata
5616
-                if ($donnie == 'input' || $donnie == 'output') { // show input/output data
5617
-                    $b .= "<font color='white'>" . ucfirst($donnie) . ':</font><br>';
5618
-                    foreach ($marie as $captain => $tenille) { // loop through data
5619
-                        if ($captain == 'parts') { // loop thru parts
5620
-                            $b .= "&nbsp;&nbsp;$captain:<br>";
5621
-                            //if(is_array($tenille)){
5622
-                            foreach ($tenille as $joanie => $chachi) {
5623
-                                $b .= "&nbsp;&nbsp;&nbsp;&nbsp;$joanie: $chachi<br>";
5624
-                            }
5625
-                            //}
5626
-                        } else {
5627
-                            $b .= "&nbsp;&nbsp;$captain: $tenille<br>";
5628
-                        }
5629
-                    }
5630
-                } else {
5631
-                    $b .= "<font color='white'>" . ucfirst($donnie) . ":</font> $marie<br>";
5632
-                }
5633
-            }
5634
-            $b .= '</div>';
5635
-        }
5636
-        $b .= '
5637
-				<ul>
5638
-			</div>
5639
-		</div></body></html>';
5640
-        return $b;
5641
-    }
5642
-
5643
-    /**
5644
-     * serialize the parsed wsdl
5645
-     *
5646
-     * @param mixed $debug whether to put debug=1 in endpoint URL
5647
-     * @return string serialization of WSDL
5648
-     * @access public
5649
-     */
5650
-    function serialize($debug = 0)
5651
-    {
5652
-        $xml = '<?xml version="1.0" encoding="ISO-8859-1"?>';
5653
-        $xml .= "\n<definitions";
5654
-        foreach ($this->namespaces as $k => $v) {
5655
-            $xml .= " xmlns:$k=\"$v\"";
5656
-        }
5657
-        // 10.9.02 - add poulter fix for wsdl and tns declarations
5658
-        if (isset($this->namespaces['wsdl'])) {
5659
-            $xml .= " xmlns=\"" . $this->namespaces['wsdl'] . "\"";
5660
-        }
5661
-        if (isset($this->namespaces['tns'])) {
5662
-            $xml .= " targetNamespace=\"" . $this->namespaces['tns'] . "\"";
5663
-        }
5664
-        $xml .= '>';
5665
-        // imports
5666
-        if (sizeof($this->import) > 0) {
5667
-            foreach ($this->import as $ns => $list) {
5668
-                foreach ($list as $ii) {
5669
-                    if ($ii['location'] != '') {
5670
-                        $xml .= '<import location="' . $ii['location'] . '" namespace="' . $ns . '" />';
5671
-                    } else {
5672
-                        $xml .= '<import namespace="' . $ns . '" />';
5673
-                    }
5674
-                }
5675
-            }
5676
-        }
5677
-        // types
5678
-        if (count($this->schemas) >= 1) {
5679
-            $xml .= "\n<types>\n";
5680
-            foreach ($this->schemas as $list) {
5681
-                foreach ($list as $xs) {
5682
-                    $xml .= $xs->serializeSchema();
5683
-                }
5684
-            }
5685
-            $xml .= '</types>';
5686
-        }
5687
-        // messages
5688
-        if (count($this->messages) >= 1) {
5689
-            foreach ($this->messages as $msgName => $msgParts) {
5690
-                $xml .= "\n<message name=\"" . $msgName . '">';
5691
-                if (is_array($msgParts)) {
5692
-                    foreach ($msgParts as $partName => $partType) {
5693
-                        // print 'serializing '.$partType.', sv: '.$this->XMLSchemaVersion.'<br>';
5694
-                        if (strpos($partType, ':')) {
5695
-                            $typePrefix = $this->getPrefixFromNamespace($this->getPrefix($partType));
5696
-                        } elseif (isset($this->typemap[$this->namespaces['xsd']][$partType])) {
5697
-                            // print 'checking typemap: '.$this->XMLSchemaVersion.'<br>';
5698
-                            $typePrefix = 'xsd';
5699
-                        } else {
5700
-                            foreach ($this->typemap as $ns => $types) {
5701
-                                if (isset($types[$partType])) {
5702
-                                    $typePrefix = $this->getPrefixFromNamespace($ns);
5703
-                                }
5704
-                            }
5705
-                            if (!isset($typePrefix)) {
5706
-                                die("$partType has no namespace!");
5707
-                            }
5708
-                        }
5709
-                        $ns = $this->getNamespaceFromPrefix($typePrefix);
5710
-                        $localPart = $this->getLocalPart($partType);
5711
-                        $typeDef = $this->getTypeDef($localPart, $ns);
5712
-                        if (isset($typeDef['typeClass']) && $typeDef['typeClass'] == 'element') {
5713
-                            $elementortype = 'element';
5714
-                            if (substr($localPart, -1) == '^') {
5715
-                                $localPart = substr($localPart, 0, -1);
5716
-                            }
5717
-                        } else {
5718
-                            $elementortype = 'type';
5719
-                        }
5720
-                        $xml .= "\n" . '  <part name="' . $partName . '" ' . $elementortype . '="' . $typePrefix . ':' . $localPart . '" />';
5721
-                    }
5722
-                }
5723
-                $xml .= '</message>';
5724
-            }
5725
-        }
5726
-        // bindings & porttypes
5727
-        if (count($this->bindings) >= 1) {
5728
-            $binding_xml = '';
5729
-            $portType_xml = '';
5730
-            foreach ($this->bindings as $bindingName => $attrs) {
5731
-                $binding_xml .= "\n<binding name=\"" . $bindingName . '" type="tns:' . $attrs['portType'] . '">';
5732
-                $binding_xml .= "\n" . '  <soap:binding style="' . $attrs['style'] . '" transport="' . $attrs['transport'] . '"/>';
5733
-                $portType_xml .= "\n<portType name=\"" . $attrs['portType'] . '">';
5734
-                foreach ($attrs['operations'] as $opName => $opParts) {
5735
-                    $binding_xml .= "\n" . '  <operation name="' . $opName . '">';
5736
-                    $binding_xml .= "\n" . '    <soap:operation soapAction="' . $opParts['soapAction'] . '" style="' . $opParts['style'] . '"/>';
5737
-                    if (isset($opParts['input']['encodingStyle']) && $opParts['input']['encodingStyle'] != '') {
5738
-                        $enc_style = ' encodingStyle="' . $opParts['input']['encodingStyle'] . '"';
5739
-                    } else {
5740
-                        $enc_style = '';
5741
-                    }
5742
-                    $binding_xml .= "\n" . '    <input><soap:body use="' . $opParts['input']['use'] . '" namespace="' . $opParts['input']['namespace'] . '"' . $enc_style . '/></input>';
5743
-                    if (isset($opParts['output']['encodingStyle']) && $opParts['output']['encodingStyle'] != '') {
5744
-                        $enc_style = ' encodingStyle="' . $opParts['output']['encodingStyle'] . '"';
5745
-                    } else {
5746
-                        $enc_style = '';
5747
-                    }
5748
-                    $binding_xml .= "\n" . '    <output><soap:body use="' . $opParts['output']['use'] . '" namespace="' . $opParts['output']['namespace'] . '"' . $enc_style . '/></output>';
5749
-                    $binding_xml .= "\n" . '  </operation>';
5750
-                    $portType_xml .= "\n" . '  <operation name="' . $opParts['name'] . '"';
5751
-                    if (isset($opParts['parameterOrder'])) {
5752
-                        $portType_xml .= ' parameterOrder="' . $opParts['parameterOrder'] . '"';
5753
-                    }
5754
-                    $portType_xml .= '>';
5755
-                    if (isset($opParts['documentation']) && $opParts['documentation'] != '') {
5756
-                        $portType_xml .= "\n" . '    <documentation>' . htmlspecialchars($opParts['documentation']) . '</documentation>';
5757
-                    }
5758
-                    $portType_xml .= "\n" . '    <input message="tns:' . $opParts['input']['message'] . '"/>';
5759
-                    $portType_xml .= "\n" . '    <output message="tns:' . $opParts['output']['message'] . '"/>';
5760
-                    $portType_xml .= "\n" . '  </operation>';
5761
-                }
5762
-                $portType_xml .= "\n" . '</portType>';
5763
-                $binding_xml .= "\n" . '</binding>';
5764
-            }
5765
-            $xml .= $portType_xml . $binding_xml;
5766
-        }
5767
-        // services
5768
-        $xml .= "\n<service name=\"" . $this->serviceName . '">';
5769
-        if (count($this->ports) >= 1) {
5770
-            foreach ($this->ports as $pName => $attrs) {
5771
-                $xml .= "\n" . '  <port name="' . $pName . '" binding="tns:' . $attrs['binding'] . '">';
5772
-                $xml .= "\n" . '    <soap:address location="' . $attrs['location'] . ($debug ? '?debug=1' : '') . '"/>';
5773
-                $xml .= "\n" . '  </port>';
5774
-            }
5775
-        }
5776
-        $xml .= "\n" . '</service>';
5777
-        return $xml . "\n</definitions>";
5778
-    }
5779
-
5780
-    /**
5781
-     * determine whether a set of parameters are unwrapped
5782
-     * when they are expect to be wrapped, Microsoft-style.
5783
-     *
5784
-     * @param string $type the type (element name) of the wrapper
5785
-     * @param array $parameters the parameter values for the SOAP call
5786
-     * @return boolean whether they parameters are unwrapped (and should be wrapped)
5787
-     * @access private
5788
-     */
5789
-    function parametersMatchWrapped($type, $parameters)
5790
-    {
5791
-        $this->debug("in parametersMatchWrapped type=$type, parameters=");
5792
-        $this->appendDebug($this->varDump($parameters));
5793
-
5794
-        // split type into namespace:unqualified-type
5795
-        if (strpos($type, ':')) {
5796
-            $uqType = substr($type, strrpos($type, ':') + 1);
5797
-            $ns = substr($type, 0, strrpos($type, ':'));
5798
-            $this->debug("in parametersMatchWrapped: got a prefixed type: $uqType, $ns");
5799
-            if ($this->getNamespaceFromPrefix($ns)) {
5800
-                $ns = $this->getNamespaceFromPrefix($ns);
5801
-                $this->debug("in parametersMatchWrapped: expanded prefixed type: $uqType, $ns");
5802
-            }
5803
-        } else {
5804
-            // TODO: should the type be compared to types in XSD, and the namespace
5805
-            // set to XSD if the type matches?
5806
-            $this->debug("in parametersMatchWrapped: No namespace for type $type");
5807
-            $ns = '';
5808
-            $uqType = $type;
5809
-        }
5810
-
5811
-        // get the type information
5812
-        if (!$typeDef = $this->getTypeDef($uqType, $ns)) {
5813
-            $this->debug("in parametersMatchWrapped: $type ($uqType) is not a supported type.");
5814
-            return false;
5815
-        }
5816
-        $this->debug("in parametersMatchWrapped: found typeDef=");
5817
-        $this->appendDebug($this->varDump($typeDef));
5818
-        if (substr($uqType, -1) == '^') {
5819
-            $uqType = substr($uqType, 0, -1);
5820
-        }
5821
-        $phpType = $typeDef['phpType'];
5822
-        $arrayType = (isset($typeDef['arrayType']) ? $typeDef['arrayType'] : '');
5823
-        $this->debug("in parametersMatchWrapped: uqType: $uqType, ns: $ns, phptype: $phpType, arrayType: $arrayType");
5824
-
5825
-        // we expect a complexType or element of complexType
5826
-        if ($phpType != 'struct') {
5827
-            $this->debug("in parametersMatchWrapped: not a struct");
5828
-            return false;
5829
-        }
5830
-
5831
-        // see whether the parameter names match the elements
5832
-        if (isset($typeDef['elements']) && is_array($typeDef['elements'])) {
5833
-            $elements = 0;
5834
-            $matches = 0;
5835
-            foreach ($typeDef['elements'] as $name => $attrs) {
5836
-                if (isset($parameters[$name])) {
5837
-                    $this->debug("in parametersMatchWrapped: have parameter named $name");
5838
-                    $matches++;
5839
-                } else {
5840
-                    $this->debug("in parametersMatchWrapped: do not have parameter named $name");
5841
-                }
5842
-                $elements++;
5843
-            }
5844
-
5845
-            $this->debug("in parametersMatchWrapped: $matches parameter names match $elements wrapped parameter names");
5846
-            if ($matches == 0) {
5847
-                return false;
5848
-            }
5849
-            return true;
5850
-        }
5851
-
5852
-        // since there are no elements for the type, if the user passed no
5853
-        // parameters, the parameters match wrapped.
5854
-        $this->debug("in parametersMatchWrapped: no elements type $ns:$uqType");
5855
-        return count($parameters) == 0;
5856
-    }
5857
-
5858
-    /**
5859
-     * serialize PHP values according to a WSDL message definition
5860
-     * contrary to the method name, this is not limited to RPC
5861
-     *
5862
-     * TODO
5863
-     * - multi-ref serialization
5864
-     * - validate PHP values against type definitions, return errors if invalid
5865
-     *
5866
-     * @param string $operation operation name
5867
-     * @param string $direction (input|output)
5868
-     * @param mixed $parameters parameter value(s)
5869
-     * @param string $bindingType (soap|soap12)
5870
-     * @return false|string parameters serialized as XML or false on error (e.g. operation not found)
5871
-     * @access public
5872
-     */
5873
-    function serializeRPCParameters($operation, $direction, $parameters, $bindingType = 'soap')
5874
-    {
5875
-        $this->debug("in serializeRPCParameters: operation=$operation, direction=$direction, XMLSchemaVersion=$this->XMLSchemaVersion, bindingType=$bindingType");
5876
-        $this->appendDebug('parameters=' . $this->varDump($parameters));
5877
-
5878
-        if ($direction != 'input' && $direction != 'output') {
5879
-            $this->debug('The value of the \$direction argument needs to be either "input" or "output"');
5880
-            $this->setError('The value of the \$direction argument needs to be either "input" or "output"');
5881
-            return false;
5882
-        }
5883
-        if (!$opData = $this->getOperationData($operation, $bindingType)) {
5884
-            $this->debug('Unable to retrieve WSDL data for operation: ' . $operation . ' bindingType: ' . $bindingType);
5885
-            $this->setError('Unable to retrieve WSDL data for operation: ' . $operation . ' bindingType: ' . $bindingType);
5886
-            return false;
5887
-        }
5888
-        $this->debug('in serializeRPCParameters: opData:');
5889
-        $this->appendDebug($this->varDump($opData));
5890
-
5891
-        // Get encoding style for output and set to current
5892
-        $encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/';
5893
-        if (($direction == 'input') && isset($opData['output']['encodingStyle']) && ($opData['output']['encodingStyle'] != $encodingStyle)) {
5894
-            $encodingStyle = $opData['output']['encodingStyle'];
5895
-        }
5896
-
5897
-        // set input params
5898
-        $xml = '';
5899
-        if (isset($opData[$direction]['parts']) && sizeof($opData[$direction]['parts']) > 0) {
5900
-            $parts = &$opData[$direction]['parts'];
5901
-            $part_count = sizeof($parts);
5902
-            $style = $opData['style'];
5903
-            $use = $opData[$direction]['use'];
5904
-            $this->debug("have $part_count part(s) to serialize using $style/$use");
5905
-            if (is_array($parameters)) {
5906
-                $parametersArrayType = $this->isArraySimpleOrStruct($parameters);
5907
-                $parameter_count = count($parameters);
5908
-                $this->debug("have $parameter_count parameter(s) provided as $parametersArrayType to serialize");
5909
-                // check for Microsoft-style wrapped parameters
5910
-                if ($style == 'document' && $use == 'literal' && $part_count == 1 && isset($parts['parameters'])) {
5911
-                    $this->debug('check whether the caller has wrapped the parameters');
5912
-                    if ($direction == 'output' && $parametersArrayType == 'arraySimple' && $parameter_count == 1) {
5913
-                        // TODO: consider checking here for double-wrapping, when
5914
-                        // service function wraps, then NuSOAP wraps again
5915
-                        $this->debug("change simple array to associative with 'parameters' element");
5916
-                        $parameters['parameters'] = $parameters[0];
5917
-                        unset($parameters[0]);
5918
-                    }
5919
-                    if (($parametersArrayType == 'arrayStruct' || $parameter_count == 0) && !isset($parameters['parameters'])) {
5920
-                        $this->debug('check whether caller\'s parameters match the wrapped ones');
5921
-                        if ($this->parametersMatchWrapped($parts['parameters'], $parameters)) {
5922
-                            $this->debug('wrap the parameters for the caller');
5923
-                            $parameters = array('parameters' => $parameters);
5924
-                        }
5925
-                    }
5926
-                }
5927
-                foreach ($parts as $name => $type) {
5928
-                    $this->debug("serializing part $name of type $type");
5929
-                    // Track encoding style
5930
-                    if (isset($opData[$direction]['encodingStyle']) && $encodingStyle != $opData[$direction]['encodingStyle']) {
5931
-                        $encodingStyle = $opData[$direction]['encodingStyle'];
5932
-                        $enc_style = $encodingStyle;
5933
-                    } else {
5934
-                        $enc_style = false;
5935
-                    }
5936
-                    // NOTE: add error handling here
5937
-                    // if serializeType returns false, then catch global error and fault
5938
-                    if ($parametersArrayType == 'arraySimple') {
5939
-                        $p = array_shift($parameters);
5940
-                        $this->debug('calling serializeType w/indexed param');
5941
-                        $xml .= $this->serializeType($name, $type, $p, $use, $enc_style);
5942
-                    } elseif (isset($parameters[$name])) {
5943
-                        $this->debug('calling serializeType w/named param');
5944
-                        $xml .= $this->serializeType($name, $type, $parameters[$name], $use, $enc_style);
5945
-                    } else {
5946
-                        // TODO: only send nillable
5947
-                        $this->debug('calling serializeType w/null param');
5948
-                        $xml .= $this->serializeType($name, $type, null, $use, $enc_style);
5949
-                    }
5950
-                }
5951
-            } else {
5952
-                $this->debug('no parameters passed.');
5953
-            }
5954
-        }
5955
-        $this->debug("serializeRPCParameters returning: $xml");
5956
-        return $xml;
5957
-    }
5958
-
5959
-    /**
5960
-     * serialize a PHP value according to a WSDL message definition
5961
-     *
5962
-     * TODO
5963
-     * - multi-ref serialization
5964
-     * - validate PHP values against type definitions, return errors if invalid
5965
-     *
5966
-     * @param string $operation operation name
5967
-     * @param string $direction (input|output)
5968
-     * @param mixed $parameters parameter value(s)
5969
-     * @return false|string parameters serialized as XML or false on error (e.g. operation not found)
5970
-     * @access public
5971
-     * @deprecated
5972
-     */
5973
-    function serializeParameters($operation, $direction, $parameters)
5974
-    {
5975
-        $this->debug("in serializeParameters: operation=$operation, direction=$direction, XMLSchemaVersion=$this->XMLSchemaVersion");
5976
-        $this->appendDebug('parameters=' . $this->varDump($parameters));
5977
-
5978
-        if ($direction != 'input' && $direction != 'output') {
5979
-            $this->debug('The value of the \$direction argument needs to be either "input" or "output"');
5980
-            $this->setError('The value of the \$direction argument needs to be either "input" or "output"');
5981
-            return false;
5982
-        }
5983
-        if (!$opData = $this->getOperationData($operation)) {
5984
-            $this->debug('Unable to retrieve WSDL data for operation: ' . $operation);
5985
-            $this->setError('Unable to retrieve WSDL data for operation: ' . $operation);
5986
-            return false;
5987
-        }
5988
-        $this->debug('opData:');
5989
-        $this->appendDebug($this->varDump($opData));
5990
-
5991
-        // Get encoding style for output and set to current
5992
-        $encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/';
5993
-        if (($direction == 'input') && isset($opData['output']['encodingStyle']) && ($opData['output']['encodingStyle'] != $encodingStyle)) {
5994
-            $encodingStyle = $opData['output']['encodingStyle'];
5995
-        }
5996
-
5997
-        // set input params
5998
-        $xml = '';
5999
-        if (isset($opData[$direction]['parts']) && sizeof($opData[$direction]['parts']) > 0) {
6000
-
6001
-            $use = $opData[$direction]['use'];
6002
-            $this->debug("use=$use");
6003
-            $this->debug('got ' . count($opData[$direction]['parts']) . ' part(s)');
6004
-            if (is_array($parameters)) {
6005
-                $parametersArrayType = $this->isArraySimpleOrStruct($parameters);
6006
-                $this->debug('have ' . $parametersArrayType . ' parameters');
6007
-                foreach ($opData[$direction]['parts'] as $name => $type) {
6008
-                    $this->debug('serializing part "' . $name . '" of type "' . $type . '"');
6009
-                    // Track encoding style
6010
-                    if (isset($opData[$direction]['encodingStyle']) && $encodingStyle != $opData[$direction]['encodingStyle']) {
6011
-                        $encodingStyle = $opData[$direction]['encodingStyle'];
6012
-                        $enc_style = $encodingStyle;
6013
-                    } else {
6014
-                        $enc_style = false;
6015
-                    }
6016
-                    // NOTE: add error handling here
6017
-                    // if serializeType returns false, then catch global error and fault
6018
-                    if ($parametersArrayType == 'arraySimple') {
6019
-                        $p = array_shift($parameters);
6020
-                        $this->debug('calling serializeType w/indexed param');
6021
-                        $xml .= $this->serializeType($name, $type, $p, $use, $enc_style);
6022
-                    } elseif (isset($parameters[$name])) {
6023
-                        $this->debug('calling serializeType w/named param');
6024
-                        $xml .= $this->serializeType($name, $type, $parameters[$name], $use, $enc_style);
6025
-                    } else {
6026
-                        // TODO: only send nillable
6027
-                        $this->debug('calling serializeType w/null param');
6028
-                        $xml .= $this->serializeType($name, $type, null, $use, $enc_style);
6029
-                    }
6030
-                }
6031
-            } else {
6032
-                $this->debug('no parameters passed.');
6033
-            }
6034
-        }
6035
-        $this->debug("serializeParameters returning: $xml");
6036
-        return $xml;
6037
-    }
6038
-
6039
-    /**
6040
-     * serializes a PHP value according a given type definition
6041
-     *
6042
-     * @param string $name name of value (part or element)
6043
-     * @param string $type XML schema type of value (type or element)
6044
-     * @param mixed $value a native PHP value (parameter value)
6045
-     * @param string $use use for part (encoded|literal)
6046
-     * @param string $encodingStyle SOAP encoding style for the value (if different than the enclosing style)
6047
-     * @param boolean $unqualified a kludge for what should be XML namespace form handling
6048
-     * @return string value serialized as an XML string
6049
-     * @access private
6050
-     */
6051
-    function serializeType($name, $type, $value, $use = 'encoded', $encodingStyle = false, $unqualified = false)
6052
-    {
6053
-        $this->debug("in serializeType: name=$name, type=$type, use=$use, encodingStyle=$encodingStyle, unqualified=" . ($unqualified ? "unqualified" : "qualified"));
6054
-        $this->appendDebug("value=" . $this->varDump($value));
6055
-        if ($use == 'encoded' && $encodingStyle) {
6056
-            $encodingStyle = ' SOAP-ENV:encodingStyle="' . $encodingStyle . '"';
6057
-        }
6058
-
6059
-        // if a soapval has been supplied, let its type override the WSDL
6060
-        if (is_object($value) && get_class($value) == 'soapval') {
6061
-            if ($value->type_ns) {
6062
-                $type = $value->type_ns . ':' . $value->type;
6063
-                $forceType = true;
6064
-                $this->debug("in serializeType: soapval overrides type to $type");
6065
-            } elseif ($value->type) {
6066
-                $type = $value->type;
6067
-                $forceType = true;
6068
-                $this->debug("in serializeType: soapval overrides type to $type");
6069
-            } else {
6070
-                $forceType = false;
6071
-                $this->debug("in serializeType: soapval does not override type");
6072
-            }
6073
-            $attrs = $value->attributes;
6074
-            $value = $value->value;
6075
-            $this->debug("in serializeType: soapval overrides value to $value");
6076
-            if ($attrs) {
6077
-                if (!is_array($value)) {
6078
-                    $value['!'] = $value;
6079
-                }
6080
-                foreach ($attrs as $n => $v) {
6081
-                    $value['!' . $n] = $v;
6082
-                }
6083
-                $this->debug("in serializeType: soapval provides attributes");
6084
-            }
6085
-        } else {
6086
-            $forceType = false;
6087
-        }
6088
-
6089
-        $xml = '';
6090
-        if (strpos($type, ':')) {
6091
-            $uqType = substr($type, strrpos($type, ':') + 1);
6092
-            $ns = substr($type, 0, strrpos($type, ':'));
6093
-            $this->debug("in serializeType: got a prefixed type: $uqType, $ns");
6094
-            if ($this->getNamespaceFromPrefix($ns)) {
6095
-                $ns = $this->getNamespaceFromPrefix($ns);
6096
-                $this->debug("in serializeType: expanded prefixed type: $uqType, $ns");
6097
-            }
6098
-
6099
-            if ($ns == $this->XMLSchemaVersion || $ns == 'http://schemas.xmlsoap.org/soap/encoding/') {
6100
-                $this->debug('in serializeType: type namespace indicates XML Schema or SOAP Encoding type');
6101
-                if ($unqualified && $use == 'literal') {
6102
-                    $elementNS = " xmlns=\"\"";
6103
-                } else {
6104
-                    $elementNS = '';
6105
-                }
6106
-                if (is_null($value)) {
6107
-                    if ($use == 'literal') {
6108
-                        // TODO: depends on minOccurs
6109
-                        $xml = "<$name$elementNS/>";
6110
-                    } else {
6111
-                        // TODO: depends on nillable, which should be checked before calling this method
6112
-                        $xml = "<$name$elementNS xsi:nil=\"true\" xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"/>";
6113
-                    }
6114
-                    $this->debug("in serializeType: returning: $xml");
6115
-                    return $xml;
6116
-                }
6117
-                if ($uqType == 'Array') {
6118
-                    // JBoss/Axis does this sometimes
6119
-                    return $this->serialize_val($value, $name, false, false, false, false, $use);
6120
-                }
6121
-                if ($uqType == 'boolean') {
6122
-                    if ((is_string($value) && $value == 'false') || (!$value)) {
6123
-                        $value = 'false';
6124
-                    } else {
6125
-                        $value = 'true';
6126
-                    }
6127
-                }
6128
-                if ($uqType == 'string' && gettype($value) == 'string') {
6129
-                    $value = $this->expandEntities($value);
6130
-                }
6131
-                if (($uqType == 'long' || $uqType == 'unsignedLong') && gettype($value) == 'double') {
6132
-                    $value = sprintf("%.0lf", $value);
6133
-                }
6134
-                // it's a scalar
6135
-                // TODO: what about null/nil values?
6136
-                // check type isn't a custom type extending xmlschema namespace
6137
-                if (!$this->getTypeDef($uqType, $ns)) {
6138
-                    if ($use == 'literal') {
6139
-                        if ($forceType) {
6140
-                            $xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\">$value</$name>";
6141
-                        } else {
6142
-                            $xml = "<$name$elementNS>$value</$name>";
6143
-                        }
6144
-                    } else {
6145
-                        $xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"$encodingStyle>$value</$name>";
6146
-                    }
6147
-                    $this->debug("in serializeType: returning: $xml");
6148
-                    return $xml;
6149
-                }
6150
-                $this->debug('custom type extends XML Schema or SOAP Encoding namespace (yuck)');
6151
-            } elseif ($ns == 'http://xml.apache.org/xml-soap') {
6152
-                $this->debug('in serializeType: appears to be Apache SOAP type');
6153
-                if ($uqType == 'Map') {
6154
-                    $tt_prefix = $this->getPrefixFromNamespace('http://xml.apache.org/xml-soap');
6155
-                    if (!$tt_prefix) {
6156
-                        $this->debug('in serializeType: Add namespace for Apache SOAP type');
6157
-                        $tt_prefix = 'ns' . rand(1000, 9999);
6158
-                        $this->namespaces[$tt_prefix] = 'http://xml.apache.org/xml-soap';
6159
-                        // force this to be added to usedNamespaces
6160
-                        $tt_prefix = $this->getPrefixFromNamespace('http://xml.apache.org/xml-soap');
6161
-                    }
6162
-                    $contents = '';
6163
-                    foreach ($value as $k => $v) {
6164
-                        $this->debug("serializing map element: key $k, value $v");
6165
-                        $contents .= '<item>';
6166
-                        $contents .= $this->serialize_val($k, 'key', false, false, false, false, $use);
6167
-                        $contents .= $this->serialize_val($v, 'value', false, false, false, false, $use);
6168
-                        $contents .= '</item>';
6169
-                    }
6170
-                    if ($use == 'literal') {
6171
-                        if ($forceType) {
6172
-                            $xml = "<$name xsi:type=\"" . $tt_prefix . ":$uqType\">$contents</$name>";
6173
-                        } else {
6174
-                            $xml = "<$name>$contents</$name>";
6175
-                        }
6176
-                    } else {
6177
-                        $xml = "<$name xsi:type=\"" . $tt_prefix . ":$uqType\"$encodingStyle>$contents</$name>";
6178
-                    }
6179
-                    $this->debug("in serializeType: returning: $xml");
6180
-                    return $xml;
6181
-                }
6182
-                $this->debug('in serializeType: Apache SOAP type, but only support Map');
6183
-            }
6184
-        } else {
6185
-            // TODO: should the type be compared to types in XSD, and the namespace
6186
-            // set to XSD if the type matches?
6187
-            $this->debug("in serializeType: No namespace for type $type");
6188
-            $ns = '';
6189
-            $uqType = $type;
6190
-        }
6191
-        if (!$typeDef = $this->getTypeDef($uqType, $ns)) {
6192
-            $this->setError("$type ($uqType) is not a supported type.");
6193
-            $this->debug("in serializeType: $type ($uqType) is not a supported type.");
6194
-            return false;
6195
-        } else {
6196
-            $this->debug("in serializeType: found typeDef");
6197
-            $this->appendDebug('typeDef=' . $this->varDump($typeDef));
6198
-            if (substr($uqType, -1) == '^') {
6199
-                $uqType = substr($uqType, 0, -1);
6200
-            }
6201
-        }
6202
-        if (!isset($typeDef['phpType'])) {
6203
-            $this->setError("$type ($uqType) has no phpType.");
6204
-            $this->debug("in serializeType: $type ($uqType) has no phpType.");
6205
-            return false;
6206
-        }
6207
-        $phpType = $typeDef['phpType'];
6208
-        $this->debug("in serializeType: uqType: $uqType, ns: $ns, phptype: $phpType, arrayType: " . (isset($typeDef['arrayType']) ? $typeDef['arrayType'] : ''));
6209
-        // if php type == struct, map value to the <all> element names
6210
-        if ($phpType == 'struct') {
6211
-            if (isset($typeDef['typeClass']) && $typeDef['typeClass'] == 'element') {
6212
-                $elementName = $uqType;
6213
-                if (isset($typeDef['form']) && ($typeDef['form'] == 'qualified')) {
6214
-                    $elementNS = " xmlns=\"$ns\"";
6215
-                } else {
6216
-                    $elementNS = " xmlns=\"\"";
6217
-                }
6218
-            } else {
6219
-                $elementName = $name;
6220
-                if ($unqualified) {
6221
-                    $elementNS = " xmlns=\"\"";
6222
-                } else {
6223
-                    $elementNS = '';
6224
-                }
6225
-            }
6226
-            if (is_null($value)) {
6227
-                if ($use == 'literal') {
6228
-                    // TODO: depends on minOccurs and nillable
6229
-                    $xml = "<$elementName$elementNS/>";
6230
-                } else {
6231
-                    $xml = "<$elementName$elementNS xsi:nil=\"true\" xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"/>";
6232
-                }
6233
-                $this->debug("in serializeType: returning: $xml");
6234
-                return $xml;
6235
-            }
6236
-            if (is_object($value)) {
6237
-                $value = get_object_vars($value);
6238
-            }
6239
-            if (is_array($value)) {
6240
-                $elementAttrs = $this->serializeComplexTypeAttributes($typeDef, $value, $ns, $uqType);
6241
-                if ($use == 'literal') {
6242
-                    if ($forceType) {
6243
-                        $xml = "<$elementName$elementNS$elementAttrs xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\">";
6244
-                    } else {
6245
-                        $xml = "<$elementName$elementNS$elementAttrs>";
6246
-                    }
6247
-                } else {
6248
-                    $xml = "<$elementName$elementNS$elementAttrs xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"$encodingStyle>";
6249
-                }
6250
-
6251
-                if (isset($typeDef['simpleContent']) && $typeDef['simpleContent'] == 'true') {
6252
-                    if (isset($value['!'])) {
6253
-                        $xml .= $value['!'];
6254
-                        $this->debug("in serializeType: serialized simpleContent for type $type");
6255
-                    } else {
6256
-                        $this->debug("in serializeType: no simpleContent to serialize for type $type");
6257
-                    }
6258
-                } else {
6259
-                    // complexContent
6260
-                    $xml .= $this->serializeComplexTypeElements($typeDef, $value, $ns, $uqType, $use, $encodingStyle);
6261
-                }
6262
-                $xml .= "</$elementName>";
6263
-            } else {
6264
-                $this->debug("in serializeType: phpType is struct, but value is not an array");
6265
-                $this->setError("phpType is struct, but value is not an array: see debug output for details");
6266
-            }
6267
-        } elseif ($phpType == 'array') {
6268
-            if (isset($typeDef['form']) && ($typeDef['form'] == 'qualified')) {
6269
-                $elementNS = " xmlns=\"$ns\"";
6270
-            } else {
6271
-                if ($unqualified) {
6272
-                    $elementNS = " xmlns=\"\"";
6273
-                } else {
6274
-                    $elementNS = '';
6275
-                }
6276
-            }
6277
-            if (is_null($value)) {
6278
-                if ($use == 'literal') {
6279
-                    // TODO: depends on minOccurs
6280
-                    $xml = "<$name$elementNS/>";
6281
-                } else {
6282
-                    $xml = "<$name$elementNS xsi:nil=\"true\" xsi:type=\"" .
6283
-                        $this->getPrefixFromNamespace('http://schemas.xmlsoap.org/soap/encoding/') .
6284
-                        ":Array\" " .
6285
-                        $this->getPrefixFromNamespace('http://schemas.xmlsoap.org/soap/encoding/') .
6286
-                        ':arrayType="' .
6287
-                        $this->getPrefixFromNamespace($this->getPrefix($typeDef['arrayType'])) .
6288
-                        ':' .
6289
-                        $this->getLocalPart($typeDef['arrayType']) . "[0]\"/>";
6290
-                }
6291
-                $this->debug("in serializeType: returning: $xml");
6292
-                return $xml;
6293
-            }
6294
-            $cols = '';
6295
-            if (isset($typeDef['multidimensional'])) {
6296
-                $nv = array();
6297
-                foreach ($value as $v) {
6298
-                    $cols = ',' . sizeof($v);
6299
-                    $nv = array_merge($nv, $v);
6300
-                }
6301
-                $value = $nv;
6302
-            }
6303
-            if (is_array($value) && sizeof($value) >= 1) {
6304
-                $rows = sizeof($value);
6305
-                $contents = '';
6306
-                foreach ($value as $v) {
6307
-                    //$this->debug breaks when serializing ArrayOfComplexType
6308
-                    //Error: Object of class [COMPLEX-TYPE] could not be converted to string
6309
-                    //$this->debug("serializing array element: $k, " . (is_array($v) ? "array" : $v) . " of type: $typeDef[arrayType]");
6310
-                    //if (strpos($typeDef['arrayType'], ':') ) {
6311
-                    if (!in_array($typeDef['arrayType'], $this->typemap['http://www.w3.org/2001/XMLSchema'])) {
6312
-                        $contents .= $this->serializeType('item', $typeDef['arrayType'], $v, $use);
6313
-                    } else {
6314
-                        $contents .= $this->serialize_val($v, 'item', $typeDef['arrayType'], null, $this->XMLSchemaVersion, false, $use);
6315
-                    }
6316
-                }
6317
-            } else {
6318
-                $rows = 0;
6319
-                $contents = null;
6320
-            }
6321
-            // TODO: for now, an empty value will be serialized as a zero element
6322
-            // array.  Revisit this when coding the handling of null/nil values.
6323
-            if ($use == 'literal') {
6324
-                $xml = "<$name$elementNS>"
6325
-                    . $contents
6326
-                    . "</$name>";
6327
-            } else {
6328
-                $xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace('http://schemas.xmlsoap.org/soap/encoding/') . ':Array" ' .
6329
-                    $this->getPrefixFromNamespace('http://schemas.xmlsoap.org/soap/encoding/')
6330
-                    . ':arrayType="'
6331
-                    . $this->getPrefixFromNamespace($this->getPrefix($typeDef['arrayType']))
6332
-                    . ":" . $this->getLocalPart($typeDef['arrayType']) . "[$rows$cols]\">"
6333
-                    . $contents
6334
-                    . "</$name>";
6335
-            }
6336
-        } elseif ($phpType == 'scalar') {
6337
-            if (isset($typeDef['form']) && ($typeDef['form'] == 'qualified')) {
6338
-                $elementNS = " xmlns=\"$ns\"";
6339
-            } else {
6340
-                if ($unqualified) {
6341
-                    $elementNS = " xmlns=\"\"";
6342
-                } else {
6343
-                    $elementNS = '';
6344
-                }
6345
-            }
6346
-            if ($use == 'literal') {
6347
-                if ($forceType) {
6348
-                    $xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\">$value</$name>";
6349
-                } else {
6350
-                    $xml = "<$name$elementNS>$value</$name>";
6351
-                }
6352
-            } else {
6353
-                $xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"$encodingStyle>$value</$name>";
6354
-            }
6355
-        }
6356
-        $this->debug("in serializeType: returning: $xml");
6357
-        return $xml;
6358
-    }
6359
-
6360
-    /**
6361
-     * serializes the attributes for a complexType
6362
-     *
6363
-     * @param array $typeDef our internal representation of an XML schema type (or element)
6364
-     * @param mixed $value a native PHP value (parameter value)
6365
-     * @param string $ns the namespace of the type
6366
-     * @param string $uqType the local part of the type
6367
-     * @return string value serialized as an XML string
6368
-     * @access private
6369
-     */
6370
-    function serializeComplexTypeAttributes($typeDef, $value, $ns, $uqType)
6371
-    {
6372
-        $this->debug("serializeComplexTypeAttributes for XML Schema type $ns:$uqType");
6373
-        $xml = '';
6374
-        if (isset($typeDef['extensionBase'])) {
6375
-            $nsx = $this->getPrefix($typeDef['extensionBase']);
6376
-            $uqTypex = $this->getLocalPart($typeDef['extensionBase']);
6377
-            if ($this->getNamespaceFromPrefix($nsx)) {
6378
-                $nsx = $this->getNamespaceFromPrefix($nsx);
6379
-            }
6380
-            if ($typeDefx = $this->getTypeDef($uqTypex, $nsx)) {
6381
-                $this->debug("serialize attributes for extension base $nsx:$uqTypex");
6382
-                $xml .= $this->serializeComplexTypeAttributes($typeDefx, $value, $nsx, $uqTypex);
6383
-            } else {
6384
-                $this->debug("extension base $nsx:$uqTypex is not a supported type");
6385
-            }
6386
-        }
6387
-        if (isset($typeDef['attrs']) && is_array($typeDef['attrs'])) {
6388
-            $this->debug("serialize attributes for XML Schema type $ns:$uqType");
6389
-            if (is_array($value)) {
6390
-                $xvalue = $value;
6391
-            } elseif (is_object($value)) {
6392
-                $xvalue = get_object_vars($value);
6393
-            } else {
6394
-                $this->debug("value is neither an array nor an object for XML Schema type $ns:$uqType");
6395
-                $xvalue = array();
6396
-            }
6397
-            foreach ($typeDef['attrs'] as $aName => $attrs) {
6398
-                if (isset($xvalue['!' . $aName])) {
6399
-                    $xname = '!' . $aName;
6400
-                    $this->debug("value provided for attribute $aName with key $xname");
6401
-                } elseif (isset($xvalue[$aName])) {
6402
-                    $xname = $aName;
6403
-                    $this->debug("value provided for attribute $aName with key $xname");
6404
-                } elseif (isset($attrs['default'])) {
6405
-                    $xname = '!' . $aName;
6406
-                    $xvalue[$xname] = $attrs['default'];
6407
-                    $this->debug('use default value of ' . $xvalue[$aName] . ' for attribute ' . $aName);
6408
-                } else {
6409
-                    $xname = '';
6410
-                    $this->debug("no value provided for attribute $aName");
6411
-                }
6412
-                if ($xname) {
6413
-                    $xml .= " $aName=\"" . $this->expandEntities($xvalue[$xname]) . "\"";
6414
-                }
6415
-            }
6416
-        } else {
6417
-            $this->debug("no attributes to serialize for XML Schema type $ns:$uqType");
6418
-        }
6419
-        return $xml;
6420
-    }
6421
-
6422
-    /**
6423
-     * serializes the elements for a complexType
6424
-     *
6425
-     * @param array $typeDef our internal representation of an XML schema type (or element)
6426
-     * @param mixed $value a native PHP value (parameter value)
6427
-     * @param string $ns the namespace of the type
6428
-     * @param string $uqType the local part of the type
6429
-     * @param string $use use for part (encoded|literal)
6430
-     * @param string $encodingStyle SOAP encoding style for the value (if different than the enclosing style)
6431
-     * @return string value serialized as an XML string
6432
-     * @access private
6433
-     */
6434
-    function serializeComplexTypeElements($typeDef, $value, $ns, $uqType, $use = 'encoded', $encodingStyle = false)
6435
-    {
6436
-        $this->debug("in serializeComplexTypeElements for XML Schema type $ns:$uqType");
6437
-        $xml = '';
6438
-        if (isset($typeDef['extensionBase'])) {
6439
-            $nsx = $this->getPrefix($typeDef['extensionBase']);
6440
-            $uqTypex = $this->getLocalPart($typeDef['extensionBase']);
6441
-            if ($this->getNamespaceFromPrefix($nsx)) {
6442
-                $nsx = $this->getNamespaceFromPrefix($nsx);
6443
-            }
6444
-            if ($typeDefx = $this->getTypeDef($uqTypex, $nsx)) {
6445
-                $this->debug("serialize elements for extension base $nsx:$uqTypex");
6446
-                $xml .= $this->serializeComplexTypeElements($typeDefx, $value, $nsx, $uqTypex, $use, $encodingStyle);
6447
-            } else {
6448
-                $this->debug("extension base $nsx:$uqTypex is not a supported type");
6449
-            }
6450
-        }
6451
-        if (isset($typeDef['elements']) && is_array($typeDef['elements'])) {
6452
-            $this->debug("in serializeComplexTypeElements, serialize elements for XML Schema type $ns:$uqType");
6453
-            if (is_array($value)) {
6454
-                $xvalue = $value;
6455
-            } elseif (is_object($value)) {
6456
-                $xvalue = get_object_vars($value);
6457
-            } else {
6458
-                $this->debug("value is neither an array nor an object for XML Schema type $ns:$uqType");
6459
-                $xvalue = array();
6460
-            }
6461
-            // toggle whether all elements are present - ideally should validate against schema
6462
-            if (count($typeDef['elements']) != count($xvalue)) {
6463
-                $optionals = true;
6464
-            }
6465
-            foreach ($typeDef['elements'] as $eName => $attrs) {
6466
-                if (!isset($xvalue[$eName])) {
6467
-                    if (isset($attrs['default'])) {
6468
-                        $xvalue[$eName] = $attrs['default'];
6469
-                        $this->debug('use default value of ' . $xvalue[$eName] . ' for element ' . $eName);
6470
-                    }
6471
-                }
6472
-                // if user took advantage of a minOccurs=0, then only serialize named parameters
6473
-                if (isset($optionals)
6474
-                    && (!isset($xvalue[$eName]))
6475
-                    && ((!isset($attrs['nillable'])) || $attrs['nillable'] != 'true')
6476
-                ) {
6477
-                    if (isset($attrs['minOccurs']) && $attrs['minOccurs'] <> '0') {
6478
-                        $this->debug("apparent error: no value provided for element $eName with minOccurs=" . $attrs['minOccurs']);
6479
-                    }
6480
-                    // do nothing
6481
-                    $this->debug("no value provided for complexType element $eName and element is not nillable, so serialize nothing");
6482
-                } else {
6483
-                    // get value
6484
-                    if (isset($xvalue[$eName])) {
6485
-                        $v = $xvalue[$eName];
6486
-                    } else {
6487
-                        $v = null;
6488
-                    }
6489
-                    if (isset($attrs['form'])) {
6490
-                        $unqualified = ($attrs['form'] == 'unqualified');
6491
-                    } else {
6492
-                        $unqualified = false;
6493
-                    }
6494
-                    if (isset($attrs['maxOccurs']) && ($attrs['maxOccurs'] == 'unbounded' || $attrs['maxOccurs'] > 1) && isset($v) && is_array($v) && $this->isArraySimpleOrStruct($v) == 'arraySimple') {
6495
-                        $vv = $v;
6496
-                        foreach ($vv as $v) {
6497
-                            if (isset($attrs['type']) || isset($attrs['ref'])) {
6498
-                                // serialize schema-defined type
6499
-                                $xml .= $this->serializeType($eName, isset($attrs['type']) ? $attrs['type'] : $attrs['ref'], $v, $use, $encodingStyle, $unqualified);
6500
-                            } else {
6501
-                                // serialize generic type (can this ever really happen?)
6502
-                                $this->debug("calling serialize_val() for $v, $eName, false, false, false, false, $use");
6503
-                                $xml .= $this->serialize_val($v, $eName, false, false, false, false, $use);
6504
-                            }
6505
-                        }
6506
-                    } else {
6507
-                        if (!is_null ($v) || !isset($attrs['minOccurs']) || $attrs['minOccurs'] != '0')
6508
-                        {
6509
-                            if (is_null ($v) && isset($attrs['nillable']) && $attrs['nillable'] == 'true')
6510
-                            {
6511
-                                // TODO: serialize a nil correctly, but for now serialize schema-defined type
6512
-                                $xml .= $this->serializeType ($eName,
6513
-                                                              isset($attrs['type']) ? $attrs['type'] : $attrs['ref'],
6514
-                                                              $v, $use, $encodingStyle, $unqualified);
6515
-                            }
6516
-                            elseif (isset($attrs['type']) || isset($attrs['ref']))
6517
-                            {
6518
-                                // serialize schema-defined type
6519
-                                $xml .= $this->serializeType ($eName,
6520
-                                                              isset($attrs['type']) ? $attrs['type'] : $attrs['ref'],
6521
-                                                              $v, $use, $encodingStyle, $unqualified);
6522
-                            }
6523
-                            else
6524
-                            {
6525
-                                // serialize generic type (can this ever really happen?)
6526
-                                $this->debug ("calling serialize_val() for $v, $eName, false, false, false, false, $use");
6527
-                                $xml .= $this->serialize_val ($v, $eName, false, false, false, false, $use);
6528
-                            }
6529
-                        }
6530
-                    }
6531
-                }
6532
-            }
6533
-        } else {
6534
-            $this->debug("no elements to serialize for XML Schema type $ns:$uqType");
6535
-        }
6536
-        return $xml;
6537
-    }
6538
-
6539
-    /**
6540
-     * adds an XML Schema complex type to the WSDL types
6541
-     *
6542
-     * @param string $name
6543
-     * @param string $typeClass (complexType|simpleType|attribute)
6544
-     * @param string $phpType currently supported are array and struct (php assoc array)
6545
-     * @param string $compositor (all|sequence|choice)
6546
-     * @param string $restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
6547
-     * @param array $elements e.g. array ( name => array(name=>'',type=>'') )
6548
-     * @param array $attrs e.g. array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'xsd:string[]'))
6549
-     * @param string $arrayType as namespace:name (xsd:string)
6550
-     * @see nusoap_xmlschema
6551
-     * @access public
6552
-     */
6553
-    function addComplexType($name, $typeClass = 'complexType', $phpType = 'array', $compositor = '', $restrictionBase = '', $elements = array(), $attrs = array(), $arrayType = '')
6554
-    {
6555
-        if (count($elements) > 0) {
6556
-            $eElements = array();
6557
-            foreach ($elements as $n => $e) {
6558
-                // expand each element
6559
-                $ee = array();
6560
-                foreach ($e as $k => $v) {
6561
-                    $k = strpos($k, ':') ? $this->expandQname($k) : $k;
6562
-                    $v = strpos($v, ':') ? $this->expandQname($v) : $v;
6563
-                    $ee[$k] = $v;
6564
-                }
6565
-                $eElements[$n] = $ee;
6566
-            }
6567
-            $elements = $eElements;
6568
-        }
6569
-
6570
-        if (is_array($attrs) && count($attrs) > 0) {
6571
-            $eAttrs = array ();
6572
-            foreach ($attrs as $n => $a) {
6573
-                $aa = array ();
6574
-                // expand each attribute
6575
-                foreach ($a as $k => $v) {
6576
-                    $k = strpos($k, ':') ? $this->expandQname($k) : $k;
6577
-                    $v = strpos($v, ':') ? $this->expandQname($v) : $v;
6578
-                    $aa[$k] = $v;
6579
-                }
6580
-                $eAttrs[$n] = $aa;
6581
-            }
6582
-            $attrs = $eAttrs;
6583
-        }
6584
-
6585
-        $restrictionBase = strpos($restrictionBase, ':') ? $this->expandQname($restrictionBase) : $restrictionBase;
6586
-        $arrayType = strpos($arrayType, ':') ? $this->expandQname($arrayType) : $arrayType;
6587
-
6588
-        $typens = isset($this->namespaces['types']) ? $this->namespaces['types'] : $this->namespaces['tns'];
6589
-        $this->schemas[$typens][0]->addComplexType($name, $typeClass, $phpType, $compositor, $restrictionBase, $elements, $attrs, $arrayType);
6590
-    }
6591
-
6592
-    /**
6593
-     * adds an XML Schema simple type to the WSDL types
6594
-     *
6595
-     * @param string $name
6596
-     * @param string $restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
6597
-     * @param string $typeClass (should always be simpleType)
6598
-     * @param string $phpType (should always be scalar)
6599
-     * @param array $enumeration array of values
6600
-     * @see nusoap_xmlschema
6601
-     * @access public
6602
-     */
6603
-    function addSimpleType($name, $restrictionBase = '', $typeClass = 'simpleType', $phpType = 'scalar', $enumeration = array())
6604
-    {
6605
-        $restrictionBase = strpos($restrictionBase, ':') ? $this->expandQname($restrictionBase) : $restrictionBase;
6606
-
6607
-        $typens = isset($this->namespaces['types']) ? $this->namespaces['types'] : $this->namespaces['tns'];
6608
-        $this->schemas[$typens][0]->addSimpleType($name, $restrictionBase, $typeClass, $phpType, $enumeration);
6609
-    }
6610
-
6611
-    /**
6612
-     * adds an element to the WSDL types
6613
-     *
6614
-     * @param array $attrs attributes that must include name and type
6615
-     * @see nusoap_xmlschema
6616
-     * @access public
6617
-     */
6618
-    function addElement($attrs)
6619
-    {
6620
-        $typens = isset($this->namespaces['types']) ? $this->namespaces['types'] : $this->namespaces['tns'];
6621
-        $this->schemas[$typens][0]->addElement($attrs);
6622
-    }
6623
-
6624
-    /**
6625
-     * register an operation with the server
6626
-     *
6627
-     * @param string $name operation (method) name
6628
-     * @param array $in assoc array of input values: key = param name, value = param type
6629
-     * @param array $out assoc array of output values: key = param name, value = param type
6630
-     * @param string $namespace optional The namespace for the operation
6631
-     * @param string $soapaction optional The soapaction for the operation
6632
-     * @param string $style (rpc|document) optional The style for the operation Note: when 'document' is specified, parameter and return wrappers are created for you automatically
6633
-     * @param string $use (encoded|literal) optional The use for the parameters (cannot mix right now)
6634
-     * @param string $documentation optional The description to include in the WSDL
6635
-     * @param string $encodingStyle optional (usually 'http://schemas.xmlsoap.org/soap/encoding/' for encoded)
6636
-     * @param string $customResponseTagName optional Name of the outgoing response
6637
-     * @access public
6638
-     */
6639
-    function addOperation($name, $in = false, $out = false, $namespace = false, $soapaction = false, $style = 'rpc', $use = 'encoded', $documentation = '', $encodingStyle = '', $customResponseTagName = '')
6640
-    {
6641
-        if ($use == 'encoded' && $encodingStyle == '') {
6642
-            $encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/';
6643
-        }
6644
-
6645
-        if ($style == 'document') {
6646
-            $elements = array();
6647
-            foreach ($in as $n => $t) {
6648
-                $elements[$n] = array('name' => $n, 'type' => $t, 'form' => 'unqualified');
6649
-            }
6650
-            $this->addComplexType($name . 'RequestType', 'complexType', 'struct', 'all', '', $elements);
6651
-            $this->addElement(array('name' => $name, 'type' => $name . 'RequestType'));
6652
-            $in = array('parameters' => 'tns:' . $name . '^');
6653
-
6654
-            $elements = array();
6655
-            foreach ($out as $n => $t) {
6656
-                $elements[$n] = array('name' => $n, 'type' => $t, 'form' => 'unqualified');
6657
-            }
6658
-            $this->addComplexType($name . 'ResponseType', 'complexType', 'struct', 'all', '', $elements);
6659
-            $this->addElement(array('name' => $customResponseTagName, 'type' => $name . 'ResponseType', 'form' => 'qualified'));
6660
-            $out = array('parameters' => 'tns:' . $customResponseTagName . '^');
6661
-        }
6662
-
6663
-        // get binding
6664
-        $this->bindings[$this->serviceName . 'Binding']['operations'][$name] =
6665
-            array(
6666
-                'name' => $name,
6667
-                'binding' => $this->serviceName . 'Binding',
6668
-                'endpoint' => $this->endpoint,
6669
-                'soapAction' => $soapaction,
6670
-                'style' => $style,
6671
-                'input' => array(
6672
-                    'use' => $use,
6673
-                    'namespace' => $namespace,
6674
-                    'encodingStyle' => $encodingStyle,
6675
-                    'message' => $name,
6676
-                    'parts' => $in),
6677
-                'output' => array(
6678
-                    'use' => $use,
6679
-                    'namespace' => $namespace,
6680
-                    'encodingStyle' => $encodingStyle,
6681
-                    'message' => $customResponseTagName,
6682
-                    'parts' => $out),
6683
-                'namespace' => $namespace,
6684
-                'transport' => 'http://schemas.xmlsoap.org/soap/http',
6685
-                'documentation' => $documentation);
6686
-        // add portTypes
6687
-        // add messages
6688
-        if ($in) {
6689
-            foreach ($in as $pName => $pType) {
6690
-                if (strpos($pType, ':')) {
6691
-                    $pType = $this->getNamespaceFromPrefix($this->getPrefix($pType)) . ":" . $this->getLocalPart($pType);
6692
-                }
6693
-                $this->messages[$name][$pName] = $pType;
6694
-            }
6695
-        } else {
6696
-            $this->messages[$name] = '0';
6697
-        }
6698
-        if ($out) {
6699
-            foreach ($out as $pName => $pType) {
6700
-                if (strpos($pType, ':')) {
6701
-                    $pType = $this->getNamespaceFromPrefix($this->getPrefix($pType)) . ":" . $this->getLocalPart($pType);
6702
-                }
6703
-                $this->messages[$customResponseTagName][$pName] = $pType;
6704
-            }
6705
-        } else {
6706
-            $this->messages[$customResponseTagName] = '0';
6707
-        }
6708
-        return true;
6709
-    }
6708
+		return true;
6709
+	}
6710 6710
 }
6711 6711
 
6712 6712
 
@@ -6722,316 +6722,316 @@  discard block
 block discarded – undo
6722 6722
 class nusoap_parser extends nusoap_base
6723 6723
 {
6724 6724
 
6725
-    var $parser = null;
6726
-    var $methodNamespace = '';
6727
-    var $xml = '';
6728
-    var $xml_encoding = '';
6729
-    var $method = '';
6730
-    var $root_struct = '';
6731
-    var $root_struct_name = '';
6732
-    var $root_struct_namespace = '';
6733
-    var $root_header = '';
6734
-    var $document = '';            // incoming SOAP body (text)
6735
-    // determines where in the message we are (envelope,header,body,method)
6736
-    var $status = '';
6737
-    var $position = 0;
6738
-    var $depth = 0;
6739
-    var $default_namespace = '';
6740
-    var $namespaces = array();
6741
-    var $message = array();
6742
-    var $parent = '';
6743
-    var $fault = false;
6744
-    var $fault_code = '';
6745
-    var $fault_str = '';
6746
-    var $fault_detail = '';
6747
-    var $depth_array = array();
6748
-    var $debug_flag = true;
6749
-    var $soapresponse = null;    // parsed SOAP Body
6750
-    var $soapheader = null;        // parsed SOAP Header
6751
-    var $responseHeaders = '';    // incoming SOAP headers (text)
6752
-    var $body_position = 0;
6753
-    // for multiref parsing:
6754
-    // array of id => pos
6755
-    var $ids = array();
6756
-    // array of id => hrefs => pos
6757
-    var $multirefs = array();
6758
-    // toggle for auto-decoding element content
6759
-    var $decode_utf8 = true;
6760
-
6761
-    var $attachments = array();
6762
-
6763
-    /**
6764
-     * constructor that actually does the parsing
6765
-     *
6766
-     * @param    string $xml SOAP message
6767
-     * @param    string $encoding character encoding scheme of message
6768
-     * @param    string $method method for which XML is parsed (unused?)
6769
-     * @param    string $decode_utf8 whether to decode UTF-8 to ISO-8859-1
6770
-     * @access   public
6771
-     */
6772
-    function __construct($xml, $encoding = 'UTF-8', $method = '', $decode_utf8 = true)
6773
-    {
6774
-        parent::__construct();
6775
-        $this->xml = $xml;
6776
-        $this->xml_encoding = $encoding;
6777
-        $this->method = $method;
6778
-        $this->decode_utf8 = $decode_utf8;
6779
-        $this->attachments = array();
6780
-
6781
-        // Check whether content has been read.
6782
-        if (!empty($xml)) {
6783
-            // Check XML encoding
6784
-            $pos_xml = strpos($xml, '<?xml');
6785
-            if ($pos_xml !== false) {
6786
-                $xml_decl = substr($xml, $pos_xml, strpos($xml, '?>', $pos_xml + 2) - $pos_xml + 1);
6787
-                if (preg_match("/encoding=[\"']([^\"']*)[\"']/", $xml_decl, $res)) {
6788
-                    $xml_encoding = $res[1];
6789
-                    if (strtoupper($xml_encoding) != $encoding) {
6790
-                        $err = "Charset from HTTP Content-Type '" . $encoding . "' does not match encoding from XML declaration '" . $xml_encoding . "'";
6791
-                        $this->debug($err);
6792
-                        if ($encoding != 'ISO-8859-1' || strtoupper($xml_encoding) != 'UTF-8') {
6793
-                            $this->setError($err);
6794
-                            return;
6795
-                        }
6796
-                        // when HTTP says ISO-8859-1 (the default) and XML says UTF-8 (the typical), assume the other endpoint is just sloppy and proceed
6797
-                    } else {
6798
-                        $this->debug('Charset from HTTP Content-Type matches encoding from XML declaration');
6799
-                    }
6800
-                } else {
6801
-                    $this->debug('No encoding specified in XML declaration');
6802
-                }
6803
-            } else {
6804
-                $this->debug('No XML declaration');
6805
-            }
6806
-            $this->debug('Entering nusoap_parser(), length=' . strlen($xml) . ', encoding=' . $encoding);
6807
-            // Create an XML parser - why not xml_parser_create_ns?
6808
-            $this->parser = xml_parser_create($this->xml_encoding);
6809
-            // Set the options for parsing the XML data.
6810
-            //xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
6811
-            xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
6812
-            xml_parser_set_option($this->parser, XML_OPTION_TARGET_ENCODING, $this->xml_encoding);
6813
-            // Set the object for the parser.
6814
-            xml_set_object($this->parser, $this);
6815
-            // Set the element handlers for the parser.
6816
-            xml_set_element_handler($this->parser, 'start_element', 'end_element');
6817
-            xml_set_character_data_handler($this->parser, 'character_data');
6818
-            $parseErrors = array();
6819
-            $chunkSize = 4096;
6820
-            for($pointer = 0; $pointer < strlen($xml) && empty($parseErrors); $pointer += $chunkSize) {
6821
-            	$xmlString = substr($xml, $pointer, $chunkSize);
6822
-            	if(!xml_parse($this->parser, $xmlString)) {
6823
-            		$parseErrors['lineNumber'] = xml_get_current_line_number($this->parser);
6824
-            		$parseErrors['errorString'] = xml_error_string(xml_get_error_code($this->parser));
6825
-            	}
6826
-            }
6827
-            //Tell the script that is the end of the parsing (by setting is_final to TRUE)
6828
-            xml_parse($this->parser, '', true);
6829
-
6830
-            // Check if there is any attachment
6831
-            $this->attachments = array();
6832
-            foreach(preg_split("/((\r?\n)|(\r\n?))/", $xml) as $line){
6833
-                if(preg_match(("/^--(.*)/"), $line, $matches)) {
6834
-                    $this->attachments[] = array ();
6835
-                    $this->attachments[count($this->attachments)-1]['boundaryStr'] = $matches[1];
6836
-                } elseif(preg_match(("/Content-Type:(.*)/"), $line, $matches)) {
6837
-                    $this->attachments[count($this->attachments)-1]['Content-Type'] = $matches[1];
6838
-                } elseif(preg_match(("/Content-Id:(.*)/"), $line, $matches)) {
6839
-                    $this->attachments[count($this->attachments)-1]['Content-Id'] = $matches[1];
6840
-                } elseif(preg_match(("/Content-Transfer-Encoding:(.*)/"), $line, $matches)) {
6841
-                    $this->attachments[count($this->attachments)-1]['Content-Transfer-Encoding'] = $matches[1];
6842
-                }
6843
-            }
6844
-
6845
-            if(!empty($this->attachments)) {
6846
-                // Extract the content of each attachments
6847
-                $substrXml = $xml;
6848
-                foreach($this->attachments as $key => $attachment) {
6849
-                    $startPos = max(
6850
-                        stripos($substrXml, $attachment['boundaryStr']),
6851
-                        (array_key_exists('Content-Type', $attachment) ? stripos($substrXml, $attachment['Content-Type']) : 0),
6852
-                        (array_key_exists('Content-Id', $attachment) ? stripos($substrXml, $attachment['Content-Id']) : 0),
6853
-                        (array_key_exists('Content-Transfer-Encoding', $attachment) ? stripos($substrXml, $attachment['Content-Transfer-Encoding']) : 0)
6854
-                    );
6855
-                    $substrXml = substr($substrXml, $startPos);
6856
-                    $startPos = stripos($substrXml, PHP_EOL);
6857
-                    $substrXml = substr($substrXml, $startPos);
6858
-                    $substrXml = trim($substrXml);
6859
-                    $length = null;
6860
-                    if(array_key_exists($key+1, $this->attachments) && $this->attachments[$key+1] && !empty($this->attachments[$key+1]['boundaryStr'])) {
6861
-                        $length = stripos($substrXml, ('--' . $this->attachments[$key+1]['boundaryStr']))-1;
6862
-                    }
6863
-                    $content = substr($substrXml, 0, $length);
6864
-                    $this->attachments[$key]['content'] = $content;
6865
-                }
6866
-            }
6867
-
6868
-            if(!empty($parseErrors) && !empty($this->attachments)){
6869
-                // Search the SOAP response message
6870
-                foreach($this->attachments as $key => $attachment) {
6871
-                    // Settings for xml_parse
6872
-                    $this->parser = xml_parser_create($this->xml_encoding);
6873
-                    xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
6874
-                    xml_parser_set_option($this->parser, XML_OPTION_TARGET_ENCODING, $this->xml_encoding);
6875
-                    xml_set_object($this->parser, $this);
6876
-                    xml_set_element_handler($this->parser, 'start_element', 'end_element');
6877
-                    xml_set_character_data_handler($this->parser, 'character_data');
6878
-
6879
-                    if(!empty($attachment['content'])) {
6880
-                        $content = $attachment['content'];
6881
-                        foreach(preg_split("/((\r?\n)|(\r\n?))/", $content) as $line){
6882
-                            if(preg_match(("/:Envelope/"), $line, $matches)) {
6883
-                                if(!xml_parse($this->parser, $content, true)) {
6884
-                                    $parseErrors['lineNumber'] = xml_get_current_line_number($this->parser);
6885
-                                    $parseErrors['errorString'] = xml_error_string(xml_get_error_code($this->parser));
6886
-                                } else {
6887
-                                    $parseErrors = array();
6888
-                                    unset($this->attachments[$key]);
6889
-                                    break 2;
6890
-                                }
6891
-                            }
6892
-                        }
6893
-                    }
6894
-                }
6895
-            }
6896
-
6897
-            if(!empty($parseErrors)){
6898
-            	// Display an error message.
6899
-            	$err = sprintf('XML error parsing SOAP payload on line %d: %s',
6900
-            			$parseErrors['lineNumber'],
6901
-            			$parseErrors['errorString']);
6902
-            	$this->debug($err);
6903
-            	$this->setError($err);
6904
-            } else {
6905
-                $this->debug('in nusoap_parser ctor, message:');
6906
-                $this->appendDebug($this->varDump($this->message));
6907
-                $this->debug('parsed successfully, found root struct: ' . $this->root_struct . ' of name ' . $this->root_struct_name);
6908
-                // get final value
6909
-                $this->soapresponse = $this->message[$this->root_struct]['result'];
6910
-                // get header value
6911
-                if ($this->root_header != '' && isset($this->message[$this->root_header]['result'])) {
6912
-                    $this->soapheader = $this->message[$this->root_header]['result'];
6913
-                }
6914
-                // resolve hrefs/ids
6915
-                if (sizeof($this->multirefs) > 0) {
6916
-                    foreach ($this->multirefs as $id => $hrefs) {
6917
-                        $this->debug('resolving multirefs for id: ' . $id);
6918
-                        $idVal = $this->buildVal($this->ids[$id]);
6919
-                        if (is_array($idVal) && isset($idVal['!id'])) {
6920
-                            unset($idVal['!id']);
6921
-                        }
6922
-                        foreach ($hrefs as $refPos => $ref) {
6923
-                            $this->debug('resolving href at pos ' . $refPos);
6924
-                            $this->multirefs[$id][$refPos] = $idVal;
6925
-                        }
6926
-                    }
6927
-                }
6928
-            }
6929
-            xml_parser_free($this->parser);
6930
-            unset($this->parser);
6931
-        } else {
6932
-            $this->debug('xml was empty, didn\'t parse!');
6933
-            $this->setError('xml was empty, didn\'t parse!');
6934
-        }
6935
-    }
6936
-
6937
-    /**
6938
-     * start-element handler
6939
-     *
6940
-     * @param    resource $parser XML parser object
6941
-     * @param    string $name element name
6942
-     * @param    array $attrs associative array of attributes
6943
-     * @access   private
6944
-     */
6945
-    function start_element($parser, $name, $attrs)
6946
-    {
6947
-        // position in a total number of elements, starting from 0
6948
-        // update class level pos
6949
-        $pos = $this->position++;
6950
-        // and set mine
6951
-        $this->message[$pos] = array('pos' => $pos, 'children' => '', 'cdata' => '');
6952
-        // depth = how many levels removed from root?
6953
-        // set mine as current global depth and increment global depth value
6954
-        $this->message[$pos]['depth'] = $this->depth++;
6955
-
6956
-        // else add self as child to whoever the current parent is
6957
-        if ($pos != 0) {
6958
-            $this->message[$this->parent]['children'] .= '|' . $pos;
6959
-        }
6960
-        // set my parent
6961
-        $this->message[$pos]['parent'] = $this->parent;
6962
-        // set self as current parent
6963
-        $this->parent = $pos;
6964
-        // set self as current value for this depth
6965
-        $this->depth_array[$this->depth] = $pos;
6966
-        // get element prefix
6967
-        if (strpos($name, ':')) {
6968
-            // get ns prefix
6969
-            $prefix = substr($name, 0, strpos($name, ':'));
6970
-            // get unqualified name
6971
-            $name = substr(strstr($name, ':'), 1);
6972
-        }
6973
-        // set status
6974
-        if ($name == 'Envelope' && $this->status == '') {
6975
-            $this->status = 'envelope';
6976
-        } elseif ($name == 'Header' && $this->status == 'envelope') {
6977
-            $this->root_header = $pos;
6978
-            $this->status = 'header';
6979
-        } elseif ($name == 'Body' && $this->status == 'envelope') {
6980
-            $this->status = 'body';
6981
-            $this->body_position = $pos;
6982
-            // set method
6983
-        } elseif ($this->status == 'body' && $pos == ($this->body_position + 1)) {
6984
-            $this->status = 'method';
6985
-            $this->root_struct_name = $name;
6986
-            $this->root_struct = $pos;
6987
-            $this->message[$pos]['type'] = 'struct';
6988
-            $this->debug("found root struct $this->root_struct_name, pos $this->root_struct");
6989
-        }
6990
-        // set my status
6991
-        $this->message[$pos]['status'] = $this->status;
6992
-        // set name
6993
-        $this->message[$pos]['name'] = htmlspecialchars($name);
6994
-        // set attrs
6995
-        $this->message[$pos]['attrs'] = $attrs;
6996
-
6997
-        // loop through atts, logging ns and type declarations
6998
-        $attstr = '';
6999
-        foreach ($attrs as $key => $value) {
7000
-            $key_prefix = $this->getPrefix($key);
7001
-            $key_localpart = $this->getLocalPart($key);
7002
-            // if ns declarations, add to class level array of valid namespaces
7003
-            if ($key_prefix == 'xmlns') {
7004
-                if (preg_match('/^http:\/\/www.w3.org\/[0-9]{4}\/XMLSchema$/', $value)) {
7005
-                    $this->XMLSchemaVersion = $value;
7006
-                    $this->namespaces['xsd'] = $this->XMLSchemaVersion;
7007
-                    $this->namespaces['xsi'] = $this->XMLSchemaVersion . '-instance';
7008
-                }
7009
-                $this->namespaces[$key_localpart] = $value;
7010
-                // set method namespace
7011
-                if ($name == $this->root_struct_name) {
7012
-                    $this->methodNamespace = $value;
7013
-                }
7014
-                // if it's a type declaration, set type
7015
-            } elseif ($key_localpart == 'type') {
7016
-                if (!isset($this->message[$pos]['type']) || $this->message[$pos]['type'] != 'array')
7017
-                {
7018
-                    $value_prefix = $this->getPrefix ($value);
7019
-                    $value_localpart = $this->getLocalPart ($value);
7020
-                    $this->message[$pos]['type'] = $value_localpart;
7021
-                    $this->message[$pos]['typePrefix'] = $value_prefix;
7022
-                    if (isset($this->namespaces[$value_prefix]))
7023
-                    {
7024
-                        $this->message[$pos]['type_namespace'] = $this->namespaces[$value_prefix];
7025
-                    }
7026
-                    elseif (isset($attrs['xmlns:' . $value_prefix]))
7027
-                    {
7028
-                        $this->message[$pos]['type_namespace'] = $attrs['xmlns:' . $value_prefix];
7029
-                    }
7030
-                    // should do something here with the namespace of specified type?
7031
-                }
7032
-            } elseif ($key_localpart == 'arrayType') {
7033
-                $this->message[$pos]['type'] = 'array';
7034
-                /* do arrayType ereg here
6725
+	var $parser = null;
6726
+	var $methodNamespace = '';
6727
+	var $xml = '';
6728
+	var $xml_encoding = '';
6729
+	var $method = '';
6730
+	var $root_struct = '';
6731
+	var $root_struct_name = '';
6732
+	var $root_struct_namespace = '';
6733
+	var $root_header = '';
6734
+	var $document = '';            // incoming SOAP body (text)
6735
+	// determines where in the message we are (envelope,header,body,method)
6736
+	var $status = '';
6737
+	var $position = 0;
6738
+	var $depth = 0;
6739
+	var $default_namespace = '';
6740
+	var $namespaces = array();
6741
+	var $message = array();
6742
+	var $parent = '';
6743
+	var $fault = false;
6744
+	var $fault_code = '';
6745
+	var $fault_str = '';
6746
+	var $fault_detail = '';
6747
+	var $depth_array = array();
6748
+	var $debug_flag = true;
6749
+	var $soapresponse = null;    // parsed SOAP Body
6750
+	var $soapheader = null;        // parsed SOAP Header
6751
+	var $responseHeaders = '';    // incoming SOAP headers (text)
6752
+	var $body_position = 0;
6753
+	// for multiref parsing:
6754
+	// array of id => pos
6755
+	var $ids = array();
6756
+	// array of id => hrefs => pos
6757
+	var $multirefs = array();
6758
+	// toggle for auto-decoding element content
6759
+	var $decode_utf8 = true;
6760
+
6761
+	var $attachments = array();
6762
+
6763
+	/**
6764
+	 * constructor that actually does the parsing
6765
+	 *
6766
+	 * @param    string $xml SOAP message
6767
+	 * @param    string $encoding character encoding scheme of message
6768
+	 * @param    string $method method for which XML is parsed (unused?)
6769
+	 * @param    string $decode_utf8 whether to decode UTF-8 to ISO-8859-1
6770
+	 * @access   public
6771
+	 */
6772
+	function __construct($xml, $encoding = 'UTF-8', $method = '', $decode_utf8 = true)
6773
+	{
6774
+		parent::__construct();
6775
+		$this->xml = $xml;
6776
+		$this->xml_encoding = $encoding;
6777
+		$this->method = $method;
6778
+		$this->decode_utf8 = $decode_utf8;
6779
+		$this->attachments = array();
6780
+
6781
+		// Check whether content has been read.
6782
+		if (!empty($xml)) {
6783
+			// Check XML encoding
6784
+			$pos_xml = strpos($xml, '<?xml');
6785
+			if ($pos_xml !== false) {
6786
+				$xml_decl = substr($xml, $pos_xml, strpos($xml, '?>', $pos_xml + 2) - $pos_xml + 1);
6787
+				if (preg_match("/encoding=[\"']([^\"']*)[\"']/", $xml_decl, $res)) {
6788
+					$xml_encoding = $res[1];
6789
+					if (strtoupper($xml_encoding) != $encoding) {
6790
+						$err = "Charset from HTTP Content-Type '" . $encoding . "' does not match encoding from XML declaration '" . $xml_encoding . "'";
6791
+						$this->debug($err);
6792
+						if ($encoding != 'ISO-8859-1' || strtoupper($xml_encoding) != 'UTF-8') {
6793
+							$this->setError($err);
6794
+							return;
6795
+						}
6796
+						// when HTTP says ISO-8859-1 (the default) and XML says UTF-8 (the typical), assume the other endpoint is just sloppy and proceed
6797
+					} else {
6798
+						$this->debug('Charset from HTTP Content-Type matches encoding from XML declaration');
6799
+					}
6800
+				} else {
6801
+					$this->debug('No encoding specified in XML declaration');
6802
+				}
6803
+			} else {
6804
+				$this->debug('No XML declaration');
6805
+			}
6806
+			$this->debug('Entering nusoap_parser(), length=' . strlen($xml) . ', encoding=' . $encoding);
6807
+			// Create an XML parser - why not xml_parser_create_ns?
6808
+			$this->parser = xml_parser_create($this->xml_encoding);
6809
+			// Set the options for parsing the XML data.
6810
+			//xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
6811
+			xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
6812
+			xml_parser_set_option($this->parser, XML_OPTION_TARGET_ENCODING, $this->xml_encoding);
6813
+			// Set the object for the parser.
6814
+			xml_set_object($this->parser, $this);
6815
+			// Set the element handlers for the parser.
6816
+			xml_set_element_handler($this->parser, 'start_element', 'end_element');
6817
+			xml_set_character_data_handler($this->parser, 'character_data');
6818
+			$parseErrors = array();
6819
+			$chunkSize = 4096;
6820
+			for($pointer = 0; $pointer < strlen($xml) && empty($parseErrors); $pointer += $chunkSize) {
6821
+				$xmlString = substr($xml, $pointer, $chunkSize);
6822
+				if(!xml_parse($this->parser, $xmlString)) {
6823
+					$parseErrors['lineNumber'] = xml_get_current_line_number($this->parser);
6824
+					$parseErrors['errorString'] = xml_error_string(xml_get_error_code($this->parser));
6825
+				}
6826
+			}
6827
+			//Tell the script that is the end of the parsing (by setting is_final to TRUE)
6828
+			xml_parse($this->parser, '', true);
6829
+
6830
+			// Check if there is any attachment
6831
+			$this->attachments = array();
6832
+			foreach(preg_split("/((\r?\n)|(\r\n?))/", $xml) as $line){
6833
+				if(preg_match(("/^--(.*)/"), $line, $matches)) {
6834
+					$this->attachments[] = array ();
6835
+					$this->attachments[count($this->attachments)-1]['boundaryStr'] = $matches[1];
6836
+				} elseif(preg_match(("/Content-Type:(.*)/"), $line, $matches)) {
6837
+					$this->attachments[count($this->attachments)-1]['Content-Type'] = $matches[1];
6838
+				} elseif(preg_match(("/Content-Id:(.*)/"), $line, $matches)) {
6839
+					$this->attachments[count($this->attachments)-1]['Content-Id'] = $matches[1];
6840
+				} elseif(preg_match(("/Content-Transfer-Encoding:(.*)/"), $line, $matches)) {
6841
+					$this->attachments[count($this->attachments)-1]['Content-Transfer-Encoding'] = $matches[1];
6842
+				}
6843
+			}
6844
+
6845
+			if(!empty($this->attachments)) {
6846
+				// Extract the content of each attachments
6847
+				$substrXml = $xml;
6848
+				foreach($this->attachments as $key => $attachment) {
6849
+					$startPos = max(
6850
+						stripos($substrXml, $attachment['boundaryStr']),
6851
+						(array_key_exists('Content-Type', $attachment) ? stripos($substrXml, $attachment['Content-Type']) : 0),
6852
+						(array_key_exists('Content-Id', $attachment) ? stripos($substrXml, $attachment['Content-Id']) : 0),
6853
+						(array_key_exists('Content-Transfer-Encoding', $attachment) ? stripos($substrXml, $attachment['Content-Transfer-Encoding']) : 0)
6854
+					);
6855
+					$substrXml = substr($substrXml, $startPos);
6856
+					$startPos = stripos($substrXml, PHP_EOL);
6857
+					$substrXml = substr($substrXml, $startPos);
6858
+					$substrXml = trim($substrXml);
6859
+					$length = null;
6860
+					if(array_key_exists($key+1, $this->attachments) && $this->attachments[$key+1] && !empty($this->attachments[$key+1]['boundaryStr'])) {
6861
+						$length = stripos($substrXml, ('--' . $this->attachments[$key+1]['boundaryStr']))-1;
6862
+					}
6863
+					$content = substr($substrXml, 0, $length);
6864
+					$this->attachments[$key]['content'] = $content;
6865
+				}
6866
+			}
6867
+
6868
+			if(!empty($parseErrors) && !empty($this->attachments)){
6869
+				// Search the SOAP response message
6870
+				foreach($this->attachments as $key => $attachment) {
6871
+					// Settings for xml_parse
6872
+					$this->parser = xml_parser_create($this->xml_encoding);
6873
+					xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
6874
+					xml_parser_set_option($this->parser, XML_OPTION_TARGET_ENCODING, $this->xml_encoding);
6875
+					xml_set_object($this->parser, $this);
6876
+					xml_set_element_handler($this->parser, 'start_element', 'end_element');
6877
+					xml_set_character_data_handler($this->parser, 'character_data');
6878
+
6879
+					if(!empty($attachment['content'])) {
6880
+						$content = $attachment['content'];
6881
+						foreach(preg_split("/((\r?\n)|(\r\n?))/", $content) as $line){
6882
+							if(preg_match(("/:Envelope/"), $line, $matches)) {
6883
+								if(!xml_parse($this->parser, $content, true)) {
6884
+									$parseErrors['lineNumber'] = xml_get_current_line_number($this->parser);
6885
+									$parseErrors['errorString'] = xml_error_string(xml_get_error_code($this->parser));
6886
+								} else {
6887
+									$parseErrors = array();
6888
+									unset($this->attachments[$key]);
6889
+									break 2;
6890
+								}
6891
+							}
6892
+						}
6893
+					}
6894
+				}
6895
+			}
6896
+
6897
+			if(!empty($parseErrors)){
6898
+				// Display an error message.
6899
+				$err = sprintf('XML error parsing SOAP payload on line %d: %s',
6900
+						$parseErrors['lineNumber'],
6901
+						$parseErrors['errorString']);
6902
+				$this->debug($err);
6903
+				$this->setError($err);
6904
+			} else {
6905
+				$this->debug('in nusoap_parser ctor, message:');
6906
+				$this->appendDebug($this->varDump($this->message));
6907
+				$this->debug('parsed successfully, found root struct: ' . $this->root_struct . ' of name ' . $this->root_struct_name);
6908
+				// get final value
6909
+				$this->soapresponse = $this->message[$this->root_struct]['result'];
6910
+				// get header value
6911
+				if ($this->root_header != '' && isset($this->message[$this->root_header]['result'])) {
6912
+					$this->soapheader = $this->message[$this->root_header]['result'];
6913
+				}
6914
+				// resolve hrefs/ids
6915
+				if (sizeof($this->multirefs) > 0) {
6916
+					foreach ($this->multirefs as $id => $hrefs) {
6917
+						$this->debug('resolving multirefs for id: ' . $id);
6918
+						$idVal = $this->buildVal($this->ids[$id]);
6919
+						if (is_array($idVal) && isset($idVal['!id'])) {
6920
+							unset($idVal['!id']);
6921
+						}
6922
+						foreach ($hrefs as $refPos => $ref) {
6923
+							$this->debug('resolving href at pos ' . $refPos);
6924
+							$this->multirefs[$id][$refPos] = $idVal;
6925
+						}
6926
+					}
6927
+				}
6928
+			}
6929
+			xml_parser_free($this->parser);
6930
+			unset($this->parser);
6931
+		} else {
6932
+			$this->debug('xml was empty, didn\'t parse!');
6933
+			$this->setError('xml was empty, didn\'t parse!');
6934
+		}
6935
+	}
6936
+
6937
+	/**
6938
+	 * start-element handler
6939
+	 *
6940
+	 * @param    resource $parser XML parser object
6941
+	 * @param    string $name element name
6942
+	 * @param    array $attrs associative array of attributes
6943
+	 * @access   private
6944
+	 */
6945
+	function start_element($parser, $name, $attrs)
6946
+	{
6947
+		// position in a total number of elements, starting from 0
6948
+		// update class level pos
6949
+		$pos = $this->position++;
6950
+		// and set mine
6951
+		$this->message[$pos] = array('pos' => $pos, 'children' => '', 'cdata' => '');
6952
+		// depth = how many levels removed from root?
6953
+		// set mine as current global depth and increment global depth value
6954
+		$this->message[$pos]['depth'] = $this->depth++;
6955
+
6956
+		// else add self as child to whoever the current parent is
6957
+		if ($pos != 0) {
6958
+			$this->message[$this->parent]['children'] .= '|' . $pos;
6959
+		}
6960
+		// set my parent
6961
+		$this->message[$pos]['parent'] = $this->parent;
6962
+		// set self as current parent
6963
+		$this->parent = $pos;
6964
+		// set self as current value for this depth
6965
+		$this->depth_array[$this->depth] = $pos;
6966
+		// get element prefix
6967
+		if (strpos($name, ':')) {
6968
+			// get ns prefix
6969
+			$prefix = substr($name, 0, strpos($name, ':'));
6970
+			// get unqualified name
6971
+			$name = substr(strstr($name, ':'), 1);
6972
+		}
6973
+		// set status
6974
+		if ($name == 'Envelope' && $this->status == '') {
6975
+			$this->status = 'envelope';
6976
+		} elseif ($name == 'Header' && $this->status == 'envelope') {
6977
+			$this->root_header = $pos;
6978
+			$this->status = 'header';
6979
+		} elseif ($name == 'Body' && $this->status == 'envelope') {
6980
+			$this->status = 'body';
6981
+			$this->body_position = $pos;
6982
+			// set method
6983
+		} elseif ($this->status == 'body' && $pos == ($this->body_position + 1)) {
6984
+			$this->status = 'method';
6985
+			$this->root_struct_name = $name;
6986
+			$this->root_struct = $pos;
6987
+			$this->message[$pos]['type'] = 'struct';
6988
+			$this->debug("found root struct $this->root_struct_name, pos $this->root_struct");
6989
+		}
6990
+		// set my status
6991
+		$this->message[$pos]['status'] = $this->status;
6992
+		// set name
6993
+		$this->message[$pos]['name'] = htmlspecialchars($name);
6994
+		// set attrs
6995
+		$this->message[$pos]['attrs'] = $attrs;
6996
+
6997
+		// loop through atts, logging ns and type declarations
6998
+		$attstr = '';
6999
+		foreach ($attrs as $key => $value) {
7000
+			$key_prefix = $this->getPrefix($key);
7001
+			$key_localpart = $this->getLocalPart($key);
7002
+			// if ns declarations, add to class level array of valid namespaces
7003
+			if ($key_prefix == 'xmlns') {
7004
+				if (preg_match('/^http:\/\/www.w3.org\/[0-9]{4}\/XMLSchema$/', $value)) {
7005
+					$this->XMLSchemaVersion = $value;
7006
+					$this->namespaces['xsd'] = $this->XMLSchemaVersion;
7007
+					$this->namespaces['xsi'] = $this->XMLSchemaVersion . '-instance';
7008
+				}
7009
+				$this->namespaces[$key_localpart] = $value;
7010
+				// set method namespace
7011
+				if ($name == $this->root_struct_name) {
7012
+					$this->methodNamespace = $value;
7013
+				}
7014
+				// if it's a type declaration, set type
7015
+			} elseif ($key_localpart == 'type') {
7016
+				if (!isset($this->message[$pos]['type']) || $this->message[$pos]['type'] != 'array')
7017
+				{
7018
+					$value_prefix = $this->getPrefix ($value);
7019
+					$value_localpart = $this->getLocalPart ($value);
7020
+					$this->message[$pos]['type'] = $value_localpart;
7021
+					$this->message[$pos]['typePrefix'] = $value_prefix;
7022
+					if (isset($this->namespaces[$value_prefix]))
7023
+					{
7024
+						$this->message[$pos]['type_namespace'] = $this->namespaces[$value_prefix];
7025
+					}
7026
+					elseif (isset($attrs['xmlns:' . $value_prefix]))
7027
+					{
7028
+						$this->message[$pos]['type_namespace'] = $attrs['xmlns:' . $value_prefix];
7029
+					}
7030
+					// should do something here with the namespace of specified type?
7031
+				}
7032
+			} elseif ($key_localpart == 'arrayType') {
7033
+				$this->message[$pos]['type'] = 'array';
7034
+				/* do arrayType ereg here
7035 7035
 				[1]    arrayTypeValue    ::=    atype asize
7036 7036
 				[2]    atype    ::=    QName rank*
7037 7037
 				[3]    rank    ::=    '[' (',')* ']'
@@ -7039,402 +7039,402 @@  discard block
 block discarded – undo
7039 7039
 				[5]    length    ::=    nextDimension* Digit+
7040 7040
 				[6]    nextDimension    ::=    Digit+ ','
7041 7041
 				*/
7042
-                $expr = '/([A-Za-z0-9_]+):([A-Za-z]+[A-Za-z0-9_]+)\[([0-9]+),?([0-9]*)\]/';
7043
-                if (preg_match($expr, $value, $regs)) {
7044
-                    $this->message[$pos]['typePrefix'] = $regs[1];
7045
-                    $this->message[$pos]['arrayTypePrefix'] = $regs[1];
7046
-                    if (isset($this->namespaces[$regs[1]])) {
7047
-                        $this->message[$pos]['arrayTypeNamespace'] = $this->namespaces[$regs[1]];
7048
-                    } elseif (isset($attrs['xmlns:' . $regs[1]])) {
7049
-                        $this->message[$pos]['arrayTypeNamespace'] = $attrs['xmlns:' . $regs[1]];
7050
-                    }
7051
-                    $this->message[$pos]['arrayType'] = $regs[2];
7052
-                    $this->message[$pos]['arraySize'] = $regs[3];
7053
-                    $this->message[$pos]['arrayCols'] = $regs[4];
7054
-                }
7055
-                // specifies nil value (or not)
7056
-            } elseif ($key_localpart == 'nil') {
7057
-                $this->message[$pos]['nil'] = ($value == 'true' || $value == '1');
7058
-                // some other attribute
7059
-            } elseif ($key != 'href' && $key != 'xmlns' && $key_localpart != 'encodingStyle' && $key_localpart != 'root') {
7060
-                $this->message[$pos]['xattrs']['!' . $key] = $value;
7061
-            }
7062
-
7063
-            if ($key == 'xmlns') {
7064
-                $this->default_namespace = $value;
7065
-            }
7066
-            // log id
7067
-            if ($key == 'id') {
7068
-                $this->ids[$value] = $pos;
7069
-            }
7070
-            // root
7071
-            if ($key_localpart == 'root' && $value == 1) {
7072
-                $this->status = 'method';
7073
-                $this->root_struct_name = $name;
7074
-                $this->root_struct = $pos;
7075
-                $this->debug("found root struct $this->root_struct_name, pos $pos");
7076
-            }
7077
-            // for doclit
7078
-            $attstr .= " $key=\"$value\"";
7079
-        }
7080
-        // get namespace - must be done after namespace atts are processed
7081
-        if (isset($prefix)) {
7082
-            $this->message[$pos]['namespace'] = $this->namespaces[$prefix];
7083
-            $this->default_namespace = $this->namespaces[$prefix];
7084
-        } else {
7085
-            $this->message[$pos]['namespace'] = $this->default_namespace;
7086
-        }
7087
-        if ($this->status == 'header') {
7088
-            if ($this->root_header != $pos) {
7089
-                $this->responseHeaders .= "<" . (isset($prefix) ? $prefix . ':' : '') . "$name$attstr>";
7090
-            }
7091
-        } elseif ($this->root_struct_name != '') {
7092
-            $this->document .= "<" . (isset($prefix) ? $prefix . ':' : '') . "$name$attstr>";
7093
-        }
7094
-    }
7095
-
7096
-    /**
7097
-     * end-element handler
7098
-     *
7099
-     * @param    resource $parser XML parser object
7100
-     * @param    string $name element name
7101
-     * @access   private
7102
-     */
7103
-    function end_element($parser, $name)
7104
-    {
7105
-        // position of current element is equal to the last value left in depth_array for my depth
7106
-        $pos = $this->depth_array[$this->depth--];
7107
-
7108
-        // get element prefix
7109
-        if (strpos($name, ':')) {
7110
-            // get ns prefix
7111
-            $prefix = substr($name, 0, strpos($name, ':'));
7112
-            // get unqualified name
7113
-            $name = substr(strstr($name, ':'), 1);
7114
-        }
7115
-
7116
-        // build to native type
7117
-        if (isset($this->body_position) && $pos > $this->body_position) {
7118
-            // deal w/ multirefs
7119
-            if (isset($this->message[$pos]['attrs']['href'])) {
7120
-                // get id
7121
-                $id = substr($this->message[$pos]['attrs']['href'], 1);
7122
-                // add placeholder to href array
7123
-                $this->multirefs[$id][$pos] = 'placeholder';
7124
-                // add set a reference to it as the result value
7125
-                $this->message[$pos]['result'] =& $this->multirefs[$id][$pos];
7126
-                // build complexType values
7127
-            } elseif ($this->message[$pos]['children'] != '') {
7128
-                // if result has already been generated (struct/array)
7129
-                if (!isset($this->message[$pos]['result'])) {
7130
-                    $this->message[$pos]['result'] = $this->buildVal($pos);
7131
-                }
7132
-                // build complexType values of attributes and possibly simpleContent
7133
-            } elseif (isset($this->message[$pos]['xattrs'])) {
7134
-                if (isset($this->message[$pos]['nil']) && $this->message[$pos]['nil']) {
7135
-                    $this->message[$pos]['xattrs']['!'] = null;
7136
-                } elseif (isset($this->message[$pos]['cdata']) && trim($this->message[$pos]['cdata']) != '') {
7137
-                    if (isset($this->message[$pos]['type'])) {
7138
-                        $this->message[$pos]['xattrs']['!'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$pos]['type'], isset($this->message[$pos]['type_namespace']) ? $this->message[$pos]['type_namespace'] : '');
7139
-                    } else {
7140
-                        $parent = $this->message[$pos]['parent'];
7141
-                        if (isset($this->message[$parent]['type']) && ($this->message[$parent]['type'] == 'array') && isset($this->message[$parent]['arrayType'])) {
7142
-                            $this->message[$pos]['xattrs']['!'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$parent]['arrayType'], isset($this->message[$parent]['arrayTypeNamespace']) ? $this->message[$parent]['arrayTypeNamespace'] : '');
7143
-                        } else {
7144
-                            $this->message[$pos]['xattrs']['!'] = $this->message[$pos]['cdata'];
7145
-                        }
7146
-                    }
7147
-                }
7148
-                $this->message[$pos]['result'] = $this->message[$pos]['xattrs'];
7149
-                // set value of simpleType (or nil complexType)
7150
-            } else {
7151
-                //$this->debug('adding data for scalar value '.$this->message[$pos]['name'].' of value '.$this->message[$pos]['cdata']);
7152
-                if (isset($this->message[$pos]['nil']) && $this->message[$pos]['nil']) {
7153
-                    $this->message[$pos]['xattrs']['!'] = null;
7154
-                } elseif (isset($this->message[$pos]['type'])) {
7155
-                    $this->message[$pos]['result'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$pos]['type'], isset($this->message[$pos]['type_namespace']) ? $this->message[$pos]['type_namespace'] : '');
7156
-                } else {
7157
-                    $parent = $this->message[$pos]['parent'];
7158
-                    if (isset($this->message[$parent]['type']) && ($this->message[$parent]['type'] == 'array') && isset($this->message[$parent]['arrayType'])) {
7159
-                        $this->message[$pos]['result'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$parent]['arrayType'], isset($this->message[$parent]['arrayTypeNamespace']) ? $this->message[$parent]['arrayTypeNamespace'] : '');
7160
-                    } else {
7161
-                        $this->message[$pos]['result'] = $this->message[$pos]['cdata'];
7162
-                    }
7163
-                }
7164
-
7165
-                /* add value to parent's result, if parent is struct/array
7042
+				$expr = '/([A-Za-z0-9_]+):([A-Za-z]+[A-Za-z0-9_]+)\[([0-9]+),?([0-9]*)\]/';
7043
+				if (preg_match($expr, $value, $regs)) {
7044
+					$this->message[$pos]['typePrefix'] = $regs[1];
7045
+					$this->message[$pos]['arrayTypePrefix'] = $regs[1];
7046
+					if (isset($this->namespaces[$regs[1]])) {
7047
+						$this->message[$pos]['arrayTypeNamespace'] = $this->namespaces[$regs[1]];
7048
+					} elseif (isset($attrs['xmlns:' . $regs[1]])) {
7049
+						$this->message[$pos]['arrayTypeNamespace'] = $attrs['xmlns:' . $regs[1]];
7050
+					}
7051
+					$this->message[$pos]['arrayType'] = $regs[2];
7052
+					$this->message[$pos]['arraySize'] = $regs[3];
7053
+					$this->message[$pos]['arrayCols'] = $regs[4];
7054
+				}
7055
+				// specifies nil value (or not)
7056
+			} elseif ($key_localpart == 'nil') {
7057
+				$this->message[$pos]['nil'] = ($value == 'true' || $value == '1');
7058
+				// some other attribute
7059
+			} elseif ($key != 'href' && $key != 'xmlns' && $key_localpart != 'encodingStyle' && $key_localpart != 'root') {
7060
+				$this->message[$pos]['xattrs']['!' . $key] = $value;
7061
+			}
7062
+
7063
+			if ($key == 'xmlns') {
7064
+				$this->default_namespace = $value;
7065
+			}
7066
+			// log id
7067
+			if ($key == 'id') {
7068
+				$this->ids[$value] = $pos;
7069
+			}
7070
+			// root
7071
+			if ($key_localpart == 'root' && $value == 1) {
7072
+				$this->status = 'method';
7073
+				$this->root_struct_name = $name;
7074
+				$this->root_struct = $pos;
7075
+				$this->debug("found root struct $this->root_struct_name, pos $pos");
7076
+			}
7077
+			// for doclit
7078
+			$attstr .= " $key=\"$value\"";
7079
+		}
7080
+		// get namespace - must be done after namespace atts are processed
7081
+		if (isset($prefix)) {
7082
+			$this->message[$pos]['namespace'] = $this->namespaces[$prefix];
7083
+			$this->default_namespace = $this->namespaces[$prefix];
7084
+		} else {
7085
+			$this->message[$pos]['namespace'] = $this->default_namespace;
7086
+		}
7087
+		if ($this->status == 'header') {
7088
+			if ($this->root_header != $pos) {
7089
+				$this->responseHeaders .= "<" . (isset($prefix) ? $prefix . ':' : '') . "$name$attstr>";
7090
+			}
7091
+		} elseif ($this->root_struct_name != '') {
7092
+			$this->document .= "<" . (isset($prefix) ? $prefix . ':' : '') . "$name$attstr>";
7093
+		}
7094
+	}
7095
+
7096
+	/**
7097
+	 * end-element handler
7098
+	 *
7099
+	 * @param    resource $parser XML parser object
7100
+	 * @param    string $name element name
7101
+	 * @access   private
7102
+	 */
7103
+	function end_element($parser, $name)
7104
+	{
7105
+		// position of current element is equal to the last value left in depth_array for my depth
7106
+		$pos = $this->depth_array[$this->depth--];
7107
+
7108
+		// get element prefix
7109
+		if (strpos($name, ':')) {
7110
+			// get ns prefix
7111
+			$prefix = substr($name, 0, strpos($name, ':'));
7112
+			// get unqualified name
7113
+			$name = substr(strstr($name, ':'), 1);
7114
+		}
7115
+
7116
+		// build to native type
7117
+		if (isset($this->body_position) && $pos > $this->body_position) {
7118
+			// deal w/ multirefs
7119
+			if (isset($this->message[$pos]['attrs']['href'])) {
7120
+				// get id
7121
+				$id = substr($this->message[$pos]['attrs']['href'], 1);
7122
+				// add placeholder to href array
7123
+				$this->multirefs[$id][$pos] = 'placeholder';
7124
+				// add set a reference to it as the result value
7125
+				$this->message[$pos]['result'] =& $this->multirefs[$id][$pos];
7126
+				// build complexType values
7127
+			} elseif ($this->message[$pos]['children'] != '') {
7128
+				// if result has already been generated (struct/array)
7129
+				if (!isset($this->message[$pos]['result'])) {
7130
+					$this->message[$pos]['result'] = $this->buildVal($pos);
7131
+				}
7132
+				// build complexType values of attributes and possibly simpleContent
7133
+			} elseif (isset($this->message[$pos]['xattrs'])) {
7134
+				if (isset($this->message[$pos]['nil']) && $this->message[$pos]['nil']) {
7135
+					$this->message[$pos]['xattrs']['!'] = null;
7136
+				} elseif (isset($this->message[$pos]['cdata']) && trim($this->message[$pos]['cdata']) != '') {
7137
+					if (isset($this->message[$pos]['type'])) {
7138
+						$this->message[$pos]['xattrs']['!'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$pos]['type'], isset($this->message[$pos]['type_namespace']) ? $this->message[$pos]['type_namespace'] : '');
7139
+					} else {
7140
+						$parent = $this->message[$pos]['parent'];
7141
+						if (isset($this->message[$parent]['type']) && ($this->message[$parent]['type'] == 'array') && isset($this->message[$parent]['arrayType'])) {
7142
+							$this->message[$pos]['xattrs']['!'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$parent]['arrayType'], isset($this->message[$parent]['arrayTypeNamespace']) ? $this->message[$parent]['arrayTypeNamespace'] : '');
7143
+						} else {
7144
+							$this->message[$pos]['xattrs']['!'] = $this->message[$pos]['cdata'];
7145
+						}
7146
+					}
7147
+				}
7148
+				$this->message[$pos]['result'] = $this->message[$pos]['xattrs'];
7149
+				// set value of simpleType (or nil complexType)
7150
+			} else {
7151
+				//$this->debug('adding data for scalar value '.$this->message[$pos]['name'].' of value '.$this->message[$pos]['cdata']);
7152
+				if (isset($this->message[$pos]['nil']) && $this->message[$pos]['nil']) {
7153
+					$this->message[$pos]['xattrs']['!'] = null;
7154
+				} elseif (isset($this->message[$pos]['type'])) {
7155
+					$this->message[$pos]['result'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$pos]['type'], isset($this->message[$pos]['type_namespace']) ? $this->message[$pos]['type_namespace'] : '');
7156
+				} else {
7157
+					$parent = $this->message[$pos]['parent'];
7158
+					if (isset($this->message[$parent]['type']) && ($this->message[$parent]['type'] == 'array') && isset($this->message[$parent]['arrayType'])) {
7159
+						$this->message[$pos]['result'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$parent]['arrayType'], isset($this->message[$parent]['arrayTypeNamespace']) ? $this->message[$parent]['arrayTypeNamespace'] : '');
7160
+					} else {
7161
+						$this->message[$pos]['result'] = $this->message[$pos]['cdata'];
7162
+					}
7163
+				}
7164
+
7165
+				/* add value to parent's result, if parent is struct/array
7166 7166
 				$parent = $this->message[$pos]['parent'];
7167 7167
 				if($this->message[$parent]['type'] != 'map'){
7168 7168
 					if(strtolower($this->message[$parent]['type']) == 'array'){
7169 7169
 						$this->message[$parent]['result'][] = $this->message[$pos]['result'];
7170 7170
 					} else {
7171
-						$this->message[$parent]['result'][$this->message[$pos]['name']] = $this->message[$pos]['result'];
7171
+						$this->message[$parent]['result'][$this->message[$pos]['name']] = $this->message[$pos]['result'];
7172
+					}
7173
+				}
7174
+				*/
7175
+			}
7176
+		}
7177
+
7178
+		// for doclit
7179
+		if ($this->status == 'header') {
7180
+			if ($this->root_header != $pos) {
7181
+				$this->responseHeaders .= "</" . (isset($prefix) ? $prefix . ':' : '') . "$name>";
7182
+			}
7183
+		} elseif ($pos >= $this->root_struct) {
7184
+			$this->document .= "</" . (isset($prefix) ? $prefix . ':' : '') . "$name>";
7185
+		}
7186
+		// switch status
7187
+		if ($pos == $this->root_struct) {
7188
+			$this->status = 'body';
7189
+			$this->root_struct_namespace = $this->message[$pos]['namespace'];
7190
+		} elseif ($pos == $this->root_header) {
7191
+			$this->status = 'envelope';
7192
+		} elseif ($name == 'Body' && $this->status == 'body') {
7193
+			$this->status = 'envelope';
7194
+		} elseif ($name == 'Header' && $this->status == 'header') { // will never happen
7195
+			$this->status = 'envelope';
7196
+		} elseif ($name == 'Envelope' && $this->status == 'envelope') {
7197
+			$this->status = '';
7198
+		}
7199
+		// set parent back to my parent
7200
+		$this->parent = $this->message[$pos]['parent'];
7201
+	}
7202
+
7203
+	/**
7204
+	 * element content handler
7205
+	 *
7206
+	 * @param    resource $parser XML parser object
7207
+	 * @param    string $data element content
7208
+	 * @access   private
7209
+	 */
7210
+	function character_data($parser, $data)
7211
+	{
7212
+		$pos = $this->depth_array[$this->depth];
7213
+		if ($this->xml_encoding == 'UTF-8') {
7214
+			// TODO: add an option to disable this for folks who want
7215
+			// raw UTF-8 that, e.g., might not map to iso-8859-1
7216
+			// TODO: this can also be handled with xml_parser_set_option($this->parser, XML_OPTION_TARGET_ENCODING, "ISO-8859-1");
7217
+			if ($this->decode_utf8) {
7218
+				$data = function_exists('mb_convert_encoding') ? mb_convert_encoding($data, 'ISO-8859-1', 'UTF-8') : utf8_decode($data);
7219
+			}
7220
+		}
7221
+		$this->message[$pos]['cdata'] .= $data;
7222
+		// for doclit
7223
+		if ($this->status == 'header') {
7224
+			$this->responseHeaders .= $data;
7225
+		} else {
7226
+			$this->document .= $data;
7227
+		}
7228
+	}
7229
+
7230
+	/**
7231
+	 * get the parsed message (SOAP Body)
7232
+	 *
7233
+	 * @return    mixed
7234
+	 * @access   public
7235
+	 * @deprecated    use get_soapbody instead
7236
+	 */
7237
+	function get_response()
7238
+	{
7239
+		return $this->soapresponse;
7240
+	}
7241
+
7242
+	/**
7243
+	 * get the parsed SOAP Body (null if there was none)
7244
+	 *
7245
+	 * @return    mixed
7246
+	 * @access   public
7247
+	 */
7248
+	function get_soapbody()
7249
+	{
7250
+		return $this->soapresponse;
7251
+	}
7252
+
7253
+	/**
7254
+	 * get the parsed SOAP Header (null if there was none)
7255
+	 *
7256
+	 * @return    mixed
7257
+	 * @access   public
7258
+	 */
7259
+	function get_soapheader()
7260
+	{
7261
+		return $this->soapheader;
7262
+	}
7263
+
7264
+	/**
7265
+	 * get the unparsed SOAP Header
7266
+	 *
7267
+	 * @return    string XML or empty if no Header
7268
+	 * @access   public
7269
+	 */
7270
+	function getHeaders()
7271
+	{
7272
+		return $this->responseHeaders;
7273
+	}
7274
+
7275
+	/**
7276
+	 * decodes simple types into PHP variables
7277
+	 *
7278
+	 * @param    string $value value to decode
7279
+	 * @param    string $type XML type to decode
7280
+	 * @param    string $typens XML type namespace to decode
7281
+	 * @return    mixed PHP value
7282
+	 * @access   private
7283
+	 */
7284
+	function decodeSimple($value, $type, $typens)
7285
+	{
7286
+		// TODO: use the namespace!
7287
+		if ((!isset($type)) || $type == 'string' || $type == 'long' || $type == 'unsignedLong') {
7288
+			return (string) $value;
7289
+		}
7290
+		if ($type == 'int' || $type == 'integer' || $type == 'short' || $type == 'byte') {
7291
+			return (int) $value;
7292
+		}
7293
+		if ($type == 'float' || $type == 'double' || $type == 'decimal') {
7294
+			return (double) $value;
7295
+		}
7296
+		if ($type == 'boolean') {
7297
+			if (strtolower($value) == 'false' || strtolower($value) == 'f') {
7298
+				return false;
7299
+			}
7300
+			return (boolean) $value;
7301
+		}
7302
+		if ($type == 'base64' || $type == 'base64Binary') {
7303
+			$this->debug('Decode base64 value');
7304
+			return base64_decode($value);
7305
+		}
7306
+		// obscure numeric types
7307
+		if ($type == 'nonPositiveInteger' || $type == 'negativeInteger'
7308
+			|| $type == 'nonNegativeInteger' || $type == 'positiveInteger'
7309
+			|| $type == 'unsignedInt'
7310
+			|| $type == 'unsignedShort' || $type == 'unsignedByte'
7311
+		) {
7312
+			return (int) $value;
7313
+		}
7314
+		// bogus: parser treats array with no elements as a simple type
7315
+		if ($type == 'array') {
7316
+			return array();
7317
+		}
7318
+		// everything else
7319
+		return (string) $value;
7320
+	}
7321
+
7322
+	/**
7323
+	 * builds response structures for compound values (arrays/structs)
7324
+	 * and scalars
7325
+	 *
7326
+	 * @param    integer $pos position in node tree
7327
+	 * @return    mixed    PHP value
7328
+	 * @access   private
7329
+	 */
7330
+	function buildVal($pos)
7331
+	{
7332
+		if (!isset($this->message[$pos]['type'])) {
7333
+			$this->message[$pos]['type'] = '';
7334
+		}
7335
+		$this->debug('in buildVal() for ' . $this->message[$pos]['name'] . "(pos $pos) of type " . $this->message[$pos]['type']);
7336
+		// if there are children...
7337
+		if ($this->message[$pos]['children'] != '') {
7338
+			$params = [];
7339
+			$this->debug('in buildVal, there are children');
7340
+			$children = explode('|', $this->message[$pos]['children']);
7341
+			array_shift($children); // knock off empty
7342
+			// md array
7343
+			if (isset($this->message[$pos]['arrayCols']) && $this->message[$pos]['arrayCols'] != '') {
7344
+				$r = 0; // rowcount
7345
+				$c = 0; // colcount
7346
+				foreach ($children as $child_pos) {
7347
+					$this->debug("in buildVal, got an MD array element: $r, $c");
7348
+					$params[$r][] = $this->message[$child_pos]['result'];
7349
+					$c++;
7350
+					if ($c == $this->message[$pos]['arrayCols']) {
7351
+						$c = 0;
7352
+						$r++;
7353
+					}
7354
+				}
7355
+				// array
7356
+			} elseif ($this->message[$pos]['type'] == 'array' || $this->message[$pos]['type'] == 'Array') {
7357
+				$this->debug('in buildVal, adding array ' . $this->message[$pos]['name']);
7358
+				foreach ($children as $child_pos) {
7359
+					$params[] = &$this->message[$child_pos]['result'];
7360
+				}
7361
+				// apache Map type: java hashtable
7362
+			} elseif ($this->message[$pos]['type'] == 'Map' && $this->message[$pos]['type_namespace'] == 'http://xml.apache.org/xml-soap') {
7363
+				$this->debug('in buildVal, Java Map ' . $this->message[$pos]['name']);
7364
+				foreach ($children as $child_pos) {
7365
+					$kv = explode("|", $this->message[$child_pos]['children']);
7366
+					$params[$this->message[$kv[1]]['result']] = &$this->message[$kv[2]]['result'];
7367
+				}
7368
+				// generic compound type
7369
+				//} elseif($this->message[$pos]['type'] == 'SOAPStruct' || $this->message[$pos]['type'] == 'struct') {
7370
+			} else {
7371
+				// Apache Vector type: treat as an array
7372
+				$this->debug('in buildVal, adding Java Vector or generic compound type ' . $this->message[$pos]['name']);
7373
+				if ($this->message[$pos]['type'] == 'Vector' && $this->message[$pos]['type_namespace'] == 'http://xml.apache.org/xml-soap') {
7374
+					$notstruct = 1;
7375
+				} else {
7376
+					$notstruct = 0;
7377
+				}
7378
+				//
7379
+				foreach ($children as $child_pos) {
7380
+					if ($notstruct) {
7381
+						$params[] = &$this->message[$child_pos]['result'];
7382
+					} else {
7383
+						if (isset($params[$this->message[$child_pos]['name']])) {
7384
+							// de-serialize repeated element name into an array
7385
+							if ((!is_array($params[$this->message[$child_pos]['name']])) || (!isset($params[$this->message[$child_pos]['name']][0]))) {
7386
+								$params[$this->message[$child_pos]['name']] = array($params[$this->message[$child_pos]['name']]);
7387
+							}
7388
+							$params[$this->message[$child_pos]['name']][] = &$this->message[$child_pos]['result'];
7389
+						} else {
7390
+							$params[$this->message[$child_pos]['name']] = &$this->message[$child_pos]['result'];
7391
+						}
7172 7392
 					}
7173 7393
 				}
7174
-				*/
7175
-            }
7176
-        }
7177
-
7178
-        // for doclit
7179
-        if ($this->status == 'header') {
7180
-            if ($this->root_header != $pos) {
7181
-                $this->responseHeaders .= "</" . (isset($prefix) ? $prefix . ':' : '') . "$name>";
7182
-            }
7183
-        } elseif ($pos >= $this->root_struct) {
7184
-            $this->document .= "</" . (isset($prefix) ? $prefix . ':' : '') . "$name>";
7185
-        }
7186
-        // switch status
7187
-        if ($pos == $this->root_struct) {
7188
-            $this->status = 'body';
7189
-            $this->root_struct_namespace = $this->message[$pos]['namespace'];
7190
-        } elseif ($pos == $this->root_header) {
7191
-            $this->status = 'envelope';
7192
-        } elseif ($name == 'Body' && $this->status == 'body') {
7193
-            $this->status = 'envelope';
7194
-        } elseif ($name == 'Header' && $this->status == 'header') { // will never happen
7195
-            $this->status = 'envelope';
7196
-        } elseif ($name == 'Envelope' && $this->status == 'envelope') {
7197
-            $this->status = '';
7198
-        }
7199
-        // set parent back to my parent
7200
-        $this->parent = $this->message[$pos]['parent'];
7201
-    }
7202
-
7203
-    /**
7204
-     * element content handler
7205
-     *
7206
-     * @param    resource $parser XML parser object
7207
-     * @param    string $data element content
7208
-     * @access   private
7209
-     */
7210
-    function character_data($parser, $data)
7211
-    {
7212
-        $pos = $this->depth_array[$this->depth];
7213
-        if ($this->xml_encoding == 'UTF-8') {
7214
-            // TODO: add an option to disable this for folks who want
7215
-            // raw UTF-8 that, e.g., might not map to iso-8859-1
7216
-            // TODO: this can also be handled with xml_parser_set_option($this->parser, XML_OPTION_TARGET_ENCODING, "ISO-8859-1");
7217
-            if ($this->decode_utf8) {
7218
-                $data = function_exists('mb_convert_encoding') ? mb_convert_encoding($data, 'ISO-8859-1', 'UTF-8') : utf8_decode($data);
7219
-            }
7220
-        }
7221
-        $this->message[$pos]['cdata'] .= $data;
7222
-        // for doclit
7223
-        if ($this->status == 'header') {
7224
-            $this->responseHeaders .= $data;
7225
-        } else {
7226
-            $this->document .= $data;
7227
-        }
7228
-    }
7229
-
7230
-    /**
7231
-     * get the parsed message (SOAP Body)
7232
-     *
7233
-     * @return    mixed
7234
-     * @access   public
7235
-     * @deprecated    use get_soapbody instead
7236
-     */
7237
-    function get_response()
7238
-    {
7239
-        return $this->soapresponse;
7240
-    }
7241
-
7242
-    /**
7243
-     * get the parsed SOAP Body (null if there was none)
7244
-     *
7245
-     * @return    mixed
7246
-     * @access   public
7247
-     */
7248
-    function get_soapbody()
7249
-    {
7250
-        return $this->soapresponse;
7251
-    }
7252
-
7253
-    /**
7254
-     * get the parsed SOAP Header (null if there was none)
7255
-     *
7256
-     * @return    mixed
7257
-     * @access   public
7258
-     */
7259
-    function get_soapheader()
7260
-    {
7261
-        return $this->soapheader;
7262
-    }
7263
-
7264
-    /**
7265
-     * get the unparsed SOAP Header
7266
-     *
7267
-     * @return    string XML or empty if no Header
7268
-     * @access   public
7269
-     */
7270
-    function getHeaders()
7271
-    {
7272
-        return $this->responseHeaders;
7273
-    }
7274
-
7275
-    /**
7276
-     * decodes simple types into PHP variables
7277
-     *
7278
-     * @param    string $value value to decode
7279
-     * @param    string $type XML type to decode
7280
-     * @param    string $typens XML type namespace to decode
7281
-     * @return    mixed PHP value
7282
-     * @access   private
7283
-     */
7284
-    function decodeSimple($value, $type, $typens)
7285
-    {
7286
-        // TODO: use the namespace!
7287
-        if ((!isset($type)) || $type == 'string' || $type == 'long' || $type == 'unsignedLong') {
7288
-            return (string) $value;
7289
-        }
7290
-        if ($type == 'int' || $type == 'integer' || $type == 'short' || $type == 'byte') {
7291
-            return (int) $value;
7292
-        }
7293
-        if ($type == 'float' || $type == 'double' || $type == 'decimal') {
7294
-            return (double) $value;
7295
-        }
7296
-        if ($type == 'boolean') {
7297
-            if (strtolower($value) == 'false' || strtolower($value) == 'f') {
7298
-                return false;
7299
-            }
7300
-            return (boolean) $value;
7301
-        }
7302
-        if ($type == 'base64' || $type == 'base64Binary') {
7303
-            $this->debug('Decode base64 value');
7304
-            return base64_decode($value);
7305
-        }
7306
-        // obscure numeric types
7307
-        if ($type == 'nonPositiveInteger' || $type == 'negativeInteger'
7308
-            || $type == 'nonNegativeInteger' || $type == 'positiveInteger'
7309
-            || $type == 'unsignedInt'
7310
-            || $type == 'unsignedShort' || $type == 'unsignedByte'
7311
-        ) {
7312
-            return (int) $value;
7313
-        }
7314
-        // bogus: parser treats array with no elements as a simple type
7315
-        if ($type == 'array') {
7316
-            return array();
7317
-        }
7318
-        // everything else
7319
-        return (string) $value;
7320
-    }
7321
-
7322
-    /**
7323
-     * builds response structures for compound values (arrays/structs)
7324
-     * and scalars
7325
-     *
7326
-     * @param    integer $pos position in node tree
7327
-     * @return    mixed    PHP value
7328
-     * @access   private
7329
-     */
7330
-    function buildVal($pos)
7331
-    {
7332
-        if (!isset($this->message[$pos]['type'])) {
7333
-            $this->message[$pos]['type'] = '';
7334
-        }
7335
-        $this->debug('in buildVal() for ' . $this->message[$pos]['name'] . "(pos $pos) of type " . $this->message[$pos]['type']);
7336
-        // if there are children...
7337
-        if ($this->message[$pos]['children'] != '') {
7338
-            $params = [];
7339
-            $this->debug('in buildVal, there are children');
7340
-            $children = explode('|', $this->message[$pos]['children']);
7341
-            array_shift($children); // knock off empty
7342
-            // md array
7343
-            if (isset($this->message[$pos]['arrayCols']) && $this->message[$pos]['arrayCols'] != '') {
7344
-                $r = 0; // rowcount
7345
-                $c = 0; // colcount
7346
-                foreach ($children as $child_pos) {
7347
-                    $this->debug("in buildVal, got an MD array element: $r, $c");
7348
-                    $params[$r][] = $this->message[$child_pos]['result'];
7349
-                    $c++;
7350
-                    if ($c == $this->message[$pos]['arrayCols']) {
7351
-                        $c = 0;
7352
-                        $r++;
7353
-                    }
7354
-                }
7355
-                // array
7356
-            } elseif ($this->message[$pos]['type'] == 'array' || $this->message[$pos]['type'] == 'Array') {
7357
-                $this->debug('in buildVal, adding array ' . $this->message[$pos]['name']);
7358
-                foreach ($children as $child_pos) {
7359
-                    $params[] = &$this->message[$child_pos]['result'];
7360
-                }
7361
-                // apache Map type: java hashtable
7362
-            } elseif ($this->message[$pos]['type'] == 'Map' && $this->message[$pos]['type_namespace'] == 'http://xml.apache.org/xml-soap') {
7363
-                $this->debug('in buildVal, Java Map ' . $this->message[$pos]['name']);
7364
-                foreach ($children as $child_pos) {
7365
-                    $kv = explode("|", $this->message[$child_pos]['children']);
7366
-                    $params[$this->message[$kv[1]]['result']] = &$this->message[$kv[2]]['result'];
7367
-                }
7368
-                // generic compound type
7369
-                //} elseif($this->message[$pos]['type'] == 'SOAPStruct' || $this->message[$pos]['type'] == 'struct') {
7370
-            } else {
7371
-                // Apache Vector type: treat as an array
7372
-                $this->debug('in buildVal, adding Java Vector or generic compound type ' . $this->message[$pos]['name']);
7373
-                if ($this->message[$pos]['type'] == 'Vector' && $this->message[$pos]['type_namespace'] == 'http://xml.apache.org/xml-soap') {
7374
-                    $notstruct = 1;
7375
-                } else {
7376
-                    $notstruct = 0;
7377
-                }
7378
-                //
7379
-                foreach ($children as $child_pos) {
7380
-                    if ($notstruct) {
7381
-                        $params[] = &$this->message[$child_pos]['result'];
7382
-                    } else {
7383
-                        if (isset($params[$this->message[$child_pos]['name']])) {
7384
-                            // de-serialize repeated element name into an array
7385
-                            if ((!is_array($params[$this->message[$child_pos]['name']])) || (!isset($params[$this->message[$child_pos]['name']][0]))) {
7386
-                                $params[$this->message[$child_pos]['name']] = array($params[$this->message[$child_pos]['name']]);
7387
-                            }
7388
-                            $params[$this->message[$child_pos]['name']][] = &$this->message[$child_pos]['result'];
7389
-                        } else {
7390
-                            $params[$this->message[$child_pos]['name']] = &$this->message[$child_pos]['result'];
7391
-                        }
7392
-                    }
7393
-                }
7394
-            }
7395
-            if (isset($this->message[$pos]['xattrs'])) {
7396
-                $this->debug('in buildVal, handling attributes');
7397
-                foreach ($this->message[$pos]['xattrs'] as $n => $v) {
7398
-                    $params[$n] = $v;
7399
-                }
7400
-            }
7401
-            // handle simpleContent
7402
-            if (isset($this->message[$pos]['cdata']) && trim($this->message[$pos]['cdata']) != '') {
7403
-                $this->debug('in buildVal, handling simpleContent');
7404
-                if (isset($this->message[$pos]['type'])) {
7405
-                    $params['!'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$pos]['type'], isset($this->message[$pos]['type_namespace']) ? $this->message[$pos]['type_namespace'] : '');
7406
-                } else {
7407
-                    $parent = $this->message[$pos]['parent'];
7408
-                    if (isset($this->message[$parent]['type']) && ($this->message[$parent]['type'] == 'array') && isset($this->message[$parent]['arrayType'])) {
7409
-                        $params['!'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$parent]['arrayType'], isset($this->message[$parent]['arrayTypeNamespace']) ? $this->message[$parent]['arrayTypeNamespace'] : '');
7410
-                    } else {
7411
-                        $params['!'] = $this->message[$pos]['cdata'];
7412
-                    }
7413
-                }
7414
-            }
7415
-            $ret = is_array($params) ? $params : array();
7416
-            $this->debug('in buildVal, return:');
7417
-            $this->appendDebug($this->varDump($ret));
7418
-        } else {
7419
-            $this->debug('in buildVal, no children, building scalar');
7420
-            $cdata = isset($this->message[$pos]['cdata']) ? $this->message[$pos]['cdata'] : '';
7421
-            if (isset($this->message[$pos]['type'])) {
7422
-                $ret = $this->decodeSimple($cdata, $this->message[$pos]['type'], isset($this->message[$pos]['type_namespace']) ? $this->message[$pos]['type_namespace'] : '');
7423
-                $this->debug("in buildVal, return: $ret");
7424
-                return $ret;
7425
-            }
7426
-            $parent = $this->message[$pos]['parent'];
7427
-            if (isset($this->message[$parent]['type']) && ($this->message[$parent]['type'] == 'array') && isset($this->message[$parent]['arrayType'])) {
7428
-                $ret = $this->decodeSimple($cdata, $this->message[$parent]['arrayType'], isset($this->message[$parent]['arrayTypeNamespace']) ? $this->message[$parent]['arrayTypeNamespace'] : '');
7429
-                $this->debug("in buildVal, return: $ret");
7430
-                return $ret;
7431
-            }
7432
-            $ret = $this->message[$pos]['cdata'];
7433
-            $this->debug("in buildVal, return: $ret");
7434
-        }
7435
-
7436
-        return $ret;
7437
-    }
7394
+			}
7395
+			if (isset($this->message[$pos]['xattrs'])) {
7396
+				$this->debug('in buildVal, handling attributes');
7397
+				foreach ($this->message[$pos]['xattrs'] as $n => $v) {
7398
+					$params[$n] = $v;
7399
+				}
7400
+			}
7401
+			// handle simpleContent
7402
+			if (isset($this->message[$pos]['cdata']) && trim($this->message[$pos]['cdata']) != '') {
7403
+				$this->debug('in buildVal, handling simpleContent');
7404
+				if (isset($this->message[$pos]['type'])) {
7405
+					$params['!'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$pos]['type'], isset($this->message[$pos]['type_namespace']) ? $this->message[$pos]['type_namespace'] : '');
7406
+				} else {
7407
+					$parent = $this->message[$pos]['parent'];
7408
+					if (isset($this->message[$parent]['type']) && ($this->message[$parent]['type'] == 'array') && isset($this->message[$parent]['arrayType'])) {
7409
+						$params['!'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$parent]['arrayType'], isset($this->message[$parent]['arrayTypeNamespace']) ? $this->message[$parent]['arrayTypeNamespace'] : '');
7410
+					} else {
7411
+						$params['!'] = $this->message[$pos]['cdata'];
7412
+					}
7413
+				}
7414
+			}
7415
+			$ret = is_array($params) ? $params : array();
7416
+			$this->debug('in buildVal, return:');
7417
+			$this->appendDebug($this->varDump($ret));
7418
+		} else {
7419
+			$this->debug('in buildVal, no children, building scalar');
7420
+			$cdata = isset($this->message[$pos]['cdata']) ? $this->message[$pos]['cdata'] : '';
7421
+			if (isset($this->message[$pos]['type'])) {
7422
+				$ret = $this->decodeSimple($cdata, $this->message[$pos]['type'], isset($this->message[$pos]['type_namespace']) ? $this->message[$pos]['type_namespace'] : '');
7423
+				$this->debug("in buildVal, return: $ret");
7424
+				return $ret;
7425
+			}
7426
+			$parent = $this->message[$pos]['parent'];
7427
+			if (isset($this->message[$parent]['type']) && ($this->message[$parent]['type'] == 'array') && isset($this->message[$parent]['arrayType'])) {
7428
+				$ret = $this->decodeSimple($cdata, $this->message[$parent]['arrayType'], isset($this->message[$parent]['arrayTypeNamespace']) ? $this->message[$parent]['arrayTypeNamespace'] : '');
7429
+				$this->debug("in buildVal, return: $ret");
7430
+				return $ret;
7431
+			}
7432
+			$ret = $this->message[$pos]['cdata'];
7433
+			$this->debug("in buildVal, return: $ret");
7434
+		}
7435
+
7436
+		return $ret;
7437
+	}
7438 7438
 }
7439 7439
 
7440 7440
 
@@ -7469,264 +7469,264 @@  discard block
 block discarded – undo
7469 7469
 class nusoap_client extends nusoap_base
7470 7470
 {
7471 7471
 
7472
-    var $attachments = '';
7473
-    var $return = null;
7474
-    var $operation = '';
7475
-    var $opData = array();
7476
-    var $username = '';                // Username for HTTP authentication
7477
-    var $password = '';                // Password for HTTP authentication
7478
-    var $authtype = '';                // Type of HTTP authentication
7479
-    var $certRequest = array();        // Certificate for HTTP SSL authentication
7480
-    var $requestHeaders = false;    // SOAP headers in request (text)
7481
-    var $responseHeaders = '';        // SOAP headers from response (incomplete namespace resolution) (text)
7482
-    var $responseHeader = null;        // SOAP Header from response (parsed)
7483
-    var $document = '';                // SOAP body response portion (incomplete namespace resolution) (text)
7484
-    var $endpoint;
7485
-    var $forceEndpoint = '';        // overrides WSDL endpoint
7486
-    var $proxyhost = '';
7487
-    var $proxyport = '';
7488
-    var $proxyusername = '';
7489
-    var $proxypassword = '';
7490
-    var $portName = '';                // port name to use in WSDL
7491
-    var $xml_encoding = '';            // character set encoding of incoming (response) messages
7492
-    var $http_encoding = false;
7493
-    var $timeout = 0;                // HTTP connection timeout
7494
-    var $response_timeout = 30;        // HTTP response timeout
7495
-    var $endpointType = '';            // soap|wsdl, empty for WSDL initialization error
7496
-    var $persistentConnection = false;
7497
-    var $defaultRpcParams = false;    // This is no longer used
7498
-    var $request = '';                // HTTP request
7499
-    var $response = '';                // HTTP response
7500
-    var $responseData = '';            // SOAP payload of response
7501
-    var $cookies = array();            // Cookies from response or for request
7502
-    var $decode_utf8 = true;        // toggles whether the parser decodes element content w/ utf8_decode()
7503
-    var $operations = array();        // WSDL operations, empty for WSDL initialization error
7504
-    var $curl_options = array();    // User-specified cURL options
7505
-    var $bindingType = '';            // WSDL operation binding type
7506
-    var $use_curl = false;            // whether to always try to use cURL
7507
-
7508
-    /*
7472
+	var $attachments = '';
7473
+	var $return = null;
7474
+	var $operation = '';
7475
+	var $opData = array();
7476
+	var $username = '';                // Username for HTTP authentication
7477
+	var $password = '';                // Password for HTTP authentication
7478
+	var $authtype = '';                // Type of HTTP authentication
7479
+	var $certRequest = array();        // Certificate for HTTP SSL authentication
7480
+	var $requestHeaders = false;    // SOAP headers in request (text)
7481
+	var $responseHeaders = '';        // SOAP headers from response (incomplete namespace resolution) (text)
7482
+	var $responseHeader = null;        // SOAP Header from response (parsed)
7483
+	var $document = '';                // SOAP body response portion (incomplete namespace resolution) (text)
7484
+	var $endpoint;
7485
+	var $forceEndpoint = '';        // overrides WSDL endpoint
7486
+	var $proxyhost = '';
7487
+	var $proxyport = '';
7488
+	var $proxyusername = '';
7489
+	var $proxypassword = '';
7490
+	var $portName = '';                // port name to use in WSDL
7491
+	var $xml_encoding = '';            // character set encoding of incoming (response) messages
7492
+	var $http_encoding = false;
7493
+	var $timeout = 0;                // HTTP connection timeout
7494
+	var $response_timeout = 30;        // HTTP response timeout
7495
+	var $endpointType = '';            // soap|wsdl, empty for WSDL initialization error
7496
+	var $persistentConnection = false;
7497
+	var $defaultRpcParams = false;    // This is no longer used
7498
+	var $request = '';                // HTTP request
7499
+	var $response = '';                // HTTP response
7500
+	var $responseData = '';            // SOAP payload of response
7501
+	var $cookies = array();            // Cookies from response or for request
7502
+	var $decode_utf8 = true;        // toggles whether the parser decodes element content w/ utf8_decode()
7503
+	var $operations = array();        // WSDL operations, empty for WSDL initialization error
7504
+	var $curl_options = array();    // User-specified cURL options
7505
+	var $bindingType = '';            // WSDL operation binding type
7506
+	var $use_curl = false;            // whether to always try to use cURL
7507
+
7508
+	/*
7509 7509
 	 * fault related variables
7510 7510
 	 */
7511
-    /**
7512
-     * @var      bool
7513
-     * @access   public
7514
-     */
7515
-    var $fault;
7516
-    /**
7517
-     * @var      string
7518
-     * @access   public
7519
-     */
7520
-    var $faultcode;
7521
-    /**
7522
-     * @var      string
7523
-     * @access   public
7524
-     */
7525
-    var $faultstring;
7526
-    /**
7527
-     * @var      string
7528
-     * @access   public
7529
-     */
7530
-    var $faultdetail;
7531
-
7532
-    /** @var wsdl|null */
7533
-    var $wsdl;
7534
-    /** @var mixed */
7535
-    var $wsdlFile;
7536
-
7537
-    /**
7538
-     * constructor
7539
-     *
7540
-     * @param    mixed $endpoint SOAP server or WSDL URL (string), or wsdl instance (object)
7541
-     * @param    mixed $wsdl optional, set to 'wsdl' or true if using WSDL
7542
-     * @param    string $proxyhost optional
7543
-     * @param    string $proxyport optional
7544
-     * @param    string $proxyusername optional
7545
-     * @param    string $proxypassword optional
7546
-     * @param    integer $timeout set the connection timeout
7547
-     * @param    integer $response_timeout set the response timeout
7548
-     * @param    string $portName optional portName in WSDL document
7549
-     * @access   public
7550
-     */
7551
-    function __construct($endpoint, $wsdl = false, $proxyhost = false, $proxyport = false, $proxyusername = false, $proxypassword = false, $timeout = 0, $response_timeout = 30, $portName = '')
7552
-    {
7553
-        parent::__construct();
7554
-        $this->endpoint = $endpoint;
7555
-        $this->proxyhost = $proxyhost;
7556
-        $this->proxyport = $proxyport;
7557
-        $this->proxyusername = $proxyusername;
7558
-        $this->proxypassword = $proxypassword;
7559
-        $this->timeout = $timeout;
7560
-        $this->response_timeout = $response_timeout;
7561
-        $this->portName = $portName;
7562
-
7563
-        $this->debug("ctor wsdl=$wsdl timeout=$timeout response_timeout=$response_timeout");
7564
-        $this->appendDebug('endpoint=' . $this->varDump($endpoint));
7565
-
7566
-        // make values
7567
-        if ($wsdl) {
7568
-            if (is_object($endpoint) && (get_class($endpoint) == 'wsdl')) {
7569
-                $this->wsdl = $endpoint;
7570
-                $this->endpoint = $this->wsdl->wsdl;
7571
-                $this->wsdlFile = $this->endpoint;
7572
-                $this->debug('existing wsdl instance created from ' . $this->endpoint);
7573
-                $this->checkWSDL();
7574
-            } else {
7575
-                $this->wsdlFile = $this->endpoint;
7576
-                $this->wsdl = null;
7577
-                $this->debug('will use lazy evaluation of wsdl from ' . $this->endpoint);
7578
-            }
7579
-            $this->endpointType = 'wsdl';
7580
-        } else {
7581
-            $this->debug("instantiate SOAP with endpoint at $endpoint");
7582
-            $this->endpointType = 'soap';
7583
-        }
7584
-    }
7585
-
7586
-    /**
7587
-     * calls method, returns PHP native type
7588
-     *
7589
-     * @param    string $operation SOAP server URL or path
7590
-     * @param    mixed $params An array, associative or simple, of the parameters
7591
-     *                          for the method call, or a string that is the XML
7592
-     *                          for the call.  For rpc style, this call will
7593
-     *                          wrap the XML in a tag named after the method, as
7594
-     *                          well as the SOAP Envelope and Body.  For document
7595
-     *                          style, this will only wrap with the Envelope and Body.
7596
-     *                          IMPORTANT: when using an array with document style,
7597
-     *                          in which case there
7598
-     *                         is really one parameter, the root of the fragment
7599
-     *                         used in the call, which encloses what programmers
7600
-     *                         normally think of parameters.  A parameter array
7601
-     *                         *must* include the wrapper.
7602
-     * @param    string $namespace optional method namespace (WSDL can override)
7603
-     * @param    string $soapAction optional SOAPAction value (WSDL can override)
7604
-     * @param    mixed $headers optional string of XML with SOAP header content, or array of soapval objects for SOAP headers, or associative array
7605
-     * @param    boolean $rpcParams optional (no longer used)
7606
-     * @param    string $style optional (rpc|document) the style to use when serializing parameters (WSDL can override)
7607
-     * @param    string $use optional (encoded|literal|literal wrapped) the use when serializing parameters (WSDL can override)
7608
-     * @return    mixed    response from SOAP call, normally an associative array mirroring the structure of the XML response, false for certain fatal errors
7609
-     * @access   public
7610
-     */
7611
-    function call($operation, $params = array(), $namespace = 'http://tempuri.org', $soapAction = '', $headers = false, $rpcParams = null, $style = 'rpc', $use = 'encoded')
7612
-    {
7613
-        $this->operation = $operation;
7614
-        $this->fault = false;
7615
-        $this->setError('');
7616
-        $this->request = '';
7617
-        $this->response = '';
7618
-        $this->responseData = '';
7619
-        $this->faultstring = '';
7620
-        $this->faultcode = '';
7621
-        $this->opData = array();
7622
-
7623
-        $usewrapped = false;
7624
-
7625
-        $this->debug("call: operation=$operation, namespace=$namespace, soapAction=$soapAction, rpcParams=$rpcParams, style=$style, use=$use, endpointType=$this->endpointType");
7626
-        $this->appendDebug('params=' . $this->varDump($params));
7627
-        $this->appendDebug('headers=' . $this->varDump($headers));
7628
-        if ($headers) {
7629
-            $this->requestHeaders = $headers;
7630
-        }
7631
-        if ($this->endpointType == 'wsdl' && is_null($this->wsdl)) {
7632
-            $this->loadWSDL();
7633
-            if ($this->getError()) {
7634
-                return false;
7635
-            }
7636
-        }
7637
-        // serialize parameters
7638
-        if ($this->endpointType == 'wsdl' && $opData = $this->getOperationData($operation)) {
7639
-            // use WSDL for operation
7640
-            $this->opData = $opData;
7641
-            $this->debug("found operation");
7642
-            $this->appendDebug('opData=' . $this->varDump($opData));
7643
-            if (isset($opData['soapAction'])) {
7644
-                $soapAction = $opData['soapAction'];
7645
-            }
7646
-            if (!$this->forceEndpoint) {
7647
-                $this->endpoint = $opData['endpoint'];
7648
-            } else {
7649
-                $this->endpoint = $this->forceEndpoint;
7650
-            }
7651
-            $namespace = isset($opData['input']['namespace']) ? $opData['input']['namespace'] : $namespace;
7652
-            $style = $opData['style'];
7653
-            $use = $opData['input']['use'];
7654
-            // add ns to ns array
7655
-            if ($namespace != '' && !isset($this->wsdl->namespaces[$namespace])) {
7656
-                $nsPrefix = 'ns' . rand(1000, 9999);
7657
-                $this->wsdl->namespaces[$nsPrefix] = $namespace;
7658
-            }
7659
-            $nsPrefix = $this->wsdl->getPrefixFromNamespace($namespace);
7660
-            // serialize payload
7661
-            if (is_string($params)) {
7662
-                $this->debug("serializing param string for WSDL operation $operation");
7663
-                $payload = $params;
7664
-            } elseif (is_array($params)) {
7665
-                $this->debug("serializing param array for WSDL operation $operation");
7666
-                $payload = $this->wsdl->serializeRPCParameters($operation, 'input', $params, $this->bindingType);
7667
-            } else {
7668
-                $this->debug('params must be array or string');
7669
-                $this->setError('params must be array or string');
7670
-                return false;
7671
-            }
7672
-            $usedNamespaces = $this->wsdl->usedNamespaces;
7673
-            if (isset($opData['input']['encodingStyle'])) {
7674
-                $encodingStyle = $opData['input']['encodingStyle'];
7675
-            } else {
7676
-                $encodingStyle = '';
7677
-            }
7678
-            $this->appendDebug($this->wsdl->getDebug());
7679
-            $this->wsdl->clearDebug();
7680
-            if ($errstr = $this->wsdl->getError()) {
7681
-                $this->debug('got wsdl error: ' . $errstr);
7682
-                $this->setError('wsdl error: ' . $errstr);
7683
-                return false;
7684
-            }
7685
-        } elseif ($this->endpointType == 'wsdl') {
7686
-            // operation not in WSDL
7687
-            $this->appendDebug($this->wsdl->getDebug());
7688
-            $this->wsdl->clearDebug();
7689
-            $this->setError('operation ' . $operation . ' not present in WSDL.');
7690
-            $this->debug("operation '$operation' not present in WSDL.");
7691
-            return false;
7692
-        } else {
7693
-            // no WSDL
7694
-            //$this->namespaces['ns1'] = $namespace;
7695
-            $nsPrefix = 'ns' . rand(1000, 9999);
7696
-            // serialize
7697
-            $payload = '';
7698
-
7699
-            if ($use == 'literal wrapped') {
7700
-                // 'literal wrapped' is only sensible (and defined) for 'document'.
7701
-                if ($style == 'document') {
7702
-                    $usewrapped = true;
7703
-                }
7704
-                // For compatibility with the rest of the code:
7705
-                $use = 'literal';
7706
-            }
7707
-
7708
-            if (is_string($params)) {
7709
-                $this->debug("serializing param string for operation $operation");
7710
-                $payload = $params;
7711
-            } elseif (is_array($params)) {
7712
-                $this->debug("serializing param array for operation $operation");
7713
-                foreach ($params as $k => $v) {
7714
-                    $payload .= $this->serialize_val($v, $k, false, false, false, false, $use);
7715
-                }
7716
-            } else {
7717
-                $this->debug('params must be array or string');
7718
-                $this->setError('params must be array or string');
7719
-                return false;
7720
-            }
7721
-            $usedNamespaces = array();
7722
-            if ($use == 'encoded') {
7723
-                $encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/';
7724
-            } else {
7725
-                $encodingStyle = '';
7726
-            }
7727
-        }
7728
-
7729
-        // wrap document/literal wrapped calls with operation element
7511
+	/**
7512
+	 * @var      bool
7513
+	 * @access   public
7514
+	 */
7515
+	var $fault;
7516
+	/**
7517
+	 * @var      string
7518
+	 * @access   public
7519
+	 */
7520
+	var $faultcode;
7521
+	/**
7522
+	 * @var      string
7523
+	 * @access   public
7524
+	 */
7525
+	var $faultstring;
7526
+	/**
7527
+	 * @var      string
7528
+	 * @access   public
7529
+	 */
7530
+	var $faultdetail;
7531
+
7532
+	/** @var wsdl|null */
7533
+	var $wsdl;
7534
+	/** @var mixed */
7535
+	var $wsdlFile;
7536
+
7537
+	/**
7538
+	 * constructor
7539
+	 *
7540
+	 * @param    mixed $endpoint SOAP server or WSDL URL (string), or wsdl instance (object)
7541
+	 * @param    mixed $wsdl optional, set to 'wsdl' or true if using WSDL
7542
+	 * @param    string $proxyhost optional
7543
+	 * @param    string $proxyport optional
7544
+	 * @param    string $proxyusername optional
7545
+	 * @param    string $proxypassword optional
7546
+	 * @param    integer $timeout set the connection timeout
7547
+	 * @param    integer $response_timeout set the response timeout
7548
+	 * @param    string $portName optional portName in WSDL document
7549
+	 * @access   public
7550
+	 */
7551
+	function __construct($endpoint, $wsdl = false, $proxyhost = false, $proxyport = false, $proxyusername = false, $proxypassword = false, $timeout = 0, $response_timeout = 30, $portName = '')
7552
+	{
7553
+		parent::__construct();
7554
+		$this->endpoint = $endpoint;
7555
+		$this->proxyhost = $proxyhost;
7556
+		$this->proxyport = $proxyport;
7557
+		$this->proxyusername = $proxyusername;
7558
+		$this->proxypassword = $proxypassword;
7559
+		$this->timeout = $timeout;
7560
+		$this->response_timeout = $response_timeout;
7561
+		$this->portName = $portName;
7562
+
7563
+		$this->debug("ctor wsdl=$wsdl timeout=$timeout response_timeout=$response_timeout");
7564
+		$this->appendDebug('endpoint=' . $this->varDump($endpoint));
7565
+
7566
+		// make values
7567
+		if ($wsdl) {
7568
+			if (is_object($endpoint) && (get_class($endpoint) == 'wsdl')) {
7569
+				$this->wsdl = $endpoint;
7570
+				$this->endpoint = $this->wsdl->wsdl;
7571
+				$this->wsdlFile = $this->endpoint;
7572
+				$this->debug('existing wsdl instance created from ' . $this->endpoint);
7573
+				$this->checkWSDL();
7574
+			} else {
7575
+				$this->wsdlFile = $this->endpoint;
7576
+				$this->wsdl = null;
7577
+				$this->debug('will use lazy evaluation of wsdl from ' . $this->endpoint);
7578
+			}
7579
+			$this->endpointType = 'wsdl';
7580
+		} else {
7581
+			$this->debug("instantiate SOAP with endpoint at $endpoint");
7582
+			$this->endpointType = 'soap';
7583
+		}
7584
+	}
7585
+
7586
+	/**
7587
+	 * calls method, returns PHP native type
7588
+	 *
7589
+	 * @param    string $operation SOAP server URL or path
7590
+	 * @param    mixed $params An array, associative or simple, of the parameters
7591
+	 *                          for the method call, or a string that is the XML
7592
+	 *                          for the call.  For rpc style, this call will
7593
+	 *                          wrap the XML in a tag named after the method, as
7594
+	 *                          well as the SOAP Envelope and Body.  For document
7595
+	 *                          style, this will only wrap with the Envelope and Body.
7596
+	 *                          IMPORTANT: when using an array with document style,
7597
+	 *                          in which case there
7598
+	 *                         is really one parameter, the root of the fragment
7599
+	 *                         used in the call, which encloses what programmers
7600
+	 *                         normally think of parameters.  A parameter array
7601
+	 *                         *must* include the wrapper.
7602
+	 * @param    string $namespace optional method namespace (WSDL can override)
7603
+	 * @param    string $soapAction optional SOAPAction value (WSDL can override)
7604
+	 * @param    mixed $headers optional string of XML with SOAP header content, or array of soapval objects for SOAP headers, or associative array
7605
+	 * @param    boolean $rpcParams optional (no longer used)
7606
+	 * @param    string $style optional (rpc|document) the style to use when serializing parameters (WSDL can override)
7607
+	 * @param    string $use optional (encoded|literal|literal wrapped) the use when serializing parameters (WSDL can override)
7608
+	 * @return    mixed    response from SOAP call, normally an associative array mirroring the structure of the XML response, false for certain fatal errors
7609
+	 * @access   public
7610
+	 */
7611
+	function call($operation, $params = array(), $namespace = 'http://tempuri.org', $soapAction = '', $headers = false, $rpcParams = null, $style = 'rpc', $use = 'encoded')
7612
+	{
7613
+		$this->operation = $operation;
7614
+		$this->fault = false;
7615
+		$this->setError('');
7616
+		$this->request = '';
7617
+		$this->response = '';
7618
+		$this->responseData = '';
7619
+		$this->faultstring = '';
7620
+		$this->faultcode = '';
7621
+		$this->opData = array();
7622
+
7623
+		$usewrapped = false;
7624
+
7625
+		$this->debug("call: operation=$operation, namespace=$namespace, soapAction=$soapAction, rpcParams=$rpcParams, style=$style, use=$use, endpointType=$this->endpointType");
7626
+		$this->appendDebug('params=' . $this->varDump($params));
7627
+		$this->appendDebug('headers=' . $this->varDump($headers));
7628
+		if ($headers) {
7629
+			$this->requestHeaders = $headers;
7630
+		}
7631
+		if ($this->endpointType == 'wsdl' && is_null($this->wsdl)) {
7632
+			$this->loadWSDL();
7633
+			if ($this->getError()) {
7634
+				return false;
7635
+			}
7636
+		}
7637
+		// serialize parameters
7638
+		if ($this->endpointType == 'wsdl' && $opData = $this->getOperationData($operation)) {
7639
+			// use WSDL for operation
7640
+			$this->opData = $opData;
7641
+			$this->debug("found operation");
7642
+			$this->appendDebug('opData=' . $this->varDump($opData));
7643
+			if (isset($opData['soapAction'])) {
7644
+				$soapAction = $opData['soapAction'];
7645
+			}
7646
+			if (!$this->forceEndpoint) {
7647
+				$this->endpoint = $opData['endpoint'];
7648
+			} else {
7649
+				$this->endpoint = $this->forceEndpoint;
7650
+			}
7651
+			$namespace = isset($opData['input']['namespace']) ? $opData['input']['namespace'] : $namespace;
7652
+			$style = $opData['style'];
7653
+			$use = $opData['input']['use'];
7654
+			// add ns to ns array
7655
+			if ($namespace != '' && !isset($this->wsdl->namespaces[$namespace])) {
7656
+				$nsPrefix = 'ns' . rand(1000, 9999);
7657
+				$this->wsdl->namespaces[$nsPrefix] = $namespace;
7658
+			}
7659
+			$nsPrefix = $this->wsdl->getPrefixFromNamespace($namespace);
7660
+			// serialize payload
7661
+			if (is_string($params)) {
7662
+				$this->debug("serializing param string for WSDL operation $operation");
7663
+				$payload = $params;
7664
+			} elseif (is_array($params)) {
7665
+				$this->debug("serializing param array for WSDL operation $operation");
7666
+				$payload = $this->wsdl->serializeRPCParameters($operation, 'input', $params, $this->bindingType);
7667
+			} else {
7668
+				$this->debug('params must be array or string');
7669
+				$this->setError('params must be array or string');
7670
+				return false;
7671
+			}
7672
+			$usedNamespaces = $this->wsdl->usedNamespaces;
7673
+			if (isset($opData['input']['encodingStyle'])) {
7674
+				$encodingStyle = $opData['input']['encodingStyle'];
7675
+			} else {
7676
+				$encodingStyle = '';
7677
+			}
7678
+			$this->appendDebug($this->wsdl->getDebug());
7679
+			$this->wsdl->clearDebug();
7680
+			if ($errstr = $this->wsdl->getError()) {
7681
+				$this->debug('got wsdl error: ' . $errstr);
7682
+				$this->setError('wsdl error: ' . $errstr);
7683
+				return false;
7684
+			}
7685
+		} elseif ($this->endpointType == 'wsdl') {
7686
+			// operation not in WSDL
7687
+			$this->appendDebug($this->wsdl->getDebug());
7688
+			$this->wsdl->clearDebug();
7689
+			$this->setError('operation ' . $operation . ' not present in WSDL.');
7690
+			$this->debug("operation '$operation' not present in WSDL.");
7691
+			return false;
7692
+		} else {
7693
+			// no WSDL
7694
+			//$this->namespaces['ns1'] = $namespace;
7695
+			$nsPrefix = 'ns' . rand(1000, 9999);
7696
+			// serialize
7697
+			$payload = '';
7698
+
7699
+			if ($use == 'literal wrapped') {
7700
+				// 'literal wrapped' is only sensible (and defined) for 'document'.
7701
+				if ($style == 'document') {
7702
+					$usewrapped = true;
7703
+				}
7704
+				// For compatibility with the rest of the code:
7705
+				$use = 'literal';
7706
+			}
7707
+
7708
+			if (is_string($params)) {
7709
+				$this->debug("serializing param string for operation $operation");
7710
+				$payload = $params;
7711
+			} elseif (is_array($params)) {
7712
+				$this->debug("serializing param array for operation $operation");
7713
+				foreach ($params as $k => $v) {
7714
+					$payload .= $this->serialize_val($v, $k, false, false, false, false, $use);
7715
+				}
7716
+			} else {
7717
+				$this->debug('params must be array or string');
7718
+				$this->setError('params must be array or string');
7719
+				return false;
7720
+			}
7721
+			$usedNamespaces = array();
7722
+			if ($use == 'encoded') {
7723
+				$encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/';
7724
+			} else {
7725
+				$encodingStyle = '';
7726
+			}
7727
+		}
7728
+
7729
+		// wrap document/literal wrapped calls with operation element
7730 7730
 		if ($usewrapped) {
7731 7731
 			// (This code block was based on http://www.ibm.com/developerworks/webservices/library/ws-whichwsdl/
7732 7732
 			// and tailored to the needs of one specific SOAP server, where no nsPrefix was seen...
@@ -7735,787 +7735,787 @@  discard block
 block discarded – undo
7735 7735
 			if ($namespace) {
7736 7736
 				$payload = "<$operation xmlns=\"$namespace\">" .
7737 7737
 					$payload .
7738
-                    "</$operation>";
7738
+					"</$operation>";
7739 7739
 			} else {
7740 7740
 				$payload = "<$operation>" . $payload . "</$operation>";
7741 7741
 			}
7742 7742
 		}
7743 7743
 
7744
-        // wrap RPC calls with method element
7745
-        if ($style == 'rpc') {
7746
-            if ($use == 'literal') {
7747
-                $this->debug("wrapping RPC request with literal method element");
7748
-                if ($namespace) {
7749
-                    // http://www.ws-i.org/Profiles/BasicProfile-1.1-2004-08-24.html R2735 says rpc/literal accessor elements should not be in a namespace
7750
-                    $payload = "<$nsPrefix:$operation xmlns:$nsPrefix=\"$namespace\">" .
7751
-                        $payload .
7752
-                        "</$nsPrefix:$operation>";
7753
-                } else {
7754
-                    $payload = "<$operation>" . $payload . "</$operation>";
7755
-                }
7756
-            } else {
7757
-                $this->debug("wrapping RPC request with encoded method element");
7758
-                if ($namespace) {
7759
-                    $payload = "<$nsPrefix:$operation xmlns:$nsPrefix=\"$namespace\">" .
7760
-                        $payload .
7761
-                        "</$nsPrefix:$operation>";
7762
-                } else {
7763
-                    $payload = "<$operation>" .
7764
-                        $payload .
7765
-                        "</$operation>";
7766
-                }
7767
-            }
7768
-        }
7769
-        // serialize envelope
7770
-        $soapmsg = $this->serializeEnvelope($payload, $this->requestHeaders, $usedNamespaces, $style, $use, $encodingStyle);
7771
-        $this->debug("endpoint=$this->endpoint, soapAction=$soapAction, namespace=$namespace, style=$style, use=$use, encodingStyle=$encodingStyle");
7772
-        $this->debug('SOAP message length=' . strlen($soapmsg) . ' contents (max 1000 bytes)=' . substr($soapmsg, 0, 1000));
7773
-        // send
7774
-        $return = $this->send($this->getHTTPBody($soapmsg), $soapAction, $this->timeout, $this->response_timeout);
7775
-        if ($errstr = $this->getError()) {
7776
-            $this->debug('Error: ' . $errstr);
7777
-            return false;
7778
-        } else {
7779
-            $this->return = $return;
7780
-            $this->debug('sent message successfully and got a(n) ' . gettype($return));
7781
-            $this->appendDebug('return=' . $this->varDump($return));
7782
-
7783
-            // fault?
7784
-            if (is_array($return) && isset($return['faultcode'])) {
7785
-                $this->debug('got fault');
7786
-                $this->setError($return['faultcode'] . ': ' . $return['faultstring']);
7787
-                $this->fault = true;
7788
-                foreach ($return as $k => $v) {
7789
-                    $this->$k = $v;
7790
-                    if (is_array($v)) {
7791
-                        $this->debug("$k = " . json_encode($v));
7792
-                    } else {
7793
-                        $this->debug("$k = $v<br>");
7794
-                    }
7795
-                }
7796
-                return $return;
7797
-            } elseif ($style == 'document') {
7798
-                // NOTE: if the response is defined to have multiple parts (i.e. unwrapped),
7799
-                // we are only going to return the first part here...sorry about that
7800
-                return $return;
7801
-            } else {
7802
-                // array of return values
7803
-                if (is_array($return)) {
7804
-                    // multiple 'out' parameters, which we return wrapped up
7805
-                    // in the array
7806
-                    if (sizeof($return) > 1) {
7807
-                        return $return;
7808
-                    }
7809
-                    // single 'out' parameter (normally the return value)
7810
-                    $return = array_shift($return);
7811
-                    $this->debug('return shifted value: ');
7812
-                    $this->appendDebug($this->varDump($return));
7813
-                    return $return;
7814
-                    // nothing returned (ie, echoVoid)
7815
-                } else {
7816
-                    return "";
7817
-                }
7818
-            }
7819
-        }
7820
-    }
7821
-
7822
-    /**
7823
-     * check WSDL passed as an instance or pulled from an endpoint
7824
-     *
7825
-     * @access   private
7826
-     */
7827
-    function checkWSDL()
7828
-    {
7829
-        $this->appendDebug($this->wsdl->getDebug());
7830
-        $this->wsdl->clearDebug();
7831
-        $this->debug('checkWSDL');
7832
-        // catch errors
7833
-        if ($errstr = $this->wsdl->getError()) {
7834
-            $this->appendDebug($this->wsdl->getDebug());
7835
-            $this->wsdl->clearDebug();
7836
-            $this->debug('got wsdl error: ' . $errstr);
7837
-            $this->setError('wsdl error: ' . $errstr);
7838
-        } elseif ($this->operations = $this->wsdl->getOperations($this->portName)) {
7839
-            $this->appendDebug($this->wsdl->getDebug());
7840
-            $this->wsdl->clearDebug();
7841
-            $this->bindingType = 'soap';
7842
-            $this->debug('got ' . count($this->operations) . ' operations from wsdl ' . $this->wsdlFile . ' for binding type ' . $this->bindingType);
7843
-        } elseif ($this->operations = $this->wsdl->getOperations($this->portName, 'soap12')) {
7844
-            $this->appendDebug($this->wsdl->getDebug());
7845
-            $this->wsdl->clearDebug();
7846
-            $this->bindingType = 'soap12';
7847
-            $this->debug('got ' . count($this->operations) . ' operations from wsdl ' . $this->wsdlFile . ' for binding type ' . $this->bindingType);
7848
-            $this->debug('**************** WARNING: SOAP 1.2 BINDING *****************');
7849
-        } else {
7850
-            $this->appendDebug($this->wsdl->getDebug());
7851
-            $this->wsdl->clearDebug();
7852
-            $this->debug('getOperations returned false');
7853
-            $this->setError('no operations defined in the WSDL document!');
7854
-        }
7855
-    }
7856
-
7857
-    /**
7858
-     * instantiate wsdl object and parse wsdl file
7859
-     *
7860
-     * @access    public
7861
-     */
7862
-    function loadWSDL()
7863
-    {
7864
-        $this->debug('instantiating wsdl class with doc: ' . $this->wsdlFile);
7865
-        $this->wsdl = new wsdl('', $this->proxyhost, $this->proxyport, $this->proxyusername, $this->proxypassword, $this->timeout, $this->response_timeout, $this->curl_options, $this->use_curl);
7866
-        $this->wsdl->setCredentials($this->username, $this->password, $this->authtype, $this->certRequest);
7867
-        $this->wsdl->fetchWSDL($this->wsdlFile);
7868
-        $this->checkWSDL();
7869
-    }
7870
-
7871
-    /**
7872
-     * get available data pertaining to an operation
7873
-     *
7874
-     * @param    string $operation operation name
7875
-     * @return   array|false array of data pertaining to the operation, false on error or no data
7876
-     * @access   public
7877
-     */
7878
-    function getOperationData($operation)
7879
-    {
7880
-        if ($this->endpointType == 'wsdl' && is_null($this->wsdl)) {
7881
-            $this->loadWSDL();
7882
-            if ($this->getError()) {
7883
-                return false;
7884
-            }
7885
-        }
7886
-        if (isset($this->operations[$operation])) {
7887
-            return $this->operations[$operation];
7888
-        }
7889
-        $this->debug("No data for operation: $operation");
7890
-        return false;
7891
-    }
7892
-
7893
-    /**
7894
-     * send the SOAP message
7895
-     *
7896
-     * Note: if the operation has multiple return values
7897
-     * the return value of this method will be an array
7898
-     * of those values.
7899
-     *
7900
-     * @param    string $msg a SOAPx4 soapmsg object
7901
-     * @param    string $soapaction SOAPAction value
7902
-     * @param    integer $timeout set connection timeout in seconds
7903
-     * @param    integer $response_timeout set response timeout in seconds
7904
-     * @return    mixed native PHP types.
7905
-     * @access   private
7906
-     */
7907
-    function send($msg, $soapaction = '', $timeout = 0, $response_timeout = 30)
7908
-    {
7909
-        $this->checkCookies();
7910
-        // detect transport
7911
-        switch (true) {
7912
-            // http(s)
7913
-            case preg_match('/^http/', $this->endpoint):
7914
-                $this->debug('transporting via HTTP');
7915
-                if ($this->persistentConnection && is_object($this->persistentConnection)) {
7916
-                    $http =& $this->persistentConnection;
7917
-                } else {
7918
-                    $http = new soap_transport_http($this->endpoint, $this->curl_options, $this->use_curl);
7919
-                    if ($this->persistentConnection) {
7920
-                        $http->usePersistentConnection();
7921
-                    }
7922
-                }
7923
-                $http->setContentType($this->getHTTPContentType(), $this->getHTTPContentTypeCharset());
7924
-                $http->setSOAPAction($soapaction);
7925
-                if ($this->proxyhost && $this->proxyport) {
7926
-                    $http->setProxy($this->proxyhost, $this->proxyport, $this->proxyusername, $this->proxypassword);
7927
-                }
7928
-                if ($this->authtype != '') {
7929
-                    $http->setCredentials($this->username, $this->password, $this->authtype, array(), $this->certRequest);
7930
-                }
7931
-                if ($this->http_encoding != '') {
7932
-                    $http->setEncoding($this->http_encoding);
7933
-                }
7934
-                $this->debug('sending message, length=' . strlen($msg));
7935
-                if (preg_match('/^http:/', $this->endpoint)) {
7936
-                    //if(strpos($this->endpoint,'http:')){
7937
-                    $this->responseData = $http->send($msg, $timeout, $response_timeout, $this->cookies);
7938
-                } elseif (preg_match('/^https/', $this->endpoint)) {
7939
-                    //} elseif(strpos($this->endpoint,'https:')){
7940
-                    //if(phpversion() == '4.3.0-dev'){
7941
-                    //$response = $http->send($msg,$timeout,$response_timeout);
7942
-                    //$this->request = $http->outgoing_payload;
7943
-                    //$this->response = $http->incoming_payload;
7944
-                    //} else
7945
-                    $this->responseData = $http->sendHTTPS($msg, $timeout, $response_timeout, $this->cookies);
7946
-                } else {
7947
-                    $this->setError('no http/s in endpoint url');
7948
-                }
7949
-                $this->request = $http->outgoing_payload;
7950
-                $this->response = $http->incoming_payload;
7951
-                $this->appendDebug($http->getDebug());
7952
-                $this->UpdateCookies($http->incoming_cookies);
7953
-
7954
-                // save transport object if using persistent connections
7955
-                if ($this->persistentConnection) {
7956
-                    $http->clearDebug();
7957
-                    if (!is_object($this->persistentConnection)) {
7958
-                        $this->persistentConnection = $http;
7959
-                    }
7960
-                }
7961
-
7962
-                if ($err = $http->getError()) {
7963
-                    $this->setError('HTTP Error: ' . $err);
7964
-                    return false;
7965
-                } elseif ($this->getError()) {
7966
-                    return false;
7967
-                } else {
7968
-                    $this->debug('got response, length=' . strlen($this->responseData) . ' type=' . $http->incoming_headers['content-type']);
7969
-                    return $this->parseResponse($http->incoming_headers, $this->responseData);
7970
-                }
7971
-            default:
7972
-                $this->setError('no transport found, or selected transport is not yet supported!');
7973
-                return false;
7974
-        }
7975
-    }
7976
-
7977
-    /**
7978
-     * processes SOAP message returned from server
7979
-     *
7980
-     * @param    array $headers The HTTP headers
7981
-     * @param    string $data unprocessed response data from server
7982
-     * @return    mixed    value of the message, decoded into a PHP type
7983
-     * @access   private
7984
-     */
7985
-    function parseResponse($headers, $data)
7986
-    {
7987
-        $this->debug('Entering parseResponse() for data of length ' . strlen($data) . ' headers:');
7988
-        $this->appendDebug($this->varDump($headers));
7989
-        if (!isset($headers['content-type'])) {
7990
-            $this->setError('Response not of type '.$this->contentType.' (no content-type header)');
7991
-            return false;
7992
-        }
7993
-        if (!strstr($headers['content-type'], $this->contentType)) {
7994
-            $this->setError('Response not of type '.$this->contentType.': ' . $headers['content-type']);
7995
-            return false;
7996
-        }
7997
-        if (strpos($headers['content-type'], '=')) {
7998
-            $enc = str_replace('"', '', substr(strstr($headers["content-type"], '='), 1));
7999
-            $this->debug('Got response encoding: ' . $enc);
8000
-            if (preg_match('/^(ISO-8859-1|US-ASCII|UTF-8)$/i', $enc)) {
8001
-                $this->xml_encoding = strtoupper($enc);
8002
-            } else {
8003
-                $this->xml_encoding = 'US-ASCII';
8004
-            }
8005
-        } else {
8006
-            // should be US-ASCII for HTTP 1.0 or ISO-8859-1 for HTTP 1.1
8007
-            $this->xml_encoding = 'ISO-8859-1';
8008
-        }
8009
-        $this->debug('Use encoding: ' . $this->xml_encoding . ' when creating nusoap_parser');
8010
-        $parser = new nusoap_parser($data, $this->xml_encoding, $this->operations, $this->decode_utf8);
8011
-        // add parser debug data to our debug
8012
-        $this->appendDebug($parser->getDebug());
8013
-        // if parse errors
8014
-        if ($errstr = $parser->getError()) {
8015
-            $this->setError($errstr);
8016
-            // destroy the parser object
8017
-            unset($parser);
8018
-            return false;
8019
-        } else {
8020
-            // get SOAP headers
8021
-            $this->responseHeaders = $parser->getHeaders();
8022
-            // get SOAP headers
8023
-            $this->responseHeader = $parser->get_soapheader();
8024
-            // get decoded message
8025
-            $return = $parser->get_soapbody();
8026
-            // add document for doclit support
8027
-            $this->document = $parser->document;
8028
-            // Add attachments
8029
-            $this->attachments = $parser->attachments;
8030
-            // destroy the parser object
8031
-            unset($parser);
8032
-            // return decode message
8033
-            return $return;
8034
-        }
8035
-    }
8036
-
8037
-    /**
8038
-     * sets user-specified cURL options
8039
-     *
8040
-     * @param    mixed $option The cURL option (always integer?)
8041
-     * @param    mixed $value The cURL option value
8042
-     * @access   public
8043
-     */
8044
-    function setCurlOption($option, $value)
8045
-    {
8046
-        $this->debug("setCurlOption option=$option, value=");
8047
-        $this->appendDebug($this->varDump($value));
8048
-        $this->curl_options[$option] = $value;
8049
-    }
8050
-
8051
-    /**
8052
-     * sets the SOAP endpoint, which can override WSDL
8053
-     *
8054
-     * @param    string $endpoint The endpoint URL to use, or empty string or false to prevent override
8055
-     * @access   public
8056
-     */
8057
-    function setEndpoint($endpoint)
8058
-    {
8059
-        $this->debug("setEndpoint(\"$endpoint\")");
8060
-        $this->forceEndpoint = $endpoint;
8061
-    }
8062
-
8063
-    /**
8064
-     * set the SOAP headers
8065
-     *
8066
-     * @param    mixed $headers String of XML with SOAP header content, or array of soapval objects for SOAP headers
8067
-     * @access   public
8068
-     */
8069
-    function setHeaders($headers)
8070
-    {
8071
-        $this->debug("setHeaders headers=");
8072
-        $this->appendDebug($this->varDump($headers));
8073
-        $this->requestHeaders = $headers;
8074
-    }
8075
-
8076
-    /**
8077
-     * get the SOAP response headers (namespace resolution incomplete)
8078
-     *
8079
-     * @return    string
8080
-     * @access   public
8081
-     */
8082
-    function getHeaders()
8083
-    {
8084
-        return $this->responseHeaders;
8085
-    }
8086
-
8087
-    /**
8088
-     * get the SOAP response Header (parsed)
8089
-     *
8090
-     * @return    mixed
8091
-     * @access   public
8092
-     */
8093
-    function getHeader()
8094
-    {
8095
-        return $this->responseHeader;
8096
-    }
8097
-
8098
-    /**
8099
-     * set proxy info here
8100
-     *
8101
-     * @param    string $proxyhost
8102
-     * @param    string $proxyport
8103
-     * @param    string $proxyusername
8104
-     * @param    string $proxypassword
8105
-     * @access   public
8106
-     */
8107
-    function setHTTPProxy($proxyhost, $proxyport, $proxyusername = '', $proxypassword = '')
8108
-    {
8109
-        $this->proxyhost = $proxyhost;
8110
-        $this->proxyport = $proxyport;
8111
-        $this->proxyusername = $proxyusername;
8112
-        $this->proxypassword = $proxypassword;
8113
-    }
8114
-
8115
-    /**
8116
-     * if authenticating, set user credentials here
8117
-     *
8118
-     * @param    string $username
8119
-     * @param    string $password
8120
-     * @param    string $authtype (basic|digest|certificate|ntlm)
8121
-     * @param    array $certRequest (keys must be cainfofile (optional), sslcertfile, sslkeyfile, passphrase, verifypeer (optional), verifyhost (optional): see corresponding options in cURL docs)
8122
-     * @access   public
8123
-     */
8124
-    function setCredentials($username, $password, $authtype = 'basic', $certRequest = array())
8125
-    {
8126
-        $this->debug("setCredentials username=$username authtype=$authtype certRequest=");
8127
-        $this->appendDebug($this->varDump($certRequest));
8128
-        $this->username = $username;
8129
-        $this->password = $password;
8130
-        $this->authtype = $authtype;
8131
-        $this->certRequest = $certRequest;
8132
-    }
8133
-
8134
-    /**
8135
-     * use HTTP encoding
8136
-     *
8137
-     * @param    string $enc HTTP encoding
8138
-     * @access   public
8139
-     */
8140
-    function setHTTPEncoding($enc = 'gzip, deflate')
8141
-    {
8142
-        $this->debug("setHTTPEncoding(\"$enc\")");
8143
-        $this->http_encoding = $enc;
8144
-    }
8145
-
8146
-    /**
8147
-     * Set whether to try to use cURL connections if possible
8148
-     *
8149
-     * @param    boolean $use Whether to try to use cURL
8150
-     * @access   public
8151
-     */
8152
-    function setUseCURL($use)
8153
-    {
8154
-        $this->debug("setUseCURL($use)");
8155
-        $this->use_curl = $use;
8156
-    }
8157
-
8158
-    /**
8159
-     * use HTTP persistent connections if possible
8160
-     *
8161
-     * @access   public
8162
-     */
8163
-    function useHTTPPersistentConnection()
8164
-    {
8165
-        $this->debug("useHTTPPersistentConnection");
8166
-        $this->persistentConnection = true;
8167
-    }
8168
-
8169
-    /**
8170
-     * gets the default RPC parameter setting.
8171
-     * If true, default is that call params are like RPC even for document style.
8172
-     * Each call() can override this value.
8173
-     *
8174
-     * This is no longer used.
8175
-     *
8176
-     * @return boolean
8177
-     * @access public
8178
-     * @deprecated
8179
-     */
8180
-    function getDefaultRpcParams()
8181
-    {
8182
-        return $this->defaultRpcParams;
8183
-    }
8184
-
8185
-    /**
8186
-     * sets the default RPC parameter setting.
8187
-     * If true, default is that call params are like RPC even for document style
8188
-     * Each call() can override this value.
8189
-     *
8190
-     * This is no longer used.
8191
-     *
8192
-     * @param    boolean $rpcParams
8193
-     * @access public
8194
-     * @deprecated
8195
-     */
8196
-    function setDefaultRpcParams($rpcParams)
8197
-    {
8198
-        $this->defaultRpcParams = $rpcParams;
8199
-    }
8200
-
8201
-    /**
8202
-     * dynamically creates an instance of a proxy class,
8203
-     * allowing user to directly call methods from wsdl
8204
-     *
8205
-     * @return   object soap_proxy object
8206
-     * @access   public
8207
-     */
8208
-    function getProxy()
8209
-    {
8210
-        $r = rand();
8211
-        $evalStr = $this->_getProxyClassCode($r);
8212
-        //$this->debug("proxy class: $evalStr");
8213
-        if ($this->getError()) {
8214
-            $this->debug("Error from _getProxyClassCode, so return null");
8215
-            return null;
8216
-        }
8217
-        // eval the class
8218
-        eval($evalStr);
8219
-        // instantiate proxy object
8220
-        /** @var nusoap_client $proxy */
8221
-        eval("\$proxy = new nusoap_proxy_$r('');");
8222
-        // transfer current wsdl data to the proxy thereby avoiding parsing the wsdl twice
8223
-        $proxy->endpointType = 'wsdl';
8224
-        $proxy->wsdlFile = $this->wsdlFile;
8225
-        $proxy->wsdl = $this->wsdl;
8226
-        $proxy->operations = $this->operations;
8227
-        $proxy->defaultRpcParams = $this->defaultRpcParams;
8228
-        // transfer other state
8229
-        $proxy->soap_defencoding = $this->soap_defencoding;
8230
-        $proxy->username = $this->username;
8231
-        $proxy->password = $this->password;
8232
-        $proxy->authtype = $this->authtype;
8233
-        $proxy->certRequest = $this->certRequest;
8234
-        $proxy->requestHeaders = $this->requestHeaders;
8235
-        $proxy->endpoint = $this->endpoint;
8236
-        $proxy->forceEndpoint = $this->forceEndpoint;
8237
-        $proxy->proxyhost = $this->proxyhost;
8238
-        $proxy->proxyport = $this->proxyport;
8239
-        $proxy->proxyusername = $this->proxyusername;
8240
-        $proxy->proxypassword = $this->proxypassword;
8241
-        $proxy->http_encoding = $this->http_encoding;
8242
-        $proxy->timeout = $this->timeout;
8243
-        $proxy->response_timeout = $this->response_timeout;
8244
-        $proxy->persistentConnection = &$this->persistentConnection;
8245
-        $proxy->decode_utf8 = $this->decode_utf8;
8246
-        $proxy->curl_options = $this->curl_options;
8247
-        $proxy->bindingType = $this->bindingType;
8248
-        $proxy->use_curl = $this->use_curl;
8249
-        return $proxy;
8250
-    }
8251
-
8252
-    /**
8253
-     * dynamically creates proxy class code
8254
-     *
8255
-     * @return   string PHP/NuSOAP code for the proxy class
8256
-     * @access   private
8257
-     */
8258
-    function _getProxyClassCode($r)
8259
-    {
8260
-        $this->debug("in getProxy endpointType=$this->endpointType");
8261
-        $this->appendDebug("wsdl=" . $this->varDump($this->wsdl));
8262
-        if ($this->endpointType != 'wsdl') {
8263
-            $evalStr = 'A proxy can only be created for a WSDL client';
8264
-            $this->setError($evalStr);
8265
-
8266
-          return "echo \"$evalStr\";";
8267
-        }
8268
-        if (is_null($this->wsdl)) {
8269
-            $this->loadWSDL();
8270
-            if ($this->getError()) {
8271
-                return "echo \"" . $this->getError() . "\";";
8272
-            }
8273
-        }
8274
-        $evalStr = '';
8275
-        foreach ($this->operations as $operation => $opData) {
8276
-            if ($operation != '') {
8277
-                $paramStr = '';
8278
-                $paramArrayStr = '';
8279
-                // create param string and param comment string
8280
-                if (sizeof($opData['input']['parts']) > 0) {
8281
-                    $paramCommentStr = '';
8282
-                    foreach ($opData['input']['parts'] as $name => $type) {
8283
-                        $paramStr .= "\$$name, ";
8284
-                        $paramArrayStr .= "'$name' => \$$name, ";
8285
-                        $paramCommentStr .= "$type \$$name, ";
8286
-                    }
8287
-                    $paramStr = substr($paramStr, 0, strlen($paramStr) - 2);
8288
-                    $paramArrayStr = substr($paramArrayStr, 0, strlen($paramArrayStr) - 2);
8289
-                    $paramCommentStr = substr($paramCommentStr, 0, strlen($paramCommentStr) - 2);
8290
-                } else {
8291
-                    $paramCommentStr = 'void';
8292
-                }
8293
-                $opData['namespace'] = !isset($opData['namespace']) ? 'http://testuri.com' : $opData['namespace'];
8294
-                $evalStr .= "// $paramCommentStr
7744
+		// wrap RPC calls with method element
7745
+		if ($style == 'rpc') {
7746
+			if ($use == 'literal') {
7747
+				$this->debug("wrapping RPC request with literal method element");
7748
+				if ($namespace) {
7749
+					// http://www.ws-i.org/Profiles/BasicProfile-1.1-2004-08-24.html R2735 says rpc/literal accessor elements should not be in a namespace
7750
+					$payload = "<$nsPrefix:$operation xmlns:$nsPrefix=\"$namespace\">" .
7751
+						$payload .
7752
+						"</$nsPrefix:$operation>";
7753
+				} else {
7754
+					$payload = "<$operation>" . $payload . "</$operation>";
7755
+				}
7756
+			} else {
7757
+				$this->debug("wrapping RPC request with encoded method element");
7758
+				if ($namespace) {
7759
+					$payload = "<$nsPrefix:$operation xmlns:$nsPrefix=\"$namespace\">" .
7760
+						$payload .
7761
+						"</$nsPrefix:$operation>";
7762
+				} else {
7763
+					$payload = "<$operation>" .
7764
+						$payload .
7765
+						"</$operation>";
7766
+				}
7767
+			}
7768
+		}
7769
+		// serialize envelope
7770
+		$soapmsg = $this->serializeEnvelope($payload, $this->requestHeaders, $usedNamespaces, $style, $use, $encodingStyle);
7771
+		$this->debug("endpoint=$this->endpoint, soapAction=$soapAction, namespace=$namespace, style=$style, use=$use, encodingStyle=$encodingStyle");
7772
+		$this->debug('SOAP message length=' . strlen($soapmsg) . ' contents (max 1000 bytes)=' . substr($soapmsg, 0, 1000));
7773
+		// send
7774
+		$return = $this->send($this->getHTTPBody($soapmsg), $soapAction, $this->timeout, $this->response_timeout);
7775
+		if ($errstr = $this->getError()) {
7776
+			$this->debug('Error: ' . $errstr);
7777
+			return false;
7778
+		} else {
7779
+			$this->return = $return;
7780
+			$this->debug('sent message successfully and got a(n) ' . gettype($return));
7781
+			$this->appendDebug('return=' . $this->varDump($return));
7782
+
7783
+			// fault?
7784
+			if (is_array($return) && isset($return['faultcode'])) {
7785
+				$this->debug('got fault');
7786
+				$this->setError($return['faultcode'] . ': ' . $return['faultstring']);
7787
+				$this->fault = true;
7788
+				foreach ($return as $k => $v) {
7789
+					$this->$k = $v;
7790
+					if (is_array($v)) {
7791
+						$this->debug("$k = " . json_encode($v));
7792
+					} else {
7793
+						$this->debug("$k = $v<br>");
7794
+					}
7795
+				}
7796
+				return $return;
7797
+			} elseif ($style == 'document') {
7798
+				// NOTE: if the response is defined to have multiple parts (i.e. unwrapped),
7799
+				// we are only going to return the first part here...sorry about that
7800
+				return $return;
7801
+			} else {
7802
+				// array of return values
7803
+				if (is_array($return)) {
7804
+					// multiple 'out' parameters, which we return wrapped up
7805
+					// in the array
7806
+					if (sizeof($return) > 1) {
7807
+						return $return;
7808
+					}
7809
+					// single 'out' parameter (normally the return value)
7810
+					$return = array_shift($return);
7811
+					$this->debug('return shifted value: ');
7812
+					$this->appendDebug($this->varDump($return));
7813
+					return $return;
7814
+					// nothing returned (ie, echoVoid)
7815
+				} else {
7816
+					return "";
7817
+				}
7818
+			}
7819
+		}
7820
+	}
7821
+
7822
+	/**
7823
+	 * check WSDL passed as an instance or pulled from an endpoint
7824
+	 *
7825
+	 * @access   private
7826
+	 */
7827
+	function checkWSDL()
7828
+	{
7829
+		$this->appendDebug($this->wsdl->getDebug());
7830
+		$this->wsdl->clearDebug();
7831
+		$this->debug('checkWSDL');
7832
+		// catch errors
7833
+		if ($errstr = $this->wsdl->getError()) {
7834
+			$this->appendDebug($this->wsdl->getDebug());
7835
+			$this->wsdl->clearDebug();
7836
+			$this->debug('got wsdl error: ' . $errstr);
7837
+			$this->setError('wsdl error: ' . $errstr);
7838
+		} elseif ($this->operations = $this->wsdl->getOperations($this->portName)) {
7839
+			$this->appendDebug($this->wsdl->getDebug());
7840
+			$this->wsdl->clearDebug();
7841
+			$this->bindingType = 'soap';
7842
+			$this->debug('got ' . count($this->operations) . ' operations from wsdl ' . $this->wsdlFile . ' for binding type ' . $this->bindingType);
7843
+		} elseif ($this->operations = $this->wsdl->getOperations($this->portName, 'soap12')) {
7844
+			$this->appendDebug($this->wsdl->getDebug());
7845
+			$this->wsdl->clearDebug();
7846
+			$this->bindingType = 'soap12';
7847
+			$this->debug('got ' . count($this->operations) . ' operations from wsdl ' . $this->wsdlFile . ' for binding type ' . $this->bindingType);
7848
+			$this->debug('**************** WARNING: SOAP 1.2 BINDING *****************');
7849
+		} else {
7850
+			$this->appendDebug($this->wsdl->getDebug());
7851
+			$this->wsdl->clearDebug();
7852
+			$this->debug('getOperations returned false');
7853
+			$this->setError('no operations defined in the WSDL document!');
7854
+		}
7855
+	}
7856
+
7857
+	/**
7858
+	 * instantiate wsdl object and parse wsdl file
7859
+	 *
7860
+	 * @access    public
7861
+	 */
7862
+	function loadWSDL()
7863
+	{
7864
+		$this->debug('instantiating wsdl class with doc: ' . $this->wsdlFile);
7865
+		$this->wsdl = new wsdl('', $this->proxyhost, $this->proxyport, $this->proxyusername, $this->proxypassword, $this->timeout, $this->response_timeout, $this->curl_options, $this->use_curl);
7866
+		$this->wsdl->setCredentials($this->username, $this->password, $this->authtype, $this->certRequest);
7867
+		$this->wsdl->fetchWSDL($this->wsdlFile);
7868
+		$this->checkWSDL();
7869
+	}
7870
+
7871
+	/**
7872
+	 * get available data pertaining to an operation
7873
+	 *
7874
+	 * @param    string $operation operation name
7875
+	 * @return   array|false array of data pertaining to the operation, false on error or no data
7876
+	 * @access   public
7877
+	 */
7878
+	function getOperationData($operation)
7879
+	{
7880
+		if ($this->endpointType == 'wsdl' && is_null($this->wsdl)) {
7881
+			$this->loadWSDL();
7882
+			if ($this->getError()) {
7883
+				return false;
7884
+			}
7885
+		}
7886
+		if (isset($this->operations[$operation])) {
7887
+			return $this->operations[$operation];
7888
+		}
7889
+		$this->debug("No data for operation: $operation");
7890
+		return false;
7891
+	}
7892
+
7893
+	/**
7894
+	 * send the SOAP message
7895
+	 *
7896
+	 * Note: if the operation has multiple return values
7897
+	 * the return value of this method will be an array
7898
+	 * of those values.
7899
+	 *
7900
+	 * @param    string $msg a SOAPx4 soapmsg object
7901
+	 * @param    string $soapaction SOAPAction value
7902
+	 * @param    integer $timeout set connection timeout in seconds
7903
+	 * @param    integer $response_timeout set response timeout in seconds
7904
+	 * @return    mixed native PHP types.
7905
+	 * @access   private
7906
+	 */
7907
+	function send($msg, $soapaction = '', $timeout = 0, $response_timeout = 30)
7908
+	{
7909
+		$this->checkCookies();
7910
+		// detect transport
7911
+		switch (true) {
7912
+			// http(s)
7913
+			case preg_match('/^http/', $this->endpoint):
7914
+				$this->debug('transporting via HTTP');
7915
+				if ($this->persistentConnection && is_object($this->persistentConnection)) {
7916
+					$http =& $this->persistentConnection;
7917
+				} else {
7918
+					$http = new soap_transport_http($this->endpoint, $this->curl_options, $this->use_curl);
7919
+					if ($this->persistentConnection) {
7920
+						$http->usePersistentConnection();
7921
+					}
7922
+				}
7923
+				$http->setContentType($this->getHTTPContentType(), $this->getHTTPContentTypeCharset());
7924
+				$http->setSOAPAction($soapaction);
7925
+				if ($this->proxyhost && $this->proxyport) {
7926
+					$http->setProxy($this->proxyhost, $this->proxyport, $this->proxyusername, $this->proxypassword);
7927
+				}
7928
+				if ($this->authtype != '') {
7929
+					$http->setCredentials($this->username, $this->password, $this->authtype, array(), $this->certRequest);
7930
+				}
7931
+				if ($this->http_encoding != '') {
7932
+					$http->setEncoding($this->http_encoding);
7933
+				}
7934
+				$this->debug('sending message, length=' . strlen($msg));
7935
+				if (preg_match('/^http:/', $this->endpoint)) {
7936
+					//if(strpos($this->endpoint,'http:')){
7937
+					$this->responseData = $http->send($msg, $timeout, $response_timeout, $this->cookies);
7938
+				} elseif (preg_match('/^https/', $this->endpoint)) {
7939
+					//} elseif(strpos($this->endpoint,'https:')){
7940
+					//if(phpversion() == '4.3.0-dev'){
7941
+					//$response = $http->send($msg,$timeout,$response_timeout);
7942
+					//$this->request = $http->outgoing_payload;
7943
+					//$this->response = $http->incoming_payload;
7944
+					//} else
7945
+					$this->responseData = $http->sendHTTPS($msg, $timeout, $response_timeout, $this->cookies);
7946
+				} else {
7947
+					$this->setError('no http/s in endpoint url');
7948
+				}
7949
+				$this->request = $http->outgoing_payload;
7950
+				$this->response = $http->incoming_payload;
7951
+				$this->appendDebug($http->getDebug());
7952
+				$this->UpdateCookies($http->incoming_cookies);
7953
+
7954
+				// save transport object if using persistent connections
7955
+				if ($this->persistentConnection) {
7956
+					$http->clearDebug();
7957
+					if (!is_object($this->persistentConnection)) {
7958
+						$this->persistentConnection = $http;
7959
+					}
7960
+				}
7961
+
7962
+				if ($err = $http->getError()) {
7963
+					$this->setError('HTTP Error: ' . $err);
7964
+					return false;
7965
+				} elseif ($this->getError()) {
7966
+					return false;
7967
+				} else {
7968
+					$this->debug('got response, length=' . strlen($this->responseData) . ' type=' . $http->incoming_headers['content-type']);
7969
+					return $this->parseResponse($http->incoming_headers, $this->responseData);
7970
+				}
7971
+			default:
7972
+				$this->setError('no transport found, or selected transport is not yet supported!');
7973
+				return false;
7974
+		}
7975
+	}
7976
+
7977
+	/**
7978
+	 * processes SOAP message returned from server
7979
+	 *
7980
+	 * @param    array $headers The HTTP headers
7981
+	 * @param    string $data unprocessed response data from server
7982
+	 * @return    mixed    value of the message, decoded into a PHP type
7983
+	 * @access   private
7984
+	 */
7985
+	function parseResponse($headers, $data)
7986
+	{
7987
+		$this->debug('Entering parseResponse() for data of length ' . strlen($data) . ' headers:');
7988
+		$this->appendDebug($this->varDump($headers));
7989
+		if (!isset($headers['content-type'])) {
7990
+			$this->setError('Response not of type '.$this->contentType.' (no content-type header)');
7991
+			return false;
7992
+		}
7993
+		if (!strstr($headers['content-type'], $this->contentType)) {
7994
+			$this->setError('Response not of type '.$this->contentType.': ' . $headers['content-type']);
7995
+			return false;
7996
+		}
7997
+		if (strpos($headers['content-type'], '=')) {
7998
+			$enc = str_replace('"', '', substr(strstr($headers["content-type"], '='), 1));
7999
+			$this->debug('Got response encoding: ' . $enc);
8000
+			if (preg_match('/^(ISO-8859-1|US-ASCII|UTF-8)$/i', $enc)) {
8001
+				$this->xml_encoding = strtoupper($enc);
8002
+			} else {
8003
+				$this->xml_encoding = 'US-ASCII';
8004
+			}
8005
+		} else {
8006
+			// should be US-ASCII for HTTP 1.0 or ISO-8859-1 for HTTP 1.1
8007
+			$this->xml_encoding = 'ISO-8859-1';
8008
+		}
8009
+		$this->debug('Use encoding: ' . $this->xml_encoding . ' when creating nusoap_parser');
8010
+		$parser = new nusoap_parser($data, $this->xml_encoding, $this->operations, $this->decode_utf8);
8011
+		// add parser debug data to our debug
8012
+		$this->appendDebug($parser->getDebug());
8013
+		// if parse errors
8014
+		if ($errstr = $parser->getError()) {
8015
+			$this->setError($errstr);
8016
+			// destroy the parser object
8017
+			unset($parser);
8018
+			return false;
8019
+		} else {
8020
+			// get SOAP headers
8021
+			$this->responseHeaders = $parser->getHeaders();
8022
+			// get SOAP headers
8023
+			$this->responseHeader = $parser->get_soapheader();
8024
+			// get decoded message
8025
+			$return = $parser->get_soapbody();
8026
+			// add document for doclit support
8027
+			$this->document = $parser->document;
8028
+			// Add attachments
8029
+			$this->attachments = $parser->attachments;
8030
+			// destroy the parser object
8031
+			unset($parser);
8032
+			// return decode message
8033
+			return $return;
8034
+		}
8035
+	}
8036
+
8037
+	/**
8038
+	 * sets user-specified cURL options
8039
+	 *
8040
+	 * @param    mixed $option The cURL option (always integer?)
8041
+	 * @param    mixed $value The cURL option value
8042
+	 * @access   public
8043
+	 */
8044
+	function setCurlOption($option, $value)
8045
+	{
8046
+		$this->debug("setCurlOption option=$option, value=");
8047
+		$this->appendDebug($this->varDump($value));
8048
+		$this->curl_options[$option] = $value;
8049
+	}
8050
+
8051
+	/**
8052
+	 * sets the SOAP endpoint, which can override WSDL
8053
+	 *
8054
+	 * @param    string $endpoint The endpoint URL to use, or empty string or false to prevent override
8055
+	 * @access   public
8056
+	 */
8057
+	function setEndpoint($endpoint)
8058
+	{
8059
+		$this->debug("setEndpoint(\"$endpoint\")");
8060
+		$this->forceEndpoint = $endpoint;
8061
+	}
8062
+
8063
+	/**
8064
+	 * set the SOAP headers
8065
+	 *
8066
+	 * @param    mixed $headers String of XML with SOAP header content, or array of soapval objects for SOAP headers
8067
+	 * @access   public
8068
+	 */
8069
+	function setHeaders($headers)
8070
+	{
8071
+		$this->debug("setHeaders headers=");
8072
+		$this->appendDebug($this->varDump($headers));
8073
+		$this->requestHeaders = $headers;
8074
+	}
8075
+
8076
+	/**
8077
+	 * get the SOAP response headers (namespace resolution incomplete)
8078
+	 *
8079
+	 * @return    string
8080
+	 * @access   public
8081
+	 */
8082
+	function getHeaders()
8083
+	{
8084
+		return $this->responseHeaders;
8085
+	}
8086
+
8087
+	/**
8088
+	 * get the SOAP response Header (parsed)
8089
+	 *
8090
+	 * @return    mixed
8091
+	 * @access   public
8092
+	 */
8093
+	function getHeader()
8094
+	{
8095
+		return $this->responseHeader;
8096
+	}
8097
+
8098
+	/**
8099
+	 * set proxy info here
8100
+	 *
8101
+	 * @param    string $proxyhost
8102
+	 * @param    string $proxyport
8103
+	 * @param    string $proxyusername
8104
+	 * @param    string $proxypassword
8105
+	 * @access   public
8106
+	 */
8107
+	function setHTTPProxy($proxyhost, $proxyport, $proxyusername = '', $proxypassword = '')
8108
+	{
8109
+		$this->proxyhost = $proxyhost;
8110
+		$this->proxyport = $proxyport;
8111
+		$this->proxyusername = $proxyusername;
8112
+		$this->proxypassword = $proxypassword;
8113
+	}
8114
+
8115
+	/**
8116
+	 * if authenticating, set user credentials here
8117
+	 *
8118
+	 * @param    string $username
8119
+	 * @param    string $password
8120
+	 * @param    string $authtype (basic|digest|certificate|ntlm)
8121
+	 * @param    array $certRequest (keys must be cainfofile (optional), sslcertfile, sslkeyfile, passphrase, verifypeer (optional), verifyhost (optional): see corresponding options in cURL docs)
8122
+	 * @access   public
8123
+	 */
8124
+	function setCredentials($username, $password, $authtype = 'basic', $certRequest = array())
8125
+	{
8126
+		$this->debug("setCredentials username=$username authtype=$authtype certRequest=");
8127
+		$this->appendDebug($this->varDump($certRequest));
8128
+		$this->username = $username;
8129
+		$this->password = $password;
8130
+		$this->authtype = $authtype;
8131
+		$this->certRequest = $certRequest;
8132
+	}
8133
+
8134
+	/**
8135
+	 * use HTTP encoding
8136
+	 *
8137
+	 * @param    string $enc HTTP encoding
8138
+	 * @access   public
8139
+	 */
8140
+	function setHTTPEncoding($enc = 'gzip, deflate')
8141
+	{
8142
+		$this->debug("setHTTPEncoding(\"$enc\")");
8143
+		$this->http_encoding = $enc;
8144
+	}
8145
+
8146
+	/**
8147
+	 * Set whether to try to use cURL connections if possible
8148
+	 *
8149
+	 * @param    boolean $use Whether to try to use cURL
8150
+	 * @access   public
8151
+	 */
8152
+	function setUseCURL($use)
8153
+	{
8154
+		$this->debug("setUseCURL($use)");
8155
+		$this->use_curl = $use;
8156
+	}
8157
+
8158
+	/**
8159
+	 * use HTTP persistent connections if possible
8160
+	 *
8161
+	 * @access   public
8162
+	 */
8163
+	function useHTTPPersistentConnection()
8164
+	{
8165
+		$this->debug("useHTTPPersistentConnection");
8166
+		$this->persistentConnection = true;
8167
+	}
8168
+
8169
+	/**
8170
+	 * gets the default RPC parameter setting.
8171
+	 * If true, default is that call params are like RPC even for document style.
8172
+	 * Each call() can override this value.
8173
+	 *
8174
+	 * This is no longer used.
8175
+	 *
8176
+	 * @return boolean
8177
+	 * @access public
8178
+	 * @deprecated
8179
+	 */
8180
+	function getDefaultRpcParams()
8181
+	{
8182
+		return $this->defaultRpcParams;
8183
+	}
8184
+
8185
+	/**
8186
+	 * sets the default RPC parameter setting.
8187
+	 * If true, default is that call params are like RPC even for document style
8188
+	 * Each call() can override this value.
8189
+	 *
8190
+	 * This is no longer used.
8191
+	 *
8192
+	 * @param    boolean $rpcParams
8193
+	 * @access public
8194
+	 * @deprecated
8195
+	 */
8196
+	function setDefaultRpcParams($rpcParams)
8197
+	{
8198
+		$this->defaultRpcParams = $rpcParams;
8199
+	}
8200
+
8201
+	/**
8202
+	 * dynamically creates an instance of a proxy class,
8203
+	 * allowing user to directly call methods from wsdl
8204
+	 *
8205
+	 * @return   object soap_proxy object
8206
+	 * @access   public
8207
+	 */
8208
+	function getProxy()
8209
+	{
8210
+		$r = rand();
8211
+		$evalStr = $this->_getProxyClassCode($r);
8212
+		//$this->debug("proxy class: $evalStr");
8213
+		if ($this->getError()) {
8214
+			$this->debug("Error from _getProxyClassCode, so return null");
8215
+			return null;
8216
+		}
8217
+		// eval the class
8218
+		eval($evalStr);
8219
+		// instantiate proxy object
8220
+		/** @var nusoap_client $proxy */
8221
+		eval("\$proxy = new nusoap_proxy_$r('');");
8222
+		// transfer current wsdl data to the proxy thereby avoiding parsing the wsdl twice
8223
+		$proxy->endpointType = 'wsdl';
8224
+		$proxy->wsdlFile = $this->wsdlFile;
8225
+		$proxy->wsdl = $this->wsdl;
8226
+		$proxy->operations = $this->operations;
8227
+		$proxy->defaultRpcParams = $this->defaultRpcParams;
8228
+		// transfer other state
8229
+		$proxy->soap_defencoding = $this->soap_defencoding;
8230
+		$proxy->username = $this->username;
8231
+		$proxy->password = $this->password;
8232
+		$proxy->authtype = $this->authtype;
8233
+		$proxy->certRequest = $this->certRequest;
8234
+		$proxy->requestHeaders = $this->requestHeaders;
8235
+		$proxy->endpoint = $this->endpoint;
8236
+		$proxy->forceEndpoint = $this->forceEndpoint;
8237
+		$proxy->proxyhost = $this->proxyhost;
8238
+		$proxy->proxyport = $this->proxyport;
8239
+		$proxy->proxyusername = $this->proxyusername;
8240
+		$proxy->proxypassword = $this->proxypassword;
8241
+		$proxy->http_encoding = $this->http_encoding;
8242
+		$proxy->timeout = $this->timeout;
8243
+		$proxy->response_timeout = $this->response_timeout;
8244
+		$proxy->persistentConnection = &$this->persistentConnection;
8245
+		$proxy->decode_utf8 = $this->decode_utf8;
8246
+		$proxy->curl_options = $this->curl_options;
8247
+		$proxy->bindingType = $this->bindingType;
8248
+		$proxy->use_curl = $this->use_curl;
8249
+		return $proxy;
8250
+	}
8251
+
8252
+	/**
8253
+	 * dynamically creates proxy class code
8254
+	 *
8255
+	 * @return   string PHP/NuSOAP code for the proxy class
8256
+	 * @access   private
8257
+	 */
8258
+	function _getProxyClassCode($r)
8259
+	{
8260
+		$this->debug("in getProxy endpointType=$this->endpointType");
8261
+		$this->appendDebug("wsdl=" . $this->varDump($this->wsdl));
8262
+		if ($this->endpointType != 'wsdl') {
8263
+			$evalStr = 'A proxy can only be created for a WSDL client';
8264
+			$this->setError($evalStr);
8265
+
8266
+		  return "echo \"$evalStr\";";
8267
+		}
8268
+		if (is_null($this->wsdl)) {
8269
+			$this->loadWSDL();
8270
+			if ($this->getError()) {
8271
+				return "echo \"" . $this->getError() . "\";";
8272
+			}
8273
+		}
8274
+		$evalStr = '';
8275
+		foreach ($this->operations as $operation => $opData) {
8276
+			if ($operation != '') {
8277
+				$paramStr = '';
8278
+				$paramArrayStr = '';
8279
+				// create param string and param comment string
8280
+				if (sizeof($opData['input']['parts']) > 0) {
8281
+					$paramCommentStr = '';
8282
+					foreach ($opData['input']['parts'] as $name => $type) {
8283
+						$paramStr .= "\$$name, ";
8284
+						$paramArrayStr .= "'$name' => \$$name, ";
8285
+						$paramCommentStr .= "$type \$$name, ";
8286
+					}
8287
+					$paramStr = substr($paramStr, 0, strlen($paramStr) - 2);
8288
+					$paramArrayStr = substr($paramArrayStr, 0, strlen($paramArrayStr) - 2);
8289
+					$paramCommentStr = substr($paramCommentStr, 0, strlen($paramCommentStr) - 2);
8290
+				} else {
8291
+					$paramCommentStr = 'void';
8292
+				}
8293
+				$opData['namespace'] = !isset($opData['namespace']) ? 'http://testuri.com' : $opData['namespace'];
8294
+				$evalStr .= "// $paramCommentStr
8295 8295
 	function " . str_replace('.', '__', $operation) . "($paramStr) {
8296 8296
 		\$params = array($paramArrayStr);
8297 8297
 		return \$this->call('$operation', \$params, '" . $opData['namespace'] . "', '" . (isset($opData['soapAction']) ? $opData['soapAction'] : '') . "');
8298 8298
 	}
8299 8299
 	";
8300
-                unset($paramStr);
8301
-                unset($paramCommentStr);
8302
-            }
8303
-        }
8300
+				unset($paramStr);
8301
+				unset($paramCommentStr);
8302
+			}
8303
+		}
8304 8304
 
8305
-      return 'class nusoap_proxy_' . $r . ' extends nusoap_client {
8305
+	  return 'class nusoap_proxy_' . $r . ' extends nusoap_client {
8306 8306
 ' . $evalStr . '
8307 8307
 }';
8308
-    }
8309
-
8310
-    /**
8311
-     * dynamically creates proxy class code
8312
-     *
8313
-     * @return   string PHP/NuSOAP code for the proxy class
8314
-     * @access   public
8315
-     */
8316
-    function getProxyClassCode()
8317
-    {
8318
-        $r = rand();
8319
-        return $this->_getProxyClassCode($r);
8320
-    }
8321
-
8322
-    /**
8323
-     * gets the HTTP body for the current request.
8324
-     *
8325
-     * @param string $soapmsg The SOAP payload
8326
-     * @return string The HTTP body, which includes the SOAP payload
8327
-     * @access private
8328
-     */
8329
-    function getHTTPBody($soapmsg)
8330
-    {
8331
-        return $soapmsg;
8332
-    }
8333
-
8334
-    /**
8335
-     * gets the HTTP content type for the current request.
8336
-     *
8337
-     * Note: getHTTPBody must be called before this.
8338
-     *
8339
-     * @return string the HTTP content type for the current request.
8340
-     * @access private
8341
-     */
8342
-    function getHTTPContentType()
8343
-    {
8344
-        return $this->contentType;
8345
-    }
8346
-
8347
-    /**
8348
-     * allows you to change the HTTP ContentType of the request.
8349
-     *
8350
-     * @param   string $contentTypeNew
8351
-     * @return  void
8352
-     */
8353
-    function setHTTPContentType($contentTypeNew = "text/xml"){
8354
-        $this->contentType = $contentTypeNew;
8355
-    }
8356
-
8357
-    /**
8358
-     * gets the HTTP content type charset for the current request.
8359
-     * returns false for non-text content types.
8360
-     *
8361
-     * Note: getHTTPBody must be called before this.
8362
-     *
8363
-     * @return string the HTTP content type charset for the current request.
8364
-     * @access private
8365
-     */
8366
-    function getHTTPContentTypeCharset()
8367
-    {
8368
-        return $this->soap_defencoding;
8369
-    }
8370
-
8371
-    /*
8308
+	}
8309
+
8310
+	/**
8311
+	 * dynamically creates proxy class code
8312
+	 *
8313
+	 * @return   string PHP/NuSOAP code for the proxy class
8314
+	 * @access   public
8315
+	 */
8316
+	function getProxyClassCode()
8317
+	{
8318
+		$r = rand();
8319
+		return $this->_getProxyClassCode($r);
8320
+	}
8321
+
8322
+	/**
8323
+	 * gets the HTTP body for the current request.
8324
+	 *
8325
+	 * @param string $soapmsg The SOAP payload
8326
+	 * @return string The HTTP body, which includes the SOAP payload
8327
+	 * @access private
8328
+	 */
8329
+	function getHTTPBody($soapmsg)
8330
+	{
8331
+		return $soapmsg;
8332
+	}
8333
+
8334
+	/**
8335
+	 * gets the HTTP content type for the current request.
8336
+	 *
8337
+	 * Note: getHTTPBody must be called before this.
8338
+	 *
8339
+	 * @return string the HTTP content type for the current request.
8340
+	 * @access private
8341
+	 */
8342
+	function getHTTPContentType()
8343
+	{
8344
+		return $this->contentType;
8345
+	}
8346
+
8347
+	/**
8348
+	 * allows you to change the HTTP ContentType of the request.
8349
+	 *
8350
+	 * @param   string $contentTypeNew
8351
+	 * @return  void
8352
+	 */
8353
+	function setHTTPContentType($contentTypeNew = "text/xml"){
8354
+		$this->contentType = $contentTypeNew;
8355
+	}
8356
+
8357
+	/**
8358
+	 * gets the HTTP content type charset for the current request.
8359
+	 * returns false for non-text content types.
8360
+	 *
8361
+	 * Note: getHTTPBody must be called before this.
8362
+	 *
8363
+	 * @return string the HTTP content type charset for the current request.
8364
+	 * @access private
8365
+	 */
8366
+	function getHTTPContentTypeCharset()
8367
+	{
8368
+		return $this->soap_defencoding;
8369
+	}
8370
+
8371
+	/*
8372 8372
 	* whether or not parser should decode utf8 element content
8373 8373
     *
8374 8374
     * @return   always returns true
8375 8375
     * @access   public
8376 8376
     */
8377
-    function decodeUTF8($bool)
8378
-    {
8379
-        $this->decode_utf8 = $bool;
8380
-        return true;
8381
-    }
8382
-
8383
-    /**
8384
-     * adds a new Cookie into $this->cookies array
8385
-     *
8386
-     * @param    string $name Cookie Name
8387
-     * @param    string $value Cookie Value
8388
-     * @return    boolean if cookie-set was successful returns true, else false
8389
-     * @access    public
8390
-     */
8391
-    function setCookie($name, $value)
8392
-    {
8393
-        if (strlen($name) == 0) {
8394
-            return false;
8395
-        }
8396
-        $this->cookies[] = array('name' => $name, 'value' => $value);
8397
-        return true;
8398
-    }
8399
-
8400
-    /**
8401
-     * gets all Cookies
8402
-     *
8403
-     * @return   array with all internal cookies
8404
-     * @access   public
8405
-     */
8406
-    function getCookies()
8407
-    {
8408
-        return $this->cookies;
8409
-    }
8410
-
8411
-    /**
8412
-     * checks all Cookies and delete those which are expired
8413
-     *
8414
-     * @return   boolean always return true
8415
-     * @access   private
8416
-     */
8417
-    function checkCookies()
8418
-    {
8419
-        if (sizeof($this->cookies) == 0) {
8420
-            return true;
8421
-        }
8422
-        $this->debug('checkCookie: check ' . sizeof($this->cookies) . ' cookies');
8423
-        $curr_cookies = $this->cookies;
8424
-        $this->cookies = array();
8425
-        foreach ($curr_cookies as $cookie) {
8426
-            if (!is_array($cookie)) {
8427
-                $this->debug('Remove cookie that is not an array');
8428
-                continue;
8429
-            }
8430
-            if ((isset($cookie['expires'])) && (!empty($cookie['expires']))) {
8431
-                if (strtotime($cookie['expires']) > time()) {
8432
-                    $this->cookies[] = $cookie;
8433
-                } else {
8434
-                    $this->debug('Remove expired cookie ' . $cookie['name']);
8435
-                }
8436
-            } else {
8437
-                $this->cookies[] = $cookie;
8438
-            }
8439
-        }
8440
-        $this->debug('checkCookie: ' . sizeof($this->cookies) . ' cookies left in array');
8441
-        return true;
8442
-    }
8443
-
8444
-    /**
8445
-     * updates the current cookies with a new set
8446
-     *
8447
-     * @param    array $cookies new cookies with which to update current ones
8448
-     * @return    boolean always return true
8449
-     * @access    private
8450
-     */
8451
-    function UpdateCookies($cookies)
8452
-    {
8453
-        if (sizeof($this->cookies) == 0) {
8454
-            // no existing cookies: take whatever is new
8455
-            if (sizeof($cookies) > 0) {
8456
-                $this->debug('Setting new cookie(s)');
8457
-                $this->cookies = $cookies;
8458
-            }
8459
-            return true;
8460
-        }
8461
-        if (sizeof($cookies) == 0) {
8462
-            // no new cookies: keep what we've got
8463
-            return true;
8464
-        }
8465
-        // merge
8466
-        foreach ($cookies as $newCookie) {
8467
-            if (!is_array($newCookie)) {
8468
-                continue;
8469
-            }
8470
-            if ((!isset($newCookie['name'])) || (!isset($newCookie['value']))) {
8471
-                continue;
8472
-            }
8473
-            $newName = $newCookie['name'];
8474
-
8475
-            $found = false;
8476
-            for ($i = 0; $i < count($this->cookies); $i++) {
8477
-                $cookie = $this->cookies[$i];
8478
-                if (!is_array($cookie)) {
8479
-                    continue;
8480
-                }
8481
-                if (!isset($cookie['name'])) {
8482
-                    continue;
8483
-                }
8484
-                if ($newName != $cookie['name']) {
8485
-                    continue;
8486
-                }
8487
-                $newDomain = isset($newCookie['domain']) ? $newCookie['domain'] : 'NODOMAIN';
8488
-                $domain = isset($cookie['domain']) ? $cookie['domain'] : 'NODOMAIN';
8489
-                if ($newDomain != $domain) {
8490
-                    continue;
8491
-                }
8492
-                $newPath = isset($newCookie['path']) ? $newCookie['path'] : 'NOPATH';
8493
-                $path = isset($cookie['path']) ? $cookie['path'] : 'NOPATH';
8494
-                if ($newPath != $path) {
8495
-                    continue;
8496
-                }
8497
-                $this->cookies[$i] = $newCookie;
8498
-                $found = true;
8499
-                $this->debug('Update cookie ' . $newName . '=' . $newCookie['value']);
8500
-                break;
8501
-            }
8502
-            if (!$found) {
8503
-                $this->debug('Add cookie ' . $newName . '=' . $newCookie['value']);
8504
-                $this->cookies[] = $newCookie;
8505
-            }
8506
-        }
8507
-        return true;
8508
-    }
8377
+	function decodeUTF8($bool)
8378
+	{
8379
+		$this->decode_utf8 = $bool;
8380
+		return true;
8381
+	}
8382
+
8383
+	/**
8384
+	 * adds a new Cookie into $this->cookies array
8385
+	 *
8386
+	 * @param    string $name Cookie Name
8387
+	 * @param    string $value Cookie Value
8388
+	 * @return    boolean if cookie-set was successful returns true, else false
8389
+	 * @access    public
8390
+	 */
8391
+	function setCookie($name, $value)
8392
+	{
8393
+		if (strlen($name) == 0) {
8394
+			return false;
8395
+		}
8396
+		$this->cookies[] = array('name' => $name, 'value' => $value);
8397
+		return true;
8398
+	}
8399
+
8400
+	/**
8401
+	 * gets all Cookies
8402
+	 *
8403
+	 * @return   array with all internal cookies
8404
+	 * @access   public
8405
+	 */
8406
+	function getCookies()
8407
+	{
8408
+		return $this->cookies;
8409
+	}
8410
+
8411
+	/**
8412
+	 * checks all Cookies and delete those which are expired
8413
+	 *
8414
+	 * @return   boolean always return true
8415
+	 * @access   private
8416
+	 */
8417
+	function checkCookies()
8418
+	{
8419
+		if (sizeof($this->cookies) == 0) {
8420
+			return true;
8421
+		}
8422
+		$this->debug('checkCookie: check ' . sizeof($this->cookies) . ' cookies');
8423
+		$curr_cookies = $this->cookies;
8424
+		$this->cookies = array();
8425
+		foreach ($curr_cookies as $cookie) {
8426
+			if (!is_array($cookie)) {
8427
+				$this->debug('Remove cookie that is not an array');
8428
+				continue;
8429
+			}
8430
+			if ((isset($cookie['expires'])) && (!empty($cookie['expires']))) {
8431
+				if (strtotime($cookie['expires']) > time()) {
8432
+					$this->cookies[] = $cookie;
8433
+				} else {
8434
+					$this->debug('Remove expired cookie ' . $cookie['name']);
8435
+				}
8436
+			} else {
8437
+				$this->cookies[] = $cookie;
8438
+			}
8439
+		}
8440
+		$this->debug('checkCookie: ' . sizeof($this->cookies) . ' cookies left in array');
8441
+		return true;
8442
+	}
8443
+
8444
+	/**
8445
+	 * updates the current cookies with a new set
8446
+	 *
8447
+	 * @param    array $cookies new cookies with which to update current ones
8448
+	 * @return    boolean always return true
8449
+	 * @access    private
8450
+	 */
8451
+	function UpdateCookies($cookies)
8452
+	{
8453
+		if (sizeof($this->cookies) == 0) {
8454
+			// no existing cookies: take whatever is new
8455
+			if (sizeof($cookies) > 0) {
8456
+				$this->debug('Setting new cookie(s)');
8457
+				$this->cookies = $cookies;
8458
+			}
8459
+			return true;
8460
+		}
8461
+		if (sizeof($cookies) == 0) {
8462
+			// no new cookies: keep what we've got
8463
+			return true;
8464
+		}
8465
+		// merge
8466
+		foreach ($cookies as $newCookie) {
8467
+			if (!is_array($newCookie)) {
8468
+				continue;
8469
+			}
8470
+			if ((!isset($newCookie['name'])) || (!isset($newCookie['value']))) {
8471
+				continue;
8472
+			}
8473
+			$newName = $newCookie['name'];
8474
+
8475
+			$found = false;
8476
+			for ($i = 0; $i < count($this->cookies); $i++) {
8477
+				$cookie = $this->cookies[$i];
8478
+				if (!is_array($cookie)) {
8479
+					continue;
8480
+				}
8481
+				if (!isset($cookie['name'])) {
8482
+					continue;
8483
+				}
8484
+				if ($newName != $cookie['name']) {
8485
+					continue;
8486
+				}
8487
+				$newDomain = isset($newCookie['domain']) ? $newCookie['domain'] : 'NODOMAIN';
8488
+				$domain = isset($cookie['domain']) ? $cookie['domain'] : 'NODOMAIN';
8489
+				if ($newDomain != $domain) {
8490
+					continue;
8491
+				}
8492
+				$newPath = isset($newCookie['path']) ? $newCookie['path'] : 'NOPATH';
8493
+				$path = isset($cookie['path']) ? $cookie['path'] : 'NOPATH';
8494
+				if ($newPath != $path) {
8495
+					continue;
8496
+				}
8497
+				$this->cookies[$i] = $newCookie;
8498
+				$found = true;
8499
+				$this->debug('Update cookie ' . $newName . '=' . $newCookie['value']);
8500
+				break;
8501
+			}
8502
+			if (!$found) {
8503
+				$this->debug('Add cookie ' . $newName . '=' . $newCookie['value']);
8504
+				$this->cookies[] = $newCookie;
8505
+			}
8506
+		}
8507
+		return true;
8508
+	}
8509 8509
 }
8510 8510
 
8511 8511
 
8512 8512
 if (!extension_loaded('soap')) {
8513
-    /**
8514
-     *    For backwards compatiblity, define soapclient unless the PHP SOAP extension is loaded.
8515
-     */
8516
-    class soapclient extends nusoap_client
8517
-    {
8518
-    }
8513
+	/**
8514
+	 *    For backwards compatiblity, define soapclient unless the PHP SOAP extension is loaded.
8515
+	 */
8516
+	class soapclient extends nusoap_client
8517
+	{
8518
+	}
8519 8519
 }
8520 8520
 
8521 8521
 /**
@@ -8527,189 +8527,189 @@  discard block
 block discarded – undo
8527 8527
  * @access public
8528 8528
  */
8529 8529
 class nusoap_wsdlcache {
8530
-    /**
8531
-     *	@var resource
8532
-     *	@access private
8533
-     */
8534
-    var $fplock;
8535
-    /**
8536
-     *	@var integer
8537
-     *	@access private
8538
-     */
8539
-    var $cache_lifetime;
8540
-    /**
8541
-     *	@var string
8542
-     *	@access private
8543
-     */
8544
-    var $cache_dir;
8545
-    /**
8546
-     *	@var string
8547
-     *	@access public
8548
-     */
8549
-    var $debug_str = '';
8550
-
8551
-    /**
8552
-     * constructor
8553
-     *
8554
-     * @param string $cache_dir directory for cache-files
8555
-     * @param integer $cache_lifetime lifetime for caching-files in seconds or 0 for unlimited
8556
-     * @access public
8557
-     */
8558
-    function __construct($cache_dir='.', $cache_lifetime=0) {
8559
-        $this->fplock = array();
8560
-        $this->cache_dir = $cache_dir != '' ? $cache_dir : '.';
8561
-        $this->cache_lifetime = $cache_lifetime;
8562
-    }
8563
-
8564
-    /**
8565
-     * creates the filename used to cache a wsdl instance
8566
-     *
8567
-     * @param string $wsdl The URL of the wsdl instance
8568
-     * @return string The filename used to cache the instance
8569
-     * @access private
8570
-     */
8571
-    function createFilename($wsdl) {
8572
-        return $this->cache_dir.'/wsdlcache-' . md5($wsdl);
8573
-    }
8574
-
8575
-    /**
8576
-     * adds debug data to the class level debug string
8577
-     *
8578
-     * @param    string $string debug data
8579
-     * @access   private
8580
-     */
8581
-    function debug($string){
8582
-        $this->debug_str .= get_class($this).": $string\n";
8583
-    }
8584
-
8585
-    /**
8586
-     * gets a wsdl instance from the cache
8587
-     *
8588
-     * @param string $wsdl The URL of the wsdl instance
8589
-     * @return object wsdl The cached wsdl instance, null if the instance is not in the cache
8590
-     * @access public
8591
-     */
8592
-    function get($wsdl) {
8593
-        $filename = $this->createFilename($wsdl);
8594
-        if ($this->obtainMutex($filename, "r")) {
8595
-            // check for expired WSDL that must be removed from the cache
8596
-            if ($this->cache_lifetime > 0) {
8597
-                if (file_exists($filename) && (time() - filemtime($filename) > $this->cache_lifetime)) {
8598
-                    unlink($filename);
8599
-                    $this->debug("Expired $wsdl ($filename) from cache");
8600
-                    $this->releaseMutex($filename);
8601
-                    return null;
8602
-                }
8603
-            }
8604
-            // see what there is to return
8605
-            if (!file_exists($filename)) {
8606
-                $this->debug("$wsdl ($filename) not in cache (1)");
8607
-                $this->releaseMutex($filename);
8608
-                return null;
8609
-            }
8610
-            $fp = @fopen($filename, "r");
8611
-            if ($fp) {
8612
-                $s = implode("", @file($filename));
8613
-                fclose($fp);
8614
-                $this->debug("Got $wsdl ($filename) from cache");
8615
-            } else {
8616
-                $s = null;
8617
-                $this->debug("$wsdl ($filename) not in cache (2)");
8618
-            }
8619
-            $this->releaseMutex($filename);
8620
-            return (!is_null($s)) ? unserialize($s) : null;
8621
-        } else {
8622
-            $this->debug("Unable to obtain mutex for $filename in get");
8623
-        }
8624
-        return null;
8625
-    }
8626
-
8627
-    /**
8628
-     * obtains the local mutex
8629
-     *
8630
-     * @param string $filename The Filename of the Cache to lock
8631
-     * @param string $mode The open-mode ("r" or "w") or the file - affects lock-mode
8632
-     * @return boolean Lock successfully obtained ?!
8633
-     * @access private
8634
-     */
8635
-    function obtainMutex($filename, $mode) {
8636
-        if (isset($this->fplock[md5($filename)])) {
8637
-            $this->debug("Lock for $filename already exists");
8638
-            return false;
8639
-        }
8640
-        $this->fplock[md5($filename)] = fopen($filename.".lock", "w");
8641
-        if ($mode == "r") {
8642
-            return flock($this->fplock[md5($filename)], LOCK_SH);
8643
-        } else {
8644
-            return flock($this->fplock[md5($filename)], LOCK_EX);
8645
-        }
8646
-    }
8647
-
8648
-    /**
8649
-     * adds a wsdl instance to the cache
8650
-     *
8651
-     * @param wsdl $wsdl_instance The wsdl instance to add
8652
-     * @return boolean WSDL successfully cached
8653
-     * @access public
8654
-     */
8655
-    function put($wsdl_instance) {
8656
-        $filename = $this->createFilename($wsdl_instance->wsdl);
8657
-        $s = serialize($wsdl_instance);
8658
-        if ($this->obtainMutex($filename, "w")) {
8659
-            $fp = fopen($filename, "w");
8660
-            if (! $fp) {
8661
-                $this->debug("Cannot write $wsdl_instance->wsdl ($filename) in cache");
8662
-                $this->releaseMutex($filename);
8663
-                return false;
8664
-            }
8665
-            fputs($fp, $s);
8666
-            fclose($fp);
8667
-            $this->debug("Put $wsdl_instance->wsdl ($filename) in cache");
8668
-            $this->releaseMutex($filename);
8669
-            return true;
8670
-        } else {
8671
-            $this->debug("Unable to obtain mutex for $filename in put");
8672
-        }
8673
-        return false;
8674
-    }
8675
-
8676
-    /**
8677
-     * releases the local mutex
8678
-     *
8679
-     * @param string $filename The Filename of the Cache to lock
8680
-     * @return boolean Lock successfully released
8681
-     * @access private
8682
-     */
8683
-    function releaseMutex($filename) {
8684
-        $ret = flock($this->fplock[md5($filename)], LOCK_UN);
8685
-        fclose($this->fplock[md5($filename)]);
8686
-        unset($this->fplock[md5($filename)]);
8687
-        if (! $ret) {
8688
-            $this->debug("Not able to release lock for $filename");
8689
-        }
8690
-        return $ret;
8691
-    }
8692
-
8693
-    /**
8694
-     * removes a wsdl instance from the cache
8695
-     *
8696
-     * @param string $wsdl The URL of the wsdl instance
8697
-     * @return boolean Whether there was an instance to remove
8698
-     * @access public
8699
-     */
8700
-    function remove($wsdl) {
8701
-        $filename = $this->createFilename($wsdl);
8702
-        if (!file_exists($filename)) {
8703
-            $this->debug("$wsdl ($filename) not in cache to be removed");
8704
-            return false;
8705
-        }
8706
-        // ignore errors obtaining mutex
8707
-        $this->obtainMutex($filename, "w");
8708
-        $ret = unlink($filename);
8709
-        $this->debug("Removed ($ret) $wsdl ($filename) from cache");
8710
-        $this->releaseMutex($filename);
8711
-        return $ret;
8712
-    }
8530
+	/**
8531
+	 *	@var resource
8532
+	 *	@access private
8533
+	 */
8534
+	var $fplock;
8535
+	/**
8536
+	 *	@var integer
8537
+	 *	@access private
8538
+	 */
8539
+	var $cache_lifetime;
8540
+	/**
8541
+	 *	@var string
8542
+	 *	@access private
8543
+	 */
8544
+	var $cache_dir;
8545
+	/**
8546
+	 *	@var string
8547
+	 *	@access public
8548
+	 */
8549
+	var $debug_str = '';
8550
+
8551
+	/**
8552
+	 * constructor
8553
+	 *
8554
+	 * @param string $cache_dir directory for cache-files
8555
+	 * @param integer $cache_lifetime lifetime for caching-files in seconds or 0 for unlimited
8556
+	 * @access public
8557
+	 */
8558
+	function __construct($cache_dir='.', $cache_lifetime=0) {
8559
+		$this->fplock = array();
8560
+		$this->cache_dir = $cache_dir != '' ? $cache_dir : '.';
8561
+		$this->cache_lifetime = $cache_lifetime;
8562
+	}
8563
+
8564
+	/**
8565
+	 * creates the filename used to cache a wsdl instance
8566
+	 *
8567
+	 * @param string $wsdl The URL of the wsdl instance
8568
+	 * @return string The filename used to cache the instance
8569
+	 * @access private
8570
+	 */
8571
+	function createFilename($wsdl) {
8572
+		return $this->cache_dir.'/wsdlcache-' . md5($wsdl);
8573
+	}
8574
+
8575
+	/**
8576
+	 * adds debug data to the class level debug string
8577
+	 *
8578
+	 * @param    string $string debug data
8579
+	 * @access   private
8580
+	 */
8581
+	function debug($string){
8582
+		$this->debug_str .= get_class($this).": $string\n";
8583
+	}
8584
+
8585
+	/**
8586
+	 * gets a wsdl instance from the cache
8587
+	 *
8588
+	 * @param string $wsdl The URL of the wsdl instance
8589
+	 * @return object wsdl The cached wsdl instance, null if the instance is not in the cache
8590
+	 * @access public
8591
+	 */
8592
+	function get($wsdl) {
8593
+		$filename = $this->createFilename($wsdl);
8594
+		if ($this->obtainMutex($filename, "r")) {
8595
+			// check for expired WSDL that must be removed from the cache
8596
+			if ($this->cache_lifetime > 0) {
8597
+				if (file_exists($filename) && (time() - filemtime($filename) > $this->cache_lifetime)) {
8598
+					unlink($filename);
8599
+					$this->debug("Expired $wsdl ($filename) from cache");
8600
+					$this->releaseMutex($filename);
8601
+					return null;
8602
+				}
8603
+			}
8604
+			// see what there is to return
8605
+			if (!file_exists($filename)) {
8606
+				$this->debug("$wsdl ($filename) not in cache (1)");
8607
+				$this->releaseMutex($filename);
8608
+				return null;
8609
+			}
8610
+			$fp = @fopen($filename, "r");
8611
+			if ($fp) {
8612
+				$s = implode("", @file($filename));
8613
+				fclose($fp);
8614
+				$this->debug("Got $wsdl ($filename) from cache");
8615
+			} else {
8616
+				$s = null;
8617
+				$this->debug("$wsdl ($filename) not in cache (2)");
8618
+			}
8619
+			$this->releaseMutex($filename);
8620
+			return (!is_null($s)) ? unserialize($s) : null;
8621
+		} else {
8622
+			$this->debug("Unable to obtain mutex for $filename in get");
8623
+		}
8624
+		return null;
8625
+	}
8626
+
8627
+	/**
8628
+	 * obtains the local mutex
8629
+	 *
8630
+	 * @param string $filename The Filename of the Cache to lock
8631
+	 * @param string $mode The open-mode ("r" or "w") or the file - affects lock-mode
8632
+	 * @return boolean Lock successfully obtained ?!
8633
+	 * @access private
8634
+	 */
8635
+	function obtainMutex($filename, $mode) {
8636
+		if (isset($this->fplock[md5($filename)])) {
8637
+			$this->debug("Lock for $filename already exists");
8638
+			return false;
8639
+		}
8640
+		$this->fplock[md5($filename)] = fopen($filename.".lock", "w");
8641
+		if ($mode == "r") {
8642
+			return flock($this->fplock[md5($filename)], LOCK_SH);
8643
+		} else {
8644
+			return flock($this->fplock[md5($filename)], LOCK_EX);
8645
+		}
8646
+	}
8647
+
8648
+	/**
8649
+	 * adds a wsdl instance to the cache
8650
+	 *
8651
+	 * @param wsdl $wsdl_instance The wsdl instance to add
8652
+	 * @return boolean WSDL successfully cached
8653
+	 * @access public
8654
+	 */
8655
+	function put($wsdl_instance) {
8656
+		$filename = $this->createFilename($wsdl_instance->wsdl);
8657
+		$s = serialize($wsdl_instance);
8658
+		if ($this->obtainMutex($filename, "w")) {
8659
+			$fp = fopen($filename, "w");
8660
+			if (! $fp) {
8661
+				$this->debug("Cannot write $wsdl_instance->wsdl ($filename) in cache");
8662
+				$this->releaseMutex($filename);
8663
+				return false;
8664
+			}
8665
+			fputs($fp, $s);
8666
+			fclose($fp);
8667
+			$this->debug("Put $wsdl_instance->wsdl ($filename) in cache");
8668
+			$this->releaseMutex($filename);
8669
+			return true;
8670
+		} else {
8671
+			$this->debug("Unable to obtain mutex for $filename in put");
8672
+		}
8673
+		return false;
8674
+	}
8675
+
8676
+	/**
8677
+	 * releases the local mutex
8678
+	 *
8679
+	 * @param string $filename The Filename of the Cache to lock
8680
+	 * @return boolean Lock successfully released
8681
+	 * @access private
8682
+	 */
8683
+	function releaseMutex($filename) {
8684
+		$ret = flock($this->fplock[md5($filename)], LOCK_UN);
8685
+		fclose($this->fplock[md5($filename)]);
8686
+		unset($this->fplock[md5($filename)]);
8687
+		if (! $ret) {
8688
+			$this->debug("Not able to release lock for $filename");
8689
+		}
8690
+		return $ret;
8691
+	}
8692
+
8693
+	/**
8694
+	 * removes a wsdl instance from the cache
8695
+	 *
8696
+	 * @param string $wsdl The URL of the wsdl instance
8697
+	 * @return boolean Whether there was an instance to remove
8698
+	 * @access public
8699
+	 */
8700
+	function remove($wsdl) {
8701
+		$filename = $this->createFilename($wsdl);
8702
+		if (!file_exists($filename)) {
8703
+			$this->debug("$wsdl ($filename) not in cache to be removed");
8704
+			return false;
8705
+		}
8706
+		// ignore errors obtaining mutex
8707
+		$this->obtainMutex($filename, "w");
8708
+		$ret = unlink($filename);
8709
+		$this->debug("Removed ($ret) $wsdl ($filename) from cache");
8710
+		$this->releaseMutex($filename);
8711
+		return $ret;
8712
+	}
8713 8713
 }
8714 8714
 
8715 8715
 /**
Please login to merge, or discard this patch.
htdocs/commande/messaging.php 1 patch
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -27,10 +27,10 @@  discard block
 block discarded – undo
27 27
 
28 28
 // Load Dolibarr environment
29 29
 require '../main.inc.php';
30
-require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php';
31
-require_once DOL_DOCUMENT_ROOT . '/commande/class/commande.class.php';
32
-require_once DOL_DOCUMENT_ROOT . '/core/lib/order.lib.php';
33
-require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php';
30
+require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
31
+require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
32
+require_once DOL_DOCUMENT_ROOT.'/core/lib/order.lib.php';
33
+require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
34 34
 
35 35
 /**
36 36
  * @var Conf $conf
@@ -83,14 +83,14 @@  discard block
 block discarded – undo
83 83
 $hookmanager->initHooks(array('orderagenda', 'globalcard'));
84 84
 
85 85
 // Load object
86
-include DOL_DOCUMENT_ROOT . '/core/actions_fetchobject.inc.php'; // Must be 'include', not 'include_once'. Include fetch and fetch_thirdparty but not fetch_optionals
86
+include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be 'include', not 'include_once'. Include fetch and fetch_thirdparty but not fetch_optionals
87 87
 if ($id > 0 || !empty($ref)) {
88
-	$upload_dir = $conf->order->multidir_output[!empty($object->entity) ? $object->entity : $conf->entity] . "/" . $object->id;
88
+	$upload_dir = $conf->order->multidir_output[!empty($object->entity) ? $object->entity : $conf->entity]."/".$object->id;
89 89
 }
90 90
 
91 91
 // Security check
92 92
 if ($user->socid > 0) {
93
-	$socid = $user->socid;    // For external user, no check is done on company because readability is managed by public status of order and assignment.
93
+	$socid = $user->socid; // For external user, no check is done on company because readability is managed by public status of order and assignment.
94 94
 }
95 95
 $isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
96 96
 restrictedArea($user, 'commande', $id, '', '', 'fk_soc', 'rowid', $isdraft);
@@ -137,10 +137,10 @@  discard block
 block discarded – undo
137 137
 
138 138
 $form = new Form($db);
139 139
 
140
-$agenda = (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) ? '/' . $langs->trans("Agenda") : '';
141
-$title = $langs->trans('Events') . $agenda . ' - ' . $object->ref; // Removed $object->name as orders typically don't have it
140
+$agenda = (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) ? '/'.$langs->trans("Agenda") : '';
141
+$title = $langs->trans('Events').$agenda.' - '.$object->ref; // Removed $object->name as orders typically don't have it
142 142
 if (getDolGlobalString('MAIN_HTML_TITLE') && preg_match('/ordernamonly/', getDolGlobalString('MAIN_HTML_TITLE'))) {
143
-	$title = $object->ref . ' - ' . $langs->trans("Info"); // Simplified title
143
+	$title = $object->ref.' - '.$langs->trans("Info"); // Simplified title
144 144
 }
145 145
 $help_url = "EN:Module_Orders|FR:Module_Commandes|ES:M&oacute;dulo_Pedidos";
146 146
 llxHeader("", $title, $help_url, '', 0, 0, '', '', '', 'mod-order page-card_messaging');
@@ -155,9 +155,9 @@  discard block
 block discarded – undo
155 155
 if (!empty($_SESSION['pageforbacktolist']) && !empty($_SESSION['pageforbacktolist']['order'])) {
156 156
 	$tmpurl = $_SESSION['pageforbacktolist']['order'];
157 157
 	$tmpurl = preg_replace('/__SOCID__/', (string) $object->socid, $tmpurl);
158
-	$linkback = '<a href="' . $tmpurl . (preg_match('/\?/', $tmpurl) ? '&' : '?') . 'restore_lastsearch_values=1">' . $langs->trans("BackToList") . '</a>';
158
+	$linkback = '<a href="'.$tmpurl.(preg_match('/\?/', $tmpurl) ? '&' : '?').'restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
159 159
 } else {
160
-	$linkback = '<a href="' . DOL_URL_ROOT . '/commande/list.php?restore_lastsearch_values=1">' . $langs->trans("BackToList") . '</a>';
160
+	$linkback = '<a href="'.DOL_URL_ROOT.'/commande/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
161 161
 }
162 162
 
163 163
 $morehtmlref = '<div class="refidno">';
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 $morehtmlref .= $object->ref;
166 166
 // Thirdparty
167 167
 if (!empty($object->thirdparty->id) && $object->thirdparty->id > 0) {
168
-	$morehtmlref .= '<br>' . $object->thirdparty->getNomUrl(1, 'order');
168
+	$morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1, 'order');
169 169
 }
170 170
 $morehtmlref .= '</div>';
171 171
 
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
 $out = '';
199 199
 $permok = $user->hasRight('agenda', 'myactions', 'create');
200 200
 if ($permok) {
201
-	$out .= '&orderid=' . $object->id;
201
+	$out .= '&orderid='.$object->id;
202 202
 }
203 203
 
204 204
 
@@ -213,11 +213,11 @@  discard block
 block discarded – undo
213 213
 
214 214
 
215 215
 	// Show link to change view in message
216
-	$messagingUrl = DOL_URL_ROOT . '/commande/messaging.php?id=' . $object->id;
216
+	$messagingUrl = DOL_URL_ROOT.'/commande/messaging.php?id='.$object->id;
217 217
 	$morehtmlright .= dolGetButtonTitle($langs->trans('ShowAsConversation'), '', 'fa fa-comments imgforviewmode', $messagingUrl, '', 2);
218 218
 
219 219
 	// Show link to change view in agenda
220
-	$messagingUrl = DOL_URL_ROOT . '/commande/agenda.php?id=' . $object->id;
220
+	$messagingUrl = DOL_URL_ROOT.'/commande/agenda.php?id='.$object->id;
221 221
 	$morehtmlright .= dolGetButtonTitle($langs->trans('MessageListViewType'), '', 'fa fa-bars imgforviewmode', $messagingUrl, '', 1);
222 222
 
223 223
 
@@ -234,24 +234,24 @@  discard block
 block discarded – undo
234 234
 	// Show link to add event
235 235
 	if (isModEnabled('agenda')) {
236 236
 		$addActionBtnRight = $user->hasRight('agenda', 'myactions', 'create') || $user->hasRight('agenda', 'allactions', 'create');
237
-		$morehtmlright .= dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', DOL_URL_ROOT . '/comm/action/card.php?action=create' . $out . '&socid=' . $object->socid . '&backtopage=' . urlencode($_SERVER["PHP_SELF"] . '?id=' . $object->id), '', (int) $addActionBtnRight);
237
+		$morehtmlright .= dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/comm/action/card.php?action=create'.$out.'&socid='.$object->socid.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?id='.$object->id), '', (int) $addActionBtnRight);
238 238
 	}
239 239
 
240
-	$param = '&id=' . $object->id;
240
+	$param = '&id='.$object->id;
241 241
 	if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
242
-		$param .= '&contextpage=' . urlencode($contextpage);
242
+		$param .= '&contextpage='.urlencode($contextpage);
243 243
 	}
244 244
 	if ($limit > 0 && $limit != $conf->liste_limit) {
245
-		$param .= '&limit=' . ((int) $limit);
245
+		$param .= '&limit='.((int) $limit);
246 246
 	}
247 247
 
248
-	require_once DOL_DOCUMENT_ROOT . '/core/lib/memory.lib.php';
249
-	$cachekey = 'count_events_order_' . $object->id;
248
+	require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
249
+	$cachekey = 'count_events_order_'.$object->id;
250 250
 	$nbEvent = dol_getcache($cachekey);
251 251
 
252
-	$titlelist = $langs->trans("ActionsOnOrder") . (is_numeric($nbEvent) ? '<span class="opacitymedium colorblack paddingleft">(' . $nbEvent . ')</span>' : '');
252
+	$titlelist = $langs->trans("ActionsOnOrder").(is_numeric($nbEvent) ? '<span class="opacitymedium colorblack paddingleft">('.$nbEvent.')</span>' : '');
253 253
 	if (!empty($conf->dol_optimize_smallscreen)) {
254
-		$titlelist = $langs->trans("Actions") . (is_numeric($nbEvent) ? '<span class="opacitymedium colorblack paddingleft">(' . $nbEvent . ')</span>' : '');
254
+		$titlelist = $langs->trans("Actions").(is_numeric($nbEvent) ? '<span class="opacitymedium colorblack paddingleft">('.$nbEvent.')</span>' : '');
255 255
 	}
256 256
 
257 257
 	print_barre_liste($titlelist, 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', 0, -1, '', 0, $morehtmlright, '', 0, 1, 0);
Please login to merge, or discard this patch.
htdocs/commande/agenda.php 1 patch
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -27,12 +27,12 @@  discard block
 block discarded – undo
27 27
 
28 28
 // Load Dolibarr environment
29 29
 require '../main.inc.php';
30
-require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php';
31
-require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php'; // Added for contact object
32
-require_once DOL_DOCUMENT_ROOT . '/commande/class/commande.class.php';
33
-require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php'; // Keep if you use project linking in order
34
-require_once DOL_DOCUMENT_ROOT . '/core/lib/order.lib.php';
35
-require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php';
30
+require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
31
+require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; // Added for contact object
32
+require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
33
+require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; // Keep if you use project linking in order
34
+require_once DOL_DOCUMENT_ROOT.'/core/lib/order.lib.php';
35
+require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
36 36
 
37 37
 /**
38 38
  * @var Conf $conf
@@ -83,9 +83,9 @@  discard block
 block discarded – undo
83 83
 $hookmanager->initHooks(array('orderagenda', 'globalcard'));
84 84
 
85 85
 // Load object
86
-include DOL_DOCUMENT_ROOT . '/core/actions_fetchobject.inc.php'; // Must be 'include', not 'include_once'. Include fetch and fetch_thirdparty but not fetch_optionals
86
+include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be 'include', not 'include_once'. Include fetch and fetch_thirdparty but not fetch_optionals
87 87
 if ($id > 0 || !empty($ref)) {
88
-	$upload_dir = $conf->order->multidir_output[!empty($object->entity) ? $object->entity : $conf->entity] . "/" . $object->id;
88
+	$upload_dir = $conf->order->multidir_output[!empty($object->entity) ? $object->entity : $conf->entity]."/".$object->id;
89 89
 }
90 90
 
91 91
 // Security check
@@ -136,11 +136,11 @@  discard block
 block discarded – undo
136 136
  */
137 137
 
138 138
 $form = new Form($db);
139
-$agenda = (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) ? '/' . $langs->trans("Agenda") : '';
140
-$title = $langs->trans('Events') . $agenda . ' - ' . $object->ref;
139
+$agenda = (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) ? '/'.$langs->trans("Agenda") : '';
140
+$title = $langs->trans('Events').$agenda.' - '.$object->ref;
141 141
 
142 142
 if (getDolGlobalString('MAIN_HTML_TITLE') && preg_match('/ordernamonly/', getDolGlobalString('MAIN_HTML_TITLE')) && $object->ref) {
143
-	$title = $object->ref . ' - ' . $langs->trans("Info"); // Simplified title
143
+	$title = $object->ref.' - '.$langs->trans("Info"); // Simplified title
144 144
 }
145 145
 $help_url = "EN:Module_Orders|FR:Module_Commandes|ES:M&oacute;dulo_Pedidos";
146 146
 llxHeader("", $title, $help_url, '', 0, 0, '', '', '', 'mod-order page-card_agenda');
@@ -155,9 +155,9 @@  discard block
 block discarded – undo
155 155
 if (!empty($_SESSION['pageforbacktolist']) && !empty($_SESSION['pageforbacktolist']['order'])) {
156 156
 	$tmpurl = $_SESSION['pageforbacktolist']['order'];
157 157
 	$tmpurl = preg_replace('/__SOCID__/', (string) $object->socid, $tmpurl);
158
-	$linkback = '<a href="' . $tmpurl . (preg_match('/\?/', $tmpurl) ? '&' : '?') . 'restore_lastsearch_values=1">' . $langs->trans("BackToList") . '</a>';
158
+	$linkback = '<a href="'.$tmpurl.(preg_match('/\?/', $tmpurl) ? '&' : '?').'restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
159 159
 } else {
160
-	$linkback = '<a href="' . DOL_URL_ROOT . '/commande/list.php?restore_lastsearch_values=1">' . $langs->trans("BackToList") . '</a>';
160
+	$linkback = '<a href="'.DOL_URL_ROOT.'/commande/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
161 161
 }
162 162
 
163 163
 $morehtmlref = '<div class="refidno">';
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
166 166
 $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
167 167
 // Thirdparty
168
-$morehtmlref .= '<br>' . $object->thirdparty->getNomUrl(1);
168
+$morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1);
169 169
 // Project
170 170
 if (isModEnabled('project')) {
171 171
 	$langs->load("projects");
@@ -173,16 +173,16 @@  discard block
 block discarded – undo
173 173
 	if (0) {	// @phpstan-ignore-line
174 174
 		$morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
175 175
 		if ($action != 'classify') {
176
-			$morehtmlref .= '<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token=' . newToken() . '&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> ';
176
+			$morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
177 177
 		}
178
-		$morehtmlref .= $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, (string) $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
178
+		$morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, (string) $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
179 179
 	} else {
180 180
 		if (!empty($object->fk_project)) {
181 181
 			$proj = new Project($db);
182 182
 			$proj->fetch($object->fk_project);
183 183
 			$morehtmlref .= $proj->getNomUrl(1);
184 184
 			if ($proj->title) {
185
-				$morehtmlref .= '<span class="opacitymedium"> - ' . dol_escape_htmltag($proj->title) . '</span>';
185
+				$morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
186 186
 			}
187 187
 		}
188 188
 	}
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
 $out = '';
215 215
 $permok = $user->hasRight('agenda', 'myactions', 'create');
216 216
 if ($permok) {
217
-	$out .= '&orderid=' . $object->id;
217
+	$out .= '&orderid='.$object->id;
218 218
 }
219 219
 
220 220
 
@@ -228,35 +228,35 @@  discard block
 block discarded – undo
228 228
 	$morehtmlright = '';
229 229
 
230 230
 	// Show link to change view in message
231
-	$messagingUrl = DOL_URL_ROOT . '/commande/messaging.php?id=' . $object->id;
231
+	$messagingUrl = DOL_URL_ROOT.'/commande/messaging.php?id='.$object->id;
232 232
 	$morehtmlright .= dolGetButtonTitle($langs->trans('ShowAsConversation'), '', 'fa fa-comments imgforviewmode', $messagingUrl, '', 1); // Status 1 for "not current page"
233 233
 
234 234
 
235 235
 	// Show link to change view in agenda
236
-	$messagingUrl = DOL_URL_ROOT . '/commande/agenda.php?id=' . $object->id;
236
+	$messagingUrl = DOL_URL_ROOT.'/commande/agenda.php?id='.$object->id;
237 237
 	$morehtmlright .= dolGetButtonTitle($langs->trans('MessageListViewType'), '', 'fa fa-bars imgforviewmode', $messagingUrl, '', 2); // Status 2 for "current page"
238 238
 
239 239
 	// Show link to add event
240 240
 	if (isModEnabled('agenda')) {
241 241
 		$addActionBtnRight = $user->hasRight('agenda', 'myactions', 'create') || $user->hasRight('agenda', 'allactions', 'create');
242
-		$morehtmlright .= dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', DOL_URL_ROOT . '/comm/action/card.php?action=create' . $out . '&socid=' . $object->socid . '&backtopage=' . urlencode($_SERVER["PHP_SELF"] . '?id=' . $object->id), '', (int) $addActionBtnRight);
242
+		$morehtmlright .= dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/comm/action/card.php?action=create'.$out.'&socid='.$object->socid.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?id='.$object->id), '', (int) $addActionBtnRight);
243 243
 	}
244 244
 
245
-	$param = '&id=' . $object->id;
245
+	$param = '&id='.$object->id;
246 246
 	if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
247
-		$param .= '&contextpage=' . urlencode($contextpage);
247
+		$param .= '&contextpage='.urlencode($contextpage);
248 248
 	}
249 249
 	if ($limit > 0 && $limit != $conf->liste_limit) {
250
-		$param .= '&limit=' . ((int) $limit);
250
+		$param .= '&limit='.((int) $limit);
251 251
 	}
252 252
 
253
-	require_once DOL_DOCUMENT_ROOT . '/core/lib/memory.lib.php';
254
-	$cachekey = 'count_events_commande_' . $object->id;
253
+	require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
254
+	$cachekey = 'count_events_commande_'.$object->id;
255 255
 	$nbEvent = dol_getcache($cachekey);
256 256
 
257
-	$titlelist = $langs->trans("ActionsOnOrder") . (is_numeric($nbEvent) ? '<span class="opacitymedium colorblack paddingleft">(' . $nbEvent . ')</span>' : '');
257
+	$titlelist = $langs->trans("ActionsOnOrder").(is_numeric($nbEvent) ? '<span class="opacitymedium colorblack paddingleft">('.$nbEvent.')</span>' : '');
258 258
 	if (!empty($conf->dol_optimize_smallscreen)) {
259
-		$titlelist = $langs->trans("Actions") . (is_numeric($nbEvent) ? '<span class="opacitymedium colorblack paddingleft">(' . $nbEvent . ')</span>' : '');
259
+		$titlelist = $langs->trans("Actions").(is_numeric($nbEvent) ? '<span class="opacitymedium colorblack paddingleft">('.$nbEvent.')</span>' : '');
260 260
 	}
261 261
 
262 262
 	print_barre_liste($titlelist, 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', 0, -1, '', 0, $morehtmlright, '', 0, 1, 0);
Please login to merge, or discard this patch.
htdocs/expedition/messaging.php 1 patch
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -27,11 +27,11 @@  discard block
 block discarded – undo
27 27
 
28 28
 // Load Dolibarr environment
29 29
 require '../main.inc.php';
30
-require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php';
31
-require_once DOL_DOCUMENT_ROOT . '/expedition/class/expedition.class.php';
32
-require_once DOL_DOCUMENT_ROOT . '/core/lib/expedition.lib.php';
33
-require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php';
34
-require_once DOL_DOCUMENT_ROOT . '/core/lib/sendings.lib.php';
30
+require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
31
+require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
32
+require_once DOL_DOCUMENT_ROOT.'/core/lib/expedition.lib.php';
33
+require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
34
+require_once DOL_DOCUMENT_ROOT.'/core/lib/sendings.lib.php';
35 35
 
36 36
 
37 37
 /**
@@ -123,11 +123,11 @@  discard block
 block discarded – undo
123 123
  */
124 124
 
125 125
 $form = new Form($db);
126
-$agenda = (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) ? '/' . $langs->trans("Agenda") : '';
127
-$title = $langs->trans('Events') . $agenda . ' - ' . $object->ref; // Shipping uses ref primarily
126
+$agenda = (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) ? '/'.$langs->trans("Agenda") : '';
127
+$title = $langs->trans('Events').$agenda.' - '.$object->ref; // Shipping uses ref primarily
128 128
 
129 129
 if (getDolGlobalString('MAIN_HTML_TITLE') && preg_match('/shippingrefonly/', getDolGlobalString('MAIN_HTML_TITLE')) && $object->ref) { // New constant or fallback
130
-	$title = $object->ref . ' - ' . $langs->trans("Info");
130
+	$title = $object->ref.' - '.$langs->trans("Info");
131 131
 }
132 132
 $help_url = "EN:Module_Shippings|FR:Module_Expeditions|ES:M&oacute;dulo_Expediciones";
133 133
 llxHeader("", $title, $help_url, '', 0, 0, '', '', '', 'mod-shipping page-card_messaging');
@@ -142,9 +142,9 @@  discard block
 block discarded – undo
142 142
 if (!empty($_SESSION['pageforbacktolist']) && !empty($_SESSION['pageforbacktolist']['expedition'])) {
143 143
 	$tmpurl = $_SESSION['pageforbacktolist']['expedition'];
144 144
 	$tmpurl = preg_replace('/__SOCID__/', (string) $object->socid, $tmpurl);
145
-	$linkback = '<a href="' . $tmpurl . (preg_match('/\?/', $tmpurl) ? '&' : '?') . 'restore_lastsearch_values=1">' . $langs->trans("BackToList") . '</a>';
145
+	$linkback = '<a href="'.$tmpurl.(preg_match('/\?/', $tmpurl) ? '&' : '?').'restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
146 146
 } else {
147
-	$linkback = '<a href="' . DOL_URL_ROOT . '/expedition/list.php?restore_lastsearch_values=1">' . $langs->trans("BackToList") . '</a>';
147
+	$linkback = '<a href="'.DOL_URL_ROOT.'/expedition/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
148 148
 }
149 149
 
150 150
 $morehtmlref = '<div class="refidno">';
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
 $morehtmlref .= $object->ref;
153 153
 // Thirdparty
154 154
 if (!empty($object->thirdparty->id) && $object->thirdparty->id > 0) {
155
-	$morehtmlref .= '<br>' . $object->thirdparty->getNomUrl(1, 'shipping');
155
+	$morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1, 'shipping');
156 156
 }
157 157
 $morehtmlref .= '</div>';
158 158
 
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
 $out = '';
180 180
 $permok = $user->hasRight('agenda', 'myactions', 'create');
181 181
 if ($permok) {
182
-	$out .= '&shippingid=' . $object->id;
182
+	$out .= '&shippingid='.$object->id;
183 183
 }
184 184
 
185 185
 
@@ -190,35 +190,35 @@  discard block
 block discarded – undo
190 190
 	$morehtmlright = '';
191 191
 
192 192
 	// Show link to change view in message
193
-	$messagingUrl = DOL_URL_ROOT . '/expedition/messaging.php?id=' . $object->id;
193
+	$messagingUrl = DOL_URL_ROOT.'/expedition/messaging.php?id='.$object->id;
194 194
 	$morehtmlright .= dolGetButtonTitle($langs->trans('ShowAsConversation'), '', 'fa fa-comments imgforviewmode', $messagingUrl, '', 2); // Status 2 for "current page"
195 195
 
196 196
 	// Show link to change view in agenda
197
-	$messagingUrl = DOL_URL_ROOT . '/expedition/agenda.php?id=' . $object->id;
197
+	$messagingUrl = DOL_URL_ROOT.'/expedition/agenda.php?id='.$object->id;
198 198
 	$morehtmlright .= dolGetButtonTitle($langs->trans('MessageListViewType'), '', 'fa fa-bars imgforviewmode', $messagingUrl, '', 1); // Status 1 for "not current page"
199 199
 
200 200
 
201 201
 	// Show link to add event
202 202
 	if (isModEnabled('agenda')) {
203 203
 		$addActionBtnRight = $user->hasRight('agenda', 'myactions', 'create') || $user->hasRight('agenda', 'allactions', 'create');
204
-		$morehtmlright .= dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', DOL_URL_ROOT . '/comm/action/card.php?action=create' . $out . '&socid=' . $object->socid . '&backtopage=' . urlencode($_SERVER["PHP_SELF"] . '?id=' . $object->id), '', (int) $addActionBtnRight);
204
+		$morehtmlright .= dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/comm/action/card.php?action=create'.$out.'&socid='.$object->socid.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?id='.$object->id), '', (int) $addActionBtnRight);
205 205
 	}
206 206
 
207
-	$param = '&id=' . $object->id;
207
+	$param = '&id='.$object->id;
208 208
 	if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
209
-		$param .= '&contextpage=' . urlencode($contextpage);
209
+		$param .= '&contextpage='.urlencode($contextpage);
210 210
 	}
211 211
 	if ($limit > 0 && $limit != $conf->liste_limit) {
212
-		$param .= '&limit=' . ((int) $limit);
212
+		$param .= '&limit='.((int) $limit);
213 213
 	}
214 214
 
215
-	require_once DOL_DOCUMENT_ROOT . '/core/lib/memory.lib.php';
216
-	$cachekey = 'count_events_expedition_' . $object->id;
215
+	require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
216
+	$cachekey = 'count_events_expedition_'.$object->id;
217 217
 	$nbEvent = dol_getcache($cachekey);
218 218
 
219
-	$titlelist = $langs->trans("ActionsOnShipping") . (is_numeric($nbEvent) ? '<span class="opacitymedium colorblack paddingleft">(' . $nbEvent . ')</span>' : '');
219
+	$titlelist = $langs->trans("ActionsOnShipping").(is_numeric($nbEvent) ? '<span class="opacitymedium colorblack paddingleft">('.$nbEvent.')</span>' : '');
220 220
 	if (!empty($conf->dol_optimize_smallscreen)) {
221
-		$titlelist = $langs->trans("Actions") . (is_numeric($nbEvent) ? '<span class="opacitymedium colorblack paddingleft">(' . $nbEvent . ')</span>' : '');
221
+		$titlelist = $langs->trans("Actions").(is_numeric($nbEvent) ? '<span class="opacitymedium colorblack paddingleft">('.$nbEvent.')</span>' : '');
222 222
 	}
223 223
 
224 224
 	print_barre_liste($titlelist, 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', 0, -1, '', 0, $morehtmlright, '', 0, 1, 0);
Please login to merge, or discard this patch.
htdocs/expedition/agenda.php 1 patch
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -27,16 +27,16 @@  discard block
 block discarded – undo
27 27
 
28 28
 // Load Dolibarr environment
29 29
 require '../main.inc.php';
30
-require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php';
31
-require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php';
32
-require_once DOL_DOCUMENT_ROOT . '/expedition/class/expedition.class.php';
33
-require_once DOL_DOCUMENT_ROOT . '/core/modules/expedition/modules_expedition.php';
34
-require_once DOL_DOCUMENT_ROOT . '/core/lib/sendings.lib.php';
30
+require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
31
+require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
32
+require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
33
+require_once DOL_DOCUMENT_ROOT.'/core/modules/expedition/modules_expedition.php';
34
+require_once DOL_DOCUMENT_ROOT.'/core/lib/sendings.lib.php';
35 35
 
36
-require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
37
-require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php';
38
-require_once DOL_DOCUMENT_ROOT . '/core/lib/expedition.lib.php';
39
-require_once DOL_DOCUMENT_ROOT . '/core/class/html.form.class.php';
36
+require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
37
+require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
38
+require_once DOL_DOCUMENT_ROOT.'/core/lib/expedition.lib.php';
39
+require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
40 40
 
41 41
 /**
42 42
  * @var Conf $conf
@@ -125,11 +125,11 @@  discard block
 block discarded – undo
125 125
  */
126 126
 
127 127
 $form = new Form($db);
128
-$agenda = (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) ? '/' . $langs->trans("Agenda") : '';
129
-$title = $langs->trans('Events') . $agenda . ' - ' . $object->ref; // Shipping uses ref primarily
128
+$agenda = (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) ? '/'.$langs->trans("Agenda") : '';
129
+$title = $langs->trans('Events').$agenda.' - '.$object->ref; // Shipping uses ref primarily
130 130
 
131 131
 if (getDolGlobalString('MAIN_HTML_TITLE') && preg_match('/shippingrefonly/', getDolGlobalString('MAIN_HTML_TITLE')) && $object->ref) { // New constant or fallback
132
-	$title = $object->ref . ' - ' . $langs->trans("Info");
132
+	$title = $object->ref.' - '.$langs->trans("Info");
133 133
 }
134 134
 $help_url = "EN:Module_Shippings|FR:Module_Expeditions|ES:M&oacute;dulo_Expediciones";
135 135
 llxHeader("", $title, $help_url, '', 0, 0, '', '', '', 'mod-shipping page-card_agenda');
@@ -143,9 +143,9 @@  discard block
 block discarded – undo
143 143
 if (!empty($_SESSION['pageforbacktolist']) && !empty($_SESSION['pageforbacktolist']['expedition'])) {
144 144
 	$tmpurl = $_SESSION['pageforbacktolist']['expedition'];
145 145
 	$tmpurl = preg_replace('/__SOCID__/', (string) $object->socid, $tmpurl);
146
-	$linkback = '<a href="' . $tmpurl . (preg_match('/\?/', $tmpurl) ? '&' : '?') . 'restore_lastsearch_values=1">' . $langs->trans("BackToList") . '</a>';
146
+	$linkback = '<a href="'.$tmpurl.(preg_match('/\?/', $tmpurl) ? '&' : '?').'restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
147 147
 } else {
148
-	$linkback = '<a href="' . DOL_URL_ROOT . '/expedition/list.php?restore_lastsearch_values=1">' . $langs->trans("BackToList") . '</a>'; // Changed from commande
148
+	$linkback = '<a href="'.DOL_URL_ROOT.'/expedition/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>'; // Changed from commande
149 149
 }
150 150
 
151 151
 $morehtmlref = '<div class="refidno">';
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
 $morehtmlref .= $object->ref;
154 154
 // Thirdparty
155 155
 if (!empty($object->thirdparty->id) && $object->thirdparty->id > 0) {
156
-	$morehtmlref .= '<br>' . $object->thirdparty->getNomUrl(1, 'shipping');
156
+	$morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1, 'shipping');
157 157
 }
158 158
 // Project - Keep as is if shipping can be linked to projects
159 159
 if (isModEnabled('project')) {
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
 		$proj->fetch($object->fk_project);
165 165
 		$morehtmlref .= $proj->getNomUrl(1);
166 166
 		if ($proj->title) {
167
-			$morehtmlref .= '<span class="opacitymedium"> - ' . dol_escape_htmltag($proj->title) . '</span>';
167
+			$morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
168 168
 		}
169 169
 	}
170 170
 }
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
 $out = '';
193 193
 $permok = $user->hasRight('agenda', 'myactions', 'create');
194 194
 if ($permok) {
195
-	$out .= '&shippingid=' . $object->id;
195
+	$out .= '&shippingid='.$object->id;
196 196
 }
197 197
 
198 198
 
@@ -202,35 +202,35 @@  discard block
 block discarded – undo
202 202
 	$morehtmlright = '';
203 203
 
204 204
 	// Show link to change view in message
205
-	$messagingUrl = DOL_URL_ROOT . '/expedition/messaging.php?id=' . $object->id;
205
+	$messagingUrl = DOL_URL_ROOT.'/expedition/messaging.php?id='.$object->id;
206 206
 	$morehtmlright .= dolGetButtonTitle($langs->trans('ShowAsConversation'), '', 'fa fa-comments imgforviewmode', $messagingUrl, '', 1);
207 207
 
208 208
 	// Show link to change view in agenda
209
-	$messagingUrl = DOL_URL_ROOT . '/expedition/agenda.php?id=' . $object->id;
209
+	$messagingUrl = DOL_URL_ROOT.'/expedition/agenda.php?id='.$object->id;
210 210
 	$morehtmlright .= dolGetButtonTitle($langs->trans('MessageListViewType'), '', 'fa fa-bars imgforviewmode', $messagingUrl, '', 2);
211 211
 
212 212
 
213 213
 	// Show link to add event
214 214
 	if (isModEnabled('agenda')) {
215 215
 		$addActionBtnRight = $user->hasRight('agenda', 'myactions', 'create') || $user->hasRight('agenda', 'allactions', 'create');
216
-		$morehtmlright .= dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', DOL_URL_ROOT . '/comm/action/card.php?action=create' . $out . '&socid=' . $object->socid . '&backtopage=' . urlencode($_SERVER["PHP_SELF"] . '?id=' . $object->id), '', (int) $addActionBtnRight);
216
+		$morehtmlright .= dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/comm/action/card.php?action=create'.$out.'&socid='.$object->socid.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?id='.$object->id), '', (int) $addActionBtnRight);
217 217
 	}
218 218
 
219
-	$param = '&id=' . $object->id;
219
+	$param = '&id='.$object->id;
220 220
 	if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
221
-		$param .= '&contextpage=' . urlencode($contextpage);
221
+		$param .= '&contextpage='.urlencode($contextpage);
222 222
 	}
223 223
 	if ($limit > 0 && $limit != $conf->liste_limit) {
224
-		$param .= '&limit=' . ((int) $limit);
224
+		$param .= '&limit='.((int) $limit);
225 225
 	}
226 226
 
227
-	require_once DOL_DOCUMENT_ROOT . '/core/lib/memory.lib.php';
228
-	$cachekey = 'count_events_expedition_' . $object->id;
227
+	require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
228
+	$cachekey = 'count_events_expedition_'.$object->id;
229 229
 	$nbEvent = dol_getcache($cachekey);
230 230
 
231
-	$titlelist = $langs->trans("ActionsOnShipping") . (is_numeric($nbEvent) ? '<span class="opacitymedium colorblack paddingleft">(' . $nbEvent . ')</span>' : '');
231
+	$titlelist = $langs->trans("ActionsOnShipping").(is_numeric($nbEvent) ? '<span class="opacitymedium colorblack paddingleft">('.$nbEvent.')</span>' : '');
232 232
 	if (!empty($conf->dol_optimize_smallscreen)) {
233
-		$titlelist = $langs->trans("Actions") . (is_numeric($nbEvent) ? '<span class="opacitymedium colorblack paddingleft">(' . $nbEvent . ')</span>' : '');
233
+		$titlelist = $langs->trans("Actions").(is_numeric($nbEvent) ? '<span class="opacitymedium colorblack paddingleft">('.$nbEvent.')</span>' : '');
234 234
 	}
235 235
 
236 236
 	print_barre_liste($titlelist, 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', 0, -1, '', 0, $morehtmlright, '', 0, 1, 0);
Please login to merge, or discard this patch.
htdocs/compta/bank/class/api_bankaccounts.class.php 1 patch
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 
22 22
 use Luracast\Restler\RestException;
23 23
 
24
-require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php';
24
+require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
25 25
 
26 26
 /**
27 27
  * API class for accounts
@@ -78,12 +78,12 @@  discard block
 block discarded – undo
78 78
 
79 79
 		$sql = "SELECT t.rowid FROM ".MAIN_DB_PREFIX."bank_account AS t LEFT JOIN ".MAIN_DB_PREFIX."bank_account_extrafields AS ef ON (ef.fk_object = t.rowid)"; // Modification VMR Global Solutions to include extrafields as search parameters in the API GET call, so we will be able to filter on extrafields
80 80
 		if ($category > 0) {
81
-			$sql .= ", " . MAIN_DB_PREFIX . "categorie_account as c";
81
+			$sql .= ", ".MAIN_DB_PREFIX."categorie_account as c";
82 82
 		}
83
-		$sql .= ' WHERE t.entity IN (' . getEntity('bank_account') . ')';
83
+		$sql .= ' WHERE t.entity IN ('.getEntity('bank_account').')';
84 84
 		// Select accounts of given category
85 85
 		if ($category > 0) {
86
-			$sql .= " AND c.fk_categorie = " . ((int) $category) . " AND c.fk_account = t.rowid";
86
+			$sql .= " AND c.fk_categorie = ".((int) $category)." AND c.fk_account = t.rowid";
87 87
 		}
88 88
 		// Add sql filters
89 89
 		if ($sqlfilters) {
@@ -114,12 +114,12 @@  discard block
 block discarded – undo
114 114
 				$obj = $this->db->fetch_object($result);
115 115
 				$account = new Account($this->db);
116 116
 				if ($account->fetch($obj->rowid) > 0) {
117
-					$account->balance = $account->solde(1);  // 1=Exclude future operation date
117
+					$account->balance = $account->solde(1); // 1=Exclude future operation date
118 118
 					$list[] = $this->_filterObjectProperties($this->_cleanObjectDatas($account), $properties);
119 119
 				}
120 120
 			}
121 121
 		} else {
122
-			throw new RestException(503, 'Error when retrieving list of accounts: ' . $this->db->lasterror());
122
+			throw new RestException(503, 'Error when retrieving list of accounts: '.$this->db->lasterror());
123 123
 		}
124 124
 
125 125
 		return $list;
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
 			throw new RestException(403);
218 218
 		}
219 219
 
220
-		require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php';
220
+		require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
221 221
 
222 222
 		$accountfrom = new Account($this->db);
223 223
 		$resultAccountFrom = $accountfrom->fetch($bankaccount_from_id);
@@ -293,7 +293,7 @@  discard block
 block discarded – undo
293 293
 		 * Creating links between bank line record and its source
294 294
 		 */
295 295
 
296
-		$url = DOL_URL_ROOT . '/compta/bank/line.php?rowid=';
296
+		$url = DOL_URL_ROOT.'/compta/bank/line.php?rowid=';
297 297
 		$label = '(banktransfert)';
298 298
 		$type = 'banktransfert';
299 299
 
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
 			);
325 325
 		} else {
326 326
 			$this->db->rollback();
327
-			throw new RestException(500, $accountfrom->error . ' ' . $accountto->error);
327
+			throw new RestException(500, $accountfrom->error.' '.$accountto->error);
328 328
 		}
329 329
 	}
330 330
 
@@ -473,8 +473,8 @@  discard block
 block discarded – undo
473 473
 			throw new RestException(404, 'account not found');
474 474
 		}
475 475
 
476
-		$sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "bank ";
477
-		$sql .= " WHERE fk_account = " . ((int) $id);
476
+		$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."bank ";
477
+		$sql .= " WHERE fk_account = ".((int) $id);
478 478
 
479 479
 		// Add sql filters
480 480
 		if ($sqlfilters) {
@@ -499,7 +499,7 @@  discard block
 block discarded – undo
499 499
 				}
500 500
 			}
501 501
 		} else {
502
-			throw new RestException(503, 'Error when retrieving list of account lines: ' . $this->db->lasterror());
502
+			throw new RestException(503, 'Error when retrieving list of account lines: '.$this->db->lasterror());
503 503
 		}
504 504
 
505 505
 		return $list;
@@ -559,7 +559,7 @@  discard block
 block discarded – undo
559 559
 			$num_releve
560 560
 		);
561 561
 		if ($result < 0) {
562
-			throw new RestException(503, 'Error when adding line to account: ' . $account->error);
562
+			throw new RestException(503, 'Error when adding line to account: '.$account->error);
563 563
 		}
564 564
 		return $result;
565 565
 	}
@@ -601,7 +601,7 @@  discard block
 block discarded – undo
601 601
 
602 602
 		$result = $account->add_url_line($line_id, $url_id, $url, $label, $type);
603 603
 		if ($result < 0) {
604
-			throw new RestException(503, 'Error when adding link to account line: ' . $account->error);
604
+			throw new RestException(503, 'Error when adding link to account line: '.$account->error);
605 605
 		}
606 606
 		return $result;
607 607
 	}
@@ -671,7 +671,7 @@  discard block
 block discarded – undo
671 671
 
672 672
 		$result = $accountLine->updateLabel();
673 673
 		if ($result < 0) {
674
-			throw new RestException(503, 'Error when updating link to account line: ' . $accountLine->error);
674
+			throw new RestException(503, 'Error when updating link to account line: '.$accountLine->error);
675 675
 		}
676 676
 		return $accountLine->id;
677 677
 	}
@@ -764,7 +764,7 @@  discard block
 block discarded – undo
764 764
 			throw new RestException(404, 'account not found');
765 765
 		}
766 766
 
767
-		$balance = $account->solde(1);  //1=Exclude future operation date (this is to exclude input made in advance and have real account sold)
767
+		$balance = $account->solde(1); //1=Exclude future operation date (this is to exclude input made in advance and have real account sold)
768 768
 
769 769
 		return $balance;
770 770
 	}
Please login to merge, or discard this patch.
htdocs/accountancy/bookkeeping/list.php 1 patch
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 $search_doc_type = GETPOST("search_doc_type", 'alpha');
72 72
 $search_doc_ref = GETPOST("search_doc_ref", 'alpha');
73 73
 
74
-$search_doc_date = GETPOSTDATE('doc_date', 'getpost');	// deprecated. Can use 'search_date_start/end'
74
+$search_doc_date = GETPOSTDATE('doc_date', 'getpost'); // deprecated. Can use 'search_date_start/end'
75 75
 
76 76
 $search_date_start = GETPOSTDATE('search_date_start', 'getpost', 'auto', 'search_date_start_accountancy');
77 77
 $search_date_end = GETPOSTDATE('search_date_end', 'getpostend', 'auto', 'search_date_end_accountancy');
@@ -163,9 +163,9 @@  discard block
 block discarded – undo
163 163
 		$sql = "SELECT date_start, date_end";
164 164
 		$sql .= " FROM ".MAIN_DB_PREFIX."accounting_fiscalyear ";
165 165
 		if (getDolGlobalInt('ACCOUNTANCY_FISCALYEAR_DEFAULT')) {
166
-			$sql .= " WHERE rowid = " . getDolGlobalInt('ACCOUNTANCY_FISCALYEAR_DEFAULT');
166
+			$sql .= " WHERE rowid = ".getDolGlobalInt('ACCOUNTANCY_FISCALYEAR_DEFAULT');
167 167
 		} else {
168
-			$sql .= " WHERE date_start < '" . $db->idate(dol_now()) . "' and date_end > '" . $db->idate(dol_now()) . "'";
168
+			$sql .= " WHERE date_start < '".$db->idate(dol_now())."' and date_end > '".$db->idate(dol_now())."'";
169 169
 		}
170 170
 		$sql .= $db->plimit(1);
171 171
 		$res = $db->query($sql);
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
 		$search_date_due_start = '';
288 288
 		// Due date end
289 289
 		$search_date_due_end_day = '';
290
-		$search_date_due_end_month =  '';
290
+		$search_date_due_end_month = '';
291 291
 		$search_date_due_end_year = '';
292 292
 		$search_date_due_end = '';
293 293
 		$search_debit = '';
@@ -463,7 +463,7 @@  discard block
 block discarded – undo
463 463
 	// Actions
464 464
 	if ($action === 'exporttopdf' && $permissiontoadd) {
465 465
 		$object->fetchAll('ASC,ASC,ASC', 'code_journal,doc_date,piece_num', 0, 0, $filter);
466
-		require_once DOL_DOCUMENT_ROOT . '/core/modules/accountancy/doc/pdf_bookkeeping.modules.php';
466
+		require_once DOL_DOCUMENT_ROOT.'/core/modules/accountancy/doc/pdf_bookkeeping.modules.php';
467 467
 		$pdf = new pdf_bookkeeping($db);
468 468
 		$pdf->fromDate = $search_date_start;
469 469
 		$pdf->toDate = $search_date_end;
@@ -608,7 +608,7 @@  discard block
 block discarded – undo
608 608
 			}
609 609
 
610 610
 			if (!$error) {
611
-				header('Location: ' . $_SERVER['PHP_SELF'] . '?noreset=1' . $param);
611
+				header('Location: '.$_SERVER['PHP_SELF'].'?noreset=1'.$param);
612 612
 				exit();
613 613
 			}
614 614
 		} elseif ($massaction == 'letteringmanual' && $permissiontoadd) {
@@ -618,7 +618,7 @@  discard block
 block discarded – undo
618 618
 				setEventMessages('', $lettering->errors, 'errors');
619 619
 			} else {
620 620
 				setEventMessages($langs->trans('AccountancyOneLetteringModifiedSuccessfully'), array(), 'mesgs');
621
-				header('Location: ' . $_SERVER['PHP_SELF'] . '?noreset=1' . $param);
621
+				header('Location: '.$_SERVER['PHP_SELF'].'?noreset=1'.$param);
622 622
 				exit();
623 623
 			}
624 624
 		} elseif ($action == 'unletteringauto' && $confirm == "yes" && $permissiontoadd) {
@@ -639,7 +639,7 @@  discard block
 block discarded – undo
639 639
 			}
640 640
 
641 641
 			if (!$error) {
642
-				header('Location: ' . $_SERVER['PHP_SELF'] . '?noreset=1' . $param);
642
+				header('Location: '.$_SERVER['PHP_SELF'].'?noreset=1'.$param);
643 643
 				exit();
644 644
 			}
645 645
 		} elseif ($action == 'unletteringmanual' && $confirm == "yes" && $permissiontoadd) {
@@ -649,7 +649,7 @@  discard block
 block discarded – undo
649 649
 				setEventMessages('', $lettering->errors, 'errors');
650 650
 			} else {
651 651
 				setEventMessages($langs->trans('AccountancyOneUnletteringModifiedSuccessfully'), array(), 'mesgs');
652
-				header('Location: ' . $_SERVER['PHP_SELF'] . '?noreset=1' . $param);
652
+				header('Location: '.$_SERVER['PHP_SELF'].'?noreset=1'.$param);
653 653
 				exit();
654 654
 			}
655 655
 		}
@@ -830,10 +830,10 @@  discard block
 block discarded – undo
830 830
 // List of mass actions available
831 831
 $arrayofmassactions = array();
832 832
 if (getDolGlobalInt('ACCOUNTING_ENABLE_LETTERING') && $user->hasRight('accounting', 'mouvements', 'creer')) {
833
-	$arrayofmassactions['letteringauto'] = img_picto('', 'check', 'class="pictofixedwidth"') . $langs->trans('LetteringAuto');
834
-	$arrayofmassactions['preunletteringauto'] = img_picto('', 'uncheck', 'class="pictofixedwidth"') . $langs->trans('UnletteringAuto');
835
-	$arrayofmassactions['letteringmanual'] = img_picto('', 'check', 'class="pictofixedwidth"') . $langs->trans('LetteringManual');
836
-	$arrayofmassactions['preunletteringmanual'] = img_picto('', 'uncheck', 'class="pictofixedwidth"') . $langs->trans('UnletteringManual');
833
+	$arrayofmassactions['letteringauto'] = img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans('LetteringAuto');
834
+	$arrayofmassactions['preunletteringauto'] = img_picto('', 'uncheck', 'class="pictofixedwidth"').$langs->trans('UnletteringAuto');
835
+	$arrayofmassactions['letteringmanual'] = img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans('LetteringManual');
836
+	$arrayofmassactions['preunletteringmanual'] = img_picto('', 'uncheck', 'class="pictofixedwidth"').$langs->trans('UnletteringManual');
837 837
 }
838 838
 if ($user->hasRight('accounting', 'mouvements', 'creer')) {
839 839
 	$arrayofmassactions['preclonebookkeepingwriting'] = img_picto('', 'clone', 'class="pictofixedwidth"').$langs->trans("Clone");
@@ -882,7 +882,7 @@  discard block
 block discarded – undo
882 882
 	$newcardbutton .= dolGetButtonTitle($langs->trans('ViewFlatList'), '', 'fa fa-list paddingleft imgforviewmode', DOL_URL_ROOT.'/accountancy/bookkeeping/list.php?'.$param, '', 1, array('morecss' => 'marginleftonly btnTitleSelected'));
883 883
 	$newcardbutton .= dolGetButtonTitle($langs->trans('GroupByAccountAccounting'), '', 'fa fa-stream paddingleft imgforviewmode', DOL_URL_ROOT.'/accountancy/bookkeeping/listbyaccount.php?'.$param, '', 1, array('morecss' => 'marginleftonly'));
884 884
 	$newcardbutton .= dolGetButtonTitle($langs->trans('GroupBySubAccountAccounting'), '', 'fa fa-align-left vmirror paddingleft imgforviewmode', DOL_URL_ROOT.'/accountancy/bookkeeping/listbyaccount.php?type=sub'.$param, '', 1, array('morecss' => 'marginleftonly'));
885
-	$newcardbutton .= dolGetButtonTitle($langs->trans('ExportToPdf'), '', 'fa fa-file-pdf paddingleft', $_SERVER['PHP_SELF'] . '?action=exporttopdf&' . $param, '', 1, array('morecss' => 'marginleftonly'));
885
+	$newcardbutton .= dolGetButtonTitle($langs->trans('ExportToPdf'), '', 'fa fa-file-pdf paddingleft', $_SERVER['PHP_SELF'].'?action=exporttopdf&'.$param, '', 1, array('morecss' => 'marginleftonly'));
886 886
 
887 887
 	$url = './card.php?action=create'.(!empty($type) ? '&type=sub' : '').'&backtopage='.urlencode($_SERVER['PHP_SELF']);
888 888
 	if (!empty($socid)) {
@@ -902,16 +902,16 @@  discard block
 block discarded – undo
902 902
 	print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassDeleteBookkeepingWriting"), $langs->trans("ConfirmMassDeleteBookkeepingWritingQuestion", count($toselect)), "deletebookkeepingwriting", null, '', 0, 200, 500, 1);
903 903
 } elseif ($massaction == 'preassignaccountbookkeepingwriting') {
904 904
 	$input = $formaccounting->select_account('', 'account', 1);
905
-	$formquestion = array(array('type' => 'other', 'name' => 'account', 'label' => '<span class="fieldrequired">' . $langs->trans("AccountAccountingShort") . '</span>', 'value' => $input),);
905
+	$formquestion = array(array('type' => 'other', 'name' => 'account', 'label' => '<span class="fieldrequired">'.$langs->trans("AccountAccountingShort").'</span>', 'value' => $input),);
906 906
 	print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("confirmMassAssignAccountBookkeepingWritingConfirm"), $langs->trans("ConfirmMassAssignAccountBookkeepingWritingQuestion", count($toselect)), "assignaccountbookkeepingwriting", $formquestion, '', 0, 200, 500, 1);
907 907
 } elseif ($massaction == 'preclonebookkeepingwriting') {
908 908
 	$input1 = $form->selectDate('', 'massdate', 0, 0, 0, "create_mvt", 1, 1);
909
-	$input2 = $formaccounting->select_journal($journal_code, 'code_journal', 0, 0, 1, 1) . '</td>';
909
+	$input2 = $formaccounting->select_journal($journal_code, 'code_journal', 0, 0, 1, 1).'</td>';
910 910
 	$formquestion = array(
911 911
 		array(
912 912
 			'type' => 'other',
913 913
 			'name' => 'massdate',
914
-			'label' => '<span class="fieldrequired">' . $langs->trans("Docdate") . '</span>',
914
+			'label' => '<span class="fieldrequired">'.$langs->trans("Docdate").'</span>',
915 915
 			'value' => $input1
916 916
 		)
917 917
 	);
@@ -920,7 +920,7 @@  discard block
 block discarded – undo
920 920
 		$formquestion[] = array(
921 921
 			'type' => 'text',
922 922
 			'name' => 'code_journal',
923
-			'label' => '<span class="fieldrequired">' . $langs->trans("Codejournal") . '</span>',
923
+			'label' => '<span class="fieldrequired">'.$langs->trans("Codejournal").'</span>',
924 924
 			'value' => $input2
925 925
 		);
926 926
 	}
@@ -935,7 +935,7 @@  discard block
 block discarded – undo
935 935
 	);
936 936
 } elseif ($massaction == 'prereturnaccountbookkeepingwriting') {
937 937
 	$input1 = $form->selectDate('', 'massdate', 0, 0, 0, "create_mvt", 1, 1);
938
-	$formquestion = array(array('type' => 'other', 'name' => 'massdate', 'label' => '<span class="fieldrequired">' . $langs->trans("Docdate") . '</span>', 'value' => $input1));
938
+	$formquestion = array(array('type' => 'other', 'name' => 'massdate', 'label' => '<span class="fieldrequired">'.$langs->trans("Docdate").'</span>', 'value' => $input1));
939 939
 	print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassReturnAccountBookkeepingWriting"), $langs->trans("ConfirmMassReturnAccountBookkeepingWritingQuestion", count($toselect)), "returnaccountbookkeepingwriting", $formquestion, '', 0, 200, 500, 1);
940 940
 }
941 941
 
@@ -1304,7 +1304,7 @@  discard block
 block discarded – undo
1304 1304
 	}
1305 1305
 
1306 1306
 	// Document ref
1307
-	$modulepart = '';	// may be used by include*.tpl.php
1307
+	$modulepart = ''; // may be used by include*.tpl.php
1308 1308
 	if (!empty($arrayfields['t.doc_ref']['checked'])) {
1309 1309
 		$documentlink = '';
1310 1310
 		$objectstatic = null;
@@ -1373,8 +1373,8 @@  discard block
 block discarded – undo
1373 1373
 			$labeltoshow .= $objectstatic->getNomUrl(1);
1374 1374
 			$labeltoshowalt .= $objectstatic->ref;
1375 1375
 			$bank_ref = strstr($line->doc_ref, '-');
1376
-			$labeltoshow .= " " . $bank_ref;
1377
-			$labeltoshowalt .= " " . $bank_ref;
1376
+			$labeltoshow .= " ".$bank_ref;
1377
+			$labeltoshowalt .= " ".$bank_ref;
1378 1378
 		} else {
1379 1379
 			$labeltoshow .= $line->doc_ref;
1380 1380
 			$labeltoshowalt .= $line->doc_ref;
Please login to merge, or discard this patch.
htdocs/comm/propal/messaging.php 1 patch
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -27,11 +27,11 @@  discard block
 block discarded – undo
27 27
 
28 28
 // Load Dolibarr environment
29 29
 require '../../main.inc.php';
30
-require_once DOL_DOCUMENT_ROOT . '/comm/propal/class/propal.class.php';
31
-require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php';
32
-require_once DOL_DOCUMENT_ROOT . '/core/lib/propal.lib.php';
33
-require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php';
34
-require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
30
+require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
31
+require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
32
+require_once DOL_DOCUMENT_ROOT.'/core/lib/propal.lib.php';
33
+require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
34
+require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
35 35
 
36 36
 /**
37 37
  * @var Conf $conf
@@ -125,10 +125,10 @@  discard block
 block discarded – undo
125 125
 
126 126
 $form = new Form($db);
127 127
 
128
-$agenda = (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) ? '/' . $langs->trans("Agenda") : '';
129
-$title = $langs->trans('Events') . $agenda . ' - ' . $object->ref; // Removed $object->name as orders typically don't have it
128
+$agenda = (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) ? '/'.$langs->trans("Agenda") : '';
129
+$title = $langs->trans('Events').$agenda.' - '.$object->ref; // Removed $object->name as orders typically don't have it
130 130
 if (getDolGlobalString('MAIN_HTML_TITLE') && preg_match('/ordernamonly/', getDolGlobalString('MAIN_HTML_TITLE'))) { // Changed from projectnameonly
131
-	$title = $object->ref . ' - ' . $langs->trans("Info"); // Simplified title
131
+	$title = $object->ref.' - '.$langs->trans("Info"); // Simplified title
132 132
 }
133 133
 $help_url = 'EN:Commercial_Proposals|FR:Proposition_commerciale|ES:Presupuestos|DE:Modul_Angebote';
134 134
 
@@ -140,14 +140,14 @@  discard block
 block discarded – undo
140 140
 
141 141
 // Object card
142 142
 // ------------------------------------------------------------
143
-$linkback = '<a href="' . DOL_URL_ROOT . '/comm/propal/list.php?restore_lastsearch_values=1' . (!empty($socid) ? '&socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
143
+$linkback = '<a href="'.DOL_URL_ROOT.'/comm/propal/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
144 144
 
145 145
 $morehtmlref = '<div class="refidno">';
146 146
 // Ref customer
147 147
 $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_customer, $object, 0, 'string', '', 0, 1);
148 148
 $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_customer, $object, 0, 'string', '', null, null, '', 1);
149 149
 // Thirdparty
150
-$morehtmlref .= '<br>' . $object->thirdparty->getNomUrl(1);
150
+$morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1);
151 151
 // Project
152 152
 if (isModEnabled('project')) {
153 153
 	$langs->load("projects");
@@ -155,16 +155,16 @@  discard block
 block discarded – undo
155 155
 	if (0) {	// @phpstan-ignore-line
156 156
 		$morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
157 157
 		if ($action != 'classify') {
158
-			$morehtmlref .= '<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token=' . newToken() . '&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> ';
158
+			$morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
159 159
 		}
160
-		$morehtmlref .= $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, (string) $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
160
+		$morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, (string) $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
161 161
 	} else {
162 162
 		if (!empty($object->fk_project)) {
163 163
 			$proj = new Project($db);
164 164
 			$proj->fetch($object->fk_project);
165 165
 			$morehtmlref .= $proj->getNomUrl(1);
166 166
 			if ($proj->title) {
167
-				$morehtmlref .= '<span class="opacitymedium"> - ' . dol_escape_htmltag($proj->title) . '</span>';
167
+				$morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
168 168
 			}
169 169
 		}
170 170
 	}
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
 $out = '';
192 192
 $permok = $user->hasRight('agenda', 'myactions', 'create');
193 193
 if ($permok) {
194
-	$out .= '&propalid=' . $object->id;
194
+	$out .= '&propalid='.$object->id;
195 195
 }
196 196
 
197 197
 
@@ -206,11 +206,11 @@  discard block
 block discarded – undo
206 206
 
207 207
 
208 208
 	// Show link to change view in message
209
-	$messagingUrl = DOL_URL_ROOT . '/comm/propal/messaging.php?id=' . $object->id; // Changed from projet
209
+	$messagingUrl = DOL_URL_ROOT.'/comm/propal/messaging.php?id='.$object->id; // Changed from projet
210 210
 	$morehtmlright .= dolGetButtonTitle($langs->trans('ShowAsConversation'), '', 'fa fa-comments imgforviewmode', $messagingUrl, '', 2);
211 211
 
212 212
 	// Show link to change view in agenda
213
-	$messagingUrl = DOL_URL_ROOT . '/comm/propal/agenda.php?id=' . $object->id; // Changed from projet
213
+	$messagingUrl = DOL_URL_ROOT.'/comm/propal/agenda.php?id='.$object->id; // Changed from projet
214 214
 	$morehtmlright .= dolGetButtonTitle($langs->trans('MessageListViewType'), '', 'fa fa-bars imgforviewmode', $messagingUrl, '', 1);
215 215
 
216 216
 
@@ -227,24 +227,24 @@  discard block
 block discarded – undo
227 227
 	// Show link to add event
228 228
 	if (isModEnabled('agenda')) {
229 229
 		$addActionBtnRight = $user->hasRight('agenda', 'myactions', 'create') || $user->hasRight('agenda', 'allactions', 'create');
230
-		$morehtmlright .= dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', DOL_URL_ROOT . '/comm/action/card.php?action=create' . $out . '&socid=' . $object->socid . '&backtopage=' . urlencode($_SERVER["PHP_SELF"] . '?id=' . $object->id), '', (int) $addActionBtnRight);
230
+		$morehtmlright .= dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/comm/action/card.php?action=create'.$out.'&socid='.$object->socid.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?id='.$object->id), '', (int) $addActionBtnRight);
231 231
 	}
232 232
 
233
-	$param = '&id=' . $object->id;
233
+	$param = '&id='.$object->id;
234 234
 	if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
235
-		$param .= '&contextpage=' . urlencode($contextpage);
235
+		$param .= '&contextpage='.urlencode($contextpage);
236 236
 	}
237 237
 	if ($limit > 0 && $limit != $conf->liste_limit) {
238
-		$param .= '&limit=' . ((int) $limit);
238
+		$param .= '&limit='.((int) $limit);
239 239
 	}
240 240
 
241
-	require_once DOL_DOCUMENT_ROOT . '/core/lib/memory.lib.php';
242
-	$cachekey = 'count_events_propal_' . $object->id;
241
+	require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
242
+	$cachekey = 'count_events_propal_'.$object->id;
243 243
 	$nbEvent = dol_getcache($cachekey);
244 244
 
245
-	$titlelist = $langs->trans("ActionsOnPropal") . (is_numeric($nbEvent) ? '<span class="opacitymedium colorblack paddingleft">(' . $nbEvent . ')</span>' : ''); // Changed from ActionsOnProject
245
+	$titlelist = $langs->trans("ActionsOnPropal").(is_numeric($nbEvent) ? '<span class="opacitymedium colorblack paddingleft">('.$nbEvent.')</span>' : ''); // Changed from ActionsOnProject
246 246
 	if (!empty($conf->dol_optimize_smallscreen)) {
247
-		$titlelist = $langs->trans("Actions") . (is_numeric($nbEvent) ? '<span class="opacitymedium colorblack paddingleft">(' . $nbEvent . ')</span>' : '');
247
+		$titlelist = $langs->trans("Actions").(is_numeric($nbEvent) ? '<span class="opacitymedium colorblack paddingleft">('.$nbEvent.')</span>' : '');
248 248
 	}
249 249
 
250 250
 	print_barre_liste($titlelist, 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', 0, -1, '', 0, $morehtmlright, '', 0, 1, 0);
Please login to merge, or discard this patch.
htdocs/fourn/commande/info.php 1 patch
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -29,12 +29,12 @@  discard block
 block discarded – undo
29 29
 
30 30
 // Load Dolibarr environment
31 31
 require '../../main.inc.php';
32
-require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php';
33
-require_once DOL_DOCUMENT_ROOT . '/core/lib/fourn.lib.php';
34
-require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php';
35
-require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.commande.class.php';
32
+require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
33
+require_once DOL_DOCUMENT_ROOT.'/core/lib/fourn.lib.php';
34
+require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
35
+require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
36 36
 if (isModEnabled('project')) {
37
-	require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
37
+	require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
38 38
 }
39 39
 
40 40
 /**
@@ -95,8 +95,8 @@  discard block
 block discarded – undo
95 95
 	accessforbidden();
96 96
 }
97 97
 
98
-$usercancreate	= ($user->hasRight("fournisseur", "commande", "creer") || $user->hasRight("supplier_order", "creer"));
99
-$permissiontoadd	= $usercancreate; // Used by the include of actions_addupdatedelete.inc.php
98
+$usercancreate = ($user->hasRight("fournisseur", "commande", "creer") || $user->hasRight("supplier_order", "creer"));
99
+$permissiontoadd = $usercancreate; // Used by the include of actions_addupdatedelete.inc.php
100 100
 $caneditproject = false;
101 101
 
102 102
 
@@ -131,9 +131,9 @@  discard block
 block discarded – undo
131 131
 	$object->info($object->id);
132 132
 }
133 133
 
134
-$title = $object->ref . ' - ' . $langs->trans('Info') . ' - ' . $object->ref . ' ' . $object->name;
134
+$title = $object->ref.' - '.$langs->trans('Info').' - '.$object->ref.' '.$object->name;
135 135
 if (getDolGlobalString('MAIN_HTML_TITLE') && preg_match('/projectnameonly/', getDolGlobalString('MAIN_HTML_TITLE')) && $object->name) {
136
-	$title = $object->ref . ' ' . $object->name . ' - ' . $langs->trans("Info");
136
+	$title = $object->ref.' '.$object->name.' - '.$langs->trans("Info");
137 137
 }
138 138
 $help_url = 'EN:Module_Suppliers_Orders|FR:CommandeFournisseur|ES:Módulo_Pedidos_a_proveedores';
139 139
 llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-supplier-order page-info');
@@ -146,14 +146,14 @@  discard block
 block discarded – undo
146 146
 
147 147
 // Supplier order card
148 148
 
149
-$linkback = '<a href="' . DOL_URL_ROOT . '/fourn/commande/list.php' . (!empty($socid) ? '?socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
149
+$linkback = '<a href="'.DOL_URL_ROOT.'/fourn/commande/list.php'.(!empty($socid) ? '?socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
150 150
 
151 151
 $morehtmlref = '<div class="refidno">';
152 152
 // Ref supplier
153 153
 $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1);
154 154
 $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1);
155 155
 // Thirdparty
156
-$morehtmlref .= '<br>' . $object->thirdparty->getNomUrl(1);
156
+$morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1);
157 157
 // Project
158 158
 if (isModEnabled('project')) {
159 159
 	$langs->load("projects");
@@ -161,16 +161,16 @@  discard block
 block discarded – undo
161 161
 	if (0) {	// @phpstan-ignore-line
162 162
 		$morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
163 163
 		if ($action != 'classify' && $caneditproject) {  // Always false @phpstan-ignore-line
164
-			$morehtmlref .= '<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token=' . newToken() . '&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> ';
164
+			$morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
165 165
 		}
166
-		$morehtmlref .= $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, (!getDolGlobalString('PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS') ? $object->socid : -1), (string) $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
166
+		$morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, (!getDolGlobalString('PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS') ? $object->socid : -1), (string) $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
167 167
 	} else {
168 168
 		if (!empty($object->fk_project)) {
169 169
 			$proj = new Project($db);
170 170
 			$proj->fetch($object->fk_project);
171 171
 			$morehtmlref .= $proj->getNomUrl(1);
172 172
 			if ($proj->title) {
173
-				$morehtmlref .= '<span class="opacitymedium"> - ' . dol_escape_htmltag($proj->title) . '</span>';
173
+				$morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
174 174
 			}
175 175
 		}
176 176
 	}
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
 $out = '';
196 196
 $permok = $user->hasRight('agenda', 'myactions', 'create');
197 197
 if ($permok) {
198
-	$out .= '&originid=' . $object->id . '&origin=order_supplier';
198
+	$out .= '&originid='.$object->id.'&origin=order_supplier';
199 199
 }
200 200
 
201 201
 // print '<div class="tabsAction">';
@@ -215,25 +215,25 @@  discard block
 block discarded – undo
215 215
 	$morehtmlright = '';
216 216
 
217 217
 	// Show link to change view in message
218
-	$messagingUrl = DOL_URL_ROOT . '/fourn/commande/messaging.php?id=' . $object->id;
218
+	$messagingUrl = DOL_URL_ROOT.'/fourn/commande/messaging.php?id='.$object->id;
219 219
 	$morehtmlright .= dolGetButtonTitle($langs->trans('ShowAsConversation'), '', 'fa fa-comments imgforviewmode', $messagingUrl, '', 1); // Status 1 for "not current page"
220 220
 
221 221
 	// Show link to change view in agenda
222
-	$messagingUrl = DOL_URL_ROOT . '/fourn/commande/info.php?id=' . $object->id;
222
+	$messagingUrl = DOL_URL_ROOT.'/fourn/commande/info.php?id='.$object->id;
223 223
 	$morehtmlright .= dolGetButtonTitle($langs->trans('MessageListViewType'), '', 'fa fa-bars imgforviewmode', $messagingUrl, '', 2); // Status 2 for "current page"
224 224
 
225 225
 	// Show link to add event
226 226
 	if (isModEnabled('agenda')) {
227 227
 		$addActionBtnRight = $user->hasRight('agenda', 'myactions', 'create') || $user->hasRight('agenda', 'allactions', 'create');
228
-		$morehtmlright .= dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', DOL_URL_ROOT . '/comm/action/card.php?action=create' . $out . '&socid=' . $object->socid . '&backtopage=' . urlencode($_SERVER["PHP_SELF"] . '?id=' . $object->id), '', (int) $addActionBtnRight);
228
+		$morehtmlright .= dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/comm/action/card.php?action=create'.$out.'&socid='.$object->socid.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?id='.$object->id), '', (int) $addActionBtnRight);
229 229
 	}
230 230
 
231
-	$param = '&id=' . $object->id;
231
+	$param = '&id='.$object->id;
232 232
 	if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
233
-		$param .= '&contextpage=' . $contextpage;
233
+		$param .= '&contextpage='.$contextpage;
234 234
 	}
235 235
 	if ($limit > 0 && $limit != $conf->liste_limit) {
236
-		$param .= '&limit=' . $limit;
236
+		$param .= '&limit='.$limit;
237 237
 	}
238 238
 
239 239
 	// print load_fiche_titre($langs->trans("ActionsOnOrder"), '', '');
@@ -249,14 +249,14 @@  discard block
 block discarded – undo
249 249
 	// List of done actions
250 250
 	//show_actions_done($conf,$langs,$db,$object,null,0,$actioncode, '', $filters, $sortfield, $sortorder);
251 251
 
252
-	require_once DOL_DOCUMENT_ROOT . '/core/lib/memory.lib.php';
253
-	$cachekey = 'count_events_commande_' . $object->id;
252
+	require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
253
+	$cachekey = 'count_events_commande_'.$object->id;
254 254
 	$nbEvent = dol_getcache($cachekey);
255 255
 
256 256
 
257
-	$titlelist = $langs->trans("ActionsOnOrder") . (is_numeric($nbEvent) ? '<span class="opacitymedium colorblack paddingleft">(' . $nbEvent . ')</span>' : '');
257
+	$titlelist = $langs->trans("ActionsOnOrder").(is_numeric($nbEvent) ? '<span class="opacitymedium colorblack paddingleft">('.$nbEvent.')</span>' : '');
258 258
 	if (!empty($conf->dol_optimize_smallscreen)) {
259
-		$titlelist = $langs->trans("Actions") . (is_numeric($nbEvent) ? '<span class="opacitymedium colorblack paddingleft">(' . $nbEvent . ')</span>' : '');
259
+		$titlelist = $langs->trans("Actions").(is_numeric($nbEvent) ? '<span class="opacitymedium colorblack paddingleft">('.$nbEvent.')</span>' : '');
260 260
 	}
261 261
 
262 262
 	print_barre_liste($titlelist, 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', 0, -1, '', 0, $morehtmlright, '', 0, 1, 0);
Please login to merge, or discard this patch.