A
download class.Remitt.php
Language: PHP
LOC: 766
Project Info
FreeMED Project(freemed)
Server: SourceForge
Type: cvs
...reemed\freemed\freemed\lib\
   acl.php
   API.php
   bcadd.php
   calendar-functions.php
   class.AdminModule.php
   class.Agata.php
   class.Authorizations.php
   class.BaseModule.php
   class.BillingModule.php
   class.CalendarModule.php
   class.ClaimLog.php
   class.Coverage.php
   class.Debug.php
   class.diagnosis_set.php
   class.Djvu.php
   class.EMRModule.php
   class.Fax.php
   class.FixedFormEntry.php
   ...s.FixedFormRenderer.php
   class.FormRenderer.php
   class.FreeMEDSelfTest.php
   class.GeneralConfig.php
   class.GraphModule.php
   class.Guarantor.php
   class.Handler_HL7v2.php
   ...s.Handler_HL7v2_A04.php
   ...s.Handler_HL7v2_A08.php
   ...s.Handler_HL7v2_S12.php
   ...s.Handler_HL7v2_S15.php
   class.InsuranceCompany.php
   class.LanguageRegistry.php
   class.Ledger.php
   ...s.MaintenanceModule.php
   class.Messages.php
   class.OMBS_Patient.php
   class.OMBS_Wrapper.php
   class.Parser_HL7v2.php
   class.Patient.php
   class.Payer.php
   class.PHPlot.php
   class.Physician.php
   class.Procedure.php
   class.RecordLock.php
   class.Remitt.php
   class.ReportsModule.php
   class.rxlist.php
   class.Scheduler.php
   class.TeX.php
   class.User.php
   class.UtilityModule.php
   class.vCalendar.php
   class.vCalendarEvent.php
   error_handler.php
   freemed.php
   i18n.php
   iso-set.php
   macros.php
   mail-functions.php
   settings.php
   settings.php.tmpl
   xml.php
   xmlrpc_services.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
<?php
	// $Id: class.Remitt.php,v 1.15 2005/07/14 18:56:59 rufustfirefly Exp $
	// $Author: rufustfirefly $

// Class: FreeMED.Remitt
//
//	Communication and document creation class for interfacing with
//	a REMITT server.
//
class Remitt {

	var $ref; // references hash
	var $_cache; // result cache
	var $_connection; // XMLRPC connection

	function Remitt ( $server = '127.0.0.1' ) {
		$this->protocol = 'http';
		$this->server = $server;
		$this->port = freemed::config_value('remitt_port'); 
		if (!$this->port) { $this->port = '7688'; }
		$this->_connection = CreateObject('PHP.xmlrpc_client', '/RPC2', $this->server, $this->port);
		// TODO: set credentials ...
		
	} // end constructor

	// Method: GetFIleList
	//
	// Parameters:
	//
	//	$type - Type of files
	//
	//	$criteria - Type of criteria (ex: years)
	//
	//	$value - Criteria
	//
	// Returns:
	//
	//	Array of files
	//
	function GetFileList ( $type, $criteria, $value ) {
		$results = $this->_call(
			'Remitt.Interface.FileList',
			array (
				CreateObject('PHP.xmlrpcval', $type, 'string'),
				CreateObject('PHP.xmlrpcval', $criteria, 'string'),
				CreateObject('PHP.xmlrpcval', $value, 'string')
			),
			false
		);
		return $results;
	} // end method GetFileList

	// Method: GetProtocolVersion
	//
	//	Retrieves the protocol revision being used by a REMITT
	//	server. Is supported from REMITT version 0.1+.
	//
	// Returns:
	//
	//	Version number.
	//
	function GetProtocolVersion ( ) {
		if (!$this->GetServerStatus()) { return NULL; }
		$this->_connection->SetCredentials(
			$_SESSION['remitt']['sessionid'],
			$_SESSION['remitt']['key']
		);
		$version = $this->_call( 'Remitt.Interface.ProtocolVersion' );
		return $version;
	} // end method GetProtocolVersion

	// Method: GetServerStatus
	//
	//	Determine if the REMITT server is up.
	//
	// Returns:
	//
	//	true if up, false if not
	//
	function GetServerStatus ( ) {
		if (@fsockopen($this->server, $this->port, $_err, $_str, 10)) {
			return true;
		} else {
			return false;
		}
	} // end method GetServerStatus

	// Method: GetStatus
	//
	//	Retrieves the current status of a REMITT billing run by
	//	its unique identifier.
	//
	// Parameters:
	//
	//	$unique - Unique identifier
	//
	// Returns:
	//
	//	NULL meaning still in process, or name of result file.
	//
	function GetStatus ( $unique ) {
		if (!$this->GetServerStatus()) {
			trigger_error(__("The REMITT server is not running."), E_USER_ERROR);
		}
		$this->_connection->SetCredentials(
			$_SESSION['remitt']['sessionid'],
			$_SESSION['remitt']['key']
		);
		$status = $this->_call(
			'Remitt.Interface.GetStatus',
			array(
				CreateObject('PHP.xmlrpcval', $unique, 'string')
			)
		);
		switch ($status) {
			case -1: return NULL;
			case -2: return NULL;
			default: return $status;
		} // end switch status
	} // end method GetStatus

