File: export.php

package info (click to toggle)
cacti 1.2.30%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 67,176 kB
  • sloc: php: 123,193; javascript: 29,825; sql: 2,595; xml: 1,823; sh: 1,228; perl: 194; makefile: 65; python: 51; ruby: 9
file content (1167 lines) | stat: -rw-r--r-- 38,080 bytes parent folder | download
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
<?php
/*
 +-------------------------------------------------------------------------+
 | Copyright (C) 2004-2024 The Cacti Group                                 |
 |                                                                         |
 | This program is free software; you can redistribute it and/or           |
 | modify it under the terms of the GNU General Public License             |
 | as published by the Free Software Foundation; either version 2          |
 | of the License, or (at your option) any later version.                  |
 |                                                                         |
 | This program is distributed in the hope that it will be useful,         |
 | but WITHOUT ANY WARRANTY; without even the implied warranty of          |
 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           |
 | GNU General Public License for more details.                            |
 +-------------------------------------------------------------------------+
 | Cacti: The Complete RRDtool-based Graphing Solution                     |
 +-------------------------------------------------------------------------+
 | This code is designed, written, and maintained by the Cacti Group. See  |
 | about.php and/or the AUTHORS file for specific developer information.   |
 +-------------------------------------------------------------------------+
 | http://www.cacti.net/                                                   |
 +-------------------------------------------------------------------------+
*/

function graph_template_to_xml($graph_template_id) {
	global $struct_graph, $fields_graph_template_input_edit, $struct_graph_item, $export_errors;

	// Remote caching item
	unset($struct_graph_item['data_template_id']);

	$hash['graph_template'] = get_hash_version('graph_template') . get_hash_graph_template($graph_template_id);
	$xml_text = '';

	$graph_template = db_fetch_row_prepared('SELECT *
		FROM graph_templates
		WHERE id = ?',
		array($graph_template_id));

	$graph_template_graph = db_fetch_row_prepared('SELECT *
		FROM graph_templates_graph
		WHERE graph_template_id = ?
		AND local_graph_id = 0
		ORDER BY id',
		array($graph_template_id));

	$graph_template_items = db_fetch_assoc_prepared('SELECT *
		FROM graph_templates_item
		WHERE graph_template_id = ?
		AND local_graph_id = 0
		AND hash != ""
		ORDER BY sequence',
		array($graph_template_id));

	$graph_template_inputs = db_fetch_assoc_prepared('SELECT *
		FROM graph_template_input
		WHERE graph_template_id = ?
		ORDER BY id',
		array($graph_template_id));

	if ((empty($graph_template['id'])) || (empty($graph_template_graph['id']))) {
		$export_errors++;
		raise_message(30);
		cacti_log('ERROR: Invalid Graph Template found in Database for Template ' . $graph_template['name'] . '[' . $graph_template['id'] . '] GTGid: ' . $graph_template_graph['id'] . '.  Please run database repair script to identify and/or correct.', false, 'WEBUI');
		return;
	}

	$xml_text .= '<hash_' . $hash['graph_template'] . ">\n";
	$xml_text .= "\t<name>"        . xml_character_encode($graph_template['name'])        . "</name>\n";
	$xml_text .= "\t<multiple>"    . xml_character_encode($graph_template['multiple'])    . "</multiple>\n";
	$xml_text .= "\t<test_source>" . xml_character_encode($graph_template['test_source']) . "</test_source>\n";

	$xml_text .= "\t<graph>\n";

	/* XML Branch: <graph> */
	foreach ($struct_graph as $field_name => $field_array) {
		if ($field_array['method'] != 'spacer') {
			$xml_text .= "\t\t<t_$field_name>" . xml_character_encode($graph_template_graph['t_' . $field_name]) . "</t_$field_name>\n";
			$xml_text .= "\t\t<$field_name>" . xml_character_encode($graph_template_graph[$field_name]) . "</$field_name>\n";
		}
	}

	$xml_text .= "\t</graph>\n";

	/* XML Branch: <items> */

	$xml_text .= "\t<items>\n";

	$i = 0;
	if (cacti_sizeof($graph_template_items) > 0) {
		foreach ($graph_template_items as $item) {
			$hash['graph_template_item'] = get_hash_version('graph_template_item') . get_hash_graph_template($item['id'], 'graph_template_item');

			$xml_text .= "\t\t<hash_" . $hash['graph_template_item'] . ">\n";

			foreach ($struct_graph_item as $field_name => $field_array) {
				if (!empty($item[$field_name])) {
					switch ($field_name) {
						case 'task_item_id':
							$xml_text .= "\t\t\t<$field_name>hash_" . get_hash_version('data_template_item') . get_hash_data_template($item[$field_name], 'data_template_item') . "</$field_name>\n";
							break;
						case 'cdef_id':
							$xml_text .= "\t\t\t<$field_name>hash_" . get_hash_version('cdef') . get_hash_cdef($item[$field_name]) . "</$field_name>\n";
							break;
						case 'vdef_id':
							$xml_text .= "\t\t\t<$field_name>hash_" . get_hash_version('vdef') . get_hash_vdef($item[$field_name]) . "</$field_name>\n";
							break;
						case 'gprint_id':
							$xml_text .= "\t\t\t<$field_name>hash_" . get_hash_version('gprint_preset') . get_hash_gprint($item[$field_name]) . "</$field_name>\n";
							break;
						case 'color_id':
							$xml_text .= "\t\t\t<$field_name>" . db_fetch_cell_prepared('SELECT hex FROM colors WHERE id = ?', array($item[$field_name])) . "</$field_name>\n";
							break;
						default:
							$xml_text .= "\t\t\t<$field_name>" . xml_character_encode($item[$field_name]) . "</$field_name>\n";
							break;
					}
				} else {
					$xml_text .= "\t\t\t<$field_name>" . xml_character_encode($item[$field_name]) . "</$field_name>\n";
				}
			}

			$xml_text .= "\t\t</hash_" . $hash['graph_template_item'] . ">\n";

			$i++;
		}
	}

	$xml_text .= "\t</items>\n";

	/* XML Branch: <inputs> */

	$xml_text .= "\t<inputs>\n";

	$i = 0;
	if (cacti_sizeof($graph_template_inputs) > 0) {
		foreach ($graph_template_inputs as $item) {
			$hash['graph_template_input'] = get_hash_version('graph_template_input') . get_hash_graph_template($item['id'], 'graph_template_input');

			$xml_text .= "\t\t<hash_" . $hash['graph_template_input'] . ">\n";

			foreach ($fields_graph_template_input_edit as $field_name => $field_array) {
				if (($field_array['method'] != 'hidden_zero') && ($field_array['method'] != 'hidden')) {
					$xml_text .= "\t\t\t<$field_name>" . xml_character_encode($item[$field_name]) . "</$field_name>\n";
				}
			}

			$graph_template_input_items = db_fetch_assoc_prepared('SELECT graph_template_item_id
				FROM graph_template_input_defs
				WHERE graph_template_input_id = ?',
				array($item['id']));

			$xml_text .= "\t\t\t<items>";

			$j = 0;
			if (cacti_sizeof($graph_template_input_items) > 0) {
				foreach ($graph_template_input_items as $item2) {
					$xml_text .= 'hash_' . get_hash_version('graph_template') . get_hash_graph_template($item2['graph_template_item_id'], 'graph_template_item');

					if (($j+1) < cacti_sizeof($graph_template_input_items)) {
						$xml_text .= '|';
					}

					$j++;
				}
			}

			$xml_text .= "</items>\n";
			$xml_text .= "\t\t</hash_" . $hash['graph_template_input'] . ">\n";

			$i++;
		}
	}

	$xml_text .= "\t</inputs>\n";
	$xml_text .= '</hash_' . $hash['graph_template'] . '>';

	return $xml_text;
}

