getTypeName() static public method

static public getTypeName ( $nb )
示例#1
0
 /**
  * Get the group of elements regarding given item.
  * Two kind of item :
  *              - Device* feed by a link to the attached item (Computer, Printer ...)
  *              - Computer, Printer ...: feed by the "global" properties of the CommonDevice
  * Then feed with the specificities of the Item_Device elements
  * In cas of $item is an instance, then $options contains the type of the item (Computer,
  * Printer ...).
  *
  * @param $item
  * @param $table
  * @param $options            array
  * @param $delete_all_column          (default NULL)
  * @param $common_column
  * @param $specific_column
  * @param $delete_column               (default NULL)
  * @param $dynamic_column
  **/
 function getTableGroup(CommonDBTM $item, HTMLTableMain $table, array $options, HTMLTableSuperHeader $delete_all_column = NULL, HTMLTableSuperHeader $common_column, HTMLTableSuperHeader $specific_column, HTMLTableSuperHeader $delete_column = NULL, $dynamic_column)
 {
     global $DB;
     $is_device = $item instanceof CommonDevice;
     if ($is_device) {
         $peer_type = $options['itemtype'];
         if (empty($peer_type)) {
             $column_label = __('Dissociated devices');
             $group_name = 'None';
         } else {
             $column_label = $peer_type::getTypeName(Session::getPluralNumber());
             $group_name = $peer_type;
         }
         $table_group = $table->createGroup($group_name, '');
         $peer_column = $table_group->addHeader('item', $column_label, $common_column, NULL);
         if (!empty($peer_type)) {
             //TRANS : %1$s is the type of the device
             //        %2$s is the type of the item
             //        %3$s is the name of the item (used for headings of a list),
             $itemtype_nav_title = sprintf(__('%1$s of %2$s: %3$s'), $peer_type::getTypeName(Session::getPluralNumber()), $item->getTypeName(1), $item->getName());
             $peer_column->setItemType($peer_type, $itemtype_nav_title);
         }
     } else {
         $peer_type = $this->getDeviceType();
         $table_group = $table->createGroup($peer_type, '');
         //TRANS : %1$s is the type of the device
         //        %2$s is the type of the item
         //        %3$s is the name of the item (used for headings of a list),
         $options['itemtype_title'] = sprintf(__('%1$s of %2$s: %3$s'), $peer_type::getTypeName(Session::getPluralNumber()), $item->getTypeName(1), $item->getName());
         $peer_type::getHTMLTableHeader($item->getType(), $table_group, $common_column, NULL, $options);
     }
     $specificity_columns = array();
     $link_column = $table_group->addHeader('spec_link', '', $specific_column);
     $spec_column = $link_column;
     foreach ($this->getSpecificities() as $field => $attributs) {
         $spec_column = $table_group->addHeader('spec_' . $field, $attributs['long name'], $specific_column, $spec_column);
         $specificity_columns[$field] = $spec_column;
     }
     $infocom_column = $table_group->addHeader('infocom', Infocom::getTypeName(Session::getPluralNumber()), $specific_column, $spec_column);
     $document_column = $table_group->addHeader('document', Document::getTypeName(Session::getPluralNumber()), $specific_column, $spec_column);
     if ($item->isDynamic()) {
         $dynamics_column = $table_group->addHeader('one', ' ', $dynamic_column, $spec_column);
         $previous_column = $dynamics_column;
     } else {
         $previous_column = $spec_column;
     }
     if ($options['canedit']) {
         $group_checkbox_tag = empty($peer_type) ? '__' : $peer_type;
         $content = Html::getCheckbox(array('criterion' => array('tag_for_massive' => $group_checkbox_tag)));
         $delete_one = $table_group->addHeader('one', $content, $delete_column, $previous_column);
     }
     if ($is_device) {
         $fk = 'items_id';
         // Entity restrict
         $leftjoin = '';
         $where = "";
         if (!empty($peer_type)) {
             $leftjoin = "LEFT JOIN `" . getTableForItemType($peer_type) . "`\n                        ON (`" . $this->getTable() . "`.`items_id` = `" . getTableForItemType($peer_type) . "`.`id`\n                            AND `" . $this->getTable() . "`.`itemtype` = '{$peer_type}')";
             $where = getEntitiesRestrictRequest(" AND", getTableForItemType($peer_type));
         }
         $query = "SELECT `" . $this->getTable() . "`.*\n                   FROM `" . $this->getTable() . "`\n                   {$leftjoin}\n                   WHERE `" . $this->getDeviceForeignKey() . "` = '" . $item->getID() . "'\n                         AND `" . $this->getTable() . "`.`itemtype` = '{$peer_type}'\n                         AND `" . $this->getTable() . "`.`is_deleted` = '0'\n                         {$where}\n                   ORDER BY `" . $this->getTable() . "`.`itemtype`, `" . $this->getTable() . "`.`{$fk}`";
     } else {
         $fk = $this->getDeviceForeignKey();
         $query = "SELECT *\n                   FROM `" . $this->getTable() . "`\n                   WHERE `itemtype` = '" . $item->getType() . "'\n                         AND `items_id` = '" . $item->getID() . "'\n                         AND `is_deleted` = '0'\n                   ORDER BY {$fk}";
     }
     if (!empty($peer_type)) {
         $peer = new $peer_type();
         $peer->getEmpty();
     } else {
         $peer = NULL;
     }
     foreach ($DB->request($query) as $link) {
         Session::addToNavigateListItems(static::getType(), $link["id"]);
         $this->getFromDB($link['id']);
         if (is_null($peer) || $link[$fk] != $peer->getID()) {
             if ($peer instanceof CommonDBTM) {
                 $peer->getFromDB($link[$fk]);
             }
             $current_row = $table_group->createRow();
             $peer_group = $peer_type . '_' . $link[$fk] . '_' . mt_rand();
             $current_row->setHTMLID($peer_group);
             if ($options['canedit']) {
                 $cell_value = Html::getCheckAllAsCheckbox($peer_group);
                 $current_row->addCell($delete_all_column, $cell_value);
             }
             if ($is_device) {
                 $cell = $current_row->addCell($peer_column, $peer ? $peer->getLink() : __('None'), NULL, $peer);
                 if (is_null($peer)) {
                     $cell->setHTMLClass('center');
                 }
             } else {
                 $peer->getHTMLTableCellForItem($current_row, $item, NULL, $options);
             }
         }
         if (Session::haveRight('device', UPDATE)) {
             $mode = __s('Update');
         } else {
             $mode = __s('View');
         }
         $spec_cell = $current_row->addCell($link_column, "<a href='" . $this->getLinkURL() . "'>{$mode}</a>");
         foreach ($this->getSpecificities() as $field => $attributs) {
             if (!empty($link[$field])) {
                 $content = $link[$field];
             } else {
                 $content = '';
             }
             $spec_cell = $current_row->addCell($specificity_columns[$field], $content, $spec_cell);
         }
         if (countElementsInTable('glpi_infocoms', "`itemtype`='" . $this->getType() . "' AND\n                                                    `items_id`='" . $link['id'] . "'")) {
             $content = array(array('function' => 'Infocom::showDisplayLink', 'parameters' => array($this->getType(), $link['id'])));
         } else {
             $content = '';
         }
         $current_row->addCell($infocom_column, $content, $spec_cell);
         $content = array();
         // The order is to be sure that specific documents appear first
         $query = "SELECT `documents_id`\n                   FROM `glpi_documents_items`\n                   WHERE (`itemtype` = '" . $this->getType() . "' AND `items_id` = '" . $link['id'] . "')\n                          OR (`itemtype` = '" . $this->getDeviceType() . "'\n                              AND `items_id` = '" . $link[$this->getDeviceForeignKey()] . "')\n                   ORDER BY `itemtype` = '" . $this->getDeviceType() . "'";
         $document = new Document();
         foreach ($DB->request($query) as $document_link) {
             if ($document->can($document_link['documents_id'], READ)) {
                 $content[] = $document->getLink();
             }
         }
         $content = implode('<br>', $content);
         $current_row->addCell($document_column, $content, $spec_cell);
         if ($item->isDynamic()) {
             $previous_cell = $current_row->addCell($dynamics_column, Dropdown::getYesNo($link['is_dynamic']), $spec_cell);
         } else {
             $previous_cell = $spec_cell;
         }
         if ($options['canedit']) {
             $cell_value = Html::getMassiveActionCheckBox($this->getType(), $link['id'], array('massive_tags' => $group_checkbox_tag));
             $current_row->addCell($delete_one, $cell_value, $previous_cell);
         }
     }
 }
