本文整理汇总了PHP中Monitor::update方法的典型用法代码示例。如果您正苦于以下问题:PHP Monitor::update方法的具体用法?PHP Monitor::update怎么用?PHP Monitor::update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Monitor
的用法示例。
在下文中一共展示了Monitor::update方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sprintf
} else {
if (isset($_POST["restore"])) {
$monitor->check($_POST["id"], 'd');
$monitor->restore($_POST);
Event::log($_POST["id"], "monitors", 4, "inventory", sprintf(__('%s restores an item'), $_SESSION["glpiname"]));
$monitor->redirectToList();
} else {
if (isset($_POST["purge"])) {
$monitor->check($_POST["id"], 'd');
$monitor->delete($_POST, 1);
Event::log($_POST["id"], "monitors", 4, "inventory", sprintf(__('%s purges an item'), $_SESSION["glpiname"]));
$monitor->redirectToList();
} else {
if (isset($_POST["update"])) {
$monitor->check($_POST["id"], 'w');
$monitor->update($_POST);
Event::log($_POST["id"], "monitors", 4, "inventory", sprintf(__('%s updates an item'), $_SESSION["glpiname"]));
Html::back();
} else {
if (isset($_POST["unglobalize"])) {
$monitor->check($_POST["id"], 'w');
Computer_Item::unglobalizeItem($monitor);
Event::log($_POST["id"], "monitors", 4, "inventory", sprintf(__('%s sets unitary management'), $_SESSION["glpiname"]));
Html::redirect($CFG_GLPI["root_doc"] . "/front/monitor.form.php?id=" . $_POST["id"]);
} else {
Html::header(Monitor::getTypeName(2), $_SERVER['PHP_SELF'], "inventory", "monitor");
$monitor->showForm($_GET["id"], array('withtemplate' => $_GET["withtemplate"]));
Html::footer();
}
}
}
示例2: importMonitor
//.........这里部分代码省略.........
if ($cfg_ocs["import_monitor"] >= 2) {
//Config says : manage monitors as single units
//Import all monitors as non global.
$mon["is_global"] = 0;
// Try to find a monitor with the same serial.
if (!empty($mon["serial"])) {
$query = "SELECT `id`\n FROM `glpi_monitors`\n WHERE `serial` LIKE '%" . $mon["serial"] . "%'\n AND `is_global` = '0'\n AND `entities_id` = '{$entity}'";
$result_search = $DB->query($query);
if ($DB->numrows($result_search) == 1) {
//Monitor founded
$id_monitor = $DB->result($result_search, 0, "id");
}
}
//Search by serial failed, search by name
if ($cfg_ocs["import_monitor"] == 2 && !$id_monitor) {
//Try to find a monitor with no serial, the same name and not already connected.
if (!empty($mon["name"])) {
$query = "SELECT `glpi_monitors`.`id`\n FROM `glpi_monitors`\n LEFT JOIN `glpi_computers_items`\n ON (`glpi_computers_items`.`itemtype`='Monitor'\n AND `glpi_computers_items`.`items_id`\n =`glpi_monitors`.`id`)\n WHERE `serial` = ''\n AND `name` = '" . $mon["name"] . "'\n AND `is_global` = '0'\n AND `entities_id` = '{$entity}'\n AND `glpi_computers_items`.`computers_id` IS NULL";
$result_search = $DB->query($query);
if ($DB->numrows($result_search) == 1) {
$id_monitor = $DB->result($result_search, 0, "id");
}
}
}
if (!$id_monitor) {
$input = $mon;
if ($cfg_ocs["states_id_default"] > 0) {
$input["states_id"] = $cfg_ocs["states_id_default"];
}
$input["entities_id"] = $entity;
$id_monitor = $m->add($input);
}
}
}
// ($cfg_ocs["import_monitor"] >= 2)
if ($id_monitor) {
//Import unique : Disconnect monitor on other computer done in Connect function
$connID = $conn->add(array('computers_id' => $computers_id, 'itemtype' => 'Monitor', 'items_id' => $id_monitor, '_no_history' => !$dohistory, 'is_dynamic' => 1, 'is_deleted' => 0));
$already_processed[] = $id_monitor;
//Update column "is_deleted" set value to 0 and set status to default
$input = array();
$old = new Monitor();
if ($old->getFromDB($id_monitor)) {
if ($old->fields["is_deleted"]) {
$input["is_deleted"] = 0;
}
if ($cfg_ocs["states_id_default"] > 0 && $old->fields["states_id"] != $cfg_ocs["states_id_default"]) {
$input["states_id"] = $cfg_ocs["states_id_default"];
}
if (empty($old->fields["name"]) && !empty($mon["name"])) {
$input["name"] = $mon["name"];
}
if (empty($old->fields["serial"]) && !empty($mon["serial"])) {
$input["serial"] = $mon["serial"];
}
if (count($input)) {
$input["id"] = $id_monitor;
$input['entities_id'] = $entity;
$m->update($input);
}
}
}
} else {
$already_processed[] = $id;
}
// } // end foreach
// if ($cfg_ocs["import_monitor"]<=2 || $checkserial){
//Look for all monitors, not locked, not linked to the computer anymore
$query = "SELECT `id`\n FROM `glpi_computers_items`\n WHERE `itemtype`='Monitor'\n AND `computers_id`='{$computers_id}'\n AND `is_dynamic`='1'\n AND `is_deleted`='0'";
if (!empty($already_processed)) {
$query .= "AND `items_id` NOT IN (" . implode(',', $already_processed) . ")";
}
foreach ($DB->request($query) as $data) {
// Delete all connexions
//Get OCS configuration
$ocs_config = PluginOcsinventoryngOcsServer::getConfig($ocsservers_id);
//Get the management mode for this device
$mode = PluginOcsinventoryngOcsServer::getDevicesManagementMode($ocs_config, 'Monitor');
$decoConf = $ocs_config["deconnection_behavior"];
//Change status if :
// 1 : the management mode IS NOT global
// 2 : a deconnection's status have been defined
// 3 : unique with serial
if ($mode >= 2 && strlen($decoConf) > 0) {
//Delete periph from glpi
if ($decoConf == "delete") {
$query = "DELETE\n FROM `glpi_computers_items`\n WHERE `id`='" . $data['id'] . "'";
$result = $DB->query($query);
//Put periph in dustbin
} else {
if ($decoConf == "trash") {
$query = "UPDATE\n `glpi_computers_items`\n SET `is_deleted` = 1\n WHERE `id`='" . $data['id'] . "'";
$result = $DB->query($query);
}
}
}
}
}
}
}
示例3: importMonitor
//.........这里部分代码省略.........
if ($cfg_ocs["import_monitor"] == 1) {
//Config says : manage monitors as global
//check if monitors already exists in GLPI
$mon["is_global"] = 1;
$query = "SELECT `id`\n FROM `glpi_monitors`\n WHERE `name` = '" . $mon["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_monitor = $DB->result($result_search, 0, "id");
} else {
$input = $mon;
if ($cfg_ocs["states_id_default"] > 0) {
$input["states_id"] = $cfg_ocs["states_id_default"];
}
$input["entities_id"] = $entity;
$id_monitor = $m->add($input);
}
} else {
if ($cfg_ocs["import_monitor"] >= 2) {
//Config says : manage monitors as single units
//Import all monitors as non global.
$mon["is_global"] = 0;
// Try to find a monitor with the same serial.
if (!empty($mon["serial"])) {
$query = "SELECT `id`\n FROM `glpi_monitors`\n WHERE `serial` LIKE '%" . $mon["serial"] . "%'\n AND `is_global` = '0'\n AND `entities_id` = '{$entity}'";
$result_search = $DB->query($query);
if ($DB->numrows($result_search) == 1) {
//Monitor founded
$id_monitor = $DB->result($result_search, 0, "id");
}
}
//Search by serial failed, search by name
if ($cfg_ocs["import_monitor"] == 2 && !$id_monitor) {
//Try to find a monitor with no serial, the same name and not already connected.
if (!empty($mon["name"])) {
$query = "SELECT `glpi_monitors`.`id`\n FROM `glpi_monitors`\n LEFT JOIN `glpi_computers_items`\n ON (`glpi_computers_items`.`itemtype`='Monitor'\n AND `glpi_computers_items`.`items_id`\n =`glpi_monitors`.`id`)\n WHERE `serial` = ''\n AND `name` = '" . $mon["name"] . "'\n AND `is_global` = '0'\n AND `entities_id` = '{$entity}'\n AND `glpi_computers_items`.`computers_id` IS NULL";
$result_search = $DB->query($query);
if ($DB->numrows($result_search) == 1) {
$id_monitor = $DB->result($result_search, 0, "id");
}
}
}
if (!$id_monitor) {
$input = $mon;
if ($cfg_ocs["states_id_default"] > 0) {
$input["states_id"] = $cfg_ocs["states_id_default"];
}
$input["entities_id"] = $entity;
$id_monitor = $m->add($input);
}
}
}
// ($cfg_ocs["import_monitor"] >= 2)
if ($id_monitor) {
//Import unique : Disconnect monitor on other computer done in Connect function
$connID = $conn->add(array('computers_id' => $computers_id, 'itemtype' => 'Monitor', 'items_id' => $id_monitor, '_no_history' => !$dohistory, 'is_dynamic' => 1, 'is_deleted' => 0));
$already_processed[] = $id_monitor;
//Update column "is_deleted" set value to 0 and set status to default
$input = array();
$old = new Monitor();
if ($old->getFromDB($id_monitor)) {
if ($old->fields["is_deleted"]) {
$input["is_deleted"] = 0;
}
if ($cfg_ocs["states_id_default"] > 0 && $old->fields["states_id"] != $cfg_ocs["states_id_default"]) {
$input["states_id"] = $cfg_ocs["states_id_default"];
}
if (empty($old->fields["name"]) && !empty($mon["name"])) {
$input["name"] = $mon["name"];
}
if (empty($old->fields["serial"]) && !empty($mon["serial"])) {
$input["serial"] = $mon["serial"];
}
if (count($input)) {
$input["id"] = $id_monitor;
$input['entities_id'] = $entity;
$m->update($input);
}
}
}
} else {
$already_processed[] = $id;
}
}
// end foreach
if ($cfg_ocs["import_monitor"] <= 2 || $checkserial) {
//Look for all monitors, not locked, not linked to the computer anymore
$query = "SELECT `id`\n FROM `glpi_computers_items`\n WHERE `itemtype`='Monitor'\n AND `computers_id`='{$computers_id}'\n AND `is_dynamic`='1'\n AND `is_deleted`='0'";
if (!empty($already_processed)) {
$query .= "AND `items_id` NOT IN (" . implode(',', $already_processed) . ")";
}
foreach ($DB->request($query) as $data) {
//Delete all connexions
$conn->delete(array('id' => $data['id'], '_ocsservers_id' => $ocsservers_id), true);
}
}
}
}
}
示例4: 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) {
//.........这里部分代码省略.........