	// Method: ListOptions
	//
	//	Wrapper for Remitt.Interface.ListOptions
	//
	// Parameters:
	//
	//	$type - Plugin type (Render, Translation, Transport)
	//
	//	$plugin - Name of the plugin to query
	//
	//	$media - (optional) Electronic or Paper. If neither is
	//	specified, defaults to all media forms. (Default is NULL)
	//
	//	$format - (optional) Input XML format. Defaults to
	//	NULL, which disables the qualification.
	//
	// Returns:
	//
	//	Array of available options for the specified plugin
	//
	function ListOptions ( $type, $plugin, $media = NULL, $format = NULL ) {
		$this->_connection->SetCredentials(
			$_SESSION['remitt']['sessionid'],
			$_SESSION['remitt']['key']
		);

		if (!isset($this->_cache['ListOptions'][$type][$plugin]['x_'.$format])) {
			if ($format) {
				$this->_cache['ListOptions'][$type][$plugin]['x_'.$format] = $this->_call(
					'Remitt.Interface.ListOptions',
					array(
						CreateObject('PHP.xmlrpcval', $type, 'string'),
						CreateObject('PHP.xmlrpcval', $plugin, 'string'),
						CreateObject('PHP.xmlrpcval', $format, 'string')
					)
				);
			} else {
				$this->_cache['ListOptions'][$type][$plugin]['x_'.$format] = $this->_call(
					'Remitt.Interface.ListOptions',
					array(
						CreateObject('PHP.xmlrpcval', $type, 'string'),
						CreateObject('PHP.xmlrpcval', $plugin, 'string')
					)
				);
			}
		}

		// Process into nice form for select widgets
		foreach ($this->_cache['ListOptions'][$type][$plugin]['x_'.$format] AS $k => $v) {
			if (($media == NULL) or ($v['Media'] == $media)) {
				$r[$v['Description']] = $k;
			}
		}
		return $r;
	} // end method ListOptions
			
	// Method: ListPlugins
	//
	//	Wrapper for Remitt.Interface.ListPlugins
	//
	// Parameters:
	//
	//	$type - Plugin type (Render, Translation, Transport)
	//
	// Returns:
	//
	//	Array of available plugins
	//
	function ListPlugins ( $type ) {
		$this->_connection->SetCredentials(
			$_SESSION['remitt']['sessionid'],
			$_SESSION['remitt']['key']
		);

		if (!isset($this->_cache['ListPlugins'][$type])) {
			$this->_cache['ListPlugins'][$type] = $this->_call(
				'Remitt.Interface.ListPlugins',
				array(
					CreateObject('PHP.xmlrpcval', $type, 'string')
				)
			);
		}
		return $this->_cache['ListPlugins'][$type];
	} // end method ListPlugins
			
	// Method: ListOutputMonths
	//
	//	Wrapper for Remitt.Interface.GetOutputMonths
	//
	// Parameters:
	//
	//	$year - (optional) Year to list months for
	//
	// Returns:
	//
	//	Hash of years => number of output files available.
	//
	function ListOutputMonths ( $year = NULL ) {
		$this->_connection->SetCredentials(
			$_SESSION['remitt']['sessionid'],
			$_SESSION['remitt']['key']
		);
		if ($year) {
			$months = $this->_call( 
				'Remitt.Interface.GetOutputMonths',
				array (
					CreateObject('PHP.xmlrpcval', $year, 'string'),
				)
			);
		} else {
			$months = $this->_call( 'Remitt.Interface.GetOutputMonths' );
		}
		if (!is_array($months)) { $months = array ( $months ); }
		return $months;
	} // end method ListOutputMonths
			
	// Method: ListOutputYears
	//
	//	Wrapper for Remitt.Interface.GetOutputYears
	//
	// Returns:
	//
	//	Hash of years => number of output files available.
	//
	function ListOutputYears ( ) {
		$this->_connection->SetCredentials(
			$_SESSION['remitt']['sessionid'],
			$_SESSION['remitt']['key']
		);
		$years = $this->_call( 'Remitt.Interface.GetOutputYears' );
		if (!is_array($years)) { $years = array ( $years ); }
		return $years;
	} // end method ListOutputYears
			
	// Method: Login
	//
	//	Logs into the Remitt server, and stores authentication
	//	data received in the session.
	//
	// Parameters:
	//
	//	$username - Username to be passed to the Remitt server
	//
	//	$password - Password to be passed to the Remitt server
	//
	function Login ( $username, $password ) {
/*
		// Check for session data
		if ($_SESSION['remitt']) { 
			// Set credentials properly
			$this->_connection->SetCredentials(
				$_SESSION['remitt']['sessionid'],
				$_SESSION['remitt']['key']
			);

			// Skip the rest
			return false; 
		}
*/

		// Otherwise, attempt to establish credentials
		//print "Logging in with $username and $password<br/>\n";
		$this->_connection->SetCredentials($username, $password);
		$message = CreateObject('PHP.xmlrpcmsg',
			'Remitt.Interface.SystemLogin',
			array(
				CreateObject('PHP.xmlrpcval', $username, 'string'),
				CreateObject('PHP.xmlrpcval', $password, 'string')
			)
		);
		$response_raw = $this->_connection->send(
			$message,
			0,
			$this->protocol
		);
		$response = $response_raw->deserialize();
		$_SESSION['remitt'] = $response;

		// Set credentials properly
		$this->_connection->SetCredentials(
			$_SESSION['remitt']['sessionid'],
			$_SESSION['remitt']['key']
		);
		//print "Got this: "; print_r($response); print "<br/>\n";

		// Return to program
		return true;
	} // end method Login

	// Method: ProcessBill
	function ProcessBill ( $billkey, $render, $transport ) {
		if (!$this->GetServerStatus()) {
			trigger_error(__("The REMITT server is not running."), E_USER_ERROR);
		}
		$billkey_hash = unserialize(freemed::get_link_field($billkey, 'billkey', 'billkey'));
		// For now, just use the first ones ... FIXME FIXME FIXME
		$bc = $bs = $ch = 1;
		$xml = $this->RenderPayerXML($billkey_hash['procedures'], $bc, $bs, $ch);
		//print "length of xml = ".strlen($xml)."<br/>\n";
		$this->_connection->SetCredentials(
			$_SESSION['remitt']['sessionid'],
			$_SESSION['remitt']['key']
		);
		//print "calling with ( ..., XSLT, $render, $transport ) <br/>\n";
		$output = $this->_call(
			'Remitt.Interface.Execute',
			array(
				CreateObject('PHP.xmlrpcval', $xml, 'base64'),
				CreateObject('PHP.xmlrpcval', 'XSLT', 'string'),
				CreateObject('PHP.xmlrpcval', $render, 'string'),
				CreateObject('PHP.xmlrpcval', $transport, 'string')
			)
		);
		return $output;
	} // end method ProcessBill

