forked from noackorama/ZensusPlugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzensus_xml_func.php
575 lines (528 loc) · 24.2 KB
/
zensus_xml_func.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
<?php
/**
* create zensus_xmlheader
*
* This function creates a xml-header for output.
* Its contents are Name of University, Stud.IP-Version, Range of Export (e.g. "root"), and temporal range.
*
* @access public
* @return string xml-header
*/
function zensus_xmlheader($ex_sem = '')
{
global $UNI_NAME_CLEAN, $SOFTWARE_VERSION;
$semester = $ex_sem ? Semester::find($ex_sem) : Semester::findCurrent();
$xml_tag_string = '<?xml version="1.0" encoding="utf-8" ?>' . "\n";
$xml_tag_string .= "<studip version=\"" . zensus_xmlescape ($SOFTWARE_VERSION) . "\" logo=\"". zensus_xmlescape ($GLOBALS['ASSETS_URL']."images/logos/logo2b.gif") . "\"";
if ($UNI_NAME_CLEAN != "") $xml_tag_string .= " uni=\"" . zensus_xmlescape ($UNI_NAME_CLEAN) . "\"";
if ($semester)
$xml_tag_string .= " zeitraum=\"" . zensus_xmlescape ($semester->name) . "\" semester_id=\"" . zensus_xmlescape ($semester->getId()) . "\"";
$xml_tag_string .= ">\n";
return $xml_tag_string;
}
/**
* create opening xml-tag
*
* This function creates an open xml-tag.
* The tag-name is defined by the given parameter $tag_name.
* An optional parameter allows to set an attribute named "key".
*
* @access public
* @param string tag name
* @param string value for optional attribute "key"
* @return string xml open tag
*/
function zensus_xmlopen_tag($tag_name, $tag_key = "")
{
if ($tag_key != "")
$xml_tag_string .= " key=\"" . zensus_xmlescape ($tag_key ) ."\"" ;
$xml_tag_string = "<" . $tag_name . $xml_tag_string . ">";
return $xml_tag_string;
}
/**
* create closing xml-tag
*
* This function creates a closed xml-tag.
* The tag-name is defined by the given parameter $tag_name.
*
* @access public
* @param string tag name
* @return string xml close tag
*/
function zensus_xmlclose_tag($tag_name)
{
$xml_tag_string = "</" . $tag_name . ">\n";
return $xml_tag_string;
}
/**
* create xml-tag
*
* This function creates a xml-tag.
* The tag-name is defined by the given parameter $tag_name.
* The given parameter tag_content is put between open tag and close tag.
*
* @access public
* @param string tag name
* @param string content for xml-tag
* @param array array of tag attributes
* @return string xml tag
*/
function zensus_xmltag($tag_name, $tag_content, $tag_attributes = null)
{
if (is_array($tag_attributes)){
foreach($tag_attributes as $key => $value){
$xml_tag_string .= " $key=\"" .zensus_xmlescape($value)."\" ";
}
}
$xml_tag_string = "<" . $tag_name . $xml_tag_string . ">"
. zensus_xmlescape ( $tag_content )
. "</" . $tag_name . ">\n";
return $xml_tag_string;
}
/**
* create xml-footer
*
* This function creates the footer for xml output,
* which is a closing "studip"-tag.
*
* @access public
* @return string xml footer
*/
function zensus_xmlfooter()
{
$xml_tag_string = "</studip>";
return $xml_tag_string;
}
/**
* escapes special characters for xml use
* optinally encodes to utf8
*
* @param string $string the string to escape
* @param bool $utf8encode encode the string as utf-8
* @return string
*/
function zensus_xmlescape($string, $utf8encode = true)
{
$string = preg_replace('/[\x00-\x08\x0b\x0c\x0e-\x1f]/', '', $string);
if ($utf8encode) {
return htmlspecialchars($string, ENT_QUOTES, 'UTF-8');
} else {
return htmlspecialchars(html_entity_decode($string, ENT_QUOTES, 'UTF-8'), ENT_QUOTES, 'UTF-8', false);
}
}
/**
* Writes the xml-stream into a file or to the screen.
*
* This function writes the xml-stream $object_data into a file or to the screen,
* depending on the content of $output_mode.
*
* @access public
* @param string $object_data xml-stream
* @param string $output_mode switch for output target
*/
function zensus_output_data($object_data, $output_mode = "direct", $flush = false)
{
global $xml_file;
static $fp;
if (is_null($fp)) {
$fp = fopen('php://temp', 'r+');
}
fwrite($fp, $object_data);
if($flush && is_resource($fp)) {
rewind($fp);
if (in_array($output_mode, words('file processor passthrough choose')) ) {
stream_copy_to_stream($fp, $xml_file);
} elseif ($output_mode == "direct") {
$out = fopen('php://output', 'w');
stream_copy_to_stream($fp, $out);
fclose($out);
}
fclose($fp);
}
}
/**
* Exports data of the given range.
*
* This function calls the functions that export the data sepcified by the given $export_range.
* It calls the function output_data afterwards.
*
* @access public
* @param string $range_id Stud.IP-range_id for export
*/
function zensus_export_range($range_id, $ex_sem, $o_mode = 'direct', $auth_uid = null)
{
global $persons;
$db=new DB_Seminar;
zensus_output_data ( zensus_xmlheader(), $o_mode);
if ($auth_uid) {
$z_institutes = array();
if ($GLOBALS['perm']->get_perm($auth_uid) != 'root') {
$z_role = current(array_filter(RolePersistence::getAssignedRoles($auth_uid), function ($r) {
return $r->rolename == 'ZensusAdmin';
}));
$z_institutes = array_filter(RolePersistence::getAssignedRoleInstitutes($auth_uid, $z_role->roleid));
}
if (count($z_institutes)) {
$z_institutes = array_unique(array_merge($z_institutes, Institute::findAndMapBySQL(function ($i) {
return $i->id;
}, "fakultaets_id IN (?)", array($z_institutes))));
if ($range_id == 'root') {
$db->query("SELECT Institut_id, fakultaets_id FROM Institute WHERE Institut_id IN ('" . join("','", $z_institutes) . "') ORDER BY Institut_id=fakultaets_id");
$faks = array();
$insts = array();
while ($db->next_record()) {
if ($db->f('fakultaets_id') == $db->f('Institut_id')) $faks[] = $db->f('Institut_id');
else if (!in_array($db->f('Institut_id'), $faks)) $insts[] = $db->f('Institut_id');
}
foreach ($faks as $f) {
$db->query("SELECT * FROM Institute WHERE Institut_id = '" . $f . "'");
if (($db->next_record()) And ($db->f("Name") != "")) {
zensus_export_inst($f, 'all', $o_mode);
}
$db->query("SELECT * FROM Institute WHERE fakultaets_id = '" . $f . "' ");
while ($db->next_record()) {
if (($db->f("Name") != "") And ($db->f("Institut_id") != $f)) {
zensus_export_inst($db->f("Institut_id"), 'all', $o_mode);
}
}
}
foreach ($insts as $i) {
zensus_export_inst($i, 'all', $o_mode);
}
} else {
if (get_object_type($range_id) == 'inst' && in_array($range_id, $z_institutes)) {
zensus_export_inst($range_id, 'all', $o_mode);
}
if (get_object_type($range_id) == 'fak' && in_array($range_id, $z_institutes)) {
$db->query("SELECT Institut_id FROM Institute WHERE fakultaets_id = '" . $range_id . "' ORDER BY Institut_id=fakultaets_id");
while ($db->next_record()) {
zensus_export_inst($db->f("Institut_id"), 'all', $o_mode);
}
}
if (get_object_type($range_id) == 'sem') {
$db->query("SELECT * FROM seminare WHERE Seminar_id = '" . $range_id . "'");
if (($db->next_record()) And ($db->f("Name") != "") && in_array($db->f("Institut_id"), $z_institutes)) {
zensus_export_inst($db->f("Institut_id"), $db->f("Seminar_id"), $o_mode);
}
}
}
} else {
// Ist die Range-ID eine Einrichtungs-ID?
$db->query("SELECT * FROM Institute WHERE Institut_id = '" . $range_id . "'");
if (($db->next_record()) And ($db->f("Name") != "")) {
zensus_export_inst($range_id, 'all', $o_mode);
}
// Ist die Range-ID eine Fakultaets-ID? Dann auch untergeordnete Institute exportieren!
$db->query("SELECT * FROM Institute WHERE fakultaets_id = '" . $range_id . "' ");
while ($db->next_record())
if (($db->f("Name") != "") And ($db->f("Institut_id") != $range_id)) {
zensus_export_inst($db->f("Institut_id"), 'all', $o_mode);
}
// Ist die Range-ID eine Seminar-ID?
$db->query("SELECT * FROM seminare WHERE Seminar_id = '" . $range_id . "'");
if (($db->next_record()) And ($db->f("Name") != "")) {
zensus_export_inst($db->f("Institut_id"), $db->f("Seminar_id"), $o_mode);
}
// Ist die Range-ID eine VeranstaltungsNummer?
$number_query = "SELECT * FROM seminare WHERE VeranstaltungsNummer = :value";
if (isset($ex_sem) && $semester = Semester::find($ex_sem)){
$number_query .= " AND start_time <= :semester AND (:semester <= (start_time + duration_time) OR duration_time = -1)";
}
$courses = DBManager::get()->fetchAll($number_query, array('value' => $range_id, 'semester' => $semester->beginn));
foreach ($courses as $c) {
if ($c["Name"] != "") {
zensus_export_inst( $c["Institut_id"], $c["Seminar_id"] , $o_mode);
}
}
// Ist die Range-ID ein Range-Tree-Item?
if ($range_id != 'root') {
$tree_object = new RangeTreeObject($range_id);
$range_name = $tree_object->item_data["name"];
// Tree-Item ist ein Institut:
if ($tree_object->item_data['studip_object'] == 'inst') {
zensus_export_inst($tree_object->item_data['studip_object_id'], 'all', $o_mode);
}
// Tree-Item hat Institute als Kinder:
$inst_array = $tree_object->GetInstKids();
if (sizeof($inst_array) > 0) {
while (list($key, $inst_ids) = each($inst_array)) {
zensus_export_inst($inst_ids, 'all', $o_mode);
}
}
}
$db->query("SELECT sem_tree_id FROM sem_tree WHERE sem_tree_id = '$range_id' ");
if ($db->next_record() || $range_id == 'root') {
if (isset($ex_sem) && $semester = Semester::find($ex_sem)) {
$args = array('sem_number' => array(SemesterData::GetSemesterIndexById($ex_sem)));
} else {
$args = array();
}
if ($range_id != 'root') {
$the_tree = TreeAbstract::GetInstance('StudipSemTree', $args);
$sem_ids = array_unique($the_tree->getSemIds($range_id, true));
}
if (is_array($sem_ids) || $range_id == 'root') {
if (is_array($sem_ids)) {
$to_export = DbManager::get()
->query("SELECT DISTINCT Institut_id FROM seminare
WHERE Seminar_id IN('" . join("','", $sem_ids) . "')")
->fetchAll(PDO::FETCH_COLUMN);
} else {
$sem_ids = 'root';
$to_export = DbManager::get()
->query("SELECT DISTINCT Institut_id FROM seminare INNER JOIN seminar_sem_tree USING(seminar_id)
" . ($semester ?
"WHERE seminare.start_time <=" . $semester->beginn . " AND (" . $semester->beginn . " <= (seminare.start_time + seminare.duration_time) OR seminare.duration_time = -1)"
: ""))->fetchAll(PDO::FETCH_COLUMN);
}
foreach ($to_export as $inst) zensus_export_inst($inst, $sem_ids, $o_mode);
}
}
}
}
if (is_array($persons)){
zensus_export_persons(array_keys($persons), $o_mode);
}
zensus_output_data ( zensus_xmlfooter(), $o_mode, $flush = true);
}
/**
* Exports a Stud.IP-institute.
*
* This function gets the data of an institute and writes it into $data_object.
* It calls one of the functions export_sem, export_pers or export_teilis and then output_data.
*
* @access public
* @param string $inst_id Stud.IP-inst_id for export
* @param string $ex_sem_id allows to choose if only a specific lecture is to be exported
*/
function zensus_export_inst($inst_id, $ex_sem_id = "all", $o_mode = 'direct')
{
global $xml_file, $xml_names_inst, $xml_groupnames_inst, $INST_TYPE;
$db=new DB_Seminar;
$db->query("SELECT * FROM Institute WHERE Institut_id = '" . $inst_id . "'");
$db->next_record();
$data_object .= zensus_xmlopen_tag($xml_groupnames_inst["object"], $db->f("Institut_id"));
while ( list($key, $val) = each($xml_names_inst))
{
if ($val == "") $val = $key;
if (($key == "type") AND ($INST_TYPE[$db->f($key)]["name"] != ""))
$data_object .= zensus_xmltag($val, $INST_TYPE[$db->f($key)]["name"]);
elseif ($db->f($key) != "")
$data_object .= zensus_xmltag($val, $db->f($key));
}
reset($xml_names_inst);
$db->query("SELECT Name, Institut_id FROM Institute WHERE Institut_id = '" . $db->f('fakultaets_id') . "' AND fakultaets_id = '" . $db->f('fakultaets_id') . "'");
$db->next_record();
{
if ($db->f("Name") != "")
$data_object .= zensus_xmltag($xml_groupnames_inst["childobject"], $db->f("Name"), array('key' => $db->f('Institut_id')));
}
// freie Datenfelder ausgeben
$data_object .= zensus_export_datafields($inst_id, $xml_groupnames_inst["childgroup2"], $xml_groupnames_inst["childobject2"], 'inst');
zensus_output_data( $data_object, $o_mode );
$data_object = "";
zensus_export_sem($inst_id, $ex_sem_id, $o_mode);
$data_object .= zensus_xmlclose_tag($xml_groupnames_inst["object"]);
zensus_output_data($data_object, $o_mode);
}
/**
* Exports lecture-data.
*
* This function gets the data of the lectures at an institute and writes it into $data_object.
* It calls output_data afterwards.
*
* @access public
* @param string $inst_id Stud.IP-inst_id for export
* @param string $ex_sem_id allows to choose if only a specific lecture is to be exported
*/
function zensus_export_sem($inst_id, $ex_sem_id = "all", $o_mode = 'direct')
{
global $xml_file, $xml_names_lecture, $xml_groupnames_lecture, $SEM_TYPE, $SEM_CLASS, $persons;
global $ex_sem, $ex_only_homeinst,$ex_sem_class, $ex_only_visible;
$db=new DB_Seminar;
$db2=new DB_Seminar;
$db3=new DB_Seminar;
$order = "seminare.status, seminare.Name";
$group = "FIRSTGROUP";
$group_tab_zelle = "status";
$do_group = true;
if (isset($ex_sem) && $semester = Semester::find($ex_sem)){
$addquery = " AND seminare.start_time <=".$semester->beginn." AND (".$semester->beginn." <= (seminare.start_time + seminare.duration_time) OR seminare.duration_time = -1) ";
}
if ($ex_sem_id != "all"){
if ($ex_sem_id == 'root') {
$addquery .= " AND EXISTS(SELECT * FROM seminar_sem_tree WHERE seminar_sem_tree.seminar_id=seminare.Seminar_id) ";
} else {
if (!is_array($ex_sem_id)) $ex_sem_id = array($ex_sem_id);
$ex_sem_id = array_flip($ex_sem_id);
}
}
if ($ex_only_visible) $addquery .= " AND visible=1 ";
if(count($ex_sem_class)) {
$allowed_sem_types = array();
foreach($ex_sem_class as $semclassid){
$allowed_sem_types += array_keys(SeminarCategories::get($semclassid)->getTypes());
}
$addquery .= sprintf(" AND seminare.status IN(%s) ", join(",", $allowed_sem_types));
}
if($ex_only_homeinst){
$db->query("SELECT seminare.*,Seminar_id as seminar_id, Institute.Name as heimateinrichtung FROM seminare
LEFT JOIN Institute ON seminare.Institut_id=Institute.Institut_id
WHERE seminare.Institut_id = '" . $inst_id . "' " . $addquery . "
ORDER BY " . $order);
} else {
$db->query("SELECT seminare.*,seminar_inst.seminar_id, Institute.Name as heimateinrichtung FROM seminar_inst
LEFT JOIN seminare USING (Seminar_id)
LEFT JOIN Institute ON seminare.Institut_id=Institute.Institut_id
WHERE seminar_inst.Institut_id = '" . $inst_id . "' " . $addquery . "
ORDER BY " . $order);
}
$data_object .= zensus_xmlopen_tag( $xml_groupnames_lecture["group"] );
while ($db->next_record())
{
if (is_array($ex_sem_id) && !isset($ex_sem_id[$db->f("seminar_id")])) continue;
$group_string = "";
if (($do_group) AND ($group != $db->f($group_tab_zelle)))
{
if ($group != "FIRSTGROUP")
$group_string .= zensus_xmlclose_tag($xml_groupnames_lecture["subgroup1"]);
if ($group_tab_zelle == "status")
$group_string .= zensus_xmlopen_tag($xml_groupnames_lecture["subgroup1"], $SEM_TYPE[$db->f($group_tab_zelle)]["name"]);
else
$group_string .= zensus_xmlopen_tag($xml_groupnames_lecture["subgroup1"], $db->f($group_tab_zelle));
$group = $db->f($group_tab_zelle);
if (($do_subgroup) AND ($subgroup == $db->f($subgroup_tab_zelle)))
$subgroup = "NEXTGROUP";
}
if (($do_subgroup) AND ($subgroup != $db->f($subgroup_tab_zelle)))
{
if ($subgroup != "FIRSTGROUP")
$group_string = zensus_xmlclose_tag($xml_groupnames_lecture["subgroup2"]) . $group_string;
$group_string .= zensus_xmlopen_tag($xml_groupnames_lecture["subgroup2"], $db->f($subgroup_tab_zelle));
$subgroup = $db->f($subgroup_tab_zelle);
}
$data_object .= $group_string;
$data_object .= zensus_xmlopen_tag($xml_groupnames_lecture["object"], $db->f("seminar_id"));
while ( list($key, $val) = each($xml_names_lecture))
{
if (is_callable($val)) {
$data_object .= call_user_func($val, $key, $db->f("seminar_id"));
continue;
}
if ($val == "") $val = $key;
if ($key == "status") {
$data_object .= zensus_xmltag($val, $SEM_TYPE[$db->f($key)]["name"]);
}
elseif (($key == "bereich") AND (($SEM_CLASS[$SEM_TYPE[$db->f("status")]["class"]]["bereiche"]))) {
$data_object .= zensus_xmlopen_tag($xml_groupnames_lecture["childgroup3"]);
$pathes = get_sem_tree_path($db->f("seminar_id"));
if (is_array($pathes)){
foreach ($pathes as $sem_tree_id => $path_name)
$data_object .= zensus_xmltag($val, $path_name);
} else {
$data_object .= zensus_xmltag($val, "n.a.");
}
$data_object .= zensus_xmlclose_tag($xml_groupnames_lecture["childgroup3"]);
}
elseif ($key == "admission_turnout")
{
$data_object .= zensus_xmlopen_tag($val, sprintf ("%s", $db->f("admission_type")) ? _("max.") : _("erw.")) . $db->f($key) . zensus_xmlclose_tag($val);
}
elseif ($key == "teilnehmer_anzahl_aktuell")
{
$db3->query("SELECT COUNT(user_id) FROM seminar_user WHERE seminar_id='".$db->f('seminar_id')."' AND status='autor'");
$db3->next_record();
$data_object .= zensus_xmltag($val, $db3->f(0));
}
elseif ($key == "Institut_id")
{
$data_object .= zensus_xmltag($val, $db->f('heimateinrichtung') , array('key' => $db->f($key)));
}
elseif ($db->f($key) != "")
$data_object .= zensus_xmltag($val, $db->f($key));
}
$db2->query("SELECT seminar_user.position, auth_user_md5.user_id,auth_user_md5.username, auth_user_md5.Vorname, auth_user_md5.Nachname, user_info.title_front, user_info.title_rear FROM seminar_user
LEFT JOIN user_info USING(user_id)
LEFT JOIN auth_user_md5 USING(user_id)
WHERE (seminar_user.status = 'dozent') AND (seminar_user.Seminar_id = '" . $db->f('seminar_id') . "') ORDER BY seminar_user.position ");
$data_object .= "<" . $xml_groupnames_lecture["childgroup2"] . ">\n";
while ($db2->next_record())
{
$persons[$db2->f('user_id')] = true;
$content_string = $db2->f("Vorname") . " " . $db2->f("Nachname");
if ($db2->f("title_front") != "")
$content_string = $db2->f("title_front") . " " . $content_string;
if ($db2->f("title_rear") != "")
$content_string = $content_string . ", " . $db2->f("title_rear");
$data_object .= zensus_xmltag($xml_groupnames_lecture["childobject2"], $content_string, array('key' => $db2->f('username')));
}
$data_object .= zensus_xmlclose_tag( $xml_groupnames_lecture["childgroup2"] );
// freie Datenfelder ausgeben
$data_object .= zensus_export_datafields($db->f("seminar_id"), $xml_groupnames_lecture["childgroup4"], $xml_groupnames_lecture["childobject4"],'sem',$db->f("status"));
$data_object .= zensus_xmlclose_tag( $xml_groupnames_lecture["object"] );
reset($xml_names_lecture);
zensus_output_data($data_object, $o_mode);
$data_object = "";
}
if (($do_subgroup) AND ($subgroup != "FIRSTGROUP"))
$data_object .= zensus_xmlclose_tag($xml_groupnames_lecture["subgroup2"]);
if (($do_group) AND ($group != "FIRSTGROUP"))
$data_object .= zensus_xmlclose_tag($xml_groupnames_lecture["subgroup1"]);
$data_object .= zensus_xmlclose_tag($xml_groupnames_lecture["group"]);
zensus_output_data($data_object, $o_mode);
}
/**
* Exports list of persons.
*
*
* @access public
* @param array $persons Stud.IP-user_ids for export
*/
function zensus_export_persons($persons, $o_mode = 'direct')
{
global $xml_names_person, $xml_groupnames_person;
$db = new DB_Seminar;
if (is_array($persons)){
$db->query("SELECT * FROM auth_user_md5
LEFT JOIN user_info info USING(user_id)
WHERE auth_user_md5.user_id IN('".join("','", $persons)."')");
while ($db->next_record()) {
$data_object = zensus_xmlopen_tag($xml_groupnames_person["object"], $db->f("username"));
$data_object .= zensus_xmltag('id', $db->f('user_id'));
while ( list($key, $val) = each($xml_names_person)){
if ($val == "") $val = $key;
if ($db->f($key) != "") $data_object .= zensus_xmltag($val, $db->f($key));
}
// freie Datenfelder ausgeben
$data_object .= zensus_export_datafields($db->f("user_id"), $xml_groupnames_person["childgroup1"], $xml_groupnames_person["childobject1"],'user');
$data_object .= zensus_xmlclose_tag( $xml_groupnames_person["object"] );
reset($xml_names_person);
zensus_output_data($data_object, $o_mode);
$data_object = "";
}
}
$data_object = "";
}
/**
* helper function to export custom datafields
*
* only visible datafields are exported (depending on user perms)
* @access public
* @param string $range_id id for object to export
* @param string $childgroup_tag name of outer tag
* @param string $childobject_tag name of inner tags
*/
function zensus_export_datafields($range_id, $childgroup_tag, $childobject_tag, $object_type = null, $object_class_hint = null){
$ret = '';
$d_fields = false;
$localEntries = DataFieldEntry::getDataFieldEntries($range_id,$object_type, $object_class_hint);
if(is_array($localEntries )){
foreach ($localEntries as $entry){
if (!$d_fields) $ret .= zensus_xmlopen_tag( $childgroup_tag );
$ret .= zensus_xmltag($childobject_tag, $entry->getDisplayValue(false), array('key' => $entry->getName(), 'id' => $entry->getId()));
$d_fields = true;
}
}
if ($d_fields) $ret .= zensus_xmlclose_tag( $childgroup_tag );
return $ret;
}