/**
  * Get URL for module (for REST)
  *
  * @param $module value name of module
  *
  * @return nothing
  *
  **/
 static function getUrlForModule($modulename, $entities_id = -1)
 {
     // Get current entity URL if it exists ...
     $pfEntity = new PluginFusioninventoryEntity();
     $baseUrl = $pfEntity->getValue('agent_base_url', $entities_id);
     if (!empty($baseUrl)) {
         PluginFusioninventoryToolbox::logIfExtradebug("pluginFusioninventory-agent-url", "Entity " . $entities_id . ", agent base URL: " . $baseUrl);
         if ($baseUrl != 'N/A') {
             return $baseUrl . '/plugins/fusioninventory/b/' . strtolower($modulename) . '/';
         }
     }
     // ... else use global plugin configuration parameter.
     $config = new PluginFusioninventoryConfig();
     if (strlen($pfEntity->getValue('agent_base_url', $entities_id)) < 10) {
         PluginFusioninventoryCommunicationRest::sendError();
         exit;
         // die ("agent_base_url is unset!\n");
     }
     PluginFusioninventoryToolbox::logIfExtradebug("pluginFusioninventory-agent-url", "Global configuration URL: " . $pfEntity->getValue('agent_base_url', $entities_id));
     # Construct the path to the JSON back from the agent_base_url.
     # agent_base_url is the initial URL used by the agent
     return $pfEntity->getValue('agent_base_url', $entities_id) . '/plugins/fusioninventory/b/' . strtolower($modulename) . '/';
 }
                    $params['msg'] = $_GET['msg'];
                } else {
                    $params['code'] = 'running';
                    if (array_key_exists("currentStep", $_GET)) {
                        $params['msg'] = $partjob_mapping[$_GET['currentStep']] . ":" . $_GET['msg'];
                    } else {
                        $params['msg'] = $_GET['msg'];
                    }
                }
            }
            if (is_array($params['msg'])) {
                if (version_compare(PHP_VERSION, '5.4.0') >= 0) {
                    $htmlspecialchars_flags = ENT_SUBSTITUTE | ENT_DISALLOWED;
                } else {
                    $htmlspecialchars_flags = NULL;
                }
                $tmp_msg = implode("\n", $params['msg']);
                $flags = NULL;
                $tmp_msg = stripcslashes(htmlspecialchars($tmp_msg, $htmlspecialchars_flags, 'UTF-8', FALSE));
                $params['msg'] = nl2br($tmp_msg);
            }
            //Generic method to update logs
            PluginFusioninventoryCommunicationRest::updateLog($params);
            break;
    }
    if ($response !== FALSE) {
        echo $response;
    } else {
        echo json_encode((object) array());
    }
}
$_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();
            $pfTaskjobstate = new PluginFusioninventoryTaskjobstate();
            $agent = $pfAgent->InfosByKey(Toolbox::addslashes_deep($_GET['machineid']));
            if (isset($agent['id'])) {
                $taskjobstates = $pfTask->getTaskjobstatesForAgent($agent['id'], array('InventoryComputerESX'));
                ////start of json response
                $order = new stdClass();
                $order->jobs = array();
                $module = new PluginFusioninventoryInventoryComputerESX();
                foreach ($taskjobstates as $taskjobstate) {
                    $order->jobs[] = $module->run($taskjobstate);
                    $taskjobstate->changeStatus($taskjobstate->fields['id'], $taskjobstate::SERVER_HAS_SENT_DATA);
                }
                // return an empty dictionnary if there are no jobs.
                if (count($order->jobs) == 0) {
                    $response = "{}";
                } else {
                    $response = json_encode($order);
                }
            }
            break;
        case 'setLog':
            //Generic method to update logs
            PluginFusioninventoryCommunicationRest::updateLog($_GET);
            break;
    }
    if ($response !== FALSE) {
        echo $response;
    } else {
        echo json_encode((object) array());
    }
}
 /**
  * @test
  */
 public function getCollectURLRootEntity()
 {
     global $DB;
     $DB->connect();
     $_SESSION['glpiactive_entity'] = 0;
     $_SESSION["plugin_fusioninventory_entity"] = 0;
     $_SESSION["glpiname"] = 'Plugin_FusionInventory';
     $entities_id = 1;
     $agents_id = 1;
     $config = new PluginFusioninventoryConfig();
     $config->loadCache();
     $pfEntity = new PluginFusioninventoryEntity();
     $pfEntity->delete(array('id' => 2));
     // Get answer
     $input = array('action' => 'getConfig', 'task' => array('COLLECT' => '1.0.0'), 'machineid' => 'toto-device');
     $response = PluginFusioninventoryCommunicationRest::communicate($input);
     $this->assertEquals('http://127.0.0.1/glpi085/plugins/fusioninventory/b/collect/', $response['schedule'][0]['remote'], 'Wrong URL');
 }
 /**
  * Manage REST parameters
  **/
 static function handleFusionCommunication()
 {
     $response = PluginFusioninventoryCommunicationRest::communicate($_GET);
     if ($response) {
         echo json_encode($response);
     } else {
         PluginFusioninventoryCommunicationRest::sendError();
     }
 }