Пример #1
0
 /**
  * @since version 0.84
  *
  * @param $row             HTMLTableRow object (default NULL)
  * @param $item            CommonDBTM object (default NULL)
  * @param $father          HTMLTableCell object (default NULL)
  * @param $options   array
  **/
 static function getHTMLTableCellsForItem(HTMLTableRow $row = NULL, CommonDBTM $item = NULL, HTMLTableCell $father = NULL, array $options = array())
 {
     global $DB, $CFG_GLPI;
     $column_name = __CLASS__;
     if (empty($item)) {
         if (empty($father)) {
             return;
         }
         $item = $father->getItem();
     }
     switch ($item->getType()) {
         case 'FQDN':
             $JOINS = "";
             $ORDER = "`glpi_networknames`.`name`";
             if (isset($options['order'])) {
                 switch ($options['order']) {
                     case 'name':
                         break;
                     case 'ip':
                         $JOINS = " LEFT JOIN `glpi_ipaddresses`\n                                    ON (`glpi_ipaddresses`.`items_id` = `glpi_networknames`.`id`\n                                        AND `glpi_ipaddresses`.`itemtype` = 'NetworkName'\n                                        AND `glpi_ipaddresses`.`is_deleted` = '0')";
                         $ORDER = "ISNULL (`glpi_ipaddresses`.`id`),\n                               `glpi_ipaddresses`.`binary_3`, `glpi_ipaddresses`.`binary_2`,\n                               `glpi_ipaddresses`.`binary_1`, `glpi_ipaddresses`.`binary_0`";
                         break;
                     case 'alias':
                         $JOINS = " LEFT JOIN `glpi_networkaliases`\n                                    ON (`glpi_networkaliases`.`networknames_id`\n                                          = `glpi_networknames`.`id`)";
                         $ORDER = "ISNULL(`glpi_networkaliases`.`name`),\n                               `glpi_networkaliases`.`name`";
                         break;
                 }
             }
             $query = "SELECT `glpi_networknames`.`id`\n                      FROM `glpi_networknames`\n                      {$JOINS}\n                      WHERE `glpi_networknames`.`fqdns_id` = '" . $item->fields["id"] . "'\n                            AND `glpi_networknames`.`is_deleted` = '0'\n                      ORDER BY {$ORDER}";
             break;
         case 'NetworkPort':
             $query = "SELECT `id`\n                      FROM `glpi_networknames`\n                      WHERE `itemtype` = '" . $item->getType() . "'\n                            AND `items_id` = '" . $item->getID() . "'\n                            AND `glpi_networknames`.`is_deleted` = '0'";
             break;
         case 'NetworkEquipment':
             $query = "SELECT `glpi_networknames`.`id`\n                      FROM `glpi_networknames`, `glpi_networkports`\n                      WHERE `glpi_networkports`.`itemtype` = '" . $item->getType() . "'\n                            AND `glpi_networkports`.`items_id` ='" . $item->getID() . "'\n                            AND `glpi_networknames`.`itemtype` = 'NetworkPort'\n                            AND `glpi_networknames`.`items_id` = `glpi_networkports`.`id`\n                            AND `glpi_networknames`.`is_deleted` = '0'";
             break;
     }
     if (isset($options['SQL_options'])) {
         $query .= " " . $options['SQL_options'];
     }
     $canedit = isset($options['canedit']) && $options['canedit'];
     $createRow = isset($options['createRow']) && $options['createRow'];
     $options['createRow'] = false;
     $address = new self();
     foreach ($DB->request($query) as $line) {
         if ($address->getFromDB($line["id"])) {
             if ($createRow) {
                 $row = $row->createAnotherRow();
             }
             if (isset($options['massiveactionnetworkname']) && $options['massiveactionnetworkname']) {
                 $header = $row->getGroup()->getHeaderByName('Internet', 'delete');
                 $cell_value = Html::getMassiveActionCheckBox(__CLASS__, $line["id"]);
                 $delete_cell = $row->addCell($header, $cell_value, $father);
             }
             $internetName = $address->getInternetName();
             if (empty($internetName)) {
                 $internetName = "(" . $line["id"] . ")";
             }
             $content = $internetName;
             if (Session::haveRight('internet', READ)) {
                 $content = "<a href='" . $address->getLinkURL() . "'>" . $internetName . "</a>";
             }
             if (!isset($options['dont_display'][$column_name])) {
                 $header = $row->getGroup()->getHeaderByName('Internet', $column_name);
                 $name_cell = $row->addCell($header, $content, $father, $address);
                 if (isset($options['display_isDynamic']) && $options['display_isDynamic']) {
                     $dyn_header = $row->getGroup()->getHeaderByName('Internet', $column_name . '_dynamic');
                     $dynamic_cell = $row->addCell($dyn_header, Dropdown::getYesNo($address->fields['is_dynamic']), $name_cell);
                     $father_for_children = $dynamic_cell;
                 } else {
                     $father_for_children = $name_cell;
                 }
             } else {
                 $father_for_children = $father;
             }
             NetworkAlias::getHTMLTableCellsForItem($row, $address, $father_for_children, $options);
             IPAddress::getHTMLTableCellsForItem($row, $address, $father_for_children, $options);
         }
     }
 }
