/**
  * Show the Device associated with an applicatif
  *
  * Called from the applicatif form
  **/
 static function showForAppliance(PluginAppliancesAppliance $appli)
 {
     global $DB, $CFG_GLPI;
     $instID = $appli->fields['id'];
     if (!$appli->can($instID, "r")) {
         return false;
     }
     $rand = mt_rand();
     $canedit = $appli->can($instID, 'w');
     $query = "SELECT DISTINCT `itemtype`\n                FROM `glpi_plugin_appliances_appliances_items`\n                WHERE `plugin_appliances_appliances_id` = '" . $instID . "'\n                ORDER BY `itemtype`";
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     $i = 0;
     if (Session::isMultiEntitiesMode()) {
         $colsup = 1;
     } else {
         $colsup = 0;
     }
     echo "<form method='post' name='appliances_form{$rand}' id='appliances_form{$rand}' action=\"" . $CFG_GLPI["root_doc"] . "/plugins/appliances/front/appliance.form.php\">";
     echo "<div class='center'><table class='tab_cadre_fixehov'>";
     echo "<tr><th colspan='" . ($canedit ? 6 + $colsup : 5 + $colsup) . "'>" . __('Associated items', 'appliances') . "</th></tr><tr>";
     if ($canedit) {
         echo "<th>&nbsp;</th>";
     }
     echo "<th>" . __('Type') . "</th>";
     echo "<th>" . __('Name') . "</th>";
     if (Session::isMultiEntitiesMode()) {
         echo "<th>" . __('Entity') . "</th>";
     }
     if ($appli->fields["relationtype"]) {
         echo "<th>" . __('Item to link', 'appliances') . "<br>" . __('User fields', 'appliances') . "</th>";
     }
     echo "<th>" . __('Serial number') . "</th>";
     echo "<th>" . __('Inventory number') . "</th>";
     echo "</tr>";
     for ($i = 0; $i < $number; $i++) {
         $type = $DB->result($result, $i, "itemtype");
         if (!($item = getItemForItemtype($type))) {
             continue;
         }
         if ($item->canView()) {
             $column = "name";
             if ($type == 'Ticket') {
                 $column = "id";
             }
             if ($type == 'KnowbaseItem') {
                 $column = "question";
             }
             $query = "SELECT `" . $item->getTable() . "`.*,\n                             `glpi_plugin_appliances_appliances_items`.`id` AS IDD,\n                             `glpi_entities`.`id` AS entity\n                      FROM `glpi_plugin_appliances_appliances_items`, " . getTableForItemType($type) . "\n                      LEFT JOIN `glpi_entities`\n                           ON (`glpi_entities`.`id` = `" . $item->getTable() . "`.`entities_id`)\n                      WHERE `" . $item->getTable() . "`.`id`\n                                 = `glpi_plugin_appliances_appliances_items`.`items_id`\n                            AND `glpi_plugin_appliances_appliances_items`.`itemtype` = '" . $type . "'\n                            AND `glpi_plugin_appliances_appliances_items`.`plugin_appliances_appliances_id`\n                                 = '" . $instID . "' " . getEntitiesRestrictRequest(" AND ", $item->getTable());
             if ($item->maybeTemplate()) {
                 $query .= " AND `" . $item->getTable() . "`.`is_template` = '0'";
             }
             $query .= " ORDER BY `glpi_entities`.`completename`, `" . $item->getTable() . "`.{$column}";
             if ($result_linked = $DB->query($query)) {
                 if ($DB->numrows($result_linked)) {
                     Session::initNavigateListItems($type, _n('Appliance', 'Appliances', 2, 'appliances') . "\n                                                   = " . $appli->getNameID());
                     while ($data = $DB->fetch_assoc($result_linked)) {
                         $item->getFromDB($data["id"]);
                         Session::addToNavigateListItems($type, $data["id"]);
                         //TODO $ID never user - why this part ?
                         $ID = "";
                         if ($type == 'Ticket') {
                             $data["name"] = sprintf(__('%1$s %2$s'), __('Ticket'), $data["id"]);
                         }
                         if ($type == 'KnowbaseItem') {
                             $data["name"] = $data["question"];
                         }
                         if ($_SESSION["glpiis_ids_visible"] || empty($data["name"])) {
                             $ID = " (" . $data["id"] . ")";
                         }
                         $name = $item->getLink();
                         echo "<tr class='tab_bg_1'>";
                         if ($canedit) {
                             echo "<td width='10'>";
                             $sel = "";
                             if (isset($_GET["select"]) && $_GET["select"] == "all") {
                                 $sel = "checked";
                             }
                             echo "<input type='checkbox' name='item[" . $data["IDD"] . "]' value='1' {$sel}>";
                             echo "</td>";
                         }
                         echo "<td class='center'>" . $item->getTypeName() . "</td>";
                         echo "<td class='center' " . (isset($data['deleted']) && $data['deleted'] ? "class='tab_bg_2_2'" : "") . ">" . $name . "</td>";
                         if (Session::isMultiEntitiesMode()) {
                             echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entity']) . "</td>";
                         }
                         if ($appli->fields["relationtype"]) {
                             echo "<td class='center'>" . PluginAppliancesRelation::getTypeName($appli->fields["relationtype"]) . "&nbsp;:&nbsp;";
                             PluginAppliancesRelation::showList($appli->fields["relationtype"], $data["IDD"], $item->fields["entities_id"], false);
                             PluginAppliancesOptvalue_Item::showList($type, $data["id"], $instID, false);
                             echo "</td>";
                         }
                         echo "<td class='center'>" . (isset($data["serial"]) ? "" . $data["serial"] . "" : "-") . "</td>";
                         echo "<td class='center'>" . (isset($data["otherserial"]) ? "" . $data["otherserial"] . "" : "-") . "</td>";
                         echo "</tr>";
                     }
                 }
             }
         }
     }
     if ($canedit) {
         echo "<tr class='tab_bg_1'><td colspan='" . (3 + $colsup) . "' class='center'>";
         echo "<input type='hidden' name='conID' value='{$instID}'>";
         Dropdown::showAllItems("item", 0, 0, $appli->fields['is_recursive'] ? -1 : $appli->fields['entities_id'], $appli->getTypes());
         echo "</td>";
         echo "<td colspan='3' class='center' class='tab_bg_2'>";
         echo "<input type='submit' name='additem' value='" . __('Add') . "' class='submit'>";
         echo "</td></tr>";
         echo "</table></div>";
         Html::openArrowMassives("appliances_form{$rand}", true);
         Html::closeArrowMassives(array('deleteitem' => __('Delete permanently')));
     } else {
         echo "</table></div>";
     }
     Html::closeForm();
 }