function data_template_to_xml($data_template_id) {
	global $struct_data_source, $struct_data_source_item, $export_errors;

	$hash['data_template'] = get_hash_version('data_template') . get_hash_data_template($data_template_id);
	$xml_text = '';

	$data_template = db_fetch_row_prepared('SELECT id, name
		FROM data_template
		WHERE id = ?',
		array($data_template_id));

	$data_template_data = db_fetch_row_prepared('SELECT *
		FROM data_template_data
		WHERE data_template_id = ?
		AND local_data_id = 0
		ORDER BY id',
		array($data_template_id));

	$data_template_rrd = db_fetch_assoc_prepared('SELECT *
		FROM data_template_rrd
		WHERE data_template_id = ?
		AND local_data_id = 0
		AND hash != ""
		ORDER BY id',
		array($data_template_id));

	$data_input_data = db_fetch_assoc_prepared('SELECT *
		FROM data_input_data
		WHERE data_template_data_id = ?',
		array($data_template_data['id']));

	if ((empty($data_template['id'])) || (empty($data_template_data['id']))) {
		$export_errors++;
		raise_message(27);
		cacti_log('ERROR: Invalid Data Template found in Database.  Please run database repair script to identify and/or correct.', false, 'WEBUI');
		return;
	}

	$xml_text .= '<hash_' . $hash['data_template'] . ">\n\t<name>" . xml_character_encode($data_template['name']) . "</name>\n\t<ds>\n";

	/* XML Branch: <ds> */
	foreach ($struct_data_source as $field_name => $field_array) {
		if (isset($data_template_data['t_' . $field_name])) {
			$xml_text .= "\t\t<t_$field_name>" . xml_character_encode($data_template_data['t_' . $field_name]) . "</t_$field_name>\n";
		}

		if (($field_name == 'data_input_id') && (!empty($data_template_data[$field_name]))) {
			$xml_text .= "\t\t<$field_name>hash_" . get_hash_version('data_input_method') . get_hash_data_input($data_template_data[$field_name]) . "</$field_name>\n";
		} elseif (($field_name == 'data_source_profile_id') && (!empty($data_template_data[$field_name]))) {
			$xml_text .= "\t\t<$field_name>hash_" . get_hash_version('data_source_profile') . get_hash_data_source_profile($data_template_data[$field_name]) . "</$field_name>\n";
		} else {
			if (isset($data_template_data[$field_name])) {
				$xml_text .= "\t\t<$field_name>" . xml_character_encode($data_template_data[$field_name]) . "</$field_name>\n";
			}
		}
	}

	$xml_text .= "\t</ds>\n";

	/* XML Branch: <items> */

	$xml_text .= "\t<items>\n";

	$i = 0;
	if (cacti_sizeof($data_template_rrd) > 0) {
		foreach ($data_template_rrd as $item) {
			$hash['data_template_item'] = get_hash_version('data_template_item') . get_hash_data_template($item['id'], 'data_template_item');

			$xml_text .= "\t\t<hash_" . $hash['data_template_item'] . ">\n";

			foreach ($struct_data_source_item as $field_name => $field_array) {
				if (isset($item['t_' . $field_name])) {
					$xml_text .= "\t\t\t<t_$field_name>" . xml_character_encode($item['t_' . $field_name]) . "</t_$field_name>\n";
				}

				if (($field_name == 'data_input_field_id') && (!empty($item[$field_name]))) {
					$xml_text .= "\t\t\t<$field_name>hash_" . get_hash_version('data_input_field') . get_hash_data_input($item[$field_name], 'data_input_field') . "</$field_name>\n";
				} else {
					if (isset($item[$field_name])) {
						$xml_text .= "\t\t\t<$field_name>" . xml_character_encode($item[$field_name]) . "</$field_name>\n";
					}
				}
			}

			$xml_text .= "\t\t</hash_" . $hash['data_template_item'] . ">\n";

			$i++;
		}
	}

	$xml_text .= "\t</items>\n";

	/* XML Branch: <data> */

	$xml_text .= "\t<data>\n";

	$i = 0;
	if (cacti_sizeof($data_input_data) > 0) {
		foreach ($data_input_data as $item) {
			$xml_text .= "\t\t<item_" . str_pad(strval($i), 3, '0', STR_PAD_LEFT) . ">\n";

			$xml_text .= "\t\t\t<data_input_field_id>hash_" . get_hash_version('data_input_field') . get_hash_data_input($item['data_input_field_id'], 'data_input_field') . "</data_input_field_id>\n";
			$xml_text .= "\t\t\t<t_value>" . xml_character_encode($item['t_value']) . "</t_value>\n";
			$xml_text .= "\t\t\t<value>" . xml_character_encode($item['value']) . "</value>\n";

			$xml_text .= "\t\t</item_" . str_pad(strval($i), 3, '0', STR_PAD_LEFT) . ">\n";

			$i++;
		}
	}

	$xml_text .= "\t</data>\n";

	$xml_text .= '</hash_' . $hash['data_template'] . '>';

	return $xml_text;
}

