Example #1
0
 function createGraph($format, $obj, $plugin_archires_views_id)
 {
     global $DB, $CFG_GLPI;
     $type = get_class($obj);
     $ID = $obj->fields["id"];
     $object_view = $obj->fields["plugin_archires_views_id"];
     if (!isset($plugin_archires_views_id)) {
         $plugin_archires_views_id = $object_view;
     }
     $PluginArchiresView = new PluginArchiresView();
     $plugin = new Plugin();
     if ($plugin->isActivated("appliances")) {
         $PluginArchiresApplianceQuery = new PluginArchiresApplianceQuery();
     }
     $PluginArchiresLocationQuery = new PluginArchiresLocationQuery();
     $PluginArchiresNetworkEquipmentQuery = new PluginArchiresNetworkEquipmentQuery();
     $PluginArchiresImageItem = new PluginArchiresImageItem();
     $PluginArchiresView->getFromDB($plugin_archires_views_id);
     $devices = array();
     $ports = array();
     if ($type == 'PluginArchiresLocationQuery') {
         $devices = $PluginArchiresLocationQuery->Query($ID, $PluginArchiresView, true);
         $ports = $PluginArchiresLocationQuery->Query($ID, $PluginArchiresView, false);
     } else {
         if ($type == 'PluginArchiresNetworkEquipmentQuery') {
             $devices = $PluginArchiresNetworkEquipmentQuery->Query($ID, $PluginArchiresView, true);
             $ports = $PluginArchiresNetworkEquipmentQuery->Query($ID, $PluginArchiresView, false);
         } else {
             if ($type == 'PluginArchiresApplianceQuery') {
                 $devices = $PluginArchiresApplianceQuery->Query($ID, $PluginArchiresView, true);
                 $ports = $PluginArchiresApplianceQuery->Query($ID, $PluginArchiresView, false);
             }
         }
     }
     $wires = array();
     $query = "SELECT `id`, `networkports_id_1`, `networkports_id_2`\n                FROM `glpi_networkports_networkports`";
     if ($result = $DB->query($query)) {
         while ($data = $DB->fetch_array($result)) {
             $wires[$data["id"]]["networkports_id_1"] = $data["networkports_id_1"];
             $wires[$data["id"]]["networkports_id_2"] = $data["networkports_id_2"];
         }
     }
     $graph = "graph G {\n";
     $graph .= "overlap=false;\n";
     $graph .= "bgcolor=white;\n";
     //items
     $graph .= "node [shape=polygon, sides=6, fontname=\"Verdana\", fontsize=\"5\"];\n";
     foreach ($devices as $itemtype => $typed_devices) {
         foreach ($typed_devices as $device_id => $device) {
             $image_name = $PluginArchiresImageItem->displayItemImage($device["type"], $itemtype, false);
             $link = Toolbox::getItemTypeFormURL($itemtype);
             $url = $link . "?id=" . $device_id;
             $graph .= $this->graphItems($device, $device_id, $itemtype, $format, $image_name, $url, $PluginArchiresView);
         }
     }
     foreach ($wires as $wire) {
         if (!empty($ports[$wire["networkports_id_1"]]) && !empty($ports[$wire["networkports_id_2"]]) && isset($ports[$wire["networkports_id_1"]]) && isset($ports[$wire["networkports_id_2"]])) {
             $graph .= $this->graphPorts($devices, $ports, $wire, $format, $PluginArchiresView);
         }
     }
     $graph .= "}\n";
     return $this->generateGraphviz($graph, $format, $PluginArchiresView);
 }
Example #2
0
Archires 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 Archires. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
if (!defined('GLPI_ROOT')) {
    include "../../../inc/includes.php";
}
$plugin = new Plugin();
if ($plugin->isActivated("archires")) {
    Session::checkRight("config", "w");
    $PluginArchiresImageItem = new PluginArchiresImageItem();
    $PluginArchiresNetworkInterfaceColor = new PluginArchiresNetworkInterfaceColor();
    $PluginArchiresVlanColor = new PluginArchiresVlanColor();
    $PluginArchiresStateColor = new PluginArchiresStateColor();
    if (isset($_POST["add"]) && isset($_POST['type'])) {
        $test = explode(";", $_POST['type']);
        if (isset($test[0])) {
            $_POST['type'] = $test[1];
            $_POST['itemtype'] = $test[0];
            if ($PluginArchiresImageItem->canCreate()) {
                $PluginArchiresImageItem->addItemImage($_POST['type'], $_POST['itemtype'], $_POST['img']);
            }
        }
        Html::back();
    } else {
        if (isset($_POST["delete"])) {