/** * @param $itemtype **/ function plugin_ocsinventoryng_getAddSearchOptions($itemtype) { $sopt = array(); if ($itemtype == 'Computer') { if (plugin_ocsinventoryng_haveRight("ocsng", "r")) { $sopt[10002]['table'] = 'glpi_plugin_ocsinventoryng_ocslinks'; $sopt[10002]['field'] = 'last_update'; $sopt[10002]['name'] = __('GLPI import date', 'ocsinventoryng'); $sopt[10002]['datatype'] = 'datetime'; $sopt[10002]['massiveaction'] = false; $sopt[10002]['joinparams'] = array('jointype' => 'child'); $sopt[10003]['table'] = 'glpi_plugin_ocsinventoryng_ocslinks'; $sopt[10003]['field'] = 'last_ocs_update'; $sopt[10003]['name'] = __('Last OCSNG inventory date', 'ocsinventoryng'); $sopt[10003]['datatype'] = 'datetime'; $sopt[10003]['massiveaction'] = false; $sopt[10003]['joinparams'] = array('jointype' => 'child'); $sopt[10001]['table'] = 'glpi_plugin_ocsinventoryng_ocslinks'; $sopt[10001]['field'] = 'use_auto_update'; $sopt[10001]['linkfield'] = '_auto_update_ocs'; // update through compter update process $sopt[10001]['name'] = __('Automatic update OCSNG', 'ocsinventoryng'); $sopt[10001]['datatype'] = 'bool'; $sopt[10001]['joinparams'] = array('jointype' => 'child'); $sopt[10004]['table'] = 'glpi_plugin_ocsinventoryng_ocslinks'; $sopt[10004]['field'] = 'ocs_agent_version'; $sopt[10004]['name'] = __('Inventory agent', 'ocsinventoryng'); $sopt[10004]['massiveaction'] = false; $sopt[10004]['joinparams'] = array('jointype' => 'child'); $sopt[10005]['table'] = 'glpi_plugin_ocsinventoryng_ocslinks'; $sopt[10005]['field'] = 'tag'; $sopt[10005]['name'] = __('OCSNG TAG', 'ocsinventoryng'); $sopt[10005]['datatype'] = 'string'; $sopt[10005]['massiveaction'] = false; $sopt[10005]['joinparams'] = array('jointype' => 'child'); $sopt[10006]['table'] = 'glpi_plugin_ocsinventoryng_ocslinks'; $sopt[10006]['field'] = 'ocsid'; $sopt[10006]['name'] = __('OCSNG ID', 'ocsinventoryng'); $sopt[10006]['datatype'] = 'number'; $sopt[10006]['massiveaction'] = false; $sopt[10006]['joinparams'] = array('jointype' => 'child'); //$sopt['registry'] = __('Registry', 'ocsinventoryng'); $sopt[10010]['table'] = 'glpi_plugin_ocsinventoryng_registrykeys'; $sopt[10010]['field'] = 'value'; $sopt[10010]['name'] = sprintf(__('%1$s: %2$s'), __('Registry', 'ocsinventoryng'), __('Key/Value', 'ocsinventoryng')); $sopt[10010]['forcegroupby'] = true; $sopt[10010]['massiveaction'] = false; $sopt[10010]['joinparams'] = array('jointype' => 'child'); $sopt[10011]['table'] = 'glpi_plugin_ocsinventoryng_registrykeys'; $sopt[10011]['field'] = 'ocs_name'; $sopt[10011]['name'] = sprintf(__('%1$s: %2$s'), __('Registry', 'ocsinventoryng'), __('OCSNG name', 'ocsinventoryng')); $sopt[10011]['forcegroupby'] = true; $sopt[10011]['massiveaction'] = false; $sopt[10011]['joinparams'] = array('jointype' => 'child'); } } return $sopt; }
/** * Display a list of computers to add or to link * * @param plugin_ocsinventoryng_ocsservers_id the ID of the ocs server * @param advanced display detail about the computer import or not (target entity, matched rules, etc.) * @param check indicates if checkboxes are checked or not * @param start display a list of computers starting at rowX * @param entity a list of entities in which computers can be added or linked * @param tolinked false for an import, true for a link * * @return nothing **/ static function showComputersToAdd($plugin_ocsinventoryng_ocsservers_id, $advanced, $check, $start, $entity = 0, $tolinked = false) { global $DB, $PluginOcsinventoryngDBocs, $CFG_GLPI; if (!plugin_ocsinventoryng_haveRight("ocsng", "w")) { return false; } $target = $CFG_GLPI['root_doc'] . '/plugins/ocsinventoryng/front/ocsng.import.php'; if ($tolinked) { $target = $CFG_GLPI['root_doc'] . '/plugins/ocsinventoryng/front/ocsng.link.php'; } $cfg_ocs = self::getConfig($plugin_ocsinventoryng_ocsservers_id); $WHERE = self::getTagLimit($cfg_ocs); $query_ocs = "SELECT `hardware`.*,\n `accountinfo`.`TAG` AS TAG,\n `bios`.`SSN` AS SERIAL,\n `bios`.`SMODEL`,\n `bios`.`SMANUFACTURER`\n FROM `hardware`\n INNER JOIN `accountinfo` ON (`hardware`.`id` = `accountinfo`.`HARDWARE_ID`)\n INNER JOIN `bios` ON (`hardware`.`id` = `bios`.`HARDWARE_ID`)" . (!empty($WHERE) ? "WHERE {$WHERE}" : "") . "\n ORDER BY `hardware`.`NAME`"; $result_ocs = $PluginOcsinventoryngDBocs->query($query_ocs); // Existing OCS - GLPI link $query_glpi = "SELECT*\n FROM `glpi_plugin_ocsinventoryng_ocslinks`\n WHERE `plugin_ocsinventoryng_ocsservers_id`\n = '{$plugin_ocsinventoryng_ocsservers_id}'"; $result_glpi = $DB->query($query_glpi); if ($PluginOcsinventoryngDBocs->numrows($result_ocs) > 0) { // Get all hardware from OCS DB $hardware = array(); while ($data = $PluginOcsinventoryngDBocs->fetch_array($result_ocs)) { $data = Toolbox::clean_cross_side_scripting_deep(Toolbox::addslashes_deep($data)); $hardware[$data["ID"]]["date"] = $data["LASTDATE"]; $hardware[$data["ID"]]["name"] = $data["NAME"]; $hardware[$data["ID"]]["TAG"] = $data["TAG"]; $hardware[$data["ID"]]["id"] = $data["ID"]; $hardware[$data["ID"]]["serial"] = $data["SERIAL"]; $hardware[$data["ID"]]["model"] = $data["SMODEL"]; $hardware[$data["ID"]]["manufacturer"] = $data["SMANUFACTURER"]; $query_network = "SELECT*\n FROM `networks`\n WHERE `HARDWARE_ID` = '" . $data["ID"] . "'"; //Get network informations for this computer //Ignore informations that contains "??" foreach ($PluginOcsinventoryngDBocs->request($query_network) as $network) { if (isset($network['IPADDRESS']) && $network['IPADDRESS'] != '??') { $hardware[$data["ID"]]['IPADDRESS'][] = $network['IPADDRESS']; } if (isset($network['IPSUBNET']) && $network['IPSUBNET'] != '??') { $hardware[$data["ID"]]['IPSUBNET'][] = $network['IPSUBNET']; } if (isset($network['MACADDRESS']) && $network['MACADDR'] != '??') { $hardware[$data["ID"]]['MACADDRESS'][] = $network['MACADDR']; } } } // Get all links between glpi and OCS $already_linked = array(); if ($DB->numrows($result_glpi) > 0) { while ($data = $PluginOcsinventoryngDBocs->fetch_array($result_glpi)) { $already_linked[$data["ocsid"]] = $data["last_update"]; } } // Clean $hardware from already linked element if (count($already_linked) > 0) { foreach ($already_linked as $ID => $date) { if (isset($hardware[$ID]) && isset($already_linked[$ID])) { unset($hardware[$ID]); } } } if ($tolinked && count($hardware)) { echo "<div class='center b'>" . __('Caution! The imported data (see your configuration) will overwrite the existing one', 'ocsinventoryng') . "</div>"; } echo "<div class='center'>"; if (($numrows = count($hardware)) > 0) { $parameters = "check={$check}"; Html::printPager($start, $numrows, $target, $parameters); // delete end array_splice($hardware, $start + $_SESSION['glpilist_limit']); // delete begin if ($start > 0) { array_splice($hardware, 0, $start); } //Show preview form only in import even in multi-entity mode because computer import //can be refused by a rule if (!$tolinked) { echo "<div class='firstbloc'>"; echo "<form method='post' name='ocsng_import_mode' id='ocsng_import_mode'\n action='{$target}'>\n"; echo "<table class='tab_cadre_fixe'>"; echo "<tr><th>" . __('Manual import mode', 'ocsinventoryng') . "</th></tr>\n"; echo "<tr class='tab_bg_1'><td class='center'>"; if ($advanced) { Html::showSimpleForm($target, 'change_import_mode', __('Disable preview', 'ocsinventoryng'), array('id' => 'false')); } else { Html::showSimpleForm($target, 'change_import_mode', __('Enable preview', 'ocsinventoryng'), array('id' => 'true')); } echo "</td></tr>"; echo "<tr class='tab_bg_1'><td class='center b'>" . __('Check first that duplicates have been correctly managed in OCSNG', 'ocsinventoryng') . "</td>"; echo "</tr></table>"; Html::closeForm(); echo "</div>"; } echo "<form method='post' name='ocsng_form' id='ocsng_form' action='{$target}'>"; if (!$tolinked) { self::checkBox($target); } echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'><td colspan='" . ($advanced || $tolinked ? 10 : 7) . "' class='center'>"; echo "<input class='submit' type='submit' name='import_ok' value=\"" . _sx('button', 'Import', 'ocsinventoryng') . "\">"; echo "</td></tr>\n"; echo "<tr><th>" . __('Name') . "</th>\n"; echo "<th>" . __('Manufacturer') . "</th>\n"; echo "<th>" . __('Model') . "</th>\n"; echo "<th>" . __('Serial number') . "</th>\n"; echo "<th>" . __('Date') . "</th>\n"; echo "<th>" . __('OCSNG TAG', 'ocsinventoryng') . "</th>\n"; if ($advanced && !$tolinked) { echo "<th>" . __('Match the rule ?', 'ocsinventoryng') . "</th>\n"; echo "<th>" . __('Destination entity') . "</th>\n"; echo "<th>" . __('Target location', 'ocsinventoryng') . "</th>\n"; } echo "<th> </th></tr>\n"; $rule = new RuleImportEntityCollection(); foreach ($hardware as $ID => $tab) { $comp = new Computer(); $comp->fields["id"] = $tab["id"]; $data = array(); if ($advanced && !$tolinked) { $data = $rule->processAllRules(array('ocsservers_id' => $plugin_ocsinventoryng_ocsservers_id, '_source' => 'ocsinventoryng'), array(), array('ocsid' => $tab["id"])); } echo "<tr class='tab_bg_2'><td>" . $tab["name"] . "</td>\n"; echo "<td>" . $tab["manufacturer"] . "</td><td>" . $tab["model"] . "</td>"; echo "<td>" . $tab["serial"] . "</td>\n"; echo "<td>" . Html::convDateTime($tab["date"]) . "</td>\n"; echo "<td>" . $tab["TAG"] . "</td>\n"; if ($advanced && !$tolinked) { if (!isset($data['entities_id']) || $data['entities_id'] == -1) { echo "<td class='center'><img src=\"" . $CFG_GLPI['root_doc'] . "/pics/redbutton.png\"></td>\n"; $data['entities_id'] = -1; } else { echo "<td class='center'>"; $tmprule = new RuleImportEntity(); if ($tmprule->can($data['_ruleid'], 'r')) { echo "<a href='" . $tmprule->getLinkURL() . "'>" . $tmprule->getName() . "</a>"; } else { echo $tmprule->getName(); } echo "</td>\n"; } echo "<td>"; Entity::dropdown(array('name' => "toimport_entities[" . $tab["id"] . "]=" . $data['entities_id'], 'value' => $data['entities_id'], 'comments' => 0)); echo "</td>\n"; echo "<td>"; if (!isset($data['locations_id'])) { $data['locations_id'] = 0; } Location::dropdown(array('name' => "toimport_locations[" . $tab["id"] . "]=" . $data['locations_id'], 'value' => $data['locations_id'], 'comments' => 0)); echo "</td>\n"; } echo "<td>"; if (!$tolinked) { echo "<input type='checkbox' name='toimport[" . $tab["id"] . "]' " . ($check == "all" ? "checked" : "") . ">"; } else { $rulelink = new RuleImportComputerCollection(); $rulelink_results = array(); $params = array('entities_id' => $entity, 'plugin_ocsinventoryng_ocsservers_id' => $plugin_ocsinventoryng_ocsservers_id); $rulelink_results = $rulelink->processAllRules(Toolbox::stripslashes_deep($tab), array(), $params); //Look for the computer using automatic link criterias as defined in OCSNG configuration $options = array('name' => "tolink[" . $tab["id"] . "]"); $show_dropdown = true; //If the computer is not explicitly refused by a rule if (!isset($rulelink_results['action']) || $rulelink_results['action'] != self::LINK_RESULT_NO_IMPORT) { if (!empty($rulelink_results['found_computers'])) { $options['value'] = $rulelink_results['found_computers'][0]; $options['entity'] = $entity; } Computer::dropdown($options); } else { echo "<img src='" . $CFG_GLPI['root_doc'] . "/pics/redbutton.png'>"; } } echo "</td></tr>\n"; } echo "<tr class='tab_bg_1'><td colspan='" . ($advanced || $tolinked ? 10 : 7) . "' class='center'>"; echo "<input class='submit' type='submit' name='import_ok' value=\"" . _sx('button', 'Import', 'ocsinventoryng') . "\">\n"; echo "<input type=hidden name='plugin_ocsinventoryng_ocsservers_id' " . "value='{$plugin_ocsinventoryng_ocsservers_id}'>"; echo "</td></tr>"; echo "</table>\n"; Html::closeForm(); if (!$tolinked) { self::checkBox($target); } Html::printPager($start, $numrows, $target, $parameters); } else { echo "<table class='tab_cadre_fixe'>"; echo "<tr><th>" . __('Import new computers') . "</th></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td class='center b'>" . __('No new computer to be imported', 'ocsinventoryng') . "</td></tr>\n"; echo "</table>"; } echo "</div>"; } else { echo "<div class='center'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr><th>" . __('Import new computers', 'ocsinventoryng') . "</th></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td class='center b'>" . __('No new computer to be imported', 'ocsinventoryng') . "</td></tr>\n"; echo "</table></div>"; } }
static function canCreate() { return plugin_ocsinventoryng_haveRight("ocsng", "w"); }
LICENSE This file is part of ocsinventoryng. Ocsinventoryng plugin is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. Ocsinventoryng plugin is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with ocsinventoryng. If not, see <http://www.gnu.org/licenses/>. ---------------------------------------------------------------------------------------------------------------------------------------------------- */ include '../../../inc/includes.php'; $plugin = new Plugin(); if ($plugin->isActivated("ocsinventoryng") && plugin_ocsinventoryng_haveRight("ocsng", "w")) { Html::header('OCSInventory NG', "", "plugins", "ocsinventoryng"); // choose config server or config synchro PluginOcsinventoryngConfig::showMenu(); } else { Html::header(__('Setup'), '', "config", "plugins"); echo "<div class='center'><br><br>"; echo "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/warning.png\" alt='" . __s('Warning') . "'><br><br>"; echo "<b>" . __('Please activate the plugin', 'ocsinventoryng') . "</b></div>"; } Html::footer();
/** * Get an history entry message * * @param $data Array from glpi_logs table * * @return string **/ static function getHistoryEntry($data) { if (plugin_ocsinventoryng_haveRight('ocsng', 'r')) { switch ($data['linked_action'] - Log::HISTORY_PLUGIN) { case self::HISTORY_OCS_IMPORT: return sprintf(__('%1$s: %2$s'), __('Imported from OCSNG', 'ocsinventoryng'), $data['new_value']); case self::HISTORY_OCS_DELETE: return sprintf(__('%1$s: %2$s'), __('Deleted in OCSNG', 'ocsinventoryng'), $data['old_value']); case self::HISTORY_OCS_LINK: return sprintf(__('%1$s: %2$s'), __('Linked with an OCSNG computer', 'ocsinventoryng'), $data['new_value']); case self::HISTORY_OCS_IDCHANGED: return sprintf(__('The OCSNG ID of the computer changed from %1$s to %2$s', 'ocsinventoryng'), $data['old_value'], $data['new_value']); case self::HISTORY_OCS_TAGCHANGED: return sprintf(__('The OCSNG TAG of the computer changed from %1$s to %2$s', 'ocsinventoryng'), $data['old_value'], $data['new_value']); } } return ''; }
static function displayAlerts() { global $DB; $CronTask = new CronTask(); $config = new PluginAdditionalalertsConfig(); $config->getFromDB('1'); $infocom = new PluginAdditionalalertsInfocomAlert(); $infocom->getFromDBbyEntity($_SESSION["glpiactive_entity"]); if (isset($infocom->fields["use_infocom_alert"]) && $infocom->fields["use_infocom_alert"] > 0) { $use_infocom_alert = $infocom->fields["use_infocom_alert"]; } else { $use_infocom_alert = $config->fields["use_infocom_alert"]; } $ocsalert = new PluginAdditionalalertsOcsAlert(); $ocsalert->getFromDBbyEntity($_SESSION["glpiactive_entity"]); if (isset($ocsalert->fields["use_newocs_alert"]) && $ocsalert->fields["use_newocs_alert"] > 0) { $use_newocs_alert = $ocsalert->fields["use_newocs_alert"]; } else { $use_newocs_alert = $config->fields["use_newocs_alert"]; } if (isset($ocsalert->fields["delay_ocs"]) && $ocsalert->fields["delay_ocs"] > 0) { $delay_ocs = $ocsalert->fields["delay_ocs"]; } else { $delay_ocs = $config->fields["delay_ocs"]; } $additionalalerts_ocs = 0; if ($CronTask->getFromDBbyName("PluginAdditionalalertsOcsAlert", "AdditionalalertsOcs")) { if ($CronTask->fields["state"] != CronTask::STATE_DISABLE && $delay_ocs > 0) { $additionalalerts_ocs = 1; } } $additionalalerts_new_ocs = 0; if ($CronTask->getFromDBbyName("PluginAdditionalalertsOcsAlert", "AdditionalalertsNewOcs")) { if ($CronTask->fields["state"] != CronTask::STATE_DISABLE && $use_newocs_alert > 0) { $additionalalerts_new_ocs = 1; } } $additionalalerts_not_infocom = 0; if ($CronTask->getFromDBbyName("PluginAdditionalalertsInfocomAlert", "AdditionalalertsNotInfocom")) { if ($CronTask->fields["state"] != CronTask::STATE_DISABLE && $use_infocom_alert > 0) { $additionalalerts_not_infocom = 1; } } if ($additionalalerts_ocs == 0 && $additionalalerts_new_ocs == 0 && $additionalalerts_not_infocom == 0) { echo "<div align='center'><b>" . __('No used alerts', 'additionalalerts') . "</b></div>"; } if ($additionalalerts_not_infocom != 0) { if (Session::haveRight("infocom", "w")) { $query = PluginAdditionalalertsInfocomAlert::query($_SESSION["glpiactive_entity"]); $result = $DB->query($query); if ($DB->numrows($result) > 0) { if (Session::isMultiEntitiesMode()) { $nbcol = 7; } else { $nbcol = 6; } echo "<div align='center'><table class='tab_cadre' cellspacing='2' cellpadding='3'><tr><th colspan='{$nbcol}'>"; echo PluginAdditionalalertsInfocomAlert::getTypeName(2) . "</th></tr>"; echo "<tr><th>" . __('Name') . "</th>"; if (Session::isMultiEntitiesMode()) { echo "<th>" . __('Entity') . "</th>"; } echo "<th>" . __('Type') . "</th>"; echo "<th>" . __('Operating system') . "</th>"; echo "<th>" . __('Status') . "</th>"; echo "<th>" . __('Location') . "</th>"; echo "<th>" . __('User') . " / " . __('Group') . " / " . __('Alternate username') . "</th></tr>"; while ($data = $DB->fetch_array($result)) { echo PluginAdditionalalertsInfocomAlert::displayBody($data); } echo "</table></div>"; } else { echo "<br><div align='center'><b>" . __('No computers with no buy date', 'additionalalerts') . "</b></div>"; } echo "<br>"; } } if ($additionalalerts_new_ocs != 0) { $plugin = new Plugin(); if ($plugin->isActivated("ocsinventoryng") && plugin_ocsinventoryng_haveRight("ocsng", "w")) { foreach ($DB->request("glpi_plugin_ocsinventoryng_ocsservers", "`is_active` = 1") as $config) { $query = PluginAdditionalalertsOcsAlert::queryNew($config, $_SESSION["glpiactive_entity"]); $result = $DB->query($query); if ($DB->numrows($result) > 0) { if (Session::isMultiEntitiesMode()) { $nbcol = 9; } else { $nbcol = 8; } echo "<div align='center'><table class='tab_cadre' cellspacing='2' cellpadding='3'><tr><th colspan='{$nbcol}'>"; echo __('New imported computers from OCS-NG', 'additionalalerts') . "</th></tr>"; echo "<tr><th>" . __('Name') . "</th>"; if (Session::isMultiEntitiesMode()) { echo "<th>" . __('Entity') . "</th>"; } echo "<th>" . __('Operating system') . "</th>"; echo "<th>" . __('Status') . "</th>"; echo "<th>" . __('Location') . "</th>"; echo "<th>" . __('User') . " / " . __('Group') . " / " . __('Alternate username') . "</th>"; echo "<th>" . __('Last OCSNG inventory date', 'additionalalerts') . "</th>"; echo "<th>" . __('Import date in GLPI', 'additionalalerts') . "</th>"; echo "<th>" . __('OCSNG server', 'additionalalerts') . "</th></tr>"; while ($data = $DB->fetch_array($result)) { echo PluginAdditionalalertsOcsAlert::displayBody($data); } echo "</table></div>"; } else { echo "<br><div align='center'><b>" . __('No new imported computer from OCS-NG', 'additionalalerts') . "</b></div>"; } } echo "<br>"; } } if ($additionalalerts_ocs != 0) { $plugin = new Plugin(); if ($plugin->isActivated("ocsinventoryng") && plugin_ocsinventoryng_haveRight("ocsng", "w")) { foreach ($DB->request("glpi_plugin_ocsinventoryng_ocsservers", "`is_active` = 1") as $config) { $query = PluginAdditionalalertsOcsAlert::query($delay_ocs, $config, $_SESSION["glpiactive_entity"]); $result = $DB->query($query); if ($DB->numrows($result) > 0) { if (Session::isMultiEntitiesMode()) { $nbcol = 9; } else { $nbcol = 8; } echo "<div align='center'><table class='tab_cadre' cellspacing='2' cellpadding='3'><tr><th colspan='{$nbcol}'>"; echo __('Computers not synchronized with OCS-NG since more', 'additionalalerts') . " " . $delay_ocs . " " . _n('Day', 'Days', 2) . "</th></tr>"; echo "<tr><th>" . __('Name') . "</th>"; if (Session::isMultiEntitiesMode()) { echo "<th>" . __('Entity') . "</th>"; } echo "<th>" . __('Operating system') . "</th>"; echo "<th>" . __('Status') . "</th>"; echo "<th>" . __('Location') . "</th>"; echo "<th>" . __('User') . " / " . __('Group') . " / " . __('Alternate username') . "</th>"; echo "<th>" . __('Last OCSNG inventory date', 'additionalalerts') . "</th>"; echo "<th>" . __('Import date in GLPI', 'additionalalerts') . "</th>"; echo "<th>" . __('OCSNG server', 'additionalalerts') . "</th></tr>"; while ($data = $DB->fetch_array($result)) { echo PluginAdditionalalertsOcsAlert::displayBody($data); } echo "</table></div>"; } else { echo "<br><div align='center'><b>" . __('No computer not synchronized since more', 'additionalalerts') . " " . $delay_ocs . " " . _n('Day', 'Days', 2) . "</b></div>"; } } echo "<br>"; } } }
/** * @param $target **/ function showProcesses($target) { global $DB, $CFG_GLPI; $canedit = plugin_ocsinventoryng_haveRight("ocsng", "w"); $config = new PluginOcsinventoryngConfig(); $config->getFromDB(1); $minfreq = 9999; $task = new CronTask(); if ($task->getFromDBbyName('PluginOcsinventoryngThread', 'CleanOldThreads')) { //First of all, deleted old processes $this->deleteOldProcesses($task->fields['param']); if ($task->fields['param'] > 0) { $minfreq = $task->fields['param']; } } $imported_number = new PluginOcsinventoryngMiniStat(); $synchronized_number = new PluginOcsinventoryngMiniStat(); $linked_number = new PluginOcsinventoryngMiniStat(); $failed_number = new PluginOcsinventoryngMiniStat(); $notupdated_number = new PluginOcsinventoryngMiniStat(); $notunique_number = new PluginOcsinventoryngMiniStat(); $linkedrefused_number = new PluginOcsinventoryngMiniStat(); $process_time = new PluginOcsinventoryngMiniStat(); $sql = "SELECT `id`, `processid`, SUM(`total_number_machines`) AS total_machines,\n `plugin_ocsinventoryng_ocsservers_id`, `status`, COUNT(*) AS threads_number,\n MIN(`start_time`) AS starting_date, MAX(`end_time`) AS ending_date,\n TIME_TO_SEC(MAX(`end_time`)) - TIME_TO_SEC(MIN(`start_time`)) AS duree,\n SUM(`imported_machines_number`) AS imported_machines,\n SUM(`synchronized_machines_number`) AS synchronized_machines,\n SUM(`linked_machines_number`) AS linked_machines,\n SUM(`failed_rules_machines_number`) AS failed_rules_machines,\n SUM(`notupdated_machines_number`) AS notupdated_machines,\n SUM(`not_unique_machines_number`) AS not_unique_machines_number,\n SUM(`link_refused_machines_number`) AS link_refused_machines_number,\n `end_time` >= DATE_ADD(NOW(), INTERVAL - " . $minfreq . " HOUR) AS DoStat\n FROM `" . $this->getTable() . "`\n GROUP BY `processid`\n ORDER BY `id` DESC"; $result = $DB->query($sql); echo "<div class='center'>"; echo "<form name='processes' id='processes' action='{$target}' method='post'>"; echo "<table class='tab_cadrehov'>"; echo "<tr><th colspan='16'>" . __('Processes execution of automatic actions', 'ocsinventoryng') . "</th></tr>"; echo "<tr>"; echo "<th> </th>"; echo "<th> </th>"; echo "<th>" . __('Status') . "</th>"; echo "<th>" . __('Number of threads', 'ocsinventoryng') . "</th>"; echo "<th>" . __('Beginning date of execution', 'ocsinventoryng') . "</th>"; echo "<th>" . __('Ending date of execution', 'ocsinventoryng') . "</th>"; echo "<th>" . __('Computers imported by automatic actions', 'ocsinventoryng') . "</th>"; echo "<th>" . __('Computers synchronized', 'ocsinventoryng') . "</th>"; echo "<th>" . __('Computers linked', 'ocsinventoryng') . "</th>"; echo "<th>" . __('Computers not imported by automatic actions', 'ocsinventoryng') . "</th>"; echo "<th>" . __('Computers not updated', 'ocsinventoryng') . "</th>"; echo "<th>" . __('Computers not unique', 'ocsinventoryng') . "</th>"; echo "<th>" . __('Computers refused', 'ocsinventoryng') . "</th>"; echo "<th>" . __('Process time execution', 'ocsinventoryng') . "</th>"; echo "<th>" . __('Server') . "</th>"; echo "<th> </th>"; echo "</th></tr>\n"; if ($DB->numrows($result)) { while ($thread = $DB->fetch_array($result)) { if ($config->fields["is_displayempty"] || $thread["status"] != PLUGIN_OCSINVENTORYNG_STATE_FINISHED || !$config->fields["is_displayempty"] && $thread["total_machines"] > 0 && $thread["status"] == PLUGIN_OCSINVENTORYNG_STATE_FINISHED) { if ($thread["DoStat"] && $thread["status"] == PLUGIN_OCSINVENTORYNG_STATE_FINISHED) { $imported_number->AddValue($thread["imported_machines"]); $synchronized_number->AddValue($thread["synchronized_machines"]); $linked_number->AddValue($thread["linked_machines"]); $failed_number->AddValue($thread["failed_rules_machines"]); $notupdated_number->AddValue($thread["notupdated_machines"]); $notunique_number->AddValue($thread["not_unique_machines_number"]); $linkedrefused_number->AddValue($thread["link_refused_machines_number"]); $process_time->AddValue($thread["duree"]); } else { if ($imported_number->GetCount() > 0) { $this->showshowStat($minfreq, $imported_number, $synchronized_number, $linked_number, $failed_number, $notupdated_number, $notunique_number, $linkedrefused_number, $process_time); $imported_number->Reset(); } } echo "<tr class='tab_bg_1'>"; echo "<td width='10'>"; if ($canedit) { echo "<input type='checkbox' name='item[" . $thread["processid"] . "]' value='1'>"; } else { echo " "; } echo "</td>"; echo "<td class='center'>"; echo "<a href=\"./thread.form.php?pid=" . $thread["processid"] . "\">" . $thread["processid"] . "</a></td>"; echo "<td class='center'>"; $this->displayProcessStatusIcon($this->getProcessStatus($thread["processid"])); echo "</td>"; echo "<td class='center'>" . $thread["threads_number"] . "</td>"; echo "<td class='center'>" . Html::convDateTime($thread["starting_date"]) . "</td>"; echo "<td class='center'>" . Html::convDateTime($thread["ending_date"]) . "</td>"; echo "<td class='center'>" . $thread["imported_machines"] . "</td>"; echo "<td class='center'>" . $thread["synchronized_machines"] . "</td>"; echo "<td class='center'>" . $thread["linked_machines"] . "</td>"; echo "<td class='center'>" . $thread["failed_rules_machines"] . "</td>"; echo "<td class='center'>" . $thread["notupdated_machines"] . "</td>"; echo "<td class='center'>" . $thread["not_unique_machines_number"] . "</td>"; echo "<td class='center'>" . $thread["link_refused_machines_number"] . "</td>"; echo "<td class='center'>"; if ($thread["status"] == PLUGIN_OCSINVENTORYNG_STATE_FINISHED) { echo Html::timestampToString($thread["duree"]); } else { echo Dropdown::EMPTY_VALUE; } echo "</td>"; echo "<td class='center'>"; if ($thread["plugin_ocsinventoryng_ocsservers_id"] != -1) { $ocsConfig = PluginOcsinventoryngOcsServer::getConfig($thread["plugin_ocsinventoryng_ocsservers_id"]); echo "<a href=\"ocsserver.form.php?id=" . $ocsConfig["id"] . "\">" . $ocsConfig["name"] . "</a>"; } else { _e('All servers', 'ocsinventoryng'); } echo "</td>"; echo "<td class='center'>"; echo "<a href=\"detail.php?reset=reset_before&field[0]=" . "5&contains[0]=^" . $thread["processid"] . '$">' . "<img src='" . $CFG_GLPI["root_doc"] . "/pics/rdv.png'</a></td>"; echo "</tr>\n"; } } } if ($imported_number->GetCount() > 0) { $this->showshowStat($minfreq, $imported_number, $synchronized_number, $linked_number, $failed_number, $notupdated_number, $notunique_number, $linkedrefused_number, $process_time); } echo "</table>"; if ($canedit) { Html::openArrowMassives("processes"); Html::closeArrowMassives(array("delete_processes" => _x('button', 'Delete permanently'))); } Html::closeForm(); }
static function canView() { return plugin_ocsinventoryng_haveRight('ocsng', 'r'); }
/** * Check if I have one of the right specified * * @param $modules array of modules where keys are modules and value are right * * @return Nothing : display error if not permit **/ function plugin_ocsinventoryng_checkSeveralRightsOr($modules) { global $CFG_GLPI; $valid = false; if (count($modules)) { foreach ($modules as $mod => $right) { // Itemtype if (preg_match('/[A-Z]/', $mod[0])) { if ($item = getItemForItemtype($mod)) { if ($item->canGlobal($right)) { $valid = true; } } } else { if (plugin_ocsinventoryng_haveRight($mod, $right)) { $valid = true; } } } } if (!$valid) { // Gestion timeout session if (!Session::getLoginUserID()) { Html::redirect($CFG_GLPI["root_doc"] . "/index.php"); exit; } Html::displayRightError(); } }