static function pdfMain(PluginPdfSimplePDF $pdf, KnowbaseItem $item) { global $DB; $ID = $item->getField('id'); if (!Session::haveRight('knowbase', 'r') || !Session::haveRight('faq', 'r')) { return false; } $knowbaseitemcategories_id = $item->getField('knowbaseitemcategories_id'); $fullcategoryname = Html::clean(getTreeValueCompleteName("glpi_knowbaseitemcategories", $knowbaseitemcategories_id)); $question = Html::clean(Toolbox::unclean_cross_side_scripting_deep(html_entity_decode($item->getField('name'), ENT_QUOTES, "UTF-8"))); $answer = Html::clean(Toolbox::unclean_cross_side_scripting_deep(html_entity_decode($item->getField('answer'), ENT_QUOTES, "UTF-8"))); $pdf->setColumnsSize(100); if (Toolbox::strlen($fullcategoryname) > 0) { $pdf->displayTitle('<b>' . __('Category name') . '</b>'); $pdf->displayLine($fullcategoryname); } if (Toolbox::strlen($question) > 0) { $pdf->displayTitle('<b>' . __('Subject') . '</b>'); $pdf->displayText('', $question, 5); } else { $pdf->displayTitle('<b>' . __('No question found', 'pdf') . '</b>'); } if (Toolbox::strlen($answer) > 0) { $pdf->displayTitle('<b>' . __('Content') . '</b>'); $pdf->displayText('', $answer, 5); } else { $pdf->displayTitle('<b>' . __('No answer found') . '</b>'); } $pdf->setColumnsSize(50, 15, 15, 10, 10); $pdf->displayTitle(__('Writer'), __('Creation date'), __('Last update'), __('FAQ'), _n('View', 'Views', 2)); $pdf->displayLine(getUserName($item->fields["users_id"]), Html::convDateTime($item->fields["date"]), Html::convDateTime($item->fields["date_mod"]), Dropdown::getYesNo($item->fields["is_faq"]), $item->fields["view"]); $pdf->displaySpace(); }
/** * @see NotificationTarget::getDatasForTemplate() **/ function getDatasForTemplate($event, $options = array()) { global $CFG_GLPI; $events = $this->getAllEvents(); $this->datas['##recall.action##'] = $events[$event]; $this->datas['##recall.itemtype##'] = $this->target_object->getTypeName(1); $this->datas['##recall.item.URL##'] = ''; // For task show parent link if ($this->target_object instanceof CommonDBChild || $this->target_object instanceof CommonITILTask) { $item2 = $this->target_object->getItem(); $this->datas['##recall.item.url##'] = urldecode($CFG_GLPI["url_base"] . "/index.php" . "?redirect=" . strtolower($item2->getType()) . "_" . $item2->getID()); } else { $this->datas['##recall.item.url##'] = urldecode($CFG_GLPI["url_base"] . "/index.php" . "?redirect=" . strtolower($this->target_object->getType()) . "_" . $this->target_object->getID()); } $this->datas['##recall.item.name##'] = ''; if ($this->target_object->isField('name')) { $this->datas['##recall.item.name##'] = $this->target_object->getField('name'); } else { if (($item2 = $this->target_object->getItem()) && $item2->isField('name')) { $this->datas['##recall.item.name##'] = $item2->getField('name'); } } $this->datas['##recall.item.content##'] = ''; if ($this->target_object->isField('content')) { $this->datas['##recall.item.content##'] = $this->target_object->getField('content'); } if ($this->target_object->isField('text')) { $this->datas['##recall.item.content##'] = $this->target_object->getField('text'); } $this->datas['##recall.item.private##'] = ''; if ($this->target_object->isField('is_private')) { $this->datas['##recall.item.private##'] = Dropdown::getYesNo($this->target_object->getField('is_private')); } $this->datas['##recall.item.date_mod##'] = ''; if ($this->target_object->isField('date_mod')) { $this->datas['##recall.item.date_mod##'] = Html::convDateTime($this->target_object->getField('date_mod')); } $this->datas['##recall.item.user##'] = ''; $user_tmp = new User(); if ($user_tmp->getFromDB($this->target_object->getField('users_id'))) { $this->datas['##recall.item.user##'] = $user_tmp->getName(); } $this->datas['##recall.planning.state##'] = ''; if ($this->target_object->isField('state')) { $this->datas['##recall.planning.state##'] = Planning::getState($this->target_object->getField('state')); } $this->datas['##recall.planning.begin##'] = Html::convDateTime($this->target_object->getField('begin')); $this->datas['##recall.planning.end##'] = Html::convDateTime($this->target_object->getField('end')); $this->getTags(); foreach ($this->tag_descriptions[NotificationTarget::TAG_LANGUAGE] as $tag => $values) { if (!isset($this->datas[$tag])) { $this->datas[$tag] = $values['label']; } } }
function showTestResults($rule, $output, $global_result) { global $LANG; $actions = $rule->getActions(); echo "<tr><th colspan='4'>" . $LANG['rulesengine'][81] . "</th></tr>"; echo "<tr class='tab_bg_2'>"; echo "<td class='center' colspan='4'>" . $LANG['rulesengine'][41] . " : <strong> " . Dropdown::getYesNo($global_result) . "</strong></td>"; if (isset($output["_ldap_rules"]["rules_entities"])) { echo "<tr class='tab_bg_2'>"; echo "<td class='center' colspan='4'>" . $LANG['rulesengine'][111] . "</td>"; foreach ($output["_ldap_rules"]["rules_entities"] as $entities) { foreach ($entities as $entity) { $this->displayActionByName("entity", $entity[0]); if (isset($entity[1])) { $this->displayActionByName("recursive", $entity[1]); } } } } if (isset($output["_ldap_rules"]["rules_rights"])) { echo "<tr class='tab_bg_2'>"; echo "<td colspan='4' class='center'>" . $LANG['rulesengine'][110] . "</td>"; foreach ($output["_ldap_rules"]["rules_rights"] as $val) { $this->displayActionByName("profile", $val[0]); } } if (isset($output["_ldap_rules"]["rules_entities_rights"])) { echo "<tr class='tab_bg_2'>"; echo "<td colspan='4' class='center'>" . $LANG['rulesengine'][112] . "</td>"; foreach ($output["_ldap_rules"]["rules_entities_rights"] as $val) { $this->displayActionByName("entity", $val[0]); if (isset($val[1])) { $this->displayActionByName("profile", $val[1]); } if (isset($val[2])) { $this->displayActionByName("is_recursive", $val[2]); } } } if (isset($output["_ldap_rules"])) { unset($output["_ldap_rules"]); } foreach ($output as $criteria => $value) { if (isset($actions[$criteria])) { // ignore _* fields echo "<tr class='tab_bg_2'>"; echo "<td class='center'>" . $actions[$criteria]["name"] . "</td>"; echo "<td class='center'>" . $rule->getActionValue($criteria, $value) . "</td></tr>\n"; } } echo "</tr>"; }
/** * return the display data for a specific device * * @return array **/ function getFormData() { global $LANG; $data['label'] = $data['value'] = array(); if ($this->fields["is_atx"]) { $data['label'][] = $LANG['device_power'][1]; $data['value'][] = Dropdown::getYesNo($this->fields["is_atx"]); } if (!empty($this->fields["power"])) { $data['label'][] = $LANG['device_power'][0]; $data['value'][] = $this->fields["power"]; } return $data; }
static function pdfMain(PluginPdfSimplePDF $pdf, Group $item) { $ID = $item->getField('id'); $pdf->setColumnsSize(50, 50); $pdf->displayTitle('<b>' . sprintf(__('%1$s %2$s'), __('ID'), $item->fields['id']) . '</b>', sprintf(__('%1$s: %2$s'), __('Last update'), Html::convDateTime($item->fields['date_mod']))); $pdf->setColumnsSize(100); $pdf->displayLine('<b><i>' . sprintf(__('%1$s: %2$s'), __('Complete name') . '</i></b>', $item->fields['completename'])); $pdf->setColumnsSize(50, 50); $pdf->displayLine('<b><i>' . sprintf(__('%1$s: %2$s'), __('Child entities') . '</i></b>', Dropdown::getYesNo($item->fields['is_recursive'])), '<b><i>' . sprintf(__('%1$s: %2$s'), __('Can be notified') . '</i></b>', Dropdown::getYesNo($item->fields['is_notify']))); $pdf->displayLine('<b><i>' . sprintf(__('%1$s: %2$s'), sprintf(__('%1$s - %2$s'), __('Visible in a ticket'), __('Requester')) . '</i></b>', Dropdown::getYesNo($item->fields['is_requester'])), '<b><i>' . sprintf(__('%1$s: %2$s'), sprintf(__('%1$s - %2$s'), _('Visible in a ticket'), __('Assigned to')) . '</i></b>', Dropdown::getYesNo($item->fields['is_assign']))); $pdf->displayLine('<b><i>' . sprintf(__('%1$s: %2$s'), sprintf(__('%1$s - %2$s'), __('Can contain'), _n('Item', 'Items', 2)) . '</i></b>', Dropdown::getYesNo($item->fields['is_itemgroup'])), '<b><i>' . sprintf(__('%1$s: %2$s'), sprintf(__('%1$s - %2$s'), __('Can contain'), _n('User', 'Users', 2)) . '</i></b>', Dropdown::getYesNo($item->fields['is_usergroup']))); PluginPdfCommon::mainLine($pdf, $item, 'comment'); $pdf->displaySpace(); }
/** * return the display data for a specific device * * @return array **/ function getFormData() { global $LANG; $data['label'] = $data['value'] = array(); if ($this->fields["is_raid"]) { $data['label'][] = $LANG['device_control'][0]; $data['value'][] = Dropdown::getYesNo($this->fields["is_raid"]); } if ($this->fields["interfacetypes_id"]) { $data['label'][] = $LANG['common'][65]; $data['value'][] = Dropdown::getDropdownName("glpi_interfacetypes", $this->fields["interfacetypes_id"]); } return $data; }
function showCacheRuleDetail($fields) { global $LANG; echo "<td class='tab_bg_2'>" . $fields["old_value"] . "</td>"; echo "<td class='tab_bg_2'>" . $fields["manufacturer"] . "</td>"; echo "<td class='tab_bg_2'>" . ($fields["new_value"] != '' ? $fields["new_value"] : $LANG['rulesengine'][106]) . "</td>"; echo "<td class='tab_bg_2'>" . ($fields["is_global"] != '' ? Dropdown::getGlobalSwitch($fields["is_global"]) : $LANG['rulesengine'][106]) . "</td>"; echo "<td class='tab_bg_2'>" . (isset($fields["new_manufacturer"]) && $fields["new_manufacturer"] != '' ? Dropdown::getDropdownName("glpi_manufacturers", $fields["new_manufacturer"]) : $LANG['rulesengine'][106]) . "</td>"; echo "<td class='tab_bg_2'>"; if ($fields["ignore_ocs_import"] == '') { echo " "; } else { echo Dropdown::getYesNo($fields["ignore_ocs_import"]); } echo "</td>"; }
/** * @since version 0.84 * * @see CommonDevice::getHTMLTableCellForItem() **/ function getHTMLTableCellForItem(HTMLTableRow $row = NULL, CommonDBTM $item = NULL, HTMLTableCell $father = NULL, array $options = array()) { $column = parent::getHTMLTableCellForItem($row, $item, $father, $options); if ($column == $father) { return $father; } switch ($item->getType()) { case 'Computer': Manufacturer::getHTMLTableCellsForItem($row, $this, NULL, $options); if ($this->fields["assettag"]) { $row->addCell($row->getHeaderByName('devicebiosdata_tag'), Dropdown::getYesNo($this->fields["assettag"]), $father); } if ($this->fields["date"]) { $row->addCell($row->getHeaderByName('devicebiosdata_date'), $this->fields["date"], $father); } } }
static function pdfForGroup(PluginPdfSimplePDF $pdf, Group $group, $tree) { global $DB, $CFG_GLPI; $used = array(); $ids = array(); // Retrieve member list $entityrestrict = Group_User::getDataForGroup($group, $used, $ids, '', $tree); $title = "<b>" . sprintf(__('%1$s (%2$s)'), _n('User', 'Users', 2) . "</b>", __('D=Dynamic')); $number = count($used); if ($number > $_SESSION['glpilist_limit']) { $title = sprintf(__('%1$s (%2$s)'), $title, $_SESSION['glpilist_limit'] . "/" . $number); } else { $title = sprintf(__('%1$s (%2$s)'), $title, $number); } $pdf->setColumnsSize(100); $pdf->displayTitle($title); if ($number) { $user = new User(); $group = new Group(); if ($tree) { $pdf->setColumnsSize(35, 45, 10, 10); $pdf->displayTitle(User::getTypeName(1), Group::getTypeName(1), __('Manager'), __('Delegatee')); } else { $pdf->setColumnsSize(60, 20, 20); $pdf->displayTitle(User::getTypeName(1), __('Manager'), __('Delegatee')); } for ($i = 0; $i < $number && $i < $_SESSION['glpilist_limit']; $i++) { $data = $used[$i]; $name = Html::clean(getUserName($data["id"])); if ($data["is_dynamic"]) { $name = sprintf(__('%1$s (%2$s)'), $name, '<b>' . __('D') . '</b>'); } if ($tree) { $group->getFromDB($data["groups_id"]); $pdf->displayLine($name, $group->getName(), Dropdown::getYesNo($data['is_manager']), Dropdown::getYesNo($data['is_userdelegate'])); } else { $pdf->displayLine($name, Dropdown::getYesNo($data['is_manager']), Dropdown::getYesNo($data['is_userdelegate'])); } } } else { $pdf->setColumnsAlign('center'); $pdf->displayLine(__('No item found')); } $pdf->displaySpace(); }
/** * return the display data for a specific device * * @return array **/ function getFormData() { global $LANG; $data['label'] = $data['value'] = array(); if ($this->fields["is_writer"]) { $data['label'][] = $LANG['device_drive'][0]; $data['value'][] = Dropdown::getYesNo($this->fields["is_writer"]); } if (!empty($this->fields["speed"])) { $data['label'][] = $LANG['device_drive'][1]; $data['value'][] = $this->fields["speed"]; } if ($this->fields["interfacetypes_id"]) { $data['label'][] = $LANG['common'][65]; $data['value'][] = Dropdown::getDropdownName("glpi_interfacetypes", $this->fields["interfacetypes_id"]); } return $data; }
static function pdfMain(PluginPdfSimplePDF $pdf, Phone $item) { PluginPdfCommon::mainTitle($pdf, $item); PluginPdfCommon::mainLine($pdf, $item, 'name-status'); PluginPdfCommon::mainLine($pdf, $item, 'location-type'); PluginPdfCommon::mainLine($pdf, $item, 'tech-manufacturer'); PluginPdfCommon::mainLine($pdf, $item, 'group-model'); PluginPdfCommon::mainLine($pdf, $item, 'contactnum-serial'); PluginPdfCommon::mainLine($pdf, $item, 'contact-otherserial'); PluginPdfCommon::mainLine($pdf, $item, 'user-management'); $pdf->displayLine('<b><i>' . sprintf(__('%1$s: %2$s'), __('Group') . '</i></b>', Html::clean(Dropdown::getDropdownName('glpi_groups', $item->fields['groups_id']))), '<b><i>' . sprintf(__('%1$s: %2$s'), __('Power supply') . '</i></b>', Dropdown::getYesNo($item->fields['phonepowersupplies_id']))); $pdf->displayLine('<b><i>' . sprintf(__('%1$s: %2$s'), __('Brand') . '</i></b>', $item->fields['brand']), '<b><i>' . sprintf(__('%1$s: %2$s'), _x('quantity', 'Number of lines') . '</i></b>', $item->fields['number_line'])); $pdf->displayLine('<b><i>' . sprintf(__('%1$s: %2$s'), _n('Firmware', 'Firmwares', 1) . '</i></b>', $item->fields['firmware'])); $opts = array('have_headset' => __('Headset'), 'have_hp' => __('Speaker')); foreach ($opts as $key => $val) { if (!$item->fields[$key]) { unset($opts[$key]); } } $pdf->setColumnsSize(100); $pdf->displayLine('<b><i>' . sprintf(__('%1$s: %2$s'), __('Flags') . '</i></b>', count($opts) ? implode(', ', $opts) : __('None'))); PluginPdfCommon::mainLine($pdf, $item, 'comment'); $pdf->displaySpace(); }
/** * Show test results for a rule * * @param $rule rule object * @param $output Output data array * @param $global_result boolean : global result * * @return cleaned array **/ function showTestResults($rule, $output, $global_result) { global $LANG; $actions = $rule->getActions(); echo "<table class='tab_cadrehov'>"; echo "<tr><th colspan='2'>" . $LANG['rulesengine'][81] . "</th></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td colspan='2' class='center'>" . $LANG['rulesengine'][41] . " : <strong> " . Dropdown::getYesNo($global_result) . "</strong></td>"; $output = $this->preProcessPreviewResults($output); foreach ($output as $criteria => $value) { if (isset($actions[$criteria])) { echo "<tr class='tab_bg_2'>"; echo "<td>" . $actions[$criteria]["name"] . "</td>"; echo "<td>" . $rule->getActionValue($criteria, $value) . "</td>"; echo "</tr>\n"; } } echo "</tr></table>\n"; }
/** * @since version 0.84 * * @see CommonDevice::getHTMLTableCellForItem() **/ function getHTMLTableCellForItem(HTMLTableRow $row = NULL, CommonDBTM $item = NULL, HTMLTableCell $father = NULL, array $options = array()) { $column = parent::getHTMLTableCellForItem($row, $item, $father, $options); if ($column == $father) { return $father; } switch ($item->getType()) { case 'Computer': Manufacturer::getHTMLTableCellsForItem($row, $this, NULL, $options); if ($this->fields["is_writer"]) { $row->addCell($row->getHeaderByName('devicedrive_writer'), Dropdown::getYesNo($this->fields["is_writer"]), $father); } if ($this->fields["speed"]) { $row->addCell($row->getHeaderByName('devicedrive_speed'), $this->fields["speed"], $father); } InterfaceType::getHTMLTableCellsForItem($row, $this, NULL, $options); } }
/** * Print the rssfeed form * * @param $ID integer Id of the item to print * @param $options array of possible options: * - target filename : where to go when done. **/ function showForm($ID, $options = array()) { global $CFG_GLPI; // Test _rss cache directory. I permission trouble : unable to edit if (Toolbox::testWriteAccessToDirectory(GLPI_RSS_DIR) > 0) { echo "<div class='center'>"; printf(__('Check permissions to the directory: %s'), GLPI_RSS_DIR); echo "<p class='red b'>" . __('Error') . "</p>"; echo "</div>"; return false; } $this->initForm($ID, $options); $canedit = $this->can($ID, UPDATE); $this->showFormHeader($options); $rowspan = 4; if (!$this->isNewID($ID)) { // Force getting feed : $feed = self::getRSSFeed($this->fields['url'], $this->fields['refresh_rate']); if (!$feed || $feed->error()) { $this->setError(true); } else { $this->setError(false); } echo "<tr class='tab_bg_2'>"; echo "<td>" . __('Name') . "</td>"; echo "<td>"; Html::autocompletionTextField($this, "name", array('entity' => -1, 'user' => $this->fields["users_id"])); echo "</td><td colspan ='2'> </td></tr>\n"; } echo "<tr class='tab_bg_1'><td>" . __('URL') . "</td>"; echo "<td colspan='3'>"; echo "<input type='text' name='url' size='100' value='" . $this->fields["url"] . "'>"; echo "</td></tr>"; echo "<tr class='tab_bg_2'>"; echo "<td>" . __('By') . "</td>"; echo "<td>"; echo getUserName($this->fields["users_id"]); echo "<input type='hidden' name='users_id' value='" . $this->fields['users_id'] . "'>\n"; echo "</td>"; echo "<td rowspan='{$rowspan}'>" . __('Comments') . "</td>"; echo "<td rowspan='{$rowspan}' class='middle'>"; echo "<textarea cols='45' rows='" . ($rowspan + 3) . "' name='comment' >" . $this->fields["comment"] . "</textarea>"; echo "</td></tr>\n"; echo "<tr class='tab_bg_2'>"; echo "<td>" . __('Active') . "</td>"; echo "<td>"; Dropdown::showYesNo('is_active', $this->fields['is_active']); echo "</td></tr>\n"; echo "<tr class='tab_bg_2'>"; echo "<td>" . __('Refresh rate') . "</td>"; echo "<td>"; Dropdown::showTimeStamp("refresh_rate", array('value' => $this->fields["refresh_rate"], 'min' => HOUR_TIMESTAMP, 'max' => DAY_TIMESTAMP, 'step' => HOUR_TIMESTAMP, 'display_emptychoice' => false, 'toadd' => array(5 * MINUTE_TIMESTAMP, 15 * MINUTE_TIMESTAMP, 30 * MINUTE_TIMESTAMP, 45 * MINUTE_TIMESTAMP))); echo "</td></tr>\n"; echo "<tr class='tab_bg_2'>"; echo "<td>" . __('Number of items displayed') . "</td>"; echo "<td>"; Dropdown::showNumber("max_items", array('value' => $this->fields["max_items"], 'min' => 5, 'max' => 100, 'step' => 5, 'toadd' => array(1), 'display_emptychoice' => false)); echo "</td></tr>\n"; echo "<tr class='tab_bg_2'>"; echo "<td>" . __('Error retrieving RSS feed') . "</td>"; echo "<td>"; echo Dropdown::getYesNo($this->fields['have_error']); echo "</td>"; if ($this->fields['have_error']) { echo "<td>" . __('RSS feeds found'); echo "</td><td>"; $this->showDiscoveredFeeds(); echo "</td>\n"; } else { echo "<td colspan='2'> </td>"; } echo "</tr>"; $this->showFormButtons($options); return true; }
/** * show tooltip for user notification informations * * @param $type integer : user type * @param $canedit boolean : can edit ? * * @return nothing display **/ function showUsersAssociated($type, $canedit) { global $CFG_GLPI, $LANG; $showuserlink = 0; if (haveRight('user', 'r')) { $showuserlink = 2; } $usericon = self::getActorIcon('user', $type); $user = new User(); if (isset($this->users[$type]) && count($this->users[$type])) { foreach ($this->users[$type] as $k => $d) { $save_showuserlink = $showuserlink; echo "{$usericon} "; if ($k) { $userdata = getUserName($k, $showuserlink); } else { $email = $d['alternative_email']; $userdata = "<a href='mailto:{$email}'>{$email}</a>"; $showuserlink = false; } if ($showuserlink) { echo $userdata['name'] . " " . showToolTip($userdata["comment"], array('link' => $userdata["link"], 'display' => false)); } else { echo $userdata; } if ($CFG_GLPI['use_mailing']) { $text = $LANG['job'][19] . " : " . Dropdown::getYesNo($d['use_notification']) . '<br>'; if ($d['use_notification']) { $uemail = $d['alternative_email']; if (empty($uemail) && $user->getFromDB($d['users_id'])) { $uemail = $user->getField('email'); } $text .= $LANG['mailing'][118] . " : " . $uemail; if (!NotificationMail::isUserAddressValid($uemail)) { $text .= "<span class='red'>" . $LANG['mailing'][110] . "</span>"; } } echo " "; if ($canedit || $d['users_id'] == getLoginUserID()) { $opt = array('img' => $CFG_GLPI['root_doc'] . '/pics/edit.png', 'popup' => 'edit_user_notification&id=' . $d['id']); showToolTip($text, $opt); } } if ($canedit) { echo " <a href='" . $CFG_GLPI["root_doc"] . "/front/ticket.form.php?delete_user=delete_user&id=" . $d['id'] . "&tickets_id=" . $this->fields['id'] . "' title=\"" . $LANG['buttons'][6] . "\">\n <img src='" . $CFG_GLPI["root_doc"] . "/pics/delete.png'\n alt=\"" . $LANG['buttons'][6] . "\" title=\"" . $LANG['buttons'][6] . "\"></a>"; } echo "<br>"; $showuserlink = $save_showuserlink; } } }
/** * Display action using its name * * @param $name action name * @param $value default value **/ function displayActionByName($name, $value) { echo "<tr class='tab_bg_2'>"; switch ($name) { case "entity": echo "<td class='center'>" . __('Entity') . " </td>\n"; echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $value) . "</td>"; break; case "profile": echo "<td class='center'>" . _n('Profile', 'Profiles', Session::getPluralNumber()) . " </td>\n"; echo "<td class='center'>" . Dropdown::getDropdownName("glpi_profiles", $value) . "</td>"; break; case "is_recursive": echo "<td class='center'>" . __('Recursive') . " </td>\n"; echo "<td class='center'>" . Dropdown::getYesNo($value) . "</td>"; break; } echo "</tr>"; }
/** * @param $ticket Tichet object * @param $rand * @param $showprivate **/ function showInTicketSumnary(Ticket $ticket, $rand, $showprivate) { global $DB, $CFG_GLPI; $canedit = $this->canEdit($this->fields['id']); echo "<tr class='tab_bg_" . ($this->fields['is_private'] == 1 ? "4" : "2") . "' " . ($canedit ? "style='cursor:pointer' onClick=\"viewEditFollowup" . $ticket->fields['id'] . $this->fields['id'] . "{$rand}();\"" : '') . " id='viewfollowup" . $this->fields['tickets_id'] . $this->fields["id"] . "{$rand}'>"; $name = $this->getTypeName(); if ($this->fields['requesttypes_id']) { $name = sprintf(__('%1$s - %2$s'), $name, Dropdown::getDropdownName('glpi_requesttypes', $this->fields['requesttypes_id'])); } echo "<td>" . $name . "</td>"; echo "<td>"; if ($canedit) { echo "\n<script type='text/javascript' >\n"; echo "function viewEditFollowup" . $ticket->fields['id'] . $this->fields["id"] . "{$rand}() {\n"; $params = array('type' => __CLASS__, 'parenttype' => 'Ticket', 'tickets_id' => $this->fields["tickets_id"], 'id' => $this->fields["id"]); Ajax::updateItemJsCode("viewfollowup" . $ticket->fields['id'] . "{$rand}", $CFG_GLPI["root_doc"] . "/ajax/viewsubitem.php", $params); echo "};"; echo "</script>\n"; } echo Html::convDateTime($this->fields["date"]) . "</td>"; echo "<td class='left'>" . nl2br($this->fields["content"]) . "</td>"; echo "<td>" . getUserName($this->fields["users_id"]) . "</td>"; if ($showprivate) { echo "<td>" . Dropdown::getYesNo($this->fields["is_private"]) . "</td>"; } echo "</tr>\n"; }
/** * show tooltip for user notification information * * @param $type integer user type * @param $canedit boolean can edit ? * @param $options array options for default values ($options of showForm) * * @return nothing display **/ function showUsersAssociated($type, $canedit, array $options = array()) { global $CFG_GLPI; $showuserlink = 0; if (User::canView()) { $showuserlink = 2; } $usericon = self::getActorIcon('user', $type); $user = new User(); $linkuser = new $this->userlinkclass(); $itemtype = $this->getType(); $typename = self::getActorFieldNameType($type); $candelete = true; $mandatory = ''; // For ticket templates : mandatories if ($itemtype == 'Ticket' && isset($options['_tickettemplate'])) { $mandatory = $options['_tickettemplate']->getMandatoryMark("_users_id_" . $typename); if ($options['_tickettemplate']->isMandatoryField("_users_id_" . $typename) && isset($this->users[$type]) && count($this->users[$type]) == 1) { $candelete = false; } } if (isset($this->users[$type]) && count($this->users[$type])) { foreach ($this->users[$type] as $d) { $k = $d['users_id']; echo "{$mandatory}{$usericon} "; if ($k) { $userdata = getUserName($k, 2); } else { $email = $d['alternative_email']; $userdata = "<a href='mailto:{$email}'>{$email}</a>"; } if ($k) { $param = array('display' => false); if ($showuserlink) { $param['link'] = $userdata["link"]; } echo $userdata['name'] . " " . Html::showToolTip($userdata["comment"], $param); } else { echo $userdata; } if ($CFG_GLPI['use_mailing']) { $text = __('Email followup') . " " . Dropdown::getYesNo($d['use_notification']) . '<br>'; if ($d['use_notification']) { $uemail = $d['alternative_email']; if (empty($uemail) && $user->getFromDB($d['users_id'])) { $uemail = $user->getDefaultEmail(); } $text .= sprintf(__('%1$s: %2$s'), __('Email'), $uemail); if (!NotificationMail::isUserAddressValid($uemail)) { $text .= " <span class='red'>" . __('Invalid email address') . "</span>"; } } echo " "; if ($canedit || $d['users_id'] == Session::getLoginUserID()) { $opt = array('img' => $CFG_GLPI['root_doc'] . '/pics/edit.png', 'popup' => $linkuser->getFormURL() . "?id=" . $d['id']); Html::showToolTip($text, $opt); } } if ($canedit && $candelete) { echo " "; Html::showSimpleForm($linkuser->getFormURL(), 'delete', _x('button', 'Delete permanently'), array('id' => $d['id']), $CFG_GLPI["root_doc"] . "/pics/delete.png"); } echo "<br>"; } } }
} echo "<th>" . $LANG['common'][15] . "</th>"; echo "<th>" . $LANG['financial'][14] . "</th>"; echo "<th>" . $LANG['financial'][80] . "</th>"; echo "<th>" . $LANG['financial'][6] . "</th>"; echo "<th>" . $LANG['search'][8] . "</th>"; echo "<th>" . $LANG['search'][9] . "</th>"; echo "</tr>"; while ($data = $DB->fetch_array($result)) { echo "<tr class='tab_bg_1'>"; if ($data['itemname']) { echo "<td> " . $data['itemname'] . " </td>"; } else { echo "<td> " . NOT_AVAILABLE . " </td>"; } echo "<td> " . Dropdown::getYesNo($data['itemdeleted']) . " </td>"; if ($display_entity) { if ($data['entID'] == 0) { echo "<td>" . $LANG['entity'][2] . "</td>"; } else { echo "<td>" . $data['entname'] . "</td>"; } } if ($data['location']) { echo "<td> " . $data['location'] . " </td>"; } else { echo "<td> " . NOT_AVAILABLE . " </td>"; } if ($data['buy_date']) { echo "<td> " . convDate($data['buy_date']) . " </td>"; if ($data["warranty_duration"]) {
/** * 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); } } }
/** * Generic Function to display Items * * @param $itemtype item type * @param $ID ID of the SEARCH_OPTION item * @param $data array containing data results * @param $num item num in the request * @param $meta is a meta item ? (default 0) * @param $addobjectparams array added parameters for union search * * @return string to print **/ static function giveItem($itemtype, $ID, array $data, $num, $meta = 0, array $addobjectparams = array()) { global $CFG_GLPI, $DB; $searchopt =& self::getOptions($itemtype); if (isset($CFG_GLPI["union_search_type"][$itemtype]) && $CFG_GLPI["union_search_type"][$itemtype] == $searchopt[$ID]["table"]) { if (isset($searchopt[$ID]['addobjectparams']) && $searchopt[$ID]['addobjectparams']) { return self::giveItem($data["TYPE"], $ID, $data, $num, $meta, $searchopt[$ID]['addobjectparams']); } return self::giveItem($data["TYPE"], $ID, $data, $num, $meta); } if (count($addobjectparams)) { $searchopt[$ID] = array_merge($searchopt[$ID], $addobjectparams); } // Plugin can override core definition for its type if ($plug = isPluginItemType($itemtype)) { $function = 'plugin_' . $plug['plugin'] . '_giveItem'; if (function_exists($function)) { $out = $function($itemtype, $ID, $data, $num); if (!empty($out)) { return $out; } } } $NAME = "ITEM_"; // if ($meta) { // $NAME = "META_"; // } if (isset($searchopt[$ID]["table"])) { $table = $searchopt[$ID]["table"]; $field = $searchopt[$ID]["field"]; $linkfield = $searchopt[$ID]["linkfield"]; /// TODO try to clean all specific cases using SpecificToDisplay switch ($table . '.' . $field) { case "glpi_users.name": // USER search case if ($itemtype != 'User' && isset($searchopt[$ID]["forcegroupby"]) && $searchopt[$ID]["forcegroupby"]) { $out = ""; $count_display = 0; $added = array(); $showuserlink = 0; if (Session::haveRight('user', READ)) { $showuserlink = 1; } for ($k = 0; $k < $data[$num]['count']; $k++) { if (isset($data[$num][$k]['name']) && $data[$num][$k]['name'] > 0 || isset($data[$num][$k][2]) && $data[$num][$k][2] != '') { if ($count_display) { $out .= self::LBBR; } if ($itemtype == 'Ticket') { if (isset($data[$num][$k]['name']) && $data[$num][$k]['name'] > 0) { $userdata = getUserName($data[$num][$k]['name'], 2); $tooltip = ""; if (Session::haveRight('user', READ)) { $tooltip = Html::showToolTip($userdata["comment"], array('link' => $userdata["link"], 'display' => false)); } $out .= sprintf(__('%1$s %2$s'), $userdata['name'], $tooltip); $count_display++; } } else { $out .= getUserName($data[$num][$k]['name'], $showuserlink); $count_display++; } // Manage alternative_email for tickets_users if ($itemtype == 'Ticket' && isset($data[$num][$k][2])) { $split = explode(self::LONGSEP, $data[$num][$k][2]); for ($l = 0; $l < count($split); $l++) { $split2 = explode(" ", $split[$l]); if (count($split2) == 2 && $split2[0] == 0 && !empty($split2[1])) { if ($count_display) { $out .= self::LBBR; } $count_display++; $out .= "<a href='mailto:" . $split2[1] . "'>" . $split2[1] . "</a>"; } } } } } return $out; } if ($itemtype != 'User') { $toadd = ''; if ($itemtype == 'Ticket' && $data[$num][0]['id'] > 0) { $userdata = getUserName($data[$num][0]['id'], 2); $toadd = Html::showToolTip($userdata["comment"], array('link' => $userdata["link"], 'display' => false)); } $usernameformat = formatUserName($data[$num][0]['id'], $data[$num][0]['name'], $data[$num][0]['realname'], $data[$num][0]['firstname'], 1); return sprintf(__('%1$s %2$s'), $usernameformat, $toadd); } break; case "glpi_profiles.name": if ($itemtype == 'User' && $ID == 20) { $out = ""; $count_display = 0; $added = array(); for ($k = 0; $k < $data[$num]['count']; $k++) { if (strlen(trim($data[$num][$k]['name'])) > 0) { $text = sprintf(__('%1$s - %2$s'), $data[$num][$k]['name'], Dropdown::getDropdownName('glpi_entities', $data[$num][$k]['entities_id'])); $comp = ''; if ($data[$num][$k]['is_recursive']) { $comp = __('R'); if ($data[$num][$k]['is_dynamic']) { $comp = sprintf(__('%1$s%2$s'), $comp, ", "); } } if ($data[$num][$k]['is_dynamic']) { $comp = sprintf(__('%1$s%2$s'), $comp, __('D')); } if (!empty($comp)) { $text = sprintf(__('%1$s %2$s'), $text, "(" . $comp . ")"); } if (!in_array($text, $added)) { if ($count_display) { $out .= self::LBBR; } $count_display++; $out .= $text; $added[] = $text; } } } return $out; } break; case "glpi_entities.completename": if ($itemtype == 'User') { $out = ""; $added = array(); $count_display = 0; for ($k = 0; $k < $data[$num]['count']; $k++) { if (strlen(trim($data[$num][$k]['name'])) > 0) { $text = sprintf(__('%1$s - %2$s'), $data[$num][$k]['name'], Dropdown::getDropdownName('glpi_profiles', $data[$num][$k]['profiles_id'])); $comp = ''; if ($data[$num][$k]['is_recursive']) { $comp = __('R'); if ($data[$num][$k]['is_dynamic']) { $comp = sprintf(__('%1$s%2$s'), $comp, ", "); } } if ($data[$num][$k]['is_dynamic']) { $comp = sprintf(__('%1$s%2$s'), $comp, __('D')); } if (!empty($comp)) { $text = sprintf(__('%1$s %2$s'), $text, "(" . $comp . ")"); } if (!in_array($text, $added)) { if ($count_display) { $out .= self::LBBR; } $count_display++; $out .= $text; $added[] = $text; } } } return $out; } break; case "glpi_documenttypes.icon": if (!empty($data[$num][0]['name'])) { return "<img class='middle' alt='' src='" . $CFG_GLPI["typedoc_icon_dir"] . "/" . $data[$num][0]['name'] . "'>"; } return " "; case "glpi_documents.filename": $doc = new Document(); if ($doc->getFromDB($data['id'])) { return $doc->getDownloadLink(); } return NOT_AVAILABLE; case "glpi_tickets_tickets.tickets_id_1": $out = ""; $displayed = array(); for ($k = 0; $k < $data[$num]['count']; $k++) { $linkid = $data[$num][$k]['tickets_id_2'] == $data['id'] ? $data[$num][$k]['name'] : $data[$num][$k]['tickets_id_2']; if ($linkid > 0 && !isset($displayed[$linkid])) { $text = "<a "; $text .= "href=\"" . $CFG_GLPI["root_doc"] . "/front/ticket.form.php?id={$linkid}\">"; $text .= Dropdown::getDropdownName('glpi_tickets', $linkid) . "</a>"; if (count($displayed)) { $out .= self::LBBR; } $displayed[$linkid] = $linkid; $out .= $text; } } return $out; case "glpi_problems.id": if ($searchopt[$ID]["datatype"] == 'count') { if ($data[$num][0]['name'] > 0 && Session::haveRight("problem", Problem::READALL)) { if ($itemtype == 'ITILCategory') { $options['criteria'][0]['field'] = 7; $options['criteria'][0]['searchtype'] = 'equals'; $options['criteria'][0]['value'] = $data['id']; $options['criteria'][0]['link'] = 'AND'; } else { $options['criteria'][0]['field'] = 12; $options['criteria'][0]['searchtype'] = 'equals'; $options['criteria'][0]['value'] = 'all'; $options['criteria'][0]['link'] = 'AND'; $options['metacriteria'][0]['itemtype'] = $itemtype; $options['metacriteria'][0]['field'] = self::getOptionNumber($itemtype, 'name'); $options['metacriteria'][0]['searchtype'] = 'equals'; $options['metacriteria'][0]['value'] = $data['id']; $options['metacriteria'][0]['link'] = 'AND'; } $options['reset'] = 'reset'; $out = "<a id='problem{$itemtype}" . $data['id'] . "' "; $out .= "href=\"" . $CFG_GLPI["root_doc"] . "/front/problem.php?" . Toolbox::append_params($options, '&') . "\">"; $out .= $data[$num][0]['name'] . "</a>"; return $out; } } break; case "glpi_tickets.id": if ($searchopt[$ID]["datatype"] == 'count') { if ($data[$num][0]['name'] > 0 && Session::haveRight("ticket", Ticket::READALL)) { if ($itemtype == 'User') { // Requester if ($ID == 60) { $options['criteria'][0]['field'] = 4; $options['criteria'][0]['searchtype'] = 'equals'; $options['criteria'][0]['value'] = $data['id']; $options['criteria'][0]['link'] = 'AND'; } // Writer if ($ID == 61) { $options['criteria'][0]['field'] = 22; $options['criteria'][0]['searchtype'] = 'equals'; $options['criteria'][0]['value'] = $data['id']; $options['criteria'][0]['link'] = 'AND'; } // Assign if ($ID == 64) { $options['criteria'][0]['field'] = 5; $options['criteria'][0]['searchtype'] = 'equals'; $options['criteria'][0]['value'] = $data['id']; $options['criteria'][0]['link'] = 'AND'; } } else { if ($itemtype == 'ITILCategory') { $options['criteria'][0]['field'] = 7; $options['criteria'][0]['searchtype'] = 'equals'; $options['criteria'][0]['value'] = $data['id']; $options['criteria'][0]['link'] = 'AND'; } else { $options['criteria'][0]['field'] = 12; $options['criteria'][0]['searchtype'] = 'equals'; $options['criteria'][0]['value'] = 'all'; $options['criteria'][0]['link'] = 'AND'; $options['metacriteria'][0]['itemtype'] = $itemtype; $options['metacriteria'][0]['field'] = self::getOptionNumber($itemtype, 'name'); $options['metacriteria'][0]['searchtype'] = 'equals'; $options['metacriteria'][0]['value'] = $data['id']; $options['metacriteria'][0]['link'] = 'AND'; } } $options['reset'] = 'reset'; $out = "<a id='ticket{$itemtype}" . $data['id'] . "' "; $out .= "href=\"" . $CFG_GLPI["root_doc"] . "/front/ticket.php?" . Toolbox::append_params($options, '&') . "\">"; $out .= $data[$num][0]['name'] . "</a>"; return $out; } } break; case "glpi_tickets.due_date": case "glpi_problems.due_date": case "glpi_changes.due_date": // Due date + progress if ($ID == 151) { $out = Html::convDate($data[$num][0]['name']); // No due date in waiting status if ($data[$num][0]['status'] == CommonITILObject::WAITING) { return ''; } if (empty($data[$num][0]['name'])) { return ''; } if ($data[$num][0]['status'] == Ticket::SOLVED || $data[$num][0]['status'] == Ticket::CLOSED) { return $out; } $itemtype = getItemTypeForTable($table); $item = new $itemtype(); $item->getFromDB($data['id']); $percentage = 0; $totaltime = 0; $currenttime = 0; if ($item->isField('slas_id') && $item->fields['slas_id'] != 0) { // Have SLA $sla = new SLA(); $sla->getFromDB($item->fields['slas_id']); $currenttime = $sla->getActiveTimeBetween($item->fields['date'], date('Y-m-d H:i:s')); $totaltime = $sla->getActiveTimeBetween($item->fields['date'], $data[$num][0]['name']); } else { $calendars_id = Entity::getUsedConfig('calendars_id', $item->fields['entities_id']); if ($calendars_id != 0) { // Ticket entity have calendar $calendar = new Calendar(); $calendar->getFromDB($calendars_id); $currenttime = $calendar->getActiveTimeBetween($item->fields['date'], date('Y-m-d H:i:s')); $totaltime = $calendar->getActiveTimeBetween($item->fields['date'], $data[$num][0]['name']); } else { // No calendar $currenttime = strtotime(date('Y-m-d H:i:s')) - strtotime($item->fields['date']); $totaltime = strtotime($data[$num][0]['name']) - strtotime($item->fields['date']); } } if ($totaltime != 0) { $percentage = round(100 * $currenttime / $totaltime); } else { // Total time is null : no active time $percentage = 100; } if ($percentage > 100) { $percentage = 100; } $percentage_text = $percentage; if ($_SESSION['glpiduedatewarning_unit'] == '%') { $less_warn_limit = $_SESSION['glpiduedatewarning_less']; $less_warn = 100 - $percentage; } else { if ($_SESSION['glpiduedatewarning_unit'] == 'hour') { $less_warn_limit = $_SESSION['glpiduedatewarning_less'] * HOUR_TIMESTAMP; $less_warn = $totaltime - $currenttime; } else { if ($_SESSION['glpiduedatewarning_unit'] == 'day') { $less_warn_limit = $_SESSION['glpiduedatewarning_less'] * DAY_TIMESTAMP; $less_warn = $totaltime - $currenttime; } } } if ($_SESSION['glpiduedatecritical_unit'] == '%') { $less_crit_limit = $_SESSION['glpiduedatecritical_less']; $less_crit = 100 - $percentage; } else { if ($_SESSION['glpiduedatecritical_unit'] == 'hour') { $less_crit_limit = $_SESSION['glpiduedatecritical_less'] * HOUR_TIMESTAMP; $less_crit = $totaltime - $currenttime; } else { if ($_SESSION['glpiduedatecritical_unit'] == 'day') { $less_crit_limit = $_SESSION['glpiduedatecritical_less'] * DAY_TIMESTAMP; $less_crit = $totaltime - $currenttime; } } } $color = $_SESSION['glpiduedateok_color']; if ($less_crit < $less_crit_limit) { $color = $_SESSION['glpiduedatecritical_color']; } else { if ($less_warn < $less_warn_limit) { $color = $_SESSION['glpiduedatewarning_color']; } } //Calculate bar progress $out .= "<div class='center' style='background-color: #ffffff; width: 100%;\n border: 1px solid #9BA563; position: relative;' >"; $out .= "<div style='position:absolute;'> " . $percentage_text . "%</div>"; $out .= "<div class='center' style='background-color: " . $color . ";\n width: " . $percentage . "%; height: 12px' ></div>"; $out .= "</div>"; return $out; } break; case "glpi_softwarelicenses.number": if ($data[$num][0]['min'] == -1) { return __('Unlimited'); } if (empty($data[$num][0]['name'])) { return 0; } return $data[$num][0]['name']; case "glpi_auth_tables.name": return Auth::getMethodName($data[$num][0]['name'], $data[$num][0]['auths_id'], 1, $data[$num][0]['ldapname'] . $data[$num][0]['mailname']); case "glpi_reservationitems.comment": if (empty($data[$num][0]['name'])) { return "<a title=\"" . __s('Modify the comment') . "\"\n href='" . $CFG_GLPI["root_doc"] . "/front/reservationitem.form.php?id=" . $data["refID"] . "' >" . __('None') . "</a>"; } return "<a title=\"" . __s('Modify the comment') . "\"\n href='" . $CFG_GLPI["root_doc"] . "/front/reservationitem.form.php?id=" . $data['refID'] . "' >" . Html::resume_text($data[$num][0]['name']) . "</a>"; case 'glpi_crontasks.description': $tmp = new CronTask(); return $tmp->getDescription($data[$num][0]['name']); case 'glpi_changes.status': $status = Change::getStatus($data[$num][0]['name']); return "<img src=\"" . Change::getStatusIconURL($data[$num][0]['name']) . "\"\n alt=\"{$status}\" title=\"{$status}\"> {$status}"; case 'glpi_problems.status': $status = Problem::getStatus($data[$num][0]['name']); return "<img src=\"" . Problem::getStatusIconURL($data[$num][0]['name']) . "\"\n alt=\"{$status}\" title=\"{$status}\"> {$status}"; case 'glpi_tickets.status': $status = Ticket::getStatus($data[$num][0]['name']); return "<img src=\"" . Ticket::getStatusIconURL($data[$num][0]['name']) . "\"\n alt=\"{$status}\" title=\"{$status}\"> {$status}"; case 'glpi_projectstates.name': $out = ''; $query = "SELECT `color`\n FROM `glpi_projectstates`\n WHERE `name` = '" . $data[$num][0]['name'] . "'"; foreach ($DB->request($query) as $color) { $color = $color['color']; $out = "<div style=\"background-color:" . $color . ";\">"; $name = $data[$num][0]['name']; if (isset($data[$num][0]['trans'])) { $name = $data[$num][0]['trans']; } if ($itemtype == 'ProjectState') { $out .= "<a href='" . $CFG_GLPI["root_doc"] . "/front/projectstate.form.php?id=" . $data[$num][0]["id"] . "'>" . $name . "</a></div>"; } else { $out .= $name . "</div>"; } } return $out; case 'glpi_items_tickets.items_id': case 'glpi_items_problems.items_id': if (!empty($data[$num])) { $items = array(); foreach ($data[$num] as $key => $val) { if (is_numeric($key)) { if (!empty($val['itemtype']) && ($item = getItemForItemtype($val['itemtype']))) { if ($item->getFromDB($val['name'])) { $items[] = $item->getLink(array('comments' => true)); } } } } if (!empty($items)) { return implode("<br>", $items); } } return ' '; case 'glpi_items_tickets.itemtype': case 'glpi_items_problems.itemtype': if (!empty($data[$num])) { $itemtypes = array(); foreach ($data[$num] as $key => $val) { if (is_numeric($key)) { if (!empty($val['name'])) { if (substr($val['name'], 0, 6) == 'Plugin') { $plug = new $val['name'](); $name = $plug->getTypeName(); $itemtypes[] = __($name); } else { $itemtypes[] = __($val['name']); } } } } if (!empty($itemtypes)) { return implode("<br>", $itemtypes); } } return ' '; case 'glpi_tickets.name': case 'glpi_problems.name': case 'glpi_changes.name': if (isset($data[$num][0]['content']) && isset($data[$num][0]['id']) && isset($data[$num][0]['status'])) { $link = Toolbox::getItemTypeFormURL($itemtype); $out = "<a id='{$itemtype}" . $data[$num][0]['id'] . "' href=\"" . $link; $out .= strstr($link, '?') ? '&' : '?'; $out .= 'id=' . $data[$num][0]['id']; // Force solution tab if solved if ($item = getItemForItemtype($itemtype)) { if (in_array($data[$num][0]['status'], $item->getSolvedStatusArray())) { $out .= "&forcetab={$itemtype}\$2"; } } $out .= "\">"; $name = $data[$num][0]['name']; if ($_SESSION["glpiis_ids_visible"] || empty($data[$num][0]['name'])) { $name = sprintf(__('%1$s (%2$s)'), $name, $data[$num][0]['id']); } $out .= $name . "</a>"; $hdecode = Html::entity_decode_deep($data[$num][0]['content']); $content = Toolbox::unclean_cross_side_scripting_deep($hdecode); $out = sprintf(__('%1$s %2$s'), $out, Html::showToolTip(nl2br(Html::Clean($content)), array('applyto' => $itemtype . $data[$num][0]['id'], 'display' => false))); return $out; } case 'glpi_ticketvalidations.status': $out = ''; for ($k = 0; $k < $data[$num]['count']; $k++) { if ($data[$num][$k]['name']) { $status = TicketValidation::getStatus($data[$num][$k]['name']); $bgcolor = TicketValidation::getStatusColor($data[$num][$k]['name']); $out .= (empty($out) ? '' : self::LBBR) . "<div style=\"background-color:" . $bgcolor . ";\">" . $status . '</div>'; } } return $out; case 'glpi_ticketsatisfactions.satisfaction': if (self::$output_type == self::HTML_OUTPUT) { return TicketSatisfaction::displaySatisfaction($data[$num][0]['name']); } break; case 'glpi_projects._virtual_planned_duration': return Html::timestampToString(ProjectTask::getTotalPlannedDurationForProject($data["id"]), false); case 'glpi_projects._virtual_effective_duration': return Html::timestampToString(ProjectTask::getTotalEffectiveDurationForProject($data["id"]), false); case 'glpi_cartridgeitems._virtual': return Cartridge::getCount($data["id"], $data[$num][0]['alarm_threshold'], self::$output_type != self::HTML_OUTPUT); case 'glpi_printers._virtual': return Cartridge::getCountForPrinter($data["id"], self::$output_type != self::HTML_OUTPUT); case 'glpi_consumableitems._virtual': return Consumable::getCount($data["id"], $data[$num][0]['alarm_threshold'], self::$output_type != self::HTML_OUTPUT); case 'glpi_links._virtual': $out = ''; $link = new Link(); if (($item = getItemForItemtype($itemtype)) && $item->getFromDB($data['id']) && $link->getfromDB($data[$num][0]['id']) && $item->fields['entities_id'] == $link->fields['entities_id']) { if (count($data[$num])) { $count_display = 0; foreach ($data[$num] as $val) { if (is_array($val)) { $links = Link::getAllLinksFor($item, $val); foreach ($links as $link) { if ($count_display) { $out .= self::LBBR; } $out .= $link; $count_display++; } } } } } return $out; case 'glpi_reservationitems._virtual': if ($data[$num][0]['is_active']) { return "<a href='reservation.php?reservationitems_id=" . $data["refID"] . "' title=\"" . __s('See planning') . "\">" . "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/reservation-3.png\" alt='' title=''></a>"; } else { return " "; } } } //// Default case // Link with plugin tables : need to know left join structure if (isset($table)) { if (preg_match("/^glpi_plugin_([a-z0-9]+)/", $table . '.' . $field, $matches)) { if (count($matches) == 2) { $plug = $matches[1]; $function = 'plugin_' . $plug . '_giveItem'; if (function_exists($function)) { $out = $function($itemtype, $ID, $data, $num); if (!empty($out)) { return $out; } } } } } $unit = ''; if (isset($searchopt[$ID]['unit'])) { $unit = $searchopt[$ID]['unit']; } // Preformat items if (isset($searchopt[$ID]["datatype"])) { switch ($searchopt[$ID]["datatype"]) { case "itemlink": $linkitemtype = getItemTypeForTable($searchopt[$ID]["table"]); $out = ""; $count_display = 0; $separate = self::LBBR; if (isset($searchopt[$ID]['splititems']) && $searchopt[$ID]['splititems']) { $separate = self::LBHR; } for ($k = 0; $k < $data[$num]['count']; $k++) { if (isset($data[$num][$k]['id'])) { if ($count_display) { $out .= $separate; } $count_display++; $page = $linkitemtype::getFormUrl(); $page .= strpos($page, '?') ? '&id' : '?id'; $name = Dropdown::getValueWithUnit($data[$num][$k]['name'], $unit); if ($_SESSION["glpiis_ids_visible"] || empty($data[$num][$k]['name'])) { $name = sprintf(__('%1$s (%2$s)'), $name, $data[$num][$k]['id']); } $out .= "<a id='" . $linkitemtype . "_" . $data['id'] . "_" . $data[$num][$k]['id'] . "' href='{$page}=" . $data[$num][$k]['id'] . "'>" . $name . "</a>"; } } return $out; case "text": $separate = self::LBBR; if (isset($searchopt[$ID]['splititems']) && $searchopt[$ID]['splititems']) { $separate = self::LBHR; } $out = ''; $count_display = 0; for ($k = 0; $k < $data[$num]['count']; $k++) { if (strlen(trim($data[$num][$k]['name'])) > 0) { if ($count_display) { $out .= $separate; } $count_display++; $text = ""; if (isset($searchopt[$ID]['htmltext']) && $searchopt[$ID]['htmltext']) { $text = Html::clean(Toolbox::unclean_cross_side_scripting_deep(nl2br($data[$num][$k]['name']))); } else { $text = nl2br($data[$num][$k]['name']); } if (self::$output_type == self::HTML_OUTPUT && Toolbox::strlen($text) > $CFG_GLPI['cut']) { $rand = mt_rand(); $out .= sprintf(__('%1$s %2$s'), "<span id='text{$rand}'>" . Html::resume_text($text, $CFG_GLPI['cut']) . '</span>', Html::showToolTip($text, array('applyto' => "text{$rand}", 'display' => false))); } else { $out .= $text; } } } return $out; case "date": case "date_delay": $out = ''; for ($k = 0; $k < $data[$num]['count']; $k++) { if (is_null($data[$num][$k]['name']) && isset($searchopt[$ID]['emptylabel']) && $searchopt[$ID]['emptylabel']) { $out .= (empty($out) ? '' : self::LBBR) . $searchopt[$ID]['emptylabel']; } else { $out .= (empty($out) ? '' : self::LBBR) . Html::convDate($data[$num][$k]['name']); } } return $out; case "datetime": $out = ''; for ($k = 0; $k < $data[$num]['count']; $k++) { if (is_null($data[$num][$k]['name']) && isset($searchopt[$ID]['emptylabel']) && $searchopt[$ID]['emptylabel']) { $out .= (empty($out) ? '' : self::LBBR) . $searchopt[$ID]['emptylabel']; } else { $out .= (empty($out) ? '' : self::LBBR) . Html::convDateTime($data[$num][$k]['name']); } } return $out; case "timestamp": $withseconds = false; if (isset($searchopt[$ID]['withseconds'])) { $withseconds = $searchopt[$ID]['withseconds']; } $withdays = true; if (isset($searchopt[$ID]['withdays'])) { $withdays = $searchopt[$ID]['withdays']; } $out = ''; for ($k = 0; $k < $data[$num]['count']; $k++) { $out .= (empty($out) ? '' : '<br>') . Html::timestampToString($data[$num][$k]['name'], $withseconds, $withdays); } return $out; case "email": $out = ''; $count_display = 0; for ($k = 0; $k < $data[$num]['count']; $k++) { if ($count_display) { $out .= self::LBBR; } $count_display++; if (!empty($data[$num][$k]['name'])) { $out .= empty($out) ? '' : self::LBBR; $out .= "<a href='mailto:" . $data[$num][$k]['name'] . "'>" . $data[$num][$k]['name']; $out .= "</a>"; } } return empty($out) ? " " : $out; case "weblink": $orig_link = trim($data[$num][0]['name']); if (!empty($orig_link)) { // strip begin of link $link = preg_replace('/https?:\\/\\/(www[^\\.]*\\.)?/', '', $orig_link); $link = preg_replace('/\\/$/', '', $link); if (Toolbox::strlen($link) > $CFG_GLPI["url_maxlength"]) { $link = Toolbox::substr($link, 0, $CFG_GLPI["url_maxlength"]) . "..."; } return "<a href=\"" . formatOutputWebLink($orig_link) . "\" target='_blank'>{$link}</a>"; } return " "; case "count": case "number": $out = ""; $count_display = 0; for ($k = 0; $k < $data[$num]['count']; $k++) { if (strlen(trim($data[$num][$k]['name'])) > 0) { if ($count_display) { $out .= self::LBBR; } $count_display++; if (isset($searchopt[$ID]['toadd']) && isset($searchopt[$ID]['toadd'][$data[$num][$k]['name']])) { $out .= $searchopt[$ID]['toadd'][$data[$num][$k]['name']]; } else { $number = str_replace(' ', ' ', Html::formatNumber($data[$num][$k]['name'], false, 0)); $out .= Dropdown::getValueWithUnit($number, $unit); } } } return $out; case "decimal": $out = ""; $count_display = 0; for ($k = 0; $k < $data[$num]['count']; $k++) { if (strlen(trim($data[$num][$k]['name'])) > 0) { if ($count_display) { $out .= self::LBBR; } $count_display++; if (isset($searchopt[$ID]['toadd']) && isset($searchopt[$ID]['toadd'][$data[$num][$k]['name']])) { $out .= $searchopt[$ID]['toadd'][$data[$num][$k]['name']]; } else { $number = str_replace(' ', ' ', Html::formatNumber($data[$num][$k]['name'])); $out .= Dropdown::getValueWithUnit($number, $unit); } } } return $out; case "bool": $out = ""; $count_display = 0; for ($k = 0; $k < $data[$num]['count']; $k++) { if (strlen(trim($data[$num][$k]['name'])) > 0) { if ($count_display) { $out .= self::LBBR; } $count_display++; $out .= Dropdown::getValueWithUnit(Dropdown::getYesNo($data[$num][$k]['name']), $unit); } } return $out; case "itemtypename": if ($obj = getItemForItemtype($data[$num][0]['name'])) { return $obj->getTypeName(); } return ""; case "language": if (isset($CFG_GLPI['languages'][$data[$num][0]['name']])) { return $CFG_GLPI['languages'][$data[$num][0]['name']][0]; } return __('Default value'); } } // Manage items with need group by / group_concat $out = ""; $count_display = 0; $separate = self::LBBR; if (isset($searchopt[$ID]['splititems']) && $searchopt[$ID]['splititems']) { $separate = self::LBHR; } for ($k = 0; $k < $data[$num]['count']; $k++) { if (strlen(trim($data[$num][$k]['name'])) > 0) { if ($count_display) { $out .= $separate; } $count_display++; // Get specific display if available $itemtype = getItemTypeForTable($table); if ($item = getItemForItemtype($itemtype)) { $tmpdata = $data[$num][$k]; // Copy name to real field $tmpdata[$field] = $data[$num][$k]['name']; $specific = $item->getSpecificValueToDisplay($field, $tmpdata, array('html' => true, 'searchopt' => $searchopt[$ID])); } if (!empty($specific)) { $out .= $specific; } else { if (isset($searchopt[$ID]['toadd']) && isset($searchopt[$ID]['toadd'][$data[$num][$k]['name']])) { $out .= $searchopt[$ID]['toadd'][$data[$num][$k]['name']]; } else { // Empty is 0 or empty if (empty($split[0]) && isset($searchopt[$ID]['emptylabel'])) { $out .= $searchopt[$ID]['emptylabel']; } else { // Trans field exists if (isset($data[$num][$k]['trans']) && !empty($data[$num][$k]['trans'])) { $out .= Dropdown::getValueWithUnit($data[$num][$k]['trans'], $unit); } else { $out .= Dropdown::getValueWithUnit($data[$num][$k]['name'], $unit); } } } } } } return $out; // Trans in group concat if (count($split) == 3 && !empty($split[1])) { return Dropdown::getValueWithUnit($split[1], $unit); } return Dropdown::getValueWithUnit($split[0], $unit); }
/** * Print the config form for default user prefs * * @param $data array containing datas * (CFG_GLPI for global config / glpi_users fields for user prefs) * * @return Nothing (display) **/ function showFormUserPrefs($data = array()) { global $DB, $CFG_GLPI; $oncentral = $_SESSION["glpiactiveprofile"]["interface"] == "central"; $userpref = false; $url = Toolbox::getItemTypeFormURL(__CLASS__); if (array_key_exists('last_login', $data)) { $userpref = true; if ($data["id"] === Session::getLoginUserID()) { $url = $CFG_GLPI['root_doc'] . "/front/preference.php"; } else { $url = $CFG_GLPI['root_doc'] . "/front/user.form.php"; } } echo "<form name='form' action='{$url}' method='post'>"; // Only set id for user prefs if ($userpref) { echo "<input type='hidden' name='id' value='" . $data['id'] . "'>"; } echo "<div class='center' id='tabsbody'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr><th colspan='4'>" . __('Personalization') . "</th></tr>"; echo "<tr class='tab_bg_2'>"; echo "<td width='30%'>" . ($userpref ? __('Language') : __('Default language')) . "</td>"; echo "<td width='20%'>"; if (Config::canUpdate() || !GLPI_DEMO_MODE) { Dropdown::showLanguages("language", array('value' => $data["language"])); } else { echo " "; } echo "<td width='30%'>" . __('Date format') . "</td>"; echo "<td width='20%'>"; $date_formats = array(0 => __('YYYY-MM-DD'), 1 => __('DD-MM-YYYY'), 2 => __('MM-DD-YYYY')); Dropdown::showFromArray('date_format', $date_formats, array('value' => $data["date_format"])); echo "</td></tr>"; echo "<tr class='tab_bg_2'>"; echo "<td>" . __('Results to display by page') . "</td><td>"; // Limit using global config $value = $data['list_limit'] < $CFG_GLPI['list_limit_max'] ? $data['list_limit'] : $CFG_GLPI['list_limit_max']; Dropdown::showNumber('list_limit', array('value' => $value, 'min' => 5, 'max' => $CFG_GLPI['list_limit_max'], 'step' => 5)); echo "</td>"; echo "<td>" . __('Number format') . "</td>"; $values = array(0 => '1 234.56', 1 => '1,234.56', 2 => '1 234,56', 3 => '1234.56', 4 => '1234,56'); echo "<td>"; Dropdown::showFromArray('number_format', $values, array('value' => $data["number_format"])); echo "</td></tr>"; echo "<tr class='tab_bg_2'>"; echo "<td>" . __('Display order of surnames firstnames') . "</td><td>"; $values = array(User::REALNAME_BEFORE => __('Surname, First name'), User::FIRSTNAME_BEFORE => __('First name, Surname')); Dropdown::showFromArray('names_format', $values, array('value' => $data["names_format"])); echo "</td>"; echo "<td>" . __("Color palette") . "</td><td>"; $themes_files = scandir(GLPI_ROOT . "/css/palettes/"); echo "<select name='palette' id='theme-selector'>"; foreach ($themes_files as $key => $file) { if (strpos($file, ".css") !== false) { $name = substr($file, 0, -4); $selected = ""; if ($data["palette"] == $name) { $selected = "selected='selected'"; } echo "<option value='{$name}' {$selected}>" . ucfirst($name) . "</option>"; } } echo Html::scriptBlock("\n function formatThemes(theme) {\n return \" <img src='../css/palettes/previews/\" + theme.text.toLowerCase() + \".png'/>\"\n + \" \" + theme.text;\n }\n \$(\"#theme-selector\").select2({\n formatResult: formatThemes,\n formatSelection: formatThemes,\n width: '100%',\n escapeMarkup: function(m) { return m; }\n });\n "); echo "</select>"; echo "</td></tr>"; echo "<tr class='tab_bg_2'>"; if ($oncentral) { echo "<td>" . __('Display the complete name in tree dropdowns') . "</td><td>"; Dropdown::showYesNo('use_flat_dropdowntree', $data["use_flat_dropdowntree"]); echo "</td>"; } else { echo "<td colspan='2'> </td>"; } if (!$userpref || $CFG_GLPI['show_count_on_tabs'] != -1) { echo "<td>" . __('Display counts in tabs') . "</td><td>"; $values = array(0 => __('No'), 1 => __('Yes')); if (!$userpref) { $values[-1] = __('Never'); } Dropdown::showFromArray('show_count_on_tabs', $values, array('value' => $data["show_count_on_tabs"])); echo "</td>"; } else { echo "<td colspan='2'> </td>"; } echo "</tr>"; echo "<tr class='tab_bg_2'>"; if ($oncentral) { echo "<td>" . __('Show GLPI ID') . "</td><td>"; Dropdown::showYesNo("is_ids_visible", $data["is_ids_visible"]); echo "</td>"; } else { echo "<td colspan='2'></td>"; } echo "<td>" . __('CSV delimiter') . "</td><td>"; $values = array(';' => ';', ',' => ','); Dropdown::showFromArray('csv_delimiter', $values, array('value' => $data["csv_delimiter"])); echo "</td></tr>"; echo "<tr class='tab_bg_2'>"; echo "<td>" . __('Notifications for my changes') . "</td><td>"; Dropdown::showYesNo("notification_to_myself", $data["notification_to_myself"]); echo "</td>"; if ($oncentral) { echo "<td>" . __('Results to display on home page') . "</td><td>"; Dropdown::showNumber('display_count_on_home', array('value' => $data['display_count_on_home'], 'min' => 0, 'max' => 30)); echo "</td>"; } else { echo "<td colspan='2'> </td>"; } echo "</tr>"; echo "<tr class='tab_bg_2'>"; echo "<td>" . __('PDF export font') . "</td><td>"; Dropdown::showFromArray("pdffont", GLPIPDF::getFontList(), array('value' => $data["pdffont"], 'width' => 200)); echo "</td>"; echo "<td>" . __('Keep devices when purging an item') . "</td><td>"; Dropdown::showYesNo('keep_devices_when_purging_item', $data['keep_devices_when_purging_item']); echo "</td></tr>"; echo "<tr class='tab_bg_2'><td>" . __('Go to created item after creation') . "</td>"; echo "<td>"; Dropdown::showYesNo("backcreated", $data["backcreated"]); echo "</td>"; echo "<td>" . __('Layout') . "</td><td>"; $layout_options = array('lefttab' => __("Tabs on left"), 'classic' => __("Classic view"), 'vsplit' => __("Vertical split")); echo "<select name='layout' id='layout-selector'>"; foreach ($layout_options as $key => $name) { $selected = ""; if ($data["layout"] == $key) { $selected = "selected='selected'"; } echo "<option value='{$key}' {$selected}>" . ucfirst($name) . "</option>"; } echo Html::scriptBlock("\n function formatLayout(layout) {\n return \" <img src='../pics/layout_\" + layout.id.toLowerCase() + \".png'/>\"\n + \" \" + layout.text;\n }\n \$(\"#layout-selector\").select2({\n formatResult: formatLayout,\n formatSelection: formatLayout,\n escapeMarkup: function(m) { return m; }\n });\n "); echo "</select>"; echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_2'><td>" . __('Enable ticket timeline') . "</td>"; echo "<td>"; Dropdown::showYesNo('ticket_timeline', $data['ticket_timeline']); echo "</td>"; echo "<td>" . __('Keep tabs replaced by the ticket timeline') . "</td><td>"; Dropdown::showYesNo('ticket_timeline_keep_replaced_tabs', $data['ticket_timeline_keep_replaced_tabs']); echo "</td></tr>"; if ($oncentral) { echo "<tr class='tab_bg_1'><th colspan='4'>" . __('Assistance') . "</th></tr>"; echo "<tr class='tab_bg_2'>"; echo "<td>" . __('Private followups by default') . "</td><td>"; Dropdown::showYesNo("followup_private", $data["followup_private"]); echo "</td><td>" . __('Show new tickets on the home page') . "</td><td>"; if (Session::haveRightsOr("ticket", array(Ticket::READMY, Ticket::READALL, Ticket::READASSIGN))) { Dropdown::showYesNo("show_jobs_at_login", $data["show_jobs_at_login"]); } else { echo Dropdown::getYesNo(0); } echo " </td></tr>"; echo "<tr class='tab_bg_2'><td>" . __('Private tasks by default') . "</td><td>"; Dropdown::showYesNo("task_private", $data["task_private"]); echo "</td><td> " . __('Request sources by default') . "</td><td>"; RequestType::dropdown(array('value' => $data["default_requesttypes_id"], 'name' => "default_requesttypes_id")); echo "</td></tr>"; echo "<tr class='tab_bg_2'><td>" . __('Tasks state by default') . "</td><td>"; Planning::dropdownState("task_state", $data["task_state"]); echo "</td><td colspan='2'> </td></tr>"; echo "<tr class='tab_bg_2'><td>" . __('Pre-select me as a technician when creating a ticket') . "</td><td>"; if (!$userpref || Session::haveRight('ticket', Ticket::OWN)) { Dropdown::showYesNo("set_default_tech", $data["set_default_tech"]); } else { echo Dropdown::getYesNo(0); } echo "</td><td>" . __('Automatically refresh the list of tickets (minutes)') . "</td><td>"; Dropdown::showNumber('refresh_ticket_list', array('value' => $data["refresh_ticket_list"], 'min' => 1, 'max' => 30, 'step' => 1, 'toadd' => array(0 => __('Never')))); echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_2'>"; echo "<td>" . __('Priority colors') . "</td>"; echo "<td colspan='3'>"; echo "<table><tr>"; echo "<td>1 "; Html::showColorField('priority_1', array('value' => $data["priority_1"])); echo "</td>"; echo "<td>2 "; Html::showColorField('priority_2', array('value' => $data["priority_2"])); echo "</td>"; echo "<td>3 "; Html::showColorField('priority_3', array('value' => $data["priority_3"])); echo "</td>"; echo "<td>4 "; Html::showColorField('priority_4', array('value' => $data["priority_4"])); echo "</td>"; echo "<td>5 "; Html::showColorField('priority_5', array('value' => $data["priority_5"])); echo "</td>"; echo "<td>6 "; Html::showColorField('priority_6', array('value' => $data["priority_6"])); echo "</td>"; echo "</tr></table>"; echo "</td></tr>"; } // Only for user if (array_key_exists('personal_token', $data)) { echo "<tr class='tab_bg_1'><th colspan='4'>" . __('Remote access key') . "</th></tr>"; echo "<tr class='tab_bg_1'><td>" . __('Remote access key'); if (!empty($data["personal_token"])) { //TRANS: %s is the generation date echo "<br>" . sprintf(__('generated on %s'), Html::convDateTime($data["personal_token_date"])); } echo "</td><td colspan='3'>"; echo "<input type='checkbox' name='_reset_personal_token'> " . __('Regenerate'); echo "</td></tr>"; } echo "<tr><th colspan='4'>" . __('Due date progression') . "</th></tr>"; echo "<tr class='tab_bg_1'>" . "<td>" . __('OK state color') . "</td>"; echo "<td>"; Html::showColorField('duedateok_color', array('value' => $data["duedateok_color"])); echo "</td><td colspan='2'> </td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Warning state color') . "</td>"; echo "<td>"; Html::showColorField('duedatewarning_color', array('value' => $data["duedatewarning_color"])); echo "</td>"; echo "<td>" . __('Warning state threshold') . "</td>"; echo "<td>"; Dropdown::showNumber("duedatewarning_less", array('value' => $data['duedatewarning_less'])); $elements = array('%' => '%', 'hours' => _n('Hour', 'Hours', Session::getPluralNumber()), 'days' => _n('Day', 'Days', Session::getPluralNumber())); echo " "; Dropdown::showFromArray("duedatewarning_unit", $elements, array('value' => $data['duedatewarning_unit'])); echo "</td></tr>"; echo "<tr class='tab_bg_1'>" . "<td>" . __('Critical state color') . "</td>"; echo "<td>"; Html::showColorField('duedatecritical_color', array('value' => $data["duedatecritical_color"])); echo "</td>"; echo "<td>" . __('Critical state threshold') . "</td>"; echo "<td>"; Dropdown::showNumber("duedatecritical_less", array('value' => $data['duedatecritical_less'])); echo " "; $elements = array('%' => '%', 'hours' => _n('Hour', 'Hours', Session::getPluralNumber()), 'days' => _n('Day', 'Days', Session::getPluralNumber())); Dropdown::showFromArray("duedatecritical_unit", $elements, array('value' => $data['duedatecritical_unit'])); echo "</td></tr>"; echo "<tr class='tab_bg_2'>"; echo "<td colspan='4' class='center'>"; echo "<input type='submit' name='update' class='submit' value=\"" . _sx('button', 'Save') . "\">"; echo "</td></tr>"; echo "</table></div>"; Html::closeForm(); }
static function getSpecificValueToDisplay($field, $values, array $options = array()) { global $CFG_GLPI; if (!is_array($values)) { $values = array($field => $values); } switch ($field) { case "id": self::$currentItem = new PluginMonitoringUnavailability(); self::$currentItem->getFromDB($values[$field]); break; case "name": return "test"; break; case "scheduled": $out = Dropdown::getValueWithUnit(Dropdown::getYesNo($values[$field]), ''); if (Session::haveRight("plugin_monitoring_acknowledge", READ)) { $newValue = self::$currentItem->fields['scheduled'] == '0' ? '1' : '0'; $out .= " "; $out .= "<a href='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/unavailability.form.php?id=" . self::$currentItem->fields['id'] . "&scheduled=" . $newValue . "'>" . "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/pics/acknowledge_checked.png'" . " alt='" . __('Change unavailability period schedule status', 'monitoring') . "'" . " title='" . __('Change unavailability period schedule status', 'monitoring') . "'" . " width='20' height='20'/>" . "</a>"; } return $out; } return ''; }
public function showForm($ID, $options = array()) { global $CFG_GLPI, $DB; $this->initForm($ID, $options); $this->showFormHeader($options); $rand = mt_rand(); $config = PluginOrderConfig::getConfig(); $user = new User(); if (isset($options['withtemplate']) && $options['withtemplate'] == 2) { $template = "newcomp"; $datestring = sprintf(__('Created on %s'), Html::convDateTime($_SESSION["glpi_currenttime"])); } elseif (isset($options['withtemplate']) && $options['withtemplate'] == 1) { $template = "newtemplate"; $datestring = sprintf(__('Created on %s'), Html::convDateTime($_SESSION["glpi_currenttime"])); } else { $template = false; $datestring = sprintf(__('Last update on %s'), Html::convDateTime($this->fields["date_mod"])); } $canedit = $this->canUpdateOrder() && $this->canUpdate() && !$this->isCanceled(); $cancancel = self::canCancel() && $this->can($ID, UPDATE) && $this->isCanceled(); $options['canedit'] = $canedit; $options['candel'] = $cancancel; if ($template) { $this->fields['order_date'] = NULL; } // Displaying OVER BUDGET ALERT if ($this->fields['budgets_id'] > 0) { self::displayAlertOverBudget(self::isOverBudget($ID)); } //Display without inside table /* title */ echo "<tr class='tab_bg_1'><td>" . __("Order name", "order") . "*: </td>"; echo "<td>"; if ($canedit) { $objectName = autoName($this->fields["name"], "name", $template === "newcomp", $this->getType(), $this->fields["entities_id"]); Html::autocompletionTextField($this, "name", array('value' => $objectName)); } else { echo $this->fields["name"]; } echo "</td>"; /* date of order */ echo "<td>" . __("Date of order", "order") . ":</td><td>"; if ($canedit) { if ($this->fields["order_date"] == NULL) { Html::showDateFormItem("order_date", date("Y-m-d"), true, true); } else { Html::showDateFormItem("order_date", $this->fields["order_date"], true, true); } } else { echo Html::convDate($this->fields["order_date"]); } echo "</td></tr>"; /* num order */ echo "<tr class='tab_bg_1'><td>" . __("Order number", "order"); if ($ID > 0) { echo "*"; } else { echo " <span class='red'>*</span>"; } echo ": </td>"; echo "<td>"; if ($canedit) { $objectOrder = autoName($this->fields["num_order"], "num_order", $template === "newcomp", $this->getType(), $this->fields["entities_id"]); Html::autocompletionTextField($this, "num_order", array('value' => $objectOrder)); } else { echo $this->fields["num_order"]; } echo "</td>"; /* type order */ echo "<td>" . __("Type") . ": </td><td>"; if ($canedit) { PluginOrderOrderType::Dropdown(array('name' => "plugin_order_ordertypes_id", 'value' => $this->fields["plugin_order_ordertypes_id"])); } else { echo Dropdown::getDropdownName("glpi_plugin_order_ordertypes", $this->fields["plugin_order_ordertypes_id"]); } echo "</td></tr>"; /* state */ echo "<tr class='tab_bg_1'><td>" . __("Order status", "order") . ": </td>"; echo "<td>"; if (!$this->getID()) { $state = $config->getDraftState(); } else { $state = $this->fields["plugin_order_orderstates_id"]; } if ($canedit) { PluginOrderOrderState::Dropdown(array('name' => "plugin_order_orderstates_id", 'value' => $state)); } else { echo Dropdown::getDropdownName("glpi_plugin_order_orderstates", $this->getState()); } echo "</td>"; /* budget */ echo "<td>" . __("Budget") . ": </td>"; echo "<td>"; if ($canedit) { if ($config->canHideInactiveBudgets()) { $restrict = " (`end_date` IS NULL) OR (`end_date`> '" . date("Y-m-d") . "')"; } else { $restrict = ""; } Budget::Dropdown(array('name' => "budgets_id", 'value' => $this->fields["budgets_id"], 'entity' => $this->fields["entities_id"], 'comments' => true, 'condition' => $restrict, 'width' => '150px')); } else { $budget = new Budget(); if ($this->fields["budgets_id"] > 0 && $budget->can($this->fields["budgets_id"], READ)) { echo $budget->getLink(); } else { echo Dropdown::getDropdownName("glpi_budgets", $this->fields["budgets_id"]); } } echo "</td></tr>"; /* location */ echo "<tr class='tab_bg_1'><td>" . __("Delivery location", "order") . ": </td>"; echo "<td>"; if ($canedit) { Location::Dropdown(array('name' => "locations_id", 'value' => $this->fields["locations_id"], 'entity' => $this->fields["entities_id"])); } else { echo Dropdown::getDropdownName("glpi_locations", $this->fields["locations_id"]); } echo "</td>"; /* payment */ echo "<td>" . __("Payment conditions", "order") . ": </td><td>"; if ($canedit) { PluginOrderOrderPayment::Dropdown(array('name' => "plugin_order_orderpayments_id", 'value' => $this->fields["plugin_order_orderpayments_id"])); } else { echo Dropdown::getDropdownName("glpi_plugin_order_orderpayments", $this->fields["plugin_order_orderpayments_id"]); } echo "</td>"; echo "</tr>"; /* supplier of order */ echo "<tr class='tab_bg_1'><td>" . __("Supplier") . ": </td>"; echo "<td>"; if ($canedit && !$this->checkIfDetailExists($ID)) { $rand = mt_rand(); Supplier::dropdown(array('name' => "suppliers_id", 'rand' => $rand, 'value' => $this->fields["suppliers_id"], 'entity' => $this->fields["entities_id"])); $params = array('suppliers_id' => '__VALUE__', 'fieldname' => 'contacts_id'); Ajax::updateItemOnSelectEvent("dropdown_suppliers_id{$rand}", "show_contacts_id{$rand}", "../ajax/dropdownSupplier.php", $params); } else { $supplier = new Supplier(); if ($supplier->can($this->fields['suppliers_id'], READ)) { echo $supplier->getLink(); } else { echo Dropdown::getDropdownName("glpi_suppliers", $this->fields["suppliers_id"]); } } echo "</td>"; /* port price */ echo "<td>" . __("Postage", "order") . ": </td>"; echo "<td>"; if ($canedit) { echo "<input type='number' step='" . PLUGIN_ORDER_NUMBER_STEP . "' name='port_price' size='5'" . " value=\"" . Html::formatNumber($this->fields["port_price"], true) . "\">"; } else { echo Html::formatNumber($this->fields["port_price"]); } echo "</td>"; echo "</tr>"; /* linked contact of the supplier of order */ echo "<tr class='tab_bg_1'><td>" . __("Contact") . ": </td>"; echo "<td><span id='show_contacts_id'>"; if ($canedit) { echo "<span id='show_contacts_id{$rand}'>"; // Make a select box $query = "SELECT c.`id`, c.`name`, c.`firstname`\n FROM `glpi_contacts` c\n LEFT JOIN `glpi_contacts_suppliers` s ON (s.`contacts_id` = c.`id`)\n WHERE s.`suppliers_id` = '{$this->fields['suppliers_id']}'\n ORDER BY c.`name`"; $result = $DB->query($query); $number = $DB->numrows($result); $values = array(0 => Dropdown::EMPTY_VALUE); if ($number) { while ($data = $DB->fetch_assoc($result)) { $values[$data['id']] = formatUserName('', '', $data['name'], $data['firstname']); } } Dropdown::showFromArray("contacts_id", $values, array('value' => $this->fields['contacts_id'], 'rand' => $rand)); echo "</span>\n"; } else { echo Dropdown::getDropdownName("glpi_contacts", $this->fields["contacts_id"]); } echo "</span></td>"; /* tva port price */ echo "<td>" . __("VAT", "order") . " " . __("Postage", "order") . ": </td><td>"; $PluginOrderConfig = new PluginOrderConfig(); $default_taxes = $PluginOrderConfig->getDefaultTaxes(); $taxes = empty($ID) || $ID < 0 ? $default_taxes : $this->fields["plugin_order_ordertaxes_id"]; if ($canedit) { PluginOrderOrderTax::Dropdown(array('name' => "plugin_order_ordertaxes_id", 'value' => $taxes, 'display_emptychoice' => true, 'emptylabel' => __("No VAT", "order"))); } else { echo Dropdown::getDropdownName("glpi_plugin_order_ordertaxes", $taxes); } echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __("Associable to a ticket") . " :</td><td>"; if ($canedit) { Dropdown::showYesNo('is_helpdesk_visible', $this->fields['is_helpdesk_visible']); } else { echo Dropdown::getYesNo($this->fields['is_helpdesk_visible']); } echo "</td>"; echo "<td>"; echo __("Estimated due date", "order") . ":"; if ($this->isDelivered() && $this->fields['deliverydate']) { echo "<br/>" . __("Delivery date") . ":"; } echo " </td><td>"; if ($canedit) { if ($this->fields["duedate"] == NULL) { Html::showDateFormItem("duedate", '', true, true); } else { Html::showDateFormItem("duedate", $this->fields["duedate"], true, true); } } else { echo Html::convDate($this->fields["duedate"]); } if ($this->shouldBeAlreadyDelivered()) { echo "<br/><span class='red'>" . __("Due date overtaken", "order") . "</span>"; } if ($this->isDelivered() && $this->fields['deliverydate']) { echo "<br/>" . Html::convDate($this->fields['deliverydate']); } echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td colspan='2' class='center'>" . $datestring; if (!$template && !empty($this->fields['template_name'])) { echo "<span class='small_space'>(" . __("Template name") . " : " . $this->fields['template_name'] . ")</span>"; } echo "</td><td colspan='2'></td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; //comments of order echo "<td>" . __("Comments") . ": </td>"; echo "<td colspan='3' align='center'>"; if ($canedit) { echo "<textarea cols='40' rows='3' name='comment'>" . $this->fields["comment"] . "</textarea>"; } else { echo $this->fields["comment"]; } echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<th colspan='2'>" . __("Actor") . "</th>"; if ($ID > 0 && !$template) { echo "<th colspan='2'>" . __("Cost") . "</th></tr>"; } else { echo "<th colspan='2'></th>"; } echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td colspan='2'>"; echo "<table class='format'>"; echo "<tr class='tab_bg_1'><td>" . __("Author") . ":</td><td style='width: 170px;'>"; if ($canedit) { if ($template == 'newcomp') { $value = Session::getLoginUserID(); } else { $value = $this->fields['users_id']; } User::Dropdown(array('name' => 'users_id', 'value' => $value, 'right' => 'interface', 'entity' => $this->fields["entities_id"], 'width' => '150px')); } else { if ($this->fields['users_id']) { $output = ""; if ($user->getFromDB($this->fields['users_id'])) { $output = formatUserName($this->fields['users_id'], $user->fields['name'], $user->fields['realname'], $user->fields['firstname']); } echo $output; } } echo "</td>"; echo "<td>" . __("Author group", "order") . ":</td>"; echo "<td style='width: 180px;'>"; if ($canedit) { if (empty($ID) || $ID < 0) { if (!empty($this->fields['groups_id'])) { $groups_id = $this->fields['groups_id']; } else { $groups_id = $config->getDefaultAuthorGroup(); } } else { $groups_id = $this->fields['groups_id']; } Group::Dropdown(array('value' => $groups_id, 'width' => '150px')); } else { echo Dropdown::getDropdownName('glpi_groups', $this->fields['groups_id']); } echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __("Recipient") . ":</td>"; echo "<td style='width: 170px;'>"; if ($canedit) { if (empty($ID) || $ID < 0) { if (!empty($this->fields['users_id_delivery'])) { $users_id = $this->fields['users_id_delivery']; } else { $users_id = $config->getDefaultRecipient(); } } else { $users_id = $this->fields['users_id_delivery']; } User::Dropdown(array('name' => 'users_id_delivery', 'value' => $users_id, 'right' => 'all', 'entity' => $this->fields["entities_id"], 'width' => '150px')); } else { if ($this->fields['users_id_delivery']) { $user->getFromDB($this->fields['users_id_delivery']); $output = formatUserName($this->fields['users_id'], $user->fields['name'], $user->fields['realname'], $user->fields['firstname']); echo $output; } } echo "</td>"; echo "<td>" . __("Recipient group", "order") . ":</td>"; echo "<td style='width: 180px;'>"; if ($canedit) { if (empty($ID) || $ID < 0) { if (!empty($this->fields['groups_id_delivery'])) { $groups_id = $this->fields['groups_id_delivery']; } else { $groups_id = $config->getDefaultRecipientGroup(); } } else { $groups_id = $this->fields['groups_id_delivery']; } Group::Dropdown(array('name' => 'groups_id_delivery', 'value' => $groups_id, 'width' => '150px')); } else { echo Dropdown::getDropdownName('glpi_groups', $this->fields['groups_id_delivery']); } echo "</td>"; echo "</tr></table></td>"; echo "<td colspan='2'>"; if ($ID > 0 && !$template) { $PluginOrderOrder_Item = new PluginOrderOrder_Item(); $prices = $PluginOrderOrder_Item->getAllPrices($ID); echo "<table class='format'>"; echo "<tr>"; echo "<td>" . __("Price tax free", "order") . "</td>"; echo "<td>" . Html::formatNumber($prices["priceHT"]) . "</td>"; echo "</tr>"; // total price (with postage) $postagewithTVA = $PluginOrderOrder_Item->getPricesATI($this->fields["port_price"], Dropdown::getDropdownName("glpi_plugin_order_ordertaxes", $this->fields["plugin_order_ordertaxes_id"])); $priceHTwithpostage = $prices["priceHT"] + $this->fields["port_price"]; echo "<tr>"; echo "<td>" . __("Price tax free with postage", "order") . "</td>"; echo "<td>" . Html::formatNumber($priceHTwithpostage) . "</td>"; echo "</tr>"; // total price (with taxes) $total = $prices["priceTTC"] + $postagewithTVA; echo "<tr>"; echo "<td>" . __("Price ATI", "order") . "</td>"; echo "<td>" . Html::formatNumber($total) . "</td>"; echo "</tr>"; // total TVA $total_tva = $prices["priceTVA"] + ($postagewithTVA - $this->fields["port_price"]); echo "<tr>"; echo "<td>" . __("VAT", "order") . "</td>"; echo "<td>" . Html::formatNumber($total_tva) . "</td>"; echo "</tr>"; echo "</table>"; } echo "</td>"; echo "</tr>"; if ($canedit || $cancancel) { $this->showFormButtons($options); } else { echo "</table></div>"; Html::closeForm(); } return true; }
/** * @since version 0.84 * * @param $row HTMLTableRow object (default NULL) * @param $item CommonDBTM object (default NULL) * @param $father HTMLTableCell object (default NULL) * @param $options array **/ static function getHTMLTableCellsForItem(HTMLTableRow $row = NULL, CommonDBTM $item = NULL, HTMLTableCell $father = NULL, array $options = array()) { global $DB, $CFG_GLPI; $column_name = __CLASS__; if (empty($item)) { if (empty($father)) { return; } $item = $father->getItem(); } switch ($item->getType()) { case 'FQDN': $JOINS = ""; $ORDER = "`glpi_networknames`.`name`"; if (isset($options['order'])) { switch ($options['order']) { case 'name': break; case 'ip': $JOINS = " LEFT JOIN `glpi_ipaddresses`\n ON (`glpi_ipaddresses`.`items_id` = `glpi_networknames`.`id`\n AND `glpi_ipaddresses`.`itemtype` = 'NetworkName'\n AND `glpi_ipaddresses`.`is_deleted` = '0')"; $ORDER = "ISNULL (`glpi_ipaddresses`.`id`),\n `glpi_ipaddresses`.`binary_3`, `glpi_ipaddresses`.`binary_2`,\n `glpi_ipaddresses`.`binary_1`, `glpi_ipaddresses`.`binary_0`"; break; case 'alias': $JOINS = " LEFT JOIN `glpi_networkaliases`\n ON (`glpi_networkaliases`.`networknames_id`\n = `glpi_networknames`.`id`)"; $ORDER = "ISNULL(`glpi_networkaliases`.`name`),\n `glpi_networkaliases`.`name`"; break; } } $query = "SELECT `glpi_networknames`.`id`\n FROM `glpi_networknames`\n {$JOINS}\n WHERE `glpi_networknames`.`fqdns_id` = '" . $item->fields["id"] . "'\n AND `glpi_networknames`.`is_deleted` = '0'\n ORDER BY {$ORDER}"; break; case 'NetworkPort': $query = "SELECT `id`\n FROM `glpi_networknames`\n WHERE `itemtype` = '" . $item->getType() . "'\n AND `items_id` = '" . $item->getID() . "'\n AND `glpi_networknames`.`is_deleted` = '0'"; break; case 'NetworkEquipment': $query = "SELECT `glpi_networknames`.`id`\n FROM `glpi_networknames`, `glpi_networkports`\n WHERE `glpi_networkports`.`itemtype` = '" . $item->getType() . "'\n AND `glpi_networkports`.`items_id` ='" . $item->getID() . "'\n AND `glpi_networknames`.`itemtype` = 'NetworkPort'\n AND `glpi_networknames`.`items_id` = `glpi_networkports`.`id`\n AND `glpi_networknames`.`is_deleted` = '0'"; break; } if (isset($options['SQL_options'])) { $query .= " " . $options['SQL_options']; } $canedit = isset($options['canedit']) && $options['canedit']; $createRow = isset($options['createRow']) && $options['createRow']; $options['createRow'] = false; $address = new self(); foreach ($DB->request($query) as $line) { if ($address->getFromDB($line["id"])) { if ($createRow) { $row = $row->createAnotherRow(); } if (isset($options['massiveactionnetworkname']) && $options['massiveactionnetworkname']) { $header = $row->getGroup()->getHeaderByName('Internet', 'delete'); $cell_value = Html::getMassiveActionCheckBox(__CLASS__, $line["id"]); $delete_cell = $row->addCell($header, $cell_value, $father); } $internetName = $address->getInternetName(); if (empty($internetName)) { $internetName = "(" . $line["id"] . ")"; } $content = $internetName; if (Session::haveRight('internet', READ)) { $content = "<a href='" . $address->getLinkURL() . "'>" . $internetName . "</a>"; } if (!isset($options['dont_display'][$column_name])) { $header = $row->getGroup()->getHeaderByName('Internet', $column_name); $name_cell = $row->addCell($header, $content, $father, $address); if (isset($options['display_isDynamic']) && $options['display_isDynamic']) { $dyn_header = $row->getGroup()->getHeaderByName('Internet', $column_name . '_dynamic'); $dynamic_cell = $row->addCell($dyn_header, Dropdown::getYesNo($address->fields['is_dynamic']), $name_cell); $father_for_children = $dynamic_cell; } else { $father_for_children = $name_cell; } } else { $father_for_children = $father; } NetworkAlias::getHTMLTableCellsForItem($row, $address, $father_for_children, $options); IPAddress::getHTMLTableCellsForItem($row, $address, $father_for_children, $options); } } }
/** * @param $row HTMLTableRow object (default NULL) * @param $item CommonDBTM object (default NULL) * @param $father HTMLTableCell object (default NULL) * @param $options array **/ static function getHTMLTableCellsForItem(HTMLTableRow $row = NULL, CommonDBTM $item = NULL, HTMLTableCell $father = NULL, array $options = array()) { global $DB, $CFG_GLPI; if ($item !== NULL && $item->getType() == 'IPNetwork') { $queries = array(); foreach ($CFG_GLPI["networkport_types"] as $itemtype) { $table = getTableForItemType($itemtype); $queries[] = "(SELECT ADDR.`binary_0` AS binary_0,\n ADDR.`binary_1` AS binary_1,\n ADDR.`binary_2` AS binary_2,\n ADDR.`binary_3` AS binary_3,\n ADDR.`name` AS ip,\n ADDR.`id` AS id,\n ADDR.`itemtype` AS addr_item_type,\n ADDR.`items_id` AS addr_item_id,\n `glpi_entities`.`completename` AS entity,\n NAME.`id` AS name_id,\n PORT.`id` AS port_id,\n ITEM.`id` AS item_id,\n '{$itemtype}' AS item_type\n FROM `glpi_ipaddresses_ipnetworks` AS LINK\n JOIN `glpi_ipaddresses` AS ADDR ON (ADDR.`id` = LINK.`ipaddresses_id`\n AND ADDR.`itemtype` = 'NetworkName'\n AND ADDR.`is_deleted` = '0')\n LEFT JOIN `glpi_entities` ON (ADDR.`entities_id` = `glpi_entities`.`id`)\n JOIN `glpi_networknames` AS NAME ON (NAME.`id` = ADDR.`items_id`\n AND NAME.`itemtype` = 'NetworkPort')\n JOIN `glpi_networkports` AS PORT ON (NAME.`items_id` = PORT.`id`\n AND PORT.`itemtype` = '{$itemtype}')\n JOIN `{$table}` AS ITEM ON (ITEM.`id` = PORT.`items_id`)\n WHERE LINK.`ipnetworks_id` = '" . $item->getID() . "')"; } $queries[] = "(SELECT ADDR.`binary_0` AS binary_0,\n ADDR.`binary_1` AS binary_1,\n ADDR.`binary_2` AS binary_2,\n ADDR.`binary_3` AS binary_3,\n ADDR.`name` AS ip,\n ADDR.`id` AS id,\n ADDR.`itemtype` AS addr_item_type,\n ADDR.`items_id` AS addr_item_id,\n `glpi_entities`.`completename` AS entity,\n NAME.`id` AS name_id,\n PORT.`id` AS port_id,\n NULL AS item_id,\n NULL AS item_type\n FROM `glpi_ipaddresses_ipnetworks` AS LINK\n JOIN `glpi_ipaddresses` AS ADDR ON (ADDR.`id` = LINK.`ipaddresses_id`\n AND ADDR.`itemtype` = 'NetworkName'\n AND ADDR.`is_deleted` = '0')\n LEFT JOIN `glpi_entities` ON (ADDR.`entities_id` = `glpi_entities`.`id`)\n JOIN `glpi_networknames` AS NAME ON (NAME.`id` = ADDR.`items_id`\n AND NAME.`itemtype` = 'NetworkPort')\n JOIN `glpi_networkports` AS PORT\n ON (NAME.`items_id` = PORT.`id`\n AND PORT.`itemtype`\n NOT IN ('" . implode("', '", $CFG_GLPI["networkport_types"]) . "'))\n WHERE LINK.`ipnetworks_id` = '" . $item->getID() . "')"; $queries[] = "(SELECT ADDR.`binary_0` AS binary_0,\n ADDR.`binary_1` AS binary_1,\n ADDR.`binary_2` AS binary_2,\n ADDR.`binary_3` AS binary_3,\n ADDR.`name` AS ip,\n ADDR.`id` AS id,\n ADDR.`itemtype` AS addr_item_type,\n ADDR.`items_id` AS addr_item_id,\n `glpi_entities`.`completename` AS entity,\n NAME.`id` AS name_id,\n NULL AS port_id,\n NULL AS item_id,\n NULL AS item_type\n FROM `glpi_ipaddresses_ipnetworks` AS LINK\n JOIN `glpi_ipaddresses` AS ADDR ON (ADDR.`id` = LINK.`ipaddresses_id`\n AND ADDR.`itemtype` = 'NetworkName'\n AND ADDR.`is_deleted` = '0')\n LEFT JOIN `glpi_entities` ON (ADDR.`entities_id` = `glpi_entities`.`id`)\n JOIN `glpi_networknames` AS NAME ON (NAME.`id` = ADDR.`items_id`\n AND NAME.`itemtype` != 'NetworkPort')\n WHERE LINK.`ipnetworks_id` = '" . $item->getID() . "')"; $queries[] = "(SELECT ADDR.`binary_0` AS binary_0,\n ADDR.`binary_1` AS binary_1,\n ADDR.`binary_2` AS binary_2,\n ADDR.`binary_3` AS binary_3,\n ADDR.`name` AS ip,\n ADDR.`id` AS id,\n ADDR.`itemtype` AS addr_item_type,\n ADDR.`items_id` AS addr_item_id,\n `glpi_entities`.`completename` AS entity,\n NULL AS name_id,\n NULL AS port_id,\n NULL AS item_id,\n NULL AS item_type\n FROM `glpi_ipaddresses_ipnetworks` AS LINK\n JOIN `glpi_ipaddresses` AS ADDR ON (ADDR.`id` = LINK.`ipaddresses_id`\n AND ADDR.`itemtype` != 'NetworkName'\n AND ADDR.`is_deleted` = '0')\n LEFT JOIN `glpi_entities` ON (ADDR.`entities_id` = `glpi_entities`.`id`)\n WHERE LINK.`ipnetworks_id` = '" . $item->getID() . "')"; $query = implode('UNION ', $queries); if ($options['order'] == 'ip' || $options['order'] == 'itemtype') { $query .= " ORDER BY binary_0, binary_1, binary_2, binary_3"; } if (isset($options['SQL_options'])) { $query .= "\n" . $options['SQL_options']; } $canedit = isset($options['canedit']) && $options['canedit']; $options['createRow'] = false; $address = new self(); $ipaddress = new self(); $networkname = new NetworkName(); $networkport = new NetworkPort(); $item = NULL; foreach ($DB->request($query) as $line) { unset($row); if ($options['order'] == 'itemtype' && !empty($line['item_type'])) { $row = $options['group_' . $line['item_type']]->createRow(); } if (!isset($row)) { $row = $options['group_None']->createRow(); } $ip_header = $row->getGroup()->getSuperHeaderByName('IP Address'); $item_header = $row->getGroup()->getHeaderByName('Item', 'Item'); $port_header = $row->getGroup()->getHeaderByName('Item', 'NetworkPort'); $name_header = $row->getGroup()->getHeaderByName('Item', 'NetworkName'); $entity_header = $row->getGroup()->getHeaderByName('Item', 'Entity'); $row->addCell($ip_header, $line['ip'], $father); if (!empty($line['name_id'])) { $networkname->getFromDB($line['name_id']); $row->addCell($name_header, $networkname->getLink(), $father); if (!empty($line['port_id'])) { $networkport->getFromDB($line['port_id']); $row->addCell($port_header, $networkport->getLink(), $father); if (!empty($line['item_id']) && !empty($line['item_type'])) { $itemtype = $line['item_type']; $item = new $itemtype(); $item->getFromDB($line['item_id']); $row->addCell($item_header, $item->getLink(), $father); } } $row->addCell($entity_header, $line['entity'], $father); } else { if (!empty($line['addr_item_id']) && !empty($line['addr_item_type'])) { $itemtype = $line['addr_item_type']; $item = new $itemtype(); $item->getFromDB($line['addr_item_id']); if ($item instanceof CommonDBChild) { $items = $item->recursivelyGetItems(); $elements = array($item->getLink()); foreach ($items as $item_) { $elements[] = $item_->getLink(); } $row->addCell($item_header, implode(' > ', $elements), $father); } else { $row->addCell($item_header, $item->getLink(), $father); } $row->addCell($entity_header, $line['entity'], $father); } } } } else { if (isset($options['dont_display']['IPAddress'])) { return; } $header = $row->getGroup()->getHeaderByName('Internet', __CLASS__); if (!$header) { return; } if (empty($item)) { if (empty($father)) { return; } $item = $father->getItem(); } $query = "SELECT `id`\n FROM `glpi_ipaddresses`\n WHERE `items_id` = '" . $item->getID() . "'\n AND `itemtype` = '" . $item->getType() . "'\n AND `is_deleted` = '0'"; $canedit = isset($options['canedit']) && $options['canedit']; $createRow = isset($options['createRow']) && $options['createRow']; $options['createRow'] = false; $address = new self(); foreach ($DB->request($query) as $ipaddress) { if ($address->getFromDB($ipaddress['id'])) { if ($createRow) { $row = $row->createRow(); } $content = $address->fields['name']; $this_cell = $row->addCell($header, $content, $father); if (isset($options['display_isDynamic']) && $options['display_isDynamic']) { $dyn_header = $row->getGroup()->getHeaderByName('Internet', __CLASS__ . '_dynamic'); $this_cell = $row->addCell($dyn_header, Dropdown::getYesNo($address->fields['is_dynamic']), $this_cell); } IPNetwork::getHTMLTableCellsForItem($row, $address, $this_cell, $options); } } } }
/** * Print the computers disks * * @param $comp Computer object * * @return Nothing (call to classes members) **/ static function showForComputer(Computer $comp) { global $DB; $ID = $comp->fields['id']; if (!$comp->getFromDB($ID) || !$comp->can($ID, "r")) { return false; } $canedit = $comp->can($ID, "w"); echo "<div class='spaced center'>"; $virtualmachines = getAllDatasFromTable('glpi_computervirtualmachines', "`computers_id` = '{$ID}' AND `is_deleted` = '0'"); echo "<table class='tab_cadre_fixe'>"; Session::initNavigateListItems('ComputerVirtualMachine', sprintf(__('%1$s = %2$s'), __('Computer'), empty($comp->fields['name']) ? "({$ID})" : $comp->fields['name'])); if (empty($virtualmachines)) { echo "<tr><th>" . __('No virtual machine associated with the computer') . "</th></tr>"; } else { echo "<tr><th colspan='10'>" . __('List of virtual machines') . "</th></tr>"; echo "<tr><th>" . __('Name') . "</th>"; if (Plugin::haveImport()) { echo "<th>" . __('Automatic inventory') . "</th>"; } echo "<th>" . __('Virtualization system') . "</th>"; echo "<th>" . __('Virtualization model') . "</th>"; echo "<th>" . __('State of the virtual machine') . "</th>"; echo "<th>" . __('UUID') . "</th>"; echo "<th>" . _x('quantity', 'Processors number') . "</th>"; echo "<th>" . sprintf(__('%1$s (%2$s)'), __('Memory'), __('Mio')) . "</th>"; echo "<th>" . __('Machine') . "</th>"; echo "</tr>"; $vm = new self(); foreach ($virtualmachines as $virtualmachine) { $vm->getFromDB($virtualmachine['id']); echo "<tr class='tab_bg_2'>"; echo "<td>" . $vm->getLink() . "</td>"; if (Plugin::haveImport()) { echo "<td>"; echo Dropdown::getYesNo($vm->isDynamic()); echo "</td>"; } echo "<td>"; echo Dropdown::getDropdownName('glpi_virtualmachinetypes', $virtualmachine['virtualmachinetypes_id']); echo "</td>"; echo "<td>"; echo Dropdown::getDropdownName('glpi_virtualmachinesystems', $virtualmachine['virtualmachinesystems_id']); echo "</td>"; echo "<td>"; echo Dropdown::getDropdownName('glpi_virtualmachinestates', $virtualmachine['virtualmachinestates_id']); echo "</td>"; echo "<td>" . $virtualmachine['uuid'] . "</a></td>"; echo "<td>" . $virtualmachine['vcpu'] . "</td>"; echo "<td>" . $virtualmachine['ram'] . "</td>"; echo "<td>"; if ($link_computer = self::findVirtualMachine($virtualmachine)) { $computer = new Computer(); if ($computer->can($link_computer, 'r')) { $url = "<a href='computer.form.php?id=" . $link_computer . "'>"; $url .= $computer->fields["name"] . "</a>"; $tooltip = "<table><tr><td>" . __('Name') . "</td><td>" . $computer->fields['name'] . '</td></tr>'; $tooltip .= "<tr><td>" . __('Serial number') . "</td><td>" . $computer->fields['serial'] . '</td></tr>'; $tooltip .= "<tr><td>" . __('Comments') . "</td><td>" . $computer->fields['comment'] . '</td></tr></table>'; $url .= " " . Html::showToolTip($tooltip, array('display' => false)); } else { $url = $computer->fields['name']; } echo $url; } echo "</td>"; echo "</tr>"; Session::addToNavigateListItems('ComputerVirtualMachine', $virtualmachine['id']); } } if ($canedit) { echo "<tr class='tab_bg_1'><td colspan='8' class='center'>"; echo "<a class='vsubmit' href='computervirtualmachine.form.php?computers_id={$ID}'>" . __('Add a virtual machine') . "</a></td></tr>"; } echo "</table>"; echo "</div>"; }
/** * Print the computers disks * * @param $comp Computer object * @param $withtemplate boolean Template or basic item (default '') * * @return Nothing (call to classes members) **/ static function showForComputer(Computer $comp, $withtemplate = '') { global $DB; $ID = $comp->fields['id']; if (!$comp->getFromDB($ID) || !$comp->can($ID, READ)) { return false; } $canedit = $comp->canEdit($ID); if ($canedit && !(!empty($withtemplate) && $withtemplate == 2)) { echo "<div class='center firstbloc'>" . "<a class='vsubmit' href='computerdisk.form.php?computers_id={$ID}&withtemplate=" . $withtemplate . "'>"; _e('Add a volume'); echo "</a></div>\n"; } echo "<div class='center'>"; $query = "SELECT `glpi_filesystems`.`name` AS fsname,\n `glpi_computerdisks`.*\n FROM `glpi_computerdisks`\n LEFT JOIN `glpi_filesystems`\n ON (`glpi_computerdisks`.`filesystems_id` = `glpi_filesystems`.`id`)\n WHERE `computers_id` = '{$ID}'\n AND `is_deleted` = '0'"; if ($result = $DB->query($query)) { echo "<table class='tab_cadre_fixehov table-striped table-hover'>"; $colspan = 7; if (Plugin::haveImport()) { $colspan++; } echo "<tr class='noHover'><th colspan='{$colspan}'>" . self::getTypeName($DB->numrows($result)) . "</th></tr>"; if ($DB->numrows($result)) { $header = "<tr><th>" . __('Name') . "</th>"; if (Plugin::haveImport()) { $header .= "<th>" . __('Automatic inventory') . "</th>"; } $header .= "<th>" . __('Partition') . "</th>"; $header .= "<th>" . __('Mount point') . "</th>"; $header .= "<th>" . __('File system') . "</th>"; $header .= "<th>" . __('Global size') . "</th>"; $header .= "<th>" . __('Free size') . "</th>"; $header .= "<th>" . __('Free percentage') . "</th>"; $header .= "</tr>"; echo $header; Session::initNavigateListItems(__CLASS__, sprintf(__('%1$s = %2$s'), Computer::getTypeName(1), $comp->getName())); $disk = new self(); while ($data = $DB->fetch_assoc($result)) { $disk->getFromDB($data['id']); echo "<tr class='tab_bg_2'>"; echo "<td>" . $disk->getLink() . "</td>"; if (Plugin::haveImport()) { echo "<td>" . Dropdown::getYesNo($data['is_dynamic']) . "</td>"; } echo "<td>" . $data['device'] . "</td>"; echo "<td>" . $data['mountpoint'] . "</td>"; echo "<td>" . $data['fsname'] . "</td>"; //TRANS: %s is a size $tmp = sprintf(__('%s Mio'), Html::formatNumber($data['totalsize'], false, 0)); echo "<td class='right'>{$tmp}<span class='small_space'></span></td>"; $tmp = sprintf(__('%s Mio'), Html::formatNumber($data['freesize'], false, 0)); echo "<td class='right'>{$tmp}<span class='small_space'></span></td>"; echo "<td>"; $percent = 0; if ($data['totalsize'] > 0) { $percent = round(100 * $data['freesize'] / $data['totalsize']); } Html::displayProgressBar('100', $percent, array('simple' => true, 'forcepadding' => false)); echo "</td>"; echo "</tr>"; Session::addToNavigateListItems(__CLASS__, $data['id']); } echo $header; } else { echo "<tr class='tab_bg_2'><th colspan='{$colspan}'>" . __('No item found') . "</th></tr>"; } echo "</table>"; } echo "</div><br>"; }
/** * 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(); } }
/** * @see NotificationTargetCommonITILObject::getDatasForObject() **/ function getDatasForObject(CommonDBTM $item, array $options, $simple = false) { global $CFG_GLPI; // Common ITIL datas $datas = parent::getDatasForObject($item, $options, $simple); $datas['##ticket.description##'] = Html::clean($datas['##ticket.description##']); $datas['##ticket.description##'] = $item->convertContentForNotification($datas['##ticket.description##'], $item); $datas['##ticket.content##'] = $datas['##ticket.description##']; // Specific datas $datas['##ticket.urlvalidation##'] = $this->formatURL($options['additionnaloption']['usertype'], "ticket_" . $item->getField("id") . "_TicketValidation\$1"); $datas['##ticket.globalvalidation##'] = TicketValidation::getStatus($item->getField('global_validation')); $datas['##ticket.type##'] = Ticket::getTicketTypeName($item->getField('type')); $datas['##ticket.requesttype##'] = Dropdown::getDropdownName('glpi_requesttypes', $item->getField('requesttypes_id')); $autoclose_value = Entity::getUsedConfig('autoclose_delay', $this->getEntity(), '', Entity::CONFIG_NEVER); $datas['##ticket.autoclose##'] = __('Never'); $datas['##lang.ticket.autoclosewarning##'] = ""; if ($autoclose_value > 0) { $datas['##ticket.autoclose##'] = $autoclose_value; $datas['##lang.ticket.autoclosewarning##'] = sprintf(_n('Without a reply, the ticket will be automatically closed after %s day', 'Without a reply, the ticket will be automatically closed after %s days', $autoclose_value), $autoclose_value); } $datas['##ticket.sla##'] = ''; if ($item->getField('slas_id')) { $datas['##ticket.sla##'] = Dropdown::getDropdownName('glpi_slas', $item->getField('slas_id')); } $datas['##ticket.location##'] = ''; if ($item->getField('locations_id')) { $datas['##ticket.location##'] = Dropdown::getDropdownName('glpi_locations', $item->getField('locations_id')); } // is ticket deleted $datas['##ticket.isdeleted##'] = Dropdown::getYesNo($item->getField('is_deleted')); //Tags associated with the object linked to the ticket $datas['##ticket.itemtype##'] = ''; $datas['##ticket.item.name##'] = ''; $datas['##ticket.item.serial##'] = ''; $datas['##ticket.item.otherserial##'] = ''; $datas['##ticket.item.location##'] = ''; $datas['##ticket.item.contact##'] = ''; $datas['##ticket.item.contactnumber##'] = ''; $datas['##ticket.item.user##'] = ''; $datas['##ticket.item.group##'] = ''; $datas['##ticket.item.model##'] = ''; $item_ticket = new Item_Ticket(); $items = $item_ticket->find("`tickets_id` = '" . $item->getField('id') . "'"); $datas['items'] = array(); if (count($items)) { foreach ($items as $val) { if (isset($val['itemtype']) && ($hardware = getItemForItemtype($val['itemtype'])) && isset($val["items_id"]) && $hardware->getFromDB($val["items_id"])) { $tmp = array(); //Object type $tmp['##ticket.itemtype##'] = $hardware->getTypeName(); //Object name $tmp['##ticket.item.name##'] = $hardware->getField('name'); //Object serial if ($hardware->isField('serial')) { $tmp['##ticket.item.serial##'] = $hardware->getField('serial'); } //Object contact if ($hardware->isField('contact')) { $tmp['##ticket.item.contact##'] = $hardware->getField('contact'); } //Object contact num if ($hardware->isField('contact_num')) { $tmp['##ticket.item.contactnumber##'] = $hardware->getField('contact_num'); } //Object otherserial if ($hardware->isField('otherserial')) { $tmp['##ticket.item.otherserial##'] = $hardware->getField('otherserial'); } //Object location if ($hardware->isField('locations_id')) { $tmp['##ticket.item.location##'] = Dropdown::getDropdownName('glpi_locations', $hardware->getField('locations_id')); } //Object user if ($hardware->getField('users_id')) { $user_tmp = new User(); if ($user_tmp->getFromDB($hardware->getField('users_id'))) { $tmp['##ticket.item.user##'] = $user_tmp->getName(); } } //Object group if ($hardware->getField('groups_id')) { $tmp['##ticket.item.group##'] = Dropdown::getDropdownName('glpi_groups', $hardware->getField('groups_id')); } $modeltable = getSingular($hardware->getTable()) . "models"; $modelfield = getForeignKeyFieldForTable($modeltable); if ($hardware->isField($modelfield)) { $tmp['##ticket.item.model##'] = Dropdown::getDropdownName($modeltable, $hardware->getField($modelfield)); } $datas['items'][] = $tmp; } } } $datas['##ticket.numberofitems##'] = count($datas['items']); // Get followups, log, validation, satisfaction, linked tickets if (!$simple) { // Linked tickets $linked_tickets = Ticket_Ticket::getLinkedTicketsTo($item->getField('id')); $datas['linkedtickets'] = array(); if (count($linked_tickets)) { $linkedticket = new Ticket(); foreach ($linked_tickets as $data) { if ($linkedticket->getFromDB($data['tickets_id'])) { $tmp = array(); $tmp['##linkedticket.id##'] = $data['tickets_id']; $tmp['##linkedticket.link##'] = Ticket_Ticket::getLinkName($data['link']); $tmp['##linkedticket.url##'] = $this->formatURL($options['additionnaloption']['usertype'], "ticket_" . $data['tickets_id']); $tmp['##linkedticket.title##'] = $linkedticket->getField('name'); $tmp['##linkedticket.content##'] = $linkedticket->getField('content'); $datas['linkedtickets'][] = $tmp; } } } $datas['##ticket.numberoflinkedtickets##'] = count($datas['linkedtickets']); $restrict = "`tickets_id`='" . $item->getField('id') . "'"; $problems = getAllDatasFromTable('glpi_problems_tickets', $restrict); $datas['problems'] = array(); if (count($problems)) { $problem = new Problem(); foreach ($problems as $data) { if ($problem->getFromDB($data['problems_id'])) { $tmp = array(); $tmp['##problem.id##'] = $data['problems_id']; $tmp['##problem.date##'] = $problem->getField('date'); $tmp['##problem.title##'] = $problem->getField('name'); $tmp['##problem.url##'] = $this->formatURL($options['additionnaloption']['usertype'], "problem_" . $data['problems_id']); $tmp['##problem.content##'] = $problem->getField('content'); $datas['problems'][] = $tmp; } } } $datas['##ticket.numberofproblems##'] = count($datas['problems']); $restrict = "`tickets_id`='" . $item->getField('id') . "'"; $changes = getAllDatasFromTable('glpi_changes_tickets', $restrict); $datas['changes'] = array(); if (count($changes)) { $change = new Change(); foreach ($changes as $data) { if ($change->getFromDB($data['changes_id'])) { $tmp = array(); $tmp['##change.id##'] = $data['changes_id']; $tmp['##change.date##'] = $change->getField('date'); $tmp['##change.title##'] = $change->getField('name'); $tmp['##change.url##'] = $this->formatURL($options['additionnaloption']['usertype'], "change_" . $data['changes_id']); $tmp['##change.content##'] = $change->getField('content'); $datas['changes'][] = $tmp; } } } $datas['##ticket.numberofchanges##'] = count($datas['changes']); if (!isset($options['additionnaloption']['show_private']) || !$options['additionnaloption']['show_private']) { $restrict .= " AND `is_private` = '0'"; } $restrict .= " ORDER BY `date` DESC, `id` ASC"; //Followup infos $followups = getAllDatasFromTable('glpi_ticketfollowups', $restrict); $datas['followups'] = array(); foreach ($followups as $followup) { $tmp = array(); $tmp['##followup.isprivate##'] = Dropdown::getYesNo($followup['is_private']); $tmp['##followup.author##'] = Html::clean(getUserName($followup['users_id'])); $tmp['##followup.requesttype##'] = Dropdown::getDropdownName('glpi_requesttypes', $followup['requesttypes_id']); $tmp['##followup.date##'] = Html::convDateTime($followup['date']); $tmp['##followup.description##'] = $followup['content']; $datas['followups'][] = $tmp; } $datas['##ticket.numberoffollowups##'] = count($datas['followups']); // Approbation of solution $restrict .= " LIMIT 1"; $replysolved = getAllDatasFromTable('glpi_ticketfollowups', $restrict); $data = current($replysolved); $datas['##ticket.solution.approval.description##'] = $data['content']; $datas['##ticket.solution.approval.date##'] = Html::convDateTime($data['date']); $datas['##ticket.solution.approval.author##'] = Html::clean(getUserName($data['users_id'])); //Validation infos $restrict = "`tickets_id`='" . $item->getField('id') . "'"; if (isset($options['validation_id']) && $options['validation_id']) { $restrict .= " AND `glpi_ticketvalidations`.`id` = '" . $options['validation_id'] . "'"; } $restrict .= " ORDER BY `submission_date` DESC, `id` ASC"; $validations = getAllDatasFromTable('glpi_ticketvalidations', $restrict); $datas['validations'] = array(); foreach ($validations as $validation) { $tmp = array(); $tmp['##validation.submission.title##'] = sprintf(__('An approval request has been submitted by %s'), Html::clean(getUserName($validation['users_id']))); $tmp['##validation.answer.title##'] = sprintf(__('An answer to an an approval request was produced by %s'), Html::clean(getUserName($validation['users_id_validate']))); $tmp['##validation.author##'] = Html::clean(getUserName($validation['users_id'])); $tmp['##validation.status##'] = TicketValidation::getStatus($validation['status']); $tmp['##validation.storestatus##'] = $validation['status']; $tmp['##validation.submissiondate##'] = Html::convDateTime($validation['submission_date']); $tmp['##validation.commentsubmission##'] = $validation['comment_submission']; $tmp['##validation.validationdate##'] = Html::convDateTime($validation['validation_date']); $tmp['##validation.validator##'] = Html::clean(getUserName($validation['users_id_validate'])); $tmp['##validation.commentvalidation##'] = $validation['comment_validation']; $datas['validations'][] = $tmp; } // Ticket Satisfaction $inquest = new TicketSatisfaction(); $datas['##satisfaction.type##'] = ''; $datas['##satisfaction.datebegin##'] = ''; $datas['##satisfaction.dateanswered##'] = ''; $datas['##satisfaction.satisfaction##'] = ''; $datas['##satisfaction.description##'] = ''; if ($inquest->getFromDB($item->getField('id'))) { // internal inquest if ($inquest->fields['type'] == 1) { $datas['##ticket.urlsatisfaction##'] = $this->formatURL($options['additionnaloption']['usertype'], "ticket_" . $item->getField("id") . '_Ticket$3'); // external inquest } else { if ($inquest->fields['type'] == 2) { $datas['##ticket.urlsatisfaction##'] = Entity::generateLinkSatisfaction($item); } } $datas['##satisfaction.type##'] = $inquest->getTypeInquestName($inquest->getfield('type')); $datas['##satisfaction.datebegin##'] = Html::convDateTime($inquest->fields['date_begin']); $datas['##satisfaction.dateanswered##'] = Html::convDateTime($inquest->fields['date_answered']); $datas['##satisfaction.satisfaction##'] = $inquest->fields['satisfaction']; $datas['##satisfaction.description##'] = $inquest->fields['comment']; } } return $datas; }