示例#2
0
based on GLPI - Gestionnaire Libre de Parc Informatique
Copyright (C) 2003-2014 by the INDEPNET Development Team.

-------------------------------------------------------------------------

LICENSE

This file is part of GLPI.

GLPI is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

GLPI is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with GLPI. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
/** @file
* @brief
*/
include '../inc/includes.php';
Session::checkRight("document", READ);
Html::header(Document::getTypeName(Session::getPluralNumber()), $_SERVER['PHP_SELF'], "management", "document");
Search::show('Document');
Html::footer();
示例#3
0
        $doc->redirectToList();
    } else {
        if (isset($_POST["restore"])) {
            $doc->check($_POST["id"], 'd');
            if ($doc->restore($_POST)) {
                Event::log($_POST["id"], "documents", 4, "document", sprintf(__('%s restores an item'), $_SESSION["glpiname"]));
            }
            $doc->redirectToList();
        } else {
            if (isset($_POST["purge"])) {
                $doc->check($_POST["id"], 'd');
                if ($doc->delete($_POST, 1)) {
                    Event::log($_POST["id"], "documents", 4, "document", sprintf(__('%s purges an item'), $_SESSION["glpiname"]));
                }
                $doc->redirectToList();
            } else {
                if (isset($_POST["update"])) {
                    $doc->check($_POST["id"], 'w');
                    if ($doc->update($_POST)) {
                        Event::log($_POST["id"], "documents", 4, "document", sprintf(__('%s updates an item'), $_SESSION["glpiname"]));
                    }
                    Html::back();
                } else {
                    Html::header(Document::getTypeName(2), $_SERVER['PHP_SELF'], "financial", "document");
                    $doc->showForm($_GET["id"]);
                    Html::footer();
                }
            }
        }
    }
}
示例#4
0
 function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
 {
     $nbdoc = $nbitem = 0;
     switch ($item->getType()) {
         case 'Document':
             $ong = array();
             if ($_SESSION['glpishow_count_on_tabs']) {
                 $nbdoc = self::countForDocument($item);
                 $nbitem = self::countForItem($item);
             }
             $ong[1] = self::createTabEntry(_n('Associated item', 'Associated items', Session::getPluralNumber()), $nbdoc);
             $ong[2] = self::createTabEntry(Document::getTypeName(Session::getPluralNumber()), $nbitem);
             return $ong;
         default:
             // Can exist for template
             if (Document::canView() || $item->getType() == 'Ticket' || $item->getType() == 'Reminder' || $item->getType() == 'KnowbaseItem') {
                 if ($_SESSION['glpishow_count_on_tabs']) {
                     $nbitem = self::countForItem($item);
                 }
                 return self::createTabEntry(Document::getTypeName(Session::getPluralNumber()), $nbitem);
             }
     }
     return '';
 }
