/adei/trunk

To get this branch, use:
bzr branch http://darksoft.org/webbzr/adei/trunk
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
<?php
global $ADEI_ID_DELIMITER;
global $ADEI_SRCTREE_EXTRA;

header("Content-type: text/xml");
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");


$id = $_GET['id'];
$child = 1;
if (isset($id)) {
    $tmp = explode($ADEI_ID_DELIMITER, $id, 3);
    $prefix = $id . $ADEI_ID_DELIMITER;
    $parent = $id;

    if ($tmp[0] == "virtual") {
        $props = array();
        $extra_mod = $tmp[1];
        $prefix = $tmp[2];
        $type = 4;
    } else {
        $props = array(
	    "db_server" => $tmp[0]
        );
    
        if (isset($tmp[1])) {
	    $props["db_name"] = $tmp[1];
	    if (isset($tmp[2])) {
	        $props["db_group"] = $tmp[2];
	        $type = 3;
	        $child = 0;
	    } else {
	        $type = 2;
	    }
        } else {
	    $type = 1;
        }
    }
} else {
    $prefix = "";
    $props = array();
    $type = 0;
    $parent = "0";
    unset($extra_mod);
}


$tree = "";
try {
    switch ($type) {
     case 0:
	$req = new REQUEST($props);
	$list = $req->GetServerList();
	break;
     case 1:
	$req = new SERVERRequest($props);
	$list = $req->GetDatabaseList(REQUEST::LIST_WILDCARDED);
	break;
     case 2:
	$req = new SOURCERequest($props);
	$list = $req->GetGroupList();
	break;
     case 3:
	$req = new GROUPRequest($props);
	$list = $req->GetItemList();
	break;
     default:
	$req = new REQUEST($props);
    }

    $branches = array();
    
    if (($type == 0)||($type == 4)) {
        if ($ADEI_SRCTREE_EXTRA) {
	    foreach ($ADEI_SRCTREE_EXTRA as $extra => $cfg) {
	        if (isset($extra_mode)&&($extra != $extra_mod)) continue;
	        
	        ADEI::RequireClass("srctree/{$cfg['class']}");
	        $cl = new $extra($req, $cfg['options']);
	        $res = $cl->GetBranches($prefix);
	        $extra_prefix = "virtual__" . strtolower($extra) . "__";
	        foreach ($res as $id => $info) {
	            $branches[$extra_prefix . $id ] = $info;
	        }
    	    }
        }
    }

    if ($list) {
        foreach ($list as $id => $info) {
            $branches["{$prefix}{$id}"] = array_merge($info, array("child" => $child));
        }
    }
} catch (ADEIException $ex) {
    $ex->logInfo(NULL, $req);
    $err = xml_escape($ex->getInfo());
}


if ($err) {
    echo "<?xml version='1.0' encoding='UTF-8'?>
<tree id=\"$parent\">
  <item id=\"{$prefix}___error\" text=\"" . translate("Source tree generation is failed, error: %s", $err) . "\"/>
</tree>";
    exit(0);

}

/*
foreach ($list as $id => $info) {
    $tree.="<item id=\"{$prefix}{$id}\" text=\"" . xml_escape($info['name']) . "\" child=\"$child\" select=\"yes\"/>";
}
*/

foreach ($branches as $id => $info) {
    $tree.="<item id=\"{$id}\" text=\"" . xml_escape($info['name']) . "\" child=\"" . ($info['child']?1:0) . "\" select=\"yes\"/>";
}


echo "<?xml version='1.0' encoding='UTF-8'?>
<tree id=\"$parent\">
 $tree
</tree>";

?>