当前位置: 首页>>代码示例>>PHP>>正文


PHP Printer::add方法代码示例

本文整理汇总了PHP中Printer::add方法的典型用法代码示例。如果您正苦于以下问题:PHP Printer::add方法的具体用法?PHP Printer::add怎么用?PHP Printer::add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Printer的用法示例。


在下文中一共展示了Printer::add方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testPrinterTemplate

 /**
  * Check delete / purge on a template of printer
  */
 public function testPrinterTemplate()
 {
     $printer = new Printer();
     // Create
     $id[0] = $printer->add(array('name' => "Printer 1", 'entities_id' => 0, 'is_template' => 1));
     $this->assertGreaterThan(0, $id[0], "Fail to create Printer Template");
     $this->assertTrue($printer->getFromDB($id[0]), "Fail: can't read Template");
     $this->assertEquals(0, $printer->fields['is_deleted'], "Fail: is_deleted set");
     $this->assertEquals(1, $printer->fields['is_template'], "Fail: is_template not set");
     // Delete (= purge)
     $this->assertTrue($printer->delete(array('id' => $id[0]), 0), "Fail: can't delete Template");
     $this->assertFalse($printer->getFromDB($id[0]), "Fail: can read Template (deleted)");
 }
开发者ID:btry,项目名称:glpi,代码行数:16,代码来源:DeleteRestore.php

示例2: testDelete

 /**
  * @covers Printer::delete
  * @covers Printer::restore
  */
 public function testDelete()
 {
     $obj = new Printer();
     $this->assertTrue($obj->maybeDeleted());
     // Add
     $id = $obj->add(['name' => __METHOD__]);
     $this->assertGreaterThan(0, $id);
     $this->assertTrue($obj->getFromDB($id));
     $this->assertEquals(0, $obj->getField('is_deleted'));
     $this->assertEquals(0, $obj->isDeleted());
     // Delete
     $this->assertTrue($obj->delete(['id' => $id], 0));
     $this->assertTrue($obj->getFromDB($id));
     $this->assertEquals(1, $obj->getField('is_deleted'));
     $this->assertEquals(1, $obj->isDeleted());
     // Restore
     $this->assertTrue($obj->restore(['id' => $id], 0));
     $this->assertTrue($obj->getFromDB($id));
     $this->assertEquals(0, $obj->getField('is_deleted'));
     $this->assertEquals(0, $obj->isDeleted());
     // Purge
     $this->assertTrue($obj->delete(['id' => $id], 1));
     $this->assertFalse($obj->getFromDB($id));
 }
开发者ID:btry,项目名称:glpi,代码行数:28,代码来源:PrinterTest.php

示例3: Printer

