function plugin_fusioninventory_addWhere($link, $nott, $type, $id, $val) { $searchopt =& Search::getOptions($type); $table = $searchopt[$id]["table"]; $field = $searchopt[$id]["field"]; switch ($type) { case 'PluginFusioninventoryTaskjob': /* * WARNING: The following is some minor hack in order to select a range of ids. * * More precisely, when using the ID filter, you can now put IDs separated by commas. * This is used by the DeployPackage class when it comes to check running tasks on some * packages. */ if ($table == 'glpi_plugin_fusioninventory_tasks') { if ($field == 'id') { //check if this range is numeric $ids = explode(',', $val); foreach ($ids as $k => $i) { if (!is_numeric($i)) { unset($ids[$k]); } } if (count($ids) >= 1) { return $link . " `{$table}`.`id` IN (" . implode(',', $ids) . ")"; } else { return ""; } } elseif ($field == 'name') { $val = stripslashes($val); //decode a json query to match task names in taskjobs list $names = json_decode($val); if ($names !== NULL && is_array($names)) { $names = array_map(create_function('$a', 'return "\\"".$a."\\"";'), $names); return $link . " `{$table}`.`name` IN (" . implode(',', $names) . ")"; } else { return ""; } } } break; case 'PluginFusioninventoryAgent': $pfAgentmodule = new PluginFusioninventoryAgentmodule(); $a_modules = $pfAgentmodule->find(); foreach ($a_modules as $data) { if ($table . "." . $field == "glpi_plugin_fusioninventory_agentmodules." . $data['modulename']) { if ($data['exceptions'] != "[]" and $data['exceptions'] != "") { $a_exceptions = importArrayFromDB($data['exceptions']); $current_id = current($a_exceptions); $in = "("; foreach ($a_exceptions as $agent_id) { $in .= $agent_id . ", "; } $in .= ")"; $in = str_replace(", )", ")", $in); if ($val != $data['is_active']) { return $link . " (FUSION_" . $data['modulename'] . ".`exceptions` LIKE '%\"" . $current_id . "\"%' ) AND `glpi_plugin_fusioninventory_agents`.`id` IN " . $in . " "; } else { return $link . " `glpi_plugin_fusioninventory_agents`.`id` NOT IN " . $in . " "; } } else { if ($val != $data['is_active']) { return $link . " (FUSION_" . $data['modulename'] . ".`is_active`!='" . $data['is_active'] . "') "; } else { return $link . " (FUSION_" . $data['modulename'] . ".`is_active`='" . $data['is_active'] . "') "; } } } } break; case 'PluginFusioninventoryTaskjoblog': if ($field == 'uniqid') { return $link . " (`" . $table . "`.`uniqid`='" . $val . "') "; } break; // * Computer List (front/computer.php) // * Computer List (front/computer.php) case 'Computer': switch ($table . "." . $field) { // ** FusionInventory - switch case "glpi_plugin_fusioninventory_networkequipments.name": $ADD = ""; if ($nott == "0" && $val == "NULL") { $ADD = " OR glpi_networkequipments.id IS NULL"; } else { if ($nott == "1" && $val == "NULL") { $ADD = " OR glpi_networkequipments.id IS NOT NULL"; } } return $link . " (glpi_networkequipments.id LIKE '%" . $val . "%' {$ADD} ) "; break; // ** FusionInventory - switch port // ** FusionInventory - switch port case "glpi_plugin_fusioninventory_networkports.id": $ADD = ""; if ($nott == "0" && $val == "NULL") { $ADD = " OR FUSIONINVENTORY_22.name IS NULL"; } else { if ($nott == "1" && $val == "NULL") { $ADD = " OR FUSIONINVENTORY_22.name IS NOT NULL"; } } return $link . " (FUSIONINVENTORY_22.name LIKE '%" . $val . "%' {$ADD} ) "; break; } $a_agent_modules = PluginFusioninventoryAgentmodule::getModules(); foreach ($a_agent_modules as $module) { if ($table . "." . $field == 'glpi_plugin_fusioninventory_agentmodules.' . $module) { $pfAgentmodule = new PluginFusioninventoryAgentmodule(); $a_modules = $pfAgentmodule->find("`modulename`='" . $module . "'"); $data = current($a_modules); if ($data['exceptions'] != "[]" and $data['exceptions'] != "") { $a_exceptions = importArrayFromDB($data['exceptions']); $current_id = current($a_exceptions); $in = "("; foreach ($a_exceptions as $agent_id) { $in .= $agent_id . ", "; } $in .= ")"; $in = str_replace(", )", ")", $in); if ($val != $data['is_active']) { return $link . " (FUSION_" . $module . ".`exceptions` LIKE '%\"" . $current_id . "\"%' ) AND `agent" . strtolower($module) . "`.`id` IN " . $in . " "; } else { return $link . " `agent" . strtolower($module) . "`.`id` NOT IN " . $in . " "; } } else { if ($val != $data['is_active']) { return $link . " (FUSION_" . $module . ".`is_active`!='" . $data['is_active'] . "') "; } else { return $link . " (FUSION_" . $module . ".`is_active`='" . $data['is_active'] . "') "; } } } } break; // * Networking List (front/networking.php) // * Networking List (front/networking.php) case 'NetworkEquipment': switch ($table . "." . $field) { // ** FusionInventory - last inventory case "glpi_plugin_fusioninventory_networkequipments.networkequipments_id": $ADD = ""; if ($nott == "0" && $val == "NULL") { $ADD = " OR {$table}.last_fusinvsnmp_update IS NULL"; } else { if ($nott == "1" && $val == "NULL") { $ADD = " OR {$table}.last_fusinvsnmp_update IS NOT NULL"; } } return $link . " ({$table}.last_fusinvsnmp_update LIKE '%" . $val . "%' {$ADD} ) "; break; // ** FusionInventory - SNMP authentification // ** FusionInventory - SNMP authentification case "glpi_plugin_fusioninventory_networkequipments.plugin_fusinvsnmp_snmpauths_id": $ADD = ""; if ($nott == "0" && $val == "NULL") { $ADD = " OR glpi_plugin_fusioninventory_configsecurities.name IS NULL"; } else { if ($nott == "1" && $val == "NULL") { $ADD = " OR glpi_plugin_fusioninventory_configsecurities.name IS NOT NULL"; } } return $link . " (glpi_plugin_fusioninventory_configsecurities.name LIKE '%" . $val . "%' {$ADD} ) "; break; // ** FusionInventory - CPU // ** FusionInventory - CPU case "glpi_plugin_fusioninventory_networkequipments.cpu": break; } break; // * Printer List (front/printer.php) // * Printer List (front/printer.php) case 'Printer': switch ($table . "." . $field) { // ** FusionInventory - last inventory case "glpi_plugin_fusioninventory_printers.printers_id": $ADD = ""; if ($nott == "0" && $val == "NULL") { $ADD = " OR {$table}.last_fusinvsnmp_update IS NULL"; } else { if ($nott == "1" && $val == "NULL") { $ADD = " OR {$table}.last_fusinvsnmp_update IS NOT NULL"; } } return $link . " ({$table}.last_fusinvsnmp_update LIKE '%" . $val . "%' {$ADD} ) "; break; // ** FusionInventory - SNMP authentification // ** FusionInventory - SNMP authentification case "glpi_plugin_fusioninventory_networkequipments.plugin_fusinvsnmp_snmpauths_id": $ADD = ""; if ($nott == "0" && $val == "NULL") { $ADD = " OR {$table}.name IS NULL"; } else { if ($nott == "1" && $val == "NULL") { $ADD = " OR {$table}.name IS NOT NULL"; } } return $link . " ({$table}.name LIKE '%" . $val . "%' {$ADD} ) "; break; // ** FusionInventory - switch // ** FusionInventory - switch case "glpi_plugin_fusioninventory_networkequipments.name": $ADD = ""; if ($nott == "0" && $val == "NULL") { $ADD = " OR glpi_networkequipments.id IS NULL"; } else { if ($nott == "1" && $val == "NULL") { $ADD = " OR glpi_networkequipments.id IS NOT NULL"; } } return $link . " (glpi_networkequipments.id LIKE '%" . $val . "%' {$ADD} ) "; break; // ** FusionInventory - switch port // ** FusionInventory - switch port case "glpi_plugin_fusioninventory_networkports.id": $ADD = ""; if ($nott == "0" && $val == "NULL") { $ADD = " OR FUSIONINVENTORY_22.name IS NULL"; } else { if ($nott == "1" && $val == "NULL") { $ADD = " OR FUSIONINVENTORY_22.name IS NOT NULL"; } } return $link . " (FUSIONINVENTORY_22.name LIKE '%" . $val . "%' {$ADD} ) "; break; } break; // * Unknown mac addresses connectd on switch - report // (plugins/fusinvsnmp/report/unknown_mac.php) // * Unknown mac addresses connectd on switch - report // (plugins/fusinvsnmp/report/unknown_mac.php) case 'PluginFusioninventoryUnmanaged': switch ($table . "." . $field) { // ** FusionInventory - switch case "glpi_plugin_fusioninventory_networkequipments.id": $ADD = ""; if ($nott == "0" && $val == "NULL") { $ADD = " OR FUSIONINVENTORY_12.items_id IS NULL"; } else { if ($nott == "1" && $val == "NULL") { $ADD = " OR FUSIONINVENTORY_12.items_id IS NOT NULL"; } } return $link . " (FUSIONINVENTORY_13.name LIKE '%" . $val . "%' {$ADD} ) "; break; // ** FusionInventory - switch port // ** FusionInventory - switch port case "glpi_plugin_fusioninventory_networkports.id": $ADD = ""; if ($nott == "0" && $val == "NULL") { $ADD = " OR FUSIONINVENTORY_22.name IS NULL"; } else { if ($nott == "1" && $val == "NULL") { $ADD = " OR FUSIONINVENTORY_22.name IS NOT NULL"; } } return $link . " (FUSIONINVENTORY_22.name LIKE '%" . $val . "%' {$ADD} ) "; break; } break; // * Ports date connection - report (plugins/fusinvsnmp/report/ports_date_connections.php) // * Ports date connection - report (plugins/fusinvsnmp/report/ports_date_connections.php) case 'PluginFusioninventoryNetworkPort': switch ($table . "." . $field) { // ** Name and link of networking device (switch) case "glpi_plugin_fusioninventory_networkports.id": break; // ** Name and link of port of networking device (port of switch) // ** Name and link of port of networking device (port of switch) case "glpi_plugin_fusioninventory_networkports.networkports_id": break; // ** Location of switch // ** Location of switch case "glpi_locations.id": $ADD = ""; if ($nott == "0" && $val == "NULL") { $ADD = " OR glpi_networkequipments.location IS NULL"; } else { if ($nott == "1" && $val == "NULL") { $ADD = " OR glpi_networkequipments.location IS NOT NULL"; } } if ($val == "0") { return $link . " (glpi_networkequipments.location >= -1 ) "; } return $link . " (glpi_networkequipments.location = '" . $val . "' {$ADD} ) "; break; case "glpi_plugin_fusioninventory_networkports.lastup": $ADD = ""; //$val = str_replace("<", ">", $val); //$val = str_replace("\\", "", $val); if ($nott == "0" && $val == "NULL") { $ADD = " OR {$table}.{$field} IS NULL"; } else { if ($nott == "1" && $val == "NULL") { $ADD = " OR {$table}.{$field} IS NOT NULL"; } } return $link . " ({$table}.{$field} {$val} {$ADD} ) "; break; } break; // * range IP list (plugins/fusinvsnmp/front/iprange.php) // * range IP list (plugins/fusinvsnmp/front/iprange.php) case 'PluginFusioninventoryIPRange': switch ($table . "." . $field) { // ** Name of range IP and link to form case "glpi_plugin_fusioninventory_ipranges.name": break; // ** Agent name associed to IP range and link to agent form // ** Agent name associed to IP range and link to agent form case "glpi_plugin_fusinvsnmp_agents.id": $ADD = ""; if ($nott == "0" && $val == "NULL") { $ADD = " OR {$table}.name IS NULL"; } else { if ($nott == "1" && $val == "NULL") { $ADD = " OR {$table}.name IS NOT NULL"; } } return $link . " ({$table}.name LIKE '%" . $val . "%' {$ADD} ) "; break; } switch ($table . "." . $field) { case "glpi_plugin_fusinvsnmp_agents.plugin_fusinvsnmp_agents_id_query": $ADD = ""; if ($nott == "0" && $val == "NULL") { $ADD = " OR {$table}.name IS NULL"; } else { if ($nott == "1" && $val == "NULL") { $ADD = " OR {$table}.name IS NOT NULL"; } } return $link . " (gpta.name LIKE '%" . $val . "%' {$ADD} ) "; break; } break; case 'PluginFusioninventoryNetworkPortLog': switch ($table . "." . $field) { // ** Display switch and Port case "glpi_networkports.id": $ADD = ""; if ($nott == "0" && $val == "NULL") { $ADD = " OR {$table}.id IS NULL "; } else { if ($nott == "1" && $val == "NULL") { $ADD = " OR {$table}.id IS NOT NULL "; } } return $link . " ({$table}.id = '" . $val . "' {$ADD} ) "; break; // ** Display GLPI field of device // ** Display GLPI field of device case "glpi_plugin_fusinvsnmp_networkportlogs.field": $ADD = ""; if ($nott == "0" && $val == "NULL") { $ADD = " OR {$table}.{$field} IS NULL "; } else { if ($nott == "1" && $val == "NULL") { $ADD = " OR {$table}.{$field} IS NOT NULL "; } } if (!empty($val)) { $map = new PluginFusioninventoryMapping(); $mapfields = $map->get('NetworkEquipment', $val); if ($mapfields != FALSE) { $val = $mapfields['tablefields']; } else { $val = ''; } } return $link . " ({$table}.{$field} = '" . addslashes($val) . "' {$ADD} ) "; break; } break; } return ""; }