pandorafms/pandora_console/include/class/Map.class.php

176 lines
4.5 KiB
PHP
Raw Normal View History

<?php
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2011 Artica Soluciones Tecnologicas
// Please see http://pandorafms.org for full contribution list
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation; version 2
// This program 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.
/**
* @package Include
* @subpackage Maps
*/
2016-02-04 16:59:40 +01:00
abstract class Map {
protected $status = STATUS_OK;
protected $id = null;
2016-02-04 16:59:40 +01:00
protected $type = null;
protected $subtype = null;
protected $id_group = null;
2016-02-09 13:52:03 +01:00
protected $generation_method = null;
2016-02-17 12:25:03 +01:00
protected $width = null;
protected $height = null;
2016-02-17 12:25:03 +01:00
2016-02-22 12:05:28 +01:00
protected $nodes = array();
protected $edges = array();
2016-02-04 16:59:40 +01:00
protected $requires_js = null;
2016-02-22 13:18:54 +01:00
public static function getName($id = null) {
if (empty($id)) {
return null;
}
else {
return db_get_value('name', 'tmap', 'id', $id);
}
}
public function __construct($id) {
$this->id = $id;
2016-02-04 16:59:40 +01:00
2016-02-09 11:02:41 +01:00
$this->requires_js = array();
$this->requires_js[] = "include/javascript/d3.3.5.14.js";
$this->requires_js[] = "include/javascript/map/MapController.js";
$this->requires_js[] = "include/javascript/jquery.tooltipster.js";
$this->requires_js[] = "include/javascript/jquery.svg.js";
$this->requires_js[] = "include/javascript/jquery.svgdom.js";
2016-02-22 13:18:54 +01:00
if (!$this->loadDB()) {
$this->status = STATUS_ERROR;
}
}
protected function processDBValues($dbValues) {
$this->type = (int)$dbValues['type'];
$this->subtype = (int)$dbValues['subtype'];
2016-02-04 16:59:40 +01:00
$this->id_group = (int)$dbValues['id_group'];
2016-02-09 13:52:03 +01:00
$this->generation_method = (int)$dbValues['generation_method'];
$this->width = (int)$dbValues['width'];
$this->height = (int)$dbValues['height'];
}
2016-02-04 16:59:40 +01:00
private function loadDB() {
$row = db_get_row_filter('tmap', array('id' => $this->id));
if (empty($row))
return false;
switch (get_class($this)) {
case 'Networkmap':
Networkmap::processDBValues($row);
break;
case 'NetworkmapEnterprise':
NetworkmapEnterprise::processDBValues($row);
break;
default:
$this->processDBValues($row);
break;
}
2016-02-04 16:59:40 +01:00
}
abstract function printJSInit();
2016-02-04 16:59:40 +01:00
2016-02-17 15:36:44 +01:00
public function writeJSGraph() {
?>
<script type="text/javascript">
<?php
echo "var nodes = " . json_encode($this->nodes) . ";";
echo "var edges = " . json_encode($this->edges) . ";";
?>
2016-02-22 12:05:28 +01:00
var temp = [];
for (var i in nodes) { temp[parseInt(i)] = nodes[i];}
nodes = temp;
temp = [];
for (var i in edges) { temp[parseInt(i)] = edges[i];}
edges = temp;
2016-02-17 15:36:44 +01:00
</script>
<?php
}
public function show() {
// Tooltip css
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"include/styles/tooltipster.css\"/>" . "\n";
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"include/styles/tooltipster-punk.css\"/>" . "\n";
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"include/styles/tooltipster-shadow.css\"/>" . "\n";
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"include/styles/tooltipster-noir.css\"/>" . "\n";
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"include/styles/tooltipster-light.css\"/>" . "\n";
2016-02-04 16:59:40 +01:00
foreach ($this->requires_js as $js) {
echo "<script type='text/javascript' src='$js'></script>" . "\n";
}
2016-02-17 15:36:44 +01:00
$this->writeJSContants();
$this->writeJSGraph();
?>
2016-02-04 16:59:40 +01:00
<div id="map" data-id="<?php echo $this->id;?>" style="border: 1px red solid;">
2016-02-17 15:36:44 +01:00
<?php
if ($this->width == 0) {
$width = "100%";
}
else {
$width = $this->width . "px";
}
if ($this->height == 0) {
$height = "500px";
}
else {
$height = $this->height . "px";
}
?>
<svg xmlns="http://www.w3.org/2000/svg" pointer-events="all" width="<?php echo $width;?>" height="<?php echo $height;?>">
</svg>
</div>
2016-02-04 16:59:40 +01:00
<?php
$this->printJSInit();
}
2016-02-17 15:36:44 +01:00
public function writeJSContants() {
2016-02-17 18:31:46 +01:00
$contants = array();
$contants["ITEM_TYPE_AGENT_NETWORKMAP"] = ITEM_TYPE_AGENT_NETWORKMAP;
$contants["ITEM_TYPE_MODULE_NETWORKMAP"] = ITEM_TYPE_MODULE_NETWORKMAP;
$contants["ITEM_TYPE_EDGE_NETWORKMAP"] = ITEM_TYPE_EDGE_NETWORKMAP;
2016-02-17 15:36:44 +01:00
?>
<script type="text/javascript">
<?php
2016-02-17 18:31:46 +01:00
foreach ($contants as $name => $value) {
echo "var $name = $value \n";
}
2016-02-17 15:36:44 +01:00
?>
</script>
<?php
}
public function getType() {
return $this->type;
}
}
?>