* Copyright 2016 Nicolas Goaziou * * This file is part of CHD Gestion. * * CHD Gestion 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 3 of the License, or * (at your option) any later version. * * CHD Gestion 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. * * You should have received a copy of the GNU General Public License * along with CHD Gestion. If not, see . **/ include_once('inc/config.php'); $mysqli = new mysqli($db_config['host'], $db_config['username'], $db_config['password'], $db_config['database']); unset($db_config); $mysqli->query("SET NAMES 'utf8'"); $opt_show_source=array_key_exists('s', $_GET); $arg_adt=(array_key_exists('a', $_GET) && is_numeric($_GET['a']))?(0+$_GET['a']):NULL; if (!$arg_adt) { die("Wrong args"); } // Piping to Graphviz' dot command or to browser if opt_show_source is set if (!$opt_show_source) { $descriptorspec = array( 0 => array("pipe", "r"), // stdin is a pipe that the child will read from 1 => array("pipe", "w"), // stdout is a pipe that the child will write to 2 => array("pipe", "w") ); $pipes=array(); $proc = proc_open('dot -Tsvg', $descriptorspec, $pipes, '/var/www/priv/api'); if (!is_resource($proc)) die("Pb ouverture dot"); $fd=$pipes[0]; } else { header('Content-Type: text/plain'); $fd=fopen("php://output","w"); } function graph_header() { return << $adt
$adt_title >, URL="/gestion/adherents/view/$adherent_id"]; EOD; } // >]; function node_equipement($eid, $shape, $img, $label) { $label = htmlentities($label); return << $label
eid $eid >, URL="/gestion/equipements/view/$eid"]; EOD; } function edge_service($adherent_id, $routeur_eid, $service) { $service = htmlentities($service); return << "e$routeur_eid" [ label=<$service> ] EOD; } function node_relais($rid, $eid, $shape, $label) { $label = htmlentities($label); return << 
$label
rid $rid >]; "e$eid" -> "r$rid" [ dir=back, arrowtail=empty, style=dashed ]; EOD; } // >, URL="/gestion/relais/view/$rid"]; fwrite($fd, graph_header()); $res = $mysqli->query("SELECT * FROM v_relais_detail WHERE adherent_id=" . $arg_adt); $empty=true; while ( $row = $res->fetch_assoc() ) { $empty=false; if ( isset($row['adt']) && isset($row['service_id']) && isset($row['routeur_equipement_id']) ) { fwrite($fd, node_adt($row['adherent_id'], 'none', $row['adt'], $row['adt_title'])); //egg fwrite($fd, node_equipement($row['routeur_equipement_id'], 'none', 'rt.png', 'Routeur')); //rectangle fwrite($fd, edge_service($row['adherent_id'],$row['routeur_equipement_id'], $row['service'])); } if ( isset($row['antenne1_equipement_id']) ) { fwrite($fd, node_equipement($row['antenne1_equipement_id'], 'none', 'ant.png', 'Antenne1')); fwrite($fd, "\te".$row['routeur_equipement_id']." -> e".$row['antenne1_equipement_id'].";\n"); } if ( isset($row['antenne2_equipement_id']) ) { fwrite($fd, node_equipement($row['antenne2_equipement_id'], 'none', 'ant.png', 'Antenne2')); fwrite($fd, "\te".$row['antenne1_equipement_id']." -> e".$row['antenne2_equipement_id'].";\n"); } if ( isset($row['relais_id']) && isset($row['relais_degre']) ) { switch ($row['relais_degre']) { case 1: $e_node = $row['routeur_equipement_id']; break; case 2: $e_node = $row['antenne1_equipement_id']; break; case 3: $e_node = $row['antenne2_equipement_id']; break; default: continue; } fwrite($fd, node_relais($row['relais_id'], $e_node, 'none', $row['relais'])); } } if ($empty) { fwrite($fd, "\tnothing;\n"); } fwrite($fd, "}\n"); if (!$opt_show_source) { fclose($fd); $image_data = stream_get_contents($pipes[1]); fclose($pipes[1]); $err_data = stream_get_contents($pipes[2]); fclose($pipes[2]); $return_value = proc_close($proc); if ( $return_value !== 0 || strlen($err_data) !== 0 ) { header('Content-Type: text/plain'); echo $err_data; } else { header('Content-Type: image/svg+xml'); echo $image_data; } flush(); }