Completed
Push — 1.11.x ( 4463da...cd5efc )
by José
55:32 queued 28:22
created
main/inc/lib/nusoap/class.nusoap_base.php 1 patch
Indentation   +845 added lines, -845 removed lines patch added patch discarded remove patch
@@ -84,810 +84,810 @@  discard block
 block discarded – undo
84 84
 */
85 85
 class nusoap_base
86 86
 {
87
-	/**
88
-	 * Identification for HTTP headers.
89
-	 *
90
-	 * @var string
91
-	 * @access private
92
-	 */
93
-	var $title = 'NuSOAP';
94
-	/**
95
-	 * Version for HTTP headers.
96
-	 *
97
-	 * @var string
98
-	 * @access private
99
-	 */
100
-	var $version = '0.9.5';
101
-	/**
102
-	 * CVS revision for HTTP headers.
103
-	 *
104
-	 * @var string
105
-	 * @access private
106
-	 */
107
-	var $revision = '$Revision: 1.56 $';
87
+    /**
88
+     * Identification for HTTP headers.
89
+     *
90
+     * @var string
91
+     * @access private
92
+     */
93
+    var $title = 'NuSOAP';
94
+    /**
95
+     * Version for HTTP headers.
96
+     *
97
+     * @var string
98
+     * @access private
99
+     */
100
+    var $version = '0.9.5';
101
+    /**
102
+     * CVS revision for HTTP headers.
103
+     *
104
+     * @var string
105
+     * @access private
106
+     */
107
+    var $revision = '$Revision: 1.56 $';
108 108
     /**
109 109
      * Current error string (manipulated by getError/setError)
110
-	 *
111
-	 * @var string
112
-	 * @access private
113
-	 */
114
-	var $error_str = '';
110
+     *
111
+     * @var string
112
+     * @access private
113
+     */
114
+    var $error_str = '';
115 115
     /**
116 116
      * Current debug string (manipulated by debug/appendDebug/clearDebug/getDebug/getDebugAsXMLComment)
117
-	 *
118
-	 * @var string
119
-	 * @access private
120
-	 */
117
+     *
118
+     * @var string
119
+     * @access private
120
+     */
121 121
     var $debug_str = '';
122 122
     /**
123
-	 * toggles automatic encoding of special characters as entities
124
-	 * (should always be true, I think)
125
-	 *
126
-	 * @var boolean
127
-	 * @access private
128
-	 */
129
-	var $charencoding = true;
130
-	/**
131
-	 * the debug level for this instance
132
-	 *
133
-	 * @var	integer
134
-	 * @access private
135
-	 */
136
-	var $debugLevel;
137
-
138
-    /**
139
-	* set schema version
140
-	*
141
-	* @var      string
142
-	* @access   public
143
-	*/
144
-	var $XMLSchemaVersion = 'http://www.w3.org/2001/XMLSchema';
145
-
146
-    /**
147
-	* charset encoding for outgoing messages
148
-	*
149
-	* @var      string
150
-	* @access   public
151
-	*/
123
+     * toggles automatic encoding of special characters as entities
124
+     * (should always be true, I think)
125
+     *
126
+     * @var boolean
127
+     * @access private
128
+     */
129
+    var $charencoding = true;
130
+    /**
131
+     * the debug level for this instance
132
+     *
133
+     * @var	integer
134
+     * @access private
135
+     */
136
+    var $debugLevel;
137
+
138
+    /**
139
+     * set schema version
140
+     *
141
+     * @var      string
142
+     * @access   public
143
+     */
144
+    var $XMLSchemaVersion = 'http://www.w3.org/2001/XMLSchema';
145
+
146
+    /**
147
+     * charset encoding for outgoing messages
148
+     *
149
+     * @var      string
150
+     * @access   public
151
+     */
152 152
     var $soap_defencoding = 'ISO-8859-1';
153
-	//var $soap_defencoding = 'UTF-8';
154
-
155
-	/**
156
-	* namespaces in an array of prefix => uri
157
-	*
158
-	* this is "seeded" by a set of constants, but it may be altered by code
159
-	*
160
-	* @var      array
161
-	* @access   public
162
-	*/
163
-	var $namespaces = array(
164
-		'SOAP-ENV' => 'http://schemas.xmlsoap.org/soap/envelope/',
165
-		'xsd' => 'http://www.w3.org/2001/XMLSchema',
166
-		'xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
167
-		'SOAP-ENC' => 'http://schemas.xmlsoap.org/soap/encoding/'
168
-		);
169
-
170
-	/**
171
-	* namespaces used in the current context, e.g. during serialization
172
-	*
173
-	* @var      array
174
-	* @access   private
175
-	*/
176
-	var $usedNamespaces = array();
177
-
178
-	/**
179
-	* XML Schema types in an array of uri => (array of xml type => php type)
180
-	* is this legacy yet?
181
-	* no, this is used by the nusoap_xmlschema class to verify type => namespace mappings.
182
-	* @var      array
183
-	* @access   public
184
-	*/
185
-	var $typemap = array(
186
-	'http://www.w3.org/2001/XMLSchema' => array(
187
-		'string'=>'string','boolean'=>'boolean','float'=>'double','double'=>'double','decimal'=>'double',
188
-		'duration'=>'','dateTime'=>'string','time'=>'string','date'=>'string','gYearMonth'=>'',
189
-		'gYear'=>'','gMonthDay'=>'','gDay'=>'','gMonth'=>'','hexBinary'=>'string','base64Binary'=>'string',
190
-		// abstract "any" types
191
-		'anyType'=>'string','anySimpleType'=>'string',
192
-		// derived datatypes
193
-		'normalizedString'=>'string','token'=>'string','language'=>'','NMTOKEN'=>'','NMTOKENS'=>'','Name'=>'','NCName'=>'','ID'=>'',
194
-		'IDREF'=>'','IDREFS'=>'','ENTITY'=>'','ENTITIES'=>'','integer'=>'integer','nonPositiveInteger'=>'integer',
195
-		'negativeInteger'=>'integer','long'=>'integer','int'=>'integer','short'=>'integer','byte'=>'integer','nonNegativeInteger'=>'integer',
196
-		'unsignedLong'=>'','unsignedInt'=>'','unsignedShort'=>'','unsignedByte'=>'','positiveInteger'=>''),
197
-	'http://www.w3.org/2000/10/XMLSchema' => array(
198
-		'i4'=>'','int'=>'integer','boolean'=>'boolean','string'=>'string','double'=>'double',
199
-		'float'=>'double','dateTime'=>'string',
200
-		'timeInstant'=>'string','base64Binary'=>'string','base64'=>'string','ur-type'=>'array'),
201
-	'http://www.w3.org/1999/XMLSchema' => array(
202
-		'i4'=>'','int'=>'integer','boolean'=>'boolean','string'=>'string','double'=>'double',
203
-		'float'=>'double','dateTime'=>'string',
204
-		'timeInstant'=>'string','base64Binary'=>'string','base64'=>'string','ur-type'=>'array'),
205
-	'http://soapinterop.org/xsd' => array('SOAPStruct'=>'struct'),
206
-	'http://schemas.xmlsoap.org/soap/encoding/' => array('base64'=>'string','array'=>'array','Array'=>'array'),
153
+    //var $soap_defencoding = 'UTF-8';
154
+
155
+    /**
156
+     * namespaces in an array of prefix => uri
157
+     *
158
+     * this is "seeded" by a set of constants, but it may be altered by code
159
+     *
160
+     * @var      array
161
+     * @access   public
162
+     */
163
+    var $namespaces = array(
164
+        'SOAP-ENV' => 'http://schemas.xmlsoap.org/soap/envelope/',
165
+        'xsd' => 'http://www.w3.org/2001/XMLSchema',
166
+        'xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
167
+        'SOAP-ENC' => 'http://schemas.xmlsoap.org/soap/encoding/'
168
+        );
169
+
170
+    /**
171
+     * namespaces used in the current context, e.g. during serialization
172
+     *
173
+     * @var      array
174
+     * @access   private
175
+     */
176
+    var $usedNamespaces = array();
177
+
178
+    /**
179
+     * XML Schema types in an array of uri => (array of xml type => php type)
180
+     * is this legacy yet?
181
+     * no, this is used by the nusoap_xmlschema class to verify type => namespace mappings.
182
+     * @var      array
183
+     * @access   public
184
+     */
185
+    var $typemap = array(
186
+    'http://www.w3.org/2001/XMLSchema' => array(
187
+        'string'=>'string','boolean'=>'boolean','float'=>'double','double'=>'double','decimal'=>'double',
188
+        'duration'=>'','dateTime'=>'string','time'=>'string','date'=>'string','gYearMonth'=>'',
189
+        'gYear'=>'','gMonthDay'=>'','gDay'=>'','gMonth'=>'','hexBinary'=>'string','base64Binary'=>'string',
190
+        // abstract "any" types
191
+        'anyType'=>'string','anySimpleType'=>'string',
192
+        // derived datatypes
193
+        'normalizedString'=>'string','token'=>'string','language'=>'','NMTOKEN'=>'','NMTOKENS'=>'','Name'=>'','NCName'=>'','ID'=>'',
194
+        'IDREF'=>'','IDREFS'=>'','ENTITY'=>'','ENTITIES'=>'','integer'=>'integer','nonPositiveInteger'=>'integer',
195
+        'negativeInteger'=>'integer','long'=>'integer','int'=>'integer','short'=>'integer','byte'=>'integer','nonNegativeInteger'=>'integer',
196
+        'unsignedLong'=>'','unsignedInt'=>'','unsignedShort'=>'','unsignedByte'=>'','positiveInteger'=>''),
197
+    'http://www.w3.org/2000/10/XMLSchema' => array(
198
+        'i4'=>'','int'=>'integer','boolean'=>'boolean','string'=>'string','double'=>'double',
199
+        'float'=>'double','dateTime'=>'string',
200
+        'timeInstant'=>'string','base64Binary'=>'string','base64'=>'string','ur-type'=>'array'),
201
+    'http://www.w3.org/1999/XMLSchema' => array(
202
+        'i4'=>'','int'=>'integer','boolean'=>'boolean','string'=>'string','double'=>'double',
203
+        'float'=>'double','dateTime'=>'string',
204
+        'timeInstant'=>'string','base64Binary'=>'string','base64'=>'string','ur-type'=>'array'),
205
+    'http://soapinterop.org/xsd' => array('SOAPStruct'=>'struct'),
206
+    'http://schemas.xmlsoap.org/soap/encoding/' => array('base64'=>'string','array'=>'array','Array'=>'array'),
207 207
     'http://xml.apache.org/xml-soap' => array('Map')
208
-	);
209
-
210
-	/**
211
-	* XML entities to convert
212
-	*
213
-	* @var      array
214
-	* @access   public
215
-	* @deprecated
216
-	* @see	expandEntities
217
-	*/
218
-	var $xmlEntities = array('quot' => '"','amp' => '&',
219
-		'lt' => '<','gt' => '>','apos' => "'");
220
-
221
-	/**
222
-	* constructor
223
-	*
224
-	* @access	public
225
-	*/
226
-	public function __construct()
208
+    );
209
+
210
+    /**
211
+     * XML entities to convert
212
+     *
213
+     * @var      array
214
+     * @access   public
215
+     * @deprecated
216
+     * @see	expandEntities
217
+     */
218
+    var $xmlEntities = array('quot' => '"','amp' => '&',
219
+        'lt' => '<','gt' => '>','apos' => "'");
220
+
221
+    /**
222
+     * constructor
223
+     *
224
+     * @access	public
225
+     */
226
+    public function __construct()
227 227
     {
228
-		$this->debugLevel = $GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel'];
229
-	}
230
-
231
-	/**
232
-	* gets the global debug level, which applies to future instances
233
-	*
234
-	* @return	integer	Debug level 0-9, where 0 turns off
235
-	* @access	public
236
-	*/
237
-	function getGlobalDebugLevel() {
238
-		return $GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel'];
239
-	}
240
-
241
-	/**
242
-	* sets the global debug level, which applies to future instances
243
-	*
244
-	* @param	int	$level	Debug level 0-9, where 0 turns off
245
-	* @access	public
246
-	*/
247
-	function setGlobalDebugLevel($level) {
248
-		$GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel'] = $level;
249
-	}
250
-
251
-	/**
252
-	* gets the debug level for this instance
253
-	*
254
-	* @return	int	Debug level 0-9, where 0 turns off
255
-	* @access	public
256
-	*/
257
-	function getDebugLevel() {
258
-		return $this->debugLevel;
259
-	}
260
-
261
-	/**
262
-	* sets the debug level for this instance
263
-	*
264
-	* @param	int	$level	Debug level 0-9, where 0 turns off
265
-	* @access	public
266
-	*/
267
-	function setDebugLevel($level) {
268
-		$this->debugLevel = $level;
269
-	}
270
-
271
-	/**
272
-	* adds debug data to the instance debug string with formatting
273
-	*
274
-	* @param    string $string debug data
275
-	* @access   private
276
-	*/
277
-	function debug($string){
278
-		if ($this->debugLevel > 0) {
279
-			$this->appendDebug($this->getmicrotime().' '.get_class($this).": $string\n");
280
-		}
281
-	}
282
-
283
-	/**
284
-	* adds debug data to the instance debug string without formatting
285
-	*
286
-	* @param    string $string debug data
287
-	* @access   public
288
-	*/
289
-	function appendDebug($string){
290
-		if ($this->debugLevel > 0) {
291
-			// it would be nice to use a memory stream here to use
292
-			// memory more efficiently
293
-			$this->debug_str .= $string;
294
-		}
295
-	}
296
-
297
-	/**
298
-	* clears the current debug data for this instance
299
-	*
300
-	* @access   public
301
-	*/
302
-	function clearDebug() {
303
-		// it would be nice to use a memory stream here to use
304
-		// memory more efficiently
305
-		$this->debug_str = '';
306
-	}
307
-
308
-	/**
309
-	* gets the current debug data for this instance
310
-	*
311
-	* @return   debug data
312
-	* @access   public
313
-	*/
314
-	function &getDebug() {
315
-		// it would be nice to use a memory stream here to use
316
-		// memory more efficiently
317
-		return $this->debug_str;
318
-	}
319
-
320
-	/**
321
-	* gets the current debug data for this instance as an XML comment
322
-	* this may change the contents of the debug data
323
-	*
324
-	* @return   debug data as an XML comment
325
-	* @access   public
326
-	*/
327
-	function &getDebugAsXMLComment() {
328
-		// it would be nice to use a memory stream here to use
329
-		// memory more efficiently
330
-		while (strpos($this->debug_str, '--')) {
331
-			$this->debug_str = str_replace('--', '- -', $this->debug_str);
332
-		}
333
-		$ret = "<!--\n" . $this->debug_str . "\n-->";
334
-    	return $ret;
335
-	}
336
-
337
-	/**
338
-	* expands entities, e.g. changes '<' to '&lt;'.
339
-	*
340
-	* @param	string	$val	The string in which to expand entities.
341
-	* @access	private
342
-	*/
343
-	function expandEntities($val) {
344
-		if ($this->charencoding) {
345
-	    	$val = str_replace('&', '&amp;', $val);
346
-	    	$val = str_replace("'", '&apos;', $val);
347
-	    	$val = str_replace('"', '&quot;', $val);
348
-	    	$val = str_replace('<', '&lt;', $val);
349
-	    	$val = str_replace('>', '&gt;', $val);
350
-	    }
351
-	    return $val;
352
-	}
353
-
354
-	/**
355
-	* returns error string if present
356
-	*
357
-	* @return   mixed error string or false
358
-	* @access   public
359
-	*/
360
-	function getError(){
361
-		if($this->error_str != ''){
362
-			return $this->error_str;
363
-		}
364
-		return false;
365
-	}
366
-
367
-	/**
368
-	* sets error string
369
-	*
370
-	* @return   boolean $string error string
371
-	* @access   private
372
-	*/
373
-	function setError($str){
374
-		$this->error_str = $str;
375
-	}
376
-
377
-	/**
378
-	* detect if array is a simple array or a struct (associative array)
379
-	*
380
-	* @param	mixed	$val	The PHP array
381
-	* @return	string	(arraySimple|arrayStruct)
382
-	* @access	private
383
-	*/
384
-	function isArraySimpleOrStruct($val) {
228
+        $this->debugLevel = $GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel'];
229
+    }
230
+
231
+    /**
232
+     * gets the global debug level, which applies to future instances
233
+     *
234
+     * @return	integer	Debug level 0-9, where 0 turns off
235
+     * @access	public
236
+     */
237
+    function getGlobalDebugLevel() {
238
+        return $GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel'];
239
+    }
240
+
241
+    /**
242
+     * sets the global debug level, which applies to future instances
243
+     *
244
+     * @param	int	$level	Debug level 0-9, where 0 turns off
245
+     * @access	public
246
+     */
247
+    function setGlobalDebugLevel($level) {
248
+        $GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel'] = $level;
249
+    }
250
+
251
+    /**
252
+     * gets the debug level for this instance
253
+     *
254
+     * @return	int	Debug level 0-9, where 0 turns off
255
+     * @access	public
256
+     */
257
+    function getDebugLevel() {
258
+        return $this->debugLevel;
259
+    }
260
+
261
+    /**
262
+     * sets the debug level for this instance
263
+     *
264
+     * @param	int	$level	Debug level 0-9, where 0 turns off
265
+     * @access	public
266
+     */
267
+    function setDebugLevel($level) {
268
+        $this->debugLevel = $level;
269
+    }
270
+
271
+    /**
272
+     * adds debug data to the instance debug string with formatting
273
+     *
274
+     * @param    string $string debug data
275
+     * @access   private
276
+     */
277
+    function debug($string){
278
+        if ($this->debugLevel > 0) {
279
+            $this->appendDebug($this->getmicrotime().' '.get_class($this).": $string\n");
280
+        }
281
+    }
282
+
283
+    /**
284
+     * adds debug data to the instance debug string without formatting
285
+     *
286
+     * @param    string $string debug data
287
+     * @access   public
288
+     */
289
+    function appendDebug($string){
290
+        if ($this->debugLevel > 0) {
291
+            // it would be nice to use a memory stream here to use
292
+            // memory more efficiently
293
+            $this->debug_str .= $string;
294
+        }
295
+    }
296
+
297
+    /**
298
+     * clears the current debug data for this instance
299
+     *
300
+     * @access   public
301
+     */
302
+    function clearDebug() {
303
+        // it would be nice to use a memory stream here to use
304
+        // memory more efficiently
305
+        $this->debug_str = '';
306
+    }
307
+
308
+    /**
309
+     * gets the current debug data for this instance
310
+     *
311
+     * @return   debug data
312
+     * @access   public
313
+     */
314
+    function &getDebug() {
315
+        // it would be nice to use a memory stream here to use
316
+        // memory more efficiently
317
+        return $this->debug_str;
318
+    }
319
+
320
+    /**
321
+     * gets the current debug data for this instance as an XML comment
322
+     * this may change the contents of the debug data
323
+     *
324
+     * @return   debug data as an XML comment
325
+     * @access   public
326
+     */
327
+    function &getDebugAsXMLComment() {
328
+        // it would be nice to use a memory stream here to use
329
+        // memory more efficiently
330
+        while (strpos($this->debug_str, '--')) {
331
+            $this->debug_str = str_replace('--', '- -', $this->debug_str);
332
+        }
333
+        $ret = "<!--\n" . $this->debug_str . "\n-->";
334
+        return $ret;
335
+    }
336
+
337
+    /**
338
+     * expands entities, e.g. changes '<' to '&lt;'.
339
+     *
340
+     * @param	string	$val	The string in which to expand entities.
341
+     * @access	private
342
+     */
343
+    function expandEntities($val) {
344
+        if ($this->charencoding) {
345
+            $val = str_replace('&', '&amp;', $val);
346
+            $val = str_replace("'", '&apos;', $val);
347
+            $val = str_replace('"', '&quot;', $val);
348
+            $val = str_replace('<', '&lt;', $val);
349
+            $val = str_replace('>', '&gt;', $val);
350
+        }
351
+        return $val;
352
+    }
353
+
354
+    /**
355
+     * returns error string if present
356
+     *
357
+     * @return   mixed error string or false
358
+     * @access   public
359
+     */
360
+    function getError(){
361
+        if($this->error_str != ''){
362
+            return $this->error_str;
363
+        }
364
+        return false;
365
+    }
366
+
367
+    /**
368
+     * sets error string
369
+     *
370
+     * @return   boolean $string error string
371
+     * @access   private
372
+     */
373
+    function setError($str){
374
+        $this->error_str = $str;
375
+    }
376
+
377
+    /**
378
+     * detect if array is a simple array or a struct (associative array)
379
+     *
380
+     * @param	mixed	$val	The PHP array
381
+     * @return	string	(arraySimple|arrayStruct)
382
+     * @access	private
383
+     */
384
+    function isArraySimpleOrStruct($val) {
385 385
         $keyList = array_keys($val);
386
-		foreach ($keyList as $keyListValue) {
387
-			if (!is_int($keyListValue)) {
388
-				return 'arrayStruct';
389
-			}
390
-		}
391
-		return 'arraySimple';
392
-	}
393
-
394
-	/**
395
-	* serializes PHP values in accordance w/ section 5. Type information is
396
-	* not serialized if $use == 'literal'.
397
-	*
398
-	* @param	mixed	$val	The value to serialize
399
-	* @param	string	$name	The name (local part) of the XML element
400
-	* @param	string	$type	The XML schema type (local part) for the element
401
-	* @param	string	$name_ns	The namespace for the name of the XML element
402
-	* @param	string	$type_ns	The namespace for the type of the element
403
-	* @param	array	$attributes	The attributes to serialize as name=>value pairs
404
-	* @param	string	$use	The WSDL "use" (encoded|literal)
405
-	* @param	boolean	$soapval	Whether this is called from soapval.
406
-	* @return	string	The serialized element, possibly with child elements
407
-    * @access	public
408
-	*/
409
-	function serialize_val($val,$name=false,$type=false,$name_ns=false,$type_ns=false,$attributes=false,$use='encoded',$soapval=false) {
410
-		$this->debug("in serialize_val: name=$name, type=$type, name_ns=$name_ns, type_ns=$type_ns, use=$use, soapval=$soapval");
411
-		$this->appendDebug('value=' . $this->varDump($val));
412
-		$this->appendDebug('attributes=' . $this->varDump($attributes));
413
-
414
-    	if (is_object($val) && get_class($val) == 'soapval' && (! $soapval)) {
415
-    		$this->debug("serialize_val: serialize soapval");
416
-        	$xml = $val->serialize($use);
417
-			$this->appendDebug($val->getDebug());
418
-			$val->clearDebug();
419
-			$this->debug("serialize_val of soapval returning $xml");
420
-			return $xml;
386
+        foreach ($keyList as $keyListValue) {
387
+            if (!is_int($keyListValue)) {
388
+                return 'arrayStruct';
389
+            }
390
+        }
391
+        return 'arraySimple';
392
+    }
393
+
394
+    /**
395
+     * serializes PHP values in accordance w/ section 5. Type information is
396
+     * not serialized if $use == 'literal'.
397
+     *
398
+     * @param	mixed	$val	The value to serialize
399
+     * @param	string	$name	The name (local part) of the XML element
400
+     * @param	string	$type	The XML schema type (local part) for the element
401
+     * @param	string	$name_ns	The namespace for the name of the XML element
402
+     * @param	string	$type_ns	The namespace for the type of the element
403
+     * @param	array	$attributes	The attributes to serialize as name=>value pairs
404
+     * @param	string	$use	The WSDL "use" (encoded|literal)
405
+     * @param	boolean	$soapval	Whether this is called from soapval.
406
+     * @return	string	The serialized element, possibly with child elements
407
+     * @access	public
408
+     */
409
+    function serialize_val($val,$name=false,$type=false,$name_ns=false,$type_ns=false,$attributes=false,$use='encoded',$soapval=false) {
410
+        $this->debug("in serialize_val: name=$name, type=$type, name_ns=$name_ns, type_ns=$type_ns, use=$use, soapval=$soapval");
411
+        $this->appendDebug('value=' . $this->varDump($val));
412
+        $this->appendDebug('attributes=' . $this->varDump($attributes));
413
+
414
+        if (is_object($val) && get_class($val) == 'soapval' && (! $soapval)) {
415
+            $this->debug("serialize_val: serialize soapval");
416
+            $xml = $val->serialize($use);
417
+            $this->appendDebug($val->getDebug());
418
+            $val->clearDebug();
419
+            $this->debug("serialize_val of soapval returning $xml");
420
+            return $xml;
421 421
         }
422
-		// force valid name if necessary
423
-		if (is_numeric($name)) {
424
-			$name = '__numeric_' . $name;
425
-		} elseif (! $name) {
426
-			$name = 'noname';
427
-		}
428
-		// if name has ns, add ns prefix to name
429
-		$xmlns = '';
422
+        // force valid name if necessary
423
+        if (is_numeric($name)) {
424
+            $name = '__numeric_' . $name;
425
+        } elseif (! $name) {
426
+            $name = 'noname';
427
+        }
428
+        // if name has ns, add ns prefix to name
429
+        $xmlns = '';
430 430
         if($name_ns){
431
-			$prefix = 'nu'.rand(1000,9999);
432
-			$name = $prefix.':'.$name;
433
-			$xmlns .= " xmlns:$prefix=\"$name_ns\"";
434
-		}
435
-		// if type is prefixed, create type prefix
436
-		if($type_ns != '' && $type_ns == $this->namespaces['xsd']){
437
-			// need to fix this. shouldn't default to xsd if no ns specified
438
-		    // w/o checking against typemap
439
-			$type_prefix = 'xsd';
440
-		} elseif($type_ns){
441
-			$type_prefix = 'ns'.rand(1000,9999);
442
-			$xmlns .= " xmlns:$type_prefix=\"$type_ns\"";
443
-		}
444
-		// serialize attributes if present
445
-		$atts = '';
446
-		if($attributes){
447
-			foreach($attributes as $k => $v){
448
-				$atts .= " $k=\"".$this->expandEntities($v).'"';
449
-			}
450
-		}
451
-		// serialize null value
452
-		if (is_null($val)) {
453
-    		$this->debug("serialize_val: serialize null");
454
-			if ($use == 'literal') {
455
-				// TODO: depends on minOccurs
456
-				$xml = "<$name$xmlns$atts/>";
457
-				$this->debug("serialize_val returning $xml");
458
-	        	return $xml;
459
-        	} else {
460
-				if (isset($type) && isset($type_prefix)) {
461
-					$type_str = " xsi:type=\"$type_prefix:$type\"";
462
-				} else {
463
-					$type_str = '';
464
-				}
465
-				$xml = "<$name$xmlns$type_str$atts xsi:nil=\"true\"/>";
466
-				$this->debug("serialize_val returning $xml");
467
-	        	return $xml;
468
-        	}
469
-		}
431
+            $prefix = 'nu'.rand(1000,9999);
432
+            $name = $prefix.':'.$name;
433
+            $xmlns .= " xmlns:$prefix=\"$name_ns\"";
434
+        }
435
+        // if type is prefixed, create type prefix
436
+        if($type_ns != '' && $type_ns == $this->namespaces['xsd']){
437
+            // need to fix this. shouldn't default to xsd if no ns specified
438
+            // w/o checking against typemap
439
+            $type_prefix = 'xsd';
440
+        } elseif($type_ns){
441
+            $type_prefix = 'ns'.rand(1000,9999);
442
+            $xmlns .= " xmlns:$type_prefix=\"$type_ns\"";
443
+        }
444
+        // serialize attributes if present
445
+        $atts = '';
446
+        if($attributes){
447
+            foreach($attributes as $k => $v){
448
+                $atts .= " $k=\"".$this->expandEntities($v).'"';
449
+            }
450
+        }
451
+        // serialize null value
452
+        if (is_null($val)) {
453
+            $this->debug("serialize_val: serialize null");
454
+            if ($use == 'literal') {
455
+                // TODO: depends on minOccurs
456
+                $xml = "<$name$xmlns$atts/>";
457
+                $this->debug("serialize_val returning $xml");
458
+                return $xml;
459
+            } else {
460
+                if (isset($type) && isset($type_prefix)) {
461
+                    $type_str = " xsi:type=\"$type_prefix:$type\"";
462
+                } else {
463
+                    $type_str = '';
464
+                }
465
+                $xml = "<$name$xmlns$type_str$atts xsi:nil=\"true\"/>";
466
+                $this->debug("serialize_val returning $xml");
467
+                return $xml;
468
+            }
469
+        }
470 470
         // serialize if an xsd built-in primitive type
471 471
         if($type != '' && isset($this->typemap[$this->XMLSchemaVersion][$type])){
472
-    		$this->debug("serialize_val: serialize xsd built-in primitive type");
473
-        	if (is_bool($val)) {
474
-        		if ($type == 'boolean') {
475
-	        		$val = $val ? 'true' : 'false';
476
-	        	} elseif (! $val) {
477
-	        		$val = 0;
478
-	        	}
479
-			} else if (is_string($val)) {
480
-				$val = $this->expandEntities($val);
481
-			}
482
-			if ($use == 'literal') {
483
-				$xml = "<$name$xmlns$atts>$val</$name>";
484
-				$this->debug("serialize_val returning $xml");
485
-	        	return $xml;
486
-        	} else {
487
-				$xml = "<$name$xmlns xsi:type=\"xsd:$type\"$atts>$val</$name>";
488
-				$this->debug("serialize_val returning $xml");
489
-	        	return $xml;
490
-        	}
472
+            $this->debug("serialize_val: serialize xsd built-in primitive type");
473
+            if (is_bool($val)) {
474
+                if ($type == 'boolean') {
475
+                    $val = $val ? 'true' : 'false';
476
+                } elseif (! $val) {
477
+                    $val = 0;
478
+                }
479
+            } else if (is_string($val)) {
480
+                $val = $this->expandEntities($val);
481
+            }
482
+            if ($use == 'literal') {
483
+                $xml = "<$name$xmlns$atts>$val</$name>";
484
+                $this->debug("serialize_val returning $xml");
485
+                return $xml;
486
+            } else {
487
+                $xml = "<$name$xmlns xsi:type=\"xsd:$type\"$atts>$val</$name>";
488
+                $this->debug("serialize_val returning $xml");
489
+                return $xml;
490
+            }
491 491
         }
492
-		// detect type and serialize
493
-		$xml = '';
494
-		switch(true) {
495
-			case (is_bool($val) || $type == 'boolean'):
496
-		   		$this->debug("serialize_val: serialize boolean");
497
-        		if ($type == 'boolean') {
498
-	        		$val = $val ? 'true' : 'false';
499
-	        	} elseif (! $val) {
500
-	        		$val = 0;
501
-	        	}
502
-				if ($use == 'literal') {
503
-					$xml .= "<$name$xmlns$atts>$val</$name>";
504
-				} else {
505
-					$xml .= "<$name$xmlns xsi:type=\"xsd:boolean\"$atts>$val</$name>";
506
-				}
507
-				break;
508
-			case (is_int($val) || is_long($val) || $type == 'int'):
509
-		   		$this->debug("serialize_val: serialize int");
510
-				if ($use == 'literal') {
511
-					$xml .= "<$name$xmlns$atts>$val</$name>";
512
-				} else {
513
-					$xml .= "<$name$xmlns xsi:type=\"xsd:int\"$atts>$val</$name>";
514
-				}
515
-				break;
516
-			case (is_float($val)|| is_double($val) || $type == 'float'):
517
-		   		$this->debug("serialize_val: serialize float");
518
-				if ($use == 'literal') {
519
-					$xml .= "<$name$xmlns$atts>$val</$name>";
520
-				} else {
521
-					$xml .= "<$name$xmlns xsi:type=\"xsd:float\"$atts>$val</$name>";
522
-				}
523
-				break;
524
-			case (is_string($val) || $type == 'string'):
525
-		   		$this->debug("serialize_val: serialize string");
526
-				$val = $this->expandEntities($val);
527
-				if ($use == 'literal') {
528
-					$xml .= "<$name$xmlns$atts>$val</$name>";
529
-				} else {
530
-					$xml .= "<$name$xmlns xsi:type=\"xsd:string\"$atts>$val</$name>";
531
-				}
532
-				break;
533
-			case is_object($val):
534
-		   		$this->debug("serialize_val: serialize object");
535
-		    	if (get_class($val) == 'soapval') {
536
-		    		$this->debug("serialize_val: serialize soapval object");
537
-		        	$pXml = $val->serialize($use);
538
-					$this->appendDebug($val->getDebug());
539
-					$val->clearDebug();
540
-		        } else {
541
-					if (! $name) {
542
-						$name = get_class($val);
543
-						$this->debug("In serialize_val, used class name $name as element name");
544
-					} else {
545
-						$this->debug("In serialize_val, do not override name $name for element name for class " . get_class($val));
546
-					}
547
-					foreach(get_object_vars($val) as $k => $v){
548
-						$pXml = isset($pXml) ? $pXml.$this->serialize_val($v,$k,false,false,false,false,$use) : $this->serialize_val($v,$k,false,false,false,false,$use);
549
-					}
550
-				}
551
-				if(isset($type) && isset($type_prefix)){
552
-					$type_str = " xsi:type=\"$type_prefix:$type\"";
553
-				} else {
554
-					$type_str = '';
555
-				}
556
-				if ($use == 'literal') {
557
-					$xml .= "<$name$xmlns$atts>$pXml</$name>";
558
-				} else {
559
-					$xml .= "<$name$xmlns$type_str$atts>$pXml</$name>";
560
-				}
561
-				break;
562
-			case (is_array($val) || $type):
563
-				// detect if struct or array
564
-				$valueType = $this->isArraySimpleOrStruct($val);
492
+        // detect type and serialize
493
+        $xml = '';
494
+        switch(true) {
495
+            case (is_bool($val) || $type == 'boolean'):
496
+                   $this->debug("serialize_val: serialize boolean");
497
+                if ($type == 'boolean') {
498
+                    $val = $val ? 'true' : 'false';
499
+                } elseif (! $val) {
500
+                    $val = 0;
501
+                }
502
+                if ($use == 'literal') {
503
+                    $xml .= "<$name$xmlns$atts>$val</$name>";
504
+                } else {
505
+                    $xml .= "<$name$xmlns xsi:type=\"xsd:boolean\"$atts>$val</$name>";
506
+                }
507
+                break;
508
+            case (is_int($val) || is_long($val) || $type == 'int'):
509
+                   $this->debug("serialize_val: serialize int");
510
+                if ($use == 'literal') {
511
+                    $xml .= "<$name$xmlns$atts>$val</$name>";
512
+                } else {
513
+                    $xml .= "<$name$xmlns xsi:type=\"xsd:int\"$atts>$val</$name>";
514
+                }
515
+                break;
516
+            case (is_float($val)|| is_double($val) || $type == 'float'):
517
+                   $this->debug("serialize_val: serialize float");
518
+                if ($use == 'literal') {
519
+                    $xml .= "<$name$xmlns$atts>$val</$name>";
520
+                } else {
521
+                    $xml .= "<$name$xmlns xsi:type=\"xsd:float\"$atts>$val</$name>";
522
+                }
523
+                break;
524
+            case (is_string($val) || $type == 'string'):
525
+                   $this->debug("serialize_val: serialize string");
526
+                $val = $this->expandEntities($val);
527
+                if ($use == 'literal') {
528
+                    $xml .= "<$name$xmlns$atts>$val</$name>";
529
+                } else {
530
+                    $xml .= "<$name$xmlns xsi:type=\"xsd:string\"$atts>$val</$name>";
531
+                }
532
+                break;
533
+            case is_object($val):
534
+                   $this->debug("serialize_val: serialize object");
535
+                if (get_class($val) == 'soapval') {
536
+                    $this->debug("serialize_val: serialize soapval object");
537
+                    $pXml = $val->serialize($use);
538
+                    $this->appendDebug($val->getDebug());
539
+                    $val->clearDebug();
540
+                } else {
541
+                    if (! $name) {
542
+                        $name = get_class($val);
543
+                        $this->debug("In serialize_val, used class name $name as element name");
544
+                    } else {
545
+                        $this->debug("In serialize_val, do not override name $name for element name for class " . get_class($val));
546
+                    }
547
+                    foreach(get_object_vars($val) as $k => $v){
548
+                        $pXml = isset($pXml) ? $pXml.$this->serialize_val($v,$k,false,false,false,false,$use) : $this->serialize_val($v,$k,false,false,false,false,$use);
549
+                    }
550
+                }
551
+                if(isset($type) && isset($type_prefix)){
552
+                    $type_str = " xsi:type=\"$type_prefix:$type\"";
553
+                } else {
554
+                    $type_str = '';
555
+                }
556
+                if ($use == 'literal') {
557
+                    $xml .= "<$name$xmlns$atts>$pXml</$name>";
558
+                } else {
559
+                    $xml .= "<$name$xmlns$type_str$atts>$pXml</$name>";
560
+                }
561
+                break;
562
+            case (is_array($val) || $type):
563
+                // detect if struct or array
564
+                $valueType = $this->isArraySimpleOrStruct($val);
565 565
                 if($valueType=='arraySimple' || preg_match('/^ArrayOf/',$type)){
566
-			   		$this->debug("serialize_val: serialize array");
567
-					$i = 0;
568
-					if(is_array($val) && count($val)> 0){
569
-						foreach($val as $v){
570
-	                    	if(is_object($v) && get_class($v) ==  'soapval'){
571
-								$tt_ns = $v->type_ns;
572
-								$tt = $v->type;
573
-							} elseif (is_array($v)) {
574
-								$tt = $this->isArraySimpleOrStruct($v);
575
-							} else {
576
-								$tt = gettype($v);
577
-	                        }
578
-							$array_types[$tt] = 1;
579
-							// TODO: for literal, the name should be $name
580
-							$xml .= $this->serialize_val($v,'item',false,false,false,false,$use);
581
-							++$i;
582
-						}
583
-						if(count($array_types) > 1){
584
-							$array_typename = 'xsd:anyType';
585
-						} elseif(isset($tt) && isset($this->typemap[$this->XMLSchemaVersion][$tt])) {
586
-							if ($tt == 'integer') {
587
-								$tt = 'int';
588
-							}
589
-							$array_typename = 'xsd:'.$tt;
590
-						} elseif(isset($tt) && $tt == 'arraySimple'){
591
-							$array_typename = 'SOAP-ENC:Array';
592
-						} elseif(isset($tt) && $tt == 'arrayStruct'){
593
-							$array_typename = 'unnamed_struct_use_soapval';
594
-						} else {
595
-							// if type is prefixed, create type prefix
596
-							if ($tt_ns != '' && $tt_ns == $this->namespaces['xsd']){
597
-								 $array_typename = 'xsd:' . $tt;
598
-							} elseif ($tt_ns) {
599
-								$tt_prefix = 'ns' . rand(1000, 9999);
600
-								$array_typename = "$tt_prefix:$tt";
601
-								$xmlns .= " xmlns:$tt_prefix=\"$tt_ns\"";
602
-							} else {
603
-								$array_typename = $tt;
604
-							}
605
-						}
606
-						$array_type = $i;
607
-						if ($use == 'literal') {
608
-							$type_str = '';
609
-						} else if (isset($type) && isset($type_prefix)) {
610
-							$type_str = " xsi:type=\"$type_prefix:$type\"";
611
-						} else {
612
-							$type_str = " xsi:type=\"SOAP-ENC:Array\" SOAP-ENC:arrayType=\"".$array_typename."[$array_type]\"";
613
-						}
614
-					// empty array
615
-					} else {
616
-						if ($use == 'literal') {
617
-							$type_str = '';
618
-						} else if (isset($type) && isset($type_prefix)) {
619
-							$type_str = " xsi:type=\"$type_prefix:$type\"";
620
-						} else {
621
-							$type_str = " xsi:type=\"SOAP-ENC:Array\" SOAP-ENC:arrayType=\"xsd:anyType[0]\"";
622
-						}
623
-					}
624
-					// TODO: for array in literal, there is no wrapper here
625
-					$xml = "<$name$xmlns$type_str$atts>".$xml."</$name>";
626
-				} else {
627
-					// got a struct
628
-			   		$this->debug("serialize_val: serialize struct");
629
-					if(isset($type) && isset($type_prefix)){
630
-						$type_str = " xsi:type=\"$type_prefix:$type\"";
631
-					} else {
632
-						$type_str = '';
633
-					}
634
-					if ($use == 'literal') {
635
-						$xml .= "<$name$xmlns$atts>";
636
-					} else {
637
-						$xml .= "<$name$xmlns$type_str$atts>";
638
-					}
639
-					foreach($val as $k => $v){
640
-						// Apache Map
641
-						if ($type == 'Map' && $type_ns == 'http://xml.apache.org/xml-soap') {
642
-							$xml .= '<item>';
643
-							$xml .= $this->serialize_val($k,'key',false,false,false,false,$use);
644
-							$xml .= $this->serialize_val($v,'value',false,false,false,false,$use);
645
-							$xml .= '</item>';
646
-						} else {
647
-							$xml .= $this->serialize_val($v,$k,false,false,false,false,$use);
648
-						}
649
-					}
650
-					$xml .= "</$name>";
651
-				}
652
-				break;
653
-			default:
654
-		   		$this->debug("serialize_val: serialize unknown");
655
-				$xml .= 'not detected, got '.gettype($val).' for '.$val;
656
-				break;
657
-		}
658
-		$this->debug("serialize_val returning $xml");
659
-		return $xml;
660
-	}
661
-
662
-    /**
663
-    * serializes a message
664
-    *
665
-    * @param string $body the XML of the SOAP body
666
-    * @param mixed $headers optional string of XML with SOAP header content, or array of soapval objects for SOAP headers, or associative array
667
-    * @param array $namespaces optional the namespaces used in generating the body and headers
668
-    * @param string $style optional (rpc|document)
669
-    * @param string $use optional (encoded|literal)
670
-    * @param string $encodingStyle optional (usually 'http://schemas.xmlsoap.org/soap/encoding/' for encoded)
671
-    * @return string the message
672
-    * @access public
673
-    */
566
+                        $this->debug("serialize_val: serialize array");
567
+                    $i = 0;
568
+                    if(is_array($val) && count($val)> 0){
569
+                        foreach($val as $v){
570
+                            if(is_object($v) && get_class($v) ==  'soapval'){
571
+                                $tt_ns = $v->type_ns;
572
+                                $tt = $v->type;
573
+                            } elseif (is_array($v)) {
574
+                                $tt = $this->isArraySimpleOrStruct($v);
575
+                            } else {
576
+                                $tt = gettype($v);
577
+                            }
578
+                            $array_types[$tt] = 1;
579
+                            // TODO: for literal, the name should be $name
580
+                            $xml .= $this->serialize_val($v,'item',false,false,false,false,$use);
581
+                            ++$i;
582
+                        }
583
+                        if(count($array_types) > 1){
584
+                            $array_typename = 'xsd:anyType';
585
+                        } elseif(isset($tt) && isset($this->typemap[$this->XMLSchemaVersion][$tt])) {
586
+                            if ($tt == 'integer') {
587
+                                $tt = 'int';
588
+                            }
589
+                            $array_typename = 'xsd:'.$tt;
590
+                        } elseif(isset($tt) && $tt == 'arraySimple'){
591
+                            $array_typename = 'SOAP-ENC:Array';
592
+                        } elseif(isset($tt) && $tt == 'arrayStruct'){
593
+                            $array_typename = 'unnamed_struct_use_soapval';
594
+                        } else {
595
+                            // if type is prefixed, create type prefix
596
+                            if ($tt_ns != '' && $tt_ns == $this->namespaces['xsd']){
597
+                                    $array_typename = 'xsd:' . $tt;
598
+                            } elseif ($tt_ns) {
599
+                                $tt_prefix = 'ns' . rand(1000, 9999);
600
+                                $array_typename = "$tt_prefix:$tt";
601
+                                $xmlns .= " xmlns:$tt_prefix=\"$tt_ns\"";
602
+                            } else {
603
+                                $array_typename = $tt;
604
+                            }
605
+                        }
606
+                        $array_type = $i;
607
+                        if ($use == 'literal') {
608
+                            $type_str = '';
609
+                        } else if (isset($type) && isset($type_prefix)) {
610
+                            $type_str = " xsi:type=\"$type_prefix:$type\"";
611
+                        } else {
612
+                            $type_str = " xsi:type=\"SOAP-ENC:Array\" SOAP-ENC:arrayType=\"".$array_typename."[$array_type]\"";
613
+                        }
614
+                    // empty array
615
+                    } else {
616
+                        if ($use == 'literal') {
617
+                            $type_str = '';
618
+                        } else if (isset($type) && isset($type_prefix)) {
619
+                            $type_str = " xsi:type=\"$type_prefix:$type\"";
620
+                        } else {
621
+                            $type_str = " xsi:type=\"SOAP-ENC:Array\" SOAP-ENC:arrayType=\"xsd:anyType[0]\"";
622
+                        }
623
+                    }
624
+                    // TODO: for array in literal, there is no wrapper here
625
+                    $xml = "<$name$xmlns$type_str$atts>".$xml."</$name>";
626
+                } else {
627
+                    // got a struct
628
+                        $this->debug("serialize_val: serialize struct");
629
+                    if(isset($type) && isset($type_prefix)){
630
+                        $type_str = " xsi:type=\"$type_prefix:$type\"";
631
+                    } else {
632
+                        $type_str = '';
633
+                    }
634
+                    if ($use == 'literal') {
635
+                        $xml .= "<$name$xmlns$atts>";
636
+                    } else {
637
+                        $xml .= "<$name$xmlns$type_str$atts>";
638
+                    }
639
+                    foreach($val as $k => $v){
640
+                        // Apache Map
641
+                        if ($type == 'Map' && $type_ns == 'http://xml.apache.org/xml-soap') {
642
+                            $xml .= '<item>';
643
+                            $xml .= $this->serialize_val($k,'key',false,false,false,false,$use);
644
+                            $xml .= $this->serialize_val($v,'value',false,false,false,false,$use);
645
+                            $xml .= '</item>';
646
+                        } else {
647
+                            $xml .= $this->serialize_val($v,$k,false,false,false,false,$use);
648
+                        }
649
+                    }
650
+                    $xml .= "</$name>";
651
+                }
652
+                break;
653
+            default:
654
+                   $this->debug("serialize_val: serialize unknown");
655
+                $xml .= 'not detected, got '.gettype($val).' for '.$val;
656
+                break;
657
+        }
658
+        $this->debug("serialize_val returning $xml");
659
+        return $xml;
660
+    }
661
+
662
+    /**
663
+     * serializes a message
664
+     *
665
+     * @param string $body the XML of the SOAP body
666
+     * @param mixed $headers optional string of XML with SOAP header content, or array of soapval objects for SOAP headers, or associative array
667
+     * @param array $namespaces optional the namespaces used in generating the body and headers
668
+     * @param string $style optional (rpc|document)
669
+     * @param string $use optional (encoded|literal)
670
+     * @param string $encodingStyle optional (usually 'http://schemas.xmlsoap.org/soap/encoding/' for encoded)
671
+     * @return string the message
672
+     * @access public
673
+     */
674 674
     function serializeEnvelope($body,$headers=false,$namespaces=array(),$style='rpc',$use='encoded',$encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'){
675 675
     // TODO: add an option to automatically run utf8_encode on $body and $headers
676 676
     // if $this->soap_defencoding is UTF-8.  Not doing this automatically allows
677 677
     // one to send arbitrary UTF-8 characters, not just characters that map to ISO-8859-1
678 678
 
679
-	$this->debug("In serializeEnvelope length=" . strlen($body) . " body (max 1000 characters)=" . substr($body, 0, 1000) . " style=$style use=$use encodingStyle=$encodingStyle");
680
-	$this->debug("headers:");
681
-	$this->appendDebug($this->varDump($headers));
682
-	$this->debug("namespaces:");
683
-	$this->appendDebug($this->varDump($namespaces));
679
+    $this->debug("In serializeEnvelope length=" . strlen($body) . " body (max 1000 characters)=" . substr($body, 0, 1000) . " style=$style use=$use encodingStyle=$encodingStyle");
680
+    $this->debug("headers:");
681
+    $this->appendDebug($this->varDump($headers));
682
+    $this->debug("namespaces:");
683
+    $this->appendDebug($this->varDump($namespaces));
684 684
 
685
-	// serialize namespaces
685
+    // serialize namespaces
686 686
     $ns_string = '';
687
-	foreach(array_merge($this->namespaces,$namespaces) as $k => $v){
688
-		$ns_string .= " xmlns:$k=\"$v\"";
689
-	}
690
-	if($encodingStyle) {
691
-		$ns_string = " SOAP-ENV:encodingStyle=\"$encodingStyle\"$ns_string";
692
-	}
693
-
694
-	// serialize headers
695
-	if($headers){
696
-		if (is_array($headers)) {
697
-			$xml = '';
698
-			foreach ($headers as $k => $v) {
699
-				if (is_object($v) && get_class($v) == 'soapval') {
700
-					$xml .= $this->serialize_val($v, false, false, false, false, false, $use);
701
-				} else {
702
-					$xml .= $this->serialize_val($v, $k, false, false, false, false, $use);
703
-				}
704
-			}
705
-			$headers = $xml;
706
-			$this->debug("In serializeEnvelope, serialized array of headers to $headers");
707
-		}
708
-		$headers = "<SOAP-ENV:Header>".$headers."</SOAP-ENV:Header>";
709
-	}
710
-	// serialize envelope
711
-	return
712
-	'<?xml version="1.0" encoding="'.$this->soap_defencoding .'"?'.">".
713
-	'<SOAP-ENV:Envelope'.$ns_string.">".
714
-	$headers.
715
-	"<SOAP-ENV:Body>".
716
-		$body.
717
-	"</SOAP-ENV:Body>".
718
-	"</SOAP-ENV:Envelope>";
719
-    }
720
-
721
-	/**
722
-	 * formats a string to be inserted into an HTML stream
723
-	 *
724
-	 * @param string $str The string to format
725
-	 * @return string The formatted string
726
-	 * @access public
727
-	 * @deprecated
728
-	 */
687
+    foreach(array_merge($this->namespaces,$namespaces) as $k => $v){
688
+        $ns_string .= " xmlns:$k=\"$v\"";
689
+    }
690
+    if($encodingStyle) {
691
+        $ns_string = " SOAP-ENV:encodingStyle=\"$encodingStyle\"$ns_string";
692
+    }
693
+
694
+    // serialize headers
695
+    if($headers){
696
+        if (is_array($headers)) {
697
+            $xml = '';
698
+            foreach ($headers as $k => $v) {
699
+                if (is_object($v) && get_class($v) == 'soapval') {
700
+                    $xml .= $this->serialize_val($v, false, false, false, false, false, $use);
701
+                } else {
702
+                    $xml .= $this->serialize_val($v, $k, false, false, false, false, $use);
703
+                }
704
+            }
705
+            $headers = $xml;
706
+            $this->debug("In serializeEnvelope, serialized array of headers to $headers");
707
+        }
708
+        $headers = "<SOAP-ENV:Header>".$headers."</SOAP-ENV:Header>";
709
+    }
710
+    // serialize envelope
711
+    return
712
+    '<?xml version="1.0" encoding="'.$this->soap_defencoding .'"?'.">".
713
+    '<SOAP-ENV:Envelope'.$ns_string.">".
714
+    $headers.
715
+    "<SOAP-ENV:Body>".
716
+        $body.
717
+    "</SOAP-ENV:Body>".
718
+    "</SOAP-ENV:Envelope>";
719
+    }
720
+
721
+    /**
722
+     * formats a string to be inserted into an HTML stream
723
+     *
724
+     * @param string $str The string to format
725
+     * @return string The formatted string
726
+     * @access public
727
+     * @deprecated
728
+     */
729 729
     function formatDump($str){
730
-		$str = htmlspecialchars($str);
731
-		return nl2br($str);
732
-    }
733
-
734
-	/**
735
-	* contracts (changes namespace to prefix) a qualified name
736
-	*
737
-	* @param    string $qname qname
738
-	* @return	string contracted qname
739
-	* @access   private
740
-	*/
741
-	function contractQname($qname){
742
-		// get element namespace
743
-		//$this->xdebug("Contract $qname");
744
-		if (strrpos($qname, ':')) {
745
-			// get unqualified name
746
-			$name = substr($qname, strrpos($qname, ':') + 1);
747
-			// get ns
748
-			$ns = substr($qname, 0, strrpos($qname, ':'));
749
-			$p = $this->getPrefixFromNamespace($ns);
750
-			if ($p) {
751
-				return $p . ':' . $name;
752
-			}
753
-			return $qname;
754
-		} else {
755
-			return $qname;
756
-		}
757
-	}
758
-
759
-	/**
760
-	* expands (changes prefix to namespace) a qualified name
761
-	*
762
-	* @param    string $qname qname
763
-	* @return	string expanded qname
764
-	* @access   private
765
-	*/
766
-	function expandQname($qname){
767
-		// get element prefix
768
-		if(strpos($qname,':') && !preg_match('/^http:\/\//',$qname)){
769
-			// get unqualified name
770
-			$name = substr(strstr($qname,':'),1);
771
-			// get ns prefix
772
-			$prefix = substr($qname,0,strpos($qname,':'));
773
-			if(isset($this->namespaces[$prefix])){
774
-				return $this->namespaces[$prefix].':'.$name;
775
-			} else {
776
-				return $qname;
777
-			}
778
-		} else {
779
-			return $qname;
780
-		}
781
-	}
782
-
783
-    /**
784
-    * returns the local part of a prefixed string
785
-    * returns the original string, if not prefixed
786
-    *
787
-    * @param string $str The prefixed string
788
-    * @return string The local part
789
-    * @access public
790
-    */
791
-	function getLocalPart($str){
792
-		if($sstr = strrchr($str,':')){
793
-			// get unqualified name
794
-			return substr( $sstr, 1 );
795
-		} else {
796
-			return $str;
797
-		}
798
-	}
799
-
800
-	/**
801
-    * returns the prefix part of a prefixed string
802
-    * returns false, if not prefixed
803
-    *
804
-    * @param string $str The prefixed string
805
-    * @return mixed The prefix or false if there is no prefix
806
-    * @access public
807
-    */
808
-	function getPrefix($str){
809
-		if($pos = strrpos($str,':')){
810
-			// get prefix
811
-			return substr($str,0,$pos);
812
-		}
813
-		return false;
814
-	}
815
-
816
-	/**
817
-    * pass it a prefix, it returns a namespace
818
-    *
819
-    * @param string $prefix The prefix
820
-    * @return mixed The namespace, false if no namespace has the specified prefix
821
-    * @access public
822
-    */
823
-	function getNamespaceFromPrefix($prefix){
824
-		if (isset($this->namespaces[$prefix])) {
825
-			return $this->namespaces[$prefix];
826
-		}
827
-		//$this->setError("No namespace registered for prefix '$prefix'");
828
-		return false;
829
-	}
830
-
831
-	/**
832
-    * returns the prefix for a given namespace (or prefix)
833
-    * or false if no prefixes registered for the given namespace
834
-    *
835
-    * @param string $ns The namespace
836
-    * @return mixed The prefix, false if the namespace has no prefixes
837
-    * @access public
838
-    */
839
-	function getPrefixFromNamespace($ns) {
840
-		foreach ($this->namespaces as $p => $n) {
841
-			if ($ns == $n || $ns == $p) {
842
-			    $this->usedNamespaces[$p] = $n;
843
-				return $p;
844
-			}
845
-		}
846
-		return false;
847
-	}
848
-
849
-	/**
850
-    * returns the time in ODBC canonical form with microseconds
851
-    *
852
-    * @return string The time in ODBC canonical form with microseconds
853
-    * @access public
854
-    */
855
-	function getmicrotime() {
856
-		if (function_exists('gettimeofday')) {
857
-			$tod = gettimeofday();
858
-			$sec = $tod['sec'];
859
-			$usec = $tod['usec'];
860
-		} else {
861
-			$sec = time();
862
-			$usec = 0;
863
-		}
864
-		return strftime('%Y-%m-%d %H:%M:%S', $sec) . '.' . sprintf('%06d', $usec);
865
-	}
866
-
867
-	/**
868
-	 * Returns a string with the output of var_dump
869
-	 *
870
-	 * @param mixed $data The variable to var_dump
871
-	 * @return string The output of var_dump
872
-	 * @access public
873
-	 */
730
+        $str = htmlspecialchars($str);
731
+        return nl2br($str);
732
+    }
733
+
734
+    /**
735
+     * contracts (changes namespace to prefix) a qualified name
736
+     *
737
+     * @param    string $qname qname
738
+     * @return	string contracted qname
739
+     * @access   private
740
+     */
741
+    function contractQname($qname){
742
+        // get element namespace
743
+        //$this->xdebug("Contract $qname");
744
+        if (strrpos($qname, ':')) {
745
+            // get unqualified name
746
+            $name = substr($qname, strrpos($qname, ':') + 1);
747
+            // get ns
748
+            $ns = substr($qname, 0, strrpos($qname, ':'));
749
+            $p = $this->getPrefixFromNamespace($ns);
750
+            if ($p) {
751
+                return $p . ':' . $name;
752
+            }
753
+            return $qname;
754
+        } else {
755
+            return $qname;
756
+        }
757
+    }
758
+
759
+    /**
760
+     * expands (changes prefix to namespace) a qualified name
761
+     *
762
+     * @param    string $qname qname
763
+     * @return	string expanded qname
764
+     * @access   private
765
+     */
766
+    function expandQname($qname){
767
+        // get element prefix
768
+        if(strpos($qname,':') && !preg_match('/^http:\/\//',$qname)){
769
+            // get unqualified name
770
+            $name = substr(strstr($qname,':'),1);
771
+            // get ns prefix
772
+            $prefix = substr($qname,0,strpos($qname,':'));
773
+            if(isset($this->namespaces[$prefix])){
774
+                return $this->namespaces[$prefix].':'.$name;
775
+            } else {
776
+                return $qname;
777
+            }
778
+        } else {
779
+            return $qname;
780
+        }
781
+    }
782
+
783
+    /**
784
+     * returns the local part of a prefixed string
785
+     * returns the original string, if not prefixed
786
+     *
787
+     * @param string $str The prefixed string
788
+     * @return string The local part
789
+     * @access public
790
+     */
791
+    function getLocalPart($str){
792
+        if($sstr = strrchr($str,':')){
793
+            // get unqualified name
794
+            return substr( $sstr, 1 );
795
+        } else {
796
+            return $str;
797
+        }
798
+    }
799
+
800
+    /**
801
+     * returns the prefix part of a prefixed string
802
+     * returns false, if not prefixed
803
+     *
804
+     * @param string $str The prefixed string
805
+     * @return mixed The prefix or false if there is no prefix
806
+     * @access public
807
+     */
808
+    function getPrefix($str){
809
+        if($pos = strrpos($str,':')){
810
+            // get prefix
811
+            return substr($str,0,$pos);
812
+        }
813
+        return false;
814
+    }
815
+
816
+    /**
817
+     * pass it a prefix, it returns a namespace
818
+     *
819
+     * @param string $prefix The prefix
820
+     * @return mixed The namespace, false if no namespace has the specified prefix
821
+     * @access public
822
+     */
823
+    function getNamespaceFromPrefix($prefix){
824
+        if (isset($this->namespaces[$prefix])) {
825
+            return $this->namespaces[$prefix];
826
+        }
827
+        //$this->setError("No namespace registered for prefix '$prefix'");
828
+        return false;
829
+    }
830
+
831
+    /**
832
+     * returns the prefix for a given namespace (or prefix)
833
+     * or false if no prefixes registered for the given namespace
834
+     *
835
+     * @param string $ns The namespace
836
+     * @return mixed The prefix, false if the namespace has no prefixes
837
+     * @access public
838
+     */
839
+    function getPrefixFromNamespace($ns) {
840
+        foreach ($this->namespaces as $p => $n) {
841
+            if ($ns == $n || $ns == $p) {
842
+                $this->usedNamespaces[$p] = $n;
843
+                return $p;
844
+            }
845
+        }
846
+        return false;
847
+    }
848
+
849
+    /**
850
+     * returns the time in ODBC canonical form with microseconds
851
+     *
852
+     * @return string The time in ODBC canonical form with microseconds
853
+     * @access public
854
+     */
855
+    function getmicrotime() {
856
+        if (function_exists('gettimeofday')) {
857
+            $tod = gettimeofday();
858
+            $sec = $tod['sec'];
859
+            $usec = $tod['usec'];
860
+        } else {
861
+            $sec = time();
862
+            $usec = 0;
863
+        }
864
+        return strftime('%Y-%m-%d %H:%M:%S', $sec) . '.' . sprintf('%06d', $usec);
865
+    }
866
+
867
+    /**
868
+     * Returns a string with the output of var_dump
869
+     *
870
+     * @param mixed $data The variable to var_dump
871
+     * @return string The output of var_dump
872
+     * @access public
873
+     */
874 874
     function varDump($data) {
875
-		ob_start();
876
-		var_dump($data);
877
-		$ret_val = ob_get_contents();
878
-		ob_end_clean();
879
-		return $ret_val;
880
-	}
881
-
882
-	/**
883
-	* represents the object as a string
884
-	*
885
-	* @return	string
886
-	* @access   public
887
-	*/
888
-	function __toString() {
889
-		return $this->varDump($this);
890
-	}
875
+        ob_start();
876
+        var_dump($data);
877
+        $ret_val = ob_get_contents();
878
+        ob_end_clean();
879
+        return $ret_val;
880
+    }
881
+
882
+    /**
883
+     * represents the object as a string
884
+     *
885
+     * @return	string
886
+     * @access   public
887
+     */
888
+    function __toString() {
889
+        return $this->varDump($this);
890
+    }
891 891
 }
892 892
 
893 893
 // XML Schema Datatype Helper Functions
@@ -903,35 +903,35 @@  discard block
 block discarded – undo
903 903
 * @access   public
904 904
 */
905 905
 function timestamp_to_iso8601($timestamp,$utc=true){
906
-	$datestr = date('Y-m-d\TH:i:sO',$timestamp);
907
-	$pos = strrpos($datestr, "+");
908
-	if ($pos === FALSE) {
909
-		$pos = strrpos($datestr, "-");
910
-	}
911
-	if ($pos !== FALSE) {
912
-		if (strlen($datestr) == $pos + 5) {
913
-			$datestr = substr($datestr, 0, $pos + 3) . ':' . substr($datestr, -2);
914
-		}
915
-	}
916
-	if($utc){
917
-		$pattern = '/'.
918
-		'([0-9]{4})-'.	// centuries & years CCYY-
919
-		'([0-9]{2})-'.	// months MM-
920
-		'([0-9]{2})'.	// days DD
921
-		'T'.			// separator T
922
-		'([0-9]{2}):'.	// hours hh:
923
-		'([0-9]{2}):'.	// minutes mm:
924
-		'([0-9]{2})(\.[0-9]*)?'. // seconds ss.ss...
925
-		'(Z|[+\-][0-9]{2}:?[0-9]{2})?'. // Z to indicate UTC, -/+HH:MM:SS.SS... for local tz's
926
-		'/';
927
-
928
-		if(preg_match($pattern,$datestr,$regs)){
929
-			return sprintf('%04d-%02d-%02dT%02d:%02d:%02dZ',$regs[1],$regs[2],$regs[3],$regs[4],$regs[5],$regs[6]);
930
-		}
931
-		return false;
932
-	} else {
933
-		return $datestr;
934
-	}
906
+    $datestr = date('Y-m-d\TH:i:sO',$timestamp);
907
+    $pos = strrpos($datestr, "+");
908
+    if ($pos === FALSE) {
909
+        $pos = strrpos($datestr, "-");
910
+    }
911
+    if ($pos !== FALSE) {
912
+        if (strlen($datestr) == $pos + 5) {
913
+            $datestr = substr($datestr, 0, $pos + 3) . ':' . substr($datestr, -2);
914
+        }
915
+    }
916
+    if($utc){
917
+        $pattern = '/'.
918
+        '([0-9]{4})-'.	// centuries & years CCYY-
919
+        '([0-9]{2})-'.	// months MM-
920
+        '([0-9]{2})'.	// days DD
921
+        'T'.			// separator T
922
+        '([0-9]{2}):'.	// hours hh:
923
+        '([0-9]{2}):'.	// minutes mm:
924
+        '([0-9]{2})(\.[0-9]*)?'. // seconds ss.ss...
925
+        '(Z|[+\-][0-9]{2}:?[0-9]{2})?'. // Z to indicate UTC, -/+HH:MM:SS.SS... for local tz's
926
+        '/';
927
+
928
+        if(preg_match($pattern,$datestr,$regs)){
929
+            return sprintf('%04d-%02d-%02dT%02d:%02d:%02dZ',$regs[1],$regs[2],$regs[3],$regs[4],$regs[5],$regs[6]);
930
+        }
931
+        return false;
932
+    } else {
933
+        return $datestr;
934
+    }
935 935
 }
936 936
 
937 937
 /**
@@ -942,35 +942,35 @@  discard block
 block discarded – undo
942 942
 * @access   public
943 943
 */
944 944
 function iso8601_to_timestamp($datestr){
945
-	$pattern = '/'.
946
-	'([0-9]{4})-'.	// centuries & years CCYY-
947
-	'([0-9]{2})-'.	// months MM-
948
-	'([0-9]{2})'.	// days DD
949
-	'T'.			// separator T
950
-	'([0-9]{2}):'.	// hours hh:
951
-	'([0-9]{2}):'.	// minutes mm:
952
-	'([0-9]{2})(\.[0-9]+)?'. // seconds ss.ss...
953
-	'(Z|[+\-][0-9]{2}:?[0-9]{2})?'. // Z to indicate UTC, -/+HH:MM:SS.SS... for local tz's
954
-	'/';
955
-	if(preg_match($pattern,$datestr,$regs)){
956
-		// not utc
957
-		if($regs[8] != 'Z'){
958
-			$op = substr($regs[8],0,1);
959
-			$h = substr($regs[8],1,2);
960
-			$m = substr($regs[8],strlen($regs[8])-2,2);
961
-			if($op == '-'){
962
-				$regs[4] = $regs[4] + $h;
963
-				$regs[5] = $regs[5] + $m;
964
-			} elseif($op == '+'){
965
-				$regs[4] = $regs[4] - $h;
966
-				$regs[5] = $regs[5] - $m;
967
-			}
968
-		}
969
-		return gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
945
+    $pattern = '/'.
946
+    '([0-9]{4})-'.	// centuries & years CCYY-
947
+    '([0-9]{2})-'.	// months MM-
948
+    '([0-9]{2})'.	// days DD
949
+    'T'.			// separator T
950
+    '([0-9]{2}):'.	// hours hh:
951
+    '([0-9]{2}):'.	// minutes mm:
952
+    '([0-9]{2})(\.[0-9]+)?'. // seconds ss.ss...
953
+    '(Z|[+\-][0-9]{2}:?[0-9]{2})?'. // Z to indicate UTC, -/+HH:MM:SS.SS... for local tz's
954
+    '/';
955
+    if(preg_match($pattern,$datestr,$regs)){
956
+        // not utc
957
+        if($regs[8] != 'Z'){
958
+            $op = substr($regs[8],0,1);
959
+            $h = substr($regs[8],1,2);
960
+            $m = substr($regs[8],strlen($regs[8])-2,2);
961
+            if($op == '-'){
962
+                $regs[4] = $regs[4] + $h;
963
+                $regs[5] = $regs[5] + $m;
964
+            } elseif($op == '+'){
965
+                $regs[4] = $regs[4] - $h;
966
+                $regs[5] = $regs[5] - $m;
967
+            }
968
+        }
969
+        return gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
970 970
 //		return strtotime("$regs[1]-$regs[2]-$regs[3] $regs[4]:$regs[5]:$regs[6]Z");
971
-	} else {
972
-		return false;
973
-	}
971
+    } else {
972
+        return false;
973
+    }
974 974
 }
975 975
 
976 976
 /**
@@ -982,13 +982,13 @@  discard block
 block discarded – undo
982 982
 */
983 983
 function usleepWindows($usec)
984 984
 {
985
-	$start = gettimeofday();
986
-
987
-	do
988
-	{
989
-		$stop = gettimeofday();
990
-		$timePassed = 1000000 * ($stop['sec'] - $start['sec'])
991
-		+ $stop['usec'] - $start['usec'];
992
-	}
993
-	while ($timePassed < $usec);
985
+    $start = gettimeofday();
986
+
987
+    do
988
+    {
989
+        $stop = gettimeofday();
990
+        $timePassed = 1000000 * ($stop['sec'] - $start['sec'])
991
+        + $stop['usec'] - $start['usec'];
992
+    }
993
+    while ($timePassed < $usec);
994 994
 }
Please login to merge, or discard this patch.
main/inc/lib/nusoap/class.wsdlcache.php 1 patch
Indentation   +175 added lines, -175 removed lines patch added patch discarded remove patch
@@ -17,189 +17,189 @@
 block discarded – undo
17 17
 */
18 18
 class nusoap_wsdlcache
19 19
 {
20
-	/**
21
-	 *	@var resource
22
-	 *	@access private
23
-	 */
24
-	var $fplock;
25
-	/**
26
-	 *	@var integer
27
-	 *	@access private
28
-	 */
29
-	var $cache_lifetime;
30
-	/**
31
-	 *	@var string
32
-	 *	@access private
33
-	 */
34
-	var $cache_dir;
35
-	/**
36
-	 *	@var string
37
-	 *	@access public
38
-	 */
39
-	var $debug_str = '';
20
+    /**
21
+     *	@var resource
22
+     *	@access private
23
+     */
24
+    var $fplock;
25
+    /**
26
+     *	@var integer
27
+     *	@access private
28
+     */
29
+    var $cache_lifetime;
30
+    /**
31
+     *	@var string
32
+     *	@access private
33
+     */
34
+    var $cache_dir;
35
+    /**
36
+     *	@var string
37
+     *	@access public
38
+     */
39
+    var $debug_str = '';
40 40
 
41
-	/**
42
-	* constructor
43
-	*
44
-	* @param string $cache_dir directory for cache-files
45
-	* @param integer $cache_lifetime lifetime for caching-files in seconds or 0 for unlimited
46
-	* @access public
47
-	*/
48
-	function __construct($cache_dir='.', $cache_lifetime=0) {
49
-		$this->fplock = array();
50
-		$this->cache_dir = $cache_dir != '' ? $cache_dir : '.';
51
-		$this->cache_lifetime = $cache_lifetime;
52
-	}
41
+    /**
42
+     * constructor
43
+     *
44
+     * @param string $cache_dir directory for cache-files
45
+     * @param integer $cache_lifetime lifetime for caching-files in seconds or 0 for unlimited
46
+     * @access public
47
+     */
48
+    function __construct($cache_dir='.', $cache_lifetime=0) {
49
+        $this->fplock = array();
50
+        $this->cache_dir = $cache_dir != '' ? $cache_dir : '.';
51
+        $this->cache_lifetime = $cache_lifetime;
52
+    }
53 53
 
54
-	/**
55
-	* creates the filename used to cache a wsdl instance
56
-	*
57
-	* @param string $wsdl The URL of the wsdl instance
58
-	* @return string The filename used to cache the instance
59
-	* @access private
60
-	*/
61
-	function createFilename($wsdl) {
62
-		return $this->cache_dir.'/wsdlcache-' . md5($wsdl);
63
-	}
54
+    /**
55
+     * creates the filename used to cache a wsdl instance
56
+     *
57
+     * @param string $wsdl The URL of the wsdl instance
58
+     * @return string The filename used to cache the instance
59
+     * @access private
60
+     */
61
+    function createFilename($wsdl) {
62
+        return $this->cache_dir.'/wsdlcache-' . md5($wsdl);
63
+    }
64 64
 
65
-	/**
66
-	* adds debug data to the class level debug string
67
-	*
68
-	* @param    string $string debug data
69
-	* @access   private
70
-	*/
71
-	function debug($string){
72
-		$this->debug_str .= get_class($this).": $string\n";
73
-	}
65
+    /**
66
+     * adds debug data to the class level debug string
67
+     *
68
+     * @param    string $string debug data
69
+     * @access   private
70
+     */
71
+    function debug($string){
72
+        $this->debug_str .= get_class($this).": $string\n";
73
+    }
74 74
 
75
-	/**
76
-	* gets a wsdl instance from the cache
77
-	*
78
-	* @param string $wsdl The URL of the wsdl instance
79
-	* @return object wsdl The cached wsdl instance, null if the instance is not in the cache
80
-	* @access public
81
-	*/
82
-	function get($wsdl) {
83
-		$filename = $this->createFilename($wsdl);
84
-		if ($this->obtainMutex($filename, "r")) {
85
-			// check for expired WSDL that must be removed from the cache
86
- 			if ($this->cache_lifetime > 0) {
87
-				if (file_exists($filename) && (time() - filemtime($filename) > $this->cache_lifetime)) {
88
-					unlink($filename);
89
-					$this->debug("Expired $wsdl ($filename) from cache");
90
-					$this->releaseMutex($filename);
91
-					return null;
92
-  				}
93
-			}
94
-			// see what there is to return
95
-			if (!file_exists($filename)) {
96
-				$this->debug("$wsdl ($filename) not in cache (1)");
97
-				$this->releaseMutex($filename);
98
-				return null;
99
-			}
100
-			$fp = @fopen($filename, "r");
101
-			if ($fp) {
102
-				$s = implode("", @file($filename));
103
-				fclose($fp);
104
-				$this->debug("Got $wsdl ($filename) from cache");
105
-			} else {
106
-				$s = null;
107
-				$this->debug("$wsdl ($filename) not in cache (2)");
108
-			}
109
-			$this->releaseMutex($filename);
110
-			return (!is_null($s)) ? unserialize($s) : null;
111
-		} else {
112
-			$this->debug("Unable to obtain mutex for $filename in get");
113
-		}
114
-		return null;
115
-	}
75
+    /**
76
+     * gets a wsdl instance from the cache
77
+     *
78
+     * @param string $wsdl The URL of the wsdl instance
79
+     * @return object wsdl The cached wsdl instance, null if the instance is not in the cache
80
+     * @access public
81
+     */
82
+    function get($wsdl) {
83
+        $filename = $this->createFilename($wsdl);
84
+        if ($this->obtainMutex($filename, "r")) {
85
+            // check for expired WSDL that must be removed from the cache
86
+                if ($this->cache_lifetime > 0) {
87
+                if (file_exists($filename) && (time() - filemtime($filename) > $this->cache_lifetime)) {
88
+                    unlink($filename);
89
+                    $this->debug("Expired $wsdl ($filename) from cache");
90
+                    $this->releaseMutex($filename);
91
+                    return null;
92
+                    }
93
+            }
94
+            // see what there is to return
95
+            if (!file_exists($filename)) {
96
+                $this->debug("$wsdl ($filename) not in cache (1)");
97
+                $this->releaseMutex($filename);
98
+                return null;
99
+            }
100
+            $fp = @fopen($filename, "r");
101
+            if ($fp) {
102
+                $s = implode("", @file($filename));
103
+                fclose($fp);
104
+                $this->debug("Got $wsdl ($filename) from cache");
105
+            } else {
106
+                $s = null;
107
+                $this->debug("$wsdl ($filename) not in cache (2)");
108
+            }
109
+            $this->releaseMutex($filename);
110
+            return (!is_null($s)) ? unserialize($s) : null;
111
+        } else {
112
+            $this->debug("Unable to obtain mutex for $filename in get");
113
+        }
114
+        return null;
115
+    }
116 116
 
117
-	/**
118
-	* obtains the local mutex
119
-	*
120
-	* @param string $filename The Filename of the Cache to lock
121
-	* @param string $mode The open-mode ("r" or "w") or the file - affects lock-mode
122
-	* @return boolean Lock successfully obtained ?!
123
-	* @access private
124
-	*/
125
-	function obtainMutex($filename, $mode) {
126
-		if (isset($this->fplock[md5($filename)])) {
127
-			$this->debug("Lock for $filename already exists");
128
-			return false;
129
-		}
130
-		$this->fplock[md5($filename)] = fopen($filename.".lock", "w");
131
-		if ($mode == "r") {
132
-			return flock($this->fplock[md5($filename)], LOCK_SH);
133
-		} else {
134
-			return flock($this->fplock[md5($filename)], LOCK_EX);
135
-		}
136
-	}
117
+    /**
118
+     * obtains the local mutex
119
+     *
120
+     * @param string $filename The Filename of the Cache to lock
121
+     * @param string $mode The open-mode ("r" or "w") or the file - affects lock-mode
122
+     * @return boolean Lock successfully obtained ?!
123
+     * @access private
124
+     */
125
+    function obtainMutex($filename, $mode) {
126
+        if (isset($this->fplock[md5($filename)])) {
127
+            $this->debug("Lock for $filename already exists");
128
+            return false;
129
+        }
130
+        $this->fplock[md5($filename)] = fopen($filename.".lock", "w");
131
+        if ($mode == "r") {
132
+            return flock($this->fplock[md5($filename)], LOCK_SH);
133
+        } else {
134
+            return flock($this->fplock[md5($filename)], LOCK_EX);
135
+        }
136
+    }
137 137
 
138
-	/**
139
-	* adds a wsdl instance to the cache
140
-	*
141
-	* @param object wsdl $wsdl_instance The wsdl instance to add
142
-	* @return boolean WSDL successfully cached
143
-	* @access public
144
-	*/
145
-	function put($wsdl_instance) {
146
-		$filename = $this->createFilename($wsdl_instance->wsdl);
147
-		$s = serialize($wsdl_instance);
148
-		if ($this->obtainMutex($filename, "w")) {
149
-			$fp = fopen($filename, "w");
150
-			if (! $fp) {
151
-				$this->debug("Cannot write $wsdl_instance->wsdl ($filename) in cache");
152
-				$this->releaseMutex($filename);
153
-				return false;
154
-			}
155
-			fputs($fp, $s);
156
-			fclose($fp);
157
-			$this->debug("Put $wsdl_instance->wsdl ($filename) in cache");
158
-			$this->releaseMutex($filename);
159
-			return true;
160
-		} else {
161
-			$this->debug("Unable to obtain mutex for $filename in put");
162
-		}
163
-		return false;
164
-	}
138
+    /**
139
+     * adds a wsdl instance to the cache
140
+     *
141
+     * @param object wsdl $wsdl_instance The wsdl instance to add
142
+     * @return boolean WSDL successfully cached
143
+     * @access public
144
+     */
145
+    function put($wsdl_instance) {
146
+        $filename = $this->createFilename($wsdl_instance->wsdl);
147
+        $s = serialize($wsdl_instance);
148
+        if ($this->obtainMutex($filename, "w")) {
149
+            $fp = fopen($filename, "w");
150
+            if (! $fp) {
151
+                $this->debug("Cannot write $wsdl_instance->wsdl ($filename) in cache");
152
+                $this->releaseMutex($filename);
153
+                return false;
154
+            }
155
+            fputs($fp, $s);
156
+            fclose($fp);
157
+            $this->debug("Put $wsdl_instance->wsdl ($filename) in cache");
158
+            $this->releaseMutex($filename);
159
+            return true;
160
+        } else {
161
+            $this->debug("Unable to obtain mutex for $filename in put");
162
+        }
163
+        return false;
164
+    }
165 165
 
166
-	/**
167
-	* releases the local mutex
168
-	*
169
-	* @param string $filename The Filename of the Cache to lock
170
-	* @return boolean Lock successfully released
171
-	* @access private
172
-	*/
173
-	function releaseMutex($filename) {
174
-		$ret = flock($this->fplock[md5($filename)], LOCK_UN);
175
-		fclose($this->fplock[md5($filename)]);
176
-		unset($this->fplock[md5($filename)]);
177
-		if (! $ret) {
178
-			$this->debug("Not able to release lock for $filename");
179
-		}
180
-		return $ret;
181
-	}
166
+    /**
167
+     * releases the local mutex
168
+     *
169
+     * @param string $filename The Filename of the Cache to lock
170
+     * @return boolean Lock successfully released
171
+     * @access private
172
+     */
173
+    function releaseMutex($filename) {
174
+        $ret = flock($this->fplock[md5($filename)], LOCK_UN);
175
+        fclose($this->fplock[md5($filename)]);
176
+        unset($this->fplock[md5($filename)]);
177
+        if (! $ret) {
178
+            $this->debug("Not able to release lock for $filename");
179
+        }
180
+        return $ret;
181
+    }
182 182
 
183
-	/**
184
-	* removes a wsdl instance from the cache
185
-	*
186
-	* @param string $wsdl The URL of the wsdl instance
187
-	* @return boolean Whether there was an instance to remove
188
-	* @access public
189
-	*/
190
-	function remove($wsdl) {
191
-		$filename = $this->createFilename($wsdl);
192
-		if (!file_exists($filename)) {
193
-			$this->debug("$wsdl ($filename) not in cache to be removed");
194
-			return false;
195
-		}
196
-		// ignore errors obtaining mutex
197
-		$this->obtainMutex($filename, "w");
198
-		$ret = unlink($filename);
199
-		$this->debug("Removed ($ret) $wsdl ($filename) from cache");
200
-		$this->releaseMutex($filename);
201
-		return $ret;
202
-	}
183
+    /**
184
+     * removes a wsdl instance from the cache
185
+     *
186
+     * @param string $wsdl The URL of the wsdl instance
187
+     * @return boolean Whether there was an instance to remove
188
+     * @access public
189
+     */
190
+    function remove($wsdl) {
191
+        $filename = $this->createFilename($wsdl);
192
+        if (!file_exists($filename)) {
193
+            $this->debug("$wsdl ($filename) not in cache to be removed");
194
+            return false;
195
+        }
196
+        // ignore errors obtaining mutex
197
+        $this->obtainMutex($filename, "w");
198
+        $ret = unlink($filename);
199
+        $this->debug("Removed ($ret) $wsdl ($filename) from cache");
200
+        $this->releaseMutex($filename);
201
+        return $ret;
202
+    }
203 203
 }
204 204
 
205 205
 /**
Please login to merge, or discard this patch.
main/inc/lib/nusoap/class.soap_fault.php 1 patch
Indentation   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -10,72 +10,72 @@
 block discarded – undo
10 10
 */
11 11
 class nusoap_fault extends nusoap_base
12 12
 {
13
-	/**
14
-	 * The fault code (client|server)
15
-	 * @var string
16
-	 * @access private
17
-	 */
18
-	var $faultcode;
19
-	/**
20
-	 * The fault actor
21
-	 * @var string
22
-	 * @access private
23
-	 */
24
-	var $faultactor;
25
-	/**
26
-	 * The fault string, a description of the fault
27
-	 * @var string
28
-	 * @access private
29
-	 */
30
-	var $faultstring;
31
-	/**
32
-	 * The fault detail, typically a string or array of string
33
-	 * @var mixed
34
-	 * @access private
35
-	 */
36
-	var $faultdetail;
13
+    /**
14
+     * The fault code (client|server)
15
+     * @var string
16
+     * @access private
17
+     */
18
+    var $faultcode;
19
+    /**
20
+     * The fault actor
21
+     * @var string
22
+     * @access private
23
+     */
24
+    var $faultactor;
25
+    /**
26
+     * The fault string, a description of the fault
27
+     * @var string
28
+     * @access private
29
+     */
30
+    var $faultstring;
31
+    /**
32
+     * The fault detail, typically a string or array of string
33
+     * @var mixed
34
+     * @access private
35
+     */
36
+    var $faultdetail;
37 37
 
38
-	/**
39
-	* constructor
40
-    *
41
-    * @param string $faultcode (SOAP-ENV:Client | SOAP-ENV:Server)
42
-    * @param string $faultactor only used when msg routed between multiple actors
43
-    * @param string $faultstring human readable error message
44
-    * @param mixed $faultdetail detail, typically a string or array of string
45
-	*/
46
-	public function __construct($faultcode,$faultactor='',$faultstring='',$faultdetail=''){
47
-		parent::__construct();
48
-		$this->faultcode = $faultcode;
49
-		$this->faultactor = $faultactor;
50
-		$this->faultstring = $faultstring;
51
-		$this->faultdetail = $faultdetail;
52
-	}
38
+    /**
39
+     * constructor
40
+     *
41
+     * @param string $faultcode (SOAP-ENV:Client | SOAP-ENV:Server)
42
+     * @param string $faultactor only used when msg routed between multiple actors
43
+     * @param string $faultstring human readable error message
44
+     * @param mixed $faultdetail detail, typically a string or array of string
45
+     */
46
+    public function __construct($faultcode,$faultactor='',$faultstring='',$faultdetail=''){
47
+        parent::__construct();
48
+        $this->faultcode = $faultcode;
49
+        $this->faultactor = $faultactor;
50
+        $this->faultstring = $faultstring;
51
+        $this->faultdetail = $faultdetail;
52
+    }
53 53
 
54
-	/**
55
-	* serialize a fault
56
-	*
57
-	* @return	string	The serialization of the fault instance.
58
-	* @access   public
59
-	*/
60
-	function serialize(){
61
-		$ns_string = '';
62
-		foreach($this->namespaces as $k => $v){
63
-			$ns_string .= "\n  xmlns:$k=\"$v\"";
64
-		}
65
-		$return_msg =
66
-			'<?xml version="1.0" encoding="'.$this->soap_defencoding.'"?>'.
67
-			'<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"'.$ns_string.">\n".
68
-				'<SOAP-ENV:Body>'.
69
-				'<SOAP-ENV:Fault>'.
70
-					$this->serialize_val($this->faultcode, 'faultcode').
71
-					$this->serialize_val($this->faultactor, 'faultactor').
72
-					$this->serialize_val($this->faultstring, 'faultstring').
73
-					$this->serialize_val($this->faultdetail, 'detail').
74
-				'</SOAP-ENV:Fault>'.
75
-				'</SOAP-ENV:Body>'.
76
-			'</SOAP-ENV:Envelope>';
77
-		return $return_msg;
78
-	}
54
+    /**
55
+     * serialize a fault
56
+     *
57
+     * @return	string	The serialization of the fault instance.
58
+     * @access   public
59
+     */
60
+    function serialize(){
61
+        $ns_string = '';
62
+        foreach($this->namespaces as $k => $v){
63
+            $ns_string .= "\n  xmlns:$k=\"$v\"";
64
+        }
65
+        $return_msg =
66
+            '<?xml version="1.0" encoding="'.$this->soap_defencoding.'"?>'.
67
+            '<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"'.$ns_string.">\n".
68
+                '<SOAP-ENV:Body>'.
69
+                '<SOAP-ENV:Fault>'.
70
+                    $this->serialize_val($this->faultcode, 'faultcode').
71
+                    $this->serialize_val($this->faultactor, 'faultactor').
72
+                    $this->serialize_val($this->faultstring, 'faultstring').
73
+                    $this->serialize_val($this->faultdetail, 'detail').
74
+                '</SOAP-ENV:Fault>'.
75
+                '</SOAP-ENV:Body>'.
76
+            '</SOAP-ENV:Envelope>';
77
+        return $return_msg;
78
+    }
79 79
 }
80 80
 
81 81
 /**
Please login to merge, or discard this patch.
main/inc/lib/nusoap/class.soap_transport_http.php 1 patch
Indentation   +1262 added lines, -1262 removed lines patch added patch discarded remove patch
@@ -11,171 +11,171 @@  discard block
 block discarded – undo
11 11
 */
12 12
 class soap_transport_http extends nusoap_base
13 13
 {
14
-	var $url = '';
15
-	var $uri = '';
16
-	var $digest_uri = '';
17
-	var $scheme = '';
18
-	var $host = '';
19
-	var $port = '';
20
-	var $path = '';
21
-	var $request_method = 'POST';
22
-	var $protocol_version = '1.0';
23
-	var $encoding = '';
24
-	var $outgoing_headers = array();
25
-	var $incoming_headers = array();
26
-	var $incoming_cookies = array();
27
-	var $outgoing_payload = '';
28
-	var $incoming_payload = '';
29
-	var $response_status_line;	// HTTP response status line
30
-	var $useSOAPAction = true;
31
-	var $persistentConnection = false;
32
-	var $ch = false;	// cURL handle
33
-	var $ch_options = array();	// cURL custom options
34
-	var $use_curl = false;		// force cURL use
35
-	var $proxy = null;			// proxy information (associative array)
36
-	var $username = '';
37
-	var $password = '';
38
-	var $authtype = '';
39
-	var $digestRequest = array();
40
-	var $certRequest = array();	// keys must be cainfofile (optional), sslcertfile, sslkeyfile, passphrase, certpassword (optional), verifypeer (optional), verifyhost (optional)
41
-								// cainfofile: certificate authority file, e.g. '$pathToPemFiles/rootca.pem'
42
-								// sslcertfile: SSL certificate file, e.g. '$pathToPemFiles/mycert.pem'
43
-								// sslkeyfile: SSL key file, e.g. '$pathToPemFiles/mykey.pem'
44
-								// passphrase: SSL key password/passphrase
45
-								// certpassword: SSL certificate password
46
-								// verifypeer: default is 1
47
-								// verifyhost: default is 1
48
-
49
-	/**
50
-	* constructor
51
-	*
52
-	* @param string $url The URL to which to connect
53
-	* @param array $curl_options User-specified cURL options
54
-	* @param boolean $use_curl Whether to try to force cURL use
55
-	* @access public
56
-	*/
57
-	function __construct($url, $curl_options = NULL, $use_curl = false){
58
-		parent::__construct();
59
-		$this->debug("ctor url=$url use_curl=$use_curl curl_options:");
60
-		$this->appendDebug($this->varDump($curl_options));
61
-		$this->setURL($url);
62
-		if (is_array($curl_options)) {
63
-			$this->ch_options = $curl_options;
64
-		}
65
-		$this->use_curl = $use_curl;
66
-		preg_match('/\$Revisio' . 'n: ([^ ]+)/', $this->revision, $rev);
67
-		$this->setHeader('User-Agent', $this->title.'/'.$this->version.' ('.$rev[1].')');
68
-	}
69
-
70
-	/**
71
-	* sets a cURL option
72
-	*
73
-	* @param	mixed $option The cURL option (always integer?)
74
-	* @param	mixed $value The cURL option value
75
-	* @access   private
76
-	*/
77
-	function setCurlOption($option, $value) {
78
-		$this->debug("setCurlOption option=$option, value=");
79
-		$this->appendDebug($this->varDump($value));
80
-		curl_setopt($this->ch, $option, $value);
81
-	}
82
-
83
-	/**
84
-	* sets an HTTP header
85
-	*
86
-	* @param string $name The name of the header
87
-	* @param string $value The value of the header
88
-	* @access private
89
-	*/
90
-	function setHeader($name, $value) {
91
-		$this->outgoing_headers[$name] = $value;
92
-		$this->debug("set header $name: $value");
93
-	}
94
-
95
-	/**
96
-	* unsets an HTTP header
97
-	*
98
-	* @param string $name The name of the header
99
-	* @access private
100
-	*/
101
-	function unsetHeader($name) {
102
-		if (isset($this->outgoing_headers[$name])) {
103
-			$this->debug("unset header $name");
104
-			unset($this->outgoing_headers[$name]);
105
-		}
106
-	}
107
-
108
-	/**
109
-	* sets the URL to which to connect
110
-	*
111
-	* @param string $url The URL to which to connect
112
-	* @access private
113
-	*/
114
-	function setURL($url) {
115
-		$this->url = $url;
116
-
117
-		$u = parse_url($url);
118
-		foreach($u as $k => $v){
119
-			$this->debug("parsed URL $k = $v");
120
-			$this->$k = $v;
121
-		}
122
-
123
-		// add any GET params to path
124
-		if(isset($u['query']) && $u['query'] != ''){
14
+    var $url = '';
15
+    var $uri = '';
16
+    var $digest_uri = '';
17
+    var $scheme = '';
18
+    var $host = '';
19
+    var $port = '';
20
+    var $path = '';
21
+    var $request_method = 'POST';
22
+    var $protocol_version = '1.0';
23
+    var $encoding = '';
24
+    var $outgoing_headers = array();
25
+    var $incoming_headers = array();
26
+    var $incoming_cookies = array();
27
+    var $outgoing_payload = '';
28
+    var $incoming_payload = '';
29
+    var $response_status_line;	// HTTP response status line
30
+    var $useSOAPAction = true;
31
+    var $persistentConnection = false;
32
+    var $ch = false;	// cURL handle
33
+    var $ch_options = array();	// cURL custom options
34
+    var $use_curl = false;		// force cURL use
35
+    var $proxy = null;			// proxy information (associative array)
36
+    var $username = '';
37
+    var $password = '';
38
+    var $authtype = '';
39
+    var $digestRequest = array();
40
+    var $certRequest = array();	// keys must be cainfofile (optional), sslcertfile, sslkeyfile, passphrase, certpassword (optional), verifypeer (optional), verifyhost (optional)
41
+                                // cainfofile: certificate authority file, e.g. '$pathToPemFiles/rootca.pem'
42
+                                // sslcertfile: SSL certificate file, e.g. '$pathToPemFiles/mycert.pem'
43
+                                // sslkeyfile: SSL key file, e.g. '$pathToPemFiles/mykey.pem'
44
+                                // passphrase: SSL key password/passphrase
45
+                                // certpassword: SSL certificate password
46
+                                // verifypeer: default is 1
47
+                                // verifyhost: default is 1
48
+
49
+    /**
50
+     * constructor
51
+     *
52
+     * @param string $url The URL to which to connect
53
+     * @param array $curl_options User-specified cURL options
54
+     * @param boolean $use_curl Whether to try to force cURL use
55
+     * @access public
56
+     */
57
+    function __construct($url, $curl_options = NULL, $use_curl = false){
58
+        parent::__construct();
59
+        $this->debug("ctor url=$url use_curl=$use_curl curl_options:");
60
+        $this->appendDebug($this->varDump($curl_options));
61
+        $this->setURL($url);
62
+        if (is_array($curl_options)) {
63
+            $this->ch_options = $curl_options;
64
+        }
65
+        $this->use_curl = $use_curl;
66
+        preg_match('/\$Revisio' . 'n: ([^ ]+)/', $this->revision, $rev);
67
+        $this->setHeader('User-Agent', $this->title.'/'.$this->version.' ('.$rev[1].')');
68
+    }
69
+
70
+    /**
71
+     * sets a cURL option
72
+     *
73
+     * @param	mixed $option The cURL option (always integer?)
74
+     * @param	mixed $value The cURL option value
75
+     * @access   private
76
+     */
77
+    function setCurlOption($option, $value) {
78
+        $this->debug("setCurlOption option=$option, value=");
79
+        $this->appendDebug($this->varDump($value));
80
+        curl_setopt($this->ch, $option, $value);
81
+    }
82
+
83
+    /**
84
+     * sets an HTTP header
85
+     *
86
+     * @param string $name The name of the header
87
+     * @param string $value The value of the header
88
+     * @access private
89
+     */
90
+    function setHeader($name, $value) {
91
+        $this->outgoing_headers[$name] = $value;
92
+        $this->debug("set header $name: $value");
93
+    }
94
+
95
+    /**
96
+     * unsets an HTTP header
97
+     *
98
+     * @param string $name The name of the header
99
+     * @access private
100
+     */
101
+    function unsetHeader($name) {
102
+        if (isset($this->outgoing_headers[$name])) {
103
+            $this->debug("unset header $name");
104
+            unset($this->outgoing_headers[$name]);
105
+        }
106
+    }
107
+
108
+    /**
109
+     * sets the URL to which to connect
110
+     *
111
+     * @param string $url The URL to which to connect
112
+     * @access private
113
+     */
114
+    function setURL($url) {
115
+        $this->url = $url;
116
+
117
+        $u = parse_url($url);
118
+        foreach($u as $k => $v){
119
+            $this->debug("parsed URL $k = $v");
120
+            $this->$k = $v;
121
+        }
122
+
123
+        // add any GET params to path
124
+        if(isset($u['query']) && $u['query'] != ''){
125 125
             $this->path .= '?' . $u['query'];
126
-		}
127
-
128
-		// set default port
129
-		if(!isset($u['port'])){
130
-			if($u['scheme'] == 'https'){
131
-				$this->port = 443;
132
-			} else {
133
-				$this->port = 80;
134
-			}
135
-		}
136
-
137
-		$this->uri = $this->path;
138
-		$this->digest_uri = $this->uri;
139
-
140
-		// build headers
141
-		if (!isset($u['port'])) {
142
-			$this->setHeader('Host', $this->host);
143
-		} else {
144
-			$this->setHeader('Host', $this->host.':'.$this->port);
145
-		}
146
-
147
-		if (isset($u['user']) && $u['user'] != '') {
148
-			$this->setCredentials(urldecode($u['user']), isset($u['pass']) ? urldecode($u['pass']) : '');
149
-		}
150
-	}
151
-
152
-	/**
153
-	* gets the I/O method to use
154
-	*
155
-	* @return	string	I/O method to use (socket|curl|unknown)
156
-	* @access	private
157
-	*/
158
-	function io_method() {
159
-		if ($this->use_curl || ($this->scheme == 'https') || ($this->scheme == 'http' && $this->authtype == 'ntlm') || ($this->scheme == 'http' && is_array($this->proxy) && $this->proxy['authtype'] == 'ntlm'))
160
-			return 'curl';
161
-		if (($this->scheme == 'http' || $this->scheme == 'ssl') && $this->authtype != 'ntlm' && (!is_array($this->proxy) || $this->proxy['authtype'] != 'ntlm'))
162
-			return 'socket';
163
-		return 'unknown';
164
-	}
165
-
166
-	/**
167
-	* establish an HTTP connection
168
-	*
169
-	* @param    integer $timeout set connection timeout in seconds
170
-	* @param	integer $response_timeout set response timeout in seconds
171
-	* @return	boolean true if connected, false if not
172
-	* @access   private
173
-	*/
174
-	function connect($connection_timeout=0,$response_timeout=30){
175
-	  	// For PHP 4.3 with OpenSSL, change https scheme to ssl, then treat like
176
-	  	// "regular" socket.
177
-	  	// TODO: disabled for now because OpenSSL must be *compiled* in (not just
178
-	  	//       loaded), and until PHP5 stream_get_wrappers is not available.
126
+        }
127
+
128
+        // set default port
129
+        if(!isset($u['port'])){
130
+            if($u['scheme'] == 'https'){
131
+                $this->port = 443;
132
+            } else {
133
+                $this->port = 80;
134
+            }
135
+        }
136
+
137
+        $this->uri = $this->path;
138
+        $this->digest_uri = $this->uri;
139
+
140
+        // build headers
141
+        if (!isset($u['port'])) {
142
+            $this->setHeader('Host', $this->host);
143
+        } else {
144
+            $this->setHeader('Host', $this->host.':'.$this->port);
145
+        }
146
+
147
+        if (isset($u['user']) && $u['user'] != '') {
148
+            $this->setCredentials(urldecode($u['user']), isset($u['pass']) ? urldecode($u['pass']) : '');
149
+        }
150
+    }
151
+
152
+    /**
153
+     * gets the I/O method to use
154
+     *
155
+     * @return	string	I/O method to use (socket|curl|unknown)
156
+     * @access	private
157
+     */
158
+    function io_method() {
159
+        if ($this->use_curl || ($this->scheme == 'https') || ($this->scheme == 'http' && $this->authtype == 'ntlm') || ($this->scheme == 'http' && is_array($this->proxy) && $this->proxy['authtype'] == 'ntlm'))
160
+            return 'curl';
161
+        if (($this->scheme == 'http' || $this->scheme == 'ssl') && $this->authtype != 'ntlm' && (!is_array($this->proxy) || $this->proxy['authtype'] != 'ntlm'))
162
+            return 'socket';
163
+        return 'unknown';
164
+    }
165
+
166
+    /**
167
+     * establish an HTTP connection
168
+     *
169
+     * @param    integer $timeout set connection timeout in seconds
170
+     * @param	integer $response_timeout set response timeout in seconds
171
+     * @return	boolean true if connected, false if not
172
+     * @access   private
173
+     */
174
+    function connect($connection_timeout=0,$response_timeout=30){
175
+            // For PHP 4.3 with OpenSSL, change https scheme to ssl, then treat like
176
+            // "regular" socket.
177
+            // TODO: disabled for now because OpenSSL must be *compiled* in (not just
178
+            //       loaded), and until PHP5 stream_get_wrappers is not available.
179 179
 //	  	if ($this->scheme == 'https') {
180 180
 //		  	if (version_compare(phpversion(), '4.3.0') >= 0) {
181 181
 //		  		if (extension_loaded('openssl')) {
@@ -184,1120 +184,1120 @@  discard block
 block discarded – undo
184 184
 //		  		}
185 185
 //		  	}
186 186
 //		}
187
-		$this->debug("connect connection_timeout $connection_timeout, response_timeout $response_timeout, scheme $this->scheme, host $this->host, port $this->port");
188
-	  if ($this->io_method() == 'socket') {
189
-		if (!is_array($this->proxy)) {
190
-			$host = $this->host;
191
-			$port = $this->port;
192
-		} else {
193
-			$host = $this->proxy['host'];
194
-			$port = $this->proxy['port'];
195
-		}
196
-
197
-		// use persistent connection
198
-		if($this->persistentConnection && isset($this->fp) && is_resource($this->fp)){
199
-			if (!feof($this->fp)) {
200
-				$this->debug('Re-use persistent connection');
201
-				return true;
202
-			}
203
-			fclose($this->fp);
204
-			$this->debug('Closed persistent connection at EOF');
205
-		}
206
-
207
-		// munge host if using OpenSSL
208
-		if ($this->scheme == 'ssl') {
209
-			$host = 'ssl://' . $host;
210
-		}
211
-		$this->debug('calling fsockopen with host ' . $host . ' connection_timeout ' . $connection_timeout);
212
-
213
-		// open socket
214
-		if($connection_timeout > 0){
215
-			$this->fp = @fsockopen( $host, $this->port, $this->errno, $this->error_str, $connection_timeout);
216
-		} else {
217
-			$this->fp = @fsockopen( $host, $this->port, $this->errno, $this->error_str);
218
-		}
219
-
220
-		// test pointer
221
-		if(!$this->fp) {
222
-			$msg = 'Couldn\'t open socket connection to server ' . $this->url;
223
-			if ($this->errno) {
224
-				$msg .= ', Error ('.$this->errno.'): '.$this->error_str;
225
-			} else {
226
-				$msg .= ' prior to connect().  This is often a problem looking up the host name.';
227
-			}
228
-			$this->debug($msg);
229
-			$this->setError($msg);
230
-			return false;
231
-		}
232
-
233
-		// set response timeout
234
-		$this->debug('set response timeout to ' . $response_timeout);
235
-		socket_set_timeout( $this->fp, $response_timeout);
236
-
237
-		$this->debug('socket connected');
238
-		return true;
239
-	  } else if ($this->io_method() == 'curl') {
240
-		if (!extension_loaded('curl')) {
187
+        $this->debug("connect connection_timeout $connection_timeout, response_timeout $response_timeout, scheme $this->scheme, host $this->host, port $this->port");
188
+        if ($this->io_method() == 'socket') {
189
+        if (!is_array($this->proxy)) {
190
+            $host = $this->host;
191
+            $port = $this->port;
192
+        } else {
193
+            $host = $this->proxy['host'];
194
+            $port = $this->proxy['port'];
195
+        }
196
+
197
+        // use persistent connection
198
+        if($this->persistentConnection && isset($this->fp) && is_resource($this->fp)){
199
+            if (!feof($this->fp)) {
200
+                $this->debug('Re-use persistent connection');
201
+                return true;
202
+            }
203
+            fclose($this->fp);
204
+            $this->debug('Closed persistent connection at EOF');
205
+        }
206
+
207
+        // munge host if using OpenSSL
208
+        if ($this->scheme == 'ssl') {
209
+            $host = 'ssl://' . $host;
210
+        }
211
+        $this->debug('calling fsockopen with host ' . $host . ' connection_timeout ' . $connection_timeout);
212
+
213
+        // open socket
214
+        if($connection_timeout > 0){
215
+            $this->fp = @fsockopen( $host, $this->port, $this->errno, $this->error_str, $connection_timeout);
216
+        } else {
217
+            $this->fp = @fsockopen( $host, $this->port, $this->errno, $this->error_str);
218
+        }
219
+
220
+        // test pointer
221
+        if(!$this->fp) {
222
+            $msg = 'Couldn\'t open socket connection to server ' . $this->url;
223
+            if ($this->errno) {
224
+                $msg .= ', Error ('.$this->errno.'): '.$this->error_str;
225
+            } else {
226
+                $msg .= ' prior to connect().  This is often a problem looking up the host name.';
227
+            }
228
+            $this->debug($msg);
229
+            $this->setError($msg);
230
+            return false;
231
+        }
232
+
233
+        // set response timeout
234
+        $this->debug('set response timeout to ' . $response_timeout);
235
+        socket_set_timeout( $this->fp, $response_timeout);
236
+
237
+        $this->debug('socket connected');
238
+        return true;
239
+        } else if ($this->io_method() == 'curl') {
240
+        if (!extension_loaded('curl')) {
241 241
 //			$this->setError('cURL Extension, or OpenSSL extension w/ PHP version >= 4.3 is required for HTTPS');
242
-			$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.');
243
-			return false;
244
-		}
245
-		// Avoid warnings when PHP does not have these options
246
-		if (defined('CURLOPT_CONNECTIONTIMEOUT'))
247
-			$CURLOPT_CONNECTIONTIMEOUT = CURLOPT_CONNECTIONTIMEOUT;
248
-		else
249
-			$CURLOPT_CONNECTIONTIMEOUT = 78;
250
-		if (defined('CURLOPT_HTTPAUTH'))
251
-			$CURLOPT_HTTPAUTH = CURLOPT_HTTPAUTH;
252
-		else
253
-			$CURLOPT_HTTPAUTH = 107;
254
-		if (defined('CURLOPT_PROXYAUTH'))
255
-			$CURLOPT_PROXYAUTH = CURLOPT_PROXYAUTH;
256
-		else
257
-			$CURLOPT_PROXYAUTH = 111;
258
-		if (defined('CURLAUTH_BASIC'))
259
-			$CURLAUTH_BASIC = CURLAUTH_BASIC;
260
-		else
261
-			$CURLAUTH_BASIC = 1;
262
-		if (defined('CURLAUTH_DIGEST'))
263
-			$CURLAUTH_DIGEST = CURLAUTH_DIGEST;
264
-		else
265
-			$CURLAUTH_DIGEST = 2;
266
-		if (defined('CURLAUTH_NTLM'))
267
-			$CURLAUTH_NTLM = CURLAUTH_NTLM;
268
-		else
269
-			$CURLAUTH_NTLM = 8;
270
-
271
-		$this->debug('connect using cURL');
272
-		// init CURL
273
-		$this->ch = curl_init();
274
-		// set url
275
-		$hostURL = ($this->port != '') ? "$this->scheme://$this->host:$this->port" : "$this->scheme://$this->host";
276
-		// add path
277
-		$hostURL .= $this->path;
278
-		$this->setCurlOption(CURLOPT_URL, $hostURL);
279
-		// follow location headers (re-directs)
280
-		if (ini_get('safe_mode') || ini_get('open_basedir')) {
281
-			$this->debug('safe_mode or open_basedir set, so do not set CURLOPT_FOLLOWLOCATION');
282
-			$this->debug('safe_mode = ');
283
-			$this->appendDebug($this->varDump(ini_get('safe_mode')));
284
-			$this->debug('open_basedir = ');
285
-			$this->appendDebug($this->varDump(ini_get('open_basedir')));
286
-		} else {
287
-			$this->setCurlOption(CURLOPT_FOLLOWLOCATION, 1);
288
-		}
289
-		// ask for headers in the response output
290
-		$this->setCurlOption(CURLOPT_HEADER, 1);
291
-		// ask for the response output as the return value
292
-		$this->setCurlOption(CURLOPT_RETURNTRANSFER, 1);
293
-		// encode
294
-		// We manage this ourselves through headers and encoding
242
+            $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.');
243
+            return false;
244
+        }
245
+        // Avoid warnings when PHP does not have these options
246
+        if (defined('CURLOPT_CONNECTIONTIMEOUT'))
247
+            $CURLOPT_CONNECTIONTIMEOUT = CURLOPT_CONNECTIONTIMEOUT;
248
+        else
249
+            $CURLOPT_CONNECTIONTIMEOUT = 78;
250
+        if (defined('CURLOPT_HTTPAUTH'))
251
+            $CURLOPT_HTTPAUTH = CURLOPT_HTTPAUTH;
252
+        else
253
+            $CURLOPT_HTTPAUTH = 107;
254
+        if (defined('CURLOPT_PROXYAUTH'))
255
+            $CURLOPT_PROXYAUTH = CURLOPT_PROXYAUTH;
256
+        else
257
+            $CURLOPT_PROXYAUTH = 111;
258
+        if (defined('CURLAUTH_BASIC'))
259
+            $CURLAUTH_BASIC = CURLAUTH_BASIC;
260
+        else
261
+            $CURLAUTH_BASIC = 1;
262
+        if (defined('CURLAUTH_DIGEST'))
263
+            $CURLAUTH_DIGEST = CURLAUTH_DIGEST;
264
+        else
265
+            $CURLAUTH_DIGEST = 2;
266
+        if (defined('CURLAUTH_NTLM'))
267
+            $CURLAUTH_NTLM = CURLAUTH_NTLM;
268
+        else
269
+            $CURLAUTH_NTLM = 8;
270
+
271
+        $this->debug('connect using cURL');
272
+        // init CURL
273
+        $this->ch = curl_init();
274
+        // set url
275
+        $hostURL = ($this->port != '') ? "$this->scheme://$this->host:$this->port" : "$this->scheme://$this->host";
276
+        // add path
277
+        $hostURL .= $this->path;
278
+        $this->setCurlOption(CURLOPT_URL, $hostURL);
279
+        // follow location headers (re-directs)
280
+        if (ini_get('safe_mode') || ini_get('open_basedir')) {
281
+            $this->debug('safe_mode or open_basedir set, so do not set CURLOPT_FOLLOWLOCATION');
282
+            $this->debug('safe_mode = ');
283
+            $this->appendDebug($this->varDump(ini_get('safe_mode')));
284
+            $this->debug('open_basedir = ');
285
+            $this->appendDebug($this->varDump(ini_get('open_basedir')));
286
+        } else {
287
+            $this->setCurlOption(CURLOPT_FOLLOWLOCATION, 1);
288
+        }
289
+        // ask for headers in the response output
290
+        $this->setCurlOption(CURLOPT_HEADER, 1);
291
+        // ask for the response output as the return value
292
+        $this->setCurlOption(CURLOPT_RETURNTRANSFER, 1);
293
+        // encode
294
+        // We manage this ourselves through headers and encoding
295 295
 //		if(function_exists('gzuncompress')){
296 296
 //			$this->setCurlOption(CURLOPT_ENCODING, 'deflate');
297 297
 //		}
298
-		// persistent connection
299
-		if ($this->persistentConnection) {
300
-			// I believe the following comment is now bogus, having applied to
301
-			// the code when it used CURLOPT_CUSTOMREQUEST to send the request.
302
-			// The way we send data, we cannot use persistent connections, since
303
-			// there will be some "junk" at the end of our request.
304
-			//$this->setCurlOption(CURL_HTTP_VERSION_1_1, true);
305
-			$this->persistentConnection = false;
306
-			$this->setHeader('Connection', 'close');
307
-		}
308
-		// set timeouts
309
-		if ($connection_timeout != 0) {
310
-			$this->setCurlOption($CURLOPT_CONNECTIONTIMEOUT, $connection_timeout);
311
-		}
312
-		if ($response_timeout != 0) {
313
-			$this->setCurlOption(CURLOPT_TIMEOUT, $response_timeout);
314
-		}
315
-
316
-		if ($this->scheme == 'https') {
317
-			$this->debug('set cURL SSL verify options');
318
-			// recent versions of cURL turn on peer/host checking by default,
319
-			// while PHP binaries are not compiled with a default location for the
320
-			// CA cert bundle, so disable peer/host checking.
321
-			//$this->setCurlOption(CURLOPT_CAINFO, 'f:\php-4.3.2-win32\extensions\curl-ca-bundle.crt');
322
-			$this->setCurlOption(CURLOPT_SSL_VERIFYPEER, 0);
323
-			$this->setCurlOption(CURLOPT_SSL_VERIFYHOST, 0);
324
-
325
-			// support client certificates (thanks Tobias Boes, Doug Anarino, Eryan Ariobowo)
326
-			if ($this->authtype == 'certificate') {
327
-				$this->debug('set cURL certificate options');
328
-				if (isset($this->certRequest['cainfofile'])) {
329
-					$this->setCurlOption(CURLOPT_CAINFO, $this->certRequest['cainfofile']);
330
-				}
331
-				if (isset($this->certRequest['verifypeer'])) {
332
-					$this->setCurlOption(CURLOPT_SSL_VERIFYPEER, $this->certRequest['verifypeer']);
333
-				} else {
334
-					$this->setCurlOption(CURLOPT_SSL_VERIFYPEER, 1);
335
-				}
336
-				if (isset($this->certRequest['verifyhost'])) {
337
-					$this->setCurlOption(CURLOPT_SSL_VERIFYHOST, $this->certRequest['verifyhost']);
338
-				} else {
339
-					$this->setCurlOption(CURLOPT_SSL_VERIFYHOST, 1);
340
-				}
341
-				if (isset($this->certRequest['sslcertfile'])) {
342
-					$this->setCurlOption(CURLOPT_SSLCERT, $this->certRequest['sslcertfile']);
343
-				}
344
-				if (isset($this->certRequest['sslkeyfile'])) {
345
-					$this->setCurlOption(CURLOPT_SSLKEY, $this->certRequest['sslkeyfile']);
346
-				}
347
-				if (isset($this->certRequest['passphrase'])) {
348
-					$this->setCurlOption(CURLOPT_SSLKEYPASSWD, $this->certRequest['passphrase']);
349
-				}
350
-				if (isset($this->certRequest['certpassword'])) {
351
-					$this->setCurlOption(CURLOPT_SSLCERTPASSWD, $this->certRequest['certpassword']);
352
-				}
353
-			}
354
-		}
355
-		if ($this->authtype && ($this->authtype != 'certificate')) {
356
-			if ($this->username) {
357
-				$this->debug('set cURL username/password');
358
-				$this->setCurlOption(CURLOPT_USERPWD, "$this->username:$this->password");
359
-			}
360
-			if ($this->authtype == 'basic') {
361
-				$this->debug('set cURL for Basic authentication');
362
-				$this->setCurlOption($CURLOPT_HTTPAUTH, $CURLAUTH_BASIC);
363
-			}
364
-			if ($this->authtype == 'digest') {
365
-				$this->debug('set cURL for digest authentication');
366
-				$this->setCurlOption($CURLOPT_HTTPAUTH, $CURLAUTH_DIGEST);
367
-			}
368
-			if ($this->authtype == 'ntlm') {
369
-				$this->debug('set cURL for NTLM authentication');
370
-				$this->setCurlOption($CURLOPT_HTTPAUTH, $CURLAUTH_NTLM);
371
-			}
372
-		}
373
-		if (is_array($this->proxy)) {
374
-			$this->debug('set cURL proxy options');
375
-			if ($this->proxy['port'] != '') {
376
-				$this->setCurlOption(CURLOPT_PROXY, $this->proxy['host'].':'.$this->proxy['port']);
377
-			} else {
378
-				$this->setCurlOption(CURLOPT_PROXY, $this->proxy['host']);
379
-			}
380
-			if ($this->proxy['username'] || $this->proxy['password']) {
381
-				$this->debug('set cURL proxy authentication options');
382
-				$this->setCurlOption(CURLOPT_PROXYUSERPWD, $this->proxy['username'].':'.$this->proxy['password']);
383
-				if ($this->proxy['authtype'] == 'basic') {
384
-					$this->setCurlOption($CURLOPT_PROXYAUTH, $CURLAUTH_BASIC);
385
-				}
386
-				if ($this->proxy['authtype'] == 'ntlm') {
387
-					$this->setCurlOption($CURLOPT_PROXYAUTH, $CURLAUTH_NTLM);
388
-				}
389
-			}
390
-		}
391
-		$this->debug('cURL connection set up');
392
-		return true;
393
-	  } else {
394
-		$this->setError('Unknown scheme ' . $this->scheme);
395
-		$this->debug('Unknown scheme ' . $this->scheme);
396
-		return false;
397
-	  }
398
-	}
399
-
400
-	/**
401
-	* sends the SOAP request and gets the SOAP response via HTTP[S]
402
-	*
403
-	* @param    string $data message data
404
-	* @param    integer $timeout set connection timeout in seconds
405
-	* @param	integer $response_timeout set response timeout in seconds
406
-	* @param	array $cookies cookies to send
407
-	* @return	string data
408
-	* @access   public
409
-	*/
410
-	function send($data, $timeout=0, $response_timeout=30, $cookies=NULL) {
411
-
412
-		$this->debug('entered send() with data of length: '.strlen($data));
413
-
414
-		$this->tryagain = true;
415
-		$tries = 0;
416
-		while ($this->tryagain) {
417
-			$this->tryagain = false;
418
-			if ($tries++ < 2) {
419
-				// make connnection
420
-				if (!$this->connect($timeout, $response_timeout)){
421
-					return false;
422
-				}
423
-
424
-				// send request
425
-				if (!$this->sendRequest($data, $cookies)){
426
-					return false;
427
-				}
428
-
429
-				// get response
430
-				$respdata = $this->getResponse();
431
-			} else {
432
-				$this->setError("Too many tries to get an OK response ($this->response_status_line)");
433
-			}
434
-		}
435
-		$this->debug('end of send()');
436
-		return $respdata;
437
-	}
438
-
439
-
440
-	/**
441
-	* sends the SOAP request and gets the SOAP response via HTTPS using CURL
442
-	*
443
-	* @param    string $data message data
444
-	* @param    integer $timeout set connection timeout in seconds
445
-	* @param	integer $response_timeout set response timeout in seconds
446
-	* @param	array $cookies cookies to send
447
-	* @return	string data
448
-	* @access   public
449
-	* @deprecated
450
-	*/
451
-	function sendHTTPS($data, $timeout=0, $response_timeout=30, $cookies) {
452
-		return $this->send($data, $timeout, $response_timeout, $cookies);
453
-	}
454
-
455
-	/**
456
-	* if authenticating, set user credentials here
457
-	*
458
-	* @param    string $username
459
-	* @param    string $password
460
-	* @param	string $authtype (basic|digest|certificate|ntlm)
461
-	* @param	array $digestRequest (keys must be nonce, nc, realm, qop)
462
-	* @param	array $certRequest (keys must be cainfofile (optional), sslcertfile, sslkeyfile, passphrase, certpassword (optional), verifypeer (optional), verifyhost (optional): see corresponding options in cURL docs)
463
-	* @access   public
464
-	*/
465
-	function setCredentials($username, $password, $authtype = 'basic', $digestRequest = array(), $certRequest = array()) {
466
-		$this->debug("setCredentials username=$username authtype=$authtype digestRequest=");
467
-		$this->appendDebug($this->varDump($digestRequest));
468
-		$this->debug("certRequest=");
469
-		$this->appendDebug($this->varDump($certRequest));
470
-		// cf. RFC 2617
471
-		if ($authtype == 'basic') {
472
-			$this->setHeader('Authorization', 'Basic '.base64_encode(str_replace(':','',$username).':'.$password));
473
-		} elseif ($authtype == 'digest') {
474
-			if (isset($digestRequest['nonce'])) {
475
-				$digestRequest['nc'] = isset($digestRequest['nc']) ? $digestRequest['nc']++ : 1;
476
-
477
-				// calculate the Digest hashes (calculate code based on digest implementation found at: http://www.rassoc.com/gregr/weblog/stories/2002/07/09/webServicesSecurityHttpDigestAuthenticationWithoutActiveDirectory.html)
478
-
479
-				// A1 = unq(username-value) ":" unq(realm-value) ":" passwd
480
-				$A1 = $username. ':' . (isset($digestRequest['realm']) ? $digestRequest['realm'] : '') . ':' . $password;
481
-
482
-				// H(A1) = MD5(A1)
483
-				$HA1 = md5($A1);
484
-
485
-				// A2 = Method ":" digest-uri-value
486
-				$A2 = $this->request_method . ':' . $this->digest_uri;
487
-
488
-				// H(A2)
489
-				$HA2 =  md5($A2);
490
-
491
-				// KD(secret, data) = H(concat(secret, ":", data))
492
-				// if qop == auth:
493
-				// request-digest  = <"> < KD ( H(A1),     unq(nonce-value)
494
-				//                              ":" nc-value
495
-				//                              ":" unq(cnonce-value)
496
-				//                              ":" unq(qop-value)
497
-				//                              ":" H(A2)
498
-				//                            ) <">
499
-				// if qop is missing,
500
-				// request-digest  = <"> < KD ( H(A1), unq(nonce-value) ":" H(A2) ) > <">
501
-
502
-				$unhashedDigest = '';
503
-				$nonce = isset($digestRequest['nonce']) ? $digestRequest['nonce'] : '';
504
-				$cnonce = $nonce;
505
-				if ($digestRequest['qop'] != '') {
506
-					$unhashedDigest = $HA1 . ':' . $nonce . ':' . sprintf("%08d", $digestRequest['nc']) . ':' . $cnonce . ':' . $digestRequest['qop'] . ':' . $HA2;
507
-				} else {
508
-					$unhashedDigest = $HA1 . ':' . $nonce . ':' . $HA2;
509
-				}
510
-
511
-				$hashedDigest = md5($unhashedDigest);
512
-
513
-				$opaque = '';
514
-				if (isset($digestRequest['opaque'])) {
515
-					$opaque = ', opaque="' . $digestRequest['opaque'] . '"';
516
-				}
517
-
518
-				$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 . '"');
519
-			}
520
-		} elseif ($authtype == 'certificate') {
521
-			$this->certRequest = $certRequest;
522
-			$this->debug('Authorization header not set for certificate');
523
-		} elseif ($authtype == 'ntlm') {
524
-			// do nothing
525
-			$this->debug('Authorization header not set for ntlm');
526
-		}
527
-		$this->username = $username;
528
-		$this->password = $password;
529
-		$this->authtype = $authtype;
530
-		$this->digestRequest = $digestRequest;
531
-	}
532
-
533
-	/**
534
-	* set the soapaction value
535
-	*
536
-	* @param    string $soapaction
537
-	* @access   public
538
-	*/
539
-	function setSOAPAction($soapaction) {
540
-		$this->setHeader('SOAPAction', '"' . $soapaction . '"');
541
-	}
542
-
543
-	/**
544
-	* use http encoding
545
-	*
546
-	* @param    string $enc encoding style. supported values: gzip, deflate, or both
547
-	* @access   public
548
-	*/
549
-	function setEncoding($enc='gzip, deflate') {
550
-		if (function_exists('gzdeflate')) {
551
-			$this->protocol_version = '1.1';
552
-			$this->setHeader('Accept-Encoding', $enc);
553
-			if (!isset($this->outgoing_headers['Connection'])) {
554
-				$this->setHeader('Connection', 'close');
555
-				$this->persistentConnection = false;
556
-			}
557
-			// deprecated as of PHP 5.3.0
558
-			//set_magic_quotes_runtime(0);
559
-			$this->encoding = $enc;
560
-		}
561
-	}
562
-
563
-	/**
564
-	* set proxy info here
565
-	*
566
-	* @param    string $proxyhost use an empty string to remove proxy
567
-	* @param    string $proxyport
568
-	* @param	string $proxyusername
569
-	* @param	string $proxypassword
570
-	* @param	string $proxyauthtype (basic|ntlm)
571
-	* @access   public
572
-	*/
573
-	function setProxy($proxyhost, $proxyport, $proxyusername = '', $proxypassword = '', $proxyauthtype = 'basic') {
574
-		if ($proxyhost) {
575
-			$this->proxy = array(
576
-				'host' => $proxyhost,
577
-				'port' => $proxyport,
578
-				'username' => $proxyusername,
579
-				'password' => $proxypassword,
580
-				'authtype' => $proxyauthtype
581
-			);
582
-			if ($proxyusername != '' && $proxypassword != '' && $proxyauthtype = 'basic') {
583
-				$this->setHeader('Proxy-Authorization', ' Basic '.base64_encode($proxyusername.':'.$proxypassword));
584
-			}
585
-		} else {
586
-			$this->debug('remove proxy');
587
-			$proxy = null;
588
-			unsetHeader('Proxy-Authorization');
589
-		}
590
-	}
591
-
592
-
593
-	/**
594
-	 * Test if the given string starts with a header that is to be skipped.
595
-	 * Skippable headers result from chunked transfer and proxy requests.
596
-	 *
597
-	 * @param	string $data The string to check.
598
-	 * @returns	boolean	Whether a skippable header was found.
599
-	 * @access	private
600
-	 */
601
-	function isSkippableCurlHeader(&$data) {
602
-		$skipHeaders = array(	'HTTP/1.1 100',
603
-								'HTTP/1.0 301',
604
-								'HTTP/1.1 301',
605
-								'HTTP/1.0 302',
606
-								'HTTP/1.1 302',
607
-								'HTTP/1.0 401',
608
-								'HTTP/1.1 401',
609
-								'HTTP/1.0 200 Connection established');
610
-		foreach ($skipHeaders as $hd) {
611
-			$prefix = substr($data, 0, strlen($hd));
612
-			if ($prefix == $hd) return true;
613
-		}
614
-
615
-		return false;
616
-	}
617
-
618
-	/**
619
-	* decode a string that is encoded w/ "chunked' transfer encoding
620
- 	* as defined in RFC2068 19.4.6
621
-	*
622
-	* @param    string $buffer
623
-	* @param    string $lb
624
-	* @returns	string
625
-	* @access   public
626
-	* @deprecated
627
-	*/
628
-	function decodeChunked($buffer, $lb){
629
-		// length := 0
630
-		$length = 0;
631
-		$new = '';
632
-
633
-		// read chunk-size, chunk-extension (if any) and CRLF
634
-		// get the position of the linebreak
635
-		$chunkend = strpos($buffer, $lb);
636
-		if ($chunkend == FALSE) {
637
-			$this->debug('no linebreak found in decodeChunked');
638
-			return $new;
639
-		}
640
-		$temp = substr($buffer,0,$chunkend);
641
-		$chunk_size = hexdec( trim($temp) );
642
-		$chunkstart = $chunkend + strlen($lb);
643
-		// while (chunk-size > 0) {
644
-		while ($chunk_size > 0) {
645
-			$this->debug("chunkstart: $chunkstart chunk_size: $chunk_size");
646
-			$chunkend = strpos( $buffer, $lb, $chunkstart + $chunk_size);
647
-
648
-			// Just in case we got a broken connection
649
-		  	if ($chunkend == FALSE) {
650
-		  	    $chunk = substr($buffer,$chunkstart);
651
-				// append chunk-data to entity-body
652
-		    	$new .= $chunk;
653
-		  	    $length += strlen($chunk);
654
-		  	    break;
655
-			}
656
-
657
-		  	// read chunk-data and CRLF
658
-		  	$chunk = substr($buffer,$chunkstart,$chunkend-$chunkstart);
659
-		  	// append chunk-data to entity-body
660
-		  	$new .= $chunk;
661
-		  	// length := length + chunk-size
662
-		  	$length += strlen($chunk);
663
-		  	// read chunk-size and CRLF
664
-		  	$chunkstart = $chunkend + strlen($lb);
665
-
666
-		  	$chunkend = strpos($buffer, $lb, $chunkstart) + strlen($lb);
667
-			if ($chunkend == FALSE) {
668
-				break; //Just in case we got a broken connection
669
-			}
670
-			$temp = substr($buffer,$chunkstart,$chunkend-$chunkstart);
671
-			$chunk_size = hexdec( trim($temp) );
672
-			$chunkstart = $chunkend;
673
-		}
674
-		return $new;
675
-	}
676
-
677
-	/**
678
-	 * Writes the payload, including HTTP headers, to $this->outgoing_payload.
679
-	 *
680
-	 * @param	string $data HTTP body
681
-	 * @param	string $cookie_str data for HTTP Cookie header
682
-	 * @return	void
683
-	 * @access	private
684
-	 */
685
-	function buildPayload($data, $cookie_str = '') {
686
-		// Note: for cURL connections, $this->outgoing_payload is ignored,
687
-		// as is the Content-Length header, but these are still created as
688
-		// debugging guides.
689
-
690
-		// add content-length header
691
-		if ($this->request_method != 'GET') {
692
-			$this->setHeader('Content-Length', strlen($data));
693
-		}
694
-
695
-		// start building outgoing payload:
696
-		if ($this->proxy) {
697
-			$uri = $this->url;
698
-		} else {
699
-			$uri = $this->uri;
700
-		}
701
-		$req = "$this->request_method $uri HTTP/$this->protocol_version";
702
-		$this->debug("HTTP request: $req");
703
-		$this->outgoing_payload = "$req\r\n";
704
-
705
-		// loop thru headers, serializing
706
-		foreach($this->outgoing_headers as $k => $v){
707
-			$hdr = $k.': '.$v;
708
-			$this->debug("HTTP header: $hdr");
709
-			$this->outgoing_payload .= "$hdr\r\n";
710
-		}
711
-
712
-		// add any cookies
713
-		if ($cookie_str != '') {
714
-			$hdr = 'Cookie: '.$cookie_str;
715
-			$this->debug("HTTP header: $hdr");
716
-			$this->outgoing_payload .= "$hdr\r\n";
717
-		}
718
-
719
-		// header/body separator
720
-		$this->outgoing_payload .= "\r\n";
721
-
722
-		// add data
723
-		$this->outgoing_payload .= $data;
724
-	}
725
-
726
-	/**
727
-	* sends the SOAP request via HTTP[S]
728
-	*
729
-	* @param    string $data message data
730
-	* @param	array $cookies cookies to send
731
-	* @return	boolean	true if OK, false if problem
732
-	* @access   private
733
-	*/
734
-	function sendRequest($data, $cookies = NULL) {
735
-		// build cookie string
736
-		$cookie_str = $this->getCookiesForRequest($cookies, (($this->scheme == 'ssl') || ($this->scheme == 'https')));
737
-
738
-		// build payload
739
-		$this->buildPayload($data, $cookie_str);
740
-
741
-	  if ($this->io_method() == 'socket') {
742
-		// send payload
743
-		if(!fputs($this->fp, $this->outgoing_payload, strlen($this->outgoing_payload))) {
744
-			$this->setError('couldn\'t write message data to socket');
745
-			$this->debug('couldn\'t write message data to socket');
746
-			return false;
747
-		}
748
-		$this->debug('wrote data to socket, length = ' . strlen($this->outgoing_payload));
749
-		return true;
750
-	  } else if ($this->io_method() == 'curl') {
751
-		// set payload
752
-		// cURL does say this should only be the verb, and in fact it
753
-		// turns out that the URI and HTTP version are appended to this, which
754
-		// some servers refuse to work with (so we no longer use this method!)
755
-		//$this->setCurlOption(CURLOPT_CUSTOMREQUEST, $this->outgoing_payload);
756
-		$curl_headers = array();
757
-		foreach($this->outgoing_headers as $k => $v){
758
-			if ($k == 'Connection' || $k == 'Content-Length' || $k == 'Host' || $k == 'Authorization' || $k == 'Proxy-Authorization') {
759
-				$this->debug("Skip cURL header $k: $v");
760
-			} else {
761
-				$curl_headers[] = "$k: $v";
762
-			}
763
-		}
764
-		if ($cookie_str != '') {
765
-			$curl_headers[] = 'Cookie: ' . $cookie_str;
766
-		}
767
-		$this->setCurlOption(CURLOPT_HTTPHEADER, $curl_headers);
768
-		$this->debug('set cURL HTTP headers');
769
-		if ($this->request_method == "POST") {
770
-	  		$this->setCurlOption(CURLOPT_POST, 1);
771
-	  		$this->setCurlOption(CURLOPT_POSTFIELDS, $data);
772
-			$this->debug('set cURL POST data');
773
-	  	} else {
774
-	  	}
775
-		// insert custom user-set cURL options
776
-		foreach ($this->ch_options as $key => $val) {
777
-			$this->setCurlOption($key, $val);
778
-		}
779
-
780
-		$this->debug('set cURL payload');
781
-		return true;
782
-	  }
783
-	}
784
-
785
-	/**
786
-	* gets the SOAP response via HTTP[S]
787
-	*
788
-	* @return	string the response (also sets member variables like incoming_payload)
789
-	* @access   private
790
-	*/
791
-	function getResponse(){
792
-		$this->incoming_payload = '';
793
-
794
-	  if ($this->io_method() == 'socket') {
795
-	    // loop until headers have been retrieved
796
-	    $data = '';
797
-	    while (!isset($lb)){
798
-
799
-			// We might EOF during header read.
800
-			if(feof($this->fp)) {
801
-				$this->incoming_payload = $data;
802
-				$this->debug('found no headers before EOF after length ' . strlen($data));
803
-				$this->debug("received before EOF:\n" . $data);
804
-				$this->setError('server failed to send headers');
805
-				return false;
806
-			}
807
-
808
-			$tmp = fgets($this->fp, 256);
809
-			$tmplen = strlen($tmp);
810
-			$this->debug("read line of $tmplen bytes: " . trim($tmp));
811
-
812
-			if ($tmplen == 0) {
813
-				$this->incoming_payload = $data;
814
-				$this->debug('socket read of headers timed out after length ' . strlen($data));
815
-				$this->debug("read before timeout: " . $data);
816
-				$this->setError('socket read of headers timed out');
817
-				return false;
818
-			}
819
-
820
-			$data .= $tmp;
821
-			$pos = strpos($data,"\r\n\r\n");
822
-			if($pos > 1){
823
-				$lb = "\r\n";
824
-			} else {
825
-				$pos = strpos($data,"\n\n");
826
-				if($pos > 1){
827
-					$lb = "\n";
828
-				}
829
-			}
830
-			// remove 100 headers
831
-			if (isset($lb) && preg_match('/^HTTP\/1.1 100/',$data)) {
832
-				unset($lb);
833
-				$data = '';
834
-			}//
835
-		}
836
-		// store header data
837
-		$this->incoming_payload .= $data;
838
-		$this->debug('found end of headers after length ' . strlen($data));
839
-		// process headers
840
-		$header_data = trim(substr($data,0,$pos));
841
-		$header_array = explode($lb,$header_data);
842
-		$this->incoming_headers = array();
843
-		$this->incoming_cookies = array();
844
-		foreach($header_array as $header_line){
845
-			$arr = explode(':',$header_line, 2);
846
-			if(count($arr) > 1){
847
-				$header_name = strtolower(trim($arr[0]));
848
-				$this->incoming_headers[$header_name] = trim($arr[1]);
849
-				if ($header_name == 'set-cookie') {
850
-					// TODO: allow multiple cookies from parseCookie
851
-					$cookie = $this->parseCookie(trim($arr[1]));
852
-					if ($cookie) {
853
-						$this->incoming_cookies[] = $cookie;
854
-						$this->debug('found cookie: ' . $cookie['name'] . ' = ' . $cookie['value']);
855
-					} else {
856
-						$this->debug('did not find cookie in ' . trim($arr[1]));
857
-					}
858
-    			}
859
-			} else if (isset($header_name)) {
860
-				// append continuation line to previous header
861
-				$this->incoming_headers[$header_name] .= $lb . ' ' . $header_line;
862
-			}
863
-		}
864
-
865
-		// loop until msg has been received
866
-		if (isset($this->incoming_headers['transfer-encoding']) && strtolower($this->incoming_headers['transfer-encoding']) == 'chunked') {
867
-			$content_length =  2147483647;	// ignore any content-length header
868
-			$chunked = true;
869
-			$this->debug("want to read chunked content");
870
-		} elseif (isset($this->incoming_headers['content-length'])) {
871
-			$content_length = $this->incoming_headers['content-length'];
872
-			$chunked = false;
873
-			$this->debug("want to read content of length $content_length");
874
-		} else {
875
-			$content_length =  2147483647;
876
-			$chunked = false;
877
-			$this->debug("want to read content to EOF");
878
-		}
879
-		$data = '';
880
-		do {
881
-			if ($chunked) {
882
-				$tmp = fgets($this->fp, 256);
883
-				$tmplen = strlen($tmp);
884
-				$this->debug("read chunk line of $tmplen bytes");
885
-				if ($tmplen == 0) {
886
-					$this->incoming_payload = $data;
887
-					$this->debug('socket read of chunk length timed out after length ' . strlen($data));
888
-					$this->debug("read before timeout:\n" . $data);
889
-					$this->setError('socket read of chunk length timed out');
890
-					return false;
891
-				}
892
-				$content_length = hexdec(trim($tmp));
893
-				$this->debug("chunk length $content_length");
894
-			}
895
-			$strlen = 0;
896
-		    while (($strlen < $content_length) && (!feof($this->fp))) {
897
-		    	$readlen = min(8192, $content_length - $strlen);
898
-				$tmp = fread($this->fp, $readlen);
899
-				$tmplen = strlen($tmp);
900
-				$this->debug("read buffer of $tmplen bytes");
901
-				if (($tmplen == 0) && (!feof($this->fp))) {
902
-					$this->incoming_payload = $data;
903
-					$this->debug('socket read of body timed out after length ' . strlen($data));
904
-					$this->debug("read before timeout:\n" . $data);
905
-					$this->setError('socket read of body timed out');
906
-					return false;
907
-				}
908
-				$strlen += $tmplen;
909
-				$data .= $tmp;
910
-			}
911
-			if ($chunked && ($content_length > 0)) {
912
-				$tmp = fgets($this->fp, 256);
913
-				$tmplen = strlen($tmp);
914
-				$this->debug("read chunk terminator of $tmplen bytes");
915
-				if ($tmplen == 0) {
916
-					$this->incoming_payload = $data;
917
-					$this->debug('socket read of chunk terminator timed out after length ' . strlen($data));
918
-					$this->debug("read before timeout:\n" . $data);
919
-					$this->setError('socket read of chunk terminator timed out');
920
-					return false;
921
-				}
922
-			}
923
-		} while ($chunked && ($content_length > 0) && (!feof($this->fp)));
924
-		if (feof($this->fp)) {
925
-			$this->debug('read to EOF');
926
-		}
927
-		$this->debug('read body of length ' . strlen($data));
928
-		$this->incoming_payload .= $data;
929
-		$this->debug('received a total of '.strlen($this->incoming_payload).' bytes of data from server');
930
-
931
-		// close filepointer
932
-		if(
933
-			(isset($this->incoming_headers['connection']) && strtolower($this->incoming_headers['connection']) == 'close') ||
934
-			(! $this->persistentConnection) || feof($this->fp)){
935
-			fclose($this->fp);
936
-			$this->fp = false;
937
-			$this->debug('closed socket');
938
-		}
939
-
940
-		// connection was closed unexpectedly
941
-		if($this->incoming_payload == ''){
942
-			$this->setError('no response from server');
943
-			return false;
944
-		}
945
-
946
-		// decode transfer-encoding
298
+        // persistent connection
299
+        if ($this->persistentConnection) {
300
+            // I believe the following comment is now bogus, having applied to
301
+            // the code when it used CURLOPT_CUSTOMREQUEST to send the request.
302
+            // The way we send data, we cannot use persistent connections, since
303
+            // there will be some "junk" at the end of our request.
304
+            //$this->setCurlOption(CURL_HTTP_VERSION_1_1, true);
305
+            $this->persistentConnection = false;
306
+            $this->setHeader('Connection', 'close');
307
+        }
308
+        // set timeouts
309
+        if ($connection_timeout != 0) {
310
+            $this->setCurlOption($CURLOPT_CONNECTIONTIMEOUT, $connection_timeout);
311
+        }
312
+        if ($response_timeout != 0) {
313
+            $this->setCurlOption(CURLOPT_TIMEOUT, $response_timeout);
314
+        }
315
+
316
+        if ($this->scheme == 'https') {
317
+            $this->debug('set cURL SSL verify options');
318
+            // recent versions of cURL turn on peer/host checking by default,
319
+            // while PHP binaries are not compiled with a default location for the
320
+            // CA cert bundle, so disable peer/host checking.
321
+            //$this->setCurlOption(CURLOPT_CAINFO, 'f:\php-4.3.2-win32\extensions\curl-ca-bundle.crt');
322
+            $this->setCurlOption(CURLOPT_SSL_VERIFYPEER, 0);
323
+            $this->setCurlOption(CURLOPT_SSL_VERIFYHOST, 0);
324
+
325
+            // support client certificates (thanks Tobias Boes, Doug Anarino, Eryan Ariobowo)
326
+            if ($this->authtype == 'certificate') {
327
+                $this->debug('set cURL certificate options');
328
+                if (isset($this->certRequest['cainfofile'])) {
329
+                    $this->setCurlOption(CURLOPT_CAINFO, $this->certRequest['cainfofile']);
330
+                }
331
+                if (isset($this->certRequest['verifypeer'])) {
332
+                    $this->setCurlOption(CURLOPT_SSL_VERIFYPEER, $this->certRequest['verifypeer']);
333
+                } else {
334
+                    $this->setCurlOption(CURLOPT_SSL_VERIFYPEER, 1);
335
+                }
336
+                if (isset($this->certRequest['verifyhost'])) {
337
+                    $this->setCurlOption(CURLOPT_SSL_VERIFYHOST, $this->certRequest['verifyhost']);
338
+                } else {
339
+                    $this->setCurlOption(CURLOPT_SSL_VERIFYHOST, 1);
340
+                }
341
+                if (isset($this->certRequest['sslcertfile'])) {
342
+                    $this->setCurlOption(CURLOPT_SSLCERT, $this->certRequest['sslcertfile']);
343
+                }
344
+                if (isset($this->certRequest['sslkeyfile'])) {
345
+                    $this->setCurlOption(CURLOPT_SSLKEY, $this->certRequest['sslkeyfile']);
346
+                }
347
+                if (isset($this->certRequest['passphrase'])) {
348
+                    $this->setCurlOption(CURLOPT_SSLKEYPASSWD, $this->certRequest['passphrase']);
349
+                }
350
+                if (isset($this->certRequest['certpassword'])) {
351
+                    $this->setCurlOption(CURLOPT_SSLCERTPASSWD, $this->certRequest['certpassword']);
352
+                }
353
+            }
354
+        }
355
+        if ($this->authtype && ($this->authtype != 'certificate')) {
356
+            if ($this->username) {
357
+                $this->debug('set cURL username/password');
358
+                $this->setCurlOption(CURLOPT_USERPWD, "$this->username:$this->password");
359
+            }
360
+            if ($this->authtype == 'basic') {
361
+                $this->debug('set cURL for Basic authentication');
362
+                $this->setCurlOption($CURLOPT_HTTPAUTH, $CURLAUTH_BASIC);
363
+            }
364
+            if ($this->authtype == 'digest') {
365
+                $this->debug('set cURL for digest authentication');
366
+                $this->setCurlOption($CURLOPT_HTTPAUTH, $CURLAUTH_DIGEST);
367
+            }
368
+            if ($this->authtype == 'ntlm') {
369
+                $this->debug('set cURL for NTLM authentication');
370
+                $this->setCurlOption($CURLOPT_HTTPAUTH, $CURLAUTH_NTLM);
371
+            }
372
+        }
373
+        if (is_array($this->proxy)) {
374
+            $this->debug('set cURL proxy options');
375
+            if ($this->proxy['port'] != '') {
376
+                $this->setCurlOption(CURLOPT_PROXY, $this->proxy['host'].':'.$this->proxy['port']);
377
+            } else {
378
+                $this->setCurlOption(CURLOPT_PROXY, $this->proxy['host']);
379
+            }
380
+            if ($this->proxy['username'] || $this->proxy['password']) {
381
+                $this->debug('set cURL proxy authentication options');
382
+                $this->setCurlOption(CURLOPT_PROXYUSERPWD, $this->proxy['username'].':'.$this->proxy['password']);
383
+                if ($this->proxy['authtype'] == 'basic') {
384
+                    $this->setCurlOption($CURLOPT_PROXYAUTH, $CURLAUTH_BASIC);
385
+                }
386
+                if ($this->proxy['authtype'] == 'ntlm') {
387
+                    $this->setCurlOption($CURLOPT_PROXYAUTH, $CURLAUTH_NTLM);
388
+                }
389
+            }
390
+        }
391
+        $this->debug('cURL connection set up');
392
+        return true;
393
+        } else {
394
+        $this->setError('Unknown scheme ' . $this->scheme);
395
+        $this->debug('Unknown scheme ' . $this->scheme);
396
+        return false;
397
+        }
398
+    }
399
+
400
+    /**
401
+     * sends the SOAP request and gets the SOAP response via HTTP[S]
402
+     *
403
+     * @param    string $data message data
404
+     * @param    integer $timeout set connection timeout in seconds
405
+     * @param	integer $response_timeout set response timeout in seconds
406
+     * @param	array $cookies cookies to send
407
+     * @return	string data
408
+     * @access   public
409
+     */
410
+    function send($data, $timeout=0, $response_timeout=30, $cookies=NULL) {
411
+
412
+        $this->debug('entered send() with data of length: '.strlen($data));
413
+
414
+        $this->tryagain = true;
415
+        $tries = 0;
416
+        while ($this->tryagain) {
417
+            $this->tryagain = false;
418
+            if ($tries++ < 2) {
419
+                // make connnection
420
+                if (!$this->connect($timeout, $response_timeout)){
421
+                    return false;
422
+                }
423
+
424
+                // send request
425
+                if (!$this->sendRequest($data, $cookies)){
426
+                    return false;
427
+                }
428
+
429
+                // get response
430
+                $respdata = $this->getResponse();
431
+            } else {
432
+                $this->setError("Too many tries to get an OK response ($this->response_status_line)");
433
+            }
434
+        }
435
+        $this->debug('end of send()');
436
+        return $respdata;
437
+    }
438
+
439
+
440
+    /**
441
+     * sends the SOAP request and gets the SOAP response via HTTPS using CURL
442
+     *
443
+     * @param    string $data message data
444
+     * @param    integer $timeout set connection timeout in seconds
445
+     * @param	integer $response_timeout set response timeout in seconds
446
+     * @param	array $cookies cookies to send
447
+     * @return	string data
448
+     * @access   public
449
+     * @deprecated
450
+     */
451
+    function sendHTTPS($data, $timeout=0, $response_timeout=30, $cookies) {
452
+        return $this->send($data, $timeout, $response_timeout, $cookies);
453
+    }
454
+
455
+    /**
456
+     * if authenticating, set user credentials here
457
+     *
458
+     * @param    string $username
459
+     * @param    string $password
460
+     * @param	string $authtype (basic|digest|certificate|ntlm)
461
+     * @param	array $digestRequest (keys must be nonce, nc, realm, qop)
462
+     * @param	array $certRequest (keys must be cainfofile (optional), sslcertfile, sslkeyfile, passphrase, certpassword (optional), verifypeer (optional), verifyhost (optional): see corresponding options in cURL docs)
463
+     * @access   public
464
+     */
465
+    function setCredentials($username, $password, $authtype = 'basic', $digestRequest = array(), $certRequest = array()) {
466
+        $this->debug("setCredentials username=$username authtype=$authtype digestRequest=");
467
+        $this->appendDebug($this->varDump($digestRequest));
468
+        $this->debug("certRequest=");
469
+        $this->appendDebug($this->varDump($certRequest));
470
+        // cf. RFC 2617
471
+        if ($authtype == 'basic') {
472
+            $this->setHeader('Authorization', 'Basic '.base64_encode(str_replace(':','',$username).':'.$password));
473
+        } elseif ($authtype == 'digest') {
474
+            if (isset($digestRequest['nonce'])) {
475
+                $digestRequest['nc'] = isset($digestRequest['nc']) ? $digestRequest['nc']++ : 1;
476
+
477
+                // calculate the Digest hashes (calculate code based on digest implementation found at: http://www.rassoc.com/gregr/weblog/stories/2002/07/09/webServicesSecurityHttpDigestAuthenticationWithoutActiveDirectory.html)
478
+
479
+                // A1 = unq(username-value) ":" unq(realm-value) ":" passwd
480
+                $A1 = $username. ':' . (isset($digestRequest['realm']) ? $digestRequest['realm'] : '') . ':' . $password;
481
+
482
+                // H(A1) = MD5(A1)
483
+                $HA1 = md5($A1);
484
+
485
+                // A2 = Method ":" digest-uri-value
486
+                $A2 = $this->request_method . ':' . $this->digest_uri;
487
+
488
+                // H(A2)
489
+                $HA2 =  md5($A2);
490
+
491
+                // KD(secret, data) = H(concat(secret, ":", data))
492
+                // if qop == auth:
493
+                // request-digest  = <"> < KD ( H(A1),     unq(nonce-value)
494
+                //                              ":" nc-value
495
+                //                              ":" unq(cnonce-value)
496
+                //                              ":" unq(qop-value)
497
+                //                              ":" H(A2)
498
+                //                            ) <">
499
+                // if qop is missing,
500
+                // request-digest  = <"> < KD ( H(A1), unq(nonce-value) ":" H(A2) ) > <">
501
+
502
+                $unhashedDigest = '';
503
+                $nonce = isset($digestRequest['nonce']) ? $digestRequest['nonce'] : '';
504
+                $cnonce = $nonce;
505
+                if ($digestRequest['qop'] != '') {
506
+                    $unhashedDigest = $HA1 . ':' . $nonce . ':' . sprintf("%08d", $digestRequest['nc']) . ':' . $cnonce . ':' . $digestRequest['qop'] . ':' . $HA2;
507
+                } else {
508
+                    $unhashedDigest = $HA1 . ':' . $nonce . ':' . $HA2;
509
+                }
510
+
511
+                $hashedDigest = md5($unhashedDigest);
512
+
513
+                $opaque = '';
514
+                if (isset($digestRequest['opaque'])) {
515
+                    $opaque = ', opaque="' . $digestRequest['opaque'] . '"';
516
+                }
517
+
518
+                $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 . '"');
519
+            }
520
+        } elseif ($authtype == 'certificate') {
521
+            $this->certRequest = $certRequest;
522
+            $this->debug('Authorization header not set for certificate');
523
+        } elseif ($authtype == 'ntlm') {
524
+            // do nothing
525
+            $this->debug('Authorization header not set for ntlm');
526
+        }
527
+        $this->username = $username;
528
+        $this->password = $password;
529
+        $this->authtype = $authtype;
530
+        $this->digestRequest = $digestRequest;
531
+    }
532
+
533
+    /**
534
+     * set the soapaction value
535
+     *
536
+     * @param    string $soapaction
537
+     * @access   public
538
+     */
539
+    function setSOAPAction($soapaction) {
540
+        $this->setHeader('SOAPAction', '"' . $soapaction . '"');
541
+    }
542
+
543
+    /**
544
+     * use http encoding
545
+     *
546
+     * @param    string $enc encoding style. supported values: gzip, deflate, or both
547
+     * @access   public
548
+     */
549
+    function setEncoding($enc='gzip, deflate') {
550
+        if (function_exists('gzdeflate')) {
551
+            $this->protocol_version = '1.1';
552
+            $this->setHeader('Accept-Encoding', $enc);
553
+            if (!isset($this->outgoing_headers['Connection'])) {
554
+                $this->setHeader('Connection', 'close');
555
+                $this->persistentConnection = false;
556
+            }
557
+            // deprecated as of PHP 5.3.0
558
+            //set_magic_quotes_runtime(0);
559
+            $this->encoding = $enc;
560
+        }
561
+    }
562
+
563
+    /**
564
+     * set proxy info here
565
+     *
566
+     * @param    string $proxyhost use an empty string to remove proxy
567
+     * @param    string $proxyport
568
+     * @param	string $proxyusername
569
+     * @param	string $proxypassword
570
+     * @param	string $proxyauthtype (basic|ntlm)
571
+     * @access   public
572
+     */
573
+    function setProxy($proxyhost, $proxyport, $proxyusername = '', $proxypassword = '', $proxyauthtype = 'basic') {
574
+        if ($proxyhost) {
575
+            $this->proxy = array(
576
+                'host' => $proxyhost,
577
+                'port' => $proxyport,
578
+                'username' => $proxyusername,
579
+                'password' => $proxypassword,
580
+                'authtype' => $proxyauthtype
581
+            );
582
+            if ($proxyusername != '' && $proxypassword != '' && $proxyauthtype = 'basic') {
583
+                $this->setHeader('Proxy-Authorization', ' Basic '.base64_encode($proxyusername.':'.$proxypassword));
584
+            }
585
+        } else {
586
+            $this->debug('remove proxy');
587
+            $proxy = null;
588
+            unsetHeader('Proxy-Authorization');
589
+        }
590
+    }
591
+
592
+
593
+    /**
594
+     * Test if the given string starts with a header that is to be skipped.
595
+     * Skippable headers result from chunked transfer and proxy requests.
596
+     *
597
+     * @param	string $data The string to check.
598
+     * @returns	boolean	Whether a skippable header was found.
599
+     * @access	private
600
+     */
601
+    function isSkippableCurlHeader(&$data) {
602
+        $skipHeaders = array(	'HTTP/1.1 100',
603
+                                'HTTP/1.0 301',
604
+                                'HTTP/1.1 301',
605
+                                'HTTP/1.0 302',
606
+                                'HTTP/1.1 302',
607
+                                'HTTP/1.0 401',
608
+                                'HTTP/1.1 401',
609
+                                'HTTP/1.0 200 Connection established');
610
+        foreach ($skipHeaders as $hd) {
611
+            $prefix = substr($data, 0, strlen($hd));
612
+            if ($prefix == $hd) return true;
613
+        }
614
+
615
+        return false;
616
+    }
617
+
618
+    /**
619
+     * decode a string that is encoded w/ "chunked' transfer encoding
620
+     * as defined in RFC2068 19.4.6
621
+     *
622
+     * @param    string $buffer
623
+     * @param    string $lb
624
+     * @returns	string
625
+     * @access   public
626
+     * @deprecated
627
+     */
628
+    function decodeChunked($buffer, $lb){
629
+        // length := 0
630
+        $length = 0;
631
+        $new = '';
632
+
633
+        // read chunk-size, chunk-extension (if any) and CRLF
634
+        // get the position of the linebreak
635
+        $chunkend = strpos($buffer, $lb);
636
+        if ($chunkend == FALSE) {
637
+            $this->debug('no linebreak found in decodeChunked');
638
+            return $new;
639
+        }
640
+        $temp = substr($buffer,0,$chunkend);
641
+        $chunk_size = hexdec( trim($temp) );
642
+        $chunkstart = $chunkend + strlen($lb);
643
+        // while (chunk-size > 0) {
644
+        while ($chunk_size > 0) {
645
+            $this->debug("chunkstart: $chunkstart chunk_size: $chunk_size");
646
+            $chunkend = strpos( $buffer, $lb, $chunkstart + $chunk_size);
647
+
648
+            // Just in case we got a broken connection
649
+                if ($chunkend == FALSE) {
650
+                    $chunk = substr($buffer,$chunkstart);
651
+                // append chunk-data to entity-body
652
+                $new .= $chunk;
653
+                    $length += strlen($chunk);
654
+                    break;
655
+            }
656
+
657
+                // read chunk-data and CRLF
658
+                $chunk = substr($buffer,$chunkstart,$chunkend-$chunkstart);
659
+                // append chunk-data to entity-body
660
+                $new .= $chunk;
661
+                // length := length + chunk-size
662
+                $length += strlen($chunk);
663
+                // read chunk-size and CRLF
664
+                $chunkstart = $chunkend + strlen($lb);
665
+
666
+                $chunkend = strpos($buffer, $lb, $chunkstart) + strlen($lb);
667
+            if ($chunkend == FALSE) {
668
+                break; //Just in case we got a broken connection
669
+            }
670
+            $temp = substr($buffer,$chunkstart,$chunkend-$chunkstart);
671
+            $chunk_size = hexdec( trim($temp) );
672
+            $chunkstart = $chunkend;
673
+        }
674
+        return $new;
675
+    }
676
+
677
+    /**
678
+     * Writes the payload, including HTTP headers, to $this->outgoing_payload.
679
+     *
680
+     * @param	string $data HTTP body
681
+     * @param	string $cookie_str data for HTTP Cookie header
682
+     * @return	void
683
+     * @access	private
684
+     */
685
+    function buildPayload($data, $cookie_str = '') {
686
+        // Note: for cURL connections, $this->outgoing_payload is ignored,
687
+        // as is the Content-Length header, but these are still created as
688
+        // debugging guides.
689
+
690
+        // add content-length header
691
+        if ($this->request_method != 'GET') {
692
+            $this->setHeader('Content-Length', strlen($data));
693
+        }
694
+
695
+        // start building outgoing payload:
696
+        if ($this->proxy) {
697
+            $uri = $this->url;
698
+        } else {
699
+            $uri = $this->uri;
700
+        }
701
+        $req = "$this->request_method $uri HTTP/$this->protocol_version";
702
+        $this->debug("HTTP request: $req");
703
+        $this->outgoing_payload = "$req\r\n";
704
+
705
+        // loop thru headers, serializing
706
+        foreach($this->outgoing_headers as $k => $v){
707
+            $hdr = $k.': '.$v;
708
+            $this->debug("HTTP header: $hdr");
709
+            $this->outgoing_payload .= "$hdr\r\n";
710
+        }
711
+
712
+        // add any cookies
713
+        if ($cookie_str != '') {
714
+            $hdr = 'Cookie: '.$cookie_str;
715
+            $this->debug("HTTP header: $hdr");
716
+            $this->outgoing_payload .= "$hdr\r\n";
717
+        }
718
+
719
+        // header/body separator
720
+        $this->outgoing_payload .= "\r\n";
721
+
722
+        // add data
723
+        $this->outgoing_payload .= $data;
724
+    }
725
+
726
+    /**
727
+     * sends the SOAP request via HTTP[S]
728
+     *
729
+     * @param    string $data message data
730
+     * @param	array $cookies cookies to send
731
+     * @return	boolean	true if OK, false if problem
732
+     * @access   private
733
+     */
734
+    function sendRequest($data, $cookies = NULL) {
735
+        // build cookie string
736
+        $cookie_str = $this->getCookiesForRequest($cookies, (($this->scheme == 'ssl') || ($this->scheme == 'https')));
737
+
738
+        // build payload
739
+        $this->buildPayload($data, $cookie_str);
740
+
741
+        if ($this->io_method() == 'socket') {
742
+        // send payload
743
+        if(!fputs($this->fp, $this->outgoing_payload, strlen($this->outgoing_payload))) {
744
+            $this->setError('couldn\'t write message data to socket');
745
+            $this->debug('couldn\'t write message data to socket');
746
+            return false;
747
+        }
748
+        $this->debug('wrote data to socket, length = ' . strlen($this->outgoing_payload));
749
+        return true;
750
+        } else if ($this->io_method() == 'curl') {
751
+        // set payload
752
+        // cURL does say this should only be the verb, and in fact it
753
+        // turns out that the URI and HTTP version are appended to this, which
754
+        // some servers refuse to work with (so we no longer use this method!)
755
+        //$this->setCurlOption(CURLOPT_CUSTOMREQUEST, $this->outgoing_payload);
756
+        $curl_headers = array();
757
+        foreach($this->outgoing_headers as $k => $v){
758
+            if ($k == 'Connection' || $k == 'Content-Length' || $k == 'Host' || $k == 'Authorization' || $k == 'Proxy-Authorization') {
759
+                $this->debug("Skip cURL header $k: $v");
760
+            } else {
761
+                $curl_headers[] = "$k: $v";
762
+            }
763
+        }
764
+        if ($cookie_str != '') {
765
+            $curl_headers[] = 'Cookie: ' . $cookie_str;
766
+        }
767
+        $this->setCurlOption(CURLOPT_HTTPHEADER, $curl_headers);
768
+        $this->debug('set cURL HTTP headers');
769
+        if ($this->request_method == "POST") {
770
+                $this->setCurlOption(CURLOPT_POST, 1);
771
+                $this->setCurlOption(CURLOPT_POSTFIELDS, $data);
772
+            $this->debug('set cURL POST data');
773
+            } else {
774
+            }
775
+        // insert custom user-set cURL options
776
+        foreach ($this->ch_options as $key => $val) {
777
+            $this->setCurlOption($key, $val);
778
+        }
779
+
780
+        $this->debug('set cURL payload');
781
+        return true;
782
+        }
783
+    }
784
+
785
+    /**
786
+     * gets the SOAP response via HTTP[S]
787
+     *
788
+     * @return	string the response (also sets member variables like incoming_payload)
789
+     * @access   private
790
+     */
791
+    function getResponse(){
792
+        $this->incoming_payload = '';
793
+
794
+        if ($this->io_method() == 'socket') {
795
+        // loop until headers have been retrieved
796
+        $data = '';
797
+        while (!isset($lb)){
798
+
799
+            // We might EOF during header read.
800
+            if(feof($this->fp)) {
801
+                $this->incoming_payload = $data;
802
+                $this->debug('found no headers before EOF after length ' . strlen($data));
803
+                $this->debug("received before EOF:\n" . $data);
804
+                $this->setError('server failed to send headers');
805
+                return false;
806
+            }
807
+
808
+            $tmp = fgets($this->fp, 256);
809
+            $tmplen = strlen($tmp);
810
+            $this->debug("read line of $tmplen bytes: " . trim($tmp));
811
+
812
+            if ($tmplen == 0) {
813
+                $this->incoming_payload = $data;
814
+                $this->debug('socket read of headers timed out after length ' . strlen($data));
815
+                $this->debug("read before timeout: " . $data);
816
+                $this->setError('socket read of headers timed out');
817
+                return false;
818
+            }
819
+
820
+            $data .= $tmp;
821
+            $pos = strpos($data,"\r\n\r\n");
822
+            if($pos > 1){
823
+                $lb = "\r\n";
824
+            } else {
825
+                $pos = strpos($data,"\n\n");
826
+                if($pos > 1){
827
+                    $lb = "\n";
828
+                }
829
+            }
830
+            // remove 100 headers
831
+            if (isset($lb) && preg_match('/^HTTP\/1.1 100/',$data)) {
832
+                unset($lb);
833
+                $data = '';
834
+            }//
835
+        }
836
+        // store header data
837
+        $this->incoming_payload .= $data;
838
+        $this->debug('found end of headers after length ' . strlen($data));
839
+        // process headers
840
+        $header_data = trim(substr($data,0,$pos));
841
+        $header_array = explode($lb,$header_data);
842
+        $this->incoming_headers = array();
843
+        $this->incoming_cookies = array();
844
+        foreach($header_array as $header_line){
845
+            $arr = explode(':',$header_line, 2);
846
+            if(count($arr) > 1){
847
+                $header_name = strtolower(trim($arr[0]));
848
+                $this->incoming_headers[$header_name] = trim($arr[1]);
849
+                if ($header_name == 'set-cookie') {
850
+                    // TODO: allow multiple cookies from parseCookie
851
+                    $cookie = $this->parseCookie(trim($arr[1]));
852
+                    if ($cookie) {
853
+                        $this->incoming_cookies[] = $cookie;
854
+                        $this->debug('found cookie: ' . $cookie['name'] . ' = ' . $cookie['value']);
855
+                    } else {
856
+                        $this->debug('did not find cookie in ' . trim($arr[1]));
857
+                    }
858
+                }
859
+            } else if (isset($header_name)) {
860
+                // append continuation line to previous header
861
+                $this->incoming_headers[$header_name] .= $lb . ' ' . $header_line;
862
+            }
863
+        }
864
+
865
+        // loop until msg has been received
866
+        if (isset($this->incoming_headers['transfer-encoding']) && strtolower($this->incoming_headers['transfer-encoding']) == 'chunked') {
867
+            $content_length =  2147483647;	// ignore any content-length header
868
+            $chunked = true;
869
+            $this->debug("want to read chunked content");
870
+        } elseif (isset($this->incoming_headers['content-length'])) {
871
+            $content_length = $this->incoming_headers['content-length'];
872
+            $chunked = false;
873
+            $this->debug("want to read content of length $content_length");
874
+        } else {
875
+            $content_length =  2147483647;
876
+            $chunked = false;
877
+            $this->debug("want to read content to EOF");
878
+        }
879
+        $data = '';
880
+        do {
881
+            if ($chunked) {
882
+                $tmp = fgets($this->fp, 256);
883
+                $tmplen = strlen($tmp);
884
+                $this->debug("read chunk line of $tmplen bytes");
885
+                if ($tmplen == 0) {
886
+                    $this->incoming_payload = $data;
887
+                    $this->debug('socket read of chunk length timed out after length ' . strlen($data));
888
+                    $this->debug("read before timeout:\n" . $data);
889
+                    $this->setError('socket read of chunk length timed out');
890
+                    return false;
891
+                }
892
+                $content_length = hexdec(trim($tmp));
893
+                $this->debug("chunk length $content_length");
894
+            }
895
+            $strlen = 0;
896
+            while (($strlen < $content_length) && (!feof($this->fp))) {
897
+                $readlen = min(8192, $content_length - $strlen);
898
+                $tmp = fread($this->fp, $readlen);
899
+                $tmplen = strlen($tmp);
900
+                $this->debug("read buffer of $tmplen bytes");
901
+                if (($tmplen == 0) && (!feof($this->fp))) {
902
+                    $this->incoming_payload = $data;
903
+                    $this->debug('socket read of body timed out after length ' . strlen($data));
904
+                    $this->debug("read before timeout:\n" . $data);
905
+                    $this->setError('socket read of body timed out');
906
+                    return false;
907
+                }
908
+                $strlen += $tmplen;
909
+                $data .= $tmp;
910
+            }
911
+            if ($chunked && ($content_length > 0)) {
912
+                $tmp = fgets($this->fp, 256);
913
+                $tmplen = strlen($tmp);
914
+                $this->debug("read chunk terminator of $tmplen bytes");
915
+                if ($tmplen == 0) {
916
+                    $this->incoming_payload = $data;
917
+                    $this->debug('socket read of chunk terminator timed out after length ' . strlen($data));
918
+                    $this->debug("read before timeout:\n" . $data);
919
+                    $this->setError('socket read of chunk terminator timed out');
920
+                    return false;
921
+                }
922
+            }
923
+        } while ($chunked && ($content_length > 0) && (!feof($this->fp)));
924
+        if (feof($this->fp)) {
925
+            $this->debug('read to EOF');
926
+        }
927
+        $this->debug('read body of length ' . strlen($data));
928
+        $this->incoming_payload .= $data;
929
+        $this->debug('received a total of '.strlen($this->incoming_payload).' bytes of data from server');
930
+
931
+        // close filepointer
932
+        if(
933
+            (isset($this->incoming_headers['connection']) && strtolower($this->incoming_headers['connection']) == 'close') ||
934
+            (! $this->persistentConnection) || feof($this->fp)){
935
+            fclose($this->fp);
936
+            $this->fp = false;
937
+            $this->debug('closed socket');
938
+        }
939
+
940
+        // connection was closed unexpectedly
941
+        if($this->incoming_payload == ''){
942
+            $this->setError('no response from server');
943
+            return false;
944
+        }
945
+
946
+        // decode transfer-encoding
947 947
 //		if(isset($this->incoming_headers['transfer-encoding']) && strtolower($this->incoming_headers['transfer-encoding']) == 'chunked'){
948 948
 //			if(!$data = $this->decodeChunked($data, $lb)){
949 949
 //				$this->setError('Decoding of chunked data failed');
950 950
 //				return false;
951 951
 //			}
952
-			//print "<pre>\nde-chunked:\n---------------\n$data\n\n---------------\n</pre>";
953
-			// set decoded payload
952
+            //print "<pre>\nde-chunked:\n---------------\n$data\n\n---------------\n</pre>";
953
+            // set decoded payload
954 954
 //			$this->incoming_payload = $header_data.$lb.$lb.$data;
955 955
 //		}
956 956
 
957
-	  } else if ($this->io_method() == 'curl') {
958
-		// send and receive
959
-		$this->debug('send and receive with cURL');
960
-		$this->incoming_payload = curl_exec($this->ch);
961
-		$data = $this->incoming_payload;
957
+        } else if ($this->io_method() == 'curl') {
958
+        // send and receive
959
+        $this->debug('send and receive with cURL');
960
+        $this->incoming_payload = curl_exec($this->ch);
961
+        $data = $this->incoming_payload;
962 962
 
963 963
         $cErr = curl_error($this->ch);
964
-		if ($cErr != '') {
965
-        	$err = 'cURL ERROR: '.curl_errno($this->ch).': '.$cErr.'<br>';
966
-        	// TODO: there is a PHP bug that can cause this to SEGV for CURLINFO_CONTENT_TYPE
967
-			foreach(curl_getinfo($this->ch) as $k => $v){
968
-				$err .= "$k: $v<br>";
969
-			}
970
-			$this->debug($err);
971
-			$this->setError($err);
972
-			curl_close($this->ch);
973
-	    	return false;
974
-		} else {
975
-			//echo '<pre>';
976
-			//var_dump(curl_getinfo($this->ch));
977
-			//echo '</pre>';
978
-		}
979
-		// close curl
980
-		$this->debug('No cURL error, closing cURL');
981
-		curl_close($this->ch);
982
-
983
-		// try removing skippable headers
984
-		$savedata = $data;
985
-		while ($this->isSkippableCurlHeader($data)) {
986
-			$this->debug("Found HTTP header to skip");
987
-			if ($pos = strpos($data,"\r\n\r\n")) {
988
-				$data = ltrim(substr($data,$pos));
989
-			} elseif($pos = strpos($data,"\n\n") ) {
990
-				$data = ltrim(substr($data,$pos));
991
-			}
992
-		}
993
-
994
-		if ($data == '') {
995
-			// have nothing left; just remove 100 header(s)
996
-			$data = $savedata;
997
-			while (preg_match('/^HTTP\/1.1 100/',$data)) {
998
-				if ($pos = strpos($data,"\r\n\r\n")) {
999
-					$data = ltrim(substr($data,$pos));
1000
-				} elseif($pos = strpos($data,"\n\n") ) {
1001
-					$data = ltrim(substr($data,$pos));
1002
-				}
1003
-			}
1004
-		}
1005
-
1006
-		// separate content from HTTP headers
1007
-		if ($pos = strpos($data,"\r\n\r\n")) {
1008
-			$lb = "\r\n";
1009
-		} elseif( $pos = strpos($data,"\n\n")) {
1010
-			$lb = "\n";
1011
-		} else {
1012
-			$this->debug('no proper separation of headers and document');
1013
-			$this->setError('no proper separation of headers and document');
1014
-			return false;
1015
-		}
1016
-		$header_data = trim(substr($data,0,$pos));
1017
-		$header_array = explode($lb,$header_data);
1018
-		$data = ltrim(substr($data,$pos));
1019
-		$this->debug('found proper separation of headers and document');
1020
-		$this->debug('cleaned data, stringlen: '.strlen($data));
1021
-		// clean headers
1022
-		foreach ($header_array as $header_line) {
1023
-			$arr = explode(':',$header_line,2);
1024
-			if(count($arr) > 1){
1025
-				$header_name = strtolower(trim($arr[0]));
1026
-				$this->incoming_headers[$header_name] = trim($arr[1]);
1027
-				if ($header_name == 'set-cookie') {
1028
-					// TODO: allow multiple cookies from parseCookie
1029
-					$cookie = $this->parseCookie(trim($arr[1]));
1030
-					if ($cookie) {
1031
-						$this->incoming_cookies[] = $cookie;
1032
-						$this->debug('found cookie: ' . $cookie['name'] . ' = ' . $cookie['value']);
1033
-					} else {
1034
-						$this->debug('did not find cookie in ' . trim($arr[1]));
1035
-					}
1036
-    			}
1037
-			} else if (isset($header_name)) {
1038
-				// append continuation line to previous header
1039
-				$this->incoming_headers[$header_name] .= $lb . ' ' . $header_line;
1040
-			}
1041
-		}
1042
-	  }
1043
-
1044
-		$this->response_status_line = $header_array[0];
1045
-		$arr = explode(' ', $this->response_status_line, 3);
1046
-		$http_version = $arr[0];
1047
-		$http_status = intval($arr[1]);
1048
-		$http_reason = count($arr) > 2 ? $arr[2] : '';
1049
-
1050
- 		// see if we need to resend the request with http digest authentication
1051
- 		if (isset($this->incoming_headers['location']) && ($http_status == 301 || $http_status == 302)) {
1052
- 			$this->debug("Got $http_status $http_reason with Location: " . $this->incoming_headers['location']);
1053
- 			$this->setURL($this->incoming_headers['location']);
1054
-			$this->tryagain = true;
1055
-			return false;
1056
-		}
1057
-
1058
- 		// see if we need to resend the request with http digest authentication
1059
- 		if (isset($this->incoming_headers['www-authenticate']) && $http_status == 401) {
1060
- 			$this->debug("Got 401 $http_reason with WWW-Authenticate: " . $this->incoming_headers['www-authenticate']);
1061
- 			if (strstr($this->incoming_headers['www-authenticate'], "Digest ")) {
1062
- 				$this->debug('Server wants digest authentication');
1063
- 				// remove "Digest " from our elements
1064
- 				$digestString = str_replace('Digest ', '', $this->incoming_headers['www-authenticate']);
1065
-
1066
- 				// parse elements into array
1067
- 				$digestElements = explode(',', $digestString);
1068
- 				foreach ($digestElements as $val) {
1069
- 					$tempElement = explode('=', trim($val), 2);
1070
- 					$digestRequest[$tempElement[0]] = str_replace("\"", '', $tempElement[1]);
1071
- 				}
1072
-
1073
-				// should have (at least) qop, realm, nonce
1074
- 				if (isset($digestRequest['nonce'])) {
1075
- 					$this->setCredentials($this->username, $this->password, 'digest', $digestRequest);
1076
- 					$this->tryagain = true;
1077
- 					return false;
1078
- 				}
1079
- 			}
1080
-			$this->debug('HTTP authentication failed');
1081
-			$this->setError('HTTP authentication failed');
1082
-			return false;
1083
- 		}
1084
-
1085
-		if (
1086
-			($http_status >= 300 && $http_status <= 307) ||
1087
-			($http_status >= 400 && $http_status <= 417) ||
1088
-			($http_status >= 501 && $http_status <= 505)
1089
-		   ) {
1090
-			$this->setError("Unsupported HTTP response status $http_status $http_reason (soapclient->response has contents of the response)");
1091
-			return false;
1092
-		}
1093
-
1094
-		// decode content-encoding
1095
-		if(isset($this->incoming_headers['content-encoding']) && $this->incoming_headers['content-encoding'] != ''){
1096
-			if(strtolower($this->incoming_headers['content-encoding']) == 'deflate' || strtolower($this->incoming_headers['content-encoding']) == 'gzip'){
1097
-    			// if decoding works, use it. else assume data wasn't gzencoded
1098
-    			if(function_exists('gzinflate')){
1099
-					//$timer->setMarker('starting decoding of gzip/deflated content');
1100
-					// IIS 5 requires gzinflate instead of gzuncompress (similar to IE 5 and gzdeflate v. gzcompress)
1101
-					// this means there are no Zlib headers, although there should be
1102
-					$this->debug('The gzinflate function exists');
1103
-					$datalen = strlen($data);
1104
-					if ($this->incoming_headers['content-encoding'] == 'deflate') {
1105
-						if ($degzdata = @gzinflate($data)) {
1106
-	    					$data = $degzdata;
1107
-	    					$this->debug('The payload has been inflated to ' . strlen($data) . ' bytes');
1108
-	    					if (strlen($data) < $datalen) {
1109
-	    						// test for the case that the payload has been compressed twice
1110
-		    					$this->debug('The inflated payload is smaller than the gzipped one; try again');
1111
-								if ($degzdata = @gzinflate($data)) {
1112
-			    					$data = $degzdata;
1113
-			    					$this->debug('The payload has been inflated again to ' . strlen($data) . ' bytes');
1114
-								}
1115
-	    					}
1116
-	    				} else {
1117
-	    					$this->debug('Error using gzinflate to inflate the payload');
1118
-	    					$this->setError('Error using gzinflate to inflate the payload');
1119
-	    				}
1120
-					} elseif ($this->incoming_headers['content-encoding'] == 'gzip') {
1121
-						if ($degzdata = @gzinflate(substr($data, 10))) {	// do our best
1122
-							$data = $degzdata;
1123
-	    					$this->debug('The payload has been un-gzipped to ' . strlen($data) . ' bytes');
1124
-	    					if (strlen($data) < $datalen) {
1125
-	    						// test for the case that the payload has been compressed twice
1126
-		    					$this->debug('The un-gzipped payload is smaller than the gzipped one; try again');
1127
-								if ($degzdata = @gzinflate(substr($data, 10))) {
1128
-			    					$data = $degzdata;
1129
-			    					$this->debug('The payload has been un-gzipped again to ' . strlen($data) . ' bytes');
1130
-								}
1131
-	    					}
1132
-	    				} else {
1133
-	    					$this->debug('Error using gzinflate to un-gzip the payload');
1134
-							$this->setError('Error using gzinflate to un-gzip the payload');
1135
-	    				}
1136
-					}
1137
-					//$timer->setMarker('finished decoding of gzip/deflated content');
1138
-					//print "<xmp>\nde-inflated:\n---------------\n$data\n-------------\n</xmp>";
1139
-					// set decoded payload
1140
-					$this->incoming_payload = $header_data.$lb.$lb.$data;
1141
-    			} else {
1142
-					$this->debug('The server sent compressed data. Your php install must have the Zlib extension compiled in to support this.');
1143
-					$this->setError('The server sent compressed data. Your php install must have the Zlib extension compiled in to support this.');
1144
-				}
1145
-			} else {
1146
-				$this->debug('Unsupported Content-Encoding ' . $this->incoming_headers['content-encoding']);
1147
-				$this->setError('Unsupported Content-Encoding ' . $this->incoming_headers['content-encoding']);
1148
-			}
1149
-		} else {
1150
-			$this->debug('No Content-Encoding header');
1151
-		}
1152
-
1153
-		if(strlen($data) == 0){
1154
-			$this->debug('no data after headers!');
1155
-			$this->setError('no data present after HTTP headers');
1156
-			return false;
1157
-		}
1158
-
1159
-		return $data;
1160
-	}
1161
-
1162
-	/**
1163
-	 * sets the content-type for the SOAP message to be sent
1164
-	 *
1165
-	 * @param	string $type the content type, MIME style
1166
-	 * @param	mixed $charset character set used for encoding (or false)
1167
-	 * @access	public
1168
-	 */
1169
-	function setContentType($type, $charset = false) {
1170
-		$this->setHeader('Content-Type', $type . ($charset ? '; charset=' . $charset : ''));
1171
-	}
1172
-
1173
-	/**
1174
-	 * specifies that an HTTP persistent connection should be used
1175
-	 *
1176
-	 * @return	boolean whether the request was honored by this method.
1177
-	 * @access	public
1178
-	 */
1179
-	function usePersistentConnection(){
1180
-		if (isset($this->outgoing_headers['Accept-Encoding'])) {
1181
-			return false;
1182
-		}
1183
-		$this->protocol_version = '1.1';
1184
-		$this->persistentConnection = true;
1185
-		$this->setHeader('Connection', 'Keep-Alive');
1186
-		return true;
1187
-	}
1188
-
1189
-	/**
1190
-	 * parse an incoming Cookie into it's parts
1191
-	 *
1192
-	 * @param	string $cookie_str content of cookie
1193
-	 * @return	array with data of that cookie
1194
-	 * @access	private
1195
-	 */
1196
-	/*
964
+        if ($cErr != '') {
965
+            $err = 'cURL ERROR: '.curl_errno($this->ch).': '.$cErr.'<br>';
966
+            // TODO: there is a PHP bug that can cause this to SEGV for CURLINFO_CONTENT_TYPE
967
+            foreach(curl_getinfo($this->ch) as $k => $v){
968
+                $err .= "$k: $v<br>";
969
+            }
970
+            $this->debug($err);
971
+            $this->setError($err);
972
+            curl_close($this->ch);
973
+            return false;
974
+        } else {
975
+            //echo '<pre>';
976
+            //var_dump(curl_getinfo($this->ch));
977
+            //echo '</pre>';
978
+        }
979
+        // close curl
980
+        $this->debug('No cURL error, closing cURL');
981
+        curl_close($this->ch);
982
+
983
+        // try removing skippable headers
984
+        $savedata = $data;
985
+        while ($this->isSkippableCurlHeader($data)) {
986
+            $this->debug("Found HTTP header to skip");
987
+            if ($pos = strpos($data,"\r\n\r\n")) {
988
+                $data = ltrim(substr($data,$pos));
989
+            } elseif($pos = strpos($data,"\n\n") ) {
990
+                $data = ltrim(substr($data,$pos));
991
+            }
992
+        }
993
+
994
+        if ($data == '') {
995
+            // have nothing left; just remove 100 header(s)
996
+            $data = $savedata;
997
+            while (preg_match('/^HTTP\/1.1 100/',$data)) {
998
+                if ($pos = strpos($data,"\r\n\r\n")) {
999
+                    $data = ltrim(substr($data,$pos));
1000
+                } elseif($pos = strpos($data,"\n\n") ) {
1001
+                    $data = ltrim(substr($data,$pos));
1002
+                }
1003
+            }
1004
+        }
1005
+
1006
+        // separate content from HTTP headers
1007
+        if ($pos = strpos($data,"\r\n\r\n")) {
1008
+            $lb = "\r\n";
1009
+        } elseif( $pos = strpos($data,"\n\n")) {
1010
+            $lb = "\n";
1011
+        } else {
1012
+            $this->debug('no proper separation of headers and document');
1013
+            $this->setError('no proper separation of headers and document');
1014
+            return false;
1015
+        }
1016
+        $header_data = trim(substr($data,0,$pos));
1017
+        $header_array = explode($lb,$header_data);
1018
+        $data = ltrim(substr($data,$pos));
1019
+        $this->debug('found proper separation of headers and document');
1020
+        $this->debug('cleaned data, stringlen: '.strlen($data));
1021
+        // clean headers
1022
+        foreach ($header_array as $header_line) {
1023
+            $arr = explode(':',$header_line,2);
1024
+            if(count($arr) > 1){
1025
+                $header_name = strtolower(trim($arr[0]));
1026
+                $this->incoming_headers[$header_name] = trim($arr[1]);
1027
+                if ($header_name == 'set-cookie') {
1028
+                    // TODO: allow multiple cookies from parseCookie
1029
+                    $cookie = $this->parseCookie(trim($arr[1]));
1030
+                    if ($cookie) {
1031
+                        $this->incoming_cookies[] = $cookie;
1032
+                        $this->debug('found cookie: ' . $cookie['name'] . ' = ' . $cookie['value']);
1033
+                    } else {
1034
+                        $this->debug('did not find cookie in ' . trim($arr[1]));
1035
+                    }
1036
+                }
1037
+            } else if (isset($header_name)) {
1038
+                // append continuation line to previous header
1039
+                $this->incoming_headers[$header_name] .= $lb . ' ' . $header_line;
1040
+            }
1041
+        }
1042
+        }
1043
+
1044
+        $this->response_status_line = $header_array[0];
1045
+        $arr = explode(' ', $this->response_status_line, 3);
1046
+        $http_version = $arr[0];
1047
+        $http_status = intval($arr[1]);
1048
+        $http_reason = count($arr) > 2 ? $arr[2] : '';
1049
+
1050
+            // see if we need to resend the request with http digest authentication
1051
+            if (isset($this->incoming_headers['location']) && ($http_status == 301 || $http_status == 302)) {
1052
+                $this->debug("Got $http_status $http_reason with Location: " . $this->incoming_headers['location']);
1053
+                $this->setURL($this->incoming_headers['location']);
1054
+            $this->tryagain = true;
1055
+            return false;
1056
+        }
1057
+
1058
+            // see if we need to resend the request with http digest authentication
1059
+            if (isset($this->incoming_headers['www-authenticate']) && $http_status == 401) {
1060
+                $this->debug("Got 401 $http_reason with WWW-Authenticate: " . $this->incoming_headers['www-authenticate']);
1061
+                if (strstr($this->incoming_headers['www-authenticate'], "Digest ")) {
1062
+                    $this->debug('Server wants digest authentication');
1063
+                    // remove "Digest " from our elements
1064
+                    $digestString = str_replace('Digest ', '', $this->incoming_headers['www-authenticate']);
1065
+
1066
+                    // parse elements into array
1067
+                    $digestElements = explode(',', $digestString);
1068
+                    foreach ($digestElements as $val) {
1069
+                        $tempElement = explode('=', trim($val), 2);
1070
+                        $digestRequest[$tempElement[0]] = str_replace("\"", '', $tempElement[1]);
1071
+                    }
1072
+
1073
+                // should have (at least) qop, realm, nonce
1074
+                    if (isset($digestRequest['nonce'])) {
1075
+                        $this->setCredentials($this->username, $this->password, 'digest', $digestRequest);
1076
+                        $this->tryagain = true;
1077
+                        return false;
1078
+                    }
1079
+                }
1080
+            $this->debug('HTTP authentication failed');
1081
+            $this->setError('HTTP authentication failed');
1082
+            return false;
1083
+            }
1084
+
1085
+        if (
1086
+            ($http_status >= 300 && $http_status <= 307) ||
1087
+            ($http_status >= 400 && $http_status <= 417) ||
1088
+            ($http_status >= 501 && $http_status <= 505)
1089
+            ) {
1090
+            $this->setError("Unsupported HTTP response status $http_status $http_reason (soapclient->response has contents of the response)");
1091
+            return false;
1092
+        }
1093
+
1094
+        // decode content-encoding
1095
+        if(isset($this->incoming_headers['content-encoding']) && $this->incoming_headers['content-encoding'] != ''){
1096
+            if(strtolower($this->incoming_headers['content-encoding']) == 'deflate' || strtolower($this->incoming_headers['content-encoding']) == 'gzip'){
1097
+                // if decoding works, use it. else assume data wasn't gzencoded
1098
+                if(function_exists('gzinflate')){
1099
+                    //$timer->setMarker('starting decoding of gzip/deflated content');
1100
+                    // IIS 5 requires gzinflate instead of gzuncompress (similar to IE 5 and gzdeflate v. gzcompress)
1101
+                    // this means there are no Zlib headers, although there should be
1102
+                    $this->debug('The gzinflate function exists');
1103
+                    $datalen = strlen($data);
1104
+                    if ($this->incoming_headers['content-encoding'] == 'deflate') {
1105
+                        if ($degzdata = @gzinflate($data)) {
1106
+                            $data = $degzdata;
1107
+                            $this->debug('The payload has been inflated to ' . strlen($data) . ' bytes');
1108
+                            if (strlen($data) < $datalen) {
1109
+                                // test for the case that the payload has been compressed twice
1110
+                                $this->debug('The inflated payload is smaller than the gzipped one; try again');
1111
+                                if ($degzdata = @gzinflate($data)) {
1112
+                                    $data = $degzdata;
1113
+                                    $this->debug('The payload has been inflated again to ' . strlen($data) . ' bytes');
1114
+                                }
1115
+                            }
1116
+                        } else {
1117
+                            $this->debug('Error using gzinflate to inflate the payload');
1118
+                            $this->setError('Error using gzinflate to inflate the payload');
1119
+                        }
1120
+                    } elseif ($this->incoming_headers['content-encoding'] == 'gzip') {
1121
+                        if ($degzdata = @gzinflate(substr($data, 10))) {	// do our best
1122
+                            $data = $degzdata;
1123
+                            $this->debug('The payload has been un-gzipped to ' . strlen($data) . ' bytes');
1124
+                            if (strlen($data) < $datalen) {
1125
+                                // test for the case that the payload has been compressed twice
1126
+                                $this->debug('The un-gzipped payload is smaller than the gzipped one; try again');
1127
+                                if ($degzdata = @gzinflate(substr($data, 10))) {
1128
+                                    $data = $degzdata;
1129
+                                    $this->debug('The payload has been un-gzipped again to ' . strlen($data) . ' bytes');
1130
+                                }
1131
+                            }
1132
+                        } else {
1133
+                            $this->debug('Error using gzinflate to un-gzip the payload');
1134
+                            $this->setError('Error using gzinflate to un-gzip the payload');
1135
+                        }
1136
+                    }
1137
+                    //$timer->setMarker('finished decoding of gzip/deflated content');
1138
+                    //print "<xmp>\nde-inflated:\n---------------\n$data\n-------------\n</xmp>";
1139
+                    // set decoded payload
1140
+                    $this->incoming_payload = $header_data.$lb.$lb.$data;
1141
+                } else {
1142
+                    $this->debug('The server sent compressed data. Your php install must have the Zlib extension compiled in to support this.');
1143
+                    $this->setError('The server sent compressed data. Your php install must have the Zlib extension compiled in to support this.');
1144
+                }
1145
+            } else {
1146
+                $this->debug('Unsupported Content-Encoding ' . $this->incoming_headers['content-encoding']);
1147
+                $this->setError('Unsupported Content-Encoding ' . $this->incoming_headers['content-encoding']);
1148
+            }
1149
+        } else {
1150
+            $this->debug('No Content-Encoding header');
1151
+        }
1152
+
1153
+        if(strlen($data) == 0){
1154
+            $this->debug('no data after headers!');
1155
+            $this->setError('no data present after HTTP headers');
1156
+            return false;
1157
+        }
1158
+
1159
+        return $data;
1160
+    }
1161
+
1162
+    /**
1163
+     * sets the content-type for the SOAP message to be sent
1164
+     *
1165
+     * @param	string $type the content type, MIME style
1166
+     * @param	mixed $charset character set used for encoding (or false)
1167
+     * @access	public
1168
+     */
1169
+    function setContentType($type, $charset = false) {
1170
+        $this->setHeader('Content-Type', $type . ($charset ? '; charset=' . $charset : ''));
1171
+    }
1172
+
1173
+    /**
1174
+     * specifies that an HTTP persistent connection should be used
1175
+     *
1176
+     * @return	boolean whether the request was honored by this method.
1177
+     * @access	public
1178
+     */
1179
+    function usePersistentConnection(){
1180
+        if (isset($this->outgoing_headers['Accept-Encoding'])) {
1181
+            return false;
1182
+        }
1183
+        $this->protocol_version = '1.1';
1184
+        $this->persistentConnection = true;
1185
+        $this->setHeader('Connection', 'Keep-Alive');
1186
+        return true;
1187
+    }
1188
+
1189
+    /**
1190
+     * parse an incoming Cookie into it's parts
1191
+     *
1192
+     * @param	string $cookie_str content of cookie
1193
+     * @return	array with data of that cookie
1194
+     * @access	private
1195
+     */
1196
+    /*
1197 1197
 	 * TODO: allow a Set-Cookie string to be parsed into multiple cookies
1198 1198
 	 */
1199
-	function parseCookie($cookie_str) {
1200
-		$cookie_str = str_replace('; ', ';', $cookie_str) . ';';
1201
-		$data = preg_split('/;/', $cookie_str);
1202
-		$value_str = $data[0];
1203
-
1204
-		$cookie_param = 'domain=';
1205
-		$start = strpos($cookie_str, $cookie_param);
1206
-		if ($start > 0) {
1207
-			$domain = substr($cookie_str, $start + strlen($cookie_param));
1208
-			$domain = substr($domain, 0, strpos($domain, ';'));
1209
-		} else {
1210
-			$domain = '';
1211
-		}
1212
-
1213
-		$cookie_param = 'expires=';
1214
-		$start = strpos($cookie_str, $cookie_param);
1215
-		if ($start > 0) {
1216
-			$expires = substr($cookie_str, $start + strlen($cookie_param));
1217
-			$expires = substr($expires, 0, strpos($expires, ';'));
1218
-		} else {
1219
-			$expires = '';
1220
-		}
1221
-
1222
-		$cookie_param = 'path=';
1223
-		$start = strpos($cookie_str, $cookie_param);
1224
-		if ( $start > 0 ) {
1225
-			$path = substr($cookie_str, $start + strlen($cookie_param));
1226
-			$path = substr($path, 0, strpos($path, ';'));
1227
-		} else {
1228
-			$path = '/';
1229
-		}
1230
-
1231
-		$cookie_param = ';secure;';
1232
-		if (strpos($cookie_str, $cookie_param) !== FALSE) {
1233
-			$secure = true;
1234
-		} else {
1235
-			$secure = false;
1236
-		}
1237
-
1238
-		$sep_pos = strpos($value_str, '=');
1239
-
1240
-		if ($sep_pos) {
1241
-			$name = substr($value_str, 0, $sep_pos);
1242
-			$value = substr($value_str, $sep_pos + 1);
1243
-			$cookie= array(	'name' => $name,
1244
-			                'value' => $value,
1245
-							'domain' => $domain,
1246
-							'path' => $path,
1247
-							'expires' => $expires,
1248
-							'secure' => $secure
1249
-							);
1250
-			return $cookie;
1251
-		}
1252
-		return false;
1253
-	}
1254
-
1255
-	/**
1256
-	 * sort out cookies for the current request
1257
-	 *
1258
-	 * @param	array $cookies array with all cookies
1259
-	 * @param	boolean $secure is the send-content secure or not?
1260
-	 * @return	string for Cookie-HTTP-Header
1261
-	 * @access	private
1262
-	 */
1263
-	function getCookiesForRequest($cookies, $secure=false) {
1264
-		$cookie_str = '';
1265
-		if ((! is_null($cookies)) && (is_array($cookies))) {
1266
-			foreach ($cookies as $cookie) {
1267
-				if (! is_array($cookie)) {
1268
-					continue;
1269
-				}
1270
-	    		$this->debug("check cookie for validity: ".$cookie['name'].'='.$cookie['value']);
1271
-				if ((isset($cookie['expires'])) && (! empty($cookie['expires']))) {
1272
-					if (strtotime($cookie['expires']) <= time()) {
1273
-						$this->debug('cookie has expired');
1274
-						continue;
1275
-					}
1276
-				}
1277
-				if ((isset($cookie['domain'])) && (! empty($cookie['domain']))) {
1278
-					$domain = preg_quote($cookie['domain']);
1279
-					if (! preg_match("'.*$domain$'i", $this->host)) {
1280
-						$this->debug('cookie has different domain');
1281
-						continue;
1282
-					}
1283
-				}
1284
-				if ((isset($cookie['path'])) && (! empty($cookie['path']))) {
1285
-					$path = preg_quote($cookie['path']);
1286
-					if (! preg_match("'^$path.*'i", $this->path)) {
1287
-						$this->debug('cookie is for a different path');
1288
-						continue;
1289
-					}
1290
-				}
1291
-				if ((! $secure) && (isset($cookie['secure'])) && ($cookie['secure'])) {
1292
-					$this->debug('cookie is secure, transport is not');
1293
-					continue;
1294
-				}
1295
-				$cookie_str .= $cookie['name'] . '=' . $cookie['value'] . '; ';
1296
-	    		$this->debug('add cookie to Cookie-String: ' . $cookie['name'] . '=' . $cookie['value']);
1297
-			}
1298
-		}
1299
-		return $cookie_str;
1300
-  }
1199
+    function parseCookie($cookie_str) {
1200
+        $cookie_str = str_replace('; ', ';', $cookie_str) . ';';
1201
+        $data = preg_split('/;/', $cookie_str);
1202
+        $value_str = $data[0];
1203
+
1204
+        $cookie_param = 'domain=';
1205
+        $start = strpos($cookie_str, $cookie_param);
1206
+        if ($start > 0) {
1207
+            $domain = substr($cookie_str, $start + strlen($cookie_param));
1208
+            $domain = substr($domain, 0, strpos($domain, ';'));
1209
+        } else {
1210
+            $domain = '';
1211
+        }
1212
+
1213
+        $cookie_param = 'expires=';
1214
+        $start = strpos($cookie_str, $cookie_param);
1215
+        if ($start > 0) {
1216
+            $expires = substr($cookie_str, $start + strlen($cookie_param));
1217
+            $expires = substr($expires, 0, strpos($expires, ';'));
1218
+        } else {
1219
+            $expires = '';
1220
+        }
1221
+
1222
+        $cookie_param = 'path=';
1223
+        $start = strpos($cookie_str, $cookie_param);
1224
+        if ( $start > 0 ) {
1225
+            $path = substr($cookie_str, $start + strlen($cookie_param));
1226
+            $path = substr($path, 0, strpos($path, ';'));
1227
+        } else {
1228
+            $path = '/';
1229
+        }
1230
+
1231
+        $cookie_param = ';secure;';
1232
+        if (strpos($cookie_str, $cookie_param) !== FALSE) {
1233
+            $secure = true;
1234
+        } else {
1235
+            $secure = false;
1236
+        }
1237
+
1238
+        $sep_pos = strpos($value_str, '=');
1239
+
1240
+        if ($sep_pos) {
1241
+            $name = substr($value_str, 0, $sep_pos);
1242
+            $value = substr($value_str, $sep_pos + 1);
1243
+            $cookie= array(	'name' => $name,
1244
+                            'value' => $value,
1245
+                            'domain' => $domain,
1246
+                            'path' => $path,
1247
+                            'expires' => $expires,
1248
+                            'secure' => $secure
1249
+                            );
1250
+            return $cookie;
1251
+        }
1252
+        return false;
1253
+    }
1254
+
1255
+    /**
1256
+     * sort out cookies for the current request
1257
+     *
1258
+     * @param	array $cookies array with all cookies
1259
+     * @param	boolean $secure is the send-content secure or not?
1260
+     * @return	string for Cookie-HTTP-Header
1261
+     * @access	private
1262
+     */
1263
+    function getCookiesForRequest($cookies, $secure=false) {
1264
+        $cookie_str = '';
1265
+        if ((! is_null($cookies)) && (is_array($cookies))) {
1266
+            foreach ($cookies as $cookie) {
1267
+                if (! is_array($cookie)) {
1268
+                    continue;
1269
+                }
1270
+                $this->debug("check cookie for validity: ".$cookie['name'].'='.$cookie['value']);
1271
+                if ((isset($cookie['expires'])) && (! empty($cookie['expires']))) {
1272
+                    if (strtotime($cookie['expires']) <= time()) {
1273
+                        $this->debug('cookie has expired');
1274
+                        continue;
1275
+                    }
1276
+                }
1277
+                if ((isset($cookie['domain'])) && (! empty($cookie['domain']))) {
1278
+                    $domain = preg_quote($cookie['domain']);
1279
+                    if (! preg_match("'.*$domain$'i", $this->host)) {
1280
+                        $this->debug('cookie has different domain');
1281
+                        continue;
1282
+                    }
1283
+                }
1284
+                if ((isset($cookie['path'])) && (! empty($cookie['path']))) {
1285
+                    $path = preg_quote($cookie['path']);
1286
+                    if (! preg_match("'^$path.*'i", $this->path)) {
1287
+                        $this->debug('cookie is for a different path');
1288
+                        continue;
1289
+                    }
1290
+                }
1291
+                if ((! $secure) && (isset($cookie['secure'])) && ($cookie['secure'])) {
1292
+                    $this->debug('cookie is secure, transport is not');
1293
+                    continue;
1294
+                }
1295
+                $cookie_str .= $cookie['name'] . '=' . $cookie['value'] . '; ';
1296
+                $this->debug('add cookie to Cookie-String: ' . $cookie['name'] . '=' . $cookie['value']);
1297
+            }
1298
+        }
1299
+        return $cookie_str;
1300
+    }
1301 1301
 }
1302 1302
 
1303 1303
 
Please login to merge, or discard this patch.
main/inc/lib/nusoap/class.xmlschema.php 1 patch
Indentation   +910 added lines, -910 removed lines patch added patch discarded remove patch
@@ -11,275 +11,275 @@  discard block
 block discarded – undo
11 11
 */
12 12
 class nusoap_xmlschema extends nusoap_base
13 13
 {
14
-	// files
15
-	var $schema = '';
16
-	var $xml = '';
17
-	// namespaces
18
-	var $enclosingNamespaces;
19
-	// schema info
20
-	var $schemaInfo = array();
21
-	var $schemaTargetNamespace = '';
22
-	// types, elements, attributes defined by the schema
23
-	var $attributes = array();
24
-	var $complexTypes = array();
25
-	var $complexTypeStack = array();
26
-	var $currentComplexType = null;
27
-	var $elements = array();
28
-	var $elementStack = array();
29
-	var $currentElement = null;
30
-	var $simpleTypes = array();
31
-	var $simpleTypeStack = array();
32
-	var $currentSimpleType = null;
33
-	// imports
34
-	var $imports = array();
35
-	// parser vars
36
-	var $parser;
37
-	var $position = 0;
38
-	var $depth = 0;
39
-	var $depth_array = array();
40
-	var $message = array();
41
-	var $defaultNamespace = array();
42
-
43
-	/**
44
-	* constructor
45
-	*
46
-	* @param    string $schema schema document URI
47
-	* @param    string $xml xml document URI
48
-	* @param	string $namespaces namespaces defined in enclosing XML
49
-	* @access   public
50
-	*/
51
-	function __construct($schema='',$xml='',$namespaces=array()){
52
-		parent::__construct();
53
-		$this->debug('nusoap_xmlschema class instantiated, inside constructor');
54
-		// files
55
-		$this->schema = $schema;
56
-		$this->xml = $xml;
57
-
58
-		// namespaces
59
-		$this->enclosingNamespaces = $namespaces;
60
-		$this->namespaces = array_merge($this->namespaces, $namespaces);
61
-
62
-		// parse schema file
63
-		if($schema != ''){
64
-			$this->debug('initial schema file: '.$schema);
65
-			$this->parseFile($schema, 'schema');
66
-		}
67
-
68
-		// parse xml file
69
-		if($xml != ''){
70
-			$this->debug('initial xml file: '.$xml);
71
-			$this->parseFile($xml, 'xml');
72
-		}
73
-
74
-	}
14
+    // files
15
+    var $schema = '';
16
+    var $xml = '';
17
+    // namespaces
18
+    var $enclosingNamespaces;
19
+    // schema info
20
+    var $schemaInfo = array();
21
+    var $schemaTargetNamespace = '';
22
+    // types, elements, attributes defined by the schema
23
+    var $attributes = array();
24
+    var $complexTypes = array();
25
+    var $complexTypeStack = array();
26
+    var $currentComplexType = null;
27
+    var $elements = array();
28
+    var $elementStack = array();
29
+    var $currentElement = null;
30
+    var $simpleTypes = array();
31
+    var $simpleTypeStack = array();
32
+    var $currentSimpleType = null;
33
+    // imports
34
+    var $imports = array();
35
+    // parser vars
36
+    var $parser;
37
+    var $position = 0;
38
+    var $depth = 0;
39
+    var $depth_array = array();
40
+    var $message = array();
41
+    var $defaultNamespace = array();
75 42
 
76 43
     /**
77
-    * parse an XML file
78
-    *
79
-    * @param string $xml path/URL to XML file
80
-    * @param string $type (schema | xml)
81
-	* @return boolean
82
-    * @access public
83
-    */
84
-	function parseFile($xml,$type){
85
-		// parse xml file
86
-		if($xml != ""){
87
-			$xmlStr = @join("",@file($xml));
88
-			if($xmlStr == ""){
89
-				$msg = 'Error reading XML from '.$xml;
90
-				$this->setError($msg);
91
-				$this->debug($msg);
92
-			return false;
93
-			} else {
94
-				$this->debug("parsing $xml");
95
-				$this->parseString($xmlStr,$type);
96
-				$this->debug("done parsing $xml");
97
-			return true;
98
-			}
99
-		}
100
-		return false;
101
-	}
102
-
103
-	/**
104
-	* parse an XML string
105
-	*
106
-	* @param    string $xml path or URL
107
-    * @param	string $type (schema|xml)
108
-	* @access   private
109
-	*/
110
-	function parseString($xml,$type){
111
-		// parse xml string
112
-		if($xml != ""){
113
-
114
-	    	// Create an XML parser.
115
-	    	$this->parser = xml_parser_create();
116
-	    	// Set the options for parsing the XML data.
117
-	    	xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
118
-
119
-	    	// Set the object for the parser.
120
-	    	xml_set_object($this->parser, $this);
121
-
122
-	    	// Set the element handlers for the parser.
123
-			if($type == "schema"){
124
-		    	xml_set_element_handler($this->parser, 'schemaStartElement','schemaEndElement');
125
-		    	xml_set_character_data_handler($this->parser,'schemaCharacterData');
126
-			} elseif($type == "xml"){
127
-				xml_set_element_handler($this->parser, 'xmlStartElement','xmlEndElement');
128
-		    	xml_set_character_data_handler($this->parser,'xmlCharacterData');
129
-			}
130
-
131
-		    // Parse the XML file.
132
-		    if(!xml_parse($this->parser,$xml,true)){
133
-			// Display an error message.
134
-				$errstr = sprintf('XML error parsing XML schema on line %d: %s',
135
-				xml_get_current_line_number($this->parser),
136
-				xml_error_string(xml_get_error_code($this->parser))
137
-				);
138
-				$this->debug($errstr);
139
-				$this->debug("XML payload:\n" . $xml);
140
-				$this->setError($errstr);
141
-	    	}
142
-
143
-			xml_parser_free($this->parser);
144
-		} else{
145
-			$this->debug('no xml passed to parseString()!!');
146
-			$this->setError('no xml passed to parseString()!!');
147
-		}
148
-	}
149
-
150
-	/**
151
-	 * gets a type name for an unnamed type
152
-	 *
153
-	 * @param	string	Element name
154
-	 * @return	string	A type name for an unnamed type
155
-	 * @access	private
156
-	 */
157
-	function CreateTypeName($ename) {
158
-		$scope = '';
159
-		for ($i = 0; $i < count($this->complexTypeStack); $i++) {
160
-			$scope .= $this->complexTypeStack[$i] . '_';
161
-		}
162
-		return $scope . $ename . '_ContainedType';
163
-	}
164
-
165
-	/**
166
-	* start-element handler
167
-	*
168
-	* @param    string $parser XML parser object
169
-	* @param    string $name element name
170
-	* @param    string $attrs associative array of attributes
171
-	* @access   private
172
-	*/
173
-	function schemaStartElement($parser, $name, $attrs) {
174
-
175
-		// position in the total number of elements, starting from 0
176
-		$pos = $this->position++;
177
-		$depth = $this->depth++;
178
-		// set self as current value for this depth
179
-		$this->depth_array[$depth] = $pos;
180
-		$this->message[$pos] = array('cdata' => '');
181
-		if ($depth > 0) {
182
-			$this->defaultNamespace[$pos] = $this->defaultNamespace[$this->depth_array[$depth - 1]];
183
-		} else {
184
-			$this->defaultNamespace[$pos] = false;
185
-		}
186
-
187
-		// get element prefix
188
-		if($prefix = $this->getPrefix($name)){
189
-			// get unqualified name
190
-			$name = $this->getLocalPart($name);
191
-		} else {
192
-        	$prefix = '';
44
+     * constructor
45
+     *
46
+     * @param    string $schema schema document URI
47
+     * @param    string $xml xml document URI
48
+     * @param	string $namespaces namespaces defined in enclosing XML
49
+     * @access   public
50
+     */
51
+    function __construct($schema='',$xml='',$namespaces=array()){
52
+        parent::__construct();
53
+        $this->debug('nusoap_xmlschema class instantiated, inside constructor');
54
+        // files
55
+        $this->schema = $schema;
56
+        $this->xml = $xml;
57
+
58
+        // namespaces
59
+        $this->enclosingNamespaces = $namespaces;
60
+        $this->namespaces = array_merge($this->namespaces, $namespaces);
61
+
62
+        // parse schema file
63
+        if($schema != ''){
64
+            $this->debug('initial schema file: '.$schema);
65
+            $this->parseFile($schema, 'schema');
66
+        }
67
+
68
+        // parse xml file
69
+        if($xml != ''){
70
+            $this->debug('initial xml file: '.$xml);
71
+            $this->parseFile($xml, 'xml');
72
+        }
73
+
74
+    }
75
+
76
+    /**
77
+     * parse an XML file
78
+     *
79
+     * @param string $xml path/URL to XML file
80
+     * @param string $type (schema | xml)
81
+     * @return boolean
82
+     * @access public
83
+     */
84
+    function parseFile($xml,$type){
85
+        // parse xml file
86
+        if($xml != ""){
87
+            $xmlStr = @join("",@file($xml));
88
+            if($xmlStr == ""){
89
+                $msg = 'Error reading XML from '.$xml;
90
+                $this->setError($msg);
91
+                $this->debug($msg);
92
+            return false;
93
+            } else {
94
+                $this->debug("parsing $xml");
95
+                $this->parseString($xmlStr,$type);
96
+                $this->debug("done parsing $xml");
97
+            return true;
98
+            }
99
+        }
100
+        return false;
101
+    }
102
+
103
+    /**
104
+     * parse an XML string
105
+     *
106
+     * @param    string $xml path or URL
107
+     * @param	string $type (schema|xml)
108
+     * @access   private
109
+     */
110
+    function parseString($xml,$type){
111
+        // parse xml string
112
+        if($xml != ""){
113
+
114
+            // Create an XML parser.
115
+            $this->parser = xml_parser_create();
116
+            // Set the options for parsing the XML data.
117
+            xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
118
+
119
+            // Set the object for the parser.
120
+            xml_set_object($this->parser, $this);
121
+
122
+            // Set the element handlers for the parser.
123
+            if($type == "schema"){
124
+                xml_set_element_handler($this->parser, 'schemaStartElement','schemaEndElement');
125
+                xml_set_character_data_handler($this->parser,'schemaCharacterData');
126
+            } elseif($type == "xml"){
127
+                xml_set_element_handler($this->parser, 'xmlStartElement','xmlEndElement');
128
+                xml_set_character_data_handler($this->parser,'xmlCharacterData');
129
+            }
130
+
131
+            // Parse the XML file.
132
+            if(!xml_parse($this->parser,$xml,true)){
133
+            // Display an error message.
134
+                $errstr = sprintf('XML error parsing XML schema on line %d: %s',
135
+                xml_get_current_line_number($this->parser),
136
+                xml_error_string(xml_get_error_code($this->parser))
137
+                );
138
+                $this->debug($errstr);
139
+                $this->debug("XML payload:\n" . $xml);
140
+                $this->setError($errstr);
141
+            }
142
+
143
+            xml_parser_free($this->parser);
144
+        } else{
145
+            $this->debug('no xml passed to parseString()!!');
146
+            $this->setError('no xml passed to parseString()!!');
147
+        }
148
+    }
149
+
150
+    /**
151
+     * gets a type name for an unnamed type
152
+     *
153
+     * @param	string	Element name
154
+     * @return	string	A type name for an unnamed type
155
+     * @access	private
156
+     */
157
+    function CreateTypeName($ename) {
158
+        $scope = '';
159
+        for ($i = 0; $i < count($this->complexTypeStack); $i++) {
160
+            $scope .= $this->complexTypeStack[$i] . '_';
161
+        }
162
+        return $scope . $ename . '_ContainedType';
163
+    }
164
+
165
+    /**
166
+     * start-element handler
167
+     *
168
+     * @param    string $parser XML parser object
169
+     * @param    string $name element name
170
+     * @param    string $attrs associative array of attributes
171
+     * @access   private
172
+     */
173
+    function schemaStartElement($parser, $name, $attrs) {
174
+
175
+        // position in the total number of elements, starting from 0
176
+        $pos = $this->position++;
177
+        $depth = $this->depth++;
178
+        // set self as current value for this depth
179
+        $this->depth_array[$depth] = $pos;
180
+        $this->message[$pos] = array('cdata' => '');
181
+        if ($depth > 0) {
182
+            $this->defaultNamespace[$pos] = $this->defaultNamespace[$this->depth_array[$depth - 1]];
183
+        } else {
184
+            $this->defaultNamespace[$pos] = false;
185
+        }
186
+
187
+        // get element prefix
188
+        if($prefix = $this->getPrefix($name)){
189
+            // get unqualified name
190
+            $name = $this->getLocalPart($name);
191
+        } else {
192
+            $prefix = '';
193 193
         }
194 194
 
195 195
         // loop thru attributes, expanding, and registering namespace declarations
196 196
         if(count($attrs) > 0){
197
-        	foreach($attrs as $k => $v){
197
+            foreach($attrs as $k => $v){
198 198
                 // if ns declarations, add to class level array of valid namespaces
199
-				if(preg_match('/^xmlns/',$k)){
200
-                	//$this->xdebug("$k: $v");
201
-                	//$this->xdebug('ns_prefix: '.$this->getPrefix($k));
202
-                	if($ns_prefix = substr(strrchr($k,':'),1)){
203
-                		//$this->xdebug("Add namespace[$ns_prefix] = $v");
204
-						$this->namespaces[$ns_prefix] = $v;
205
-					} else {
206
-						$this->defaultNamespace[$pos] = $v;
207
-						if (! $this->getPrefixFromNamespace($v)) {
208
-							$this->namespaces['ns'.(count($this->namespaces)+1)] = $v;
209
-						}
210
-					}
211
-					if($v == 'http://www.w3.org/2001/XMLSchema' || $v == 'http://www.w3.org/1999/XMLSchema' || $v == 'http://www.w3.org/2000/10/XMLSchema'){
212
-						$this->XMLSchemaVersion = $v;
213
-						$this->namespaces['xsi'] = $v.'-instance';
214
-					}
215
-				}
216
-        	}
217
-        	foreach($attrs as $k => $v){
199
+                if(preg_match('/^xmlns/',$k)){
200
+                    //$this->xdebug("$k: $v");
201
+                    //$this->xdebug('ns_prefix: '.$this->getPrefix($k));
202
+                    if($ns_prefix = substr(strrchr($k,':'),1)){
203
+                        //$this->xdebug("Add namespace[$ns_prefix] = $v");
204
+                        $this->namespaces[$ns_prefix] = $v;
205
+                    } else {
206
+                        $this->defaultNamespace[$pos] = $v;
207
+                        if (! $this->getPrefixFromNamespace($v)) {
208
+                            $this->namespaces['ns'.(count($this->namespaces)+1)] = $v;
209
+                        }
210
+                    }
211
+                    if($v == 'http://www.w3.org/2001/XMLSchema' || $v == 'http://www.w3.org/1999/XMLSchema' || $v == 'http://www.w3.org/2000/10/XMLSchema'){
212
+                        $this->XMLSchemaVersion = $v;
213
+                        $this->namespaces['xsi'] = $v.'-instance';
214
+                    }
215
+                }
216
+            }
217
+            foreach($attrs as $k => $v){
218 218
                 // expand each attribute
219 219
                 $k = strpos($k,':') ? $this->expandQname($k) : $k;
220 220
                 $v = strpos($v,':') ? $this->expandQname($v) : $v;
221
-        		$eAttrs[$k] = $v;
222
-        	}
223
-        	$attrs = $eAttrs;
221
+                $eAttrs[$k] = $v;
222
+            }
223
+            $attrs = $eAttrs;
224 224
         } else {
225
-        	$attrs = array();
225
+            $attrs = array();
226 226
         }
227
-		// find status, register data
228
-		switch($name){
229
-			case 'all':			// (optional) compositor content for a complexType
230
-			case 'choice':
231
-			case 'group':
232
-			case 'sequence':
233
-				//$this->xdebug("compositor $name for currentComplexType: $this->currentComplexType and currentElement: $this->currentElement");
234
-				$this->complexTypes[$this->currentComplexType]['compositor'] = $name;
235
-				//if($name == 'all' || $name == 'sequence'){
236
-				//	$this->complexTypes[$this->currentComplexType]['phpType'] = 'struct';
237
-				//}
238
-			break;
239
-			case 'attribute':	// complexType attribute
240
-            	//$this->xdebug("parsing attribute $attrs[name] $attrs[ref] of value: ".$attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']);
241
-            	$this->xdebug("parsing attribute:");
242
-            	$this->appendDebug($this->varDump($attrs));
243
-				if (!isset($attrs['form'])) {
244
-					// TODO: handle globals
245
-					$attrs['form'] = $this->schemaInfo['attributeFormDefault'];
246
-				}
247
-            	if (isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])) {
248
-					$v = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'];
249
-					if (!strpos($v, ':')) {
250
-						// no namespace in arrayType attribute value...
251
-						if ($this->defaultNamespace[$pos]) {
252
-							// ...so use the default
253
-							$attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'] = $this->defaultNamespace[$pos] . ':' . $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'];
254
-						}
255
-					}
256
-            	}
227
+        // find status, register data
228
+        switch($name){
229
+            case 'all':			// (optional) compositor content for a complexType
230
+            case 'choice':
231
+            case 'group':
232
+            case 'sequence':
233
+                //$this->xdebug("compositor $name for currentComplexType: $this->currentComplexType and currentElement: $this->currentElement");
234
+                $this->complexTypes[$this->currentComplexType]['compositor'] = $name;
235
+                //if($name == 'all' || $name == 'sequence'){
236
+                //	$this->complexTypes[$this->currentComplexType]['phpType'] = 'struct';
237
+                //}
238
+            break;
239
+            case 'attribute':	// complexType attribute
240
+                //$this->xdebug("parsing attribute $attrs[name] $attrs[ref] of value: ".$attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']);
241
+                $this->xdebug("parsing attribute:");
242
+                $this->appendDebug($this->varDump($attrs));
243
+                if (!isset($attrs['form'])) {
244
+                    // TODO: handle globals
245
+                    $attrs['form'] = $this->schemaInfo['attributeFormDefault'];
246
+                }
247
+                if (isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])) {
248
+                    $v = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'];
249
+                    if (!strpos($v, ':')) {
250
+                        // no namespace in arrayType attribute value...
251
+                        if ($this->defaultNamespace[$pos]) {
252
+                            // ...so use the default
253
+                            $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'] = $this->defaultNamespace[$pos] . ':' . $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'];
254
+                        }
255
+                    }
256
+                }
257 257
                 if(isset($attrs['name'])){
258
-					$this->attributes[$attrs['name']] = $attrs;
259
-					$aname = $attrs['name'];
260
-				} elseif(isset($attrs['ref']) && $attrs['ref'] == 'http://schemas.xmlsoap.org/soap/encoding/:arrayType'){
261
-					if (isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])) {
262
-	                	$aname = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'];
263
-	                } else {
264
-	                	$aname = '';
265
-	                }
266
-				} elseif(isset($attrs['ref'])){
267
-					$aname = $attrs['ref'];
258
+                    $this->attributes[$attrs['name']] = $attrs;
259
+                    $aname = $attrs['name'];
260
+                } elseif(isset($attrs['ref']) && $attrs['ref'] == 'http://schemas.xmlsoap.org/soap/encoding/:arrayType'){
261
+                    if (isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])) {
262
+                        $aname = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'];
263
+                    } else {
264
+                        $aname = '';
265
+                    }
266
+                } elseif(isset($attrs['ref'])){
267
+                    $aname = $attrs['ref'];
268 268
                     $this->attributes[$attrs['ref']] = $attrs;
269
-				}
270
-
271
-				if($this->currentComplexType){	// This should *always* be
272
-					$this->complexTypes[$this->currentComplexType]['attrs'][$aname] = $attrs;
273
-				}
274
-				// arrayType attribute
275
-				if(isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']) || $this->getLocalPart($aname) == 'arrayType'){
276
-					$this->complexTypes[$this->currentComplexType]['phpType'] = 'array';
277
-                	$prefix = $this->getPrefix($aname);
278
-					if(isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])){
279
-						$v = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'];
280
-					} else {
281
-						$v = '';
282
-					}
269
+                }
270
+
271
+                if($this->currentComplexType){	// This should *always* be
272
+                    $this->complexTypes[$this->currentComplexType]['attrs'][$aname] = $attrs;
273
+                }
274
+                // arrayType attribute
275
+                if(isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']) || $this->getLocalPart($aname) == 'arrayType'){
276
+                    $this->complexTypes[$this->currentComplexType]['phpType'] = 'array';
277
+                    $prefix = $this->getPrefix($aname);
278
+                    if(isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])){
279
+                        $v = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'];
280
+                    } else {
281
+                        $v = '';
282
+                    }
283 283
                     if(strpos($v,'[,]')){
284 284
                         $this->complexTypes[$this->currentComplexType]['multidimensional'] = true;
285 285
                     }
@@ -288,676 +288,676 @@  discard block
 block discarded – undo
288 288
                         $v = $this->XMLSchemaVersion.':'.$v;
289 289
                     }
290 290
                     $this->complexTypes[$this->currentComplexType]['arrayType'] = $v;
291
-				}
292
-			break;
293
-			case 'complexContent':	// (optional) content for a complexType
294
-				$this->xdebug("do nothing for element $name");
295
-			break;
296
-			case 'complexType':
297
-				array_push($this->complexTypeStack, $this->currentComplexType);
298
-				if(isset($attrs['name'])){
299
-					// TODO: what is the scope of named complexTypes that appear
300
-					//       nested within other c complexTypes?
301
-					$this->xdebug('processing named complexType '.$attrs['name']);
302
-					//$this->currentElement = false;
303
-					$this->currentComplexType = $attrs['name'];
304
-					$this->complexTypes[$this->currentComplexType] = $attrs;
305
-					$this->complexTypes[$this->currentComplexType]['typeClass'] = 'complexType';
306
-					// This is for constructs like
307
-					//           <complexType name="ListOfString" base="soap:Array">
308
-					//                <sequence>
309
-					//                    <element name="string" type="xsd:string"
310
-					//                        minOccurs="0" maxOccurs="unbounded" />
311
-					//                </sequence>
312
-					//            </complexType>
313
-					if(isset($attrs['base']) && preg_match('/:Array$/',$attrs['base'])){
314
-						$this->xdebug('complexType is unusual array');
315
-						$this->complexTypes[$this->currentComplexType]['phpType'] = 'array';
316
-					} else {
317
-						$this->complexTypes[$this->currentComplexType]['phpType'] = 'struct';
318
-					}
319
-				} else {
320
-					$name = $this->CreateTypeName($this->currentElement);
321
-					$this->xdebug('processing unnamed complexType for element ' . $this->currentElement . ' named ' . $name);
322
-					$this->currentComplexType = $name;
323
-					//$this->currentElement = false;
324
-					$this->complexTypes[$this->currentComplexType] = $attrs;
325
-					$this->complexTypes[$this->currentComplexType]['typeClass'] = 'complexType';
326
-					// This is for constructs like
327
-					//           <complexType name="ListOfString" base="soap:Array">
328
-					//                <sequence>
329
-					//                    <element name="string" type="xsd:string"
330
-					//                        minOccurs="0" maxOccurs="unbounded" />
331
-					//                </sequence>
332
-					//            </complexType>
333
-					if(isset($attrs['base']) && preg_match('/:Array$/',$attrs['base'])){
334
-						$this->xdebug('complexType is unusual array');
335
-						$this->complexTypes[$this->currentComplexType]['phpType'] = 'array';
336
-					} else {
337
-						$this->complexTypes[$this->currentComplexType]['phpType'] = 'struct';
338
-					}
339
-				}
340
-				$this->complexTypes[$this->currentComplexType]['simpleContent'] = 'false';
341
-			break;
342
-			case 'element':
343
-				array_push($this->elementStack, $this->currentElement);
344
-				if (!isset($attrs['form'])) {
345
-					if ($this->currentComplexType) {
346
-						$attrs['form'] = $this->schemaInfo['elementFormDefault'];
347
-					} else {
348
-						// global
349
-						$attrs['form'] = 'qualified';
350
-					}
351
-				}
352
-				if(isset($attrs['type'])){
353
-					$this->xdebug("processing typed element ".$attrs['name']." of type ".$attrs['type']);
354
-					if (! $this->getPrefix($attrs['type'])) {
355
-						if ($this->defaultNamespace[$pos]) {
356
-							$attrs['type'] = $this->defaultNamespace[$pos] . ':' . $attrs['type'];
357
-							$this->xdebug('used default namespace to make type ' . $attrs['type']);
358
-						}
359
-					}
360
-					// This is for constructs like
361
-					//           <complexType name="ListOfString" base="soap:Array">
362
-					//                <sequence>
363
-					//                    <element name="string" type="xsd:string"
364
-					//                        minOccurs="0" maxOccurs="unbounded" />
365
-					//                </sequence>
366
-					//            </complexType>
367
-					if ($this->currentComplexType && $this->complexTypes[$this->currentComplexType]['phpType'] == 'array') {
368
-						$this->xdebug('arrayType for unusual array is ' . $attrs['type']);
369
-						$this->complexTypes[$this->currentComplexType]['arrayType'] = $attrs['type'];
370
-					}
371
-					$this->currentElement = $attrs['name'];
372
-					$ename = $attrs['name'];
373
-				} elseif(isset($attrs['ref'])){
374
-					$this->xdebug("processing element as ref to ".$attrs['ref']);
375
-					$this->currentElement = "ref to ".$attrs['ref'];
376
-					$ename = $this->getLocalPart($attrs['ref']);
377
-				} else {
378
-					$type = $this->CreateTypeName($this->currentComplexType . '_' . $attrs['name']);
379
-					$this->xdebug("processing untyped element " . $attrs['name'] . ' type ' . $type);
380
-					$this->currentElement = $attrs['name'];
381
-					$attrs['type'] = $this->schemaTargetNamespace . ':' . $type;
382
-					$ename = $attrs['name'];
383
-				}
384
-				if (isset($ename) && $this->currentComplexType) {
385
-					$this->xdebug("add element $ename to complexType $this->currentComplexType");
386
-					$this->complexTypes[$this->currentComplexType]['elements'][$ename] = $attrs;
387
-				} elseif (!isset($attrs['ref'])) {
388
-					$this->xdebug("add element $ename to elements array");
389
-					$this->elements[ $attrs['name'] ] = $attrs;
390
-					$this->elements[ $attrs['name'] ]['typeClass'] = 'element';
391
-				}
392
-			break;
393
-			case 'enumeration':	//	restriction value list member
394
-				$this->xdebug('enumeration ' . $attrs['value']);
395
-				if ($this->currentSimpleType) {
396
-					$this->simpleTypes[$this->currentSimpleType]['enumeration'][] = $attrs['value'];
397
-				} elseif ($this->currentComplexType) {
398
-					$this->complexTypes[$this->currentComplexType]['enumeration'][] = $attrs['value'];
399
-				}
400
-			break;
401
-			case 'extension':	// simpleContent or complexContent type extension
402
-				$this->xdebug('extension ' . $attrs['base']);
403
-				if ($this->currentComplexType) {
404
-					$ns = $this->getPrefix($attrs['base']);
405
-					if ($ns == '') {
406
-						$this->complexTypes[$this->currentComplexType]['extensionBase'] = $this->schemaTargetNamespace . ':' . $attrs['base'];
407
-					} else {
408
-						$this->complexTypes[$this->currentComplexType]['extensionBase'] = $attrs['base'];
409
-					}
410
-				} else {
411
-					$this->xdebug('no current complexType to set extensionBase');
412
-				}
413
-			break;
414
-			case 'import':
415
-			    if (isset($attrs['schemaLocation'])) {
416
-					$this->xdebug('import namespace ' . $attrs['namespace'] . ' from ' . $attrs['schemaLocation']);
291
+                }
292
+            break;
293
+            case 'complexContent':	// (optional) content for a complexType
294
+                $this->xdebug("do nothing for element $name");
295
+            break;
296
+            case 'complexType':
297
+                array_push($this->complexTypeStack, $this->currentComplexType);
298
+                if(isset($attrs['name'])){
299
+                    // TODO: what is the scope of named complexTypes that appear
300
+                    //       nested within other c complexTypes?
301
+                    $this->xdebug('processing named complexType '.$attrs['name']);
302
+                    //$this->currentElement = false;
303
+                    $this->currentComplexType = $attrs['name'];
304
+                    $this->complexTypes[$this->currentComplexType] = $attrs;
305
+                    $this->complexTypes[$this->currentComplexType]['typeClass'] = 'complexType';
306
+                    // This is for constructs like
307
+                    //           <complexType name="ListOfString" base="soap:Array">
308
+                    //                <sequence>
309
+                    //                    <element name="string" type="xsd:string"
310
+                    //                        minOccurs="0" maxOccurs="unbounded" />
311
+                    //                </sequence>
312
+                    //            </complexType>
313
+                    if(isset($attrs['base']) && preg_match('/:Array$/',$attrs['base'])){
314
+                        $this->xdebug('complexType is unusual array');
315
+                        $this->complexTypes[$this->currentComplexType]['phpType'] = 'array';
316
+                    } else {
317
+                        $this->complexTypes[$this->currentComplexType]['phpType'] = 'struct';
318
+                    }
319
+                } else {
320
+                    $name = $this->CreateTypeName($this->currentElement);
321
+                    $this->xdebug('processing unnamed complexType for element ' . $this->currentElement . ' named ' . $name);
322
+                    $this->currentComplexType = $name;
323
+                    //$this->currentElement = false;
324
+                    $this->complexTypes[$this->currentComplexType] = $attrs;
325
+                    $this->complexTypes[$this->currentComplexType]['typeClass'] = 'complexType';
326
+                    // This is for constructs like
327
+                    //           <complexType name="ListOfString" base="soap:Array">
328
+                    //                <sequence>
329
+                    //                    <element name="string" type="xsd:string"
330
+                    //                        minOccurs="0" maxOccurs="unbounded" />
331
+                    //                </sequence>
332
+                    //            </complexType>
333
+                    if(isset($attrs['base']) && preg_match('/:Array$/',$attrs['base'])){
334
+                        $this->xdebug('complexType is unusual array');
335
+                        $this->complexTypes[$this->currentComplexType]['phpType'] = 'array';
336
+                    } else {
337
+                        $this->complexTypes[$this->currentComplexType]['phpType'] = 'struct';
338
+                    }
339
+                }
340
+                $this->complexTypes[$this->currentComplexType]['simpleContent'] = 'false';
341
+            break;
342
+            case 'element':
343
+                array_push($this->elementStack, $this->currentElement);
344
+                if (!isset($attrs['form'])) {
345
+                    if ($this->currentComplexType) {
346
+                        $attrs['form'] = $this->schemaInfo['elementFormDefault'];
347
+                    } else {
348
+                        // global
349
+                        $attrs['form'] = 'qualified';
350
+                    }
351
+                }
352
+                if(isset($attrs['type'])){
353
+                    $this->xdebug("processing typed element ".$attrs['name']." of type ".$attrs['type']);
354
+                    if (! $this->getPrefix($attrs['type'])) {
355
+                        if ($this->defaultNamespace[$pos]) {
356
+                            $attrs['type'] = $this->defaultNamespace[$pos] . ':' . $attrs['type'];
357
+                            $this->xdebug('used default namespace to make type ' . $attrs['type']);
358
+                        }
359
+                    }
360
+                    // This is for constructs like
361
+                    //           <complexType name="ListOfString" base="soap:Array">
362
+                    //                <sequence>
363
+                    //                    <element name="string" type="xsd:string"
364
+                    //                        minOccurs="0" maxOccurs="unbounded" />
365
+                    //                </sequence>
366
+                    //            </complexType>
367
+                    if ($this->currentComplexType && $this->complexTypes[$this->currentComplexType]['phpType'] == 'array') {
368
+                        $this->xdebug('arrayType for unusual array is ' . $attrs['type']);
369
+                        $this->complexTypes[$this->currentComplexType]['arrayType'] = $attrs['type'];
370
+                    }
371
+                    $this->currentElement = $attrs['name'];
372
+                    $ename = $attrs['name'];
373
+                } elseif(isset($attrs['ref'])){
374
+                    $this->xdebug("processing element as ref to ".$attrs['ref']);
375
+                    $this->currentElement = "ref to ".$attrs['ref'];
376
+                    $ename = $this->getLocalPart($attrs['ref']);
377
+                } else {
378
+                    $type = $this->CreateTypeName($this->currentComplexType . '_' . $attrs['name']);
379
+                    $this->xdebug("processing untyped element " . $attrs['name'] . ' type ' . $type);
380
+                    $this->currentElement = $attrs['name'];
381
+                    $attrs['type'] = $this->schemaTargetNamespace . ':' . $type;
382
+                    $ename = $attrs['name'];
383
+                }
384
+                if (isset($ename) && $this->currentComplexType) {
385
+                    $this->xdebug("add element $ename to complexType $this->currentComplexType");
386
+                    $this->complexTypes[$this->currentComplexType]['elements'][$ename] = $attrs;
387
+                } elseif (!isset($attrs['ref'])) {
388
+                    $this->xdebug("add element $ename to elements array");
389
+                    $this->elements[ $attrs['name'] ] = $attrs;
390
+                    $this->elements[ $attrs['name'] ]['typeClass'] = 'element';
391
+                }
392
+            break;
393
+            case 'enumeration':	//	restriction value list member
394
+                $this->xdebug('enumeration ' . $attrs['value']);
395
+                if ($this->currentSimpleType) {
396
+                    $this->simpleTypes[$this->currentSimpleType]['enumeration'][] = $attrs['value'];
397
+                } elseif ($this->currentComplexType) {
398
+                    $this->complexTypes[$this->currentComplexType]['enumeration'][] = $attrs['value'];
399
+                }
400
+            break;
401
+            case 'extension':	// simpleContent or complexContent type extension
402
+                $this->xdebug('extension ' . $attrs['base']);
403
+                if ($this->currentComplexType) {
404
+                    $ns = $this->getPrefix($attrs['base']);
405
+                    if ($ns == '') {
406
+                        $this->complexTypes[$this->currentComplexType]['extensionBase'] = $this->schemaTargetNamespace . ':' . $attrs['base'];
407
+                    } else {
408
+                        $this->complexTypes[$this->currentComplexType]['extensionBase'] = $attrs['base'];
409
+                    }
410
+                } else {
411
+                    $this->xdebug('no current complexType to set extensionBase');
412
+                }
413
+            break;
414
+            case 'import':
415
+                if (isset($attrs['schemaLocation'])) {
416
+                    $this->xdebug('import namespace ' . $attrs['namespace'] . ' from ' . $attrs['schemaLocation']);
417 417
                     $this->imports[$attrs['namespace']][] = array('location' => $attrs['schemaLocation'], 'loaded' => false);
418
-				} else {
419
-					$this->xdebug('import namespace ' . $attrs['namespace']);
418
+                } else {
419
+                    $this->xdebug('import namespace ' . $attrs['namespace']);
420 420
                     $this->imports[$attrs['namespace']][] = array('location' => '', 'loaded' => true);
421
-					if (! $this->getPrefixFromNamespace($attrs['namespace'])) {
422
-						$this->namespaces['ns'.(count($this->namespaces)+1)] = $attrs['namespace'];
423
-					}
424
-				}
425
-			break;
426
-			case 'include':
427
-			    if (isset($attrs['schemaLocation'])) {
428
-					$this->xdebug('include into namespace ' . $this->schemaTargetNamespace . ' from ' . $attrs['schemaLocation']);
421
+                    if (! $this->getPrefixFromNamespace($attrs['namespace'])) {
422
+                        $this->namespaces['ns'.(count($this->namespaces)+1)] = $attrs['namespace'];
423
+                    }
424
+                }
425
+            break;
426
+            case 'include':
427
+                if (isset($attrs['schemaLocation'])) {
428
+                    $this->xdebug('include into namespace ' . $this->schemaTargetNamespace . ' from ' . $attrs['schemaLocation']);
429 429
                     $this->imports[$this->schemaTargetNamespace][] = array('location' => $attrs['schemaLocation'], 'loaded' => false);
430
-				} else {
431
-					$this->xdebug('ignoring invalid XML Schema construct: include without schemaLocation attribute');
432
-				}
433
-			break;
434
-			case 'list':	// simpleType value list
435
-				$this->xdebug("do nothing for element $name");
436
-			break;
437
-			case 'restriction':	// simpleType, simpleContent or complexContent value restriction
438
-				$this->xdebug('restriction ' . $attrs['base']);
439
-				if($this->currentSimpleType){
440
-					$this->simpleTypes[$this->currentSimpleType]['type'] = $attrs['base'];
441
-				} elseif($this->currentComplexType){
442
-					$this->complexTypes[$this->currentComplexType]['restrictionBase'] = $attrs['base'];
443
-					if(strstr($attrs['base'],':') == ':Array'){
444
-						$this->complexTypes[$this->currentComplexType]['phpType'] = 'array';
445
-					}
446
-				}
447
-			break;
448
-			case 'schema':
449
-				$this->schemaInfo = $attrs;
450
-				$this->schemaInfo['schemaVersion'] = $this->getNamespaceFromPrefix($prefix);
451
-				if (isset($attrs['targetNamespace'])) {
452
-					$this->schemaTargetNamespace = $attrs['targetNamespace'];
453
-				}
454
-				if (!isset($attrs['elementFormDefault'])) {
455
-					$this->schemaInfo['elementFormDefault'] = 'unqualified';
456
-				}
457
-				if (!isset($attrs['attributeFormDefault'])) {
458
-					$this->schemaInfo['attributeFormDefault'] = 'unqualified';
459
-				}
460
-			break;
461
-			case 'simpleContent':	// (optional) content for a complexType
462
-				if ($this->currentComplexType) {	// This should *always* be
463
-					$this->complexTypes[$this->currentComplexType]['simpleContent'] = 'true';
464
-				} else {
465
-					$this->xdebug("do nothing for element $name because there is no current complexType");
466
-				}
467
-			break;
468
-			case 'simpleType':
469
-				array_push($this->simpleTypeStack, $this->currentSimpleType);
470
-				if(isset($attrs['name'])){
471
-					$this->xdebug("processing simpleType for name " . $attrs['name']);
472
-					$this->currentSimpleType = $attrs['name'];
473
-					$this->simpleTypes[ $attrs['name'] ] = $attrs;
474
-					$this->simpleTypes[ $attrs['name'] ]['typeClass'] = 'simpleType';
475
-					$this->simpleTypes[ $attrs['name'] ]['phpType'] = 'scalar';
476
-				} else {
477
-					$name = $this->CreateTypeName($this->currentComplexType . '_' . $this->currentElement);
478
-					$this->xdebug('processing unnamed simpleType for element ' . $this->currentElement . ' named ' . $name);
479
-					$this->currentSimpleType = $name;
480
-					//$this->currentElement = false;
481
-					$this->simpleTypes[$this->currentSimpleType] = $attrs;
482
-					$this->simpleTypes[$this->currentSimpleType]['phpType'] = 'scalar';
483
-				}
484
-			break;
485
-			case 'union':	// simpleType type list
486
-				$this->xdebug("do nothing for element $name");
487
-			break;
488
-			default:
489
-				$this->xdebug("do not have any logic to process element $name");
490
-		}
491
-	}
492
-
493
-	/**
494
-	* end-element handler
495
-	*
496
-	* @param    string $parser XML parser object
497
-	* @param    string $name element name
498
-	* @access   private
499
-	*/
500
-	function schemaEndElement($parser, $name) {
501
-		// bring depth down a notch
502
-		$this->depth--;
503
-		// position of current element is equal to the last value left in depth_array for my depth
504
-		if(isset($this->depth_array[$this->depth])){
505
-        	$pos = $this->depth_array[$this->depth];
430
+                } else {
431
+                    $this->xdebug('ignoring invalid XML Schema construct: include without schemaLocation attribute');
432
+                }
433
+            break;
434
+            case 'list':	// simpleType value list
435
+                $this->xdebug("do nothing for element $name");
436
+            break;
437
+            case 'restriction':	// simpleType, simpleContent or complexContent value restriction
438
+                $this->xdebug('restriction ' . $attrs['base']);
439
+                if($this->currentSimpleType){
440
+                    $this->simpleTypes[$this->currentSimpleType]['type'] = $attrs['base'];
441
+                } elseif($this->currentComplexType){
442
+                    $this->complexTypes[$this->currentComplexType]['restrictionBase'] = $attrs['base'];
443
+                    if(strstr($attrs['base'],':') == ':Array'){
444
+                        $this->complexTypes[$this->currentComplexType]['phpType'] = 'array';
445
+                    }
446
+                }
447
+            break;
448
+            case 'schema':
449
+                $this->schemaInfo = $attrs;
450
+                $this->schemaInfo['schemaVersion'] = $this->getNamespaceFromPrefix($prefix);
451
+                if (isset($attrs['targetNamespace'])) {
452
+                    $this->schemaTargetNamespace = $attrs['targetNamespace'];
453
+                }
454
+                if (!isset($attrs['elementFormDefault'])) {
455
+                    $this->schemaInfo['elementFormDefault'] = 'unqualified';
456
+                }
457
+                if (!isset($attrs['attributeFormDefault'])) {
458
+                    $this->schemaInfo['attributeFormDefault'] = 'unqualified';
459
+                }
460
+            break;
461
+            case 'simpleContent':	// (optional) content for a complexType
462
+                if ($this->currentComplexType) {	// This should *always* be
463
+                    $this->complexTypes[$this->currentComplexType]['simpleContent'] = 'true';
464
+                } else {
465
+                    $this->xdebug("do nothing for element $name because there is no current complexType");
466
+                }
467
+            break;
468
+            case 'simpleType':
469
+                array_push($this->simpleTypeStack, $this->currentSimpleType);
470
+                if(isset($attrs['name'])){
471
+                    $this->xdebug("processing simpleType for name " . $attrs['name']);
472
+                    $this->currentSimpleType = $attrs['name'];
473
+                    $this->simpleTypes[ $attrs['name'] ] = $attrs;
474
+                    $this->simpleTypes[ $attrs['name'] ]['typeClass'] = 'simpleType';
475
+                    $this->simpleTypes[ $attrs['name'] ]['phpType'] = 'scalar';
476
+                } else {
477
+                    $name = $this->CreateTypeName($this->currentComplexType . '_' . $this->currentElement);
478
+                    $this->xdebug('processing unnamed simpleType for element ' . $this->currentElement . ' named ' . $name);
479
+                    $this->currentSimpleType = $name;
480
+                    //$this->currentElement = false;
481
+                    $this->simpleTypes[$this->currentSimpleType] = $attrs;
482
+                    $this->simpleTypes[$this->currentSimpleType]['phpType'] = 'scalar';
483
+                }
484
+            break;
485
+            case 'union':	// simpleType type list
486
+                $this->xdebug("do nothing for element $name");
487
+            break;
488
+            default:
489
+                $this->xdebug("do not have any logic to process element $name");
490
+        }
491
+    }
492
+
493
+    /**
494
+     * end-element handler
495
+     *
496
+     * @param    string $parser XML parser object
497
+     * @param    string $name element name
498
+     * @access   private
499
+     */
500
+    function schemaEndElement($parser, $name) {
501
+        // bring depth down a notch
502
+        $this->depth--;
503
+        // position of current element is equal to the last value left in depth_array for my depth
504
+        if(isset($this->depth_array[$this->depth])){
505
+            $pos = $this->depth_array[$this->depth];
506
+        }
507
+        // get element prefix
508
+        if ($prefix = $this->getPrefix($name)){
509
+            // get unqualified name
510
+            $name = $this->getLocalPart($name);
511
+        } else {
512
+            $prefix = '';
513
+        }
514
+        // move on...
515
+        if($name == 'complexType'){
516
+            $this->xdebug('done processing complexType ' . ($this->currentComplexType ? $this->currentComplexType : '(unknown)'));
517
+            $this->xdebug($this->varDump($this->complexTypes[$this->currentComplexType]));
518
+            $this->currentComplexType = array_pop($this->complexTypeStack);
519
+            //$this->currentElement = false;
520
+        }
521
+        if($name == 'element'){
522
+            $this->xdebug('done processing element ' . ($this->currentElement ? $this->currentElement : '(unknown)'));
523
+            $this->currentElement = array_pop($this->elementStack);
506 524
         }
507
-		// get element prefix
508
-		if ($prefix = $this->getPrefix($name)){
509
-			// get unqualified name
510
-			$name = $this->getLocalPart($name);
511
-		} else {
512
-        	$prefix = '';
525
+        if($name == 'simpleType'){
526
+            $this->xdebug('done processing simpleType ' . ($this->currentSimpleType ? $this->currentSimpleType : '(unknown)'));
527
+            $this->xdebug($this->varDump($this->simpleTypes[$this->currentSimpleType]));
528
+            $this->currentSimpleType = array_pop($this->simpleTypeStack);
513 529
         }
514
-		// move on...
515
-		if($name == 'complexType'){
516
-			$this->xdebug('done processing complexType ' . ($this->currentComplexType ? $this->currentComplexType : '(unknown)'));
517
-			$this->xdebug($this->varDump($this->complexTypes[$this->currentComplexType]));
518
-			$this->currentComplexType = array_pop($this->complexTypeStack);
519
-			//$this->currentElement = false;
520
-		}
521
-		if($name == 'element'){
522
-			$this->xdebug('done processing element ' . ($this->currentElement ? $this->currentElement : '(unknown)'));
523
-			$this->currentElement = array_pop($this->elementStack);
524
-		}
525
-		if($name == 'simpleType'){
526
-			$this->xdebug('done processing simpleType ' . ($this->currentSimpleType ? $this->currentSimpleType : '(unknown)'));
527
-			$this->xdebug($this->varDump($this->simpleTypes[$this->currentSimpleType]));
528
-			$this->currentSimpleType = array_pop($this->simpleTypeStack);
529
-		}
530
-	}
531
-
532
-	/**
533
-	* element content handler
534
-	*
535
-	* @param    string $parser XML parser object
536
-	* @param    string $data element content
537
-	* @access   private
538
-	*/
539
-	function schemaCharacterData($parser, $data){
540
-		$pos = $this->depth_array[$this->depth - 1];
541
-		$this->message[$pos]['cdata'] .= $data;
542
-	}
543
-
544
-	/**
545
-	* serialize the schema
546
-	*
547
-	* @access   public
548
-	*/
549
-	function serializeSchema(){
550
-
551
-		$schemaPrefix = $this->getPrefixFromNamespace($this->XMLSchemaVersion);
552
-		$xml = '';
553
-		// imports
554
-		if (sizeof($this->imports) > 0) {
555
-			foreach($this->imports as $ns => $list) {
556
-				foreach ($list as $ii) {
557
-					if ($ii['location'] != '') {
558
-						$xml .= " <$schemaPrefix:import location=\"" . $ii['location'] . '" namespace="' . $ns . "\" />\n";
559
-					} else {
560
-						$xml .= " <$schemaPrefix:import namespace=\"" . $ns . "\" />\n";
561
-					}
562
-				}
563
-			}
564
-		}
565
-		// complex types
566
-		foreach($this->complexTypes as $typeName => $attrs){
567
-			$contentStr = '';
568
-			// serialize child elements
569
-			if(isset($attrs['elements']) && (count($attrs['elements']) > 0)){
570
-				foreach($attrs['elements'] as $element => $eParts){
571
-					if(isset($eParts['ref'])){
572
-						$contentStr .= "   <$schemaPrefix:element ref=\"$element\"/>\n";
573
-					} else {
574
-						$contentStr .= "   <$schemaPrefix:element name=\"$element\" type=\"" . $this->contractQName($eParts['type']) . "\"";
575
-						foreach ($eParts as $aName => $aValue) {
576
-							// handle, e.g., abstract, default, form, minOccurs, maxOccurs, nillable
577
-							if ($aName != 'name' && $aName != 'type') {
578
-								$contentStr .= " $aName=\"$aValue\"";
579
-							}
580
-						}
581
-						$contentStr .= "/>\n";
582
-					}
583
-				}
584
-				// compositor wraps elements
585
-				if (isset($attrs['compositor']) && ($attrs['compositor'] != '')) {
586
-					$contentStr = "  <$schemaPrefix:$attrs[compositor]>\n".$contentStr."  </$schemaPrefix:$attrs[compositor]>\n";
587
-				}
588
-			}
589
-			// attributes
590
-			if(isset($attrs['attrs']) && (count($attrs['attrs']) >= 1)){
591
-				foreach($attrs['attrs'] as $attr => $aParts){
592
-					$contentStr .= "    <$schemaPrefix:attribute";
593
-					foreach ($aParts as $a => $v) {
594
-						if ($a == 'ref' || $a == 'type') {
595
-							$contentStr .= " $a=\"".$this->contractQName($v).'"';
596
-						} elseif ($a == 'http://schemas.xmlsoap.org/wsdl/:arrayType') {
597
-							$this->usedNamespaces['wsdl'] = $this->namespaces['wsdl'];
598
-							$contentStr .= ' wsdl:arrayType="'.$this->contractQName($v).'"';
599
-						} else {
600
-							$contentStr .= " $a=\"$v\"";
601
-						}
602
-					}
603
-					$contentStr .= "/>\n";
604
-				}
605
-			}
606
-			// if restriction
607
-			if (isset($attrs['restrictionBase']) && $attrs['restrictionBase'] != ''){
608
-				$contentStr = "   <$schemaPrefix:restriction base=\"".$this->contractQName($attrs['restrictionBase'])."\">\n".$contentStr."   </$schemaPrefix:restriction>\n";
609
-				// complex or simple content
610
-				if ((isset($attrs['elements']) && count($attrs['elements']) > 0) || (isset($attrs['attrs']) && count($attrs['attrs']) > 0)){
611
-					$contentStr = "  <$schemaPrefix:complexContent>\n".$contentStr."  </$schemaPrefix:complexContent>\n";
612
-				}
613
-			}
614
-			// finalize complex type
615
-			if($contentStr != ''){
616
-				$contentStr = " <$schemaPrefix:complexType name=\"$typeName\">\n".$contentStr." </$schemaPrefix:complexType>\n";
617
-			} else {
618
-				$contentStr = " <$schemaPrefix:complexType name=\"$typeName\"/>\n";
619
-			}
620
-			$xml .= $contentStr;
621
-		}
622
-		// simple types
623
-		if(isset($this->simpleTypes) && count($this->simpleTypes) > 0){
624
-			foreach($this->simpleTypes as $typeName => $eParts){
625
-				$xml .= " <$schemaPrefix:simpleType name=\"$typeName\">\n  <$schemaPrefix:restriction base=\"".$this->contractQName($eParts['type'])."\">\n";
626
-				if (isset($eParts['enumeration'])) {
627
-					foreach ($eParts['enumeration'] as $e) {
628
-						$xml .= "  <$schemaPrefix:enumeration value=\"$e\"/>\n";
629
-					}
630
-				}
631
-				$xml .= "  </$schemaPrefix:restriction>\n </$schemaPrefix:simpleType>";
632
-			}
633
-		}
634
-		// elements
635
-		if(isset($this->elements) && count($this->elements) > 0){
636
-			foreach($this->elements as $element => $eParts){
637
-				$xml .= " <$schemaPrefix:element name=\"$element\" type=\"".$this->contractQName($eParts['type'])."\"/>\n";
638
-			}
639
-		}
640
-		// attributes
641
-		if(isset($this->attributes) && count($this->attributes) > 0){
642
-			foreach($this->attributes as $attr => $aParts){
643
-				$xml .= " <$schemaPrefix:attribute name=\"$attr\" type=\"".$this->contractQName($aParts['type'])."\"\n/>";
644
-			}
645
-		}
646
-		// finish 'er up
647
-		$attr = '';
648
-		foreach ($this->schemaInfo as $k => $v) {
649
-			if ($k == 'elementFormDefault' || $k == 'attributeFormDefault') {
650
-				$attr .= " $k=\"$v\"";
651
-			}
652
-		}
653
-		$el = "<$schemaPrefix:schema$attr targetNamespace=\"$this->schemaTargetNamespace\"\n";
654
-		foreach (array_diff($this->usedNamespaces, $this->enclosingNamespaces) as $nsp => $ns) {
655
-			$el .= " xmlns:$nsp=\"$ns\"";
656
-		}
657
-		$xml = $el . ">\n".$xml."</$schemaPrefix:schema>\n";
658
-		return $xml;
659
-	}
660
-
661
-	/**
662
-	* adds debug data to the clas level debug string
663
-	*
664
-	* @param    string $string debug data
665
-	* @access   private
666
-	*/
667
-	function xdebug($string){
668
-		$this->debug('<' . $this->schemaTargetNamespace . '> '.$string);
669
-	}
530
+    }
531
+
532
+    /**
533
+     * element content handler
534
+     *
535
+     * @param    string $parser XML parser object
536
+     * @param    string $data element content
537
+     * @access   private
538
+     */
539
+    function schemaCharacterData($parser, $data){
540
+        $pos = $this->depth_array[$this->depth - 1];
541
+        $this->message[$pos]['cdata'] .= $data;
542
+    }
670 543
 
671 544
     /**
672
-    * get the PHP type of a user defined type in the schema
673
-    * PHP type is kind of a misnomer since it actually returns 'struct' for assoc. arrays
674
-    * returns false if no type exists, or not w/ the given namespace
675
-    * else returns a string that is either a native php type, or 'struct'
676
-    *
677
-    * @param string $type name of defined type
678
-    * @param string $ns namespace of type
679
-    * @return mixed
680
-    * @access public
681
-    * @deprecated
682
-    */
683
-	function getPHPType($type,$ns){
684
-		if(isset($this->typemap[$ns][$type])){
685
-			//print "found type '$type' and ns $ns in typemap<br>";
686
-			return $this->typemap[$ns][$type];
687
-		} elseif(isset($this->complexTypes[$type])){
688
-			//print "getting type '$type' and ns $ns from complexTypes array<br>";
689
-			return $this->complexTypes[$type]['phpType'];
690
-		}
691
-		return false;
692
-	}
693
-
694
-	/**
695
-    * returns an associative array of information about a given type
696
-    * returns false if no type exists by the given name
697
-    *
698
-	*	For a complexType typeDef = array(
699
-	*	'restrictionBase' => '',
700
-	*	'phpType' => '',
701
-	*	'compositor' => '(sequence|all)',
702
-	*	'elements' => array(), // refs to elements array
703
-	*	'attrs' => array() // refs to attributes array
704
-	*	... and so on (see addComplexType)
705
-	*	)
706
-	*
707
-	*   For simpleType or element, the array has different keys.
708
-    *
709
-    * @param string $type
710
-    * @return mixed
711
-    * @access public
712
-    * @see addComplexType
713
-    * @see addSimpleType
714
-    * @see addElement
715
-    */
716
-	function getTypeDef($type){
717
-		//$this->debug("in getTypeDef for type $type");
718
-		if (substr($type, -1) == '^') {
719
-			$is_element = 1;
720
-			$type = substr($type, 0, -1);
721
-		} else {
722
-			$is_element = 0;
723
-		}
724
-
725
-		if((! $is_element) && isset($this->complexTypes[$type])){
726
-			$this->xdebug("in getTypeDef, found complexType $type");
727
-			return $this->complexTypes[$type];
728
-		} elseif((! $is_element) && isset($this->simpleTypes[$type])){
729
-			$this->xdebug("in getTypeDef, found simpleType $type");
730
-			if (!isset($this->simpleTypes[$type]['phpType'])) {
731
-				// get info for type to tack onto the simple type
732
-				// TODO: can this ever really apply (i.e. what is a simpleType really?)
733
-				$uqType = substr($this->simpleTypes[$type]['type'], strrpos($this->simpleTypes[$type]['type'], ':') + 1);
734
-				$ns = substr($this->simpleTypes[$type]['type'], 0, strrpos($this->simpleTypes[$type]['type'], ':'));
735
-				$etype = $this->getTypeDef($uqType);
736
-				if ($etype) {
737
-					$this->xdebug("in getTypeDef, found type for simpleType $type:");
738
-					$this->xdebug($this->varDump($etype));
739
-					if (isset($etype['phpType'])) {
740
-						$this->simpleTypes[$type]['phpType'] = $etype['phpType'];
741
-					}
742
-					if (isset($etype['elements'])) {
743
-						$this->simpleTypes[$type]['elements'] = $etype['elements'];
744
-					}
745
-				}
746
-			}
747
-			return $this->simpleTypes[$type];
748
-		} elseif(isset($this->elements[$type])){
749
-			$this->xdebug("in getTypeDef, found element $type");
750
-			if (!isset($this->elements[$type]['phpType'])) {
751
-				// get info for type to tack onto the element
752
-				$uqType = substr($this->elements[$type]['type'], strrpos($this->elements[$type]['type'], ':') + 1);
753
-				$ns = substr($this->elements[$type]['type'], 0, strrpos($this->elements[$type]['type'], ':'));
754
-				$etype = $this->getTypeDef($uqType);
755
-				if ($etype) {
756
-					$this->xdebug("in getTypeDef, found type for element $type:");
757
-					$this->xdebug($this->varDump($etype));
758
-					if (isset($etype['phpType'])) {
759
-						$this->elements[$type]['phpType'] = $etype['phpType'];
760
-					}
761
-					if (isset($etype['elements'])) {
762
-						$this->elements[$type]['elements'] = $etype['elements'];
763
-					}
764
-					if (isset($etype['extensionBase'])) {
765
-						$this->elements[$type]['extensionBase'] = $etype['extensionBase'];
766
-					}
767
-				} elseif ($ns == 'http://www.w3.org/2001/XMLSchema') {
768
-					$this->xdebug("in getTypeDef, element $type is an XSD type");
769
-					$this->elements[$type]['phpType'] = 'scalar';
770
-				}
771
-			}
772
-			return $this->elements[$type];
773
-		} elseif(isset($this->attributes[$type])){
774
-			$this->xdebug("in getTypeDef, found attribute $type");
775
-			return $this->attributes[$type];
776
-		} elseif (preg_match('/_ContainedType$/', $type)) {
777
-			$this->xdebug("in getTypeDef, have an untyped element $type");
778
-			$typeDef['typeClass'] = 'simpleType';
779
-			$typeDef['phpType'] = 'scalar';
780
-			$typeDef['type'] = 'http://www.w3.org/2001/XMLSchema:string';
781
-			return $typeDef;
782
-		}
783
-		$this->xdebug("in getTypeDef, did not find $type");
784
-		return false;
785
-	}
786
-
787
-	/**
788
-    * returns a sample serialization of a given type, or false if no type by the given name
789
-    *
790
-    * @param string $type name of type
791
-    * @return mixed
792
-    * @access public
793
-    * @deprecated
794
-    */
545
+     * serialize the schema
546
+     *
547
+     * @access   public
548
+     */
549
+    function serializeSchema(){
550
+
551
+        $schemaPrefix = $this->getPrefixFromNamespace($this->XMLSchemaVersion);
552
+        $xml = '';
553
+        // imports
554
+        if (sizeof($this->imports) > 0) {
555
+            foreach($this->imports as $ns => $list) {
556
+                foreach ($list as $ii) {
557
+                    if ($ii['location'] != '') {
558
+                        $xml .= " <$schemaPrefix:import location=\"" . $ii['location'] . '" namespace="' . $ns . "\" />\n";
559
+                    } else {
560
+                        $xml .= " <$schemaPrefix:import namespace=\"" . $ns . "\" />\n";
561
+                    }
562
+                }
563
+            }
564
+        }
565
+        // complex types
566
+        foreach($this->complexTypes as $typeName => $attrs){
567
+            $contentStr = '';
568
+            // serialize child elements
569
+            if(isset($attrs['elements']) && (count($attrs['elements']) > 0)){
570
+                foreach($attrs['elements'] as $element => $eParts){
571
+                    if(isset($eParts['ref'])){
572
+                        $contentStr .= "   <$schemaPrefix:element ref=\"$element\"/>\n";
573
+                    } else {
574
+                        $contentStr .= "   <$schemaPrefix:element name=\"$element\" type=\"" . $this->contractQName($eParts['type']) . "\"";
575
+                        foreach ($eParts as $aName => $aValue) {
576
+                            // handle, e.g., abstract, default, form, minOccurs, maxOccurs, nillable
577
+                            if ($aName != 'name' && $aName != 'type') {
578
+                                $contentStr .= " $aName=\"$aValue\"";
579
+                            }
580
+                        }
581
+                        $contentStr .= "/>\n";
582
+                    }
583
+                }
584
+                // compositor wraps elements
585
+                if (isset($attrs['compositor']) && ($attrs['compositor'] != '')) {
586
+                    $contentStr = "  <$schemaPrefix:$attrs[compositor]>\n".$contentStr."  </$schemaPrefix:$attrs[compositor]>\n";
587
+                }
588
+            }
589
+            // attributes
590
+            if(isset($attrs['attrs']) && (count($attrs['attrs']) >= 1)){
591
+                foreach($attrs['attrs'] as $attr => $aParts){
592
+                    $contentStr .= "    <$schemaPrefix:attribute";
593
+                    foreach ($aParts as $a => $v) {
594
+                        if ($a == 'ref' || $a == 'type') {
595
+                            $contentStr .= " $a=\"".$this->contractQName($v).'"';
596
+                        } elseif ($a == 'http://schemas.xmlsoap.org/wsdl/:arrayType') {
597
+                            $this->usedNamespaces['wsdl'] = $this->namespaces['wsdl'];
598
+                            $contentStr .= ' wsdl:arrayType="'.$this->contractQName($v).'"';
599
+                        } else {
600
+                            $contentStr .= " $a=\"$v\"";
601
+                        }
602
+                    }
603
+                    $contentStr .= "/>\n";
604
+                }
605
+            }
606
+            // if restriction
607
+            if (isset($attrs['restrictionBase']) && $attrs['restrictionBase'] != ''){
608
+                $contentStr = "   <$schemaPrefix:restriction base=\"".$this->contractQName($attrs['restrictionBase'])."\">\n".$contentStr."   </$schemaPrefix:restriction>\n";
609
+                // complex or simple content
610
+                if ((isset($attrs['elements']) && count($attrs['elements']) > 0) || (isset($attrs['attrs']) && count($attrs['attrs']) > 0)){
611
+                    $contentStr = "  <$schemaPrefix:complexContent>\n".$contentStr."  </$schemaPrefix:complexContent>\n";
612
+                }
613
+            }
614
+            // finalize complex type
615
+            if($contentStr != ''){
616
+                $contentStr = " <$schemaPrefix:complexType name=\"$typeName\">\n".$contentStr." </$schemaPrefix:complexType>\n";
617
+            } else {
618
+                $contentStr = " <$schemaPrefix:complexType name=\"$typeName\"/>\n";
619
+            }
620
+            $xml .= $contentStr;
621
+        }
622
+        // simple types
623
+        if(isset($this->simpleTypes) && count($this->simpleTypes) > 0){
624
+            foreach($this->simpleTypes as $typeName => $eParts){
625
+                $xml .= " <$schemaPrefix:simpleType name=\"$typeName\">\n  <$schemaPrefix:restriction base=\"".$this->contractQName($eParts['type'])."\">\n";
626
+                if (isset($eParts['enumeration'])) {
627
+                    foreach ($eParts['enumeration'] as $e) {
628
+                        $xml .= "  <$schemaPrefix:enumeration value=\"$e\"/>\n";
629
+                    }
630
+                }
631
+                $xml .= "  </$schemaPrefix:restriction>\n </$schemaPrefix:simpleType>";
632
+            }
633
+        }
634
+        // elements
635
+        if(isset($this->elements) && count($this->elements) > 0){
636
+            foreach($this->elements as $element => $eParts){
637
+                $xml .= " <$schemaPrefix:element name=\"$element\" type=\"".$this->contractQName($eParts['type'])."\"/>\n";
638
+            }
639
+        }
640
+        // attributes
641
+        if(isset($this->attributes) && count($this->attributes) > 0){
642
+            foreach($this->attributes as $attr => $aParts){
643
+                $xml .= " <$schemaPrefix:attribute name=\"$attr\" type=\"".$this->contractQName($aParts['type'])."\"\n/>";
644
+            }
645
+        }
646
+        // finish 'er up
647
+        $attr = '';
648
+        foreach ($this->schemaInfo as $k => $v) {
649
+            if ($k == 'elementFormDefault' || $k == 'attributeFormDefault') {
650
+                $attr .= " $k=\"$v\"";
651
+            }
652
+        }
653
+        $el = "<$schemaPrefix:schema$attr targetNamespace=\"$this->schemaTargetNamespace\"\n";
654
+        foreach (array_diff($this->usedNamespaces, $this->enclosingNamespaces) as $nsp => $ns) {
655
+            $el .= " xmlns:$nsp=\"$ns\"";
656
+        }
657
+        $xml = $el . ">\n".$xml."</$schemaPrefix:schema>\n";
658
+        return $xml;
659
+    }
660
+
661
+    /**
662
+     * adds debug data to the clas level debug string
663
+     *
664
+     * @param    string $string debug data
665
+     * @access   private
666
+     */
667
+    function xdebug($string){
668
+        $this->debug('<' . $this->schemaTargetNamespace . '> '.$string);
669
+    }
670
+
671
+    /**
672
+     * get the PHP type of a user defined type in the schema
673
+     * PHP type is kind of a misnomer since it actually returns 'struct' for assoc. arrays
674
+     * returns false if no type exists, or not w/ the given namespace
675
+     * else returns a string that is either a native php type, or 'struct'
676
+     *
677
+     * @param string $type name of defined type
678
+     * @param string $ns namespace of type
679
+     * @return mixed
680
+     * @access public
681
+     * @deprecated
682
+     */
683
+    function getPHPType($type,$ns){
684
+        if(isset($this->typemap[$ns][$type])){
685
+            //print "found type '$type' and ns $ns in typemap<br>";
686
+            return $this->typemap[$ns][$type];
687
+        } elseif(isset($this->complexTypes[$type])){
688
+            //print "getting type '$type' and ns $ns from complexTypes array<br>";
689
+            return $this->complexTypes[$type]['phpType'];
690
+        }
691
+        return false;
692
+    }
693
+
694
+    /**
695
+     * returns an associative array of information about a given type
696
+     * returns false if no type exists by the given name
697
+     *
698
+     *	For a complexType typeDef = array(
699
+     *	'restrictionBase' => '',
700
+     *	'phpType' => '',
701
+     *	'compositor' => '(sequence|all)',
702
+     *	'elements' => array(), // refs to elements array
703
+     *	'attrs' => array() // refs to attributes array
704
+     *	... and so on (see addComplexType)
705
+     *	)
706
+     *
707
+     *   For simpleType or element, the array has different keys.
708
+     *
709
+     * @param string $type
710
+     * @return mixed
711
+     * @access public
712
+     * @see addComplexType
713
+     * @see addSimpleType
714
+     * @see addElement
715
+     */
716
+    function getTypeDef($type){
717
+        //$this->debug("in getTypeDef for type $type");
718
+        if (substr($type, -1) == '^') {
719
+            $is_element = 1;
720
+            $type = substr($type, 0, -1);
721
+        } else {
722
+            $is_element = 0;
723
+        }
724
+
725
+        if((! $is_element) && isset($this->complexTypes[$type])){
726
+            $this->xdebug("in getTypeDef, found complexType $type");
727
+            return $this->complexTypes[$type];
728
+        } elseif((! $is_element) && isset($this->simpleTypes[$type])){
729
+            $this->xdebug("in getTypeDef, found simpleType $type");
730
+            if (!isset($this->simpleTypes[$type]['phpType'])) {
731
+                // get info for type to tack onto the simple type
732
+                // TODO: can this ever really apply (i.e. what is a simpleType really?)
733
+                $uqType = substr($this->simpleTypes[$type]['type'], strrpos($this->simpleTypes[$type]['type'], ':') + 1);
734
+                $ns = substr($this->simpleTypes[$type]['type'], 0, strrpos($this->simpleTypes[$type]['type'], ':'));
735
+                $etype = $this->getTypeDef($uqType);
736
+                if ($etype) {
737
+                    $this->xdebug("in getTypeDef, found type for simpleType $type:");
738
+                    $this->xdebug($this->varDump($etype));
739
+                    if (isset($etype['phpType'])) {
740
+                        $this->simpleTypes[$type]['phpType'] = $etype['phpType'];
741
+                    }
742
+                    if (isset($etype['elements'])) {
743
+                        $this->simpleTypes[$type]['elements'] = $etype['elements'];
744
+                    }
745
+                }
746
+            }
747
+            return $this->simpleTypes[$type];
748
+        } elseif(isset($this->elements[$type])){
749
+            $this->xdebug("in getTypeDef, found element $type");
750
+            if (!isset($this->elements[$type]['phpType'])) {
751
+                // get info for type to tack onto the element
752
+                $uqType = substr($this->elements[$type]['type'], strrpos($this->elements[$type]['type'], ':') + 1);
753
+                $ns = substr($this->elements[$type]['type'], 0, strrpos($this->elements[$type]['type'], ':'));
754
+                $etype = $this->getTypeDef($uqType);
755
+                if ($etype) {
756
+                    $this->xdebug("in getTypeDef, found type for element $type:");
757
+                    $this->xdebug($this->varDump($etype));
758
+                    if (isset($etype['phpType'])) {
759
+                        $this->elements[$type]['phpType'] = $etype['phpType'];
760
+                    }
761
+                    if (isset($etype['elements'])) {
762
+                        $this->elements[$type]['elements'] = $etype['elements'];
763
+                    }
764
+                    if (isset($etype['extensionBase'])) {
765
+                        $this->elements[$type]['extensionBase'] = $etype['extensionBase'];
766
+                    }
767
+                } elseif ($ns == 'http://www.w3.org/2001/XMLSchema') {
768
+                    $this->xdebug("in getTypeDef, element $type is an XSD type");
769
+                    $this->elements[$type]['phpType'] = 'scalar';
770
+                }
771
+            }
772
+            return $this->elements[$type];
773
+        } elseif(isset($this->attributes[$type])){
774
+            $this->xdebug("in getTypeDef, found attribute $type");
775
+            return $this->attributes[$type];
776
+        } elseif (preg_match('/_ContainedType$/', $type)) {
777
+            $this->xdebug("in getTypeDef, have an untyped element $type");
778
+            $typeDef['typeClass'] = 'simpleType';
779
+            $typeDef['phpType'] = 'scalar';
780
+            $typeDef['type'] = 'http://www.w3.org/2001/XMLSchema:string';
781
+            return $typeDef;
782
+        }
783
+        $this->xdebug("in getTypeDef, did not find $type");
784
+        return false;
785
+    }
786
+
787
+    /**
788
+     * returns a sample serialization of a given type, or false if no type by the given name
789
+     *
790
+     * @param string $type name of type
791
+     * @return mixed
792
+     * @access public
793
+     * @deprecated
794
+     */
795 795
     function serializeTypeDef($type){
796
-    	//print "in sTD() for type $type<br>";
797
-	if($typeDef = $this->getTypeDef($type)){
798
-		$str .= '<'.$type;
799
-	    if(is_array($typeDef['attrs'])){
800
-		foreach($typeDef['attrs'] as $attName => $data){
801
-		    $str .= " $attName=\"{type = ".$data['type']."}\"";
802
-		}
803
-	    }
804
-	    $str .= " xmlns=\"".$this->schema['targetNamespace']."\"";
805
-	    if(count($typeDef['elements']) > 0){
806
-		$str .= ">";
807
-		foreach($typeDef['elements'] as $element => $eData){
808
-		    $str .= $this->serializeTypeDef($element);
809
-		}
810
-		$str .= "</$type>";
811
-	    } elseif($typeDef['typeClass'] == 'element') {
812
-		$str .= "></$type>";
813
-	    } else {
814
-		$str .= "/>";
815
-	    }
816
-			return $str;
817
-	}
818
-    	return false;
796
+        //print "in sTD() for type $type<br>";
797
+    if($typeDef = $this->getTypeDef($type)){
798
+        $str .= '<'.$type;
799
+        if(is_array($typeDef['attrs'])){
800
+        foreach($typeDef['attrs'] as $attName => $data){
801
+            $str .= " $attName=\"{type = ".$data['type']."}\"";
802
+        }
803
+        }
804
+        $str .= " xmlns=\"".$this->schema['targetNamespace']."\"";
805
+        if(count($typeDef['elements']) > 0){
806
+        $str .= ">";
807
+        foreach($typeDef['elements'] as $element => $eData){
808
+            $str .= $this->serializeTypeDef($element);
809
+        }
810
+        $str .= "</$type>";
811
+        } elseif($typeDef['typeClass'] == 'element') {
812
+        $str .= "></$type>";
813
+        } else {
814
+        $str .= "/>";
815
+        }
816
+            return $str;
817
+    }
818
+        return false;
819 819
     }
820 820
 
821 821
     /**
822
-    * returns HTML form elements that allow a user
823
-    * to enter values for creating an instance of the given type.
824
-    *
825
-    * @param string $name name for type instance
826
-    * @param string $type name of type
827
-    * @return string
828
-    * @access public
829
-    * @deprecated
830
-	*/
831
-	function typeToForm($name,$type){
832
-		// get typedef
833
-		if($typeDef = $this->getTypeDef($type)){
834
-			// if struct
835
-			if($typeDef['phpType'] == 'struct'){
836
-				$buffer .= '<table>';
837
-				foreach($typeDef['elements'] as $child => $childDef){
838
-					$buffer .= "
822
+     * returns HTML form elements that allow a user
823
+     * to enter values for creating an instance of the given type.
824
+     *
825
+     * @param string $name name for type instance
826
+     * @param string $type name of type
827
+     * @return string
828
+     * @access public
829
+     * @deprecated
830
+     */
831
+    function typeToForm($name,$type){
832
+        // get typedef
833
+        if($typeDef = $this->getTypeDef($type)){
834
+            // if struct
835
+            if($typeDef['phpType'] == 'struct'){
836
+                $buffer .= '<table>';
837
+                foreach($typeDef['elements'] as $child => $childDef){
838
+                    $buffer .= "
839 839
 					<tr><td align='right'>$childDef[name] (type: ".$this->getLocalPart($childDef['type'])."):</td>
840 840
 					<td><input type='text' name='parameters[".$name."][$childDef[name]]'></td></tr>";
841
-				}
842
-				$buffer .= '</table>';
843
-			// if array
844
-			} elseif($typeDef['phpType'] == 'array'){
845
-				$buffer .= '<table>';
846
-				for($i=0;$i < 3; $i++){
847
-					$buffer .= "
841
+                }
842
+                $buffer .= '</table>';
843
+            // if array
844
+            } elseif($typeDef['phpType'] == 'array'){
845
+                $buffer .= '<table>';
846
+                for($i=0;$i < 3; $i++){
847
+                    $buffer .= "
848 848
 					<tr><td align='right'>array item (type: $typeDef[arrayType]):</td>
849 849
 					<td><input type='text' name='parameters[".$name."][]'></td></tr>";
850
-				}
851
-				$buffer .= '</table>';
852
-			// if scalar
853
-			} else {
854
-				$buffer .= "<input type='text' name='parameters[$name]'>";
855
-			}
856
-		} else {
857
-			$buffer .= "<input type='text' name='parameters[$name]'>";
858
-		}
859
-		return $buffer;
860
-	}
861
-
862
-	/**
863
-	* adds a complex type to the schema
864
-	*
865
-	* example: array
866
-	*
867
-	* addType(
868
-	* 	'ArrayOfstring',
869
-	* 	'complexType',
870
-	* 	'array',
871
-	* 	'',
872
-	* 	'SOAP-ENC:Array',
873
-	* 	array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'string[]'),
874
-	* 	'xsd:string'
875
-	* );
876
-	*
877
-	* example: PHP associative array ( SOAP Struct )
878
-	*
879
-	* addType(
880
-	* 	'SOAPStruct',
881
-	* 	'complexType',
882
-	* 	'struct',
883
-	* 	'all',
884
-	* 	array('myVar'=> array('name'=>'myVar','type'=>'string')
885
-	* );
886
-	*
887
-	* @param name
888
-	* @param typeClass (complexType|simpleType|attribute)
889
-	* @param phpType: currently supported are array and struct (php assoc array)
890
-	* @param compositor (all|sequence|choice)
891
-	* @param restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
892
-	* @param elements = array ( name = array(name=>'',type=>'') )
893
-	* @param attrs = array(
894
-	* 	array(
895
-	*		'ref' => "http://schemas.xmlsoap.org/soap/encoding/:arrayType",
896
-	*		"http://schemas.xmlsoap.org/wsdl/:arrayType" => "string[]"
897
-	* 	)
898
-	* )
899
-	* @param arrayType: namespace:name (http://www.w3.org/2001/XMLSchema:string)
900
-	* @access public
901
-	* @see getTypeDef
902
-	*/
903
-	function addComplexType($name,$typeClass='complexType',$phpType='array',$compositor='',$restrictionBase='',$elements=array(),$attrs=array(),$arrayType=''){
904
-		$this->complexTypes[$name] = array(
905
-	    'name'		=> $name,
906
-	    'typeClass'	=> $typeClass,
907
-	    'phpType'	=> $phpType,
908
-		'compositor'=> $compositor,
909
-	    'restrictionBase' => $restrictionBase,
910
-		'elements'	=> $elements,
911
-	    'attrs'		=> $attrs,
912
-	    'arrayType'	=> $arrayType
913
-		);
914
-
915
-		$this->xdebug("addComplexType $name:");
916
-		$this->appendDebug($this->varDump($this->complexTypes[$name]));
917
-	}
918
-
919
-	/**
920
-	* adds a simple type to the schema
921
-	*
922
-	* @param string $name
923
-	* @param string $restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
924
-	* @param string $typeClass (should always be simpleType)
925
-	* @param string $phpType (should always be scalar)
926
-	* @param array $enumeration array of values
927
-	* @access public
928
-	* @see nusoap_xmlschema
929
-	* @see getTypeDef
930
-	*/
931
-	function addSimpleType($name, $restrictionBase='', $typeClass='simpleType', $phpType='scalar', $enumeration=array()) {
932
-		$this->simpleTypes[$name] = array(
933
-	    'name'			=> $name,
934
-	    'typeClass'		=> $typeClass,
935
-	    'phpType'		=> $phpType,
936
-	    'type'			=> $restrictionBase,
937
-	    'enumeration'	=> $enumeration
938
-		);
939
-
940
-		$this->xdebug("addSimpleType $name:");
941
-		$this->appendDebug($this->varDump($this->simpleTypes[$name]));
942
-	}
943
-
944
-	/**
945
-	* adds an element to the schema
946
-	*
947
-	* @param array $attrs attributes that must include name and type
948
-	* @see nusoap_xmlschema
949
-	* @access public
950
-	*/
951
-	function addElement($attrs) {
952
-		if (! $this->getPrefix($attrs['type'])) {
953
-			$attrs['type'] = $this->schemaTargetNamespace . ':' . $attrs['type'];
954
-		}
955
-		$this->elements[ $attrs['name'] ] = $attrs;
956
-		$this->elements[ $attrs['name'] ]['typeClass'] = 'element';
957
-
958
-		$this->xdebug("addElement " . $attrs['name']);
959
-		$this->appendDebug($this->varDump($this->elements[ $attrs['name'] ]));
960
-	}
850
+                }
851
+                $buffer .= '</table>';
852
+            // if scalar
853
+            } else {
854
+                $buffer .= "<input type='text' name='parameters[$name]'>";
855
+            }
856
+        } else {
857
+            $buffer .= "<input type='text' name='parameters[$name]'>";
858
+        }
859
+        return $buffer;
860
+    }
861
+
862
+    /**
863
+     * adds a complex type to the schema
864
+     *
865
+     * example: array
866
+     *
867
+     * addType(
868
+     * 	'ArrayOfstring',
869
+     * 	'complexType',
870
+     * 	'array',
871
+     * 	'',
872
+     * 	'SOAP-ENC:Array',
873
+     * 	array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'string[]'),
874
+     * 	'xsd:string'
875
+     * );
876
+     *
877
+     * example: PHP associative array ( SOAP Struct )
878
+     *
879
+     * addType(
880
+     * 	'SOAPStruct',
881
+     * 	'complexType',
882
+     * 	'struct',
883
+     * 	'all',
884
+     * 	array('myVar'=> array('name'=>'myVar','type'=>'string')
885
+     * );
886
+     *
887
+     * @param name
888
+     * @param typeClass (complexType|simpleType|attribute)
889
+     * @param phpType: currently supported are array and struct (php assoc array)
890
+     * @param compositor (all|sequence|choice)
891
+     * @param restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
892
+     * @param elements = array ( name = array(name=>'',type=>'') )
893
+     * @param attrs = array(
894
+     * 	array(
895
+     *		'ref' => "http://schemas.xmlsoap.org/soap/encoding/:arrayType",
896
+     *		"http://schemas.xmlsoap.org/wsdl/:arrayType" => "string[]"
897
+     * 	)
898
+     * )
899
+     * @param arrayType: namespace:name (http://www.w3.org/2001/XMLSchema:string)
900
+     * @access public
901
+     * @see getTypeDef
902
+     */
903
+    function addComplexType($name,$typeClass='complexType',$phpType='array',$compositor='',$restrictionBase='',$elements=array(),$attrs=array(),$arrayType=''){
904
+        $this->complexTypes[$name] = array(
905
+        'name'		=> $name,
906
+        'typeClass'	=> $typeClass,
907
+        'phpType'	=> $phpType,
908
+        'compositor'=> $compositor,
909
+        'restrictionBase' => $restrictionBase,
910
+        'elements'	=> $elements,
911
+        'attrs'		=> $attrs,
912
+        'arrayType'	=> $arrayType
913
+        );
914
+
915
+        $this->xdebug("addComplexType $name:");
916
+        $this->appendDebug($this->varDump($this->complexTypes[$name]));
917
+    }
918
+
919
+    /**
920
+     * adds a simple type to the schema
921
+     *
922
+     * @param string $name
923
+     * @param string $restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
924
+     * @param string $typeClass (should always be simpleType)
925
+     * @param string $phpType (should always be scalar)
926
+     * @param array $enumeration array of values
927
+     * @access public
928
+     * @see nusoap_xmlschema
929
+     * @see getTypeDef
930
+     */
931
+    function addSimpleType($name, $restrictionBase='', $typeClass='simpleType', $phpType='scalar', $enumeration=array()) {
932
+        $this->simpleTypes[$name] = array(
933
+        'name'			=> $name,
934
+        'typeClass'		=> $typeClass,
935
+        'phpType'		=> $phpType,
936
+        'type'			=> $restrictionBase,
937
+        'enumeration'	=> $enumeration
938
+        );
939
+
940
+        $this->xdebug("addSimpleType $name:");
941
+        $this->appendDebug($this->varDump($this->simpleTypes[$name]));
942
+    }
943
+
944
+    /**
945
+     * adds an element to the schema
946
+     *
947
+     * @param array $attrs attributes that must include name and type
948
+     * @see nusoap_xmlschema
949
+     * @access public
950
+     */
951
+    function addElement($attrs) {
952
+        if (! $this->getPrefix($attrs['type'])) {
953
+            $attrs['type'] = $this->schemaTargetNamespace . ':' . $attrs['type'];
954
+        }
955
+        $this->elements[ $attrs['name'] ] = $attrs;
956
+        $this->elements[ $attrs['name'] ]['typeClass'] = 'element';
957
+
958
+        $this->xdebug("addElement " . $attrs['name']);
959
+        $this->appendDebug($this->varDump($this->elements[ $attrs['name'] ]));
960
+    }
961 961
 }
962 962
 
963 963
 /**
Please login to merge, or discard this patch.
main/inc/lib/nusoap/nusoapmime.php 1 patch
Indentation   +418 added lines, -418 removed lines patch added patch discarded remove patch
@@ -52,224 +52,224 @@  discard block
 block discarded – undo
52 52
 * @access   public
53 53
 */
54 54
 class nusoap_client_mime extends nusoap_client {
55
-	/**
56
-	 * @var array Each array element in the return is an associative array with keys
57
-	 * data, filename, contenttype, cid
58
-	 * @access private
59
-	 */
60
-	var $requestAttachments = array();
61
-	/**
62
-	 * @var array Each array element in the return is an associative array with keys
63
-	 * data, filename, contenttype, cid
64
-	 * @access private
65
-	 */
66
-	var $responseAttachments;
67
-	/**
68
-	 * @var string
69
-	 * @access private
70
-	 */
71
-	var $mimeContentType;
72
-
73
-	/**
74
-	* adds a MIME attachment to the current request.
75
-	*
76
-	* If the $data parameter contains an empty string, this method will read
77
-	* the contents of the file named by the $filename parameter.
78
-	*
79
-	* If the $cid parameter is false, this method will generate the cid.
80
-	*
81
-	* @param string $data The data of the attachment
82
-	* @param string $filename The filename of the attachment (default is empty string)
83
-	* @param string $contenttype The MIME Content-Type of the attachment (default is application/octet-stream)
84
-	* @param string $cid The content-id (cid) of the attachment (default is false)
85
-	* @return string The content-id (cid) of the attachment
86
-	* @access public
87
-	*/
88
-	function addAttachment($data, $filename = '', $contenttype = 'application/octet-stream', $cid = false) {
89
-		if (! $cid) {
90
-			$cid = md5(uniqid(time()));
91
-		}
92
-
93
-		$info['data'] = $data;
94
-		$info['filename'] = $filename;
95
-		$info['contenttype'] = $contenttype;
96
-		$info['cid'] = $cid;
97
-
98
-		$this->requestAttachments[] = $info;
99
-
100
-		return $cid;
101
-	}
102
-
103
-	/**
104
-	* clears the MIME attachments for the current request.
105
-	*
106
-	* @access public
107
-	*/
108
-	function clearAttachments() {
109
-		$this->requestAttachments = array();
110
-	}
111
-
112
-	/**
113
-	* gets the MIME attachments from the current response.
114
-	*
115
-	* Each array element in the return is an associative array with keys
116
-	* data, filename, contenttype, cid.  These keys correspond to the parameters
117
-	* for addAttachment.
118
-	*
119
-	* @return array The attachments.
120
-	* @access public
121
-	*/
122
-	function getAttachments() {
123
-		return $this->responseAttachments;
124
-	}
125
-
126
-	/**
127
-	* gets the HTTP body for the current request.
128
-	*
129
-	* @param string $soapmsg The SOAP payload
130
-	* @return string The HTTP body, which includes the SOAP payload
131
-	* @access private
132
-	*/
133
-	function getHTTPBody($soapmsg) {
134
-		if (count($this->requestAttachments) > 0) {
135
-			$params['content_type'] = 'multipart/related; type="text/xml"';
136
-			$mimeMessage = new Mail_mimePart('', $params);
137
-			unset($params);
138
-
139
-			$params['content_type'] = 'text/xml';
140
-			$params['encoding']     = '8bit';
141
-			$params['charset']      = $this->soap_defencoding;
142
-			$mimeMessage->addSubpart($soapmsg, $params);
143
-
144
-			foreach ($this->requestAttachments as $att) {
145
-				unset($params);
146
-
147
-				$params['content_type'] = $att['contenttype'];
148
-				$params['encoding']     = 'base64';
149
-				$params['disposition']  = 'attachment';
150
-				$params['dfilename']    = $att['filename'];
151
-				$params['cid']          = $att['cid'];
152
-
153
-				if ($att['data'] == '' && $att['filename'] <> '') {
154
-					if ($fd = fopen($att['filename'], 'rb')) {
155
-						$data = fread($fd, filesize($att['filename']));
156
-						fclose($fd);
157
-					} else {
158
-						$data = '';
159
-					}
160
-					$mimeMessage->addSubpart($data, $params);
161
-				} else {
162
-					$mimeMessage->addSubpart($att['data'], $params);
163
-				}
164
-			}
165
-
166
-			$output = $mimeMessage->encode();
167
-			$mimeHeaders = $output['headers'];
168
-
169
-			foreach ($mimeHeaders as $k => $v) {
170
-				$this->debug("MIME header $k: $v");
171
-				if (strtolower($k) == 'content-type') {
172
-					// PHP header() seems to strip leading whitespace starting
173
-					// the second line, so force everything to one line
174
-					$this->mimeContentType = str_replace("\r\n", " ", $v);
175
-				}
176
-			}
177
-
178
-			return $output['body'];
179
-		}
180
-
181
-		return parent::getHTTPBody($soapmsg);
182
-	}
183
-
184
-	/**
185
-	* gets the HTTP content type for the current request.
186
-	*
187
-	* Note: getHTTPBody must be called before this.
188
-	*
189
-	* @return string the HTTP content type for the current request.
190
-	* @access private
191
-	*/
192
-	function getHTTPContentType() {
193
-		if (count($this->requestAttachments) > 0) {
194
-			return $this->mimeContentType;
195
-		}
196
-		return parent::getHTTPContentType();
197
-	}
198
-
199
-	/**
200
-	* gets the HTTP content type charset for the current request.
201
-	* returns false for non-text content types.
202
-	*
203
-	* Note: getHTTPBody must be called before this.
204
-	*
205
-	* @return string the HTTP content type charset for the current request.
206
-	* @access private
207
-	*/
208
-	function getHTTPContentTypeCharset() {
209
-		if (count($this->requestAttachments) > 0) {
210
-			return false;
211
-		}
212
-		return parent::getHTTPContentTypeCharset();
213
-	}
214
-
215
-	/**
216
-	* processes SOAP message returned from server
217
-	*
218
-	* @param	array	$headers	The HTTP headers
219
-	* @param	string	$data		unprocessed response data from server
220
-	* @return	mixed	value of the message, decoded into a PHP type
221
-	* @access   private
222
-	*/
55
+    /**
56
+     * @var array Each array element in the return is an associative array with keys
57
+     * data, filename, contenttype, cid
58
+     * @access private
59
+     */
60
+    var $requestAttachments = array();
61
+    /**
62
+     * @var array Each array element in the return is an associative array with keys
63
+     * data, filename, contenttype, cid
64
+     * @access private
65
+     */
66
+    var $responseAttachments;
67
+    /**
68
+     * @var string
69
+     * @access private
70
+     */
71
+    var $mimeContentType;
72
+
73
+    /**
74
+     * adds a MIME attachment to the current request.
75
+     *
76
+     * If the $data parameter contains an empty string, this method will read
77
+     * the contents of the file named by the $filename parameter.
78
+     *
79
+     * If the $cid parameter is false, this method will generate the cid.
80
+     *
81
+     * @param string $data The data of the attachment
82
+     * @param string $filename The filename of the attachment (default is empty string)
83
+     * @param string $contenttype The MIME Content-Type of the attachment (default is application/octet-stream)
84
+     * @param string $cid The content-id (cid) of the attachment (default is false)
85
+     * @return string The content-id (cid) of the attachment
86
+     * @access public
87
+     */
88
+    function addAttachment($data, $filename = '', $contenttype = 'application/octet-stream', $cid = false) {
89
+        if (! $cid) {
90
+            $cid = md5(uniqid(time()));
91
+        }
92
+
93
+        $info['data'] = $data;
94
+        $info['filename'] = $filename;
95
+        $info['contenttype'] = $contenttype;
96
+        $info['cid'] = $cid;
97
+
98
+        $this->requestAttachments[] = $info;
99
+
100
+        return $cid;
101
+    }
102
+
103
+    /**
104
+     * clears the MIME attachments for the current request.
105
+     *
106
+     * @access public
107
+     */
108
+    function clearAttachments() {
109
+        $this->requestAttachments = array();
110
+    }
111
+
112
+    /**
113
+     * gets the MIME attachments from the current response.
114
+     *
115
+     * Each array element in the return is an associative array with keys
116
+     * data, filename, contenttype, cid.  These keys correspond to the parameters
117
+     * for addAttachment.
118
+     *
119
+     * @return array The attachments.
120
+     * @access public
121
+     */
122
+    function getAttachments() {
123
+        return $this->responseAttachments;
124
+    }
125
+
126
+    /**
127
+     * gets the HTTP body for the current request.
128
+     *
129
+     * @param string $soapmsg The SOAP payload
130
+     * @return string The HTTP body, which includes the SOAP payload
131
+     * @access private
132
+     */
133
+    function getHTTPBody($soapmsg) {
134
+        if (count($this->requestAttachments) > 0) {
135
+            $params['content_type'] = 'multipart/related; type="text/xml"';
136
+            $mimeMessage = new Mail_mimePart('', $params);
137
+            unset($params);
138
+
139
+            $params['content_type'] = 'text/xml';
140
+            $params['encoding']     = '8bit';
141
+            $params['charset']      = $this->soap_defencoding;
142
+            $mimeMessage->addSubpart($soapmsg, $params);
143
+
144
+            foreach ($this->requestAttachments as $att) {
145
+                unset($params);
146
+
147
+                $params['content_type'] = $att['contenttype'];
148
+                $params['encoding']     = 'base64';
149
+                $params['disposition']  = 'attachment';
150
+                $params['dfilename']    = $att['filename'];
151
+                $params['cid']          = $att['cid'];
152
+
153
+                if ($att['data'] == '' && $att['filename'] <> '') {
154
+                    if ($fd = fopen($att['filename'], 'rb')) {
155
+                        $data = fread($fd, filesize($att['filename']));
156
+                        fclose($fd);
157
+                    } else {
158
+                        $data = '';
159
+                    }
160
+                    $mimeMessage->addSubpart($data, $params);
161
+                } else {
162
+                    $mimeMessage->addSubpart($att['data'], $params);
163
+                }
164
+            }
165
+
166
+            $output = $mimeMessage->encode();
167
+            $mimeHeaders = $output['headers'];
168
+
169
+            foreach ($mimeHeaders as $k => $v) {
170
+                $this->debug("MIME header $k: $v");
171
+                if (strtolower($k) == 'content-type') {
172
+                    // PHP header() seems to strip leading whitespace starting
173
+                    // the second line, so force everything to one line
174
+                    $this->mimeContentType = str_replace("\r\n", " ", $v);
175
+                }
176
+            }
177
+
178
+            return $output['body'];
179
+        }
180
+
181
+        return parent::getHTTPBody($soapmsg);
182
+    }
183
+
184
+    /**
185
+     * gets the HTTP content type for the current request.
186
+     *
187
+     * Note: getHTTPBody must be called before this.
188
+     *
189
+     * @return string the HTTP content type for the current request.
190
+     * @access private
191
+     */
192
+    function getHTTPContentType() {
193
+        if (count($this->requestAttachments) > 0) {
194
+            return $this->mimeContentType;
195
+        }
196
+        return parent::getHTTPContentType();
197
+    }
198
+
199
+    /**
200
+     * gets the HTTP content type charset for the current request.
201
+     * returns false for non-text content types.
202
+     *
203
+     * Note: getHTTPBody must be called before this.
204
+     *
205
+     * @return string the HTTP content type charset for the current request.
206
+     * @access private
207
+     */
208
+    function getHTTPContentTypeCharset() {
209
+        if (count($this->requestAttachments) > 0) {
210
+            return false;
211
+        }
212
+        return parent::getHTTPContentTypeCharset();
213
+    }
214
+
215
+    /**
216
+     * processes SOAP message returned from server
217
+     *
218
+     * @param	array	$headers	The HTTP headers
219
+     * @param	string	$data		unprocessed response data from server
220
+     * @return	mixed	value of the message, decoded into a PHP type
221
+     * @access   private
222
+     */
223 223
     function parseResponse($headers, $data) {
224
-		$this->debug('Entering parseResponse() for payload of length ' . strlen($data) . ' and type of ' . $headers['content-type']);
225
-		$this->responseAttachments = array();
226
-		if (strstr($headers['content-type'], 'multipart/related')) {
227
-			$this->debug('Decode multipart/related');
228
-			$input = '';
229
-			foreach ($headers as $k => $v) {
230
-				$input .= "$k: $v\r\n";
231
-			}
232
-			$params['input'] = $input . "\r\n" . $data;
233
-			$params['include_bodies'] = true;
234
-			$params['decode_bodies'] = true;
235
-			$params['decode_headers'] = true;
236
-
237
-			$structure = Mail_mimeDecode::decode($params);
238
-
239
-			foreach ($structure->parts as $part) {
240
-				if (!isset($part->disposition) && (strstr($part->headers['content-type'], 'text/xml'))) {
241
-					$this->debug('Have root part of type ' . $part->headers['content-type']);
242
-					$root = $part->body;
243
-					$return = parent::parseResponse($part->headers, $part->body);
244
-				} else {
245
-					$this->debug('Have an attachment of type ' . $part->headers['content-type']);
246
-					$info['data'] = $part->body;
247
-					$info['filename'] = isset($part->d_parameters['filename']) ? $part->d_parameters['filename'] : '';
248
-					$info['contenttype'] = $part->headers['content-type'];
249
-					$info['cid'] = $part->headers['content-id'];
250
-					$this->responseAttachments[] = $info;
251
-				}
252
-			}
253
-
254
-			if (isset($return)) {
255
-				$this->responseData = $root;
256
-				return $return;
257
-			}
258
-
259
-			$this->setError('No root part found in multipart/related content');
260
-			return '';
261
-		}
262
-		$this->debug('Not multipart/related');
263
-		return parent::parseResponse($headers, $data);
264
-	}
224
+        $this->debug('Entering parseResponse() for payload of length ' . strlen($data) . ' and type of ' . $headers['content-type']);
225
+        $this->responseAttachments = array();
226
+        if (strstr($headers['content-type'], 'multipart/related')) {
227
+            $this->debug('Decode multipart/related');
228
+            $input = '';
229
+            foreach ($headers as $k => $v) {
230
+                $input .= "$k: $v\r\n";
231
+            }
232
+            $params['input'] = $input . "\r\n" . $data;
233
+            $params['include_bodies'] = true;
234
+            $params['decode_bodies'] = true;
235
+            $params['decode_headers'] = true;
236
+
237
+            $structure = Mail_mimeDecode::decode($params);
238
+
239
+            foreach ($structure->parts as $part) {
240
+                if (!isset($part->disposition) && (strstr($part->headers['content-type'], 'text/xml'))) {
241
+                    $this->debug('Have root part of type ' . $part->headers['content-type']);
242
+                    $root = $part->body;
243
+                    $return = parent::parseResponse($part->headers, $part->body);
244
+                } else {
245
+                    $this->debug('Have an attachment of type ' . $part->headers['content-type']);
246
+                    $info['data'] = $part->body;
247
+                    $info['filename'] = isset($part->d_parameters['filename']) ? $part->d_parameters['filename'] : '';
248
+                    $info['contenttype'] = $part->headers['content-type'];
249
+                    $info['cid'] = $part->headers['content-id'];
250
+                    $this->responseAttachments[] = $info;
251
+                }
252
+            }
253
+
254
+            if (isset($return)) {
255
+                $this->responseData = $root;
256
+                return $return;
257
+            }
258
+
259
+            $this->setError('No root part found in multipart/related content');
260
+            return '';
261
+        }
262
+        $this->debug('Not multipart/related');
263
+        return parent::parseResponse($headers, $data);
264
+    }
265 265
 }
266 266
 
267 267
 /*
268 268
  *	For backwards compatiblity, define soapclientmime unless the PHP SOAP extension is loaded.
269 269
  */
270 270
 if (!extension_loaded('soap')) {
271
-	class soapclientmime extends nusoap_client_mime {
272
-	}
271
+    class soapclientmime extends nusoap_client_mime {
272
+    }
273 273
 }
274 274
 
275 275
 /**
@@ -282,214 +282,214 @@  discard block
 block discarded – undo
282 282
 * @access   public
283 283
 */
284 284
 class nusoap_server_mime extends nusoap_server {
285
-	/**
286
-	 * @var array Each array element in the return is an associative array with keys
287
-	 * data, filename, contenttype, cid
288
-	 * @access private
289
-	 */
290
-	var $requestAttachments = array();
291
-	/**
292
-	 * @var array Each array element in the return is an associative array with keys
293
-	 * data, filename, contenttype, cid
294
-	 * @access private
295
-	 */
296
-	var $responseAttachments;
297
-	/**
298
-	 * @var string
299
-	 * @access private
300
-	 */
301
-	var $mimeContentType;
302
-
303
-	/**
304
-	* adds a MIME attachment to the current response.
305
-	*
306
-	* If the $data parameter contains an empty string, this method will read
307
-	* the contents of the file named by the $filename parameter.
308
-	*
309
-	* If the $cid parameter is false, this method will generate the cid.
310
-	*
311
-	* @param string $data The data of the attachment
312
-	* @param string $filename The filename of the attachment (default is empty string)
313
-	* @param string $contenttype The MIME Content-Type of the attachment (default is application/octet-stream)
314
-	* @param string $cid The content-id (cid) of the attachment (default is false)
315
-	* @return string The content-id (cid) of the attachment
316
-	* @access public
317
-	*/
318
-	function addAttachment($data, $filename = '', $contenttype = 'application/octet-stream', $cid = false) {
319
-		if (! $cid) {
320
-			$cid = md5(uniqid(time()));
321
-		}
322
-
323
-		$info['data'] = $data;
324
-		$info['filename'] = $filename;
325
-		$info['contenttype'] = $contenttype;
326
-		$info['cid'] = $cid;
327
-
328
-		$this->responseAttachments[] = $info;
329
-
330
-		return $cid;
331
-	}
332
-
333
-	/**
334
-	* clears the MIME attachments for the current response.
335
-	*
336
-	* @access public
337
-	*/
338
-	function clearAttachments() {
339
-		$this->responseAttachments = array();
340
-	}
341
-
342
-	/**
343
-	* gets the MIME attachments from the current request.
344
-	*
345
-	* Each array element in the return is an associative array with keys
346
-	* data, filename, contenttype, cid.  These keys correspond to the parameters
347
-	* for addAttachment.
348
-	*
349
-	* @return array The attachments.
350
-	* @access public
351
-	*/
352
-	function getAttachments() {
353
-		return $this->requestAttachments;
354
-	}
355
-
356
-	/**
357
-	* gets the HTTP body for the current response.
358
-	*
359
-	* @param string $soapmsg The SOAP payload
360
-	* @return string The HTTP body, which includes the SOAP payload
361
-	* @access private
362
-	*/
363
-	function getHTTPBody($soapmsg) {
364
-		if (count($this->responseAttachments) > 0) {
365
-			$params['content_type'] = 'multipart/related; type="text/xml"';
366
-			$mimeMessage = new Mail_mimePart('', $params);
367
-			unset($params);
368
-
369
-			$params['content_type'] = 'text/xml';
370
-			$params['encoding']     = '8bit';
371
-			$params['charset']      = $this->soap_defencoding;
372
-			$mimeMessage->addSubpart($soapmsg, $params);
373
-
374
-			foreach ($this->responseAttachments as $att) {
375
-				unset($params);
376
-
377
-				$params['content_type'] = $att['contenttype'];
378
-				$params['encoding']     = 'base64';
379
-				$params['disposition']  = 'attachment';
380
-				$params['dfilename']    = $att['filename'];
381
-				$params['cid']          = $att['cid'];
382
-
383
-				if ($att['data'] == '' && $att['filename'] <> '') {
384
-					if ($fd = fopen($att['filename'], 'rb')) {
385
-						$data = fread($fd, filesize($att['filename']));
386
-						fclose($fd);
387
-					} else {
388
-						$data = '';
389
-					}
390
-					$mimeMessage->addSubpart($data, $params);
391
-				} else {
392
-					$mimeMessage->addSubpart($att['data'], $params);
393
-				}
394
-			}
395
-
396
-			$output = $mimeMessage->encode();
397
-			$mimeHeaders = $output['headers'];
398
-
399
-			foreach ($mimeHeaders as $k => $v) {
400
-				$this->debug("MIME header $k: $v");
401
-				if (strtolower($k) == 'content-type') {
402
-					// PHP header() seems to strip leading whitespace starting
403
-					// the second line, so force everything to one line
404
-					$this->mimeContentType = str_replace("\r\n", " ", $v);
405
-				}
406
-			}
407
-
408
-			return $output['body'];
409
-		}
410
-
411
-		return parent::getHTTPBody($soapmsg);
412
-	}
413
-
414
-	/**
415
-	* gets the HTTP content type for the current response.
416
-	*
417
-	* Note: getHTTPBody must be called before this.
418
-	*
419
-	* @return string the HTTP content type for the current response.
420
-	* @access private
421
-	*/
422
-	function getHTTPContentType() {
423
-		if (count($this->responseAttachments) > 0) {
424
-			return $this->mimeContentType;
425
-		}
426
-		return parent::getHTTPContentType();
427
-	}
428
-
429
-	/**
430
-	* gets the HTTP content type charset for the current response.
431
-	* returns false for non-text content types.
432
-	*
433
-	* Note: getHTTPBody must be called before this.
434
-	*
435
-	* @return string the HTTP content type charset for the current response.
436
-	* @access private
437
-	*/
438
-	function getHTTPContentTypeCharset() {
439
-		if (count($this->responseAttachments) > 0) {
440
-			return false;
441
-		}
442
-		return parent::getHTTPContentTypeCharset();
443
-	}
444
-
445
-	/**
446
-	* processes SOAP message received from client
447
-	*
448
-	* @param	array	$headers	The HTTP headers
449
-	* @param	string	$data		unprocessed request data from client
450
-	* @return	mixed	value of the message, decoded into a PHP type
451
-	* @access   private
452
-	*/
285
+    /**
286
+     * @var array Each array element in the return is an associative array with keys
287
+     * data, filename, contenttype, cid
288
+     * @access private
289
+     */
290
+    var $requestAttachments = array();
291
+    /**
292
+     * @var array Each array element in the return is an associative array with keys
293
+     * data, filename, contenttype, cid
294
+     * @access private
295
+     */
296
+    var $responseAttachments;
297
+    /**
298
+     * @var string
299
+     * @access private
300
+     */
301
+    var $mimeContentType;
302
+
303
+    /**
304
+     * adds a MIME attachment to the current response.
305
+     *
306
+     * If the $data parameter contains an empty string, this method will read
307
+     * the contents of the file named by the $filename parameter.
308
+     *
309
+     * If the $cid parameter is false, this method will generate the cid.
310
+     *
311
+     * @param string $data The data of the attachment
312
+     * @param string $filename The filename of the attachment (default is empty string)
313
+     * @param string $contenttype The MIME Content-Type of the attachment (default is application/octet-stream)
314
+     * @param string $cid The content-id (cid) of the attachment (default is false)
315
+     * @return string The content-id (cid) of the attachment
316
+     * @access public
317
+     */
318
+    function addAttachment($data, $filename = '', $contenttype = 'application/octet-stream', $cid = false) {
319
+        if (! $cid) {
320
+            $cid = md5(uniqid(time()));
321
+        }
322
+
323
+        $info['data'] = $data;
324
+        $info['filename'] = $filename;
325
+        $info['contenttype'] = $contenttype;
326
+        $info['cid'] = $cid;
327
+
328
+        $this->responseAttachments[] = $info;
329
+
330
+        return $cid;
331
+    }
332
+
333
+    /**
334
+     * clears the MIME attachments for the current response.
335
+     *
336
+     * @access public
337
+     */
338
+    function clearAttachments() {
339
+        $this->responseAttachments = array();
340
+    }
341
+
342
+    /**
343
+     * gets the MIME attachments from the current request.
344
+     *
345
+     * Each array element in the return is an associative array with keys
346
+     * data, filename, contenttype, cid.  These keys correspond to the parameters
347
+     * for addAttachment.
348
+     *
349
+     * @return array The attachments.
350
+     * @access public
351
+     */
352
+    function getAttachments() {
353
+        return $this->requestAttachments;
354
+    }
355
+
356
+    /**
357
+     * gets the HTTP body for the current response.
358
+     *
359
+     * @param string $soapmsg The SOAP payload
360
+     * @return string The HTTP body, which includes the SOAP payload
361
+     * @access private
362
+     */
363
+    function getHTTPBody($soapmsg) {
364
+        if (count($this->responseAttachments) > 0) {
365
+            $params['content_type'] = 'multipart/related; type="text/xml"';
366
+            $mimeMessage = new Mail_mimePart('', $params);
367
+            unset($params);
368
+
369
+            $params['content_type'] = 'text/xml';
370
+            $params['encoding']     = '8bit';
371
+            $params['charset']      = $this->soap_defencoding;
372
+            $mimeMessage->addSubpart($soapmsg, $params);
373
+
374
+            foreach ($this->responseAttachments as $att) {
375
+                unset($params);
376
+
377
+                $params['content_type'] = $att['contenttype'];
378
+                $params['encoding']     = 'base64';
379
+                $params['disposition']  = 'attachment';
380
+                $params['dfilename']    = $att['filename'];
381
+                $params['cid']          = $att['cid'];
382
+
383
+                if ($att['data'] == '' && $att['filename'] <> '') {
384
+                    if ($fd = fopen($att['filename'], 'rb')) {
385
+                        $data = fread($fd, filesize($att['filename']));
386
+                        fclose($fd);
387
+                    } else {
388
+                        $data = '';
389
+                    }
390
+                    $mimeMessage->addSubpart($data, $params);
391
+                } else {
392
+                    $mimeMessage->addSubpart($att['data'], $params);
393
+                }
394
+            }
395
+
396
+            $output = $mimeMessage->encode();
397
+            $mimeHeaders = $output['headers'];
398
+
399
+            foreach ($mimeHeaders as $k => $v) {
400
+                $this->debug("MIME header $k: $v");
401
+                if (strtolower($k) == 'content-type') {
402
+                    // PHP header() seems to strip leading whitespace starting
403
+                    // the second line, so force everything to one line
404
+                    $this->mimeContentType = str_replace("\r\n", " ", $v);
405
+                }
406
+            }
407
+
408
+            return $output['body'];
409
+        }
410
+
411
+        return parent::getHTTPBody($soapmsg);
412
+    }
413
+
414
+    /**
415
+     * gets the HTTP content type for the current response.
416
+     *
417
+     * Note: getHTTPBody must be called before this.
418
+     *
419
+     * @return string the HTTP content type for the current response.
420
+     * @access private
421
+     */
422
+    function getHTTPContentType() {
423
+        if (count($this->responseAttachments) > 0) {
424
+            return $this->mimeContentType;
425
+        }
426
+        return parent::getHTTPContentType();
427
+    }
428
+
429
+    /**
430
+     * gets the HTTP content type charset for the current response.
431
+     * returns false for non-text content types.
432
+     *
433
+     * Note: getHTTPBody must be called before this.
434
+     *
435
+     * @return string the HTTP content type charset for the current response.
436
+     * @access private
437
+     */
438
+    function getHTTPContentTypeCharset() {
439
+        if (count($this->responseAttachments) > 0) {
440
+            return false;
441
+        }
442
+        return parent::getHTTPContentTypeCharset();
443
+    }
444
+
445
+    /**
446
+     * processes SOAP message received from client
447
+     *
448
+     * @param	array	$headers	The HTTP headers
449
+     * @param	string	$data		unprocessed request data from client
450
+     * @return	mixed	value of the message, decoded into a PHP type
451
+     * @access   private
452
+     */
453 453
     function parseRequest($headers, $data) {
454
-		$this->debug('Entering parseRequest() for payload of length ' . strlen($data) . ' and type of ' . $headers['content-type']);
455
-		$this->requestAttachments = array();
456
-		if (strstr($headers['content-type'], 'multipart/related')) {
457
-			$this->debug('Decode multipart/related');
458
-			$input = '';
459
-			foreach ($headers as $k => $v) {
460
-				$input .= "$k: $v\r\n";
461
-			}
462
-			$params['input'] = $input . "\r\n" . $data;
463
-			$params['include_bodies'] = true;
464
-			$params['decode_bodies'] = true;
465
-			$params['decode_headers'] = true;
466
-
467
-			$structure = Mail_mimeDecode::decode($params);
468
-
469
-			foreach ($structure->parts as $part) {
470
-				if (!isset($part->disposition) && (strstr($part->headers['content-type'], 'text/xml'))) {
471
-					$this->debug('Have root part of type ' . $part->headers['content-type']);
472
-					$return = parent::parseRequest($part->headers, $part->body);
473
-				} else {
474
-					$this->debug('Have an attachment of type ' . $part->headers['content-type']);
475
-					$info['data'] = $part->body;
476
-					$info['filename'] = isset($part->d_parameters['filename']) ? $part->d_parameters['filename'] : '';
477
-					$info['contenttype'] = $part->headers['content-type'];
478
-					$info['cid'] = $part->headers['content-id'];
479
-					$this->requestAttachments[] = $info;
480
-				}
481
-			}
482
-
483
-			if (isset($return)) {
484
-				return $return;
485
-			}
486
-
487
-			$this->setError('No root part found in multipart/related content');
488
-			return;
489
-		}
490
-		$this->debug('Not multipart/related');
491
-		return parent::parseRequest($headers, $data);
492
-	}
454
+        $this->debug('Entering parseRequest() for payload of length ' . strlen($data) . ' and type of ' . $headers['content-type']);
455
+        $this->requestAttachments = array();
456
+        if (strstr($headers['content-type'], 'multipart/related')) {
457
+            $this->debug('Decode multipart/related');
458
+            $input = '';
459
+            foreach ($headers as $k => $v) {
460
+                $input .= "$k: $v\r\n";
461
+            }
462
+            $params['input'] = $input . "\r\n" . $data;
463
+            $params['include_bodies'] = true;
464
+            $params['decode_bodies'] = true;
465
+            $params['decode_headers'] = true;
466
+
467
+            $structure = Mail_mimeDecode::decode($params);
468
+
469
+            foreach ($structure->parts as $part) {
470
+                if (!isset($part->disposition) && (strstr($part->headers['content-type'], 'text/xml'))) {
471
+                    $this->debug('Have root part of type ' . $part->headers['content-type']);
472
+                    $return = parent::parseRequest($part->headers, $part->body);
473
+                } else {
474
+                    $this->debug('Have an attachment of type ' . $part->headers['content-type']);
475
+                    $info['data'] = $part->body;
476
+                    $info['filename'] = isset($part->d_parameters['filename']) ? $part->d_parameters['filename'] : '';
477
+                    $info['contenttype'] = $part->headers['content-type'];
478
+                    $info['cid'] = $part->headers['content-id'];
479
+                    $this->requestAttachments[] = $info;
480
+                }
481
+            }
482
+
483
+            if (isset($return)) {
484
+                return $return;
485
+            }
486
+
487
+            $this->setError('No root part found in multipart/related content');
488
+            return;
489
+        }
490
+        $this->debug('Not multipart/related');
491
+        return parent::parseRequest($headers, $data);
492
+    }
493 493
 }
494 494
 
495 495
 /*
Please login to merge, or discard this patch.
main/session/index.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
                             if ($exercise_info->start_time != '0000-00-00 00:00:00') {
283 283
                                 $allowed_time = api_strtotime($exercise_info->start_time, 'UTC');
284 284
                                 if ($now < $allowed_time) {
285
-                                      continue;
285
+                                        continue;
286 286
                                 }
287 287
                             }
288 288
                             $exercise_info->exercise = Display::url(
@@ -512,11 +512,11 @@  discard block
 block discarded – undo
512 512
 		window.location.href=ui.tab;
513 513
     });
514 514
 <?php
515
-     //Displays js code to use a jqgrid
516
-     echo Display::grid_js('courses',       '',             $columns_courses, $column_model_courses, $extra_params_courses, $new_course_list);
517
-     echo Display::grid_js('list_default',  $url,           $columns,         $column_model,$extra_params,array(), '');
518
-     echo Display::grid_js('list_course',   $url_by_course, $columns,         $column_model,$extra_params_course,array(),'');
519
-     echo Display::grid_js('list_week',     $url_week,      $column_week,     $column_week_model, $extra_params_week,array(),'');
515
+        //Displays js code to use a jqgrid
516
+        echo Display::grid_js('courses',       '',             $columns_courses, $column_model_courses, $extra_params_courses, $new_course_list);
517
+        echo Display::grid_js('list_default',  $url,           $columns,         $column_model,$extra_params,array(), '');
518
+        echo Display::grid_js('list_course',   $url_by_course, $columns,         $column_model,$extra_params_course,array(),'');
519
+        echo Display::grid_js('list_week',     $url_week,      $column_week,     $column_week_model, $extra_params_week,array(),'');
520 520
 
521 521
     if (!api_is_anonymous()) {
522 522
         echo Display::grid_js('exercises', '', $column_exercise, $column_exercise_model, $extra_params_exercise, $my_real_array);
Please login to merge, or discard this patch.
plugin/ims_lti/OAuthSimple.php 1 patch
Indentation   +186 added lines, -186 removed lines patch added patch discarded remove patch
@@ -18,24 +18,24 @@  discard block
 block discarded – undo
18 18
     private $_nonce_chars;
19 19
 
20 20
     /**
21
-	 * Constructor
21
+     * Constructor
22 22
      *
23
-	 * @access public
23
+     * @access public
24 24
      * @param api_key (String) The API Key (sometimes referred to as the consumer key) This value is usually supplied by the site you wish to use.
25 25
      * @param shared_secret (String) The shared secret. This value is also usually provided by the site you wish to use.
26
-	 * @return OAuthSimple (Object)
26
+     * @return OAuthSimple (Object)
27 27
      */
28 28
     function __construct ($APIKey = "", $sharedSecret=""){
29 29
 
30 30
         if (!empty($APIKey))
31
-		{
32
-			$this->_secrets['consumer_key'] = $APIKey;
33
-		}
31
+        {
32
+            $this->_secrets['consumer_key'] = $APIKey;
33
+        }
34 34
 
35 35
         if (!empty($sharedSecret))
36
-		{
37
-			$this->_secrets['shared_secret'] = $sharedSecret;
38
-		}
36
+        {
37
+            $this->_secrets['shared_secret'] = $sharedSecret;
38
+        }
39 39
 
40 40
         $this->_default_signature_method = "HMAC-SHA1";
41 41
         $this->_action = "GET";
@@ -45,11 +45,11 @@  discard block
 block discarded – undo
45 45
     }
46 46
 
47 47
     /**
48
-	 * Reset the parameters and URL
49
-	 *
50
-	 * @access public
51
-	 * @return OAuthSimple (Object)
52
-	 */
48
+     * Reset the parameters and URL
49
+     *
50
+     * @access public
51
+     * @return OAuthSimple (Object)
52
+     */
53 53
     public function reset() {
54 54
         $this->_parameters = Array();
55 55
         $this->path = NULL;
@@ -59,87 +59,87 @@  discard block
 block discarded – undo
59 59
     }
60 60
 
61 61
     /**
62
-	 * Set the parameters either from a hash or a string
63
-	 *
64
-	 * @access public
65
-	 * @param(string, object) List of parameters for the call, this can either be a URI string (e.g. "foo=bar&gorp=banana" or an object/hash)
66
-	 * @return OAuthSimple (Object)
67
-	 */
62
+     * Set the parameters either from a hash or a string
63
+     *
64
+     * @access public
65
+     * @param(string, object) List of parameters for the call, this can either be a URI string (e.g. "foo=bar&gorp=banana" or an object/hash)
66
+     * @return OAuthSimple (Object)
67
+     */
68 68
     public function setParameters ($parameters=Array()) {
69 69
 
70 70
         if (is_string($parameters))
71
-		{
72
-			$parameters = $this->_parseParameterString($parameters);
73
-		}
71
+        {
72
+            $parameters = $this->_parseParameterString($parameters);
73
+        }
74 74
         if (empty($this->_parameters))
75
-		{
76
-			$this->_parameters = $parameters;
77
-		}
75
+        {
76
+            $this->_parameters = $parameters;
77
+        }
78 78
         else if (!empty($parameters))
79
-		{
80
-			$this->_parameters = array_merge($this->_parameters,$parameters);
81
-		}
79
+        {
80
+            $this->_parameters = array_merge($this->_parameters,$parameters);
81
+        }
82 82
         if (empty($this->_parameters['oauth_nonce']))
83
-		{
84
-			$this->_getNonce();
85
-		}
83
+        {
84
+            $this->_getNonce();
85
+        }
86 86
         if (empty($this->_parameters['oauth_timestamp']))
87
-		{
88
-			 $this->_getTimeStamp();
89
-		}
87
+        {
88
+                $this->_getTimeStamp();
89
+        }
90 90
         if (empty($this->_parameters['oauth_consumer_key']))
91
-		{
92
-			$this->_getApiKey();
93
-		}
91
+        {
92
+            $this->_getApiKey();
93
+        }
94 94
         if (empty($this->_parameters['oauth_token']))
95
-		{
96
-			  $this->_getAccessToken();
97
-		}
95
+        {
96
+                $this->_getAccessToken();
97
+        }
98 98
         if (empty($this->_parameters['oauth_signature_method']))
99
-		{
99
+        {
100 100
             $this->setSignatureMethod();
101
-		}
101
+        }
102 102
         if (empty($this->_parameters['oauth_version']))
103
-		{
103
+        {
104 104
             $this->_parameters['oauth_version']="1.0";
105
-		}
105
+        }
106 106
 
107 107
         return $this;
108 108
     }
109 109
 
110 110
     /**
111
-	 * Convenience method for setParameters
112
-	 *
113
-	 * @access public
114
-	 * @see setParameters
115
-	 */
111
+     * Convenience method for setParameters
112
+     *
113
+     * @access public
114
+     * @see setParameters
115
+     */
116 116
     public function setQueryString ($parameters)
117 117
     {
118 118
         return $this->setParameters($parameters);
119 119
     }
120 120
 
121 121
     /**
122
-	 * Set the target URL (does not include the parameters)
123
-	 *
122
+     * Set the target URL (does not include the parameters)
123
+     *
124 124
      * @param path (String) the fully qualified URI (excluding query arguments) (e.g "http://example.org/foo")
125
-	 * @return OAuthSimple (Object)
125
+     * @return OAuthSimple (Object)
126 126
      */
127 127
     public function setURL ($path)
128
-	{
128
+    {
129 129
         if (empty($path))
130
-		{
130
+        {
131 131
             throw new OAuthSimpleException('No path specified for OAuthSimple.setURL');
132
-		}
132
+        }
133 133
         $this->_path=$path;
134 134
 
135 135
         return $this;
136 136
     }
137 137
 
138 138
     /**
139
-	 * Convenience method for setURL
139
+     * Convenience method for setURL
140 140
      *
141 141
      * @param path (String)
142
-	 * @see setURL
142
+     * @see setURL
143 143
      */
144 144
     public function setPath ($path)
145 145
     {
@@ -147,39 +147,39 @@  discard block
 block discarded – undo
147 147
     }
148 148
 
149 149
     /**
150
-	 * Set the "action" for the url, (e.g. GET,POST, DELETE, etc.)
150
+     * Set the "action" for the url, (e.g. GET,POST, DELETE, etc.)
151 151
      *
152 152
      * @param action (String) HTTP Action word.
153
-	 * @return OAuthSimple (Object)
153
+     * @return OAuthSimple (Object)
154 154
      */
155 155
     public function setAction ($action)
156 156
     {
157 157
         if (empty($action))
158
-		{
159
-			$action = 'GET';
160
-		}
158
+        {
159
+            $action = 'GET';
160
+        }
161 161
         $action = strtoupper($action);
162 162
         if (preg_match('/[^A-Z]/',$action))
163
-		{
163
+        {
164 164
             throw new OAuthSimpleException('Invalid action specified for OAuthSimple.setAction');
165
-		}
165
+        }
166 166
         $this->_action = $action;
167 167
 
168 168
         return $this;
169 169
     }
170 170
 
171 171
     /**
172
-	 * Set the signatures (as well as validate the ones you have)
172
+     * Set the signatures (as well as validate the ones you have)
173 173
      *
174 174
      * @param signatures (object) object/hash of the token/signature pairs {api_key:, shared_secret:, oauth_token: oauth_secret:}
175
-	 * @return OAuthSimple (Object)
175
+     * @return OAuthSimple (Object)
176 176
      */
177 177
     public function signatures ($signatures)
178 178
     {
179 179
         if (!empty($signatures) && !is_array($signatures))
180
-		{
180
+        {
181 181
             throw new OAuthSimpleException('Must pass dictionary array to OAuthSimple.signatures');
182
-		}
182
+        }
183 183
         if (!empty($signatures))
184 184
         {
185 185
             if (empty($this->_secrets))
@@ -189,33 +189,33 @@  discard block
 block discarded – undo
189 189
             $this->_secrets=array_merge($this->_secrets,$signatures);
190 190
         }
191 191
         if (isset($this->_secrets['api_key']))
192
-		{
192
+        {
193 193
             $this->_secrets['consumer_key'] = $this->_secrets['api_key'];
194
-		}
194
+        }
195 195
         if (isset($this->_secrets['access_token']))
196
-		{
196
+        {
197 197
             $this->_secrets['oauth_token'] = $this->_secrets['access_token'];
198
-		}
198
+        }
199 199
         if (isset($this->_secrets['access_secret']))
200
-		{
200
+        {
201 201
             $this->_secrets['shared_secret'] = $this->_secrets['access_secret'];
202 202
         }
203 203
         if (isset($this->_secrets['oauth_token_secret']))
204
-		{
204
+        {
205 205
             $this->_secrets['oauth_secret'] = $this->_secrets['oauth_token_secret'];
206
-		}
206
+        }
207 207
         if (empty($this->_secrets['consumer_key']))
208
-		{
208
+        {
209 209
             throw new OAuthSimpleException('Missing required consumer_key in OAuthSimple.signatures');
210 210
         }
211 211
         if (empty($this->_secrets['shared_secret']))
212
-		{
212
+        {
213 213
             throw new OAuthSimpleException('Missing requires shared_secret in OAuthSimple.signatures');
214
-		}
214
+        }
215 215
         if (!empty($this->_secrets['oauth_token']) && empty($this->_secrets['oauth_secret']))
216
-		{
216
+        {
217 217
             throw new OAuthSimpleException('Missing oauth_secret for supplied oauth_token in OAuthSimple.signatures');
218
-		}
218
+        }
219 219
 
220 220
         return $this;
221 221
     }
@@ -226,30 +226,30 @@  discard block
 block discarded – undo
226 226
     }
227 227
 
228 228
     /**
229
-	 * Set the signature method (currently only Plaintext or SHA-MAC1)
229
+     * Set the signature method (currently only Plaintext or SHA-MAC1)
230 230
      *
231 231
      * @param method (String) Method of signing the transaction (only PLAINTEXT and SHA-MAC1 allowed for now)
232
-	 * @return OAuthSimple (Object)
233
-    */
232
+     * @return OAuthSimple (Object)
233
+     */
234 234
     public function setSignatureMethod ($method="")
235
-	{
235
+    {
236 236
         if (empty($method))
237
-		{
237
+        {
238 238
             $method = $this->_default_signature_method;
239
-		}
239
+        }
240 240
         $method = strtoupper($method);
241 241
         switch($method)
242 242
         {
243 243
             case 'PLAINTEXT':
244 244
             case 'HMAC-SHA1':
245 245
                 $this->_parameters['oauth_signature_method']=$method;
246
-				break;
246
+                break;
247 247
             default:
248 248
                 throw new OAuthSimpleException ("Unknown signing method $method specified for OAuthSimple.setSignatureMethod");
249
-				break;
249
+                break;
250 250
         }
251 251
 
252
-		return $this;
252
+        return $this;
253 253
     }
254 254
 
255 255
     /** sign the request
@@ -258,30 +258,30 @@  discard block
 block discarded – undo
258 258
      * other helper functions.
259 259
      *
260 260
      * @param args (Array) hash of arguments for the call {action, path, parameters (array), method, signatures (array)} all arguments are optional.
261
-	 * @return (Array) signed values
261
+     * @return (Array) signed values
262 262
      */
263 263
     public function sign($args=array())
264 264
     {
265 265
         if (!empty($args['action']))
266
-		{
266
+        {
267 267
             $this->setAction($args['action']);
268
-		}
268
+        }
269 269
         if (!empty($args['path']))
270
-		{
270
+        {
271 271
             $this->setPath($args['path']);
272 272
         }
273 273
         if (!empty($args['method']))
274
-		{
274
+        {
275 275
             $this->setSignatureMethod($args['method']);
276
-		}
276
+        }
277 277
         if (!empty($args['signatures']))
278
-		{
278
+        {
279 279
             $this->signatures($args['signatures']);
280
-		}
280
+        }
281 281
         if (empty($args['parameters']))
282
-		{
282
+        {
283 283
             $args['parameters']=array();
284
-		}
284
+        }
285 285
         $this->setParameters($args['parameters']);
286 286
         $normParams = $this->_normalizedParameters();
287 287
 
@@ -295,29 +295,29 @@  discard block
 block discarded – undo
295 295
     }
296 296
 
297 297
     /**
298
-	 * Return a formatted "header" string
298
+     * Return a formatted "header" string
299 299
      *
300 300
      * NOTE: This doesn't set the "Authorization: " prefix, which is required.
301 301
      * It's not set because various set header functions prefer different
302 302
      * ways to do that.
303 303
      *
304 304
      * @param args (Array)
305
-	 * @return $result (String)
306
-    */
305
+     * @return $result (String)
306
+     */
307 307
     public function getHeaderString ($args=array())
308 308
     {
309 309
         if (empty($this->_parameters['oauth_signature']))
310
-		{
310
+        {
311 311
             $this->sign($args);
312
-		}
312
+        }
313 313
         $result = 'OAuth ';
314 314
 
315 315
         foreach ($this->_parameters as $pName => $pValue)
316 316
         {
317 317
             if (strpos($pName,'oauth_') !== 0)
318
-			{
318
+            {
319 319
                 continue;
320
-			}
320
+            }
321 321
             if (is_array($pValue))
322 322
             {
323 323
                 foreach ($pValue as $val)
@@ -342,19 +342,19 @@  discard block
 block discarded – undo
342 342
         {
343 343
             list ($key,$token) = explode('=',$element);
344 344
             if ($token)
345
-			{
345
+            {
346 346
                 $token = urldecode($token);
347
-			}
347
+            }
348 348
             if (!empty($result[$key]))
349 349
             {
350 350
                 if (!is_array($result[$key]))
351
-				{
351
+                {
352 352
                     $result[$key] = array($result[$key],$token);
353
-				}
353
+                }
354 354
                 else
355
-				{
355
+                {
356 356
                     array_push($result[$key],$token);
357
-				}
357
+                }
358 358
             }
359 359
             else
360 360
                 $result[$key]=$token;
@@ -366,14 +366,14 @@  discard block
 block discarded – undo
366 366
     private static function _oauthEscape($string)
367 367
     {
368 368
         if ($string === 0) { return 0; }
369
-		if ($string == '0') { return '0'; }
369
+        if ($string == '0') { return '0'; }
370 370
         if (strlen($string) == 0) { return ''; }
371 371
         if (is_array($string)) {
372 372
             throw new OAuthSimpleException('Array passed to _oauthEscape');
373
-		}
373
+        }
374 374
         $string = urlencode($string);
375 375
 
376
-	    //FIX: urlencode of ~ and '+'
376
+        //FIX: urlencode of ~ and '+'
377 377
         $string = str_replace(
378 378
             Array('%7E','+'  ), // Replace these
379 379
             Array('~',  '%20'), // with these
@@ -410,13 +410,13 @@  discard block
 block discarded – undo
410 410
     private function _getAccessToken()
411 411
     {
412 412
         if (!isset($this->_secrets['oauth_secret']))
413
-		{
413
+        {
414 414
             return '';
415
-		}
415
+        }
416 416
         if (!isset($this->_secrets['oauth_token']))
417
-		{
417
+        {
418 418
             throw new OAuthSimpleException('No access token (oauth_token) set for OAuthSimple.');
419
-		}
419
+        }
420 420
         $this->_parameters['oauth_token'] = $this->_secrets['oauth_token'];
421 421
 
422 422
         return $this->_parameters['oauth_token'];
@@ -429,8 +429,8 @@  discard block
 block discarded – undo
429 429
 
430 430
     private function _normalizedParameters()
431 431
     {
432
-		$normalized_keys = array();
433
-		$return_array = array();
432
+        $normalized_keys = array();
433
+        $return_array = array();
434 434
 
435 435
         foreach ( $this->_parameters as $paramName=>$paramValue) {
436 436
             if (preg_match('/w+_secret/', $paramName) OR
@@ -439,59 +439,59 @@  discard block
 block discarded – undo
439 439
                 }
440 440
             // Read parameters from a file. Hope you're practicing safe PHP.
441 441
             //if (strpos($paramValue, '@') !== 0 && !file_exists(substr($paramValue, 1)))
442
-			//{
443
-				if (is_array($paramValue))
444
-				{
445
-					$normalized_keys[self::_oauthEscape($paramName)] = array();
446
-					foreach($paramValue as $item)
447
-					{
448
-						array_push($normalized_keys[self::_oauthEscape($paramName)],  self::_oauthEscape($item));
449
-					}
450
-				}
451
-				else
452
-				{
453
-					$normalized_keys[self::_oauthEscape($paramName)] = self::_oauthEscape($paramValue);
454
-				}
455
-			//}
456
-        }
457
-
458
-		ksort($normalized_keys);
459
-
460
-		foreach($normalized_keys as $key=>$val)
461
-		{
462
-			if (is_array($val))
463
-			{
464
-				sort($val);
465
-				foreach($val as $element)
466
-				{
467
-					array_push($return_array, $key . "=" . $element);
468
-				}
469
-			}
470
-			else
471
-			{
472
-				array_push($return_array, $key .'='. $val);
473
-			}
442
+            //{
443
+                if (is_array($paramValue))
444
+                {
445
+                    $normalized_keys[self::_oauthEscape($paramName)] = array();
446
+                    foreach($paramValue as $item)
447
+                    {
448
+                        array_push($normalized_keys[self::_oauthEscape($paramName)],  self::_oauthEscape($item));
449
+                    }
450
+                }
451
+                else
452
+                {
453
+                    $normalized_keys[self::_oauthEscape($paramName)] = self::_oauthEscape($paramValue);
454
+                }
455
+            //}
456
+        }
457
+
458
+        ksort($normalized_keys);
459
+
460
+        foreach($normalized_keys as $key=>$val)
461
+        {
462
+            if (is_array($val))
463
+            {
464
+                sort($val);
465
+                foreach($val as $element)
466
+                {
467
+                    array_push($return_array, $key . "=" . $element);
468
+                }
469
+            }
470
+            else
471
+            {
472
+                array_push($return_array, $key .'='. $val);
473
+            }
474 474
 
475 475
         }
476 476
         $presig = join("&", $return_array);
477 477
         $sig = $this->_generateSignature($presig);
478 478
         $this->_parameters['oauth_signature']=$sig;
479 479
         array_push($return_array, "oauth_signature=$sig");
480
-		return join("&", $return_array);
480
+        return join("&", $return_array);
481 481
     }
482 482
 
483 483
 
484 484
     private function _generateSignature ($parameters="")
485 485
     {
486 486
         $secretKey = '';
487
-		if(isset($this->_secrets['shared_secret']))
488
-		{
489
-			$secretKey = self::_oauthEscape($this->_secrets['shared_secret']);
490
-		}
491
-
492
-		$secretKey .= '&';
493
-		if(isset($this->_secrets['oauth_secret']))
494
-		{
487
+        if(isset($this->_secrets['shared_secret']))
488
+        {
489
+            $secretKey = self::_oauthEscape($this->_secrets['shared_secret']);
490
+        }
491
+
492
+        $secretKey .= '&';
493
+        if(isset($this->_secrets['oauth_secret']))
494
+        {
495 495
             $secretKey .= self::_oauthEscape($this->_secrets['oauth_secret']);
496 496
         }
497 497
         if(!empty($parameters)){
@@ -507,33 +507,33 @@  discard block
 block discarded – undo
507 507
                 return base64_encode(hash_hmac('sha1',$this->sbs,$secretKey,TRUE));
508 508
             default:
509 509
                 throw new OAuthSimpleException('Unknown signature method for OAuthSimple');
510
-				break;
510
+                break;
511 511
         }
512 512
     }
513 513
 }
514 514
 
515 515
 class OAuthSimpleException extends Exception {
516 516
 
517
-	public function __construct($err, $isDebug = FALSE)
518
-	{
519
-		self::log_error($err);
520
-		if ($isDebug)
521
-		{
522
-			self::display_error($err, TRUE);
523
-		}
524
-	}
525
-
526
-	public static function log_error($err)
527
-	{
528
-		error_log($err, 0);
529
-	}
530
-
531
-	public static function display_error($err, $kill = FALSE)
532
-	{
533
-		print_r($err);
534
-		if ($kill === FALSE)
535
-		{
536
-			die();
537
-		}
538
-	}
517
+    public function __construct($err, $isDebug = FALSE)
518
+    {
519
+        self::log_error($err);
520
+        if ($isDebug)
521
+        {
522
+            self::display_error($err, TRUE);
523
+        }
524
+    }
525
+
526
+    public static function log_error($err)
527
+    {
528
+        error_log($err, 0);
529
+    }
530
+
531
+    public static function display_error($err, $kill = FALSE)
532
+    {
533
+        print_r($err);
534
+        if ($kill === FALSE)
535
+        {
536
+            die();
537
+        }
538
+    }
539 539
 }
Please login to merge, or discard this patch.
main/dropbox/index.php 1 patch
Indentation   +424 added lines, -424 removed lines patch added patch discarded remove patch
@@ -7,12 +7,12 @@  discard block
 block discarded – undo
7 7
 $last_access = '';
8 8
 // get the last time the user accessed the tool
9 9
 if (isset($_SESSION[$_course['id']]) && $_SESSION[$_course['id']]['last_access'][TOOL_DROPBOX] == '') {
10
-	$last_access = get_last_tool_access(TOOL_DROPBOX);
11
-	$_SESSION[$_course['id']]['last_access'][TOOL_DROPBOX] = $last_access;
10
+    $last_access = get_last_tool_access(TOOL_DROPBOX);
11
+    $_SESSION[$_course['id']]['last_access'][TOOL_DROPBOX] = $last_access;
12 12
 } else {
13
-	if (isset($_SESSION[$_course['id']])) {
14
-		$last_access = $_SESSION[$_course['id']]['last_access'][TOOL_DROPBOX];
15
-	}
13
+    if (isset($_SESSION[$_course['id']])) {
14
+        $last_access = $_SESSION[$_course['id']]['last_access'][TOOL_DROPBOX];
15
+    }
16 16
 }
17 17
 
18 18
 $postAction = isset($_POST['action']) ? $_POST['action'] : null;
@@ -50,9 +50,9 @@  discard block
 block discarded – undo
50 50
 
51 51
 // Display the form for adding a new dropbox item.
52 52
 if ($action == 'add') {
53
-	if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
54
-		api_not_allowed();
55
-	}
53
+    if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
54
+        api_not_allowed();
55
+    }
56 56
     display_add_form(
57 57
         $dropbox_unid,
58 58
         $viewReceivedCategory,
@@ -62,56 +62,56 @@  discard block
 block discarded – undo
62 62
 }
63 63
 
64 64
 if (isset($_POST['submitWork'])) {
65
-	$check = Security::check_token();
66
-	if ($check) {
65
+    $check = Security::check_token();
66
+    if ($check) {
67 67
         store_add_dropbox();
68
-	}
68
+    }
69 69
 }
70 70
 
71 71
 // Display the form for adding a category
72 72
 if ($action == 'addreceivedcategory' || $action == 'addsentcategory') {
73
-	if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
74
-		api_not_allowed();
75
-	}
76
-	$categoryName = isset($_POST['category_name']) ? $_POST['category_name'] : '';
77
-	display_addcategory_form($categoryName, '', $_GET['action']);
73
+    if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
74
+        api_not_allowed();
75
+    }
76
+    $categoryName = isset($_POST['category_name']) ? $_POST['category_name'] : '';
77
+    display_addcategory_form($categoryName, '', $_GET['action']);
78 78
 }
79 79
 
80 80
 // Editing a category: displaying the form
81 81
 if ($action == 'editcategory' && isset($_GET['id'])) {
82
-	if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
83
-		api_not_allowed();
84
-	}
85
-	if (!$_POST) {
86
-		if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
87
-			api_not_allowed();
88
-		}
89
-		display_addcategory_form('', $_GET['id'], 'editcategory');
90
-	}
82
+    if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
83
+        api_not_allowed();
84
+    }
85
+    if (!$_POST) {
86
+        if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
87
+            api_not_allowed();
88
+        }
89
+        display_addcategory_form('', $_GET['id'], 'editcategory');
90
+    }
91 91
 }
92 92
 
93 93
 // Storing a new or edited category
94 94
 if (isset($_POST['StoreCategory'])) {
95
-	if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
96
-		api_not_allowed();
97
-	}
98
-	$return_information = store_addcategory();
99
-	if ($return_information['type'] == 'confirmation') {
100
-		Display :: display_confirmation_message($return_information['message']);
101
-	}
102
-	if ($return_information['type'] == 'error') {
103
-		Display :: display_error_message(get_lang('FormHasErrorsPleaseComplete').'<br />'.$return_information['message']);
104
-		display_addcategory_form($_POST['category_name'], $_POST['edit_id'], $postAction);
105
-	}
95
+    if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
96
+        api_not_allowed();
97
+    }
98
+    $return_information = store_addcategory();
99
+    if ($return_information['type'] == 'confirmation') {
100
+        Display :: display_confirmation_message($return_information['message']);
101
+    }
102
+    if ($return_information['type'] == 'error') {
103
+        Display :: display_error_message(get_lang('FormHasErrorsPleaseComplete').'<br />'.$return_information['message']);
104
+        display_addcategory_form($_POST['category_name'], $_POST['edit_id'], $postAction);
105
+    }
106 106
 }
107 107
 
108 108
 
109 109
 // Move a File
110 110
 if (($action == 'movesent' || $action == 'movereceived') AND isset($_GET['move_id'])) {
111
-	if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
112
-		api_not_allowed();
113
-	}
114
-	display_move_form(
111
+    if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
112
+        api_not_allowed();
113
+    }
114
+    display_move_form(
115 115
         str_replace('move', '', $action),
116 116
         $_GET['move_id'],
117 117
         get_dropbox_categories(str_replace('move', '', $action)),
@@ -122,33 +122,33 @@  discard block
 block discarded – undo
122 122
     );
123 123
 }
124 124
 if (isset($_POST['do_move'])) {
125
-	Display :: display_confirmation_message(store_move($_POST['id'], $_POST['move_target'], $_POST['part']));
125
+    Display :: display_confirmation_message(store_move($_POST['id'], $_POST['move_target'], $_POST['part']));
126 126
 }
127 127
 
128 128
 // Delete a file
129 129
 if (($action == 'deletereceivedfile' || $action == 'deletesentfile') AND isset($_GET['id']) AND is_numeric($_GET['id'])) {
130
-	if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
131
-		api_not_allowed();
132
-	}
133
-	$dropboxfile = new Dropbox_Person(api_get_user_id(), $is_courseAdmin, $is_courseTutor);
134
-	if ($action == 'deletereceivedfile') {
135
-		$dropboxfile->deleteReceivedWork($_GET['id']);
136
-		$message = get_lang('ReceivedFileDeleted');
137
-	}
138
-	if ($action == 'deletesentfile') {
139
-		$dropboxfile->deleteSentWork($_GET['id']);
140
-		$message = get_lang('SentFileDeleted');
141
-	}
142
-	Display :: display_confirmation_message($message);
130
+    if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
131
+        api_not_allowed();
132
+    }
133
+    $dropboxfile = new Dropbox_Person(api_get_user_id(), $is_courseAdmin, $is_courseTutor);
134
+    if ($action == 'deletereceivedfile') {
135
+        $dropboxfile->deleteReceivedWork($_GET['id']);
136
+        $message = get_lang('ReceivedFileDeleted');
137
+    }
138
+    if ($action == 'deletesentfile') {
139
+        $dropboxfile->deleteSentWork($_GET['id']);
140
+        $message = get_lang('SentFileDeleted');
141
+    }
142
+    Display :: display_confirmation_message($message);
143 143
 }
144 144
 
145 145
 // Delete a category
146 146
 if (($action == 'deletereceivedcategory' || $action == 'deletesentcategory') AND isset($_GET['id']) AND is_numeric($_GET['id'])) {
147
-	if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
148
-		api_not_allowed();
149
-	}
150
-	$message = delete_category($action, $_GET['id']);
151
-	Display :: display_confirmation_message($message);
147
+    if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
148
+        api_not_allowed();
149
+    }
150
+    $message = delete_category($action, $_GET['id']);
151
+    Display :: display_confirmation_message($message);
152 152
 }
153 153
 
154 154
 // Do an action on multiple files
@@ -163,27 +163,27 @@  discard block
 block discarded – undo
163 163
     $postAction == 'delete_sent' ||
164 164
     $postAction == 'download_sent')
165 165
 ) {
166
-	$display_message = handle_multiple_actions();
167
-	Display :: display_normal_message($display_message);
166
+    $display_message = handle_multiple_actions();
167
+    Display :: display_normal_message($display_message);
168 168
 }
169 169
 
170 170
 // Store Feedback
171 171
 
172 172
 if (isset($_POST['feedback'])) {
173
-	if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
174
-		api_not_allowed();
175
-	}
176
-	$check = Security::check_token();
177
-	if ($check) {
178
-		$display_message = store_feedback();
179
-		Display :: display_normal_message($display_message);
180
-		Security::check_token();
181
-	}
173
+    if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
174
+        api_not_allowed();
175
+    }
176
+    $check = Security::check_token();
177
+    if ($check) {
178
+        $display_message = store_feedback();
179
+        Display :: display_normal_message($display_message);
180
+        Security::check_token();
181
+    }
182 182
 }
183 183
 
184 184
 // Error Message
185 185
 if (isset($_GET['error']) AND !empty($_GET['error'])) {
186
-	Display :: display_normal_message(get_lang($_GET['error']));
186
+    Display :: display_normal_message(get_lang($_GET['error']));
187 187
 }
188 188
 
189 189
 $dropbox_data_sent = array();
@@ -191,96 +191,96 @@  discard block
 block discarded – undo
191 191
 $dropbox_data_recieved = array();
192 192
 
193 193
 if ($action != 'add') {
194
-	// Getting all the categories in the dropbox for the given user
195
-	$dropbox_categories = get_dropbox_categories();
196
-	// Greating the arrays with the categories for the received files and for the sent files
197
-	foreach ($dropbox_categories as $category) {
198
-		if ($category['received'] == '1') {
199
-			$dropbox_received_category[] = $category;
200
-		}
201
-		if ($category['sent'] == '1') {
202
-			$dropbox_sent_category[] = $category;
203
-		}
204
-	}
205
-
206
-	// ACTIONS
207
-	if ($view == 'received' || !$showSentReceivedTabs) {
208
-		//echo '<h3>'.get_lang('ReceivedFiles').'</h3>';
209
-
210
-		// This is for the categories
211
-		if (isset($viewReceivedCategory) AND $viewReceivedCategory != '') {
212
-			$view_dropbox_category_received = $viewReceivedCategory;
213
-		} else {
214
-			$view_dropbox_category_received = 0;
215
-		}
216
-
217
-		/* Menu Received */
218
-
219
-		if (api_get_session_id() == 0) {
220
-			echo '<div class="actions">';
221
-			if ($view_dropbox_category_received != 0  && api_is_allowed_to_session_edit(false, true)) {
222
-				echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category=0&view_sent_category='.$viewSentCategory.'&view='.$view.'">'.Display::return_icon('folder_up.png', get_lang('Up').' '.get_lang('Root'),'',ICON_SIZE_MEDIUM)."</a>";
223
-				echo get_lang('Category').': <strong>'.Security::remove_XSS($dropbox_categories[$view_dropbox_category_received]['cat_name']).'</strong> ';
224
-				$movelist[0] = 'Root'; // move_received selectbox content
225
-			} else {
226
-				echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&action=addreceivedcategory&view='.$view.'">'.Display::return_icon('new_folder.png', get_lang('AddNewCategory'),'',ICON_SIZE_MEDIUM).'</a>';
227
-			}
228
-			echo '</div>';
229
-		} else {
230
-			if (api_is_allowed_to_session_edit(false, true)) {
231
-				echo '<div class="actions">';
232
-				if ($view_dropbox_category_received != 0 && api_is_allowed_to_session_edit(false, true)) {
233
-					echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category=0&view_sent_category='.$viewSentCategory.'&view='.$view.'">'.Display::return_icon('folder_up.png', get_lang('Up').' '.get_lang('Root'),'',ICON_SIZE_MEDIUM)."</a>";
234
-					echo get_lang('Category').': <strong>'.Security::remove_XSS($dropbox_categories[$view_dropbox_category_received]['cat_name']).'</strong> ';
235
-					$movelist[0] = 'Root'; // move_received selectbox content
236
-				} else {
237
-					echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&action=addreceivedcategory&view='.$view.'">'.Display::return_icon('new_folder.png', get_lang('AddNewCategory'),'',ICON_SIZE_MEDIUM).'</a>';
238
-				}
239
-				echo '</div>';
240
-			}
241
-		}
242
-	}
243
-
244
-	if (!$view || $view == 'sent' || !$showSentReceivedTabs) {
245
-		// This is for the categories
246
-		if (isset($viewSentCategory) AND $viewSentCategory != '') {
247
-			$view_dropbox_category_sent = $viewSentCategory;
248
-		} else {
249
-			$view_dropbox_category_sent = 0;
250
-		}
251
-
252
-		/* Menu Sent */
253
-
254
-		if (api_get_session_id() == 0) {
255
-			echo '<div class="actions">';
256
-			if ($view_dropbox_category_sent != 0) {
257
-				echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category=0&view='.$view.'">'.Display::return_icon('folder_up.png', get_lang('Up').' '.get_lang('Root'),'',ICON_SIZE_MEDIUM)."</a>";
258
-				echo get_lang('Category').': <strong>'.Security::remove_XSS($dropbox_categories[$view_dropbox_category_sent]['cat_name']).'</strong> ';
259
-			} else {
260
-				echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&view=".$view."&action=addsentcategory\">".Display::return_icon('new_folder.png', get_lang('AddNewCategory'),'',ICON_SIZE_MEDIUM)."</a>\n";
261
-			}
262
-			if (empty($viewSentCategory)) {
263
-				echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&view=".$view."&action=add\">".Display::return_icon('upload_file.png', get_lang('UploadNewFile'),'',ICON_SIZE_MEDIUM)."</a>";
264
-			}
265
-			echo '</div>';
266
-		} else {
267
-			if (api_is_allowed_to_session_edit(false, true)) {
268
-				echo '<div class="actions">';
269
-				if ($view_dropbox_category_sent != 0) {
270
-					echo get_lang('CurrentlySeeing').': <strong>'.Security::remove_XSS($dropbox_categories[$view_dropbox_category_sent]['cat_name']).'</strong> ';
271
-					echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category=0&view='.$view.'">'.Display::return_icon('folder_up.png', get_lang('Up').' '.get_lang('Root'),'',ICON_SIZE_MEDIUM)."</a>";
272
-				} else {
273
-					echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&view=".$view."&action=addsentcategory\">".Display::return_icon('new_folder.png', get_lang('AddNewCategory'),'',ICON_SIZE_MEDIUM)."</a>\n";
274
-				}
275
-				if (empty($viewSentCategory)) {
276
-					echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&view=".$view."&action=add\">".Display::return_icon('upload_file.png', get_lang('UploadNewFile'),'',ICON_SIZE_MEDIUM)."</a>";
277
-				}
278
-				echo '</div>';
279
-			}
280
-		}
281
-	}
282
-	/*	THE MENU TABS */
283
-	if ($showSentReceivedTabs) {
194
+    // Getting all the categories in the dropbox for the given user
195
+    $dropbox_categories = get_dropbox_categories();
196
+    // Greating the arrays with the categories for the received files and for the sent files
197
+    foreach ($dropbox_categories as $category) {
198
+        if ($category['received'] == '1') {
199
+            $dropbox_received_category[] = $category;
200
+        }
201
+        if ($category['sent'] == '1') {
202
+            $dropbox_sent_category[] = $category;
203
+        }
204
+    }
205
+
206
+    // ACTIONS
207
+    if ($view == 'received' || !$showSentReceivedTabs) {
208
+        //echo '<h3>'.get_lang('ReceivedFiles').'</h3>';
209
+
210
+        // This is for the categories
211
+        if (isset($viewReceivedCategory) AND $viewReceivedCategory != '') {
212
+            $view_dropbox_category_received = $viewReceivedCategory;
213
+        } else {
214
+            $view_dropbox_category_received = 0;
215
+        }
216
+
217
+        /* Menu Received */
218
+
219
+        if (api_get_session_id() == 0) {
220
+            echo '<div class="actions">';
221
+            if ($view_dropbox_category_received != 0  && api_is_allowed_to_session_edit(false, true)) {
222
+                echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category=0&view_sent_category='.$viewSentCategory.'&view='.$view.'">'.Display::return_icon('folder_up.png', get_lang('Up').' '.get_lang('Root'),'',ICON_SIZE_MEDIUM)."</a>";
223
+                echo get_lang('Category').': <strong>'.Security::remove_XSS($dropbox_categories[$view_dropbox_category_received]['cat_name']).'</strong> ';
224
+                $movelist[0] = 'Root'; // move_received selectbox content
225
+            } else {
226
+                echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&action=addreceivedcategory&view='.$view.'">'.Display::return_icon('new_folder.png', get_lang('AddNewCategory'),'',ICON_SIZE_MEDIUM).'</a>';
227
+            }
228
+            echo '</div>';
229
+        } else {
230
+            if (api_is_allowed_to_session_edit(false, true)) {
231
+                echo '<div class="actions">';
232
+                if ($view_dropbox_category_received != 0 && api_is_allowed_to_session_edit(false, true)) {
233
+                    echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category=0&view_sent_category='.$viewSentCategory.'&view='.$view.'">'.Display::return_icon('folder_up.png', get_lang('Up').' '.get_lang('Root'),'',ICON_SIZE_MEDIUM)."</a>";
234
+                    echo get_lang('Category').': <strong>'.Security::remove_XSS($dropbox_categories[$view_dropbox_category_received]['cat_name']).'</strong> ';
235
+                    $movelist[0] = 'Root'; // move_received selectbox content
236
+                } else {
237
+                    echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&action=addreceivedcategory&view='.$view.'">'.Display::return_icon('new_folder.png', get_lang('AddNewCategory'),'',ICON_SIZE_MEDIUM).'</a>';
238
+                }
239
+                echo '</div>';
240
+            }
241
+        }
242
+    }
243
+
244
+    if (!$view || $view == 'sent' || !$showSentReceivedTabs) {
245
+        // This is for the categories
246
+        if (isset($viewSentCategory) AND $viewSentCategory != '') {
247
+            $view_dropbox_category_sent = $viewSentCategory;
248
+        } else {
249
+            $view_dropbox_category_sent = 0;
250
+        }
251
+
252
+        /* Menu Sent */
253
+
254
+        if (api_get_session_id() == 0) {
255
+            echo '<div class="actions">';
256
+            if ($view_dropbox_category_sent != 0) {
257
+                echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category=0&view='.$view.'">'.Display::return_icon('folder_up.png', get_lang('Up').' '.get_lang('Root'),'',ICON_SIZE_MEDIUM)."</a>";
258
+                echo get_lang('Category').': <strong>'.Security::remove_XSS($dropbox_categories[$view_dropbox_category_sent]['cat_name']).'</strong> ';
259
+            } else {
260
+                echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&view=".$view."&action=addsentcategory\">".Display::return_icon('new_folder.png', get_lang('AddNewCategory'),'',ICON_SIZE_MEDIUM)."</a>\n";
261
+            }
262
+            if (empty($viewSentCategory)) {
263
+                echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&view=".$view."&action=add\">".Display::return_icon('upload_file.png', get_lang('UploadNewFile'),'',ICON_SIZE_MEDIUM)."</a>";
264
+            }
265
+            echo '</div>';
266
+        } else {
267
+            if (api_is_allowed_to_session_edit(false, true)) {
268
+                echo '<div class="actions">';
269
+                if ($view_dropbox_category_sent != 0) {
270
+                    echo get_lang('CurrentlySeeing').': <strong>'.Security::remove_XSS($dropbox_categories[$view_dropbox_category_sent]['cat_name']).'</strong> ';
271
+                    echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category=0&view='.$view.'">'.Display::return_icon('folder_up.png', get_lang('Up').' '.get_lang('Root'),'',ICON_SIZE_MEDIUM)."</a>";
272
+                } else {
273
+                    echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&view=".$view."&action=addsentcategory\">".Display::return_icon('new_folder.png', get_lang('AddNewCategory'),'',ICON_SIZE_MEDIUM)."</a>\n";
274
+                }
275
+                if (empty($viewSentCategory)) {
276
+                    echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&view=".$view."&action=add\">".Display::return_icon('upload_file.png', get_lang('UploadNewFile'),'',ICON_SIZE_MEDIUM)."</a>";
277
+                }
278
+                echo '</div>';
279
+            }
280
+        }
281
+    }
282
+    /*	THE MENU TABS */
283
+    if ($showSentReceivedTabs) {
284 284
 ?>
285 285
 <ul class="nav nav-tabs">
286 286
     <li <?php if (!$view || $view == 'sent') { echo 'class="active"'; } ?> >
@@ -294,80 +294,80 @@  discard block
 block discarded – undo
294 294
     </li>
295 295
 </ul>
296 296
 <?php
297
-	}
297
+    }
298 298
     /*	RECEIVED FILES */
299
-	if ($view == 'received' || !$showSentReceivedTabs) {
300
-		// This is for the categories
301
-		if (isset($viewReceivedCategory) AND $viewReceivedCategory != '') {
302
-			$view_dropbox_category_received = $viewReceivedCategory;
303
-		} else {
304
-			$view_dropbox_category_received = 0;
305
-		}
306
-
307
-		// Object initialisation
308
-		$dropbox_person = new Dropbox_Person(api_get_user_id(), $is_courseAdmin, $is_courseTutor);
309
-		 // note: are the $is_courseAdmin and $is_courseTutor parameters needed????
310
-
311
-		// Constructing the array that contains the total number of feedback messages per document.
312
-		$number_feedback = get_total_number_feedback();
313
-
314
-		// Sorting and paging options
315
-		$sorting_options = array();
316
-		$paging_options = array();
317
-
318
-		// The headers of the sortable tables
319
-		$column_header = array();
320
-		$column_header[] = array('', false, '');
321
-		$column_header[] = array(get_lang('Type'), true, 'style="width:40px"', 'style="text-align:center"');
322
-		$column_header[] = array(get_lang('ReceivedTitle'), true, '');
323
-		$column_header[] = array(get_lang('Size'), true, '');
324
-		$column_header[] = array(get_lang('Authors'), true, '');
325
-		$column_header[] = array(get_lang('LastResent'), true);
326
-
327
-		if (api_get_session_id() == 0) {
328
-			$column_header[] = array(get_lang('Modify'), false, '', 'nowrap style="text-align: right"');
329
-		} elseif (api_is_allowed_to_session_edit(false,true)) {
330
-			$column_header[] = array(get_lang('Modify'), false, '', 'nowrap style="text-align: right"');
331
-		}
332
-
333
-		$column_header[] = array('RealDate', true);
334
-		$column_header[] = array('RealSize', true);
335
-
336
-		// An array with the setting of the columns -> 1: columns that we will show, 0:columns that will be hide
337
-		$column_show[] = 1;
338
-		$column_show[] = 1;
339
-		$column_show[] = 1;
340
-		$column_show[] = 1;
341
-		$column_show[] = 1;
342
-		$column_show[] = 1;
343
-
344
-		if (api_get_session_id() == 0) {
345
-			$column_show[] = 1;
346
-		} elseif (api_is_allowed_to_session_edit(false, true)) {
347
-			$column_show[] = 1;
348
-		}
349
-		$column_show[] = 0;
350
-
351
-		// Here we change the way how the columns are going to be sort
352
-		// in this case the the column of LastResent ( 4th element in $column_header) we will be order like the column RealDate
353
-		// because in the column RealDate we have the days in a correct format "2008-03-12 10:35:48"
354
-
355
-		$column_order[3] = 8;
356
-		$column_order[5] = 7;
357
-
358
-		// The content of the sortable table = the received files
359
-		foreach ($dropbox_person -> receivedWork as $dropbox_file) {
360
-			$dropbox_file_data = array();
361
-			if ($view_dropbox_category_received == $dropbox_file->category) {
299
+    if ($view == 'received' || !$showSentReceivedTabs) {
300
+        // This is for the categories
301
+        if (isset($viewReceivedCategory) AND $viewReceivedCategory != '') {
302
+            $view_dropbox_category_received = $viewReceivedCategory;
303
+        } else {
304
+            $view_dropbox_category_received = 0;
305
+        }
306
+
307
+        // Object initialisation
308
+        $dropbox_person = new Dropbox_Person(api_get_user_id(), $is_courseAdmin, $is_courseTutor);
309
+            // note: are the $is_courseAdmin and $is_courseTutor parameters needed????
310
+
311
+        // Constructing the array that contains the total number of feedback messages per document.
312
+        $number_feedback = get_total_number_feedback();
313
+
314
+        // Sorting and paging options
315
+        $sorting_options = array();
316
+        $paging_options = array();
317
+
318
+        // The headers of the sortable tables
319
+        $column_header = array();
320
+        $column_header[] = array('', false, '');
321
+        $column_header[] = array(get_lang('Type'), true, 'style="width:40px"', 'style="text-align:center"');
322
+        $column_header[] = array(get_lang('ReceivedTitle'), true, '');
323
+        $column_header[] = array(get_lang('Size'), true, '');
324
+        $column_header[] = array(get_lang('Authors'), true, '');
325
+        $column_header[] = array(get_lang('LastResent'), true);
326
+
327
+        if (api_get_session_id() == 0) {
328
+            $column_header[] = array(get_lang('Modify'), false, '', 'nowrap style="text-align: right"');
329
+        } elseif (api_is_allowed_to_session_edit(false,true)) {
330
+            $column_header[] = array(get_lang('Modify'), false, '', 'nowrap style="text-align: right"');
331
+        }
332
+
333
+        $column_header[] = array('RealDate', true);
334
+        $column_header[] = array('RealSize', true);
335
+
336
+        // An array with the setting of the columns -> 1: columns that we will show, 0:columns that will be hide
337
+        $column_show[] = 1;
338
+        $column_show[] = 1;
339
+        $column_show[] = 1;
340
+        $column_show[] = 1;
341
+        $column_show[] = 1;
342
+        $column_show[] = 1;
343
+
344
+        if (api_get_session_id() == 0) {
345
+            $column_show[] = 1;
346
+        } elseif (api_is_allowed_to_session_edit(false, true)) {
347
+            $column_show[] = 1;
348
+        }
349
+        $column_show[] = 0;
350
+
351
+        // Here we change the way how the columns are going to be sort
352
+        // in this case the the column of LastResent ( 4th element in $column_header) we will be order like the column RealDate
353
+        // because in the column RealDate we have the days in a correct format "2008-03-12 10:35:48"
354
+
355
+        $column_order[3] = 8;
356
+        $column_order[5] = 7;
357
+
358
+        // The content of the sortable table = the received files
359
+        foreach ($dropbox_person -> receivedWork as $dropbox_file) {
360
+            $dropbox_file_data = array();
361
+            if ($view_dropbox_category_received == $dropbox_file->category) {
362 362
                 // we only display the files that are in the category that we are in.
363
-				$dropbox_file_data[] = $dropbox_file->id;
363
+                $dropbox_file_data[] = $dropbox_file->id;
364 364
 
365
-				if (isset($_SESSION['_seen']) && !is_array($_SESSION['_seen'][$_course['id']][TOOL_DROPBOX])) {
366
-					$_SESSION['_seen'][$_course['id']][TOOL_DROPBOX] = array();
367
-				}
365
+                if (isset($_SESSION['_seen']) && !is_array($_SESSION['_seen'][$_course['id']][TOOL_DROPBOX])) {
366
+                    $_SESSION['_seen'][$_course['id']][TOOL_DROPBOX] = array();
367
+                }
368 368
 
369
-				// New icon
370
-				$new_icon = '';
369
+                // New icon
370
+                $new_icon = '';
371 371
                 if (isset($_SESSION['_seen'])) {
372 372
                     if ($dropbox_file->last_upload_date > $last_access &&
373 373
                         !in_array(
@@ -384,12 +384,12 @@  discard block
 block discarded – undo
384 384
                     }
385 385
                 }
386 386
 
387
-				$link_open = '<a href="'.api_get_path(WEB_CODE_PATH).'dropbox/dropbox_download.php?'.api_get_cidreq().'&id='.$dropbox_file->id.'">';
388
-				$dropbox_file_data[] = $link_open.DocumentManager::build_document_icon_tag('file', $dropbox_file->title).'</a>';
389
-				$dropbox_file_data[] = '<a href="'.api_get_path(WEB_CODE_PATH).'dropbox/dropbox_download.php?'.api_get_cidreq().'&id='.$dropbox_file->id.'&action=download">'.
387
+                $link_open = '<a href="'.api_get_path(WEB_CODE_PATH).'dropbox/dropbox_download.php?'.api_get_cidreq().'&id='.$dropbox_file->id.'">';
388
+                $dropbox_file_data[] = $link_open.DocumentManager::build_document_icon_tag('file', $dropbox_file->title).'</a>';
389
+                $dropbox_file_data[] = '<a href="'.api_get_path(WEB_CODE_PATH).'dropbox/dropbox_download.php?'.api_get_cidreq().'&id='.$dropbox_file->id.'&action=download">'.
390 390
                     Display::return_icon('save.png', get_lang('Download'), array('style' => 'float:right;'),ICON_SIZE_SMALL).'</a>'.$link_open.$dropbox_file->title.'</a>'.$new_icon.'<br />'.$dropbox_file->description;
391
-				$file_size = $dropbox_file->filesize;
392
-				$dropbox_file_data[] = format_file_size($file_size);
391
+                $file_size = $dropbox_file->filesize;
392
+                $dropbox_file_data[] = format_file_size($file_size);
393 393
 
394 394
                 $authorInfo = api_get_user_info($dropbox_file->uploader_id);
395 395
                 if ($authorInfo) {
@@ -398,62 +398,62 @@  discard block
 block discarded – undo
398 398
                     $dropbox_file_data[] = '';
399 399
                 }
400 400
 
401
-				$last_upload_date = api_get_local_time($dropbox_file->last_upload_date);
402
-				$dropbox_file_data[] = date_to_str_ago($dropbox_file->last_upload_date).'<br /><span class="dropbox_date">'.
401
+                $last_upload_date = api_get_local_time($dropbox_file->last_upload_date);
402
+                $dropbox_file_data[] = date_to_str_ago($dropbox_file->last_upload_date).'<br /><span class="dropbox_date">'.
403 403
                     api_format_date($last_upload_date).'</span>';
404 404
 
405
-				$action_icons = check_number_feedback($dropbox_file->id, $number_feedback).' '.get_lang('Feedback').'
405
+                $action_icons = check_number_feedback($dropbox_file->id, $number_feedback).' '.get_lang('Feedback').'
406 406
                 <a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=viewfeedback&id='.$dropbox_file->id.'&'.$sort_params.'">'.Display::return_icon('discuss.png', get_lang('Comment'),'',ICON_SIZE_SMALL).'</a>
407 407
                 <a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=movereceived&move_id='.$dropbox_file->id.'&'.$sort_params.'">'.Display::return_icon('move.png', get_lang('Move'),'',ICON_SIZE_SMALL).'</a>
408 408
                 <a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=deletereceivedfile&id='.$dropbox_file->id.'&'.$sort_params.'" onclick="javascript: return confirmation(\''.$dropbox_file->title.'\');">'.
409 409
                 Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>';
410 410
 
411
-				// This is a hack to have an additional row in a sortable table
412
-
413
-				if ($action == 'viewfeedback' AND isset($_GET['id']) and is_numeric($_GET['id']) AND $dropbox_file->id == $_GET['id']) {
414
-					$action_icons .= "</td></tr>"; // Ending the normal row of the sortable table
415
-					$action_icons .= '<tr><td colspan="2"><a href="'.api_get_path(WEB_CODE_PATH).'dropbox/index.php?"'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory."&view_sent_category=".$viewSentCategory."&view=".$view.'&'.$sort_params."\">".get_lang('CloseFeedback')."</a></td><td colspan=\"7\">".feedback($dropbox_file->feedback2)."</td></tr>";
416
-				}
417
-				if (api_get_session_id() == 0) {
418
-					$dropbox_file_data[] = $action_icons;
419
-				} elseif (api_is_allowed_to_session_edit(false, true)) {
420
-					$dropbox_file_data[] = $action_icons;
421
-				}
422
-				$action_icons = '';
423
-				$dropbox_file_data[] = $last_upload_date;
424
-				$dropbox_file_data[] = $file_size;
425
-				$dropbox_data_recieved[] = $dropbox_file_data;
426
-			}
427
-		}
428
-
429
-		// The content of the sortable table = the categories (if we are not in the root)
430
-		if ($view_dropbox_category_received == 0) {
431
-			foreach ($dropbox_categories as $category) {
432
-			    /*  Note: This can probably be shortened since the categories
411
+                // This is a hack to have an additional row in a sortable table
412
+
413
+                if ($action == 'viewfeedback' AND isset($_GET['id']) and is_numeric($_GET['id']) AND $dropbox_file->id == $_GET['id']) {
414
+                    $action_icons .= "</td></tr>"; // Ending the normal row of the sortable table
415
+                    $action_icons .= '<tr><td colspan="2"><a href="'.api_get_path(WEB_CODE_PATH).'dropbox/index.php?"'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory."&view_sent_category=".$viewSentCategory."&view=".$view.'&'.$sort_params."\">".get_lang('CloseFeedback')."</a></td><td colspan=\"7\">".feedback($dropbox_file->feedback2)."</td></tr>";
416
+                }
417
+                if (api_get_session_id() == 0) {
418
+                    $dropbox_file_data[] = $action_icons;
419
+                } elseif (api_is_allowed_to_session_edit(false, true)) {
420
+                    $dropbox_file_data[] = $action_icons;
421
+                }
422
+                $action_icons = '';
423
+                $dropbox_file_data[] = $last_upload_date;
424
+                $dropbox_file_data[] = $file_size;
425
+                $dropbox_data_recieved[] = $dropbox_file_data;
426
+            }
427
+        }
428
+
429
+        // The content of the sortable table = the categories (if we are not in the root)
430
+        if ($view_dropbox_category_received == 0) {
431
+            foreach ($dropbox_categories as $category) {
432
+                /*  Note: This can probably be shortened since the categories
433 433
 			    for the received files are already in the
434 434
 			    $dropbox_received_category array;*/
435
-				$dropbox_category_data = array();
436
-				if ($category['received'] == '1') {
437
-					$movelist[$category['cat_id']] = $category['cat_name'];
435
+                $dropbox_category_data = array();
436
+                if ($category['received'] == '1') {
437
+                    $movelist[$category['cat_id']] = $category['cat_name'];
438 438
                     // This is where the checkbox icon for the files appear
439
-					$dropbox_category_data[] = $category['cat_id'];
440
-					// The icon of the category
441
-					$link_open = '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$category['cat_id'].'&view_sent_category='.$viewSentCategory.'&view='.$view.'">';
442
-					$dropbox_category_data[] = $link_open.DocumentManager::build_document_icon_tag('folder', $category['cat_name']).'</a>';
443
-					$dropbox_category_data[] = '<a href="'.api_get_path(WEB_CODE_PATH).'dropbox/dropbox_download.php?'.api_get_cidreq().'&cat_id='.$category['cat_id'].'&action=downloadcategory&sent_received=received">'.Display::return_icon('save_pack.png', get_lang('Save'), array('style' => 'float:right;'),ICON_SIZE_SMALL).'</a>'.$link_open.$category['cat_name'].'</a>';
444
-					$dropbox_category_data[] = '';
445
-					$dropbox_category_data[] = '';
446
-					$dropbox_category_data[] = '';
447
-					$dropbox_category_data[] = '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=editcategory&id='.$category['cat_id'].'">'.Display::return_icon('edit.png',get_lang('Edit'),'',ICON_SIZE_SMALL).'</a>
439
+                    $dropbox_category_data[] = $category['cat_id'];
440
+                    // The icon of the category
441
+                    $link_open = '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$category['cat_id'].'&view_sent_category='.$viewSentCategory.'&view='.$view.'">';
442
+                    $dropbox_category_data[] = $link_open.DocumentManager::build_document_icon_tag('folder', $category['cat_name']).'</a>';
443
+                    $dropbox_category_data[] = '<a href="'.api_get_path(WEB_CODE_PATH).'dropbox/dropbox_download.php?'.api_get_cidreq().'&cat_id='.$category['cat_id'].'&action=downloadcategory&sent_received=received">'.Display::return_icon('save_pack.png', get_lang('Save'), array('style' => 'float:right;'),ICON_SIZE_SMALL).'</a>'.$link_open.$category['cat_name'].'</a>';
444
+                    $dropbox_category_data[] = '';
445
+                    $dropbox_category_data[] = '';
446
+                    $dropbox_category_data[] = '';
447
+                    $dropbox_category_data[] = '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=editcategory&id='.$category['cat_id'].'">'.Display::return_icon('edit.png',get_lang('Edit'),'',ICON_SIZE_SMALL).'</a>
448 448
 										  <a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=deletereceivedcategory&id='.$category['cat_id'].'" onclick="javascript: return confirmation(\''.Security::remove_XSS($category['cat_name']).'\');">'.Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>';
449
-				}
450
-				if (is_array($dropbox_category_data) && count($dropbox_category_data) > 0) {
451
-					$dropbox_data_recieved[] = $dropbox_category_data;
452
-				}
453
-			}
454
-		}
455
-
456
-		// Displaying the table
449
+                }
450
+                if (is_array($dropbox_category_data) && count($dropbox_category_data) > 0) {
451
+                    $dropbox_data_recieved[] = $dropbox_category_data;
452
+                }
453
+            }
454
+        }
455
+
456
+        // Displaying the table
457 457
         $additional_get_parameters = array(
458 458
             'view' => $view,
459 459
             'view_received_category' => $viewReceivedCategory,
@@ -464,15 +464,15 @@  discard block
 block discarded – undo
464 464
             'download_received' => get_lang('Download')
465 465
         );
466 466
 
467
-		if (is_array($movelist)) {
468
-			foreach ($movelist as $catid => $catname){
469
-				$selectlist['move_received_'.$catid] = get_lang('Move') . '->'. Security::remove_XSS($catname);
470
-			}
471
-		}
467
+        if (is_array($movelist)) {
468
+            foreach ($movelist as $catid => $catname){
469
+                $selectlist['move_received_'.$catid] = get_lang('Move') . '->'. Security::remove_XSS($catname);
470
+            }
471
+        }
472 472
 
473
-		if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
474
-			$selectlist = array();
475
-		}
473
+        if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
474
+            $selectlist = array();
475
+        }
476 476
         echo '<div class="files-table">';
477 477
         Display::display_sortable_config_table(
478 478
             'dropbox',
@@ -486,154 +486,154 @@  discard block
 block discarded – undo
486 486
             $selectlist
487 487
         );
488 488
         echo '</div>';
489
-	}
490
-
491
-	/*	SENT FILES */
492
-
493
-	if (!$view || $view == 'sent' || !$showSentReceivedTabs) {
494
-		// This is for the categories
495
-		if (isset($viewSentCategory) AND $viewSentCategory != '') {
496
-			$view_dropbox_category_sent = $viewSentCategory;
497
-		} else {
498
-			$view_dropbox_category_sent = 0;
499
-		}
500
-
501
-		// Object initialisation
502
-		$dropbox_person = new Dropbox_Person(api_get_user_id(), $is_courseAdmin, $is_courseTutor);
503
-
504
-		// Constructing the array that contains the total number of feedback messages per document.
505
-		$number_feedback = get_total_number_feedback();
506
-
507
-		// Sorting and paging options
508
-		$sorting_options = array();
509
-		$paging_options = array();
510
-
511
-		// The headers of the sortable tables
512
-		$column_header = array();
513
-
514
-		$column_header[] = array('', false, '');
515
-		$column_header[] = array(get_lang('Type'), true, 'style="width:40px"', 'style="text-align:center"');
516
-		$column_header[] = array(get_lang('SentTitle'), true, '');
517
-		$column_header[] = array(get_lang('Size'), true, '');
518
-		$column_header[] = array(get_lang('SentTo'), true, '');
519
-		$column_header[] = array(get_lang('LastResent'), true, '');
520
-
521
-		if (api_get_session_id() == 0) {
522
-			$column_header[] = array(get_lang('Modify'), false, '', 'nowrap style="text-align: right"');
523
-		} elseif (api_is_allowed_to_session_edit(false, true)) {
524
-			$column_header[] = array(get_lang('Modify'), false, '', 'nowrap style="text-align: right"');
525
-		}
526
-
527
-		$column_header[] = array('RealDate', true);
528
-		$column_header[] = array('RealSize', true);
529
-
530
-		$column_show = array();
531
-		$column_order = array();
532
-
533
-		// An array with the setting of the columns -> 1: columns that we will show, 0:columns that will be hide
534
-		$column_show[] = 1;
535
-		$column_show[] = 1;
536
-		$column_show[] = 1;
537
-		$column_show[] = 1;
538
-		$column_show[] = 1;
539
-		$column_show[] = 1;
540
-		if (api_get_session_id() == 0) {
541
-			$column_show[] = 1;
542
-		} elseif (api_is_allowed_to_session_edit(false, true)) {
543
-			$column_show[] = 1;
544
-		}
545
-		$column_show[] = 0;
546
-
547
-		// Here we change the way how the colums are going to be sort
548
-		// in this case the the column of LastResent ( 4th element in $column_header) we will be order like the column RealDate
549
-		// because in the column RealDate we have the days in a correct format "2008-03-12 10:35:48"
550
-
551
-		$column_order[3] = 8;
552
-		$column_order[5] = 7;
553
-
554
-		// The content of the sortable table = the received files
555
-		foreach ($dropbox_person->sentWork as $dropbox_file) {
556
-			$dropbox_file_data = array();
557
-
558
-			if ($view_dropbox_category_sent == $dropbox_file->category) {
559
-				$dropbox_file_data[] = $dropbox_file->id;
560
-				$link_open = '<a href="'.api_get_path(WEB_CODE_PATH).'dropbox/dropbox_download.php?'.api_get_cidreq().'&id='.$dropbox_file->id.'">';
561
-				$dropbox_file_data[] = $link_open.DocumentManager::build_document_icon_tag('file', $dropbox_file->title).'</a>';
562
-				$dropbox_file_data[] = '<a href="'.api_get_path(WEB_CODE_PATH).'dropbox/dropbox_download.php?'.api_get_cidreq().'&id='.$dropbox_file->id.'&action=download">'.
489
+    }
490
+
491
+    /*	SENT FILES */
492
+
493
+    if (!$view || $view == 'sent' || !$showSentReceivedTabs) {
494
+        // This is for the categories
495
+        if (isset($viewSentCategory) AND $viewSentCategory != '') {
496
+            $view_dropbox_category_sent = $viewSentCategory;
497
+        } else {
498
+            $view_dropbox_category_sent = 0;
499
+        }
500
+
501
+        // Object initialisation
502
+        $dropbox_person = new Dropbox_Person(api_get_user_id(), $is_courseAdmin, $is_courseTutor);
503
+
504
+        // Constructing the array that contains the total number of feedback messages per document.
505
+        $number_feedback = get_total_number_feedback();
506
+
507
+        // Sorting and paging options
508
+        $sorting_options = array();
509
+        $paging_options = array();
510
+
511
+        // The headers of the sortable tables
512
+        $column_header = array();
513
+
514
+        $column_header[] = array('', false, '');
515
+        $column_header[] = array(get_lang('Type'), true, 'style="width:40px"', 'style="text-align:center"');
516
+        $column_header[] = array(get_lang('SentTitle'), true, '');
517
+        $column_header[] = array(get_lang('Size'), true, '');
518
+        $column_header[] = array(get_lang('SentTo'), true, '');
519
+        $column_header[] = array(get_lang('LastResent'), true, '');
520
+
521
+        if (api_get_session_id() == 0) {
522
+            $column_header[] = array(get_lang('Modify'), false, '', 'nowrap style="text-align: right"');
523
+        } elseif (api_is_allowed_to_session_edit(false, true)) {
524
+            $column_header[] = array(get_lang('Modify'), false, '', 'nowrap style="text-align: right"');
525
+        }
526
+
527
+        $column_header[] = array('RealDate', true);
528
+        $column_header[] = array('RealSize', true);
529
+
530
+        $column_show = array();
531
+        $column_order = array();
532
+
533
+        // An array with the setting of the columns -> 1: columns that we will show, 0:columns that will be hide
534
+        $column_show[] = 1;
535
+        $column_show[] = 1;
536
+        $column_show[] = 1;
537
+        $column_show[] = 1;
538
+        $column_show[] = 1;
539
+        $column_show[] = 1;
540
+        if (api_get_session_id() == 0) {
541
+            $column_show[] = 1;
542
+        } elseif (api_is_allowed_to_session_edit(false, true)) {
543
+            $column_show[] = 1;
544
+        }
545
+        $column_show[] = 0;
546
+
547
+        // Here we change the way how the colums are going to be sort
548
+        // in this case the the column of LastResent ( 4th element in $column_header) we will be order like the column RealDate
549
+        // because in the column RealDate we have the days in a correct format "2008-03-12 10:35:48"
550
+
551
+        $column_order[3] = 8;
552
+        $column_order[5] = 7;
553
+
554
+        // The content of the sortable table = the received files
555
+        foreach ($dropbox_person->sentWork as $dropbox_file) {
556
+            $dropbox_file_data = array();
557
+
558
+            if ($view_dropbox_category_sent == $dropbox_file->category) {
559
+                $dropbox_file_data[] = $dropbox_file->id;
560
+                $link_open = '<a href="'.api_get_path(WEB_CODE_PATH).'dropbox/dropbox_download.php?'.api_get_cidreq().'&id='.$dropbox_file->id.'">';
561
+                $dropbox_file_data[] = $link_open.DocumentManager::build_document_icon_tag('file', $dropbox_file->title).'</a>';
562
+                $dropbox_file_data[] = '<a href="'.api_get_path(WEB_CODE_PATH).'dropbox/dropbox_download.php?'.api_get_cidreq().'&id='.$dropbox_file->id.'&action=download">'.
563 563
                     Display::return_icon('save.png', get_lang('Save'), array('style' => 'float:right;'),ICON_SIZE_SMALL).'</a>'.$link_open.$dropbox_file->title.'</a><br />'.$dropbox_file->description;
564
-				$file_size = $dropbox_file->filesize;
565
-				$dropbox_file_data[] = format_file_size($file_size);
564
+                $file_size = $dropbox_file->filesize;
565
+                $dropbox_file_data[] = format_file_size($file_size);
566 566
                 $receivers_celldata = null;
567
-				foreach ($dropbox_file->recipients as $recipient) {
568
-					$userInfo = api_get_user_info($recipient['user_id']);
569
-					$receivers_celldata = UserManager::getUserProfileLink($userInfo).', '.$receivers_celldata;
570
-				}
571
-				$receivers_celldata = trim(trim($receivers_celldata), ','); // Removing the trailing comma.
572
-				$dropbox_file_data[] = $receivers_celldata;
573
-				$last_upload_date = api_get_local_time($dropbox_file->last_upload_date);
574
-				$dropbox_file_data[] = date_to_str_ago($dropbox_file->last_upload_date).'<br /><span class="dropbox_date">'.
575
-					api_format_date($last_upload_date).'</span>';
576
-
577
-				//$dropbox_file_data[] = $dropbox_file->author;
578
-				$receivers_celldata = '';
579
-
580
-				$action_icons = check_number_feedback($dropbox_file->id, $number_feedback).' '.get_lang('Feedback').'
567
+                foreach ($dropbox_file->recipients as $recipient) {
568
+                    $userInfo = api_get_user_info($recipient['user_id']);
569
+                    $receivers_celldata = UserManager::getUserProfileLink($userInfo).', '.$receivers_celldata;
570
+                }
571
+                $receivers_celldata = trim(trim($receivers_celldata), ','); // Removing the trailing comma.
572
+                $dropbox_file_data[] = $receivers_celldata;
573
+                $last_upload_date = api_get_local_time($dropbox_file->last_upload_date);
574
+                $dropbox_file_data[] = date_to_str_ago($dropbox_file->last_upload_date).'<br /><span class="dropbox_date">'.
575
+                    api_format_date($last_upload_date).'</span>';
576
+
577
+                //$dropbox_file_data[] = $dropbox_file->author;
578
+                $receivers_celldata = '';
579
+
580
+                $action_icons = check_number_feedback($dropbox_file->id, $number_feedback).' '.get_lang('Feedback').'
581 581
                     <a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=viewfeedback&id='.$dropbox_file->id.'&'.$sort_params.'">'.Display::return_icon('discuss.png', get_lang('Comment'),'',ICON_SIZE_SMALL).'</a>
582 582
                     <a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=movesent&move_id='.$dropbox_file->id.'&'.$sort_params.'">'.Display::return_icon('move.png', get_lang('Move'),'',ICON_SIZE_SMALL).'</a>
583 583
                     <a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=deletesentfile&id='.$dropbox_file->id.'&'.$sort_params.'" onclick="javascript: return confirmation(\''.$dropbox_file->title.'\');">'.Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>';
584
-				// This is a hack to have an additional row in a sortable table
585
-				if ($action == 'viewfeedback' && isset($_GET['id']) && is_numeric($_GET['id']) && $dropbox_file->id == $_GET['id']) {
586
-					$action_icons .= "</td></tr>\n"; // ending the normal row of the sortable table
587
-					$action_icons .= "<tr><td colspan=\"2\">";
588
-					$action_icons .= "<a href=\"".api_get_path(WEB_CODE_PATH)."dropbox/index.php?".api_get_cidreq()."&view_received_category=".$viewReceivedCategory."&view_sent_category=".$viewSentCategory."&view=".$view.'&'.$sort_params."\">".get_lang('CloseFeedback')."</a>";
589
-					$action_icons .= "</td><td colspan=\"7\">".feedback($dropbox_file->feedback2)."</td></tr>";
590
-				}
591
-				$dropbox_file_data[] = $action_icons;
592
-				$dropbox_file_data[] = $last_upload_date;
593
-				$dropbox_file_data[] = $file_size;
594
-				$action_icons = '';
595
-				$dropbox_data_sent[] = $dropbox_file_data;
596
-			}
597
-		}
584
+                // This is a hack to have an additional row in a sortable table
585
+                if ($action == 'viewfeedback' && isset($_GET['id']) && is_numeric($_GET['id']) && $dropbox_file->id == $_GET['id']) {
586
+                    $action_icons .= "</td></tr>\n"; // ending the normal row of the sortable table
587
+                    $action_icons .= "<tr><td colspan=\"2\">";
588
+                    $action_icons .= "<a href=\"".api_get_path(WEB_CODE_PATH)."dropbox/index.php?".api_get_cidreq()."&view_received_category=".$viewReceivedCategory."&view_sent_category=".$viewSentCategory."&view=".$view.'&'.$sort_params."\">".get_lang('CloseFeedback')."</a>";
589
+                    $action_icons .= "</td><td colspan=\"7\">".feedback($dropbox_file->feedback2)."</td></tr>";
590
+                }
591
+                $dropbox_file_data[] = $action_icons;
592
+                $dropbox_file_data[] = $last_upload_date;
593
+                $dropbox_file_data[] = $file_size;
594
+                $action_icons = '';
595
+                $dropbox_data_sent[] = $dropbox_file_data;
596
+            }
597
+        }
598 598
 
599 599
         $moveList = array();
600
-		// The content of the sortable table = the categories (if we are not in the root)
601
-		if ($view_dropbox_category_sent == 0) {
602
-			foreach ($dropbox_categories as $category) {
603
-				$dropbox_category_data = array();
600
+        // The content of the sortable table = the categories (if we are not in the root)
601
+        if ($view_dropbox_category_sent == 0) {
602
+            foreach ($dropbox_categories as $category) {
603
+                $dropbox_category_data = array();
604 604
 
605
-				if ($category['sent'] == '1') {
605
+                if ($category['sent'] == '1') {
606 606
 
607 607
                     $moveList[$category['cat_id']] = $category['cat_name'];
608
-					$dropbox_category_data[] = $category['cat_id'];
609
-					// This is where the checkbox icon for the files appear.
610
-					$link_open = '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$category['cat_id'].'&view='.$view.'">';
611
-					$dropbox_category_data[] = $link_open.DocumentManager::build_document_icon_tag('folder', Security::remove_XSS($category['cat_name'])).'</a>';
612
-					$dropbox_category_data[] = '<a href="'.api_get_path(WEB_CODE_PATH).'dropbox/dropbox_download.php?'.api_get_cidreq().'&cat_id='.$category['cat_id'].'&action=downloadcategory&sent_received=sent">'.Display::return_icon('save_pack.png', get_lang('Save'), array('style' => 'float:right;'),ICON_SIZE_SMALL).'</a>'.$link_open.Security::remove_XSS($category['cat_name']).'</a>';
613
-					//$dropbox_category_data[] = '';
614
-					$dropbox_category_data[] = '';
615
-					//$dropbox_category_data[] = '';
616
-					$dropbox_category_data[] = '';
617
-					$dropbox_category_data[] = '';
618
-					$dropbox_category_data[] = '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=editcategory&id='.$category['cat_id'].'">'.
608
+                    $dropbox_category_data[] = $category['cat_id'];
609
+                    // This is where the checkbox icon for the files appear.
610
+                    $link_open = '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$category['cat_id'].'&view='.$view.'">';
611
+                    $dropbox_category_data[] = $link_open.DocumentManager::build_document_icon_tag('folder', Security::remove_XSS($category['cat_name'])).'</a>';
612
+                    $dropbox_category_data[] = '<a href="'.api_get_path(WEB_CODE_PATH).'dropbox/dropbox_download.php?'.api_get_cidreq().'&cat_id='.$category['cat_id'].'&action=downloadcategory&sent_received=sent">'.Display::return_icon('save_pack.png', get_lang('Save'), array('style' => 'float:right;'),ICON_SIZE_SMALL).'</a>'.$link_open.Security::remove_XSS($category['cat_name']).'</a>';
613
+                    //$dropbox_category_data[] = '';
614
+                    $dropbox_category_data[] = '';
615
+                    //$dropbox_category_data[] = '';
616
+                    $dropbox_category_data[] = '';
617
+                    $dropbox_category_data[] = '';
618
+                    $dropbox_category_data[] = '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=editcategory&id='.$category['cat_id'].'">'.
619 619
                                     Display::return_icon('edit.png', get_lang('Edit'),'',ICON_SIZE_SMALL).'</a>
620 620
 									<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=deletesentcategory&id='.$category['cat_id'].'" onclick="javascript: return confirmation(\''.Security::remove_XSS($category['cat_name']).'\');">'.
621 621
                                     Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>';
622
-				}
623
-				if (is_array($dropbox_category_data) && count($dropbox_category_data) > 0) {
624
-					$dropbox_data_sent[] = $dropbox_category_data;
625
-				}
626
-			}
627
-		}
628
-
629
-		// Displaying the table
630
-		$additional_get_parameters = array(
622
+                }
623
+                if (is_array($dropbox_category_data) && count($dropbox_category_data) > 0) {
624
+                    $dropbox_data_sent[] = $dropbox_category_data;
625
+                }
626
+            }
627
+        }
628
+
629
+        // Displaying the table
630
+        $additional_get_parameters = array(
631 631
             'view' => $view,
632 632
             'view_received_category' => $viewReceivedCategory,
633 633
             'view_sent_category' => $viewSentCategory
634 634
         );
635 635
 
636
-		$selectlist = array(
636
+        $selectlist = array(
637 637
             'delete_received' => get_lang('Delete'),
638 638
             'download_received' => get_lang('Download')
639 639
         );
@@ -644,12 +644,12 @@  discard block
 block discarded – undo
644 644
             }
645 645
         }
646 646
 
647
-		if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
648
-			$selectlist = array('download_received' => get_lang('Download'));
649
-		}
647
+        if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
648
+            $selectlist = array('download_received' => get_lang('Download'));
649
+        }
650 650
 
651 651
         echo '<div class="files-table">';
652
-		Display::display_sortable_config_table(
652
+        Display::display_sortable_config_table(
653 653
             'dropbox',
654 654
             $column_header,
655 655
             $dropbox_data_sent,
@@ -661,7 +661,7 @@  discard block
 block discarded – undo
661 661
             $selectlist
662 662
         );
663 663
         echo '</div>';
664
-	}
664
+    }
665 665
 }
666 666
 
667 667
 Display::display_footer();
Please login to merge, or discard this patch.