Пример #2
0
 /**
  * @since version 0.84
  *
  * @param $row                HTMLTableRow object (default NULL)
  * @param $item               CommonDBTM object (default NULL)
  * @param $father             HTMLTableCell object (default NULL)
  * @param $options   array
  **/
 static function getHTMLTableCellsForItem(HTMLTableRow $row = NULL, CommonDBTM $item = NULL, HTMLTableCell $father = NULL, array $options = array())
 {
     global $DB, $CFG_GLPI;
     if (empty($item)) {
         if (empty($father)) {
             return;
         }
         $item = $father->getItem();
     }
     if ($item->getType() != 'NetworkName') {
         return;
     }
     $column_name = __CLASS__;
     if (isset($options['dont_display'][$column_name])) {
         return;
     }
     $header = $row->getGroup()->getHeaderByName('Internet', $column_name);
     if (!$header) {
         return;
     }
     $canedit = isset($options['canedit']) && $options['canedit'];
     $createRow = isset($options['createRow']) && $options['createRow'];
     $options['createRow'] = false;
     $query = "SELECT `id`\n                               FROM `glpi_networkaliases`\n                               WHERE `networknames_id` = '" . $item->getID() . "'";
     $alias = new self();
     foreach ($DB->request($query) as $line) {
         if ($alias->getFromDB($line["id"])) {
             if ($createRow) {
                 $row = $row->createRow();
             }
             $content = "<a href='" . $alias->getLinkURL() . "'>" . $alias->getInternetName() . "</a>";
             $row->addCell($header, $content, $father, $alias);
         }
     }
 }
 /**
  * @since version 0.84
  *
  * @param $row                HTMLTableRow object (default NULL)
  * @param $item               CommonDBTM object (default NULL)
  * @param $father             HTMLTableCell object (default NULL)
  * @param $options   array
  **/
 static function getHTMLTableCellsForItem(HTMLTableRow $row = NULL, CommonDBTM $item = NULL, HTMLTableCell $father = NULL, array $options = array())
 {
     global $DB, $CFG_GLPI;
     if (empty($item)) {
         if (empty($father)) {
             return;
         }
         $item = $father->getItem();
     }
     $query = self::getSQLRequestToSearchForItem($item->getType(), $item->getID());
     if (!empty($query)) {
         $relation = new static();
         foreach ($DB->request($query) as $line) {
             if ($line['is_1'] != $line['is_2']) {
                 if ($line['is_1'] == 0) {
                     $options['items_id'] = $line['items_id_1'];
                     $oppositetype = $line['itemtype_1'];
                 } else {
                     $options['items_id'] = $line['items_id_2'];
                     $oppositetype = $line['itemtype_2'];
                 }
                 if (class_exists($oppositetype) && method_exists($oppositetype, 'getHTMLTableCellsForItem') && $relation->getFromDB($line[static::getIndexName()])) {
                     $oppositetype::getHTMLTableCellsForItem($row, $relation, $father, $options);
                 }
             }
         }
     }
 }
 /**
  * @since version 0.84
  *
  * @see CommonDevice::getHTMLTableCellForItem()
  **/
 static function getHTMLTableCellsForItem(HTMLTableRow $row = NULL, CommonDBTM $item = NULL, HTMLTableCell $father = NULL, array $options = array())
 {
     $column_name = __CLASS__;
     if (isset($options['dont_display'][$column_name])) {
         return;
     }
     if (empty($item)) {
         if (empty($father)) {
             return;
         }
         $item = $father->getItem();
     }
     if (in_array($item->getType(), NetworkPort::getNetworkPortInstantiations())) {
         $link = new Item_DeviceNetworkCard();
         if ($link->getFromDB($item->fields['items_devicenetworkcards_id'])) {
             $device = $link->getOnePeer(1);
             if ($device) {
                 $row->addCell($row->getHeaderByName($column_name), $device->getLink(), $father);
             }
         }
     }
 }
