// Original Author of file: David DURIEUX
// Purpose of file:
// ----------------------------------------------------------------------
$NEEDED_ITEMS = array("setup", "rulesengine", "fusioninventory", "search", "computer", "device", "printer", "networking", "peripheral", "monitor");
define('GLPI_ROOT', '../../..');
include GLPI_ROOT . "/inc/includes.php";
$agents = new PluginFusioninventoryAgents();
commonHeader($LANG['plugin_fusioninventory']["title"][0], $_SERVER["PHP_SELF"], "plugins", "fusioninventory", "agents");
PluginFusioninventoryAuth::checkRight("agents", "r");
PluginFusioninventoryDisplay::mini_menu();
if (isset($_POST["add"])) {
    PluginFusioninventoryAuth::checkRight("agents", "w");
    if ($_POST['on_device'] != "0" and $_POST['on_device'] != "") {
        $_POST['device_type'] = '1';
    }
    $agents->add($_POST);
    glpi_header($_SERVER['HTTP_REFERER']);
} else {
    if (isset($_POST["update"])) {
        PluginFusioninventoryAuth::checkRight("agents", "w");
        if (isset($_POST['on_device'])) {
            if ($_POST['on_device'] != "0" and $_POST['on_device'] != "") {
                $_POST['device_type'] = '1';
            }
        }
        $agents->update($_POST);
        glpi_header($_SERVER['HTTP_REFERER']);
    } else {
        if (isset($_POST["delete"])) {
            PluginFusioninventoryAuth::checkRight("agents", "w");
            $agents->delete($_POST);
 function importToken($p_xml)
 {
     $this->setXML($p_xml);
     if (isset($this->sxml->DEVICEID) and isset($this->sxml->TOKEN)) {
         $pta = new PluginFusioninventoryAgents();
         $a_agent = $pta->find("`key`='" . $this->sxml->DEVICEID . "'", "", "1");
         if (empty($a_agent)) {
             $a_input = array();
             $a_input['token'] = $this->sxml->TOKEN;
             $a_input['name'] = $this->sxml->DEVICEID;
             $a_input['key'] = $this->sxml->DEVICEID;
             $pta->add($a_input);
             return 2;
         } else {
             foreach ($a_agent as $id_agent => $dataInfos) {
                 $input = array();
                 $input['ID'] = $id_agent;
                 $input['token'] = $this->sxml->TOKEN;
                 $pta->update($input);
             }
         }
     }
     return 1;
 }