if ($_POST['x'] == '') {
        Html::back();
        exit;
    }
    $pmWeathermapnode->add($_POST);
    Html::back();
} else {
    if (isset($_POST["update"])) {
        if ($_POST['x'] == '') {
            Html::back();
            exit;
        }
        unset($_POST['name']);
        $_POST['name'] = $_POST['nameupdate'];
        unset($_POST['itemtype']);
        $_POST['id'] = $_POST['id_update'];
        $pmWeathermapnode->update($_POST);
        Html::back();
    } else {
        if (isset($_POST["purge"])) {
            $pmWeathermaplink = new PluginMonitoringWeathermaplink();
            $a_links = $pmWeathermaplink->find("`plugin_monitoring_weathermapnodes_id_1`='" . $_POST['id'] . "'\n      OR `plugin_monitoring_weathermapnodes_id_2`='" . $_POST['id'] . "'");
            foreach ($a_links as $data) {
                $pmWeathermaplink->delete($data);
            }
            $pmWeathermapnode->delete($_POST);
            Html::back();
        }
    }
}
Html::footer();
Example #2
0
    function configureNodesLinks($weathermaps_id)
    {
        global $DB, $CFG_GLPI;
        $networkPort = new NetworkPort();
        $pmWeathermapnode = new PluginMonitoringWeathermapnode();
        $this->getFromDB($weathermaps_id);
        echo "<table class='tab_cadre_fixe'>";
        echo "<tr class='tab_bg_1'>";
        echo "<th colspan='2'>";
        echo __('Nodes and links', 'monitoring');
        echo "</th>";
        echo "</tr>";
        $this->generateWeathermap($weathermaps_id, 1, 1);
        $map = "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/send.php?file=weathermap-" . $weathermaps_id . ".png'/>";
        echo "<tr class='tab_bg_1'>";
        echo "<td valign='top' width='10'>";
        if ($this->fields['background'] == '') {
            echo '<script language="JavaScript" type="text/JavaScript">

         function FindPosition(oElement) {
            if(typeof( oElement.offsetParent ) != "undefined") {
               for(var posX = 0, posY = 0; oElement; oElement = oElement.offsetParent) {
                  posX += oElement.offsetLeft;
                  posY += oElement.offsetTop;
               }
               return [ posX, posY ];
            } else {
               return [ oElement.x, oElement.y ];
            }
         }

         function GetCoordinates(e) {
            var PosX = 0;
            var PosY = 0;
            var ImgPos;
            ImgPos = FindPosition(myImg);
            if (!e) var e = window.event;
            if (e.pageX || e.pageY) {
               PosX = e.pageX;
               PosY = e.pageY;
            } else if (e.clientX || e.clientY) {
               PosX = e.clientX + document.body.scrollLeft
                 + document.documentElement.scrollLeft;
               PosY = e.clientY + document.body.scrollTop
                 + document.documentElement.scrollTop;
            }
            PosX = PosX - ImgPos[0];
            PosY = PosY - ImgPos[1];

            document.pointform.x.value = PosX;
            document.pointform.y.value = PosY;
         }

         var myImg = document.getElementById("myImgId");
         myImg.onmousedown = GetCoordinates;

         </script>';
            echo "<div><img src='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/send.php?file=weathermap-" . $weathermaps_id . ".png'/>";
            echo "<div style='position: absolute; top:40px;' id='myImgId' >\n            <table class='gridweathermap' width='" . $this->fields['width'] . "' \n               height='" . $this->fields['height'] . "'>";
            $line = '';
            $nbcol = ceil($this->fields['width'] / 15);
            for ($num = 0; $num < $nbcol; $num++) {
                $line .= "<td></td>";
            }
            $line = '<tr>' . $line . '</tr>';
            $nbline = ceil($this->fields['height'] / 15);
            for ($num = 0; $num < $nbline; $num++) {
                echo $line;
            }
            echo "</table></div></div>";
        } else {
            echo '<div id="pointer_div" onclick="point_it(event)" style = "background-image:url(\'' . $this->fields['background'] . '\');">
            <img id="cross" style="position:relative;visibility:hidden;z-index:2;">
            ' . $map . '</div>';
            echo '<script language="JavaScript">
         function point_it(event){
            pos_x = event.offsetX?(event.offsetX):event.pageX;
            pos_y = event.offsetY?(event.offsetY):event.pageY;
            document.getElementById("cross").style.left = (pos_x-1) ;
            document.getElementById("cross").style.top = (pos_y-15) ;

            var topValue= 0;
            var leftValue= 0;
            var obj = document.getElementById("pointer_div");
            while(obj){
               leftValue+= obj.offsetLeft;
               topValue+= obj.offsetTop;
               obj= obj.offsetParent;
            }


            document.pointform.x.value = pos_x-leftValue;
            document.pointform.y.value = pos_y-topValue;

         }
         </script>';
        }
        echo "</td>";
        echo "<td valign='top'>";
        echo "<div style='position: fixed;top: 30px;right: 0;z-index:999;' >";
        echo "<table class='tab_cadre' width='100%'>";
        echo "<tr>";
        echo "<td>";
        echo "<a onClick='Ext.get(\"weathermapform\").toggle();'>\n      <img src='" . $CFG_GLPI["root_doc"] . "/pics/deplier_down.png' />&nbsp;\n         " . __('Display weathermap form', 'monitoring') . "\n      &nbsp;<img src='" . $CFG_GLPI["root_doc"] . "/pics/deplier_down.png' /></a>";
        echo "</td>";
        echo "</tr>";
        echo "</table>";
        echo "</div>";
        echo "<div style='position: fixed;top: 50px;right: 0;z-index:1000;' id='weathermapform' >";
        echo '<form name="pointform" method="post" action="' . $CFG_GLPI['root_doc'] . '/plugins/monitoring/front/weathermapnode.form.php">';
        echo "<table>";
        echo "<tr>";
        echo "<td>";
        echo "<table class='tab_cadre' width='100%'>";
        echo "<tr>";
        echo "<th colspan='2'>";
        echo "x : ";
        echo '<input type="text" name="x" size="4" />';
        echo " ";
        echo "y : ";
        echo '<input type="text" name="y" size="4" />';
        echo "</th>";
        echo "</tr>";
        // * Add node
        echo "<tr>";
        echo "<th colspan='2'>";
        echo "<input type='hidden' name='plugin_monitoring_weathermaps_id' value='" . $weathermaps_id . "' />";
        echo __('Add a node', 'monitoring');
        echo "</th>";
        echo "</tr>";
        echo "<tr>";
        echo "<td>";
        echo __('Node', 'monitoring') . "&nbsp;:";
        echo "</td>";
        echo "<td>";
        Dropdown::showAllItems("items_id");
        echo "</td>";
        echo "</tr>";
        echo "<tr>";
        echo "<td>";
        echo __('Name') . "&nbsp;:";
        echo "</td>";
        echo "<td>";
        echo "<input type='text' name='name' value='' />";
        echo "</td>";
        echo "</tr>";
        echo "<tr>";
        echo "<td align='center' colspan='2'>";
        echo "<input type='submit' name='add' value=\"" . __('Add') . "\" class='submit'>";
        echo "</td>";
        echo "</tr>";
        // * Change node position
        echo "<tr>";
        echo "<th colspan='2'>";
        echo __('Edit a node', 'monitoring');
        echo "</th>";
        echo "</tr>";
        echo "<tr>";
        echo "<td colspan='2' align='center'>";
        $query = "SELECT * FROM `" . getTableForItemType("PluginMonitoringWeathermapnode") . "`\n            WHERE `plugin_monitoring_weathermaps_id`='" . $weathermaps_id . "'\n            ORDER BY `name`";
        $result = $DB->query($query);
        $elements = array();
        $elements[0] = Dropdown::EMPTY_VALUE;
        $result = $DB->query($query);
        while ($data = $DB->fetch_array($result)) {
            $itemtype = $data['itemtype'];
            if ($itemtype == '0') {
                $pmWeathermapnode->delete($data);
            } else {
                $item = new $itemtype();
                $item->getFromDB($data['items_id']);
                $name = $data['name'];
                if ($name == '') {
                    $name = $item->getName();
                }
                $elements[$data['id']] = $name;
            }
        }
        $rand = Dropdown::showFromArray('id_update', $elements);
        $params = array('items_id' => '__VALUE__', 'rand' => $rand);
        Ajax::updateItemOnSelectEvent("dropdown_id_update{$rand}", "show_updatenode{$rand}", $CFG_GLPI["root_doc"] . "/plugins/monitoring/ajax/dropdownWnode.php", $params, false);
        echo "<span id='show_updatenode{$rand}'></span>\n";
        echo "</td>";
        echo "</tr>";
        echo "<tr>";
        echo "<td align='center' colspan='2'>";
        echo "<input type='submit' name='update' value=\"" . __('Save') . "\" class='submit'>";
        echo "</td>";
        echo "</tr>";
        // * Delete node
        echo "<tr>";
        echo "<th colspan='2'>";
        echo __('Delete a node', 'monitoring');
        echo "</th>";
        echo "</tr>";
        echo "<tr>";
        echo "<td>";
        echo "</td>";
        echo "<td>";
        $query = "SELECT * FROM `" . getTableForItemType("PluginMonitoringWeathermapnode") . "`\n            WHERE `plugin_monitoring_weathermaps_id`='" . $weathermaps_id . "'\n            ORDER BY `name`";
        $result = $DB->query($query);
        $elements = array();
        $elements[0] = Dropdown::EMPTY_VALUE;
        $result = $DB->query($query);
        while ($data = $DB->fetch_array($result)) {
            $itemtype = $data['itemtype'];
            $item = new $itemtype();
            $item->getFromDB($data['items_id']);
            $name = $data['name'];
            if ($name == '') {
                $name = $item->getName();
            }
            $elements[$data['id']] = $name;
        }
        Dropdown::showFromArray('id', $elements);
        echo "</td>";
        echo "</tr>";
        echo "<tr>";
        echo "<td align='center' colspan='2'>";
        echo "<input type='submit' name='purge' value=\"" . __('Delete permanently') . "\" class='submit'>";
        echo "</td>";
        echo "</tr>";
        echo "</table>";
        Html::closeForm();
        echo "</td>";
        echo "</tr>";
        echo "<tr>";
        echo "<td>";
        echo '<form name="formlink" method="post" action="' . $CFG_GLPI['root_doc'] . '/plugins/monitoring/front/weathermaplink.form.php">';
        echo "<table class='tab_cadre' width='100%'>";
        // *Add Link
        echo "<tr>";
        echo "<th colspan='2'>";
        echo __('Add a link', 'monitoring');
        echo "</th>";
        echo "</tr>";
        echo "<tr>";
        echo "<td>";
        echo __('Source', 'monitoring') . "*&nbsp;:";
        echo "</td>";
        echo "<td>";
        $query = "SELECT `glpi_plugin_monitoring_weathermapnodes`.`id` as `id`,\n               `glpi_plugin_monitoring_weathermapnodes`.`name` as `name`,\n               `glpi_plugin_monitoring_componentscatalogs_hosts`.`itemtype`, \n               `glpi_plugin_monitoring_componentscatalogs_hosts`.`items_id`,\n               `glpi_plugin_monitoring_services`.`id` as `services_id`,\n               `glpi_plugin_monitoring_components`.`name` as `components_name`,\n               `plugin_monitoring_commands_id`, `glpi_plugin_monitoring_components`.`arguments`,\n               `glpi_plugin_monitoring_services`.`networkports_id`\n            FROM `glpi_plugin_monitoring_weathermapnodes`\n            \n            LEFT JOIN `glpi_plugin_monitoring_componentscatalogs_hosts`\n               ON (`glpi_plugin_monitoring_weathermapnodes`.`items_id`=`glpi_plugin_monitoring_componentscatalogs_hosts`.`items_id`\n                  AND `glpi_plugin_monitoring_weathermapnodes`.`itemtype`=`glpi_plugin_monitoring_componentscatalogs_hosts`.`itemtype`)\n            \n            LEFT JOIN `glpi_plugin_monitoring_services` \n               ON `plugin_monitoring_componentscatalogs_hosts_id`= `glpi_plugin_monitoring_componentscatalogs_hosts`.`id`\n\n            LEFT JOIN `glpi_plugin_monitoring_components` \n               ON `plugin_monitoring_components_id` = `glpi_plugin_monitoring_components`.`id`\n            \n\n            WHERE `is_weathermap` = '1'\n               AND `plugin_monitoring_weathermaps_id`='" . $weathermaps_id . "'\n            ORDER BY `itemtype`,`items_id`,`glpi_plugin_monitoring_components`.`name`";
        $elements = array();
        $elements[0] = Dropdown::EMPTY_VALUE;
        $elements2 = array();
        $result = $DB->query($query);
        while ($data = $DB->fetch_array($result)) {
            $itemtype = $data['itemtype'];
            $item = new $itemtype();
            $item->getFromDB($data['items_id']);
            $name = $data['name'];
            if ($name == '') {
                $name = $item->getName();
            }
            // Try to get device/node connected on this port
            $device_connected = '';
            if ($data['arguments'] != '') {
                $arguments = importArrayFromDB($data['arguments']);
                foreach ($arguments as $argument) {
                    if (!is_numeric($argument)) {
                        if (strstr($argument, "[[NETWORKPORTDESCR]]")) {
                            if (class_exists("PluginFusinvsnmpNetworkPort")) {
                                $pfNetworkPort = new PluginFusinvsnmpNetworkPort();
                                $pfNetworkPort->loadNetworkport($data['networkports_id']);
                                $argument = $pfNetworkPort->getValue("ifdescr");
                            }
                        } elseif (strstr($argument, "[[NETWORKPORTNUM]]")) {
                            $networkPort = new NetworkPort();
                            $networkPort->getFromDB($data['networkports_id']);
                            $argument = $pfNetworkPort->fields['logical_number'];
                        } elseif (strstr($argument, "[[NETWORKPORTNAME]]")) {
                            $networkPort = new NetworkPort();
                            $networkPort->getFromDB($data['networkports_id']);
                            $argument = $pfNetworkPort->fields['name'];
                        }
                        // Search networkport have this name or description
                        $a_ports = $networkPort->find("`itemtype`='" . $itemtype . "'\n                        AND `items_id`='" . $data['items_id'] . "'\n                        AND `name`='" . $argument . "'");
                        foreach ($a_ports as $pdata) {
                            if ($device_connected == '') {
                                $oppositeports_id = $networkPort->getContact($pdata['id']);
                                if ($oppositeports_id) {
                                    $networkPort->getFromDB($oppositeports_id);
                                    $a_nodes = $pmWeathermapnode->find("\n                                 `plugin_monitoring_weathermaps_id`='" . $weathermaps_id . "'\n                                 AND `itemtype`='" . $networkPort->fields['itemtype'] . "'\n                                 AND `items_id`='" . $networkPort->fields['items_id'] . "'", "", 1);
                                    if (count($a_nodes) > 0) {
                                        $a_node = current($a_nodes);
                                        $device_connected = $pmWeathermapnode->getNodeName($a_node['id']);
                                    }
                                }
                            }
                        }
                        if ($device_connected == '' and class_exists("PluginFusinvsnmpNetworkPort")) {
                            $queryn = "SELECT `glpi_networkports`.`id` FROM `glpi_plugin_fusinvsnmp_networkports`\n                           \n                           LEFT JOIN `glpi_networkports`\n                              ON `glpi_networkports`.`id`=`networkports_id`\n                              \n                           WHERE `itemtype`='" . $itemtype . "'\n                           AND `items_id`='" . $data['items_id'] . "'\n                           AND `ifdescr`='" . $argument . "'";
                            $resultn = $DB->query($queryn);
                            while ($pdata = $DB->fetch_array($resultn)) {
                                if ($device_connected == '') {
                                    $oppositeports_id = $networkPort->getContact($pdata['id']);
                                    if ($oppositeports_id) {
                                        $networkPort->getFromDB($oppositeports_id);
                                        $a_nodes = $pmWeathermapnode->find("\n                                    `plugin_monitoring_weathermaps_id`='" . $weathermaps_id . "'\n                                    AND `itemtype`='" . $networkPort->fields['itemtype'] . "'\n                                    AND `items_id`='" . $networkPort->fields['items_id'] . "'", "", 1);
                                        if (count($a_nodes) > 0) {
                                            $a_node = current($a_nodes);
                                            $queryl = "SELECT `plugin_monitoring_weathermapnodes_id_1`\n                                       FROM `glpi_plugin_monitoring_weathermaplinks`\n\n                                       LEFT JOIN `glpi_plugin_monitoring_weathermapnodes`\n                                          ON `glpi_plugin_monitoring_weathermapnodes`.`id` = `plugin_monitoring_weathermapnodes_id_1`\n\n                                       WHERE ((`plugin_monitoring_weathermapnodes_id_1`='" . $data['id'] . "'\n                                                   AND `plugin_monitoring_weathermapnodes_id_2`='" . $a_node['id'] . "')\n                                                OR (`plugin_monitoring_weathermapnodes_id_1`='" . $a_node['id'] . "'\n                                                   AND `plugin_monitoring_weathermapnodes_id_2`='" . $data['id'] . "'))\n                                          AND `plugin_monitoring_weathermaps_id` = '" . $weathermaps_id . "'";
                                            $resultl = $DB->query($queryl);
                                            if ($DB->numrows($resultl) == '0') {
                                                $device_connected = $pmWeathermapnode->getNodeName($a_node['id']);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if ($device_connected == '') {
                $networkPort->getFromDB($data['networkports_id']);
                $elements2[$data['id'] . "-" . $data['services_id']] = $name . " [" . $networkPort->getfield('name') . "] (" . $data['components_name'] . ")";
            } else {
                $networkPort->getFromDB($data['networkports_id']);
                $elements[$data['id'] . "-" . $data['services_id']] = $name . " [" . $networkPort->getfield('name') . "] (" . $data['components_name'] . ") > " . $device_connected;
            }
        }
        if (count($elements) > 1 and count($elements2) > 0) {
            $elements = array_merge($elements, array('0' => Dropdown::EMPTY_VALUE));
            $elements = array_merge($elements, $elements2);
        } else {
            $elements = array_merge($elements, $elements2);
        }
        Dropdown::showFromArray('linksource', $elements);
        echo "</td>";
        echo "</tr>";
        echo "<tr>";
        echo "<td>";
        echo __('Destination', 'monitoring') . "&nbsp;:";
        echo "</td>";
        echo "<td>";
        echo "<div id='nodedestination'>";
        $query = "SELECT * FROM `" . getTableForItemType("PluginMonitoringWeathermapnode") . "`\n            WHERE `plugin_monitoring_weathermaps_id`='" . $weathermaps_id . "'\n            ORDER BY `name`";
        $result = $DB->query($query);
        $elements = array();
        $elements[0] = Dropdown::EMPTY_VALUE;
        $result = $DB->query($query);
        while ($data = $DB->fetch_array($result)) {
            $itemtype = $data['itemtype'];
            $item = new $itemtype();
            $item->getFromDB($data['items_id']);
            $name = $data['name'];
            if ($name == '') {
                $name = $item->getName();
            }
            $elements[$data['id']] = $name;
        }
        Dropdown::showFromArray('plugin_monitoring_weathermapnodes_id_2', $elements);
        echo "</div>";
        echo "</td>";
        echo "</tr>";
        echo "<tr>";
        echo "<td>";
        echo __('Max bandwidth input', 'monitoring') . "&nbsp;:";
        echo "</td>";
        echo "<td>";
        echo "<input type='text' name='bandwidth_in' value=''/>";
        echo "</td>";
        echo "</tr>";
        echo "<tr>";
        echo "<td>";
        echo __('Max bandwidth output', 'monitoring') . "&nbsp;:";
        echo "</td>";
        echo "<td>";
        echo "<input type='text' name='bandwidth_out' value=''/>";
        echo "</td>";
        echo "</tr>";
        echo "<tr>";
        echo "<td align='center' colspan='2'>";
        echo "<input type='submit' name='add' value=\"" . __('Add') . "\" class='submit'>";
        echo "</td>";
        echo "</tr>";
        // * Edit link
        echo "<tr>";
        echo "<th colspan='2'>";
        echo __('Edit a link', 'monitoring');
        echo "</th>";
        echo "</tr>";
        echo "<tr>";
        echo "<td colspan='2' align='center'>";
        $pmWeathermapnode = new PluginMonitoringWeathermapnode();
        $query = "SELECT `glpi_plugin_monitoring_weathermaplinks`.`id` as `id`,\n               `itemtype`, `items_id`, `name`, `plugin_monitoring_weathermapnodes_id_2`\n            FROM `glpi_plugin_monitoring_weathermaplinks`\n            \n            LEFT JOIN `glpi_plugin_monitoring_weathermapnodes`\n               ON `glpi_plugin_monitoring_weathermapnodes`.`id` = `plugin_monitoring_weathermapnodes_id_1`\n\n            WHERE `plugin_monitoring_weathermaps_id` = '" . $weathermaps_id . "'";
        $elements = array();
        $elements[0] = Dropdown::EMPTY_VALUE;
        $result = $DB->query($query);
        while ($data = $DB->fetch_array($result)) {
            $itemtype = $data['itemtype'];
            $item = new $itemtype();
            $item->getFromDB($data['items_id']);
            $name1 = $data['name'];
            if ($name1 == '') {
                $name1 = $item->getName();
            }
            $pmWeathermapnode->getFromDB($data['plugin_monitoring_weathermapnodes_id_2']);
            $itemtype = $pmWeathermapnode->fields['itemtype'];
            $item = new $itemtype();
            $item->getFromDB($pmWeathermapnode->fields['items_id']);
            $name2 = $pmWeathermapnode->fields['name'];
            if ($name2 == '') {
                $name2 = $item->getName();
            }
            $elements[$data['id']] = $name1 . " - " . $name2;
        }
        $rand = Dropdown::showFromArray('id_update', $elements);
        $params = array('items_id' => '__VALUE__', 'rand' => $rand);
        Ajax::updateItemOnSelectEvent("dropdown_id_update{$rand}", "show_updatelink{$rand}", $CFG_GLPI["root_doc"] . "/plugins/monitoring/ajax/dropdownWlink.php", $params, false);
        echo "<span id='show_updatelink{$rand}'></span>\n";
        echo "</td>";
        echo "</tr>";
        // * Delete link
        echo "<tr>";
        echo "<th colspan='2'>";
        echo __('Delete a link', 'monitoring');
        echo "</th>";
        echo "</tr>";
        echo "<tr>";
        echo "<td>";
        echo "Link :";
        echo "</td>";
        echo "<td>";
        Dropdown::showFromArray('id', $elements);
        echo "</td>";
        echo "</tr>";
        echo "<tr>";
        echo "<td align='center' colspan='2'>";
        echo "<input type='submit' name='purge' value=\"" . __('Delete permanently') . "\" class='submit'>";
        echo "</td>";
        echo "</tr>";
        echo "</table>";
        Html::closeForm();
        echo "</td>";
        echo "</tr>";
        echo "</table>";
        echo "</div>";
        echo "</td>";
        echo "</tr>";
    }