From a392378a04d9b92d114a0e952dd1082ac6a8e499 Mon Sep 17 00:00:00 2001 From: Ludovic Pouzenc Date: Sun, 27 Mar 2016 23:33:58 +0200 Subject: =?UTF-8?q?Synoptique=20Adh=C3=A9rent=20/=20Services=20/=20Equipem?= =?UTF-8?q?ents=20/=20Relais?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Mostly broken :) --- api/icons/adt.png | 1 + api/icons/ant.png | 1 + api/icons/rt.png | 1 + api/img_adt_svc_relais.php | 166 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 169 insertions(+) create mode 120000 api/icons/adt.png create mode 120000 api/icons/ant.png create mode 120000 api/icons/rt.png create mode 100644 api/img_adt_svc_relais.php (limited to 'api') diff --git a/api/icons/adt.png b/api/icons/adt.png new file mode 120000 index 0000000..83c9cc7 --- /dev/null +++ b/api/icons/adt.png @@ -0,0 +1 @@ +/usr/share/pixmaps/debian-logo.png \ No newline at end of file diff --git a/api/icons/ant.png b/api/icons/ant.png new file mode 120000 index 0000000..83c9cc7 --- /dev/null +++ b/api/icons/ant.png @@ -0,0 +1 @@ +/usr/share/pixmaps/debian-logo.png \ No newline at end of file diff --git a/api/icons/rt.png b/api/icons/rt.png new file mode 120000 index 0000000..83c9cc7 --- /dev/null +++ b/api/icons/rt.png @@ -0,0 +1 @@ +/usr/share/pixmaps/debian-logo.png \ No newline at end of file diff --git a/api/img_adt_svc_relais.php b/api/img_adt_svc_relais.php new file mode 100644 index 0000000..4071cfc --- /dev/null +++ b/api/img_adt_svc_relais.php @@ -0,0 +1,166 @@ + + * 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(); +} -- cgit v1.1