示例#5
0
 function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
 {
     if (!$withtemplate) {
         if ($item->getType() == __CLASS__) {
             return __('See the map', 'positions');
         } else {
             if ($item->getType() == "Location") {
                 if ($_SESSION['glpishow_count_on_tabs']) {
                     return self::createTabEntry(Document::getTypeName(Session::getPluralNumber()), Document_Item::countForItem($item));
                 }
                 return Document::getTypeName(Session::getPluralNumber());
             } else {
                 if (in_array($item->getType(), self::getTypes(true)) && Session::haveRight('plugin_positions', READ)) {
                     if ($_SESSION['glpishow_count_on_tabs']) {
                         return self::createTabEntry(self::getTypeName(Session::getPluralNumber()), self::countForItem($item));
                     }
                     return self::getTypeName(Session::getPluralNumber());
                 }
             }
         }
     }
     return '';
 }
示例#6
0
 function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
 {
     switch ($item->getType()) {
         case 'Document':
             $ong = array();
             if ($_SESSION['glpishow_count_on_tabs']) {
                 $ong[1] = self::createTabEntry(_n('Associated item', 'Associated items', self::countForDocument($item)));
             }
             $ong[1] = _n('Associated item', 'Associated items', 2);
             if ($_SESSION['glpishow_count_on_tabs']) {
                 $ong[2] = Document::createTabEntry(Document::getTypeName(2), self::countForItem($item));
             }
             $ong[2] = Document::getTypeName(2);
             return $ong;
         default:
             // Can exist for template
             if (Session::haveRight("document", "r") || $item->getType() == 'Ticket' || $item->getType() == 'KnowbaseItem') {
                 if ($_SESSION['glpishow_count_on_tabs']) {
                     return Document::createTabEntry(Document::getTypeName(2), self::countForItem($item));
                 }
                 return Document::getTypeName(2);
             }
     }
     return '';
 }
