Get the name of the object
public getName ( $options = [] ) : String: | ||
$options | array of options - comments : boolean / display comments - complete : boolean / display completename instead of name - additional : boolean / display aditionals information | |
Результат | String: |
/** * Show rack associated to an item * * @since version 0.84 * * @param $item CommonDBTM object for which associated rack must be displayed * @param $withtemplate (default '') **/ static function showForItem(CommonDBTM $item, $withtemplate = '') { global $DB, $CFG_GLPI; $ID = $item->getField('id'); if ($item->isNewID($ID) || !self::canView() || !$item->can($item->fields['id'], READ)) { return false; } if (empty($withtemplate)) { $withtemplate = 0; } $canedit = $item->canadditem('PluginRacksRack'); $rand = mt_rand(); $is_recursive = $item->isRecursive(); $itemtype = $item->getType() . "Model"; $query = "SELECT `glpi_plugin_racks_racks_items`.`id` AS assocID,\n `glpi_plugin_racks_racks_items`.`faces_id`,\n `glpi_plugin_racks_racks_items`.`position`,\n `glpi_entities`.`id` AS entity,\n `glpi_plugin_racks_racks`.`name` AS assocName,\n `glpi_plugin_racks_racks`.*\n FROM `glpi_plugin_racks_racks_items`\n LEFT JOIN `glpi_plugin_racks_racks`\n ON (`glpi_plugin_racks_racks_items`.`plugin_racks_racks_id`=`glpi_plugin_racks_racks`.`id`)\n LEFT JOIN `glpi_entities` ON (`glpi_plugin_racks_racks`.`entities_id`=`glpi_entities`.`id`)\n WHERE `glpi_plugin_racks_racks_items`.`items_id` = '{$ID}'\n AND `glpi_plugin_racks_racks_items`.`itemtype` = '" . $itemtype . "' "; $query .= getEntitiesRestrictRequest(" AND", "glpi_plugin_racks_racks", '', '', true); $query .= " ORDER BY `assocName`"; $result = $DB->query($query); $number = $DB->numrows($result); $i = 0; $racks = array(); $rack = new PluginRacksRack(); $used = array(); if ($numrows = $DB->numrows($result)) { while ($data = $DB->fetch_assoc($result)) { $racks[$data['assocID']] = $data; $used[$data['id']] = $data['id']; } } echo "<div class='spaced'>"; if ($canedit && $number && $withtemplate < 2) { Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array('num_displayed' => $number); Html::showMassiveActions($massiveactionparams); } echo "<table class='tab_cadre_fixe'>"; echo "<tr>"; if ($canedit && $number && $withtemplate < 2) { echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>"; } echo "<th>" . __('Name') . "</th>"; if (Session::isMultiEntitiesMode()) { echo "<th>" . __('Entity') . "</th>"; } echo "<th>" . __('Disposition', 'racks') . "</th>"; echo "<th>" . __('Position', 'racks') . "</th>"; echo "<th>" . __('Location') . "</th>"; echo "<th>" . __('Place', 'racks') . "</th>"; echo "<th>" . __('Manufacturer') . "</th>"; echo "</tr>"; $used = array(); if ($number) { Session::initNavigateListItems('PluginRacksRack', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName())); foreach ($racks as $data) { $rackID = $data["id"]; $link = NOT_AVAILABLE; if ($rack->getFromDB($rackID)) { $link = $rack->getLink(); } Session::addToNavigateListItems('PluginRacksRack', $rackID); $used[$rackID] = $rackID; $assocID = $data["assocID"]; echo "<tr class='tab_bg_1" . ($data["is_deleted"] ? "_2" : "") . "'>"; if ($canedit && $withtemplate < 2) { echo "<td width='10'>"; Html::showMassiveActionCheckBox(__CLASS__, $data["assocID"]); echo "</td>"; } echo "<td class='center'>{$link}</td>"; if (Session::isMultiEntitiesMode()) { echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entities_id']) . "</td>"; } if ($data["faces_id"] == PluginRacksRack::FRONT_FACE) { $faces_id = __('Front', 'racks'); } else { $faces_id = _x('Rack enclosure', 'Back', 'racks'); } echo "<td class='center'>" . $faces_id . "</td>"; echo "<td class='center'>" . $data["position"] . "</td>"; echo "<td>" . Dropdown::getDropdownName("glpi_locations", $data["locations_id"]) . "</td>"; echo "<td class='center'>" . Dropdown::getDropdownName("glpi_plugin_racks_roomlocations", $data["plugin_racks_roomlocations_id"], 0) . "</td>"; echo "<td>" . Dropdown::getDropdownName("glpi_manufacturers", $data["manufacturers_id"]) . "</td>"; echo "</tr>"; $i++; } } echo "</table>"; if ($canedit && $number && $withtemplate < 2) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } echo "</div>"; }
/** * Execute massive action for PluginFormcreatorFrom * * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { global $DB; switch ($ma->getAction()) { case 'Duplicate': foreach ($ids as $id) { if ($item->getFromDB($id) && $item->Duplicate()) { Session::addMessageAfterRedirect(sprintf(__('Form duplicated: %s', 'formcreator'), $item->getName())); $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { // Example of ko count $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); } } return; } parent::processMassiveActionsForOneItemtype($ma, $item, $ids); }
/** * Display changes for an item * * Will also display changes of linked items * * @param $item CommonDBTM object * * @return nothing (display a table) **/ static function showListForItem(CommonDBTM $item) { global $DB, $CFG_GLPI; if (!Session::haveRight(self::$rightname, self::READALL)) { return false; } if ($item->isNewID($item->getID())) { return false; } $restrict = ''; $order = ''; $options['reset'] = 'reset'; switch ($item->getType()) { case 'User': $restrict = "(`glpi_changes_users`.`users_id` = '" . $item->getID() . "')"; $order = '`glpi_changes`.`date_mod` DESC'; $options['criteria'][0]['field'] = 4; // status $options['criteria'][0]['searchtype'] = 'equals'; $options['criteria'][0]['value'] = $item->getID(); $options['criteria'][0]['link'] = 'OR'; $options['criteria'][1]['field'] = 66; // status $options['criteria'][1]['searchtype'] = 'equals'; $options['criteria'][1]['value'] = $item->getID(); $options['criteria'][1]['link'] = 'OR'; $options['criteria'][5]['field'] = 5; // status $options['criteria'][5]['searchtype'] = 'equals'; $options['criteria'][5]['value'] = $item->getID(); $options['criteria'][5]['link'] = 'OR'; break; case 'Supplier': $restrict = "(`glpi_changes_suppliers`.`suppliers_id` = '" . $item->getID() . "')"; $order = '`glpi_changes`.`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 changes') . "</th></tr>"; echo "<tr class='tab_bg_1'><td class='center'>"; _e('Child groups'); 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_changes_groups`.`groups_id` {$restrict}\n AND `glpi_changes_groups`.`type` = " . CommonITILActor::REQUESTER . ")"; $order = '`glpi_changes`.`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 = "(`items_id` = '" . $item->getID() . "'\n AND `itemtype` = '" . $item->getType() . "')"; $order = '`glpi_changes`.`date_mod` DESC'; break; } $query = "SELECT " . self::getCommonSelect() . "\n FROM `glpi_changes`\n LEFT JOIN `glpi_changes_items`\n ON (`glpi_changes`.`id` = `glpi_changes_items`.`changes_id`) " . self::getCommonLeftJoin() . "\n WHERE {$restrict} " . getEntitiesRestrictRequest("AND", "glpi_changes") . "\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'>"; $colspan = 11; if (count($_SESSION["glpiactiveentities"]) > 1) { $colspan++; } if ($number > 0) { Session::initNavigateListItems('Change', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName())); echo "<tr><th colspan='{$colspan}'>"; //TRANS : %d is the number of problems echo sprintf(_n('Last %d change', 'Last %d changes', $number), $number); // echo "<span class='small_space'><a href='".$CFG_GLPI["root_doc"]."/front/ticket.php?". // Toolbox::append_params($options,'&')."'>".__('Show all')."</a></span>"; echo "</th></tr>"; } else { echo "<tr><th>" . __('No change found.') . "</th></tr>"; } // Ticket list if ($number > 0) { self::commonListHeader(Search::HTML_OUTPUT); while ($data = $DB->fetch_assoc($result)) { Session::addToNavigateListItems('Problem', $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[] = "(`itemtype` = '{$ltype}' AND `items_id` = '{$lID}')"; } } } if (count($restrict)) { $query = "SELECT " . self::getCommonSelect() . "\n FROM `glpi_changes`\n LEFT JOIN `glpi_changes_items`\n ON (`glpi_changes`.`id` = `glpi_changes_items`.`changes_id`) " . self::getCommonLeftJoin() . "\n WHERE " . implode(' OR ', $restrict) . getEntitiesRestrictRequest(' AND ', 'glpi_changes') . "\n ORDER BY `glpi_changes`.`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='{$colspan}'>"; _e('Changes on linked items'); 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 change found.') . "</th></tr>"; } echo "</table></div>"; } // Subquery for linked item }
/** * Generate link * * @param $link string : original string content * @param $item CommonDBTM : item used to make replacements * @param $name string : name used for multi link generation * @param $noip boolean : true to not evaluate IP/MAC * * @return array of link contents (may have several when item have several IP / MAC cases) */ static function generateLinkContents($link, CommonDBTM $item, $name = '', $noip = false) { global $DB; if (strstr($link, "[ID]")) { $link = str_replace("[ID]", $item->fields['id'], $link); } if (strstr($link, "[LOGIN]") && isset($_SESSION["glpiname"])) { if (isset($_SESSION["glpiname"])) { $link = str_replace("[LOGIN]", $_SESSION["glpiname"], $link); } } if (strstr($link, "[NAME]")) { $link = str_replace("[NAME]", $item->getName(), $link); } if (strstr($link, "[SERIAL]")) { if ($item->isField('serial')) { $link = str_replace("[SERIAL]", $item->getField('serial'), $link); } } if (strstr($link, "[OTHERSERIAL]")) { if ($item->isField('otherserial')) { $link = str_replace("[OTHERSERIAL]", $item->getField('otherserial'), $link); } } if (strstr($link, "[LOCATIONID]")) { if ($item->isField('locations_id')) { $link = str_replace("[LOCATIONID]", $item->getField('locations_id'), $link); } } if (strstr($link, "[LOCATION]")) { if ($item->isField('locations_id')) { $link = str_replace("[LOCATION]", Dropdown::getDropdownName("glpi_locations", $item->getField('locations_id')), $link); } } if (strstr($link, "[NETWORK]")) { if ($item->isField('networks_id')) { $link = str_replace("[NETWORK]", Dropdown::getDropdownName("glpi_networks", $item->getField('networks_id')), $link); } } if (strstr($link, "[DOMAIN]")) { if ($item->isField('domains_id')) { $link = str_replace("[DOMAIN]", Dropdown::getDropdownName("glpi_domains", $item->getField('domains_id')), $link); } } if (strstr($link, "[USER]")) { if ($item->isField('users_id')) { $link = str_replace("[USER]", Dropdown::getDropdownName("glpi_users", $item->getField('users_id')), $link); } } if (strstr($link, "[GROUP]")) { if ($item->isField('groups_id')) { $link = str_replace("[GROUP]", Dropdown::getDropdownName("glpi_groups", $item->getField('groups_id')), $link); } } $ipmac = array(); $i = 0; if ($noip || !strstr($link, "[IP]") && !strstr($link, "[MAC]")) { return array($link); } else { // Return sevral links id several IP / MAC $links = array(); $query2 = "SELECT `ip`, `mac`, `logical_number`\n FROM `glpi_networkports`\n WHERE `items_id` = '" . $item->fields['id'] . "'\n AND `itemtype` = '" . get_class($item) . "'\n ORDER BY `logical_number`"; $result2 = $DB->query($query2); if ($DB->numrows($result2) > 0) { while ($data2 = $DB->fetch_array($result2)) { $ipmac[$i]['ip'] = $data2["ip"]; $ipmac[$i]['mac'] = $data2["mac"]; $ipmac[$i]['number'] = $data2["logical_number"]; $i++; } } // Add IP/MAC internal switch if (get_class($item) == 'NetworkEquipment') { $tmplink = $link; $tmplink = str_replace("[IP]", $item->getField('ip'), $tmplink); $tmplink = str_replace("[MAC]", $item->getField('mac'), $tmplink); $links["{$name} - {$tmplink}"] = $tmplink; } if (count($ipmac) > 0) { foreach ($ipmac as $key => $val) { $tmplink = $link; $disp = 1; if (strstr($link, "[IP]")) { if (empty($val['ip'])) { $disp = 0; } else { $tmplink = str_replace("[IP]", $val['ip'], $tmplink); } } if (strstr($link, "[MAC]")) { if (empty($val['mac'])) { $disp = 0; } else { $tmplink = str_replace("[MAC]", $val['mac'], $tmplink); } } if ($disp) { $links["{$name} #" . $val['number'] . " - {$tmplink}"] = $tmplink; } } } if (count($links)) { return $links; } return array($link); } }
/** * Show Infocom form for an item (not a standard showForm) * * @param $item CommonDBTM object * @param $withtemplate integer template or basic item (default '') **/ static function showForItem(CommonDBTM $item, $withtemplate = '') { global $CFG_GLPI; // Show Infocom or blank form if (!Session::haveRight("infocom", "r")) { return false; } if (!$item) { echo "<div class='spaced'>" . __('Requested item not found') . "</div>"; } else { $date_tax = $CFG_GLPI["date_tax"]; $dev_ID = $item->getField('id'); $ic = new self(); $option = ""; if ($withtemplate == 2) { $option = " readonly "; } if (!strpos($_SERVER['PHP_SELF'], "infocoms-show") && in_array($item->getType(), array('CartridgeItem', 'ConsumableItem', 'Software'))) { echo "<div class='firstbloc center'>" . __('For this type of item, the financial and administrative information are only a model for the items which you should add.') . "</div>"; } if (!$ic->getFromDBforDevice($item->getType(), $dev_ID)) { $input = array('itemtype' => $item->getType(), 'items_id' => $dev_ID, 'entities_id' => $item->getEntityID()); if ($ic->can(-1, "w", $input) && $withtemplate != 2) { echo "<div class='spaced b'>"; echo "<table class='tab_cadre_fixe'><tr class='tab_bg_1'><th>"; echo sprintf(__('%1$s - %2$s'), $item->getTypeName(1), $item->getName()) . "</th></tr>"; echo "<tr class='tab_bg_1'><td class='center'>"; Html::showSimpleForm($CFG_GLPI["root_doc"] . "/front/infocom.form.php", 'add', __('Enable the financial and administrative information'), array('itemtype' => $item->getType(), 'items_id' => $dev_ID)); echo "</td></tr></table></div>"; } } else { // getFromDBforDevice $canedit = $ic->can($ic->fields['id'], "w") && $withtemplate != 2; if ($canedit) { echo "<form name='form_ic' method='post' action='" . $CFG_GLPI["root_doc"] . "/front/infocom.form.php'>"; } echo "<div class='spaced'>"; echo "<table class='tab_cadre" . (!strpos($_SERVER['PHP_SELF'], "infocoms-show") ? "_fixe" : "") . "'>"; echo "<tr><th colspan='4'>" . __('Financial and administrative information') . "</th></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Supplier') . "</td>"; echo "<td>"; if ($withtemplate == 2) { echo Dropdown::getDropdownName("glpi_suppliers", $ic->fields["suppliers_id"]); } else { Supplier::dropdown(array('value' => $ic->fields["suppliers_id"], 'entity' => $item->getEntityID())); } echo "</td>"; if (Session::haveRight("budget", "r")) { echo "<td>" . __('Budget') . "</td><td >"; Budget::dropdown(array('value' => $ic->fields["budgets_id"], 'entity' => $item->getEntityID(), 'comments' => 1)); } else { echo "<td colspan='2'>"; } echo "</td></tr>"; // Can edit calendar ? $editcalendar = $withtemplate != 2; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Order number') . "</td>"; echo "<td >"; Html::autocompletionTextField($ic, "order_number", array('option' => $option)); echo "</td>"; echo "<td>" . __('Order date') . "</td><td>"; Html::showDateFormItem("order_date", $ic->fields["order_date"], true, $editcalendar); echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; $istemplate = ''; if ($item->isTemplate() || in_array($item->getType(), array('CartridgeItem', 'ConsumableItem', 'Software'))) { $istemplate = '*'; } echo "<td>" . sprintf(__('%1$s%2$s'), __('Immobilization number'), $istemplate) . "</td>"; echo "<td>"; $objectName = autoName($ic->fields["immo_number"], "immo_number", $withtemplate == 2, 'Infocom', $item->getEntityID()); Html::autocompletionTextField($ic, "immo_number", array('value' => $objectName, 'option' => $option)); echo "</td>"; echo "<td>" . __('Date of purchase') . "</td><td>"; Html::showDateFormItem("buy_date", $ic->fields["buy_date"], true, $editcalendar); echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Invoice number') . "</td>"; echo "<td>"; Html::autocompletionTextField($ic, "bill", array('option' => $option)); echo "</td>"; echo "<td>" . __('Delivery date') . "</td><td>"; Html::showDateFormItem("delivery_date", $ic->fields["delivery_date"], true, $editcalendar); echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Delivery form') . "</td><td>"; Html::autocompletionTextField($ic, "delivery_number", array('option' => $option)); echo "</td>"; echo "<td>" . __('Startup date') . "</td><td>"; Html::showDateFormItem("use_date", $ic->fields["use_date"], true, $editcalendar); echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Value') . "</td>"; echo "<td><input type='text' name='value' {$option} value='" . Html::formatNumber($ic->fields["value"], true) . "' size='14'></td>"; echo "</td>"; echo "<td>" . __('Date of last physical inventory') . "</td><td>"; Html::showDateFormItem("inventory_date", $ic->fields["inventory_date"], true, $editcalendar); echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Warranty extension value') . "</td>"; echo "<td><input type='text' {$option} name='warranty_value' value='" . Html::formatNumber($ic->fields["warranty_value"], true) . "' size='14'></td>"; echo "<td rowspan='5'>" . __('Comments') . "</td>"; echo "<td rowspan='5' class='middle'>"; echo "<textarea cols='45' rows='9' name='comment' >" . $ic->fields["comment"]; echo "</textarea></td></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Account net value') . "</td><td>"; echo Html::formatNumber(self::Amort($ic->fields["sink_type"], $ic->fields["value"], $ic->fields["sink_time"], $ic->fields["sink_coeff"], $ic->fields["warranty_date"], $ic->fields["use_date"], $date_tax, "n")); echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Amortization type') . "</td><td >"; if ($withtemplate == 2) { echo self::getAmortTypeName($ic->fields["sink_type"]); } else { self::dropdownAmortType("sink_type", $ic->fields["sink_type"]); } echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Amortization duration') . "</td><td>"; if ($withtemplate == 2) { printf(_n('%d year', '%d years', $ic->fields["sink_time"]), $ic->fields["sink_time"]); } else { Dropdown::showNumber("sink_time", array('value' => $ic->fields["sink_time"], 'max' => 15, 'unit' => 'year')); } echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Amortization coefficient') . "</td>"; echo "<td>"; Html::autocompletionTextField($ic, "sink_coeff", array('size' => 14, 'option' => $option)); echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; if (!in_array($item->getType(), array('Cartridge', 'CartridgeItem', 'Consumable', 'ConsumableItem', 'Software', 'SoftwareLicense'))) { echo "<td>" . __('TCO (value + tracking cost)') . "</td><td>"; echo self::showTco($item->getField('ticket_tco'), $ic->fields["value"]); } else { echo "<td colspan='2'>"; } echo "</td>"; if (!in_array($item->getType(), array('Cartridge', 'CartridgeItem', 'Consumable', 'ConsumableItem', 'Software', 'SoftwareLicense'))) { echo "<td>" . __('Monthly TCO') . "</td><td>"; echo self::showTco($item->getField('ticket_tco'), $ic->fields["value"], $ic->fields["warranty_date"]); } else { echo "<td colspan='2'>"; } echo "</td></tr>"; echo "<tr><th colspan='4'>" . __('Warranty information') . "</th></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Start date of warranty') . "</td><td>"; Html::showDateFormItem("warranty_date", $ic->fields["warranty_date"], true, $editcalendar); echo "</td>"; echo "<td>" . __('Warranty duration') . "</td><td>"; if ($withtemplate == 2) { // -1 = life if ($ic->fields["warranty_duration"] == -1) { _e('Lifelong'); } else { printf(_n('%d month', '%d months', $ic->fields["warranty_duration"]), $ic->fields["warranty_duration"]); } } else { Dropdown::showInteger("warranty_duration", $ic->fields["warranty_duration"], 0, 120, 1, array(-1 => __('Lifelong')), array('unit' => 'month')); } $tmpdat = self::getWarrantyExpir($ic->fields["warranty_date"], $ic->fields["warranty_duration"], 0, true); if ($tmpdat) { echo "<span class='small_space'>" . sprintf(__('Valid to %s'), $tmpdat) . "</span>"; } echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Warranty information') . "</td>"; echo "<td >"; Html::autocompletionTextField($ic, "warranty_info", array('option' => $option)); echo "</td>"; if ($CFG_GLPI['use_mailing']) { echo "<td>" . __('Alarms on financial and administrative information') . "</td>"; echo "<td>"; self::dropdownAlert(array('name' => "alert", 'value' => $ic->fields["alert"])); Alert::displayLastAlert('Infocom', $ic->fields['id']); echo "</td>"; } else { echo "</td><td colspan='2'>"; } echo "</td></tr>"; if ($canedit) { echo "<tr>"; echo "<td class='tab_bg_2 center' colspan='2'>"; echo "<input type='hidden' name='id' value='" . $ic->fields['id'] . "'>"; echo "<input type='submit' name='update' value=\"" . _sx('button', 'Save') . "\"\n class='submit'>"; echo "</td>"; echo "<td class='tab_bg_2 center' colspan='2'>"; echo "<input type='submit' name='delete' value=\"" . _sx('button', 'Delete permanently') . "\"\n class='submit'>"; echo "</td></tr>"; echo "</table></div>"; Html::closeForm(); } else { echo "</table></div>"; } } } }
/** * 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); } } }
/** * Show routetables associated to an item * * @since version 0.84 * * @param $item CommonDBTM object for which associated routetables must be displayed * @param $withtemplate (default '') * */ static function showForItem(CommonDBTM $item, $withtemplate = '') { global $DB, $CFG_GLPI; $ID = $item->getField('id'); if ($item->isNewID($ID)) { return false; } if (!plugin_routetables_haveRight('routetables', 'r')) { return false; } if (!$item->can($item->fields['id'], 'r')) { return false; } if (empty($withtemplate)) { $withtemplate = 0; } $canedit = $item->canadditem('PluginRoutetablesRoutetable'); $rand = mt_rand(); $is_recursive = $item->isRecursive(); $query = "SELECT `glpi_plugin_routetables_routetables_items`.`id` AS assocID,\n `glpi_entities`.`id` AS entity,\n `glpi_plugin_routetables_routetables`.`name` AS assocName,\n `glpi_plugin_routetables_routetables`.*\n FROM `glpi_plugin_routetables_routetables_items`\n LEFT JOIN `glpi_plugin_routetables_routetables`\n ON (`glpi_plugin_routetables_routetables_items`.`plugin_routetables_routetables_id`=`glpi_plugin_routetables_routetables`.`id`)\n LEFT JOIN `glpi_entities` ON (`glpi_plugin_routetables_routetables`.`entities_id`=`glpi_entities`.`id`)\n WHERE `glpi_plugin_routetables_routetables_items`.`items_id` = '{$ID}'\n AND `glpi_plugin_routetables_routetables_items`.`itemtype` = '" . $item->getType() . "' "; $query .= getEntitiesRestrictRequest(" AND", "glpi_plugin_routetables_routetables", '', '', false); $query .= " ORDER BY `assocName`"; $result = $DB->query($query); $number = $DB->numrows($result); $i = 0; $routetables = array(); $routetable = new PluginRoutetablesRoutetable(); $used = array(); if ($numrows = $DB->numrows($result)) { while ($data = $DB->fetch_assoc($result)) { $routetables[$data['id']] = $data; $used[$data['id']] = $data['id']; } } if ($canedit && $withtemplate < 2) { // Restrict entity for knowbase $entities = ""; $entity = $_SESSION["glpiactive_entity"]; if ($item->isEntityAssign()) { /// Case of personal items : entity = -1 : create on active entity (Reminder case)) if ($item->getEntityID() >= 0) { $entity = $item->getEntityID(); } if ($item->isRecursive()) { $entities = getSonsOf('glpi_entities', $entity); } else { $entities = $entity; } } $limit = getEntitiesRestrictRequest(" AND ", "glpi_plugin_routetables_routetables", '', $entities, false); $q = "SELECT COUNT(*)\n FROM `glpi_plugin_routetables_routetables`\n WHERE `is_deleted` = '0'\n {$limit}"; $result = $DB->query($q); $nb = $DB->result($result, 0, 0); echo "<div class='firstbloc'>"; if (plugin_routetables_haveRight('routetables', 'r') && $nb > count($used)) { echo "<form name='routetable_form{$rand}' id='routetable_form{$rand}' method='post'\n action='" . Toolbox::getItemTypeFormURL('PluginRoutetablesRoutetable') . "'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'>"; echo "<td colspan='4' class='center'>"; echo "<input type='hidden' name='entities_id' value='{$entity}'>"; echo "<input type='hidden' name='is_recursive' value='{$is_recursive}'>"; echo "<input type='hidden' name='itemtype' value='" . $item->getType() . "'>"; echo "<input type='hidden' name='items_id' value='{$ID}'>"; if ($item->getType() == 'Ticket') { echo "<input type='hidden' name='tickets_id' value='{$ID}'>"; } $routetable->dropdownRouteTables("plugin_routetables_routetables_id", $entities, $used); echo "</td><td class='center' width='20%'>"; echo "<input type='submit' name='additem' value=\"" . _sx('button', 'Associate a routing table', 'routetables') . "\" class='submit'>"; echo "</td>"; echo "</tr>"; echo "</table>"; Html::closeForm(); } echo "</div>"; } echo "<div class='spaced'>"; if ($canedit && $number && $withtemplate < 2) { Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array('num_displayed' => $number); Html::showMassiveActions(__CLASS__, $massiveactionparams); } echo "<table class='tab_cadre_fixe'>"; echo "<tr>"; if ($canedit && $number && $withtemplate < 2) { echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>"; } echo "<th>" . __('Name') . "</th>"; if (Session::isMultiEntitiesMode()) { echo "<th>" . __('Entity') . "</th>"; } echo "<th>" . __('Network') . "</th>"; echo "<th>" . __('Subnet mask') . "</th>"; echo "<th>" . __('Gateway') . "</th>"; echo "<th>" . __('Metric', 'routetables') . "</th>"; echo "<th>" . __('Interface') . "</th>"; echo "<th>" . __('Persistance', 'routetables') . "</th>"; echo "<th>" . __('Comments') . "</th>"; echo "</tr>"; $used = array(); if ($number) { Session::initNavigateListItems('PluginRoutetablesRoutetable', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName())); foreach ($routetables as $data) { $routetableID = $data["id"]; $link = NOT_AVAILABLE; if ($routetable->getFromDB($routetableID)) { $link = $routetable->getLink(); } Session::addToNavigateListItems('PluginRoutetablesRoutetable', $routetable); $used[$routetableID] = $routetableID; $assocID = $data["assocID"]; echo "<tr class='tab_bg_1" . ($data["is_deleted"] ? "_2" : "") . "'>"; if ($canedit && $withtemplate < 2) { echo "<td width='10'>"; Html::showMassiveActionCheckBox(__CLASS__, $data["assocID"]); echo "</td>"; } echo "<td class='center'>{$link}</td>"; if (Session::isMultiEntitiesMode()) { echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entities_id']) . "</td>"; } echo "<td class='center'>" . $data["destination"] . "</td>"; echo "<td class='center'>" . $data["netmask"] . "</td>"; echo "<td class='center'>" . $data["gateway"] . "</td>"; echo "<td class='center'>" . $data["metric"] . "</td>"; echo "<td class='center'>" . $data["interface"] . "</td>"; echo "<td class='center'>" . Dropdown::getYesNo($data["persistence"]) . "</td>"; echo "<td class='center'>" . $data["comment"] . "</td>"; echo "</tr>"; $i++; } } echo "</table>"; if ($canedit && $number && $withtemplate < 2) { $massiveactionparams['ontop'] = false; Html::showMassiveActions(__CLASS__, $massiveactionparams); Html::closeForm(); } echo "</div>"; }
/** * Show resource associated to an item * * @since version 0.84 * * @param $item CommonDBTM object for which associated resource must be displayed * @param $withtemplate (default '') **/ static function showForItem(CommonDBTM $item, $withtemplate = '') { global $DB, $CFG_GLPI; $ID = $item->getField('id'); if ($item->isNewID($ID)) { return false; } if (!plugin_resources_haveRight('resources', 'r')) { return false; } if (!$item->can($item->fields['id'], 'r')) { return false; } if (empty($withtemplate)) { $withtemplate = 0; } $canedit = $item->canadditem('PluginResourcesResource'); $rand = mt_rand(); $is_recursive = $item->isRecursive(); $query = "SELECT `glpi_plugin_resources_resources_items`.`id` AS assocID,\n `glpi_entities`.`id` AS entity,\n `glpi_plugin_resources_resources`.`name` AS assocName,\n `glpi_plugin_resources_resources`.*\n FROM `glpi_plugin_resources_resources_items`\n LEFT JOIN `glpi_plugin_resources_resources`\n ON (`glpi_plugin_resources_resources_items`.`plugin_resources_resources_id`=`glpi_plugin_resources_resources`.`id`)\n LEFT JOIN `glpi_entities` ON (`glpi_plugin_resources_resources`.`entities_id`=`glpi_entities`.`id`)\n WHERE `glpi_plugin_resources_resources_items`.`items_id` = '{$ID}'\n AND `glpi_plugin_resources_resources_items`.`itemtype` = '" . $item->getType() . "' "; $query .= getEntitiesRestrictRequest(" AND", "glpi_plugin_resources_resources", '', '', true); $query .= " ORDER BY `assocName`"; $result = $DB->query($query); $number = $DB->numrows($result); $i = 0; $resources = array(); $used = array(); if ($numrows = $DB->numrows($result)) { while ($data = $DB->fetch_assoc($result)) { $resources[$data['assocID']] = $data; $used[$data['id']] = $data['id']; } } $resource = new PluginResourcesResource(); $more = true; if ($item->getType() == "User" && $number != 0) { $more = false; } if ($canedit && $withtemplate < 2 && $more) { // Restrict entity for knowbase $entities = ""; $entity = $_SESSION["glpiactive_entity"]; if ($item->isEntityAssign()) { /// Case of personal items : entity = -1 : create on active entity (Reminder case)) if ($item->getEntityID() >= 0) { $entity = $item->getEntityID(); } if ($item->isRecursive()) { $entities = getSonsOf('glpi_entities', $entity); } else { $entities = $entity; } } $limit = getEntitiesRestrictRequest(" AND ", "glpi_plugin_resources_resources", '', $entities, true); $q = "SELECT COUNT(*)\n FROM `glpi_plugin_resources_resources`\n WHERE `is_deleted` = '0'\n AND `is_template` = '0' "; if ($item->getType() != 'User') { $q .= " {$limit}"; } $result = $DB->query($q); $nb = $DB->result($result, 0, 0); echo "<div class='firstbloc'>"; if (plugin_resources_haveRight('resources', 'r') && $nb > count($used)) { echo "<form name='resource_form{$rand}' id='resource_form{$rand}' method='post'\n action='" . Toolbox::getItemTypeFormURL('PluginResourcesResource') . "'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'>"; echo "<td colspan='4' class='center'>"; echo "<input type='hidden' name='itemtype' value='" . $item->getType() . "'>"; echo "<input type='hidden' name='items_id' value='{$ID}'>"; if ($item->getType() == 'Ticket') { echo "<input type='hidden' name='tickets_id' value='{$ID}'>"; } PluginResourcesResource::dropdown(array('entity' => $entities, 'used' => $used)); echo "</td><td class='center' width='20%'>"; echo "<input type='submit' name='additem' value=\"" . __s('Associate a resource', 'resources') . "\" class='submit'>"; echo "</td>"; echo "</tr>"; echo "</table>"; Html::closeForm(); } echo "</div>"; } echo "<div class='spaced'>"; if ($canedit && $number && $withtemplate < 2) { Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array('num_displayed' => $number); Html::showMassiveActions(__CLASS__, $massiveactionparams); } echo "<table class='tab_cadre_fixe'>"; if (Session::isMultiEntitiesMode()) { $colsup = 1; } else { $colsup = 0; } echo "<tr>"; if ($canedit && $number && $withtemplate < 2) { echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>"; } echo "<th>" . __('Name') . "</th>"; echo "<th>" . __('First name') . "</th>"; if (Session::isMultiEntitiesMode()) { echo "<th>" . __('Entity') . "</th>"; } echo "<th>" . __('Location') . "</th>"; echo "<th>" . PluginResourcesContractType::getTypeName(1) . "</th>"; echo "<th>" . PluginResourcesDepartment::getTypeName(1) . "</th>"; echo "<th>" . __('Arrival date', 'resources') . "</th>"; echo "<th>" . __('Departure date', 'resources') . "</th>"; echo "</tr>"; $used = array(); $resourceID = 0; if ($number) { Session::initNavigateListItems('PluginResourcesResource', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName())); foreach ($resources as $data) { $resourceID = $data["id"]; $link = NOT_AVAILABLE; if ($resource->getFromDB($resourceID)) { $link = $resource->getLink(); } Session::addToNavigateListItems('PluginResourcesResource', $resourceID); $used[$resourceID] = $resourceID; $assocID = $data["assocID"]; echo "<tr class='tab_bg_1" . ($data["is_deleted"] ? "_2" : "") . "'>"; if ($canedit && $withtemplate < 2) { echo "<td width='10'>"; Html::showMassiveActionCheckBox(__CLASS__, $data["assocID"]); echo "</td>"; } echo "<td class='center'>{$link}</td>"; echo "<td class='center'>" . $data['firstname'] . "</td>"; if (Session::isMultiEntitiesMode()) { echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entities_id']) . "</td>"; } echo "<td class='center'>"; echo Dropdown::getDropdownName("glpi_locations", $data["locations_id"]); echo "</td>"; echo "<td class='center'>"; echo Dropdown::getDropdownName("glpi_plugin_resources_contracttypes", $data["plugin_resources_contracttypes_id"]); echo "</td>"; echo "<td class='center'>"; echo Dropdown::getDropdownName("glpi_plugin_resources_departments", $data["plugin_resources_departments_id"]); echo "</td>"; echo "<td class='center'>" . Html::convDate($data["date_begin"]) . "</td>"; if ($data["date_end"] <= date('Y-m-d') && !empty($data["date_end"])) { echo "<td class='center'>"; echo "<span class='plugin_resources_date_color'>"; echo Html::convDate($data["date_end"]); echo "</span>"; echo "</td>"; } else { if (empty($data["date_end"])) { echo "<td class='center'>" . __('Not defined', 'resources') . "</td>"; } else { echo "<td class='center'>" . Html::convDate($data["date_end"]) . "</td>"; } } echo "</tr>"; $i++; } } echo "</table>"; if ($canedit && $number && $withtemplate < 2) { $massiveactionparams['ontop'] = false; Html::showMassiveActions(__CLASS__, $massiveactionparams); Html::closeForm(); } echo "</div>"; if ($item->getType() == "User") { $PluginResourcesEmployee = new PluginResourcesEmployee(); $PluginResourcesEmployee->showForm($resourceID, $ID, 0); } }
/** * Show domains associated to a supplier * * @since version 0.84 * * @param $item CommonDBTM object for which associated domains must be displayed * @param $withtemplate (default '') **/ static function showForSupplier(CommonDBTM $item, $withtemplate = '') { global $DB, $CFG_GLPI; $ID = $item->getField('id'); if ($item->isNewID($ID)) { return false; } if (!plugin_domains_haveRight('domains', 'r')) { return false; } if (!$item->can($item->fields['id'], 'r')) { return false; } if (empty($withtemplate)) { $withtemplate = 0; } $rand = mt_rand(); $is_recursive = $item->isRecursive(); $query = "SELECT `glpi_plugin_domains_domains`.`id` AS assocID,\n `glpi_entities`.`id` AS entity,\n `glpi_plugin_domains_domains`.`name` AS assocName,\n `glpi_plugin_domains_domains`.* " . "FROM `glpi_plugin_domains_domains` " . " LEFT JOIN `glpi_entities` ON (`glpi_entities`.`id` = `glpi_plugin_domains_domains`.`entities_id`) " . " WHERE `suppliers_id` = '{$ID}' " . getEntitiesRestrictRequest(" AND ", "glpi_plugin_domains_domains", '', '', true); $query .= " ORDER BY `assocName` "; $result = $DB->query($query); $number = $DB->numrows($result); $i = 0; $domains = array(); $domain = new PluginDomainsDomain(); $used = array(); if ($numrows = $DB->numrows($result)) { while ($data = $DB->fetch_assoc($result)) { $domains[$data['assocID']] = $data; $used[$data['id']] = $data['id']; } } echo "<div class='spaced'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr>"; echo "<th>" . __('Name') . "</th>"; if (Session::isMultiEntitiesMode()) { echo "<th>" . __('Entity') . "</th>"; } echo "<th>" . __('Group in charge of the hardware') . "</th>"; echo "<th>" . __('Supplier') . "</th>"; echo "<th>" . __('Technician in charge of the hardware') . "</th>"; echo "<th>" . __('Type') . "</th>"; echo "<th>" . __('Creation date') . "</th>"; echo "<th>" . __('Expiration date') . "</th>"; echo "</tr>"; $used = array(); if ($number) { Session::initNavigateListItems('PluginDomainsDomain', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName())); foreach ($domains as $data) { $domainID = $data["id"]; $link = NOT_AVAILABLE; if ($domain->getFromDB($domainID)) { $link = $domain->getLink(); } Session::addToNavigateListItems('PluginDomainsDomain', $domainID); $used[$domainID] = $domainID; $assocID = $data["assocID"]; echo "<tr class='tab_bg_1" . ($data["is_deleted"] ? "_2" : "") . "'>"; echo "<td class='center'>{$link}</td>"; if (Session::isMultiEntitiesMode()) { echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entities_id']) . "</td>"; } echo "<td class='center'>" . Dropdown::getDropdownName("glpi_groups", $data["groups_id_tech"]) . "</td>"; echo "<td>"; echo "<a href=\"" . $CFG_GLPI["root_doc"] . "/front/enterprise.form.php?ID=" . $data["suppliers_id"] . "\">"; echo Dropdown::getDropdownName("glpi_suppliers", $data["suppliers_id"]); if ($_SESSION["glpiis_ids_visible"] == 1) { echo " (" . $data["suppliers_id"] . ")"; } echo "</a></td>"; echo "<td class='center'>" . getUsername($data["users_id_tech"]) . "</td>"; echo "<td class='center'>" . Dropdown::getDropdownName("glpi_plugin_domains_domaintypes", $data["plugin_domains_domaintypes_id"]) . "</td>"; echo "<td class='center'>" . Html::convdate($data["date_creation"]) . "</td>"; if ($data["date_expiration"] <= date('Y-m-d') && !empty($data["date_expiration"])) { echo "<td class='center'><div class='deleted'>" . convdate($data["date_expiration"]) . "</div></td>"; } else { if (empty($data["date_expiration"])) { echo "<td class='center'>" . __('Does not expire', 'domains') . "</td>"; } else { echo "<td class='center'>" . Html::convdate($data["date_expiration"]) . "</td>"; } } echo "</tr>"; $i++; } } echo "</table>"; echo "</div>"; }
static function showGrupos(CommonDBTM $item, $withtemplate = '') { global $DB, $CFG_GLPI; $objeto = $item->getType(); $appli = new $objeto(); $ID = $item->fields['id']; $appli->getFromDB($item->fields['id']); //$canedit = $appli->can($appli->fields['id'],'w'); $canedit = $appli->canCreate(); //$canedit = Session::haveRight('update_ticket', 1); $rand = mt_rand(); $groups = self::getFormGroups($ID); $used = array(); if (!empty($groups)) { foreach ($groups as $data) { $used[$data["id"]] = $data["id"]; } } echo "<div class='center'>"; echo "<form name='form_grupo' id='form_grupo' method='post' action='../front/formgroup.form.php'>"; echo "<table class='tab_cadre_fixe'>"; echo "<th colspan=2>" . __('Grupos', 'Grupos') . "</th>"; echo "<tr>"; echo "<th>" . __('Grupo', 'Grupo') . " :" . "</th>"; echo "<td>"; if ($canedit) { Group::dropdown(array('name' => 'groups_id', 'entity' => $_SESSION['glpiactive_entity'], 'condition' => '`is_assign`')); } echo "</td>"; //----------------------------- echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td colspan='2' align = 'center'>"; echo "<input type='submit' name='agregarGrupo' value='Agregar' class='submit'>"; echo "</td></tr>"; echo "</table>"; echo "<input type='hidden' name='itemtype' value='Group'>"; echo "<input type='hidden' name='peticion_id' value='" . $item->fields['id'] . "'>"; //echo "</form>"; Html::closeForm(); echo "</div>"; // Listado de Grupos echo "<div class='spaced'>"; /* if ($canedit && count($used)) { $rand = mt_rand(); Html::openMassiveActionsForm('mass'.__CLASS__.$rand); echo "<input type='hidden' name='plugin_formcreator_forms_id' value='".$item->fields['id']."'>"; $massiveactionparams = array('num_displayed' => count($used), 'container' => 'mass'.__CLASS__.$rand); Html::showMassiveActions($massiveactionparams); }*/ if ($canedit && $withtemplate < 2) { Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array('num_displayed' => count($used)); Html::showMassiveActions($massiveactionparams); } echo "<table class='tab_cadre_fixehov'>"; $header_begin = "<tr>"; $header_top = ''; $header_bottom = ''; $header_end = ''; if ($canedit && count($used)) { $header_begin .= "<th width='10'>"; $header_top .= Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); $header_bottom .= Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); $header_end .= "</th>"; } $header_end .= "<th>" . Group::getTypeName(1) . "</th>"; echo $header_begin . $header_top . $header_end; $group = new Group(); if (!empty($groups)) { Session::initNavigateListItems('PluginFormcreatorForm', sprintf(__('%1$s = %2$s'), $item::getTypeName(1), $item->getName())); foreach ($groups as $data) { if (!$group->getFromDB($data["id"])) { continue; } Session::addToNavigateListItems('PluginFormcreatorForm', $data["id"]); echo "<tr class='tab_bg_1'>"; if ($canedit && count($used)) { echo "<td width='10'>"; // echo __CLASS__; Html::showMassiveActionCheckBox('PluginFormcreatorForm_Item', $data["linkID"]); echo "</td>"; } $link = $data["completename"]; if ($_SESSION["glpiis_ids_visible"]) { $link = sprintf(__('%1$s (%2$s)'), $link, $data["id"]); } $href = "<a href='" . $CFG_GLPI["root_doc"] . "/front/group.form.php?id=" . $data["id"] . "'>" . $link . "</a>"; echo "<td>" . $group->getLink() . "</td>"; echo "</tr>"; } echo $header_begin . $header_bottom . $header_end; } else { echo "<tr class='tab_bg_1'>"; echo "<td colspan='5' class='center'>" . __('None') . "</td></tr>"; } echo "</table>"; if ($canedit && count($used)) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } echo "</div>"; }
/** * Show domains associated to an item * * @since version 0.84 * * @param $item CommonDBTM object for which associated domains must be displayed * @param $withtemplate (default '') **/ static function showForItem(CommonDBTM $item, $withtemplate = '') { global $DB, $CFG_GLPI; $ID = $item->getField('id'); if ($item->isNewID($ID)) { return false; } if (!plugin_domains_haveRight('domains', 'r')) { return false; } if (!$item->can($item->fields['id'], 'r')) { return false; } if (empty($withtemplate)) { $withtemplate = 0; } $canedit = $item->canadditem('PluginDomainsDomain'); $rand = mt_rand(); $is_recursive = $item->isRecursive(); $query = "SELECT `glpi_plugin_domains_domains_items`.`id` AS assocID,\n `glpi_entities`.`id` AS entity,\n `glpi_plugin_domains_domains`.`name` AS assocName,\n `glpi_plugin_domains_domains`.*\n FROM `glpi_plugin_domains_domains_items`\n LEFT JOIN `glpi_plugin_domains_domains`\n ON (`glpi_plugin_domains_domains_items`.`plugin_domains_domains_id`=`glpi_plugin_domains_domains`.`id`)\n LEFT JOIN `glpi_entities` ON (`glpi_plugin_domains_domains`.`entities_id`=`glpi_entities`.`id`)\n WHERE `glpi_plugin_domains_domains_items`.`items_id` = '{$ID}'\n AND `glpi_plugin_domains_domains_items`.`itemtype` = '" . $item->getType() . "' "; $query .= getEntitiesRestrictRequest(" AND", "glpi_plugin_domains_domains", '', '', true); $query .= " ORDER BY `assocName`"; $result = $DB->query($query); $number = $DB->numrows($result); $i = 0; $domains = array(); $domain = new PluginDomainsDomain(); $used = array(); if ($numrows = $DB->numrows($result)) { while ($data = $DB->fetch_assoc($result)) { $domains[$data['assocID']] = $data; $used[$data['id']] = $data['id']; } } if ($canedit && $withtemplate < 2) { // Restrict entity for knowbase $entities = ""; $entity = $_SESSION["glpiactive_entity"]; if ($item->isEntityAssign()) { /// Case of personal items : entity = -1 : create on active entity (Reminder case)) if ($item->getEntityID() >= 0) { $entity = $item->getEntityID(); } if ($item->isRecursive()) { $entities = getSonsOf('glpi_entities', $entity); } else { $entities = $entity; } } $limit = getEntitiesRestrictRequest(" AND ", "glpi_plugin_domains_domains", '', $entities, true); $q = "SELECT COUNT(*)\n FROM `glpi_plugin_domains_domains`\n WHERE `is_deleted` = '0'\n {$limit}"; $result = $DB->query($q); $nb = $DB->result($result, 0, 0); echo "<div class='firstbloc'>"; if (plugin_domains_haveRight('domains', 'r') && $nb > count($used)) { echo "<form name='domain_form{$rand}' id='domain_form{$rand}' method='post'\n action='" . Toolbox::getItemTypeFormURL('PluginDomainsDomain') . "'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'>"; echo "<td colspan='4' class='center'>"; echo "<input type='hidden' name='entities_id' value='{$entity}'>"; echo "<input type='hidden' name='is_recursive' value='{$is_recursive}'>"; echo "<input type='hidden' name='itemtype' value='" . $item->getType() . "'>"; echo "<input type='hidden' name='items_id' value='{$ID}'>"; if ($item->getType() == 'Ticket') { echo "<input type='hidden' name='tickets_id' value='{$ID}'>"; } $domain->dropdownDomains("plugin_domains_domains_id", $entities, $used); echo "</td><td class='center' width='20%'>"; echo "<input type='submit' name='additem' value=\"" . __s('Associate a domain', 'domains') . "\" class='submit'>"; echo "</td>"; echo "</tr>"; echo "</table>"; Html::closeForm(); } echo "</div>"; } echo "<div class='spaced'>"; if ($canedit && $number && $withtemplate < 2) { Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array('num_displayed' => $number); Html::showMassiveActions(__CLASS__, $massiveactionparams); } echo "<table class='tab_cadre_fixe'>"; echo "<tr>"; if ($canedit && $number && $withtemplate < 2) { echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>"; } echo "<th>" . __('Name') . "</th>"; if (Session::isMultiEntitiesMode()) { echo "<th>" . __('Entity') . "</th>"; } echo "<th>" . __('Group in charge of the hardware') . "</th>"; echo "<th>" . __('Supplier') . "</th>"; echo "<th>" . __('Technician in charge of the hardware') . "</th>"; echo "<th>" . __('Type') . "</th>"; echo "<th>" . __('Creation date') . "</th>"; echo "<th>" . __('Expiration date') . "</th>"; echo "</tr>"; $used = array(); if ($number) { Session::initNavigateListItems('PluginDomainsDomain', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName())); foreach ($domains as $data) { $domainID = $data["id"]; $link = NOT_AVAILABLE; if ($domain->getFromDB($domainID)) { $link = $domain->getLink(); } Session::addToNavigateListItems('PluginDomainsDomain', $domainID); $used[$domainID] = $domainID; $assocID = $data["assocID"]; echo "<tr class='tab_bg_1" . ($data["is_deleted"] ? "_2" : "") . "'>"; if ($canedit && $withtemplate < 2) { echo "<td width='10'>"; Html::showMassiveActionCheckBox(__CLASS__, $data["assocID"]); echo "</td>"; } echo "<td class='center'>{$link}</td>"; if (Session::isMultiEntitiesMode()) { echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entities_id']) . "</td>"; } echo "<td class='center'>" . Dropdown::getDropdownName("glpi_groups", $data["groups_id_tech"]) . "</td>"; echo "<td>"; echo "<a href=\"" . $CFG_GLPI["root_doc"] . "/front/enterprise.form.php?ID=" . $data["suppliers_id"] . "\">"; echo Dropdown::getDropdownName("glpi_suppliers", $data["suppliers_id"]); if ($_SESSION["glpiis_ids_visible"] == 1) { echo " (" . $data["suppliers_id"] . ")"; } echo "</a></td>"; echo "<td class='center'>" . getUsername($data["users_id_tech"]) . "</td>"; echo "<td class='center'>" . Dropdown::getDropdownName("glpi_plugin_domains_domaintypes", $data["plugin_domains_domaintypes_id"]) . "</td>"; echo "<td class='center'>" . Html::convdate($data["date_creation"]) . "</td>"; if ($data["date_expiration"] <= date('Y-m-d') && !empty($data["date_expiration"])) { echo "<td class='center'><div class='deleted'>" . convdate($data["date_expiration"]) . "</div></td>"; } else { if (empty($data["date_expiration"])) { echo "<td class='center'>" . __('Does not expire', 'domains') . "</td>"; } else { echo "<td class='center'>" . Html::convdate($data["date_expiration"]) . "</td>"; } } echo "</tr>"; $i++; } } echo "</table>"; if ($canedit && $number && $withtemplate < 2) { $massiveactionparams['ontop'] = false; Html::showMassiveActions(__CLASS__, $massiveactionparams); Html::closeForm(); } echo "</div>"; }
/** * Show accounts associated to an item * * @since version 0.84 * * @param $item CommonDBTM object for which associated accounts must be displayed * @param $withtemplate (default '') **/ static function showForItem(CommonDBTM $item, $withtemplate = '') { global $DB, $CFG_GLPI; $ID = $item->getField('id'); if ($item->isNewID($ID)) { return false; } if (!Session::haveRight("plugin_accounts", READ)) { return false; } if (!$item->can($item->fields['id'], READ)) { return false; } if (empty($withtemplate)) { $withtemplate = 0; } $canedit = $item->canadditem('PluginAccountsAccount'); $rand = mt_rand(); $is_recursive = $item->isRecursive(); $who = Session::getLoginUserID(); if (count($_SESSION["glpigroups"]) && Session::haveRight("plugin_accounts_my_groups", 1)) { $first_groups = true; $groups = ""; foreach ($_SESSION['glpigroups'] as $val) { if (!$first_groups) { $groups .= ","; } else { $first_groups = false; } $groups .= "'" . $val . "'"; } $ASSIGN = "( `groups_id` IN ({$groups}) OR `users_id` = '{$who}') "; } else { // Only personal ones $ASSIGN = " `users_id` = '{$who}' "; } $query = "SELECT `glpi_plugin_accounts_accounts_items`.`id` AS assocID,\n `glpi_entities`.`id` AS entity,\n `glpi_plugin_accounts_accounts`.`name` AS assocName,\n `glpi_plugin_accounts_accounts`.*\n FROM `glpi_plugin_accounts_accounts_items`\n LEFT JOIN `glpi_plugin_accounts_accounts`\n ON (`glpi_plugin_accounts_accounts_items`.`plugin_accounts_accounts_id`=`glpi_plugin_accounts_accounts`.`id`)\n LEFT JOIN `glpi_entities` ON (`glpi_plugin_accounts_accounts`.`entities_id`=`glpi_entities`.`id`)\n WHERE `glpi_plugin_accounts_accounts_items`.`items_id` = '{$ID}'\n AND `glpi_plugin_accounts_accounts_items`.`itemtype` = '" . $item->getType() . "' "; $query .= getEntitiesRestrictRequest(" AND", "glpi_plugin_accounts_accounts", '', '', true); if (!Session::haveRight("plugin_accounts_see_all_users", 1)) { $query .= " AND {$ASSIGN} "; } $query .= " ORDER BY `assocName`"; $result = $DB->query($query); $number = $DB->numrows($result); $i = 0; $accounts = array(); $account = new PluginAccountsAccount(); $used = array(); if ($numrows = $DB->numrows($result)) { while ($data = $DB->fetch_assoc($result)) { $accounts[$data['assocID']] = $data; $used[$data['id']] = $data['id']; } } if ($canedit && $withtemplate < 2) { // Restrict entity for knowbase $entities = ""; $entity = $_SESSION["glpiactive_entity"]; if ($item->isEntityAssign()) { /// Case of personal items : entity = -1 : create on active entity (Reminder case)) if ($item->getEntityID() >= 0) { $entity = $item->getEntityID(); } if ($item->isRecursive()) { $entities = getSonsOf('glpi_entities', $entity); } else { $entities = $entity; } } $limit = getEntitiesRestrictRequest(" AND ", "glpi_plugin_accounts_accounts", '', $entities, true); $q = "SELECT COUNT(*)\n FROM `glpi_plugin_accounts_accounts`\n WHERE `is_deleted` = '0'\n {$limit}"; $result = $DB->query($q); $nb = $DB->result($result, 0, 0); echo "<div class='firstbloc'>"; if (Session::haveRight('plugin_accounts', READ) && $nb > count($used)) { echo "<form name='account_form{$rand}' id='account_form{$rand}' method='post'\n action='" . Toolbox::getItemTypeFormURL('PluginAccountsAccount') . "'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'>"; echo "<td colspan='4' class='center'>"; echo "<input type='hidden' name='entities_id' value='{$entity}'>"; echo "<input type='hidden' name='is_recursive' value='{$is_recursive}'>"; echo "<input type='hidden' name='itemtype' value='" . $item->getType() . "'>"; echo "<input type='hidden' name='items_id' value='{$ID}'>"; if ($item->getType() == 'Ticket') { echo "<input type='hidden' name='tickets_id' value='{$ID}'>"; } PluginAccountsAccount::dropdownAccount(array('entity' => $entities, 'used' => $used)); echo "</td><td class='center' width='20%'>"; echo "<input type='submit' name='additem' value=\"" . _sx('button', 'Associate a account', 'accounts') . "\" class='submit'>"; echo "</td>"; echo "</tr>"; echo "</table>"; Html::closeForm(); } echo "</div>"; } echo "<div class='spaced'>"; if ($canedit && $number && $withtemplate < 2) { Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array('num_displayed' => $number); Html::showMassiveActions($massiveactionparams); } echo "<table class='tab_cadre_fixe'>"; if (Session::isMultiEntitiesMode()) { $colsup = 1; } else { $colsup = 0; } //hash $hashclass = new PluginAccountsHash(); $hash = 0; $restrict = getEntitiesRestrictRequest(" ", "glpi_plugin_accounts_hashes", '', $item->getEntityID(), $hashclass->maybeRecursive()); $hashes = getAllDatasFromTable("glpi_plugin_accounts_hashes", $restrict); if (!empty($hashes)) { foreach ($hashes as $hashe) { $hash = $hashe["hash"]; $hash_id = $hashe["id"]; } $alert = ''; } else { $alert = __('There is no encryption key for this entity', 'accounts'); } $aeskey = new PluginAccountsAesKey(); echo "<tr><th colspan='" . (8 + $colsup) . "'>"; if ($hash) { if (!$aeskey->getFromDBByHash($hash_id) || !$aeskey->fields["name"]) { _e('Encryption key', 'accounts'); echo "<input type='password' name='aeskey' id='aeskey' autocomplete='off'>"; } else { echo Html::hidden('aeskey', array('value' => $aeskey->fields["name"], 'id' => 'aeskey', 'autocomplete' => 'off')); } } else { echo __('Encryption key', 'accounts'); echo "<div class='red'>"; echo $alert; echo "</div>"; } echo "<tr>"; if ($canedit && $number && $withtemplate < 2) { echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>"; } echo "<th>" . __('Name') . "</th>"; if (Session::isMultiEntitiesMode()) { echo "<th>" . __('Entity') . "</th>"; } echo "<th>" . __('Login') . "</th>"; echo "<th>" . __('Password') . "</th>"; echo "<th>" . __('Affected User', 'accounts') . "</th>"; echo "<th>" . __('Type') . "</th>"; echo "<th>" . __('Creation date') . "</th>"; echo "<th>" . __('Expiration date') . "</th>"; echo "</tr>"; $used = array(); if ($number) { Session::initNavigateListItems('PluginAccountsAccount', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName())); foreach ($accounts as $data) { $accountID = $data["id"]; $link = NOT_AVAILABLE; if ($account->getFromDB($accountID)) { $link = $account->getLink(); } Session::addToNavigateListItems('PluginAccountsAccount', $accountID); $used[$accountID] = $accountID; $assocID = $data["assocID"]; echo "<tr class='tab_bg_1" . ($data["is_deleted"] ? "_2" : "") . "'>"; if ($canedit && $withtemplate < 2) { echo "<td width='10'>"; Html::showMassiveActionCheckBox(__CLASS__, $data["assocID"]); echo "</td>"; } echo "<td class='center'>{$link}</td>"; if (Session::isMultiEntitiesMode()) { echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entities_id']) . "</td>"; } echo "<td class='center'>" . $data["login"] . "</td>"; echo "<td class='center'>"; //hash if (isset($hash_id) && $aeskey->getFromDBByHash($hash_id) && $aeskey->fields["name"]) { echo Html::hidden("encrypted_password{$accountID}", array('value' => $data["encrypted_password"], 'id' => "encrypted_password{$accountID}", 'autocomplete' => 'off')); echo "<input type='text' id='hidden_password{$accountID}' value='' size='30' >"; echo Html::scriptBlock("\n if (!check_hash()) {\n \$('#hidden_password{$accountID}')\n .after('" . __('Wrong encryption key', 'accounts') . "')\n .remove();\n } else {\n decrypt_password('{$accountID}');\n }\n "); } else { $url = $CFG_GLPI["root_doc"] . "/plugins/accounts/front/account.form.php"; echo " <input type='button' id='decrypt_link{$accountID}' name='decrypte' value='" . __s('Uncrypt', 'accounts') . "'\n class='submit'>"; echo Html::hidden("encrypted_password{$accountID}", array('value' => $data["encrypted_password"], 'id' => "encrypted_password{$accountID}", 'autocomplete' => 'off')); echo Html::scriptBlock("\$(document).on('click', '#decrypt_link{$accountID}', function(event) {\n if (!check_hash()) {\n alert('" . __('Wrong encryption key', 'accounts') . "');\n } else {\n var decrypted_password = decrypt_password('{$accountID}');\n \$('#decrypt_link{$accountID}')\n .after(decrypted_password)\n .remove();\n }\n });"); } echo "</td>"; echo "<td class='center'>"; echo getUsername($data["users_id"]); echo "</td>"; echo "<td class='center'>"; echo Dropdown::getDropdownName("glpi_plugin_accounts_accounttypes", $data["plugin_accounts_accounttypes_id"]); echo "</td>"; echo "<td class='center'>" . Html::convdate($data["date_creation"]) . "</td>"; if ($data["date_expiration"] <= date('Y-m-d') && !empty($data["date_expiration"])) { echo "<td class='center'>"; echo "<div class='deleted'>" . Html::convdate($data["date_expiration"]) . "</div>"; echo "</td>"; } else { if (empty($data["date_expiration"])) { echo "<td class='center'>" . __('Don\'t expire', 'accounts') . "</td>"; } else { echo "<td class='center'>" . Html::convdate($data["date_expiration"]) . "</td>"; } } echo "</tr>"; $i++; } } echo "</table>"; echo Html::hidden('good_hash', array('value' => $hash, 'id' => 'good_hash')); if ($canedit && $number && $withtemplate < 2) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } echo "</div>"; }
/** * Show projet associated to an item * * @since version 0.84 * * @param $item CommonDBTM object for which associated projet must be displayed * @param $withtemplate (default '') **/ static function showForItem(CommonDBTM $item, $withtemplate = '') { global $DB, $CFG_GLPI; $ID = $item->getField('id'); if ($item->isNewID($ID)) { return false; } if (!plugin_projet_haveRight('projet', 'r')) { return false; } if (!$item->can($item->fields['id'], 'r')) { return false; } if (empty($withtemplate)) { $withtemplate = 0; } $canedit = $item->canadditem('PluginProjetProjet'); $rand = mt_rand(); $is_recursive = $item->isRecursive(); $query = "SELECT `glpi_plugin_projet_projets_items`.`id` AS assocID,\n `glpi_entities`.`id` AS entity,\n `glpi_plugin_projet_projets`.`name` AS assocName,\n `glpi_plugin_projet_projets`.*\n FROM `glpi_plugin_projet_projets_items`\n LEFT JOIN `glpi_plugin_projet_projets`\n ON (`glpi_plugin_projet_projets_items`.`plugin_projet_projets_id`=`glpi_plugin_projet_projets`.`id`)\n LEFT JOIN `glpi_entities` ON (`glpi_plugin_projet_projets`.`entities_id`=`glpi_entities`.`id`)\n WHERE `glpi_plugin_projet_projets_items`.`items_id` = '{$ID}'\n AND `glpi_plugin_projet_projets_items`.`itemtype` = '" . $item->getType() . "' "; $query .= getEntitiesRestrictRequest(" AND", "glpi_plugin_projet_projets", '', '', true); $query .= " ORDER BY `assocName`"; $result = $DB->query($query); $number = $DB->numrows($result); $i = 0; $projets = array(); $used = array(); if ($numrows = $DB->numrows($result)) { while ($data = $DB->fetch_assoc($result)) { $projets[$data['assocID']] = $data; $used[$data['id']] = $data['id']; } } $projet = new PluginProjetProjet(); if ($canedit && $withtemplate < 2) { // Restrict entity for knowbase $entities = ""; $entity = $_SESSION["glpiactive_entity"]; if ($item->isEntityAssign()) { /// Case of personal items : entity = -1 : create on active entity (Reminder case)) if ($item->getEntityID() >= 0) { $entity = $item->getEntityID(); } if ($item->isRecursive()) { $entities = getSonsOf('glpi_entities', $entity); } else { $entities = $entity; } } $limit = getEntitiesRestrictRequest(" AND ", "glpi_plugin_projet_projets", '', $entities, true); $q = "SELECT COUNT(*)\n FROM `glpi_plugin_projet_projets`\n WHERE `is_deleted` = '0'\n AND `is_template` = '0' "; if ($item->getType() != 'User') { $q .= " {$limit}"; } $result = $DB->query($q); $nb = $DB->result($result, 0, 0); echo "<div class='firstbloc'>"; if (plugin_projet_haveRight('projet', 'r') && $nb > count($used)) { echo "<form name='projet_form{$rand}' id='projet_form{$rand}' method='post'\n action='" . Toolbox::getItemTypeFormURL('PluginProjetProjet') . "'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'>"; echo "<td colspan='4' class='center'>"; echo "<input type='hidden' name='entities_id' value='{$entity}'>"; echo "<input type='hidden' name='is_recursive' value='{$is_recursive}'>"; echo "<input type='hidden' name='itemtype' value='" . $item->getType() . "'>"; echo "<input type='hidden' name='items_id' value='{$ID}'>"; if ($item->getType() == 'Ticket') { echo "<input type='hidden' name='tickets_id' value='{$ID}'>"; } if ($item->getType() != 'User') { $projet->dropdownProjet("plugin_projet_projets_id", $entities, $used); } else { $strict_entities = Profile_User::getUserEntities($ID, true); if (!Session::haveAccessToOneOfEntities($strict_entities) && !isViewAllEntities()) { $canedit = false; } if (countElementsInTableForEntity("glpi_plugin_projet_projets", $strict_entities) > count($used)) { Dropdown::show('PluginProjetProjet', array('name' => "plugin_projet_projets_id", 'used' => $used, 'entity' => $strict_entities)); } } echo "</td><td class='center' width='20%'>"; echo "<input type='submit' name='additem' value=\"" . _sx('button', 'Associate a project', 'projet') . "\" class='submit'>"; echo "</td>"; echo "</tr>"; echo "</table>"; Html::closeForm(); } echo "</div>"; } echo "<div class='spaced'>"; if ($canedit && $number && $withtemplate < 2) { Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array('num_displayed' => $number); Html::showMassiveActions(__CLASS__, $massiveactionparams); } echo "<table class='tab_cadre_fixe'>"; if (Session::isMultiEntitiesMode()) { $colsup = 1; } else { $colsup = 0; } if ($item->getType() == "Group" || $item->getType() == "User") { echo "<tr><th colspan='" . (7 + $colsup) . "'>" . _n('Associated project', 'Associated projects', 2, 'projet') . ":</th></tr>"; } echo "<tr>"; if ($canedit && $number && $withtemplate < 2) { echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>"; } echo "<th>" . __('Name') . "</th>"; if (Session::isMultiEntitiesMode()) { echo "<th>" . __('Entity') . "</th>"; } echo "<th>" . __('Description') . "</th>"; echo "<th>" . __('Progress') . "</th>"; echo "<th>" . __('Start date') . "</th>"; echo "<th>" . __('End date') . "</th>"; echo "</tr>"; $used = array(); if ($number) { Session::initNavigateListItems('PluginProjetProjet', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName())); foreach ($projets as $data) { $projetID = $data["id"]; $link = NOT_AVAILABLE; if ($projet->getFromDB($projetID)) { $link = $projet->getLink(); } Session::addToNavigateListItems('PluginProjetProjet', $projetID); $used[$projetID] = $projetID; $assocID = $data["assocID"]; echo "<tr class='tab_bg_1" . ($data["is_deleted"] ? "_2" : "") . "'>"; if ($canedit && $withtemplate < 2) { echo "<td width='10'>"; Html::showMassiveActionCheckBox(__CLASS__, $data["assocID"]); echo "</td>"; } echo "<td class='center'>{$link}</td>"; if (Session::isMultiEntitiesMode()) { echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entities_id']) . "</td>"; } echo "<td align='center'>" . Html::resume_text($data["description"], 250) . "</td>"; echo "<td align='center'>" . PluginProjetProjet::displayProgressBar('100', $data["advance"]) . "</td>"; echo "<td class='center'>" . Html::convdate($data["date_begin"]) . "</td>"; if ($data["date_end"] <= date('Y-m-d') && !empty($data["date_end"])) { echo "<td class='center'><span class='red'>" . Html::convdate($data["date_end"]) . "</span></td>"; } else { echo "<td class='center'><span class='green'>" . Html::convdate($data["date_end"]) . "</span></td>"; } echo "</tr>"; $i++; } } echo "</table>"; if ($canedit && $number && $withtemplate < 2) { $massiveactionparams['ontop'] = false; Html::showMassiveActions(__CLASS__, $massiveactionparams); Html::closeForm(); } echo "</div>"; }
/** * Print an HTML array of contract associated to an object * * @since version 0.84 * * @param $item CommonDBTM object wanted * @param $withtemplate not used (to be deleted) (default '') * * @return Nothing (display) **/ static function showForItem(CommonDBTM $item, $withtemplate = '') { global $DB, $CFG_GLPI; $itemtype = $item->getType(); $ID = $item->fields['id']; if (!Contract::canView() || !$item->can($ID, READ)) { return false; } $canedit = $item->can($ID, UPDATE); $rand = mt_rand(); $query = "SELECT `glpi_contracts_items`.*\n FROM `glpi_contracts_items`,\n `glpi_contracts`\n LEFT JOIN `glpi_entities` ON (`glpi_contracts`.`entities_id`=`glpi_entities`.`id`)\n WHERE `glpi_contracts`.`id`=`glpi_contracts_items`.`contracts_id`\n AND `glpi_contracts_items`.`items_id` = '{$ID}'\n AND `glpi_contracts_items`.`itemtype` = '{$itemtype}'" . getEntitiesRestrictRequest(" AND", "glpi_contracts", '', '', true) . "\n ORDER BY `glpi_contracts`.`name`"; $result = $DB->query($query); $contracts = array(); $used = array(); if ($number = $DB->numrows($result)) { while ($data = $DB->fetch_assoc($result)) { $contracts[$data['id']] = $data; $used[$data['contracts_id']] = $data['contracts_id']; } } if ($canedit && $withtemplate != 2) { echo "<div class='firstbloc'>"; echo "<form name='contractitem_form{$rand}' id='contractitem_form{$rand}' method='post'\n action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>"; echo "<input type='hidden' name='items_id' value='{$ID}'>"; echo "<input type='hidden' name='itemtype' value='{$itemtype}'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_2'><th colspan='2'>" . __('Add a contract') . "</th></tr>"; echo "<tr class='tab_bg_1'><td>"; Contract::dropdown(array('entity' => $item->getEntityID(), 'used' => $used)); echo "</td><td class='center'>"; echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>"; echo "</td></tr>"; echo "</table>"; Html::closeForm(); echo "</div>"; } echo "<div class='spaced'>"; if ($withtemplate != 2) { if ($canedit && $number) { Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array('num_displayed' => $number, 'container' => 'mass' . __CLASS__ . $rand); Html::showMassiveActions($massiveactionparams); } } echo "<table class='tab_cadre_fixehov'>"; $header_begin = "<tr>"; $header_top = ''; $header_bottom = ''; $header_end = ''; if ($canedit && $number && $withtemplate != 2) { $header_top .= "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); $header_top .= "</th>"; $header_bottom .= "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); $header_bottom .= "</th>"; } $header_end .= "<th>" . __('Name') . "</th>"; $header_end .= "<th>" . __('Entity') . "</th>"; $header_end .= "<th>" . _x('phone', 'Number') . "</th>"; $header_end .= "<th>" . __('Contract type') . "</th>"; $header_end .= "<th>" . __('Supplier') . "</th>"; $header_end .= "<th>" . __('Start date') . "</th>"; $header_end .= "<th>" . __('Initial contract period') . "</th>"; $header_end .= "</tr>"; echo $header_begin . $header_top . $header_end; if ($number > 0) { Session::initNavigateListItems(__CLASS__, sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName())); foreach ($contracts as $data) { $cID = $data["contracts_id"]; Session::addToNavigateListItems(__CLASS__, $cID); $contracts[] = $cID; $assocID = $data["id"]; $con = new Contract(); $con->getFromDB($cID); echo "<tr class='tab_bg_1" . ($con->fields["is_deleted"] ? "_2" : "") . "'>"; if ($canedit && $withtemplate != 2) { echo "<td width='10'>"; Html::showMassiveActionCheckBox(__CLASS__, $data["id"]); echo "</td>"; } echo "<td class='center b'>"; $name = $con->fields["name"]; if ($_SESSION["glpiis_ids_visible"] || empty($con->fields["name"])) { $name = sprintf(__('%1$s (%2$s)'), $name, $con->fields["id"]); } echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/contract.form.php?id={$cID}'>" . $name; echo "</a></td>"; echo "<td class='center'>"; echo Dropdown::getDropdownName("glpi_entities", $con->fields["entities_id"]) . "</td>"; echo "<td class='center'>" . $con->fields["num"] . "</td>"; echo "<td class='center'>"; echo Dropdown::getDropdownName("glpi_contracttypes", $con->fields["contracttypes_id"]) . "</td>"; echo "<td class='center'>" . $con->getSuppliersNames() . "</td>"; echo "<td class='center'>" . Html::convDate($con->fields["begin_date"]) . "</td>"; echo "<td class='center'>" . sprintf(__('%1$s %2$s'), $con->fields["duration"], _n('month', 'months', $con->fields["duration"])); if ($con->fields["begin_date"] != '' && !empty($con->fields["begin_date"])) { echo " -> " . Infocom::getWarrantyExpir($con->fields["begin_date"], $con->fields["duration"], 0, true); } echo "</td>"; echo "</tr>"; } echo $header_begin . $header_bottom . $header_end; } echo "</table>"; if ($canedit && $number && $withtemplate != 2) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } echo "</div>"; }
/** * Show Infocom form for an item (not a standard showForm) * * @param $item CommonDBTM object * @param $withtemplate integer: template or basic item **/ static function showForItem(CommonDBTM $item, $withtemplate = '') { global $CFG_GLPI, $LANG; // Show Infocom or blank form if (!haveRight("infocom", "r")) { return false; } if (!$item) { echo "<div class='spaced'>" . $LANG['financial'][85] . "</div>"; } else { $date_tax = $CFG_GLPI["date_tax"]; $dev_ID = $item->getField('id'); $ic = new self(); $option = ""; if ($withtemplate == 2) { $option = " readonly "; } if (!strpos($_SERVER['PHP_SELF'], "infocoms-show") && in_array($item->getType(), array('CartridgeItem', 'ConsumableItem', 'Software'))) { echo "<div class='firstbloc center'>" . $LANG['financial'][84] . "</div>"; } if (!$ic->getFromDBforDevice($item->getType(), $dev_ID)) { $input = array('itemtype' => $item->getType(), 'items_id' => $dev_ID, 'entities_id' => $item->getEntityID()); if ($ic->can(-1, "w", $input) && $withtemplate != 2) { echo "<div class='spaced b'>"; echo "<table class='tab_cadre_fixe'><tr class='tab_bg_1'><th>"; echo $item->getTypeName() . " - " . $item->getName() . "</th></tr>"; echo "<tr class='tab_bg_1'><td class='center'>"; echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/infocom.form.php?itemtype=" . $item->getType() . "&items_id={$dev_ID}&add=add'>" . $LANG['financial'][68]; echo "</a></td></tr></table></div>"; } } else { // getFromDBforDevice $canedit = $ic->can($ic->fields['id'], "w") && $withtemplate != 2; if ($canedit) { echo "<form name='form_ic' method='post' action='" . $CFG_GLPI["root_doc"] . "/front/infocom.form.php'>"; } echo "<div class='spaced'>"; echo "<table class='tab_cadre" . (!strpos($_SERVER['PHP_SELF'], "infocoms-show") ? "_fixe" : "") . "'>"; echo "<tr><th colspan='4'>" . $LANG['financial'][3] . "</th></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . $LANG['financial'][26] . " :</td>"; echo "<td>"; if ($withtemplate == 2) { echo Dropdown::getDropdownName("glpi_suppliers", $ic->fields["suppliers_id"]); } else { Dropdown::show('Supplier', array('value' => $ic->fields["suppliers_id"], 'entity' => $item->getEntityID())); } echo "</td>"; if (haveRight("budget", "r")) { echo "<td>" . $LANG['financial'][87] . " :</td><td >"; Dropdown::show('Budget', array('value' => $ic->fields["budgets_id"], 'entity' => $item->getEntityID(), 'comments' => 1)); } else { echo "<td colspan='2'>"; } echo "</td></tr>"; // Can edit calendar ? $editcalendar = $withtemplate != 2; echo "<tr class='tab_bg_1'>"; echo "<td>" . $LANG['financial'][18] . " :</td>"; echo "<td >"; autocompletionTextField($ic, "order_number", array('option' => $option)); echo "</td>"; echo "<td>" . $LANG['financial'][28] . " :</td><td>"; showDateFormItem("order_date", $ic->fields["order_date"], true, $editcalendar); echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . $LANG['financial'][20] . "* :</td>"; echo "<td>"; $objectName = autoName($ic->fields["immo_number"], "immo_number", $withtemplate == 2, 'Infocom', $item->getEntityID()); autocompletionTextField($ic, "immo_number", array('value' => $objectName, 'option' => $option)); echo "</td>"; echo "<td>" . $LANG['financial'][14] . " :</td><td>"; showDateFormItem("buy_date", $ic->fields["buy_date"], true, $editcalendar); echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . $LANG['financial'][82] . " :</td>"; echo "<td>"; autocompletionTextField($ic, "bill", array('option' => $option)); echo "</td>"; echo "<td>" . $LANG['financial'][27] . " :</td><td>"; showDateFormItem("delivery_date", $ic->fields["delivery_date"], true, $editcalendar); echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . $LANG['financial'][19] . " :</td><td>"; autocompletionTextField($ic, "delivery_number", array('option' => $option)); echo "</td>"; echo "<td>" . $LANG['financial'][76] . " :</td><td>"; showDateFormItem("use_date", $ic->fields["use_date"], true, $editcalendar); echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . $LANG['financial'][21] . " :</td>"; echo "<td><input type='text' name='value' {$option} value='" . formatNumber($ic->fields["value"], true) . "' size='14'></td>"; echo "</td>"; echo "<td>" . $LANG['financial'][114] . " :</td><td>"; showDateFormItem("inventory_date", $ic->fields["inventory_date"], true, $editcalendar); echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . $LANG['financial'][78] . " :</td>"; echo "<td><input type='text' {$option} name='warranty_value' value='" . formatNumber($ic->fields["warranty_value"], true) . "' size='14'></td>"; echo "<td rowspan='5'>" . $LANG['common'][25] . " :</td>"; echo "<td rowspan='5' class='middle'>"; echo "<textarea cols='45' rows='9' name='comment' >" . $ic->fields["comment"]; echo "</textarea></td></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td>" . $LANG['financial'][81] . " :</td><td>"; echo formatNumber(self::Amort($ic->fields["sink_type"], $ic->fields["value"], $ic->fields["sink_time"], $ic->fields["sink_coeff"], $ic->fields["warranty_date"], $ic->fields["use_date"], $date_tax, "n")); echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . $LANG['financial'][22] . " :</td><td >"; if ($withtemplate == 2) { echo self::getAmortTypeName($ic->fields["sink_type"]); } else { self::dropdownAmortType("sink_type", $ic->fields["sink_type"]); } echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . $LANG['financial'][23] . " :</td><td>"; if ($withtemplate == 2) { echo $ic->fields["sink_time"]; } else { Dropdown::showInteger("sink_time", $ic->fields["sink_time"], 0, 15); } echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . $LANG['financial'][77] . " :</td>"; echo "<td>"; autocompletionTextField($ic, "sink_coeff", array('size' => 14, 'option' => $option)); echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; if (!in_array($item->getType(), array('Cartridge', 'CartridgeItem', 'Consumable', 'ConsumableItem', 'Software', 'SoftwareLicense'))) { echo "<td>" . $LANG['financial'][89] . " :</td><td>"; echo self::showTco($item->getField('ticket_tco'), $ic->fields["value"]); } else { echo "<td colspan='2'>"; } echo "</td>"; if (!in_array($item->getType(), array('Cartridge', 'CartridgeItem', 'Consumable', 'ConsumableItem', 'Software', 'SoftwareLicense'))) { echo "<td>" . $LANG['financial'][90] . " :</td><td>"; echo self::showTco($item->getField('ticket_tco'), $ic->fields["value"], $ic->fields["warranty_date"]); } else { echo "<td colspan='2'>"; } echo "</td></tr>"; echo "<tr><th colspan='4'>" . $LANG['financial'][7] . "</th></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . $LANG['financial'][29] . " :</td><td>"; showDateFormItem("warranty_date", $ic->fields["warranty_date"], true, $editcalendar); echo "</td>"; echo "<td>" . $LANG['financial'][15] . " :</td><td>"; if ($withtemplate == 2) { // -1 = life if ($ic->fields["warranty_duration"] == -1) { echo $LANG['financial'][2]; } else { echo $ic->fields["warranty_duration"]; } } else { Dropdown::showInteger("warranty_duration", $ic->fields["warranty_duration"], 0, 120, 1, array(-1 => $LANG['financial'][2])); } if ($ic->fields["warranty_duration"] >= 0) { echo " " . $LANG['financial'][57]; } echo "<span class='small_space'>" . $LANG['financial'][88] . "</span> "; echo getWarrantyExpir($ic->fields["warranty_date"], $ic->fields["warranty_duration"]); echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . $LANG['financial'][16] . " :</td>"; echo "<td >"; autocompletionTextField($ic, "warranty_info", array('option' => $option)); echo "</td>"; if ($CFG_GLPI['use_mailing']) { echo "<td>" . $LANG['setup'][247] . " :</td>"; echo "<td>"; echo self::dropdownAlert("alert", $ic->fields["alert"]); Alert::displayLastAlert('Infocom', $ic->fields['id']); echo "</td>"; } else { echo "</td><td colspan='2'>"; } echo "</td></tr>"; if ($canedit) { echo "<tr>"; echo "<td class='tab_bg_2 center' colspan='2'>"; echo "<input type='hidden' name='id' value='" . $ic->fields['id'] . "'>"; echo "<input type='submit' name='update' value=\"" . $LANG['buttons'][7] . "\"\n class='submit'>"; echo "</td>"; echo "<td class='tab_bg_2 center' colspan='2'>"; echo "<input type='submit' name='delete' value=\"" . $LANG['buttons'][6] . "\"\n class='submit'>"; echo "</td></tr>"; echo "</table></div></form>"; } else { echo "</table></div>"; } } } }
/** * Show certificates associated to an item * * @since version 0.84 * * @param $item CommonDBTM object for which associated certificates must be displayed * @param $withtemplate (default '') **/ static function showForItem(CommonDBTM $item, $withtemplate='') { global $DB, $CFG_GLPI; $ID = $item->getField('id'); if ($item->isNewID($ID)) { return false; } if (!Session::haveRight("plugin_certificates", READ)) { return false; } if (!$item->can($item->fields['id'], READ)) { return false; } if (empty($withtemplate)) { $withtemplate = 0; } $canedit = $item->canadditem('PluginCertificatesCertificate'); $rand = mt_rand(); $is_recursive = $item->isRecursive(); $query = "SELECT `glpi_plugin_certificates_certificates_items`.`id` AS assocID, `glpi_entities`.`id` AS entity, `glpi_plugin_certificates_certificates`.`name` AS assocName, `glpi_plugin_certificates_certificates`.* FROM `glpi_plugin_certificates_certificates_items` LEFT JOIN `glpi_plugin_certificates_certificates` ON (`glpi_plugin_certificates_certificates_items`.`plugin_certificates_certificates_id`=`glpi_plugin_certificates_certificates`.`id`) LEFT JOIN `glpi_entities` ON (`glpi_plugin_certificates_certificates`.`entities_id`=`glpi_entities`.`id`) WHERE `glpi_plugin_certificates_certificates_items`.`items_id` = '$ID' AND `glpi_plugin_certificates_certificates_items`.`itemtype` = '".$item->getType()."' "; $query .= getEntitiesRestrictRequest(" AND","glpi_plugin_certificates_certificates",'','',true); $query .= " ORDER BY `assocName`"; $result = $DB->query($query); $number = $DB->numrows($result); $i = 0; $certificates = array(); $certificate = new PluginCertificatesCertificate(); $used = array(); if ($numrows = $DB->numrows($result)) { while ($data = $DB->fetch_assoc($result)) { $certificates[$data['assocID']] = $data; $used[$data['id']] = $data['id']; } } if ($canedit && $withtemplate < 2) { // Restrict entity for knowbase $entities = ""; $entity = $_SESSION["glpiactive_entity"]; if ($item->isEntityAssign()) { /// Case of personal items : entity = -1 : create on active entity (Reminder case)) if ($item->getEntityID() >=0 ) { $entity = $item->getEntityID(); } if ($item->isRecursive()) { $entities = getSonsOf('glpi_entities',$entity); } else { $entities = $entity; } } $limit = getEntitiesRestrictRequest(" AND ","glpi_plugin_certificates_certificates",'',$entities,true); $q = "SELECT COUNT(*) FROM `glpi_plugin_certificates_certificates` WHERE `is_deleted` = '0' $limit"; $result = $DB->query($q); $nb = $DB->result($result,0,0); echo "<div class='firstbloc'>"; if (Session::haveRight("plugin_certificates", READ) && ($nb > count($used))) { echo "<form name='certificate_form$rand' id='certificate_form$rand' method='post' action='".Toolbox::getItemTypeFormURL('PluginCertificatesCertificate')."'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'>"; echo "<td colspan='4' class='center'>"; echo "<input type='hidden' name='entities_id' value='$entity'>"; echo "<input type='hidden' name='is_recursive' value='$is_recursive'>"; echo "<input type='hidden' name='itemtype' value='".$item->getType()."'>"; echo "<input type='hidden' name='items_id' value='$ID'>"; if ($item->getType() == 'Ticket') { echo "<input type='hidden' name='tickets_id' value='$ID'>"; } PluginCertificatesCertificate::dropdown(array('entity' => $entities , 'used' => $used)); echo "</td><td class='center' width='20%'>"; echo "<input type='submit' name='additem' value=\"". _sx('button', 'Associate a certificate', 'certificates')."\" class='submit'>"; echo "</td>"; echo "</tr>"; echo "</table>"; Html::closeForm(); } echo "</div>"; } echo "<div class='spaced'>"; if ($canedit && $number && ($withtemplate < 2)) { Html::openMassiveActionsForm('mass'.__CLASS__.$rand); $massiveactionparams = array('num_displayed' => $number); Html::showMassiveActions($massiveactionparams); } echo "<table class='tab_cadre_fixe'>"; echo "<tr>"; if ($canedit && $number && ($withtemplate < 2)) { echo "<th width='10'>".Html::getCheckAllAsCheckbox('mass'.__CLASS__.$rand)."</th>"; } echo "<th>".__('Name')."</th>"; if (Session::isMultiEntitiesMode()) { echo "<th>".__('Entity')."</th>"; } echo "<th>".__('Type')."</th>"; echo "<th>".__('DNS name', 'certificates')."</th>"; echo "<th>".__('DNS suffix', 'certificates')."</th>"; echo "<th>".__('Creation date')."</th>"; echo "<th>".__('Expiration date')."</th>"; echo "<th>".__('Status')."</th>"; echo "</tr>"; $used = array(); if ($number) { Session::initNavigateListItems('PluginCertificatesCertificate', //TRANS : %1$s is the itemtype name, // %2$s is the name of the item (used for headings of a list) sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName())); foreach ($certificates as $data) { $certificateID = $data["id"]; $link = NOT_AVAILABLE; if ($certificate->getFromDB($certificateID)) { $link = $certificate->getLink(); } Session::addToNavigateListItems('PluginCertificatesCertificate', $certificateID); $used[$certificateID] = $certificateID; $assocID = $data["assocID"]; echo "<tr class='tab_bg_1".($data["is_deleted"]?"_2":"")."'>"; if ($canedit && ($withtemplate < 2)) { echo "<td width='10'>"; Html::showMassiveActionCheckBox(__CLASS__, $data["assocID"]); echo "</td>"; } echo "<td class='center'>$link</td>"; if (Session::isMultiEntitiesMode()) { echo "<td class='center'>".Dropdown::getDropdownName("glpi_entities", $data['entities_id']). "</td>"; } echo "<td class='center'>"; echo Dropdown::getDropdownName("glpi_plugin_certificates_certificatetypes", $data["plugin_certificates_certificatetypes_id"]); echo "</td>"; echo "<td class='center'>".$data["dns_name"]."</td>"; echo "<td class='center'>".$data["dns_suffix"]."</td>"; echo "<td class='center'>".Html::convdate($data["date_query"])."</td>"; if ($data["date_expiration"] <= date('Y-m-d') && !empty($data["date_expiration"])) { echo "<td class='center'>"; echo "<div class='deleted'>".Html::convdate($data["date_expiration"])."</div>"; echo "</td>"; } else if (empty($data["date_expiration"])) { echo "<td class='center'>".__('Does not expire', 'certificates')."</td>"; } else { echo "<td class='center'>".Html::convdate($data["date_expiration"])."</td>"; } echo "<td class='center'>"; echo Dropdown::getDropdownName("glpi_plugin_certificates_certificatestates", $data["plugin_certificates_certificatestates_id"]); echo "</td>"; echo "</tr>"; $i++; } } echo "</table>"; if ($canedit && $number && ($withtemplate < 2)) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } echo "</div>"; }
/** * Show shellcommands associated to an item * * @since version 0.84 * * @param $item CommonDBTM object for which associated shellcommands must be displayed * @param $withtemplate (default '') * */ static function showForItem(CommonDBTM $item, $withtemplate = '') { global $DB, $CFG_GLPI; $ID = $item->getField('id'); if ($item->isNewID($ID)) { return false; } if (!self::canView()) { return false; } if (!$item->can($item->fields['id'], READ)) { return false; } if (empty($withtemplate)) { $withtemplate = 0; } $width = 200; $canedit = $item->canadditem('PluginShellcommandsShellcommand'); $rand = mt_rand(); $is_recursive = $item->isRecursive(); $query = "SELECT `glpi_plugin_shellcommands_shellcommands_items`.`id` AS assocID,\n `glpi_entities`.`id` AS entity,\n `glpi_plugin_shellcommands_shellcommands`.`name` AS assocName,\n `glpi_plugin_shellcommands_shellcommands`.*\n FROM `glpi_plugin_shellcommands_shellcommands_items`\n LEFT JOIN `glpi_plugin_shellcommands_shellcommands`\n ON (`glpi_plugin_shellcommands_shellcommands_items`.`plugin_shellcommands_shellcommands_id`=`glpi_plugin_shellcommands_shellcommands`.`id`)\n LEFT JOIN `glpi_entities` ON (`glpi_plugin_shellcommands_shellcommands`.`entities_id`=`glpi_entities`.`id`)\n WHERE `glpi_plugin_shellcommands_shellcommands_items`.`itemtype` = '" . $item->getType() . "' \n AND !`glpi_plugin_shellcommands_shellcommands`.`is_deleted`"; $query .= getEntitiesRestrictRequest(" AND", "glpi_plugin_shellcommands_shellcommands", '', '', true); $query .= " ORDER BY `assocName`"; $result = $DB->query($query); $number = $DB->numrows($result); $i = 0; $shells = array(); if ($numrows = $DB->numrows($result)) { while ($data = $DB->fetch_assoc($result)) { $shells[$data['assocID']] = $data; } } echo "<div class='spaced'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr>"; echo "<th>" . __('Associated Commands', 'shellcommands') . "</th>"; echo "</tr>"; if ($number) { Session::initNavigateListItems('PluginShellcommandsShellcommand', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName())); $selectCommandName[0] = Dropdown::EMPTY_VALUE; // $countCommand = self::countForItem($item, array('type' => 'ALL')); foreach ($shells as $data) { // if(isset($countCommand[$data['link'].$data['id']])) $selectCommandName[$data['link'] . '-' . $data['id']] = $data['assocName']; } echo "<tr class='tab_bg_2'>\n <td class='center'>" . PluginShellcommandsShellcommand::getTypeName(1) . " "; $randSelect = Dropdown::showFromArray("name", $selectCommandName, array('width' => $width)); echo "<span id='command_name{$randSelect}'></span></td>"; echo "</tr>"; Ajax::updateItemOnSelectEvent("dropdown_name{$randSelect}", "command_name{$randSelect}", $CFG_GLPI["root_doc"] . "/plugins/shellcommands/ajax/dropdownCommandValue.php", array('idtable' => $item->getType(), 'width' => $width, 'value' => '__VALUE__', 'itemID' => $ID, 'countItem' => 1, 'itemtype' => $item->getType(), 'toupdate' => 'shellcommand_result', 'command_type' => 'PluginShellcommandsShellcommand', 'myname' => "command_name")); } echo "</table>"; echo "</div>"; echo "<div class='spaced' id='shellcommand_result'></div>"; }
/** * Show webapplications associated to an item * * @since version 0.84 * * @param $item CommonDBTM object for which associated webapplications must be displayed * @param $withtemplate (default '') **/ static function showForItem(CommonDBTM $item, $withtemplate = '') { global $DB, $CFG_GLPI; $ID = $item->getField('id'); if ($item->isNewID($ID)) { return false; } if (!Session::haveRight("plugin_webapplications", READ)) { return false; } if (!$item->can($item->fields['id'], READ)) { return false; } if (empty($withtemplate)) { $withtemplate = 0; } $canedit = $item->canadditem('PluginWebapplicationsWebapplication'); $rand = mt_rand(); $is_recursive = $item->isRecursive(); $query = "SELECT `glpi_plugin_webapplications_webapplications_items`.`id` AS assocID,\n `glpi_entities`.`id` AS entity,\n `glpi_plugin_webapplications_webapplications`.`name` AS assocName,\n `glpi_plugin_webapplications_webapplications`.*\n FROM `glpi_plugin_webapplications_webapplications_items`\n LEFT JOIN `glpi_plugin_webapplications_webapplications`\n ON (`glpi_plugin_webapplications_webapplications_items`.`plugin_webapplications_webapplications_id`=`glpi_plugin_webapplications_webapplications`.`id`)\n LEFT JOIN `glpi_entities` ON (`glpi_plugin_webapplications_webapplications`.`entities_id`=`glpi_entities`.`id`)\n WHERE `glpi_plugin_webapplications_webapplications_items`.`items_id` = '{$ID}'\n AND `glpi_plugin_webapplications_webapplications_items`.`itemtype` = '" . $item->getType() . "' "; $query .= getEntitiesRestrictRequest(" AND", "glpi_plugin_webapplications_webapplications", '', '', true); $query .= " ORDER BY `assocName`"; $result = $DB->query($query); $number = $DB->numrows($result); $i = 0; $webs = array(); $web = new PluginWebapplicationsWebapplication(); $used = array(); if ($numrows = $DB->numrows($result)) { while ($data = $DB->fetch_assoc($result)) { $webs[$data['assocID']] = $data; $used[$data['id']] = $data['id']; } } if ($canedit && $withtemplate < 2) { // Restrict entity for knowbase $entities = ""; $entity = $_SESSION["glpiactive_entity"]; if ($item->isEntityAssign()) { /// Case of personal items : entity = -1 : create on active entity (Reminder case)) if ($item->getEntityID() >= 0) { $entity = $item->getEntityID(); } if ($item->isRecursive()) { $entities = getSonsOf('glpi_entities', $entity); } else { $entities = $entity; } } $limit = getEntitiesRestrictRequest(" AND ", "glpi_plugin_webapplications_webapplications", '', $entities, true); $q = "SELECT COUNT(*)\n FROM `glpi_plugin_webapplications_webapplications`\n WHERE `is_deleted` = '0'\n {$limit}"; $result = $DB->query($q); $nb = $DB->result($result, 0, 0); echo "<div class='firstbloc'>"; if (Session::haveRight("plugin_webapplications", READ) && $nb > count($used)) { echo "<form name='webapplication_form{$rand}' id='webapplication_form{$rand}' method='post'\n action='" . Toolbox::getItemTypeFormURL('PluginWebapplicationsWebapplication') . "'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'>"; echo "<td colspan='4' class='center'>"; echo "<input type='hidden' name='entities_id' value='{$entity}'>"; echo "<input type='hidden' name='is_recursive' value='{$is_recursive}'>"; echo "<input type='hidden' name='itemtype' value='" . $item->getType() . "'>"; echo "<input type='hidden' name='items_id' value='{$ID}'>"; if ($item->getType() == 'Ticket') { echo "<input type='hidden' name='tickets_id' value='{$ID}'>"; } PluginWebapplicationsWebapplication::dropdownWebapplication(array('entity' => $entities, 'used' => $used)); echo "</td><td class='center' width='20%'>"; echo "<input type='submit' name='additem' value=\"" . __s('Associate a web application', 'webapplications') . "\" class='submit'>"; echo "</td>"; echo "</tr>"; echo "</table>"; Html::closeForm(); } echo "</div>"; } echo "<div class='spaced'>"; if ($canedit && $number && $withtemplate < 2) { Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array('num_displayed' => $number); Html::showMassiveActions($massiveactionparams); } echo "<table class='tab_cadre_fixe'>"; echo "<tr>"; if ($canedit && $number && $withtemplate < 2) { echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>"; } echo "<th>" . __('Name') . "</th>"; if (Session::isMultiEntitiesMode()) { echo "<th>" . __('Entity') . "</th>"; } echo "<th>" . PluginWebapplicationsWebapplicationType::getTypeName(1) . "</th>"; echo "<th>" . __('URL') . "</th>"; echo "<th>" . __('Server') . "</th>"; echo "<th>" . __('Language') . "</th>"; echo "<th>" . __('Version') . "</th>"; echo "<th>" . __('Comments') . "</th>"; echo "</tr>"; $used = array(); if ($number) { Session::initNavigateListItems('PluginWebapplicationsWebapplication', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName())); foreach ($webs as $data) { $webID = $data["id"]; $link = NOT_AVAILABLE; if ($web->getFromDB($webID)) { $link = $web->getLink(); } Session::addToNavigateListItems('PluginWebapplicationsWebapplication', $webID); $used[$webID] = $webID; $assocID = $data["assocID"]; echo "<tr class='tab_bg_1" . ($data["is_deleted"] ? "_2" : "") . "'>"; if ($canedit && $withtemplate < 2) { echo "<td width='10'>"; Html::showMassiveActionCheckBox(__CLASS__, $data["assocID"]); echo "</td>"; } echo "<td class='center'>{$link}</td>"; if (Session::isMultiEntitiesMode()) { echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entities_id']) . "</td>"; } echo "<td>" . Dropdown::getDropdownName("glpi_plugin_webapplications_webapplicationtypes", $data["plugin_webapplications_webapplicationtypes_id"]) . "</td>"; $link = Toolbox::substr($data["address"], 0, 30) . "..."; echo "<td class='center'>" . "<a href=\"" . str_replace("&", "&", $data["address"]) . "\" target=\"_blank\">" . "<u>" . $link . "</u></a></td>"; echo "<td>" . Dropdown::getDropdownName("glpi_plugin_webapplications_webapplicationservertypes", $data["plugin_webapplications_webapplicationservertypes_id"]) . "</td>"; echo "<td>" . Dropdown::getDropdownName("glpi_plugin_webapplications_webapplicationtechnics", $data["plugin_webapplications_webapplicationtechnics_id"]) . "</td>"; echo "<td>" . $data["version"] . "</td>"; echo "<td>" . $data["comment"] . "</td>"; echo "</tr>"; $i++; } } echo "</table>"; if ($canedit && $number && $withtemplate < 2) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } echo "</div>"; }
/** * Show accounts associated to an item * * @since version 0.84 * * @param $item CommonDBTM object for which associated accounts must be displayed * @param $withtemplate (default '') **/ static function showForItem(CommonDBTM $item, $withtemplate = '') { global $DB, $CFG_GLPI; $ID = $item->getField('id'); if ($item->isNewID($ID)) { return false; } if (!plugin_accounts_haveRight('accounts', 'r')) { return false; } if (!$item->can($item->fields['id'], 'r')) { return false; } if (empty($withtemplate)) { $withtemplate = 0; } $canedit = $item->canadditem('PluginAccountsAccount'); $rand = mt_rand(); $is_recursive = $item->isRecursive(); $who = Session::getLoginUserID(); if (count($_SESSION["glpigroups"]) && plugin_accounts_haveRight("my_groups", "r")) { $first_groups = true; $groups = ""; foreach ($_SESSION['glpigroups'] as $val) { if (!$first_groups) { $groups .= ","; } else { $first_groups = false; } $groups .= "'" . $val . "'"; } $ASSIGN = "( `groups_id` IN ({$groups}) OR `users_id` = '{$who}') "; } else { // Only personal ones $ASSIGN = " `users_id` = '{$who}' "; } $query = "SELECT `glpi_plugin_accounts_accounts_items`.`id` AS assocID,\n `glpi_entities`.`id` AS entity,\n `glpi_plugin_accounts_accounts`.`name` AS assocName,\n `glpi_plugin_accounts_accounts`.*\n FROM `glpi_plugin_accounts_accounts_items`\n LEFT JOIN `glpi_plugin_accounts_accounts`\n ON (`glpi_plugin_accounts_accounts_items`.`plugin_accounts_accounts_id`=`glpi_plugin_accounts_accounts`.`id`)\n LEFT JOIN `glpi_entities` ON (`glpi_plugin_accounts_accounts`.`entities_id`=`glpi_entities`.`id`)\n WHERE `glpi_plugin_accounts_accounts_items`.`items_id` = '{$ID}'\n AND `glpi_plugin_accounts_accounts_items`.`itemtype` = '" . $item->getType() . "' "; $query .= getEntitiesRestrictRequest(" AND", "glpi_plugin_accounts_accounts", '', '', true); if (!plugin_accounts_haveRight("all_users", "r")) { $query .= " AND {$ASSIGN} "; } $query .= " ORDER BY `assocName`"; $result = $DB->query($query); $number = $DB->numrows($result); $i = 0; $accounts = array(); $account = new PluginAccountsAccount(); $used = array(); if ($numrows = $DB->numrows($result)) { while ($data = $DB->fetch_assoc($result)) { $accounts[$data['assocID']] = $data; $used[$data['id']] = $data['id']; } } if ($canedit && $withtemplate < 2) { // Restrict entity for knowbase $entities = ""; $entity = $_SESSION["glpiactive_entity"]; if ($item->isEntityAssign()) { /// Case of personal items : entity = -1 : create on active entity (Reminder case)) if ($item->getEntityID() >= 0) { $entity = $item->getEntityID(); } if ($item->isRecursive()) { $entities = getSonsOf('glpi_entities', $entity); } else { $entities = $entity; } } $limit = getEntitiesRestrictRequest(" AND ", "glpi_plugin_accounts_accounts", '', $entities, true); $q = "SELECT COUNT(*)\n FROM `glpi_plugin_accounts_accounts`\n WHERE `is_deleted` = '0'\n {$limit}"; $result = $DB->query($q); $nb = $DB->result($result, 0, 0); echo "<div class='firstbloc'>"; if (plugin_accounts_haveRight('accounts', 'r') && $nb > count($used)) { echo "<form name='account_form{$rand}' id='account_form{$rand}' method='post'\n action='" . Toolbox::getItemTypeFormURL('PluginAccountsAccount') . "'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'>"; echo "<td colspan='4' class='center'>"; echo "<input type='hidden' name='entities_id' value='{$entity}'>"; echo "<input type='hidden' name='is_recursive' value='{$is_recursive}'>"; echo "<input type='hidden' name='itemtype' value='" . $item->getType() . "'>"; echo "<input type='hidden' name='items_id' value='{$ID}'>"; if ($item->getType() == 'Ticket') { echo "<input type='hidden' name='tickets_id' value='{$ID}'>"; } $account->dropdownAccounts("plugin_accounts_accounts_id", $entities, $used); echo "</td><td class='center' width='20%'>"; echo "<input type='submit' name='additem' value=\"" . _sx('button', 'Associate a account', 'accounts') . "\" class='submit'>"; echo "</td>"; echo "</tr>"; echo "</table>"; Html::closeForm(); } echo "</div>"; } echo "<div class='spaced'>"; if ($canedit && $number && $withtemplate < 2) { Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array('num_displayed' => $number); Html::showMassiveActions(__CLASS__, $massiveactionparams); } echo "<table class='tab_cadre_fixe'>"; if (Session::isMultiEntitiesMode()) { $colsup = 1; } else { $colsup = 0; } //hash $hashclass = new PluginAccountsHash(); $hash = 0; $restrict = getEntitiesRestrictRequest(" ", "glpi_plugin_accounts_hashes", '', $item->getEntityID(), $hashclass->maybeRecursive()); $hashes = getAllDatasFromTable("glpi_plugin_accounts_hashes", $restrict); if (!empty($hashes)) { foreach ($hashes as $hashe) { $hash = $hashe["hash"]; $hash_id = $hashe["id"]; } $alert = ''; } else { $alert = __('There is no encryption key for this entity', 'accounts'); } $aeskey = new PluginAccountsAesKey(); if ($hash) { if (!$aeskey->getFromDBByHash($hash_id) || !$aeskey->fields["name"]) { echo "<tr><th colspan='" . (8 + $colsup) . "'>"; _e('Encryption key', 'accounts'); echo "<input type='password' name='aescrypted_key' id= 'aescrypted_key' autocomplete='off'>"; echo "</th></tr>"; } } else { echo "<tr><th colspan='" . (8 + $colsup) . "'>"; echo __('Encryption key', 'accounts') . "<div class='red'>"; echo $alert; echo "</div>"; echo "</th></tr>"; } echo "<tr>"; if ($canedit && $number && $withtemplate < 2) { echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>"; } echo "<th>" . __('Name') . "</th>"; if (Session::isMultiEntitiesMode()) { echo "<th>" . __('Entity') . "</th>"; } echo "<th>" . __('Login') . "</th>"; echo "<th>" . __('Password') . "</th>"; echo "<th>" . __('Affected User', 'accounts') . "</th>"; echo "<th>" . __('Type') . "</th>"; echo "<th>" . __('Creation date') . "</th>"; echo "<th>" . __('Expiration date') . "</th>"; echo "</tr>"; $used = array(); if ($number) { Session::initNavigateListItems('PluginAccountsAccount', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName())); foreach ($accounts as $data) { $accountID = $data["id"]; $link = NOT_AVAILABLE; if ($account->getFromDB($accountID)) { $link = $account->getLink(); } Session::addToNavigateListItems('PluginAccountsAccount', $accountID); $used[$accountID] = $accountID; $assocID = $data["assocID"]; echo "<tr class='tab_bg_1" . ($data["is_deleted"] ? "_2" : "") . "'>"; if ($canedit && $withtemplate < 2) { echo "<td width='10'>"; Html::showMassiveActionCheckBox(__CLASS__, $data["assocID"]); echo "</td>"; } echo "<td class='center'>{$link}</td>"; if (Session::isMultiEntitiesMode()) { echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entities_id']) . "</td>"; } echo "<td class='center'>" . $data["login"] . "</td>"; echo "<td class='center'>"; //hash if (isset($hash_id) && $aeskey->getFromDBByHash($hash_id) && $aeskey->fields["name"]) { echo "<input type='hidden' name='aeskey' id= 'aeskey'\n value='" . $aeskey->fields["name"] . "' class='' autocomplete='off'>"; echo "<input type='hidden' autocomplete='off'\n name='encrypted_password\${$accountID}' value='" . $data["encrypted_password"] . "'>"; echo "<input type='text' name='hidden_password\${$accountID}' value='' size='30' >"; echo "<script language='javascript'>\n var good_hash=\"{$hash}\";\n var hash=SHA256(SHA256(document.getElementById(\"aeskey\").value));\n if (hash != good_hash) {\n document.getElementsByName(\"hidden_password\${$accountID}\").\n item(0).value=\"" . __s('Wrong encryption key', 'accounts') . "\";\n } else {\n document.getElementsByName(\"hidden_password\${$accountID}\").\n item(0).value=AESDecryptCtr(document.getElementsByName(\"encrypted_password\${$accountID}\").\n item(0).value,SHA256(document.getElementById(\"aeskey\").value), 256)};</script>"; } else { $url = $CFG_GLPI["root_doc"] . "/plugins/accounts/front/account.form.php"; echo " <input type='button' id='decrypte_link{$accountID}' name='decrypte' value='" . __s('Uncrypt', 'accounts') . "'\n class='submit' onclick='return false;'>"; echo "<script type='text/javascript'>\n Ext.get('decrypte_link{$accountID}').on('click', function () {\n\n Ext.Ajax.request({\n url: '../plugins/accounts/ajax/get_new_crsf_token.php',\n success: function(response, opts) {\n var token = response.responseText;\n Ext.select('#account_form input[name=_glpi_csrf_token]')\n .set({'value': token});\n\n },\n failure: function(response, opts) {\n console.log('server-side failure with status code ' + response.status);\n }\n });\n\n var good_hash=\"{$hash}\";\n var hash=SHA256(SHA256(document.getElementById(\"aescrypted_key\").value));\n if (hash != good_hash) {\n alert(\"" . __('Wrong encryption key', 'accounts') . "\");\n return false;\n };\n alert(AESDecryptCtr(\"" . $data['encrypted_password'] . "\",\n SHA256(document.getElementById(\"aescrypted_key\").value),\n 256));\n\n callAjax(\"{$url}\",\n \"{$accountID}\" ,\n document.getElementsByName(\"name\").item(0).value,\n document.getElementsByName(\"_glpi_csrf_token\").item(0).value);\n\n });\n </script>"; } echo "</td>"; echo "<td class='center'>"; echo getUsername($data["users_id"]); echo "</td>"; echo "<td class='center'>"; echo Dropdown::getDropdownName("glpi_plugin_accounts_accounttypes", $data["plugin_accounts_accounttypes_id"]); echo "</td>"; echo "<td class='center'>" . Html::convdate($data["date_creation"]) . "</td>"; if ($data["date_expiration"] <= date('Y-m-d') && !empty($data["date_expiration"])) { echo "<td class='center'>"; echo "<div class='deleted'>" . Html::convdate($data["date_expiration"]) . "</div>"; echo "</td>"; } else { if (empty($data["date_expiration"])) { echo "<td class='center'>" . __('Don\'t expire', 'accounts') . "</td>"; } else { echo "<td class='center'>" . Html::convdate($data["date_expiration"]) . "</td>"; } } echo "</tr>"; $i++; } } echo "</table>"; if ($canedit && $number && $withtemplate < 2) { $massiveactionparams['ontop'] = false; Html::showMassiveActions(__CLASS__, $massiveactionparams); Html::closeForm(); } echo "</div>"; }
/** * 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') . " "; 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, '&') . "'>" . __('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 }
static 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; $device_type = static::getDeviceType(); $table_group = $table->createGroup($device_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'), $device_type::getTypeName(2), $item->getTypeName(1), $item->getName()); $device_type::getHTMLTableHeader($item->getType(), $table_group, $common_column, NULL, $options); $spec_column = NULL; $specificity_columns = array(); foreach (static::getSpecificities() as $field => $attributs) { $spec_column = $table_group->addHeader('spec_' . $field, $attributs['long name'], $specific_column, $spec_column); $specificity_columns[$field] = $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']) { $delete_one = $table_group->addHeader('one', ' ', $delete_column, $previous_column); } $fk = static::getDeviceForeignKey(); $query = "SELECT *\n FROM `" . static::getTable() . "`\n WHERE `itemtype` = '" . $item->getType() . "'\n AND `items_id` = '" . $item->getID() . "'\n AND `is_deleted` = '0'\n ORDER BY {$fk}"; $device = new $device_type(); $device->getEmpty(); foreach ($DB->request($query) as $link) { if ($link[$fk] != $device->getID()) { $device->getFromDB($link[$fk]); $current_row = $table_group->createRow(); $device_group = $device_type . '_' . $link[$fk] . '_' . mt_rand(); $current_row->setHTMLID($device_group); if ($options['canedit']) { $cell_value = Html::getCheckAllAsCheckbox($device_group); $current_row->addCell($delete_all_column, $cell_value); } $device->getHTMLTableCellForItem($current_row, $item, NULL, $options); } $spec_cell = NULL; foreach (static::getSpecificities() as $field => $attributs) { $content = $link[$field]; if ($options['canedit']) { $content = "<input type='text' name='value_" . $device_type . "_" . $link['id'] . "_" . $field . "' value='{$content}' size='" . $attributs['size'] . "'>"; } $spec_cell = $current_row->addCell($specificity_columns[$field], $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 = "<input type='checkbox' name='remove_" . $device_type . "_" . $link['id'] . "' value='1'>"; $current_row->addCell($delete_one, $cell_value, $previous_cell); } } }
/** * Show ports for an item * * @param $item CommonDBTM object * @param $withtemplate integer withtemplate param (default '') **/ static function showForItem(CommonDBTM $item, $withtemplate = '') { global $DB, $CFG_GLPI; $rand = mt_rand(); $itemtype = $item->getType(); $items_id = $item->getField('id'); if (!Session::haveRight('networking', 'r') || !$item->can($items_id, 'r')) { return false; } $netport = new self(); $netport->item = $item; if ($itemtype == 'NetworkPort') { $canedit = false; } else { $canedit = $item->can($items_id, 'w'); } $showmassiveactions = false; if ($withtemplate != 2) { $showmassiveactions = $canedit; } // Show Add Form if ($canedit && (empty($withtemplate) || $withtemplate != 2)) { echo "\n<form method='get' action='" . $netport->getFormURL() . "'>\n"; echo "<input type='hidden' name='items_id' value='" . $item->getID() . "'>\n"; echo "<input type='hidden' name='itemtype' value='" . $item->getType() . "'>\n"; echo "<div class='firstbloc'><table class='tab_cadre_fixe'>\n"; echo "<tr class='tab_bg_2'><td class='center'>\n"; _e('Network port type to be added'); echo " "; $instantiations = array(); foreach (self::getNetworkPortInstantiations() as $inst_type) { if (call_user_func(array($inst_type, 'canCreate'))) { $instantiations[$inst_type] = call_user_func(array($inst_type, 'getTypeName')); } } Dropdown::showFromArray('instantiation_type', $instantiations, array('value' => 'NetworkPortEthernet')); echo "</td>\n"; echo "<td class='tab_bg_2 center' width='50%'>"; _e('Add several ports'); echo " <input type='checkbox' name='several' value='1'></td>\n"; echo "<td>\n"; echo "<input type='submit' name='create' value=\"" . _sx('button', 'Add') . "\" class='submit'>\n"; echo "</td></tr></table></div>\n"; Html::closeForm(); } if ($showmassiveactions) { $checkbox_column = true; Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); } else { $checkbox_column = false; } $is_active_network_port = false; Session::initNavigateListItems('NetworkPort', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName())); if ($itemtype == 'NetworkPort') { $porttypes = array('NetworkPortAlias', 'NetworkPortAggregate'); } else { $porttypes = self::getNetworkPortInstantiations(); // Manage NetworkportMigration $porttypes[] = ''; } $display_options = self::getDisplayOptions($itemtype); $table = new HTMLTableMain(); $number_port = self::countForItem($item); $table_options = array('canedit' => $canedit, 'display_options' => &$display_options); // Make table name and add the correct show/hide parameters $table_name = sprintf(__('%1$s: %2$d'), self::getTypeName($number_port), $number_port); // Add the link to the popup to display the options ... $table_namelink = self::getDisplayOptionsLink($itemtype); $table_name = sprintf(__('%1$s - %2$s'), $table_name, $table_namelink); $table->setTitle($table_name); $c_main = $table->addHeader('main', self::getTypeName(2)); if ($display_options['dynamic_import'] && $item->isDynamic()) { $table_options['display_isDynamic'] = true; } else { $table_options['display_isDynamic'] = false; } if ($display_options['characteristics']) { $c_instant = $table->addHeader('Instantiation', __('Characteristics')); $c_instant->setHTMLClass('center'); } if ($display_options['internet']) { $options = array('names' => 'NetworkName', 'aliases' => 'NetworkAlias', 'ipaddresses' => 'IPAddress', 'ipnetworks' => 'IPNetwork'); $table_options['dont_display'] = array(); foreach ($options as $option => $itemtype_for_option) { if (!$display_options[$option]) { $table_options['dont_display'][$itemtype_for_option] = true; } } $c_network = $table->addHeader('Internet', _n(__('Internet information'), __('Internet information'), 2)); $c_network->setHTMLClass('center'); } else { $c_network = NULL; } foreach ($porttypes as $portType) { if (empty($portType)) { $group_name = 'Migration'; $group_title = __('Network ports waiting for manual migration'); } else { $group_name = $portType; $group_title = $portType::getTypeName(2); } $t_group = $table->createGroup($group_name, $group_title); if ($withtemplate != 2 && $canedit) { $c_checkbox = $t_group->addHeader('checkbox', Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand, '__RAND__'), $c_main); } else { $c_checkbox = NULL; } $c_number = $t_group->addHeader('NetworkPort', "#", $c_main); $c_name = $t_group->addHeader("Name", __('Name'), $c_main); $c_name->setItemType('NetworkPort'); $c_name->setHTMLClass('center'); if ($table_options['display_isDynamic']) { $c_dynamic = $t_group->addHeader("Dynamic", __('Automatic inventory'), $c_main); $c_dynamic->setHTMLClass('center'); } if ($display_options['characteristics']) { if (empty($portType)) { NetworkPortMigration::getMigrationInstantiationHTMLTableHeaders($t_group, $c_instant, $c_network, NULL, $table_options); } else { $instantiation = new $portType(); $instantiation->getInstantiationHTMLTableHeaders($t_group, $c_instant, $c_network, NULL, $table_options); unset($instantiation); } } if ($display_options['internet'] && !$display_options['characteristics']) { NetworkName::getHTMLTableHeader(__CLASS__, $t_group, $c_network, NULL, $table_options); } if ($itemtype == 'NetworkPort') { switch ($portType) { case 'NetworkPortAlias': $search_table = 'glpi_networkportaliases'; $search_request = "`networkports_id_alias`='{$items_id}'"; break; case 'NetworkPortAggregate': $search_table = 'glpi_networkportaggregates'; $search_request = "`networkports_id_list` like '%\"{$items_id}\"%'"; break; } $query = "SELECT `networkports_id` AS id\n FROM `{$search_table}`\n WHERE {$search_request}"; } else { $query = "SELECT `id`\n FROM `glpi_networkports`\n WHERE `items_id` = '{$items_id}'\n AND `itemtype` = '{$itemtype}'\n AND `instantiation_type` = '{$portType}'\n AND `is_deleted` = '0'\n ORDER BY `name`,\n `logical_number`"; } if ($result = $DB->query($query)) { echo "<div class='spaced'>"; $number_port = $DB->numrows($result); if ($number_port != 0) { $is_active_network_port = true; $save_canedit = $canedit; if (!empty($portType)) { $name = sprintf(__('%1$s (%2$s)'), self::getTypeName($number_port), call_user_func(array($portType, 'getTypeName'))); $name = sprintf(__('%1$s: %2$s'), $name, $number_port); } else { $name = __('Network ports waiting for manual migration'); $canedit = false; } while ($devid = $DB->fetch_row($result)) { $t_row = $t_group->createRow(); $netport->getFromDB(current($devid)); // No massive action for migration ports if ($withtemplate != 2 && $canedit && !empty($portType)) { $ce_checkbox = $t_row->addCell($c_checkbox, "<input type='checkbox' name='item[" . $netport->fields["id"] . "]' value='1'>"); } else { $ce_checkbox = NULL; } $content = "<span class='b'>"; // Display link based on default rights if ($save_canedit && $withtemplate != 2) { if (!empty($portType)) { $content .= "<a href=\"" . $CFG_GLPI["root_doc"] . "/front/networkport.form.php?id=" . $netport->fields["id"] . "\">"; } else { $content .= "<a href=\"" . $CFG_GLPI["root_doc"] . "/front/networkportmigration.form.php?id=" . $netport->fields["id"] . "\">"; } } $content .= $netport->fields["logical_number"]; if ($canedit && $withtemplate != 2) { $content .= "</a>"; } $content .= "</span>"; $content .= Html::showToolTip($netport->fields['comment'], array('display' => false)); $t_row->addCell($c_number, $content); $value = $netport->fields["name"]; $t_row->addCell($c_name, $value, NULL, $netport); if ($table_options['display_isDynamic']) { $t_row->addCell($c_dynamic, Dropdown::getYesNo($netport->fields['is_dynamic'])); } $instant_cell = NULL; if ($display_options['characteristics']) { $instantiation = $netport->getInstantiation(); if ($instantiation !== false) { $instantiation->getInstantiationHTMLTable($netport, $t_row, NULL, $table_options); unset($instantiation); } } else { if ($display_options['internet']) { NetworkName::getHTMLTableCellsForItem($t_row, $netport, NULL, $table_options); } } } $canedit = $save_canedit; } echo "</div>"; } } if ($is_active_network_port && $showmassiveactions) { $massiveactionparams = array('num_displayed' => $number_port, 'check_itemtype' => $itemtype, 'check_items_id' => $items_id); Html::showMassiveActions('NetworkPort', $massiveactionparams); } $table->display(array('display_thead' => false, 'display_tfoot' => false)); unset($table); if (!$is_active_network_port) { echo "<table class='tab_cadre_fixe'><tr><th>" . __('No network port found') . "</th></tr>"; echo "</table>"; } if ($showmassiveactions) { $massiveactionparams['ontop'] = false; Html::showMassiveActions('NetworkPort', $massiveactionparams); Html::closeForm(); } }
/** * Execute massive action for PluginFormcreatorFrom * * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { global $DB; switch ($ma->getAction()) { case 'Duplicate': foreach ($ids as $id) { if ($item->getFromDB($id) && $item->Duplicate()) { Session::addMessageAfterRedirect(sprintf(__('Form duplicated: %s', 'formcreator'), $item->getName())); $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { // Example of ko count $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); } } //return; break; //[CRI] //[CRI] case "Pedido": if ($item->getType() == 'Ticket') { // [CRI] $Plugin = new PluginFormcreatorForm(); $PluginItem = new PluginFormcreatorForm_Item(); $Target = new PluginFormcreatorTarget(); $helpdesk = new PluginFormcreatorTargetTicket(); $input = $ma->getInput(); foreach ($ids as $key) { $listForm = $PluginItem->find("items_id = " . $key . " and itemtype = '" . $item->getType() . "'"); if (empty($listForm)) { $input11 = array('plugin_formcreator_forms_id' => $input['plugin_formcreator_forms_id'], 'items_id' => $key, 'itemtype' => $item->getType()); $PluginItem->add($input11); } else { foreach ($listForm as $form_id => $value) { $input12 = array('id' => $form_id); $input12['plugin_formcreator_forms_id'] = $input['plugin_formcreator_forms_id']; $input12['items_id'] = $key; $input12['itemtype'] = $item->getType(); $PluginItem->update($input12); } } //Actualizar Ticket PluginFormcreatorForm::fromcreatorDropUserAndGrouponTicket($key); // PluginFormcreatorForm::updateTicketFromForm($input['plugin_formcreator_forms_id'], $key); $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK); } } break; //parent::processMassiveActionsForOneItemtype($ma, $item, $ids); } }
/** * Generate link * * @param $link string original string content * @param $item CommonDBTM object: item used to make replacements * * @return array of link contents (may have several when item have several IP / MAC cases) **/ static function generateLinkContents($link, CommonDBTM $item) { global $DB; if (strstr($link, "[ID]")) { $link = str_replace("[ID]", $item->fields['id'], $link); } if (strstr($link, "[LOGIN]") && isset($_SESSION["glpiname"])) { $link = str_replace("[LOGIN]", $_SESSION["glpiname"], $link); } if (strstr($link, "[NAME]")) { $link = str_replace("[NAME]", $item->getName(), $link); } if (strstr($link, "[SERIAL]") && $item->isField('serial')) { $link = str_replace("[SERIAL]", $item->getField('serial'), $link); } if (strstr($link, "[OTHERSERIAL]") && $item->isField('otherserial')) { $link = str_replace("[OTHERSERIAL]", $item->getField('otherserial'), $link); } if (strstr($link, "[LOCATIONID]") && $item->isField('locations_id')) { $link = str_replace("[LOCATIONID]", $item->getField('locations_id'), $link); } if (strstr($link, "[LOCATION]") && $item->isField('locations_id')) { $link = str_replace("[LOCATION]", Dropdown::getDropdownName("glpi_locations", $item->getField('locations_id')), $link); } if (strstr($link, "[NETWORK]") && $item->isField('networks_id')) { $link = str_replace("[NETWORK]", Dropdown::getDropdownName("glpi_networks", $item->getField('networks_id')), $link); } if (strstr($link, "[DOMAIN]") && $item->isField('domains_id')) { $link = str_replace("[DOMAIN]", Dropdown::getDropdownName("glpi_domains", $item->getField('domains_id')), $link); } if (strstr($link, "[USER]") && $item->isField('users_id')) { $link = str_replace("[USER]", Dropdown::getDropdownName("glpi_users", $item->getField('users_id')), $link); } if (strstr($link, "[GROUP]") && $item->isField('groups_id')) { $link = str_replace("[GROUP]", Dropdown::getDropdownName("glpi_groups", $item->getField('groups_id')), $link); } if (strstr($link, "[REALNAME]") && $item->isField('realname')) { $link = str_replace("[REALNAME]", $item->getField('realname'), $link); } if (strstr($link, "[FIRSTNAME]") && $item->isField('firstname')) { $link = str_replace("[FIRSTNAME]", $item->getField('firstname'), $link); } $replace_IP = strstr($link, "[IP]"); $replace_MAC = strstr($link, "[MAC]"); if (!$replace_IP && !$replace_MAC) { return array($link); } // Return several links id several IP / MAC $ipmac = array(); if (get_class($item) == 'NetworkEquipment') { if ($replace_IP) { $query2 = "SELECT `glpi_ipaddresses`.`id`,\n `glpi_ipaddresses`.`name` AS ip\n FROM `glpi_networknames`, `glpi_ipaddresses`\n WHERE `glpi_networknames`.`items_id` = '" . $item->getID() . "'\n AND `glpi_networknames`.`itemtype` = 'NetworkEquipment'\n AND `glpi_ipaddresses`.`itemtype` = 'NetworkName'\n AND `glpi_ipaddresses`.`items_id` = `glpi_networknames`.`id`"; foreach ($DB->request($query2) as $data2) { $ipmac['ip' . $data2['id']]['ip'] = $data2["ip"]; $ipmac['ip' . $data2['id']]['mac'] = $item->getField('mac'); } } if ($replace_MAC) { // If there is no entry, then, we must at least define the mac of the item ... if (count($ipmac) == 0) { $ipmac['mac0']['ip'] = ''; $ipmac['mac0']['mac'] = $item->getField('mac'); } } } if ($replace_IP) { $query2 = "SELECT `glpi_ipaddresses`.`id`,\n `glpi_networkports`.`mac`,\n `glpi_ipaddresses`.`name` AS ip\n FROM `glpi_networkports`, `glpi_networknames`, `glpi_ipaddresses`\n WHERE `glpi_networkports`.`items_id` = '" . $item->getID() . "'\n AND `glpi_networkports`.`itemtype` = '" . $item->getType() . "'\n AND `glpi_networknames`.`itemtype` = 'NetworkPort'\n AND `glpi_networknames`.`items_id` = `glpi_networkports`.`id`\n AND `glpi_ipaddresses`.`itemtype` = 'NetworkName'\n AND `glpi_ipaddresses`.`items_id` = `glpi_networknames`.`id`"; foreach ($DB->request($query2) as $data2) { $ipmac['ip' . $data2['id']]['ip'] = $data2["ip"]; $ipmac['ip' . $data2['id']]['mac'] = $data2["mac"]; } } if ($replace_MAC) { $left = ''; $where = ''; if ($replace_IP) { $left = " LEFT JOIN `glpi_networknames`\n ON (`glpi_networknames`.`items_id` = `glpi_networkports`.`id`\n AND `glpi_networknames`.`itemtype` = 'NetworkPort')"; $where = " AND `glpi_networknames`.`id` IS NULL"; } $query2 = "SELECT `glpi_networkports`.`id`,\n `glpi_networkports`.`mac`\n FROM `glpi_networkports`\n {$left}\n WHERE `glpi_networkports`.`items_id` = '" . $item->getID() . "'\n AND `glpi_networkports`.`itemtype` = '" . $item->getType() . "'\n {$where}\n GROUP BY `glpi_networkports`.`mac`"; foreach ($DB->request($query2) as $data2) { $ipmac['mac' . $data2['id']]['ip'] = ''; $ipmac['mac' . $data2['id']]['mac'] = $data2["mac"]; } } $links = array(); if (count($ipmac) > 0) { foreach ($ipmac as $key => $val) { $tmplink = $link; $disp = 1; if (strstr($link, "[IP]")) { if (empty($val['ip'])) { $disp = 0; } else { $tmplink = str_replace("[IP]", $val['ip'], $tmplink); } } if (strstr($link, "[MAC]")) { if (empty($val['mac'])) { $disp = 0; } else { $tmplink = str_replace("[MAC]", $val['mac'], $tmplink); } } if ($disp) { $links[$key] = $tmplink; } } } if (count($links)) { return $links; } return array($link); }
/** * Print an HTML array of contract associated to an object * * *@param $item CommonDBTM : object wanted *@param $withtemplate='' not used (to be deleted) * *@return Nothing (display) * **/ static function showAssociated(CommonDBTM $item, $withtemplate = '') { global $DB, $CFG_GLPI, $LANG; $itemtype = $item->getType(); $ID = $item->fields['id']; if (!haveRight("contract", "r") || !$item->can($ID, "r")) { return false; } $canedit = $item->can($ID, "w"); $query = "SELECT `glpi_contracts_items`.*\n FROM `glpi_contracts_items`,\n `glpi_contracts`\n LEFT JOIN `glpi_entities` ON (`glpi_contracts`.`entities_id`=`glpi_entities`.`id`)\n WHERE `glpi_contracts`.`id`=`glpi_contracts_items`.`contracts_id`\n AND `glpi_contracts_items`.`items_id` = '{$ID}'\n AND `glpi_contracts_items`.`itemtype` = '{$itemtype}'" . getEntitiesRestrictRequest(" AND", "glpi_contracts", '', '', true) . "\n ORDER BY `glpi_contracts`.`name`"; $result = $DB->query($query); $number = $DB->numrows($result); $i = 0; echo "<div class='spaced'>"; if ($withtemplate != 2) { echo "<form method='post' action=\"" . $CFG_GLPI["root_doc"] . "/front/contract.form.php\">"; } echo "<table class='tab_cadre_fixe'>"; echo "<tr><th colspan='8'>"; if ($number == 0) { echo $LANG['financial'][58]; } else { if ($number == 1) { echo $LANG['financial'][63]; } else { echo $LANG['financial'][66]; } } echo "</th></tr>"; echo "<tr><th>" . $LANG['common'][16] . "</th>"; echo "<th>" . $LANG['entity'][0] . "</th>"; echo "<th>" . $LANG['financial'][4] . "</th>"; echo "<th>" . $LANG['financial'][6] . "</th>"; echo "<th>" . $LANG['financial'][26] . "</th>"; echo "<th>" . $LANG['search'][8] . "</th>"; echo "<th>" . $LANG['financial'][8] . "</th>"; if ($withtemplate != 2) { echo "<th> </th>"; } echo "</tr>"; if ($number > 0) { initNavigateListItems('Contract', $item->getTypeName() . " = " . $item->getName()); } $contracts = array(); while ($i < $number) { $cID = $DB->result($result, $i, "contracts_id"); addToNavigateListItems('Contract', $cID); $contracts[] = $cID; $assocID = $DB->result($result, $i, "id"); $con = new Contract(); $con->getFromDB($cID); echo "<tr class='tab_bg_1" . ($con->fields["is_deleted"] ? "_2" : "") . "'>"; echo "<td class='center'>"; echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/contract.form.php?id={$cID}'>"; echo "<strong>" . $con->fields["name"]; if ($_SESSION["glpiis_ids_visible"] || empty($con->fields["name"])) { echo " (" . $con->fields["id"] . ")"; } echo "</strong></a></td>"; echo "<td class='center'>"; echo Dropdown::getDropdownName("glpi_entities", $con->fields["entities_id"]) . "</td>"; echo "<td class='center'>" . $con->fields["num"] . "</td>"; echo "<td class='center'>"; echo Dropdown::getDropdownName("glpi_contracttypes", $con->fields["contracttypes_id"]) . "</td>"; echo "<td class='center'>" . $con->getSuppliersNames() . "</td>"; echo "<td class='center'>" . convDate($con->fields["begin_date"]) . "</td>"; echo "<td class='center'>" . $con->fields["duration"] . " " . $LANG['financial'][57]; if ($con->fields["begin_date"] != '' && !empty($con->fields["begin_date"])) { echo " -> " . getWarrantyExpir($con->fields["begin_date"], $con->fields["duration"]); } echo "</td>"; if ($withtemplate != 2) { echo "<td class='tab_bg_2 center'>"; if ($canedit) { echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/contract.form.php?deleteitem=deleteitem&id={$assocID}&contracts_id={$cID}'>"; echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/delete2.png' alt='" . $LANG['buttons'][6] . "'></a>"; } else { echo " "; } echo "</td>"; } echo "</tr>"; $i++; } $q = "SELECT *\n FROM `glpi_contracts`\n WHERE `is_deleted` = '0' " . getEntitiesRestrictRequest("AND", "glpi_contracts", "entities_id", $item->getEntityID(), true); $result = $DB->query($q); $nb = $DB->numrows($result); if ($canedit) { if ($withtemplate != 2 && $nb > count($contracts)) { echo "<tr class='tab_bg_1'><td class='right' colspan='3'>"; echo "<input type='hidden' name='items_id' value='{$ID}'>"; echo "<input type='hidden' name='itemtype' value='{$itemtype}'>"; self::dropdown(array('entity' => $item->getEntityID(), 'used' => $contracts)); echo "</td><td class='center'>"; echo "<input type='submit' name='additem' value=\"" . $LANG['buttons'][8] . "\"\n class='submit'>"; echo "</td>"; echo "<td> </td><td> </td><td> </td><td> </td></tr>"; } } echo "</table>"; if ($withtemplate != 2) { echo "</form>"; } echo "</div>"; }