	// Method: ProcessStatement
	function ProcessStatement ( $procedures ) {
		if (!$this->GetServerStatus()) {
			trigger_error(__("The REMITT server is not running."), E_USER_ERROR);
		}
		// For now, just use the first ones ... FIXME FIXME FIXME
		$xml = $this->RenderStatementXML($procedures);
		//print "length of xml = ".strlen($xml)."<br/>\n";
		$this->_connection->SetCredentials(
			$_SESSION['remitt']['sessionid'],
			$_SESSION['remitt']['key']
		);
		//print "calling with ( ..., XSLT, $render, $transport ) <br/>\n";
		$output = $this->_call(
			'Remitt.Interface.Execute',
			array(
				CreateObject('PHP.xmlrpcval', $xml, 'base64'),
				CreateObject('PHP.xmlrpcval', 'XSLT', 'string'),
				CreateObject('PHP.xmlrpcval', 'statement', 'string'),
				CreateObject('PHP.xmlrpcval', 'PDF', 'string')
			)
		);
		return $output;
	} // end method ProcessStatement

	// Method: StoreBillKey
	//
	//	Stores billing data in a temporary key table.
	//
	// Parameters:
	//
	//	$billkey - Data to be serialized
	//
	// Returns:
	//
	//	Table key for billkey
	//
	function StoreBillKey ( $billkey ) {
		$query = $GLOBALS['sql']->insert_query (
			'billkey',
			array(
				'billkeydate' => date('Y-m-d'),
				'billkey' => serialize($billkey)
			)
		);
		$result = $GLOBALS['sql']->query($query);
		//print "query= $query<br/>\n";
		$id = $GLOBALS['sql']->last_record($result, 'billkey');
		syslog(LOG_INFO, 'Remitt.StoreBillKey| created key '.$id);
		return $id;
	} // end method StoreBillKey
	
	// Method: RenderPayerXML
	//
	//	Renders procedure entries into XML file to be transmitted
	//	to REMITT server.
	//
	// Parameters:
	//
	//	$procedures - Array of procedure id keys to be processed.
	//
	//	$bc - Billing contact id. Defaults to 1.
	//
	//	$bs - Billing service id. Default to 1.
	//
	//	$ch - Clearinghouse id. Defaults to 1.
	//
	// Returns:
	//
	//	Text of XML file.
	//
	function RenderPayerXML ( $_procedures, $bc=1, $bs=1, $ch=1 ) {
		// Sanitize and fold procedures array
		if (is_array($_procedures)) {
			foreach ($_procedures AS $k => $v) {
				if (is_array($v)) {
					$procedures = array_merge($procedures, $v);
				} else {
					$procedures[] = $v;
				}
			}
		} else {
			$procedures = array ( $_procedures );
		}

		$buffer .= "<?xml version=\"1.0\"?>\n";

		// Create master document element
		$buffer .= "<remitt doctype=\"payerxml\">\n";

		// global information
		$buffer .= "\n\t<!-- global information -->\n\n";
		$buffer .= $this->_tag('global',
			$this->_tag('generator',
				$this->_tag('program', PACKAGENAME, true).
				$this->_tag('version', VERSION, true),
			false).
			$this->_date('currentdate', date('Y-m-d')).
			$this->_tag('currenttime',
				$this->_tag('hour', date('H'), true).
				$this->_tag('minute', date('i'), true),
			false),
			false);

		// Handle billing service
		$bcobj = freemed::get_link_rec($bc, 'bcontact');
		$buffer .= "\n\t<!-- billing contact $bc -->\n\n".
			"<billingcontact>\n".
			$this->_tag('name', $bcobj['bcname'], true).
			$this->_addr('address', $bcobj['bcaddr'], $bsobj['bccity'], $bsobj['bsctate'], $bsobj['bczip']).
			$this->_phone('phone', $bcobj['bcphone']).
			$this->_tag('tin', $bcobj['bctin'], true).
			$this->_tag('etin', $bcobj['bcetin'], true).
			"</billingcontact>\n\n";

		// Handle billing service
		$bsobj = freemed::get_link_rec($bs, 'bservice');
		$buffer .= "\n\t<!-- billing service $bs -->\n\n".
			"<billingservice>\n".
			$this->_tag('name', $bsobj['bsname'], true).
			$this->_addr('address', $bsobj['bsaddr'], $bsobj['bscity'], $bsobj['bsstate'], $bsobj['bszip']).
			$this->_phone('phone', $bsobj['bsphone']).
			$this->_tag('tin', $bsobj['bstin'], true).
			$this->_tag('etin', $bsobj['bsetin'], true).
			"</billingservice>\n\n";

		// Handle clearinghouse
		$chobj = freemed::get_link_rec($ch, 'clearinghouse');
		$buffer .= "\n\t<!-- clearinghouse $ch -->\n\n".
			"<clearinghouse>\n".
			$this->_tag('name', $chobj['chname'], true).
			$this->_addr('address', $chobj['chaddr'], $chobj['chcity'], $chobj['chstate'], $chobj['chzip']).
			$this->_phone('phone', $chobj['chphone']).
			$this->_tag('etin', $chobj['chetin'], true).
			$this->_tag('x12gssenderid', $chobj['chx12gssender'], true).
			$this->_tag('x12gsreceiverid', $chobj['chx12gsreceiver'], true).
			"</clearinghouse>\n\n";

		// Render all objects (from procedures on) to buffer,
		// and loop to check that they all have XML representations
		// in a hash before proceeding to generate

		$_proc = ( is_array($procedures) ? $procedures :
				array($procedures) );

		foreach ($_proc as $proc) {
			if ($proc) {
			$buffer .= "\n\t<!-- procedure $proc -->\n\n".
				$this->_RenderProcedure($proc).
				"\n";
			}
		}

		foreach ($this->ref['patient'] as $pat) {
			if ($pat) {
			$buffer .= "\n\t<!-- patient $pat -->\n\n".
				$this->_RenderPatient($pat).
				"\n";
			}
		}

		// Loop through all providers
		//$this->ref[$table][$id] = $id;
		foreach ($this->ref['physician'] as $prov) {
			if ($prov) {
			$buffer .= "\n\t<!-- provider $prov -->\n\n".
				$this->_RenderProvider($prov).
				"\n";
			}
		}

		foreach ($this->ref['facility'] as $fac) {
			if ($fac) {
			$buffer .= "\n\t<!-- facility $fac -->\n\n".
				$this->_RenderFacility($fac).
				"\n";
			}
		}

		//print "cov ref array = "; print_r($this->ref['coverage']); print "<br/>\n";
		foreach ($this->ref['coverage'] as $cov) {
			//print "Should have rendered $cov as coverage<br/>\n";
			if ($cov) {
			$buffer .= "\n\t<!-- insured $cov -->\n\n".
				$this->_RenderInsured($cov).
				"\n";
			}
		}

		foreach ($this->ref['insco'] as $pay) {
			if ($pay) {
			$buffer .= "\n\t<!-- payer $pay -->\n\n".
				$this->_RenderPayer($pay).
				"\n";
			}
		}

		foreach ($this->ref['practice'] as $prac) {
			$buffer .= "\n\t<!-- practice $prac -->\n\n".
				$this->_RenderPractice($prac).
				"\n";
		}

		foreach ($this->ref['diagnosis'] as $diag) {
			$buffer .= "\n\t<!-- diagnosis $diag -->\n\n".
				$this->_RenderDiagnosis($diag).
				"\n";
		}

		// Closing tag
		$buffer .= "</remitt>\n";

		return $buffer;
	} // end method RenderPayerXML

