getOptionNumber() static public method

Get an option number in the SEARCH_OPTION array
static public getOptionNumber ( $itemtype, $field ) : integer
$itemtype
$field name
return integer
コード例 #1
0
 /**
  * Display tickets for an item
  *
  * Will also display tickets of linked items
  *
  * @param $itemtype
  * @param $items_id
  *
  * @return nothing (display a table)
  **/
 static function showListForItem($itemtype, $items_id)
 {
     global $DB, $CFG_GLPI, $LANG;
     if (!haveRight("show_all_ticket", "1")) {
         return false;
     }
     if (!class_exists($itemtype)) {
         return false;
     }
     $item = new $itemtype();
     if (!$item->getFromDB($items_id)) {
         return false;
     }
     $restrict = '';
     $order = '';
     $options['reset'] = 'reset';
     if ($itemtype == 'Sla') {
         $restrict = "(`slas_id` = '{$items_id}')";
         $order = '`glpi_tickets`.`due_date` DESC';
         $options['field'][0] = 30;
         $options['searchtype'][0] = 'equals';
         $options['contains'][0] = $items_id;
         $options['link'][0] = 'AND';
     } else {
         $restrict = "(`items_id` = '{$items_id}' AND `itemtype` = '{$itemtype}')";
         $order = '`glpi_tickets`.`date_mod` DESC';
         $options['field'][0] = 12;
         $options['searchtype'][0] = 'equals';
         $options['contains'][0] = 'all';
         $options['link'][0] = 'AND';
         $options['itemtype2'][0] = $itemtype;
         $options['field2'][0] = Search::getOptionNumber($itemtype, 'id');
         $options['searchtype2'][0] = 'equals';
         $options['contains2'][0] = $items_id;
         $options['link2'][0] = 'AND';
     }
     $query = "SELECT " . self::getCommonSelect() . "\n                FROM `glpi_tickets` " . self::getCommonLeftJoin() . "\n                WHERE {$restrict}" . getEntitiesRestrictRequest("AND", "glpi_tickets") . "\n                ORDER BY {$order}\n                LIMIT " . intval($_SESSION['glpilist_limit']);
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     // Ticket for the item
     echo "<div class='firstbloc'><table class='tab_cadre_fixe'>";
     if ($number > 0) {
         initNavigateListItems('Ticket', $item->getTypeName() . " = " . $item->getName());
         echo "<tr><th colspan='11'>";
         if ($number == 1) {
             echo $LANG['job'][10] . "&nbsp;:&nbsp;" . $number;
             echo "<span class='small_space'><a href='" . $CFG_GLPI["root_doc"] . "/front/ticket.php?" . append_params($options, '&amp;') . "'>" . $LANG['buttons'][40] . "</a></span>";
         } else {
             echo $LANG['job'][8] . "&nbsp;:&nbsp;" . $number;
             echo "<span class='small_space'><a href='" . $CFG_GLPI["root_doc"] . "/front/ticket.php?" . append_params($options, '&amp;') . "'>" . $LANG['buttons'][40] . "</a></span>";
         }
         echo "</th></tr>";
     } else {
         echo "<tr><th>" . $LANG['joblist'][8] . "</th></tr>";
     }
     // Link to open a new ticcket
     if ($items_id && in_array($itemtype, $_SESSION['glpiactiveprofile']['helpdesk_item_type'])) {
         echo "<tr><td class='tab_bg_2 center' colspan='11'>";
         echo "<a href=\"" . $CFG_GLPI["root_doc"] . "/front/ticket.form.php?items_id=" . "{$items_id}&amp;itemtype=" . "{$itemtype}\"><strong>" . $LANG['joblist'][7] . "</strong></a>";
         echo "</td></tr>";
     }
     // Ticket list
     if ($number > 0) {
         self::commonListHeader(HTML_OUTPUT);
         while ($data = $DB->fetch_assoc($result)) {
             addToNavigateListItems('Ticket', $data["id"]);
             self::showShort($data["id"], 0);
         }
     }
     echo "</table></div>";
     // Tickets for linked items
     if ($subquery = $item->getSelectLinkedItem()) {
         $query = "SELECT " . self::getCommonSelect() . "\n                   FROM `glpi_tickets` " . self::getCommonLeftJoin() . "\n                   WHERE (`itemtype`,`items_id`) IN (" . $subquery . ")" . getEntitiesRestrictRequest(' AND ', 'glpi_tickets') . "\n                   ORDER BY `glpi_tickets`.`date_mod` DESC\n                   LIMIT " . intval($_SESSION['glpilist_limit']);
         $result = $DB->query($query);
         $number = $DB->numrows($result);
         echo "<div class='spaced'><table class='tab_cadre_fixe'>";
         echo "<tr><th colspan='11'>";
         if ($number > 1) {
             echo $LANG['joblist'][28];
         } else {
             echo $LANG['joblist'][25];
         }
         echo "</th></tr>";
         if ($number > 0) {
             self::commonListHeader(HTML_OUTPUT);
             while ($data = $DB->fetch_assoc($result)) {
                 // addToNavigateListItems(TRACKING_TYPE,$data["id"]);
                 self::showShort($data["id"], 0);
             }
         } else {
             echo "<tr><th>" . $LANG['joblist'][8] . "</th></tr>";
         }
         echo "</table></div>";
     }
     // Subquery for linked item
 }