示例#7
0
 function dropdownTaskItems($ID, $name, $used = array())
 {
     global $DB, $CFG_GLPI;
     $restrict = "`plugin_projet_projets_id` = '{$ID}'";
     $items = getAllDatasFromTable("glpi_plugin_projet_projets_items", $restrict);
     $restrictdoc = "`items_id` = '{$ID}' AND `itemtype` = 'PluginProjetProjet'";
     $docs = getAllDatasFromTable("glpi_documents_items", $restrictdoc);
     $restrictcontract = "`items_id` = '{$ID}' AND `itemtype` = 'PluginProjetProjet'";
     $contracts = getAllDatasFromTable("glpi_contracts_items", $restrictcontract);
     echo "<select name='{$name}'>";
     echo "<option value='0' selected>" . Dropdown::EMPTY_VALUE . "</option>";
     if (!empty($items)) {
         foreach ($items as $item) {
             $table = getTableForItemType($item["itemtype"]);
             $query = "SELECT `" . $table . "`.*\n                     FROM `glpi_plugin_projet_projets_items`\n                     INNER JOIN `" . $table . "` ON (`" . $table . "`.`id` = `glpi_plugin_projet_projets_items`.`items_id`)\n                     WHERE `glpi_plugin_projet_projets_items`.`itemtype` = '" . $item["itemtype"] . "'\n                     AND `glpi_plugin_projet_projets_items`.`items_id` = '" . $item["items_id"] . "' ";
             if (count($used)) {
                 $query .= " AND `" . $table . "`.`id` NOT IN (0";
                 foreach ($used as $ID) {
                     $query .= ",{$ID}";
                 }
                 $query .= ")";
             }
             $query .= " GROUP BY `" . $table . "`.`name`";
             $query .= " ORDER BY `" . $table . "`.`name`";
             $result_linked = $DB->query($query);
             if ($DB->numrows($result_linked)) {
                 while ($data = $DB->fetch_assoc($result_linked)) {
                     $name = $data["name"];
                     $itemclass = new $item["itemtype"]();
                     if ($item["itemtype"] == 'User') {
                         $name = getUserName($data["id"]);
                     }
                     echo "<option value='" . $data["id"] . "," . $item["itemtype"] . "'>" . $itemclass->getTypeName() . " - " . $name;
                     if (empty($data["name"]) || $_SESSION["glpiis_ids_visible"] == 1) {
                         echo " (";
                         echo $data["id"] . ")";
                     }
                     echo "</option>";
                 }
             }
         }
     }
     if (!empty($docs)) {
         foreach ($docs as $doc) {
             $docclass = new Document();
             if ($docclass->getFromDB($doc["documents_id"])) {
                 $name = $docclass->fields["name"];
                 echo "<option value='" . $doc["documents_id"] . ",Document'>" . $docclass->getTypeName() . " - " . $name;
                 if (empty($name) || $_SESSION["glpiis_ids_visible"] == 1) {
                     echo " (";
                     echo $doc["documents_id"] . ")";
                 }
                 echo "</option>";
             }
         }
     }
     if (!empty($contracts)) {
         foreach ($contracts as $contract) {
             $contractclass = new Contract();
             if ($contractclass->getFromDB($contract["contracts_id"])) {
                 $name = $contractclass->fields["name"];
                 echo "<option value='" . $contract["contracts_id"] . ",Contract'>" . $contractclass->getTypeName() . " - " . $name;
                 if (empty($name) || $_SESSION["glpiis_ids_visible"] == 1) {
                     echo " (";
                     echo $contract["contracts_id"] . ")";
                 }
                 echo "</option>";
             }
         }
     }
     echo "</select>";
 }