function data_input_method_to_xml($data_input_id) {
	global $fields_data_input_edit, $fields_data_input_field_edit, $fields_data_input_field_edit_1, $export_errors;

	/* aggregate field arrays */
	$fields_data_input_field_edit += $fields_data_input_field_edit_1;

	$hash['data_input_method'] = get_hash_version('data_input_method') . get_hash_data_input($data_input_id);
	$xml_text = '';

	$data_input = db_fetch_row_prepared('SELECT *
		FROM data_input
		WHERE id = ?',
		array($data_input_id));

	$data_input_fields = db_fetch_assoc_prepared('SELECT *
		FROM data_input_fields
		WHERE data_input_id = ?
		ORDER BY id',
		array($data_input_id));

	if (empty($data_input['id'])) {
		$export_errors++;
		raise_message(26);
		cacti_log('ERROR: Invalid Data Input Method found in Data Template.  Please run database repair script to identify and/or correct.', false, 'WEBUI');
		return;
	}

	$xml_text .= '<hash_' . $hash['data_input_method'] . ">\n";

	/* XML Branch: <> */
	foreach ($fields_data_input_edit as $field_name => $field_array) {
		if (($field_array['method'] != 'hidden_zero') &&
			($field_array['method'] != 'hidden') &&
			($field_array['method'] != 'spacer') &&
			($field_array['method'] != 'other')) {
			if ($field_name == 'input_string') {
				$xml_text .= "\t<$field_name>" . base64_encode($data_input[$field_name]) . "</$field_name>\n";
			} else {
				$xml_text .= "\t<$field_name>" . xml_character_encode($data_input[$field_name]) . "</$field_name>\n";
			}
		}
	}

	/* XML Branch: <fields> */

	$xml_text .= "\t<fields>\n";

	if (cacti_sizeof($data_input_fields)) {
		foreach ($data_input_fields as $item) {
			$hash['data_input_field'] = get_hash_version('data_input_field') . get_hash_data_input($item['id'], 'data_input_field');

			$xml_text .= "\t\t<hash_" . $hash['data_input_field'] . ">\n";

			foreach ($fields_data_input_field_edit as $field_name => $field_array) {
				if (($field_name == 'input_output') && (!empty($item[$field_name]))) {
					$xml_text .= "\t\t\t<$field_name>" . xml_character_encode($item[$field_name]) . "</$field_name>\n";
				} else {
					$method = $field_array['method'];

					if ($method != 'hidden_zero' && $method != 'hidden' && $method != 'spacer') {
						// Work around renaming of field in form
						// To get around JavaScript form issue
						// In data_input.php
						if ($field_name == 'fname') {
							$field_name = 'name';
						}

						$xml_text .= "\t\t\t<$field_name>" . xml_character_encode($item[$field_name]) . "</$field_name>\n";
					}
				}
			}

			$xml_text .= "\t\t</hash_" . $hash['data_input_field'] . ">\n";
		}
	}

	$xml_text .= "\t</fields>\n";

	$xml_text .= '</hash_' . $hash['data_input_method'] . '>';

	return $xml_text;
}


/** encode a cdef along with all cdef_items as XML text
 * @param int $cdef_id	- the id of the cdef that has to be encoded
 * @return string		- the resulting XML text
 */