コード例 #2
0
ファイル: ticket.class.php プロジェクト: glpi-project/glpi
 /**
  * Display tickets for an item
  *
  * Will also display tickets of linked items
  *
  * @param $item CommonDBTM object
  *
  * @return nothing (display a table)
  **/
 static function showListForItem(CommonDBTM $item)
 {
     global $DB, $CFG_GLPI;
     if (!Session::haveRightsOr(self::$rightname, array(self::READALL, self::READMY, self::READASSIGN, CREATE))) {
         return false;
     }
     if ($item->isNewID($item->getID())) {
         return false;
     }
     $restrict = '';
     $order = '';
     $options['reset'] = 'reset';
     switch ($item->getType()) {
         case 'User':
             $restrict = "(`glpi_tickets_users`.`users_id` = '" . $item->getID() . "' " . " AND `glpi_tickets_users`.`type` = " . CommonITILActor::REQUESTER . ")";
             $order = '`glpi_tickets`.`date_mod` DESC';
             $options['reset'] = 'reset';
             $options['criteria'][0]['field'] = 4;
             // status
             $options['criteria'][0]['searchtype'] = 'equals';
             $options['criteria'][0]['value'] = $item->getID();
             $options['criteria'][0]['link'] = 'AND';
             break;
         case 'SLT':
             $restrict = "`slts_tto_id` = '" . $item->getID() . "'\n                           OR `slts_ttr_id` = '" . $item->getID() . "'";
             $order = '`glpi_tickets`.`due_date` DESC';
             $options['criteria'][0]['field'] = 30;
             $options['criteria'][0]['searchtype'] = 'equals';
             $options['criteria'][0]['value'] = $item->getID();
             $options['criteria'][0]['link'] = 'AND';
             break;
         case 'Supplier':
             $restrict = "(`glpi_suppliers_tickets`.`suppliers_id` = '" . $item->getID() . "' " . "  AND `glpi_suppliers_tickets`.`type` = " . CommonITILActor::ASSIGN . ")";
             $order = '`glpi_tickets`.`date_mod` DESC';
             $options['criteria'][0]['field'] = 6;
             $options['criteria'][0]['searchtype'] = 'equals';
             $options['criteria'][0]['value'] = $item->getID();
             $options['criteria'][0]['link'] = 'AND';
             break;
         case 'Group':
             // Mini search engine
             if ($item->haveChildren()) {
                 $tree = Session::getSavedOption(__CLASS__, 'tree', 0);
                 echo "<table class='tab_cadre_fixe'>";
                 echo "<tr class='tab_bg_1'><th>" . __('Last tickets') . "</th></tr>";
                 echo "<tr class='tab_bg_1'><td class='center'>";
                 echo __('Child groups') . "&nbsp;";
                 Dropdown::showYesNo('tree', $tree, -1, array('on_change' => 'reloadTab("start=0&tree="+this.value)'));
             } else {
                 $tree = 0;
             }
             echo "</td></tr></table>";
             if ($tree) {
                 $restrict = "IN (" . implode(',', getSonsOf('glpi_groups', $item->getID())) . ")";
             } else {
                 $restrict = "='" . $item->getID() . "'";
             }
             $restrict = "(`glpi_groups_tickets`.`groups_id` {$restrict}" . " AND `glpi_groups_tickets`.`type` = " . CommonITILActor::REQUESTER . ")";
             $order = '`glpi_tickets`.`date_mod` DESC';
             $options['criteria'][0]['field'] = 71;
             $options['criteria'][0]['searchtype'] = $tree ? 'under' : 'equals';
             $options['criteria'][0]['value'] = $item->getID();
             $options['criteria'][0]['link'] = 'AND';
             break;
         default:
             $restrict = "(`glpi_items_tickets`.`items_id` = '" . $item->getID() . "' " . " AND `glpi_items_tickets`.`itemtype` = '" . $item->getType() . "')";
             // you can only see your tickets
             if (!Session::haveRight(self::$rightname, self::READALL)) {
                 $restrict .= " AND (`glpi_tickets`.`users_id_recipient` = '" . Session::getLoginUserID() . "'\n                                   OR (`glpi_tickets_users`.`tickets_id` = '" . $item->getID() . "'\n                                       AND `glpi_tickets_users`.`users_id`\n                                            = '" . Session::getLoginUserID() . "'))";
             }
             $order = '`glpi_tickets`.`date_mod` DESC';
             $options['criteria'][0]['field'] = 12;
             $options['criteria'][0]['searchtype'] = 'equals';
             $options['criteria'][0]['value'] = 'all';
             $options['criteria'][0]['link'] = 'AND';
             $options['metacriteria'][0]['itemtype'] = $item->getType();
             $options['metacriteria'][0]['field'] = Search::getOptionNumber($item->getType(), 'id');
             $options['metacriteria'][0]['searchtype'] = 'equals';
             $options['metacriteria'][0]['value'] = $item->getID();
             $options['metacriteria'][0]['link'] = 'AND';
             break;
     }
     $query = "SELECT " . self::getCommonSelect() . "\n                FROM `glpi_tickets` " . self::getCommonLeftJoin() . "\n                WHERE {$restrict} " . getEntitiesRestrictRequest("AND", "glpi_tickets") . "\n                ORDER BY {$order}\n                LIMIT " . intval($_SESSION['glpilist_limit']);
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     $colspan = 11;
     if (count($_SESSION["glpiactiveentities"]) > 1) {
         $colspan++;
     }
     // Ticket for the item
     echo "<div class='firstbloc'>";
     // Link to open a new ticket
     if ($item->getID() && Ticket::isPossibleToAssignType($item->getType()) && self::canCreate()) {
         Html::showSimpleForm($CFG_GLPI["root_doc"] . "/front/ticket.form.php", '_add_fromitem', __('New ticket for this item...'), array('itemtype' => $item->getType(), 'items_id' => $item->getID()));
     }
     echo "</div><div>";
     if ($number > 0) {
         echo "<table class='tab_cadre_fixehov'>";
         if (Session::haveRight(self::$rightname, self::READALL)) {
             Session::initNavigateListItems('Ticket', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName()));
             echo "<tr class='noHover'><th colspan='{$colspan}'>";
             $title = sprintf(_n('Last %d ticket', 'Last %d tickets', $number), $number);
             $link = "<a href='" . $CFG_GLPI["root_doc"] . "/front/ticket.php?" . Toolbox::append_params($options, '&amp;') . "'>" . __('Show all') . "</a>";
             $title = printf(__('%1$s (%2$s)'), $title, $link);
             echo "</th></tr>";
         } else {
             echo "<tr><th colspan='{$colspan}'>" . __("You don't have right to see all tickets") . "</th></tr>";
         }
     } else {
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr><th>" . __('No ticket found.') . "</th></tr>";
     }
     if ($item->getID() && $item->getType() == 'User' && self::canCreate()) {
         echo "<tr><td class='tab_bg_2 center b' colspan='{$colspan}'>";
         Html::showSimpleForm($CFG_GLPI["root_doc"] . "/front/ticket.form.php", '_add_fromitem', __('New ticket for this item...'), array('_users_id_requester' => $item->getID()));
         echo "</td></tr>";
     }
     // Ticket list
     if ($number > 0) {
         self::commonListHeader(Search::HTML_OUTPUT);
         while ($data = $DB->fetch_assoc($result)) {
             Session::addToNavigateListItems('Ticket', $data["id"]);
             self::showShort($data["id"]);
         }
         self::commonListHeader(Search::HTML_OUTPUT);
     }
     echo "</table></div>";
     // Tickets for linked items
     $linkeditems = $item->getLinkedItems();
     $restrict = array();
     if (count($linkeditems)) {
         foreach ($linkeditems as $ltype => $tab) {
             foreach ($tab as $lID) {
                 $restrict[] = "(`glpi_items_tickets`.`itemtype` = '{$ltype}' AND `glpi_items_tickets`.`items_id` = '{$lID}')";
             }
         }
     }
     if (count($restrict) && Session::haveRight(self::$rightname, self::READALL)) {
         $query = "SELECT " . self::getCommonSelect() . "\n                   FROM `glpi_tickets` " . self::getCommonLeftJoin() . "\n                   WHERE " . implode(' OR ', $restrict) . getEntitiesRestrictRequest(' AND ', 'glpi_tickets') . "\n                   ORDER BY `glpi_tickets`.`date_mod` DESC\n                   LIMIT " . intval($_SESSION['glpilist_limit']);
         $result = $DB->query($query);
         $number = $DB->numrows($result);
         echo "<div class='spaced'><table class='tab_cadre_fixe'>";
         echo "<tr><th colspan='12'>";
         echo _n('Ticket on linked items', 'Tickets on linked items', $number);
         echo "</th></tr>";
         if ($number > 0) {
             self::commonListHeader(Search::HTML_OUTPUT);
             while ($data = $DB->fetch_assoc($result)) {
                 // Session::addToNavigateListItems(TRACKING_TYPE,$data["id"]);
                 self::showShort($data["id"]);
             }
             self::commonListHeader(Search::HTML_OUTPUT);
         } else {
             echo "<tr><th>" . __('No ticket found.') . "</th></tr>";
         }
         echo "</table></div>";
     }
     // Subquery for linked item
 }