	// Method: RenderStatementXML
	//
	//	Renders procedure entries into XML file to be transmitted
	//	to REMITT server for patient statement billing
	//
	// Parameters:
	//
	//	$procedures - Array of procedure id keys to be processed.
	//
	// Returns:
	//
	//	Text of XML file.
	//
	function RenderStatementXML ( $_procedures ) {
		// Sanitize and fold procedures array
		if (is_array($_procedures)) {
			foreach ($_procedures AS $k => $v) {
				if (is_array($v)) {
					$procedures = array_merge($procedures, $v);
				} else {
					$procedures[] = $v;
				}
			}
		} else {
			$procedures = array ( $_procedures );
		}

		$buffer .= "<?xml version=\"1.0\"?>\n";

		// Create master document element
		$buffer .= "<remitt doctype=\"statementxml\">\n";

		// global information
		$buffer .= "\n\t<!-- global information -->\n\n";
		$buffer .= $this->_tag('global',
			$this->_tag('generator',
				$this->_tag('program', PACKAGENAME, true).
				$this->_tag('version', VERSION, true),
			false).
			$this->_date('currentdate', date('Y-m-d')).
			$this->_tag('currenttime',
				$this->_tag('hour', date('H'), true).
				$this->_tag('minute', date('i'), true),
			false),
			false);

		// Render all objects (from procedures on) to buffer,
		// and loop to check that they all have XML representations
		// in a hash before proceeding to generate

		$_proc = ( is_array($procedures) ? $procedures :
				array($procedures) );

		foreach ($_proc as $proc) {
			if ($proc) {
			$buffer .= "\n\t<!-- procedure $proc -->\n\n".
				$this->_RenderProcedure($proc).
				"\n";
			}
		}

		foreach ($this->ref['patient'] as $pat) {
			if ($pat) {
			$buffer .= "\n\t<!-- patient $pat -->\n\n".
				$this->_RenderPatient($pat).
				"\n";
			}
		}

		// Loop through all providers
		//$this->ref[$table][$id] = $id;
		foreach ($this->ref['physician'] as $prov) {
			if ($prov) {
			$buffer .= "\n\t<!-- provider $prov -->\n\n".
				$this->_RenderProvider($prov).
				"\n";
			}
		}

		foreach ($this->ref['facility'] as $fac) {
			if ($fac) {
			$buffer .= "\n\t<!-- facility $fac -->\n\n".
				$this->_RenderFacility($fac).
				"\n";
			}
		}

		foreach ($this->ref['practice'] as $prac) {
			$buffer .= "\n\t<!-- practice $prac -->\n\n".
				$this->_RenderPractice($prac).
				"\n";
		}

		foreach ($this->ref['diagnosis'] as $diag) {
			$buffer .= "\n\t<!-- diagnosis $diag -->\n\n".
				$this->_RenderDiagnosis($diag).
				"\n";
		}

		// Closing tag
		$buffer .= "</remitt>\n";

		return $buffer;
	} // end method RenderStatementXML

