本文整理汇总了PHP中Computer_Item::add方法的典型用法代码示例。如果您正苦于以下问题:PHP Computer_Item::add方法的具体用法?PHP Computer_Item::add怎么用?PHP Computer_Item::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Computer_Item
的用法示例。
在下文中一共展示了Computer_Item::add方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testTypeName
/**
* @covers Computer::post_updateItem
*/
public function testTypeName()
{
global $CFG_GLPI;
$computer = getItemByTypeName('Computer', '_test_pc01');
$savecomp = $computer->fields;
$saveconf = $CFG_GLPI;
$printer = getItemByTypeName('Printer', '_test_printer_all');
// Create the link
$link = new Computer_Item();
$in = ['computers_id' => $computer->getField('id'), 'itemtype' => $printer->getType(), 'items_id' => $printer->getID()];
$this->assertGreaterThan(0, $link->add($in));
// Change the computer
$CFG_GLPI['is_contact_autoupdate'] = 1;
$CFG_GLPI['is_user_autoupdate'] = 1;
$CFG_GLPI['is_group_autoupdate'] = 1;
$CFG_GLPI['state_autoupdate_mode'] = -1;
$CFG_GLPI['is_location_autoupdate'] = 1;
$in = ['id' => $computer->getField('id'), 'contact' => $this->getUniqueString(), 'contact_num' => $this->getUniqueString(), 'users_id' => $this->getUniqueInteger(), 'groups_id' => $this->getUniqueInteger(), 'states_id' => $this->getUniqueInteger(), 'locations_id' => $this->getUniqueInteger()];
$this->assertTrue($computer->update($in));
$this->assertTrue($computer->getFromDB($computer->getID()));
$this->assertTrue($printer->getFromDB($printer->getID()));
foreach ($in as $k => $v) {
// Check the computer new values
$this->assertEquals($v, $computer->getField($k), $k);
// Check the printer and test propagation occurs
$this->assertEquals($v, $printer->getField($k), $k);
}
// Change the computer again
$CFG_GLPI['is_contact_autoupdate'] = 0;
$CFG_GLPI['is_user_autoupdate'] = 0;
$CFG_GLPI['is_group_autoupdate'] = 0;
$CFG_GLPI['state_autoupdate_mode'] = 0;
$CFG_GLPI['is_location_autoupdate'] = 0;
$in2 = ['id' => $computer->getField('id'), 'contact' => $this->getUniqueString(), 'contact_num' => $this->getUniqueString(), 'users_id' => $this->getUniqueInteger(), 'groups_id' => $this->getUniqueInteger(), 'states_id' => $this->getUniqueInteger(), 'locations_id' => $this->getUniqueInteger()];
$this->assertTrue($computer->update($in2));
$this->assertTrue($computer->getFromDB($computer->getID()));
$this->assertTrue($printer->getFromDB($printer->getID()));
foreach ($in2 as $k => $v) {
// Check the computer new values
$this->assertEquals($v, $computer->getField($k), $k);
// Check the printer and test propagation DOES NOT occurs
$this->assertEquals($in[$k], $printer->getField($k), $k);
}
// Restore state
$computer->update($savecomp);
// Restore configuration
$CFG_GLPI = $saveconf;
}
示例2: generate_entity
/** Generate bigdump : generate items for an entity
*
* @param $ID_entity entity ID
**/
function generate_entity($ID_entity) {
global $MAX, $DB, $percent, $FIRST, $LAST, $MAX_KBITEMS_BY_CAT, $MAX_DISK,
$DOCUMENTS, $NET_PORT, $NET_LOC;
regenerateTreeCompleteName("glpi_entities");
$current_year = date("Y");
// DOMAIN
$items = array("SP2MI", "CAMPUS"," IUT86", "PRESIDENCE", "CEAT", "D'omaine");
$dp = new Domain();
$FIRST["domain"] = getMaxItem("glpi_domains")+1;
for ($i=0 ; $i<$MAX['domain'] ; $i++) {
if (isset($items[$i])) {
$val = $items[$i];
} else {
$val = "domain $ID_entity '$i";
}
$dp->add(toolbox::addslashes_deep(array('name' => $val,
'entities_id' => $ID_entity,
'is_recursive' => 1,
'comment' => "comment $val")));
}
$LAST["domain"] = getMaxItem("glpi_domains");
// STATUS
$items = array("Reparation", "En stock", "En fonction", "Retour SAV", "En attente d'");
$dp = new State();
$FIRST["state"] = getMaxItem("glpi_states")+1;
for ($i=0 ; $i<$MAX['state'] ; $i++) {
if (isset($items[$i])) {
$val = $items[$i];
} else {
$val = "State $ID_entity '$i";
}
$state_id = $dp->add(toolbox::addslashes_deep(array('name' => $val,
'entities_id' => $ID_entity,
'is_recursive' => 1,
'comment' => "comment $val")));
// generate sub status
for ($j=0 ; $j<$MAX['state'] ; $j++) {
$val2 = "Sub $val $j";
$dp->add(toolbox::addslashes_deep(array('name' => $val2,
'entities_id' => $ID_entity,
'is_recursive' => 1,
'states_id' => $state_id,
'comment' => "comment $val")));
}
}
$LAST["state"] = getMaxItem("glpi_states");
// glpi_groups
$FIRST["groups"] = getMaxItem("glpi_groups")+1;
$group = new Group();
for ($i=0 ; $i<$MAX['groups'] ; $i++) {
$gID = $group->add(toolbox::addslashes_deep(
array('entities_id' => $ID_entity,
'name' => "group d'$i",
'comment' => "comment group d'$i",
'is_assign' => 0)));
// Generate sub group
for ($j=0 ; $j<$MAX['groups'] ; $j++) {
$group->add(toolbox::addslashes_deep(
array('entities_id' => $ID_entity,
'name' => "subgroup d'$j",
'comment' => "comment subgroup d'$j of group $i",
'groups_id' => $gID,
'is_assign' => 0)));
}
}
$LAST["groups"] = getMaxItem("glpi_groups");
$FIRST["techgroups"] = $LAST["groups"]+1;
for ($i=0 ; $i<$MAX['groups'] ; $i++) {
$group->add(toolbox::addslashes_deep(
array('entities_id' => $ID_entity,
'name' => "tech group d'$i",
'comment' => "comment tech group d'$i")));
}
$LAST["techgroups"] = getMaxItem("glpi_groups");
regenerateTreeCompleteName("glpi_groups");
// glpi_users
$FIRST["users_sadmin"] = getMaxItem("glpi_users")+1;
//.........这里部分代码省略.........
示例3: importPeripheral
/**
*
* Import peripherals from OCS
* @since 1.0
* @param $cfg_ocs OCSNG mode configuration
* @param $computers_id computer's id in GLPI
* @param $ocsid computer's id in OCS
* @param $ocsservers_id OCS server id
* @param $entity the entity in which the peripheral will be created
* @param $dohistory record in history link between peripheral and computer
*/
static function importPeripheral($cfg_ocs, $computers_id, $ocsservers_id, $ocsid, $entity, $dohistory)
{
global $PluginOcsinventoryngDBocs, $DB;
self::checkOCSconnection($ocsservers_id);
if ($cfg_ocs["import_periph"]) {
$already_processed = array();
$p = new Peripheral();
$conn = new Computer_Item();
$query = "SELECT DISTINCT `CAPTION`, `MANUFACTURER`, `INTERFACE`, `TYPE`\n FROM `inputs`\n WHERE `HARDWARE_ID` = '{$ocsid}'\n AND `CAPTION` <> ''";
$result = $PluginOcsinventoryngDBocs->query($query);
if ($PluginOcsinventoryngDBocs->numrows($result) > 0) {
while ($line = $PluginOcsinventoryngDBocs->fetch_array($result)) {
$line = Toolbox::clean_cross_side_scripting_deep(Toolbox::addslashes_deep($line));
$periph = array();
$periph["name"] = self::encodeOcsDataInUtf8($cfg_ocs["ocs_db_utf8"], $line["CAPTION"]);
//Look for a monitor with the same name (and serial if possible) already connected
//to this computer
$query = "SELECT `p`.`id`, `gci`.`is_deleted`\n FROM `glpi_printers` as `p`, `glpi_computers_items` as `gci`\n WHERE `p`.`id` = `gci`.`items_id`\n AND `gci`.`is_dynamic`='1'\n AND `computers_id`='{$computers_id}'\n AND `itemtype`='Peripheral'\n AND `p`.`name`='" . $periph["name"] . "'";
$results = $DB->query($query);
$id = false;
$lock = false;
if ($DB->numrows($results) > 0) {
$id = $DB->result($results, 0, 'id');
$lock = $DB->result($results, 0, 'is_deleted');
}
if (!$id) {
// Clean peripheral object
$p->reset();
if ($line["MANUFACTURER"] != "NULL") {
$periph["brand"] = self::encodeOcsDataInUtf8($cfg_ocs["ocs_db_utf8"], $line["MANUFACTURER"]);
}
if ($line["INTERFACE"] != "NULL") {
$periph["comment"] = self::encodeOcsDataInUtf8($cfg_ocs["ocs_db_utf8"], $line["INTERFACE"]);
}
$periph["peripheraltypes_id"] = Dropdown::importExternal('PeripheralType', $line["TYPE"]);
$id_periph = 0;
if ($cfg_ocs["import_periph"] == 1) {
//Config says : manage peripherals as global
//check if peripherals already exists in GLPI
$periph["is_global"] = 1;
$query = "SELECT `id`\n FROM `glpi_peripherals`\n WHERE `name` = '" . $periph["name"] . "'\n AND `is_global` = '1'\n AND `entities_id` = '{$entity}'";
$result_search = $DB->query($query);
if ($DB->numrows($result_search) > 0) {
//Periph is already in GLPI
//Do not import anything just get periph ID for link
$id_periph = $DB->result($result_search, 0, "id");
} else {
$input = $periph;
if ($cfg_ocs["states_id_default"] > 0) {
$input["states_id"] = $cfg_ocs["states_id_default"];
}
$input["entities_id"] = $entity;
$id_periph = $p->add($input);
}
} else {
if ($cfg_ocs["import_periph"] == 2) {
//Config says : manage peripherals as single units
//Import all peripherals as non global.
$input = $periph;
$input["is_global"] = 0;
if ($cfg_ocs["states_id_default"] > 0) {
$input["states_id"] = $cfg_ocs["states_id_default"];
}
$input["entities_id"] = $entity;
$id_periph = $p->add($input);
}
}
if ($id_periph) {
$already_processed[] = $id_periph;
$conn = new Computer_Item();
if ($connID = $conn->add(array('computers_id' => $computers_id, 'itemtype' => 'Peripheral', 'items_id' => $id_periph, '_no_history' => !$dohistory, 'is_dynamic' => 1))) {
//Update column "is_deleted" set value to 0 and set status to default
$input = array();
$input["id"] = $id_periph;
$input["is_deleted"] = 0;
$input["entities_id"] = $entity;
if ($cfg_ocs["states_id_default"] > 0) {
$input["states_id"] = $cfg_ocs["states_id_default"];
}
$p->update($input);
}
}
} else {
$already_processed[] = $id;
}
}
}
//Look for all monitors, not locked, not linked to the computer anymore
$query = "SELECT `id`\n FROM `glpi_computers_items`\n WHERE `itemtype`='Peripheral'\n AND `computers_id`='{$computers_id}'\n AND `is_dynamic`='1'\n AND `is_deleted`='0'";
//.........这里部分代码省略.........
示例4: methodLinkObjects
/**
* Link inventory object to another one
*
* @param $params the input parameters
* @param $protocol the commonication protocol used
*
**/
static function methodLinkObjects($params, $protocol)
{
global $CFG_GLPI;
if (isset($params['help'])) {
return array('fields' => 'array, mandatory', 'help' => 'bool, optional');
}
if (!Session::getLoginUserID()) {
return self::Error($protocol, WEBSERVICES_ERROR_NOTAUTHENTICATED);
}
//Must be superadmin to use this method
if (!Session::haveRight('config', UPDATE)) {
return self::Error($protocol, WEBSERVICES_ERROR_NOTALLOWED);
}
if (!isset($params['fields']) || empty($params['fields']) || !is_array($params['fields'])) {
return self::Error($protocol, WEBSERVICES_ERROR_MISSINGPARAMETER, '', 'fields');
}
if (!isset($_SESSION["glpi_currenttime"])) {
$_SESSION["glpi_currenttime"] = date("Y-m-d H:i:s");
}
$resp = array();
$errors = array();
foreach ($params['fields'] as $links) {
if (!in_array($links['from_item']['itemtype'], array('Computer')) && !preg_match("/Device/", $links['from_item']['itemtype'])) {
$errors[] = self::Error($protocol, WEBSERVICES_ERROR_NOTALLOWED, '', self::getDisplayError());
}
switch ($links['from_item']['itemtype']) {
case 'Computer':
// Direct connections
if (in_array($links['to_item']['itemtype'], array('Monitor', 'Peripheral', 'Phone', 'Printer'))) {
$comp_item = new Computer_Item();
$data = array();
$data['items_id'] = $links['to_item']['id'];
$data['computers_id'] = $links['from_item']['id'];
$data['itemtype'] = $links['to_item']['itemtype'];
if (!$comp_item->can(-1, UPDATE, $data)) {
$errors[] = self::Error($protocol, WEBSERVICES_ERROR_NOTALLOWED, '', self::getDisplayError());
} else {
if ($comp_item->add($data)) {
$resp['Computer'][$data['computers_id']] = self::methodGetObject(array('itemtype' => 'Computer', 'id' => $data['computers_id'], 'with_printer' => 1, 'with_monitor' => 1, 'with_phone' => 1, 'with_peripheral' => 1), $protocol);
} else {
$errors[] = self::Error($protocol, WEBSERVICES_ERROR_FAILED, '', self::getDisplayError());
}
}
}
// Device connection
if (preg_match("/Device/", $links['to_item']['itemtype'])) {
$comp_device = new Computer_Device();
$links_field = getPlural(strtolower($links['to_item']['itemtype'])) . "_id";
$data = array();
$data['computers_id'] = $links['from_item']['id'];
$data[$links_field] = $links['to_item']['id'];
$data['itemtype'] = $links['to_item']['itemtype'];
if (!isset($links['to_item']['quantity']) || !is_numeric($links['to_item']['quantity'])) {
$quantity = 1;
} else {
$quantity = $links['to_item']['quantity'];
}
if (isset($links['to_item']['specificity'])) {
if (!is_numeric($links['to_item']['specificity'])) {
$errors[] = self::Error($protocol, WEBSERVICES_ERROR_MISSINGPARAMETER, '', 'specificity');
} else {
$data['specificity'] = $links['to_item']['specificity'];
}
}
$linked = false;
for ($i = 0; $i < $quantity; $i++) {
if (!$comp_device->can(-1, UPDATE, $data)) {
$errors[] = self::Error($protocol, WEBSERVICES_ERROR_NOTALLOWED, '', self::getDisplayError());
} else {
if ($comp_device->add($data)) {
$linked = true;
}
}
}
if ($linked) {
$resp['Computer'][$data['computers_id']] = self::methodGetObject(array('itemtype' => 'Computer', 'id' => $data['computers_id']), $protocol);
} else {
$errors[] = self::Error($protocol, WEBSERVICES_ERROR_FAILED, '', self::getDisplayError());
}
}
//other link object
break;
//itemtype
}
}
if (count($errors)) {
$resp = array($resp, $errors);
}
return $resp;
}
示例5: array
$input = array('computers_id' => $key, 'itemtype' => $_POST["itemtype"], 'items_id' => $_POST["connect_item"]);
if ($conn->can(-1, 'w', $input)) {
$conn->add($input);
}
}
}
}
break;
case "connect":
if (isset($_POST["connect_item"]) && $_POST["connect_item"]) {
$conn = new Computer_Item();
foreach ($_POST["item"] as $key => $val) {
if ($val == 1) {
$input = array('computers_id' => $_POST["connect_item"], 'itemtype' => $_POST["itemtype"], 'items_id' => $key);
if ($conn->can(-1, 'w', $input)) {
$conn->add($input);
}
}
}
}
break;
case "disconnect":
$conn = new Computer_Item();
foreach ($_POST["item"] as $key => $val) {
if ($val == 1) {
if ($item->getFromDB($key)) {
$conn->disconnectForItem($item);
}
}
}
break;
示例6: sprintf
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GLPI. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
/** @file
* @brief
* @since version 0.84
*/
include '../inc/includes.php';
Session::checkCentralAccess();
$conn = new Computer_Item();
if (isset($_POST["disconnect"])) {
$conn->check($_POST["id"], PURGE);
$conn->delete($_POST, 1);
Event::log($_POST["computers_id"], "computers", 5, "inventory", sprintf(__('%s disconnects an item'), $_SESSION["glpiname"]));
Html::back();
// Connect a computer to a printer/monitor/phone/peripheral
} else {
if (isset($_POST["add"])) {
if (isset($_POST["items_id"]) && $_POST["items_id"] > 0) {
$conn->check(-1, CREATE, $_POST);
if ($newID = $conn->add($_POST)) {
Event::log($_POST["computers_id"], "computers", 5, "inventory", sprintf(__('%s connects an item'), $_SESSION["glpiname"]));
}
}
Html::back();
}
}
Html::displayErrorAndDie('Lost');
示例7: updateComputer
/**
* Update computer data
*
* @global type $DB
*
* @param php array $a_computerinventory all data from the agent
* @param integer $computers_id id of the computer
* @param boolean $no_history set true if not want history
*
* @return nothing
*/
function updateComputer($a_computerinventory, $computers_id, $no_history, $setdynamic = 0)
{
global $DB, $CFG_GLPI;
$computer = new Computer();
$pfInventoryComputerComputer = new PluginFusioninventoryInventoryComputerComputer();
$item_DeviceProcessor = new Item_DeviceProcessor();
$deviceProcessor = new DeviceProcessor();
$item_DeviceMemory = new Item_DeviceMemory();
$deviceMemory = new DeviceMemory();
$computerVirtualmachine = new ComputerVirtualMachine();
$computerDisk = new ComputerDisk();
$item_DeviceControl = new Item_DeviceControl();
$item_DeviceHardDrive = new Item_DeviceHardDrive();
$item_DeviceDrive = new Item_DeviceDrive();
$item_DeviceGraphicCard = new Item_DeviceGraphicCard();
$item_DeviceNetworkCard = new Item_DeviceNetworkCard();
$item_DeviceSoundCard = new Item_DeviceSoundCard();
$networkPort = new NetworkPort();
$networkName = new NetworkName();
$iPAddress = new IPAddress();
$ipnetwork = new IPNetwork();
$pfInventoryComputerAntivirus = new PluginFusioninventoryInventoryComputerAntivirus();
$pfConfig = new PluginFusioninventoryConfig();
$pfComputerLicenseInfo = new PluginFusioninventoryComputerLicenseInfo();
$computer_Item = new Computer_Item();
$monitor = new Monitor();
$printer = new Printer();
$peripheral = new Peripheral();
// $pfInventoryComputerStorage = new PluginFusioninventoryInventoryComputerStorage();
// $pfInventoryComputerStorage_Storage =
// new PluginFusioninventoryInventoryComputerStorage_Storage();
$computer->getFromDB($computers_id);
$a_lockable = PluginFusioninventoryLock::getLockFields('glpi_computers', $computers_id);
// * Computer
$db_computer = array();
$db_computer = $computer->fields;
$computerName = $a_computerinventory['Computer']['name'];
$a_ret = PluginFusioninventoryToolbox::checkLock($a_computerinventory['Computer'], $db_computer, $a_lockable);
$a_computerinventory['Computer'] = $a_ret[0];
$input = $a_computerinventory['Computer'];
$input['id'] = $computers_id;
$history = TRUE;
if ($no_history) {
$history = FALSE;
}
$input['_no_history'] = $no_history;
PluginFusioninventoryInventoryComputerInventory::addDefaultStateIfNeeded($input);
$computer->update($input, !$no_history);
$this->computer = $computer;
// * Computer fusion (ext)
$db_computer = array();
if ($no_history === FALSE) {
$query = "SELECT * FROM `glpi_plugin_fusioninventory_inventorycomputercomputers`\n WHERE `computers_id` = '{$computers_id}'\n LIMIT 1";
$result = $DB->query($query);
while ($data = $DB->fetch_assoc($result)) {
foreach ($data as $key => $value) {
$data[$key] = Toolbox::addslashes_deep($value);
}
$db_computer = $data;
}
}
if (count($db_computer) == '0') {
// Add
$a_computerinventory['fusioninventorycomputer']['computers_id'] = $computers_id;
$pfInventoryComputerComputer->add($a_computerinventory['fusioninventorycomputer'], array(), FALSE);
} else {
// Update
if (!empty($db_computer['serialized_inventory'])) {
$setdynamic = 0;
}
$idtmp = $db_computer['id'];
unset($db_computer['id']);
unset($db_computer['computers_id']);
$a_ret = PluginFusioninventoryToolbox::checkLock($a_computerinventory['fusioninventorycomputer'], $db_computer);
$a_computerinventory['fusioninventorycomputer'] = $a_ret[0];
$db_computer = $a_ret[1];
$input = $a_computerinventory['fusioninventorycomputer'];
$input['id'] = $idtmp;
$input['_no_history'] = $no_history;
$pfInventoryComputerComputer->update($input, !$no_history);
}
// Put all link item dynamic (in case of update computer not yet inventoried with fusion)
if ($setdynamic == 1) {
$this->setDynamicLinkItems($computers_id);
}
// * Processors
if ($pfConfig->getValue("component_processor") != 0) {
$db_processors = array();
if ($no_history === FALSE) {
//.........这里部分代码省略.........
示例8: cloneComputer
/**
* Duplicate connected items to computer from an item template to its clone
*
* @since version 0.84
*
* @param $oldid ID of the item to clone
* @param $newid ID of the item cloned
**/
static function cloneComputer($oldid, $newid)
{
global $DB;
$query = "SELECT *\n FROM `glpi_computers_items`\n WHERE `computers_id` = '" . $oldid . "';";
$result = $DB->query($query);
foreach ($DB->request($query) as $data) {
$conn = new Computer_Item();
$conn->add(array('computers_id' => $newid, 'itemtype' => $data["itemtype"], 'items_id' => $data["items_id"]));
}
}
示例9: Infocom
function post_addItem()
{
global $DB;
// Manage add from template
if (isset($this->input["_oldID"])) {
// ADD Devices
$compdev = new Computer_Device();
$compdev->cloneComputer($this->input["_oldID"], $this->fields['id']);
// ADD Infocoms
$ic = new Infocom();
$ic->cloneItem($this->getType(), $this->input["_oldID"], $this->fields['id']);
// ADD volumes
$query = "SELECT `id`\n FROM `glpi_computerdisks`\n WHERE `computers_id` = '" . $this->input["_oldID"] . "'";
$result = $DB->query($query);
if ($DB->numrows($result) > 0) {
while ($data = $DB->fetch_array($result)) {
$disk = new ComputerDisk();
$disk->getfromDB($data['id']);
unset($disk->fields["id"]);
$disk->fields["computers_id"] = $this->fields['id'];
$disk->addToDB();
}
}
// ADD software
$inst = new Computer_SoftwareVersion();
$inst->cloneComputer($this->input["_oldID"], $this->fields['id']);
$inst = new Computer_SoftwareLicense();
$inst->cloneComputer($this->input["_oldID"], $this->fields['id']);
// ADD Contract
$query = "SELECT `contracts_id`\n FROM `glpi_contracts_items`\n WHERE `items_id` = '" . $this->input["_oldID"] . "'\n AND `itemtype` = '" . $this->getType() . "';";
$result = $DB->query($query);
if ($DB->numrows($result) > 0) {
$contractitem = new Contract_Item();
while ($data = $DB->fetch_array($result)) {
$contractitem->add(array('contracts_id' => $data["contracts_id"], 'itemtype' => $this->getType(), 'items_id' => $this->fields['id']));
}
}
// ADD Documents
$query = "SELECT `documents_id`\n FROM `glpi_documents_items`\n WHERE `items_id` = '" . $this->input["_oldID"] . "'\n AND `itemtype` = '" . $this->getType() . "';";
$result = $DB->query($query);
if ($DB->numrows($result) > 0) {
$docitem = new Document_Item();
while ($data = $DB->fetch_array($result)) {
$docitem->add(array('documents_id' => $data["documents_id"], 'itemtype' => $this->getType(), 'items_id' => $this->fields['id']));
}
}
// ADD Ports
$query = "SELECT `id`\n FROM `glpi_networkports`\n WHERE `items_id` = '" . $this->input["_oldID"] . "'\n AND `itemtype` = '" . $this->getType() . "';";
$result = $DB->query($query);
if ($DB->numrows($result) > 0) {
while ($data = $DB->fetch_array($result)) {
$np = new NetworkPort();
$npv = new NetworkPort_Vlan();
$np->getFromDB($data["id"]);
unset($np->fields["id"]);
unset($np->fields["ip"]);
unset($np->fields["mac"]);
unset($np->fields["netpoints_id"]);
$np->fields["items_id"] = $this->fields['id'];
$portid = $np->addToDB();
foreach ($DB->request('glpi_networkports_vlans', array('networkports_id' => $data["id"])) as $vlan) {
$npv->assignVlan($portid, $vlan['vlans_id']);
}
}
}
// Add connected devices
$query = "SELECT *\n FROM `glpi_computers_items`\n WHERE `computers_id` = '" . $this->input["_oldID"] . "';";
$result = $DB->query($query);
if ($DB->numrows($result) > 0) {
$conn = new Computer_Item();
while ($data = $DB->fetch_array($result)) {
$conn->add(array('computers_id' => $this->fields['id'], 'itemtype' => $data["itemtype"], 'items_id' => $data["items_id"]));
}
}
}
}
示例10: importPeripheral
/**
*
* Import peripherals from OCS
* @since 1.0
* @param $cfg_ocs OCSNG mode configuration
* @param $computers_id computer's id in GLPI
* @param $ocsid computer's id in OCS
* @param $ocsservers_id OCS server id
* @param $entity the entity in which the peripheral will be created
* @param $dohistory record in history link between peripheral and computer
*/
static function importPeripheral($cfg_ocs, $computers_id, $ocsservers_id, $ocsComputer, $entity, $dohistory)
{
global $DB;
$already_processed = array();
$p = new Peripheral();
$conn = new Computer_Item();
if (isset($ocsComputer["INPUTS"])) {
if (count($ocsComputer["INPUTS"]) > 0) {
foreach ($ocsComputer["INPUTS"] as $peripheral) {
if ($peripheral["CAPTION"] !== '') {
$peripherals[] = $peripheral;
}
}
if (count($peripherals) > 0) {
foreach ($peripherals as $peripheral) {
$peripheral = Toolbox::clean_cross_side_scripting_deep(Toolbox::addslashes_deep($peripheral));
$periph = array();
$periph["name"] = self::encodeOcsDataInUtf8($cfg_ocs["ocs_db_utf8"], $peripheral["CAPTION"]);
//Look for a monitor with the same name (and serial if possible) already connected
//to this computer
$query = "SELECT `p`.`id`, `gci`.`is_deleted`\n FROM `glpi_printers` as `p`, `glpi_computers_items` as `gci`\n WHERE `p`.`id` = `gci`.`items_id`\n AND `gci`.`is_dynamic`='1'\n AND `computers_id`='{$computers_id}'\n AND `itemtype`='Peripheral'\n AND `p`.`name`='" . $periph["name"] . "'";
$results = $DB->query($query);
$id = false;
$lock = false;
if ($DB->numrows($results) > 0) {
$id = $DB->result($results, 0, 'id');
$lock = $DB->result($results, 0, 'is_deleted');
}
if (!$id) {
// Clean peripheral object
$p->reset();
if ($peripheral["MANUFACTURER"] != "NULL") {
$periph["brand"] = self::encodeOcsDataInUtf8($cfg_ocs["ocs_db_utf8"], $peripheral["MANUFACTURER"]);
}
if ($peripheral["INTERFACE"] != "NULL") {
$periph["comment"] = self::encodeOcsDataInUtf8($cfg_ocs["ocs_db_utf8"], $peripheral["INTERFACE"]);
}
$periph["peripheraltypes_id"] = Dropdown::importExternal('PeripheralType', $peripheral["TYPE"]);
$id_periph = 0;
if ($cfg_ocs["import_periph"] == 1) {
//Config says : manage peripherals as global
//check if peripherals already exists in GLPI
$periph["is_global"] = 1;
$query = "SELECT `id`\n FROM `glpi_peripherals`\n WHERE `name` = '" . $periph["name"] . "'\n AND `is_global` = '1'\n AND `entities_id` = '{$entity}'";
$result_search = $DB->query($query);
if ($DB->numrows($result_search) > 0) {
//Periph is already in GLPI
//Do not import anything just get periph ID for link
$id_periph = $DB->result($result_search, 0, "id");
} else {
$input = $periph;
if ($cfg_ocs["states_id_default"] > 0) {
$input["states_id"] = $cfg_ocs["states_id_default"];
}
$input["entities_id"] = $entity;
$id_periph = $p->add($input);
}
} else {
if ($cfg_ocs["import_periph"] == 2) {
//Config says : manage peripherals as single units
//Import all peripherals as non global.
$input = $periph;
$input["is_global"] = 0;
if ($cfg_ocs["states_id_default"] > 0) {
$input["states_id"] = $cfg_ocs["states_id_default"];
}
$input["entities_id"] = $entity;
$id_periph = $p->add($input);
}
}
if ($id_periph) {
$already_processed[] = $id_periph;
$conn = new Computer_Item();
if ($connID = $conn->add(array('computers_id' => $computers_id, 'itemtype' => 'Peripheral', 'items_id' => $id_periph, '_no_history' => !$dohistory, 'is_dynamic' => 1))) {
//Update column "is_deleted" set value to 0 and set status to default
$input = array();
$input["id"] = $id_periph;
$input["is_deleted"] = 0;
$input["entities_id"] = $entity;
if ($cfg_ocs["states_id_default"] > 0) {
$input["states_id"] = $cfg_ocs["states_id_default"];
}
$p->update($input);
}
}
} else {
$already_processed[] = $id;
}
}
//.........这里部分代码省略.........
示例11: sprintf
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 GLPI. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
/** @file
* @brief
* @since version 0.84
*/
include '../inc/includes.php';
Session::checkCentralAccess();
$conn = new Computer_Item();
if (isset($_POST["disconnect"])) {
$conn->check($_POST["id"], 'd');
$conn->delete($_POST);
Event::log($_POST["computers_id"], "computers", 5, "inventory", sprintf(__('%s disconnects an item'), $_SESSION["glpiname"]));
Html::back();
// Connect a computer to a printer/monitor/phone/peripheral
} else {
if (isset($_POST["add"])) {
if (isset($_POST["items_id"]) && $_POST["items_id"] > 0) {
$conn->check(-1, 'w', $_POST);
$conn->add($_POST);
Event::log($_POST["computers_id"], "computers", 5, "inventory", sprintf(__('%s connects an item'), $_SESSION["glpiname"]));
}
Html::back();
}
}
Html::displayErrorAndDie('Lost');
示例12: updatePeripherals
/**
* Import the devices for a computer
*
* @param $itemtype integer : item type
* @param $entity integer : entity of the computer
* @param $computers_id integer : glpi computer id.
* @param $ocsid integer : ocs computer id (ID).
* @param $ocsservers_id integer : ocs server id
* @param $cfg_ocs array : ocs config
* @param $import_periph array : already imported periph
* @param $dohistory boolean : log changes ?
*
* @return Nothing (void).
**/
static function updatePeripherals($itemtype, $entity, $computers_id, $ocsid, $ocsservers_id, $cfg_ocs, $import_periph, $dohistory)
{
global $DB, $DBocs;
self::checkOCSconnection($ocsservers_id);
$do_clean = false;
$connID = 0;
//Tag for data since 0.70 for the import_monitor array.
$count_monitor = count($import_periph);
switch ($itemtype) {
case 'Monitor':
if ($cfg_ocs["import_monitor"]) {
//Update data in import_monitor array for 0.70
if (!in_array(self::IMPORT_TAG_070, $import_periph)) {
foreach ($import_periph as $key => $val) {
$monitor_tag = $val;
//delete old value
self::deleteInOcsArray($computers_id, $key, "import_monitor");
//search serial when it exists
$monitor_serial = "";
$query_monitor_id = "SELECT `items_id`\n FROM `glpi_computers_items`\n WHERE `id` = '{$key}'";
$result_monitor_id = $DB->query($query_monitor_id);
if ($DB->numrows($result_monitor_id) == 1) {
//get monitor Id
$id_monitor = $DB->result($result_monitor_id, 0, "items_id");
$query_monitor_serial = "SELECT `serial`\n FROM `glpi_monitors`\n WHERE `id` = '{$id_monitor}'";
$result_monitor_serial = $DB->query($query_monitor_serial);
//get serial
if ($DB->numrows($result_monitor_serial) == 1) {
$monitor_serial = $DB->result($result_monitor_serial, 0, "serial");
}
}
//concat name + serial
$monitor_tag .= $monitor_serial;
//add new value (serial + name when its possible)
self::addToOcsArray($computers_id, array($key => $monitor_tag), "import_monitor");
//Update the array with the new value of the monitor
$import_periph[$key] = $monitor_tag;
}
//add the tag for the array version's
self::addToOcsArray($computers_id, array(0 => self::IMPORT_TAG_070), "import_monitor");
}
$do_clean = true;
$m = new Monitor();
$query = "SELECT DISTINCT `CAPTION`, `MANUFACTURER`, `DESCRIPTION`, `SERIAL`, `TYPE`\n FROM `monitors`\n WHERE `HARDWARE_ID` = '{$ocsid}'";
$result = $DBocs->query($query);
$lines = array();
$checkserial = true;
// First pass - check if all serial present
if ($DBocs->numrows($result) > 0) {
while ($line = $DBocs->fetch_array($result)) {
if (empty($line["SERIAL"])) {
$checkserial = false;
}
$lines[] = clean_cross_side_scripting_deep(addslashes_deep($line));
}
}
if (count($lines) > 0 && ($cfg_ocs["import_monitor"] <= 2 || $checkserial)) {
foreach ($lines as $line) {
$mon = array();
$mon["name"] = $line["CAPTION"];
if (empty($line["CAPTION"]) && !empty($line["MANUFACTURER"])) {
$mon["name"] = $line["MANUFACTURER"];
}
if (empty($line["CAPTION"]) && !empty($line["TYPE"])) {
if (!empty($line["MANUFACTURER"])) {
$mon["name"] .= " ";
}
$mon["name"] .= $line["TYPE"];
}
$mon["serial"] = $line["SERIAL"];
$checkMonitor = $mon["name"];
if (!empty($mon["serial"])) {
$checkMonitor .= $mon["serial"];
}
if (!empty($mon["name"])) {
$id = array_search(stripslashes($checkMonitor), $import_periph);
}
if ($id === false) {
// Clean monitor object
$m->reset();
$mon["manufacturers_id"] = Dropdown::importExternal('Manufacturer', $line["MANUFACTURER"]);
if ($cfg_ocs["import_monitor_comment"]) {
$mon["comment"] = $line["DESCRIPTION"];
}
$id_monitor = 0;
if ($cfg_ocs["import_monitor"] == 1) {
//.........这里部分代码省略.........