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 GLPI; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  ------------------------------------------------------------------------
*/
// Original Author of file: David DURIEUX
// Purpose of file:
// ----------------------------------------------------------------------
$NEEDED_ITEMS = array("setup", "rulesengine", "fusioninventory", "search");
define('GLPI_ROOT', '../../..');
include GLPI_ROOT . "/inc/includes.php";
$rangeip = new PluginFusioninventoryRangeIP();
commonHeader($LANG['plugin_fusioninventory']["title"][0], $_SERVER["PHP_SELF"], "plugins", "fusioninventory", "rangeip");
PluginFusioninventoryAuth::checkRight("rangeip", "r");
PluginFusioninventoryDisplay::mini_menu();
if (isset($_POST["add"])) {
    if ($rangeip->checkip($_POST)) {
        PluginFusioninventoryAuth::checkRight("rangeip", "w");
        $_POST['ifaddr_start'] = $_POST['ifaddr_start0'] . "." . $_POST['ifaddr_start1'] . "." . $_POST['ifaddr_start2'] . "." . $_POST['ifaddr_start3'];
        $_POST['ifaddr_end'] = $_POST['ifaddr_end0'] . "." . $_POST['ifaddr_end1'] . "." . $_POST['ifaddr_end2'] . "." . $_POST['ifaddr_end3'];
        $rangeip->add($_POST);
    }
    glpi_header($_SERVER['HTTP_REFERER']);
} else {
    if (isset($_POST["update"])) {
        if ($rangeip->checkip($_POST)) {
            PluginFusioninventoryAuth::checkRight("rangeip", "w");
 /**
  * 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');
     }
 }