	function _RenderDiagnosis ( $diagnosis ) {
		if (!(strpos($diagnosis, ',') === false)) {
			list ($eoc, $diag) = explode (',', $diagnosis);
		} else {
			// Fudge eoc for non-existing one
			$eoc = 0;
			$diag = $diagnosis;
		}

		// Get records from keys
		$e = freemed::get_link_rec($eoc, 'eoc');
		$d = freemed::get_link_rec($diag, 'icd9');

		$buffer .= "<diagnosis id=\"".htmlentities($diagnosis)."\">\n";

		$buffer .= $this->_tag('icd9code', $d['icd9code'], true);
		$buffer .= $this->_tag('icd10code', $d['icd10code'], true);
		$buffer .= $this->_tag('relatedtohcfa', $e['eocrelothercomment'], true);
		$buffer .= $this->_tag('isrelatedtoautoaccident', ($e['eocrelauto'] == 'yes'), true);
		$buffer .= $this->_tag('autoaccidentstate', $e['eocrelautostpr'], true);
		$buffer .= $this->_tag('isrelatedtootheraccident', ($e['eocrelother'] == 'yes'), true);
		$buffer .= $this->_tag('isrelatedtoemployment', ($e['eocrelemp'] == 'yes'), true);
		$buffer .= $this->_date('dateofonset', $e['eocstartdate']);
		$buffer .= $this->_date('dateoffirstoccurence', $e['eocstartdate']);

		$buffer .= "</diagnosis>\n";
		return $buffer;
	} // end method _RenderDiagnosis

	function _RenderFacility ( $facility ) {
		$f = freemed::get_link_rec($facility, 'facility');
		$buffer .= "<facility id=\"".htmlentities($facility)."\">\n";

		$buffer .= $this->_tag('name', $f['psrname'], true);
		$buffer .= $this->_addr('address', $f['psraddr1'],
			$f['psrcity'], $f['psrstate'], $f['psrzip']);
		$buffer .= $this->_phone('phone', $f['psrphone']);
		$buffer .= $this->_tag('description', $f['psrnote'], true);
		$buffer .= $this->_tag('hcfacode', !$f['psrpos'] ? 11 : freemed::get_link_field($f['psrpos'], 'pos', 'posname'), true);
		$buffer .= $this->_tag('x12code', !$f['psrpos'] ? 11 : freemed::get_link_field($f['psrpos'], 'pos', 'posname'), true);

		$buffer .= "</facility>\n";
		return $buffer;
	} // end method _RenderFacility

	function _RenderInsured ( $insured ) {
		$i = freemed::get_link_rec($insured, 'coverage');
		$buffer .= "<insured id=\"".htmlentities($insured)."\">\n";

		$p = freemed::get_link_rec($i['covpatient'], 'patient');

		// Handle not self covered
		$buffer .= $this->_tag('relationship', $i['covrel'], true);
		if ($i['covrel'] != 'S') {
			$buffer .= $this->_name('name', $i['covlname'], $i['covfname'], $i['covmname']);
			$buffer .= $this->_addr('address', $i['covaddr1'], $i['covcity'], $i['covstate'], $i['covzip']);
			$buffer .= $this->_phone('phone', $i['covphone']);
			$buffer .= $this->_date('dateofbirth', $i['covdob']);
			$buffer .= $this->_tag('sex', strtolower($i['covsex']), true);
		} else {
			// Self
			$buffer .= $this->_name('name', $p['ptlname'], $p['ptfname'], $p['ptmname']);
			$buffer .= $this->_addr('address', $p['ptaddr1'], $p['ptcity'], $p['ptstate'], $p['ptzip']);
			$buffer .= $this->_phone('phone', $p['pthphone']);
			$buffer .= $this->_date('dateofbirth', $p['ptdob']);
			$buffer .= $this->_tag('sex', strtolower($p['ptsex']), true);
		}

		// Common stuff
		$buffer .= $this->_tag('id', $i['covpatinsno'], true);
		$buffer .= $this->_tag('planname', $i['covplanname'], true);
		$buffer .= $this->_tag('groupname', $i['covplanname'], true);
		$buffer .= $this->_tag('groupnumber', $i['covpatgrpno'], true);
		$buffer .= $this->_tag('isemployed', (!empty($i['covemployer']))+0, true);
		$buffer .= $this->_tag('employername', $i['covemployer'], true);
		$buffer .= $this->_tag('isstudent', !empty($i['covschool']), true);
		$buffer .= $this->_tag('schoolname', $i['covschool'], true);
		$buffer .= $this->_tag('isassigning', ($i['covisassigning'] > 0), true);

		$buffer .= "</insured>\n";
		return $buffer;
	} // end method _RenderInsured

	function _RenderPatient ( $patient ) {
		$p = freemed::get_link_rec($patient, 'patient');
		$buffer .= "<patient id=\"".htmlentities($patient)."\">\n";

		$buffer .= $this->_name('name', $p['ptlname'], $p['ptfname'], $p['ptmname']);
		$buffer .= $this->_addr('address', $p['ptaddr1'],
			$p['ptcity'], $p['ptstate'], $p['ptzip']);
		$buffer .= $this->_phone('phone', $p['pthphone']);
		$buffer .= $this->_tag('sex', strtolower($p['ptsex']), true);
		$buffer .= $this->_tag('socialsecuritynumber', $p['ptssn'], true);
		$buffer .= $this->_tag('isdead', ($p['ptdead'] == 1)+0, true);
		$buffer .= $this->_date('dateofbirth', $p['ptdob']);
		$buffer .= $this->_date('dateofdeath', $p['ptdeaddt']);
		$buffer .= $this->_tag('ispregnant', ($p['ptpreg'] == 'pregnant')+0, true);
		$buffer .= $this->_tag('issingle', ($p['ptmarital'] == 'single')+0, true);
		$buffer .= $this->_tag('ismarried', ($p['ptmarital'] == 'married')+0, true);
		$buffer .= $this->_tag('ismaritalotherhcfa', ( ($p['ptmarital'] != 'married') and ($p['ptmarital'] != 'single') )+0, true);
		$buffer .= $this->_tag('isemployed', (
				( $p['ptempl'] != 'y' ) and
				( $p['ptempl'] != 'p' ) and
				( $p['ptempl'] != 'm' ) and
				( $p['ptempl'] != 's' ) )+0, true);
		$buffer .= $this->_tag('isfulltimestudent', 0, true); // fixme
		$buffer .= $this->_tag('isparttimestudent', 0, true); // fixme

		// fixme: coveragecount needs to be in procedure

		$buffer .= $this->_tag('referringprovider', $p['ptrefdoc'], true);
		$this->_AddDependency('physician', $p['ptrefdoc']);

		$buffer .= $this->_tag('account', $p['ptid'], true);

		$buffer .= "</patient>\n";
		return $buffer;
	} // end method _RenderPatient