Пример #5
0
 function prepareDisplay()
 {
     if ($this->empty) {
         return false;
     }
     // First, compute the total nomber of rows ...
     $this->numberOfSubRows = 0;
     foreach ($this->cells as $cellsOfHeader) {
         if (isset($cellsOfHeader[0])) {
             $header = $cellsOfHeader[0]->getHeader();
             if (is_null($header->getFather())) {
                 $numberOfSubRowsPerHeader = 0;
                 foreach ($cellsOfHeader as $cell) {
                     $cell->computeNumberOfLines();
                     $numberOfSubRowsPerHeader += $cell->getNumberOfLines();
                 }
                 if ($this->numberOfSubRows < $numberOfSubRowsPerHeader) {
                     $this->numberOfSubRows = $numberOfSubRowsPerHeader;
                 }
             }
         }
     }
     // Then notify each cell and compute its starting row
     foreach ($this->cells as $cellsOfHeader) {
         if (isset($cellsOfHeader[0])) {
             $header = $cellsOfHeader[0]->getHeader();
             // Only do this for cells that don't have father: they will propagate this to there sons
             if (is_null($header->getFather())) {
                 HTMLTableCell::updateCellSteps($cellsOfHeader, $this->numberOfSubRows);
                 $start = 0;
                 foreach ($cellsOfHeader as $cell) {
                     $cell->computeStartEnd($start);
                 }
             }
         }
     }
     return true;
 }
Пример #6
0
 /**
  * @since version 0.84
  *
  * @param $row             HTMLTableRow object (default NULL)
  * @param $item            CommonDBTM object (default NULL)
  * @param $father          HTMLTableCell object (default NULL)
  * @param $options   array
  **/
 static function getHTMLTableCellsForItem(HTMLTableRow $row = NULL, CommonDBTM $item = NULL, HTMLTableCell $father = NULL, array $options = array())
 {
     global $DB, $CFG_GLPI;
     $column_name = __CLASS__;
     if (isset($options['dont_display'][$column_name])) {
         return;
     }
     if (empty($item)) {
         if (empty($father)) {
             return;
         }
         $item = $father->getItem();
     }
     $canedit = isset($options['canedit']) && $options['canedit'];
     if ($item->getType() == 'NetworkPort_Vlan') {
         if (isset($item->fields["tagged"]) && $item->fields["tagged"] == 1) {
             $tagged_msg = __('Tagged');
         } else {
             $tagged_msg = __('Untagged');
         }
         $vlan = new self();
         if ($vlan->getFromDB($options['items_id'])) {
             $content = sprintf(__('%1$s - %2$s'), $vlan->getName(), $tagged_msg);
             $content .= Html::showToolTip(sprintf(__('%1$s: %2$s'), __('ID TAG'), $vlan->fields['tag']) . "<br>" . sprintf(__('%1$s: %2$s'), __('Comments'), $vlan->fields['comment']), array('display' => false));
             $this_cell = $row->addCell($row->getHeaderByName($column_name), $content, $father);
         }
     }
 }
Пример #7
0
 /**
  * @since version 0.84
  *
  * @param $row                HTMLTableRow object (default NULL)
  * @param $item               CommonDBTM object (default NULL)
  * @param $father             HTMLTableCell object (default NULL)
  * @param $options   array
  **/
 static function getHTMLTableCellsForItem(HTMLTableRow $row = NULL, CommonDBTM $item = NULL, HTMLTableCell $father = NULL, array $options = array())
 {
     global $DB, $CFG_GLPI;
     if (empty($item)) {
         if (empty($father)) {
             return;
         }
         $item = $father->getItem();
     }
     if ($item->getType() != 'IPAddress') {
         return;
     }
     $column_name = __CLASS__;
     if (isset($options['dont_display'][$column_name])) {
         return;
     }
     $header = $row->getGroup()->getHeaderByName('Internet', __CLASS__);
     if (!$header) {
         return;
     }
     $createRow = isset($options['createRow']) && $options['createRow'];
     $options['createRow'] = false;
     $network = new self();
     foreach (self::searchNetworksContainingIP($item) as $networks_id) {
         if ($network->getFromDB($networks_id)) {
             if ($createRow) {
                 $row = $row->createRow();
             }
             //TRANS: %1$s is address, %2$s is netmask
             $content = sprintf(__('%1$s / %2$s'), $network->getAddress()->getTextual(), $network->getNetmask()->getTextual());
             if ($network->fields['addressable'] == 1) {
                 $content = "<span class='b'>" . $content . "</span>";
             }
             $content = sprintf(__('%1$s - %2$s'), $content, $network->getLink());
             $this_cell = $row->addCell($header, $content, $father, $network);
         }
     }
 }