function cdef_to_xml($cdef_id) {
	global $fields_cdef_edit, $export_errors;

	$fields_cdef_item_edit = array(
		'sequence' => 'sequence',
		'type' => 'type',
		'value' => 'value'
	);

	$hash['cdef'] = get_hash_version('cdef') . get_hash_cdef($cdef_id);
	$xml_text = '';

	$cdef = db_fetch_row_prepared('SELECT *
		FROM cdef
		WHERE id = ?',
		array($cdef_id));

	$cdef_items = db_fetch_assoc_prepared('SELECT *
		FROM cdef_items
		WHERE cdef_id = ?
		ORDER BY sequence',
		array($cdef_id));

	if (empty($cdef['id'])) {
		$export_errors++;
		raise_message(25);
		cacti_log('ERROR: Invalid CDEF found in Graph Template.  Please run database repair script to identify and/or correct.', false, 'WEBUI');
		return;
	}

	$xml_text .= '<hash_' . $hash['cdef'] . ">\n";

	/* XML Branch: <> */
	foreach ($fields_cdef_edit as $field_name => $field_array) {
		if (($field_array['method'] != 'hidden_zero') && ($field_array['method'] != 'hidden')) {
			$xml_text .= "\t<$field_name>" . xml_character_encode($cdef[$field_name]) . "</$field_name>\n";
		}
	}

	/* XML Branch: <items> */

	$xml_text .= "\t<items>\n";

	$i = 0;
	if (cacti_sizeof($cdef_items) > 0) {
		foreach ($cdef_items as $item) {
			$hash['cdef_item'] = get_hash_version('cdef_item') . get_hash_cdef($item['id'], 'cdef_item');

			$xml_text .= "\t\t<hash_" . $hash['cdef_item'] . ">\n";

			/* now do the encoding */
			foreach ($fields_cdef_item_edit as $field_name => $field_array) {
				/* check, if an inherited cdef as to be encoded */
				if (($field_name == 'value') && ($item['type'] == '5')) {
					$xml_text .= "\t\t\t<$field_name>hash_" . get_hash_version('cdef') . get_hash_cdef($item[$field_name]) . "</$field_name>\n";
				} else {
					$xml_text .= "\t\t\t<$field_name>" . xml_character_encode($item[$field_name]) . "</$field_name>\n";
				}
			}

			$xml_text .= "\t\t</hash_" . $hash['cdef_item'] . ">\n";

			$i++;
		}
	}

	$xml_text .= "\t</items>\n";
	$xml_text .= '</hash_' . $hash['cdef'] . '>';

	return $xml_text;
}

/** encode given VDEF as XML string
 * @param int $vdef_id  - id of VDEF
 * @return string       - XML text of encoded VDEF
 */
function vdef_to_xml($vdef_id) {
	global $config;

	include_once($config['library_path'] . '/vdef.php');

	$hash['vdef'] = get_hash_version('vdef') . get_hash_vdef($vdef_id);
	$xml_text = '';

	$vdef = db_fetch_row_prepared('SELECT *
		FROM vdef
		WHERE id = ?',
		array($vdef_id));

	$vdef_items = db_fetch_assoc_prepared('SELECT *
		FROM vdef_items
		WHERE vdef_id = ?
		ORDER BY sequence',
		array($vdef_id));

	if (empty($vdef['id'])) {
		$err_msg = 'Invalid VDEF.';
		return $err_msg;
	}

	$xml_text .= '<hash_' . $hash['vdef'] . ">\n";

	/* XML Branch: <> */
	$fields_vdef_edit = preset_vdef_form_list();
	foreach ($fields_vdef_edit as $field_name => $field_array) {
		if (($field_array['method'] != 'hidden_zero') && ($field_array['method'] != 'hidden') && ($field_array['method'] != 'spacer')) {
			$xml_text .= "\t<$field_name>" . xml_character_encode($vdef[$field_name]) . "</$field_name>\n";
		}
	}

	/* XML Branch: <items> */

	$xml_text .= "\t<items>\n";

	$i = 0;
	if (cacti_sizeof($vdef_items) > 0) {
		foreach ($vdef_items as $item) {
			$hash['vdef_item'] = get_hash_version('vdef_item') . get_hash_vdef($item['id'], 'vdef_item');

			$xml_text .= "\t\t<hash_" . $hash['vdef_item'] . ">\n";
			$fields_vdef_item_edit = preset_vdef_item_form_list();
			foreach ($fields_vdef_item_edit as $field_name) {
				$xml_text .= "\t\t\t<$field_name>" . xml_character_encode($item[$field_name]) . "</$field_name>\n";
			}
			$xml_text .= "\t\t</hash_" . $hash['vdef_item'] . ">\n";

			$i++;
		}
	}

	$xml_text .= "\t</items>\n";
	$xml_text .= '</hash_' . $hash['vdef'] . '>';

	return $xml_text;
}

function gprint_preset_to_xml($gprint_preset_id) {
	global $fields_grprint_presets_edit, $export_errors;

	$hash = get_hash_version('gprint_preset') . get_hash_gprint($gprint_preset_id);
	$xml_text = '';

	$graph_templates_gprint = db_fetch_row_prepared('SELECT *
		FROM graph_templates_gprint
		WHERE id = ?',
		array($gprint_preset_id));

	if (empty($graph_templates_gprint['id'])) {
		$export_errors++;
		raise_message(24);
		cacti_log('ERROR: Invalid GPRINT preset found in Graph Template.  Please run database repair script to identify and/or correct.', false, 'WEBUI');
		return;
	}

	$xml_text .= "<hash_$hash>\n";

	/* XML Branch: <> */
	foreach ($fields_grprint_presets_edit as $field_name => $field_array) {
		if (($field_array['method'] != 'hidden_zero') && ($field_array['method'] != 'hidden')) {
			$xml_text .= "\t<$field_name>" . xml_character_encode($graph_templates_gprint[$field_name]) . "</$field_name>\n";
		}
	}

	$xml_text .= "</hash_$hash>";

	return $xml_text;
}