	function _RenderPayer ( $payer ) {
		$p = freemed::get_link_rec($payer, 'insco');
		$buffer .= "<payer id=\"".htmlentities($payer)."\">\n";

		$buffer .= $this->_tag('name', $p['inscoalias'], true);
		$buffer .= $this->_addr('address', $p['inscoaddr1'], $p['inscocity'], $p['inscostate'], $p['inscozip']);
		$buffer .= $this->_phone('phone', $p['inscophone']);
		$buffer .= $this->_tag('x12claimtype', 'HM', true); // fix

		// IsX functions for payer types
		$x = false;
		$buffer .= $this->_tag('ismedicare', ($this->_isPayerX($payer, 'MA') or $this->_isPayerX($payer, 'MB')) + 0, true);
		$x |= ($this->_isPayerX($payer, 'MA') or $this->_isPayerX($payer, 'MB'));
		$buffer .= $this->_tag('ischampus', ($this->_isPayerX($payer, 'CH') + 0), true);
		$x |= ($this->_isPayerX($payer, 'CH'));
		$buffer .= $this->_tag('ischampusva', ($this->_isPayerX($payer, 'CH') + 0), true);
		$x += ($this->_isPayerX($payer, 'CH'));
		$buffer .= $this->_tag('ismedicaid', ($this->_isPayerX($payer, 'MC') + 0), true);
		$x |= ($this->_isPayerX($payer, 'MC'));
		$buffer .= $this->_tag('isbcbs', ($this->_isPayerX($payer, 'BL') + 0), true);
		$x |= ($this->_isPayerX($payer, 'BL'));
		$buffer .= $this->_tag('isfeca', ($this->_isPayerX($payer, 'FI') + 0), true);
		$x |= ($this->_isPayerX($payer, 'FI'));
		$buffer .= $this->_tag('isotherhcfa', ((!$x) + 0), true);
	
		$buffer .= "</payer>\n";
		return $buffer;		
	} // end method _RenderPayer

	function _RenderPractice ( $facility ) {
		$f = freemed::get_link_rec($facility, 'physician');
		$buffer .= "<practice id=\"".htmlentities($facility)."\">\n";

		// loop through payers that are in the system
		foreach ($this->ref['insco'] as $i) {
			// loop through providers
			$_i = freemed::get_link_rec($i, 'insco');
			$map = unserialize($_i['inscoidmap']);
			foreach ($this->ref['physician'] as $p) {
				if ($p and $i) {
				$buffer .= "<id payer=\"".htmlentities($i).
					"\" ".
					"physician=\"".htmlentities($p)."\">".
					htmlentities($map[$p]['id']).
					"</id>\n";
				$buffer .= "<groupid ".
					"payer=\"".htmlentities($i)."\" ".
					"physician=\"".htmlentities($p)."\">".
					htmlentities($map[$p]['group']).
					"</groupid>\n";
				}
			}
		}

		$buffer .= $this->_tag('name', $f['phypracname'], true);
		$buffer .= $this->_addr('address', $f['phyaddr1a'],
			$f['phycitya'], $f['phystatea'], $f['phyzipa']);
		$buffer .= $this->_phone('phone', $f['phyphonea']);
			// FIXME: THESE ARE NOT RIGHT ANYMORE
		$buffer .= $this->_tag('x12id', $f['psrx12id'], true);
		$buffer .= $this->_tag('x12idtype', $f['psrx12idtype'], true);
		$buffer .= $this->_tag('ein', ( $f['phypracein'] ? $f['phypracein'] : $f['physsn'] ), true);

		$buffer .= "</practice>\n";
		return $buffer;
	} // end method _RenderPractice

	function _RenderProvider ( $provider ) {
		$p = freemed::get_link_rec($provider, 'physician');
		$buffer .= "<provider id=\"".htmlentities($provider)."\">\n";

		$buffer .= $this->_name('name', $p['phylname'], $p['phyfname'], $p['phymname']);
		$buffer .= $this->_addr('address', $p['phyaddr1a'], $p['phycitya'], $p['phystatea'], $p['phyzipa']);
		$buffer .= $this->_phone('phone', $p['phyphonea']);
		$buffer .= $this->_tag('socialsecuritynumber', $p['physsn'], true);
		$buffer .= $this->_tag('tin', $p['physsn'], true);
		$buffer .= $this->_tag('ipn', $p['phyupin'], true);
	
		$buffer .= "</provider>\n";
		return $buffer;		
	} // end method _RenderProvider

