本文整理汇总了PHP中Computer::getFromDB方法的典型用法代码示例。如果您正苦于以下问题:PHP Computer::getFromDB方法的具体用法?PHP Computer::getFromDB怎么用?PHP Computer::getFromDB使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Computer
的用法示例。
在下文中一共展示了Computer::getFromDB方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: MonitorUniqueSerialimport
/**
* @test
*/
public function MonitorUniqueSerialimport()
{
global $DB;
$DB->connect();
self::restore_database();
$_SESSION['glpiactive_entity'] = 0;
$_SESSION["plugin_fusioninventory_entity"] = 0;
$_SESSION["glpiname"] = 'Plugin_FusionInventory';
$pfConfig = new PluginFusioninventoryConfig();
$pfiComputerLib = new PluginFusioninventoryInventoryComputerLib();
$computer = new Computer();
$a_computerinventory = $this->a_computer1;
$a_computer = $a_computerinventory['Computer'];
$a_computer["entities_id"] = 0;
$computers_id = $computer->add($a_computer);
$pfiComputerLib->updateComputer($a_computerinventory, $computers_id, FALSE, 1);
$computer->getFromDB(1);
$this->assertEquals('ggheb7ne7', $computer->fields['serial'], 'Computer not updated correctly');
$this->assertEquals(1, countElementsInTable('glpi_monitors'), 'First computer');
$this->assertEquals(1, countElementsInTable('glpi_computers_items', 'itemtype="Monitor"'), 'First computer (links)');
// Second try (verify not create a second same monitor)
$pfiComputerLib->updateComputer($a_computerinventory, $computers_id, FALSE, 1);
$computer->getFromDB(1);
$this->assertEquals('ggheb7ne7', $computer->fields['serial'], 'Computer not updated correctly (2)');
$this->assertEquals(1, countElementsInTable('glpi_monitors'), 'First computer (2)');
$this->assertEquals(1, countElementsInTable('glpi_computers_items', 'itemtype="Monitor"'), 'First computer (links) (2)');
// Second computer with same monitor
$a_computerinventory = $this->a_computer2;
$a_computer = $a_computerinventory['Computer'];
$a_computer["entities_id"] = 0;
$computers_id = $computer->add($a_computer);
$pfiComputerLib->updateComputer($a_computerinventory, $computers_id, FALSE, 1);
$this->assertEquals(1, countElementsInTable('glpi_monitors'), 'Second computer');
$this->assertEquals(1, countElementsInTable('glpi_computers_items', 'itemtype="Monitor"'), 'Second computer (links)');
// Retry first computer without monitor
$a_computerinventory = $this->a_computer1;
$a_computerinventory['monitor'] = array();
$pfiComputerLib->updateComputer($a_computerinventory, $computers_id, FALSE, 1);
$computer->getFromDB(1);
$this->assertEquals('ggheb7ne7', $computer->fields['serial'], 'Computer not updated correctly (3)');
$this->assertEquals(1, countElementsInTable('glpi_monitors'), 'First computer (3)');
$this->assertEquals(1, countElementsInTable('glpi_computers_items', 'itemtype="Monitor"'), 'First computer (links) (3)');
// * Retry first computer with monitor
$a_computerinventory = $this->a_computer1;
$pfiComputerLib->updateComputer($a_computerinventory, $computers_id, FALSE, 1);
$computer->getFromDB(1);
$this->assertEquals('ggheb7ne7', $computer->fields['serial'], 'Computer not updated correctly (4)');
$this->assertEquals(1, countElementsInTable('glpi_monitors'), 'First computer (4)');
$this->assertEquals(1, countElementsInTable('glpi_computers_items', 'itemtype="Monitor"'), 'First computer (links) (4)');
$this->assertEquals(0, countElementsInTable('glpi_computers_items', 'itemtype="Monitor" AND `id` > 3'), 'First computer (number id of links recreated) (4)');
}
示例2: getList
static function getList($agents_id = NULL)
{
global $PF_CONFIG;
if (is_null($agents_id)) {
return array();
}
$pfAgent = new PluginFusioninventoryAgent();
$pfAgent->getFromDB($agents_id);
$agent = $pfAgent->fields;
$results = getAllDatasFromTable('glpi_plugin_fusioninventory_deploymirrors');
if (!isset($agent) || !isset($agent['computers_id'])) {
return array();
}
$computer = new Computer();
$computer->getFromDB($agent['computers_id']);
$mirrors = array();
foreach ($results as $result) {
if ($computer->fields['locations_id'] == $result['locations_id']) {
$mirrors[] = $result['url'];
}
}
//add default mirror (this server) if enabled in config
$entities_id = 0;
if (isset($agent['entities_id'])) {
$entities_id = $agent['entities_id'];
}
if (isset($PF_CONFIG['server_as_mirror']) && (bool) $PF_CONFIG['server_as_mirror'] == TRUE) {
$mirrors[] = PluginFusioninventoryAgentmodule::getUrlForModule('DEPLOY', $entities_id) . "?action=getFilePart&file=";
}
return $mirrors;
}
示例3: show
function show()
{
global $DB;
$networkPort = new NetworkPort();
$computer = new Computer();
$pmHostconfig = new PluginMonitoringHostconfig();
// Shinken server
$source_id = $pmHostconfig->getValueAncestor('computers_id', '0');
$switches_id = 0;
$this->a_devices['Computer-' . $source_id] = "SHINKEN";
$a_networkports = $networkPort->find("`itemtype`='Computer'\n AND `items_id`='" . $source_id . "'");
foreach ($a_networkports as $data_n) {
$networkports_id = $networkPort->getContact($data_n['id']);
if ($networkports_id) {
$networkPort->getFromDB($networkports_id);
if ($networkPort->fields['itemtype'] == 'NetworkEquipment') {
$this->a_devices['NetworkEquipment-' . $networkPort->fields['items_id']] = $this->getState('NetworkEquipment', $networkPort->fields['items_id']);
$this->a_devices_link['NetworkEquipment-' . $networkPort->fields['items_id']]['Computer-' . $source_id] = 1;
$this->getNetworkEquipments($networkPort->fields['items_id']);
$switches_id = $networkPort->fields['items_id'];
}
}
}
$this->addPoint('NetworkEquipment-' . $switches_id);
$computer->getFromDB($source_id);
$this->drawCanvas($computer, array(), array());
}
示例4: pdfForComputer
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();
}
示例5: Licenses
/**
* @test
*/
public function Licenses()
{
global $DB;
$DB->connect();
$_SESSION['glpiactive_entity'] = 0;
$_SESSION["plugin_fusioninventory_entity"] = 0;
$_SESSION["glpiname"] = 'Plugin_FusionInventory';
$pfiComputerLib = new PluginFusioninventoryInventoryComputerLib();
$computer = new Computer();
$GLPIlog = new GLPIlogs();
$a_computerinventory = $this->a_computer1;
$a_computer = $a_computerinventory['Computer'];
$a_computer["entities_id"] = 0;
$computers_id = $computer->add($a_computer);
$pfiComputerLib->updateComputer($a_computerinventory, $computers_id, FALSE, 1);
$computer->getFromDB(1);
$this->assertEquals('ggheb7ne7', $computer->fields['serial'], 'Computer not updated correctly');
$this->assertEquals(1, countElementsInTable('glpi_plugin_fusioninventory_computerlicenseinfos'), 'License may be added in fusion table');
$pfComputerLicenseInfo = new PluginFusioninventoryComputerLicenseInfo();
$pfComputerLicenseInfo->getFromDB(1);
$a_ref = array('id' => 1, 'computers_id' => 1, 'softwarelicenses_id' => 0, 'name' => 'Microsoft Office 2003', 'fullname' => 'Microsoft Office Professional Edition 2003', 'serial' => 'xxxxx-xxxxx-P6RC4-xxxxx-xxxxx', 'is_trial' => '0', 'is_update' => '0', 'is_oem' => '0', 'activation_date' => NULL);
$this->assertEquals($a_ref, $pfComputerLicenseInfo->fields, 'License data');
}
示例6: PeripheralUniqueSerialimport
/**
* @test
*/
public function PeripheralUniqueSerialimport()
{
global $DB;
$DB->connect();
self::restore_database();
$_SESSION['glpiactive_entity'] = 0;
$_SESSION["plugin_fusioninventory_entity"] = 0;
$_SESSION["glpiname"] = 'Plugin_FusionInventory';
$pfConfig = new PluginFusioninventoryConfig();
$pfiComputerLib = new PluginFusioninventoryInventoryComputerLib();
$computer = new Computer();
$GLPIlog = new GLPIlogs();
$pxml = @simplexml_load_string($this->a_computer1_XML, 'SimpleXMLElement', LIBXML_NOCDATA);
$arrayinventory = PluginFusioninventoryFormatconvert::XMLtoArray($pxml);
$agent = new PluginFusioninventoryAgent();
$agents_id = $agent->importToken($arrayinventory);
$_SESSION['plugin_fusioninventory_agents_id'] = $agents_id;
$pfInventoryComputerInventory = new PluginFusioninventoryInventoryComputerInventory();
$pfInventoryComputerInventory->import('deviceid', $arrayinventory['CONTENT'], $arrayinventory);
$computer->getFromDB(1);
$this->assertEquals('ggheb7ne7', $computer->fields['serial'], 'Computer not updated correctly');
$a_ref = array(1 => array('name' => 'Périphérique USB composite', 'id' => '1', 'serial' => '10075973', 'peripheraltypes_id' => '0', 'peripheralmodels_id' => '0', 'manufacturers_id' => '2', 'is_global' => '0', 'is_deleted' => '0', 'is_template' => '0', 'is_dynamic' => '0'), 2 => array('name' => 'H5321 gw Mobile Broadband Device', 'id' => '2', 'serial' => '187A047919938CM0', 'peripheraltypes_id' => '0', 'peripheralmodels_id' => '0', 'manufacturers_id' => '7', 'is_global' => '0', 'is_deleted' => '0', 'is_template' => '0', 'is_dynamic' => '0'), 3 => array('name' => 'Périphérique d’entrée USB', 'id' => '3', 'serial' => 'STM32_EMOTION2', 'peripheraltypes_id' => '0', 'peripheralmodels_id' => '0', 'manufacturers_id' => '8', 'is_global' => '0', 'is_deleted' => '0', 'is_template' => '0', 'is_dynamic' => '0'));
$a_db_peripherals = getAllDatasFromTable('glpi_peripherals');
foreach ($a_db_peripherals as $id => $data) {
$data_temp = array('name' => $data['name'], 'id' => $data['id'], 'serial' => $data['serial'], 'peripheraltypes_id' => $data['peripheraltypes_id'], 'peripheralmodels_id' => $data['peripheralmodels_id'], 'manufacturers_id' => $data['manufacturers_id'], 'is_global' => $data['is_global'], 'is_deleted' => $data['is_deleted'], 'is_template' => $data['is_template'], 'is_dynamic' => $data['is_dynamic']);
$a_db_peripherals[$id] = $data_temp;
}
$this->assertEquals($a_ref, $a_db_peripherals, 'List of peripherals');
// Update computer and may not have new values in glpi_logs
$query = "SELECT * FROM `glpi_logs`\n ORDER BY `id` DESC LIMIT 1";
$result = $DB->query($query);
$data = $DB->fetch_assoc($result);
$last_id = $data['id'];
$pfInventoryComputerInventory->import('deviceid', $arrayinventory['CONTENT'], $arrayinventory);
$data = getAllDatasFromTable('glpi_logs', "`id`>'" . $last_id . "'");
$this->assertEquals(array(), $data, 'On update peripherals, may not have new lines in glpi_logs');
}
示例7: Computer
} else {
$DBread = $DB;
}
$comp = new Computer();
$result = $DBread->query($Sql);
for ($prev = -1, $i = 0; $data = $DBread->fetch_array($result); $i++) {
if ($prev != $data["entity"]) {
$prev = $data["entity"];
echo "<tr class='tab_bg_4'><td class='center' colspan='{$colspan}'>" . Dropdown::getDropdownName("glpi_entities", $prev) . "</td></tr>\n";
}
echo "<tr class='tab_bg_2'>";
if ($canedit) {
echo "<td><input type='checkbox' name='item[" . $data["AID"] . "]' value='1'></td>";
}
echo "<td class='b'>" . $data["AID"] . "</td>";
if ($comp->getFromDB($data["AID"])) {
echo "<td>";
echo $comp->getLink(true);
echo "</td><td>";
echo Dropdown::getDropdownName("glpi_manufacturers", $comp->getField('manufacturers_id'));
echo "</td><td>";
echo Dropdown::getDropdownName("glpi_computermodels", $comp->getField('computermodels_id'));
echo "</td><td>" . $comp->getField('serial');
echo "</td><td>" . $comp->getField('otherserial') . "</td>";
} else {
echo "<td colspan='5'>" . $data["Aname"] . "</td>";
}
if ($col) {
echo "<td>" . $data["Aaddr"] . "</td>";
}
echo "<td>" . getLastOcsUpdate($data['AID']) . "</td>";
示例8: plugin_ocsinventoryng_preProcessRulePreviewResults
/**
*
* Preview for test a Rule
* @since 0.84
* @param $params input data
* @return $output array
*/
function plugin_ocsinventoryng_preProcessRulePreviewResults($params)
{
$output = $params['output'];
switch ($params['params']['rule_itemtype']) {
case 'RuleImportComputer':
//If ticket is assign to an object, display this information first
if (isset($output["action"])) {
echo "<tr class='tab_bg_2'>";
echo "<td>" . __('Action type') . "</td>";
echo "<td>";
switch ($output["action"]) {
case PluginOcsinventoryngOcsServer::LINK_RESULT_LINK:
_e('Link possible');
break;
case PluginOcsinventoryngOcsServer::LINK_RESULT_NO_IMPORT:
_e('Import refused');
break;
case PluginOcsinventoryngOcsServer::LINK_RESULT_IMPORT:
_e('New computer created in GLPI');
break;
}
echo "</td>";
echo "</tr>";
if ($output["action"] != PluginOcsinventoryngOcsServer::LINK_RESULT_NO_IMPORT && isset($output["found_computers"])) {
echo "<tr class='tab_bg_2'>";
$item = new Computer();
if ($item->getFromDB($output["found_computers"][0])) {
echo "<td>" . __('Link with computer') . "</td>";
echo "<td>" . $item->getLink(array('comments' => true)) . "</td>";
}
echo "</tr>";
}
}
break;
}
return $output;
}
示例9: rulepassed
/**
* If rule have found computer or rule give to create computer
*
* @param $items_id integer id of the computer found (or 0 if must be created)
* @param $itemtype value Computer type here
*
* @return nothing
*
**/
function rulepassed($items_id, $itemtype)
{
global $DB, $PLUGIN_FUSIONINVENTORY_XML, $PF_ESXINVENTORY, $CFG_GLPI;
PluginFusioninventoryToolbox::logIfExtradebug("pluginFusioninventory-rules", "Rule passed : " . $items_id . ", " . $itemtype . "\n");
$pfFormatconvert = new PluginFusioninventoryFormatconvert();
$a_computerinventory = $pfFormatconvert->replaceids($this->arrayinventory);
$entities_id = $_SESSION["plugin_fusioninventory_entity"];
if ($itemtype == 'Computer') {
$pfInventoryComputerLib = new PluginFusioninventoryInventoryComputerLib();
$pfAgent = new PluginFusioninventoryAgent();
$computer = new Computer();
if ($items_id == '0') {
if ($entities_id == -1) {
$entities_id = 0;
$_SESSION["plugin_fusioninventory_entity"] = 0;
}
$_SESSION['glpiactiveentities'] = array($entities_id);
$_SESSION['glpiactiveentities_string'] = $entities_id;
$_SESSION['glpiactive_entity'] = $entities_id;
} else {
$computer->getFromDB($items_id);
$a_computerinventory['Computer']['states_id'] = $computer->fields['states_id'];
$input = array();
PluginFusioninventoryInventoryComputerInventory::addDefaultStateIfNeeded($input);
if (isset($input['states_id'])) {
$a_computerinventory['Computer']['states_id'] = $input['states_id'];
}
if ($entities_id == -1) {
$entities_id = $computer->fields['entities_id'];
$_SESSION["plugin_fusioninventory_entity"] = $computer->fields['entities_id'];
}
$_SESSION['glpiactiveentities'] = array($entities_id);
$_SESSION['glpiactiveentities_string'] = $entities_id;
$_SESSION['glpiactive_entity'] = $entities_id;
if ($computer->fields['entities_id'] != $entities_id) {
$pfEntity = new PluginFusioninventoryEntity();
$pfInventoryComputerComputer = new PluginFusioninventoryInventoryComputerComputer();
$moveentity = FALSE;
if ($pfEntity->getValue('transfers_id_auto', $computer->fields['entities_id']) > 0) {
if (!$pfInventoryComputerComputer->getLock($items_id)) {
$moveentity = TRUE;
}
}
if ($moveentity) {
$pfEntity = new PluginFusioninventoryEntity();
$transfer = new Transfer();
$transfer->getFromDB($pfEntity->getValue('transfers_id_auto', $entities_id));
$item_to_transfer = array("Computer" => array($items_id => $items_id));
$transfer->moveItems($item_to_transfer, $entities_id, $transfer->fields);
} else {
$_SESSION["plugin_fusioninventory_entity"] = $computer->fields['entities_id'];
$_SESSION['glpiactiveentities'] = array($computer->fields['entities_id']);
$_SESSION['glpiactiveentities_string'] = $computer->fields['entities_id'];
$_SESSION['glpiactive_entity'] = $computer->fields['entities_id'];
$entities_id = $computer->fields['entities_id'];
}
}
}
$a_computerinventory = $pfFormatconvert->extraCollectInfo($a_computerinventory, $items_id);
$a_computerinventory = $pfFormatconvert->computerSoftwareTransformation($a_computerinventory, $entities_id);
$no_history = FALSE;
// * New
$setdynamic = 1;
if ($items_id == '0') {
$input = array();
$input['entities_id'] = $entities_id;
PluginFusioninventoryInventoryComputerInventory::addDefaultStateIfNeeded($input);
if (isset($input['states_id'])) {
$a_computerinventory['Computer']['states_id'] = $input['states_id'];
} else {
$a_computerinventory['Computer']['states_id'] = 0;
}
$items_id = $computer->add($input);
$no_history = TRUE;
$setdynamic = 0;
}
if (isset($_SESSION['plugin_fusioninventory_locations_id'])) {
$a_computerinventory['Computer']['locations_id'] = $_SESSION['plugin_fusioninventory_locations_id'];
unset($_SESSION['plugin_fusioninventory_locations_id']);
}
$serialized = gzcompress(serialize($a_computerinventory));
$a_computerinventory['fusioninventorycomputer']['serialized_inventory'] = Toolbox::addslashes_deep($serialized);
if (!$PF_ESXINVENTORY) {
$pfAgent->setAgentWithComputerid($items_id, $this->device_id, $entities_id);
}
$pfConfig = new PluginFusioninventoryConfig();
$query = "INSERT INTO `glpi_plugin_fusioninventory_dblockinventories`\n SET `value`='" . $items_id . "'";
$CFG_GLPI["use_log_in_files"] = FALSE;
if (!$DB->query($query)) {
$communication = new PluginFusioninventoryCommunication();
$communication->setMessage("<?xml version='1.0' encoding='UTF-8'?>\n <REPLY>\n <ERROR>ERROR: SAME COMPUTER IS CURRENTLY UPDATED</ERROR>\n </REPLY>");
//.........这里部分代码省略.........
示例10: sprintf
$disk->check(-1, CREATE, $_POST);
if ($newID = $disk->add($_POST)) {
Event::log($_POST['computers_id'], "computers", 4, "inventory", sprintf(__('%s adds a virtual machine'), $_SESSION["glpiname"]));
if ($_SESSION['glpibackcreated']) {
Html::redirect(Toolbox::getItemTypeFormURL('ComputerVirtualMachine') . "?id=" . $newID);
}
}
Html::back();
} else {
if (isset($_POST["purge"])) {
$disk->check($_POST["id"], PURGE);
if ($disk->delete($_POST, 1)) {
Event::log($disk->fields['computers_id'], "computers", 4, "inventory", sprintf(__('%s purges a virtual machine'), $_SESSION["glpiname"]));
}
$computer = new Computer();
$computer->getFromDB($disk->fields['computers_id']);
Html::redirect(Toolbox::getItemTypeFormURL('Computer') . '?id=' . $disk->fields['computers_id'] . ($computer->fields['is_template'] ? "&withtemplate=1" : ""));
} else {
if (isset($_POST["update"])) {
$disk->check($_POST["id"], UPDATE);
if ($disk->update($_POST)) {
Event::log($disk->fields['computers_id'], "computers", 4, "inventory", sprintf(__('%s updates a virtual machine'), $_SESSION["glpiname"]));
}
Html::back();
} else {
Html::header(Computer::getTypeName(Session::getPluralNumber()), $_SERVER['PHP_SELF'], "assets", "computer");
$disk->display(array('id' => $_GET["id"], 'computers_id' => $_GET["computers_id"]));
Html::footer();
}
}
}
示例11: manageConnectionComputer
/**
* Delete direct connection beetween an item and a computer when transfering the item
*
* @param $itemtype itemtype to tranfer
* @param $ID ID of the item
*
* @since version 0.84.4
**/
function manageConnectionComputer($itemtype, $ID)
{
global $DB;
// Get connections
$query = "SELECT *\n FROM `glpi_computers_items`\n WHERE `computers_id` NOT IN " . $this->item_search['Computer'] . "\n AND `itemtype` = '" . $itemtype . "'\n AND `items_id` = {$ID}";
if ($result = $DB->query($query)) {
if ($DB->numrows($result) != 0) {
// Foreach get item
$conn = new Computer_Item();
$comp = new Computer();
while ($data = $DB->fetch_assoc($result)) {
$item_ID = $data['items_id'];
if ($comp->getFromDB($item_ID)) {
$conn->delete(array('id' => $data['id']));
} else {
// Unexisting item / Force disconnect
$conn->delete(array('id' => $data['id'], '_no_history' => true, '_no_auto_action' => true));
}
}
}
}
}
示例12: showForComputer
/**
* 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>";
}
示例13: AddComputerStep3
/**
* @test
*/
public function AddComputerStep3()
{
global $DB;
$this->mark_incomplete();
return;
// TODO: recode this test
$DB->connect();
$DB->query("UPDATE `glpi_entities`\n SET `entities_id_software` = '-2'\n WHERE `id`='1'");
$_SESSION['glpiactive_entity'] = 0;
$_SESSION['glpiactiveentities_string'] = 0;
$_SESSION['glpishowallentities'] = 1;
$_SESSION['glpiname'] = 'glpi';
$pfiComputerInv = new PluginFusioninventoryInventoryComputerInventory();
$computer = new Computer();
$software = new Software();
$input = array('id' => 1, 'is_recursive' => 0);
$software->update($input);
$computer->add(array('name' => 'pc2', 'entities_id' => 1));
$a_inventory = array();
$a_inventory['CONTENT']['HARDWARE'] = array('NAME' => 'pc2');
$a_inventory['CONTENT']['SOFTWARES'][] = array('COMMENTS' => "Non-interactive tool to get files from FTP, GOPHER, HTTP(S)", 'NAME' => "curl", 'VERSION' => "7.24.0_1");
// ** Add agent
$pfAgent = new PluginFusioninventoryAgent();
$a_agents_id = $pfAgent->add(array('name' => 'pc-2013-02-13', 'device_id' => 'pc-2013-02-13'));
$_SESSION['plugin_fusioninventory_agents_id'] = $a_agents_id;
// ** Add
$pfiComputerInv->import("pc2-2013-02-13", "", $a_inventory);
// creation
$computer->getFromDB(2);
$this->assertEquals(1, $computer->fields['entities_id'], 'Add computer');
$nbSoftwares = countElementsInTable("glpi_softwares");
$softs = getAllDatasFromTable("glpi_softwares");
$this->assertEquals(2, $nbSoftwares, 'Nb softwares ' . print_r($softs, true));
$software->getFromDB(2);
$this->assertEquals(1, $software->fields['entities_id'], "May be on entity 1");
// Software not in same entity as computer, may be recursive
$this->assertEquals(0, $software->fields['is_recursive'], 'Software may have recursive = 0');
}
示例14: ComputerGeneral
/**
* @test
*/
public function ComputerGeneral()
{
global $DB;
$DB->connect();
$computer = new Computer();
$computer->getFromDB(1);
unset($computer->fields['date_mod']);
$a_reference = array('name' => 'pc', 'id' => '1', 'entities_id' => '0', 'serial' => 'XB63J7D', 'otherserial' => NULL, 'contact' => 'ddurieux', 'contact_num' => NULL, 'users_id_tech' => '0', 'groups_id_tech' => '0', 'comment' => NULL, 'operatingsystems_id' => '1', 'operatingsystemversions_id' => '1', 'operatingsystemservicepacks_id' => '1', 'os_license_number' => NULL, 'os_licenseid' => NULL, 'autoupdatesystems_id' => '0', 'locations_id' => '0', 'domains_id' => '1', 'networks_id' => '0', 'computermodels_id' => '0', 'computertypes_id' => '1', 'is_template' => '0', 'template_name' => NULL, 'manufacturers_id' => '0', 'is_deleted' => '0', 'is_dynamic' => '1', 'users_id' => '0', 'groups_id' => '0', 'states_id' => '0', 'ticket_tco' => '0.0000', 'uuid' => '68405E00-E5BE-11DF-801C-B05981201220');
$this->assertEquals($a_reference, $computer->fields);
}
示例15: showForComputer
/**
* Print the computers disks
*
* @param $comp Computer object
*
* @return Nothing (call to classes members)
**/
static function showForComputer(Computer $comp)
{
global $DB;
$ID = $comp->fields['id'];
if (!$comp->getFromDB($ID) || !$comp->can($ID, "r")) {
return false;
}
$canedit = $comp->can($ID, "w");
echo "<div class='spaced center'>";
$virtualmachines = getAllDatasFromTable('glpi_computervirtualmachines', "`computers_id` = '{$ID}' AND `is_deleted` = '0'");
echo "<table class='tab_cadre_fixe'>";
Session::initNavigateListItems('ComputerVirtualMachine', sprintf(__('%1$s = %2$s'), __('Computer'), empty($comp->fields['name']) ? "({$ID})" : $comp->fields['name']));
if (empty($virtualmachines)) {
echo "<tr><th>" . __('No virtual machine associated with the computer') . "</th></tr>";
} else {
echo "<tr><th colspan='10'>" . __('List of virtual machines') . "</th></tr>";
echo "<tr><th>" . __('Name') . "</th>";
if (Plugin::haveImport()) {
echo "<th>" . __('Automatic inventory') . "</th>";
}
echo "<th>" . __('Virtualization system') . "</th>";
echo "<th>" . __('Virtualization model') . "</th>";
echo "<th>" . __('State of the virtual machine') . "</th>";
echo "<th>" . __('UUID') . "</th>";
echo "<th>" . _x('quantity', 'Processors number') . "</th>";
echo "<th>" . sprintf(__('%1$s (%2$s)'), __('Memory'), __('Mio')) . "</th>";
echo "<th>" . __('Machine') . "</th>";
echo "</tr>";
$vm = new self();
foreach ($virtualmachines as $virtualmachine) {
$vm->getFromDB($virtualmachine['id']);
echo "<tr class='tab_bg_2'>";
echo "<td>" . $vm->getLink() . "</td>";
if (Plugin::haveImport()) {
echo "<td>";
echo Dropdown::getYesNo($vm->isDynamic());
echo "</td>";
}
echo "<td>";
echo Dropdown::getDropdownName('glpi_virtualmachinetypes', $virtualmachine['virtualmachinetypes_id']);
echo "</td>";
echo "<td>";
echo Dropdown::getDropdownName('glpi_virtualmachinesystems', $virtualmachine['virtualmachinesystems_id']);
echo "</td>";
echo "<td>";
echo Dropdown::getDropdownName('glpi_virtualmachinestates', $virtualmachine['virtualmachinestates_id']);
echo "</td>";
echo "<td>" . $virtualmachine['uuid'] . "</a></td>";
echo "<td>" . $virtualmachine['vcpu'] . "</td>";
echo "<td>" . $virtualmachine['ram'] . "</td>";
echo "<td>";
if ($link_computer = self::findVirtualMachine($virtualmachine)) {
$computer = new Computer();
if ($computer->can($link_computer, 'r')) {
$url = "<a href='computer.form.php?id=" . $link_computer . "'>";
$url .= $computer->fields["name"] . "</a>";
$tooltip = "<table><tr><td>" . __('Name') . "</td><td>" . $computer->fields['name'] . '</td></tr>';
$tooltip .= "<tr><td>" . __('Serial number') . "</td><td>" . $computer->fields['serial'] . '</td></tr>';
$tooltip .= "<tr><td>" . __('Comments') . "</td><td>" . $computer->fields['comment'] . '</td></tr></table>';
$url .= " " . Html::showToolTip($tooltip, array('display' => false));
} else {
$url = $computer->fields['name'];
}
echo $url;
}
echo "</td>";
echo "</tr>";
Session::addToNavigateListItems('ComputerVirtualMachine', $virtualmachine['id']);
}
}
if ($canedit) {
echo "<tr class='tab_bg_1'><td colspan='8' class='center'>";
echo "<a class='vsubmit' href='computervirtualmachine.form.php?computers_id={$ID}'>" . __('Add a virtual machine') . "</a></td></tr>";
}
echo "</table>";
echo "</div>";
}