/**
  * Method for import XML by webservice
  *
  * @param $params array ID of the agent
  * @param $protocol value the communication protocol used
  *
  * @return array or error value
  *
  **/
 static function loadInventory($params, $protocol)
 {
     if (isset($params['help'])) {
         return array('base64' => 'string, mandatory', 'help' => 'bool, optional');
     }
     if (!isset($_SESSION['glpiID'])) {
         return PluginWebservicesMethodCommon::Error($protocol, WEBSERVICES_ERROR_NOTAUTHENTICATED);
     }
     $content = base64_decode($params['base64']);
     $pfCommunication = new PluginFusioninventoryCommunication();
     $pfCommunication->handleOCSCommunication('', $content);
     $msg = __('Computer injected into GLPI', 'fusioninventory');
     return PluginWebservicesMethodCommon::Error($protocol, WEBSERVICES_ERROR_FAILED, '', $msg);
 }
 ini_set("max_execution_time", "0");
 if (preg_match('/\\.zip/i', $_FILES['importfile']['name'])) {
     $zip = zip_open($_FILES['importfile']['tmp_name']);
     if (!$zip) {
         error_log("Zip failure");
         $_SESSION["MESSAGE_AFTER_REDIRECT"] = __("Can't read zip file!", 'fusioninventory');
     } else {
         error_log("Zip ok");
         while ($zip_entry = zip_read($zip)) {
             if (zip_entry_open($zip, $zip_entry, "r")) {
                 $xml = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
                 error_log("toto");
                 error_log($xml);
                 if (!empty($xml)) {
                     $_SESSION['glpi_fusionionventory_nolock'] = TRUE;
                     $pfCommunication->handleOCSCommunication('', $xml);
                     unset($_SESSION['glpi_fusionionventory_nolock']);
                 }
                 zip_entry_close($zip_entry);
             }
         }
         zip_close($zip);
     }
 } else {
     if (preg_match('/\\.(ocs|xml)/i', $_FILES['importfile']['name'])) {
         $xml = file_get_contents($_FILES['importfile']['tmp_name']);
         $_SESSION['glpi_fusionionventory_nolock'] = TRUE;
         $pfCommunication->handleOCSCommunication('', $xml, 'glpi');
         unset($_SESSION['glpi_fusionionventory_nolock']);
     } else {
         $_SESSION["MESSAGE_AFTER_REDIRECT"] = __('No file to import!', 'fusioninventory');
$_SESSION['glpi_use_mode'] = Session::NORMAL_MODE;
if (!isset($_SESSION['glpilanguage'])) {
    $_SESSION['glpilanguage'] = 'fr_FR';
}
$_SESSION['glpi_fusionionventory_nolock'] = TRUE;
ini_set('display_errors', 'On');
error_reporting(E_ALL | E_STRICT);
set_error_handler(array('Toolbox', 'userErrorHandlerDebug'));
$_SESSION['glpi_use_mode'] = 0;
$_SESSION['glpiparententities'] = '';
$_SESSION['glpishowallentities'] = TRUE;
ob_end_clean();
header("server-type: glpi/fusioninventory " . PLUGIN_FUSIONINVENTORY_VERSION);
if (!class_exists("PluginFusioninventoryConfig")) {
    header("Content-Type: application/xml");
    echo "<?xml version='1.0' encoding='UTF-8'?>\n<REPLY>\n   <ERROR>Plugin FusionInventory not installed!</ERROR>\n</REPLY>";
    session_destroy();
    exit;
}
$pfCommunication = new PluginFusioninventoryCommunication();
if (!isset($rawdata)) {
    $rawdata = file_get_contents("php://input");
}
if (isset($_GET['action']) && isset($_GET['machineid'])) {
    PluginFusioninventoryCommunicationRest::handleFusionCommunication();
} else {
    if (!empty($rawdata)) {
        $pfCommunication->handleOCSCommunication($rawdata);
    }
}
session_destroy();