	function _RenderProcedure ( $procedure ) {
		$p = freemed::get_link_rec($procedure, 'procrec');

		$buffer .= "<procedure id=\"".htmlentities($procedure)."\">\n".
			$this->_tag('cpt4code', freemed::get_link_field($p['proccpt'], 'cpt', 'cptcode'), true).
			$this->_tag('cpt5code', freemed::get_link_field($p['proccpt'], 'cpt', 'cptcode'), true).
			$this->_tag('cptdescription', freemed::get_link_field($p['proccpt'], 'cpt', 'cptnameint'), true).
			$this->_tag('cptcob', '0', true).
			$this->_tag('cptcharges', $p['proccharges'], true).
			$this->_tag('cptcount', 1, true).
			$this->_tag('cptemergency', '0', true).
			$this->_tag('cptepsdt', '0', true).
			$this->_tag('cptmodifier', freemed::get_link_field($p['proccptmod'], 'cptmod', 'cptmod'), true).
			$this->_tag('cptunits', $p['procunits'], true).
			$this->_tag('weightgrams', '0', true);
		$this->_AddDependency('cpt', $p['proccpt']);

		// Handle "array" of diagnoses/eoc
		$e = explode (':', $p['proceoc']);
		$eoc = $e[0];	
		for ($i=1; $i<=4; $i++) {
			if ($p['procdiag'.$i] > 0) {
				$buffer .= $this->_tag('diagnosiskey', $eoc.','.$p['procdiag'.$i], true); 
				$this->_AddDependency('diagnosis', $eoc.','.$p['procdiag'.$i]);
			}
		}
		$buffer .= $this->_tag('patientkey', $p['procpatient'], true);
		$this->_AddDependency('patient', $p['procpatient']);
	
		// Handle payer key
		switch ($p['proccurcovtp']) {
			case '1': $covnum = 1; break;
			case '2': $covnum = 2; break;
			case '3': $covnum = 3; break;
			case '4': $covnum = 4; break;
			default:  $covnum = 0; break;
		}
		$coverage = freemed::get_link_rec($p['proccov'.$covnum], 'coverage');
		$buffer .= $this->_tag('insuredkey', $p['proccov'.$covnum], true);
		//print "Should have added $coverage as coverage<br/>\n";
		$this->_AddDependency('coverage', $p['proccov'.$covnum]);
		$buffer .= $this->_tag('payerkey', $coverage['covinsco'], true);
		$this->_AddDependency('insco', $coverage['covinsco']);

		// Handle second key
		if ($covnum != 0) {
			$covnum++; 
			if ($covnum < 1 or $covnum > 4) { $covnum = 0; }
		}
		$buffer .= $this->_tag('secondinsuredkey', $p['proccov'.$covnum], true);
		$this->_AddDependency('coverage', $p['proccov'.$covnum]);
		$coverage = freemed::get_link_rec($p['proccov'.$covnum], 'coverage');
		$buffer .= $this->_tag('secondpayerkey', $coverage['covinsco'], true);
		$this->_AddDependency('insco', $coverage['covinsco']);

		// Get other insured key
		switch ($p['proccurcovtp']) {
			case '2': $covnum = 3; break;
			case '3': $covnum = 4; break;
			case '4': $covnum = 0; break;
			case '1': default: $covnum = 2; break;
		}
		$buffer .= $this->_tag('otherinsuredkey', $coverage['covinsco'], 'coverage');
		$this->_AddDependency('insco', $coverage['covinsco']);

		// Get id map
		$map = unserialize(freemed::get_link_field($p['procinsco'],
			'insco', 'inscoidmap'));

		// Figure out type of service
		$cptobj = freemed::get_link_rec($p['proccpt'], 'cpt');
		$hash = explode (':', $cptobj['cpttos']);
		if ($hash[$coverage['covinsco']] > 0) {
			$tos = freemed::get_link_field($hash[$coverage['covinsco']], 'tos', 'tosname');
		} else {
			$tos = freemed::get_link_field($cptobj['cptdeftos'], 'tos', 'tosname');
		}

		// Various resubmission codes, etc
		$buffer .=
			$this->_tag('medicaidresubmissioncode', $p['procmedicaidresub'], true).
			$this->_tag('medicaidoriginalreference', $p['procmedicaidresub'], true).
			$this->_tag('hcfalocaluse19', $map[$p['procphysician']]['local19'], true).
			$this->_tag('hcfalocaluse10d', $map[$p['procphysician']]['local10d'], true).
			$this->_tag('amountpaid', $p['procamtpaid'], true).
			$this->_tag('providerkey', $p['procphysician'], true).
			$this->_tag('facilitykey', $p['procpos'], true).
			$this->_tag('practicekey', $p['procphysician'], true).
			$this->_tag('typeofservice', $tos, true).
			'';
		$this->_AddDependency('physician', $p['procphysician']);
		$this->_AddDependency('practice', $p['procphysician']);
		$this->_AddDependency('facility', $p['procpos']);

		// Authorizations
		$buffer .= $this->_tag('priorauth', freemed::get_link_field($p['procauth'], 'authorizations', 'authnum'), true);
		$this->_AddDependency('authorizations', $p['procauth']);

		// isOutsideLab
		$buffer .= $this->_tag('isoutsidelab', ( $p['proclabcharges'] > 0 ? '1' : '0' ), true);
		$buffer .= $this->_tag('outsidelabcharges', $p['proclabcharges'] + 0, true);

		$buffer .= $this->_date('dateofservicestart', $p['procdt']);
		$buffer .= $this->_date('dateofserviceend', $p['procdt']);
		$buffer .= $this->_tag('aging', (strtotime(date("Y-m-d")) - strtotime($p['procdt'])) / (60 * 60 * 24), true);

		$e = freemed::get_link_rec($eoc, 'eoc');
		$buffer .= $this->_tag('ishospitalized', $e['eochospital'] == 1 ? '1' : '0', true);
		$buffer .= $this->_date('dateofhospitalstart', $e['eochosadmdt']);
		$buffer .= $this->_date('dateofhospitalend', $e['eochosdischrgdt']);

		$buffer .= "</procedure>\n";
		return $buffer;
	} // end method RenderProcedure

	function _isPayerX ( $payer, $mod ) {
		$i = freemed::get_link_rec($payer, 'insco');
		$mods = explode (':', $i['inscomod']);
		if (!is_array($mods)) { $mods = array ( $mods ); }
		$q = $GLOBALS['sql']->query('SELECT * FROM insmod '.
			'WHERE insmod = \''.addslashes($mod).'\'');
		$r = $GLOBALS['sql']->fetch_array($q);
		foreach ($mods AS $k => $v) {
			if ($v == $r['id']) {
				return true;
			}
		} 
		return false;
	} // end method _isPayerX