コード例 #3
0
 function showFormItemtype($p_itemtype)
 {
     $can = 0;
     $typeright = strtolower($p_itemtype);
     if ($typeright == "networkequipment") {
         $typeright = "networking";
     }
     if (Session::haveRight($typeright, UPDATE)) {
         $can = 1;
     }
     $tableName = getTableForItemType($p_itemtype);
     echo "<div width='50%'>";
     $locked = PluginFusioninventoryLock::getLockFields($tableName, 0);
     if (!count($locked)) {
         $locked = array();
     }
     $colspan = '2';
     $item = new $p_itemtype();
     $item->getEmpty();
     echo "<form method='post' action='" . PluginFusioninventoryLock::getFormURL() . "'>";
     echo "<input type='hidden' name='id' value='0'>";
     echo "<input type='hidden' name='type' value='{$p_itemtype}'>";
     echo "<table class='tab_cadre'>";
     echo "<tr>";
     echo "<th colspan='2'>" . $item->getTypeName(1) . "</th>";
     echo "</tr>";
     echo "<tr><th>&nbsp;" . __('Fields') . "&nbsp;</th>";
     echo "<th>&nbsp;" . _n('Lock', 'Locks', 2, 'fusioninventory') . "&nbsp;</th>";
     echo "</tr>";
     $checked = false;
     $a_exclude = $this->excludeFields();
     $serialized = $this->getSerialized_InventoryArray($p_itemtype, 0);
     $options = search::getOptions($p_itemtype);
     foreach ($item->fields as $key => $val) {
         $name = "";
         $key_source = $key;
         if (!in_array($key, $a_exclude)) {
             if (in_array($key, $locked)) {
                 $checked = true;
             } else {
                 $checked = false;
             }
             // Get name of field
             $num = Search::getOptionNumber($p_itemtype, $key);
             if (isset($options[$num]['name'])) {
                 $name = $options[$num]['name'];
             } else {
                 //Get name by search in linkfields
                 foreach ($options as $opt) {
                     if (isset($opt['linkfield']) && $opt['linkfield'] == $key) {
                         $name = $opt['name'];
                         break;
                     }
                 }
             }
             $css_glpi_value = '';
             // Get value of field
             $val = $this->getValueForKey($val, $key);
             echo "<tr class='tab_bg_1'>";
             $table = getTableNameForForeignKeyField($key);
             if ($name == "" && $table != "") {
                 $linkItemtype = getItemTypeForTable($table);
                 $class = new $linkItemtype();
                 $name = $class->getTypeName();
             }
             echo "<td>" . $name . "</td>";
             echo "<td align='center'>";
             Html::showCheckbox(array('name' => "lockfield_fusioninventory[{$key_source}]", 'checked' => $checked));
             echo "</td>";
             echo "</tr>";
         }
     }
     if ($can == '1') {
         echo "<tr class='tab_bg_2'>";
         echo "<td align='center' colspan='" . ($colspan + 1) . "'>";
         echo "<input class='submit' type='submit' name='unlock_field_fusioninventory'\n                         value='" . __('Update') . "'>";
         echo "</td>";
         echo "</tr>";
     }
     echo "</table>";
     Html::closeForm();
     echo "</div>";
 }