fix charts
[disclosr.git] / admin / directory.gexf.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
<?php
 
$nodes = Array(Array("id" => "gov", "label" => "Federal Government"));
$edges = Array();
 
function addEdge($source, $target) {
    global $edges;
    $edges[] = Array("id" => md5($source . $target), "source" => $source, "target" => $target);
}
 
function addNode($id, $label, $pid) {
    global $nodes;
    $nodes[] = Array("id" => $id, "label" => $label , "pid" => $pid);
}
 
function addChildren($parentID, $parentXML) {
    foreach ($parentXML as $childXML) {
 
        if ($childXML->getName() == "organization" || $childXML->getName() == "organizationalUnit" || $childXML->getName() == "person") {
            $attr = $childXML->attributes();
            $id = $attr['UUID'];
            if ($childXML->getName() == "organization" || $childXML->getName() == "organizationalUnit") {
 
                $label = $childXML->name;
            } else if ($childXML->getName() == "person") {
                  $label = $childXML->fullName;
            }
            addNode($id, $label, $parentID);
            addEdge($id, $parentID);
            addChildren($id, $childXML);
        }
    }
}
 
if (file_exists('directoryexport.xml')) {
    $xml = simplexml_load_file('directoryexport.xml');
 
    addChildren("gov", $xml);
} else {
    exit('Failed to open directoryexport.xml');
}
  header('Content-Type: application/gexf+xml');
echo '<?xml version="1.0" encoding="UTF-8"?>
<gexf xmlns="http://www.gexf.net/1.2draft" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.gexf.net/1.2draft http://www.gexf.net/1.2draft/gexf.xsd" version="1.2">
    <graph mode="static" defaultedgetype="directed">
        <nodes>';
foreach ($nodes as $node) {
    echo '          <node id="' . $node['id'] . '" label="' . htmlentities($node['label'],ENT_XML1) . '" ' . (isset($node['pid']) ? 'pid="' . $node['pid'] . '"' : "") . ' />';
}
echo '</nodes>
        <edges>';
foreach ($edges as $edge) {
    echo '            <edge id="' . $edge['id'] . '" source="' . $edge['source'] . '" target="' . $edge['target'] . '" />';
}
echo '</edges>
    </graph>
</gexf>';
?>