예제 #1
0
   /**
    * Get comments for host
    * $id, host id
    *    default is current host instance
    *
    */
   function getComments($id=-1) {
      global $CFG_GLPI;

      if ($id == -1) {
         $pm_Host = $this;
      } else {
         $pm_Host = new PluginMonitoringHost();
         $pm_Host->getFromDB($id);
      }

      // Toolbox::logInFile("pm", "Host getcomments : $id : ".$pm_Host->getID()."\n");
      $comment = "";
      $toadd   = array();

      // associated computer ...
      $item = new $pm_Host->fields['itemtype'];
      $item->getFromDB($pm_Host->fields['items_id']);

      if ($pm_Host->getField('itemtype') == 'Computer') {
         if ($item->isField('completename')) {
            $toadd[] = array('name'  => __('Complete name'),
                             'value' => nl2br($item->getField('completename')));
         }

         $type = new ComputerType();
         if ($item->getField("computertypes_id")) {
            $type->getFromDB($item->getField("computertypes_id"));
            $type = $type->getName();
            if (! empty($type)) {
               $toadd[] = array('name'  => __('Type'),
                                'value' => nl2br($type));
            }
         } else {
            return $comment;
         }

         $model = new ComputerModel();
         if ($item->getField("computermodels_id")) {
            $model->getFromDB($item->getField("computermodels_id"));
            $model = $model->getName();
            if (! empty($model)) {
               $toadd[] = array('name'  => __('Model'),
                                'value' => nl2br($model));
            }
         }

         $state = new State();
         $state->getFromDB($item->fields["states_id"]);
         $state = $state->getName();
         if (! empty($state)) {
            $toadd[] = array('name'  => __('State'),
                             'value' => nl2br($state));
         }

         $entity = new Entity();
         $entity->getFromDB($item->fields["entities_id"]);
         $entity = $entity->getName();
         if (! empty($entity)) {
            $toadd[] = array('name'  => __('Entity'),
                             'value' => nl2br($entity));
         }

         $location = new Location();
         $location->getFromDB($item->fields["locations_id"]);
         $location = $location->getName(array('complete'  => true));
         if (! empty($location)) {
            $toadd[] = array('name'  => __('Location'),
                             'value' => nl2br($location));
         }

         if (! empty($item->fields["serial"])) {
            $toadd[] = array('name'  => __('Serial'),
                             'value' => nl2br($item->fields["serial"]));
         }
         if (! empty($item->fields["otherserial"])) {
            $toadd[] = array('name'  => __('Inventory number'),
                             'value' => nl2br($item->fields["otherserial"]));
         }

         if (($pm_Host instanceof CommonDropdown)
             && $pm_Host->isField('comment')) {
            $toadd[] = array('name'  => __('Comments'),
                             'value' => nl2br($pm_Host->getField('comment')));
         }

         if (count($toadd)) {
            foreach ($toadd as $data) {
               $comment .= sprintf(__('%1$s: %2$s')."<br>",
                                   "<span class='b'>".$data['name'], "</span>".$data['value']);
            }
         }
      } else {
         $toadd[] = array('name'  => __('Host type'),
                          'value' => nl2br($item->getTypeName()));

         if ($item->isField('completename')) {
            $toadd[] = array('name'  => __('Complete name'),
                             'value' => nl2br($item->getField('completename')));
         }
      }

      if (!empty($comment)) {
         return Html::showToolTip($comment, array('display' => false));
      }
   }