*/
ob_start();
include "../../../../inc/includes.php";
ob_end_clean();
$response = array();
//Agent communication using REST protocol
if (isset($_GET['action'])) {
    switch ($_GET['action']) {
        case 'getJobs':
            if (isset($_GET['machineid'])) {
                $pfAgent = new PluginFusioninventoryAgent();
                $pfTaskjobstate = new PluginFusioninventoryTaskjobstate();
                $pfTaskjoblog = new PluginFusioninventoryTaskjoblog();
                $a_agent = $pfAgent->InfosByKey(Toolbox::addslashes_deep($_GET['machineid']));
                if (isset($a_agent['id'])) {
                    $moduleRun = $pfTaskjobstate->getTaskjobsAgent($a_agent['id']);
                    foreach ($moduleRun as $className => $array) {
                        if (class_exists($className)) {
                            if ($className == "PluginFusioninventoryCollect") {
                                $class = new PluginFusioninventoryCollect();
                                foreach ($array as $data) {
                                    $out = $class->run($data, $a_agent);
                                    if (count($out) > 0) {
                                        $response[] = $out;
                                    }
                                    $pfTaskjobstate->changeStatus($data['id'], PluginFusioninventoryTaskjobstate::SERVER_HAS_SENT_DATA);
                                    $a_input = array();
                                    $a_input['plugin_fusioninventory_taskjobstates_id'] = $data['id'];
                                    $a_input['items_id'] = $a_agent['id'];
                                    $a_input['itemtype'] = 'PluginFusioninventoryAgent';
                                    $a_input['date'] = date("Y-m-d H:i:s");