Example #2
0
 /**
  * Show for PDF the current applicatif
  *
  * @param $pdf object for the output
  **/
 function show_PDF($pdf)
 {
     global $DB;
     $pdf->setColumnsSize(50, 50);
     $col1 = '<b>' . sprintf(__('%1$s %2$s'), __('ID'), $this->fields['id']) . '</b>';
     if (isset($this->fields["date_mod"])) {
         $col2 = sprintf(__('%1$s: %2$s'), __('Last update'), Html::convDateTime($this->fields["date_mod"]));
     } else {
         $col2 = '';
     }
     $pdf->displayTitle($col1, $col2);
     $pdf->displayLine(sprintf(__('%1$s: %2$s'), '<b><i>' . __('Name') . '</i></b>', $this->fields['name']), sprintf(__('%1$s: %2$s'), '<b><i>' . -n('Status', 'Statuses', 1) . '</i></b>', Html::clean(Dropdown::getDropdownName('glpi_states', $this->fields['states_id']))));
     $pdf->displayLine(sprintf(__('%1$s: %2$s'), '<b><i>' . __('Location') . '</i></b>', Html::clean(Dropdown::getDropdownName('glpi_locations', $this->fields['locations_id']))), sprintf(__('%1$s: %2$s'), '<b><i>' . __('Type') . '</i></b>', Html::clean(Dropdown::getDropdownName('glpi_plugin_appliances_appliancetypes', $this->fields['plugin_appliances_appliancetypes_id']))));
     $pdf->displayLine(sprintf(__('%1$s: %2$s'), '<b><i>' . __('Technician in charge of the hardware') . '</i></b>', getUserName($this->fields['users_id_tech'])), sprintf(__('%1$s: %2$s'), '<b><i>' . __('Environment', 'appliances') . '</i></b>', Html::clean(Dropdown::getDropdownName('glpi_plugin_appliances_environments', $this->fields['plugin_appliances_environments_id']))));
     $pdf->displayLine(sprintf(__('%1$s: %2$s'), '<b><i>' . __('Group in charge of the hardware') . '</i></b>', Html::clean(Dropdown::getDropdownName('glpi_groups', $this->fields['groups_id_tech']))), sprintf(__('%1$s: %2$s'), '<b><i>' . __('Serial number') . '</i></b>', $this->fields['serial']));
     $pdf->displayLine(sprintf(__('%1$s: %2$s'), '<b><i>' . __('User') . '</i></b>', getUserName($this->fields['users_id'])), sprintf(__('%1$s: %2$s'), '<b><i>' . __('Inventory number') . '</i></b>', $this->fields['otherserial']));
     $pdf->displayLine(sprintf(__('%1$s: %2$s'), '<b><i>' . __('Group') . '</i></b>', Html::clean(Dropdown::getDropdownName('glpi_groups', $this->fields['groups_id']))), '');
     $pdf->displayLine(sprintf(__('%1$s: %2$s'), '<b><i>' . __('Associable to a ticket') . '</i></b>', Dropdown::getYesNo($this->fields['is_helpdesk_visible'])), sprintf(__('%1$s: %2$s'), '<b><i>' . __('Item to link') . '</i></b>', Html::clean(PluginAppliancesRelation::getTypeName($this->fields['relationtype']))));
     $pdf->displayText(sprintf(__('%1$s: %2$s'), '<b><i>' . __('Comments') . '</i></b>', $this->fields['comment']));
     $pdf->displaySpace();
 }
