/**
  * Display methods availables
  *
  * @param $myname value name of dropdown
  * @param $value value name of the method (used for edit taskjob)
  * @param $entity_restrict restriction of entity if required
  *
  * @return value rand of the dropdown
  *
  **/
 static function getModulesMethods()
 {
     $methods = PluginFusioninventoryStaticmisc::getmethods();
     $modules_methods = array();
     $modules_methods[''] = "------";
     foreach ($methods as $method) {
         if (!(isset($method['hidetask']) and $method['hidetask'] == '1')) {
             if (isset($method['name'])) {
                 $modules_methods[$method['method']] = $method['name'];
             } else {
                 $modules_methods[$method['method']] = $method['method'];
             }
         }
     }
     return $modules_methods;
 }
 /**
  * Display form to add exception of modules activation for each agent
  *
  * @param interger $items_id ID of the agent
  *
  * @return bool TRUE if form is ok
  *
  **/
 function showFormAgentException($items_id)
 {
     global $CFG_GLPI;
     $pfAgent = new PluginFusioninventoryAgent();
     $pfAgent->getFromDB($items_id);
     $canedit = $pfAgent->can($items_id, UPDATE);
     echo "<br/>";
     if ($canedit) {
         echo "<form name='form_ic' method='post' action='" . $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/front/agentmodule.form.php'>";
     }
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr>";
     echo "<th>" . __('Module', 'fusioninventory') . "</th>";
     echo "<th>Activation</th>";
     echo "<th>" . __('Module', 'fusioninventory') . "</th>";
     echo "<th>Activation</th>";
     echo "</tr>";
     $a_modules = $this->find();
     $i = 0;
     $a_methods = PluginFusioninventoryStaticmisc::getmethods();
     foreach ($a_modules as $data) {
         if ($i == 0) {
             echo "<tr class='tab_bg_1'>";
         }
         $modulename = $data["modulename"];
         foreach ($a_methods as $datamod) {
             if (strtolower($data["modulename"]) == strtolower($datamod['method']) || isset($datamod['task']) && strtolower($data["modulename"]) == strtolower($datamod['task'])) {
                 if (isset($datamod['name'])) {
                     $modulename = $datamod['name'];
                 }
                 break;
             }
         }
         // Hack for snmpquery
         if ($data["modulename"] == 'SNMPQUERY') {
             $modulename = __('Network inventory (SNMP)', 'fusioninventory');
         }
         // Hack for deploy
         if ($data["modulename"] == 'DEPLOY') {
             $modulename = __('Package deployment', 'fusioninventory');
         }
         echo "<td width='50%'>" . $modulename . " :</td>";
         echo "<td align='center'>";
         $checked = $data['is_active'];
         $a_agentList = importArrayFromDB($data['exceptions']);
         if (in_array($items_id, $a_agentList)) {
             if ($checked == 1) {
                 $checked = 0;
             } else {
                 $checked = 1;
             }
         }
         $check = "";
         if ($checked == 1) {
             $check = "checked='checked'";
         }
         echo "<input type='checkbox' name='activation-" . $data["modulename"] . "' " . "value='Activation' " . $check . " />";
         echo "</td>";
         if ($i == 1) {
             echo "</tr>";
             $i = -1;
         }
         $i++;
     }
     if ($i == 1) {
         echo "<td></td>";
         echo "<td></td>";
         echo "</tr>";
     }
     if ($canedit) {
         echo "<tr>";
         echo "<td class='tab_bg_2 center' colspan='4'>";
         echo Html::hidden('id', array('value' => $items_id));
         echo "<input type='submit' name='updateexceptions' " . "value=\"" . __('Update') . "\" class='submit'>";
         echo "</td>";
         echo "</tr>";
         echo "</table>";
         Html::closeForm();
     } else {
         echo "</table>";
     }
 }
 /**
  * Prepare Taskjobs for current
  *
  * @return bool cron is ok or not
  *
  **/
 static function cronTaskscheduler()
 {
     ini_set("max_execution_time", "0");
     $task = new self();
     $methods = array();
     foreach (PluginFusioninventoryStaticmisc::getmethods() as $method) {
         $methods[] = $method['method'];
     }
     $task->prepareTaskjobs($methods);
     return true;
 }
 function showFormAgent($agents_id)
 {
     $rule = new PluginFusioninventoryInventoryRuleImport();
     echo "<table class='tab_cadre_fixe' cellpadding='1'>";
     echo "<tr>";
     echo "<th colspan='5'>";
     echo __('Rule import logs', 'fusioninventory');
     echo "</th>";
     echo "</tr>";
     echo "<tr>";
     echo "<th>";
     echo __('Date');
     echo "</th>";
     echo "<th>";
     echo __('Rule name');
     echo "</th>";
     echo "<th>";
     echo __('Item type');
     echo "</th>";
     echo "<th>";
     echo __('Item');
     echo "</th>";
     echo "<th>";
     echo __('Module', 'fusioninventory');
     echo "</th>";
     echo "</tr>";
     $allData = $this->find("`plugin_fusioninventory_agents_id`='" . $agents_id . "'", "`date` DESC");
     foreach ($allData as $data) {
         echo "<tr class='tab_bg_1'>";
         echo "<td align='center'>";
         echo Html::convDateTime($data['date']);
         echo "</td>";
         echo "<td align='center'>";
         if ($rule->getFromDB($data['rules_id'])) {
             echo $rule->getLink(1);
         }
         echo "</td>";
         echo "<td align='center'>";
         $itemtype = $data['itemtype'];
         $item = new $itemtype();
         echo $item->getTypeName();
         echo "</td>";
         echo "<td align='center'>";
         if ($item->getFromDB($data['items_id'])) {
             echo $item->getLink(1);
         }
         echo "</td>";
         echo "<td>";
         $a_methods = PluginFusioninventoryStaticmisc::getmethods();
         foreach ($a_methods as $mdata) {
             if ($mdata['method'] == $data['method']) {
                 echo $mdata['name'];
             }
         }
         echo "</td>";
         echo "</tr>";
     }
     echo "</table>";
 }
