/**
  * @test
  */
 public function ImportNetworkEquipment()
 {
     global $DB;
     self::restore_database();
     // Load session rights
     $_SESSION['glpidefault_entity'] = 0;
     Session::initEntityProfiles(2);
     Session::changeProfile(4);
     $pfUnmanaged = new PluginFusioninventoryUnmanaged();
     $networkEquipment = new NetworkEquipment();
     $networkPort = new NetworkPort();
     $networkName = new NetworkName();
     $iPAddress = new IPAddress();
     $input = array('name' => 'switch', 'entities_id' => 0, 'item_type' => 'NetworkEquipment', 'sysdescr' => 'Cisco machin chose', 'locations_id' => 1, 'is_dynamic' => 1, 'serial' => 'XXS6BEF3', 'comment' => 'this is a comment', 'plugin_fusioninventory_configsecurities_id' => 1);
     $unmanageds_id = $pfUnmanaged->add($input);
     // * Add networkport
     $input = array();
     $input['itemtype'] = 'PluginFusioninventoryUnmanaged';
     $input['items_id'] = $unmanageds_id;
     $input['instantiation_type'] = 'NetworkPortEthernet';
     $input['name'] = 'general';
     $input['mac'] = '00:00:00:43:ae:0f';
     $input['is_dynamic'] = 1;
     $networkports_id = $networkPort->add($input);
     $input = array();
     $input['items_id'] = $networkports_id;
     $input['itemtype'] = 'NetworkPort';
     $input['name'] = '';
     $input['is_dynamic'] = 1;
     $networknames_id = $networkName->add($input);
     $input = array();
     $input['entities_id'] = 0;
     $input['itemtype'] = 'NetworkName';
     $input['items_id'] = $networknames_id;
     $input['name'] = '192.168.20.1';
     $input['is_dynamic'] = 1;
     $iPAddress->add($input);
     $pfUnmanaged->import($unmanageds_id);
     $cnt = countElementsInTable("glpi_networkequipments");
     $this->assertEquals(1, $cnt, "May have network equipment added");
     $cnt = countElementsInTable("glpi_plugin_fusioninventory_unmanageds");
     $this->assertEquals(0, $cnt, "Unknown device may be deleted");
     $networkEquipment->getFromDB(1);
     $this->assertEquals('XXS6BEF3', $networkEquipment->fields['serial'], "Serial");
     $this->assertEquals('switch', $networkEquipment->fields['name'], "Name");
     $this->assertEquals(1, $networkEquipment->fields['is_dynamic'], "is_dynamic");
     $this->assertEquals(1, $networkEquipment->fields['locations_id'], "locations_id");
     $this->assertEquals('this is a comment', $networkEquipment->fields['comment'], "comment");
     $networkPort->getFromDB(1);
     $a_reference = array('name' => 'general', 'id' => '1', 'items_id' => '1', 'itemtype' => 'NetworkEquipment', 'entities_id' => '0', 'is_recursive' => '0', 'logical_number' => '0', 'instantiation_type' => 'NetworkPortEthernet', 'mac' => '00:00:00:43:ae:0f', 'comment' => '', 'is_deleted' => '0', 'is_dynamic' => '1');
     $this->assertEquals($a_reference, $networkPort->fields, "Networkport");
     $networkName->getFromDB(1);
     $a_reference = array('id' => '1', 'entities_id' => '0', 'items_id' => '1', 'itemtype' => 'NetworkPort', 'comment' => NULL, 'fqdns_id' => '0', 'is_deleted' => '0', 'is_dynamic' => '1', 'name' => '');
     $this->assertEquals($a_reference, $networkName->fields, "Networkname");
     $iPAddress->getFromDB(1);
     $a_reference = array('name' => '192.168.20.1', 'id' => '1', 'entities_id' => '0', 'items_id' => '1', 'itemtype' => 'NetworkName', 'version' => '4', 'binary_0' => '0', 'binary_1' => '0', 'binary_2' => '65535', 'binary_3' => '3232240641', 'is_deleted' => '0', 'is_dynamic' => '1', 'mainitems_id' => '1', 'mainitemtype' => 'NetworkEquipment');
     $this->assertEquals($a_reference, $iPAddress->fields, "IPAddress");
 }
 /**
  * Override standard validation and sending notification to send the good PDF reports with 
  * appropriate rigths.
  * 
  * @see NotificationTarget::validateSendTo()
  * 
  * @param string $event notification event
  * @param Array $infos Current user informations
  * @param Boolean $notify_me Notify the current user of his own actions ?
  * 
  * @return boolean false to prevent standard mail sending
  */
 function validateSendTo($event, array $infos, $notify_me = false)
 {
     global $DB;
     if (isset($infos['users_id'])) {
         // save session variables
         $saved_session = $_SESSION;
         // Get current user full informations
         $user = new User();
         $user->getFromDB($infos['users_id']);
         // inialize session for user to build the proper PDF report
         unset($_SESSION['glpiprofiles'], $_SESSION['glpiactiveentities'], $_SESSION['glpiactiveprofile']);
         Session::initEntityProfiles($infos['users_id']);
         // Use default profile if exist
         if (isset($_SESSION['glpiprofiles'][$user->fields['profiles_id']])) {
             Session::changeProfile($user->fields['profiles_id']);
             // Else use first
         } else {
             Session::changeProfile(key($_SESSION['glpiprofiles']));
         }
         $user_name = $infos['username'] . '_';
         $file_name = $this->_buildPDF($user_name);
         $path = GLPI_PLUGIN_DOC_DIR . '/mreporting/notifications/' . $file_name;
         $mmail = new NotificationMail();
         $mmail->AddCustomHeader("Auto-Submitted: auto-generated");
         // For exchange
         $mmail->AddCustomHeader("X-Auto-Response-Suppress: OOF, DR, NDR, RN, NRN");
         // Get current entity administrator info to send the email from him
         $admin = $this->getSender();
         $mmail->From = $admin['email'];
         $mmail->FromName = $admin['name'];
         // Attach pdf to mail
         $mmail->AddAttachment($path, $file_name);
         // Get content infos
         $query = 'SELECT * 
               FROM glpi_notificationtemplatetranslations
               WHERE notificationtemplates_id = (
                  SELECT id 
                  FROM glpi_notificationtemplates 
                  WHERE itemtype = "PluginMreportingNotification"
               )
               AND (language LIKE "' . $_SESSION['glpilanguage'] . '" OR language LIKE "")
               ORDER BY language DESC
               LIMIT 0, 1';
         $result = $DB->query($query);
         $translation = $result->fetch_array();
         $mmail->isHTML(true);
         $mmail->Subject = $translation['subject'];
         $mmail->Body = $translation['content_html'];
         $mmail->AltBody = $translation['content_text'];
         $mmail->AddAddress($infos['email']);
         if ($mmail->Send()) {
         }
         //restore session
         unset($_SESSION);
         $_SESSION = $saved_session;
     }
     return false;
 }
 /**
  * @test
  */
 public function UpdateNetworkEquipment()
 {
     // Load session rights
     $_SESSION['glpidefault_entity'] = 0;
     Session::initEntityProfiles(2);
     Session::changeProfile(4);
     // Update 2nd time
     $pfCND = new PluginFusioninventoryCommunicationNetworkDiscovery();
     $networkEquipment = new NetworkEquipment();
     $networkEquipment->getFromDB(1);
     $_SESSION['SOURCE_XMLDEVICE'] = $this->source_xmldevice;
     $pfCND->importDevice($networkEquipment);
 }