本文整理汇总了PHP中Dropdown::importExternal方法的典型用法代码示例。如果您正苦于以下问题:PHP Dropdown::importExternal方法的具体用法?PHP Dropdown::importExternal怎么用?PHP Dropdown::importExternal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dropdown
的用法示例。
在下文中一共展示了Dropdown::importExternal方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: executeActions
function executeActions($output, $params)
{
if (count($this->actions)) {
foreach ($this->actions as $action) {
switch ($action->fields["action_type"]) {
case "assign":
$output[$action->fields["field"]] = $action->fields["value"];
break;
case "regex_result":
//Regex result : assign value from the regex
$res = "";
if (isset($this->regex_results[0])) {
$res .= RuleAction::getRegexResultById($action->fields["value"], $this->regex_results[0]);
} else {
$res .= $action->fields["value"];
}
if ($res != '' && ($action->fields["field"] != 'user' && $action->fields["field"] != 'otherserial' && $action->fields["field"] != 'software' && $action->fields["field"] != 'softwareversion')) {
$res = Dropdown::importExternal(getItemTypeForTable(getTableNameForForeignKeyField($action->fields['field'])), $res);
}
$output[$action->fields["field"]] = $res;
break;
default:
//plugins actions
$executeaction = clone $this;
$ouput = $executeaction->executePluginsActions($action, $output, $params);
break;
}
}
}
return $output;
}
示例2: replayRulesOnExistingDBForModel
/**
* Replay collection rules on an existing DB for model dropdowns
*
* @param $offset offset used to begin (default 0)
* @param $maxtime maximum time of process (reload at the end) (default 0)
*
* @return -1 on completion else current offset
**/
function replayRulesOnExistingDBForModel($offset = 0, $maxtime = 0)
{
global $DB;
if (isCommandLine()) {
printf(__('Replay rules on existing database started on %s') . "\n", date("r"));
}
// Model check : need to check using manufacturer extra data
if (strpos($this->item_table, 'models') === false) {
_e('Error replaying rules');
return false;
}
$model_table = getPlural(str_replace('models', '', $this->item_table));
$model_field = getForeignKeyFieldForTable($this->item_table);
// Need to give manufacturer from item table
$Sql = "SELECT DISTINCT `glpi_manufacturers`.`id` AS idmanu,\n `glpi_manufacturers`.`name` AS manufacturer,\n `" . $this->item_table . "`.`id`,\n `" . $this->item_table . "`.`name` AS name,\n `" . $this->item_table . "`.`comment`\n FROM `" . $this->item_table . "`,\n `{$model_table}`\n LEFT JOIN `glpi_manufacturers`\n ON (`{$model_table}`.`manufacturers_id` = `glpi_manufacturers`.`id`)\n WHERE `{$model_table}`.`{$model_field}` = `" . $this->item_table . "`.`id`";
if ($offset) {
$Sql .= " LIMIT " . intval($offset) . ",999999999";
}
$result = $DB->query($Sql);
$nb = $DB->numrows($result) + $offset;
$i = $offset;
if ($result && $nb > $offset) {
// Step to refresh progressbar
$step = $nb > 20 ? floor($nb / 20) : 1;
$tocheck = array();
while ($data = $DB->fetch_assoc($result)) {
if (!($i % $step)) {
if (isCommandLine()) {
printf(__('Replay rules on existing database: %1$s/%2$s') . "\r", $i, $nb);
} else {
Html::changeProgressBarPosition($i, $nb, "{$i} / {$nb}");
}
}
// Model case
if (isset($data["manufacturer"])) {
$data["manufacturer"] = Manufacturer::processName(addslashes($data["manufacturer"]));
}
//Replay Type dictionnary
$ID = Dropdown::importExternal(getItemTypeForTable($this->item_table), addslashes($data["name"]), -1, $data, addslashes($data["comment"]));
if ($data['id'] != $ID) {
$tocheck[$data["id"]][] = $ID;
$sql = "UPDATE `{$model_table}`\n SET `{$model_field}` = '{$ID}'\n WHERE `{$model_field}` = '" . $data['id'] . "'";
if (empty($data['idmanu'])) {
$sql .= " AND (`manufacturers_id` IS NULL\n OR `manufacturers_id` = '0')";
} else {
$sql .= " AND `manufacturers_id` = '" . $data['idmanu'] . "'";
}
$DB->query($sql);
}
$i++;
if ($maxtime) {
$crt = explode(" ", microtime());
if ($crt[0] + $crt[1] > $maxtime) {
break;
}
}
}
foreach ($tocheck as $ID => $tab) {
$sql = "SELECT COUNT(*)\n FROM `{$model_table}`\n WHERE `{$model_field}` = '{$ID}'";
$result = $DB->query($sql);
$deletecartmodel = false;
// No item left : delete old item
if ($result && $DB->result($result, 0, 0) == 0) {
$Sql = "DELETE\n FROM `" . $this->item_table . "`\n WHERE `id` = '{$ID}'";
$resdel = $DB->query($Sql);
$deletecartmodel = true;
}
// Manage cartridge assoc Update items
if ($this->getRuleClassName() == 'RuleDictionnaryPrinterModel') {
$sql = "SELECT *\n FROM `glpi_cartridgeitems_printermodels`\n WHERE `printermodels_id` = '{$ID}'";
if ($result = $DB->query($sql)) {
if ($DB->numrows($result)) {
// Get compatible cartridge type
$carttype = array();
while ($data = $DB->fetch_assoc($result)) {
$carttype[] = $data['cartridgeitems_id'];
}
// Delete cartrodges_assoc
if ($deletecartmodel) {
$sql = "DELETE\n FROM `glpi_cartridgeitems_printermodels`\n WHERE `printermodels_id` = 'id'";
$DB->query($sql);
}
// Add new assoc
$ct = new CartridgeItem();
foreach ($carttype as $cartID) {
foreach ($tab as $model) {
$ct->addCompatibleType($cartID, $model);
}
}
}
}
}
//.........这里部分代码省略.........
示例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: updateDB
/**
* Update an existing preloaded switch with the instance values
*
*@return nothing
**/
function updateDB()
{
if (array_key_exists('model', $this->ptcdUpdates)) {
$manufacturer = Dropdown::getDropdownName("glpi_dropdown_manufacturer", $this->getValue('FK_glpi_enterprise'));
$this->ptcdUpdates['model'] = Dropdown::importExternal("NetworkEquipmentModel", $this->ptcdUpdates['model'], 0, array('manufacturer' => $manufacturer));
}
if (array_key_exists('firmware', $this->ptcdUpdates)) {
$this->ptcdUpdates['firmware'] = Dropdown::importExternal("NetworkEquipmentFirmware", $this->ptcdUpdates['firmware']);
}
if (array_key_exists('location', $this->ptcdUpdates)) {
$this->ptcdUpdates['location'] = Dropdown::importExternal("Location", $this->ptcdUpdates['location']);
}
parent::updateDB();
// update last_fusioninventory_update even if no other update
$this->setValue('last_fusioninventory_update', date("Y-m-d H:i:s"));
$this->oFusionInventory_networking->updateDB();
// ports
$this->savePorts();
}
示例5: findWithGlobalCriteria
/**
* @see Rule::findWithGlobalCriteria()
**/
function findWithGlobalCriteria($input)
{
global $DB, $PLUGIN_HOOKS;
$complex_criterias = array();
$sql_where = '';
$sql_from = '';
$continue = true;
$global_criteria = array('manufacturer', 'model', 'name', 'serial');
//Add plugin global criteria
if (isset($PLUGIN_HOOKS['use_rules'])) {
foreach ($PLUGIN_HOOKS['use_rules'] as $plugin => $val) {
if (is_array($val) && in_array($this->getType(), $val)) {
$global_criteria = Plugin::doOneHook($plugin, "ruleImportComputer_addGlobalCriteria", $global_criteria);
}
}
}
foreach ($global_criteria as $criterion) {
$criteria = $this->getCriteriaByID($criterion);
if (!empty($criteria)) {
foreach ($criteria as $crit) {
// is a real complex criteria
if ($crit->fields["condition"] == Rule::PATTERN_FIND) {
if (!isset($input[$criterion]) || $input[$criterion] == '') {
$continue = false;
} else {
$complex_criterias[] = $crit;
}
}
}
}
}
foreach ($this->getCriteriaByID('states_id') as $crit) {
$complex_criterias[] = $crit;
}
//If a value is missing, then there's a problem !
if (!$continue) {
return false;
}
//No complex criteria
if (empty($complex_criterias)) {
return true;
}
//Build the request to check if the machine exists in GLPI
if (is_array($input['entities_id'])) {
$where_entity = implode($input['entities_id'], ',');
} else {
$where_entity = $input['entities_id'];
}
$sql_where = '1';
$sql_from = '';
$needport = false;
$needip = false;
foreach ($complex_criterias as $criteria) {
switch ($criteria->fields['criteria']) {
case 'name':
if ($criteria->fields['condition'] == Rule::PATTERN_IS_EMPTY) {
$sql_where .= " AND (`glpi_computers`.`name`=''\n OR `glpi_computers`.`name` IS NULL) ";
} else {
$sql_where .= " AND (`glpi_computers`.`name`='" . $input['name'] . "') ";
}
break;
case 'serial':
$sql_where .= " AND `glpi_computers`.`serial`='" . $input["serial"] . "'";
break;
case 'model':
// search for model, don't create it if not found
$options = array('manufacturer' => addslashes($input['manufacturer']));
$mid = Dropdown::importExternal('ComputerModel', addslashes($input['model']), -1, $options, '', false);
$sql_where .= " AND `glpi_computers`.`computermodels_id` = '{$mid}'";
break;
case 'manufacturer':
// search for manufacturer, don't create it if not found
$mid = Dropdown::importExternal('Manufacturer', addslashes($input['manufacturer']), -1, array(), '', false);
$sql_where .= " AND `glpi_computers`.`manufacturers_id` = '{$mid}'";
break;
case 'states_id':
if ($criteria->fields['condition'] == Rule::PATTERN_IS) {
$condition = " IN ";
} else {
$condition = " NOT IN ";
}
$sql_where .= " AND `glpi_computers`.`states_id`\n {$condition} ('" . $criteria->fields['pattern'] . "')";
break;
}
}
if (isset($PLUGIN_HOOKS['use_rules'])) {
foreach ($PLUGIN_HOOKS['use_rules'] as $plugin => $val) {
if (is_array($val) && in_array($this->getType(), $val)) {
$params = array('where_entity' => $where_entity, 'input' => $input, 'criteria' => $complex_criterias, 'sql_where' => $sql_where, 'sql_from' => $sql_from);
$sql_results = Plugin::doOneHook($plugin, "ruleImportComputer_getSqlRestriction", $params);
$sql_where = $sql_results['sql_where'];
$sql_from = $sql_results['sql_from'];
}
}
}
$sql_glpi = "SELECT `glpi_computers`.`id`\n FROM {$sql_from}\n WHERE {$sql_where}\n ORDER BY `glpi_computers`.`is_deleted` ASC";
$result_glpi = $DB->query($sql_glpi);
//.........这里部分代码省略.........
示例6: getFromLDAP
/**
* Function that try to load from LDAP the user information...
*
* @param $ldap_connection ldap connection descriptor
* @param $ldap_method LDAP method
* @param $userdn Basedn of the user
* @param $login User Login
*
* @return String : basedn of the user / false if not founded
**/
function getFromLDAP($ldap_connection, $ldap_method, $userdn, $login)
{
global $DB, $CFG_GLPI;
// we prevent some delay...
if (empty($ldap_method["host"])) {
return false;
}
if ($ldap_connection) {
//Set all the search fields
$this->fields['password'] = "";
$fields = AuthLDAP::getSyncFields($ldap_method);
$fields = array_filter($fields);
$f = array_values($fields);
$sr = @ldap_read($ldap_connection, $userdn, "objectClass=*", $f);
$v = ldap_get_entries_clean($ldap_connection, $sr);
if (!is_array($v) || count($v) == 0 || empty($v[0][$fields['name']][0])) {
return false;
}
//Store user's dn
$this->fields['user_dn'] = addslashes($userdn);
//Store date_sync
$this->fields['date_sync'] = $_SESSION['glpi_currenttime'];
foreach ($fields as $k => $e) {
if (empty($v[0][$e][0])) {
switch ($k) {
case "language":
// Not set value : managed but user class
break;
case "usertitles_id":
case "usercategories_id":
$this->fields[$k] = 0;
break;
default:
$this->fields[$k] = "";
}
} else {
switch ($k) {
case "language":
$language = Config::getLanguage($v[0][$e][0]);
if ($language != '') {
$this->fields[$k] = $language;
}
break;
case "usertitles_id":
$this->fields[$k] = Dropdown::importExternal('UserTitle', addslashes($v[0][$e][0]));
break;
case "usercategories_id":
$this->fields[$k] = Dropdown::importExternal('UserCategory', addslashes($v[0][$e][0]));
break;
default:
if (!empty($v[0][$e][0])) {
$this->fields[$k] = addslashes($v[0][$e][0]);
} else {
$this->fields[$k] = "";
}
}
}
}
// Empty array to ensure than syncLdapGroups will be done
$this->fields["_groups"] = array();
///The groups are retrieved by looking into an ldap user object
if ($ldap_method["group_search_type"] == 0 || $ldap_method["group_search_type"] == 2) {
$this->getFromLDAPGroupVirtual($ldap_connection, $ldap_method, $userdn, $login);
}
///The groups are retrived by looking into an ldap group object
if ($ldap_method["group_search_type"] == 1 || $ldap_method["group_search_type"] == 2) {
$this->getFromLDAPGroupDiscret($ldap_connection, $ldap_method, $userdn, $login);
}
///Only process rules if working on the master database
if (!$DB->isSlave()) {
//Instanciate the affectation's rule
$rule = new RuleRightCollection();
//Process affectation rules :
//we don't care about the function's return because all
//the datas are stored in session temporary
if (isset($this->fields["_groups"])) {
$groups = $this->fields["_groups"];
} else {
$groups = array();
}
$this->fields = $rule->processAllRules($groups, $this->fields, array('type' => 'LDAP', 'ldap_server' => $ldap_method["id"], 'connection' => $ldap_connection, 'userdn' => $userdn));
$this->fields['_ruleright_process'] = true;
//If rule action is ignore import
if (isset($this->fields["_stop_import"])) {
return false;
}
//or no rights found & do not import users with no rights
if (!$CFG_GLPI["use_noright_users_add"]) {
$ok = false;
if (isset($this->fields["_ldap_rules"]) && count($this->fields["_ldap_rules"])) {
//.........这里部分代码省略.........
示例7: importDevice
/**
* Import discovered device (add / update data in GLPI DB)
*
* @param object $item
*/
function importDevice($item)
{
PluginFusioninventoryLogger::logIfExtradebugAndDebugMode('fusioninventorycommunication', 'Function PluginFusinvsnmpCommunicationNetDiscovery->importDevice().');
$arrayinventory = $_SESSION['SOURCE_XMLDEVICE'];
$input = array();
$input['id'] = $item->getID();
$a_lockable = PluginFusioninventoryLock::getLockFields(getTableForItemType($item->getType()), $item->getID());
if (!in_array('name', $a_lockable)) {
if (isset($arrayinventory['SNMPHOSTNAME']) && !empty($arrayinventory['SNMPHOSTNAME'])) {
$input['name'] = $arrayinventory['SNMPHOSTNAME'];
} else {
if (isset($arrayinventory['NETBIOSNAME']) && !empty($arrayinventory['NETBIOSNAME'])) {
$input['name'] = $arrayinventory['NETBIOSNAME'];
} else {
if (isset($arrayinventory['DNSHOSTNAME']) && !empty($arrayinventory['DNSHOSTNAME'])) {
$input['name'] = $arrayinventory['DNSHOSTNAME'];
}
}
}
}
if (!in_array('serial', $a_lockable)) {
if (isset($arrayinventory['SERIAL'])) {
if (trim($arrayinventory['SERIAL']) != '') {
$input['serial'] = trim($arrayinventory['SERIAL']);
}
}
}
if (isset($input['name']) && $input['name'] == '') {
unset($input['name']);
}
if (isset($input['serial']) && $input['serial'] == '') {
unset($input['serial']);
}
if (isset($arrayinventory['ENTITY']) and !empty($arrayinventory['ENTITY'])) {
$input['entities_id'] = $arrayinventory['ENTITY'];
if (!isset($_SESSION['glpiactiveentities_string'])) {
$_SESSION['glpiactiveentities_string'] = "'" . $arrayinventory['ENTITY'] . "'";
}
}
if (!isset($_SESSION['glpiactiveentities_string'])) {
$_SESSION['glpiactiveentities_string'] = "'" . $item->fields['entities_id'] . "'";
}
switch ($item->getType()) {
case 'Computer':
// don't update this computer, if it is already handled by
// its own agent
if (Dropdown::getDropdownName("glpi_autoupdatesystems", $item->fields['autoupdatesystems_id']) == 'FusionInventory') {
return;
}
if (isset($arrayinventory['WORKGROUP'])) {
$domain = new Domain();
if (!in_array('domains_id', $a_lockable)) {
$input['domains_id'] = $domain->import(array('name' => $arrayinventory['WORKGROUP']));
}
}
$item->update($input);
$this->_updateNetworkInfo($arrayinventory, 'Computer', $item->getID(), 'NetworkPortEthernet', 1);
break;
case 'PluginFusioninventoryUnmanaged':
// Write XML file
if (isset($_SESSION['SOURCE_XMLDEVICE'])) {
PluginFusioninventoryToolbox::writeXML($input['id'], serialize($_SESSION['SOURCE_XMLDEVICE']), 'PluginFusioninventoryUnmanaged');
}
if (!in_array('contact', $a_lockable) && isset($arrayinventory['USERSESSION'])) {
$input['contact'] = $arrayinventory['USERSESSION'];
}
if (!in_array('domain', $a_lockable)) {
if (isset($arrayinventory['WORKGROUP']) && !empty($arrayinventory['WORKGROUP'])) {
$input['domain'] = Dropdown::importExternal("Domain", $arrayinventory['WORKGROUP'], $arrayinventory['ENTITY']);
}
}
if (!empty($arrayinventory['TYPE'])) {
switch ($arrayinventory['TYPE']) {
case '1':
case 'COMPUTER':
$input['item_type'] = 'Computer';
break;
case '2':
case 'NETWORKING':
$input['item_type'] = 'NetworkEquipment';
break;
case '3':
case 'PRINTER':
$input['item_type'] = 'Printer';
break;
}
}
$input['plugin_fusioninventory_agents_id'] = $_SESSION['glpi_plugin_fusioninventory_agentid'];
$this->_updateSNMPInfo($arrayinventory, $input, $item);
$this->_updateNetworkInfo($arrayinventory, 'PluginFusioninventoryUnmanaged', $item->getID(), 'NetworkPortEthernet', 1);
break;
case 'NetworkEquipment':
// Write XML file
if (isset($_SESSION['SOURCE_XMLDEVICE'])) {
PluginFusioninventoryToolbox::writeXML($input['id'], serialize($_SESSION['SOURCE_XMLDEVICE']), 'NetworkEquipment');
//.........这里部分代码省略.........
开发者ID:paisdelconocimiento,项目名称:glpi-smartcities,代码行数:101,代码来源:communicationnetworkdiscovery.class.php
示例8: replayDictionnaryOnOneSoftware
/**
* Replay dictionnary on one software
*
* @param &$new_softs array containing new softwares already computed
* @param $res_rule array of rule results
* @param $ID ID of the software
* @param $entity working entity ID
* @param $name softwrae name
* @param $manufacturer manufacturer name
* @param &$soft_ids array containing replay software need to be dustbined
**/
function replayDictionnaryOnOneSoftware(array &$new_softs, array $res_rule, $ID, $entity, $name, $manufacturer, array &$soft_ids)
{
global $DB;
$input["name"] = $name;
$input["manufacturer"] = $manufacturer;
$input["entities_id"] = $entity;
if (empty($res_rule)) {
$res_rule = $this->processAllRules($input, array(), array());
}
$soft = new Software();
if (isset($res_rules['_ignore_import']) && $res_rules['_ignore_import'] == 1) {
$soft->putInTrash($ID, __('Software deleted by GLPI dictionary rules'));
return;
}
//Software's name has changed or entity
if (isset($res_rule["name"]) && $res_rule["name"] != $name || !isset($res_rule["name"]) && isset($res_rule['new_entities_id']) && in_array($res_rule['new_entities_id'], getAncestorsOf('glpi_entities', $entity))) {
if (isset($res_rule["name"])) {
$new_name = $res_rule["name"];
} else {
$new_name = addslashes($name);
}
if (isset($res_rule["manufacturer"]) && $res_rule["manufacturer"]) {
$manufacturer = $res_rule["manufacturer"];
} else {
$manufacturer = addslashes($manufacturer);
}
//New software not already present in this entity
if (!isset($new_softs[$entity][$new_name])) {
// create new software or restore it from dustbin
$new_software_id = $soft->addOrRestoreFromTrash($new_name, $manufacturer, $entity, '', true);
$new_softs[$entity][$new_name] = $new_software_id;
} else {
$new_software_id = $new_softs[$entity][$new_name];
}
// Move licenses to new software
$this->moveLicenses($ID, $new_software_id);
} else {
$new_software_id = $ID;
$res_rule["id"] = $ID;
if (isset($res_rule["manufacturer"]) && $res_rule["manufacturer"]) {
$res_rule["manufacturers_id"] = Dropdown::importExternal('Manufacturer', $res_rule["manufacturer"]);
unset($res_rule["manufacturer"]);
}
$soft->update($res_rule);
}
// Add to software to deleted list
if ($new_software_id != $ID) {
$soft_ids[] = $ID;
}
//Get all the different versions for a software
$result = $DB->query("SELECT *\n FROM `glpi_softwareversions`\n WHERE `softwares_id` = '{$ID}'");
while ($version = $DB->fetch_assoc($result)) {
$input["version"] = addslashes($version["name"]);
$old_version_name = $input["version"];
if (isset($res_rule["version"]) && $res_rule["version"] != '') {
$new_version_name = $res_rule["version"];
} else {
$new_version_name = $version["name"];
}
if ($ID != $new_software_id || $new_version_name != $old_version_name) {
$this->moveVersions($ID, $new_software_id, $version["id"], $old_version_name, $new_version_name, $entity);
}
}
}
示例9: executeActions
function executeActions($output, $params)
{
PluginFusioninventoryToolbox::logIfExtradebug("pluginFusioninventory-locationrules", "execute action\n");
if (count($this->actions)) {
foreach ($this->actions as $action) {
switch ($action->fields["action_type"]) {
case "assign":
PluginFusioninventoryToolbox::logIfExtradebug("pluginFusioninventory-locationrules", "value " . $action->fields["value"] . "\n");
$output[$action->fields["field"]] = $action->fields["value"];
break;
case "regex_result":
$res = '';
if (isset($this->regex_results[0])) {
$res .= RuleAction::getRegexResultById($action->fields["value"], $this->regex_results[0]);
} else {
$res .= $action->fields["value"];
}
if ($res != '') {
$entities_id = 0;
if (isset($_SESSION["plugin_fusioninventory_entity"]) && $_SESSION["plugin_fusioninventory_entity"] > 0) {
$entities_id = $_SESSION["plugin_fusioninventory_entity"];
}
$res = Dropdown::importExternal(getItemTypeForTable(getTableNameForForeignKeyField($action->fields['field'])), $res, $entities_id);
}
$output[$action->fields["field"]] = $res;
break;
}
}
}
return $output;
}
示例10: updateSnmp
/**
* @param $ID
* @param $plugin_ocsinventoryng_ocsservers_id
* @return array
*/
static function updateSnmp($ID, $plugin_ocsinventoryng_ocsservers_id)
{
global $DB;
$query = "SELECT * FROM `glpi_plugin_ocsinventoryng_snmpocslinks` \n WHERE `id` = " . $ID . " \n AND `plugin_ocsinventoryng_ocsservers_id` = " . $plugin_ocsinventoryng_ocsservers_id;
$rep = $DB->query($query);
while ($data = $DB->fetch_array($rep)) {
$ocsid = $data['ocs_id'];
$itemtype = $data['itemtype'];
$items_id = $data['items_id'];
$linked = $data['linked'];
}
$ocsClient = PluginOcsinventoryngOcsServer::getDBocs($plugin_ocsinventoryng_ocsservers_id);
$ocsSnmp = $ocsClient->getSnmpDevice($ocsid);
$cfg_ocs = PluginOcsinventoryngOcsServer::getConfig($plugin_ocsinventoryng_ocsservers_id);
$loc_id = 0;
$dom_id = 0;
if ($cfg_ocs['importsnmp_location'] && $linked == 0 || $cfg_ocs['linksnmp_location'] && $linked) {
$loc_id = Dropdown::importExternal('Location', PluginOcsinventoryngOcsServer::encodeOcsDataInUtf8($cfg_ocs['ocs_db_utf8'], $ocsSnmp['META']['LOCATION']));
}
if ($cfg_ocs['importsnmp_domain'] && $linked == 0 || $cfg_ocs['linksnmp_domain'] && $linked) {
$dom_id = Dropdown::importExternal('Domain', PluginOcsinventoryngOcsServer::encodeOcsDataInUtf8($cfg_ocs['ocs_db_utf8'], $ocsSnmp['META']['DOMAIN']));
}
if ($itemtype == "Printer") {
self::addOrUpdatePrinter($plugin_ocsinventoryng_ocsservers_id, $itemtype, $items_id, $ocsSnmp, $loc_id, $dom_id, "update", $linked);
$now = date("Y-m-d H:i:s");
$sql = "UPDATE `glpi_plugin_ocsinventoryng_snmpocslinks` SET `last_update` = '" . $now . "' WHERE `id` = " . $ID . ";";
$DB->query($sql);
return array('status' => PluginOcsinventoryngOcsServer::SNMP_SYNCHRONIZED);
} else {
if ($itemtype == "NetworkEquipment") {
self::addOrUpdateNetworkEquipment($plugin_ocsinventoryng_ocsservers_id, $itemtype, $items_id, $ocsSnmp, $loc_id, $dom_id, "update", $linked);
$now = date("Y-m-d H:i:s");
$sql = "UPDATE `glpi_plugin_ocsinventoryng_snmpocslinks` SET `last_update` = '" . $now . "' WHERE `id` = " . $ID . ";";
$DB->query($sql);
return array('status' => PluginOcsinventoryngOcsServer::SNMP_SYNCHRONIZED);
} else {
if ($itemtype == "Computer") {
self::addOrUpdateComputer($plugin_ocsinventoryng_ocsservers_id, $itemtype, $items_id, $ocsSnmp, $loc_id, $dom_id, "update", $linked);
$now = date("Y-m-d H:i:s");
$sql = "UPDATE `glpi_plugin_ocsinventoryng_snmpocslinks` SET `last_update` = '" . $now . "' WHERE `id` = " . $ID . ";";
$DB->query($sql);
return array('status' => PluginOcsinventoryngOcsServer::SNMP_SYNCHRONIZED);
} else {
if ($itemtype == "Peripheral" || $itemtype == "Phone") {
self::addOrUpdateOther($plugin_ocsinventoryng_ocsservers_id, $itemtype, $items_id, $ocsSnmp, $loc_id, $dom_id, "update", $linked);
$now = date("Y-m-d H:i:s");
$sql = "UPDATE `glpi_plugin_ocsinventoryng_snmpocslinks` SET `last_update` = '" . $now . "' WHERE `id` = " . $ID . ";";
$DB->query($sql);
return array('status' => PluginOcsinventoryngOcsServer::SNMP_SYNCHRONIZED);
}
}
}
}
return array('status' => PluginOcsinventoryngOcsServer::SNMP_NOTUPDATED);
}
示例11: updateDB
/**
* Update an existing preloaded switch with the instance values
*
*@return nothing
**/
function updateDB()
{
global $DB;
if (array_key_exists('model', $this->ptcdUpdates)) {
$manufacturer = Dropdown::getDropdownName("glpi_dropdown_manufacturer", $this->getValue('FK_glpi_enterprise'));
$this->ptcdUpdates['model'] = Dropdown::importExternal("PrinterModel", $this->ptcdUpdates['model'], 0, array('manufacturer' => $manufacturer));
}
parent::updateDB();
// update last_fusioninventory_update even if no other update
$this->setValue('last_fusioninventory_update', date("Y-m-d H:i:s"));
$this->oFusionInventory_printer->updateDB();
// ports
$this->savePorts();
// cartridges
$this->saveCartridges();
// history
if (is_null($this->oFusionInventory_printer_history->getValue('ID'))) {
// update only if counters not already set for today
$this->oFusionInventory_printer_history->updateDB();
}
}
示例12: import_netdiscovery
function import_netdiscovery($p_xml, $agentKey)
{
global $DB, $LANG;
$test = '';
$p_criteria = array();
$walks = new PluginFusioninventoryWalk();
$ptap = new PluginFusioninventoryAgentsProcesses();
$pta = new PluginFusioninventoryAgents();
$config_discovery = new PluginFusioninventoryConfig();
$np = new Netport();
$ptud = new PluginFusioninventoryUnknownDevice();
if (isset($p_xml->AGENT->START)) {
$ptap->updateProcess($p_xml->PROCESSNUMBER, array('start_time_discovery' => date("Y-m-d H:i:s")));
} else {
if (isset($p_xml->AGENT->END)) {
$ptap->updateProcess($p_xml->PROCESSNUMBER, array('end_time_discovery' => date("Y-m-d H:i:s")));
} else {
if (isset($p_xml->AGENT->EXIT)) {
$ptap->endProcess($p_xml->PROCESSNUMBER, date("Y-m-d H:i:s"));
} else {
if (isset($p_xml->AGENT->NBIP)) {
$ptap->updateProcess($p_xml->PROCESSNUMBER, array('discovery_nb_ip' => $p_xml->AGENT->NBIP));
}
}
}
}
if (isset($p_xml->AGENT->AGENTVERSION)) {
$agent = $pta->InfosByKey($agentKey);
$agent['fusioninventory_agent_version'] = $p_xml->AGENT->AGENTVERSION;
$agent['last_agent_update'] = date("Y-m-d H:i:s");
$pta->update($agent);
}
$walkdata = '';
$count_discovery_devices = 0;
foreach ($p_xml->DEVICE as $discovery) {
$count_discovery_devices++;
}
$ptap->updateProcess($_SESSION['glpi_plugin_fusioninventory_processnumber'], array('discovery_nb_found' => $count_discovery_devices));
foreach ($p_xml->DEVICE as $discovery) {
if ($discovery->MODELSNMP != "") {
$query = "SELECT *\n FROM `glpi_plugin_fusioninventory_model_infos`\n WHERE `discovery_key`='" . $discovery->MODELSNMP . "'\n LIMIT 0,1;";
$result = $DB->query($query);
$data = $DB->fetch_assoc($result);
$FK_model = $data['ID'];
} else {
$FK_model = 0;
}
$discovery->MAC = strtolower($discovery->MAC);
if (empty($FK_model)) {
$FK_model = 0;
}
unset($p_criteria);
$p_criteria['ip'] = $discovery->IP;
if (!empty($discovery->NETBIOSNAME)) {
$p_criteria['name'] = $discovery->NETBIOSNAME;
} else {
if (!empty($discovery->SNMPHOSTNAME)) {
$p_criteria['name'] = $discovery->SNMPHOSTNAME;
}
}
$p_criteria['serial'] = $discovery->SERIAL;
$p_criteria['macaddr'] = $discovery->MAC;
$discovery_criteria = PluginFusioninventoryDiscovery::criteria($p_criteria);
if (!$discovery_criteria) {
$ptap->updateProcess($_SESSION['glpi_plugin_fusioninventory_processnumber'], array('discovery_nb_import' => '1'));
// Add in unknown device
$ptud->getEmpty();
if (!empty($discovery->NETBIOSNAME)) {
$ptud->fields['name'] = $discovery->NETBIOSNAME;
} else {
if (!empty($discovery->SNMPHOSTNAME)) {
$ptud->fields['name'] = $discovery->SNMPHOSTNAME;
}
}
$ptud->fields['dnsname'] = $discovery->DNSHOSTNAME;
$ptud->fields['FK_entities'] = $discovery->ENTITY;
$ptud->fields['serial'] = $discovery->SERIAL;
$ptud->fields['contact'] = $discovery->USERSESSION;
if (!empty($discovery->WORKGROUP)) {
$ptud->fields['domain'] = Dropdown::importExternal("Domain", $discovery->WORKGROUP, $discovery->ENTITY);
}
$ptud->fields['comments'] = $discovery->DESCRIPTION;
$ptud->fields['type'] = $discovery->TYPE;
$ptud->fields['FK_model_infos'] = $FK_model;
$ptud->fields['FK_snmp_connection'] = $discovery->AUTHSNMP;
if ($discovery->AUTHSNMP != "") {
$ptud->fields['snmp'] = 1;
}
$ptud->fields['location'] = 0;
$ptud->fields['deleted'] = 0;
if ($ptud->fields['domain'] == '') {
$ptud->fields['domain'] = 0;
}
if ($ptud->fields['type'] == '') {
$ptud->fields['type'] = 0;
}
if ($ptud->fields['snmp'] == '') {
$ptud->fields['snmp'] = 0;
}
if ($ptud->fields['FK_model_infos'] == '') {
//.........这里部分代码省略.........
示例13: addSoftware
/**
* Create a new software
*
* @param name the software's name
* @param manufacturer the software's manufacturer
* @param entity the entity in which the software must be added
* @param comment
*
* @return the software's ID
**/
function addSoftware($name, $manufacturer, $entity, $comment = '')
{
global $DB, $CFG_GLPI;
$manufacturer_id = 0;
if ($manufacturer != '') {
$manufacturer_id = Dropdown::importExternal('Manufacturer', $manufacturer);
}
$sql = "SELECT `id`\n FROM `glpi_softwares`\n WHERE `manufacturers_id` = '{$manufacturer_id}'\n AND `name` = '{$name}' " . getEntitiesRestrictRequest('AND', 'glpi_softwares', 'entities_id', $entity, true);
$res_soft = $DB->query($sql);
if ($soft = $DB->fetch_array($res_soft)) {
$id = $soft["id"];
} else {
$input["name"] = $name;
$input["manufacturers_id"] = $manufacturer_id;
$input["entities_id"] = $entity;
// No comment
$input["is_helpdesk_visible"] = $CFG_GLPI["default_software_helpdesk_visible"];
//Process software's category rules
$softcatrule = new RuleSoftwareCategoryCollection();
$result = $softcatrule->processAllRules(null, null, $input);
if (!empty($result) && isset($result["softwarecategories_id"])) {
$input["softwarecategories_id"] = $result["softwarecategories_id"];
} else {
$input["softwarecategories_id"] = 0;
}
$id = $this->add($input);
}
return $id;
}
示例14: createModel
function createModel($xml, $message)
{
global $DB;
$pfMapping = new PluginFusioninventoryMapping();
$pfModel = new PluginFusioninventorySnmpmodel();
$type = (string) $xml->type;
switch ($type) {
case '1':
$type = "Computer";
break;
case '2':
$type = "NetworkEquipment";
break;
case '3':
$type = "Printer";
break;
}
$input = array();
$input['name'] = (string) $xml->name;
$input['itemtype'] = $type;
$input['discovery_key'] = (string) $xml->key;
//$input['comment'] = Toolbox::clean_cross_side_scripting_deep(
// Toolbox::addslashes_deep((string)$xml->comments));
$plugin_fusioninventory_snmpmodels_id = $pfModel->add($input);
$a_devices = array();
if (isset($xml->devices) && isset($xml->devices->sysdescr)) {
foreach ($xml->devices->sysdescr as $child) {
$a_devices[] = (string) $child;
}
}
$pfSnmpmodeldevice = new PluginFusioninventorySnmpmodeldevice();
$pfSnmpmodeldevice->updateDevicesForModel($plugin_fusioninventory_snmpmodels_id, $a_devices);
foreach ($xml->oidlist->oidobject as $child) {
$plugin_fusioninventory_snmpmodelmibobjects_id = 0;
$plugin_fusioninventory_snmpmodelmiboids_id = 0;
$oid_port_counter = 0;
$oid_port_dyn = 0;
$mapping_type = '';
$mapping_name = '';
$vlan = 0;
$is_active = 1;
$mappings_id = 0;
if (isset($child->object)) {
$plugin_fusioninventory_snmpmodelmibobjects_id = Dropdown::importExternal("PluginFusioninventorySnmpmodelMibObject", $child->object);
}
if (isset($child->oid)) {
$plugin_fusioninventory_snmpmodelmiboids_id = Dropdown::importExternal("PluginFusioninventorySnmpmodelMibOid", $child->oid);
}
if (isset($child->portcounter)) {
$oid_port_counter = $child->portcounter;
}
if (isset($child->dynamicport)) {
$oid_port_dyn = $child->dynamicport;
}
if (isset($child->mapping_type)) {
$mapping_type = '';
switch ($child->mapping_type) {
case '1':
$mapping_type = "Computer";
break;
case '2':
$mapping_type = "NetworkEquipment";
break;
case '3':
$mapping_type = "Printer";
break;
}
if ($mapping_type == '') {
$mapping_type = $child->mapping_type;
}
}
if (isset($child->mapping_name)) {
$mapping_name = $child->mapping_name;
}
if (isset($child->vlan)) {
$vlan = $child->vlan;
}
if (isset($child->activation)) {
$is_active = $child->activation;
}
if (isset($mapping_type) and isset($mapping_name)) {
$a_mappings = $pfMapping->get($mapping_type, $mapping_name);
$mappings_id = $a_mappings['id'];
}
if (!isset($mappings_id) or empty($mappings_id)) {
$mappings_id = '0';
}
$query = "INSERT INTO `glpi_plugin_fusioninventory_snmpmodelmibs`\n (\n `plugin_fusioninventory_snmpmodels_id`,\n `plugin_fusioninventory_snmpmodelmiboids_id`,\n `plugin_fusioninventory_snmpmodelmibobjects_id`,\n `oid_port_counter`,\n `oid_port_dyn`,\n `plugin_fusioninventory_mappings_id`,\n `vlan`,\n `is_active`\n )\n VALUES(\n '" . $plugin_fusioninventory_snmpmodels_id . "',\n '" . $plugin_fusioninventory_snmpmodelmiboids_id . "',\n '" . $plugin_fusioninventory_snmpmodelmibobjects_id . "',\n '" . $oid_port_counter . "',\n '" . $oid_port_dyn . "',\n '" . $mappings_id . "',\n '" . $vlan . "',\n '" . $is_active . "'\n );";
$DB->query($query);
}
}
示例15: 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;
}
}
//.........这里部分代码省略.........