Ejemplo n.º 5
0
function plugin_fusioninventory_giveItem($type, $id, $data, $num)
{
    global $CFG_GLPI;
    $searchopt =& Search::getOptions($type);
    $table = $searchopt[$id]["table"];
    $field = $searchopt[$id]["field"];
    switch ($table . '.' . $field) {
        case "glpi_plugin_fusioninventory_taskjobs.status":
            $pfTaskjobstate = new PluginFusioninventoryTaskjobstate();
            return $pfTaskjobstate->stateTaskjob($data['raw']['id'], '200', 'htmlvar', 'simple');
            break;
        case "glpi_plugin_fusioninventory_agents.version":
            $array = importArrayFromDB($data['raw']['ITEM_' . $num]);
            $input = "";
            foreach ($array as $name => $version) {
                $input .= "<strong>" . $name . "</strong> : " . $version . "<br/>";
            }
            $input .= "*";
            $input = str_replace("<br/>*", "", $input);
            return $input;
            break;
        case "glpi_plugin_fusioninventory_credentials.itemtype":
            if ($label = PluginFusioninventoryCredential::getLabelByItemtype($data['raw']['ITEM_' . $num])) {
                return $label;
            } else {
                return '';
            }
            break;
        case 'glpi_plugin_fusioninventory_taskjoblogs.state':
            $pfTaskjoblog = new PluginFusioninventoryTaskjoblog();
            return $pfTaskjoblog->getDivState($data['raw']['ITEM_' . $num]);
            break;
        case 'glpi_plugin_fusioninventory_taskjoblogs.comment':
            $comment = $data['raw']['ITEM_' . $num];
            return PluginFusioninventoryTaskjoblog::convertComment($comment);
            break;
        case 'glpi_plugin_fusioninventory_taskjobstates.plugin_fusioninventory_agents_id':
            $pfAgent = new PluginFusioninventoryAgent();
            $pfAgent->getFromDB($data['raw']['ITEM_' . $num]);
            if (!isset($pfAgent->fields['name'])) {
                return NOT_AVAILABLE;
            }
            $itemtype = PluginFusioninventoryTaskjoblog::getStateItemtype($data['raw']['ITEM_0']);
            if ($itemtype == 'PluginFusioninventoryDeployPackage') {
                $computer = new Computer();
                $computer->getFromDB($pfAgent->fields['computers_id']);
                return $computer->getLink(1);
            }
            return $pfAgent->getLink(1);
            break;
        case 'glpi_plugin_fusioninventory_ignoredimportdevices.ip':
        case 'glpi_plugin_fusioninventory_ignoredimportdevices.mac':
            $array = importArrayFromDB($data['raw']['ITEM_' . $num]);
            return implode("<br/>", $array);
            break;
        case 'glpi_plugin_fusioninventory_ignoredimportdevices.method':
            $a_methods = PluginFusioninventoryStaticmisc::getmethods();
            foreach ($a_methods as $mdata) {
                if ($mdata['method'] == $data['raw']['ITEM_' . $num]) {
                    return $mdata['name'];
                }
            }
            break;
    }
    if ($table == "glpi_plugin_fusioninventory_agentmodules") {
        if ($type == 'Computer') {
            $pfAgentmodule = new PluginFusioninventoryAgentmodule();
            $a_modules = $pfAgentmodule->find("`modulename`='" . $field . "'");
            $data2 = current($a_modules);
            if ($table . "." . $field == "glpi_plugin_fusioninventory_agentmodules." . $data2['modulename']) {
                if (strstr($data['raw']["ITEM_" . $num . "_0"], '"' . $data['raw']["ITEM_" . $num . "_1"] . '"')) {
                    if ($data['raw']['ITEM_' . $num] == '0') {
                        return Dropdown::getYesNo(TRUE);
                    } else {
                        return Dropdown::getYesNo(FALSE);
                    }
                }
                return Dropdown::getYesNo($data['raw']['ITEM_' . $num]);
            }
        } else {
            $pfAgentmodule = new PluginFusioninventoryAgentmodule();
            $a_modules = $pfAgentmodule->find("`modulename`='" . $field . "'");
            foreach ($a_modules as $data2) {
                if ($table . "." . $field == "glpi_plugin_fusioninventory_agentmodules." . $data2['modulename']) {
                    if (strstr($data['raw']["ITEM_" . $num . "_0"], '"' . $data['raw']['id'] . '"')) {
                        if ($data['raw']['ITEM_' . $num] == 0) {
                            return Dropdown::getYesNo('1');
                        } else {
                            return Dropdown::getYesNo('0');
                        }
                    }
                    return Dropdown::getYesNo($data['raw']['ITEM_' . $num]);
                }
            }
        }
    }
    switch ($type) {
        case 'Computer':
            if ($table . '.' . $field == 'glpi_plugin_fusioninventory_networkports.id') {
                if (strstr($data['raw']["ITEM_{$num}"], "\$")) {
                    $split = explode("\$\$\$\$", $data['raw']["ITEM_{$num}"]);
                    $ports = array();
                    foreach ($split as $portconcat) {
                        $split2 = explode("....", $portconcat);
                        if (isset($split2[1])) {
                            $ports[] = $split2[1];
                        }
                    }
                    $out = implode("<br/>", $ports);
                    return $out;
                }
            }
            break;
            // * Networking List (front/networking.php)
        // * Networking List (front/networking.php)
        case 'NetworkEquipment':
            switch ($table . '.' . $field) {
            }
            break;
        case 'Printer':
            if ($table . '.' . $field == 'glpi_plugin_fusioninventory_networkequipments.name') {
                if (strstr($data['raw']["ITEM_{$num}"], "\$")) {
                    $split = explode("\$\$\$\$", $data['raw']["ITEM_{$num}"]);
                    $out = implode("<br/>", $split);
                    return $out;
                }
            }
            break;
            // * Authentification List (plugins/fusinvsnmp/front/configsecurity.php)
        // * Authentification List (plugins/fusinvsnmp/front/configsecurity.php)
        case 'PluginFusioninventoryConfigSecurity':
            switch ($table . '.' . $field) {
                // ** Hidden auth passphrase (SNMP v3)
                case "glpi_plugin_fusioninventory_configsecurities.auth_passphrase":
                    $out = "";
                    if (empty($data['raw']["ITEM_{$num}"])) {
                    } else {
                        $out = "********";
                    }
                    return $out;
                    break;
                    // ** Hidden priv passphrase (SNMP v3)
                // ** Hidden priv passphrase (SNMP v3)
                case "glpi_plugin_fusioninventory_configsecurities.priv_passphrase":
                    $out = "";
                    if (empty($data['raw']["ITEM_{$num}"])) {
                    } else {
                        $out = "********";
                    }
                    return $out;
                    break;
            }
            break;
            // * Unknown mac addresses connectd on switch - report
            //   (plugins/fusinvsnmp/report/unknown_mac.php)
        // * Unknown mac addresses connectd on switch - report
        //   (plugins/fusinvsnmp/report/unknown_mac.php)
        case 'PluginFusioninventoryUnmanaged':
            switch ($table . '.' . $field) {
                // ** FusionInventory - switch
                case "glpi_plugin_fusioninventory_networkequipments.id":
                    $out = '';
                    $NetworkPort = new NetworkPort();
                    $list = explode("\$\$\$\$", $data['raw']["ITEM_{$num}"]);
                    foreach ($list as $numtmp => $vartmp) {
                        $NetworkPort->getDeviceData($vartmp, 'PluginFusioninventoryUnmanaged');
                        $out .= "<a href=\"" . $CFG_GLPI["root_doc"] . "/";
                        $out .= "plugins/fusioninventory/front/unmanaged.form.php?id=" . $vartmp . "\">";
                        $out .= $NetworkPort->device_name;
                        if ($CFG_GLPI["view_ID"]) {
                            $out .= " (" . $vartmp . ")";
                        }
                        $out .= "</a><br/>";
                    }
                    return "<center>" . $out . "</center>";
                    break;
                    // ** FusionInventory - switch port
                // ** FusionInventory - switch port
                case "glpi_plugin_fusioninventory_networkports.id":
                    $out = '';
                    if (!empty($data['raw']["ITEM_{$num}"])) {
                        $list = explode("\$\$\$\$", $data['raw']["ITEM_{$num}"]);
                        $np = new NetworkPort();
                        foreach ($list as $numtmp => $vartmp) {
                            $np->getFromDB($vartmp);
                            $out .= "<a href='" . $CFG_GLPI['root_doc'] . "/front/networkport.form.php?id=" . $vartmp . "'>";
                            $out .= $np->fields["name"] . "</a><br/>";
                        }
                    }
                    return "<center>" . $out . "</center>";
                    break;
                case "glpi_plugin_fusinvsnmp_unmanageds.type":
                    $out = '<center> ';
                    switch ($data['raw']["ITEM_{$num}"]) {
                        case COMPUTER_TYPE:
                            $out .= __('Computers');
                            break;
                        case NETWORKING_TYPE:
                            $out .= __('Networks');
                            break;
                        case PRINTER_TYPE:
                            $out .= __('Printers');
                            break;
                        case PERIPHERAL_TYPE:
                            $out .= __('Devices');
                            break;
                        case PHONE_TYPE:
                            $out .= __('Phones');
                            break;
                    }
                    $out .= '</center>';
                    return $out;
                    break;
            }
            break;
            // * Ports date connection - report (plugins/fusinvsnmp/report/ports_date_connections.php)
        // * Ports date connection - report (plugins/fusinvsnmp/report/ports_date_connections.php)
        case 'PluginFusioninventoryNetworkPort':
            switch ($table . '.' . $field) {
                // ** Name and link of networking device (switch)
                case "glpi_plugin_fusioninventory_networkports.id":
                    $query = "SELECT `glpi_networkequipments`.`name` AS `name`, `glpi_networkequipments`.`id` AS `id`\n                         FROM `glpi_networkequipments`\n                              LEFT JOIN `glpi_networkports`\n                                        ON `items_id` = `glpi_networkequipments`.`id`\n                              LEFT JOIN `glpi_plugin_fusioninventory_networkports`\n                                        ON `glpi_networkports`.`id`=`networkports_id`\n                         WHERE `glpi_plugin_fusioninventory_networkports`.`id`='" . $data['raw']["ITEM_{$num}"] . "'\n                         LIMIT 0, 1;";
                    $result = $DB->query($query);
                    $data2 = $DB->fetch_assoc($result);
                    $out = "<a href='" . $CFG_GLPI['root_doc'] . "/front/networking.form.php?id=" . $data2["id"] . "'>";
                    $out .= $data2["name"] . "</a>";
                    return "<center>" . $out . "</center>";
                    break;
                    // ** Name and link of port of networking device (port of switch)
                // ** Name and link of port of networking device (port of switch)
                case "glpi_plugin_fusioninventory_networkports.networkports_id":
                    $NetworkPort = new NetworkPort();
                    $NetworkPort->getFromDB($data['raw']["ITEM_{$num}"]);
                    $name = "";
                    if (isset($NetworkPort->fields["name"])) {
                        $name = $NetworkPort->fields["name"];
                    }
                    $out = "<a href='" . $CFG_GLPI['root_doc'] . "/front/networkport.form.php?id=" . $data['raw']["ITEM_{$num}"];
                    $out .= "'>" . $name . "</a>";
                    return "<center>" . $out . "</center>";
                    break;
                    // ** Location of switch
                // ** Location of switch
                case "glpi_locations.id":
                    $out = Dropdown::getDropdownName("glpi_locations", $data['raw']["ITEM_{$num}"]);
                    return "<center>" . $out . "</center>";
                    break;
            }
            break;
            // * range IP list (plugins/fusinvsnmp/front/iprange.php)
        // * range IP list (plugins/fusinvsnmp/front/iprange.php)
        case 'PluginFusioninventoryIPRange':
            switch ($table . '.' . $field) {
                // ** Display entity name
                case "glpi_entities.name":
                    if ($data['raw']["ITEM_{$num}"] == '') {
                        $out = Dropdown::getDropdownName("glpi_entities", $data['raw']["ITEM_{$num}"]);
                        return "<center>" . $out . "</center>";
                    }
                    break;
            }
            break;
        case 'PluginFusioninventoryNetworkPortLog':
            switch ($table . '.' . $field) {
                // ** Display switch and Port
                case "glpi_networkports.id":
                    $Array_device = PluginFusioninventoryNetworkPort::getUniqueObjectfieldsByportID($data['raw']["ITEM_{$num}"]);
                    $item = new $Array_device["itemtype"]();
                    $item->getFromDB($Array_device["items_id"]);
                    $out = "<div align='center'>" . $item->getLink(1);
                    $query = "SELECT *\n                         FROM `glpi_networkports`\n                         WHERE `id`='" . $data['raw']["ITEM_{$num}"] . "';";
                    $result = $DB->query($query);
                    if ($DB->numrows($result) != "0") {
                        $out .= "<br/><a href='" . $CFG_GLPI['root_doc'] . "/front/networkport.form.php?id=";
                        $out .= $data['raw']["ITEM_{$num}"] . "'>" . $DB->result($result, 0, "name") . "</a>";
                    }
                    $out .= "</td>";
                    return $out;
                    break;
                    // ** Display GLPI field of device
                // ** Display GLPI field of device
                case "glpi_plugin_fusinvsnmp_networkportlogs.field":
                    //               $out = $FUSIONINVENTORY_MAPPING[NETWORKING_TYPE][$data['raw']["ITEM_$num"]]['name'];
                    $out = '';
                    $map = new PluginFusioninventoryMapping();
                    $mapfields = $map->get('NetworkEquipment', $data['raw']["ITEM_{$num}"]);
                    if ($mapfields != FALSE) {
                        $out = _get('_LANG[\'plugin_fusinvsnmp\'][\'mapping\'][$mapfields["locale"]]');
                    }
                    return $out;
                    break;
                    // ** Display Old Value (before changement of value)
                // ** Display Old Value (before changement of value)
                case "glpi_plugin_fusinvsnmp_networkportlogs.old_value":
                    // TODO ADD LINK TO DEVICE
                    if (substr_count($data['raw']["ITEM_{$num}"], ":") == 5 && empty($data['raw']["ITEM_3"])) {
                        return "<center><b>" . $data['raw']["ITEM_{$num}"] . "</b></center>";
                    }
                    break;
                    // ** Display New Value (new value modified)
                // ** Display New Value (new value modified)
                case "glpi_plugin_fusinvsnmp_networkportlogs.new_value":
                    if (substr_count($data['raw']["ITEM_{$num}"], ":") == 5 && empty($data['raw']["ITEM_3"])) {
                        return "<center><b>" . $data['raw']["ITEM_{$num}"] . "</b></center>";
                    }
                    break;
            }
            break;
        case "PluginFusioninventoryPrinterLog":
            switch ($table . '.' . $field) {
                case 'glpi_printers.name':
                    // Search pages in printer history to limit SQL queries
                    if (isset($_SESSION['glpi_plugin_fusioninventory_history_start'])) {
                        unset($_SESSION['glpi_plugin_fusioninventory_history_start']);
                    }
                    if (isset($_SESSION['glpi_plugin_fusioninventory_history_end'])) {
                        unset($_SESSION['glpi_plugin_fusioninventory_history_end']);
                    }
                    if (isset($_SESSION['glpi_plugin_fusioninventory_date_start']) and isset($_SESSION['glpi_plugin_fusioninventory_date_end'])) {
                        $query = "SELECT * FROM `glpi_plugin_fusioninventory_printerlogs`\n                     WHERE `printers_id`='" . $data['raw']['ITEM_0_2'] . "'\n                        AND `date`>= '" . $_SESSION['glpi_plugin_fusioninventory_date_start'] . "'\n                        AND `date`<= '" . $_SESSION['glpi_plugin_fusioninventory_date_end'] . " 23:59:59'\n                     ORDER BY date asc\n                     LIMIT 1";
                        $result = $DB->query($query);
                        while ($data2 = $DB->fetch_array($result)) {
                            $_SESSION['glpi_plugin_fusioninventory_history_start'] = $data2;
                        }
                        $query = "SELECT * FROM `glpi_plugin_fusioninventory_printerlogs`\n                     WHERE `printers_id`='" . $data['raw']['ITEM_0_2'] . "'\n                        AND `date`>= '" . $_SESSION['glpi_plugin_fusioninventory_date_start'] . "'\n                        AND `date`<= '" . $_SESSION['glpi_plugin_fusioninventory_date_end'] . " 23:59:59'\n                     ORDER BY date desc\n                     LIMIT 1";
                        $result = $DB->query($query);
                        while ($data2 = $DB->fetch_array($result)) {
                            $_SESSION['glpi_plugin_fusioninventory_history_end'] = $data2;
                        }
                    }
                    return "";
                    break;
            }
            switch ($table) {
                case 'glpi_plugin_fusioninventory_printerlogs':
                    if (isset($_SESSION['glpi_plugin_fusioninventory_history_start'][$field]) and isset($_SESSION['glpi_plugin_fusioninventory_history_end'][$field])) {
                        $counter_start = $_SESSION['glpi_plugin_fusioninventory_history_start'][$field];
                        $counter_end = $_SESSION['glpi_plugin_fusioninventory_history_end'][$field];
                        if ($_SESSION['glpi_plugin_fusioninventory_date_start'] == "1970-01-01") {
                            $counter_start = 0;
                        }
                        $number = $counter_end - $counter_start;
                        if ($number == '0') {
                            return '-';
                        } else {
                            return $number;
                        }
                    } else {
                        return '-';
                    }
                    break;
            }
            break;
    }
    return "";
}
 /**
  * Get configuration for an agent
  *
  * @params an array of GET parameters given by the agent
  *
  * @return an array of orders to send to the agent
  */
 static function getConfigByAgent($params = array())
 {
     $schedule = array();
     $pfAgentModule = new PluginFusioninventoryAgentmodule();
     $a_agent = PluginFusioninventoryAgent::getByDeviceID($params['machineid']);
     if (isset($params['task'])) {
         foreach (array_keys($params['task']) as $task) {
             foreach (PluginFusioninventoryStaticmisc::getmethods() as $method) {
                 $classname = '';
                 if (strtolower($task) == 'deploy') {
                     $classname = 'PluginFusioninventoryDeployPackage';
                 } else {
                     if (strtolower($task) == 'esx') {
                         $classname = 'PluginFusioninventoryCredentialIp';
                     } else {
                         if (strtolower($task) == 'collect') {
                             $classname = 'PluginFusioninventoryCollect';
                         }
                     }
                 }
                 $taskname = $method['method'];
                 if (strstr($taskname, 'deploy')) {
                     $taskname = $method['task'];
                 }
                 $class = PluginFusioninventoryStaticmisc::getStaticmiscClass($method['module']);
                 if (isset($method['task']) && strtolower($method['task']) == strtolower($task) && (isset($method['use_rest']) && $method['use_rest']) && method_exists($class, self::getMethodForParameters($task)) && $pfAgentModule->isAgentCanDo($taskname, $a_agent['id']) && countElementsInTable('glpi_plugin_fusioninventory_taskjobstates', "`plugin_fusioninventory_agents_id`='" . $a_agent['id'] . "' " . " AND `itemtype`='" . $classname . "'" . " AND `state`='0'") > 0) {
                     /*
                      * Since migration, there is only one plugin in one directory
                      * It's maybe time to redo this function -- kiniou
                      */
                     $schedule[] = call_user_func(array($class, self::getMethodForParameters($task)), $a_agent['entities_id']);
                     break;
                     //Stop the loop since we found the module corresponding to the asked task
                 }
             }
         }
     }
     return array('configValidityPeriod' => 600, 'schedule' => $schedule);
 }
