static function pdfForComputer(PluginPdfSimplePDF $pdf, Computer $item) { global $DB; $ID = $item->getField('id'); // From ComputerVirtualMachine::showForComputer() $virtualmachines = getAllDatasFromTable('glpi_computervirtualmachines', "`computers_id` = '{$ID}'"); $pdf->setColumnsSize(100); if (count($virtualmachines)) { $pdf->displayTitle("<b>" . __('List of virtual machines') . "</b>"); $pdf->setColumnsSize(20, 8, 8, 8, 25, 8, 8, 15); $pdf->setColumnsAlign('left', 'center', 'center', 'center', 'left', 'right', 'right', 'left'); $typ = explode(' ', __('Virtualization system')); $sys = explode(' ', __('Virtualization model')); $sta = explode(' ', __('State of the virtual machine')); $pdf->displayTitle(__('Name'), $typ[0], $sys[0], $sta[0], __('UUID'), __('CPU'), __('Mio'), __('Machine')); foreach ($virtualmachines as $virtualmachine) { $name = ''; if ($link_computer = ComputerVirtualMachine::findVirtualMachine($virtualmachine)) { $computer = new Computer(); if ($computer->getFromDB($link_computer)) { $name = $computer->getName(); } } $pdf->displayLine($virtualmachine['name'], Html::clean(Dropdown::getDropdownName('glpi_virtualmachinetypes', $virtualmachine['virtualmachinetypes_id'])), Html::clean(Dropdown::getDropdownName('glpi_virtualmachinesystems', $virtualmachine['virtualmachinesystems_id'])), Html::clean(Dropdown::getDropdownName('glpi_virtualmachinestates', $virtualmachine['virtualmachinestates_id'])), $virtualmachine['uuid'], $virtualmachine['vcpu'], Html::clean(Html::formatNumber($virtualmachine['ram'], false, 0)), $name); } } else { $pdf->displayTitle("<b>" . __('No virtual machine associated with the computer') . "</b>"); } // From ComputerVirtualMachine::showForVirtualMachine() if ($item->fields['uuid']) { $where = "`uuid`" . ComputerVirtualMachine::getUUIDRestrictRequest($item->fields['uuid']); $hosts = getAllDatasFromTable('glpi_computervirtualmachines', $where); if (count($hosts)) { $pdf->setColumnsSize(100); $pdf->displayTitle("<b>" . __('List of host machines') . "</b>"); $pdf->setColumnsSize(26, 37, 37); $pdf->displayTitle(__('Name'), __('Operating system'), __('Entity')); $computer = new Computer(); foreach ($hosts as $host) { if ($computer->getFromDB($host['computers_id'])) { $pdf->displayLine($computer->getName(), Html::clean(Dropdown::getDropdownName('glpi_operatingsystems', $computer->getField('operatingsystems_id'))), Html::clean(Dropdown::getDropdownName('glpi_entities', $computer->getEntityID()))); } } } } $pdf->displaySpace(); }
/** * Print the computers disks * * @param $comp Computer object * @param $withtemplate boolean Template or basic item (default '') * * @return Nothing (call to classes members) **/ static function showForComputer(Computer $comp, $withtemplate = '') { global $DB; $ID = $comp->fields['id']; if (!$comp->getFromDB($ID) || !$comp->can($ID, READ)) { return false; } $canedit = $comp->canEdit($ID); if ($canedit && !(!empty($withtemplate) && $withtemplate == 2)) { echo "<div class='center firstbloc'>" . "<a class='vsubmit' href='computerdisk.form.php?computers_id={$ID}&withtemplate=" . $withtemplate . "'>"; _e('Add a volume'); echo "</a></div>\n"; } echo "<div class='center'>"; $query = "SELECT `glpi_filesystems`.`name` AS fsname,\n `glpi_computerdisks`.*\n FROM `glpi_computerdisks`\n LEFT JOIN `glpi_filesystems`\n ON (`glpi_computerdisks`.`filesystems_id` = `glpi_filesystems`.`id`)\n WHERE `computers_id` = '{$ID}'\n AND `is_deleted` = '0'"; if ($result = $DB->query($query)) { echo "<table class='tab_cadre_fixehov table-striped table-hover'>"; $colspan = 7; if (Plugin::haveImport()) { $colspan++; } echo "<tr class='noHover'><th colspan='{$colspan}'>" . self::getTypeName($DB->numrows($result)) . "</th></tr>"; if ($DB->numrows($result)) { $header = "<tr><th>" . __('Name') . "</th>"; if (Plugin::haveImport()) { $header .= "<th>" . __('Automatic inventory') . "</th>"; } $header .= "<th>" . __('Partition') . "</th>"; $header .= "<th>" . __('Mount point') . "</th>"; $header .= "<th>" . __('File system') . "</th>"; $header .= "<th>" . __('Global size') . "</th>"; $header .= "<th>" . __('Free size') . "</th>"; $header .= "<th>" . __('Free percentage') . "</th>"; $header .= "</tr>"; echo $header; Session::initNavigateListItems(__CLASS__, sprintf(__('%1$s = %2$s'), Computer::getTypeName(1), $comp->getName())); $disk = new self(); while ($data = $DB->fetch_assoc($result)) { $disk->getFromDB($data['id']); echo "<tr class='tab_bg_2'>"; echo "<td>" . $disk->getLink() . "</td>"; if (Plugin::haveImport()) { echo "<td>" . Dropdown::getYesNo($data['is_dynamic']) . "</td>"; } echo "<td>" . $data['device'] . "</td>"; echo "<td>" . $data['mountpoint'] . "</td>"; echo "<td>" . $data['fsname'] . "</td>"; //TRANS: %s is a size $tmp = sprintf(__('%s Mio'), Html::formatNumber($data['totalsize'], false, 0)); echo "<td class='right'>{$tmp}<span class='small_space'></span></td>"; $tmp = sprintf(__('%s Mio'), Html::formatNumber($data['freesize'], false, 0)); echo "<td class='right'>{$tmp}<span class='small_space'></span></td>"; echo "<td>"; $percent = 0; if ($data['totalsize'] > 0) { $percent = round(100 * $data['freesize'] / $data['totalsize']); } Html::displayProgressBar('100', $percent, array('simple' => true, 'forcepadding' => false)); echo "</td>"; echo "</tr>"; Session::addToNavigateListItems(__CLASS__, $data['id']); } echo $header; } else { echo "<tr class='tab_bg_2'><th colspan='{$colspan}'>" . __('No item found') . "</th></tr>"; } echo "</table>"; } echo "</div><br>"; }
/** * Print the computers antiviruses * * @param $comp Computer object * @param $withtemplate boolean Template or basic item (default '') * * @return Nothing (call to classes members) **/ static function showForComputer(Computer $comp, $withtemplate = '') { global $DB; $ID = $comp->fields['id']; if (!$comp->getFromDB($ID) || !$comp->can($ID, READ)) { return false; } $canedit = $comp->canEdit($ID); if ($canedit && !(!empty($withtemplate) && $withtemplate == 2)) { echo "<div class='center firstbloc'>" . "<a class='vsubmit' href='computerantivirus.form.php?computers_id={$ID}&withtemplate=" . $withtemplate . "'>"; _e('Add an antivirus'); echo "</a></div>\n"; } echo "<div class='spaced center'>"; if ($result = $DB->request('glpi_computerantiviruses', array('computers_id' => $ID, 'is_deleted' => 0))) { echo "<table class='tab_cadre_fixehov'>"; $colspan = 7; if (Plugin::haveImport()) { $colspan++; } echo "<tr class='noHover'><th colspan='{$colspan}'>" . self::getTypeName($result->numrows()) . "</th></tr>"; if ($result->numrows() != 0) { $header = "<tr><th>" . __('Name') . "</th>"; if (Plugin::haveImport()) { $header .= "<th>" . __('Automatic inventory') . "</th>"; } $header .= "<th>" . __('Manufacturer') . "</th>"; $header .= "<th>" . __('Antivirus version') . "</th>"; $header .= "<th>" . __('Signature database version') . "</th>"; $header .= "<th>" . __('Active') . "</th>"; $header .= "<th>" . __('Up to date') . "</th>"; $header .= "<th>" . __('Expiration date') . "</th>"; $header .= "</tr>"; echo $header; Session::initNavigateListItems(__CLASS__, sprintf(__('%1$s = %2$s'), Computer::getTypeName(1), $comp->getName())); $antivirus = new self(); foreach ($result as $data) { $antivirus->getFromDB($data['id']); echo "<tr class='tab_bg_2'>"; echo "<td>" . $antivirus->getLink() . "</td>"; if (Plugin::haveImport()) { echo "<td>" . Dropdown::getYesNo($data['is_dynamic']) . "</td>"; } echo "<td>"; if ($data['manufacturers_id']) { echo Dropdown::getDropdownName('glpi_manufacturers', $data['manufacturers_id']) . "</td>"; } else { echo "</td>"; } echo "<td>" . $data['antivirus_version'] . "</td>"; echo "<td>" . $data['signature_version'] . "</td>"; echo "<td>" . Dropdown::getYesNo($data['is_active']) . "</td>"; echo "<td>" . Dropdown::getYesNo($data['is_uptodate']) . "</td>"; echo "<td>" . Html::convDate($data['date_expiration']) . "</td>"; echo "</tr>"; Session::addToNavigateListItems(__CLASS__, $data['id']); } echo $header; } else { echo "<tr class='tab_bg_2'><th colspan='{$colspan}'>" . __('No item found') . "</th></tr>"; } echo "</table>"; } echo "</div>"; }
/** * Show software installed on a computer * * @param $comp Computer object * @param $withtemplate template case of the view process (default '') * * @return nothing **/ static function showForComputer(Computer $comp, $withtemplate = '') { global $DB, $CFG_GLPI; if (!Software::canView()) { return false; } $computers_id = $comp->getField('id'); $rand = mt_rand(); $canedit = Session::haveRightsOr("software", array(CREATE, UPDATE, DELETE, PURGE)); $entities_id = $comp->fields["entities_id"]; $crit = Session::getSavedOption(__CLASS__, 'criterion', -1); $where = ''; if ($crit > -1) { $where = " AND `glpi_softwares`.`softwarecategories_id` = {$crit}"; } $add_dynamic = ''; if (Plugin::haveImport()) { $add_dynamic = "`glpi_computers_softwareversions`.`is_dynamic`,"; } $query = "SELECT `glpi_softwares`.`softwarecategories_id`,\n `glpi_softwares`.`name` AS softname,\n `glpi_computers_softwareversions`.`id`,\n {$add_dynamic}\n `glpi_states`.`name` AS state,\n `glpi_softwareversions`.`id` AS verid,\n `glpi_softwareversions`.`softwares_id`,\n `glpi_softwareversions`.`name` AS version,\n `glpi_softwares`.`is_valid` AS softvalid\n FROM `glpi_computers_softwareversions`\n LEFT JOIN `glpi_softwareversions`\n ON (`glpi_computers_softwareversions`.`softwareversions_id`\n = `glpi_softwareversions`.`id`)\n LEFT JOIN `glpi_states`\n ON (`glpi_states`.`id` = `glpi_softwareversions`.`states_id`)\n LEFT JOIN `glpi_softwares`\n ON (`glpi_softwareversions`.`softwares_id` = `glpi_softwares`.`id`)\n WHERE `glpi_computers_softwareversions`.`computers_id` = '{$computers_id}'\n AND `glpi_computers_softwareversions`.`is_deleted` = '0'\n {$where}\n ORDER BY `softname`, `version`"; $result = $DB->query($query); $i = 0; if ((empty($withtemplate) || $withtemplate != 2) && $canedit) { echo "<form method='post' action='" . $CFG_GLPI["root_doc"] . "/front/computer_softwareversion.form.php'>"; echo "<div class='spaced'><table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'><td class='center'>"; echo _n('Software', 'Software', Session::getPluralNumber()) . " "; echo "<input type='hidden' name='computers_id' value='{$computers_id}'>"; Software::dropdownSoftwareToInstall("softwareversions_id", $entities_id); echo "</td><td width='20%'>"; echo "<input type='submit' name='add' value=\"" . _sx('button', 'Install') . "\"\n class='submit'>"; echo "</td>"; echo "</tr>\n"; echo "</table></div>\n"; Html::closeForm(); } echo "<div class='spaced'>"; $cat = -1; Session::initNavigateListItems('Software', sprintf(__('%1$s = %2$s'), Computer::getTypeName(1), $comp->getName())); Session::initNavigateListItems('SoftwareLicense', sprintf(__('%1$s = %2$s'), Computer::getTypeName(1), $comp->getName())); // Mini Search engine echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'><th colspan='2'>" . Software::getTypeName(Session::getPluralNumber()) . "</th></tr>"; echo "<tr class='tab_bg_1'><td class='center'>"; echo __('Category') . "</td><td>"; SoftwareCategory::dropdown(array('value' => $crit, 'toadd' => array('-1' => __('All categories')), 'emptylabel' => __('Uncategorized software'), 'on_change' => 'reloadTab("start=0&criterion="+this.value)')); echo "</td></tr></table></div>"; $number = $DB->numrows($result); $start = isset($_REQUEST['start']) ? intval($_REQUEST['start']) : 0; if ($start >= $number) { $start = 0; } $installed = array(); if ($number) { echo "<div class='spaced'>"; Html::printAjaxPager('', $start, $number); if ($canedit) { $rand = mt_rand(); Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array('num_displayed' => $number, 'container' => 'mass' . __CLASS__ . $rand, 'specific_actions' => array('purge' => _x('button', 'Delete permanently'))); Html::showMassiveActions($massiveactionparams); } echo "<table class='tab_cadre_fixehov'>"; $header_begin = "<tr>"; $header_top = ''; $header_bottom = ''; $header_end = ''; if ($canedit) { $header_begin .= "<th width='10'>"; $header_top .= Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); $header_bottom .= Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); $header_end .= "</th>"; } $header_end .= "<th>" . __('Name') . "</th><th>" . __('Status') . "</th>"; $header_end .= "<th>" . __('Version') . "</th><th>" . __('License') . "</th>"; if (Plugin::haveImport()) { $header_end .= "<th>" . __('Automatic inventory') . "</th>"; } $header_end .= "<th>" . SoftwareCategory::getTypeName(1) . "</th>"; $header_end .= "<th>" . __('Valid license') . "</th>"; $header_end .= "</tr>\n"; echo $header_begin . $header_top . $header_end; for ($row = 0; $data = $DB->fetch_assoc($result); $row++) { if ($row >= $start && $row < $start + $_SESSION['glpilist_limit']) { $licids = self::softsByCategory($data, $computers_id, $withtemplate, $canedit, true); } else { $licids = self::softsByCategory($data, $computers_id, $withtemplate, $canedit, false); } Session::addToNavigateListItems('Software', $data["softwares_id"]); foreach ($licids as $licid) { Session::addToNavigateListItems('SoftwareLicense', $licid); $installed[] = $licid; } } echo $header_begin . $header_bottom . $header_end; echo "</table>"; if ($canedit) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } } else { echo "<p class='center b'>" . __('No item found') . "</p>"; } echo "</div>\n"; if ((empty($withtemplate) || $withtemplate != 2) && $canedit) { echo "<form method='post' action='" . $CFG_GLPI["root_doc"] . "/front/computer_softwarelicense.form.php'>"; echo "<div class='spaced'><table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'>"; echo "<td class='center'>"; echo _n('License', 'Licenses', Session::getPluralNumber()) . " "; echo "<input type='hidden' name='computers_id' value='{$computers_id}'>"; Software::dropdownLicenseToInstall("softwarelicenses_id", $entities_id); echo "</td><td width='20%'>"; echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>"; echo "</td></tr>\n"; echo "</table></div>\n"; Html::closeForm(); } echo "<div class='spaced'>"; // Affected licenses NOT installed $query = "SELECT `glpi_softwarelicenses`.*,\n `glpi_computers_softwarelicenses`.`id` AS linkID,\n `glpi_softwares`.`name` AS softname,\n `glpi_softwareversions`.`name` AS version,\n `glpi_states`.`name` AS state\n FROM `glpi_softwarelicenses`\n LEFT JOIN `glpi_computers_softwarelicenses`\n ON (`glpi_computers_softwarelicenses`.softwarelicenses_id\n = `glpi_softwarelicenses`.`id`)\n INNER JOIN `glpi_softwares`\n ON (`glpi_softwarelicenses`.`softwares_id` = `glpi_softwares`.`id`)\n LEFT JOIN `glpi_softwareversions`\n ON (`glpi_softwarelicenses`.`softwareversions_id_use`\n = `glpi_softwareversions`.`id`\n OR (`glpi_softwarelicenses`.`softwareversions_id_use` = '0'\n AND `glpi_softwarelicenses`.`softwareversions_id_buy`\n = `glpi_softwareversions`.`id`))\n LEFT JOIN `glpi_states`\n ON (`glpi_states`.`id` = `glpi_softwareversions`.`states_id`)\n WHERE `glpi_computers_softwarelicenses`.`computers_id` = '{$computers_id}'\n AND `glpi_computers_softwarelicenses`.`is_deleted` = '0'\n {$where}"; if (count($installed)) { $query .= " AND `glpi_softwarelicenses`.`id` NOT IN (" . implode(',', $installed) . ")"; } $query .= " ORDER BY `softname`, `version`;"; $req = $DB->request($query); if ($number = $req->numrows()) { if ($canedit) { $rand = mt_rand(); Html::openMassiveActionsForm('massSoftwareLicense' . $rand); $actions = array('Computer_SoftwareLicense' . MassiveAction::CLASS_ACTION_SEPARATOR . 'install' => _x('button', 'Install')); if (SoftwareLicense::canUpdate()) { $actions['purge'] = _x('button', 'Delete permanently'); } $massiveactionparams = array('num_displayed' => $number, 'container' => 'massSoftwareLicense' . $rand, 'specific_actions' => $actions); Html::showMassiveActions($massiveactionparams); } echo "<table class='tab_cadre_fixehov'>"; $header_begin = "<tr>"; $header_top = ''; $header_bottom = ''; $header_end = ''; if ($canedit) { $header_begin .= "<th width='10'>"; $header_top .= Html::getCheckAllAsCheckbox('massSoftwareLicense' . $rand); $header_bottom .= Html::getCheckAllAsCheckbox('massSoftwareLicense' . $rand); $header_end .= "</th>"; } $header_end .= "<th>" . __('Name') . "</th><th>" . __('Status') . "</th>"; $header_end .= "<th>" . __('Version') . "</th><th>" . __('License') . "</th>"; $header_end .= "</tr>\n"; echo $header_begin . $header_top . $header_end; $cat = true; foreach ($req as $data) { self::displaySoftsByLicense($data, $computers_id, $withtemplate, $canedit); Session::addToNavigateListItems('SoftwareLicense', $data["id"]); } echo $header_begin . $header_bottom . $header_end; echo "</table>"; if ($canedit) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } } echo "</div>\n"; }
/** * @param $type * @param $id * @param $data * @param $num **/ function plugin_ocsinventoryng_giveItem($type, $id, $data, $num) { global $CFG_GLPI, $DB; $searchopt =& Search::getOptions($type); $table = $searchopt[$id]["table"]; $field = $searchopt[$id]["field"]; switch ("{$table}.{$field}") { case "glpi_plugin_ocsinventoryng_details.action": $detail = new PluginOcsinventoryngDetail(); return $detail->giveActionNameByActionID($data["ITEM_{$num}"]); case "glpi_plugin_ocsinventoryng_details.computers_id": $comp = new Computer(); $comp->getFromDB($data["ITEM_{$num}"]); return "<a href='" . Toolbox::getItemTypeFormURL('Computer') . "?id=" . $data["ITEM_{$num}"] . "'>" . $comp->getName() . "</a>"; case "glpi_plugin_ocsinventoryng_details.plugin_ocsinventoryng_ocsservers_id": $ocs = new PluginOcsinventoryngOcsServer(); $ocs->getFromDB($data["ITEM_{$num}"]); return "<a href='" . Toolbox::getItemTypeFormURL('PluginOcsinventoryngOcsServer') . "?id=" . $data["ITEM_{$num}"] . "'>" . $ocs->getName() . "</a>"; case "glpi_plugin_ocsinventoryng_details.rules_id": $detail = new PluginOcsinventoryngDetail(); $detail->getFromDB($data['id']); return PluginOcsinventoryngNotimportedcomputer::getRuleMatchedMessage($detail->fields['rules_id']); case "glpi_plugin_ocsinventoryng_notimportedcomputers.reason": return PluginOcsinventoryngNotimportedcomputer::getReason($data["ITEM_{$num}"]); } return ''; }
/** * Print the form for devices linked to a computer or a template * * @param $computer Computer object * @param $withtemplate='' boolean : template or basic computer * * @return Nothing (display) **/ static function showForComputer(Computer $computer, $withtemplate = '') { global $DB, $LANG; $devtypes = self::getDeviceTypes(); $ID = $computer->getField('id'); if (!$computer->can($ID, 'r')) { return false; } $canedit = $withtemplate != 2 && $computer->can($ID, 'w'); echo "<div class='spaced'>"; if ($canedit) { echo "<form name='form_device_action' action='" . getItemTypeFormURL(__CLASS__) . "' method='post'>"; echo "<input type='hidden' name='computers_id' value='{$ID}'>"; } echo "<table class='tab_cadre_fixe' >"; echo "<tr><th colspan='63'>" . $LANG['title'][30] . "</th></tr>"; $nb = 0; $specificity_units = array('DeviceProcessor' => $LANG['setup'][35], 'DeviceMemory' => $LANG['common'][82], 'DeviceHardDrive' => $LANG['common'][82], 'DeviceGraphicCard' => $LANG['common'][82]); foreach ($devtypes as $itemtype) { initNavigateListItems($itemtype, $computer->getTypeName() . " = " . $computer->getName()); $device = new $itemtype(); $specificities = $device->getSpecifityLabel(); $specif_fields = array_keys($specificities); $specif_text = implode(',', $specif_fields); if (!empty($specif_text)) { $specif_text = " ," . $specif_text . " "; } $linktable = getTableForItemType('Computer_' . $itemtype); $fk = getForeignKeyFieldForTable(getTableForItemType($itemtype)); $query = "SELECT COUNT(*) AS NB,\n `id`,\n `{$fk}`\n {$specif_text}\n FROM `{$linktable}`\n WHERE `computers_id` = '{$ID}'\n GROUP BY `{$fk}` {$specif_text}"; $prev = ''; foreach ($DB->request($query) as $data) { addToNavigateListItems($itemtype, $data[$fk]); if ($device->getFromDB($data[$fk])) { echo "<tr class='tab_bg_2'>"; echo "<td class='center'>"; Dropdown::showInteger("quantity_" . $itemtype . "_" . $data['id'], $data['NB']); echo "</td><td>"; if ($device->canCreate()) { echo "<a href='" . $device->getSearchURL() . "'>" . $device->getTypeName() . "</a>"; } else { echo $device->getTypeName(); } echo "</td><td>" . $device->getLink() . "</td>"; $spec = $device->getFormData(); if (isset($spec['label']) && count($spec['label'])) { $colspan = 60 / count($spec['label']); foreach ($spec['label'] as $i => $label) { if (isset($spec['value'][$i])) { echo "<td colspan='{$colspan}'>" . $spec['label'][$i] . " : "; echo $spec['value'][$i] . "</td>"; } else { if ($canedit) { // Specificity echo "<td class='right' colspan='{$colspan}'>" . $spec['label'][$i] . " : "; echo "<input type='text' name='value_" . $itemtype . "_" . $data['id'] . "' value='" . $data['specificity'] . "' size='" . $spec['size'] . "'>"; if (isset($specificity_units[$device->getType()])) { echo ' ' . $specificity_units[$device->getType()]; } echo "</td>"; } else { echo "<td colspan='{$colspan}'>" . $spec['label'][$i] . " : "; echo $data['specificity']; if (isset($specificity_units[$device->getType()])) { echo ' ' . $specificity_units[$device->getType()]; } echo "</td>"; } } } } else { echo "<td colspan='60'> </td>"; } echo "</tr>"; $nb++; } } } if ($canedit) { if ($nb > 0) { echo "<tr><td colspan='63' class='tab_bg_1 center'>"; echo "<input type='submit' class='submit' name='updateall' value='" . $LANG['buttons'][7] . "'></td></tr>"; } echo "<tr><td colspan='63' class='tab_bg_1 center'>"; echo $LANG['devices'][0] . " : "; Dropdown::showAllItems('items_id', '', 0, -1, $devtypes); echo "<input type='submit' name='add' value=\"" . $LANG['buttons'][8] . "\" class='submit'>"; echo "</tr></table></form>"; } else { echo "</table>"; } echo "</div>"; }
/** * Display detail networkport based on glpi core networkport and fusioninventory * networkport * * @param array $data with id ant fusionid * @param boolean $monitoring true if monitoring installed && actived * @param boolean $aggrega true if this port is aggregate port * * @return nothing */ function showNetworkPortDetail($data, $monitoring, $aggrega = 0) { global $CFG_GLPI, $DB; $nw = new NetworkPort_NetworkPort(); $networkName = new NetworkName(); $networkPort = new NetworkPort(); $pfNetworkPort = new PluginFusioninventoryNetworkPort(); $iPAddress = new IPAddress(); $networkPort->getFromDB($data['id']); $pfNetworkPort->getFromDB($data['fusionid']); $background_img = ""; if ($pfNetworkPort->fields["trunk"] == "1" && (strstr($pfNetworkPort->fields["ifstatus"], "up") || $pfNetworkPort->fields["ifstatus"] == 1)) { $background_img = " style='background-image: url(\"" . $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/pics/port_trunk.png\"); '"; } else { if (PluginFusioninventoryNetworkPort::isPortHasMultipleMac($data['id']) && (strstr($pfNetworkPort->fields["ifstatus"], "up") || $pfNetworkPort->fields["ifstatus"] == 1)) { $background_img = " style='background-image: url(\"" . $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/pics/multiple_mac_addresses.png\"); '"; } else { if (strstr($pfNetworkPort->fields["ifstatus"], "up") || $pfNetworkPort->fields["ifstatus"] == 1) { $background_img = " style='background-image: url(\"" . $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/pics/connected_trunk.png\"); '"; } } } echo "<tr class='tab_bg_1 center' height='40'" . $background_img . ">"; if ($aggrega) { echo "<td style='background-color: #f2f2f2;'></td><td>"; } if (!$aggrega) { if ($networkPort->fields['instantiation_type'] == 'NetworkPortAggregate') { echo "<td>"; } else { echo "<td colspan='2'>"; } } echo "<a href='networkport.form.php?id=" . $networkPort->fields["id"] . "'>" . $networkPort->fields["name"] . "</a>"; Html::showToolTip($pfNetworkPort->fields['ifdescr']); if (!$aggrega) { if ($networkPort->fields['instantiation_type'] == 'NetworkPortAggregate') { echo "<td><i><font style='color: grey'>" . __('Aggregation port') . "</font></i></td>"; } } if ($monitoring == '1') { echo "<td>"; $state = PluginMonitoringNetworkport::isMonitoredNetworkport($data['id']); if (Session::haveRight("plugin_monitoring_componentscatalog", UPDATE)) { $checked = ''; if ($state) { $checked = 'checked'; } echo "<input type='checkbox' name='networkports_id[]' value='" . $data['id'] . "' " . $checked . "/>"; } else { if (Session::haveRight("plugin_monitoring_componentscatalog", READ)) { echo Dropdown::getYesNo($state); } } echo "</td>"; } $a_pref = DisplayPreference::getForTypeUser('PluginFusioninventoryNetworkport', Session::getLoginUserID()); foreach ($a_pref as $data_array) { switch ($data_array) { case 3: echo "<td>" . $pfNetworkPort->fields["ifmtu"] . "</td>"; break; case 5: echo "<td>" . $this->byteSize($pfNetworkPort->fields["ifspeed"], 1000) . "bps</td>"; break; case 6: echo "<td>"; if (strstr($pfNetworkPort->fields["ifstatus"], "up") || strstr($pfNetworkPort->fields["ifinternalstatus"], "1")) { echo "<img src='" . $CFG_GLPI['root_doc'] . "/pics/greenbutton.png'/>"; } else { if (strstr($pfNetworkPort->fields["ifstatus"], "down") || strstr($pfNetworkPort->fields["ifinternalstatus"], "2")) { echo "<img src='" . $CFG_GLPI['root_doc'] . "/pics/redbutton.png'/>"; } else { if (strstr($pfNetworkPort->fields["ifstatus"], "testing") || strstr($pfNetworkPort->fields["ifinternalstatus"], "3")) { echo "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/pics/yellowbutton.png'/>"; } } } echo "</td>"; break; case 7: echo "<td>" . $pfNetworkPort->fields["iflastchange"] . "</td>"; break; case 8: echo "<td>"; if ($pfNetworkPort->fields["ifinoctets"] == "0") { echo "-"; } else { echo $this->byteSize($pfNetworkPort->fields["ifinoctets"], 1000) . "o"; } echo " / "; if ($pfNetworkPort->fields["ifinoctets"] == "0") { echo "-"; } else { echo $this->byteSize($pfNetworkPort->fields["ifoutoctets"], 1000) . "o"; } echo "</td>"; break; case 9: $color = ''; if ($pfNetworkPort->fields["ifinerrors"] != "0" || $pfNetworkPort->fields["ifouterrors"] != "0") { $color = "background='#cf9b9b' class='tab_bg_1_2'"; } if ($pfNetworkPort->fields["ifinerrors"] == "0") { echo "<td " . $color . ">-"; } else { echo "<td " . $color . ">"; echo $pfNetworkPort->fields["ifinerrors"]; } echo " / "; if ($pfNetworkPort->fields["ifouterrors"] == "0") { echo "-"; } else { echo $pfNetworkPort->fields["ifouterrors"]; } echo "</td>"; break; case 10: if ($pfNetworkPort->fields["portduplex"] == 2) { echo "<td background='#cf9b9b' class='tab_bg_1_2'>"; echo __('Half', 'fusioninventory'); echo '</td>'; } else { if ($pfNetworkPort->fields["portduplex"] == 3) { echo '<td>'; echo __('Full', 'fusioninventory'); echo '</td>'; } else { echo "<td></td>"; } } break; case 11: // ** internal mac echo "<td>" . $networkPort->fields["mac"] . "</td>"; break; case 13: // ** Mac address and link to device which are connected to this port $opposite_port = $nw->getOppositeContact($data["id"]); if ($opposite_port != "" && $opposite_port != 0) { $networkPortOpposite = new NetworkPort(); if ($networkPortOpposite->getFromDB($opposite_port)) { $data_device = $networkPortOpposite->fields; $item = new $data_device["itemtype"](); $item->getFromDB($data_device["items_id"]); $link1 = $item->getLink(1); $link = str_replace($item->getName(0), $data_device["mac"], $item->getLink()); // * GetIP $a_networknames = current($networkName->find("`itemtype`='NetworkPort'\n AND `items_id`='" . $item->getID() . "'", "", 1)); $a_ipaddresses = current($iPAddress->find("`itemtype`='NetworkName'\n AND `items_id`='" . $a_networknames['id'] . "'", "", 1)); $link2 = str_replace($item->getName(0), $a_ipaddresses['name'], $item->getLink()); if ($data_device["itemtype"] == 'PluginFusioninventoryUnmanaged') { $icon = $this->getItemtypeIcon($item->fields["item_type"]); if ($item->getField("accepted") == "1") { echo "<td style='background:#bfec75'\n class='tab_bg_1_2'>" . $icon . $link1; } else { echo "<td background='#cf9b9b'\n class='tab_bg_1_2'>" . $icon . $link1; } if (!empty($link)) { echo "<br/>" . $link; } if (!empty($link2)) { echo "<br/>" . $link2; } if ($item->getField("hub") == "1") { $this->displayHubConnections($data_device["items_id"], $background_img); } echo "</td>"; } else { $icon = $this->getItemtypeIcon($data_device["itemtype"]); echo "<td>" . $icon . $link1; if (!empty($link)) { echo "<br/>" . $link; } if (!empty($link2)) { echo "<br/>" . $link2; } if ($data_device["itemtype"] == 'Phone') { $query_devicephone = "SELECT *\n FROM `glpi_networkports`\n WHERE `itemtype`='Phone'\n AND `items_id`='" . $data_device["items_id"] . "'\n AND `id`!='" . $data_device["id"] . "'\n LIMIT 1"; $result_devicephone = $DB->query($query_devicephone); if ($DB->numrows($result_devicephone) > 0) { $data_devicephone = $DB->fetch_assoc($result_devicephone); $computer_ports_id = $nw->getOppositeContact($data_devicephone["id"]); if ($computer_ports_id) { $networkport = new NetworkPort(); $networkport->getFromDB($computer_ports_id); if ($networkport->fields['itemtype'] == 'Computer') { echo "<hr/>"; echo "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/pics/computer_icon.png' " . "style='float:left'/> "; $computer = new Computer(); $computer->getFromDB($networkport->fields["items_id"]); $link1 = $computer->getLink(1); $link = str_replace($computer->getName(0), $networkport->fields["mac"], $computer->getLink()); $link2 = str_replace($computer->getName(0), $networkport->fields["ip"], $computer->getLink()); echo $icon . $link1; if (!empty($link)) { echo "<br/>" . $link; } if (!empty($link2)) { echo "<br/>" . $link2; } } } } } echo "</td>"; } } else { echo "<td></td>"; } } else { echo "<td></td>"; } break; case 14: // ** Connection status echo "<td>"; if (strstr($pfNetworkPort->fields["ifstatus"], "up") || strstr($pfNetworkPort->fields["ifstatus"], "1")) { echo "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/pics/wired_on.png'/>"; } else { if (strstr($pfNetworkPort->fields["ifstatus"], "down") || strstr($pfNetworkPort->fields["ifstatus"], "2")) { echo "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/pics/wired_off.png'/>"; } else { if (strstr($pfNetworkPort->fields["ifstatus"], "testing") || strstr($pfNetworkPort->fields["ifstatus"], "3")) { echo "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/pics/yellowbutton.png'/>"; } else { if (strstr($pfNetworkPort->fields["ifstatus"], "dormant") || strstr($pfNetworkPort->fields["ifstatus"], "5")) { echo "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/pics/orangebutton.png'/>"; } } } } echo "</td>"; break; case 12: echo "<td>"; $canedit = Session::haveRight('networking', UPDATE); $used = array(); $query_vlan = "SELECT * FROM glpi_networkports_vlans\n WHERE networkports_id='" . $data["id"] . "'"; $result_vlan = $DB->query($query_vlan); if ($DB->numrows($result_vlan) > 0) { echo "<table cellpadding='0' cellspacing='0'>"; while ($line = $DB->fetch_array($result_vlan)) { $used[] = $line["vlans_id"]; $vlan = new Vlan(); $vlan->getFromDB($line["vlans_id"]); if ($line['tagged'] == '1') { $state = 'T'; } else { $state = 'U'; } echo "<tr><td>" . $vlan->fields['name'] . " [" . $vlan->fields['tag'] . "] " . $state; echo "</td><td>"; if ($canedit) { echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/networkport.form.php?unassign_vlan=unassigned&id=" . $line["id"] . "'>"; echo "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/delete.png\" alt='" . __('Delete', 'fusioninventory') . "' title='" . __('Delete', 'fusioninventory') . "'></a>"; } else { echo " "; } echo "</td>"; echo "</tr>"; } echo "</table>"; } else { echo " "; } echo "</td>"; break; case 15: echo "<td align='center'>"; if ($pfNetworkPort->fields['ifstatus'] == 1) { echo __('Connected'); } else { if ($pfNetworkPort->fields['lastup'] == "0000-00-00 00:00:00") { echo '-'; } else { $time = strtotime(date('Y-m-d H:i:s')) - strtotime($pfNetworkPort->fields['lastup']); echo Html::timestampToString($time, FALSE); } } echo "</td>"; break; case 16: echo "<td>" . $pfNetworkPort->fields["ifalias"] . "</td>"; break; } } echo "</tr>"; }
/** * Show software installed on a computer * * @param $comp Computer object * @param $withtemplate template case of the view process (default '') * * @return nothing **/ static function showForComputer(Computer $comp, $withtemplate = '') { global $DB, $CFG_GLPI; if (!Session::haveRight("software", "r")) { return false; } $computers_id = $comp->getField('id'); $rand = mt_rand(); $canedit = Session::haveRight("software", "w"); $entities_id = $comp->fields["entities_id"]; $add_dynamic = ''; if (Plugin::haveImport()) { $add_dynamic = "`glpi_computers_softwareversions`.`is_dynamic`,"; } $query = "SELECT `glpi_softwares`.`softwarecategories_id`,\n `glpi_softwares`.`name` AS softname,\n `glpi_computers_softwareversions`.`id`,\n {$add_dynamic}\n `glpi_states`.`name` AS state,\n `glpi_softwareversions`.`id` AS verid,\n `glpi_softwareversions`.`softwares_id`,\n `glpi_softwareversions`.`name` AS version\n FROM `glpi_computers_softwareversions`\n LEFT JOIN `glpi_softwareversions`\n ON (`glpi_computers_softwareversions`.`softwareversions_id`\n = `glpi_softwareversions`.`id`)\n LEFT JOIN `glpi_states`\n ON (`glpi_states`.`id` = `glpi_softwareversions`.`states_id`)\n LEFT JOIN `glpi_softwares`\n ON (`glpi_softwareversions`.`softwares_id` = `glpi_softwares`.`id`)\n WHERE `glpi_computers_softwareversions`.`computers_id` = '{$computers_id}'\n AND `glpi_computers_softwareversions`.`is_deleted` = '0'\n ORDER BY `softwarecategories_id`, `softname`, `version`"; $result = $DB->query($query); $i = 0; if ((empty($withtemplate) || $withtemplate != 2) && $canedit) { echo "<form method='post' action='" . $CFG_GLPI["root_doc"] . "/front/computer_softwareversion.form.php'>"; echo "<div class='spaced'><table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'><td class='center'>"; echo _n('Software', 'Software', 2) . " "; echo "<input type='hidden' name='computers_id' value='{$computers_id}'>"; Software::dropdownSoftwareToInstall("softwareversions_id", $entities_id); echo "</td><td width='20%'>"; echo "<input type='submit' name='add' value=\"" . _sx('button', 'Install') . "\"\n class='submit'>"; echo "</td>"; echo "</tr>\n"; echo "</table></div>\n"; Html::closeForm(); } echo "<div class='spaced'>"; $cat = -1; Session::initNavigateListItems('Software', sprintf(__('%1$s = %2$s'), Computer::getTypeName(1), $comp->getName())); Session::initNavigateListItems('SoftwareLicense', sprintf(__('%1$s = %2$s'), Computer::getTypeName(1), $comp->getName())); $installed = array(); if ($number = $DB->numrows($result)) { if ($canedit) { $rand = mt_rand(); Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $paramsma = array('num_displayed' => $number, 'specific_actions' => array('purge' => _x('button', 'Delete permanently'))); Html::showMassiveActions(__CLASS__, $paramsma); } echo "<table class='tab_cadre_fixe'>"; while ($data = $DB->fetch_assoc($result)) { if ($data["softwarecategories_id"] != $cat) { self::displayCategoryFooter($cat, $rand, $canedit); $cat = self::displayCategoryHeader($computers_id, $data, $rand, $canedit); } $licids = self::displaySoftsByCategory($data, $computers_id, $withtemplate, $canedit); Session::addToNavigateListItems('Software', $data["softwares_id"]); foreach ($licids as $licid) { Session::addToNavigateListItems('SoftwareLicense', $licid); $installed[] = $licid; } } self::displayCategoryFooter($cat, $rand, $canedit); echo "</table>"; if ($canedit) { $paramsma['ontop'] = false; Html::showMassiveActions(__CLASS__, $paramsma); Html::closeForm(); } } echo "</div>\n"; if ((empty($withtemplate) || $withtemplate != 2) && $canedit) { echo "<form method='post' action='" . $CFG_GLPI["root_doc"] . "/front/computer_softwarelicense.form.php'>"; echo "<div class='spaced'><table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'>"; echo "<td class='center'>"; echo _n('License', 'Licenses', 2) . " "; echo "<input type='hidden' name='computers_id' value='{$computers_id}'>"; Software::dropdownLicenseToInstall("softwarelicenses_id", $entities_id); echo "</td><td width='20%'>"; echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>"; echo "</td></tr>\n"; echo "</table></div>\n"; Html::closeForm(); } echo "<div class='spaced'>"; // Affected licenses NOT installed $query = "SELECT `glpi_softwarelicenses`.*,\n `glpi_computers_softwarelicenses`.`id` AS linkID,\n `glpi_softwares`.`name` AS softname,\n `glpi_softwareversions`.`name` AS version,\n `glpi_states`.`name` AS state\n FROM `glpi_softwarelicenses`\n LEFT JOIN `glpi_computers_softwarelicenses`\n ON (`glpi_computers_softwarelicenses`.softwarelicenses_id\n = `glpi_softwarelicenses`.`id`)\n INNER JOIN `glpi_softwares`\n ON (`glpi_softwarelicenses`.`softwares_id` = `glpi_softwares`.`id`)\n LEFT JOIN `glpi_softwareversions`\n ON (`glpi_softwarelicenses`.`softwareversions_id_use`\n = `glpi_softwareversions`.`id`\n OR (`glpi_softwarelicenses`.`softwareversions_id_use` = '0'\n AND `glpi_softwarelicenses`.`softwareversions_id_buy`\n = `glpi_softwareversions`.`id`))\n LEFT JOIN `glpi_states`\n ON (`glpi_states`.`id` = `glpi_softwareversions`.`states_id`)\n WHERE `glpi_computers_softwarelicenses`.`computers_id` = '{$computers_id}'\n AND `glpi_computers_softwarelicenses`.`is_deleted` = '0'"; if (count($installed)) { $query .= " AND `glpi_softwarelicenses`.`id` NOT IN (" . implode(',', $installed) . ")"; } $req = $DB->request($query); if ($number = $req->numrows()) { if ($canedit) { $rand = mt_rand(); Html::openMassiveActionsForm('massSoftwareLicense' . $rand); $actions = array('install' => _x('button', 'Install')); if (SoftwareLicense::canUpdate()) { $actions['purge'] = _x('button', 'Delete permanently'); } $paramsma = array('num_displayed' => $number, 'specific_actions' => $actions); Html::showMassiveActions('Computer_SoftwareLicense', $paramsma); echo "<input type='hidden' name='computers_id' value='{$computers_id}'>"; } echo "<table class='tab_cadre_fixe'>"; $cat = true; foreach ($req as $data) { if ($cat) { self::displayCategoryHeader($computers_id, $data, $rand, $canedit); $cat = false; } self::displaySoftsByLicense($data, $computers_id, $withtemplate, $canedit); Session::addToNavigateListItems('SoftwareLicense', $data["id"]); } self::displayCategoryFooter(NULL, $rand, $canedit); echo "</table>"; if ($canedit) { $paramsma['ontop'] = false; Html::showMassiveActions('Computer_SoftwareLicense', $paramsma); Html::closeForm(); } } echo "</div>\n"; }