if (!isset($_GET["id"])) {
    $_GET["id"] = "";
}
if (!isset($_GET["sort"])) {
    $_GET["sort"] = "";
}
if (!isset($_GET["order"])) {
    $_GET["order"] = "";
}
if (!isset($_GET["withtemplate"])) {
    $_GET["withtemplate"] = "";
}
$print = new Printer();
if (isset($_POST["add"])) {
    $print->check(-1, 'w', $_POST);
    if ($newID = $print->add($_POST)) {
        Event::log($newID, "printers", 4, "inventory", $_SESSION["glpiname"] . "  " . $LANG['log'][20] . "  " . $_POST["name"] . ".");
    }
    glpi_header($_SERVER['HTTP_REFERER']);
} else {
    if (isset($_POST["delete"])) {
        $print->check($_POST["id"], 'd');
        $print->delete($_POST);
        Event::log($_POST["id"], "printers", 4, "inventory", $_SESSION["glpiname"] . " " . $LANG['log'][22]);
        $print->redirectToList();
    } else {
        if (isset($_POST["restore"])) {
            $print->check($_POST["id"], 'd');
            $print->restore($_POST);
            Event::log($_POST["id"], "printers", 4, "inventory", $_SESSION["glpiname"] . " " . $LANG['log'][23]);
            $print->redirectToList();
开发者ID:ryukansent,项目名称:Thesis-SideB,代码行数:31,代码来源:printer.form.php

示例4: 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;
//.........这里部分代码省略.........
开发者ID:KaneoGmbH,项目名称:glpi,代码行数:101,代码来源:generate_bigdump.function.php

示例5: importPrinter

 /**
  *
  * Import printers 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 printer will be created
  * @param $dohistory record in history link between printer and computer
  */
 static function importPrinter($cfg_ocs, $computers_id, $ocsservers_id, $ocsid, $entity, $dohistory)
 {
     global $PluginOcsinventoryngDBocs, $DB;
     self::checkOCSconnection($ocsservers_id);
     if ($cfg_ocs["import_printer"]) {
         $already_processed = array();
         $conn = new Computer_Item();
         $query = "SELECT*\n                     FROM `printers`\n                     WHERE `HARDWARE_ID` = '{$ocsid}'";
         $result = $PluginOcsinventoryngDBocs->query($query);
         $p = new Printer();
         if ($PluginOcsinventoryngDBocs->numrows($result) > 0) {
             while ($line = $PluginOcsinventoryngDBocs->fetch_array($result)) {
                 $line = Toolbox::clean_cross_side_scripting_deep(Toolbox::addslashes_deep($line));
                 $print = array();
                 // TO TEST : PARSE NAME to have real name.
                 $print['name'] = self::encodeOcsDataInutf8($cfg_ocs["ocs_db_utf8"], $line['NAME']);
                 if (empty($print["name"])) {
                     $print["name"] = $line["DRIVER"];
                 }
                 $management_process = $cfg_ocs["import_printer"];
                 //Params for the dictionnary
                 $params['name'] = $print['name'];
                 $params['manufacturer'] = "";
                 $params['DRIVER'] = $line['DRIVER'];
                 $params['PORT'] = $line['PORT'];
                 if (!empty($print["name"])) {
                     $rulecollection = new RuleDictionnaryPrinterCollection();
                     $res_rule = Toolbox::addslashes_deep($rulecollection->processAllRules(Toolbox::stripslashes_deep($params), array(), array()));
                     if (!isset($res_rule["_ignore_import"]) || !$res_rule["_ignore_import"]) {
                         foreach ($res_rule as $key => $value) {
                             if ($value != '' && $value[0] != '_') {
                                 $print[$key] = $value;
                             }
                         }
                         if (isset($res_rule['is_global'])) {
                             if (!$res_rule['is_global']) {
                                 $management_process = 2;
                             } else {
                                 $management_process = 1;
                             }
                         }
                         //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`='Printer'\n                                  AND `p`.`name`='" . $print["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 printer object
                             $p->reset();
                             $print["comment"] = $line["PORT"] . "\r\n" . $line["DRIVER"];
                             self::analizePrinterPorts($print, $line["PORT"]);
                             $id_printer = 0;
                             if ($management_process == 1) {
                                 //Config says : manage printers as global
                                 //check if printers already exists in GLPI
                                 $print["is_global"] = MANAGEMENT_GLOBAL;
                                 $query = "SELECT `id`\n                                      FROM `glpi_printers`\n                                      WHERE `name` = '" . $print["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_printer = $DB->result($result_search, 0, "id");
                                     $already_processed[] = $id_printer;
                                 } else {
                                     $input = $print;
                                     if ($cfg_ocs["states_id_default"] > 0) {
                                         $input["states_id"] = $cfg_ocs["states_id_default"];
                                     }
                                     $input["entities_id"] = $entity;
                                     $id_printer = $p->add($input);
                                 }
                             } else {
                                 if ($management_process == 2) {
                                     //Config says : manage printers as single units
                                     //Import all printers as non global.
                                     $input = $print;
                                     $input["is_global"] = MANAGEMENT_UNITARY;
                                     if ($cfg_ocs["states_id_default"] > 0) {
                                         $input["states_id"] = $cfg_ocs["states_id_default"];
                                     }
                                     $input["entities_id"] = $entity;
                                     $input['is_dynamic'] = 1;
                                     $id_printer = $p->add($input);
                                 }
//.........这里部分代码省略.........
开发者ID:geldarr,项目名称:hack-space,代码行数:101,代码来源:ocsserver.class.php

示例6: PrinterToInventoryWithoutIP

 /**
  * @test
  */
 public function PrinterToInventoryWithoutIP()
 {
     self::restore_database();
     $printer = new Printer();
     $networkport = new NetworkPort();
     $networkName = new NetworkName();
     $pfPrinter = new PluginFusioninventoryPrinter();
     $pfTask = new PluginFusioninventoryTask();
     $pfTaskjob = new PluginFusioninventoryTaskjob();
     $computer = new Computer();
     $pfAgent = new PluginFusioninventoryAgent();
     $communication = new PluginFusioninventoryCommunication();
     // Create computers + agents
     $input = array('entities_id' => 0, 'name' => 'computer1');
     $computers_id = $computer->add($input);
     $input = array('entities_id' => 0, 'name' => 'computer1', 'version' => '{"INVENTORY":"v2.3.11"}', 'device_id' => 'computer1', 'useragent' => 'FusionInventory-Agent_v2.3.11', 'computers_id' => $computers_id);
     $pfAgent->add($input);
     // Create printer
     $input = array('name' => 'printer 001', 'entities_id' => 0);
     $printers_id = $printer->add($input);
     // Add port
     $networkports_id = $networkport->add(array('itemtype' => 'Printer', 'instantiation_type' => 'NetworkPortEthernet', 'items_id' => $printers_id, 'entities_id' => 0));
     $networknames_id = $networkName->add(array('entities_id' => 0, 'itemtype' => 'NetworkPort', 'items_id' => $networkports_id));
     $input = array('printers_id' => 1, 'plugin_fusioninventory_configsecurities_id' => 2);
     $pfPrinter->add($input);
     // Add task
     // create task
     $input = array('entities_id' => 0, 'name' => 'network inventory', 'is_active' => 1);
     $tasks_id = $pfTask->add($input);
     // create taskjob
     $input = array('plugin_fusioninventory_tasks_id' => $tasks_id, 'entities_id' => 0, 'name' => 'inventory', 'method' => 'networkinventory', 'targets' => '[{"Printer":"' . $printers_id . '"}]', 'actors' => '[{"PluginFusioninventoryAgent":"1"}]');
     $pfTaskjob->add($input);
     PluginFusioninventoryTask::cronTaskscheduler();
     $data = $pfTask->getJoblogs(array(1));
     // Task is prepared
     // Agent will get data
     $communication->getTaskAgent(1);
     $message = $communication->getMessage();
     $json = json_encode($message);
     $array = json_decode($json, TRUE);
     $ref = array();
     $this->assertEquals($ref, $array, 'XML of SNMP inventory task');
 }
开发者ID:C-Duv,项目名称:fusioninventory-for-glpi,代码行数:46,代码来源:NetworkInventoryTest.php

示例7: NewPrinterFromNetdiscovery

 /**
  * @test
  */
 public function NewPrinterFromNetdiscovery()
 {
     global $DB;
     $DB->connect();
     $pfCNetworkDiscovery = new PluginFusioninventoryCommunicationNetworkDiscovery();
     $GLPIlog = new GLPIlogs();
     $networkName = new NetworkName();
     $iPAddress = new IPAddress();
     $_SESSION['SOURCE_XMLDEVICE'] = array('AUTHSNMP' => '1', 'DESCRIPTION' => 'Photosmart D7200 series', 'ENTITY' => '0', 'FIRMWARE' => '', 'IP' => '192.168.20.100', 'MAC' => '00:21:5a:0b:bb:c4', 'MANUFACTURER' => 'Hewlett-Packard', 'MODEL' => '', 'MODELSNMP' => 'Printer0093', 'NETBIOSNAME' => 'HP00215A0BBBC4', 'SERIAL' => 'MY89AQG0V9050N', 'SNMPHOSTNAME' => 'HP0BBBC4', 'TYPE' => 'PRINTER');
     $printer = new Printer();
     $printers_id = $printer->add(array('serial' => 'MY89AQG0V9050N', 'entities_id' => 0));
     $printer->getFromDB($printers_id);
     $pfCNetworkDiscovery->importDevice($printer);
     $GLPIlog->testSQLlogs();
     $GLPIlog->testPHPlogs();
     $printer->getFromDB($printers_id);
     $this->assertEquals('HP0BBBC4', $printer->fields['name'], 'Name must be updated');
     $a_printerextends = getAllDatasFromTable('glpi_plugin_fusioninventory_printers', "`printers_id`='" . $printers_id . "'");
     $this->assertEquals('1', count($a_printerextends), 'May have one printer extend line for this printer');
     $a_printerextend = current($a_printerextends);
     $this->assertEquals('1', $a_printerextend['plugin_fusioninventory_configsecurities_id'], 'SNMPauth may be with id 1');
     $this->assertEquals('Photosmart D7200 series', $a_printerextend['sysdescr'], 'Sysdescr not updated correctly');
     // Check mac
     $networkPort = new NetworkPort();
     $a_ports = $networkPort->find("`itemtype`='Printer' AND `items_id`='" . $printers_id . "'");
     $this->assertEquals('1', count($a_ports), 'May have one network port');
     $a_port = current($a_ports);
     $this->assertEquals('00:21:5a:0b:bb:c4', $a_port['mac'], 'Mac address');
     // check ip
     $a_networknames = $networkName->find("`itemtype`='NetworkPort'\n         AND `items_id`='" . $a_port['id'] . "'");
     $this->assertEquals('1', count($a_networknames), 'May have one networkname');
     $a_networkname = current($a_networknames);
     $a_ipaddresses = $iPAddress->find("`itemtype`='NetworkName'\n         AND `items_id`='" . $a_networkname['id'] . "'");
     $this->assertEquals('1', count($a_ipaddresses), 'May have one IP address');
     $a_ipaddress = current($a_ipaddresses);
     $this->assertEquals('192.168.20.100', $a_ipaddress['name'], 'IP address');
 }
开发者ID:C-Duv,项目名称:fusioninventory-for-glpi,代码行数:40,代码来源:PrinterUpdateTest.php

示例8: import

 /**
  * Function to import discovered device
  *
  * @param $items_id id of the device to import
  *
  * @return nothing
  *
  **/
 function import($items_id, $Import = 0, $NoImport = 0)
 {
     global $DB;
     $NetworkPort = new NetworkPort();
     $a_NetworkPorts = $NetworkPort->find("`items_id` = '" . $items_id . "'\n                      AND `itemtype` = 'PluginFusioninventoryUnmanaged'");
     $this->getFromDB($items_id);
     $this->fields = Toolbox::addslashes_deep($this->fields);
     $data = array();
     switch ($this->fields['item_type']) {
         case 'Printer':
             $Printer = new Printer();
             $data["entities_id"] = $this->fields["entities_id"];
             if (!empty($this->fields["name"])) {
                 $data["name"] = $this->fields["name"];
             }
             $data["locations_id"] = $this->fields["locations_id"];
             $data["serial"] = $this->fields["serial"];
             $data["otherserial"] = $this->fields["otherserial"];
             $data["contact"] = $this->fields["contact"];
             $data["domain"] = $this->fields["domain"];
             $data["comment"] = $this->fields["comment"];
             $data["is_dynamic"] = 1;
             $printer_id = $Printer->add($data);
             foreach ($a_NetworkPorts as $data_Port) {
                 $data_Port['items_id'] = $printer_id;
                 $data_Port['itemtype'] = $Printer->getType();
                 $NetworkPort->update($data_Port);
             }
             // Import SNMP
             $pfPrinter = new PluginFusioninventoryPrinter();
             $_SESSION['glpi_plugins_fusinvsnmp_table'] = "glpi_plugin_fusioninventory_printers";
             $query = "SELECT *\n                      FROM `glpi_plugin_fusioninventory_printers`\n                      WHERE `printers_id`='" . $printer_id . "' ";
             $result = $DB->query($query);
             $data = array();
             if ($DB->numrows($result) > 0) {
                 $data = $DB->fetch_assoc($result);
             }
             $data['sysdescr'] = $this->fields['sysdescr'];
             $data['plugin_fusioninventory_configsecurities_id'] = $this->fields['plugin_fusioninventory_configsecurities_id'];
             if ($DB->numrows($result) == 0) {
                 $data['printers_id'] = $printer_id;
                 $pfPrinter->add($data);
             } else {
                 $pfPrinter->update($data);
             }
             $this->deleteFromDB($items_id, 1);
             $Import++;
             break;
         case 'NetworkEquipment':
             $NetworkEquipment = new NetworkEquipment();
             $data["entities_id"] = $this->fields["entities_id"];
             if (!empty($this->fields["name"])) {
                 $data["name"] = $this->fields["name"];
             }
             $data["locations_id"] = $this->fields["locations_id"];
             $data["serial"] = $this->fields["serial"];
             $data["otherserial"] = $this->fields["otherserial"];
             $data["contact"] = $this->fields["contact"];
             $data["domain"] = $this->fields["domain"];
             $data["comment"] = $this->fields["comment"];
             $data["is_dynamic"] = 1;
             //            $data_Port = current($a_NetworkPorts);
             //            $data["ip"] = $data_Port["ip"];
             //            $data["mac"] = $data_Port["mac"];
             $NetworkEquipment_id = $NetworkEquipment->add($data);
             foreach ($a_NetworkPorts as $data_Port) {
                 $data_Port['items_id'] = $NetworkEquipment_id;
                 $data_Port['itemtype'] = $NetworkEquipment->getType();
                 $NetworkPort->update($data_Port);
             }
             $pfNetworkEquipment = new PluginFusioninventoryNetworkEquipment();
             $_SESSION['glpi_plugins_fusinvsnmp_table'] = "glpi_plugin_fusioninventory_networkequipments";
             $query = "SELECT *\n                      FROM `glpi_plugin_fusioninventory_networkequipments`\n                      WHERE `networkequipments_id`='" . $NetworkEquipment_id . "' ";
             $result = $DB->query($query);
             $data = array();
             if ($DB->numrows($result) > 0) {
                 $data = $DB->fetch_assoc($result);
             }
             $data['sysdescr'] = $this->fields['sysdescr'];
             $data['plugin_fusioninventory_configsecurities_id'] = $this->fields['plugin_fusioninventory_configsecurities_id'];
             if ($DB->numrows($result) == 0) {
                 $data['networkequipments_id'] = $NetworkEquipment_id;
                 $pfNetworkEquipment->add($data);
             } else {
                 $pfNetworkEquipment->update($data);
             }
             $this->deleteFromDB($items_id, 1);
             $Import++;
             break;
         case 'Peripheral':
             $Peripheral = new Peripheral();
             $data["entities_id"] = $this->fields["entities_id"];
//.........这里部分代码省略.........
开发者ID:korial29,项目名称:fusioninventory-for-glpi,代码行数:101,代码来源:unmanaged.class.php

示例9: 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) {
//.........这里部分代码省略.........
开发者ID:paisdelconocimiento,项目名称:glpi-smartcities,代码行数:101,代码来源:inventorycomputerlib.class.php

示例10: PrinterDiscoveryImport

 /**
  * @test
  */
 public function PrinterDiscoveryImport()
 {
     global $DB, $PF_CONFIG;
     $DB->connect();
     $a_inventory = array('AUTHSNMP' => '1', 'DESCRIPTION' => 'Brother NC-6400h, Firmware Ver.1.11  (06.12.20),MID 84UZ92', 'ENTITY' => '0', 'FIRMWARE' => '', 'IP' => '10.36.4.29', 'MAC' => '00:80:77:d9:51:c3', 'MANUFACTURER' => 'Brother', 'MODEL' => '', 'MODELSNMP' => 'Printer0442', 'NETBIOSNAME' => 'UH4DLPT01', 'SERIAL' => 'E8J596100', 'SNMPHOSTNAME' => 'UH4DLPT01', 'TYPE' => 'PRINTER');
     $pfCommunicationNetworkDiscovery = new PluginFusioninventoryCommunicationNetworkDiscovery();
     $printer = new Printer();
     $printer->add(array('entities_id' => '0', 'serial' => 'E8J596100'));
     $_SESSION['plugin_fusinvsnmp_taskjoblog']['taskjobs_id'] = 1;
     $_SESSION['plugin_fusinvsnmp_taskjoblog']['items_id'] = '1';
     $_SESSION['plugin_fusinvsnmp_taskjoblog']['itemtype'] = 'Printer';
     $_SESSION['plugin_fusinvsnmp_taskjoblog']['state'] = 0;
     $_SESSION['plugin_fusinvsnmp_taskjoblog']['comment'] = '';
     $pfCommunicationNetworkDiscovery->sendCriteria($a_inventory);
     $a_printers = $printer->find();
     $this->assertEquals(1, count($a_printers), 'May have only one Printer');
     $a_printer = current($a_printers);
     $this->assertEquals('UH4DLPT01', $a_printer['name'], 'Hostname of printer may be updated');
 }
开发者ID:C-Duv,项目名称:fusioninventory-for-glpi,代码行数:22,代码来源:RuleImportTest.php

示例11: testPrinter

 /**
  * Check right on Recursive object
  */
 public function testPrinter()
 {
     global $DB;
     $DB->connect();
     $ent0 = $this->sharedFixture['entity'][0];
     $ent1 = $this->sharedFixture['entity'][1];
     $ent2 = $this->sharedFixture['entity'][2];
     $printer = new Printer();
     $id[0] = $printer->add(array('name' => "Printer 1", 'entities_id' => $ent0, 'is_recursive' => 0));
     $this->assertGreaterThan(0, $id[0], "Fail to create Printer 1");
     $id[1] = $printer->add(array('name' => "Printer 2", 'entities_id' => $ent0, 'is_recursive' => 1));
     $this->assertGreaterThan(0, $id[1], "Fail to create Printer 2");
     $id[2] = $printer->add(array('name' => "Printer 3", 'entities_id' => $ent1, 'is_recursive' => 1));
     $this->assertGreaterThan(0, $id[2], "Fail to create Ptiner 3");
     $id[3] = $printer->add(array('name' => "Printer 4", 'entities_id' => $ent2));
     $this->assertGreaterThan(0, $id[3], "Fail to create Printer 4");
     // Super admin
     Session::changeProfile(4);
     $this->assertEquals(4, $_SESSION['glpiactiveprofile']['id']);
     $this->assertEquals(31, $_SESSION['glpiactiveprofile']['printer']);
     // See all
     $this->assertTrue(Session::changeActiveEntities("all"));
     $this->assertTrue($printer->can($id[0], READ), "Fail can read Printer 1");
     $this->assertTrue($printer->can($id[1], READ), "Fail can read Printer 2");
     $this->assertTrue($printer->can($id[2], READ), "Fail can read Printer 3");
     $this->assertTrue($printer->can($id[3], READ), "Fail can read Printer 4");
     $this->assertTrue($printer->canEdit($id[0]), "Fail can write Printer 1");
     $this->assertTrue($printer->canEdit($id[1]), "Fail can write Printer 2");
     $this->assertTrue($printer->canEdit($id[2]), "Fail can write Printer 3");
     $this->assertTrue($printer->canEdit($id[3]), "Fail can write Printer 4");
     // See only in main entity
     $this->assertTrue(Session::changeActiveEntities($ent0));
     $this->assertTrue($printer->can($id[0], READ), "Fail can read Printer 1");
     $this->assertTrue($printer->can($id[1], READ), "Fail can read Printer 2");
     $this->assertFalse($printer->can($id[2], READ), "Fail can't read Printer 3");
     $this->assertFalse($printer->can($id[3], READ), "Fail can't read Printer 1");
     $this->assertTrue($printer->canEdit($id[0]), "Fail can write Printer 1");
     $this->assertTrue($printer->canEdit($id[1]), "Fail can write Printer 2");
     $this->assertFalse($printer->canEdit($id[2]), "Fail can't write Printer 1");
     $this->assertFalse($printer->canEdit($id[3]), "Fail can't write Printer 1");
     // See only in child entity 1 + parent if recursive
     $this->assertTrue(Session::changeActiveEntities($ent1));
     $this->assertFalse($printer->can($id[0], READ), "Fail can't read Printer 1");
     $this->assertTrue($printer->can($id[1], READ), "Fail can read Printer 2");
     $this->assertTrue($printer->can($id[2], READ), "Fail can read Printer 3");
     $this->assertFalse($printer->can($id[3], READ), "Fail can't read Printer 4");
     $this->assertFalse($printer->canEdit($id[0]), "Fail can't write Printer 1");
     $this->assertFalse($printer->canEdit($id[1]), "Fail can't write Printer 2");
     $this->assertTrue($printer->canEdit($id[2]), "Fail can write Printer 2");
     $this->assertFalse($printer->canEdit($id[3]), "Fail can't write Printer 2");
     // See only in child entity 2 + parent if recursive
     $this->assertTrue(Session::changeActiveEntities($ent2));
     $this->assertFalse($printer->can($id[0], READ), "Fail can't read Printer 1");
     $this->assertTrue($printer->can($id[1], READ), "Fail can read Printer 2");
     $this->assertFalse($printer->can($id[2], READ), "Fail can't read Printer 3");
     $this->assertTrue($printer->can($id[3], READ), "Fail can read Printer 4");
     $this->assertFalse($printer->canEdit($id[0]), "Fail can't write Printer 1");
     $this->assertFalse($printer->canEdit($id[1]), "Fail can't write Printer 2");
     $this->assertFalse($printer->canEdit($id[2]), "Fail can't write Printer 3");
     $this->assertTrue($printer->canEdit($id[3]), "Fail can write Printer 4");
 }
开发者ID:btry,项目名称:glpi,代码行数:64,代码来源:CanCheck.php

示例12: testDeleteByCriteria

 /**
  * @covers Printer::deleteByCriteria
  * @covers Printer::restore
  */
 public function testDeleteByCriteria()
 {
     $obj = new Printer();
     $this->assertTrue($obj->maybeDeleted());
     // Add
     $id = $obj->add(['name' => __METHOD__, 'entities_id' => getItemByTypeName('Entity', '_test_root_entity', true)]);
     $this->assertGreaterThan(0, $id);
     $this->assertTrue($obj->getFromDB($id));
     $this->assertEquals(0, $obj->getField('is_deleted'));
     $this->assertEquals(0, $obj->isDeleted());
     $nb_before = countElementsInTable('glpi_logs', "itemtype = 'Printer'\n                                          AND items_id = '{$id}'");
     // DeleteByCriteria without history
     $this->assertTrue($obj->deleteByCriteria(['name' => __METHOD__], 0, 0));
     $this->assertTrue($obj->getFromDB($id));
     $this->assertEquals(1, $obj->getField('is_deleted'));
     $this->assertEquals(1, $obj->isDeleted());
     $nb_after = countElementsInTable('glpi_logs', "itemtype = 'Printer'\n                                          AND items_id = '{$id}'");
     $this->assertEquals($nb_before, $nb_after);
     // Restore
     $this->assertTrue($obj->restore(['id' => $id], 0));
     $this->assertTrue($obj->getFromDB($id));
     $this->assertEquals(0, $obj->getField('is_deleted'));
     $this->assertEquals(0, $obj->isDeleted());
     $nb_before = countElementsInTable('glpi_logs', "itemtype = 'Printer'\n                                          AND items_id = '{$id}'");
     // DeleteByCriteria with history
     $this->assertTrue($obj->deleteByCriteria(['name' => __METHOD__], 0, 1));
     $this->assertTrue($obj->getFromDB($id));
     $this->assertEquals(1, $obj->getField('is_deleted'));
     $this->assertEquals(1, $obj->isDeleted());
     $nb_after = countElementsInTable('glpi_logs', "itemtype = 'Printer'\n                                          AND items_id = '{$id}'");
     $this->assertEquals($nb_before + 1, $nb_after);
 }
开发者ID:glpi-project,项目名称:glpi,代码行数:36,代码来源:PrinterTest.php

示例13: importPrinter

 /**
  *
  * Import printers from OCS
  * @since 1.0
  * @param $cfg_ocs OCSNG mode configuration
  * @param $computers_id computer's id in GLPI
  * @param $ocsservers_id OCS server id
  * @param $ocsComputer
  * @param $entity the entity in which the printer will be created
  * @internal param computer $ocsid 's id in OCS
  */
 static function importPrinter($cfg_ocs, $computers_id, $ocsservers_id, $ocsComputer, $entity)
 {
     global $DB, $CFG_GLPI;
     $already_processed = array();
     $conn = new Computer_Item();
     $p = new Printer();
     foreach ($ocsComputer as $printer) {
         $printer = Toolbox::clean_cross_side_scripting_deep(Toolbox::addslashes_deep($printer));
         $print = array();
         // TO TEST : PARSE NAME to have real name.
         $print['name'] = self::encodeOcsDataInUtf8($cfg_ocs["ocs_db_utf8"], $printer['NAME']);
         if (empty($print["name"])) {
             $print["name"] = $printer["DRIVER"];
         }
         $management_process = $cfg_ocs["import_printer"];
         //Params for the dictionnary
         $params['name'] = $print['name'];
         $params['manufacturer'] = "";
         $params['DRIVER'] = $printer['DRIVER'];
         $params['PORT'] = $printer['PORT'];
         if (!empty($print["name"])) {
             $rulecollection = new RuleDictionnaryPrinterCollection();
             $res_rule = Toolbox::addslashes_deep($rulecollection->processAllRules(Toolbox::stripslashes_deep($params), array(), array()));
             if (!isset($res_rule["_ignore_import"]) || !$res_rule["_ignore_import"]) {
                 foreach ($res_rule as $key => $value) {
                     if ($value != '' && $value[0] != '_') {
                         $print[$key] = $value;
                     }
                 }
                 if (isset($res_rule['is_global'])) {
                     if (!$res_rule['is_global']) {
                         $management_process = 2;
                     } else {
                         $management_process = 1;
                     }
                 }
                 //Look for a printer 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`\n                                     AND `computers_id`='{$computers_id}'\n                                     AND `itemtype`='Printer'\n                                     AND `p`.`name`='" . $print["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 printer object
                     $p->reset();
                     $print["comment"] = $printer["PORT"] . "\r\n" . $printer["DRIVER"];
                     self::analizePrinterPorts($print, $printer["PORT"]);
                     $id_printer = 0;
                     if ($management_process == 1) {
                         //Config says : manage printers as global
                         //check if printers already exists in GLPI
                         $print["is_global"] = MANAGEMENT_GLOBAL;
                         $query = "SELECT `id`\n                                         FROM `glpi_printers`\n                                         WHERE `name` = '" . $print["name"] . "'\n                                            AND `is_global` = '1' ";
                         if ($CFG_GLPI['transfers_id_auto'] < 1) {
                             $query .= " 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_printer = $DB->result($result_search, 0, "id");
                             $already_processed[] = $id_printer;
                         } else {
                             $input = $print;
                             if ($cfg_ocs["states_id_default"] > 0) {
                                 $input["states_id"] = $cfg_ocs["states_id_default"];
                             }
                             $input["entities_id"] = $entity;
                             $id_printer = $p->add($input, array(), $cfg_ocs['history_printer']);
                         }
                     } else {
                         if ($management_process == 2) {
                             //Config says : manage printers as single units
                             //Import all printers as non global.
                             $input = $print;
                             $input["is_global"] = MANAGEMENT_UNITARY;
                             if ($cfg_ocs["states_id_default"] > 0) {
                                 $input["states_id"] = $cfg_ocs["states_id_default"];
                             }
                             $input["entities_id"] = $entity;
                             $input['is_dynamic'] = 1;
                             $id_printer = $p->add($input, array(), $cfg_ocs['history_printer']);
                         }
                     }
                     if ($id_printer) {
//.........这里部分代码省略.........
开发者ID:pluginsGLPI,项目名称:ocsinventoryng,代码行数:101,代码来源:ocsserver.class.php

示例14: 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) {
//.........这里部分代码省略.........
开发者ID:ryukansent,项目名称:Thesis-SideB,代码行数:101,代码来源:ocsserver.class.php


注:本文中的Printer::add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。