function data_source_profile_to_xml($data_source_profile_id) {
	global $fields_profile_edit, $fields_profile_rra_edit, $export_errors;

	$hash        = get_hash_version('data_source_profile') . get_hash_data_source_profile($data_source_profile_id);
	$xml_text    = '';

	$profile = db_fetch_row_prepared('SELECT *
		FROM data_source_profiles
		WHERE id = ?',
		array($data_source_profile_id));

	$profile_cf = db_fetch_assoc_prepared('SELECT *
		FROM data_source_profiles_cf
		WHERE data_source_profile_id = ?
		ORDER BY consolidation_function_id',
		array($data_source_profile_id));

	$profile_rra = db_fetch_assoc_prepared('SELECT *
		FROM data_source_profiles_rra
		WHERE data_source_profile_id = ?
		ORDER BY steps',
		array($data_source_profile_id));

	if (empty($profile['id'])) {
		$export_errors++;
		raise_message(23);
		cacti_log('ERROR: Invalid Data Source Profile found during Data Template export.  Please run database repair script to identify and/or correct.', false, 'WEBUI');
		return;
	}

	$xml_text .= "<hash_$hash>\n";

	/* XML Branch: <> */
	foreach ($fields_profile_edit as $field_name => $field_array) {
		if (($field_array['method'] != 'hidden_zero') && ($field_array['method'] != 'hidden')) {
			if (isset($profile[$field_name])) {
				$xml_text .= "\t<$field_name>" . xml_character_encode($profile[$field_name]) . "</$field_name>\n";
			}
		}
	}

	$xml_text .= "\t<cf_items>";

	/* XML Branch: <cf_items> */
	$i = 0;
	if (cacti_sizeof($profile_cf) > 0) {
		foreach ($profile_cf as $item) {
			$xml_text .= $item['consolidation_function_id'];

			if (($i+1) < cacti_sizeof($profile_cf)) {
				$xml_text .= '|';
			}

			$i++;
		}
	}

	$xml_text .= "</cf_items>\n";

	$xml_text .= "\t<items>\n";

	$i = 0;
	if (cacti_sizeof($profile_rra)) {
		foreach ($profile_rra as $item) {
			$xml_text .= "\t\t<item_" . str_pad(strval($i), 3, '0', STR_PAD_LEFT) . ">\n";
			foreach ($fields_profile_rra_edit as $field_name => $field_array) {
				if (($field_array['method'] != 'hidden_zero') && ($field_array['method'] != 'hidden' && ($field_array['method'] != 'other')) && ($field_array['method'] != 'spacer')) {
					$xml_text .= "\t\t\t<$field_name>" . xml_character_encode($item[$field_name]) . "</$field_name>\n";
				}
			}
			$xml_text .= "\t\t</item_" . str_pad(strval($i), 3, '0', STR_PAD_LEFT) . ">\n";

			$i++;
		}
	}

	$xml_text .= "\t</items>\n";


	$xml_text .= "</hash_$hash>";

	return $xml_text;
}

function host_template_to_xml($host_template_id) {
	global $fields_host_template_edit, $export_errors;

	$hash = get_hash_version('host_template') . get_hash_host_template($host_template_id);
	$xml_text = '';

	$host_template = db_fetch_row_prepared('SELECT *
		FROM host_template
		WHERE id = ?',
		array($host_template_id));

	$host_template_graph = db_fetch_assoc_prepared('SELECT *
		FROM host_template_graph
		WHERE host_template_id = ?
		ORDER BY graph_template_id',
		array($host_template_id));

	$host_template_snmp_query = db_fetch_assoc_prepared('SELECT *
		FROM host_template_snmp_query
		WHERE host_template_id = ?
		ORDER BY snmp_query_id',
		array($host_template_id));

	if (empty($host_template['id'])) {
		$export_errors++;
		raise_message(28);
		cacti_log('ERROR: Invalid Device Template found during Export.  Please run database repair script to identify and/or correct.', false, 'WEBUI');
		return;
	}

	$xml_text .= "<hash_$hash>\n";

	/* XML Branch: <> */
	foreach ($fields_host_template_edit as $field_name => $field_array) {
		if (($field_array['method'] != 'hidden_zero') && ($field_array['method'] != 'hidden')) {
			$xml_text .= "\t<$field_name>" . xml_character_encode($host_template[$field_name]) . "</$field_name>\n";
		}
	}

	/* XML Branch: <graph_templates> */
	$xml_text .= "\t<graph_templates>";

	$j = 0;
	if (cacti_sizeof($host_template_graph) > 0) {
		foreach ($host_template_graph as $item) {
			$xml_text .= 'hash_' . get_hash_version('graph_template') . get_hash_graph_template($item['graph_template_id']);

			if (($j+1) < cacti_sizeof($host_template_graph)) {
				$xml_text .= '|';
			}

			$j++;
		}
	}

	$xml_text .= "</graph_templates>\n";

	/* XML Branch: <data_queries> */
	$xml_text .= "\t<data_queries>";

	$j = 0;
	if (cacti_sizeof($host_template_snmp_query) > 0) {
		foreach ($host_template_snmp_query as $item) {
			$xml_text .= 'hash_' . get_hash_version('data_query') . get_hash_data_query($item['snmp_query_id']);

			if (($j+1) < cacti_sizeof($host_template_snmp_query)) {
				$xml_text .= '|';
			}

			$j++;
		}
	}

	$xml_text .= "</data_queries>\n";

	$xml_text .= "</hash_$hash>";

	return $xml_text;
}

