/**
  * Add NETDISCOVERY string to XML code
  *
  *@return nothing
  **/
 function addDiscovery($pxml, $task = 0)
 {
     $ptsnmpa = new PluginFusioninventorySnmpauth();
     $pta = new PluginFusioninventoryAgents();
     $ptap = new PluginFusioninventoryAgentsProcesses();
     $ptrip = new PluginFusioninventoryRangeIP();
     $ptt = new PluginFusioninventoryTask();
     $agent = $pta->InfosByKey($pxml->DEVICEID);
     $count_range = $ptrip->Counter($agent["ID"], "discover");
     $count_range += $ptt->Counter($agent["ID"], "NETDISCOVERY");
     if ($task == "1") {
         $tasks = $ptt->ListTask($agent["ID"], "NETDISCOVERY");
         foreach ($tasks as $task_id => $taskInfos) {
             if ($tasks[$task_id]["param"] == PLUGIN_FUSIONINVENTORY_SNMP_AGENTS) {
                 $task = "0";
             }
         }
         if ($task == "1") {
             $agent["core_discovery"] = 1;
             $agent["threads_discovery"] = 1;
         }
     }
     if ($count_range > 0 && $agent["lock"] == 0 or $task == "1") {
         $a_input = array();
         if ($_SESSION['glpi_plugin_fusioninventory_addagentprocess'] == '0') {
             $this->addProcessNumber($ptap->addProcess($pxml));
             $_SESSION['glpi_plugin_fusioninventory_addagentprocess'] = '1';
         }
         $a_input['discovery_core'] = $agent["core_discovery"];
         $a_input['discovery_threads'] = $agent["threads_discovery"];
         $ptap->updateProcess($this->sxml->PROCESSNUMBER, $a_input);
         $sxml_option = $this->sxml->addChild('OPTION');
         $sxml_option->addChild('NAME', 'NETDISCOVERY');
         $sxml_param = $sxml_option->addChild('PARAM');
         $sxml_param->addAttribute('CORE_DISCOVERY', $agent["core_discovery"]);
         $sxml_param->addAttribute('THREADS_DISCOVERY', $agent["threads_discovery"]);
         $sxml_param->addAttribute('PID', $this->sxml->PROCESSNUMBER);
         if ($task == "1") {
             foreach ($tasks as $task_id => $taskInfos) {
                 $sxml_rangeip = $sxml_option->addChild('RANGEIP');
                 $sxml_rangeip->addAttribute('ID', $task_id);
                 $sxml_rangeip->addAttribute('IPSTART', $tasks[$task_id]["ifaddr"]);
                 $sxml_rangeip->addAttribute('IPEND', $tasks[$task_id]["ifaddr"]);
                 $sxml_rangeip->addAttribute('ENTITY', "");
                 $sxml_rangeip->addAttribute('DEVICEID', $tasks[$task_id]["on_device"]);
                 $sxml_rangeip->addAttribute('TYPE', $tasks[$task_id]["device_type"]);
                 $ptt->deleteFromDB($task_id);
             }
         } else {
             $ranges = $ptrip->ListRange($agent["ID"], "discover");
             foreach ($ranges as $range_id => $rangeInfos) {
                 $sxml_rangeip = $sxml_option->addChild('RANGEIP');
                 $sxml_rangeip->addAttribute('ID', $range_id);
                 $sxml_rangeip->addAttribute('IPSTART', $ranges[$range_id]["ifaddr_start"]);
                 $sxml_rangeip->addAttribute('IPEND', $ranges[$range_id]["ifaddr_end"]);
                 $sxml_rangeip->addAttribute('ENTITY', $ranges[$range_id]["FK_entities"]);
             }
         }
         $snmpauthlist = $ptsnmpa->find();
         if (count($snmpauthlist)) {
             foreach ($snmpauthlist as $snmpauth) {
                 $this->addAuth($sxml_option, $snmpauth['ID']);
             }
         }
         //$this->sxml->addChild('RESPONSE', 'SEND');
     }
 }