diff options
author | Ludovic Pouzenc <ludovic@pouzenc.fr> | 2016-03-27 23:33:58 +0200 |
---|---|---|
committer | Ludovic Pouzenc <ludovic@pouzenc.fr> | 2016-03-27 23:33:58 +0200 |
commit | a392378a04d9b92d114a0e952dd1082ac6a8e499 (patch) | |
tree | d014f0cfef47d0854764aeda20e24bbdc0451ecd /api | |
parent | 509b591aa18d6e67acb6df4270985ddfbb17b09a (diff) | |
download | chd_gestion-a392378a04d9b92d114a0e952dd1082ac6a8e499.zip chd_gestion-a392378a04d9b92d114a0e952dd1082ac6a8e499.tar.gz chd_gestion-a392378a04d9b92d114a0e952dd1082ac6a8e499.tar.bz2 |
Synoptique Adhérent / Services / Equipements / Relais
Mostly broken :)
Diffstat (limited to 'api')
l--------- | api/icons/adt.png | 1 | ||||
l--------- | api/icons/ant.png | 1 | ||||
l--------- | api/icons/rt.png | 1 | ||||
-rw-r--r-- | api/img_adt_svc_relais.php | 166 |
4 files changed, 169 insertions, 0 deletions
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 @@ +<?php +/** + * Copyright 2016 Ludovic Pouzenc <ludovic@pouzenc.fr> + * Copyright 2016 Nicolas Goaziou <mail@nicolasgoaziou.fr> + * + * 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 <http://www.gnu.org/licenses/>. +**/ + +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 <<<EOD +digraph { + rankdir=LR; + concentrate=true; + +EOD; +} + +function node_adt($adherent_id, $shape, $adt, $adt_title) { + $adt_title = htmlentities($adt_title); + return <<<EOD + "a$adherent_id" [ margin=0, shape=$shape, label=< + <TABLE border="0" cellborder="0"> + <TR><TD><IMG SRC="icons/adt.png"/></TD></TR> + <TR><TD>$adt<br/><font point-size="8">$adt_title</font></TD></TR> + </TABLE> + >, URL="/gestion/adherents/view/$adherent_id"]; + +EOD; +} +// >]; + +function node_equipement($eid, $shape, $img, $label) { + $label = htmlentities($label); + return <<<EOD + "e$eid" [ margin=0, shape=$shape, label=< + <TABLE border="0" cellborder="0"> + <TR><TD><IMG SRC="icons/$img"/></TD></TR> + <TR><TD>$label<br/><font point-size="8">eid $eid</font></TD></TR> + </TABLE> + >, URL="/gestion/equipements/view/$eid"]; + +EOD; +} + +function edge_service($adherent_id, $routeur_eid, $service) { + $service = htmlentities($service); + return <<<EOD + "a$adherent_id" -> "e$routeur_eid" [ label=<<font point-size="8">$service</font>> ] + +EOD; +} + +function node_relais($rid, $eid, $shape, $label) { + $label = htmlentities($label); + return <<<EOD + "r$rid" [ margin=0, shape=$shape, label=< + <font point-size="8"> </font><br/> + $label<br/> + <font point-size="8">rid $rid</font> + >]; + "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(); +} |