function data_query_to_xml($data_query_id) {
	global $fields_data_query_edit, $fields_data_query_item_edit, $export_errors;

	$hash['data_query'] = get_hash_version('data_query') . get_hash_data_query($data_query_id);
	$xml_text = '';

	$snmp_query = db_fetch_row_prepared('SELECT *
		FROM snmp_query
		WHERE id = ?',
		array($data_query_id));

	$snmp_query_graph = db_fetch_assoc_prepared('SELECT *
		FROM snmp_query_graph
		WHERE snmp_query_id = ?
		ORDER BY id',
		array($data_query_id));

	if (empty($snmp_query['id'])) {
		$export_errors++;
		raise_message(28);
		cacti_log('ERROR: Invalid Data Query found during Export.  Please run database repair script to identify and/or correct.', false, 'WEBUI');
		return;
	}

	$xml_text .= '<hash_' . $hash['data_query'] . ">\n";

	/* XML Branch: <> */
	foreach ($fields_data_query_edit as $field_name => $field_array) {
		if (($field_name == 'data_input_id') && (!empty($snmp_query[$field_name]))) {
			$xml_text .= "\t<$field_name>hash_" . get_hash_version('data_input_method') . get_hash_data_input($snmp_query[$field_name]) . "</$field_name>\n";
		} else {
			if (($field_array['method'] != 'hidden_zero') && ($field_array['method'] != 'hidden')) {
				$xml_text .= "\t<$field_name>" . xml_character_encode($snmp_query[$field_name]) . "</$field_name>\n";
			}
		}
	}

	/* XML Branch: <graphs> */

	$xml_text .= "\t<graphs>\n";

	$i = 0;
	if (cacti_sizeof($snmp_query_graph) > 0) {
		foreach ($snmp_query_graph as $item) {
			$hash['data_query_graph'] = get_hash_version('data_query_graph') . get_hash_data_query($item['id'], 'data_query_graph');

			$xml_text .= "\t\t<hash_" . $hash['data_query_graph'] . ">\n";

			foreach ($fields_data_query_item_edit as $field_name => $field_array) {
				if (($field_name == 'graph_template_id') && (!empty($item[$field_name]))) {
					$xml_text .= "\t\t\t<$field_name>hash_" . get_hash_version('graph_template') . get_hash_graph_template($item[$field_name]) . "</$field_name>\n";
				} else {
					if (($field_array['method'] != 'hidden_zero') && ($field_array['method'] != 'hidden')) {
						$xml_text .= "\t\t\t<$field_name>" . xml_character_encode($item[$field_name]) . "</$field_name>\n";
					}
				}
			}

			$snmp_query_graph_rrd_sv = db_fetch_assoc_prepared('SELECT *
				FROM snmp_query_graph_rrd_sv
				WHERE snmp_query_graph_id = ?
				ORDER BY sequence',
				array($item['id']));

			$snmp_query_graph_sv = db_fetch_assoc_prepared('SELECT *
				FROM snmp_query_graph_sv
				WHERE snmp_query_graph_id = ?
				ORDER BY sequence',
				array($item['id']));

			$snmp_query_graph_rrd = db_fetch_assoc_prepared('SELECT *
				FROM snmp_query_graph_rrd
				WHERE snmp_query_graph_id = ?
				AND data_template_id > 0
				ORDER BY data_template_rrd_id',
				array($item['id']));

			/* XML Branch: <graphs/rrd> */

			$xml_text .= "\t\t\t<rrd>\n";

			$i = 0;
			if (cacti_sizeof($snmp_query_graph_rrd) > 0) {
				foreach ($snmp_query_graph_rrd as $item2) {
					$xml_text .= "\t\t\t\t<item_" . str_pad(strval($i), 3, '0', STR_PAD_LEFT) . ">\n";

					$xml_text .= "\t\t\t\t\t<snmp_field_name>" . $item2['snmp_field_name'] . "</snmp_field_name>\n";
					$xml_text .= "\t\t\t\t\t<data_template_id>hash_" . get_hash_version('data_template') . get_hash_data_template($item2['data_template_id']) . "</data_template_id>\n";
					$xml_text .= "\t\t\t\t\t<data_template_rrd_id>hash_" . get_hash_version('data_template_item') . get_hash_data_template($item2['data_template_rrd_id'], 'data_template_item') . "</data_template_rrd_id>\n";

					$xml_text .= "\t\t\t\t</item_" . str_pad(strval($i), 3, '0', STR_PAD_LEFT) . ">\n";

					$i++;
				}
			}

			$xml_text .= "\t\t\t</rrd>\n";

			/* XML Branch: <graphs/sv_graph> */

			$xml_text .= "\t\t\t<sv_graph>\n";

			$j = 0;
			if (cacti_sizeof($snmp_query_graph_sv) > 0) {
				foreach ($snmp_query_graph_sv as $item2) {
					$hash['data_query_sv_graph'] = get_hash_version('data_query_sv_graph') . get_hash_data_query($item2['id'], 'data_query_sv_graph');

					$xml_text .= "\t\t\t\t<hash_" . $hash['data_query_sv_graph'] . ">\n";

					$xml_text .= "\t\t\t\t\t<field_name>" . xml_character_encode($item2['field_name']) . "</field_name>\n";
					$xml_text .= "\t\t\t\t\t<sequence>" . $item2['sequence'] . "</sequence>\n";
					$xml_text .= "\t\t\t\t\t<text>" . xml_character_encode($item2['text']) . "</text>\n";

					$xml_text .= "\t\t\t\t</hash_" . $hash['data_query_sv_graph'] . ">\n";

					$j++;
				}
			}

			$xml_text .= "\t\t\t</sv_graph>\n";

			/* XML Branch: <graphs/sv_data_source> */

			$xml_text .= "\t\t\t<sv_data_source>\n";

			$j = 0;
			if (cacti_sizeof($snmp_query_graph_rrd_sv) > 0) {
				foreach ($snmp_query_graph_rrd_sv as $item2) {
					$hash['data_query_sv_data_source'] = get_hash_version('data_query_sv_data_source') . get_hash_data_query($item2['id'], 'data_query_sv_data_source');

					$xml_text .= "\t\t\t\t<hash_" . $hash['data_query_sv_data_source'] . ">\n";

					$xml_text .= "\t\t\t\t\t<field_name>" . xml_character_encode($item2['field_name']) . "</field_name>\n";
					$xml_text .= "\t\t\t\t\t<data_template_id>hash_" . get_hash_version('data_template') . get_hash_data_template($item2['data_template_id']) . "</data_template_id>\n";
					$xml_text .= "\t\t\t\t\t<sequence>" . $item2['sequence'] . "</sequence>\n";
					$xml_text .= "\t\t\t\t\t<text>" . xml_character_encode($item2['text']) . "</text>\n";

					$xml_text .= "\t\t\t\t</hash_" . $hash['data_query_sv_data_source'] . ">\n";

					$j++;
				}
			}

			$xml_text .= "\t\t\t</sv_data_source>\n";

			$xml_text .= "\t\t</hash_" . $hash['data_query_graph'] . ">\n";

			$i++;
		}
	}

	$xml_text .= "\t</graphs>\n";

	$xml_text .= '</hash_' . $hash['data_query'] . '>';

	return $xml_text;
}