Example #3
0
 /**
  * Show for PDF the relation for a device/applicatif
  *
  * @param $pdf object for the output
  * @param $drelation_type : type of the relation
  * @param $relID ID of the relation
  **/
 static function showList_PDF($pdf, $relationtype, $relID)
 {
     global $DB, $CFG_GLPI;
     if (!$relationtype) {
         return false;
     }
     // selects all the attached relations
     $tablename = PluginAppliancesRelation::getTypeTable($relationtype);
     $title = PluginAppliancesRelation::getTypeName($relationtype);
     if ($tablename == 'glpi_locations') {
         $sql_loc = "SELECT `glpi_plugin_appliances_relations`.`id`,\n                            `completename` AS dispname ";
     } else {
         $sql_loc = "SELECT `glpi_plugin_appliances_relations`.`id`,\n                            `name` AS dispname ";
     }
     $sql_loc .= "FROM `" . $tablename . "` ,\n                        `glpi_plugin_appliances_relations`,\n                        `glpi_plugin_appliances_appliances_items`\n                   WHERE `" . $tablename . "`.`id` = `glpi_plugin_appliances_relations`.`relations_id`\n                         AND `glpi_plugin_appliances_relations`.`plugin_appliances_appliances_items_id`\n                                 = `glpi_plugin_appliances_appliances_items`.`id`\n                         AND `glpi_plugin_appliances_appliances_items`.`id` = '" . $relID . "'";
     $result_loc = $DB->query($sql_loc);
     $opts = array();
     while ($res = $DB->fetch_array($result_loc)) {
         $opts[] = $res["dispname"];
     }
     $pdf->setColumnsSize(100);
     $pdf->displayLine(sprintf(__('%1$s: %2$s'), "<b><i>" . __('Item to link', 'appliances') . "{$title} </i> </b>", implode(', ', $opts)));
 }