chdir(dirname($_SERVER["SCRIPT_FILENAME"]));
include "../../../inc/includes.php";
include "./docopt.php";
require "./logging.php";
/**
 * Process arguments passed to the script
 */
$docopt = new \Docopt\Handler();
$args = $docopt->handle($doc);
$logger = new Logging();
$logger->setLevelFromArgs($args['--quiet'], $args['--debug']);
$logger->debug($args);
$agent = new PluginFusioninventoryAgent();
$computer = new Computer();
$task = new PluginFusioninventoryTask();
$staticmisc_methods = PluginFusioninventoryStaticmisc::getmethods();
$methods = array();
foreach ($staticmisc_methods as $method) {
    $methods[$method['method']] = $method['method'];
}
$device_ids = array();
if (count($args['<device_ids>']) == 0) {
    $agents = array_values($agent->find());
    $randid = rand(0, count($agents));
    $device_ids = array($agents[$randid]['device_id']);
} else {
    //$agents = $agent->find("device_id in ('".implode("','", $args['<device_ids>'])."')");
    //$device_ids[] = $agent_data['device_id'];
    $device_ids = $args['<device_ids>'];
}
//$logger->debug($device_ids);
 function updateMethod($method, $taskjobs_id)
 {
     $a_methods = PluginFusioninventoryStaticmisc::getmethods();
     foreach ($a_methods as $datas) {
         if ($method == $datas['method']) {
             $input = array();
             $input['id'] = $taskjobs_id;
             $input['method'] = $method;
             $input['plugins_id'] = PluginFusioninventoryModule::getModuleId($datas['module']);
             $this->update($input);
         }
     }
 }
 /**
  * Get all tasks prepared for this agent
  *
  * @param $agent_id interger id of agent
  *
  **/
 function getTaskAgent($agent_id)
 {
     $pfTask = new PluginFusioninventoryTask();
     /**
      * TODO: the following must be definitely done differently !
      * (... but i'm kind in a hurry right now ;-) )
      */
     $methods = array();
     $classnames = array();
     foreach (PluginFusioninventoryStaticmisc::getmethods() as $method) {
         if (isset($method['classname'])) {
             $methods[] = $method['method'];
             $classnames[$method['method']] = $method['classname'];
         }
     }
     $jobstates = $pfTask->getTaskjobstatesForAgent($agent_id, $methods);
     foreach ($jobstates as $jobstate) {
         $className = $classnames[$jobstate->method];
         if (class_exists($className)) {
             /*
              * TODO: check if use_rest is enabled in Staticmisc::get_methods.
              * Also, this get_methods function need to be reviewed
              */
             if ($className != "PluginFusioninventoryInventoryComputerESX" && $className != "PluginFusioninventoryDeployCommon" && $className != "PluginFusioninventoryCollect") {
                 $class = new $className();
                 $sxml_temp = $class->run($jobstate);
                 PluginFusioninventoryToolbox::append_simplexml($this->message, $sxml_temp);
             }
         }
     }
 }