function resolve_dependencies($type, $id, $dep_array) {
	/* make sure we define our variables */
	if (!isset($dep_array[$type])) {
		$dep_array[$type] = array();
	}

	switch ($type) {
	case 'graph_template':
		/* dep: data template */
		$graph_template_items = db_fetch_assoc_prepared('SELECT
			data_template_rrd.data_template_id
			FROM (graph_templates_item,data_template_rrd)
			WHERE graph_templates_item.task_item_id = data_template_rrd.id
			AND graph_templates_item.graph_template_id = ?
			AND graph_templates_item.local_graph_id = 0
			AND graph_templates_item.task_item_id > 0
			GROUP BY data_template_rrd.data_template_id', array($id));

		if (cacti_sizeof($graph_template_items) > 0) {
			foreach ($graph_template_items as $item) {
				if (!isset($dep_array['data_template'][$item['data_template_id']])) {
					$dep_array = resolve_dependencies('data_template', $item['data_template_id'], $dep_array);
				}
			}
		}

		/* dep: cdef */
		$cdef_items = db_fetch_assoc_prepared('SELECT cdef_id
			FROM graph_templates_item
			WHERE graph_template_id = ?
			AND local_graph_id = 0
			AND cdef_id > 0
			GROUP BY cdef_id', array($id));

		$recursive = true;
		/* in the first turn, search all inherited cdef items related to all cdef's known on highest recursion level */
		$search_cdef_items = array_rekey($cdef_items, 'cdef_id', 'cdef_id');
		if (cacti_sizeof($cdef_items) > 0) {
			while ($recursive) {
				/* are there any inherited cdef's within those referenced by any graph item?
				 * search for all cdef_items of type = 5 (inherited cdef)
				 * but fetch only those related to already given cdef's */
				$sql = 'SELECT value as cdef_id ' .
					'FROM cdef_items ' .
					'WHERE type = 5 ' .
					'AND ' . array_to_sql_or($search_cdef_items, 'cdef_id');

				$inherited_cdef_items = db_fetch_assoc($sql);

				/* in case we found any */
				if (cacti_sizeof($inherited_cdef_items) > 0) {
					/* join all cdef's found
					 * ATTENTION!
					 * sequence of parameters matters!
					 * we must place the newly found inherited items first
					 * reason is, that during import, the leaves have to be tackled first,
					 * that is, the inherited items must be placed first so that they are "resolved" (decoded)
					 * first during re-import */
					$cdef_items = array_merge_recursive($inherited_cdef_items, $cdef_items);
					/* for the next turn, search only new cdef's */
					$search_cdef_items = $inherited_cdef_items;
				} else {
					/* else stop recursion */
					$recursive = false;
				}
			}

			foreach ($cdef_items as $item) {
				if (!isset($dep_array['cdef'][$item['cdef_id']])) {
					$dep_array = resolve_dependencies('cdef', $item['cdef_id'], $dep_array);
				}
			}
		}

		/* dep: vdef */
		$vdef_items = db_fetch_assoc_prepared('SELECT vdef_id
			FROM graph_templates_item
			WHERE graph_template_id = ?
			AND local_graph_id = 0
			AND vdef_id > 0
			GROUP BY vdef_id',
			array($id));

		if (cacti_sizeof($vdef_items) > 0) {
			foreach ($vdef_items as $item) {
				if (!isset($dep_array['vdef'][$item['vdef_id']])) {
					$dep_array = resolve_dependencies('vdef', $item['vdef_id'], $dep_array);
				}
			}
		}

		/* dep: gprint preset */
		$graph_template_items = db_fetch_assoc_prepared('SELECT gprint_id
			FROM graph_templates_item
			WHERE graph_template_id = ?
			AND local_graph_id = 0
			AND gprint_id > 0
			GROUP BY gprint_id',
			array($id));

		if (cacti_sizeof($graph_template_items) > 0) {
			foreach ($graph_template_items as $item) {
				if (!isset($dep_array['gprint_preset'][$item['gprint_id']])) {
					$dep_array = resolve_dependencies('gprint_preset', $item['gprint_id'], $dep_array);
				}
			}
		}

		break;
	case 'data_template':
		/* dep: data input method */
		$item = db_fetch_row_prepared('SELECT data_input_id
			FROM data_template_data
			WHERE data_template_id = ?
			AND local_data_id = 0
			AND data_input_id > 0',
			array($id));

		if ((!empty($item)) && (!isset($dep_array['data_input_method'][$item['data_input_id']]))) {
			$dep_array = resolve_dependencies('data_input_method', $item['data_input_id'], $dep_array);
		}

		/* dep: data source profiles */
		$profiles = db_fetch_assoc_prepared('SELECT DISTINCT data_source_profile_id
			FROM data_template_data
			WHERE data_template_id = ?
			AND local_data_id = 0',
			array($id));

		if (cacti_sizeof($profiles)) {
			foreach ($profiles as $item) {
				if (!isset($dep_array['data_source_profile'][$item['data_source_profile_id']])) {
					$dep_array = resolve_dependencies('data_source_profile', $item['data_source_profile_id'], $dep_array);
				}
			}
		}

		break;
	case 'data_query':
		/* dep: data input method */
		$item = db_fetch_row_prepared('SELECT data_input_id
			FROM snmp_query
			WHERE id = ?
			AND data_input_id > 0',
			array($id));

		if ((!empty($item)) && (!isset($dep_array['data_input_method'][$item['data_input_id']]))) {
			$dep_array = resolve_dependencies('data_input_method', $item['data_input_id'], $dep_array);
		}

		/* dep: graph template */
		$snmp_query_graph = db_fetch_assoc_prepared('SELECT graph_template_id
			FROM snmp_query_graph
			WHERE snmp_query_id = ?
			AND graph_template_id > 0
			GROUP BY graph_template_id',
			array($id));

		if (cacti_sizeof($snmp_query_graph) > 0) {
			foreach ($snmp_query_graph as $item) {
				if (!isset($dep_array['graph_template'][$item['graph_template_id']])) {
					$dep_array = resolve_dependencies('graph_template', $item['graph_template_id'], $dep_array);
				}
			}
		}

		break;
	case 'host_template':
		/* dep: graph template */
		$host_template_graph = db_fetch_assoc_prepared('SELECT graph_template_id
			FROM host_template_graph
			WHERE host_template_id = ?
			AND graph_template_id > 0
			GROUP BY graph_template_id',
			array($id));

		if (cacti_sizeof($host_template_graph) > 0) {
			foreach ($host_template_graph as $item) {
				if (!isset($dep_array['graph_template'][$item['graph_template_id']])) {
					$dep_array = resolve_dependencies('graph_template', $item['graph_template_id'], $dep_array);
				}
			}
		}

		/* dep: data query */
		$host_template_snmp_query = db_fetch_assoc_prepared('SELECT snmp_query_id
			FROM host_template_snmp_query
			WHERE host_template_id = ?
			AND snmp_query_id > 0
			GROUP BY snmp_query_id',
			array($id));

		if (cacti_sizeof($host_template_snmp_query) > 0) {
			foreach ($host_template_snmp_query as $item) {
				if (!isset($dep_array['data_query'][$item['snmp_query_id']])) {
					$dep_array = resolve_dependencies('data_query', $item['snmp_query_id'], $dep_array);
				}
			}
		}

		break;
	default:
		$param = array();
		$param['type']      = $type;
		$param['id']        = $id;
		$param['dep_array'] = $dep_array;

		$param = api_plugin_hook_function('resolve_dependencies', $param);

		$dep_array = $param['dep_array'];
		break;
	}

	/* update the dependency array */
	$dep_array[$type][$id] = $id;

	return $dep_array;
}

function get_item_xml($type, $id, $follow_deps) {
	$xml_text = '';
	$xml_indent = '';

	if ($follow_deps == true) {
		/* follow all dependencies recursively */
		$dep_array = resolve_dependencies($type, $id, array());
	} else {
		/* we are not supposed to resolve dependencies */
		$dep_array[$type][$id] = $id;
	}

	if (cacti_sizeof($dep_array)) {
		foreach ($dep_array as $dep_type => $dep_arr) {
			foreach ($dep_arr as $dep_id => $dep_id) {
				switch($dep_type) {
				case 'graph_template':
					$xml_text .= "\n" . graph_template_to_xml($dep_id);
					break;
				case 'data_template':
					$xml_text .= "\n" . data_template_to_xml($dep_id);
					break;
				case 'host_template':
					$xml_text .= "\n" . host_template_to_xml($dep_id);
					break;
				case 'data_input_method':
					$xml_text .= "\n" . data_input_method_to_xml($dep_id);
					break;
				case 'data_query':
					$xml_text .= "\n" . data_query_to_xml($dep_id);
					break;
				case 'gprint_preset':
					$xml_text .= "\n" . gprint_preset_to_xml($dep_id);
					break;
				case 'cdef':
					$xml_text .= "\n" . cdef_to_xml($dep_id);
					break;
				case 'vdef':
					$xml_text .= "\n" . vdef_to_xml($dep_id);
					break;
				case 'data_source_profile':
					$xml_text .= "\n" . data_source_profile_to_xml($dep_id);
					break;

				default:
					$param = array();
					$param['dep_id']   = $dep_id;
					$param['dep_type'] = $dep_type;
					$param['xml_text'] = $xml_text;

					$param = api_plugin_hook_function('export_action', $param);

					$xml_text = $param['xml_text'];
				}
			}
		}
	}

	$xml_array = explode("\n", $xml_text);

	for ($i=0; $i<cacti_count($xml_array); $i++) {
		$xml_indent .= "\t" . $xml_array[$i] . "\n";
	}

	$xml_text = '<cacti>' . $xml_indent . '</cacti>';

	return $xml_text;
}

function xml_character_encode($text) {
	return html_escape($text);
}