/**
  * 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;
 }
 /**
  * agent's ids with module activations.
  * @since 0.85+1.0
  * @param $agent_ids List of agent's ids.
  * @param $methods Methods requested.
  * @return The list filtered by activated on the requested methods.
  */
 function filterAgentsByMethods($agent_ids, $methods = array())
 {
     $available_methods = PluginFusioninventoryStaticmisc::task_methods();
     $methods_requested = array();
     foreach ($available_methods as $method_info) {
         if (in_array($method_info, $methods)) {
             $methods_requested = $method_info;
         }
     }
 }
 /**
  * Display form for taskjob
  *
  * @param $items_id integer id of the taskjob
  * @param $options array
  *
  * @return bool TRUE if form is ok
  *
  **/
 function showForm($id, $options = array())
 {
     global $CFG_GLPI;
     $new_item = false;
     if ($id > 0) {
         if ($this->getFromDB($id)) {
             $this->checkConfiguration($id);
             $this->getFromDB($id);
         } else {
             $id = 0;
             $this->getEmpty();
             $this->fields['plugin_fusioninventory_tasks_id'] = $options['task_id'];
             $new_item = true;
         }
     } else {
         if (!array_key_exists('task_id', $options)) {
             echo $this->getMessage(__('A job can not be created outside a task form'), self::MSG_ERROR);
             return;
         }
         $this->getEmpty();
         $this->fields['plugin_fusioninventory_tasks_id'] = $options['task_id'];
         $new_item = true;
     }
     $pfTask = $this->getTask();
     echo "<form method='post' name='form_taskjob' action='" . $CFG_GLPI["root_doc"] . "/plugins/fusioninventory/front/taskjob.form.php''>";
     if (!$new_item) {
         echo "<input type='hidden' name='id' value='" . $id . "' />";
     }
     echo "<input type='hidden' name='plugin_fusioninventory_tasks_id' " . "value='" . $pfTask->fields['id'] . "' />";
     echo "<table class='tab_cadre_fixe'>";
     // Optional line
     $ismultientities = Session::isMultiEntitiesMode();
     echo '<tr>';
     echo '<th colspan="4">';
     if (!$new_item) {
         echo $this->getTypeName() . " - " . __('ID') . " {$id} ";
         if ($ismultientities) {
             echo "(" . Dropdown::getDropdownName('glpi_entities', $this->fields['entities_id']) . ")";
         }
     } else {
         if ($ismultientities) {
             echo __('New action', 'fusioninventory') . "&nbsp;:&nbsp;" . Dropdown::getDropdownName("glpi_entities", $this->fields['entities_id']);
         } else {
             echo __('New action', 'fusioninventory');
         }
     }
     echo '</th>';
     echo '</tr>';
     echo "<tr class='tab_bg_1'>";
     echo "<td colspan='4'>";
     echo "<div class='fusinv_form'>";
     $this->showTextField(__('Name'), "name");
     //echo "<td>".__('Name')."&nbsp;:</td>";
     //echo "<td>";
     ////if ($pfTask->fields["is_advancedmode"] == '0'
     ////        AND $this->fields["name"] == '') {
     ////   $this->fields["name"] = $pfTask->fields["name"];
     ////}
     //Html::autocompletionTextField ($this, "name", $this->fields["name"]);
     /*
      * Display Module dropdown
      */
     //echo "</td>";
     //if ($this->fields['id'] > 0) {
     //   echo "<td>".__('Module', 'fusioninventory')."&nbsp;:</td>";
     //   echo "<td>";
     //   $randmethod = $this->dropdownMethod("method", $this->fields['method']);
     //   echo "<div style='display:none' id='methodupdate' >";
     //   $params = array('method' => '__VALUE__',
     //                   'rand'      => $randmethod,
     //                   'myname'    => 'method',
     //                   'name'      => 'methodupdate',
     //                   'taskjobs_id'=>$id );
     //   Ajax::updateItemOnEvent("dropdown_method".$randmethod,
     //                           "methodupdate",
     //                           $CFG_GLPI["root_doc"].
     //                              "/plugins/fusioninventory/ajax/taskmethodupdate.php",
     //                           $params);
     //   echo "</div>";
     //}
     //echo "</td>";
     //echo "</tr>";
     //echo "<tr class='tab_bg_1'>";
     //echo "<td>".__('Comments')."&nbsp;:</td>";
     //echo "<td>";
     //echo "<textarea cols='40' rows='2' name='comment' >".$this->fields["comment"]."</textarea>";
     //echo "</td>";
     $this->showTextArea(__('Comments'), "comment");
     $modules_methods = PluginFusioninventoryStaticmisc::getModulesMethods();
     $modules_methods_rand = $this->showDropdownFromArray(__('Module method', 'fusioninventory'), "method", $modules_methods);
     if (!$new_item) {
         echo "<script type='text/javascript'>";
         echo "   taskjobs.register_update_method( 'dropdown_method" . $modules_methods_rand . "');";
         echo "</script>";
         echo "<div style='display:none' id='method_selected'>" . $this->fields['method'] . "</div>";
     }
     //if (!$new_item) {
     //   $params = array('method' => '__VALUE__',
     //      'rand'      => $modules_methods_rand,
     //      'myname'    => 'method',
     //      'name'      => 'configuration_form',
     //      'taskjobs_id'=>$id );
     //   Ajax::updateItemOnEvent(
     //      "dropdown_method".$modules_methods_rand,
     //      "methodupdate",
     //      $CFG_GLPI["root_doc"].
     //      "/plugins/fusioninventory/ajax/taskmethodupdate.php",
     //      $params);
     //}
     //if (! $new_item) {
     //   foreach ($module_methods as $method) {
     //      echo
     //         "<input type='hidden' name='method-".$method['method']."' "
     //         ."value='".PluginFusioninventoryModule::getModuleId($method['module'])
     //         ."' />";
     //   }
     //}
     echo "</div>";
     // end of first inputs column wrapper
     // Display Definition choices
     if (!$new_item) {
         //Start second column of the form
         echo "<div class='fusinv_form'>";
         echo "<div class='input_wrap split_column tab_bg_4'>";
         echo $this->getAddItemtypeButton(__('Targets', 'fusioninventory'), 'targets', $this->fields['method']);
         //echo "<br/><span class='description' style='font-size:50%;font-style:italic'>";
         echo "<br/><span class='description'>";
         echo __('The items that should be applied for this job.', 'fusioninventory');
         echo "</span>";
         echo "</div>";
         echo "<div class='input_wrap split_column tab_bg_4'>";
         echo $this->getAddItemtypeButton(__('Actors', 'fusioninventory'), 'actors', $this->fields['method']);
         echo "<br/><span class='description'>";
         echo __('The items that should carry out those targets.', 'fusioninventory');
         echo "</span>";
         echo "</div>";
         echo "<div id='taskjob_moduletypes_dropdown' />";
         echo "<div id='taskjob_moduleitems_dropdown' />";
         echo "</div>";
     }
     $targets_display_list = $this->getItemsList('targets');
     // Display targets and actors lists
     echo implode("\n", array("<hr/>", "<div>", "  <div class='taskjob_list_header'>", "     <label>" . __('Targets', 'fusioninventory') . "&nbsp;:</label>", "  </div>", "  <div id='taskjob_targets_list'>", $targets_display_list, "  </div>", "  <div>", "     <a href='javascript:void(0)'", "        onclick='taskjobs.clear_list(\"targets\")'", "        >" . __('Clear list', 'fusioninventory') . "</a>", "        /", "     <a href='javascript:void(0)'", "        onclick='taskjobs.delete_items_selected(\"targets\")'", "        >" . __('Delete selected items', 'fusioninventory') . "</a>", "  </div>", "</div>"));
     $actors_display_list = $this->getItemsList('actors');
     echo implode("\n", array("<hr/>", "<div>", "  <div class='taskjob_list_header'>", "     <label>" . __('Actors', 'fusioninventory') . "&nbsp;:</label>", "  </div>", "  <div id='taskjob_actors_list'>", $actors_display_list, "  </div>", "  <div>", "     <a href='javascript:void(0)'", "        onclick='taskjobs.clear_list(\"actors\")'", "        >" . __('Clear list', 'fusioninventory') . "</a>", "        /", "     <a href='javascript:void(0)'", "        onclick='taskjobs.delete_items_selected(\"actors\")'", "        >" . __('Delete selected items', 'fusioninventory') . "</a>", "  </div>", "</div>"));
     /*
      * Advanced mode related display (should be dropped)
      */
     //echo "<tr class='tab_bg_1'>";
     //$rowspan = 4;
     //if ($pfTask->fields["is_advancedmode"] == '1') {
     //   echo "<td>";
     //   echo __('Time between task start and start this action', 'fusioninventory')."&nbsp;:";
     //   echo "</td>";
     //   echo "<td>";
     //   Dropdown::showNumber("periodicity_count", array(
     //          'value' => $this->fields['periodicity_count'],
     //          'min'   => 0,
     //          'max'   => 300)
     //   );
     //   $a_time = array();
     //   $a_time[] = "------";
     //   $a_time['minutes'] = strtolower(__('Minute(s)', 'fusioninventory'));
     //   $a_time['hours'] = strtolower(__('hour(s)', 'fusioninventory'));
     //   $a_time['days'] = __('day(s)', 'fusioninventory');
     //   $a_time['months'] = __('months');
     //   Dropdown::showFromArray("periodicity_type",
     //                           $a_time,
     //                           array('value'=>$this->fields['periodicity_type']));
     //   echo "</td>";
     //} else {
     //   if ($this->fields['id'] > 0) {
     //      $pfTaskjoblog->displayShortLogs($this->fields['id']);
     //   } else {
     //      echo "<td colspan='2'></td>";
     //   }
     //   $rowspan = 1;
     //}
     if (!$new_item) {
         // ** Definitions
         //echo "<td rowspan='".$rowspan."' valign='top'>";
         //$this->showTaskjobItems('definition', $modules_methods_rand, $id);
         //echo "</td>";
         // ** Actions
         //echo "<td rowspan='".$rowspan."' valign='top'>";
         //$this->showTaskjobItems('action', $modules_methods_rand, $id);
         //echo "</td>";
         //echo "</tr>";
     }
     //if ($pfTask->fields["is_advancedmode"] == '1') {
     //   echo "<tr class='tab_bg_1'>";
     //   echo "<td>".__('Number of trials', 'fusioninventory')."&nbsp;:</td>";
     //   echo "<td>";
     //   Dropdown::showNumber("retry_nb", array(
     //          'value' => $this->fields['retry_nb'],
     //          'min'   => 0,
     //          'max'   => 30)
     //   );
     //   echo "</td>";
     //   echo "</tr>";
     //   echo "<tr class='tab_bg_1'>";
     //   echo "<td>".__('Time between 2 trials (in minutes)', 'fusioninventory')."&nbsp;:</td>";
     //   echo "<td>";
     //   Dropdown::showNumber("retry_time", array(
     //          'value' => $this->fields['retry_time'],
     //          'min'   => 0,
     //          'max'   => 360)
     // );
     //   echo "</td>";
     //   echo "</tr>";
     //   echo "<tr>";
     //   echo "<td colspan='2'></td>";
     //   echo "</tr>";
     //}
     if ($new_item) {
         echo "<tr>";
         echo "<td colspan='4' valign='top' align='center'>";
         echo "<input type='submit' name='add' value=\"" . __('Add') . "\" class='submit'>";
         echo "</td>";
         echo '</tr>';
     } else {
         echo "<tr>";
         echo "<td class='center'>";
         echo "<input type='submit' name='update' value=\"" . __('Update') . "\" class='submit'>";
         echo "</td>";
         echo implode("\n", array("<td class='center' colspan='2'>", "<div id='cancel_job_changes_button' style='display:none'>", "<input type='button' class='submit'", "     onclick='taskjobs.edit(", "        \"" . $this->getBaseUrlFor('fi.job.edit') . "\", ", "        {$id}", "     )'", " value=\"" . __('Cancel modifications', 'fusioninventory') . "\"/>", "</div>", "</td>"));
         echo "<td class='center'>";
         echo "<input type='submit' name='delete' value=\"" . __('Purge', 'fusioninventory') . "\"\n                         class='submit' " . Html::addConfirmationOnAction(__('Confirm the final deletion ?', 'fusioninventory')) . ">";
         echo "</td>";
         echo '</tr>';
     }
     echo "</table>";
     Html::closeForm();
     echo implode("\n", array("<script type='text/javascript'>", "  taskjobs.register_form_changed();", "</script>"));
     echo implode("\n", array("<script language='javascript'>", "  function expandtaskjobform() {", "     document.getElementById('taskjobdisplay').style.overflow='visible';", "     document.getElementById('taskjobdisplay').style.height='auto';", "     document.getElementById('seemore').style.display = 'none';", "  }", "</script>"));
     echo "<br/>";
     //$pfTaskjoblog = new PluginFusioninventoryTaskjoblog();
     //$pfTaskjoblog->showHistory($id);
     return TRUE;
 }
 static function getForItemtype($itemtype)
 {
     $itemtypes = array();
     foreach (PluginFusioninventoryModule::getAll() as $data) {
         $class = PluginFusioninventoryStaticmisc::getStaticmiscClass($data['directory']);
         if (is_callable(array($class, 'credential_types'))) {
             foreach (call_user_func(array($class, 'credential_types')) as $credential) {
                 if (in_array($itemtype, $credential['targets'])) {
                     $itemtypes[$credential['itemtype']] = $credential['name'];
                 }
             }
         }
     }
     return $itemtypes;
 }
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 "";
}
 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>";
 }
 /**
  * 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);
         }
     }
 }
 static function task_definitionselection_PluginFusioninventoryIPRange_networkinventory($title)
 {
     $rand = PluginFusioninventoryStaticmisc::task_definitionselection_PluginFusioninventoryIPRange_networkdiscovery($title);
     return $rand;
 }
 /**
  * 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);
             }
         }
     }
 }