	function _AddDependency($table, $id) {
		// Make sure no duplicates
		$this->ref[$table][$id] = $id;
	}

	function _addr ( $tag, $a, $c, $s, $z) {
		return $this->_tag($tag,
			"\t".$this->_tag('streetaddress', $a, true).
			"\t".$this->_tag('city', $c, true).
			"\t".$this->_tag('state', $s, true).
			"\t".$this->_tag('zipcode', $z, true),
			false);
	} // end method _addr

	function _date ( $name, $sqlvalue ) {
		list ($y, $m, $d) = explode ('-', $sqlvalue);
		if (strlen($y) != 4) { $y = '0000'; $m = '00'; $d = '00'; }
		return $this->_tag($name,
			$this->_tag('year', $y, true).
			$this->_tag('month', $m, true).
			$this->_tag('day', $d, true),
			false);
	} // end method _date

	function _name ( $tag, $l, $f, $m = '' ) {
		return $this->_tag($tag,
			"\t".$this->_tag('last', $l, true).
			"\t".$this->_tag('first', $f, true).
			"\t".$this->_tag('middle', $m, true),
			false);
	} // end method _name

	function _phone ( $tag, $phone ) {
		$a = substr($phone, 0, 3);
		$n = substr($phone, 3, 7);
		$e = substr($phone, 10, 4);
		return $this->_tag($tag,
			"\t".$this->_tag('country', '1', true).
			"\t".$this->_tag('area', $a, true).
			"\t".$this->_tag('number', $n, true).
			"\t".$this->_tag('extension', $e, true),
			false);
	} // end method _phone

	function _tag ( $tag, $value, $inner = false ) {
		return "<".htmlentities($tag).">". ( !$inner ? "\n" : "" ) .
			( $inner ?  trim(htmlentities(stripslashes($value))) : stripslashes($value) ).
			"</".htmlentities($tag).">\n";
	} // end method _tag

	// Method: _autoserialize
	//
	//	Automagically determines what kind of resource this is
	//	supposed to be and creates a PHP.xmlrpcval object to
	//	wrap it in.
	//
	// Parameters:
	//
	//	$mixed - Original object, any type
	//
	// Returns:
	//
	//	PHP.xmlrpcval object
	//
	function _autoserialize ( $mixed ) {
		// Handle already serialized
		if (is_object($mixed) and method_exists($mixed, 'serialize')) {
			return $mixed;
		}

		if (is_array($mixed)) {
			// If dealing with an array, recursively figure out
			@reset($mixed);
			while(list($k, $v) = @each($mixed)) {
				$ele[$k] = $this->_autoserialize($v);
			}
			// Determine if struct or array as we return it
			return CreateObject (
				'PHP.xmlrpcval',
				$ele,
				$this->_is_struct($ele) ? 'struct' : 'array'
			);
		} elseif (strpos($mixed, '<') !== false) {
			// This is an *awful* way to check for binary data,
			// and is probably broken in a thousand ways.
			return CreateObject (
				'PHP.xmlrpcval',
				$mixed,
				'base64'
			);
		} else {
			// Otherwise, use PHP auto-typing
			$type = (is_integer($mixed) ? 'int' : gettype($mixed));
			return CreateObject (
				'PHP.xmlrpcval',
				$mixed,
				$type
			);
		}
	} // end method _autoserialize

	// Method: _call
	//
	//	Call Remitt server with the specified parameters. This
	//	should only be used by internal Remitt methods to
	//	complete abstraction.
	//
	// Parameters:
	//
	//	$method - Method on the Remitt server to call
	//
	//	$parameters - (optional) Array of parameters to call
	//	$method with. Defaults to NULL.
	//
	//	$debug - (optional) Whether debug code should be shown.
	//	Defaults to false.
	//
	// Returns:
	//
	//	Reply to call as PHP variable.
	//
	function _call ( $method, $parameters = NULL, $debug = false ) {
		// Form proper message object
		if ($parameters != NULL) {
			$message = CreateObject(
				'PHP.xmlrpcmsg',
				$method,
				( is_array($parameters) ? $parameters : array($parameters) )
			);
		} else {
			$message = CreateObject(
				'PHP.xmlrpcmsg',
				$method
			);
		}
		if ($debug) { print_r($message); }

		// If we're debugging, we set the debug flag
		$this->_connection->setDebug ( $debug );

		// Dispatch message to server
		$response = $this->_connection->send (
			$message,
			0,
			$this->protocol
		);
		if ($debug) { print_r($response); }

		// Deserialize response
		$d = $response->deserialize();

		// Handle faults
		if ($response->fn) {
			trigger_error(__("XML-RPC Fault:")." ".$d['faultCode']." (".$d['faultString'].")", E_USER_ERROR);
		} else {
			// If there is no fault, return as usual
			return $d;
		}
	} // end method _call

	// Method: _is_struct
	//
	//	Determines if in an array is a structure (associative array)
	//	or a regular array.
	//
	// Parameters:
	//
	//	$var - Variable to be typed
	//
	// Returns:
	//
	//	Boolean, true if $var is an associative array, false if it
	//	is not.
	//
	function _is_struct ( $var ) {
		// Catch non-array instance
		if (!is_array($var)) return false;

		// If there are non-numeric keys, it is a structure, otherwise
		// default to false.
		foreach ($var AS $k => $v) {
			if (!is_integer($k)) return true;
		}
		return false;
	} // end method _is_struct

} // end class Remitt

?>

About Koders | Resources | Downloads | Support | Black Duck | Terms of Service | DMCA | Privacy Policy | Contact Us